顯示具有 Research 標籤的文章。 顯示所有文章
顯示具有 Research 標籤的文章。 顯示所有文章

[NS2] ARP in NS2

/* ======================================================================
Address Resolution (ARP) Header
====================================================================== */
#define ARPHRD_ETHER 1 /* ethernet hardware format */

#define ARPOP_REQUEST 1 /* request to resolve address */
#define ARPOP_REPLY 2 /* response to previous request */
#define ARPOP_REVREQUEST 3 /* request protocol address */
#define ARPOP_REVREPLY 4 /* response giving protocol address */
#define ARPOP_INVREQUEST 8 /* request to identify peer */
#define ARPOP_INVREPLY 9 /* response identifying peer */

#define ARP_HDR_LEN 28

struct hdr_arp {
u_int16_t arp_hrd;
u_int16_t arp_pro;
u_int8_t arp_hln;
u_int8_t arp_pln;
u_int16_t arp_op;
int arp_sha;
u_int16_t pad1; // so offsets are correct
nsaddr_t arp_spa;
int arp_tha;
u_int16_t pad2; // so offsets are correct
nsaddr_t arp_tpa;

// Header access methods
static int offset_; // required by PacketHeaderManager
inline static int& offset() { return offset_; }
inline static hdr_arp* access(const Packet* p) {
return (hdr_arp*) p->access(offset_);
}
};

-------------------------------------------------------------------------
About nsaddr_t:
It is the typedef of int32_t as following:

typedef
int32_t nsaddr_t;

Reference:
http://www.auto-nomos.de/ns2doku/config_8h-source.html

[NS2] The modification of ARP operation

Introduction:

The following debug messages show that the ARP operation in the NIST WiMAX module. In case of downlink (From BS to SS), as BS needs to send data packets (for example: CBR traffic), it first transmits a ARP request which the mac address of destination is -1 (it means broadcast). SS receiving the ARP request will reply the ARP reponse which the mac address of destination is set to BS's mac address. It is used for notifying BS that SS's mac address. Thus, BS can know SS's mac address through ARP operations.

The deubg messages:
============================================================================================
At 100.001125 in Mac 0 DestClassifier classifying packet for -1(size=28, type=ARP)
At 100.004529 in Mac 0 BS scheduler dlsubframe expires (frame=12499)
At 100.004530 in Mac 1 SS scheduler dlsubframe expires.
At 100.004638 in Mac 1 DestClassifier classifying packet for 0(size=28, type=ARP)
At 100.008481 in Mac 0 BS scheduler ulsubframe expires
At 100.008481 in Mac 1 SS scheduler ulsubframe expires.
At 100.008481 in Mac 1 Start contention in 0.000172(backoff=2, size=124, ps=0.000001)
At 100.009764 in Mac 1 sending packet (type=MAC, size=6, txtime=0.000030) bwreq
received bandwidth request of 34 bytes from 16385
At 100.012529 in Mac 0 BS scheduler dlsubframe expires (frame=12500)
At 100.012529 Allocating UL burst for Node 1:duration= 1
At 100.012529 in BS 0 send_nbr_adv (nb_neighbor=0)
At 100.012530 in Mac 1 SS scheduler dlsubframe expires.
At 100.016481 in Mac 0 BS scheduler ulsubframe expires
At 100.016481 in Mac 1 SS scheduler ulsubframe expires.
At 100.018092 in Mac 1 sending packet (type=ARP, size=34, txtime=0.000018)
At 100.018115 in Mac 0 DestClassifier classifying packet for 1(size=1500, type=cbr)
============================================================================================

Modification:
In our projects, BS will transmit the ARP request to RS, but RS would not relay it to SS. This will causeBS can not get SS's mac address. We will need to execute the following procedures to amend the classify:
1. We need to check the IP address of destination in BS whether is SS's IP address.
2. RS is capable of forwarding the ARP request or ARP reponse to BS/SS, thus ARP operation could be finished.

Reference:
http://www.pcnet.idv.tw/pcnet/network/network_ip_arp.htm
http://en.wikipedia.org/wiki/Address_Resolution_Protocol

[NS2] MR modification

  1. 先將BS的DL與UL subframes 調整成與 MR-BS 一樣,如圖所示:
  2. 再將RS的subframes調整成與MR-BS一致,如圖所示:
  3. 設計RS可以與MR-BS連線與互傳資料,如圖所示:
  4. 設計RS可以與SS連線與互傳資料,如圖所示:
  5. 調整relay link 與 access link 可以達到轉傳的細部程式。

[NS2] debug 日記

  • 2008/03/04 : process_dl_map()中的 dlsubframe與dltimer 的 timer 設定錯誤。

[NS2] 修改程式碼之注意事項

  • mac802_16SS.cc 中的timer有先後順序,如果相關timer設定錯誤的話,等到timer倒數結束後(expire),通常會呼叫 lost_synch()此函式,執行重新同步,通常是在換手時才會執行到。
  • 當在修改 mac802_16BS.cc 、mac802_16RS.cc 或 mac802_16SS.cc 時,必須注意其他程式可能會利用 STA_BS 、STA_MN等去辨別MAC層為何種類型,因此在修改mac802_16RS.cc時,必須去修改其他程式的相關程式碼。

