📄 classifier-addr-mpls.cc
字号:
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; } */ for (int i = Lptr_; 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_; Lptr_ = i + 1;printf("find one match i=%d,Lptr_=%d\n",i,Lptr_); 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");}// new LIB opeartorint MPLSAddressClassifier::LIBdelete(int iLabel , int oIface)
{
if ((iLabel < 0))
return -1;
for (int i = 0; i < LIB_.NB_; i++) {
if ((LIB_.Entry_[i].iLabel_ == iLabel) && (LIB_.Entry_[i].oIface_ == oIface)) {
LIB_.Entry_[i].iLabel_ = -1;
LIB_.Entry_[i].iIface_ = -1;
LIB_.Entry_[i].oLabel_ = -1;
LIB_.Entry_[i].oIface_ = -1;
LIB_.Entry_[i].LIBptr_ = -1;
return 0;
}
}
return -1;
}int MPLSAddressClassifier::LIBgetAll(int entrynb, int &iIface, int &iLabel , int &oIface, int &oLabel, int &LIBptr )
{
if (entrynb < 0)
return -1;
iIface = LIB_.Entry_[entrynb].iIface_;
iLabel = LIB_.Entry_[entrynb].iLabel_;
oIface = LIB_.Entry_[entrynb].oIface_;
oLabel = LIB_.Entry_[entrynb].oLabel_;
LIBptr = LIB_.Entry_[entrynb].LIBptr_;
return 0;
}int MPLSAddressClassifier::LIBisbranching(int Source, int Group)
{
// the origal vision /* int check;
if (iLabel < 0)
return -1;
for (int i = 0; i < LIB_.NB_; i++)
if ((LIB_.Entry_[i].iLabel_ == iLabel)) {
++check;
}*/ //maybe this is right too; if ((Source < 0) || (Group < 0))
return -1; int check = 0; int iLabel = -1,iIface = -1; if ((iLabel = LSGSGlookup(iIface, iLabel, Source, Group)) == 0) {
for (int i = 0; i < LIB_.NB_; i++)
if ((LIB_.Entry_[i].iLabel_ == iLabel)) {
++check;
} } if (check > 1)
return check;
return -1;
/* if ((Source < 0) || (Group < 0))
return -1; int check, iIface,iLabel; if ((iLabel = LSGSGlookup(iIface, iLabel, Source, Group)) == 0) {
check = LSGlabellookup(-1, iLabel, Source, Group)
if (check > 1)
return check; }
return -1;*/
}//*******************************for multicast*******************************************//--------------------------------------------------// LSG (Multicast Forward Table)//--------------------------------------------------//There maybe be still many errors in following functions, need be modified during process.int MPLSAddressClassifier::LSGinsert(int iIface, int iLabel, int Source, int Group){//the contral for err is needed, but here i simply it becasue i think 100 is to large for a group at one node and it //couldn't be exhausted//************************************************************ if (LSG_.NB_ == MPLS_MaxLSGEntryNB - 1) { fprintf(stderr, "Error in LSGinstall: higher than MaxLSGEntryNB\n"); return -1; }//************************************************************ LSG_.Entry_[LSG_.NB_].iIface_ = -1; LSG_.Entry_[LSG_.NB_].iLabel_ = -1; LSG_.Entry_[LSG_.NB_].Source_ = -1; LSG_.Entry_[LSG_.NB_].Group_ = -1; LSG_.Entry_[LSG_.NB_].Num_ = -1; if (iIface < 0) iIface = -1; if (iLabel < 0) iLabel = -1; if (Source < 0) Source = -1; if (Group < 0) Group = -1; LSG_.Entry_[LSG_.NB_].iIface_ = iIface; LSG_.Entry_[LSG_.NB_].iLabel_ = iLabel; LSG_.Entry_[LSG_.NB_].Source_ = Source; LSG_.Entry_[LSG_.NB_].Group_ = Group; LSG_.Entry_[LSG_.NB_].Num_ = 1; LSG_.NB_++; return(LSG_.NB_-1);}//it need modify if needint MPLSAddressClassifier::LSGdelete(int Source, int Group){ if ((Source < 0) || (Group < 0))
return -1; for (int i = 0; i < LSG_.NB_; i++) {
if ((LSG_.Entry_[i].Group_ == Group) && (LSG_.Entry_[i].Source_ == Source)) { LSG_.Entry_[i].iIface_ = -1; LSG_.Entry_[i].iLabel_ = -1; LSG_.Entry_[i].Source_ = -1; LSG_.Entry_[i].Group_ = -1; return 0; } } return -1;}int MPLSAddressClassifier::LSGisdeleted(int entrynb)
{
if ((LSG_.Entry_[entrynb].iIface_ == -1) &&
(LSG_.Entry_[entrynb].iLabel_ == -1) &&
(LSG_.Entry_[entrynb].Source_ == -1) &&
(LSG_.Entry_[entrynb].Group_ == -1)) {
return 0;
}
return -1;
}int MPLSAddressClassifier::LSGlabellookup(int iIface, int iLabel, int &Source, int &Group){ Source = Group = -1; if (iLabel < 0) //the condition maybe need to be modified return -1; if (LSG_.NB_ == 0) //at this condition, LSG is empty and no multicast group return -1; for (int i = 0; i < LSG_.NB_; i++) //if ((LSG_.Entry_[i].iIface_ == iIface) && (LSG_.Entry_[i].iIface_ == iIface)) //if (LSG_.Entry_[i].iLabel_ == iLabel) if ((LSG_.Entry_[i].iLabel_ == iLabel) && ((LSG_.Entry_[i].iIface_ == iIface) || (LSG_.Entry_[i].iIface_ == -1) || (iIface == -1)) ) { Source = LSG_.Entry_[i].Source_; Group = LSG_.Entry_[i].Group_; return LSG_.Entry_[i].Num_; } return -1;}void MPLSAddressClassifier::LSGupdate(int entrynb, int iIface, int iLabel,
int Source, int Group)
{
if (iIface != MPLS_DONTCARE)
LSG_.Entry_[entrynb].iIface_ = iIface;
if (iLabel != MPLS_DONTCARE)
LSG_.Entry_[entrynb].iLabel_ = iLabel;
if (Source != MPLS_DONTCARE)
LSG_.Entry_[entrynb].Source_ = Source;
if (Group != MPLS_DONTCARE)
LSG_.Entry_[entrynb].Group_ = Group;
}int MPLSAddressClassifier::MyLSGupdate(int Source, int Group, int flag) //use for add or subtract num of next node{ for (int i = 0; i < LSG_.NB_; i++) if ((LSG_.Entry_[i].Source_ == Source) && (LSG_.Entry_[i].Group_ == Group)) //if (LSG_.Entry_[i].Group_ == Group) { if (flag = 1) LSG_.Entry_[i].Num_ += 1; //join else if ((LSG_.Entry_[i].Num_ = LSG_.Entry_[i].Num_ - 1) == 0) //prune LSGdelete(Source, Group); return 0; } return -1;}int MPLSAddressClassifier::LSGlookup(int entrynb, int &Source, int &Group)
{
Source = Group = -1;
if (entrynb < 0)
return -1;
Source = LSG_.Entry_[entrynb].Source_;
Group = LSG_.Entry_[entrynb].Group_;
return 0;
}//this function maybe be used at join timeint MPLSAddressClassifier::LSGSGlookup(int &iIface, int &iLable, int Source, int Group){ iLable = iIface = -1; if ((Source < 0)||(Group < 0)) //the condition need be modified return -1; for (int i = 0; i < LSG_.NB_; i++) if ((LSG_.Entry_[i].Source_ == Source) && (LSG_.Entry_[i].Group_ == Group)) { iLable = LSG_.Entry_[i].iLabel_; iIface = LSG_.Entry_[i].iIface_; return 0; } return -1;}int MPLSAddressClassifier::LSGexist(int Group){ if (Group < 0) return -1; for (int i = 0; i < LSG_.NB_; i++) if (LSG_.Entry_[i].Group_ == Group) { return (LSG_.Entry_[i].Num_ + 1); } return -1; }void MPLSAddressClassifier::LSGdump(const char* id){ fflush(stdout); printf(" --) ___LSG dump___ [node: %s] (--\n", id); printf("-------------------------------------------------------\n"); printf(" iIface iLable Source Group Num\n"); for (int i = 0; i < LSG_.NB_; i++) { // if (LSG_.Entry_[i].iIface_ == -1) //the condition need be modified// continue; printf(" %d ", LSG_.Entry_[i].iIface_); printf(" %d ", LSG_.Entry_[i].iLabel_); printf(" %d ", LSG_.Entry_[i].Source_); printf(" %d ", LSG_.Entry_[i].Group_); printf(" %d\n", LSG_.Entry_[i].Num_); } 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 + -