classifier-hier.cc

Go to the documentation of this file.
00001 // -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*-
00002 
00003 /*
00004  * classifier-hier.cc
00005  * Copyright (C) 2000 by the University of Southern California
00006  * $Id: classifier-hier.cc,v 1.8 2005/08/25 18:58:01 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 // $Header: /nfs/jade/vint/CVSROOT/ns-2/classifier/classifier-hier.cc,v 1.8 2005/08/25 18:58:01 johnh Exp $
00049 
00050 #include <assert.h>
00051 #include "classifier-hier.h"
00052 #include "route.h"
00053 
00054 
00055 int HierClassifier::command(int argc, const char*const* argv)
00056 {
00057     Tcl& tcl = Tcl::instance();
00058     if (argc == 3) {
00059         if (strcmp(argv[1], "classifier") == 0) {
00060             // XXX Caller must guarantee that the supplied level
00061             // is within range, i.e., 0 < n <= level_
00062             tcl.resultf("%s", clsfr_[atoi(argv[2])-1]->name());
00063             return TCL_OK;
00064         } else if (strcmp(argv[1], "defaulttarget") == 0) {
00065             NsObject *o = (NsObject *)TclObject::lookup(argv[2]);
00066             for (int i = 0; 
00067                  i < AddrParamsClass::instance().hlevel(); i++)
00068                 clsfr_[i]->set_default_target(o);
00069             return (TCL_OK);
00070         } else if (strcmp(argv[1], "clear") == 0) {
00071             int slot = atoi(argv[2]);
00072             for (int i = 0; 
00073                  i < AddrParamsClass::instance().hlevel(); i++)
00074                 clsfr_[i]->clear(slot);
00075             return (TCL_OK);
00076         }
00077     } else if (argc == 4) {
00078         if (strcmp(argv[1], "add-classifier") == 0) {
00079             int n = atoi(argv[2]) - 1;
00080             Classifier *c=(Classifier*)TclObject::lookup(argv[3]);
00081             clsfr_[n] = c;
00082             return (TCL_OK);
00083         }
00084     }
00085     return Classifier::command(argc, argv);
00086 }
00087 
00088 void HierClassifier::do_install(char* dst, NsObject *target) {
00089     int istr[TINY_LEN], n=0, len=0;
00090     while(n < TINY_LEN) 
00091         istr[n++] = 0;
00092         
00093     RouteLogic::ns_strtok(dst, istr);
00094     
00095     while(istr[len] > 0) {
00096         istr[len] = istr[len] - 1;
00097         len++;
00098     }
00099     for (int i=1; i<len; i++) 
00100         clsfr_[i-1]->install(istr[i-1], clsfr_[i]);
00101     clsfr_[len-1]->install(istr[len-1], target);
00102 }
00103 
00104 void HierClassifier::set_table_size(int level, int size)
00105 {
00106     if (clsfr_[level-1])
00107         clsfr_[level-1]->set_table_size(size);
00108 }
00109 
00110         
00111 
00112 static class HierClassifierClass : public TclClass {
00113 public:
00114     HierClassifierClass() : TclClass("Classifier/Hier") {}
00115     TclObject* create(int argc, const char*const* argv) {
00116         return (new HierClassifier());
00117     }
00118 } class_hier_classifier;
00119 
00120 
00121 

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