00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #ifndef lint
00048 static const char rcsid[] =
00049 "@(#) $Header: /usr/src/mash/repository/vint/ns-2/lanRouter.cc";
00050 #endif
00051
00052 #include <tcl.h>
00053 #include "lanRouter.h"
00054 #include "address.h"
00055 #include "ip.h"
00056
00057 static class LanRouterClass : public TclClass {
00058 public:
00059 LanRouterClass() : TclClass("LanRouter") {}
00060 TclObject* create(int, const char*const*) {
00061 return (new LanRouter());
00062 }
00063 } class_mac;
00064
00065 int LanRouter::next_hop(Packet *p) {
00066 if (switch_ && switch_->classify(p)==1) {
00067 return -1;
00068 }
00069 if (!routelogic_) return -1;
00070
00071 hdr_ip* iph= hdr_ip::access(p);
00072 char* adst= Address::instance().print_nodeaddr(iph->daddr());
00073 int next_hopIP;
00074
00075 if (enableHrouting_) {
00076 char* bdst;
00077
00078 routelogic_->lookup_hier(lanaddr_, adst, next_hopIP);
00079
00080 bdst = Address::instance().print_nodeaddr(next_hopIP);
00081
00082 Tcl &tcl = Tcl::instance();
00083 tcl.evalf("[Simulator instance] get-node-id-by-addr %s", bdst);
00084 sscanf(tcl.result(), "%d", &next_hopIP);
00085 delete [] bdst;
00086 } else {
00087 routelogic_->lookup_flat(lanaddr_, adst, next_hopIP);
00088 }
00089 delete [] adst;
00090
00091 return next_hopIP;
00092 }
00093 int LanRouter::command(int argc, const char*const* argv)
00094 {
00095
00096 if (argc == 3) {
00097
00098 if (strcmp(argv[1], "lanaddr") == 0) {
00099 strcpy(lanaddr_, argv[2]);
00100 return (TCL_OK);
00101 }
00102
00103 if (strcmp(argv[1], "routing") == 0) {
00104 if (strcmp(argv[2], "hier")==0)
00105 enableHrouting_= true;
00106 else if (strcmp(argv[2], "flat")==0)
00107 enableHrouting_= false;
00108 else return (TCL_ERROR);
00109 return (TCL_OK);
00110 }
00111
00112 if (strcmp(argv[1], "switch") == 0) {
00113 switch_ = (Classifier*) TclObject::lookup(argv[2]);
00114 return (TCL_OK);
00115 }
00116
00117 if (strcmp(argv[1], "routelogic") == 0) {
00118 routelogic_ = (RouteLogic*) TclObject::lookup(argv[2]);
00119 return (TCL_OK);
00120 }
00121 }
00122 return NsObject::command(argc, argv);
00123 }
00124
00125
00126
00127
00128
00129