⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classifier-addr-mpls.cc

📁 c++编写应用于ns环境下的关于MPLS网络中的多播路由算法
💻 CC
📖 第 1 页 / 共 4 页
字号:
				tcl.result("1");			else     				tcl.result("-1");			return (TCL_OK);		}	} else if (argc == 6) {		// <classifier> ErLspStacking fec0 erlspid0 fec erfecid		if (strcmp(argv[1], "ErLspStacking") == 0) {			int erfec0   = atoi(argv[2]);			int erlspid0 = atoi(argv[3]);			int erfec    = atoi(argv[4]);			int erlspid  = atoi(argv[5]);			if (ErLspStacking(erfec0,erlspid0,erfec,erlspid) == 0)				tcl.result("1");			else     				tcl.result("-1");			return (TCL_OK);		} else if (strcmp(argv[1], "FlowAggregation") == 0) {			// <classifier> FlowAggregation <fineFEC> <finePHB>			//              <coarseFEC> <coarsePHB>			int fineaddr   = atoi(argv[2]);			int finePHB    = atoi(argv[3]);			int coarseaddr = atoi(argv[4]);			int coarsePHB  = atoi(argv[5]);			if (FlowAggregation(fineaddr, finePHB, coarseaddr,					    coarsePHB) == 0)				tcl.result("1");			else     				tcl.result("-1");			return (TCL_OK);		} else if (strcmp(argv[1], "aPathBinding") == 0) {			// <classifier> aPathBinding <FEC> <PHB> 			// <erFEC> <LSPid>			int FEC   = atoi(argv[2]);			int PHB   = atoi(argv[3]);			int erFEC = atoi(argv[4]);			int LSPid = atoi(argv[5]);			if (aPathBinding(FEC, PHB, erFEC, LSPid) == 0)				tcl.result("1");			else     				tcl.result("-1");			return (TCL_OK);		}		//*****************************LSG command********************		 else if (strcmp(argv[1], "installLSG") == 0) {
			// <classifier> installSG <iIface> <iLabel> 
			// <Source> <Group>
			int iIface = atoi(argv[2]);
			int iLabel = atoi(argv[3]);
			int Source = atoi(argv[4]);
			int Group = atoi(argv[5]);
			int check;
			check = LSGinsert(iIface, iLabel, Source, Group);
			//if (check == 0)			if (check)
				tcl.result ("1");
			else     
				tcl.result("-1");
			return (TCL_OK);
		} else if (strcmp(argv[1], "installLIB") == 0) {
			// <classifier> installLIB <Iface> <iLabel> 
			// <oIface> <oLabel>
			int iIface = atoi(argv[2]);
			int iLabel = atoi(argv[3]);
			int oIface = atoi(argv[4]);
			int oLabel = atoi(argv[5]);
			int check;
			check = LIBinsert(iIface, iLabel, oIface, oLabel) == 0;
			if (check)
				tcl.result("1");
			else     
				tcl.result("-1");
			return (TCL_OK);
		}		//************************************************************					} else if (argc == 7) {      	  //**********************************************setLSG************************				if (strcmp(argv[1], "LSG") == 0) {		//<classifier> SetLSG <iIface> <iLabel> <source> <group> <flag>		//		int iIface = atoi(argv[2]);		int iLabel = atoi(argv[3]);		int Source = atoi(argv[4]);		int Group  = atoi(argv[5]);		int flag   = atoi(argv[6]);                     //1 join, -1 prune		if (flag == 1) {		   if (MyLSGupdate(Source,Group,1) == -1)		     LSGinsert(iIface, iLabel, Source, Group);		   }  		else		   MyLSGupdate(Source,Group,-1);				return (TCL_OK);		}				//************************************************************************************			  	  	} else if (argc == 8) {      		int addr  = atoi(argv[2]);		int LSPid = atoi(argv[3]);		int PHB   = LSPid;		int LIBptr, PFTnb,ERBnb ;		if (LSPid == MPLS_DEFAULT_PHB)   // topology-based LSP			PFTnb = PFTlocate(addr,PHB,LIBptr);		else                // ER-LSP			ERBnb = ERBlocate(LSPid,addr,LIBptr);				if (strcmp(argv[1], "LSPrelease") == 0) {			// <classifier> LSPrelease <fec> <lspid> <iif> 			// 	<ilabel> <oif> <olabel>			if (LSPid < 0) {				// Topology-based LSP				if (PFTnb >= 0) {					// PFT entry exist					LIBupdate(LIBptr, atoi(argv[4]), 						  atoi(argv[5]), atoi(argv[6]),						  atoi(argv[7]));					if (LIBisdeleted(LIBptr) == 0)						PFTdeleteLIBptr(LIBptr);				}			} else {				// ER-LSP				if ( ERBnb >= 0 ) {					// ERB entry exist					LIBupdate(LIBptr, atoi(argv[4]),						  atoi(argv[5]), atoi(argv[6]),						  atoi(argv[7]));					if (LIBisdeleted(LIBptr) == 0) {						ERBdelete(ERBnb);						PFTdeleteLIBptr(LIBptr);					}				}			}			return (TCL_OK);        		} else if (strcmp(argv[1], "LSPsetup") == 0) {			// <classifier> LSPsetup <fec> <lspid> <iif> 			//     <ilabel> <oif> <olabel>			if (LSPid == MPLS_DEFAULT_PHB) {				// Topology-based LSP				if (PFTnb < 0) {					// PFT entry not exist					int ptr = LIBinsert(atoi(argv[4]),							    atoi(argv[5]),							    atoi(argv[6]),							    atoi(argv[7]));					if (ptr > -1) {						PFTinsert(addr, 							  MPLS_DEFAULT_PHB,							  ptr);						return (TCL_OK);					} else						return (TCL_ERROR);				}				// PFTnb >= 0				// PFT entry already exist				if (LIBptr <= -1) {					int ptr = LIBinsert(atoi(argv[4]),							    atoi(argv[5]),							    atoi(argv[6]),							    atoi(argv[7]));					if (ptr > -1) {						PFTupdate(PFTnb, ptr);						return (TCL_OK);					} else						return (TCL_ERROR);					}				// LIBptr > -1				// Check whether or not altanative path setup				if (!((enable_reroute_ == 1) &&				      (LIB_.Entry_[LIBptr].oIface_ > -1) && 				      (reroute_option_ == MPLS_MAKENEWLSP) &&				      (atoi(argv[6]) > -1) && 				      (is_link_down(LIB_.Entry_[LIBptr].oIface_))				      )) { 					LIBupdate(LIBptr, atoi(argv[4]),						  atoi(argv[5]), atoi(argv[6]),						  atoi(argv[7]));					return (TCL_OK);				}				PFT_.Entry_[PFTnb].aPATHptr_ = 					LIBinsert(atoi(argv[4]), atoi(argv[5]),						  atoi(argv[6]),atoi(argv[7]));				for (int i=0; i < LIB_.NB_; i++) {					if (LIB_.Entry_[i].oIface_!=atoi(argv[2]))						continue;					for (int k=0; k<PFT_.NB_; k++) {						if (PFT_.Entry_[k].LIBptr_ != i)							continue;						PFT_.Entry_[k].aPATHptr_ = 						  PFT_.Entry_[PFTnb].aPATHptr_;					}				}				return (TCL_OK);			}			// LSPid != MPLS_DEFAULT_PHB			// ER-LSP			if (ERBnb < 0) {				// ERB entry not exist				int ptr = LIBinsert(atoi(argv[4]),						    atoi(argv[5]),						    atoi(argv[6]),						    atoi(argv[7]));				if (ptr > -1) {					ERBinsert(LSPid,addr,ptr);					return (TCL_OK);				} else					return (TCL_ERROR);			} 			// ERBnb >= 0			// ERB entry already exist			if (LIBptr > -1)				LIBupdate(LIBptr, atoi(argv[4]), atoi(argv[5]),					  atoi(argv[6]), atoi(argv[7]));			else {				int ptr = 					LIBinsert(atoi(argv[4]),atoi(argv[5]),						  atoi(argv[6]),atoi(argv[7]));				if (ptr > -1)					ERBupdate(ERBnb, ptr);				else					return (TCL_ERROR);			}			return (TCL_OK);		}//***************************************************************************************  	} else if (argc == 9) {      	  //**********************************************setLSG************************     if (strcmp(argv[1], "SetLSG") == 0) {			// <classifier> SetLSG <source><group> <iif> 			//     <ilabel> <oif> <olabel><flag>			int Source  = atoi(argv[2]);			int Group  = atoi(argv[3]);		  int iIface = atoi(argv[4]);		  int iLabel = atoi(argv[5]);		  int oIface = atoi(argv[6]);		  int oLabel  = atoi(argv[7]);		  int flag   = atoi(argv[8]);                     //1 join, -1 prune//printf("iIface=%d,iLabel=%d,oIface=%d,oLabel=%d,flag=%d\n",iIface,iLabel,oIface,oLabel,flag);		  if (flag == 1) {int i,j;		  if ((i = MyLSGupdate(Source,Group,1)) == -1)		     j = LSGinsert(iIface, iLabel,Source, Group);//printf("i=%d,j=%d\n",i,j);//printf("LSG_.NB_=%d\n",LSG_.NB_);//printf("LSG_.Entry_[0].Group_=%d\n",LSG_.Entry_[0].Group_);                  int ptr = LIBinsert(iIface, iLabel, oIface, oLabel);		  } else if (MyLSGupdate(Source,Group,-1) == -1){                      LSGdelete(Source, Group);                      //modify LIB                  }		 //printf("ptr=%d",ptr);		                				  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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -