Quantcast

Routing table NS2

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Routing table NS2

Alexandre Jaron

Hello,

I am a King's College student in London. I am encountering difficulties with
my project.
I am working on a wired scenario for now, and I need to add a kind of
routing table on certain nodes. Basically, I want to tell one node: 'every
packet coming from this node, forward them to that node'.
Is it doable in NS2 ?

I found something, to add static routes : *[$node set ragent_]
addstaticroute <number of hops> <next hop> <destination node> <interface>*
But I don't know how to use it.

May somebody help me?
Kind regards,

Alexandre Jaron.
MSc student.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Routing table NS2

Sidney Doria

Alexandre,

This TCL might help you.


Thanks to Priscila Doria @ UFCG (who give me this TCL).


Sidney Doria
UFCG / BRAZIL
---------------

# Create six nodes
set x [$ns node]
set y [$ns node]
set z [$ns node]
set w [$ns node]
set r1 [$ns node]
set r2 [$ns node]
set r3 [$ns node]
set r4 [$ns node]
set a [$ns node]
set b [$ns node]
set c [$ns node]
set d [$ns node]

# Define NAM node colors
$x color green
$y color red
$z color purple
$w color white
$r1 shape box
$r2 shape box
$r3 shape box
$r4 shape box
$a color green
$b color red
$c color purple
$d color white

# Links
$ns duplex-link $r1 $x  10Mb 1ms  DropTail
$ns duplex-link $r1 $c  10Mb 1ms  DropTail
$ns duplex-link $r1 $r2 2Mb  20ms DropTail

$ns duplex-link $r2 $y  10Mb 1ms  DropTail
$ns duplex-link $r2 $d  10Mb 1ms  DropTail
$ns duplex-link $r2 $r3 10Mb 40ms DropTail

$ns duplex-link $r3 $z  10Mb 1ms  DropTail
$ns duplex-link $r3 $a  10Mb 1ms  DropTail
$ns duplex-link $r3 $r4 2Mb  20ms DropTail

$ns duplex-link $r4 $w  10Mb 1ms  DropTail
$ns duplex-link $r4 $b  10Mb 1ms  DropTail
$ns duplex-link $r4 $r1 10Mb 40ms DropTail

# Orientation (NAM)
$ns duplex-link-op $r1 $x orient up
$ns duplex-link-op $r1 $c orient left
$ns duplex-link-op $r1 $r2 orient right

$ns duplex-link-op $r2 $y orient right
$ns duplex-link-op $r2 $d orient up
$ns duplex-link-op $r2 $r3 orient down

$ns duplex-link-op $r3 $z orient right
$ns duplex-link-op $r3 $a orient down
$ns duplex-link-op $r3 $r4 orient left

$ns duplex-link-op $r4 $w orient left
$ns duplex-link-op $r4 $b orient down
$ns duplex-link-op $r4 $r1 orient up


# Returns the local link that leads to
# the next hop node with the passed
# node address parameter. If no link to
# the given node exists, the procedure
# returns -1.
Node instproc nexthop2link { nexthop } {
        #$self instvar link_
        set ns_ [Simulator instance]
        foreach {index link} [$ns_ array get link_] {
                set L [split $index :]
                set src [lindex $L 0]
                if {$src == [$self id]} {
                        set dst [lindex $L 1]
                        if {$dst == $nexthop} {
                                # Cost Debug
                                #puts "Src:$src Dst:$dst Link:$link"
                                #puts "[$link info class]"
                                # End Cost Debug
                                return $link
                        }
                }
        }
        return -1
}

#
# This procedure is used to add explicitly
# routes to a node, overriding the routing
# policy used (e.g. shortest path routing).
# Tested currently with static ns2 routing.
# Essentially, it is used to add policy-routing
# entries in realistic network topologies.
#
# Parameters:
#
# node: the ns2 node, to which the route
#      entry is added to. This parameter
#      is of type Node.
# dst: the destination, to which the route
#     entry refers to. This parameter
#      is of type Node.
# via: the next hope node, that the local node
#     will use to access the destination node.
#     This parameter is of type Node.
#
##########################################################
proc addExplicitRoute {node dst via } {
        set link2via [$node nexthop2link [$via node-addr]]
        if {$link2via != -1} {
                $node add-route [$dst node-addr] [$link2via head]
        } else {
                puts "Warning: No link exists between node [$node
node-addr] and [$via node-addr]. Explicit route not
added."
        }
}

