Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

trace-ip.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1997 Regents of the University of California.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the Daedalus Research
00017  *      Group at the University of California Berkeley.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * Contributed by Giao Nguyen, http://daedalus.cs.berkeley.edu/~gnguyen
00035  */
00036 
00037 #include "ip.h"
00038 #include "trace.h"
00039 #include "mac.h"
00040 //#include "packet.h"
00041 
00042 
00043 class TraceIp : public Trace {
00044 public:
00045         TraceIp(int type) : Trace(type) {
00046                 bind("mask_", &mask_);
00047                 bind("shift_", &shift_);
00048         }
00049         void recv(Packet*, Handler*);
00050 protected:
00051         int mask_;
00052         int shift_;
00053 };
00054 
00055 class TraceIpMac : public TraceIp {
00056 public:
00057         TraceIpMac(int type) : TraceIp(type) {}
00058         void recv(Packet*, Handler*);
00059 };
00060 
00061 
00062 class TraceIpClass : public TclClass {
00063 public:
00064         TraceIpClass() : TclClass("TraceIp") { }
00065         TclObject* create(int args, const char*const* argv) {
00066                 if (args >= 5)
00067                         return (new TraceIp(*argv[4]));
00068                 else
00069                         return NULL;
00070         }
00071 } traceip_class;
00072 
00073 class TraceIpMacClass : public TclClass {
00074 public:
00075         TraceIpMacClass() : TclClass("TraceIp/Mac") { }
00076         TclObject* create(int args, const char*const* argv) {
00077                 if (args >= 5)
00078                         return (new TraceIpMac(*argv[4]));
00079                 else
00080                         return NULL;
00081         }
00082 } trace_ip_mac_class;
00083 
00084 
00085 void TraceIp::recv(Packet* p, Handler* h)
00086 {
00087         // XXX: convert IP address to node number
00088         hdr_ip *iph = hdr_ip::access(p);
00089         int src = (src_ >= 0) ? src_ : (iph->saddr() >> shift_) & mask_;
00090         int dst = (iph->daddr() >> shift_) & mask_;
00091         format(type_, src, dst , p);
00092         pt_->dump();
00093         target_ ? send(p, h) : Packet::free(p);
00094 }
00095 
00096 
00097 void TraceIpMac::recv(Packet* p, Handler* h)
00098 {
00099         // XXX: convert IP address to node number
00100         // hdr_ip *iph = hdr_ip::access(p);
00101         
00102         hdr_ip *iph = HDR_IP(p);
00103         
00104         int src = (src_ >= 0) ? src_ : (iph->saddr() >> shift_) & mask_;
00105         int dst = (iph->daddr() >> shift_) & mask_;
00106 
00107         hdr_mac* mh = HDR_MAC(p);
00108         
00109         if (mh->ftype() == MF_ACK || mh->ftype() == MF_CTS)
00110                 format(type_, dst, src , p);
00111         else
00112                 format(type_, src, dst , p);
00113         pt_->dump();
00114         target_ ? send(p, h) : Packet::free(p);
00115 }

Generated on Tue Apr 20 12:14:37 2004 for NS2.26SourcesOriginal by doxygen 1.3.3