Showing posts with label cluster nodes TCL. Show all posts
Showing posts with label cluster nodes TCL. Show all posts

Friday, 7 March 2014

Clustering in NS-2

How to Make clustering in NS-2?
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.

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.