分类:
2011-02-10 23:58:29
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的实现是极其简单的,时隙分配算法也特别简
单。