# Now the Routing Table
$ns at 0 "addExplicitRoute $r1 $z $r4"
$ns at 0 "addExplicitRoute $r1 $a $r2"
$ns at 0 "addExplicitRoute $r1 $w $r4"

$ns at 0 "addExplicitRoute $r2 $w $r1"
$ns at 0 "addExplicitRoute $r2 $b $r3"
$ns at 0 "addExplicitRoute $r2 $x $r1"

$ns at 0 "addExplicitRoute $r3 $x $r2"
$ns at 0 "addExplicitRoute $r3 $c $r4"
$ns at 0 "addExplicitRoute $r3 $y $r2"

$ns at 0 "addExplicitRoute $r4 $y $r3"
$ns at 0 "addExplicitRoute $r4 $d $r1"
$ns at 0 "addExplicitRoute $r4 $z $r3"

------------------

2010/5/18 Alexandre Jaron <[hidden email]>:

>
> Hello,
>
> I am a King's College student in London. I am encountering difficulties with
> my project.
> I am working on a wired scenario for now, and I need to add a kind of
> routing table on certain nodes. Basically, I want to tell one node: 'every
> packet coming from this node, forward them to that node'.
> Is it doable in NS2 ?
>
> I found something, to add static routes : *[$node set ragent_]
> addstaticroute <number of hops> <next hop> <destination node> <interface>*
> But I don't know how to use it.
>
> May somebody help me?
> Kind regards,
>
> Alexandre Jaron.
> MSc student.
>



--
Sidney Doria
Redes ad hoc móveis
Doutorado em Computação
UFCG
Brasil

"Nessa jornada, o conhecimento será o seu escudo..."
(Mestre dos Magos no episódio do grimoire de ouro)

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Routing table NS2

bouhmid
In reply to this post by Alexandre Jaron
Hello ,

can you help me please to modifie routing algorithme or changing some thing to have an crossbar switch in my node with ns simulator .

Thank you.

Alexandre Jaron wrote
Hello,

I am a King's College student in London. I am encountering difficulties with
my project.
I am working on a wired scenario for now, and I need to add a kind of
routing table on certain nodes. Basically, I want to tell one node: 'every
packet coming from this node, forward them to that node'.
Is it doable in NS2 ?

I found something, to add static routes : *[$node set ragent_]
addstaticroute <number of hops> <next hop> <destination node> <interface>*
But I don't know how to use it.

May somebody help me?
Kind regards,

Alexandre Jaron.
MSc student.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Diffusion RMSt (diffagent, routing table, reinforcement messages )

anasamer
In reply to this post by Alexandre Jaron

Dear ns-2 users and developers
I have been working on ns2.29 using Directed Diffusion (RMST) to
simulate my network.

1- I attached the rmst as DiffApp to the node that conflict NS2 that
says agents should be attached to nodes and applications to the agents
so should i create diffusion agents and attach it to the nodes before.


2- i managed to run the simulation with zigbee and in the trace file i
can see packets being sent and received but as diffusion is defined to
do gradient reinforcement so can i see the packets which execute these
reinforcements in the trace file and what will they be labelled.

3- in term of packets forwarding i cannot see any packet being forwarded
from the far nodes toward the rmst sink in the trace file so should i
add the routing tables manually to each node or it is internally
implemented in the diffusion application

i have added my scripts at the end

With all appreciate to any reply or suggestion
Regards
Anas  


#===================================
#     Simulation parameters setup
#===================================

set val(chan)   Channel/WirelessChannel    ;# channel type
set val(prop)   Propagation/TwoRayGround   ;# radio-propagation model
set val(netif)  Phy/WirelessPhy/802_15_4            ;# network interface
type
set val(mac)    Mac/802_15_4                ;# MAC type
set val(ifq)    Queue/DropTail/PriQueue    ;# interface queue type
set val(ll)     LL                         ;# link layer type
set val(ant)    Antenna/OmniAntenna        ;# antenna model
set val(ifqlen) 50                         ;# max packet in ifq
set val(seed) 00.0
set val(nn)     20                          ;# number of mobilenodes
set val(filters)   GradientFilter             ;# filters  
set val(adhocRouting)   Directed_Diffusion         ;# routing protocol
set val(x)      400                      ;# X dimension of topography
set val(y)      400                      ;# Y dimension of topography
set val(stop)   80                         ;# time of simulation end
set val(en) EnergyModel        ;
set val(initialenergy)  10.0               ;  

