2

this is an anomaly detection simulation ns-2.35 I ran in Ubuntu ver16.04

*set val(chan)          Channel/WirelessChannel      ;# channel type
# here we detect the channel Wireless channel or Satelite channel
set val(prop)          Propagation/TwoRayGround     ;# radio-propagation model
set val(netif)         Phy/WirelessPhy/802_15_4     ;# network interface type
# here phy means physical and we set the kind of physical layer
set val(mac)           Mac/802_15_4                 ;# MAC type
# here we choose the mac type : simple, 802_11...,...
set val(ifq)           Queue/DropTail/PriQueue      ;# interface queue type
# queue type is droptail with priority : routing packets have higher priority then data packets
set val(ll)            LL                           ;# link layer type
set val(ant)           Antenna/OmniAntenna          ;# antenna model
# Omniantenna is antenna without any directions
set val(ifqlen)        100                  ;# max packet in ifq
set val(nn)            220              ;# number of mobilenodes
# setting a val array with index -> set val(nn) means an array named nn with 220 value
set val(anchor)        20               ;# number of anchornodes
set val(anchor_start)  200              ;# start index of anchornodes
set val(mal_start)      215
set val(mal)           5                ;# number of maliciousnodes
set val(rp)            APIT             ;# protocol type
# It's routing protocol type -> DumpAgent(Do nothing), APIT(Localization Algorithm)
set val(x)             100              ;# X dimension of topographychan
set val(y)             80               ;# Y dimension of topography
# x and y are dimensions of the whole space that nodes are in 
set val(stop)          5                ;# simulation period
set val(energymodel)   EnergyModel          ;# Energy Model
set val(initialenergy) 100              ;# value

set ns [new Simulator] ;# creating simulator
set tracefd [open trace-apit-sybi-detect.tr w]
set namtrace [open nam-apit-sybil-detect.nam w]

set node_ [$ns node]

$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y) 
# in order to show all things happen in wireless we use this
# anything happens in the channel or nodes will be added in trace file

set dist(5m)  7.69113e-06
set dist(9m)  2.37381e-06
set dist(10m) 1.92278e-06
set dist(11m) 1.58908e-06
set dist(12m) 1.33527e-06
set dist(13m) 1.13774e-06
set dist(14m) 9.81011e-07
set dist(15m) 8.54570e-07
set dist(16m) 7.51087e-07
set dist(20m) 4.80696e-07
set dist(25m) 3.07645e-07
set dist(30m) 2.13643e-07
set dist(35m) 1.56962e-07
set dist(40m) 1.20174e-07
Phy/WirelessPhy set CSThresh_ $dist(40m)
Phy/WirelessPhy set RXThresh_ $dist(40m)
# Configure initial position 
#these are needed by nam 


set topo       [new Topography] 
$topo load_flatgrid $val(x) $val(y)
# set up topography object
# creating an object from topology class
# in this command dimensions of x and y is created and will be grid in order to show the exact location of each node


create-god $val(nn)
#All things happen in nodes in simulation are managed by GOD class so we created an object from GOD class

set chan_ [new $val(chan)]
#create channel

# 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 $chan \
             -topoInstance $topo \
             -agentTrace ON \
             -routerTrace ON \
             -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


#Initialize Global Variables
proc myRand {} {
    global rand_id
    set range 8
    set rand_id [expr {0 + int(rand() * $range)}]
    return $rand_id
}

proc myRand_sybil {} {
    global rand_id
    set range 50
    set rand_id [expr {0 + int(rand() * $range)}]
    return $rand_id
}
Node/MobileNode instproc setPt { val } {
    $self instvar netif_
    $netif_(0) setTxPower $val
}


#nodes creation
for {set i 0} {$i < $val(nn) } { incr i } {
        set node_($i) [$ns node]
}


# Position ,Color ,Label of Anchors
for {set i 0} {$i < $val(anchor_start)} { incr i } {
    $node_($i) set X_ [expr {0 + int(rand() * $val(x))}]
    $node_($i) set Y_ [expr {0 + int(rand() * $val(y))}]

}
for {set i $val(anchor_start)} {$i < $val(mal_start)} { incr i } {
    $node_($i) set X_ [expr {0 + int(rand() * $val(x))}]
    $node_($i) set Y_ [expr {0 + int(rand() * $val(y))}]
    $node_($i) label "Anchor"

}
for {set i $val(mal_start)} {$i < $val(nn)} { incr i } {
    $node_($i) set X_ [expr {0 + int(rand() * $val(x))}]
    $node_($i) set Y_ [expr {0 + int(rand() * $val(y))}]
    $node_($i) label "Malicious"
}


for {set i 0} {$i < $val(nn)} { incr i } {
        $ns initial_node_pos $node_($i) 5
        $node_($i) setPt 31.32e-3
}



