如何添加一个MAC协议--NS2

1
Cloning a New IEEE 802.11 MAC Protocol in ns-2
I. INTRODUCTION
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[1]. For informative material, please check Dr. Ko’s website[2]. The
baseline ns-2 implementation chosen for our testbed is all-in-one version of ns-2.33 from sourceforge[3].
Assume we want a new MAC protocol such that we can use ”Mac/802 11new” in our tcl script: What’s the todos?
II. STEPS
1) Check source code to be modified or added, maybe a backup is necessary for future diff.
Action File to be modified
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
2) Modify Makefile by
a) adding ”mac-802 11new.o” next to existing ”mac-802 11.o” in OBJ CC section.
b) adding ”mac-timersnew.o” next to existing ”mac-timers.o” in OBJ CC section.
3) Modify InitTCL.c by adding following portion next to existing codes, from about line 70.
---BEGIN---
Mac/802_11new/Multirate set useShortPreamble_ false
Mac/802_11new/Multirate set gSyncInterval_ 0
Mac/802_11new/Multirate set bSyncInterval_ 0
Mac/802_11new/Multirate set CWMin_ 32
Mac/802_11new/Multirate set CWMax_ 1024
Mac/802_11new/Multirate set VerboseCounters_ 0
---END---
4) Modify my-endian.h by marking off first line and last line, this is to fix the compile error.
5) Modify ns-mobilenode.tcl by adding 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---
6) Modify ns-default.tcl by adding following portion next to existing codes, from about line 700.
---BEGIN---
# Mac/802_11new
Mac/802_11new set CWMin_ 31
2
Mac/802_11new set CWMax_ 1023
Mac/802_11new set SlotTime_ 0.000020
Mac/802_11new set SIFS_ 0.000010
Mac/802_11new set PreambleLength_ 144
Mac/802_11new set PLCPHeaderLength_ 48
Mac/802_11new set PLCPDataRate_ 1.0e6
Mac/802_11new set RTSThreshold_ 0
Mac/802_11new set ShortRetryLimit_ 7
Mac/802_11new set LongRetryLimit_ 4
Mac/802_11new set bugFix_timer_ true
Mac/802_11new set BeaconInterval_ 0.1
Mac/802_11new set ScanType_ PASSIVE
Mac/802_11new set ProbeDelay_ 0.0001
Mac/802_11new set MaxChannelTime_ 0.011
Mac/802_11new set MinChannelTime_ 0.005
Mac/802_11new set ChannelTime_ 0.12
---END---
7) Modify ns-mac-802 11.tcl by adding 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---
8) Modify ns-mac.tcl by adding 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
Mac/802_11new set dataRate_ 1Mb
}
---END---
9) mac-802 11new.cc
a) copy this file from ”mac-802 11.cc”
b) substitute ”Mac802 11” with ”Mac802 11new”, there are 83 instances. (match case, only full matched word)
c) substitute ”Mac802 11Class” with ”Mac802 11newClass”, there are 2 instances. (match case, only full matched
word)
d) substitute ”Mac/802 11” with ”Mac/802 11new”, there are 5 instances. (match case, only full matched word)
e) substitute ”mac-802 11” with ”mac-802 11new” in line 34.
f) substitute ”mac-timers.h” with ”mac-timersnew.h” in line 53.
g) substitute ”mac-802 11.h” with ”mac-802 11new.h” in line 54.
h) substitute ”class mac802 11” with ”class mac802 11new” in line 149.
i) substitute ”MAC 802 11” with ”MAC 802 11new” in line 1963.
10) mac-802 11new.h
a) copy this file from ”mac-802 11.h”
b) *substitute ”mac-802 11.h” with ”mac-802 11new.h” in line 34 and 37.
c) substitute ”ns mac 80211 h” with ”ns mac 80211new h” in line 40, 41 and 602.
d) substitute ”mac-timers.h” with ”mac-timersnew.h” in line 47.
e) substitute ”Mac802 11” with ”Mac802 11new”, there are 4 instances. (match case, only full matched word)
f) from line 356 to line 365, postfix the name of each timer class with ”NEW”, for example, substitute ”DeferTimer”
with ”DeferTimerNEW”
3
g) from line 554 to line 562, postfix the name of each timer class with ”NEW”, for example, substitute ”IFTimer”
with ”IFTimerNEW”
11) mac-timersnew.cc
a) copy this file from ”mac-timers.cc”
b) substitute ”mac-timers.h” with ”mac-timersnew.h” in line 49.
c) substitute ”mac-802 11.h” with ”mac-802 11new.h” in line 50.
d) 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.
12) mac-timersnew.h
a) copy this file from ”mac-timers.h”
b) substitute ” mac timers h ” with ” mac timersnew h ” in line 36, 37 and 140.
c) substitute ”Mac802 11” with ”Mac802 11new”, there are 11 instances. (match case, only full matched word)
d) substitute ”MacTimer” with ”MacTimerNEW”, there are 18 instances. (match case, only full matched word)
e) 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.
13) Remake load by entering ”make” command under ”ns-allinone-2.33\ns-2.33\”.
REFERENCES
[1]  http://www.isi.edu/nsnam/ns/index.html
[2]  http://hpds.ee.ncku.edu.tw/?smallko/ns2/ns2.htm
[3]  http://sourceforge.net/project/showfiles.php?group  id=149743&package id=169689&release id=588643
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值