模拟无线网络中的数据包丢失

问题描述:

如何模拟使用ns2从无线网络中的恶意节点丢弃的数据包?模拟无线网络中的数据包丢失

+1

请帮助我们理解这个问题: - 你要问这是怎么发生的呢? “一包”是什么意思?你是否已经有一个系统来识别恶意节点? – Aidanapword 2011-03-10 15:38:59

+0

这是一个编程问题,或更多的计算机问题?如果是后者,它可能更适合SuperUser。 – 2011-03-10 15:53:13

+0

@rlb:这是一个关于ns2的问题,它是一个网络模拟器。提问者问如何去模拟这样的事情,这需要一些编程。 (我不知道,尽管它是用Tcl编写的,但我完全不知道ns2)。 – 2011-03-11 10:10:37

首先您需要修改aodv.ccaodv.h文件。在aodv.h

/* The Routing Agent */ 
class AODV: public Agent { 

... 

/* 

* History management 

*/ 

double  PerHopTime(aodv_rt_entry *rt); 

... 
add following line 


bool  malicious; 
With this variable we are trying to define if the node is malicious or not. In aodv.cc after 


/* 

    Constructor 

*/ 

AODV::AODV(nsaddr_t id) : Agent(PT_AODV),btimer(this), htimer(this), ntimer(this), rtimer(this), lrtimer(this), rqueue() { 

index = id; 

seqno = 2; 

bid = 1; 

... 
add following line 

malicious = false; 
The above code is needed to initialize, and all nodes are initially not malicious. Then we will write a code to catch which node is set as malicious. In aodv.cc after 


if(argc == 2) { 

    Tcl& tcl = Tcl::instance(); 



    if(strncasecmp(argv[1], "id", 2) == 0) { 

     tcl.resultf("%d", index); 

     return TCL_OK; 

    } 
add following line 


if(strcmp(argv[1], "hacker") == 0) { 

    malicious = true; 

    return TCL_OK; 

} 
Now we will do some work in TCL to set a malicious node. Using script in my post , we add following line to set node 5 as malicious node. 


$ns at 0.0 "[$mnode_(5) set ragent_] hacker" 
You may add this line after 


for {set i 0} {$i < $val(nn)} { incr i } { 

$ns initial_node_pos $mnode_($i) 10 

} 

... 
Alright, we have set malicious node but we did not tell malicious node what to do. As it is known, rt_resolve(Packet *p) function is used to select next hop node when routing data packets. So, we tell malicious node just drop any packet when it receives. To do that after 


/* 

Route Handling Functions 

*/ 

void 

AODV::rt_resolve(Packet *p) { 

struct hdr_cmn *ch = HDR_CMN(p); 

struct hdr_ip *ih = HDR_IP(p); 

aodv_rt_entry *rt; 

... 
We add a few lines 


// if I am malicious node 

if (malicious == true) { 

    drop(p, DROP_RTR_ROUTE_LOOP); 

    // DROP_RTR_ROUTE_LOOP is added for no reason. 

} 

和执行恶意节点完成后。我希望这篇文章能够帮助你设计你的安全路由协议。

参考以下链接

http://elmurod.net/en/index.php/archives/196