Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

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 // Time-stamp: <2000-09-15 12:52:53 haoboy>
00004 //
00005 // Copyright (c) 2000 by the University of Southern California
00006 // All rights reserved.
00007 //
00008 // Permission to use, copy, modify, and distribute this software and its
00009 // documentation in source and binary forms for non-commercial purposes
00010 // and without fee is hereby granted, provided that the above copyright
00011 // notice appear in all copies and that both the copyright notice and
00012 // this permission notice appear in supporting documentation. and that
00013 // any documentation, advertising materials, and other materials related
00014 // to such distribution and use acknowledge that the software was
00015 // developed by the University of Southern California, Information
00016 // Sciences Institute.  The name of the University may not be used to
00017 // endorse or promote products derived from this software without
00018 // specific prior written permission.
00019 //
00020 // THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about
00021 // the suitability of this software for any purpose.  THIS SOFTWARE IS
00022 // PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
00023 // INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00024 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00025 //
00026 // Other copyrights might apply to parts of this software and are so
00027 // noted when applicable.
00028 //
00029 // Hierarchical classifier: a wrapper for hierarchical routing
00030 //
00031 // $Header: /nfs/jade/vint/CVSROOT/ns-2/classifier/classifier-hier.cc,v 1.7 2002/01/25 20:22:16 haldar Exp $
00032 
00033 #include <assert.h>
00034 #include "classifier-hier.h"
00035 #include "route.h"
00036 
00037 
00038 int HierClassifier::command(int argc, const char*const* argv)
00039 {
00040         Tcl& tcl = Tcl::instance();
00041         if (argc == 3) {
00042                 if (strcmp(argv[1], "classifier") == 0) {
00043                         // XXX Caller must guarantee that the supplied level
00044                         // is within range, i.e., 0 < n <= level_
00045                         tcl.resultf("%s", clsfr_[atoi(argv[2])-1]->name());
00046                         return TCL_OK;
00047                 } else if (strcmp(argv[1], "defaulttarget") == 0) {
00048                         NsObject *o = (NsObject *)TclObject::lookup(argv[2]);
00049                         for (int i = 0; 
00050                              i < AddrParamsClass::instance().hlevel(); i++)
00051                                 clsfr_[i]->set_default_target(o);
00052                         return (TCL_OK);
00053                 } else if (strcmp(argv[1], "clear") == 0) {
00054                         int slot = atoi(argv[2]);
00055                         for (int i = 0; 
00056                              i < AddrParamsClass::instance().hlevel(); i++)
00057                                 clsfr_[i]->clear(slot);
00058                         return (TCL_OK);
00059                 }
00060         } else if (argc == 4) {
00061                 if (strcmp(argv[1], "add-classifier") == 0) {
00062                         int n = atoi(argv[2]) - 1;
00063                         Classifier *c=(Classifier*)TclObject::lookup(argv[3]);
00064                         clsfr_[n] = c;
00065                         return (TCL_OK);
00066                 }
00067         }
00068         return Classifier::command(argc, argv);
00069 }
00070 
00071 void HierClassifier::do_install(char* dst, NsObject *target) {
00072         int istr[TINY_LEN], n=0, len=0;
00073         while(n < TINY_LEN) 
00074                 istr[n++] = 0;
00075                 
00076         RouteLogic::ns_strtok(dst, istr);
00077         
00078         while(istr[len] > 0) {
00079                 istr[len] = istr[len] - 1;
00080                 len++;
00081         }
00082         for (int i=1; i<len; i++) 
00083                 clsfr_[i-1]->install(istr[i-1], clsfr_[i]);
00084         clsfr_[len-1]->install(istr[len-1], target);
00085 }
00086 
00087 void HierClassifier::set_table_size(int level, int size)
00088 {
00089         if (clsfr_[level-1])
00090                 clsfr_[level-1]->set_table_size(size);
00091 }
00092 
00093                 
00094 
00095 static class HierClassifierClass : public TclClass {
00096 public:
00097         HierClassifierClass() : TclClass("Classifier/Hier") {}
00098         TclObject* create(int argc, const char*const* argv) {
00099                 return (new HierClassifier());
00100         }
00101 } class_hier_classifier;
00102 
00103 
00104 

Generated on Tue Apr 20 12:14:12 2004 for NS2.26SourcesOriginal by doxygen 1.3.3