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

addr-params.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:53:32 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 // Address parameters. Singleton class
00030 //
00031 // $Header: /nfs/jade/vint/CVSROOT/ns-2/routing/addr-params.cc,v 1.2 2000/09/15 20:31:56 haoboy Exp $
00032 
00033 #include <stdlib.h>
00034 #include <tclcl.h>
00035 
00036 #include "addr-params.h"
00037 
00038 AddrParamsClass* AddrParamsClass::instance_ = NULL;
00039 
00040 static AddrParamsClass addr_params_class;
00041 
00042 void AddrParamsClass::bind()
00043 {
00044         TclClass::bind();
00045         add_method("McastShift");
00046         add_method("McastMask");
00047         add_method("NodeShift");
00048         add_method("NodeMask");
00049         add_method("PortMask");
00050         add_method("PortShift");
00051         add_method("hlevel");
00052         add_method("nodebits");
00053 }
00054 
00055 int AddrParamsClass::method(int ac, const char*const* av)
00056 {
00057         Tcl& tcl = Tcl::instance();
00058         int argc = ac - 2;
00059         const char*const* argv = av + 2;
00060 
00061         if (argc == 2) {
00062                 if (strcmp(argv[1], "McastShift") == 0) {
00063                         tcl.resultf("%d", McastShift_);
00064                         return (TCL_OK);
00065                 } else if (strcmp(argv[1], "McastMask") == 0) {
00066                         tcl.resultf("%d", McastMask_);
00067                         return (TCL_OK);
00068                 } else if (strcmp(argv[1], "PortShift") == 0) {
00069                         tcl.resultf("%d", PortShift_);
00070                         return (TCL_OK);
00071                 } else if (strcmp(argv[1], "PortMask") == 0) {
00072                         tcl.resultf("%d", PortMask_);
00073                         return (TCL_OK);
00074                 } else if (strcmp(argv[1], "hlevel") == 0) {
00075                         tcl.resultf("%d", hlevel_);
00076                         return (TCL_OK);
00077                 } else if (strcmp(argv[1], "nodebits") == 0) {
00078                         tcl.resultf("%d", nodebits_);
00079                         return (TCL_OK);
00080                 }
00081         } else if (argc == 3) {
00082                 if (strcmp(argv[1], "McastShift") == 0) {
00083                         McastShift_ = atoi(argv[2]);
00084                         return (TCL_OK);
00085                 } else if (strcmp(argv[1], "McastMask") == 0) {
00086                         McastMask_ = atoi(argv[2]);
00087                         return (TCL_OK);
00088                 } else if (strcmp(argv[1], "PortShift") == 0) {
00089                         PortShift_ = atoi(argv[2]);
00090                         return (TCL_OK);
00091                 } else if (strcmp(argv[1], "PortMask") == 0) {
00092                         PortMask_ = atoi(argv[2]);
00093                         return (TCL_OK);
00094                 } else if (strcmp(argv[1], "hlevel") == 0) {
00095                         hlevel_ = atoi(argv[2]);
00096                         if (NodeMask_ != NULL)
00097                                 delete []NodeMask_;
00098                         if (NodeShift_ != NULL)
00099                                 delete []NodeShift_;
00100                         NodeMask_ = new int[hlevel_];
00101                         NodeShift_ = new int[hlevel_];
00102                         return (TCL_OK);
00103                 } else if (strcmp(argv[1], "nodebits") == 0) {
00104                         nodebits_ = atoi(argv[2]);
00105                         return (TCL_OK);
00106                 } else if (strcmp(argv[1], "NodeShift") == 0) {
00107                         tcl.resultf("%d", node_shift(atoi(argv[2])-1));
00108                         return (TCL_OK);
00109                 } else if (strcmp(argv[1], "NodeMask") == 0) {
00110                         tcl.resultf("%d", node_mask(atoi(argv[2])-1));
00111                         return (TCL_OK);
00112                 }
00113         } else if (argc == 4) {
00114                 if (strcmp(argv[1], "NodeShift") == 0) {
00115                         NodeShift_[atoi(argv[2])-1] = atoi(argv[3]);
00116                         return (TCL_OK);
00117                 } else if (strcmp(argv[1], "NodeMask") == 0) {
00118                         NodeMask_[atoi(argv[2])-1] = atoi(argv[3]);
00119                         return (TCL_OK);
00120                 }
00121         }
00122         return TclClass::method(ac, av);
00123 }

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