Lecture 13
Algorithms
Distance Vector Algorithms
Tell your neighbours about the world
Tell directly connected neighbours about all your other neighbours/learned routes
Share distance (hops) and next-hop
Routes get updated when they have lower cost
Periodic vs triggered updates depends on the algorithm
Bellman-Ford
Preliminaries:
- Undirected, weighted graph
- No sides with negative weights
Steps:
Init:
- Distance from node to itself = 0
- Distance from a node to another =
Update rule: - Minimum distance of the sum of the distance to neighbour
plus the distance of said neighbour to the target
There was an exam question on Bellman-Ford
%20Inter-Networking%20and%20Routing/Attachments/Pasted%20image%2020251014103457.png)
Iteration 3 Node 5 can also be 10, based on if the nodes get updated left to right, or all at once
I.e. parallel or consecutive
If we do left to right, when node 5 is updated, the value of node 3 is already set to 5, making for a shorter path
Algorithm needs to run
Adding Memory
Nodes can store backup paths, instead of just the best
Fall back to them when the best link fails
However, this has some quirks
Backup path might use links from primary path, i.e. cause loops
Might be stale / no longer available
Also has slightly higher overhead
Count to Infinity
Even without memory, loops can be created:
%20Inter-Networking%20and%20Routing/Attachments/Pasted%20image%2020251014104036.png)
Can be solved by (like in RIP):
- Infinity horizon:
- When a value is larger than X, drop it
- Holddown timers
- A ignores updates for a while
- Rout poisoning
- A repots infinite distance A->N to B
- B in turn reports infinite distance back
- Split horizon
- Don't advertise routes back to advertiser
- B does not report distance to N back to A
Link State Algorithm
Dijkstra
Initialisation:
- Create a set sptSet (shortest path tree set) that keeps track of vertices included in the shortest path tree, i.e., whose minimum distance from the source is calculated and finalised. Initially, this set is empty.
- Assign a distance value to all vertices in the input graph. Initialize all distance values as INFINITE. Assign the distance value as 0 for the source vertex so that it is picked first
Repeat steps: - While sptSet doesn’t include all vertices:
- Pick a neighbour vertex
that is not there in sptSet and has a minimum distance value (source -> ). - This will always be something adjacent to the current SPT, as anything else has distance
- This will always be something adjacent to the current SPT, as anything else has distance
- Include
to sptSet. - Then update the distance value of all adjacent vertices of
. - To update the distance values, iterate through all adjacent vertices.
- For every adjacent vertex
, if the sum of the distance value of (from source) and weight of edge , is less than the distance value of , then update the distance value of - If the value is not lower, do not update
- Considered greedy, as we always want the best distance
- Pick a neighbour vertex
%20Inter-Networking%20and%20Routing/Attachments/Pasted%20image%2020251014104818.png)
Exam might ask to execute Dijkstra, showing which nodes are included and the distances at each step
Shortest Path Tree (SPT)
Create a tree with the shortest path from a source node to all other nodes
Both Bellman-Ford and Dijkstra are SPT algorithms
Minimum Spanning Tree (MST)
A spanning tree is a tree-like subgraph that includes all vertices
A minimum spanning tree has all properties of a spanning tree, AND the sum of weights is minimal
There can be multiple (minimum) spanning trees per graph
Prim's and Kruskal's are MST algorithms
Algorithms based on Global or Centralised Information
Prim's Algorithm
Initialisation:
- Create a set mstSet that keeps track of vertices already included in MST.
- Assign a key value to all vertices in the input graph. Initialise all key values as INFINITE. Assign the key value as 0 for the first vertex so that it is picked first.
- While mstSet doesn’t include all vertices:
> A.k.a. always pick the smallest edge already connected to your tree that doesn't form a loop- Pick a vertex u that is not there in mstSet and has a minimum key value.
- Include u in the mstSet.
- Update the key value of all adjacent vertices of u. To update the key values, iterate through all adjacent vertices:
- For every adjacent vertex v, if the weight of edge u-v is less than the previous key value of v, update the key value as the weight of u-v.
%20Inter-Networking%20and%20Routing/Attachments/Pasted%20image%2020251014112330.png)
- For every adjacent vertex v, if the weight of edge u-v is less than the previous key value of v, update the key value as the weight of u-v.
Simple:
- Start with a random node, add it to the MST
- Choose the edge with minimum value that spans between the MST and a node not in the MST
- Update values of new MST node
- Repeat until all vertices are in MST
Kruskal's
- Sort all edges in non-decreasing order
- Pick the smallest edge that does not form a loop
- Repeat #2 until there are (V-1) edges in the spanning tree
%20Inter-Networking%20and%20Routing/Attachments/Pasted%20image%2020251014112857.png)
Key Takeaways
All tree algorithms create spanning trees
If all distances/weights are different, then there is a single/unique MST
If there is a unique MST, Kruskal can be parallelised
Not every MST is an spanning tree for all nodes
Not every SPT is automatically an MST
%20Inter-Networking%20and%20Routing/Attachments/Pasted%20image%2020251014113141.png)
Exam
Topics:
- Routing
- BGP
- OSPF
- L2 connectivity
- VLANs
- DNS (not very broad, allegedly)
- Subnet calculation maybe
- Nothing like the labs
Question types:
- Multiple choice
- No negative marking (< 0)
- Open ended
- If you add explanation that shows you don't understand, you get less points
- Problems
Allowed materials:
- Book
- Slides
- Notes
- Labs
- Calculator
Commands, headers & fields will not be tested
Q1
- ARP is a broadcast, so 255.255.255.255?
The IP it wants to know is 10.1.5.4 - The problem lies in the fact that the two networks have different subnet masks: /16 vs /24
Therefore, H2 thinks S2 is in the subnet -> it should use ARP to address it directly
However, S2 is in a different network, across a router
The network S2 is in is /24, and does not consider H2 to be in the same subnet
Therefore, the router would require special configuration to forward the ARP request anyway, or impersonate S2 and answer the ARP itself
If the above are not used, the ping will not work
Q2
- Router 5 is not connected to area 0, so no it will not work
- One can switch area 2 and area 0
Otherwise, use a virtual link that connects R4 to area 0
Q3
- VLANs, basically
Q4
- Run Dijkstra