mpls-module.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  * Copyright (C) 2000 by the University of Southern California
00005  * $Id: mpls-module.cc,v 1.4 2005/08/25 18:58:09 johnh Exp $
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License,
00009  * version 2, as published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with this program; if not, write to the Free Software Foundation, Inc.,
00018  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00019  *
00020  *
00021  * The copyright of this module includes the following
00022  * linking-with-specific-other-licenses addition:
00023  *
00024  * In addition, as a special exception, the copyright holders of
00025  * this module give you permission to combine (via static or
00026  * dynamic linking) this module with free software programs or
00027  * libraries that are released under the GNU LGPL and with code
00028  * included in the standard release of ns-2 under the Apache 2.0
00029  * license or under otherwise-compatible licenses with advertising
00030  * requirements (or modified versions of such code, with unchanged
00031  * license).  You may copy and distribute such a system following the
00032  * terms of the GNU GPL for this module and the licenses of the
00033  * other code concerned, provided that you include the source code of
00034  * that other code when and as the GNU GPL requires distribution of
00035  * source code.
00036  *
00037  * Note that people who make modified versions of this module
00038  * are not obligated to grant this special exception for their
00039  * modified versions; it is their choice whether to do so.  The GNU
00040  * General Public License gives permission to release a modified
00041  * version without this exception; this exception also makes it
00042  * possible to release a modified version which carries forward this
00043  * exception.
00044  *
00045  */
00046 
00047 /*
00048  * $Header: /nfs/jade/vint/CVSROOT/ns-2/mpls/mpls-module.cc,v 1.4 2005/08/25 18:58:09 johnh Exp $
00049  *
00050  * MPLS node plugin module
00051  */
00052 
00053 #include <tclcl.h>
00054 
00055 #include "node.h"
00056 #include "mpls/ldp.h"
00057 #include "mpls/mpls-module.h"
00058 #include "mpls/classifier-addr-mpls.h"
00059 
00060 static class MPLSModuleClass : public TclClass {
00061 public:
00062     MPLSModuleClass() : TclClass("RtModule/MPLS") {}
00063     TclObject* create(int, const char*const*) {
00064         return (new MPLSModule);
00065     }
00066 } class_mpls_module;
00067 
00068 MPLSModule::~MPLSModule() 
00069 {
00070     // Delete LDP agent list
00071     LDPListElem *e;
00072     for (LDPListElem *p = ldplist_.lh_first; p != NULL; ) {
00073         e = p;
00074         p = p->link.le_next;
00075         delete e;
00076     }
00077 }
00078 
00079 void MPLSModule::detach_ldp(LDPAgent *a)
00080 {
00081     for (LDPListElem *p = ldplist_.lh_first; p != NULL; 
00082          p = p->link.le_next)
00083         if (p->agt_ == a) {
00084             LIST_REMOVE(p, link);
00085             delete p;
00086             break;
00087         }
00088 }
00089 
00090 LDPAgent* MPLSModule::exist_ldp(int nbr)
00091 {
00092     for (LDPListElem *p = ldplist_.lh_first; p != NULL; 
00093          p = p->link.le_next)
00094         if (p->agt_->peer() == nbr)
00095             return p->agt_;
00096     return NULL;
00097 }
00098 
00099 int MPLSModule::command(int argc, const char*const* argv)
00100 {
00101     Tcl& tcl = Tcl::instance();
00102     if (argc == 2) {
00103         if (strcmp(argv[1], "new-incoming-label") == 0) {
00104             tcl.resultf("%d", ++last_inlabel_);
00105             return (TCL_OK);
00106         } else if (strcmp(argv[1], "new-outgoing-label") == 0) {
00107             tcl.resultf("%d", --last_outlabel_);
00108             return (TCL_OK);
00109         } else if (strcmp(argv[1], "get-ldp-agents") == 0) {
00110             for (LDPListElem *e = ldplist_.lh_first; e != NULL;
00111                  e = e->link.le_next)
00112                 tcl.resultf("%s %s", tcl.result(), 
00113                         e->agt_->name());
00114             return (TCL_OK);
00115         } else if (strcmp(argv[1], "trace-ldp") == 0) {
00116             for (LDPListElem *e = ldplist_.lh_first; e != NULL;
00117                  e = e->link.le_next)
00118                 e->agt_->turn_on_trace();
00119             return (TCL_OK);
00120         } else if (strcmp(argv[1], "trace-msgtbl") == 0) {
00121             printf("%d : message-table\n", node()->nodeid());
00122             for (LDPListElem *e = ldplist_.lh_first; e != NULL;
00123                  e = e->link.le_next)
00124                 e->agt_->MSGTdump();
00125             return (TCL_OK);
00126         }
00127     } else if (argc == 3) {
00128         if (strcmp(argv[1], "attach-ldp") == 0) {
00129             LDPAgent *a = (LDPAgent*)TclObject::lookup(argv[2]);
00130             if (a == NULL) {
00131                 fprintf(stderr,"Wrong object name %s",argv[2]);
00132                 return (TCL_ERROR);
00133             }
00134             attach_ldp(a);
00135             return (TCL_OK);
00136         } else if (strcmp(argv[1], "detach-ldp") == 0) {
00137             LDPAgent *a = (LDPAgent*)TclObject::lookup(argv[2]);
00138             if (a == NULL) {
00139                 fprintf(stderr,"Wrong object name %s",argv[2]);
00140                 return (TCL_ERROR);
00141             }
00142             detach_ldp(a);
00143             return (TCL_OK);
00144         } else if (strcmp(argv[1], "exist-ldp-agent") == 0) {
00145             tcl.resultf("%d", 
00146                     exist_ldp(atoi(argv[2])) == NULL ? 0 : 1 );
00147             return (TCL_OK);
00148         } else if (strcmp(argv[1], "get-ldp-agent") == 0) {
00149             LDPAgent *a = exist_ldp(atoi(argv[2]));
00150             if (a == NULL)
00151                 tcl.result("");
00152             else 
00153                 tcl.resultf("%s", a->name());
00154             return (TCL_OK);
00155         }
00156         else if (strcmp(argv[1] , "route-notify") == 0) {
00157             Node *node = (Node *)(TclObject::lookup(argv[2]));
00158             if (node == NULL) {
00159                 tcl.add_errorf("Invalid node object %s", argv[2]);
00160                 return TCL_ERROR;
00161             }
00162             if (node != n_) {
00163                 tcl.add_errorf("Node object %s different from n_", argv[2]);
00164                 return TCL_ERROR;
00165             }
00166             n_->route_notify(this);
00167             return TCL_OK;
00168         }
00169         if (strcmp(argv[1] , "unreg-route-notify") == 0) {
00170             Node *node = (Node *)(TclObject::lookup(argv[2]));
00171             if (node == NULL) {
00172                 tcl.add_errorf("Invalid node object %s", argv[2]);
00173                 return TCL_ERROR;
00174             }
00175             if (node != n_) {
00176                 tcl.add_errorf("Node object %s different from n_", argv[2]);
00177                 return TCL_ERROR;
00178             }
00179             n_->unreg_route_notify(this);
00180             return TCL_OK;
00181         }
00182         else if (strcmp(argv[1], "attach-classifier") == 0) {
00183             classifier_ = (MPLSAddressClassifier*)(TclObject::lookup(argv[2]));
00184             if (classifier_ == NULL) {
00185                 tcl.add_errorf("Wrong object name %s",argv[2]);
00186                 return TCL_ERROR;
00187             }
00188             return TCL_OK;
00189         }
00190     }
00191     return RoutingModule::command(argc, argv);
00192 }
00193 
00194 void MPLSModule::add_route(char *dst, NsObject *target) {
00195     if (classifier_) 
00196         ((MPLSAddressClassifier *)classifier_)->do_install(dst, target);
00197     if (next_rtm_ != NULL)
00198         next_rtm_->add_route(dst, target); 
00199 }

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