[NS2] base-station

In the wimax1.tcl script, the code is shown as following:

  • $wl_node_($i) base-station [AddrParams addr2id [$bstation node-addr]] ;#attach mn to basestation
We will separate this code into several parts and then introduce them:
  • [$bstation node-addr]: return the $bstation's IP address;
  • [AddrParams addr2id [$bstation node-addr]]: return the ID;
  • $wl_node_($i) base-station [...[...]] : set the base-station ID of the $wl_node_($i).

[NS2] pktRx_ and p

  • pktRx_ : 當 sendUP() 收到 p 之後, 檢查 power 與 collision ,之後會將 p 丟給 pktRx_;接著會利用 rxtimer_ 去執行 mac_->receice() 處理此 pktRx_ 封包。
  • p : 下層的封包往上層送,會呼叫 sendUP(p) 此函式,將此封包位址丟進此函式處理。

[NS2] class Mac802_16SS

*Downlink:
sendUP()
=> rxTimer_.start()
=> mac->receive()
=> process_mac_packet()
=> process_dl_map()
=> dl_timer_->resched()
=> DlTimer::expire()
=> m_->start_dlsubframe()
=> map_->getDlSubframe()->getTimer()->sched()
=> DlSubFrameTimer::expire()
=>dl_timer_->resched()

/**************************************************/
Uplink:
sendUP()
=> rxTimer_.start()
=> mac->receive()
=> process_mac_packet()
=> process_ul_map()
=> ul_timer_->resched()
=> UlTimer::expire()
=> m_->start_ulsubframe()
=> getMap()->getUlSubframe()->getTimer()->sched()
=> UlSubFrameTimer::expire()
=> mac_->transmit(p)
=> scheduler_->schedule()
=> ul_timer_->resched()

[NS2] RSScheduler 重要參數

  • 重要的參數:
    • maxdlduration: 總共有多少的symbol數可供DL配置;
    • dlduration: DL部分目前已使用了多少的symbol數;
    • nbdlbursts: DL Burst 的編號;
    • maxulduration: 總共有多少的symbol數可供UL配置;
    • nbulpdus: UL PUD的編號;
    • txtime: 傳送burst需要的時間;
    • txtime_s: 傳送burst需要多少的symbol數量;

[NS2] Physical Slot & Symbol

One frame is consisted of many Physical Slots (PSs).
One Symbol is composed by several PSs.

Physical Slot (PS) : A unit of time, dependent on PHY specification, for allocating bandwidth.
OFDM / OFDMA PS = 4/fs (fs: sampling frequency)

[NS2] Scheduler

The scheduler will perform the following steps:
1-Clear DL map
2-Allocate Burst for Broadcast message
3-Pick Unicast bursts for Downlink (Best Effort) in a RR fashion
4-Clear UL map
5-Allocate contention slots for initial ranging
6-Allocate contention slots for bandwidth requests
7-Allocate unicast burst for Uplink according to bandwidth requests received (RR fashion)

[NS2] C++ abstract base class TimerHandler

11.1 C++ abstract base class TimerHandler

The abstract base class TimerHandler contains the following public member functions:

[double delay] void sched schedule a timer to expire delay seconds in the future
[double delay] void resched reschedule a timer (similar to sched, but timer may be pending)
[] void cancel cancel a pending timer
[] int status returns timer status (either TIMER_IDLE, TIMER_PENDING, or TIMER_HANDLING)

The abstract base class TimerHandler contains the following protected members:

[Event* e] virtual void expire =0 this method must be filled in by the timer client
[Event* e] virtual void handle consumes an event; invokes expire() and sets status_ of the timer appropriately
int status keeps track of the current timer status
Event event event to be consumed upon timer expiration

The pure virtual function expire() must be defined by the timer classes deriving from this abstract base class.

Finally, two private inline functions are defined:

inline void _sched(double delay) {
(void)Scheduler::instance().schedule(this, &event_, delay);
}
inline void _cancel() {
(void)Scheduler::instance().cancel(&event_);
}

From this code we can see that timers make use of methods of the Scheduler class.

[NS2] class Mac802_16BS

Mac802_16()
=> initTimer->sched(0.001)
=> InitTimer::expire() => m_->init()

/****************************************************/
Mac802_16BS()
=> addClassifier( new DestClassifier() )
=> init_default_connections()
=> init () ( InitTimer::expire() => m_->init() )
=> dl_timer_->sched(stime) (stime = 0.005765)
=> DlTimer::expire() => m_->start_dlsubframe()
=> ((RSScheduler*)scheduler_)->schedule()
=> // update some information (DCD and UCD)
=> getMap()->getDlSubframe()->getTimer()->sched (0)
=> DlSubFrameTimer::expire()
=> dl_timer_->resched (getFrameDuration()) (frame duration = 0.004)
=> ul_timer_->resched (ul_time_) (ul_time_ = 0.00118)
=> UlTimer::expire() => m_->start_ulsubframe()

