Unicast Routing: Unicast routing is the sending of packets to a single destination. "Unicast" is derived from the word broadcast, as unicast in networks is the extreme opposite of broadcasting. There are four routing strategies in ns: Static, Session, Dynamic and Manual. Static: The static route computation strategy is the default route computation mechanism in ns. This strategy uses the Dijkstra SPF algorithm. The route computation algorithm is run exactly once prior to the start of the simulation. The routes are computed using an adjacency matrix and link costs of all the links in the topology. Session: This routing type uses also the Dijkstra SPF algorithm. The static routing strategy described earlier only computes routes for the topology once in the course of a simulation. If the above static routing is used and the topology changes while the simulation is in progress, some sources and destinations may become temporarily unreachable from each other for a short time. Dynamic (DV – distance vector): routing is the implementation of Distributed Bellman-Ford (or DistanceVector) routing in ns. The implementation sends periodic route updates every advertInterval. This variable is a class variable in the class Agent/rtProto/DV. Its default value is 2 seconds. Manual: Manual routing is not a route computation protocol (like the others), but simply away for users to configure the routing table by hand, much as you would with the “route” command on a workstation. We use add-route-to-adj-node command to set each nodes routing tables. Configuration mechanisms for specialized routing Asymmetric Routing – occurs when the path from node n1 to n2 is different from path from n2 to n1. Each routing protocol that uses link costs can observe such asymmetric routing. MultiPath Routing – each node can be individually configured to use the multiple separate paths to a particular destination. Currently, only DV routing can generate multipath routing. set n1 [$ns Node] $n1 set multiPath_ 1 ;# only enable $n1 to use multiPaths where applicable Classes There are four main classes; RouterLogic, rtObject, rtPeer, Agent/rtProto. RouterLogic: register{} – is invoked by Simulator::rtproto{}, It takes the protocol and a list of nodes as arguments and constructs an instance variable, rtprotos_, as an array. configure{} – is invoked by the simulator run procedure. Reads the rtprotos_ instance variable and invokes appropriate routing protocol for each node. lookup{} – takes two node number as arguments Id1, Id2 and returns the id of the neighbor node that Id1 uses to reach Id2. rtObject: inti{} – the constructor sets up pointer from itself to the node, in its instance variable node_. add-proto{} – creates the instance of the protocol. Attaches the protocol to the node and returns the handle of the protocol object. lookup{} – takes the destination node handle and returns the id of the neighbor node that used to reach the destination. compute-routes{} – It first checks to see if any of the routing protocol sat the node have computed any new routes. If they have, it will determine the best route to each destination from among all the protocols. If any routes have changed, the procedure will notify each of the protocols of the number of such changes, in case any of these protocols wants to send a fresh update. Finally, it will also notify any multi cast protocol that new unicast route tables have been computed. dump-routes{} – takes a output file descriptor as argument, and writes out the routing table at that node on that file descriptor. rtProto?{} – takes a route protocol as argument, and returns a handle to the instance of the protocol running at the node. nextHop?{} – takes a destination node handle, and returns the link that is used to reach that destination. rtpref?{}and metric?{} – take a destnation node handle as argument, and return the preference and metric of the route to the destination installed at the node. rtPeer: is a container class used by the protocol agents. Agent/rtProto: This class is the base class from which all routing protocol agents are derived. Each protocol agent must define the procedure init-all{} to initialize the complete protocol, and possibly instance procedures init{}, compute-routes{}, and send-updates{}. In addition, if the topology is dynamic, and the protocol supports route computation to react to changes in the topology, then the protocol should define the procedure compute-all{}, and possibly the instance procedure intf-changed{}. Commands: Rtproto{} - is the instance procedure in the class Simulator that specify the unicast routing protocol for the simulation. Te first argument of this function identifies the routing protocol, subsequent arguments specify the nodes that will be run the instance of this protocol. The default is to run the same routing protocol for all nodes. The default protocol algorithm is a Static algorithm. $ns rtproto Session $ns rtproto DV $ns1 $ns2 $ns3 ;# Enable Session routing for this session ;# Run DV agents on nodes $ns1 $ns2 $ns3 Internal Methods: Preference Assignment and Control - each protocol agent stores an array of route references, rtpref_. Agent/rtProto set preference_ 200 ;# global default preference Link Cost Assignments and Control – In the currently implemented route protocols, the metric of a route to a destination, at a node, is the cost to reach the destination from that node. $ns cost $n1 $n2 10 ;# set cost of link from $ns1 to $ns2 to 10 [$ns link $n1 $n2] cost? ;# query cost of link from $ns1 to $ns2 $ns_compute-routes: This command computes next_hop information for all nodes in the topology using the topology connectivity. This next_hop info is then used to populate the node classifiers or the routing tables. compute-routes calls compute-?atroutes or compute-hier-routes depending on the type of addressing being used for the simulation. $ns_get-routelogic: This returns a handle to the RouteLogic object (the routing table), if one has been created. Otherwise a new routing table object is created. $ns_dump-routelogic-nh: This dumps next hop information in the routing table. $ns_dump-routelogic-distance: This dumps the distance information in the routing table. $nodeadd-route<dst><Target>: This is a method used to add routing entries (next hop information) in the nodes routing table. The next hop to<dst>from this node is the <target>object and this info is added to the nodes classifier. $routelogiclookup<srcid><destid>: Returns the id of the node that is the next hop from the node with id srcid to the node with id destid. $routelogicdump<nodeid>:Dump the routing tables of all nodes whose id is less than node id. Node ids are typically assigned to nodes in ascending fashion starting from 0 by their order of creation. rtobjectdump-routes<fileID>: Dump the routing table to the output channel specified by fileID. FileID must be a file handle returned by the Tclopen command and it must have been opened for writing. $rtobjectrtProto?<proto>: Returns a handle to the routing protocol agent specified by proto if it exists at that node. Returns an empty string otherwise. $rtobjectnextHop?<destID>: Returns the id of the node that is the next hop to the destination specified by the node id, <destID>. $rtobjectrtpref?destID: Returns the preference for the route to destination node given by destid. $rtobjectmetric?destID: Returns metric for the route to destid. Node and Packet forwarding Node basics: The instance procedure node constructs a node out of more simple classifier objects. The simple structure consists of two TclObjects: and others classifier called classifier_ and the port classifier called dMux_. The function of these classifiers is to distribute incoming packets. Unicast node contains the following components: An address or id_, monotonically increasing by 1 (from initial value 0) across the simulation namespace as nodes are created A list of neighbors (neighbor_). A list of agents (agent_), A node type identifier (nodetype_) A routing module By default, nodes in ns are constructed for unicast simulations. Procedures to configure an individual node can be classified into: —Control functions —Address and Port number management, unicast routing functions —Agent management —Tracking neighbors Control functions: $node entry – returns the first element which will handle packets arriving at that node. $node reset – will reset all agents at the node. Address and Port number management $node id – returns the id (node number) of the node. $node agent <port> - returns the handle of the agent at the specified port, if exists. Otherwise returns null string. $node alloc-port – returns the next available port number. $node add-route / add-routes <destination id> <TclObject> - adds routes to populate the classifier_. TclObjects is the entry of dmux_ at the node. $node delete-routes – removes the TclObjects from the installed routes. Detailed dynamic routing uses also: init-routing{} and rtObject?. Intf-changed is invoked if a link incident on the node changes state. Agent management: $node attach <agent> - adds the agent to the list of agents, assign the port number to it and sets its source address. $node detach <agent> – removes the agent from agents. Tracking neighbors: $node add-neighbor - adds a neighbor to the list neighbor_. $node neighbors – returns the list neighbor_.