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
00031
00032
00033
00034
00035
00036
00037 #ifndef lint
00038 static const char rcsid[] =
00039 "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/satellite/sattrace.cc,v 1.12 2002/03/22 23:49:03 buchheim Exp $";
00040 #endif
00041
00042 #include <stdio.h>
00043 #include <stdlib.h>
00044 #include "packet.h"
00045 #include "ip.h"
00046 #include "tcp.h"
00047 #include "rtp.h"
00048 #include "srm.h"
00049 #include "flags.h"
00050 #include "address.h"
00051 #include "trace.h"
00052 #include "sattrace.h"
00053 #include "satposition.h"
00054 #include "satnode.h"
00055
00056 class SatTraceClass : public TclClass {
00057 public:
00058 SatTraceClass() : TclClass("Trace/Sat") { }
00059 TclObject* create(int argc, const char*const* argv) {
00060 if (argc >= 5) {
00061 return (new SatTrace(*argv[4]));
00062 }
00063 return 0;
00064 }
00065 } sat_trace_class;
00066
00067
00068 char* srm_names_[] = {
00069 SRM_NAMES
00070 };
00071
00072 void SatTrace::format(int tt, int s, int d, Packet* p)
00073 {
00074 hdr_cmn *th = hdr_cmn::access(p);
00075 hdr_ip *iph = hdr_ip::access(p);
00076 hdr_tcp *tcph = hdr_tcp::access(p);
00077 hdr_rtp *rh = hdr_rtp::access(p);
00078 hdr_srm *sh = hdr_srm::access(p);
00079
00080 const char* sname = "null";
00081 int lasth, nexth, snadd;
00082 Node* n;
00083
00084 packet_t t = th->ptype();
00085 const char* name = packet_info.name(t);
00086
00087
00088 if (strcmp(name,"SRM") == 0 || strcmp(name,"cbr") == 0 || strcmp(name,"udp") == 0) {
00089 if ( sh->type() < 5 && sh->type() > 0 ) {
00090 sname = srm_names_[sh->type()];
00091 }
00092 }
00093
00094 if (name == 0)
00095 abort();
00096
00097 int seqno;
00098
00099 if (t == PT_RTP || t == PT_CBR || t == PT_UDP || t == PT_EXP ||
00100 t == PT_PARETO)
00101 seqno = rh->seqno();
00102 else if (t == PT_TCP || t == PT_ACK || t == PT_HTTP || t == PT_FTP ||
00103 t == PT_TELNET)
00104 seqno = tcph->seqno();
00105 else
00106 seqno = -1;
00107
00108
00109
00110
00111 char flags[NUMFLAGS+1];
00112 for (int i = 0; i < NUMFLAGS; i++)
00113 flags[i] = '-';
00114 flags[NUMFLAGS] = 0;
00115
00116 hdr_flags* hf = hdr_flags::access(p);
00117 flags[0] = hf->ecn_ ? 'C' : '-';
00118 flags[1] = hf->pri_ ? 'P' : '-';
00119 flags[2] = '-';
00120 flags[3] = hf->cong_action_ ? 'A' : '-';
00121 flags[4] = hf->ecn_to_echo_ ? 'E' : '-';
00122 flags[5] = hf->fs_ ? 'F' : '-';
00123 flags[6] = hf->ecn_capable_ ? 'N' : '-';
00124
00125 #ifdef notdef
00126 flags[1] = (iph->flags() & PF_PRI) ? 'P' : '-';
00127 flags[2] = (iph->flags() & PF_USR1) ? '1' : '-';
00128 flags[3] = (iph->flags() & PF_USR2) ? '2' : '-';
00129 flags[5] = 0;
00130 #endif
00131 char *src_nodeaddr = Address::instance().print_nodeaddr(iph->saddr());
00132 char *src_portaddr = Address::instance().print_portaddr(iph->sport());
00133 char *dst_nodeaddr = Address::instance().print_nodeaddr(iph->daddr());
00134 char *dst_portaddr = Address::instance().print_portaddr(iph->dport());
00135
00136
00137 double s_lat = -999, s_lon = -999, d_lat = -999, d_lon = -999;
00138 n = Node::nodehead_.lh_first;
00139
00140
00141
00142 if (n) {
00143 lasth = th->last_hop_;
00144 nexth = th->next_hop_;
00145 for (; n; n = n->nextnode() ) {
00146 SatNode *sn = (SatNode*) n;
00147 snadd = sn->address();
00148 if (lasth == snadd) {
00149 s_lat = RAD_TO_DEG(SatGeometry::get_latitude(sn->position()->coord()));
00150 s_lon = RAD_TO_DEG(SatGeometry::get_longitude(sn->position()->coord()));
00151 if (d_lat != -999)
00152 break;
00153 }
00154 if (nexth == snadd) {
00155 d_lat = RAD_TO_DEG(SatGeometry::get_latitude(sn->position()->coord()));
00156 d_lon = RAD_TO_DEG(SatGeometry::get_longitude(sn->position()->coord()));
00157 if (s_lat != -999)
00158 break;
00159 }
00160 }
00161 }
00162
00163 if (pt_->tagged()) {
00164 sprintf(pt_->nbuffer(),
00165 "%c %g -s %d -d %d -p %s -e %d -c %d -i %d -a %d -x {%s.%s %s.%s %d %s %s}",
00166 tt,
00167 Scheduler::instance().clock(),
00168 s,
00169 d,
00170 name,
00171 th->size(),
00172 iph->flowid(),
00173 th->uid(),
00174 iph->flowid(),
00175 src_nodeaddr,
00176 src_portaddr,
00177 dst_nodeaddr,
00178 dst_portaddr,
00179 seqno,flags,sname);
00180 } else if (!show_tcphdr_) {
00181 sprintf(pt_->buffer(), "%c %.4f %d %d %s %d %s %d %s.%s %s.%s %d %d %.2f %.2f %.2f %.2f",
00182 tt,
00183 pt_->round(Scheduler::instance().clock()),
00184 lasth,
00185 nexth,
00186 name,
00187 th->size(),
00188 flags,
00189 iph->flowid() ,
00190
00191
00192
00193
00194 src_nodeaddr,
00195 src_portaddr,
00196 dst_nodeaddr,
00197 dst_portaddr,
00198 seqno,
00199 th->uid(),
00200 s_lat,
00201 s_lon,
00202 d_lat,
00203 d_lon);
00204 } else {
00205 sprintf(pt_->buffer(),
00206 "%c %.4f %d %d %s %d %s %d %s.%s %s.%s %d %d %d 0x%x %d %d %.2f %.2f %.2f %.2f",
00207 tt,
00208 pt_->round(Scheduler::instance().clock()),
00209 lasth,
00210 nexth,
00211 name,
00212 th->size(),
00213 flags,
00214 iph->flowid(),
00215
00216
00217
00218
00219 src_nodeaddr,
00220 src_portaddr,
00221 dst_nodeaddr,
00222 dst_portaddr,
00223 seqno,
00224 th->uid(),
00225 tcph->ackno(),
00226 tcph->flags(),
00227 tcph->hlen(),
00228 tcph->sa_length(),
00229 s_lat,
00230 s_lon,
00231 d_lat,
00232 d_lon);
00233 }
00234 if (pt_->namchannel() != 0)
00235 sprintf(pt_->nbuffer(),
00236 "%c -t %g -s %d -d %d -p %s -e %d -c %d -i %d -a %d -x {%s.%s %s.%s %d %s %s}",
00237 tt,
00238 Scheduler::instance().clock(),
00239 s,
00240 d,
00241 name,
00242 th->size(),
00243 iph->flowid(),
00244 th->uid(),
00245 iph->flowid(),
00246 src_nodeaddr,
00247 src_portaddr,
00248 dst_nodeaddr,
00249 dst_portaddr,
00250 seqno,flags,sname);
00251 delete [] src_nodeaddr;
00252 delete [] src_portaddr;
00253 delete [] dst_nodeaddr;
00254 delete [] dst_portaddr;
00255 }
00256
00257 void SatTrace::traceonly(Packet* p)
00258 {
00259 format(type_, src_, dst_, p);
00260 pt_->dump();
00261 }
00262
00263
00264
00265
00266
00267
00268 static class SatDequeTraceClass : public TclClass {
00269 public:
00270 SatDequeTraceClass() : TclClass("Trace/Sat/Deque") { }
00271 TclObject* create(int args, const char*const* argv) {
00272 if (args >= 5)
00273 return (new SatDequeTrace(*argv[4]));
00274 return NULL;
00275 }
00276 } sat_dequetrace_class;
00277
00278
00279 void
00280 SatDequeTrace::recv(Packet* p, Handler* h)
00281 {
00282
00283 format(type_, src_, dst_, p);
00284 pt_->dump();
00285 pt_->namdump();
00286
00287 if (pt_->namchannel() != 0) {
00288 hdr_cmn *th = hdr_cmn::access(p);
00289 hdr_ip *iph = hdr_ip::access(p);
00290 hdr_srm *sh = hdr_srm::access(p);
00291 const char* sname = "null";
00292
00293 packet_t t = th->ptype();
00294 const char* name = packet_info.name(t);
00295
00296 if (strcmp(name,"SRM") == 0 || strcmp(name,"cbr") == 0 || strcmp(name,"udp") == 0) {
00297 if ( sh->type() < 5 && sh->type() > 0 ) {
00298 sname = srm_names_[sh->type()];
00299 }
00300 }
00301
00302 char *src_nodeaddr = Address::instance().print_nodeaddr(iph->saddr());
00303 char *src_portaddr = Address::instance().print_portaddr(iph->sport());
00304 char *dst_nodeaddr = Address::instance().print_nodeaddr(iph->daddr());
00305 char *dst_portaddr = Address::instance().print_portaddr(iph->dport());
00306
00307 char flags[NUMFLAGS+1];
00308 for (int i = 0; i < NUMFLAGS; i++)
00309 flags[i] = '-';
00310 flags[NUMFLAGS] = 0;
00311
00312 hdr_flags* hf = hdr_flags::access(p);
00313 flags[0] = hf->ecn_ ? 'C' : '-';
00314 flags[1] = hf->pri_ ? 'P' : '-';
00315 flags[2] = '-';
00316 flags[3] = hf->cong_action_ ? 'A' : '-';
00317 flags[4] = hf->ecn_to_echo_ ? 'E' : '-';
00318 flags[5] = hf->fs_ ? 'F' : '-';
00319 flags[6] = hf->ecn_capable_ ? 'N' : '-';
00320
00321 #ifdef notdef
00322 flags[1] = (iph->flags() & PF_PRI) ? 'P' : '-';
00323 flags[2] = (iph->flags() & PF_USR1) ? '1' : '-';
00324 flags[3] = (iph->flags() & PF_USR2) ? '2' : '-';
00325 flags[5] = 0;
00326 #endif
00327
00328 sprintf(pt_->nbuffer(),
00329 "%c -t %g -s %d -d %d -p %s -e %d -c %d -i %d -a %d -x {%s.%s %s.%s %d %s %s}",
00330 'h',
00331 Scheduler::instance().clock(),
00332 src_,
00333 dst_,
00334 name,
00335 th->size(),
00336 iph->flowid(),
00337 th->uid(),
00338 iph->flowid(),
00339 src_nodeaddr,
00340 src_portaddr,
00341 dst_nodeaddr,
00342 dst_portaddr,
00343 -1, flags, sname);
00344 pt_->namdump();
00345 delete [] src_nodeaddr;
00346 delete [] src_portaddr;
00347 delete [] dst_nodeaddr;
00348 delete [] dst_portaddr;
00349 }
00350
00351
00352 if (target_ == 0)
00353 Packet::free(p);
00354 else
00355 send(p, h);
00356 }