00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include<packet.h>
00031 #include<node-core.h>
00032
00033
00034 #include"aodv-tracer.h"
00035 #include"aodv-pkt.h"
00036
00037 extern packet_t PT_MRCL_AODV;
00038
00039 MrclAodvTracer::MrclAodvTracer() : Tracer(3) {}
00040
00041 void MrclAodvTracer::format(Packet *p, SAP *sap)
00042 {
00043 hdr_cmn* ch = hdr_cmn::access(p);
00044
00045 if (ch->ptype()!=PT_AODV)
00046 return;
00047
00048 char pktinfo[50] = "";
00049 hdr_mrcl_aodv *ah = HDR_MRCL_AODV(p);
00050 int saddrLen;
00051 char saddr[MRCL_ADDRESS_MAX_LEN] = "";
00052 char temp[10];
00053 char daddr[MRCL_ADDRESS_MAX_LEN] = "";
00054 int daddrLen;
00055 if (ah->ah_type == AODVTYPE_RREQ)
00056 {
00057 hdr_mrcl_aodv_request *rq = HDR_MRCL_AODV_REQUEST(p);
00058 memcpy(&saddrLen, rq->rq_src, sizeof(int));
00059 if (saddrLen==0) return;
00060 strcpy(saddr, "\0");
00061 for(int i=saddrLen-1; i>=0; i--)
00062 {
00063 if (i==0)
00064 sprintf(temp,"%d", rq->rq_src[i+sizeof(int)]);
00065 else
00066 sprintf(temp,"%d.", rq->rq_src[i+sizeof(int)]);
00067 strcat(saddr,temp);
00068 }
00069 strcat(saddr,"\0");
00070 if (daddrLen>0)
00071 {
00072 memcpy(&daddrLen, rq->rq_dst, sizeof(int));
00073 strcpy(temp,"");
00074 for(int i=daddrLen-1; i>=0; i--)
00075 {
00076 if (i==0)
00077 sprintf(temp,"%d", rq->rq_dst[i+sizeof(int)]);
00078 else
00079 sprintf(temp,"%d.", rq->rq_dst[i+sizeof(int)]);
00080 strcat(daddr,temp);
00081 }
00082 }
00083 strcat(daddr,"\0");
00084 sprintf(pktinfo, "RREQ s%s d%s id%d hc%d ", saddr, daddr, rq->rq_bcast_id, rq->rq_hop_count);
00085
00086 }else if (ah->ah_type == AODVTYPE_RREP)
00087 {
00088 hdr_mrcl_aodv_reply *rp = HDR_MRCL_AODV_REPLY(p);
00089 memcpy(&saddrLen, rp->rp_src, sizeof(int));
00090 if (saddrLen==0) return;
00091 for(int i=saddrLen-1; i>=0; i--)
00092 {
00093 if (i==0)
00094 sprintf(temp,"%d", rp->rp_src[i+sizeof(int)]);
00095 else
00096 sprintf(temp,"%d.", rp->rp_src[i+sizeof(int)]);
00097 strcat(saddr,temp);
00098 }
00099 strcat(saddr,"\0");
00100 if (daddrLen>0)
00101 {
00102 memcpy(&daddrLen, rp->rp_dst, sizeof(int));
00103 strcpy(temp,"");
00104 for(int i=daddrLen-1; i>=0; i--)
00105 {
00106 if (i==0)
00107 sprintf(temp,"%d", rp->rp_dst[i+sizeof(int)]);
00108 else
00109 sprintf(temp,"%d.", rp->rp_dst[i+sizeof(int)]);
00110 strcat(daddr,temp);
00111 }
00112 }
00113 strcat(daddr,"\0");
00114 sprintf(pktinfo, "RREP s%s d%s sno%d hc%d", saddr, daddr, rp->rp_dst_seqno, rp->rp_hop_count);
00115 }else if (ah->ah_type == AODVTYPE_RERR)
00116 {
00117 strcat(pktinfo, "RERR");
00118 }
00119 else if (ah->ah_type == AODVTYPE_HELLO)
00120 {
00121 hdr_mrcl_aodv_reply *rp = HDR_MRCL_AODV_REPLY(p);
00122 sprintf(pktinfo, "HELLO sno%d", rp->rp_dst_seqno);
00123 }
00124 else strcat(pktinfo, "UNKNW");
00125
00126 writeTrace(sap, " --mAODV-- %s", pktinfo);
00127
00128 }