📄 classifier.cc
字号:
cq->Insert(now, pkt, &success); if(success != True) printf("ERROR: %s can not store the packet\n", name()); } else { // Buffer is full. Remove old packet first! cq->Remove(×tamp, &old_pkt, &success); if(success != True) { printf("ERROR: %s can not delete old packet\n", name()); free(old_pkt); } pkt = p->copy(); cq->Insert(now, pkt, &success); if(success != True) printf("ERROR: %s can not store the packet\n", name()); } } Packet::free(p); return; } else { // This means the packet is destined toward mobile host // and it needs to be buffered. if(cq != NULL) { //buffer exist int success; double now; now = Scheduler::instance().clock(); if(cq->IsFull() == False) { Packet *pkt = p->copy(); cq->Insert(now, pkt, &success); if(success == True) printf("%s stored the packet\n", name()); } else { printf("buffer is full!\n"); } } } } TAG:if (top_ == 1) { Tcl::instance().evalf("%s Lookup_Hawaii_RT %d", name(), iph->daddr()); nextHop = Tcl::instance().result(); if (!strcmp(nextHop, "-1")) { } else { NsObject* node = (NsObject*)TclObject::lookup(nextHop); node->recv(p, h); return; }} } NsObject* node = find(p); if (node == NULL) { /* * XXX this should be "dropped" somehow. Right now, * these events aren't traced. */ Packet::free(p); return; } node->recv(p,h);}/* * perform the mapping from packet to object * perform upcall if no mapping */NsObject* Classifier::find(Packet* p){ NsObject* node = NULL; int cl = classify(p); if (cl < 0 || cl >= nslot_ || (node = slot_[cl]) == 0) { if (default_target_) return default_target_; /* * Sigh. Can't pass the pkt out to tcl because it's * not an object. */ Tcl::instance().evalf("%s no-slot %ld", name(), cl); if (cl == TWICE) { /* * Try again. Maybe callback patched up the table. */ cl = classify(p); if (cl < 0 || cl >= nslot_ || (node = slot_[cl]) == 0) return (NULL); } } return (node);}NsObject* Classifier::RAfind(Packet* p){ if (default_target_) return default_target_; NsObject* node = NULL; int cl = classify(p); if (cl < 0 || cl >= nslot_ || (node = slot_[cl]) == 0) { if (default_target_) return default_target_; /* * Sigh. Can't pass the pkt out to tcl because it's * not an object. */ Tcl::instance().evalf("%s no-slot %ld", name(), cl); if (cl == TWICE) { /* * Try again. Maybe callback patched up the table. */ cl = classify(p); if (cl < 0 || cl >= nslot_ || (node = slot_[cl]) == 0) return (NULL); } } return (node);}int Classifier::command(int argc, const char*const* argv){ Tcl& tcl = Tcl::instance(); if(argc == 2) { if (strcmp(argv[1], "defaulttarget") == 0) { if (default_target_ != 0) tcl.result(default_target_->name()); return (TCL_OK); } } if (argc == 3) { /* * $classifier alloc-port nullagent */ if (strcmp(argv[1],"alloc-port") == 0) { int slot; NsObject* nullagent =(NsObject*)TclObject::lookup(argv[2]); slot=getnxt(nullagent); tcl.resultf("%u",slot); return(TCL_OK); } /* * $classifier clear $slot */ if (strcmp(argv[1], "clear") == 0) { int slot = atoi(argv[2]); clear(slot); return (TCL_OK); } /* * $classifier installNext $node */ if (strcmp(argv[1], "installNext") == 0) { int slot = maxslot_ + 1; NsObject* node = (NsObject*)TclObject::lookup(argv[2]); if (node == NULL) { tcl.resultf("Classifier::installNext attempt to install non-object %s into classifier", argv[2]); return TCL_ERROR; }; install(slot, node); tcl.resultf("%u", slot); return TCL_OK; } /* * $classifier slot snum * returns the name of the object in slot # snum */ if (strcmp(argv[1], "slot") == 0) { int slot = atoi(argv[2]); if (slot >= 0 && slot < nslot_ && slot_[slot] != NULL) { tcl.resultf("%s", slot_[slot]->name()); return TCL_OK; } tcl.resultf("Classifier: no object at slot %d", slot); return (TCL_ERROR); } /* * $classifier findslot $node * finds the slot containing $node */ if (strcmp(argv[1], "findslot") == 0) { int slot = 0; NsObject* node = (NsObject*)TclObject::lookup(argv[2]); if (node == NULL) { return (TCL_ERROR); } while (slot < nslot_) { if (strcmp(slot_[slot]->name(), argv[2]) == 0) { tcl.resultf("%u", slot); return (TCL_OK); } slot++; } tcl.result("-1"); return (TCL_OK); } if(strcmp(argv[1], "defaulttarget") == 0) { default_target_=(NsObject*)TclObject::lookup(argv[2]); if(default_target_ == 0) return TCL_ERROR; return TCL_OK; } if(strcmp(argv[1], "hawaii-buffer") == 0) { int qsize = atoi(argv[2]); if(qsize > 0) { cq = new CQueue(qsize); printf("Q is created size: %d \n", qsize); } else printf("No Q is created\n"); return (TCL_OK); } if(strcmp(argv[1], "dump-buffer") == 0) { if(cq != NULL) { printf("classifier is called\n"); this->dump(); } else { printf("ERROR there is no Q to dump\n"); } return (TCL_OK); } } else if (argc == 4) { /* * $classifier install $slot $node */ if (strcmp(argv[1], "install") == 0) { int slot = atoi(argv[2]); NsObject* node = (NsObject*)TclObject::lookup(argv[3]); install(slot, node); return (TCL_OK); } if(strcmp(argv[1], "hawaii-buffer") == 0) { int qsize = atoi(argv[2]); double tv = atoi(argv[3]); if(qsize > 0) { cq = new CQueue(qsize); cq->SetTimeLimit(tv/1000); printf("Q is created size: %d time_limit:%f\n", qsize, tv/1000); } else printf("No Q is created\n"); return (TCL_OK); } } return (NsObject::command(argc, argv));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -