Sunday, March 28, 2010

Classifiers and Routing Modules: Putting a default classifier in a node using "$ns node"

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 are they, their purposes, their relationship, and how to configure them conceptually.

What's in This Post

Now that you get the concept, let's look at how NS2 actually configure them. I will demonstrate the process by walking through a command $ns node, which creates a node.
This post focuses mainly on how a default classifier, namely classifier_, is create and inserted into a node. I will discuss about routing modules in subsequent posts.

Notation

In this post, I will use the following notation. As you can expect, "$ns node" deals with a lot of procedures. One procedure calls another. You are going to experience a great deal of confusion. Not pleasant, right.
Fortunately, with in one procedure, there are only few fundamental steps, and I will show you only these steps. You can look at the NS2 file for a complete version.
To facilitate the explanation, I will use the following notation.
    [filename] Class::Instproc
       -> Main step
       -> Main step
       ...
Also, we are going to see several files, and I will use the following notation for file names:
  • [f_NT] = ns-2.35/tcl/lib/ns-node.tcl 
  • [f_LT] = ns-2.35/tcl/lib/ns-lib.tcl
  • [f_RT] = ns-2.35/tcl/lib/ns-rtmodule.tcl
Calling Structure

Let me show you a bird-eye view of what to be done. Basically there are 3 main parts:
    I. $ns node
    II. Constructor of Class Node
    III. Inserting Routing Modules and Classifiers
Now, let's dig into each part.

Part I. $ns node

The main steps in this part is
    [f_LT] Simulator::node
      -> new [Simulator set node_factory_]
The variable node_factory_ is set to node by default. Effectively the above statement becomes
new node
which is an OTcl statement to create a Node object. The constructor is define in the instproc
[f_NT] Node::init

Part II. Constructor of Class Node (i.e., Node::init)


The main steps in the constructor of class Node are
  1. [f_NT] Node::init



      ->$self mk-default-classifier, which invokes step II.2 below.

  2. [f_NT] Node::mk-default-classifier



      ->$self register-module [new RtModule/$modname]. By default, $modname is Base. Therefore, the above statement is equivalent to $self register-module [new RtModule/Base] which in turn executes the step II.3 below. Note that this instproc belongs to class Node. Therefore $self is the instance of class Node that we are dealing with.
  3. [f_NT] Node::register-module {mod}



      ->$mod register $self,
      which insert the routing module and classifier into the Node instance that we are dealing with. Note that, mod is a base routing module created in step II.2. The insertion process is explained in Part III.
Part III. Insert Routing Modules and Classifiers

This part carries out the last step in the part II:
$mod register $self
where $mod is the base routing module, and $self is the Node instance that we are working on. Well, NS2 executes the following instproc:
[f_RT] RtModule/Base instproc register {node}
which consists of two main steps

  1. set classifier_ [new Classifier/Hash/Dest 32]

    which creates a Classifier/Hash/Dest (address classifier) instance, and puts it in the instvar classifier_.
  2. $node install-entry $self $classifier_

    which inserts the instance classifier_ (that was just created ) right after the node entry, and associated it with the routing module $self (which in our case is the base routing module created in Step II.2).
Summary: What we have done.

After a long winding road, we came up with a simple node architecture below:

We have inserted an address classifier into a node, and stored it in the instvar classifier_ of the node. In the next post, I will move one to other components in the figure.

Isn't it Long?

I know, I know. You must be tired after reading this. For the upside, at least, you now understand what routing module and classifiers are, and how NS2 puts a default classifier inside a node.
We are not done yet. The node configuration keeps going until all the boxes in the above figure are filled with color. Stay tune!!
One final note: I left out a lot of details. Feel free to look at NS2 codes, by the file indicated in [...].
==============================================================
For more information about incorporating new modules into NS2, see Chapter 2 in the following book from Springer:
T. Issaraiyakul and E. Hossain, “Introduction to Network Simulator NS2”, Springer 2009. Buy it now below




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

No comments: