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 
00006 /*
00007  * addr-params.cc
00008  * Copyright (C) 2000 by the University of Southern California
00009  * $Id: addr-params.cc,v 1.3 2005/08/25 18:58:12 johnh Exp $
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License,
00013  * version 2, as published by the Free Software Foundation.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License along
00021  * with this program; if not, write to the Free Software Foundation, Inc.,
00022  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00023  *
00024  *
00025  * The copyright of this module includes the following
00026  * linking-with-specific-other-licenses addition:
00027  *
00028  * In addition, as a special exception, the copyright holders of
00029  * this module give you permission to combine (via static or
00030  * dynamic linking) this module with free software programs or
00031  * libraries that are released under the GNU LGPL and with code
00032  * included in the standard release of ns-2 under the Apache 2.0
00033  * license or under otherwise-compatible licenses with advertising
00034  * requirements (or modified versions of such code, with unchanged
00035  * license).  You may copy and distribute such a system following the
00036  * terms of the GNU GPL for this module and the licenses of the
00037  * other code concerned, provided that you include the source code of
00038  * that other code when and as the GNU GPL requires distribution of
00039  * source code.
00040  *
00041  * Note that people who make modified versions of this module
00042  * are not obligated to grant this special exception for their
00043  * modified versions; it is their choice whether to do so.  The GNU
00044  * General Public License gives permission to release a modified
00045  * version without this exception; this exception also makes it
00046  * possible to release a modified version which carries forward this
00047  * exception.
00048  *
00049  */
00050 
00051 //
00052 // Address parameters. Singleton class
00053 //
00054 // $Header: /nfs/jade/vint/CVSROOT/ns-2/routing/addr-params.cc,v 1.3 2005/08/25 18:58:12 johnh Exp $
00055 
00056 #include <stdlib.h>
00057 #include <tclcl.h>
00058 
00059 #include "addr-params.h"
00060 
00061 AddrParamsClass* AddrParamsClass::instance_ = NULL;
00062 
00063 static AddrParamsClass addr_params_class;
00064 
00065 void AddrParamsClass::bind()
00066 {
00067     TclClass::bind();
00068     add_method("McastShift");
00069     add_method("McastMask");
00070     add_method("NodeShift");
00071     add_method("NodeMask");
00072     add_method("PortMask");
00073     add_method("PortShift");
00074     add_method("hlevel");
00075     add_method("nodebits");
00076 }
00077 
00078 int AddrParamsClass::method(int ac, const char*const* av)
00079 {
00080     Tcl& tcl = Tcl::instance();
00081     int argc = ac - 2;
00082     const char*const* argv = av + 2;
00083 
00084     if (argc == 2) {
00085         if (strcmp(argv[1], "McastShift") == 0) {
00086             tcl.resultf("%d", McastShift_);
00087             return (TCL_OK);
00088         } else if (strcmp(argv[1], "McastMask") == 0) {
00089             tcl.resultf("%d", McastMask_);
00090             return (TCL_OK);
00091         } else if (strcmp(argv[1], "PortShift") == 0) {
00092             tcl.resultf("%d", PortShift_);
00093             return (TCL_OK);
00094         } else if (strcmp(argv[1], "PortMask") == 0) {
00095             tcl.resultf("%d", PortMask_);
00096             return (TCL_OK);
00097         } else if (strcmp(argv[1], "hlevel") == 0) {
00098             tcl.resultf("%d", hlevel_);
00099             return (TCL_OK);
00100         } else if (strcmp(argv[1], "nodebits") == 0) {
00101             tcl.resultf("%d", nodebits_);
00102             return (TCL_OK);
00103         }
00104     } else if (argc == 3) {
00105         if (strcmp(argv[1], "McastShift") == 0) {
00106             McastShift_ = atoi(argv[2]);
00107             return (TCL_OK);
00108         } else if (strcmp(argv[1], "McastMask") == 0) {
00109             McastMask_ = atoi(argv[2]);
00110             return (TCL_OK);
00111         } else if (strcmp(argv[1], "PortShift") == 0) {
00112             PortShift_ = atoi(argv[2]);
00113             return (TCL_OK);
00114         } else if (strcmp(argv[1], "PortMask") == 0) {
00115             PortMask_ = atoi(argv[2]);
00116             return (TCL_OK);
00117         } else if (strcmp(argv[1], "hlevel") == 0) {
00118             hlevel_ = atoi(argv[2]);
00119             if (NodeMask_ != NULL)
00120                 delete []NodeMask_;
00121             if (NodeShift_ != NULL)
00122                 delete []NodeShift_;
00123             NodeMask_ = new int[hlevel_];
00124             NodeShift_ = new int[hlevel_];
00125             return (TCL_OK);
00126         } else if (strcmp(argv[1], "nodebits") == 0) {
00127             nodebits_ = atoi(argv[2]);
00128             return (TCL_OK);
00129         } else if (strcmp(argv[1], "NodeShift") == 0) {
00130             tcl.resultf("%d", node_shift(atoi(argv[2])-1));
00131             return (TCL_OK);
00132         } else if (strcmp(argv[1], "NodeMask") == 0) {
00133             tcl.resultf("%d", node_mask(atoi(argv[2])-1));
00134             return (TCL_OK);
00135         }
00136     } else if (argc == 4) {
00137         if (strcmp(argv[1], "NodeShift") == 0) {
00138             NodeShift_[atoi(argv[2])-1] = atoi(argv[3]);
00139             return (TCL_OK);
00140         } else if (strcmp(argv[1], "NodeMask") == 0) {
00141             NodeMask_[atoi(argv[2])-1] = atoi(argv[3]);
00142             return (TCL_OK);
00143         }
00144     }
00145     return TclClass::method(ac, av);
00146 }

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