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

dsr_proto.cc

Go to the documentation of this file.
00001 
00002 // Copyright (c) 2000 by the University of Southern California
00003 // All rights reserved.
00004 //
00005 // Permission to use, copy, modify, and distribute this software and its
00006 // documentation in source and binary forms for non-commercial purposes
00007 // and without fee is hereby granted, provided that the above copyright
00008 // notice appear in all copies and that both the copyright notice and
00009 // this permission notice appear in supporting documentation. and that
00010 // any documentation, advertising materials, and other materials related
00011 // to such distribution and use acknowledge that the software was
00012 // developed by the University of Southern California, Information
00013 // Sciences Institute.  The name of the University may not be used to
00014 // endorse or promote products derived from this software without
00015 // specific prior written permission.
00016 //
00017 // THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about
00018 // the suitability of this software for any purpose.  THIS SOFTWARE IS
00019 // PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
00020 // INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00021 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00022 //
00023 // Other copyrights might apply to parts of this software and are so
00024 // noted when applicable.
00025 //
00026 // Ported from CMU/Monarch's code, appropriate copyright applies.  
00027 
00028 /* -*- c++ -*- 
00029 
00030    dsr_proto.cc
00031    the DSR routing protocol agent
00032    
00033    */
00034 
00035 
00036 #include <packet.h>
00037 #include <object.h>
00038 #include <agent.h>
00039 #include <trace.h>
00040 #include <ip.h>
00041 #include "routecache.h"
00042 #include "dsr_proto.h"
00043 
00044 static class DSRProtoClass : public TclClass {
00045 public:
00046         DSRProtoClass() : TclClass("Agent/DSRProto") {}
00047         TclObject* create(int, const char*const*) {
00048                 return (new DSRProto);
00049         }
00050 } class_DSRProto;
00051 
00052 
00053 DSRProto::DSRProto() : Agent(PT_DSR)
00054 {
00055   // dst_ = (IP_BROADCAST << 8) | RT_PORT;
00056   dst_.addr_ = IP_BROADCAST;
00057   dst_.port_ = RT_PORT;
00058 }
00059 
00060 
00061 void
00062 DSRProto::recv(Packet* p, Handler* callback)
00063 {
00064   
00065 }
00066 
00067 void
00068 DSRProto::testinit()
00069 {
00070   //struct hdr_sr hsr;
00071   hdr_sr hsr;
00072   
00073   if (net_id == ID(1,::IP))
00074     {
00075       printf("adding route to 1\n");
00076       hsr.init();
00077       hsr.append_addr( 1<<8, NS_AF_INET );
00078       hsr.append_addr( 2<<8, NS_AF_INET );
00079       hsr.append_addr( 3<<8, NS_AF_INET );
00080       hsr.append_addr( 4<<8, NS_AF_INET );
00081       
00082       routecache->addRoute(Path(hsr.addrs(), hsr.num_addrs()), 0.0, ID(1,::IP));
00083     }
00084   
00085   if (net_id == ID(3,::IP))
00086     {
00087       printf("adding route to 3\n");
00088       hsr.init();
00089       hsr.append_addr( 3<<8, NS_AF_INET );
00090       hsr.append_addr( 2<<8, NS_AF_INET );
00091       hsr.append_addr( 1<<8, NS_AF_INET );
00092       
00093       routecache->addRoute(Path(hsr.addrs(), hsr.num_addrs()), 0.0, ID(3,::IP));
00094     }
00095 }
00096 
00097 
00098 int
00099 DSRProto::command(int argc, const char*const* argv)
00100 {
00101   if(argc == 2) 
00102     {
00103       if (strcasecmp(argv[1], "testinit") == 0)
00104         {
00105           testinit();
00106           return TCL_OK;
00107         }
00108     }
00109 
00110   if(argc == 3) 
00111     {
00112       if(strcasecmp(argv[1], "tracetarget") == 0) {
00113         tracetarget = (Trace*) TclObject::lookup(argv[2]);
00114         if(tracetarget == 0)
00115           return TCL_ERROR;
00116         return TCL_OK;
00117       }
00118       else if(strcasecmp(argv[1], "routecache") == 0) {
00119         routecache = (RouteCache*) TclObject::lookup(argv[2]);
00120         if(routecache == 0)
00121           return TCL_ERROR;
00122         return TCL_OK;
00123       }
00124       else if (strcasecmp(argv[1], "ip-addr") == 0) {
00125         net_id = ID(atoi(argv[2]), ::IP);
00126         return TCL_OK;
00127       }
00128       else if(strcasecmp(argv[1], "mac-addr") == 0) {
00129         mac_id = ID(atoi(argv[2]), ::MAC);
00130       return TCL_OK;
00131 
00132       }
00133     }
00134   return Agent::command(argc, argv);
00135 }
00136 
00137 void 
00138 DSRProto::noRouteForPacket(Packet *p)
00139 {
00140 
00141 }

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