modules/up/src/Core/network/Mtrace.cc

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. mtraceTimerHandler
  2. Mtrace
  3. Mtrace
  4. send
  5. handleTimer
  6. receive
  7. Response
  8. Response

   1 //
   2 // $Id: Mtrace.cc,v 1.1.1.1 2000/03/10 16:32:19 engin Exp $
   3 //
   4 // Author(s): Ramesh Govindan
   5 
   6 #ifdef HAVE_CONFIG_H
   7 #include <config.h>
   8 #endif
   9 
  10 #include "util/Types.hh"
  11 #include "util/Trail.hh"
  12 #include "util/Handler.hh"
  13 #include "util/Buffer.hh"
  14 #include "sys/File.hh"
  15 #include "sys/Pipe.hh"
  16 #include "sys/Time.hh"
  17 #include "sched/Timer.hh"
  18 #include "sched/Dispatcher.hh"
  19 
  20 #include "network/Mtrace.hh"
  21 #include "network/Headers.hh"
  22 #include "network/Network.hh"
  23 
  24 // Constants
  25 static const U8         MaxUnicastTtl = 255;
  26 static const U8         MaxMulticastTtl = 192;
  27 
  28 // Locals
  29 static TraceCode        traceMtrace("network");
  30 static TimeShort        maxWait(10, 0);
  31 static int              mtraceSequence = 0;
  32 
  33 static void
  34 mtraceTimerHandler(void* ptr,
     /* [<][>][^][v][top][bottom][index][help] */
  35                    void*)
  36 {
  37     ((Mtrace*) ptr)->handleTimer();
  38 }
  39 
  40 Mtrace::Mtrace(const Address* s,
     /* [<][>][^][v][top][bottom][index][help] */
  41                const Address* g,
  42                const Address* r,
  43                const Address* R,
  44                const Address* t,
  45                int h,
  46                const Handler& cb)
  47         : ListNode()
  48 {
  49     done = cb;
  50     source = *s;
  51     group = *g;
  52 
  53     multicastSocket = NULL;
  54     if (r) {
  55         replyTo = *r;
  56         ASSERT(!IN_MULTICAST(replyTo.get()));
  57     } else {
  58         replyTo.set(MtraceMulticast);
  59     }
  60 
  61     if (R) {
  62         receiver = *R;
  63     } else {
  64         receiver.set((network->interfaces.head())->address.get());
  65     }
  66     if (t) {
  67         target = *t;
  68     } else {
  69         target.set(AllRoutersMulticast);
  70     }
  71 
  72     nhops = h;
  73     timer = NULL;
  74     network->pendingMtraces.append(this);
  75 }
  76 
  77 Mtrace::~Mtrace()
     /* [<][>][^][v][top][bottom][index][help] */
  78 {
  79     if (timer) {
  80         delete timer;
  81     }
  82     if (multicastSocket) {
  83         delete multicastSocket;
  84     }
  85     responses.clear();
  86     network->pendingMtraces.remove(this);
  87 }
  88 
  89 void
  90 Mtrace::send()
     /* [<][>][^][v][top][bottom][index][help] */
  91 {
  92     Handler     th(mtraceTimerHandler, this);
  93     Handler     nh(NULL, NULL);
  94     Buffer*     buf;
  95     IP*         ip;
  96     IGMP*       igmp;
  97     IGMPTrace*  trace;
  98     RawSocket*  raw;
  99     TimeLong    at;
 100     Address     addr;
 101 
 102     raw = new RawSocket(nh, nh, RawSocketIGMP);
 103     buf = new Buffer(sizeof(IP) + sizeof(IGMP) + sizeof(IGMPTrace));
 104 
 105     ip = (IP*) buf->contents;
 106     ip->headerLength = sizeof(IP) >> 2;
 107     ip->version = 4;
 108     ip->typeOfService = 0;
 109     ip->totalLength = sizeof(IP) + sizeof(IGMP) + sizeof(IGMPTrace);
 110     ip->identifier = 0;
 111     ip->fragmentOffset = 0;
 112     ip->timeToLive = 0xff;
 113     ip->protocol = IPPROTO_IGMP;
 114     ip->source = (network->interfaces.head())->address.get();
 115     ip->destination = target.get();
 116     ip->hton();
 117     ip->checksum = 0;
 118     ip->checksum = htons(network->cksum((U16*) ip, sizeof(IP)));
 119 
 120     igmp = (IGMP*) (ip + 1);
 121     igmp->type = IGMPMtrace;
 122     igmp->code = nhops;
 123     igmp->group = group.get();
 124     igmp->hton();
 125 
 126     trace = (IGMPTrace*) (igmp + 1);
 127     trace->source = source.get();
 128     trace->destination = receiver.get();
 129     trace->responseAddress = replyTo.get();
 130     trace->timeToLive = 
 131         IN_MULTICAST(trace->destination) ? 
 132                 MaxMulticastTtl : MaxUnicastTtl;
 133     //    identifier = ++mtraceSequence;
 134     identifier = random() >> 8;
 135     trace->queryId = identifier;
 136     trace->hton();
 137 
 138     igmp->checksum = 0;
 139     igmp->checksum = network->cksum((U16*) igmp,
 140                                     sizeof(IGMP) + sizeof(IGMPTrace));
 141 
 142     addr.set(AllRoutersMulticast);
 143     raw->sendTo(buf->contents, buf->size, addr, 0);
 144 
 145     TRACE(traceMtrace, "mtrace sent to %s\n", group.name());
 146 
 147     delete raw;
 148     delete buf;
 149     
 150     if (timer) {
 151         delete timer;
 152     }
 153     at = dispatcher.systemClock;
 154     at = at + maxWait;
 155     timer = new Timer(th, at);
 156 
 157     return;
 158 }
 159 
 160 void
 161 Mtrace::handleTimer()
     /* [<][>][^][v][top][bottom][index][help] */
 162 {
 163     TRACE(traceMtrace, "mtrace failed to %s\n", group.name());
 164 
 165     timer = NULL;
 166     done.callBack((void*) this);
 167     return;
 168 }
 169 
 170 void
 171 Mtrace::receive(const IGMPTrace *trace, int length)
     /* [<][>][^][v][top][bottom][index][help] */
 172 {
 173     IGMPTraceResponse*  resp;
 174     // Save the response
 175     resp = (IGMPTraceResponse*) (trace + 1);
 176     for (int i = 0; i < (length / sizeof(IGMPTraceResponse)); i++) {
 177             Mtrace::Response*   response;
 178             
 179             response = new Mtrace::Response(resp);
 180             response->ntoh();
 181             responses.append(response);
 182             resp++;
 183     }
 184     
 185     done.callBack((void*) this);
 186     return;
 187 }
 188 
 189 Mtrace::Response::Response(IGMPTraceResponse* r)
     /* [<][>][^][v][top][bottom][index][help] */
 190         : ListNode()
 191 {
 192     response = *r;
 193 }
 194 
 195 Mtrace::Response::~Response()
     /* [<][>][^][v][top][bottom][index][help] */
 196 {
 197     // Empty
 198 }
 199 
 200 //  Copyright (c) 1994 by the University of Southern California.
 201 //  All rights reserved.
 202 //
 203 //  Permission to use, copy, modify, and distribute this software and
 204 //  its documentation in source and binary forms for lawful
 205 //  non-commercial purposes and without fee is hereby granted, provided
 206 //  that the above copyright notice appear in all copies and that both
 207 //  the copyright notice and this permission notice appear in supporting
 208 //  documentation, and that any documentation, advertising materials,
 209 //  and other materials related to such distribution and use acknowledge
 210 //  that the software was developed by the University of Southern
 211 //  California and/or Information Sciences Institute.
 212 //  The name of the University of Southern California may not
 213 //  be used to endorse or promote products derived from this software
 214 //  without specific prior written permission.
 215 //
 216 //  THE UNIVERSITY OF SOUTHERN CALIFORNIA DOES NOT MAKE ANY REPRESENTATIONS
 217 //  ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE.  THIS SOFTWARE IS
 218 //  PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
 219 //  INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 220 //  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND 
 221 //  NON-INFRINGEMENT.
 222 //
 223 //  IN NO EVENT SHALL USC, OR ANY OTHER CONTRIBUTOR BE LIABLE FOR ANY
 224 //  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, WHETHER IN CONTRACT,
 225 //  TORT, OR OTHER FORM OF ACTION, ARISING OUT OF OR IN CONNECTION WITH,
 226 //  THE USE OR PERFORMANCE OF THIS SOFTWARE.
 227 //
 228 //  Questions concerning this software should be directed to 
 229 //  scan@isi.edu.
 230 //
 231 
 232 

/* [<][>][^][v][top][bottom][index][help] */