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.
文章標籤
全站熱搜
創作者介紹
創作者 ysyang21 的頭像
ysyang21

小魚缸

ysyang21 發表在 痞客邦 留言(16) 人氣(315)