Title: Cloning a New IEEE 802.11 MAC Protocol in NS2
Author: Yang Yu-Sheng
Date: 2009/04/25
This article is a hand-on for those who would like to modify ns-2 implementation
of IEEE 802.11 MAC protocol but wish to keep the original one for comparison.
All stuffs about ns-2 except the main topic described here are skipped throughly.
For formal information please check ns-2 official website:
http://www.isi.edu/nsnam/ns/index.html
For informative material please check Dr. Ko's website:
http://hpds.ee.ncku.edu.tw/~smallko/ns2/ns2.htm
The baseline ns-2 implementation chosen for our testbed is all-in-one version of
ns-2.33 from sourceforge:
http://sourceforge.net/project/showfiles.php?group_id=149743&package_id=169689&release_id=588643
Assume we want a new MAC protocol such that we can use "Mac/802_11new" in our tcl script.
What's the todos?
[step 1] check source code to be impacted, maybe you need to backup them for diff them when needed.
(modify)ns-allinone-2.33\Makefile
(modify)ns-allinone-2.33\dei80211mr-1.1.4\src\InitTCL.cc
(modify)ns-allinone-2.33\ns-2.33\indep-utils\webtrace-conv\dec\my-endian.h
(modify)ns-allinone-2.33\ns-2.33\tcl\lib\ns-mobilenode.tcl
(modify)ns-allinone-2.33\ns-2.33\tcl\lib\ns-default.tcl
(modify)ns-allinone-2.33\ns-2.33\tcl\lan\ns-mac-802_11.tcl
(modify)ns-allinone-2.33\ns-2.33\tcl\lan\ns-mac.tcl
(add)ns-allinone-2.33\ns-2.33\mac\mac-802_11new.cc
(add)ns-allinone-2.33\ns-2.33\mac\mac-802_11new.h
(add)ns-allinone-2.33\ns-2.33\mac\mac-timersnew.cc
(add)ns-allinone-2.33\ns-2.33\mac\mac-timersnew.h
[step 2] modify Makefile
add "mac-802_11new.o" next to existing "mac-802_11.o" in OBJ_CC section
add "mac-timersnew.o" next to existing "mac-timers.o" in OBJ_CC section
[step 3] modify InitTCL.c
add following portion next to existing codes, from about line 70.
---BEGIN---
Mac/802_11new/Multirate set useShortPreamble_ false\n\
Mac/802_11new/Multirate set gSyncInterval_ 0\n\
Mac/802_11new/Multirate set bSyncInterval_ 0\n\
\n\
Mac/802_11new/Multirate set CWMin_ 32\n\
Mac/802_11new/Multirate set CWMax_ 1024\n\
\n\
Mac/802_11new/Multirate set VerboseCounters_ 0\n\
\n\
\n\
---END---
[step 4] modify my-endian.h
mark off first line and last line, this is to fix the build problem.
[step 5] ns-mobilenode.tcl
add following 2 portions next to existing codes, from about line 500 and 700.
---BEGIN---
set god_ [God instance]
if {$mactype == "Mac/802_11new"} {
$mac nodes [$god_ num_nodes]
}
---END---
---BEGIN---
if {$mactype == "Mac/802_11new"} {
$self instvar mac_
set ns_ [Simulator instance]
set beacon_period [$ns_ delay_parse $beacon_period]
set cfp_duration [$ns_ delay_parse $cfp_duration]
$mac_(0) cfp $beacon_period $cfp_duration
}
---END---
[step 6] ns-default.tcl
add following portion next to existing codes, from about line 700.
---BEGIN---
# Mac/802_11new
Mac/802_11new set CWMin_ 31
Mac/802_11new set CWMax_ 1023
Mac/802_11new set SlotTime_ 0.000020 ;# 20us
Mac/802_11new set SIFS_ 0.000010 ;# 10us
Mac/802_11new set PreambleLength_ 144 ;# 144 bit
Mac/802_11new set PLCPHeaderLength_ 48 ;# 48 bits
Mac/802_11new set PLCPDataRate_ 1.0e6 ;# 1Mbps
Mac/802_11new set RTSThreshold_ 0 ;# bytes
Mac/802_11new set ShortRetryLimit_ 7 ;# retransmittions
Mac/802_11new set LongRetryLimit_ 4 ;# retransmissions
Mac/802_11new set bugFix_timer_ true; # fix for when RTS/CTS not used
Mac/802_11new set BeaconInterval_ 0.1 ;# 100ms
Mac/802_11new set ScanType_ PASSIVE
Mac/802_11new set ProbeDelay_ 0.0001 ;# 0.1 ms
Mac/802_11new set MaxChannelTime_ 0.011 ;# 11 ms
Mac/802_11new set MinChannelTime_ 0.005 ;# 5 ms
Mac/802_11new set ChannelTime_ 0.12 ;# 120 ms
---END---
[step 7] ns-mac-802_11.tcl
add following portion next to existing codes, from about line 50.
---BEGIN---
Mac/802_11new set debug_ false
Mac/802_11new instproc init {} {
eval $self next
set ns [Simulator instance]
$ns create-eventtrace Event $self
}
---END---
[step 8] ns-mac.tcl
add following portion next to existing codes, from about line 65.
---BEGIN---
# IEEE 802.11new MAC settings
if [TclObject is-class Mac/802_11new] {
Mac/802_11new set delay_ 64us
Mac/802_11new set ifs_ 16us
Mac/802_11new set slotTime_ 16us
Mac/802_11new set cwmin_ 16
Mac/802_11new set cwmax_ 1024
Mac/802_11new set rtxLimit_ 16
Mac/802_11new set bssId_ -1
Mac/802_11new set sifs_ 8us
Mac/802_11new set pifs_ 12us
Mac/802_11new set difs_ 16us
Mac/802_11new set rtxAckLimit_ 1
Mac/802_11new set rtxRtsLimit_ 3
Mac/802_11new set basicRate_ 1Mb ;# set this to 0 if want to use bandwidth_ for
Mac/802_11new set dataRate_ 1Mb ;# both control and data pkts
}
---END---
[step 9] mac-802_11new.cc
1) copy this file from "mac-802_11.cc"
2) substitute "Mac802_11" with "Mac802_11new", there are 83 instances. (match case, only full matched word)
3) substitute "Mac802_11Class" with "Mac802_11newClass", there are 2 instances. (match case, only full matched word)
4) substitute "Mac/802_11" with "Mac/802_11new", there are 5 instances. (match case, only full matched word)
5*) substitute "mac-802_11" with "mac-802_11new" in line 34.
6) substitute "mac-timers.h" with "mac-timersnew.h" in line 53.
7) substitute "mac-802_11.h" with "mac-802_11new.h" in line 54.
8) substitute "class_mac802_11" with "class_mac802_11new" in line 149.
9*) substitute "MAC_802_11" with "MAC_802_11new" in line 1963.
[step 10] mac-802_11new.h
1) copy this file from "mac-802_11.h"
2*) substitute "mac-802_11.h" with "mac-802_11new.h" in line 34 and 37.
3) substitute "ns_mac_80211_h" with "ns_mac_80211new_h" in line 40, 41 and 602.
4) substitute "mac-timers.h" with "mac-timersnew.h" in line 47.
5) substitute "Mac802_11" with "Mac802_11new", there are 4 instances. (match case, only full matched word)
6) from line 356 to line 365, postfix the name of each timer class with "NEW", for example, substitute "DeferTimer" with "DeferTimerNEW"
7) from line 554 to line 562, postfix the name of each timer class with "NEW", for example, substitute "IFTimer" with "IFTimerNEW"
[step 11] mac-timersnew.cc
1) copy this file from "mac-timers.cc"
2) substitute "mac-timers.h" with "mac-timersnew.h" in line 49.
3) substitute "mac-802_11.h" with "mac-802_11new.h" in line 50.
4) postfix the name of each timer class with "NEW", for example, substitute "MacTimer" with "MacTimerNEW" in line 79, 95, 114, 134, 157, 169, 183, 201, 215, 230, 245, 262, 277, 289, 315 and 349.
[step 12] mac-timersnew.h
1) copy this file from "mac-timers.h"
2) substitute "__mac_timers_h__" with "__mac_timersnew_h__" in line 36, 37 and 140.
3) substitute "Mac802_11" with "Mac802_11new", there are 11 instances. (match case, only full matched word)
4) substitute "MacTimer" with "MacTimerNEW", there are 18 instances. (match case, only full matched word)
5) postfix the name of each timer class with "NEW", for example, substitute "BackoffTimer" with "BackoffTimerNEW" in line 73/75, 87/89, 95/97, 103/105, 112/114, 119/121, 126/128 and 133/135.
[step 13] rebuild
entering "make" command under "ns-allinone-2.33\ns-2.33\"
ps: The modifications in comment or static string is marked with "*", it can be skipped, but had better not to.
Author: Yang Yu-Sheng
Date: 2009/04/25
This article is a hand-on for those who would like to modify ns-2 implementation
of IEEE 802.11 MAC protocol but wish to keep the original one for comparison.
All stuffs about ns-2 except the main topic described here are skipped throughly.
For formal information please check ns-2 official website:
http://www.isi.edu/nsnam/ns/index.html
For informative material please check Dr. Ko's website:
http://hpds.ee.ncku.edu.tw/~smallko/ns2/ns2.htm
The baseline ns-2 implementation chosen for our testbed is all-in-one version of
ns-2.33 from sourceforge:
http://sourceforge.net/project/showfiles.php?group_id=149743&package_id=169689&release_id=588643
Assume we want a new MAC protocol such that we can use "Mac/802_11new" in our tcl script.
What's the todos?
[step 1] check source code to be impacted, maybe you need to backup them for diff them when needed.
(modify)ns-allinone-2.33\Makefile
(modify)ns-allinone-2.33\dei80211mr-1.1.4\src\InitTCL.cc
(modify)ns-allinone-2.33\ns-2.33\indep-utils\webtrace-conv\dec\my-endian.h
(modify)ns-allinone-2.33\ns-2.33\tcl\lib\ns-mobilenode.tcl
(modify)ns-allinone-2.33\ns-2.33\tcl\lib\ns-default.tcl
(modify)ns-allinone-2.33\ns-2.33\tcl\lan\ns-mac-802_11.tcl
(modify)ns-allinone-2.33\ns-2.33\tcl\lan\ns-mac.tcl
(add)ns-allinone-2.33\ns-2.33\mac\mac-802_11new.cc
(add)ns-allinone-2.33\ns-2.33\mac\mac-802_11new.h
(add)ns-allinone-2.33\ns-2.33\mac\mac-timersnew.cc
(add)ns-allinone-2.33\ns-2.33\mac\mac-timersnew.h
[step 2] modify Makefile
add "mac-802_11new.o" next to existing "mac-802_11.o" in OBJ_CC section
add "mac-timersnew.o" next to existing "mac-timers.o" in OBJ_CC section
[step 3] modify InitTCL.c
add following portion next to existing codes, from about line 70.
---BEGIN---
Mac/802_11new/Multirate set useShortPreamble_ false\n\
Mac/802_11new/Multirate set gSyncInterval_ 0\n\
Mac/802_11new/Multirate set bSyncInterval_ 0\n\
\n\
Mac/802_11new/Multirate set CWMin_ 32\n\
Mac/802_11new/Multirate set CWMax_ 1024\n\
\n\
Mac/802_11new/Multirate set VerboseCounters_ 0\n\
\n\
\n\
---END---
[step 4] modify my-endian.h
mark off first line and last line, this is to fix the build problem.
[step 5] ns-mobilenode.tcl
add following 2 portions next to existing codes, from about line 500 and 700.
---BEGIN---
set god_ [God instance]
if {$mactype == "Mac/802_11new"} {
$mac nodes [$god_ num_nodes]
}
---END---
---BEGIN---
if {$mactype == "Mac/802_11new"} {
$self instvar mac_
set ns_ [Simulator instance]
set beacon_period [$ns_ delay_parse $beacon_period]
set cfp_duration [$ns_ delay_parse $cfp_duration]
$mac_(0) cfp $beacon_period $cfp_duration
}
---END---
[step 6] ns-default.tcl
add following portion next to existing codes, from about line 700.
---BEGIN---
# Mac/802_11new
Mac/802_11new set CWMin_ 31
Mac/802_11new set CWMax_ 1023
Mac/802_11new set SlotTime_ 0.000020 ;# 20us
Mac/802_11new set SIFS_ 0.000010 ;# 10us
Mac/802_11new set PreambleLength_ 144 ;# 144 bit
Mac/802_11new set PLCPHeaderLength_ 48 ;# 48 bits
Mac/802_11new set PLCPDataRate_ 1.0e6 ;# 1Mbps
Mac/802_11new set RTSThreshold_ 0 ;# bytes
Mac/802_11new set ShortRetryLimit_ 7 ;# retransmittions
Mac/802_11new set LongRetryLimit_ 4 ;# retransmissions
Mac/802_11new set bugFix_timer_ true; # fix for when RTS/CTS not used
Mac/802_11new set BeaconInterval_ 0.1 ;# 100ms
Mac/802_11new set ScanType_ PASSIVE
Mac/802_11new set ProbeDelay_ 0.0001 ;# 0.1 ms
Mac/802_11new set MaxChannelTime_ 0.011 ;# 11 ms
Mac/802_11new set MinChannelTime_ 0.005 ;# 5 ms
Mac/802_11new set ChannelTime_ 0.12 ;# 120 ms
---END---
[step 7] ns-mac-802_11.tcl
add following portion next to existing codes, from about line 50.
---BEGIN---
Mac/802_11new set debug_ false
Mac/802_11new instproc init {} {
eval $self next
set ns [Simulator instance]
$ns create-eventtrace Event $self
}
---END---
[step 8] ns-mac.tcl
add following portion next to existing codes, from about line 65.
---BEGIN---
# IEEE 802.11new MAC settings
if [TclObject is-class Mac/802_11new] {
Mac/802_11new set delay_ 64us
Mac/802_11new set ifs_ 16us
Mac/802_11new set slotTime_ 16us
Mac/802_11new set cwmin_ 16
Mac/802_11new set cwmax_ 1024
Mac/802_11new set rtxLimit_ 16
Mac/802_11new set bssId_ -1
Mac/802_11new set sifs_ 8us
Mac/802_11new set pifs_ 12us
Mac/802_11new set difs_ 16us
Mac/802_11new set rtxAckLimit_ 1
Mac/802_11new set rtxRtsLimit_ 3
Mac/802_11new set basicRate_ 1Mb ;# set this to 0 if want to use bandwidth_ for
Mac/802_11new set dataRate_ 1Mb ;# both control and data pkts
}
---END---
[step 9] mac-802_11new.cc
1) copy this file from "mac-802_11.cc"
2) substitute "Mac802_11" with "Mac802_11new", there are 83 instances. (match case, only full matched word)
3) substitute "Mac802_11Class" with "Mac802_11newClass", there are 2 instances. (match case, only full matched word)
4) substitute "Mac/802_11" with "Mac/802_11new", there are 5 instances. (match case, only full matched word)
5*) substitute "mac-802_11" with "mac-802_11new" in line 34.
6) substitute "mac-timers.h" with "mac-timersnew.h" in line 53.
7) substitute "mac-802_11.h" with "mac-802_11new.h" in line 54.
8) substitute "class_mac802_11" with "class_mac802_11new" in line 149.
9*) substitute "MAC_802_11" with "MAC_802_11new" in line 1963.
[step 10] mac-802_11new.h
1) copy this file from "mac-802_11.h"
2*) substitute "mac-802_11.h" with "mac-802_11new.h" in line 34 and 37.
3) substitute "ns_mac_80211_h" with "ns_mac_80211new_h" in line 40, 41 and 602.
4) substitute "mac-timers.h" with "mac-timersnew.h" in line 47.
5) substitute "Mac802_11" with "Mac802_11new", there are 4 instances. (match case, only full matched word)
6) from line 356 to line 365, postfix the name of each timer class with "NEW", for example, substitute "DeferTimer" with "DeferTimerNEW"
7) from line 554 to line 562, postfix the name of each timer class with "NEW", for example, substitute "IFTimer" with "IFTimerNEW"
[step 11] mac-timersnew.cc
1) copy this file from "mac-timers.cc"
2) substitute "mac-timers.h" with "mac-timersnew.h" in line 49.
3) substitute "mac-802_11.h" with "mac-802_11new.h" in line 50.
4) postfix the name of each timer class with "NEW", for example, substitute "MacTimer" with "MacTimerNEW" in line 79, 95, 114, 134, 157, 169, 183, 201, 215, 230, 245, 262, 277, 289, 315 and 349.
[step 12] mac-timersnew.h
1) copy this file from "mac-timers.h"
2) substitute "__mac_timers_h__" with "__mac_timersnew_h__" in line 36, 37 and 140.
3) substitute "Mac802_11" with "Mac802_11new", there are 11 instances. (match case, only full matched word)
4) substitute "MacTimer" with "MacTimerNEW", there are 18 instances. (match case, only full matched word)
5) postfix the name of each timer class with "NEW", for example, substitute "BackoffTimer" with "BackoffTimerNEW" in line 73/75, 87/89, 95/97, 103/105, 112/114, 119/121, 126/128 and 133/135.
[step 13] rebuild
entering "make" command under "ns-allinone-2.33\ns-2.33\"
ps: The modifications in comment or static string is marked with "*", it can be skipped, but had better not to.
文章標籤
全站熱搜

