headertracer.cc

00001 /*
00002  * Copyright (c) 2006 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 "headertracer.h"
00031 #include "sap.h"
00032 #include "ip.h"
00033 #include "address.h"
00034 #include "packet.h"
00035 #include "mac.h"
00036 #include "smac.h"
00037 
00038 /*-------------------------------------------------------------------------------------------------------
00039         methods for CommonHeaderTracer class
00040 ---------------------------------------------------------------------------------------------------------*/ 
00041 
00042 CommonHeaderTracer::CommonHeaderTracer() : Tracer(1) {}
00043 
00044 void CommonHeaderTracer::format(Packet *p, SAP *sap)
00045 {
00046 
00047         hdr_cmn *ch = hdr_cmn::access(p);
00048         struct hdr_mac802_11 *mh = HDR_MAC802_11(p);
00049         struct hdr_smac *sh = HDR_SMAC(p);
00050 
00051         char dir;
00052         switch (ch->direction())
00053         {
00054                 case 1:
00055                         dir = 'u';
00056                         break;
00057                 case -1:
00058                         dir = 'd';
00059                         break;
00060                 case 0:
00061                         dir = 'n';
00062                         break;
00063         }
00064         
00065         writeTrace(sap, " %d %s %d %c",
00066                                 ch->uid(),                                                                                                      // unique packet id
00067                                 ((ch->ptype() == PT_MAC) ? (
00068                                         (mh->dh_fc.fc_subtype == MAC_Subtype_RTS) ? "RTS"  :
00069                                         (mh->dh_fc.fc_subtype == MAC_Subtype_CTS) ? "CTS"  :
00070                                         (mh->dh_fc.fc_subtype == MAC_Subtype_ACK) ? "ACK"  :
00071                                         "UNKN") :
00072                                         (ch->ptype() == PT_SMAC) ? (
00073                                         (sh->type == RTS_PKT) ? "RTS" :
00074                                         (sh->type == CTS_PKT) ? "CTS" :
00075                                         (sh->type == ACK_PKT) ? "ACK" :
00076                                         (sh->type == SYNC_PKT) ? "SYNC" :
00077                                         "UNKN") : 
00078                                         packet_info.name(ch->ptype())),
00079                                 ch->size(),                                                                                                     // size
00080                                 dir
00081                                 );
00082         
00083 }
00084 
00085 /*-------------------------------------------------------------------------------------------------------
00086         methods for IpHeaderTracer class
00087 ---------------------------------------------------------------------------------------------------------*/ 
00088 
00089 IpHeaderTracer::IpHeaderTracer() : Tracer(3) {}
00090 
00091 void IpHeaderTracer::format(Packet *p, SAP *sap)
00092 {
00093         hdr_ip *ih = hdr_ip::access(p);
00094         hdr_cmn *ch = hdr_cmn::access(p);
00095         
00096         int src = Address::instance().get_nodeaddr(ih->saddr());
00097         int dst = Address::instance().get_nodeaddr(ih->daddr());
00098         
00099         writeTrace(sap, " --IP-- [%d:%d %d:%d %d %d]",
00100                         src, ih->sport(),
00101                         dst, ih->dport(),
00102                         ih->ttl_, (ch->next_hop_ < 0) ? 0 : ch->next_hop_
00103                         );
00104 }
00105 
00106 extern "C" int Trace_Init()
00107 {
00108         /*
00109         Put here all the commands which must be execute when the library is loaded (i.e. TCL script execution)
00110         Remember to ruturn 0 if all is OK, otherwise return 1
00111         */
00112         SAP::addTracer(new CommonHeaderTracer);
00113         SAP::addTracer(new IpHeaderTracer);
00114         return 0;
00115 }
00116 extern "C" int  Cygtrace_Init()
00117 {
00118   Trace_Init();
00119 }
00120 
00121 

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