📄 classifier-base.cc
字号:
/* This software was originally developed at Alcatel USA * and subsequently modified at Washington State University, Pullman, WA * through research work which was supported by a gift from Alcatel, Inc. * The following notice is in adherence to the Washington State University * copyright policy follows. * Copyright (c) Washington State University, 2000-2002. All rights reserved. * Original Authors: Ramakrishna Shenai, Sunil Gowda and Krishna Sivalingam. * License is granted to copy, to use, and to make and to use derivative * works for research and evaluation purposes, provided that Washington * State University is acknowledged in all documentation pertaining to any such * copy or derivative work. Washington State University grants no other * licenses expressed or implied. The Washington State University name * should not be used in any advertising without its written permission. * WASHINGTON STATE UNIVERSITY MAKES NO REPRESENTATIONS CONCERNING EITHER * THE MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS SOFTWARE * FOR ANY PARTICULAR PURPOSE. The software is provided "as is" * without express or implied warranty of any kind. These notices must * be retained in any copies of any part of this software. */#include "classifier-base.h"#include "../scheduler/fdl-scheduler.h"/* The base classifier provides the base functionality over which other * OBS classifiers can be derived. * * It provides a scheduler group used to perfom data and control channel * scheduling on a per-link basic. Customs schedulers with different * scheduling algorithms can be built independently and attach via a * TCL interface method. * Refer to the manual on the section of schedulers to perform this * work. * * ver 1.0 08/01/2003 *///GMG -- added initialization of electronic buffer sizes;// default will be very large buffers (HUGE_VAL defined in math.h)double BaseClassifier::bufsize_[] = { HUGE_VAL, HUGE_VAL, HUGE_VAL, HUGE_VAL, HUGE_VAL };BaseClassifier::BaseClassifier() : Classifier(), address_( -1 ), drop_ (0) { char s[200]; bind( "address_", (int*)(&address_) ); //GMG -- cast &address_ as an int* because address_ is of type nasaddr_, which //is typecast as int32_t, which is typecast as long int on cygwin; this does //not match any of the templates for bind in tclcl.h; the closest matching //template is where 2nd argument is of type int. bind( "type_", &type_ ); // Uncommenting this line introduces some vague either I am not // doing thigs right or there is a problem in the tclc++. I will // stick with the latter :) bind( "proc_time", &proc_time_ ); //GMG -- added setting up of FDL scheduler for node bind( "nfdl", &FS_.nfdl_); bind( "fdldelay", &FS_.fdl_delay_); bind ("option", &FS_.option_); bind ("maxfdls", &FS_.max_fdls_); bind ("ebufoption", &ebuf_option_); if (FS_.option_ < 0 || FS_.option_ > 2) { sprintf (s, "Error -- Invalid FDL option_ %d (must be 0, 1, 2)", FS_.option_); Debug::debug(s); exit(1); } if (FS_.max_fdls_ < 0) { sprintf (s, "Error -- Invalid max_fdls_ %d (must be >= 0)", FS_.max_fdls_); Debug::debug(s); exit(1); } if (FS_.nfdl_ <= 0) { sprintf (s, "Error -- Invalid #FDSLs nfdl_ %d (must be > 0)", &FS_.nfdl_); Debug::debug(s); exit(1); } if (FS_.fdl_delay_ < 0) { sprintf (s, "Error -- Invalid fdl_delay_ %f (must be >= 0)", &FS_.fdl_delay_); Debug::debug(s); exit(1); } if (ebuf_option_ < 0 || ebuf_option_ > 1) { sprintf (s, "Error -- Invalid FDL option_ %d (must be 0 or 1)", ebuf_option_); Debug::debug(s); exit(1); } FS_.alloc ( FS_.nfdl_); //GMG -- added initializing of edge classifier electronic buffer fills for (int j = 0; j < nqos_classes; j++) buffill_[j] = 0.0;}// recv methodvoid BaseClassifier::recv( Packet *pkt, Handler *h ) { Classifier::recv( pkt, h );}// command methodint BaseClassifier::command( int argc, const char*const* argv ){ Tcl& tcl = Tcl::instance(); //GMG -- added because referred to in //drop target if( argc == 2 ) { if( strcmp( argv[1], "display-address" ) == 0 ) { char s[100]; sprintf( s, "Address is %d", address_ ); Debug::debug( s ); return (TCL_OK); } else if( strcmp( argv[1], "display-node-type" ) == 0 ) { char s[100]; sprintf( s, "node type is :%d", type_ ); Debug::debug( s ); return (TCL_OK); } else if( strcmp( argv[1], "dump-scheduler-group-info" ) == 0 ) { char str[100]; sg.printInfo(); return (TCL_OK); } else if (strcmp(argv[1], "drop-target") == 0) { if (drop_ != 0) tcl.resultf("%s", drop_->name()); return (TCL_OK); } } else if( argc == 3 ) { /* * $classifier dump-scheduler-info $destination */ if( strcmp( argv[1], "dump-scheduler-info" ) == 0 ) { LaucScheduler *ls = sg.search( atoi( argv[2] ) ); if( ls == NULL ) { char str[100]; sprintf( str, "No-scheduler found for dest: %d at node: %d", atoi( argv[2] ), address_ ); Debug::debug( str ); } else { char str[100]; sprintf( str, "Scheduler for %d, ncc: %d, ndc: %d, total: %d", ls->destNodeId(), ls->ncc(), ls->ndc(), ls->maxChannels() ); Debug::debug( str ); } return (TCL_OK); } else if (strcmp(argv[1], "drop-target") == 0) { drop_ = (NsObject*)TclObject::lookup(argv[2]); if (drop_ == 0) { tcl.resultf("no object %s", argv[2]); return (TCL_ERROR); } return (TCL_OK); } } else if( argc == 7 ) { /* * $classifier install-scheduler $destination $ncc $ndc $maxChannels $bwpc */ if( strcmp( argv[1], "install-scheduler" ) == 0 ) { LaucScheduler *lsc = new LaucScheduler(); lsc->alloc( (u_int)atoi( argv[3] ), (u_int)atoi( argv[4] ), (u_int)atoi( argv[5] ), this ); //GMG -- added 'this' pointer to // base classifier (*lsc).destNodeId() = (u_int)atoi( argv[2] ); lsc->chbw() = atoi( argv[6] ); sg.install( lsc ); char str[200]; sprintf( str, "Installed a LaucScheduler at %d for dest: %d", address_, lsc->destNodeId() ); Debug::debug( str ); // sg.printInfo(); return TCL_OK; } } return Classifier::command( argc, argv );}/* Retreive the next hop */int BaseClassifier::getNextHop( nsaddr_t addr ) { Tcl& tcl = Tcl::instance(); sprintf( tcl.buffer(), "$ns getnexthop %d %d", address_, addr ); tcl.eval(); return atoi( tcl.result() );}// Handle the functioning of the control (or BHP) packetvoid BaseClassifier::handleControlPacket( Packet *p ) {int fdl_count; //GMG -- added local fdl_count variable for passing to schedule function if( p == NULL ) return; Debug::markTr( address_, p ); hdr_cmn *ch = hdr_cmn::access( p ); hdr_ip *iph = hdr_ip::access( p ); hdr_IPKT *hdr = hdr_IPKT::access( p ); // double check to see this packet is of type IPKT with prio = 1 if( ( ch->ptype() != PT_IPKT ) || ( iph->prio_ != 1 ) ) { // Debug::debug( "Error incorrect control packet type" ); exit(1); } //GMG -- for control packet, link receive method will not decrement // edge node electronic buffer; therefore, set ebuf_ind to 0 hdr->ebuf_ind = 0; // Retreive the lauc scheduler for the next hop for the dest addr LaucScheduler *ls = sg.search( getNextHop( iph->daddr() ) ); if( ls == NULL ) { char debugStr[100]; sprintf( debugStr, "Laucscheduler not found for destination %s at node %d", iph->daddr(), address_ ); Debug::debug( __FILE__, __LINE__, debugStr ); // if this error occur check the TCL initialization of the laucschedulers // also check if the nextHop method returns the current next-hop. exit (-1); } double bhpDur = ls->duration( ch->size() ); double burstDur = ls->duration( hdr->C_burst_size() ); double curTime = Scheduler::instance().clock(); // Note: the bhp is scheduled to leave at bhpStartTime double bhpStartTime =curTime + proc_time_; // the earlies the burst is expected to arrive is after the offset time specified // anyway will be held until the bhp leave (input fdl) in that way the burst is // tried to synchronize to the offset time behind the burst //double burstStartTime = bhpStartTime + BurstManager::offsettime() ; // Todo: Introduce the guard bands in now !
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -