Friday, 7 March 2014

Clustering in NS2

How to Make clustering in NS2?
Fig.1
      Following are the steps to add clustering technique in your TCL file.

Step 1:
            Configure the node object to have address type as Hierarchical.   
# set up for hierarchical routing
$ns_ node-config -addressType hierarchical

Step 2:           No. of domains in the networking topology is 2
AddrParams set domain_num_ 2  ;    # number of domains

Step 3:
No. of clusters in each of these domains is defined as "2 1" which indicates the first domain (wired) to have 2 clusters and the second (wireless) to have 1 cluster.
lappend cluster_num 2 1 ;     # number of clusters in each domain

Step 4:
 The No. of nodes in each of these clusters which is "1 1 4"; i.e one node in each of the first 2 clusters (in wired domain) and 4 nodes in the cluster in the wireless domain
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 1 1 4 ;       # number of nodes in each cluster 

AddrParams set nodes_num_ $eilastlevel ;    # of each domain

Step 5: 
     Creation of topography which is nothing but networking area size defined in X && Y co-ordinates (Ex: Grid 1500 x 700)
# Create topography object
set topo   [new Topography]

# define topology
$topo load_flatgrid $opt(x) $opt(y)

$ns_ node-config -adhocRouting $opt(adhocRouting) \
                 -llType $opt(ll) \
                 -macType $opt(mac) \
         -topoInstance $topo \

Step 6: 
Consider creating nodes for wired Domain
#create nodes
set temp {0.0.0    0.1.0}        ;# hierarchical addresses for domain 1 (Consider it as Wired)
for {set i 0} {$i < $num_wired_nodes} {incr i} {
    set W($i) [$ns_ node [lindex $temp $i]] 
}

Step 7:
Consider creating nodes for Wireless domain
set temp {1.0.0   1.0.1   1.0.2   1.0.3}   ;# hier address to be used for wireless
#configure for mobile nodes
$ns_ node-config -wiredRouting OFF

  for {set j 0} {$j < $opt(nn)} {incr j} {
    set node_($j) [ $ns_ node [lindex $temp \
   [expr $j+1]] ]
    $node_($j) base-station [AddrParams addr2id \
   [$BS(0) node-addr]]
}

Step 8 :
              Please add the above relevant code in your TCL file. Take your Tcl code of any protocol used . Add the clustering code in ur tcl and see the result in NAM animator. the nodes will be in cluster based.

8 comments:

  1. Can u provide me the Tcl code as a demo so that I can easily understand that .. Thank you

    ReplyDelete
  2. Can u provide me the Tcl code as a demo so that I can easily understand that .. Thank you

    ReplyDelete
  3. I tried it but it is not working for me could you send me working .tcl file please liyu.adugna@gmail.com

    ReplyDelete
  4. can u send the tcl code to my mail id vishcs@yahoo.com plzz its urgent.

    ReplyDelete
  5. how connection is being established here?from cluster member to base station?

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. I also try it but it is not working can u send me the working tcl file in my mail - bhuyanparismita.0407@gmail.com

    ReplyDelete
  8. how connection is being established here?from cluster member to base station?
    Mail me at: nehamittal4893@gmail.com

    ReplyDelete