Monday, May 10, 2010

[ns2] Classifiers and Routing Modules: Implemenation of Routing Module--rtnotif_ v.s. ptnotif_

Note: This is a detailed note for the book, Introduction to Network Simulator NS2. You may have to read chapter 6 of the book for better understanding.

Introduction

This post is a sequel of the previous post, which demonstrated the relationship of classifiers, routing modules, and nodes:
What’s in This Post

Before proceeding further, let me refresh you memory a bit. This is the Node architecture we see earlier.  We know that $rtnotif_ is bound to address classifiers and ptnotif_ is bound to port classifiers.




This post focuses on how exactly NS2 implement $rtnotif_ and $ptnotif_

What are the purposes of routing module again?

A classifier is a multi-target forwarder [see this post] usually stored in a Node. There can be more than one classifiers in a Node, since a Node may have several criteria to classify packet (e.g., based on address, port, flow, priority).

Configuration of classifiers can be a mess. If you have 20 classifiers, you can have to have 20 configuration statements at a time. Keeping tracks of these 20 classifiers can be a headache. So, why don't you create groups of classifiers, and configure the groups instead of configuring each classifier individually? NS2 calls these groups "routing modules".

The Concept of Routing Modules

Conceptually, you create and associate a classifier with a routing module. And, you create a group by linking related routing module together. When you need to configure classifier, you do so through the "head" of the group (of routing modules) only.

Two Main Types of Implementation: Link-list and Array

There are two common ways to create a group of routing modules

1. Link-list based.

This approach is used for a group of address classifiers in a node. An example configuration is shown below:


From the above figure, a routing module connects to a classifier using its pointer classifier_. They are are links together by using pointer "next_rtm_". When we need to add a routing entry to all classifiers (by calling the instproc add-route), we only need to send the command through the first routing module (RM1), and the chain of routing modules will automatically propagate the commend to all connecting classifiers.

Note: Usually, a Node stores the first (i.e., head) routing module for the address classifier group in its instvar $rtnotif_

2. Array (list) based.

This approach is used for a group of port classifiers in a node. An example configuration is shown below:

Similar to the address classifier group, each routing module in the port classifier group connects to a classifier using its pointer classifier_.

From the above figure, routing modules are stored in each component of a array variable. Again, we do not attach an agent  directly to each of port classifiers. But we do so through the instvar storing the routing modules associated to all port classifiers (by calling the instproc add-target). NS2 will automatically send agent attaching command to all routing module in the array variable.

Note: Usually, a Node stores all routing modules for a group of port classifiers in a list instvar $ptnotif_

NS2 Codes

I will conclude  this post by showing how NS2 automatically propagates routing and agent-attaching commands.

1. Instproc add-route define in [f_NT]

I. [f_NT] Node::add-route { dst target }
  -> rtnotif_ add-route $dst $target: This statement invokes instprocs add-route of the head routing module $rtnotif_. It tells the routing module that the packet whose destination is $dst should be forwarded to NsObject $target
 
II. [f_RT] RtModule instproc add-route { dst target } 
  -> [ $self set classifier_ ] install $dst $target: Install the NsObject $target into the slot number $dst of the instvar $classifier_
  -> if { $next_rtm_ != "" } {
        $next_rtm_ add-route $dst $target
     }
     From the above figure, $next_rtm_ is the pointer to the next routing module in the address classifier group. This statement repeatedly invokes the add-route instproc from one to the next related routing module, until reaching the end of the chain.
     Again, the add-route command is entered through the head routing module, $rtnotif_. The command is then automatically propagate throughout all related routing module.
         
2. Instproc Node add-target defined in [f_NT]
 
I. [f_NT] Node::add-target { agent port }
  -> foreach m [ $self set ptnotif_ ] {: $ptnotif_ is a list (i.e., array) variable. Each of its component is a routing module associated with a port classifier (see the above figure). So the following would be done to all routing modules within the port classifier group.
  -> $m attach $agent $port: Install $agent in the slot number "$port" of the associated port classifier.
==============================================================




For more information about NS2, see Chapter 6 in the following book from Springer:
T. Issaraiyakul and E. Hossain, “Introduction to Network Simulator NS2”, Springer 2009.


You may also find lecture notes and other resource at the following website: http://www.ece.ubc.ca/~teerawat/NS2.htm

No comments: