Routing Computer Networking: A Top Down Approach 6th edition Jim Kurose, Keith Ross Addison-Wesley March 2012 Interplay between routing, forwarding routing algorithm local forwarding table header value output link 0100 0101 0111 1001 3 2 2 1 value in arriving packet’s header 0111 1 3 2 Graph abstraction 5 2 u 2 1 Graph: G = (N,E) v x 3 w 3 1 5 z 1 y 2 N = set of routers = { u, v, w, x, y, z } E = set of links ={ (u,v), (u,x), (v,x), (v,w), (x,w), (x,y), (w,y), (w,z), (y,z) } Remark: Graph abstraction is useful in other network contexts Example: P2P, where N is set of peers and E is set of TCP connections Graph abstraction: costs 5 2 u v 2 1 x • c(x,x’) = cost of link (x,x’) 3 w 3 1 5 z 1 y - e.g., c(w,z) = 5 2 • cost could always be 1, or inversely related to bandwidth, or inversely related to congestion Cost of path (x1, x2, x3,…, xp) = c(x1,x2) + c(x2,x3) + … + c(xp-1,xp) Question: What’s the least-cost path between u and z ? Routing algorithm: algorithm that finds least-cost path Routing Algorithm classification Global or decentralized information? Global: all routers have complete topology, link cost info “link state” algorithms Decentralized: router knows physicallyconnected neighbors, link costs to neighbors iterative process of computation, exchange of info with neighbors “distance vector” algorithms Static or dynamic? Static: routes change slowly over time Dynamic: routes change more quickly periodic update in response to link cost changes A Link-State Routing Algorithm Dijkstra’s algorithm net topology, link costs known to all nodes accomplished via “link state broadcast” all nodes have same info computes least cost paths from one node (‘source”) to all other nodes gives forwarding table for that node iterative: after k iterations, know least cost path to k dest.’s Notation: c(x,y): link cost from node x to y; = ∞ if not direct neighbors D(v): current value of cost of path from source to dest. v p(v): predecessor node along path from source to v N': set of nodes whose least cost path definitively known Dijsktra’s Algorithm 1 Initialization: 2 N' = {u} 3 for all nodes v 4 if v adjacent to u 5 then D(v) = c(u,v) 6 else D(v) = ∞ 7 8 Loop 9 find w not in N' such that D(w) is a minimum 10 add w to N' 11 update D(v) for all v adjacent to w and not in N' : 12 D(v) = min( D(v), D(w) + c(w,v) ) 13 /* new cost to v is either old cost to v or known 14 shortest path cost to w plus cost from w to v */ 15 until all nodes in N' Dijkstra’s algorithm: example Step 0 1 2 3 4 5 N' u ux uxy uxyv uxyvw uxyvwz D(v),p(v) D(w),p(w) 2,u 5,u 2,u 4,x 2,u 3,y 3,y D(x),p(x) 1,u 2 u 2 1 x 3 w 3 1 5 z 1 y D(z),p(z) ∞ ∞ 4,y 4,y 4,y 5 v D(y),p(y) ∞ 2,x 2 Dijkstra’s algorithm: example (2) Resulting shortest-path tree from u: v w u z x Resulting forwarding table in u: destination link v x (u,v) (u,x) y (u,x) w (u,x) z (u,x) y Dijkstra algorithm illustration [2 / s] 5 [5 / s] a b 3 2 4 [0 / s] 3 2 s 1 e 2 1 1 c [1 / s] d [∞ / ] [∞ / ] Dijkstra algorithm illustration [2 / s] 5 [4 / c] a b 3 2 4 [0 / s] 3 2 s 1 e 2 1 1 c d [1 / s] [2 / c] [∞ / ] Dijkstra algorithm illustration [2 / s] 5 [4 / c] a b 3 2 4 [0 / s] 3 2 s 1 e 2 1 1 c d [1 / s] [2 / c] [∞ / ] Dijkstra algorithm illustration [2 / s] 5 [3 / d] a b 3 2 4 [0 / s] 3 2 s 1 e 2 1 1 c [1 / s] d [2 / c] [4 / d] Dijkstra algorithm illustration [2 / s] 5 [3 / d] a b 3 2 4 [0 / s] 3 2 s 1 e 2 1 1 c d [1 / s] [2 / c] [4 / d] Dijkstra algorithm illustration [2 / s] 5 [3 / d] a b 3 2 4 [0 / s] 3 2 s 1 e 2 1 1 c d [1 / s] [2 / c] [4 / d] Dijkstra algorithm summary • 复杂度 (Complexity) – O(n2) 注意: 计算所有的最短路径和计算一条最短路径具有相同的复杂度。 • 输出结果给出了网络上的一棵生成树 (Spanning Tree)。 5 a b 3 2 4 s e 3 2 1 1 2 c d 1 Dijkstra’s algorithm, discussion Algorithm complexity: n nodes each iteration: need to check all nodes, w, not in N n(n+1)/2 comparisons: O(n2) more efficient implementations possible: O(nlogn) Oscillations possible: e.g., link cost = amount of carried traffic D 1 1 0 A 0 0 C e 1+e e initially B 1 2+e A 0 D 1+e 1 B 0 0 C … recompute routing 0 D 1 A 0 0 C 2+e B 1+e … recompute 2+e A 0 D 1+e 1 B e 0 C … recompute Distance Vector Algorithm Bellman-Ford Equation (dynamic programming) Define dx(y) := cost of least-cost path from x to y Then dx(y) = min {c(x,v) + dv(y) } v where min is taken over all neighbors v of x Bellman-Ford example 5 2 u v 2 1 x 3 w 3 1 5 z 1 y Clearly, dv(z) = 5, dx(z) = 3, dw(z) = 3 2 B-F equation says: du(z) = min { c(u,v) + dv(z), c(u,x) + dx(z), c(u,w) + dw(z) } = min {2 + 5, 1 + 3, 5 + 3} = 4 Node that achieves minimum is next hop in shortest path ➜ forwarding table Distance Vector Algorithm Dx(y) = estimate of least cost from x to y Node x knows cost to each neighbor v: c(x,v) Node x maintains distance vector Dx = [Dx(y): y є N ] Node x also maintains its neighbors’ distance vectors For each neighbor v, x maintains Dv = [Dv(y): y є N ] Distance vector algorithm (4) Basic idea: From time-to-time, each node sends its own distance vector estimate to neighbors Asynchronous When a node x receives new DV estimate from neighbor, it updates its own DV using B-F equation: Dx(y) ← minv{c(x,v) + Dv(y)} for each node y ∊ N Under minor, natural conditions, the estimate Dx(y) converge to the actual least cost dx(y) Distance Vector Algorithm (5) Iterative, asynchronous: each local iteration caused by: local link cost change DV update message from neighbor Distributed: each node notifies neighbors only when its DV changes neighbors then notify their neighbors if necessary Each node: wait for (change in local link cost or msg from neighbor) recompute estimates if DV to any dest has changed, notify neighbors Dx(y) = min{c(x,y) + Dy(y), c(x,z) + Dz(y)} = min{2+0 , 7+1} = 2 node x table cost to x y z = min{2+1 , 7+0} = 3 cost to x y z from from x 0 2 7 y ∞∞ ∞ z ∞∞ ∞ node y table cost to x y z Dx(z) = min{c(x,y) + Dy(z), c(x,z) + Dz(z)} x 0 2 3 y 2 0 1 z 7 1 0 x ∞ ∞ ∞ y 2 0 1 z ∞∞ ∞ node z table cost to x y z from from x x ∞∞ ∞ y ∞∞ ∞ z 71 0 time 2 y 7 1 z Dx(y) = min{c(x,y) + Dy(y), c(x,z) + Dz(y)} = min{2+0 , 7+1} = 2 node x table cost to x y z x ∞∞ ∞ y ∞∞ ∞ z 71 0 from from from from x 0 2 7 y 2 0 1 z 7 1 0 cost to x y z x 0 2 7 y 2 0 1 z 3 1 0 x 0 2 3 y 2 0 1 z 3 1 0 cost to x y z x 0 2 3 y 2 0 1 z 3 1 0 cost to x y z from from from x ∞ ∞ ∞ y 2 0 1 z ∞∞ ∞ node z table cost to x y z x 0 2 3 y 2 0 1 z 7 1 0 = min{2+1 , 7+0} = 3 cost to x y z cost to x y z from from x 0 2 7 y ∞∞ ∞ z ∞∞ ∞ node y table cost to x y z cost to x y z Dx(z) = min{c(x,y) + Dy(z), c(x,z) + Dz(z)} x 0 2 3 y 2 0 1 z 3 1 0 time x 2 y 7 1 z Distance Vector: link cost changes Link cost changes: node detects local link cost change updates routing info, recalculates distance vector if DV changes, notify neighbors “good news travels fast” 1 x 4 y 50 1 z At time t0, y detects the link-cost change, updates its DV, and informs its neighbors. At time t1, z receives the update from y and updates its table. It computes a new least cost to x and sends its neighbors its DV. At time t2, y receives z’s update and updates its distance table. y’s least costs do not change and hence y does not send any message to z. Distance Vector: link cost changes Good news spreads fast 1 X 4 Y 50 1 Z 算法 收敛 Distance Vector: link cost changes Link cost changes: good news travels fast bad news travels slow - “count to infinity” problem! 44 iterations before algorithm stabilizes: see text Poisoned reverse: If Z routes through Y to get to X : Z tells Y its (Z’s) distance to X is infinite (so Y won’t route to X via Z) will this completely solve count to infinity problem? 60 x 4 y 50 1 z Distance Vector: link cost changes Bad news spreads slowly, so called “Count to Infinity Problem”: 60 X 4 Y 50 1 Z 算法仍 不收敛 Distance Vector–Poisoned Reverse Poisoned Reverse: 如果 Z 到 X 的最短路径 经过 Y,那么 Z 告诉 Y “Z 到 X 的最短距离 是 ∞ “,这样 Y 就不会选择经由 Z 到达 X 的 路线。 60 X 4 Y 50 1 Z 算法 收敛 ∞ 立即修改 Comparison of LS and DV algorithms Message complexity LS: with n nodes, E links, O(nE) msgs sent DV: exchange between neighbors only convergence time varies Speed of Convergence LS: O(n2) algorithm requires O(nE) msgs may have oscillations DV: convergence time varies may be routing loops count-to-infinity problem Robustness: what happens if router malfunctions? LS: node can advertise incorrect link cost each node computes only its own table DV: DV node can advertise incorrect path cost each node’s table used by others • error propagate thru network DV versus LS Distance Vector 仅与邻居节点交换消息 消息包括到所有节点的 最短距离 收敛速度比较慢 能够广播不正确的路径 信息 有Count to Infinity Problem Link State 向网络上所有其它节 点广播消息 消息仅包括到邻居节 点的距离 收敛速度比较快 能够广播不正确的链 路信息 没有Count to Infinity Problem Hierarchical Routing Our routing study thus far - idealization all routers identical network “flat” … not true in practice scale: with 200 million destinations: can’t store all dest’s in routing tables! routing table exchange would swamp links! administrative autonomy internet = network of networks each network admin may want to control routing in its own network Hierarchical Routing aggregate routers into regions, “autonomous systems” (AS) routers in same AS run same routing protocol “intra-AS” routing protocol routers in different AS can run different intraAS routing protocol Gateway router Direct link to router in another AS Interconnected ASes 3c 3a 3b AS3 1a 2a 1c 1d 1b Intra-AS Routing algorithm 2c AS2 AS1 Inter-AS Routing algorithm Forwarding table 2b forwarding table configured by both intra- and inter-AS routing algorithm intra-AS sets entries for internal dests inter-AS & intra-As sets entries for external dests Inter-AS tasks AS1 must: 1. learn which dests are reachable through AS2, which through AS3 2. propagate this reachability info to all routers in AS1 Job of inter-AS routing! suppose router in AS1 receives datagram destined outside of AS1: router should forward packet to gateway router, but which one? 3c 3b 3a AS3 1a 2a 1c 1d 1b 2c AS2 AS1 2b Example: Setting forwarding table in router 1d suppose AS1 learns (via inter-AS protocol) that subnet x reachable via AS3 (gateway 1c) but not via AS2. inter-AS protocol propagates reachability info to all internal routers. router 1d determines from intra-AS routing info that its interface I is on the least cost path to 1c. installs forwarding table entry (x,I) x 3c 3a 3b AS3 1a 2a 1c 1d 1b AS1 2c 2b AS2 Example: Choosing among multiple ASes now suppose AS1 learns from inter-AS protocol that subnet x is reachable from AS3 and from AS2. to configure forwarding table, router 1d must determine towards which gateway it should forward packets for dest x. this is also job of inter-AS routing protocol! x 3c 3a 3b AS3 1a 2a 1c 1d 1b 2c AS2 AS1 2b Example: Choosing among multiple ASes now suppose AS1 learns from inter-AS protocol that subnet x is reachable from AS3 and from AS2. to configure forwarding table, router 1d must determine towards which gateway it should forward packets for dest x. this is also job of inter-AS routing protocol! hot potato routing: send packet towards closest of two routers. Learn from inter-AS protocol that subnet x is reachable via multiple gateways Use routing info from intra-AS protocol to determine costs of least-cost paths to each of the gateways Hot potato routing: Choose the gateway that has the smallest least cost Determine from forwarding table the interface I that leads to least-cost gateway. Enter (x,I) in forwarding table Intra-AS Routing also known as Interior Gateway Protocols (IGP) most common Intra-AS routing protocols: RIP: Routing Information Protocol OSPF: Open Shortest Path First IGRP: Interior Gateway Routing Protocol (Cisco proprietary) RIP ( Routing Information Protocol) distance vector algorithm included in BSD-UNIX Distribution in 1982 distance metric: # of hops (max = 15 hops) From router A to subnets: u v A z C B D w x y destination hops u 1 v 2 w 2 x 3 y 3 z 2 RIP advertisements distance vectors: exchanged among neighbors every 30 sec via Response Message (also called advertisement) each advertisement: list of up to 25 destination subnets within AS RIP: Example z w A x D B y C Destination Network w y z x …. Next Router Num. of hops to dest. …. .... A B B -- Routing/Forwarding table in D 2 2 7 1 RIP: Example Dest w x z …. Next C … w hops 1 1 4 ... A Advertisement from A to D z x Destination Network w y z x …. D B C y Next Router Num. of hops to dest. …. .... A B B A -- Routing/Forwarding table in D 2 2 7 5 1 RIP: Link Failure and Recovery If no advertisement heard after 180 sec --> neighbor/link declared dead routes via neighbor invalidated new advertisements sent to neighbors neighbors in turn send out new advertisements (if tables changed) link failure info quickly (?) propagates to entire net poison reverse used to prevent ping-pong loops (infinite distance = 16 hops) RIP Table processing RIP routing tables managed by application-level process called route-d (daemon) advertisements sent in UDP packets, periodically repeated routed routed Transprt (UDP) network (IP) link physical Transprt (UDP) forwarding table forwarding table network (IP) link physical OSPF (Open Shortest Path First) “open”: publicly available uses Link State algorithm LS packet dissemination topology map at each node route computation using Dijkstra’s algorithm OSPF advertisement carries one entry per neighbor router advertisements disseminated to entire AS (via flooding) carried in OSPF messages directly over IP (rather than TCP or UDP OSPF “advanced” features (not in RIP) security: all OSPF messages authenticated (to prevent malicious intrusion) multiple same-cost paths allowed (only one path in RIP) For each link, multiple cost metrics for different TOS (e.g., satellite link cost set “low” for best effort; high for real time) integrated uni- and multicast support: Multicast OSPF (MOSPF) uses same topology data base as OSPF hierarchical OSPF in large domains. Hierarchical OSPF Hierarchical OSPF two-level hierarchy: local area, backbone. Link-state advertisements only in area each nodes has detailed area topology; only know direction (shortest path) to nets in other areas. area border routers: “summarize” distances to nets in own area, advertise to other Area Border routers. backbone routers: run OSPF routing limited to backbone. boundary routers: connect to other AS’s. Internet inter-AS routing: BGP BGP (Border Gateway Protocol): the de facto standard BGP provides each AS a means to: 1. 2. 3. Obtain subnet reachability information from neighboring ASs. Propagate reachability information to all ASinternal routers. Determine “good” routes to subnets based on reachability information and policy. allows subnet to advertise its existence to rest of Internet: “I am here” BGP basics pairs of routers (BGP peers) exchange routing info over semi-permanent TCP connections: BGP sessions BGP sessions need not correspond to physical links. when AS2 advertises a prefix to AS1: AS2 promises it will forward datagrams towards that prefix. AS2 can aggregate prefixes in its advertisement eBGP session 3c 3a 3b AS3 1a AS1 iBGP session 2a 1c 1d 1b 2c AS2 2b Distributing reachability info using eBGP session between 3a and 1c, AS3 sends prefix reachability info to AS1. 1c can then use iBGP do distribute new prefix info to all routers in AS1 1b can then re-advertise new reachability info to AS2 over 1b-to-2a eBGP session when router learns of new prefix, it creates entry for prefix in its forwarding table. eBGP session 3c 3a 3b AS3 1a AS1 iBGP session 2a 1c 1d 1b 2c AS2 2b Path attributes & BGP routes advertised prefix includes BGP attributes. prefix + attributes = “route” two important attributes: AS-PATH: contains ASs through which prefix advertisement has passed: e.g, AS 67, AS 17 NEXT-HOP: indicates specific internal-AS router to next-hop AS. (may be multiple links from current AS to next-hop-AS) when gateway router receives route advertisement, uses import policy to accept/decline. BGP route selection router may learn about more than 1 route to some prefix. Router must select route. elimination rules: 1. 2. 3. 4. local preference value attribute: policy decision shortest AS-PATH closest NEXT-HOP router: hot potato routing additional criteria 单播 主机之间“一对一”的通讯模式,网络中的交换机和路由器 对数据只进行转发不进行复制。但由于其能够针对每个客户 的及时响应,所以现在的网页浏览全部都是采用IP单播协议。 网络中的路由器和交换机根据其目标地址选择传输路径,将 IP单播数据传送到其指定的目的地。 55 单播 单播的优点: 1. 服务器及时响应客户机的请求 2. 服务器针对每个客户不通的请求发送不通的数据,容 易实现个性化服务。 单播的缺点: 1. 服务器针对每个客户机发送数据流,在客户数量大、 每个客户机流量大的流媒体应用中服务器不堪重负。 2. 现有的网络带宽是金字塔结构,城际省际主干带宽仅 仅相当于其所有用户带宽之和的5%。如果全部使用单播 协议,将造成网络主干不堪重负。 56 广播 主机之间“一对所有”的通讯模式,网络对其中每一台主机 发出的信号都进行无条件复制并转发,所有主机都可以接收 到所有信息(不管你是否需要),由于其不用路径选择,所 以其网络成本可以很低廉。有线电视网就是典型的广播型网 络。在数据网络中也允许广播的存在,但其被限制在二层交 换机的局域网范围内,禁止广播数据穿过路由器,防止广播 数据影响大面积的主机。 57 广播 广播的优点: 1. 网络设备简单,维护简单,布网成本低廉 2. 由于服务器不用向每个客户机单独发送数据,所以服 务器流量负载极低。 广播的缺点: 1.无法针对每个客户的要求和时间及时提供个性化服务。 2. 网络允许服务器提供数据的带宽有限,客户端的最大 带宽=服务总带宽。 3. 广播禁止在Internet宽带网上传输。 58 Broadcast Routing deliver packets from source to all other nodes source duplication is inefficient: duplicate duplicate creation/transmission R1 R1 duplicate R2 R2 R3 R4 source duplication R3 R4 in-network duplication source duplication: how does source determine recipient addresses? In-network duplication flooding: when node receives brdcst pckt, sends copy to all neighbors Problems: cycles & broadcast storm controlled flooding: node only brdcsts pkt if it hasn’t brdcst same packet before Node keeps track of pckt ids already brdcsted Or reverse path forwarding (RPF): only forward pckt if it arrived on shortest path between node and source spanning tree No redundant packets received by any node Spanning Tree First construct a spanning tree Nodes forward copies only along spanning tree A B c F A E B c D F G (a) Broadcast initiated at A E D G (b) Broadcast initiated at D Spanning Tree: Creation Center node Each node sends unicast join message to center node Message forwarded until it arrives at a node already belonging to spanning tree A A 3 B c 4 E F 1 2 B c D F 5 E D G G (a) Stepwise construction of spanning tree (b) Constructed spanning tree 组播 主机之间“一对一组”的通讯模式,也就是加入了同一个组 的主机可以接受到此组内的所有数据,网络中的交换机和路 由器只向有需求者复制并转发其所需数据。 63 组播 组播的优点: 1. 需要相同数据流的客户端加入相同的组共享一条数据 流,节省了服务器的负载。具备广播所具备的优点。 2. 由于组播协议是根据接受者的需要对数据流进行复制 转发,所以服务端的服务总带宽不受客户接入端带宽的 限制。 3. 此协议和单播协议一样允许在Internet宽带网上传输。 组播的缺点: 1.与单播协议相比没有纠错机制,发生丢包错包后难以 弥补,但可以通过一定的容错机制和QoS加以弥补。 2.现行网络虽然都支持组播的传输,但在客户认证、 QoS等方面还需要完善,这些缺点在理论上都有成熟的 解决方案,只是需要逐步推广应用到现存网络当中。 64 Multicast Routing: Problem Statement Goal: find a tree (or trees) connecting routers having local mcast group members tree: not all paths between routers used source-based: different tree from each sender to rcvrs shared-tree: same tree used by all group members Shared tree Source-based trees Approaches for building mcast trees Approaches: source-based tree: one tree per source shortest path trees reverse path forwarding group-shared tree: group uses one tree minimal spanning (Steiner) center-based trees …we first look at basic approaches, then specific protocols adopting these approaches Shortest Path Tree mcast forwarding tree: tree of shortest path routes from source to all receivers Dijkstra’s algorithm S: source LEGEND R1 1 2 R4 R2 3 R3 router with attached group member 5 4 R6 router with no attached group member R5 6 R7 i link used for forwarding, i indicates order link added by algorithm Reverse Path Forwarding rely on router’s knowledge of unicast shortest path from it to sender each router has simple forwarding behavior: if (mcast datagram received on incoming link on shortest path back to center) then flood datagram onto all outgoing links else ignore datagram Reverse Path Forwarding: example S: source LEGEND R1 R4 router with attached group member R2 R5 R3 R6 R7 router with no attached group member datagram will be forwarded datagram will not be forwarded • result is a source-specific reverse SPT – may be a bad choice with asymmetric links Reverse Path Forwarding: pruning forwarding tree contains subtrees with no mcast group members no need to forward datagrams down subtree “prune” msgs sent upstream by router with no downstream group members LEGEND S: source R1 router with attached group member R4 R2 P R5 R3 R6 P R7 P router with no attached group member prune message links with multicast forwarding Shared-Tree: Steiner Tree Steiner Tree: minimum cost tree connecting all routers with attached group members problem is NP-complete excellent heuristics exists not used in practice: computational complexity information about entire network needed monolithic: rerun whenever a router needs to join/leave Center-based trees single delivery tree shared by all one router identified as to join: “center” of tree edge router sends unicast join-msg addressed to center router join-msg “processed” by intermediate routers and forwarded towards center join-msg either hits existing tree branch for this center, or arrives at center path taken by join-msg becomes new branch of tree for this router Center-based trees: an example Suppose R6 chosen as center: LEGEND R1 3 R2 router with attached group member R4 2 R5 R3 1 R6 R7 1 router with no attached group member path order in which join messages generated Summary Link-State Routing Distance Vector Routing Internet Routing Broadcast Multicast