Network Planning VITMM215 Practice Markosz Maliosz PhD 21/9/2016 Department of Telecommunication and Media Informatics
Basic algorithms 2
Algorithms Algorithm: a sequence of step-by-step instructions for solving a problem Problem: – Given: input data a query about input data – Algorithm: Most important: depending on the size of the input data (n) how many steps are required to solve a problem – “fast” : polynomial – number of steps ~ n k – “slow” : e.g. exponential – number of steps ~ a n or factorial ~ n! – Complexity: characterizes the problem problem classes: – P: polynomial time algorithm exists for solving – NP (nondeterministic polynomial time) hard: no polynomial time algorithm is known to solve the problem – Exhaustive search “endless” time 3
Algorithms How to solve NP hard problems in practice? – for a special case can exist a polynomial time algorithm – if the input data is not huge, then the solving time can be acceptable – if the solution is not time-critical, then maybe an exponential running time is acceptable – we do not insist on the optimum: approximation methods, heuristics 4
Algorithms Example: Number Number of possible Number of connected of nodes topologies topologies – N nodes 1 1 1 – N*(N-1)/2 possible links 2 2 1 3 8 4 – 2 N*(N-1)/2 possible 4 64 38 topologies 5 1 024 728 however some of them 6 32 768 26 704 are not connected 7 2 097 152 1 866 256 8 268 435 456 251 548 592 Goal: to reduce the 9 68 719 476 736 66 296 291 072 number of possibilities 10 35 184 372 088 832 34 496 488 594 816 to choose from Example: greedy algorithm 5
Greedy Algorithms At each step the best choice is chosen – it never steps back Advantage: generally simple Disadvantage: does not reach the optimum in many cases 6
Example A – E path? 7
Example Naïve greedy algorithm based on local information – Path: A – C – D – B – E – Cost: 2 + 2 + 1 + 5 = 10 8
Example Optimal min-cost path – Path: A – D – E – Cost: 3 + 3 = 6 9
Finding Shortest Paths Polynomial greedy algorithm that finds the optimum for the shortest path problem: Dijkstra’s algorithm Common approach: routing uses shortest paths 10
Dijkstra ’s shortest path algorithm E. W. Dijkstra, Dutch computer scientist lowest cost = shortest path shortest path in a graph with non-negative edge weights – directed or undirected graph – from a selected source – to all other nodes, as destinations it builds a spanning tree from the source node used in network routing protocols, e.g. IS-IS and OSPF (Open Shortest Path First) 11
Dijkstra ’s algorithm Given: G = (V, E): Form two sets of nodes: – S : nodes, we already determined the shortest path from the source – V-S : all the other nodes Store two values at each nodes: – d : the length of the shortest path leading from the source to this node in the current state (distance) – p : the predecessor node in the shortest path according to the current state 12
Dijkstra ’s algorithm The steps: Initialize d and p 1. – source node: d=0, other nodes: d =∞ – p: invalid for all nodes S = {} /empty set/ 2. While V-S is not empty, 3. – Sort nodes in V-S set according to shortest paths – Move the nearest u node from V-S to S set – For the nodes, that are in V-S and are connected to u : recalculate d ; if it is less then the previous value, then update it if d was updated: set p to u 13
Dijkstra ’s algorithm - example Starting point: – directed graph – source: s – S ={} – V-S = V (thin framing) – numbers on edges: weights – numbers in nodes: d s : 0 other: ∞ 14
Dijkstra ’s algorithm - example First step – nearest node: s (d=0) – move it from V-S to S (thick framing) – neighbor nodes with s : u and x update d and set p (red arrows) 15
Dijkstra ’s algorithm - example Second step – nearest node: x (d=5) – move it from V-S to S (thick framing) – neighbor nodes with x : u, v and y update d and set p (red arrows) 16
Dijkstra ’s algorithm - example Third step – nearest node: y (d=7) – move it from V-S to S (thick framing) – neighbor nodes with y : v update d and set p (red arrows) 17
Dijkstra ’s algorithm - example Fourth step – nearest node: u (d=8) – move it from V-S to S (thick framing) – neighbor nodes with u : v update d and set p (red arrow) 18
Dijkstra ’s algorithm - example Fifth (last) step – the only node in V-S : v (d=9) – move it from V-S to S (thick framing) The paths from the source to the other nodes can be backtracked with the red arrows. The red arrows ( p ) form a shortest path tree. 19
Shortest Path – Link Weights What should be the link weights? – physical distance? – delay on a link? – hop count (w=1)? – some arbitrary number? Cisco’s default: – inversely proportional to its capacity – higher capacity links are “shorter” – drives traffic to higher capacity links – can lead to strange routing 20
Link weight setting example Traffic: – q t : 1 – r t : 1 – s t : 1 – w t : 1 21
Link Weights The correct choice depends on objectives Common goal: minimize delays – if propagation delay is dominant minimize physical path distance weight = link distance – if processing delay is dominant minimize hop count, weight = 1 – if queuing delay is dominant measure delays along links calculate shortest path according to measured delay values 22
Tree Networks Connects all nodes with minimum number of links There is one and only one path between any node pairs Example applications: – cable TV network: broadcast from one source to many – Ethernet Spanning Tree Protocol 23
Spanning Tree Def.: subgraph, which is a tree and contains all nodes 24
Minimum spanning tree link cost edge weights The minimum spanning tree is the minimum cost spanning tree among all spanning trees If each link has a distinct weight, there will be a unique MST, otherwise the MST is not unique 25
Kruskal’s Algorithm Greedy algorithm to find minimum spanning tree – create a forest F (a set of trees), where each node in the graph is a separate tree – At each step, take the minimum-weight edge if it connects two different trees, then add to the forest combine the two trees into a single tree otherwise discard that edge – If there is only one tree, the problem is solved Animation: http://visualgo.net/mst 26
Prim’s Algorithm Greedy algorithm to find minimum spanning tree – select an arbitrary node as initial element of the set – in each iteration, choose a minimum-weight edge ( u , v ), connecting a node v in the set to the node u outside of the set, then node u is brought into the set – this process is repeated until all the set will contain all nodes When the algorithm terminates, the edges in the set form a minimum spanning tree Animation: http://visualgo.net/mst 27
Calculating Spanning Tree 2 4 E C A 2 6 9 5 10 4 6 B D F Find the min-cost spanning tree in the graph! 28
Ethernet STP An Ethernet network can have multiple possible paths for reliability STP is intended to create a tree to avoid loops – broadcast storm 802.1D algorithm based on Dijkstra’s alg. – switches are assigned numerical priorities – switch with lowest priority becomes root switch tie break is lowest MAC address (are unique) – each switch port is given a cost = link weight based on bandwidth of the link 29
STP Port Costs Default costs – old version based on 1 Gbps/(link bandwidth) – new version: arbitrary table port cost: integer, >0 Link speed Old cost New cost 10 Mbps 100 100 100 Mbps 10 19 1 Gbps 1 4 10 Gbps 1 2 30
STP Bridge Protocol Data Units are sent regularly – priority, cost information and state – flooded through network Protocol finds min-cost path to root switch with Dijkstra’s algorithm in a distributed way – ports not on shortest path towards root bridge are blocked 31
STP Optimization in STP – minimizes path length for each leafs to get to the root – link weights can be arbitrary! – with default weights: pushes traffic to higher bandwidth paths 32
Recommend
More recommend