#here we created the nodes and the location of nodes is random
#we can also use the $node_($i) random_motion command for random location of nodes. 
#if we set $node_($i) random_motion 0 the location of nodes will be fixed


#start sending beacon message and anchor hello message
for {set i $val(anchor_start)} {$i < $val(mal_start) } { incr i } {
        $ns at 0.0 "[$node_($i) set ragent_] anchor "
        $node_($i) color "blue"
        $ns at 0.0 "$node_($i) color blue"
        $node_($i) setPt 125.28e-3
}

set ma_sybil [myRand_sybil]
for {set i $val(mal_start)} {$i < $val(nn) } { incr i } {
$ns at 0.0 "[$node_($i) set ragent_] malicious [ expr {$ma_sybil}]"
$node_($i) color "red"
$ns at 0.0 "$node_($i) color red"
$node_($i) setPt 125.28e-3
}

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

# Stop the simulation prosedure
# 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*

But the results after running tcl file in terminal is this:

num_nodes is set 220 can't read "chan": no such variable while executing "-llType $val(ll)
-macType $val(mac)
-ifqType $val(ifq)
-ifqLen $val(ifqlen)
-antType $val(..." (file "sybil_drd_1.tcl" line 77)

May you please tell me what should I do to fix this Error.

  • APIT: https://groups.google.com/g/ns-users/c/Y_zroEPmAjA/m/M-qBnituCQAJ → The 12 "Positioning Algorithms .." https://sourceforge.net/projects/posalgorithms/files/?source=navbar .... are "almost identical templates for "possible protocols"." ....... I edited some typos in your file, added some scene files, see https://drive.google.com/drive/folders/1y5YU4jZy0BQnzhp5JnGHa6Z9SMn0glvw?usp=sharing ......... All ns2 examples https://drive.google.com/drive/folders/0B7S255p3kFXNSmRYb2lGcDRUdWs?resourcekey=0-vrEMHtGTFP3yLoTQz_UAwA&usp=sharing – Knud Larsen Mar 08 '22 at 19:19
  • Available Sybil examples, v004 ... vanet012 : sybil-vanet-12-ex-1.tar.gz https://drive.google.com/file/d/1NFohjUHuq7tKBBvyQAW_KOnMalBT40Hx/view?usp=sharing ...... INFO https://ns2simulator.com/sybil-attack-in-ns2/ – Knud Larsen Mar 09 '22 at 09:59
  • @Knud_Larsen Thanx for all files and links you shared, but when I followed the instruction in apit 2d pdf file in this link https://sourceforge.net/projects/posalgorithms/files/?source=navbar I got a long list of errors in terminal with 'make' command , now what should I do? – Sahar Zamanian Mar 12 '22 at 11:03
  • Can I install apit by terminal commands instead of setting manually in ns2 directory? – Sahar Zamanian Mar 12 '22 at 11:10
  • APIT → Repeat: Please read https://groups.google.com/g/ns-users/c/Y_zroEPmAjA/m/M-qBnituCQAJ to know the work by @Kalimuha etc. ...... APIT is a template only. If you want usable "location-based routing protocol", DREAM and LAR are available → https://drive.google.com/drive/folders/0B7S255p3kFXNZ2lWZDBRSW40Q00?resourcekey=0-eBw6mJFKhSVGultqaD2rDA&usp=sharing → LAR-dream__ns235.patch + several combinations with attacks etc. ..... lar+dream-examples-02.22.tar.xz https://drive.google.com/file/d/1NHYY0U6sbGPogBpQ_r6TrJeTzrcayxbb/view?usp=sharing – Knud Larsen Mar 12 '22 at 12:39
  • 1
    DREAM : "Printing Location Table for nodes" https://drive.google.com/drive/folders/1uwGwuCeIvYpTuI5KBzPDCGoAs3GvguoT?usp=sharing – Knud Larsen Mar 12 '22 at 13:27
  • @KnudLarsen Sir Thanks a lot for all your helpful tips, I added apit and dvhop algorithm and most of the errors disappeared but still I got this error after running the project by "ns-apit sybil_drd_1.tcl" command on terminal: num_nodes is set 220 INITIALIZE THE LIST xListHead can't set "node_(0)": variable isn't array while executing "set node_($i) [$ns node]" ("for" body line 2) invoked from within "for {set i 0} {$i < $val(nn) } { incr i } { set node_($i) [$ns node] }" (file "sybil_drd_1.tcl" line 122) – Sahar Zamanian Apr 13 '22 at 13:52
  • 1
    Please see the folder "Array-issues/" https://drive.google.com/drive/folders/1y5YU4jZy0BQnzhp5JnGHa6Z9SMn0glvw?usp=sharing – Knud Larsen Apr 13 '22 at 14:29
  • I'm so excited! Thanx so so so much @KnudLarsen Larsen finally I could run the code. Wish you the best! – Sahar Zamanian Apr 13 '22 at 16:55

0 Answers0