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

📄 classifier-addr-mpls.cc

📁 MPLS中 基于地址分类的 源代码
💻 CC
📖 第 1 页 / 共 3 页
字号:
	shimhdr->ttl_--;	int ttl   = shimhdr->ttl_;	int iLabel= shimhdr->label_;   	if (ttl == 0) {		shimhdr = DelAllShimHeader(shimhdr);		trace("L", size_, iLabel, "L3(TTL=0)", -1, -1, ttl);	}	return shimhdr;}void MPLSAddressClassifier::GetIPInfo(Packet* p, ns_addr_t &dst,				      int &phb, int &srcnode){	hdr_ip* iphdr = hdr_ip::access(p);	dst = iphdr->dst_;	srcnode = iphdr->src_.addr_;	phb = MPLS_DEFAULT_PHB;}hdr_mpls *MPLSAddressClassifier::GetShimHeader(Packet* p){	hdr_mpls *shimhdr = hdr_mpls::access(p);	size_ = 0;	if ((shimhdr->label_ == 0) && (shimhdr->bflag_ == 0) && 	    (shimhdr->ttl_ == 0)) {		shimhdr->bflag_ = -1;		shimhdr->label_ = -1;		shimhdr->ttl_ = -1;		shimhdr->top_    = shimhdr;		shimhdr->nexthdr_= shimhdr;	} else {		while (shimhdr->top_ != shimhdr) { 			shimhdr = shimhdr->top_;			size_ += 4;		}	} 	return shimhdr;}hdr_mpls *MPLSAddressClassifier::DelAllShimHeader(hdr_mpls *shimhdr){	while (shimhdr->bflag_ != -1)		shimhdr = pop(shimhdr);	return(shimhdr);}hdr_mpls *MPLSAddressClassifier::push(hdr_mpls *shimhdr, int oLabel){	hdr_mpls *newhdr;	newhdr = (hdr_mpls *) malloc( sizeof(hdr_mpls) );	newhdr->label_ = oLabel;	newhdr->bflag_ = 1;	newhdr->ttl_ = ttl_;	newhdr->top_  = newhdr;	newhdr->nexthdr_ = shimhdr;	shimhdr->top_ = newhdr;	size_ += 4;    	return newhdr;}hdr_mpls *MPLSAddressClassifier::pop(hdr_mpls *shimhdr){	shimhdr = shimhdr->nexthdr_;	free(shimhdr->top_);	shimhdr->top_ = shimhdr;	size_ -= 4;	return shimhdr;}void MPLSAddressClassifier::install(int slot, NsObject *target) {	Tcl& tcl = Tcl::instance();	if ((slot >= 0) && (slot < nslot_) && 	    (slot_[slot] != NULL)) {		if (strcmp(slot_[slot]->name(), target->name()) != 0)			tcl.evalf("%s routing-update %d %.15g",				  name(), slot,				  Scheduler::instance().clock());		else			tcl.evalf("%s routing-nochange %d %.15g",				  name(), slot,				  Scheduler::instance().clock());	} else		tcl.evalf("%s routing-new %d %.15g",			  name(), slot,			  Scheduler::instance().clock());	Classifier::install(slot,target);}int MPLSAddressClassifier::command(int argc, const char*const* argv){	Tcl& tcl = Tcl::instance();	if (argc == 2) {		if (strcmp(argv[1], "control-driven?") == 0) {			tcl.resultf("%d", control_driven_);			return (TCL_OK);		} else if (strcmp(argv[1], "data-driven?") == 0) {			tcl.resultf("%d", data_driven_);			return (TCL_OK);		} else if (strcmp(argv[1], "enable-control-driven") == 0) {			// XXX data-driven and control-driven triggers are			// exclusive 			control_driven_ = 1;			data_driven_ = 0;			return (TCL_OK);		} else if (strcmp(argv[1], "enable-data-driven") == 0) {			control_driven_ = 0;			data_driven_ = 1;			return (TCL_OK);		}	} else if (argc == 3) {      		if (strcmp(argv[1], "PFTdump") == 0) {			// <classifier> PFTdump nodeid*/			PFTdump(argv[2]);			return (TCL_OK);		} else if (strcmp(argv[1], "ERBdump") == 0) {			ERBdump(argv[2]);			return (TCL_OK);		} else if (strcmp(argv[1], "LIBdump") == 0) {			LIBdump(argv[2]);			return (TCL_OK);		} else if (strcmp(argv[1], "get-fec-for-lspid") == 0) {			// <classifier get-fec-for-lspid LSPid			int LSPid  = atoi(argv[2]);			int LIBptr = -1;			int ERBnb;			ERBnb = ERBlocate(LSPid, -1, LIBptr);			if (ERBnb >= 0)				tcl.resultf("%d", ERB_.Entry_[ERBnb].FEC_);			else   				tcl.result("-1");			return (TCL_OK);		} 	} else if (argc == 4) {		if (strcmp(argv[1], "exist-fec") == 0) {			// <classifier> exist-fec <fec> <phb>			int LIBptr;			int PFTnb = PFTlocate(atoi(argv[2]), atoi(argv[3]),					      LIBptr);         			if (PFTnb > -1)				tcl.result("1");			else				tcl.result("-1");			return (TCL_OK);		}		int PFTnb = -1;		int LIBptr = -1;		int iLabel, oLabel, iIface, oIface;		int fec   = atoi(argv[2]);		int LSPid = atoi(argv[3]);		int PHB   = LSPid;		if (LSPid < 0)     // topology-based LSP			PFTnb = PFTlocate(fec,PHB, LIBptr);		else               // ER-LSP			ERBlocate(LSPid,fec, LIBptr);		if (strcmp(argv[1], "GetInIface") == 0) {			// <classifier> GetInIface <FEC> <LSPid>			if (LIBptr > -1) {				LIBgetIncoming(LIBptr,iIface,iLabel);				tcl.resultf("%d", iIface);			} else				tcl.result("-1");			return (TCL_OK);		} else if (strcmp(argv[1], "GetInLabel") == 0) {			// <classifier> GetInLabel <FEC> <LSPid>			if (LIBptr > -1) {				LIBgetIncoming(LIBptr,iIface,iLabel);				tcl.resultf("%d", iLabel);			} else 				tcl.result("-1");			return (TCL_OK);		} else if (strcmp(argv[1], "GetOutIface") == 0) {			// <classifier> GetOutIface <FEC> <phb/LSPid>			if (LIBptr > -1) {				LIBlookup(LIBptr, oIface, oLabel, LIBptr);				tcl.resultf("%d", oIface);			} else				tcl.result("-1");			return (TCL_OK);		} else if (strcmp(argv[1], "GetOutLabel") == 0) {			// <classifier> GetOutLabel <FEC> <phb/LSPid>			if (LIBptr > -1) {				LIBlookup(LIBptr, oIface, oLabel, LIBptr);				tcl.resultf("%d", oLabel);			} else				tcl.result("-1");			return (TCL_OK);		} else if (strcmp(argv[1], "install") == 0) { 			int slot = atoi(argv[2]);			//if ((slot >= 0) && (slot < nslot_) && 			//  (slot_[slot] != NULL)) {			//	if (strcmp(slot_[slot]->name(),argv[3]) != 0)			//		tcl.evalf("%s routing-update %s %.15g",			//			  name(), argv[2],			//			Scheduler::instance().clock());			//	else			//	      tcl.evalf("%s routing-nochange %s %.15g",			//			name(), argv[2],			//			Scheduler::instance().clock());			//} else			//	tcl.evalf("%s routing-new %s %.15g",			//		  name(), argv[2],			//		  Scheduler::instance().clock());			// Then the control is passed on the the base			// address classifier!			//return AddressClassifier::command(argc, argv);			//not a good idea since it would start an infinite loop incase MPLSAddressClassifier::install is defined; 			//so call Classifier::install explicitly.			NsObject* target = (NsObject*)TclObject::lookup(argv[3]);			//Classifier::install(slot, target);			install(slot,target);			return (TCL_OK);		}	} else if (argc == 5) {      		if (strcmp(argv[1], "ErLspBinding") == 0) {			// <classifier> ErLspBinding <FEC> <PHB> <lspid>			int addr   = atoi(argv[2]);			int PHB    = atoi(argv[3]);			int LSPid  = atoi(argv[4]);			if ( !ErLspBinding(addr, PHB,-1, LSPid) )				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);		}	} else if (argc == 8) {      		int addr  = atoi(argv[2]);		int LSPid = atoi(argv[3]);		int LIBptr;		if (LSPid == MPLS_DEFAULT_PHB)  {			// topology-based LSP			int PHB   = LSPid;			int PFTnb = PFTlocate(addr,PHB,LIBptr);			if (strcmp(argv[1], "LSPrelease") == 0) {				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);				}				return (TCL_OK);			} else if (strcmp(argv[1], "LSPsetup") == 0) {				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);			}		} else {			// ER-LSP			int ERBnb = ERBlocate(LSPid,addr,LIBptr);			if (strcmp(argv[1], "LSPrelease") == 0) {				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) {				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]));

⌨️ 快捷键说明

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