📄 classifier-addr-mpls.cc
字号:
if (ptr > -1) ERBupdate(ERBnb, ptr); else return (TCL_ERROR); } return (TCL_OK); } } } return (AddressClassifier::command(argc, argv));}//--------------------------------------------------// PFT(Partial Forwarding Table)//--------------------------------------------------void MPLSAddressClassifier::PFTinsert(int FEC, int PHB, int LIBptr){ PFT_.Entry_[PFT_.NB_].FEC_ = FEC; PFT_.Entry_[PFT_.NB_].PHB_ = PHB; PFT_.Entry_[PFT_.NB_].LIBptr_ = LIBptr; PFT_.Entry_[PFT_.NB_].aPATHptr_ = -1; PFT_.NB_++;}void MPLSAddressClassifier::PFTdelete(int entrynb){ PFT_.Entry_[entrynb].FEC_ = -1; PFT_.Entry_[entrynb].PHB_ = -1; PFT_.Entry_[entrynb].LIBptr_ = -1;}void MPLSAddressClassifier::PFTdeleteLIBptr(int LIBptr){ for (int i = 0; i < PFT_.NB_; i++) { if (PFT_.Entry_[i].LIBptr_ != LIBptr) continue; PFT_.Entry_[i].FEC_ = -1; PFT_.Entry_[i].PHB_ = -1; PFT_.Entry_[i].LIBptr_ = -1; } }void MPLSAddressClassifier::PFTupdate(int entrynb, int LIBptr){ PFT_.Entry_[entrynb].LIBptr_ = LIBptr;}int MPLSAddressClassifier::PFTlocate(int FEC, int PHB, int &LIBptr){ LIBptr = -1; if (FEC < 0) return -1; for (int i = 0; i < PFT_.NB_; i++) if ((PFT_.Entry_[i].FEC_ == FEC) && (PFT_.Entry_[i].PHB_ == PHB)) { LIBptr = PFT_.Entry_[i].LIBptr_; return i; } return -1;}int MPLSAddressClassifier::PFTlookup(int FEC, int PHB, int &oIface, int &oLabel, int &LIBptr){ oIface = oLabel = LIBptr = -1; if (FEC < 0) return -1; for (int i = 0; i < PFT_.NB_; i++) if ((PFT_.Entry_[i].FEC_ == FEC) && (PFT_.Entry_[i].PHB_ == PHB)) return LIBlookup(PFT_.Entry_[i].LIBptr_, oIface, oLabel, LIBptr); return -1;}void MPLSAddressClassifier::PFTdump(const char *id){ fflush(stdout); printf(" --) ___PFT dump___ [node: %s] (--\n", id); printf("---------------------------------------------\n"); printf(" FEC PHB LIBptr AltanativePath\n"); for (int i = 0; i < PFT_.NB_; i++) { if (PFT_.Entry_[i].FEC_ == -1) continue; printf(" %d ", PFT_.Entry_[i].FEC_); printf(" %d ", PFT_.Entry_[i].PHB_); printf(" %d ", PFT_.Entry_[i].LIBptr_); printf(" %d\n", PFT_.Entry_[i].aPATHptr_); } printf("\n");}//--------------------------------------------------// ER-LSP Table//--------------------------------------------------void MPLSAddressClassifier::ERBinsert(int LSPid, int FEC, int LIBptr){ ERB_.Entry_[ERB_.NB_].LSPid_ = LSPid; ERB_.Entry_[ERB_.NB_].FEC_ = FEC; ERB_.Entry_[ERB_.NB_].LIBptr_ = LIBptr; ERB_.NB_++;} void MPLSAddressClassifier::ERBdelete(int entrynb){ ERB_.Entry_[entrynb].FEC_ = -1; ERB_.Entry_[entrynb].LSPid_ = -1; ERB_.Entry_[entrynb].LIBptr_ = -1;}void MPLSAddressClassifier::ERBupdate(int entrynb, int LIBptr){ ERB_.Entry_[entrynb].LIBptr_ = LIBptr;}int MPLSAddressClassifier::ERBlocate(int LSPid, int FEC, int &LIBptr){ LIBptr = -1; for (int i = 0; i < ERB_.NB_; i++) if (ERB_.Entry_[i].LSPid_ == LSPid) { LIBptr = ERB_.Entry_[i].LIBptr_; return(i); } return -1;}void MPLSAddressClassifier::ERBdump(const char *id){ fflush(stdout); printf(" --) ___ERB dump___ [node: %s] (--\n", id); printf("---------------------------------------------\n"); printf(" FEC LSPid LIBptr\n"); for (int i = 0; i < ERB_.NB_; i++) { if (ERB_.Entry_[i].FEC_ == -1) continue; printf(" %d ", ERB_.Entry_[i].FEC_); printf(" %d ", ERB_.Entry_[i].LSPid_); printf(" %d\n", ERB_.Entry_[i].LIBptr_); } printf("\n");}//--------------------------------------------------// LIB (Label Information Base)//--------------------------------------------------int MPLSAddressClassifier::LIBinsert(int iIface, int iLabel, int oIface, int oLabel){ if (LIB_.NB_ == MPLS_MaxLIBEntryNB - 1) { fprintf(stderr, "Error in LIBinstall: higher than MaxLIBEntryNB\n"); return -1; } LIB_.Entry_[LIB_.NB_].iIface_ = -1; LIB_.Entry_[LIB_.NB_].iLabel_ = -1; LIB_.Entry_[LIB_.NB_].oIface_ = -1; LIB_.Entry_[LIB_.NB_].oLabel_ = -1; if (iIface < 0) iIface = -1; if (iLabel < 0) iLabel = -1; if (oIface < 0) oIface = -1; if (oLabel < 0) oLabel = -1; LIB_.Entry_[LIB_.NB_].iIface_ = iIface; LIB_.Entry_[LIB_.NB_].iLabel_ = iLabel; LIB_.Entry_[LIB_.NB_].oIface_ = oIface; LIB_.Entry_[LIB_.NB_].oLabel_ = oLabel; LIB_.Entry_[LIB_.NB_].LIBptr_ = -1; LIB_.NB_++; return(LIB_.NB_-1);}int MPLSAddressClassifier::LIBisdeleted(int entrynb){ if ((LIB_.Entry_[entrynb].iIface_ == -1) && (LIB_.Entry_[entrynb].iLabel_ == -1) && (LIB_.Entry_[entrynb].oIface_ == -1) && (LIB_.Entry_[entrynb].oLabel_ == -1)) { LIB_.Entry_[entrynb].LIBptr_ = -1; // delete a entry referencing self in LIB for (int i = 0; i < LIB_.NB_; i++) if ((LIB_.Entry_[i].LIBptr_ == entrynb)) LIB_.Entry_[i].LIBptr_ = -1; return 0; } return -1;}void MPLSAddressClassifier::LIBupdate(int entrynb, int iIface, int iLabel, int oIface, int oLabel){ if (iIface != MPLS_DONTCARE) LIB_.Entry_[entrynb].iIface_ = iIface; if (iLabel != MPLS_DONTCARE) LIB_.Entry_[entrynb].iLabel_ = iLabel; if (oIface != MPLS_DONTCARE) LIB_.Entry_[entrynb].oIface_ = oIface; if (oLabel != MPLS_DONTCARE) LIB_.Entry_[entrynb].oLabel_ = oLabel;}int MPLSAddressClassifier::LIBlookup(int entrynb, int &oIface, int &oLabel, int &LIBptr){ oIface = oLabel = LIBptr = -1; if (entrynb < 0) return -1; oIface = LIB_.Entry_[entrynb].oIface_; oLabel = LIB_.Entry_[entrynb].oLabel_; LIBptr = LIB_.Entry_[entrynb].LIBptr_; return 0;}int MPLSAddressClassifier::LIBlookup(int iIface, int iLabel, int &oIface, int &oLabel, int &LIBptr){ oIface = oLabel = LIBptr = -1; if (iLabel < 0) return -1; for (int i = 0; i < LIB_.NB_; i++) if ((LIB_.Entry_[i].iLabel_ == iLabel)) { oIface = LIB_.Entry_[i].oIface_; oLabel = LIB_.Entry_[i].oLabel_; LIBptr = LIB_.Entry_[i].LIBptr_; return 0; } return -1;}int MPLSAddressClassifier::LIBgetIncoming(int entrynb, int &iIface, int &iLabel){ if (entrynb < 0) return -1; iIface = LIB_.Entry_[entrynb].iIface_; iLabel = LIB_.Entry_[entrynb].iLabel_; return 0;}void MPLSAddressClassifier::LIBdump(const char *id){ fflush(stdout); printf(" ___LIB dump___ [node: %s]\n", id); printf("---------------------------------------------\n"); printf(" # iIface iLabel oIface oLabel LIBptr\n"); for (int i = 0; i < LIB_.NB_; i++) { if (!LIBisdeleted(i)) continue; printf(" %d: ", i); printf(" %d ", LIB_.Entry_[i].iIface_); printf(" %d ", LIB_.Entry_[i].iLabel_); printf(" %d ", LIB_.Entry_[i].oIface_); printf(" %d ", LIB_.Entry_[i].oLabel_); printf(" %d\n", LIB_.Entry_[i].LIBptr_); } printf("\n");}//--------------------------------------------------// MPLS applications//--------------------------------------------------int MPLSAddressClassifier::ErLspStacking(int erFEC0,int erLSPid0, int erFEC, int erLSPid){ int erLIBptr0 =-1, erLIBptr =-1; if ((ERBlocate(erLSPid0,erFEC0,erLIBptr0) < 0) || (erLIBptr0 < 0)) return -1; if ((ERBlocate(erLSPid,erFEC,erLIBptr) < 0) || (erLIBptr < 0)) return -1; LIB_.Entry_[erLIBptr0].LIBptr_ = erLIBptr; return 0;}int MPLSAddressClassifier::ErLspBinding(int FEC,int PHB, int erFEC, int LSPid){ int LIBptr=-1; int erLIBptr=-1; if ((ERBlocate(LSPid, erFEC, erLIBptr) < 0) || (erLIBptr < 0)) return -1; int PFTnb = PFTlocate(FEC,PHB, LIBptr); if ((PFTnb < 0)) PFTinsert(FEC,PHB, erLIBptr); else { if (LIBptr < 0) PFTupdate(PFTnb, LIBptr); else { int i = LIBptr; while (i < 0) { LIBptr = i;; i = LIB_.Entry_[LIBptr].LIBptr_; } LIB_.Entry_[LIBptr].LIBptr_ = erLIBptr; } } return 0;}int MPLSAddressClassifier::FlowAggregation(int fineFEC, int finePHB, int coarseFEC, int coarsePHB){ int fLIBptr=-1; int cLIBptr=-1; if ((PFTlocate(coarseFEC,coarsePHB, cLIBptr) < 0) || (cLIBptr < 0)) return -1; int PFTnb = PFTlocate(fineFEC,finePHB, fLIBptr); if ((PFTnb < 0)) PFTinsert(fineFEC,finePHB, cLIBptr); else { if (fLIBptr < 0) PFTupdate(PFTnb, cLIBptr); else { int i=fLIBptr; while (i < 0) { fLIBptr = i;; i = LIB_.Entry_[fLIBptr].LIBptr_; } LIB_.Entry_[fLIBptr].LIBptr_ = cLIBptr; } } return 0;}int MPLSAddressClassifier::aPathBinding(int FEC, int PHB, int erFEC, int LSPid){ int entrynb,tmp,erLIBptr; entrynb = PFTlocate(FEC,PHB,tmp); if ((entrynb < 0) || (ERBlocate(LSPid,erFEC,erLIBptr) < 0)) return -1; PFT_.Entry_[entrynb].aPATHptr_ = erLIBptr; return 0;}int MPLSAddressClassifier::aPathLookup(int FEC,int PHB, int &oIface, int &oLabel, int &LIBptr){ oIface = oLabel = LIBptr = -1; if (FEC < 0) return -1; for (int i = 0; i < PFT_.NB_; i++) if ((PFT_.Entry_[i].FEC_ == FEC) && (PFT_.Entry_[i].PHB_ == PHB)) return LIBlookup(PFT_.Entry_[i].aPATHptr_, oIface, oLabel, LIBptr); return -1;}void MPLSAddressClassifier::trace(char *ptype, int psize, int ilabel, char *op, int oiface, int olabel, int ttl){ if (trace_mpls_ != 1) return; Tcl::instance().evalf("%s trace-packet-switching " TIME_FORMAT " %d %d %s %d %s %d %d %d %d", name(), Scheduler::instance().clock(), PI_.srcnode_, PI_.dst_.addr_, ptype, ilabel, op, oiface, olabel, ttl, psize);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -