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

dumb-agent.cc

Go to the documentation of this file.
00001 // Copyright (c) 2000 by the University of Southern California
00002 // All rights reserved.
00003 //
00004 // Permission to use, copy, modify, and distribute this software and its
00005 // documentation in source and binary forms for non-commercial purposes
00006 // and without fee is hereby granted, provided that the above copyright
00007 // notice appear in all copies and that both the copyright notice and
00008 // this permission notice appear in supporting documentation. and that
00009 // any documentation, advertising materials, and other materials related
00010 // to such distribution and use acknowledge that the software was
00011 // developed by the University of Southern California, Information
00012 // Sciences Institute.  The name of the University may not be used to
00013 // endorse or promote products derived from this software without
00014 // specific prior written permission.
00015 //
00016 // THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about
00017 // the suitability of this software for any purpose.  THIS SOFTWARE IS
00018 // PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
00019 // INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00020 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 //
00022 // Other copyrights might apply to parts of this software and are so
00023 // noted when applicable.
00024 //
00025 // dumb-agent.cc
00026 
00027 #include "dumb-agent.h"
00028 
00029 static class DumbAgentClass : public TclClass {
00030 public:
00031   DumbAgentClass() : TclClass("Agent/DumbAgent") {}
00032   TclObject* create(int, const char*const*) {
00033     return (new DumbAgent());
00034   }
00035 } class_DumbAgent;
00036 
00037 DumbAgent::DumbAgent() : Agent(PT_PING) {}
00038 
00039 
00040 int DumbAgent::command(int argc, const char*const* argv)
00041 {
00042   if (argc == 3) {
00043     if (strcmp(argv[1], "port-dmux") == 0) {
00044       dmux_ = (PortClassifier *)TclObject::lookup (argv[2]);
00045       if (dmux_ == 0) {
00046         fprintf (stderr, "%s: %s lookup of %s failed\n", __FILE__, argv[1],
00047                  argv[2]);
00048         return TCL_ERROR;
00049       }
00050       return TCL_OK;
00051     }
00052     else if (strcmp(argv[1], "tracetarget") == 0) {
00053       tracetarget_ = (Trace *)TclObject::lookup (argv[2]);
00054       if (tracetarget_ == 0) {
00055         fprintf (stderr, "%s: %s lookup of %s failed\n", __FILE__, argv[1],
00056                  argv[2]);
00057         return TCL_ERROR;
00058       }
00059       return TCL_OK;
00060     }
00061   }
00062   return Agent::command(argc, argv);
00063 }
00064  
00065 
00066 void DumbAgent::recv(Packet *p, Handler *h=0) 
00067 {
00068   
00069   hdr_cmn *ch = HDR_CMN(p);
00070   hdr_ip *iph = HDR_IP(p);
00071   
00072   if (ch->direction() == hdr_cmn::UP) { // in-coming pkt
00073     if ((u_int32_t)iph->daddr() == IP_BROADCAST) {
00074       printf("Recvd brdcast pkt\n");
00075       dmux_->recv(p, 0);
00076     
00077     } else {
00078       // this agent recvs pkts destined to it only
00079       // doesnot support multi-hop scenarios
00080       assert(iph->daddr() == here_.addr_);
00081       printf("Recvd unicast pkt\n");
00082       dmux_->recv(p, 0);
00083     }
00084     
00085   } else { // out-going pkt
00086     target_->recv(p, (Handler*)0);
00087   }
00088 
00089 }
00090  
00091 void DumbAgent::trace(char *fmt, ...) 
00092 {
00093   
00094   va_list ap;
00095   
00096   if (!tracetarget_)
00097     return;
00098   
00099   va_start (ap, fmt);
00100   vsprintf (tracetarget_->pt_->buffer (), fmt, ap);
00101   tracetarget_->pt_->dump ();
00102   va_end (ap);
00103 }

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