parentnode.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 
00006 /*
00007  * parentnode.cc
00008  * Copyright (C) 2000 by the University of Southern California
00009  * $Id: parentnode.cc,v 1.2 2005/08/25 18:58:02 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 // Other copyrights might apply to parts of this software and are so
00052 // noted when applicable.
00053 //
00054 #include "parentnode.h"
00055 
00056 class BcastAddressClassifier;
00057 
00058 static class LanNodeClass : public TclClass {
00059 public:
00060     LanNodeClass() : TclClass("LanNode") {}
00061     TclObject* create(int, const char*const*) {
00062                 return (new LanNode);
00063         }
00064 } class_lan_node;
00065 
00066 static class AbsLanNodeClass : public TclClass {
00067 public:
00068     AbsLanNodeClass() : TclClass("AbsLanNode") {}
00069     TclObject* create(int, const char*const*) {
00070                 return (new AbsLanNode);
00071         }
00072 } class_abslan_node;
00073 
00074 static class BroadcastNodeClass : public TclClass {
00075 public:
00076     BroadcastNodeClass() : TclClass("Node/Broadcast") {}
00077     TclObject* create(int, const char*const*) {
00078                 return (new BroadcastNode);
00079         }
00080 } class_broadcast_node;
00081 
00082 int LanNode::command(int argc, const char*const* argv) {
00083   if (argc == 3) {
00084     if (strcmp(argv[1], "addr") == 0) {
00085       address_ = Address::instance().str2addr(argv[2]);
00086       return TCL_OK;
00087     } else if (strcmp(argv[1], "nodeid") == 0) {
00088       nodeid_ = atoi(argv[2]);
00089       return TCL_OK;
00090     }
00091   }
00092   return ParentNode::command(argc,argv);
00093 }
00094 
00095 int AbsLanNode::command(int argc, const char*const* argv) {
00096   if (argc == 3) {
00097     if (strcmp(argv[1], "addr") == 0) {
00098       address_ = Address::instance().str2addr(argv[2]);
00099       return TCL_OK;
00100     } else if (strcmp(argv[1], "nodeid") == 0) {
00101       nodeid_ = Address::instance().str2addr(argv[2]);
00102       return TCL_OK;
00103     }
00104   }
00105   return ParentNode::command(argc,argv);
00106 }
00107 
00108 int BroadcastNode::command(int argc, const char*const* argv) {
00109   Tcl& tcl = Tcl::instance();
00110   if (argc == 3) {
00111     if (strcmp(argv[1], "addr") == 0) {
00112       address_ = Address::instance().str2addr(argv[2]);
00113       return TCL_OK;
00114     } 
00115     else if (strcmp(argv[1], "nodeid") == 0) {
00116       nodeid_ = Address::instance().str2addr(argv[2]);
00117       return TCL_OK;
00118     } 
00119     else if (strcmp(argv[1], "attach-classifier") == 0) {
00120       classifier_ = (BcastAddressClassifier*)(TclObject::lookup(argv[2]));
00121       if (classifier_ == NULL) {
00122     tcl.add_errorf("Wrong object name %s",argv[2]);
00123     return TCL_ERROR;
00124       }
00125       return TCL_OK;
00126     }
00127   }
00128   return ParentNode::command(argc,argv);
00129 }
00130 
00131 void BroadcastNode::add_route(char *dst, NsObject *target) {
00132   classifier_->do_install(dst,target);
00133 }
00134 
00135 void BroadcastNode::delete_route(char *dst, NsObject *nullagent) {
00136   classifier_->do_install(dst, nullagent); 
00137 }

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