/****************************************************/
sendUP()
=> rxTimer_.start()
=> mac->receive()

[NS2] How to use the Timer?

From: http://wowseason.spaces.live.com/blog/cns!8A62350BF8613BBF!107.entry


[NS2] LIST usage

怎樣使用ns自己的串列(List)
(LIST_ENTRY -> LIST_HEAD -> LIST_INIT)
1、#include "lib/bsd-list.h"

2、初始化:

1) 在節點中添加,包括了指向前驅和後繼的節點。
#define LIST_ENTRY(type)
struct {
type *le_next; /* next element */
type **le_prev; /* address of previous next element */
}

2) 定義一個串列,串列的類型為type,表頭為lh_first。
#define LIST_HEAD(name, type)
struct name {
type *lh_first; /* first element */
}

3) 初始化串列。
#define LIST_INIT(head) {
(head)->lh_first = NULL;
}

4) 插入節點。
#define LIST_INSERT_AFTER(listelm, elm, field) {
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)
(listelm)->field.le_next->field.le_prev = &(elm)->field.le_next;
(listelm)->field.le_next = (elm);
(elm)->field.le_prev = &(listelm)->field.le_next;
}

#define LIST_INSERT_BEFORE(listelm, elm, field) {
(elm)->field.le_prev = (listelm)->field.le_prev;
(elm)->field.le_next = (listelm);
*(listelm)->field.le_prev = (elm);
(listelm)->field.le_prev = &(elm)->field.le_next;
}

#define LIST_INSERT_HEAD(head, elm, field) {
if (((elm)->field.le_next = (head)->lh_first) != NULL)
(head)->lh_first->field.le_prev = &(elm)->field.le_next;
(head)->lh_first = (elm);
(elm)->field.le_prev = &(head)->lh_first;
}

5) 刪除節點
#define LIST_REMOVE(elm, field) {
if ((elm)->field.le_next != NULL)
(elm)->field.le_next->field.le_prev = (elm)->field.le_prev;
*(elm)->field.le_prev = (elm)->field.le_next;
}

6)一個例子

1. 定義節點類型
class MFlood_RTEntry {
friend class MFlood_RTable;
friend class MFlood;

public:
MFlood_RTEntry();
MFlood_RTEntry(nsaddr_t src,u_int32_t seq);
bool isNewSeq(u_int32_t seq); // old -> false, new->true
void addSeq(u_int32_t seq); // add a seqno to seqno array(rt_seqnos)

protected:
LIST_ENTRY(MFlood_RTEntry) rt_link;
nsaddr_t src_;
u_int32_t seq_;
u_int32_t rt_seqnos[REM_SEQ_COUNT]; //seqno array
u_int32_t max_seqno; //max seqno
u_int32_t min_seqno; //max seqno
u_int16_t seq_it; // seqno's iterator

};

2. 建立一個串列節點類型為MFlood_RTEntry的串列 rthead
LIST_HEAD(, MFlood_RTEntry) rthead;

3. 初始化鏈表rhead為NULL
LIST_INIT(&rthead)

4. 怎樣使用
MFlood_RTEntry*
MFlood_Rtable::rt_lookup(nsaddr_t id) {
Mflood_RTEntry *rt = rthead.lh_first; //獲取鏈表表頭
for(; rt; rt = rt->rt_link.le_next) {
if(rt->src_ == id)
break;
}
return rt;
}

5. 刪除節點
void
MFlood_RTable::rt_delete(nsaddr_t id) {
MFlood_RTEntry *rt = rt_lookup(id);
if(rt) {
LIST_REMOVE(rt, rt_link);
delete rt;
}
}

6. 插入節點
rt = new MFlood_RTEntry(ih->saddr(), fh->seq_);
LIST_INSERT_HEAD(&rtable_.rthead,rt,rt_link);

[NS2] Event scheduling in NS

http://www.baisi.net/redirect.php?tid=61243&goto=newpost

[NS2] LIST usage and code in the NS

  1. http://wowseason.spaces.live.com/blog/cns!8A62350BF8613BBF!122.entry
  2. http://rp.lip6.fr/ns-doc/ns226-doc/html/bsd-list_8h.htm#a0
  3. http://rp.lip6.fr/ns-doc/ns226-doc/html/bsd-list_8h-source.htm

[NS2] 無線網路實驗相關網址

[NS2] 無線網路 Trace 檔之格式

Q: 各欄位所代表的意思??

A: 資訊來自以下網站:
http://www.cs.binghamton.edu/~kliu/research/ns2code/index.html#trace

Content:

How to interprete the NS2 tracefile for wireless simulation?

To find the interpretation of all possible trace format when you do the wireless simulation, you'd better read the code of ns2 in file ns2home/trace/cmu-trace{.h, .cc} Mostly, the format would be as
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)
]

So we can interpret the below trace
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.

And we can also interpret the below trace
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).