來看看的朋友, 留個言吧~ Who ever find this, come leave a message~
Sir I am working on a new MAC protocol design in ns2 for my Majors As I am inexperienced on the use of ns2 I am having a lot of trouble on evaluating and comparing of my protocol with the existing standard Need help please
Well, thanks for your coming, designing a new MAC protocol is very difficult, what I can do is merely modifying IEEE 802.11 MAC to compare this modified MAC with original MAC, that's why I try to clone another MAC instead of modifying it directly.
I am working on cross layer design for wireless sensor networks. How can I get the value from MAC layer and pass to network layer to make routing more dynamic ??
Although such requirement has never occurred, but if I have to pass value between two modules (like TCP/Sack1 and MAC/802_11), I think I will reference the wnd_ or rtt_ instance in TCP module, as you can see, you can use "set curr_wnd [$tcp_(0) set cwnd_]" to get value and "$tcp_(0) set cwnd_ 100" to set value. As to understand how to map variables between tcl and c++ domain, you need to find out all strings that match "wnd_" in related ns2 source code (in both tcl and c code).
Sir, I have to implement CSMA based MAC for Cognitive Radio Networks.I got Cognitive Radio Cognitive Network Simulator(CRCN) which was mentioned as a patch. While trying to do as mentioned in it, there are certain errors occuring. It was asked to include some object files of a protocol "WCETTE" in the Makefile.in file present in the version ns2.31 and then run the commands make clean,make depend,make in the terminal. But once I try to run after putting make clean, it is displaying "Makefile:314 :***commence after first target. Stop". Dont know what does that mean? And for your information I have installed ns2.31 in cygwin installedin the OS windows xp. Kindly help sir....
Dear Kani, I have no idea about your problem, pray for you for finding correct solution soon.....
Sir, I am doing MAC level energy consumption in Adhoc sensor network model. How i can trace the node energy levels. What is the configuration for this model.
thanks a lot ysyang.. it is sooooo useful for me.. Many thaaannnnkkksss
I need the source code of transmission power control of iEEE802.11 in ns2 please iamusbah@yahoo.co.uk
I have used the procedure with mac 802.11 code unchanged but with a new name mac 802.11new. It does not work. Please help
sir i am doing MAC level quque management to handle the load balancing if the quque at level at max threshold it transfer its load to neighbour nodes plese help me how to write tcl script for that rajneesh gujral
thank you for the tutorial, I implimente 802.11n MAC layer it works but the cbr packets are dropped (IFQ) they do not pass through the layer mac.
Sir, i need the source code in ns2 to create a clone node and enable its communication.please help me...
sir i follow all the steps as you provide but i get many error while i run make command error like : invalid use of incomplete type struct mac802_11new ::trace event (char* packet*)::hdr_mac802_11new this error comes many time
This procedure is aligned with old version ns2 about more than 4 years ago. I'll update it as long as I have time to do it, sorry.
Sir, I am new to NS2 and trying to implement medium access protocol in NS2. As a new learner , can u pls guide me what to do.
I do all this steps to clone a new mac protocol but when i do make i have this error: " No rule to make target "mac / newmac.o" necessary "ns". Stop."Pleaaaaaaaaase help me.
I don't understand how can i modify the file ( my-endian.h ) in [step 4] . Thank you in advance ...