Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-28-2017, 09:15 AM   #1
LQ Newbie
Registered: Oct 2017
Posts: 1

Rep: Reputation: Disabled
Segmentation fault (core dumped)- SMAC on NS2

Hello all,

I am new to linux (ubuntu 14.04) and NS2 (Ns 2.35). I am trying to run SMAC code for wireless sensor networks in NS2. When the number of nodes are less than 20, the code runs successfully. But when the nodes are more than 20 , the code gives a "Segmentation fault(core dumped) error"

The code:
set opt(chan)		Channel/WirelessChannel
set opt(prop)		Propagation/TwoRayGround
set opt(netif)		Phy/WirelessPhy/802_15_4
#set opt(mac)            Mac/802_11                   ;# MAC type
set opt(mac)            Mac/SMAC                   ;# MAC type
set opt(ifq)		Queue/DropTail/PriQueue
set opt(ll)		LL
set opt(ant)            Antenna/OmniAntenna

set opt(x)		800	;# X dimension of the topography
set opt(y)		800		;# Y dimension of the topography
set opt(cp)		"../mobility/scene/cbr-50-10-4-512"
set opt(sc)		"../mobility/scene/scen-670x670-50-600-20-0"

set opt(ifqlen)		50		;# max packet in ifq
set opt(nn)		70		;# number of nodes
set opt(seed)		0.0
set opt(stop)		100.0		;# simulation time
set opt(tr)	;# trace file
set opt(nam)		MyTest.nam	;# animation file
set opt(rp)             DumbAgent       ;# routing protocol script
#set opt(lm)             "off"           ;# log movement
set opt(agent)          DumbAgent
set opt(energymodel)    EnergyModel     ;
#set opt(energymodel)    RadioModel     ;
set opt(radiomodel)    	RadioModel     ;
set opt(initialenergy)  1000            ;# Initial energy in Joules
#set opt(logenergy)      "on"           ;# log energy every 150 seconds

Mac/SMAC set syncFlag_ 1

Mac/SMAC set dutyCycle_ 10

Mac/SMAC set selfConfigFlag_ 1

set ns_		[new Simulator]
$ns_ use-newtrace
set topo	[new Topography]
set tracefd	[open $opt(tr) w]
set namtrace    [open $opt(nam) w]
set prop	[new $opt(prop)]

$topo load_flatgrid $opt(x) $opt(y)
#ns-random 1.0
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)

# Create god
create-god $opt(nn)

#global node setting

        $ns_ node-config -adhocRouting DumbAgent \
			 -llType $opt(ll) \
			 -macType $opt(mac) \
			 -ifqType $opt(ifq) \
			 -ifqLen $opt(ifqlen) \
			 -antType $opt(ant) \
			 -propType $opt(prop) \
			 -phyType $opt(netif) \
			 -channelType $opt(chan) \
			 -topoInstance $topo \
			 -agentTrace ON \
			 -routerTrace ON \
			 -macTrace ON \
			 -energyModel $opt(energymodel) \
			 -idlePower 1.0 \
			 -rxPower 1.0 \
			 -txPower 1.0 \
          		 -sleepPower 0.001 \
          		 -transitionPower 0.2 \
          		 -transitionTime 0.005 \
			 -initialEnergy $opt(initialenergy)

	$ns_ set WirelessNewTrace_ ON
#set AgentTrace			ON
#set RouterTrace		OFF
#set MacTrace			ON

