Hi,
I'm new in NS2, I hope you can help me, I really need it. I have to implement a routing protocol: if there is a packet to send, it will be flooded when a node receives a packet it will be dropped if the node had received it before When destination address of the incoming packet is the node itself i use the node’s dmux to accept the incoming packet I have to use cbr to generate traffic. My problem is: When destination address of the incoming packet is the node itself i can't do anything the node always accepts the packet. I use a cache to know what packets a nodes has received but it doesn't work in the case of destination address of the incoming packet is the node itself in all other cases it works. My code is the next: void Protoname::recv(Packet* p, Handler* h) { struct hdr_cmn* ch = HDR_CMN(p); struct hdr_ip* ih = HDR_IP(p); struct hdr_protoname_pkt *ph = HDR_PROTONAME_PKT(p); if (message_cache.find(ih->saddr(), ch->uid())) { //Check if i have already received drop(p, DROP_RTR_ALREADY_RECEIVED); //So drop the packet return; } else message_cache.add(ih->saddr(), ch->uid()); //If i hadn't already received i add to the cache if (ih->saddr() == ra_addr()) { // If there exists a loop, must drop the packet if (ch->num_forwards() > 0) { drop(p, DROP_RTR_ROUTE_LOOP); return; } // else if this is a packet I am originating, must add IP header else if (ch->num_forwards() == 0){ ch->size() += IP_HDR_LEN; } } ih->ttl_--; if (ih->ttl_ == 0) { drop(p, DROP_RTR_TTL); return; } forward_data(p); } void Protoname::forward_data(Packet* p) { struct hdr_cmn* ch = HDR_CMN(p); struct hdr_ip* ih = HDR_IP(p); struct hdr_protoname_pkt *ph = HDR_PROTONAME_PKT(p); if ( ih->daddr() == ra_addr()) { dmux_->recv(p, (Handler*)0); return; } else { ch->direction() = hdr_cmn::DOWN; ch->addr_type() = NS_AF_INET; ch->next_hop() = IP_BROADCAST; Scheduler::instance().schedule(target_, p, 0.0); } } My simulation: set udp [new Agent/UDP] $ns_ attach-agent $node_(4) $udp set null [new Agent/Null] $ns_ attach-agent $node_(0) $null $ns_ connect $udp $null set cbr [new Application/Traffic/CBR] $cbr set interval_ 1 $cbr attach-agent $udp $ns_ at 1 "$cbr start" $ns_ at 1.4 "$cbr stop" Trace: 1.000000000 _4_ AGT --- 0 cbr 210 [0 0 0 0] ------- [4:0 0:0 32 0] [0] 0 0 r 1.000000000 _4_ RTR --- 0 cbr 210 [0 0 0 0] ------- [4:0 0:0 32 0] [0] 0 0 s 1.000000000 _4_ RTR --- 0 PROTONAME 230 [0 0 0 0] ------- [4:0 0:0 31 0] r 1.002864000 _10_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 31 0] f 1.002864000 _10_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 30 0] r 1.002864005 _5_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 31 0] r 1.002864005 _11_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 31 0] f 1.002864005 _5_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 30 0] f 1.002864005 _11_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 30 0] r 1.002864007 _3_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 31 0] r 1.002864007 _9_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 31 0] f 1.002864007 _3_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 30 0] f 1.002864007 _9_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 30 0] r 1.002864030 _8_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 31 0] r 1.002864030 _2_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 31 0] f 1.002864030 _8_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 30 0] f 1.002864030 _2_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 30 0] r 1.002864054 _6_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 31 0] r 1.002864054 _0_ AGT --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 31 0] f 1.002864054 _6_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 30 0] r 1.002864058 _7_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 31 0] r 1.002864058 _1_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 31 0] f 1.002864058 _7_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 30 0] f 1.002864058 _1_ RTR --- 0 PROTONAME 230 [0 ffffffff 4 800] ------- [4:0 0:0 30 0] r 1.005268007 _9_ RTR --- 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] D 1.005268007 _9_ RTR ALREADY_RECEIVED 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] r 1.005268011 _5_ RTR --- 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] D 1.005268011 _5_ RTR ALREADY_RECEIVED 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] r 1.005268011 _11_ RTR --- 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] D 1.005268011 _11_ RTR ALREADY_RECEIVED 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] r 1.005268013 _4_ RTR --- 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] D 1.005268013 _4_ RTR ALREADY_RECEIVED 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] r 1.005268013 _10_ RTR --- 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] D 1.005268013 _10_ RTR ALREADY_RECEIVED 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] r 1.005268037 _8_ RTR --- 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] D 1.005268037 _8_ RTR ALREADY_RECEIVED 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] r 1.005268037 _2_ RTR --- 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] D 1.005268037 _2_ RTR ALREADY_RECEIVED 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] r 1.005268064 _6_ RTR --- 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] D 1.005268064 _6_ RTR ALREADY_RECEIVED 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] r 1.005268064 _0_ AGT --- 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] r 1.005268068 _7_ RTR --- 0 PROTONAME 230 [0 ffffffff 3 800] ------- [4:0 0:0 30 0] ... r 1.007782064 _0_ AGT --- 0 PROTONAME 230 [0 ffffffff 9 800] ------- [4:0 0:0 30 0] ... r 1.010176082 _0_ AGT --- 0 PROTONAME 230 [0 ffffffff 8 800] ------- [4:0 0:0 30 0] ... r 1.015308093 _0_ AGT --- 0 PROTONAME 230 [0 ffffffff 7 800] ------- [4:0 0:0 30 0] ... r 1.017702206 _0_ AGT --- 0 PROTONAME 230 [0 ffffffff 5 800] ------- [4:0 0:0 30 0] ... r 1.020076206 _0_ AGT --- 0 PROTONAME 230 [0 ffffffff b 800] ------- [4:0 0:0 30 0] ... ... NODE _0_ ALWAYS ACCEPTS, NEVER DROPS!!!!! WHAT'S WRONG???????????????? Please help!!! Aayushi Shashi.