aodv-tracer.cc

00001 /*
00002  * Copyright (c) 2008 Regents of the SIGNET lab, University of Padova.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University of Padova (SIGNET lab) nor the 
00014  *    names of its contributors may be used to endorse or promote products 
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00018  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
00019  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00020  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00021  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00023  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00024  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00025  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00026  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00027  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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; // routing addresses not yet initialized
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; // routing addresses not yet initialized
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 }

Generated on Wed Nov 26 15:47:27 2008 for NS-MIRACLE library by  doxygen 1.5.2