$ns_ use-scheduler Heapafter you instanced a new simulater
set ns_ [new Simulator]Heap scheduler does not change your simulation but consumes a shorter simulating time.
# Initialize the SharedMedia interface with parameters to make
# it work like the 914MHz Lucent WaveLAN DSSS radio interface
set RxT_ 3.652e-10 ;#Receiving Threshold which mostly is a hardware feature
set Frequency_ 914e+6 ;# Signal Frequency which is also hardware feature
Phy/WirelessPhy set CPThresh_ 10.0
Phy/WirelessPhy set CSThresh_ 1.559e-11
Phy/WirelessPhy set RXThresh_ $RxT_ ;# Receiving Threshold
Phy/WirelessPhy set Rb_ 2*1e6 ;# Bandwidth
Phy/WirelessPhy set freq_ $Frequency_
Phy/WirelessPhy set L_ 1.0
set opt(Pt) 61.0 ;# Transmission Power/Range in meters
if { $opt(prop) == "Propagation/TwoRayGround" } {
set SL_ 300000000.0 ;# Speed of Light
set lambda [expr $SL_/$Frequency_] ;# wavelength
set lambda_2 [expr $lambda*$lambda] ;# lambda^2
set CoD_ [expr 4.0*$PI*$opt(AnH)*$opt(AnH)/$lambda] ;# Cross Over Distance
if { $opt(Pt) <= $CoD_ } {;#Free Space for short distance communication
set temp [expr 4.0*$PI*$opt(Pt)]
set TP_ [expr $RxT_*$temp*$temp/$lambda_2]
Phy/WirelessPhy set Pt_ $TP_ ;#Set the Transmissiont Power w.r.t Distance
} else { ;# TwoRayGround for communicating with far nodes
set d4 [expr $opt(Pt)*$opt(Pt)*$opt(Pt)*$opt(Pt)]
set hr2ht2 [expr $opt(AnH)*$opt(AnH)*$opt(AnH)*$opt(AnH)]
set TP_ [expr $d4*$RxT_/$hr2ht2]
Phy/WirelessPhy set Pt_ $TP_ ;#Set the Transmissiont Power w.r.t Distance
}
}
|
Usually, for one protocol
implementation, we need several timers. According to NS2's
implementation, for each timer calling different firing function, one
more class need to be declared and defined, which is boring and
bothering.
In fact, we can use the pointer to function to same time and coding (How to do in with C++ template, I am not sure.). As below:
|
remove-all-packet-headers add-packet-header DSR ARP LL MAC CBR IPto simulation a CBR application on UDP with DSR as routing protocol in a wireless ad hoc network (OOPS!, UDP is not a header. This method is effective, but it requires you to understand most packets header you need.
foreach prot {
# Common:
Common
Flags
IP
# Transport Protocols
TCP
# Wireless
ARP
LL
Mac
# Mobility
AODV
} {
add-packet-header $prot
}
If you are creating your own packet header, put them here.
ACTION: [s|r|D]: s -- sent, r -- received, D -- dropped WHEN: the time when the action happened WHERE: the node where the action happened LAYER: AGT -- application, RTR -- routing, LL -- link layer (ARP is done here) IFQ -- outgoing packet queue (between link and mac layer) MAC -- mac, PHY -- physical flags: SEQNO: the sequence number of the packet TYPE: the packet type cbr -- CBR data stream packet DSR -- DSR routing packet (control packet generated by routing) RTS -- RTS packet generated by MAC 802.11 ARP -- link layer ARP packet SIZE: the size of packet at current layer, when packet goes down, size increases, goes up size decreases [a b c d]: a -- the packet duration in mac layer header b -- the mac address of destination c -- the mac address of source d -- the mac type of the packet body flags: [......]: [ source node ip : port_number destination node ip (-1 means broadcast) : port_number ip header ttl ip of next hop (0 means node 0 or broadcast) ]
s 76.000000000 _98_ AGT --- 1812 cbr 32 [0 0 0 0] ------- [98:0 0:0 32 0]as Application 0 (port number) on node 98 sent a CBR packet whose ID is 1812 and size is 32 bytes, at time 76.0 second, to application 0 on node 0 with TTL is 32 hops. The next hop is not decided yet.
r 0.010176954 _9_ RTR --- 1 gpsr 29 [0 ffffffff 8 800] ------- [8:255 -1:255 32 0]in the same way, as The routing agent on node 9 received a GPSR broadcast (mac address 0xff, and ip address is -1, either of them means broadcast) routing packet whose ID is 1 and size is 19 bytes, at time 0.010176954 second, from node 8 (both mac and ip addresses are 8), port 255 (routing agent).