1.开启混杂模式,接收邻居转发的所有数据包,不进行MAC过滤,全部

sendToWatchdog(const Packet *p)

2.当前节点转发数据包后,缓存数据包

sendToWatchdog(const Packet *p, int mac_dst)

//Start Watchdog Code
void
AODV::tap(const Packet *p) {
sendToWatchdog(p);
}

void
AODV::sendToWatchdog(const Packet *p){
if(debug>1) printf("taping\n");
char* data; //ns-2 does not send real data, we use the uid of the packet because is unique.
hdr_ip *iph = hdr_ip::access(p);
//hdr_mac *ipm = hdr_mac::access(p);
hdr_cmn *pk = hdr_cmn::access(p);

hdr_mac802_11 *mh;
mh = HDR_MAC802_11(p);

data = (char *) malloc(sizeof(char)*15);
sprintf(data, "%d", pk->uid());

printf("\n\nIP %d:%d (%d) -> IP %d:%d (%d), Type:%d, Data: %s, Time: %f \n",iph->src().addr_, iph->sport(), ETHER_ADDR(mh->dh_ta), iph->dst().addr_, iph->dport(), ETHER_ADDR(mh->dh_ra), pk->ptype_, data, Scheduler::instance().clock());
watchdog->newPacket(iph->src().addr_, iph->dst().addr_, ETHER_ADDR(mh->dh_ta), ETHER_ADDR(mh->dh_ra), iph->sport(), iph->dport(), pk->ptype_, data, Scheduler::instance().clock());
if(debug>1) printf("End tapping\n");
}

void
AODV::sendToWatchdog(const Packet *p, int mac_dst){
if(debug>1) printf("taping\n");
char* data; //ns-2 does not send real data, we use the uid of the packet because is unique.
hdr_ip *iph = hdr_ip::access(p);
//hdr_mac *ipm = hdr_mac::access(p);
hdr_cmn *pk = hdr_cmn::access(p);

hdr_mac802_11 *mh;
mh = HDR_MAC802_11(p);

data = (char *) malloc(sizeof(char)*15);
sprintf(data, "%d", pk->uid());

printf("\n\nIP %d:%d (%d) -> IP %d:%d (%d), Type:%d, Data: %s, Time: %f \n",iph->src().addr_, iph->sport(), ETHER_ADDR(mh->dh_ta), iph->dst().addr_, iph->dport(), mac_dst, pk->ptype_, data, Scheduler::instance().clock());
watchdog->newPacket(iph->src().addr_, iph->dst().addr_, ETHER_ADDR(mh->dh_ta), mac_dst, iph->sport(), iph->dport(), pk->ptype_, data, Scheduler::instance().clock());
if(debug>1) printf("End tapping\n");
}
//End Watchdog Code



 

 posted on 2012-03-07 20:38  Fuzzy Joke  阅读(505)  评论(0编辑  收藏  举报