Migrating NS2 simulations to Omnet

44 views
Skip to first unread message

Mac Sar

unread,
Sep 19, 2014, 4:34:42 AM9/19/14
to omn...@googlegroups.com
Hello everyone,

I have been learning Omnet from the documentation website (e.g. TicTac example). However it seems the simulation concept and methods are quite different from NS2.

Would someone please kindly give me some clue on how should I migrate my simulations (such as the below one) to Omnet? In NS2 we would create the topology and then protocols (like UDP or TCP...) and then applications that would utilize the links. How should I do the same here.

I appreciate your help.

Regards
Mac

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)        100                             ;# max packet in ifq
set val(nn)            2                            ;# number of mobilenodes
set val(rp)            AODV                            ;# protocol tye
set val(x)             40                            ;# X dimension of topography
set val(y)             40                            ;# Y dimension of topography
set val(stop)          500                            ;# simulation period
set val(energymodel)   EnergyModel                    ;# Energy Model
set val(initialenergy) 100                            ;# value

set ns                [new Simulator]
set tracefd           [open cbr-154.tr w]
set namtrace          [open cbr-154.nam w]

$ns use-newtrace
$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)

set dist(35m) 1.56962e-07
set dist(40m) 1.20174e-07
Phy/WirelessPhy set CSThresh_ $dist(40m)
Phy/WirelessPhy set RXThresh_ $dist(40m)


# set up topography object
set topo       [new Topography]
$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

# 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 [new $val(chan)] \
             -topoInstance $topo \
             -agentTrace ON \
             -routerTrace OFF \
             -macTrace  OFF \
             -movementTrace OFF \
             -energyModel $val(energymodel) \
             -initialEnergy $val(initialenergy) \
             -rxPower 35.28e-3 \
             -txPower 31.32e-3 \
         -idlePower 712e-6 \
         -sleepPower 144e-9
                          
             #-IncomingErrProc MultistateErrorProc \
             #-OutgoingErrProc MultistateErrorProc
            
for {set i 0} {$i < $val(nn) } { incr i } {
        set mnode_($i) [$ns node]
}



for {set i 1} {$i < $val(nn) } { incr i } {
    $mnode_($i) set X_ [ expr {$val(x) * rand()} ]
    $mnode_($i) set Y_ [ expr {$val(y) * rand()} ]
    $mnode_($i) set Z_ 0
}

# Position of Sink
$mnode_(0) set X_ [ expr {$val(x)/2} ]
$mnode_(0) set Y_ [ expr {$val(y)/2} ]
$mnode_(0) set Z_ 0.0
$mnode_(0) label "Sink"


for {set i 0} {$i < $val(nn)} { incr i } {
    $ns initial_node_pos $mnode_($i) 10
}


#Setup a UDP connection
set udp [new Agent/UDP]
$ns attach-agent $mnode_(1) $udp

set sink [new Agent/Null]
$ns attach-agent $mnode_(0) $sink

$ns connect $udp $sink
$udp set fid_ 2

#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.1Mb
$cbr set interval_ 2
#$cbr set random_ false

$ns at 5.0 "$cbr start"
$ns at [expr $val(stop) - 5] "$cbr stop"

# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } {
    $ns at $val(stop) "$mnode_($i) reset;"
}

# ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at [expr $val(stop) + 0.01] "puts \"end simulation\"; $ns halt"
proc stop {} {
    global ns tracefd namtrace
    $ns flush-trace
    close $tracefd
    close $namtrace
}

$ns run



Reply all
Reply to author
Forward
0 new messages