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

📄 wimedia_pnc.cc

📁 ns2.31下的UWB(Ultra WideBand)实现
💻 CC
字号:
#include "WiMedia_pnc.h"#include "WiMedia.h"#include "WiMedia_defs.h"#include "pnc_standard.h"PNC::PNC(Mac_WiMedia* mac, MacMib *macmib):enhanced_mode_(true), flow_count_(0), scheduler_(0), type_(PNC_None) {	mac_ = mac;	macmib_ = macmib;	pktBeacon_ = Packet::alloc();	// Dapeng Debug	// printf("Node #%d - PNC object created!\n", mac_->addr());}PNC::~PNC() {}void PNC::SetPNCType(PNCType type) {	if(type_ != PNC_None) {		printf("PNC:: Cannot change the PNC type after setting it! Existting...\n");		exit(1);	}	type_ = type;	switch(type_) {	case PNC_802_15_3:		macmib_->sifs 				= MAC153_SIFS;		macmib_->difs 				= MAC153_DIFS;		macmib_->AFirstGTSGap 			= MAC153_A_FIRST_GTS_GAP;		macmib_->GuardTime 			= MAC153_GUARD_TIME;		macmib_->MACHeaderLength	 	= MAC153_MAC_HEADER_LENGTH;		macmib_->PHYHeaderTxTime 		= MAC153_PHY_HEADER_TX_TIME;		break;	case PNC_802_11:		macmib_->sifs 				= MAC11E_SIFS;		macmib_->difs 				= MAC11E_DIFS;		macmib_->AFirstGTSGap 			= MAC11E_A_FIRST_GTS_GAP;		macmib_->GuardTime 			= MAC11E_GUARD_TIME;		macmib_->MACHeaderLength	 	= MAC11E_MAC_HEADER_LENGTH;		macmib_->PHYHeaderTxTime 		= MAC11E_PHY_HEADER_TX_TIME;		break;	default:		printf ("PNC:: PNC type not supported!\n");		exit (1);		break;	}// end of switch}		void PNC::AddNode(int dev_id) {	// Dapeng Debug	// printf("PNC::Node has joined the PNC\n");}void PNC::StartBeaconing(BeaconTimer2 *beaconTimer) {	if(type_ == PNC_None) {		printf("PNC::StartBeaconing - PNC type is not set yet. First set the PNCType! Exitting...\n");		exit(1);	}		if(scheduler_ == 0) {		printf ("PNC::StartBeaconing -  Scheduler not initialized! Set the Scheduler type first! Exitting...\n");		exit (1);	}	// Dapeng Debug	// printf ("PNC:: Starting beaconing...\n");	scheduler_->StartBeaconing (beaconTimer);}void PNC::OnBeaconTimer (BeaconTimer2 *beaconTimer) {	switch (type_)	{	case PNC_802_15_3:		scheduler_->OnBeaconTimer(beaconTimer);		break;	case PNC_802_11://		DoSinglePolling (beaconTimer);		break;	// The following line default is added by Dapeng	default:		break;	}}void PNC::UpdateGroupPollingBeacon(int aFirstGTSGap) {	struct hdr_cmn *ch = HDR_CMN(pktBeacon_);	struct hdr_mac *mh = HDR_MAC(pktBeacon_);		int size = mac_->TotalLen_Header() + 2 + flow_count_ * 6;	ch->size() = size;	ch->uid() = 0;	ch->ptype() = PT_MAC;	ch->iface() = -2;	ch->error() = 0;	mh->txtime_ = mac_->TxTime(pktBeacon_);	mh->macDA_ = MAC_BROADCAST;	mh->macSA_ = mac_->addr();	mh->ftype_ = MF_BEACON;	mh->beacon_.cta_count = flow_count_;		int current_offset = aFirstGTSGap - macmib_->GuardTime;		for(int i = 0; i < flow_count_; i++) {		mh->beacon_.cta[i].slot_location_ = current_offset + macmib_->GuardTime;		mh->beacon_.cta[i].slot_duration_ = flow_info_[i].alloc_;		mh->beacon_.cta[i].stream_idx_ = (u_char)flow_info_[i].flow_id_;		mh->beacon_.cta[i].src_id_ = flow_info_[i].dev_id_;		mh->beacon_.cta[i].traffic_type_ = flow_info_[i].traffic_type_;		mh->beacon_.cta[i].ack_type_ = flow_info_[i].ack_type_;				current_offset = mh->beacon_.cta[i].slot_location_ + mh->beacon_.cta[i].slot_duration_;	} // End of for}int PNC::ExecuteCommand(int argc, const char* const* argv) {	return scheduler_->ExecuteCommand(argc, argv);}void PNC::StartPolling(int sf_size, BeaconTimer2 *beaconTimer) {	switch(type_) {	case PNC_802_15_3:		UpdateGroupPollingBeacon(macmib_->AFirstGTSGap);		beaconTimer->start(sf_size * 1e-6);		mac_->SendBeacon(pktBeacon_);		// Dapeng Debug		SetPNCSchedule();		break;	case PNC_802_11:		// Bug: Here I left this part for later work 		break;	// The following line default is added by Dapeng	default:		break;	} // end of switch}void PNC::SetScheduler(const char* name) {	if(strcmp(name, "standard") == 0) {		scheduler_ = new PNCStandard(this);		enhanced_mode_ = false;	}}void PNC::ProcessPacket(Packet *p) {	scheduler_->ProcessPacket(p);}void PNC::SetPNCSchedule() {//	printf("SetPNCSchedule()\n");	mac_->recvBeacon(pktBeacon_->copy());}void PNC::PrintTitle() {	switch(type_) {	case PNC_802_15_3:		if(enhanced_mode_)			printf("MAC:Improved 802.15.3\n");		else				printf("MAC:Standard 802.15.3\n");		break;	case PNC_802_11:		printf("MAC:Standad 802.11\n");		break;	} // End of switch	scheduler_->PrintTitle();}

⌨️ 快捷键说明

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