1 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- 2 * 3 * Copyright (c) 1997 Regents of the University of California. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by the Computer Systems 17 * Engineering Group at Lawrence Berkeley Laboratory. 18 * 4. Neither the name of the University nor of the Laboratory may be used 19 * to endorse or promote products derived from this software without 20 * specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * $Header: /srv/svn/cvs/protolib/protolib/ns/ns233/cmu-trace.h,v 1.1 2008-07-07 17:38:46 dean Exp $ 35 */ 36 37 /* Ported from CMU/Monarch's code, nov'98 -Padma.*/ 38 39 #ifndef __cmu_trace__ 40 #define __cmu_trace__ 41 42 #include "trace.h" 43 #include "god.h" 44 45 #ifndef __PRETTY_FUNCTION__ 46 #define __PRETTY_FUNCTION__ ("") 47 #endif /* !__PRETTY_FUNCTION__ */ 48 49 /* ====================================================================== 50 Global Defines 51 ====================================================================== */ 52 #define DROP 'D' 53 #define RECV 'r' 54 #define SEND 's' 55 #define FWRD 'f' 56 57 // change wrt Mike's code 58 #define EOT 'x' 59 60 61 62 #define TR_ROUTER 0x01 63 #define TR_MAC 0x02 64 #define TR_IFQ 0x04 65 #define TR_AGENT 0x08 66 67 #define TR_PHY 0x10 68 69 #define DROP_END_OF_SIMULATION "END" 70 #define DROP_MAC_COLLISION "COL" 71 #define DROP_MAC_DUPLICATE "DUP" 72 #define DROP_MAC_PACKET_ERROR "ERR" 73 #define DROP_MAC_RETRY_COUNT_EXCEEDED "RET" 74 #define DROP_MAC_INVALID_STATE "STA" 75 #define DROP_MAC_BUSY "BSY" 76 #define DROP_MAC_INVALID_DST "DST" 77 #define DROP_MAC_SLEEP "SLP" // smac sleep state 78 79 #define DROP_RTR_NO_ROUTE "NRTE" // no route 80 #define DROP_RTR_ROUTE_LOOP "LOOP" // routing loop 81 #define DROP_RTR_TTL "TTL" // ttl reached zero 82 #define DROP_RTR_QFULL "IFQ" // queue full 83 #define DROP_RTR_QTIMEOUT "TOUT" // packet expired 84 #define DROP_RTR_MAC_CALLBACK "CBK" // MAC callback 85 #define DROP_RTR_SALVAGE "SAL" 86 87 #define DROP_IFQ_QFULL "IFQ" // no buffer space in IFQ 88 #define DROP_IFQ_ARP_FULL "ARP" // dropped by ARP 89 #define DROP_IFQ_FILTER "FIL" 90 91 #define DROP_OUTSIDE_SUBNET "OUT" // dropped by base stations if received rtg updates from nodes outside its domain. 92 93 #define MAX_ID_LEN 3 94 #define MAX_NODE 4096 95 96 /** 97 * This class allows a dynamic library to define the tracing format 98 * for newly defined packet types 99 * 100 */ 101 class PacketTracer 102 { 103 public: 104 PacketTracer(); 105 virtual ~PacketTracer(); 106 void setNext(PacketTracer *next); 107 PacketTracer *getNext(); 108 int format_unknow(Packet *p, int offset, BaseTrace *pt_, int newtrace); 109 protected: 110 virtual int format(Packet *p, int offset, BaseTrace *pt_, int newtrace) = 0; //return 0 if the packet is unknown 111 PacketTracer *next_; 112 }; 113 114 115 class CMUTrace : public Trace { 116 public: 117 CMUTrace(const char *s, char t); 118 void recv(Packet *p, Handler *h); 119 void recv(Packet *p, const char* why); 120 121 static void addPacketTracer(PacketTracer *pt); 122 123 124 private: 125 char tracename[MAX_ID_LEN + 1]; 126 int nodeColor[MAX_NODE]; 127 int tracetype; 128 MobileNode *node_; 129 int newtrace_; 130 131 //<zheng: ns 2.27 removed the following part, but we need it to control the broadcast radius> 132 static double bradius; 133 static double radius_scaling_factor_; 134 static double duration_scaling_factor_; 135 static void calculate_broadcast_parameters(); 136 //</zheng> 137 initialized()138 int initialized() { return node_ && 1; } 139 int node_energy(); 140 int command(int argc, const char*const* argv); 141 void format(Packet *p, const char *why); 142 143 void nam_format(Packet *p, int offset); 144 145 void format_phy(Packet *p, int offset); 146 147 void format_mac_common(Packet *p, const char *why, int offset); 148 void format_mac(Packet *p, int offset); 149 void format_smac(Packet *p, int offset); 150 void format_ip(Packet *p, int offset); 151 152 void format_arp(Packet *p, int offset); 153 void format_hdlc(Packet *p, int offset); 154 void format_dsr(Packet *p, int offset); 155 void format_msg(Packet *p, int offset); 156 void format_tcp(Packet *p, int offset); 157 void format_sctp(Packet *p, int offset); 158 void format_rtp(Packet *p, int offset); 159 void format_tora(Packet *p, int offset); 160 void format_imep(Packet *p, int offset); 161 void format_aodv(Packet *p, int offset); 162 void format_protolibmk(Packet *p, int offset); 163 164 // This holds all the tracers added at run-time 165 static PacketTracer *pktTrc_; 166 167 }; 168 169 #endif /* __cmu_trace__ */ 170