Learning to Use Numbers
1.1 Integer Numbers (int)
To determine whether the class type i.e integer or decimal etc you can type ‘type (vlan)’ as an example.
1.2 Floating-Point Numbers (float)
Section 2: Basic Arithmetic Operations in Networking
2.1 Addition (+)
This helps when adding the total bandwidth of each Transport in SD-WAN environment for licensing.
2.2 Subtraction (-)
2.3 Multiplication (*)
2.4 Division (/)
2.5 Floor Division (//)
This calculation will give you the largest number which is equivalent or less than the division as WHOLE numbers. So for example 15 // 4 = 3.75, however it will round it off to 3 instead.
2.6 Modulus (%)
This is useful when you require the remainder from a division. So if you were to divide the bandwidth from requirements and total available you can find out the remainder bandwidth available to use. QoS is a good example. Example below shows that 300/1000 = 3 and remainder is 100 available bandwidth.
2.7 Exponentiation ()**
Works out the power to. So for example 2 to the power of 8 = 2x2x2x2x2x2x2x2 = 256.
In the example below you can work out how many IP addresses required based on the cidr notation. So for a /16 subnet i can work out how many total usable IP addresses available. I have included -2 so I can remove the broadcast and network address.
Another example could be working out how many IP addresses available for a /23 subnet.
Section 3: Built-In Functions for Number Manipulation in Networking
3.1 Absolute Value: abs()
The abs()
function in Python returns the absolute value of a number. The absolute value of a number is its distance from zero on the number line, regardless of its direction. This means it is always a non-negative value.
3.2 Rounding: round()
3.3 Power: pow()
3.4 Maximum and Minimum: max()
and min()
Good example with working the average maximum and minimum bandwidths.
3.5 Sum: sum()
You can add the total bandwidth using this solution.
3.6 Divmod: divmod()
You can use this when you are dividing something and then providing the remainder once it has been divided. Such as how many IPs in a subnet and what is left over to spare in IPs.
Section 4: Converting Between Number Types in Networking
4.1 Converting to Integer: int()
String to Integer
4.2 Converting to Float: float()
String to Float (decimal points)
Section 5: Practical Mathematical Operations in Networking
5.1 Calculating Subnet Hosts
The first example below is to takeaway the broadcast and network address to give you the real useable IPs.
The 2nd example below is to include the broadcast and network IPs.
5.2 Calculating Link Utilization
5.3 Converting Latency from Milliseconds to Seconds
The formula is to divide the ms by 1000.