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 #ifndef lint
00036 static const char rcsid[] =
00037 "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/classifier/classifier-virtual.cc,v 1.12 2001/12/20 00:15:33 haldar Exp $";
00038 #endif
00039
00040 extern "C" {
00041 #include <tcl.h>
00042 }
00043 #include "config.h"
00044 #include "packet.h"
00045 #include "ip.h"
00046 #include "classifier.h"
00047 #include "route.h"
00048 #include "object.h"
00049 #include "address.h"
00050
00051 class VirtualClassifier : public Classifier {
00052 public:
00053 VirtualClassifier() : routelogic_(0) {
00054 Tcl_InitHashTable(&ht_, TCL_ONE_WORD_KEYS);
00055 }
00056 ~VirtualClassifier() {
00057 Tcl_DeleteHashTable(&ht_);
00058 }
00059 virtual void do_install(char *dst, NsObject *target) { }
00060 protected:
00061 NsObject* next_;
00062 Tcl_HashTable ht_;
00063 RouteLogic *routelogic_;
00064 NsObject* target_;
00065 bool enableHrouting_;
00066 char nodeaddr_[SMALL_LEN];
00067
00068 int classify(Packet *const p) {
00069 hdr_ip* iph = hdr_ip::access(p);
00070 return mshift(iph->daddr());
00071 }
00072
00073 void recv(Packet* p, Handler* h) {
00074 if (!routelogic_) {
00075 Tcl &tcl = Tcl::instance();
00076 tcl.evalc("[Simulator instance] get-routelogic");
00077 routelogic_= (RouteLogic*) TclObject::lookup(tcl.result());
00078
00079 }
00080
00081
00082
00083
00084 Tcl &tcl = Tcl::instance();
00085 hdr_ip* iph = hdr_ip::access(p);
00086 char* adst= Address::instance().print_nodeaddr(iph->daddr());
00087
00088 target_= 0;
00089
00090 int next_hopIP;
00091 routelogic_->lookup_flat(nodeaddr_, adst, next_hopIP);
00092 delete [] adst;
00093
00094 int newEntry;
00095 Tcl_HashEntry *ep= Tcl_CreateHashEntry(&ht_, (const char*)next_hopIP,
00096 &newEntry);
00097 if (newEntry) {
00098 tcl.evalf("%s find %d", name(), next_hopIP);
00099 Tcl_SetHashValue(ep, target_= (NsObject*)tcl.lookup(tcl.result()));
00100 } else {
00101 target_= (NsObject*)Tcl_GetHashValue(ep);
00102 }
00103
00104 if (!target_) {
00105
00106
00107
00108
00109 Packet::free(p);
00110 return;
00111 }
00112 target_->recv(p,h);
00113 }
00114 int command(int argc, const char*const* argv) {
00115 if (argc == 3) {
00116 if (strcmp(argv[1], "nodeaddr") == 0) {
00117 strcpy(nodeaddr_, argv[2]);
00118 return(TCL_OK);
00119 }
00120 }
00121 return (NsObject::command(argc, argv));
00122 }
00123 };
00124
00125 static class VirtualClassifierClass : public TclClass {
00126 public:
00127 VirtualClassifierClass() : TclClass("Classifier/Virtual") {}
00128 TclObject* create(int, const char*const*) {
00129 return (new VirtualClassifier());
00130 }
00131 } class_virtual_classifier;
00132