Phy/WirelessPhy set L_ 1.0                 ;#System Loss Factor
Phy/WirelessPhy set freq_ 2.472e9          ;#channel
Phy/WirelessPhy set bandwidth_ 11Mb        ;#Data Rate
Phy/WirelessPhy set Pt_ 1.8        ;#Transmit Power
Phy/WirelessPhy set CPThresh_ 100.0         ;#Collision Threshold
Phy/WirelessPhy set CSThresh_ 5.011872e-12 ;#Carrier Sense Power
Phy/WirelessPhy set RXThresh_ 5.82587e-09  ;#Receive Power Threshold
Mac/802_11 set dataRate_ 11Mb              ;#Rate for ta Frames
Mac/802_11 set basicRate_ 1Mb              ;#Rate for Control Frames


LL set mindelay_ 50us
LL set delay_ 25us
LL set bandwidth_ 0 ;# not used

Queue/DropTail/PriQueue set Prefer_Routing_Protocols    1
# unity gain, omni-directional antennas
# set up the antennas to be centered in the node and 1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
Antenna/OmniAntenna set Z_ 1.5
Antenna/OmniAntenna set Gt_ 1.0
Antenna/OmniAntenna set Gr_ 1.0
#set the default ports
#Agent/UDP set sport_ 0
#Agent/UDP set dport_ 1
#Agent/Null set sport_ 2
#Agent/Null set dport_ 3
#Application/DiffApp/RmstSource set sport_ 4
#Application/DiffApp/RmstSink set dport_ 5
#===================================
#        Initialization        
#===================================
#Create a ns simulator
set ns_ [new Simulator]
$ns_ use-newtrace

#$ns_ puts "simulation starts"

# Create the God

set god_ [create-god $val(nn)]

#Setup topography object

set topo       [new Topography]
$topo load_flatgrid $val(x) $val(y)


#Open the NS trace file

set tracefile [open out.tr w]
$ns_ trace-all $tracefile

#Open the NAM trace file
set namfile [open rmst.nam w]
$ns_ namtrace-all $namfile
$ns_ namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)]; #Create wireless channel

#===================================
#     Mobile node parameter setup
#===================================
#Setting the sensing nodes
#set val(adhocrouting)     AODV
$ns_ node-config -adhocRouting $val(adhocRouting) \
                 -MPLS ON \
                 -llType $val(ll) \
                 -macType $val(mac) \
                 -ifqType $val(ifq) \
                 -ifqLen $val(ifqlen) \
                 -antType $val(ant) \
                 -propType $val(prop) \
                 -phyType $val(netif) \
                 -channel  $chan \
                 -topoInstance $topo \
                 -diffusionFilter $val(filters) \
                 -agentTrace ON \
                 -routerTrace OFF \
                 -macTrace ON \
                 -idlePower 1.0 \
                 -rxPower 1.0 \
                 -txPower 1.0 \
          -sleepPower 0.001 \
          -transitionPower 0.2 \
          -transitionTime 0.005 \
                 -initialEnergy $val(initialenergy) \
                 -energyModel $val(en) \


#creating the desired number of nodes
for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns_ node $i]
        $node_($i) color black
        $node_($i) random-motion 0 ;# disable random motion
        $god_ new_node $node_($i)
               
}

