📄 ldp.cc
字号:
// -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*-/* * ldp.cc * Copyright (C) 2000 by the University of Southern California * $Id: ldp.cc,v 1.9 2005/08/25 18:58:09 johnh Exp $ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * * * The copyright of this module includes the following * linking-with-specific-other-licenses addition: * * In addition, as a special exception, the copyright holders of * this module give you permission to combine (via static or * dynamic linking) this module with free software programs or * libraries that are released under the GNU LGPL and with code * included in the standard release of ns-2 under the Apache 2.0 * license or under otherwise-compatible licenses with advertising * requirements (or modified versions of such code, with unchanged * license). You may copy and distribute such a system following the * terms of the GNU GPL for this module and the licenses of the * other code concerned, provided that you include the source code of * that other code when and as the GNU GPL requires distribution of * source code. * * Note that people who make modified versions of this module * are not obligated to grant this special exception for their * modified versions; it is their choice whether to do so. The GNU * General Public License gives permission to release a modified * version without this exception; this exception also makes it * possible to release a modified version which carries forward this * exception. * *///// Original source contributed by Gaeil Ahn. See below.//// $Header: /cvsroot/nsnam/ns-2/mpls/ldp.cc,v 1.9 2005/08/25 18:58:09 johnh Exp $/*************************************************************************** Copyright (c) 2000 by Gaeil Ahn ** Everyone is permitted to copy and distribute this software. ** Please send mail to fog1@ce.cnu.ac.kr when you modify or distribute ** this sources. ***************************************************************************//************************************************************ ** File: File for LDP & CR-LDP protocol ** Author: Gaeil Ahn (fog1@ce.cnu.ac.kr), Jan. 2000 ** ************************************************************/#include "config.h"#include <iostream>#include "ldp.h"int hdr_ldp::offset_;static class LDPHeaderClass : public PacketHeaderClass {public: LDPHeaderClass() : PacketHeaderClass("PacketHeader/LDP", sizeof(hdr_ldp)) { bind_offset(&hdr_ldp::offset_); }} class_ldphdr;static class LDPClass : public TclClass {public: LDPClass() : TclClass("Agent/LDP") {} TclObject* create(int, const char*const*) { return (new LDPAgent()); }} class_agentldp;LDPAgent::LDPAgent() : Agent(PT_LDP), new_msgid_(0), trace_ldp_(0), peer_(0){ MSGT_.NB = 0;}void LDPAgent::delay_bind_init_all(){ delay_bind_init_one("trace_ldp_"); Agent::delay_bind_init_all();}int LDPAgent::delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer){ if (delay_bind_bool(varName,localName,"trace_ldp_",&trace_ldp_,tracer)) return TCL_OK; return Agent::delay_bind_dispatch(varName, localName, tracer);}int LDPAgent::PKTsize(const char *pathvec, const char *er){ // header size for Version, PDU Length, and LDP Identifier int psize = 10; // size for message type and message id psize += 8; int len = strlen(pathvec); if (len > 1) { psize += 4; // size for path vector header for (int i=0; i<len; i++) if ( *(pathvec+i) == ' ' ) { psize += 4; // size for path vector data } } len = strlen(er); if (len > 1) { psize += 4; // size for explicit route header for (int i=0; i<len; i++) if (*(er+i) == ' ') psize += 4; // size for explicit route data } return (psize);}void LDPAgent::PKTinit(hdr_ldp *hdrldp, int msgtype, const char *pathvec, const char *er){ hdrldp->msgtype = msgtype; hdrldp->msgid = new_msgid_; hdrldp->fec = -1; hdrldp->label = -1; hdrldp->reqmsgid= -1; hdrldp->status = -1; int i; int len = strlen(pathvec); hdrldp->pathvec = (char *) malloc(len+1); for (i=0; i<len; i++) { if ( *(pathvec+i) == ' ' ) *(hdrldp->pathvec+i) = '_'; else *(hdrldp->pathvec+i) = *(pathvec+i); } *(hdrldp->pathvec+len) = '\0'; len = strlen(er); hdrldp->er = (char *) malloc(len+1); for (i=0; i<len; i++) { if ( *(er+i) == ' ' ) *(hdrldp->er+i) = '_'; else *(hdrldp->er+i) = *(er+i); } *(hdrldp->er+len) = '\0'; hdrldp->lspid = -1; hdrldp->rc = -1;}int LDPAgent::command(int argc, const char*const* argv){ Tcl& tcl = Tcl::instance(); if (argc == 2) { if (strcmp(argv[1], "msgtbl-dump") == 0) { MSGTdump(); return (TCL_OK); } else if (strcmp(argv[1], "new-msgid") == 0) { tcl.resultf("%d", ++new_msgid_); return (TCL_OK); } else if (strcmp(argv[1], "peer-ldpnode") == 0) { tcl.resultf("%d", peer_); return (TCL_OK); } } else if (argc == 3) { if (strcmp(argv[1], "set-peer") == 0) { peer_ = atoi(argv[2]); return (TCL_OK); } // The following is shared by all if-s in this branch int MsgID = atoi(argv[2]); int msgid,fec,lspid,src,pmsgid,labelop; int entrynb = MSGTlocate(MsgID); MSGTlookup(entrynb,msgid,fec,lspid,src,pmsgid,labelop); if (strcmp(argv[1], "msgtbl-clear") == 0) { /* <agent> MSGTdelete MsgID */ if (entrynb > -1) MSGTdelete(entrynb); return (TCL_OK); } else if (strcmp(argv[1], "msgtbl-get-src") == 0) { /* <agent> GetMSGTsrc MsgID */ tcl.resultf("%d", src); return (TCL_OK); } else if (strcmp(argv[1], "msgtbl-get-reqmsgid") == 0) { /* <agent> GetMSGTpmsgid msgid */ tcl.resultf("%d",pmsgid); return (TCL_OK); } else if (strcmp(argv[1], "msgtbl-get-labelop") == 0) { /* <agent> GetMSGTlabelpass msgid */ tcl.resultf("%d", labelop); return (TCL_OK); } else if (strcmp(argv[1], "msgtbl-get-erlspid") == 0) { /* * <agent> msgtbl-get-erlspid <msgid> */ tcl.resultf("%d",MSGT_.Entry[entrynb].ERLspID); return (TCL_OK); } else if (strcmp(argv[1], "msgtbl-set-labelpass") == 0) { /* * <agent> msgtbl-set-labelpass <msgid> */ MSGT_.Entry[entrynb].LabelOp = LDP_LabelPASS; return (TCL_OK); } } else if (argc == 4) { if (strcmp(argv[1], "notification-msg") == 0) { /* * <agent> notification-msg <status> <lspid> */ size_ = PKTsize("*", "*"); if ( atoi(argv[3]) > -1 ) /* packet size adjustment */ size_ += 16; else size_ += 8; Packet* pkt = allocpkt(); hdr_ldp *hdrldp = hdr_ldp::access(pkt); PKTinit(hdrldp, LDP_NotificationMSG, "*", "*"); if (strcmp(argv[2], "LoopDetected") == 0) hdrldp->status = LDP_LoopDetected; else if (strcmp(argv[2], "NoRoute") == 0) hdrldp->status = LDP_NoRoute; hdrldp->lspid = atoi(argv[3]); send(pkt, 0); return (TCL_OK); } else if (strcmp(argv[1], "withdraw-msg") == 0) { /* * <agent> withdraw-msg <fec> <lspid> */ size_ = PKTsize("*","*"); if ( atoi(argv[3]) > -1 ) /* packet size adjustment */ size_ += 16; else size_ += 8; Packet* pkt = allocpkt(); hdr_ldp *hdrldp = hdr_ldp::access(pkt); PKTinit(hdrldp, LDP_WithdrawMSG, "*", "*"); hdrldp->fec = atoi(argv[2]); hdrldp->lspid = atoi(argv[3]); send(pkt, 0); return (TCL_OK); } else if (strcmp(argv[1], "release-msg") == 0) { /* * <agent> release-msg <fec> <lspid> */ size_ = PKTsize("*","*"); if ( atoi(argv[3]) > -1 ) /* packet size adjustment */ size_ += 16; else size_ += 8; Packet* pkt = allocpkt(); hdr_ldp *hdrldp = hdr_ldp::access(pkt); PKTinit(hdrldp, LDP_ReleaseMSG,"*","*"); hdrldp->fec = atoi(argv[2]); hdrldp->lspid = atoi(argv[3]); send(pkt, 0); return (TCL_OK); } else if (strcmp(argv[1], "request-msg") == 0) { /* * <agent> request-msg <fec> <pathvec> */ size_ = PKTsize(argv[3],"*"); size_ += 8; /* packet size adjustment */ Packet* pkt = allocpkt(); hdr_ldp *hdrldp = hdr_ldp::access(pkt); PKTinit(hdrldp, LDP_RequestMSG, argv[3], "*"); hdrldp->fec = atoi(argv[2]); send(pkt, 0); return (TCL_OK); } else if (strcmp(argv[1], "msgtbl-set-labelstack") == 0) { /* * <agent> msgtbl-set-labelstack <msgid> <erlspid> */ int MsgID = atoi(argv[2]); int ERLspID = atoi(argv[3]); int entrynb = MSGTlocate(MsgID); MSGT_.Entry[entrynb].LabelOp = LDP_LabelSTACK; MSGT_.Entry[entrynb].ERLspID = ERLspID; return (TCL_OK); } } else if (argc == 5) { if (strcmp(argv[1], "msgtbl-get-msgid") == 0) { /* * <classifier> msgtbl-get-msgid <FEC> <LspID> <Src> */ int msgid,tmp; int fec = atoi(argv[2]); int LspID = atoi(argv[3]); int src = atoi(argv[4]); int entrynb = MSGTlocate(fec,LspID,src); MSGTlookup(entrynb,msgid,tmp,tmp,tmp,tmp,tmp); tcl.resultf("%d", msgid);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -