Search code examples
ubuntusimulationns2

faced this problem when runnning ns2 .tcl file Segmentation fault (core dumped)


faced this problem when try to run ns2 simulation.tcl file below this error "Segmentation fault (core dumped)"

`

`# define options 
 set val(chan) Channel/WirelessChannel                                      ;# channel type
 set val(prop) Propagation/TwoRayGround           ;# radio propagation             model 
 set val(netif) Phy/Wireless                                     ;# network interface type 
 set val(mac) Mac/802_11                                                        ;# 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(nn) 50                                              ;# number of mobile nodes 

set val(rp) MDAOMDV                                                        ;# Routing protocol 
set val(x) 800                                                    ;# X dimension of topography 
set val(y) 800                                                    ;# Y dimension of topography
set val(stop) 50                                                    ;# time of simulation end  
set val(energymodel) EnergyModel                                               ; 
set val(n_ch) chan_1 
#------------------------------------------------------------------------------ 
# ------------------------------------------------------------------------------ 
#remove-all-packet-headers 
#add- packet header IP LL Mac AODV AOMDV ATR DSDV DSR OLSR UDP TCP CBR FTP   ;# needed headers 
Mac /802_11 set CWMin_31 
Mac /802_11 set CWMax_1023 
Mac /802_set Slot Time _0.000020                                                  ;# 20us 
Mac /802_11 set SIFS_0.000010                                                        ;# 10us 
Mac /802_11 set preamble Length_144                                                 ;# 144 bit 
Mac /802_11 set short preamble Length _                                          ;# 72 bit 
Mac /802_ set preamble data rate_1.0e6                                              ;# 1Mbps
Mac /802_11 set PLCP  Header Length_ 48                                              ;# 48 bits 
Mac /802_11 set PLCP Data Rate_1.0e6                                               ;# 1Mbps 
Mac /802_11 set Short PLCP Data Rate_2.0e6                                             ;# 2Mbps 
Mac /802_11 set RTS Threshold_3000                                                 ;# bytes 
Mac /802_11 set Short Retry Limit_7                                          ;# retransmissions 
Mac /802_11 set Long Retry Limit _4                                      ;# retransmissions 
Mac /802_11 set new chipset_ false                  ;# use new chipset , allowing a more recent packet to be correctly received in place of the first sensed packet 
Mac /802_11 set Data Rate _2Mb                                ;# 802.11 data transmission rate 
Mac/802_11 set basic Rate_1Mb                                ;# 802.11 basic transmission 
Mac /802_11 set aarf_ false 
# creating simulation: 
set ns [new Simulator]
#use colors to differentiate the traffics 
$ns color 1 Green 
# creating nam and trace file: 
set trace fd[open mdaomdv.tr w] 
set namtrace [open mdaomdv.nam w] 
$ns trace _ all $ tracefd 
$ns nam trace-all-wireless $nam trace $val (x) $ val(y) 
#set up topography object 
Set topo[new Topography] 
$topo load_ flat grid $val(x) $val(y) 
Set god_[create-god val(nn)] 
#configure the nodes 
$ns node-config-ad hoc routing $val (rp) \ 
-ll Type $val(ll) \ 
-mac Type $val(mac) \ 
-ifq Type $ val (ifq)  \ 
-ifq Len $val (ifqlen) \ 
-ant Type $ val(ant) \ 
-prop Type $ (prop) \ 
-phy Type $val(net if) \ 
-channel Type $ val (chann) \ 
-topo Instance $topo \ 
-agent Trace ON \ 
-router Trace ON \ 
-mac Trace OFF \ 
-movement Trace ON 
-channel $chan_1 \ 
-energy Model $ val (energy model) \ 
#-rx power 0.3 \ 
#-tx power 0.6 \ 
#-initial Energy 90 
## creating node object  
For {set i 0} {$i < 20} { incr i } { 
Set node _ ($i) [$ns node] 
} for {set i 0} {$i < 20} {incr i } { 
$node _($i) color blue 
$ns at 0.0 "$node_($i) color blue"
} 
for {set i 20} {$i < 30 } { incr i } { 
set node _($) [$ns node] 
} 
for {set i 20} {$i < 30 } {incr i } { 
$node_($i) color cyan 
$ns at 1.0 "$node_($i) color cyan"
} 
for {set i 30} {$i < 50 } { incr i } { 
set node_($i) [$ns node] 
} 
for {set i 20} {$i < 50 } {incr i } { 
$node_($i) color red 
$ns at 2.0 "$node_($i) color red"
} 
##provide initial location of mobile nodes. 
for {set i 0} {$i < $val(nn) } { incr i } { 
set xx [expr rand()*800] 
set yy [expr rand()* 800] 
$node_($i) set X_ $xx 
$node_($i) set Y_ $yy 
} 
# Define node initial position in nam 
for {set i 0} {$i < $val(nn)} { incr i } { 
# defines the node size for nam  
$ns initial_ node_ pos $node_($i) 30  
}
Proc stop {} { 
Global ns tracefd nam trace 
$ns flush-trace 
Close $tracefd 
Close $nam trace 
Exec nam mdaomdv.nam &
} 
$ns run `

I tried to find the broken packages and delete them forcefully using this command "sudo dpkg -l | grep ^..r | apt-get purge" and again the following error happened

[sudo] password for derara: E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?


Solution

  • Segmentation fault is not caused by any "broken Ubuntu packages", but by plenty of typos etc. errors in your "mdaomdv.tcl" file.
    Section "ns node-config": Space after \ is forbidden.
    The tcl/otcl code: For is spelled 'for', Set is 'set', Proc is 'proc', Global is 'global', Close is 'close', Exec is 'exec'.
    For correct spelling, please read e.g. EnergyModel-examples-7.tar.gz https://drive.google.com/file/d/1g8WnlHHHnNXBLc0rwJY4i1z9uieKtl9s/view?usp=sharing

    Ref. https://drive.google.com/drive/folders/0B7S255p3kFXNSmRYb2lGcDRUdWs?resourcekey=0-vrEMHtGTFP3yLoTQz_UAwA&usp=share_link

    Besides that, traffic is missing in the file. I added a line source cbr-50-20-4-512ns to include a necessary example of traffic/communication → Your edited file, example "111_aomdv.tcl" + the traffic file : The AOMDV protocol is used, instead of your unknown MDAOMDV. The two files were uploaded to → →
    https://drive.google.com/drive/folders/14vdJfoIqqKj34clkdxuN0IclHc0o0Oml?usp=share_link


    111_aomdv.tcl

     # define options 
     set val(chan) Channel/WirelessChannel                                      ;# channel type
     set val(prop) Propagation/TwoRayGround           ;# radio propagation             model 
     set val(netif) Phy/WirelessPhy          ;# !!!EDITED !!!  ;# network interface type 
     set val(mac) Mac/802_11                                                        ;# 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(nn)    50                                              ;# number of mobile nodes 
    
    set val(rp)     AOMDV           ;# MDAOMDV   ;# Routing protocol 
    set val(x) 800                                                    ;# X dimension of topography 
    set val(y) 800                                                    ;# Y dimension of topography
    set val(stop) 500                                                   ;# time of simulation end  
    set val(energymodel) EnergyModel                                               ; 
    set val(n_ch) chan_1
    set val(initialenergy)  90   ;# edited/added ##########  ;# Initial energy in Joules
    #----------------------------------------- 
    # ---------------------------------------- 
    #remove-all-packet-headers 
    #add- packet header IP LL Mac AODV AOMDV ATR DSDV DSR OLSR UDP TCP CBR FTP   ;# needed headers 
    Mac /802_11 set CWMin_31 
    Mac /802_11 set CWMax_1023 
    Mac /802_set Slot Time _0.000020                                                  ;# 20us 
    Mac /802_11 set SIFS_0.000010                                                        ;# 10us 
    Mac /802_11 set preamble Length_144                                                 ;# 144 bit 
    Mac /802_11 set short preamble Length _                                          ;# 72 bit 
    Mac /802_ set preamble data rate_1.0e6                                              ;# 1Mbps
    Mac /802_11 set PLCP  Header Length_ 48                                              ;# 48 bits 
    Mac /802_11 set PLCP Data Rate_1.0e6                                               ;# 1Mbps 
    Mac /802_11 set Short PLCP Data Rate_2.0e6                                             ;# 2Mbps 
    Mac /802_11 set RTS Threshold_3000                                                 ;# bytes 
    Mac /802_11 set Short Retry Limit_7                                          ;# retransmissions 
    Mac /802_11 set Long Retry Limit _4                                      ;# retransmissions 
    Mac /802_11 set new chipset_ false                  ;# use new chipset , allowing a more recent packet to be correctly received in place of the first sensed packet
    
    Mac /802_11 set Data Rate _2Mb                                ;# 802.11 data transmission rate 
    Mac/802_11 set basic Rate_1Mb                                ;# 802.11 basic transmission 
    Mac /802_11 set aarf_ false
    
     
    # creating simulation: 
    set ns [new Simulator]
    # use colors to differentiate the traffics 
    $ns color 1 green 
    # creating nam and trace file: 
    set tracefd [open mdaomdv.tr w]     ;# edited 
    set namtrace [open mdaomdv.nam w] 
    $ns trace-all $tracefd       ;# edited
    $ns namtrace-all-wireless $namtrace $val(x) $val(y)     ;# edited
    
     
    #set up topography object           
    set topo    [new Topography]    ;# edited       
    $topo load_flatgrid $val(x) $val(y) ;# edited
    
    set god_    [create-god val(nn)]
     
    #configure the nodes        #### section is edited #################
    ## all lines in this section are edited, +added: -initialEnergy $val(initialenergy) #####
    $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) \
    -channelType $val(chan) \
    -topoInstance $topo \
    -agentTrace ON \
    -routerTrace ON \
    -macTrace OFF \
    -movementTrace ON \
    -n_chType  $val(n_ch) \
    -energyModel $val(energymodel) \
    #-rx power 0.3 \
    #-tx power 0.6 \
    -initialEnergy $val(initialenergy)
    
    
    ## creating node object  ### edited section ################
    for {set i 0} {$i < $val(nn) } {incr i} {
            set node_($i) [$ns node]    
    #       $node_($i) random-motion 0
            }
    
    for {set i 0} {$i < 20} {incr i} {      ;# edited
    $node_($i) color blue
    $ns at 0.0 "$node_($i) color blue"
    } 
    for {set i 20} {$i < 30} {incr i} { 
    set node_($) [$ns node]             
    } 
    for {set i 20} {$i < 30} {incr i} { 
    $node_($i) color cyan
    $ns at 1.0 "$node_($i) color cyan"
    } 
    for {set i 30} {$i < 50} {incr i} { 
    set node_($i) [$ns node] 
    }
    for {set i 20} {$i < 50} {incr i} {
    $node_($i) color red
    $ns at 2.0 "$node_($i) color red"
    }
    
    source cbr-50-20-4-512ns
     
    # provide initial location of mobile nodes 
    for {set i 0} {$i < $val(nn) } { incr i } { 
    set xx [expr rand()*800] 
    set yy [expr rand()* 800] 
    $node_($i) set X_ $xx 
    $node_($i) set Y_ $yy 
    }
     
    # Define node initial position in nam    ;# this section is edited #####
    for {set i 0} {$i < $val(nn)} {incr i} { 
    # defines the node size for nam  
    $ns initial_node_pos $node_($i) 30  
    }
    
    proc stop {} { 
    global ns tracefd nam trace 
    $ns flush-trace 
    close $tracefd 
    close $nam trace 
    }
    
    # Tell all the nodes when the simulation ends ###############
    for {set i 0} {$i < $val(nn) } {incr i} {
        $ns at $val(stop).000000001 "$node_($i) reset";
    }
    $ns at $val(stop).00000001 "puts \"NS EXITING...\" ; $ns halt"
    
    $ns run
    
    exec nam mdaomdv.nam &