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

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  * Copyright (C) 2000 by USC/ISI
00004  * All rights reserved.                                            
00005  *                                                                
00006  * Redistribution and use in source and binary forms are permitted
00007  * provided that the above copyright notice and this paragraph are
00008  * duplicated in all such forms and that any documentation, advertising
00009  * materials, and other materials related to such distribution and use
00010  * acknowledge that the software was developed by the University of
00011  * Southern California, Information Sciences Institute.  The name of the
00012  * University may not be used to endorse or promote products derived from
00013  * this software without specific prior written permission.
00014  * 
00015  * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
00016  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00017  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00018  *
00019  * $Header: /nfs/jade/vint/CVSROOT/ns-2/mpls/mpls-module.cc,v 1.3 2001/02/22 19:45:40 haldar Exp $
00020  *
00021  * MPLS node plugin module
00022  */
00023 
00024 #include <tclcl.h>
00025 
00026 #include "node.h"
00027 #include "mpls/ldp.h"
00028 #include "mpls/mpls-module.h"
00029 #include "mpls/classifier-addr-mpls.h"
00030 
00031 static class MPLSModuleClass : public TclClass {
00032 public:
00033         MPLSModuleClass() : TclClass("RtModule/MPLS") {}
00034         TclObject* create(int, const char*const*) {
00035                 return (new MPLSModule);
00036         }
00037 } class_mpls_module;
00038 
00039 MPLSModule::~MPLSModule() 
00040 {
00041         // Delete LDP agent list
00042         LDPListElem *e;
00043         for (LDPListElem *p = ldplist_.lh_first; p != NULL; ) {
00044                 e = p;
00045                 p = p->link.le_next;
00046                 delete e;
00047         }
00048 }
00049 
00050 void MPLSModule::detach_ldp(LDPAgent *a)
00051 {
00052         for (LDPListElem *p = ldplist_.lh_first; p != NULL; 
00053              p = p->link.le_next)
00054                 if (p->agt_ == a) {
00055                         LIST_REMOVE(p, link);
00056                         delete p;
00057                         break;
00058                 }
00059 }
00060 
00061 LDPAgent* MPLSModule::exist_ldp(int nbr)
00062 {
00063         for (LDPListElem *p = ldplist_.lh_first; p != NULL; 
00064              p = p->link.le_next)
00065                 if (p->agt_->peer() == nbr)
00066                         return p->agt_;
00067         return NULL;
00068 }
00069 
00070 int MPLSModule::command(int argc, const char*const* argv)
00071 {
00072         Tcl& tcl = Tcl::instance();
00073         if (argc == 2) {
00074                 if (strcmp(argv[1], "new-incoming-label") == 0) {
00075                         tcl.resultf("%d", ++last_inlabel_);
00076                         return (TCL_OK);
00077                 } else if (strcmp(argv[1], "new-outgoing-label") == 0) {
00078                         tcl.resultf("%d", --last_outlabel_);
00079                         return (TCL_OK);
00080                 } else if (strcmp(argv[1], "get-ldp-agents") == 0) {
00081                         for (LDPListElem *e = ldplist_.lh_first; e != NULL;
00082                              e = e->link.le_next)
00083                                 tcl.resultf("%s %s", tcl.result(), 
00084                                             e->agt_->name());
00085                         return (TCL_OK);
00086                 } else if (strcmp(argv[1], "trace-ldp") == 0) {
00087                         for (LDPListElem *e = ldplist_.lh_first; e != NULL;
00088                              e = e->link.le_next)
00089                                 e->agt_->turn_on_trace();
00090                         return (TCL_OK);
00091                 } else if (strcmp(argv[1], "trace-msgtbl") == 0) {
00092                         printf("%d : message-table\n", node()->nodeid());
00093                         for (LDPListElem *e = ldplist_.lh_first; e != NULL;
00094                              e = e->link.le_next)
00095                                 e->agt_->MSGTdump();
00096                         return (TCL_OK);
00097                 }
00098         } else if (argc == 3) {
00099                 if (strcmp(argv[1], "attach-ldp") == 0) {
00100                         LDPAgent *a = (LDPAgent*)TclObject::lookup(argv[2]);
00101                         if (a == NULL) {
00102                                 fprintf(stderr,"Wrong object name %s",argv[2]);
00103                                 return (TCL_ERROR);
00104                         }
00105                         attach_ldp(a);
00106                         return (TCL_OK);
00107                 } else if (strcmp(argv[1], "detach-ldp") == 0) {
00108                         LDPAgent *a = (LDPAgent*)TclObject::lookup(argv[2]);
00109                         if (a == NULL) {
00110                                 fprintf(stderr,"Wrong object name %s",argv[2]);
00111                                 return (TCL_ERROR);
00112                         }
00113                         detach_ldp(a);
00114                         return (TCL_OK);
00115                 } else if (strcmp(argv[1], "exist-ldp-agent") == 0) {
00116                         tcl.resultf("%d", 
00117                                     exist_ldp(atoi(argv[2])) == NULL ? 0 : 1 );
00118                         return (TCL_OK);
00119                 } else if (strcmp(argv[1], "get-ldp-agent") == 0) {
00120                         LDPAgent *a = exist_ldp(atoi(argv[2]));
00121                         if (a == NULL)
00122                                 tcl.result("");
00123                         else 
00124                                 tcl.resultf("%s", a->name());
00125                         return (TCL_OK);
00126                 }
00127                 else if (strcmp(argv[1] , "route-notify") == 0) {
00128                         Node *node = (Node *)(TclObject::lookup(argv[2]));
00129                         if (node == NULL) {
00130                                 tcl.add_errorf("Invalid node object %s", argv[2]);
00131                                 return TCL_ERROR;
00132                         }
00133                         if (node != n_) {
00134                                 tcl.add_errorf("Node object %s different from n_", argv[2]);
00135                                 return TCL_ERROR;
00136                         }
00137                         n_->route_notify(this);
00138                         return TCL_OK;
00139                 }
00140                 if (strcmp(argv[1] , "unreg-route-notify") == 0) {
00141                         Node *node = (Node *)(TclObject::lookup(argv[2]));
00142                         if (node == NULL) {
00143                                 tcl.add_errorf("Invalid node object %s", argv[2]);
00144                                 return TCL_ERROR;
00145                         }
00146                         if (node != n_) {
00147                                 tcl.add_errorf("Node object %s different from n_", argv[2]);
00148                                 return TCL_ERROR;
00149                         }
00150                         n_->unreg_route_notify(this);
00151                         return TCL_OK;
00152                 }
00153                 else if (strcmp(argv[1], "attach-classifier") == 0) {
00154                         classifier_ = (MPLSAddressClassifier*)(TclObject::lookup(argv[2]));
00155                         if (classifier_ == NULL) {
00156                                 tcl.add_errorf("Wrong object name %s",argv[2]);
00157                                 return TCL_ERROR;
00158                         }
00159                         return TCL_OK;
00160                 }
00161         }
00162         return RoutingModule::command(argc, argv);
00163 }
00164 
00165 void MPLSModule::add_route(char *dst, NsObject *target) {
00166         if (classifier_) 
00167                 ((MPLSAddressClassifier *)classifier_)->do_install(dst, target);
00168         if (next_rtm_ != NULL)
00169                 next_rtm_->add_route(dst, target); 
00170 }

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