#set the initial positions of the nodes
$node_(0) set X_ 31.454512011851
$node_(0) set Y_ 10.109707387821
$node_(0) set Z_ 0.000000000000
$node_(1) set X_ 135.041034335395
$node_(1) set Y_ 405.737513651467
$node_(1) set Z_ 0.000000000000
$node_(2) set X_ 188.743485780117
$node_(2) set Y_ 55.526538996380
$node_(2) set Z_ 0.000000000000
$node_(3) set X_ 196.784683952856
$node_(3) set Y_ 84.409070913002
$node_(3) set Z_ 0.000000000000
$node_(4) set X_ 130.960117964937
$node_(4) set Y_ 144.467582355546
$node_(4) set Z_ 0.000000000000
$node_(5) set X_ 101.263135569806
$node_(5) set Y_ 17.451727909492
$node_(5) set Z_ 0.000000000000
$node_(6) set X_ 44.470459863044
$node_(6) set Y_ 184.344972563850
$node_(6) set Z_ 0.000000000000
$node_(7) set X_ 456.787528356492
$node_(7) set Y_ 23.395449357632
$node_(7) set Z_ 0.000000000000
$node_(8) set X_ 150.887841448344
$node_(8) set Y_ 285.005548452296
$node_(8) set Z_ 0.000000000000
$node_(9) set X_ 454.820029810669
$node_(9) set Y_ 16.247174558093
$node_(9) set Z_ 0.000000000000
$node_(10) set X_ 38.147386846751
$node_(10) set Y_ 314.880165037484
$node_(10) set Z_ 0.000000000000
$node_(11) set X_ 353.290764145665
$node_(11) set Y_ 304.586930864975
$node_(11) set Z_ 0.000000000000
$node_(12) set X_ 376.563479617518
$node_(12) set Y_ 436.784908373668
$node_(12) set Z_ 0.000000000000
$node_(13) set X_ 169.123011449721
$node_(13) set Y_ 426.037760711241
$node_(13) set Z_ 0.000000000000
$node_(14) set X_ 104.142933190272
$node_(14) set Y_ 443.761913991179
$node_(14) set Z_ 0.000000000000
$node_(15) set X_ 370.331934892815
$node_(15) set Y_ 187.819583473372
$node_(15) set Z_ 0.000000000000
$node_(16) set X_ 34.298816727045
$node_(16) set Y_ 61.539912549849
$node_(16) set Z_ 0.000000000000
$node_(17) set X_ 104.367920828175
$node_(17) set Y_ 276.111349796681
$node_(17) set Z_ 0.000000000000
$node_(18) set X_ 266.513537483945
$node_(18) set Y_ 247.013554996536
$node_(18) set Z_ 0.000000000000
$node_(19) set X_ 189.999330444229
$node_(19) set Y_ 248.468574993653
$node_(19) set Z_ 0.000000000000
#$ns_ at 2 $node_(0) setdest 275.0 275.0 15
for {set i 0} {$i < $val(nn)} {incr i} {
$ns_ initial_node_pos $node_($i) 25
}
#$ns_ initial_node_pos $node_(1) 25
#$ns_ initial_node_pos $node_(2) 25

#set the diffusion agents
for {set i 0} {$i < $val(nn)} {incr i} {
set d_($i) [new Agent/Diffusion]
$node_($i) attach $d_($i) $i
}

#connect the agents
#$ns_ connect $d_(1) $d_(0)
#$ns_ connect $d_(2) $d_(0)

#define the rmstfilers
for {set i 0} {$i < $val(nn)} {incr i} {
set rmst_filter_($i) [new Application/DiffApp/RmstFilter]
$ns_ attach-diffapp $node_($i) $rmst_filter_($i)
}
#define the rmst source application and attach it to the diffusion
agents

for {set i 1} {$i < $val(nn)} {incr i} {
set src_($i) [new Application/DiffApp/RmstSource]
$ns_ attach-diffapp $node_($i) $src_($i)
}
#set src_(2) [new Application/DiffApp/RmstSource]
#$ns_ attach-diffapp $node_(2) $src_(2)


#Define the rmst sink

set snk [new Application/DiffApp/RmstSink]
$ns_ attach-diffapp $node_(0) $snk

#start the schedule
#$ns_ at 0.5 "$src_(1) subscribe"
#$ns_ at 0.6 "$src_(1) start"
#$ns_ at 0.7 "$src_(2) subscribe"
#$ns_ at 0.8 "$src_(2) start"
#$ns_ at 0.2 "$snk subscribe"
#$ns_ at 0.3 "$snk start"

for {set i 1} {$i < $val(nn) } {incr i} {
$ns_ at [expr $i + 0.5] "$src_($i) subscribe"
#$ns_ at [expr $i + 0.7] "$src_() subscribe"
$ns_ at $i "$snk subscribe"
$ns_ at 0.1 "$rmst_filter_($i) start"
}
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
 
  $ns_ at $val(stop).000000001 "$node_($i) reset";
}
# define finish proc

proc finish {} {
 global ns_ tracefile namfile
                    $ns_ flush-trace
                    $ns_ halt
                    #$ns_ nam-end-wireless $val(stop)
                    close $tracefile
                    close $namfile
                    exit 0
                }

$ns_ at $val(stop).000002 "finish"
puts "Starting Simulation..."
#puts "address [$node_(0) node-addr]"
#puts "neighbors [$node_(0) neighbors]"
for {set j 0} {$j < 10} {incr j} {
for {set i 0} {$i < $val(nn)} {incr i} {
puts "port $j of node$i has agent [$node_($i) agent $j]"
#puts "port $j has agent [$node_(1) agent $j]"
#puts "port $j has agent [$node_(2) agent $j]"
}
}
$ns_ run      

Loading...