#we generate the nodes
	for {set i 0} {$i < $opt(nn) } {incr i} {
		set node_($i) [$ns_ node]	

# deploy the nodes randomly in the topology area
for {set i 1} {$i < $opt(nn) } { incr i } {

    $node_($i) set X_ [ expr {$opt(x) * rand()} ]
    $node_($i) set Y_ [ expr {$opt(y) * rand()} ]
    $node_($i) set Z_ 0

#we deploy the sink node at the centre of the area

$node_(0) set X_ [ expr {$opt(x)/2} ]
$node_(0) set Y_ [ expr {$opt(y)/2} ]
$node_(0) set Z_ 0.0
$node_(0) label "Sink"

#how big nodes will be shown in NAM. it has to be here for the nodes to be visible
for {set i 0} {$i < $opt(nn)} { incr i } {

    $ns_ initial_node_pos $node_($i) 10

#	$node_(1) set agentTrace ON	 
#	$node_(1) set macTrace ON
#	$node_(1) set routerTrace ON		 	
#	$node_(0) set macTrace ON
#	$node_(0) set agentTrace ON	 
#	$node_(0) set routerTrace ON

# we have to establish connection. we setup udp connection

# First we  set up null agent for sink ie destination node.
set sink [new Agent/Null]
$ns_ attach-agent $node_(0) $sink

# then udp for all other nodes (ie sources nodes)

for {set i 1} {$i < $opt(nn) } {incr i} {
set udp_($i) [new Agent/UDP]
$ns_ attach-agent $node_($i) $udp_($i)

# connect udp agent to sink
for {set i 1} {$i < $opt(nn) } {incr i} {
$ns_ connect $udp_($i) $sink 

#Setup a CBR over UDP connection

#old code : to delete
#set udp_(0) [new Agent/UDP]
#$ns_ attach-agent $node_(0) $udp_(0)
#set null_(0) [new Agent/Null]
#$ns_ attach-agent $node_(1) $null_(0)
for {set i 1} {$i < $opt(nn) } {incr i} {
set cbr_($i) [new Application/Traffic/CBR]
$cbr_($i) attach-agent $udp_($i)
$cbr_($i) set packetSize_ 512
$cbr_($i) set interval_ 10.0
$cbr_($i) set random_ 1
$cbr_($i) set maxpkts_ 50000
$cbr_($i) set rate_ 0.1Mb

$ns_ at 1.00 "$cbr_($i) start"
#$ns_ at 177.000		"$node_(0) set ifqLen"
 $ns_ at $opt(stop) "$cbr_($i) stop";
# Tell all the nodes when the simulation ends
for {set i 0} {$i < $opt(nn) } {incr i} {
    $ns_ at $opt(stop) "$node_($i) reset";
$ns_ at $opt(stop) "puts "NS EXITING..." ; $ns_ halt"

proc stop {} {
    global ns tracefd namtrace
    $ns flush-trace
    close $tracefd
    close $namtrace

set b [$node_(0) set mac_(0)]
#set c [$b set freq_]
set d [Mac/SMAC set syncFlag_]

#set e [$node_(0) set netif_(0)]
#set c [$e set L_]
set c [Mac/SMAC set dutyCycle_]
#puts $tracefd "M 0.0 nn $opt(nn) x $opt(x) y $opt(y) rp $opt(rp)"
#puts $tracefd "M 0.0 sc $opt(sc) cp $opt(cp) seed $opt(seed)"
#puts $tracefd "M 0.0 prop $opt(prop) ant $opt(ant)"
#puts $tracefd "V $b : $c : $d :"
puts "Starting Simulation..."
$ns_ run
The error:

emma@emma-ThinkPad-X220:~/Downloads$ ns MyTest.tcl
num_nodes is set 70
warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
Starting Simulation...

NOTE: SMAC is running with sleep-wakeup cycles on. Please make sure to run yr applications AFTER the nodes get sync'ed which is about 40sec for the default settings.

Segmentation fault (core dumped)
Please help me solve this error

Last edited by Emma112; 11-06-2017 at 09:24 AM.
Old 10-29-2017, 10:23 AM   #2
LQ 5k Club
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2021 CentOS7.9 + 50+ other Linux OS, for test only.
Posts: 17,473

Rep: Reputation: 3631Reputation: 3631Reputation: 3631Reputation: 3631Reputation: 3631Reputation: 3631Reputation: 3631Reputation: 3631Reputation: 3631Reputation: 3631Reputation: 3631
Welcome to LQ.

Code must be shown in "code TAGS", not "Quote".
CODE Tags : [code]code text[/code]
Please edit post #1, and replace the "code text" with the real code.
Editing : That's the 'Edit' button in post #1.

'Segmentation fault' can be ignored when it happens after the trace files are written.

My test with your file, MyTest.tcl (Please use unique file names, MyTest.tcl is a generic name)
$ ns235-64 MyTest-50n.tcl : The files MyTest.nam 14.3MB, 24.3MB are created.
$ nam MyTest.nam : A perfect animation, lots of communication.


Last edited by knudfl; 10-29-2017 at 10:30 AM.


ns2, smac

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
segmentation fault (core dumped ) error in ns2.34 sims2801 Linux - Newbie 3 05-29-2015 07:17 AM
Segmentation fault (core dumped) mezyana Linux - Newbie 1 05-18-2014 03:52 PM
Segmentation fault (core dumped) Khaled ELmishad Programming 1 06-16-2012 11:13 AM
Segmentation Fault (core dumped) newuser455 Linux - Software 3 08-28-2004 02:39 PM
Segmentation fault (core dumped) plisken Linux - General 8 09-17-2003 03:32 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:43 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration