在AODV中添加恶意节点:NS2: Adding Malicious Node to AODV修改版

Many people have asked me how to implement malicious drop in AODV. I have decided to write simple code for adding malicious node in AODV ( or in any routing protocol).

First you need to modify aodv.cc and aodv.h files. In aodv.h after(line 275)

1 /*  The Routing Agent */
2 class AODV: public Agent {
3 ...
4 /*
5 * History management
6 */
7 double      PerHopTime(aodv_rt_entry *rt);
8 ...

add following line

1 bool     malicious;

With this variable we are trying to define if the node is malicious or not. In aodv.cc after(line 153)

1 /*
2   Constructor
3 */
4 AODV::AODV(nsaddr_t id) : Agent(PT_AODV),btimer(this), htimer(this), ntimer(this), rtimer(this), lrtimer(this), rqueue() {
5 index = id;
6 seqno = 2;
7 bid = 1;
8 ...

add following line

1 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(line 86)

1 if(argc == 2) {
2   Tcl& tcl = Tcl::instance();
3  
4     if(strncasecmp(argv[1], "id", 2) == 0) {
5       tcl.resultf("%d", index);
6       return TCL_OK;
7     }

add following line

1 if(strcmp(argv[1], "hacker") == 0) {
2     malicious = true;
3    return TCL_OK;
4 }

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.

1 $ns at 0.0 "[$mnode_(5) set ragent_] hacker"

You may add this line after

1 for {set 0} {$i < $val(nn)} { incr i } {
2 $ns initial_node_pos $mnode_($i) 10
3 }
4 ...

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(line 448)

1 /*
2 Route Handling Functions
3 */
4 void
5 AODV::rt_resolve(Packet *p) {
6 struct hdr_cmn *ch = HDR_CMN(p);
7 struct hdr_ip *ih = HDR_IP(p);
8 aodv_rt_entry *rt;
9 ...

We add a few lines

1 // if I am malicious node
2  if (malicious == true ) {
3     drop(p, DROP_RTR_ROUTE_LOOP);
4     // DROP_RTR_ROUTE_LOOP is added for no reason.
5 }

And implementing malicious node is done. I hope the post will be helpful to design your secure routing protocol.

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值