classifier-addr-mpls.h
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:7k
源码类别:

通讯编程

开发平台:

Visual C++

  1. // -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*-
  2. /*
  3.  * classifier-addr-mpls.h
  4.  * Copyright (C) 2000 by the University of Southern California
  5.  * $Id: classifier-addr-mpls.h,v 1.5 2005/08/25 18:58:09 johnh Exp $
  6.  *
  7.  * This program is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU General Public License,
  9.  * version 2, as published by the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License along
  17.  * with this program; if not, write to the Free Software Foundation, Inc.,
  18.  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  19.  *
  20.  *
  21.  * The copyright of this module includes the following
  22.  * linking-with-specific-other-licenses addition:
  23.  *
  24.  * In addition, as a special exception, the copyright holders of
  25.  * this module give you permission to combine (via static or
  26.  * dynamic linking) this module with free software programs or
  27.  * libraries that are released under the GNU LGPL and with code
  28.  * included in the standard release of ns-2 under the Apache 2.0
  29.  * license or under otherwise-compatible licenses with advertising
  30.  * requirements (or modified versions of such code, with unchanged
  31.  * license).  You may copy and distribute such a system following the
  32.  * terms of the GNU GPL for this module and the licenses of the
  33.  * other code concerned, provided that you include the source code of
  34.  * that other code when and as the GNU GPL requires distribution of
  35.  * source code.
  36.  *
  37.  * Note that people who make modified versions of this module
  38.  * are not obligated to grant this special exception for their
  39.  * modified versions; it is their choice whether to do so.  The GNU
  40.  * General Public License gives permission to release a modified
  41.  * version without this exception; this exception also makes it
  42.  * possible to release a modified version which carries forward this
  43.  * exception.
  44.  *
  45.  */
  46. //
  47. // Other copyrights might apply to parts of this software and are so
  48. // noted when applicable.
  49. //
  50. // Original source contributed by Gaeil Ahn. See below.
  51. //
  52. // $Header: /cvsroot/nsnam/ns-2/mpls/classifier-addr-mpls.h,v 1.5 2005/08/25 18:58:09 johnh Exp $
  53. /**************************************************************************
  54. * Copyright (c) 2000 by Gaeil Ahn                                      *
  55. * Everyone is permitted to copy and distribute this software.   *
  56. * Please send mail to fog1@ce.cnu.ac.kr when you modify or distribute     *
  57. * this sources.   *
  58. **************************************************************************/
  59. /***********************************************************
  60. *                                                          *
  61. *    File: Header File for packet switching in MPLS node   *
  62. *    Author: Gaeil Ahn (fog1@ce.cnu.ac.kr), Dec. 1999      *
  63. *                                                          *
  64. ***********************************************************/
  65. #ifndef ns_classifier_addr_mpls_h
  66. #define ns_classifier_addr_mpls_h
  67. #include "address.h"
  68. #include "classifier-addr.h"
  69. #include "tclcl.h"
  70. const int MPLS_MaxPFTEntryNB = 100;
  71. const int MPLS_MaxLIBEntryNB = 100;
  72. const int MPLS_MaxERBEntryNB = 100;
  73. const int MPLS_MINIMUM_LSPID = 1000;
  74. const int MPLS_DEFAULT_PHB = -1;
  75. const int MPLS_DONTCARE = -77;
  76. const int MPLS_GOTO_L3 = -99;
  77. /* option for reroute scheme */
  78. const int MPLS_DROPPACKET = 0;
  79. const int MPLS_L3FORWARDING = 1;
  80. const int MPLS_MAKENEWLSP = 2;
  81. struct hdr_mpls {
  82. int  label_;
  83. int  bflag_;
  84. int  ttl_;
  85. hdr_mpls* nexthdr_;
  86. hdr_mpls* top_;
  87.   
  88. int& label() { return label_; }
  89. int& bflag() { return bflag_; }
  90. int& ttl()   { return ttl_;   }
  91. // Header access methods
  92. static int offset_; // required by PacketHeaderManager
  93. inline static int& offset() { return offset_; }
  94. inline static hdr_mpls* access(const Packet* p) {
  95. return (hdr_mpls*)p->access(offset_);
  96. }
  97. };
  98. struct PFTEntry {
  99. int  FEC_;
  100. int  PHB_;
  101. int  LIBptr_;
  102. int  aPATHptr_;     // altanative path 
  103. };
  104. struct PFT {
  105. PFTEntry Entry_[MPLS_MaxPFTEntryNB];
  106. int NB_;
  107. };
  108. struct ERBEntry {
  109. int LSPid_;
  110. int FEC_;
  111. int LIBptr_;
  112. };
  113. struct ERB {
  114. ERBEntry Entry_[MPLS_MaxERBEntryNB];
  115. int NB_;
  116. };
  117. struct LIBEntry {
  118. int iIface_;
  119. int iLabel_;
  120. int oIface_;
  121. int oLabel_;
  122. int LIBptr_;    // for push operation
  123. };
  124. struct LIB {
  125. LIBEntry Entry_[MPLS_MaxLIBEntryNB];
  126. int NB_;
  127. };
  128. struct PktInfo
  129. {
  130. ns_addr_t dst_;
  131. int srcnode_;
  132. int phb_;
  133. hdr_mpls* shimhdr_;     // altanative path 
  134. };
  135. class MPLSAddressClassifier : public AddressClassifier {
  136. public: 
  137. MPLSAddressClassifier();
  138. virtual int command(int argc, const char*const* argv);
  139. // Static configuration variables. Exposed to OTcl via methods in 
  140. // MPLSNodeClass (see mpls-node.cc)
  141. static int ordered_control_;
  142. static int on_demand_;
  143. protected:
  144. virtual void install(int slot, NsObject *target);
  145. virtual int classify(Packet* p);
  146. int MPLSclassify(Packet* p);
  147.     
  148. int processIP();
  149. int processLabelP();
  150.     
  151. int convertL2toL2(int iLabel, int oIface, int oLabel, int LIBptr);
  152. int convertL3toL2(int oIface, int oLabel, int LIBptr);
  153.     
  154. void GetIPInfo(Packet* p, ns_addr_t& dstaddr, int& phb, int& srcnode);
  155. hdr_mpls* checkTTL(hdr_mpls* shimhdr);
  156.     
  157. hdr_mpls* GetShimHeader(Packet* p);
  158. hdr_mpls* DelAllShimHeader(hdr_mpls* shimhdr);
  159. hdr_mpls* push(hdr_mpls* shimhdr, int oLabel);
  160. hdr_mpls* pop(hdr_mpls* shimhdr);
  161. void swap(hdr_mpls* shimhdr, int oLabel) {
  162. shimhdr->label_ = oLabel;
  163. }
  164.     
  165. void PFTinsert(int FEC, int PHB, int LIBptr);
  166. void PFTdelete(int entrynb);
  167. void PFTdeleteLIBptr(int LIBptr);
  168. void PFTupdate(int entrynb, int LIBptr);
  169. int PFTlocate(int FEC, int PHB, int &LIBptr);
  170. int PFTlookup(int FEC, int PHB, int &oIface, 
  171.       int &oLabel, int &LIBptr);
  172. void ERBinsert(int LSPid, int FEC, int LIBptr);
  173. void ERBdelete(int entrynb);
  174. void ERBupdate(int entrynb, int LIBptr);
  175. int ERBlocate(int LSPid, int FEC, int &LIBptr);
  176.     
  177. int LIBinsert(int iIface, int iLabel, int oIface, int oLabel);
  178. int LIBisdeleted(int entrynb);
  179. void LIBupdate(int entrynb, int iIface, int iLabel, 
  180.        int oIface, int oLabel);
  181. int LIBlookup(int entrynb, int& oIface, int& oLabel, int& LIBptr);
  182. int LIBlookup(int iIface, int iLabel, 
  183.       int& oIface, int& oLabel, int& LIBptr);
  184. int LIBgetIncoming(int entrynb, int& iIface, int& iLabel);
  185.     
  186. int ErLspBinding(int FEC,int PHB, int erFEC, int LSPid);
  187. int ErLspStacking(int erFEC0, int erLSPid0, int erFEC, int erLSPid);
  188. int FlowAggregation(int fineFEC, int finePHB, int coarseFEC,
  189.     int coarsePHB);
  190. int aPathBinding(int FEC, int PHB, int erFEC,int LSPid);
  191. int aPathLookup(int FEC, int PHB, 
  192. int& oIface, int& oLabel, int& LIBptr);
  193. int is_link_down(int node);
  194. int do_reroute(Packet* p);
  195.        
  196. void PFTdump(const char* id);
  197. void ERBdump(const char* id);
  198. void LIBdump(const char* id);
  199. void trace(char* ptype, int psize, int ilabel, char *op, 
  200.    int oiface, int olabel, int ttl);
  201.     
  202. // Hash mapping between neighbors and LDP agents
  203. virtual void delay_bind_init_all();
  204. virtual int delay_bind_dispatch(const char*, const char*, TclObject*);
  205. int size_;
  206. int ttl_;
  207. int label_;
  208. int enable_reroute_;
  209. int reroute_option_;
  210.     
  211. int trace_mpls_;
  212. private:
  213. // Some states
  214. int data_driven_;
  215. int control_driven_;
  216. LIB     LIB_;
  217. PFT     PFT_;
  218. ERB     ERB_;
  219. PktInfo  PI_;
  220. };
  221. #endif