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

📄 phy-umts-nodeb.cc

📁 对ns2软件进行UMTS扩展
💻 CC
📖 第 1 页 / 共 3 页
字号:
	}	return;}/*// looking for an available Scrambling Codeint PhyUmtsNodeb::scrambling_allot(){	int i = 0;	i = Random::integer(MAX_NUM_SCRAM-1);	if (w_control.dl_scramb_[i] == 0)		w_control.dl_scramb_[i] = 1;	return (i);}*/// looks for a UE possition in the addressing arrayint PhyUmtsNodeb::look_for(int phyaddr){	int i;	for (i=0; i<MAX_NUM_UE; i++) {		if (ue_id[i] == phyaddr)			return(i);  // internal address of the UE with physical address: phyaddr	}	return(-1); // UE not found}// registries the UEvoid PhyUmtsNodeb::ue_registry(Packet* p){	int i, j;	hdr_phy *ph = HDR_PHY_UMTS(p);	hdr_ll *lh = HDR_LL(p);	if (verbose_==1)		printf("Nodeb %d at %f PHY: giving paging group to UE phyaddr %d\n",ip_nodeb_, NOW, ph->da());	if (lh->lltype() != LL_FAILURE){		// there is enough resources for the new UE		for (i=0; i<MAX_NUM_UE; i++) {			j = Random::integer(10);			if (ue_id[i] == ph->da()) {				// gives the UE a random paging group				ue_info_[i].paging_group = j;				break;			}		}	} else {		// there is not enough resources to support the new UE		i = look_for(ph->da());		if (i != -1) {			// removes the resources already allocated for that UE			ue_id[i] = -1;		}	}	return;}// transmits the FACH messagevoid PhyUmtsNodeb::tx_fach(Packet* p){	int i, pg;	hdr_cmn *ch = HDR_CMN(p);	hdr_phy *ph = HDR_PHY_UMTS(p);	hdr_ll *lh = HDR_LL(p);	if (lh->lltype() == LL_SETUP_REPLY) {		// for setup and handover procedure gives the UE its paging group		i = look_for(ph->da());		ph->paging_group_ = ue_info_[i].paging_group;	}	// fill physical and common headers	ph->size()=1.25;	ph->scrambling_c_ = w_control.p_scrambling_;	// primary scrambling code	ph->sf_ = 256;  			// spreading factor	// calculates the size in bytes depending on the spreading factor chosen	ch->size_=(int)(UMTS_TBLength / (ph->sf_ * 8));	if ((UMTS_TBLength % (ph->sf_ * 8)) != 0){		ch->size_++;	}	ch->channel_t()=SCCPCH; // ch mapping	if ((verbose_==1) && (ch->ptype() != PT_ACK))		printf("Nodeb %d at %f PHY: tx FACH to ue %d\n", ip_nodeb_, NOW, ph->da());	if ((ch->ptype() == PT_ACK) || (lh->lltype() == LL_RELEASE_REQ) || (lh->lltype() == LL_RELEASE_REPLY)){		// transmit only in one slot, more is not needed		ph->bofsec_ = 1; // begin of FACH tx		ph->eofsec_ = 1; // end of FACH tx		pkttoTx_->enqueHead(p->copy());   // stores the packet in the transmission buffer      }else {		// FACH transmission during a frame		for (i=0; i<14; i++){			if (i == 0){				ph->bofsec_ = 1; // begin of FACH tx			} else {				ph->bofsec_ = 0;			}			if (i == 14)				ph->eofsec_ = 1; // end of FACH tx			pkttoTx_->enque(p->copy());   // stores the packet in the transmission buffer		}	}	Packet::free(p);	p = NULL;	return;}// transmits AICHvoid PhyUmtsNodeb::tx_aich(Packet* p){	hdr_cmn *ch = HDR_CMN(p);	hdr_phy *ph = HDR_PHY_UMTS(p);	hdr_ip *ih = HDR_IP(p);	Packet* sp = Packet::alloc();	hdr_cmn *chsp = HDR_CMN(sp);	hdr_phy *phsp = HDR_PHY_UMTS(sp);	// fill physical and common headers	phsp->size()=1.25;	phsp->sa_ = nodeb_address_;	// source address	phsp->da_ = ue_id[ph->sa()];		// destination address	phsp->scrambling_c_ = ph->scrambling_c_;	// scrambling code	phsp->signature_ = ph->signature_;		// signature	phsp->sf_ = 256;  			// spreading factor	phsp->k_ = ph->k_;	// k for the channelisation code	// calculates the size in bytes depending on the spreading factor chosen	chsp->size_=(int)(UMTS_TBLength / (phsp->sf_ * 8));	if ((UMTS_TBLength % (phsp->sf_ * 8)) != 0){		chsp->size_++;	}	chsp->direction_ = hdr_cmn::DOWN;	chsp->error()= 0;	chsp->channel_t()=AICH;   // ch mapping	chsp->next_hop() = ch->prev_hop_;  	if (verbose_==1)		printf("Nodeb %d at %f PHY: AICH sent to UE phyaddr %d with signature: %d\n", ip_nodeb_, NOW, phsp->da(), phsp->signature_);	aichtoTx_->enque(sp->copy()); // stores the packet in the AICH transmission buffer	Packet::free(p);	p = NULL;	Packet::free(sp);	sp = NULL;	return;}// transmits PICHvoid PhyUmtsNodeb::tx_pich(Packet* p){	int uid, i;	hdr_phy *ph = HDR_PHY_UMTS(p);	Packet* sp = Packet::alloc();	hdr_cmn *chsp = HDR_CMN(sp);	hdr_phy *phsp = HDR_PHY_UMTS(sp);	// fill physical and common headers	phsp->sa_ = nodeb_address_;	// source address	phsp->da_ = BROADCAST;	// destination address	phsp->size()=2.25;  // 2.25 bytes por slot	// looks for the UE destiny of the paging	uid = look_for(ph->da());	if (uid == MAX_NUM_UE) { // error!! we don't have this ue in our cell		Packet::free(sp);		Packet::free(p);		return;	}	// the ue is registered in our cell	phsp->pi() = ue_info_[uid].paging_group;  // allocates the UE destiny paging group	phsp->scrambling_c_ = w_control.p_scrambling_;	// primary scrambling code	phsp->sf_ = 256;  			// spreading factor	// calculates the size in bytes depending on the spreading factor chosen	chsp->size_=(int)(UMTS_TBLength / (phsp->sf_ * 8));  // bytes	if ((UMTS_TBLength % (phsp->sf_ * 8)) != 0){		chsp->size_++;	}	chsp->direction_ = hdr_cmn::DOWN;	chsp->error()= 0;	chsp->channel_t()=PICH;  // ch mapping	chsp->next_hop() = PHY_BROADCAST;	if (verbose_==1)		printf("Nodeb %d at %f PHY: sending PICH to paging group %d\n", ip_nodeb_, NOW,phsp->pi());	pkttoTx_->enque(sp->copy());   // stores the packet in the transmission buffer	tx_pch(pch_recv_->copy());   // transmits the paging message	Packet::free(p);	p = NULL;	Packet::free(sp);	sp = NULL;	return;}// Transmits the paging messagevoid PhyUmtsNodeb::tx_pch(Packet* p){	int uid, i;	hdr_cmn *ch = HDR_CMN(p);	hdr_phy *ph = HDR_PHY_UMTS(p);	hdr_ip *ih = HDR_IP(p);	// fill physical and common headers	ph->scrambling_c_ = w_control.p_scrambling_;	// primary scrambling code	ph->sf_ = 256;  			// spreading factor	// calculates the size in bytes depending on the spreading factor chosen	ch->size_=(int)(UMTS_TBLength / (ph->sf_ * 8));  // bytes	if ((UMTS_TBLength % (ph->sf_ * 8)) != 0){		ch->size_++;	}	ch->error()= 0;	ch->channel_t()=SCCPCH;  // ch mapping	ch->next_hop() = ih->daddr();	// it's transmited during a frame after the PICH	for (i=0; i<15; i++){		if (i == 0){			ph->bofsec_ = 1; // begin of PCH tx		} else {			ph->bofsec_ = 0;		}		if (i == 15){			ph->eofsec_ = 1; // end of PCH tx		}		pchtoTx_->enque(p->copy());  // stores the packet in the transmission buffer	}	if (verbose_==1)		printf("Nodeb %d at %f PHY: sending PCH to UE phyaddr %d\n", ip_nodeb_, NOW, ph->da());	pPaging_.start(0.02); // stats the paging timer and waits response for two frames	Packet::free(p);	p = NULL;	return;}// make P-CCPCH for broadcastingvoid PhyUmtsNodeb::mk_pccpch(void){	int i, j;	Packet* sp = Packet::alloc();	hdr_cmn *chsp = HDR_CMN(sp);	hdr_phy *phsp = HDR_PHY_UMTS(sp);	// fill physical and common headers	phsp->size() = 1.125;	// for broadcast	for (i=0; i<MAX_NUM_SCRAM; i++){		for (j=0; j<MAX_NUM_SIG + 1; j++){			// broadcast the free uplink scrambling codes and signatures			phsp->free_resources_[i][j] = w_control.free_res_[i][j];		}	}//	for (i=0; i<MAX_NUM_SCRAM - 1; i++){//		phsp->used_dl_scramb_[i] = w_control.dl_scramb_[i];//	}	for (i=0; i<MAX_NUM_RACH; i++){		// broadcasts the free RACH channels		phsp->rach_[i] = w_control.free_rach_[i];	}	phsp->sa_ = nodeb_address_;	// source address	phsp->da_ = BROADCAST;		// destination address	phsp->scrambling_c_ = w_control.p_scrambling_;	// primary scrambling code	phsp->sf_ = 256;  			// spreading factor	phsp->k_ = 1;	// k for the channelisation code	chsp->direction_ = hdr_cmn::DOWN;  	// calculates the size in bytes depending on the spreading factor chosen	chsp->size_=(int)(2304 / (phsp->sf_ * 8));  // 2304 chips per slot	if ((2304 % (phsp->sf_ * 8)) != 0){		chsp->size_++;	}	chsp->error()= 0;	chsp->channel_t() = PCCPCH; // ch mapping	chsp->next_hop() = PHY_BROADCAST;	pkttoTx_->enqueHead(sp->copy()); // stores the packet in head the transmission buffer						   // it has to be the first packet transmitted in each slot 	Packet::free(sp);	sp = NULL;	return;}// make SCH for broadcastingvoid PhyUmtsNodeb::mk_sch(void){	Packet* sp = Packet::alloc();	hdr_cmn *chsp = HDR_CMN(sp);	hdr_phy *phsp = HDR_PHY_UMTS(sp);	// fill physical and common headers	chsp->size_ = 2;  // 256 chips in 1 slot, it has not got scrambling code	chsp->direction_ = hdr_cmn::DOWN;	chsp->error()= 0;	chsp->channel_t()=SCH;   // ch mapping	chsp->next_hop() = PHY_BROADCAST;	phsp->p_scrambling_c_ = w_control.p_scrambling_;	// primary scrambling code										// to broadcast in the cell.	phsp->sa_ = nodeb_address_;	// source address	phsp->da_ = BROADCAST;		// destination address	phsp->size() = 1.25;	pkttoTx_->enque(sp->copy());  // stores the packet in the transmission buffer	Packet::free(sp);	return;}// uplink multiplexing chainvoid PhyUmtsNodeb::dl_mux(Packet* p){	int i, j;	hdr_cmn *chp = HDR_CMN(p);	hdr_phy *php = HDR_PHY_UMTS(p);	hdr_rlc_umts *rhp = HDR_RLC_UMTS(p);	c_coding(p);   // channel coding	php->size() = chp->size_;  // stores the packet size	i = look_for(php->da());	// stores the packet in each user buffer to send them in dpdchs	data_temp_[i]->enque(p);	return;}// decodes data with direction UPvoid PhyUmtsNodeb::decode(int id){	int i, j;	Packet* p;	hdr_phy *phrecv;	hdr_cmn *chp;	hdr_ip *ihp;	hdr_phy *php;	// demux DPDCH and extract packets	for (i=0; i<d_control[id].n_dpdch_; i++) {		phrecv = HDR_PHY_UMTS(rx_dpdch[id][i]);		// go through the array extracting packets		while (phrecv->dpdch_control_->length() > 0) {			p = phrecv->dpdch_control_->deque();			chp = HDR_CMN(p);			ihp = HDR_IP(p);			php = HDR_PHY_UMTS(p);			// Previusly packets arrived not in sequence			if (ue_info_[id].in_seq_ == -1) {				if (php->seqno_ == 0) {					// first physical fragment of a packet					if (php->eofsec_ == 1) {						// last physical fragment of a packet						if (verbose_==1)							printf("Nodeb %d at %f PHY: decode: eofseq: pkt of flow %d uid %d and size %d\n",								ip_nodeb_, NOW, ihp->flowid(),chp->uid(),chp->size());						chp->channel_t() = DCH; // ch mapping						ul_demux(p->copy()); // send it to uplink demux chain						ue_info_[id].in_seq_ = 0;  // waiting for fragment 0					} else {						// is not the last fragment, drop it						if (verbose_==1)							printf("Nodeb %d at %f PHY:  decode: pkt in seq: %d ue %d flow %d uid %d and size %d\n",								ip_nodeb_, NOW, php->seqno_, php->sa(), ihp->flowid(),chp->uid(),chp->size());						ue_info_[id].in_seq_ = 1;  // waiting fragment number 1						Packet::free(p);					}				} else {					// is not the first fragment, drop the packet					if (verbose_==1)						printf("Nodeb %d at %f PHY: decode: not seq: Drop pkt\n",ip_nodeb_, NOW);					Packet::free(p);				}			} else if (php->seqno_ == ue_info_[id].in_seq_) { // Previous packets arrived in sequence				// is the fragment that we expected				if (php->eofsec_ == 1) {					// is the last physical fragment, send it to MAC					if (verbose_==1)						printf("Nodeb %d at %f PHY: decode: pkt of flow %d uid %d and size %d\n",							ip_nodeb_, NOW, ihp->flowid(),chp->uid(),chp->size());					chp->channel_t() = DCH;  // ch mapping					ul_demux(p->copy());  // send it to demux chain					ue_info_[id].in_seq_ = 0;  // waiting fragment number 0				} else {					// is not the last fragment, drop the packet					ue_info_[id].in_seq_++;					if (verbose_==1)						printf("Nodeb %d at %f PHY: decode: pkt in seq: %d ue %d flow %d uid %d and size %d\n",							ip_nodeb_, NOW, php->seqno_, php->sa(), ihp->flowid(),chp->uid(),chp->size());					Packet::free(p);				}			} else {  // Previous packets arrived in sequence				// Previous packets arrived in sequence				if (verbose_==1)					printf("Nodeb %d at %f PHY: decode: pkt not in seq: %d waiting %d ue %d flow %d uid %d and size %d\n",						ip_nodeb_, NOW, php->seqno_, ue_info_[id].in_seq_, php->sa(), ihp->flowid(),chp->uid(),chp->size());				ue_info_[id].in_seq_ = -1;  // not in sequence				Packet::free(p);			}  		}		Packet::free(rx_dpdch[id][i]);  // remove resources		rx_dpdch[id][i] = NULL;	}	return;}// uplink demultiplexing chainvoid PhyUmtsNodeb::ul_demux(Packet* p){	int i;	hdr_cmn *chp = HDR_CMN(p);	hdr_phy *php = HDR_PHY_UMTS(p);	chp->direction_ = hdr_cmn::UP;	c_decoding(p);			// channel decoding	uptarget_->recv(p, this);  // sends the packet to the MAC layer	return;}// channel codingvoid PhyUmtsNodeb::c_coding(Packet* p){	hdr_cmn *chp = HDR_CMN(p);	hdr_phy *php = HDR_PHY_UMTS(p);	switch (php->c_coding()) {		case TURBO:  // turbo coding			chp->size() = 3*chp->size();			break;		case CONV_HALF:  // convolutional half			chp->size() = 2*chp->size();			break;		case CONV_THIRD:    // convolutional third			chp->size() = 3*chp->size();			break;		default:			break;	}	return;}// channel decodingvoid PhyUmtsNodeb::c_decoding(Packet* p){	hdr_cmn *chp = HDR_CMN(p);	hdr_phy *php = HDR_PHY_UMTS(p);

⌨️ 快捷键说明

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