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

📄 patch_gprs

📁 用C++编写的GPRS协议栈源代码
💻
📖 第 1 页 / 共 5 页
字号:
< 	downtarget_(0), uptarget_(0)---> 	downtarget_(0), uptarget_(0), acked_(1), lhSend_(this), acSend_(this),> 	datacounter(0), ackcounter(0), llfraged_(1), llfragsz_(300)72a109,114> 	bind("acked_", &acked_);> 	bind("llfraged_",&llfraged_);> 	bind("llfragsz_",&llfragsz_);>     bind("llverbose_",&llverbose_);> 	> 	buf_= new PacketQueue();138,139c180,181< 	//char *mh = (char*) HDR_MAC(p);< 	//struct hdr_sr *hsr = HDR_SR(p);---> 	hdr_ll *llh = HDR_LL(p);//sandy> 	hdr_ip *iph =HDR_IP(p);141,143c183,195< 	/*< 	 * Sanity Check< 	 */---> 	//giving mac a pointer to the ifq.rj> 	if ( mac_->q_ == 0 ) {> 		//printf ("<%d> %f LL: mac q doesnt exist\n", mac_->addr(), NOW);> 		mac_->q_= ifq_; //rj  > 		//printf("LL: mac q set \n ");> 	}	> 	> 	if (llverbose_==1) fprintf(stderr,"<%d> %f LL: recv. pkt_type=%s uid=%d seqno=%d bopno=%d eopno=%d ipsrc=%d ipdst=%d\n",> 			mac_->addr(), NOW, packet_info.name(ch->ptype()), ch->uid_, llh->seqno_, > 			llh->bopno_, llh->eopno_, Address::instance().get_nodeaddr(iph->saddr()), > 			Address::instance().get_nodeaddr(iph->daddr()));>     > 	// Sanity Check149,158c201,207< < 	// If direction = UP, then pass it up the stack< 	// Otherwise, set direction to DOWN and pass it down the stack< 	if(ch->direction() == hdr_cmn::UP) {< 		//if(mac_->hdr_type(mh) == ETHERTYPE_ARP)< 		if(ch->ptype_ == PT_ARP)< 			arptable_->arpinput(p, this);< 		else< 			uptarget_ ? sendUp(p) : drop(p);< 		return;---> //if arp packet send to approprite place  //sandy> 	if(ch->direction()==hdr_cmn::UP){> 			if(ch->ptype_ == PT_ARP){> 				if (llverbose_==1) fprintf(stderr,"<%d> %f LL: sent an ARP to arptable\n", mac_->addr(), NOW );> 				arptable_->arpinput(p, this);> 				return;> 			}159a209,213> //if ack pkt or data pkt...  //sandy> 	if(llh->lltype_==LL_ACK)> 		recvACK(p);> 	else> 		recvDATA(p);161,162d214< 	ch->direction() = hdr_cmn::DOWN;< 	sendDown(p);166,167c218,234< void LL::sendDown(Packet* p)< {	---> void LL::recvDATA(Packet* p)> {> 	hdr_cmn *ch = HDR_CMN(p);> 	> 	if(ch->direction() == hdr_cmn::UP){> 		if (llverbose_==1) fprintf(stderr,"<%d> %f LL:DATA on its way up. calling SendUpDATA\n", mac_->addr(), NOW );	> 		sendUpDATA(p);> 	}else{> 		ch->direction() = hdr_cmn::DOWN;> 		if (llverbose_==1) fprintf(stderr,"<%d> %f LL: DATA on its way down. calling enqueDATA\n", mac_->addr(), NOW );> 		enqueDATA(p);> 	}> }> > > void LL::enqueDATA(Packet* p)> {175a243> 177c245< 	llh->seqno_ = ++seqno_;---> //	llh->seqno_ = ++seqno_;179d246< 181a249,250> > //	moved below --sandy	223a293,336> 	if(tx==0)> 		fragDATA(p);> }> > void LL::fragDATA(Packet *p){> 	hdr_cmn *ch = HDR_CMN(p);> //fragmenting to start here....//sandy> 	int psize;> 		if (llfraged_==1)> 			psize=llfragsz_;> 		else> 			psize=ch->size_;> > > 		int bopno=seqno_;> 		int eopno=bopno + (int)((ch->size_-1)/psize);  > 		> 		int i=seqno_;> 		> 		if (llverbose_==1) fprintf(stderr,"<%d> %f LL: creating ll %d  fragments \n", mac_->addr(), NOW, eopno-bopno);> 		for ( i = bopno; i <= eopno; i++){> 			if (i==eopno)				//new changes for size -sandy> 				psize=ch->size_-(eopno-bopno)*psize;> 			> 			Packet * sp = p->copy();> 			hdr_cmn *chsp = HDR_CMN(sp);> 			hdr_ll *llhsp = HDR_LL(sp);> 			hdr_ip *ihsp = HDR_IP(sp);> 		> 			> 			llhsp->seqno_ = 0;> 			llhsp->bopno_ = bopno;> 			llhsp->eopno_ = eopno;> 			llhsp->psize_ = ch->size_;> 			chsp->size_  = psize;> 			> 			if((acked_==0)||(chsp->next_hop()==-1)){> 				if(i==eopno)> 					llhsp->seqno_=eopno;> 		> 				// XXX HACK for now - Padma, 03/99.> 				nsaddr_t dst = (nsaddr_t)Address::instance().get_nodeaddr(ihsp->daddr());> 				> 				int tx = 0;225,229c338,387< 	if (tx == 0) {< 		Scheduler& s = Scheduler::instance();< 	// let mac decide when to take a new packet from the queue.< 		s.schedule(downtarget_, p, delay_);< 	}---> 				switch(chsp->addr_type()) {> 				case NS_AF_ILINK:> 						mac_->hdr_dst((char*) HDR_MAC(sp), chsp->next_hop());> 						break;> > 				case NS_AF_INET:> 						dst = chsp->next_hop();> 						/* FALL THROUGH */> 		> 				case NS_AF_NONE:> 		> 						if (IP_BROADCAST == (u_int32_t) dst)> 						{> 							mac_->hdr_dst((char*) HDR_MAC(sp), MAC_BROADCAST);> 							break;> 						}> 						/* Assuming arptable is present, send query */> 						if (arptable_) {> 							tx = arptable_->arpresolve(dst, sp, this);> 							break;> 						}> 						/* FALL THROUGH */> > 				default:> 		> 					int IPnh = (lanrouter_) ? lanrouter_->next_hop(sp) : -1;> 					if (IPnh < 0)> 						mac_->hdr_dst((char*) HDR_MAC(sp),macDA_);> 					else if (varp_)> 						tx = varp_->arpresolve(IPnh, sp);> 					else> 						mac_->hdr_dst((char*) HDR_MAC(sp), IPnh);> 					break;> 				}> > 			if(tx==0){> 				Scheduler& s = Scheduler::instance();> 				s.schedule(downtarget_, sp, delay_);> 				if (llverbose_==1) fprintf(stderr,"<%d> %f LL: send down NON-ack uid=%d\n", mac_->addr(), NOW ,chsp->uid_);> 			}> 			}else{> 				llhsp->seqno_=i;> 				seqno_++;> 				buf_->enque(sp);    > 				if (llverbose_==1) fprintf(stderr,"<%d> %f LL: buffering ll_seq=%d pktuid=%d bufq_length=%d \n",> 						mac_->addr(), NOW, llhsp->seqno_, chsp->uid_, buf_->length() );> 			}> 		}	> 		if(acked_==1)> 			sendDownDATA();231a390,452> void LL::sendDownDATA(void)> {> 	Packet* sp;> 	if(!(sp = buf_->deque())){> 		if (llverbose_==1) fprintf(stderr,"<%d> %f LL: bufq is empty\n", mac_->addr(), NOW );> 		return;> 	}> 	> 	hdr_cmn *chsp = HDR_CMN(sp);> 	hdr_ll *llhsp = HDR_LL(sp);> 	hdr_ip *ihsp = HDR_IP(sp);> 	> 	if (ackno_ == llhsp->seqno_){  //send new pkt if ack no matches with new pkt to be sent> 	> 		if (llverbose_==1) fprintf(stderr ,"<%d> %f LL: last ack=%d, send down pktuid=%d ll_seq=%d bopno=%d eopno=%d\n",> 				mac_->addr(), NOW ,ackno_, chsp->uid_,llhsp->seqno_,llhsp->bopno_,llhsp->eopno_);   > 		pktTx_ = sp->copy();> 	> 	// moved frm above due to arp schedules> 	// XXX HACK for now - Padma, 03/99.> 		nsaddr_t dst = (nsaddr_t)Address::instance().get_nodeaddr(ihsp->daddr());> 		int tx = 0;> 	> 		switch(chsp->addr_type()) {> > 		case NS_AF_ILINK:> 			mac_->hdr_dst((char*) HDR_MAC(sp), chsp->next_hop());> 			break;> > 		case NS_AF_INET:> 			dst = chsp->next_hop();> 			/* FALL THROUGH */> 		> 		case NS_AF_NONE:> 		> 			if (IP_BROADCAST == (u_int32_t) dst)> 			{> 				mac_->hdr_dst((char*) HDR_MAC(sp), MAC_BROADCAST);> 				break;> 			}> 			/* Assuming arptable is present, send query */> 			if (arptable_) {> 				tx = arptable_->arpresolve(dst, sp, this);> 				break;> 			}> 			//if (varp_) {> 			//tx = varp_->arpresolve(dst, p);> 			//break;> 			> 			//}			> 			/* FALL THROUGH */> > 		default:> 		> 			int IPnh = (lanrouter_) ? lanrouter_->next_hop(sp) : -1;> 			if (IPnh < 0)> 				mac_->hdr_dst((char*) HDR_MAC(sp),macDA_);> 			else if (varp_)> 				tx = varp_->arpresolve(IPnh, sp);> 			else> 				mac_->hdr_dst((char*) HDR_MAC(sp), IPnh);> 			break;> 		}232a454,467> 		if(tx==0){> 			Scheduler& s = Scheduler::instance();> 		// let mac decide when to take a new packet from the queue.> 			s.schedule(downtarget_, sp, delay_);> 			lhSend_.stop();> 			lhSend_.start(0.5);//?? why 1.5 rj> 		}> 	}> 	else{> 		if (llverbose_==1) fprintf(stderr,"<%d> %f LL: expected pkt(last ack)=%d, this pkt=%d\n", > 				mac_->addr(), NOW, ackno_, llhsp->seqno_);> 		buf_->enqueHead(sp);> 	}> }234c469< void LL::sendUp(Packet* p)---> void LL::recvACK(Packet* p)235a471,480> 	hdr_ll *llh = HDR_LL(p);> 	if(ackno_ < llh->ackno_){> 		ackno_ = llh->ackno_;> 		lhSend_.stop();> 		datacounter=0;> 	}> 	if (llverbose_==1) fprintf(stderr,"<%d> %f LL: recvd ACK num %d\n", mac_->addr(), NOW, llh->ackno_);> 	sendDownDATA();> }> 237c482,485< 	Scheduler& s = Scheduler::instance();---> void LL::sendUpDATA(Packet* p)> {> 	acSend_.stop();> 	ackcounter=0;   //see if req...was working fine240,241c488,579< 	else< 		s.schedule(uptarget_, p, delay_);---> 	else{> 		hdr_cmn *ch = HDR_CMN(p);> 		hdr_ll *llh = HDR_LL(p);> 		hdr_ip *iph = HDR_IP(p);> 	> 		> 		if(((ch->next_hop_)!=-1)&&(acked_==1)){> 			sendACK(p);> 		}> 		if ( llh->seqno_ == llh->eopno_ ){> 			ch->size_=llh->psize_;> 		  	if (llverbose_==1) fprintf(stderr , "<%d> %f LL: all LL frags for pkt uid=%d recvd. sending up.ll_seqno=ll_eopno=%d \n",> 					mac_->addr(), NOW, ch->uid_, llh->eopno_);   > 			Scheduler& s = Scheduler::instance();> 			s.schedule(uptarget_, p, delay_);> 		} else { > 		   if (llverbose_==1) fprintf(stderr , "<%d> %f LL: frag with ll_seqno=%d recvd. for pkt uid=%d ll_eopno=%d\n",> 				   mac_->addr(), NOW, llh->seqno_, ch->uid_, llh->eopno_);   > 			  Packet::free(p);   > 		}> 	}> }> > void LL::sendACK(Packet* p)

⌨️ 快捷键说明

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