Introduction to Networking Project 3 Routing Routing protocol Goal: determine “good” path (sequence of routers) thru network from source to dest. 5 2 A Graph abstraction for routing algorithms: graph nodes are routers graph edges are physical links link cost: delay, $ cost, or congestion level 2 1 B D 3 C 3 1 5 F 1 E 2 “good” path: typically means minimum cost path other def’s possible 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 routing table for that node iterative: after k iterations, know least cost path to k dest.’s Notation: c(i,j): link cost from node i to j. cost infinite 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, that is next v N: set of nodes whose least cost path definitively known Dijsktra’s Algorithm 1 Initialization: 2 N = {A} 3 for all nodes v 4 if v adjacent to A 5 then D(v) = c(A,v) 6 else D(v) = infinity 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 start N A AD ADE ADEB ADEBC ADEBCF D(B),p(B) D(C),p(C) D(D),p(D) D(E),p(E) D(F),p(F) 2,A 1,A 5,A infinity infinity 2,A 4,D 2,D infinity 2,A 3,E 4,E 3,E 4,E 4,E 5 2 A B 2 1 D 3 C 3 1 5 F 1 E 2 Distance Vector Routing Algorithm iterative: continues until no nodes exchange info. self-terminating: no “signal” to stop asynchronous: nodes need not exchange info/iterate in lock step! distributed: each node communicates only with directly-attached neighbors Distance Table data structure each node has its own row for each possible destination column for each directly-attached neighbor to node example: in node X, for dest. Y via neighbor Z: X D (Y,Z) distance from X to = Y, via Z as next hop = c(X,Z) + min {DZ(Y,w)} w Distance Vector Routing Algorithm iterative: continues until no nodes exchange info. self-terminating: no “signal” to stop Each node: wait for (change in local link cost of msg from neighbor) asynchronous: nodes need not exchange info/iterate in lock step! distributed: each node communicates only with directly-attached neighbors recompute distance table if least cost path to any dest has changed, notify neighbors Routing Lab Project 3 A distance-vector algorithm and a link-state algorithm in the context of a simple routing simulator Event-driven Simulation: event to event simulation, instead of simulating passage of time directly main loop repeatedly pulls the earliest event from a event queue and passes it to a handler until there are no more events in the queue. context.cc/context.h SimulationContext (Written for you) demo.topo A demonstration network topology file demo.event A demonstration event file error.h event.cc/event.h Event (Written for you) eventqueue.cc/eventqueue.h EventQueue (Written for you) link.cc/link.h Link (Written for you) Makefile messages.cc RoutingMessage (You will write this) messages.h node.cc Node (You will extend this) node.h routesim.cc main program table.cc RoutingTable (You will write this) table.h topology.cc/topology.h Topology (Written for you) “make TYPE=GENERIC” will build a single executable “routesim”, which contains no routing algorithm. You will do TYPE=DISTANCEVECTOR and TYPE=LINKSTATE To run: ./routesim topologyfile eventfile [singlestep] Events in routesim come from the topology file, the event file, and from handlers that are executed in response to events. The topology file generally only contains events that construct the network topology (the graph) arrival_time ADD_NODE node_num latency bandwidth arrival_time DELETE_NODE node_num latency bandwidth arrival_time ADD_LINK src_node_num dest_node_num latency bandwidth arrival_time DELETE_LINK src_node_num dest_node_num latency bandwidth The event file generally only contains events that modify link characteristics in the graph, or draw the graph, a path and etc. arrival_time CHANGE_NODE node_num latency bandwidth arrival_time CHANGE_LINK src_node_num dest_node_num latency bandwidth arrival_time DRAW_TOPOLOGY arrival_time DRAW_TREE src_node_num Note that although each link event contains both bandwidth and latency numbers, your algorithms will determine shortest paths using only the link latencies. The Node class (4 functions that you must implement) void Node::LinkHasBeenUpdated(const Link *l) void Node::ProcessIncomingRoutingMessage(const RoutingMessage *m) is called when a routing message arrives at a node. In response, you may send further routing messages using SendToNeighbors or SendToNeighbor. You may also update your tables. Node *Node::GetNextHop(const Node *dest) const is called to inform you that an outgoing link connected to your node has just changed its properties. is called when the simulation wants to know what your node currently thinks is the next hop on the path to the destination node. You should consult your routing table and then return the correct next node for reaching the destination. Table *Node::GetRoutingTable() const is called when the simulation wants to get a copy of your current routing table. Your implementation will consist of implementations of the above four functions, as well as implementations of Table and RoutingMessage The table class Mainly contains the routing table, different for DISTANCEVECTOR and LINKSTATE as discussed in the class, please refer to your lecture notes. Note that STL data structures can be quite useful here especially vector and map. Vectors can be used to store an unbounded array. Maps can be used to associate a value for each node in the graph, like the latency to each neighbor. For example the cost table for LINKSTATE can be specified as map< int, double > costtable which maps a double to an int. For a good reference to STL, see the recitals page. You should also know how iterators work if you plan to use these data structures. The RoutingMessage Class Implements the routing messages which will be sent by each node to its neighbors. Need to carefully think what will go inside these routing messages depending on the routing algorithm you are implementing. LINKSTATE routing messages contain more information than DISTANCEVECTOR routing messages. General approach to implement a routing algorithm Understand what routesim (TYPE=GENERIC) is doing. Read the link.h file to understand the Link class. Develop a Table class. This should provide you with what you need to implement the GetNextHop() and GetRoutingTable() calls. It should also be updatable, as its contents will change with link updates and routing messages. Extend the Node data structure to include your table Implement Node::GetNextHop() and Node::GetRoutingTable() Develop your routing message. Think about where your routing message will go. Implement Node::LinkHasBeenUpdated () Implement Node::ProcessRoutingMessage() Implement Node::TimeOut(), if needed. A number of ways to implementation The rest are some sample codes, they are only showing you some rough idea on how to implement, DO NOT directly copy them in your own implementation, the sample codes does NOT guarantee to work; Sample code in LS LinkHasBeenUpdated(const Link *l) void Node::LinkHasBeenUpdated(const Link *l) { cerr << *this<<": Link Update: "<<*l<<endl; /***********update own lsa database*****************/ double ts = (*context).GetTime(); lsatb->update_link(l->GetSrc(), l->GetDest(), l->GetLatency(), ts); /*************Pass this to its neighbours*****************/ RoutingMessage *m = new RoutingMessage(); (*m).LSAs.push_back(lsa(l->GetSrc(), l->GetDest(), l->GetLatency(),ts)); SendToNeighbors(m); } void Node::SendToNeighbors(const RoutingMessage *m) { cerr << "Flooding source ID: "<< number <<endl; deque<Node*> *ngbr = GetNeighbors(); for(deque<Node*>::iterator i = ngbr->begin(); i!= ngbr->end(); i++) { SendToNeighbor(*i,m); } } void Node::SendToNeighbor(const Node *n, const RoutingMessage *m) { cerr << "SendToNeighbor (Ngbr id: "<< n->number <<endl; Link l; l.SetSrc(number); l.SetDest((*n).number); Link *ml = context->FindMatchingLink(&l); assert(ml!=NULL); assert(n!=NULL); assert(m!=NULL); assert(context!=NULL); Event *e = new Event ((*context).GetTime()+(*ml).GetLatency(), ROUTING_MESSAGE_ARRIVAL,(void*)n, (void*)m); (*context).PostEvent(e); } Sample of Table head file for LS algorithm class Table { public: Table(unsigned my_id); ostream & Print(ostream &os) const; bool update_link(const unsigned s, const unsigned d, double l, double ts); int get_next_hop(unsigned dest); Table *get_routing_table() const; protected: void dijkstra(); int find_next_hop(data curr, vector<data> v, vector<unsigned> next); private: unsigned my_id; vector<unsigned> nodes; vector<aLink*> links; map<unsigned, int> routes; }; Pseudocode of Dijkstra Algorithm from Wiki Pseudocode of B-F algorithm from Wiki