How to set different channel for the nodes in the network in ns2

Description

In wireless network, the packets are transmitted through channel at the physical layer. The channel invokes a shared medium with support for contention mechanisms. The channel (wireless channel) allows the MAC to implement carrier sense, contention and collision detection. In sample10.tcl, the total number of nodes is divided into several groups. Each group of node is assigned to different channels.

#Filename: sample10.tcl

#************DIFFERENT CHANNEL FOR EVERY NODES*****************#
#********************************** CONFIGURING AND CREATING NODES WITH OBJECTS CREATED ABOVE *************************
#************* DEFINING THE DIFFERENT CHANNEL ******************

set channel1 [new Channel/WirelessChannel]
set channel2 [new Channel/WirelessChannel]

# configure the nodes
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $channel1 \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON
for { set i 0 } { $i < 1 } { incr i } {

set node_($i) [$ns node]
$node_($i) color black
set xx($i) [expr rand()*$val(x)]
set yy($i) [expr rand()*$val(y)]
$node_($i) set X_ $xx($i)
$node_($i) set Y_ $yy($i)
$node_($i) set Z_ 0
$ns at 0.1 "$node_($i) label CHANNEL1"
$ns at 0.0 "$node_($i) setdest $xx($i) $yy($i) 500.0"
}
# configure the nodes
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $channel2 \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON

for { set i 1 } { $i < 3 } { incr i } {

set node_($i) [$ns node]
$node_($i) color black
set xx($i) [expr rand()*$val(x)]
set yy($i) [expr rand()*$val(y)]
$node_($i) set X_ $xx($i)
$node_($i) set Y_ $yy($i)
$node_($i) set Z_ 0
$ns at 0.1 "$node_($i) label CHANNEL2"
$ns at 0.0 "$node_($i) setdest $xx($i) $yy($i) 500.0"
}