歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> NS2.29中Tdma的實現分析

NS2.29中Tdma的實現分析

日期:2017/2/28 14:31:18   编辑:Linux教程

1. NS2中的Tdma時幀結構如下圖:

其中前導的數據結構為:static int *tdma_preamble_;
tdma_preamble_ = new int[max_slot_num_]; //max_slot_num_為節點總數
tdma_preamble_[slot_num_] = ETHER_ADDR(MAC_TDMA(pktTx_)->dh_da);
//前導中存儲的是目標節點的Mac地址(4個字節),slot_num_表示當時隙號。

在前導時隙這段時間,完成的主要工作就是設置tdma_preamble_[0]到
tdma_preamble_[ max_slot_num_ - 1]的值,代表從0到max_slot_num_-1個數據時隙各個時隙中要發送數據的目標節點地址。

2. 整個Tdma的類圖如下:

3. Tdma執行過程和關鍵的時隙控制函數如下圖:

4. 設置前導中數據的函數makePreamble過程:

5. 發送函數流程圖:


6. 接收函數流程圖:

7. 一個例子分析,場景:三個節點,相互可見,單信道下節點0和1幾乎同時在0.020001秒即20毫秒的時候給2發送數據,2只接收不發送,仿真在1秒時結束。

Mac層采用NS2自帶的Tdma協議,則:
Tdma的時幀結構為:

輸出的結果顯示:

<0>, 0.000000, make the new preamble now.
<0>, 0.000000, write NO_PKT to slot 0 in preamble
<1>, 0.000000, make the new preamble now.
<1>, 0.000000, write NO_PKT to slot 1 in preamble
<2>, 0.000000, make the new preamble now.
<2>, 0.000000, write NO_PKT to slot 2 in preamble

<0>, 0.006000, time to send.
<1>, 0.006000, preamble[0]=-2, nothing to do now.
<2>, 0.006000, preamble[0]=-2, nothing to do now.

<0>, 0.012000, preamble[1]=-2, nothing to do now.
<1>, 0.012000, time to send.
<2>, 0.012000, preamble[1]=-2, nothing to do now.

<0>, 0.018000, preamble[2]=-2, nothing to do now.
<1>, 0.018000, preamble[2]=-2, nothing to do now.
<2>, 0.018000, time to send.


<0>, 0.024000, make the new preamble now.
<0>, 0.024000, write -1 to slot 0 in preamble
<1>, 0.024000, make the new preamble now.
<1>, 0.024000, write -1 to slot 1 in preamble
<2>, 0.024000, make the new preamble now.
<2>, 0.024000, write NO_PKT to slot 2 in preamble

<0>, 0.030000, time to send.
<1>, 0.030000, preamble[0]=-1, I am supposed to receive now.
<2>, 0.030000, preamble[0]=-1, I am supposed to receive now.

<0>, 0.036000, preamble[1]=-1, I am supposed to receive now.
<1>, 0.036000, time to send.
<2>, 0.036000, preamble[1]=-1, I am supposed to receive now.

<0>, 0.042000, preamble[2]=-2, nothing to do now.
<1>, 0.042000, preamble[2]=-2, nothing to do now.
<2>, 0.042000, time to send.
.......

從上面可以看出,NS2中自帶的Tdma的實現是極其簡單的,時隙分配算法也特別簡單。

Ubuntu 13.04 安裝NS2.35 http://www.linuxidc.com/Linux/2014-03/98266.htm

Linux平台下NS2.35安裝 http://www.linuxidc.com/Linux/2013-11/93055.htm

NS2.33在Ubuntu 12.10的完整安裝過程及相關問題 http://www.linuxidc.com/Linux/2013-05/84032.htm

NS2.33中安裝Noah協議 http://www.linuxidc.com/Linux/2012-06/63764.htm

NS2使用tcl腳本debug工具tcl-debug-2.0 http://www.linuxidc.com/Linux/2012-06/63761.htm

Copyright © Linux教程網 All Rights Reserved