dsr_proto.cc

Go to the documentation of this file.
00001 
00002 
00003 /*
00004  * dsr_proto.cc
00005  * Copyright (C) 2000 by the University of Southern California
00006  * $Id: dsr_proto.cc,v 1.3 2005/08/25 18:58:04 johnh Exp $
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License,
00010  * version 2, as published by the Free Software Foundation.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License along
00018  * with this program; if not, write to the Free Software Foundation, Inc.,
00019  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00020  *
00021  *
00022  * The copyright of this module includes the following
00023  * linking-with-specific-other-licenses addition:
00024  *
00025  * In addition, as a special exception, the copyright holders of
00026  * this module give you permission to combine (via static or
00027  * dynamic linking) this module with free software programs or
00028  * libraries that are released under the GNU LGPL and with code
00029  * included in the standard release of ns-2 under the Apache 2.0
00030  * license or under otherwise-compatible licenses with advertising
00031  * requirements (or modified versions of such code, with unchanged
00032  * license).  You may copy and distribute such a system following the
00033  * terms of the GNU GPL for this module and the licenses of the
00034  * other code concerned, provided that you include the source code of
00035  * that other code when and as the GNU GPL requires distribution of
00036  * source code.
00037  *
00038  * Note that people who make modified versions of this module
00039  * are not obligated to grant this special exception for their
00040  * modified versions; it is their choice whether to do so.  The GNU
00041  * General Public License gives permission to release a modified
00042  * version without this exception; this exception also makes it
00043  * possible to release a modified version which carries forward this
00044  * exception.
00045  *
00046  */
00047 //
00048 // Other copyrights might apply to parts of this software and are so
00049 // noted when applicable.
00050 //
00051 // Ported from CMU/Monarch's code, appropriate copyright applies.  
00052 
00053 /* -*- c++ -*- 
00054 
00055    dsr_proto.cc
00056    the DSR routing protocol agent
00057    
00058    */
00059 
00060 
00061 #include <packet.h>
00062 #include <object.h>
00063 #include <agent.h>
00064 #include <trace.h>
00065 #include <ip.h>
00066 #include "routecache.h"
00067 #include "dsr_proto.h"
00068 
00069 static class DSRProtoClass : public TclClass {
00070 public:
00071         DSRProtoClass() : TclClass("Agent/DSRProto") {}
00072         TclObject* create(int, const char*const*) {
00073                 return (new DSRProto);
00074         }
00075 } class_DSRProto;
00076 
00077 
00078 DSRProto::DSRProto() : Agent(PT_DSR)
00079 {
00080   // dst_ = (IP_BROADCAST << 8) | RT_PORT;
00081   dst_.addr_ = IP_BROADCAST;
00082   dst_.port_ = RT_PORT;
00083 }
00084 
00085 
00086 void
00087 DSRProto::recv(Packet* p, Handler* callback)
00088 {
00089   
00090 }
00091 
00092 void
00093 DSRProto::testinit()
00094 {
00095   //struct hdr_sr hsr;
00096   hdr_sr hsr;
00097   
00098   if (net_id == ID(1,::IP))
00099     {
00100       printf("adding route to 1\n");
00101       hsr.init();
00102       hsr.append_addr( 1<<8, NS_AF_INET );
00103       hsr.append_addr( 2<<8, NS_AF_INET );
00104       hsr.append_addr( 3<<8, NS_AF_INET );
00105       hsr.append_addr( 4<<8, NS_AF_INET );
00106       
00107       routecache->addRoute(Path(hsr.addrs(), hsr.num_addrs()), 0.0, ID(1,::IP));
00108     }
00109   
00110   if (net_id == ID(3,::IP))
00111     {
00112       printf("adding route to 3\n");
00113       hsr.init();
00114       hsr.append_addr( 3<<8, NS_AF_INET );
00115       hsr.append_addr( 2<<8, NS_AF_INET );
00116       hsr.append_addr( 1<<8, NS_AF_INET );
00117       
00118       routecache->addRoute(Path(hsr.addrs(), hsr.num_addrs()), 0.0, ID(3,::IP));
00119     }
00120 }
00121 
00122 
00123 int
00124 DSRProto::command(int argc, const char*const* argv)
00125 {
00126   if(argc == 2) 
00127     {
00128       if (strcasecmp(argv[1], "testinit") == 0)
00129     {
00130       testinit();
00131       return TCL_OK;
00132     }
00133     }
00134 
00135   if(argc == 3) 
00136     {
00137       if(strcasecmp(argv[1], "tracetarget") == 0) {
00138     tracetarget = (Trace*) TclObject::lookup(argv[2]);
00139     if(tracetarget == 0)
00140       return TCL_ERROR;
00141     return TCL_OK;
00142       }
00143       else if(strcasecmp(argv[1], "routecache") == 0) {
00144     routecache = (RouteCache*) TclObject::lookup(argv[2]);
00145     if(routecache == 0)
00146       return TCL_ERROR;
00147     return TCL_OK;
00148       }
00149       else if (strcasecmp(argv[1], "ip-addr") == 0) {
00150     net_id = ID(atoi(argv[2]), ::IP);
00151     return TCL_OK;
00152       }
00153       else if(strcasecmp(argv[1], "mac-addr") == 0) {
00154     mac_id = ID(atoi(argv[2]), ::MAC);
00155       return TCL_OK;
00156 
00157       }
00158     }
00159   return Agent::command(argc, argv);
00160 }
00161 
00162 void 
00163 DSRProto::noRouteForPacket(Packet *p)
00164 {
00165 
00166 }

Generated on Tue Mar 6 16:47:44 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6