亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? mac-tdma.c

?? $Header: /cvsroot/nsnam/ns-2/mac/mac-tdma.cc,v 1.16 2006/02/22 13:25:43 mahrenho Exp $ // // mac-t
?? C
?? 第 1 頁 / 共 2 頁
字號:
	// Record the start time of the new schedule.
	start_time_ = NOW;
	/* Seperate slot_num_ and the node id: 
	   we may have flexibility as node number changes.
	*/
	slot_num_ = slot_pointer++;
	tdma_schedule_[slot_num_] = (char) index_;
}

/* To handle incoming packet. */
void MacTdma::recv(Packet* p, Handler* h) {
	struct hdr_cmn *ch = HDR_CMN(p);
	
	/* Incoming packets from phy layer, send UP to ll layer. 
	   Now, it is in receiving mode. 
	*/
	if (ch->direction() == hdr_cmn::UP) {
		// Since we can't really turn the radio off at lower level, 
		// we just discard the packet.
		if (!radio_active_) {
			free(p);
			//printf("<%d>, %f, I am sleeping...\n", index_, NOW);
			return;
		}

		sendUp(p);
		//printf("<%d> packet recved: %d\n", index_, tdma_pr_++);
		return;
	}
	
	/* Packets coming down from ll layer (from ifq actually),
	   send them to phy layer. 
	   Now, it is in transmitting mode. */
	callback_ = h;
	state(MAC_SEND);
	sendDown(p);
	//printf("<%d> packet sent down: %d\n", index_, tdma_ps_++);
}

void MacTdma::sendUp(Packet* p) 
{
	struct hdr_cmn *ch = HDR_CMN(p);

	/* Can't receive while transmitting. Should not happen...?*/
	if (tx_state_ && ch->error() == 0) {
		printf("<%d>, can't receive while transmitting!\n", index_);
		ch->error() = 1;
	};

	/* Detect if there is any collision happened. should not happen...?*/
	if (rx_state_ == MAC_IDLE) {
		SET_RX_STATE(MAC_RECV);     // Change the state to recv.
		pktRx_ = p;                 // Save the packet for timer reference.

		/* Schedule the reception of this packet, 
		   since we just see the packet header. */
		double rtime = TX_Time(p);
		assert(rtime >= 0);

		/* Start the timer for receiving, will end when receiving finishes. */
		mhRxPkt_.start(p, rtime);
	} else {
		/* Note: we don't take the channel status into account, 
		   as collision should not happen...
		*/
		printf("<%d>, receiving, but the channel is not idle....???\n", index_);
	}
}

/* Actually receive data packet when RxPktTimer times out. */
void MacTdma::recvDATA(Packet *p){
	/*Adjust the MAC packet size: strip off the mac header.*/
	struct hdr_cmn *ch = HDR_CMN(p);
	ch->size() -= ETHER_HDR_LEN;
	ch->num_forwards() += 1;

	/* Pass the packet up to the link-layer.*/
	uptarget_->recv(p, (Handler*) 0);
}

/* Send packet down to the physical layer. 
   Need to calculate a certain time slot for transmission. */
void MacTdma::sendDown(Packet* p) {
	u_int32_t dst, src, size;
  
	struct hdr_cmn* ch = HDR_CMN(p);
	struct hdr_mac_tdma* dh = HDR_MAC_TDMA(p);

	/* Update the MAC header, same as 802.11 */
	ch->size() += ETHER_HDR_LEN;

	dh->dh_fc.fc_protocol_version = MAC_ProtocolVersion;
	dh->dh_fc.fc_type       = MAC_Type_Data;
	dh->dh_fc.fc_subtype    = MAC_Subtype_Data;
	
	dh->dh_fc.fc_to_ds      = 0;
	dh->dh_fc.fc_from_ds    = 0;
	dh->dh_fc.fc_more_frag  = 0;
	dh->dh_fc.fc_retry      = 0;
	dh->dh_fc.fc_pwr_mgt    = 0;
	dh->dh_fc.fc_more_data  = 0;
	dh->dh_fc.fc_wep        = 0;
	dh->dh_fc.fc_order      = 0;

	if((u_int32_t)ETHER_ADDR(dh->dh_da) != MAC_BROADCAST)
		dh->dh_duration = DATA_DURATION;
	else
		dh->dh_duration = 0;

	dst = ETHER_ADDR(dh->dh_da);
	src = ETHER_ADDR(dh->dh_sa);
	size = ch->size();

	/* buffer the packet to be sent. */
	pktTx_ = p;
}

/* Actually send the packet. */
void MacTdma::send() 
{
	u_int32_t dst, src, size;
	struct hdr_cmn* ch;
	struct hdr_mac_tdma* dh;
	double stime;

	/* Check if there is any packet buffered. */
	if (!pktTx_) {
		printf("<%d>, %f, no packet buffered.\n", index_, NOW);
		return;
	}

	/* Perform carrier sence...should not be collision...? */
	if(!is_idle()) {
		/* Note: we don't take the channel status into account, ie. no collision,
		   as collision should not happen...
		*/
		printf("<%d>, %f, transmitting, but the channel is not idle...???\n", index_, NOW);
		return;
	}

	ch = HDR_CMN(pktTx_);
	dh = HDR_MAC_TDMA(pktTx_);  

	dst = ETHER_ADDR(dh->dh_da);
	src = ETHER_ADDR(dh->dh_sa);
	size = ch->size();
	stime = TX_Time(pktTx_);
	ch->txtime() = stime;
	
	/* Turn on the radio and transmit! */
	SET_TX_STATE(MAC_SEND);						     
	radioSwitch(ON);

	/* Start a timer that expires when the packet transmission is complete. */
	mhTxPkt_.start(pktTx_->copy(), stime);
	downtarget_->recv(pktTx_, this);        

	pktTx_ = 0;
}

// Turn on / off the radio
void MacTdma::radioSwitch(int i) 
{
	radio_active_ = i;
	//EnergyModel *em = netif_->node()->energy_model();
	if (i == ON) {
		//if (em && em->sleep())
		//em->set_node_sleep(0);
		//    printf("<%d>, %f, turn radio ON\n", index_, NOW); 
		Phy *p;
		p = netif_;
		((WirelessPhy *)p)->node_wakeup();
		return;
	}

	if (i == OFF) {
		//if (em && !em->sleep()) {
		//em->set_node_sleep(1);
		//    netif_->node()->set_node_state(INROUTE);
		Phy *p;
		p = netif_;
		((WirelessPhy *)p)->node_sleep();
		//    printf("<%d>, %f, turn radio OFF\n", index_, NOW);
		return;
	}
}

// make the new preamble.
void MacTdma::makePreamble() 
{
	u_int32_t dst;
	struct hdr_mac_tdma* dh;
	
	// If there is a packet buffered, file its destination to preamble.
	if (pktTx_) {
		dh = HDR_MAC_TDMA(pktTx_);  
		dst = ETHER_ADDR(dh->dh_da);
		//printf("<%d>, %f, write %d to slot %d in preamble\n", index_, NOW, dst, slot_num_);
		tdma_preamble_[slot_num_] = dst;
	} else {
		//printf("<%d>, %f, write NO_PKT to slot %d in preamble\n", index_, NOW, slot_num_);
		tdma_preamble_[slot_num_] = NOTHING_TO_SEND;
	}
}

/* Timers' handlers */
/* Slot Timer:
   For the preamble calculation, we should have it:
   occupy one slot time,
   radio turned on for the whole slot.
*/
void MacTdma::slotHandler(Event *e) 
{
	// Restart timer for next slot.
	mhSlot_.start((Packet *)e, slot_time_);

	// Make a new presamble for next frame.
	if ((slot_count_ == active_node_) || (slot_count_ == FIRST_ROUND)) {
		//printf("<%d>, %f, make the new preamble now.\n", index_, NOW);
		// We should turn the radio on for the whole slot time.
		radioSwitch(ON);

		makePreamble();
		slot_count_ = 0;
		return;
	}

	// If it is the sending slot for me.
	if (slot_count_ == slot_num_) {
		//printf("<%d>, %f, time to send.\n", index_, NOW);
		// We have to check the preamble first to avoid the packets coming in the middle.
		if (tdma_preamble_[slot_num_] != NOTHING_TO_SEND)
			send();
		else
			radioSwitch(OFF);

		slot_count_++;
		return;
	}
 
	// If I am supposed to listen in this slot
	if ((tdma_preamble_[slot_count_] == index_) || ((u_int32_t)tdma_preamble_[slot_count_] == MAC_BROADCAST)) {
		//printf("<%d>, %f, preamble[%d]=%d, I am supposed to receive now.\n", index_, NOW, slot_count_, tdma_preamble_[slot_count_]);
		slot_count_++;

		// Wake up the receive packets.
		radioSwitch(ON);
		return;
	}

	// If I dont send / recv, do nothing.
	//printf("<%d>, %f, preamble[%d]=%d, nothing to do now.\n", index_, NOW, slot_count_, tdma_preamble_[slot_count_]);
	radioSwitch(OFF);
	slot_count_++;
	return;
}

void MacTdma::recvHandler(Event *e) 
{
	u_int32_t dst, src; 
	int size;
	struct hdr_cmn *ch = HDR_CMN(pktRx_);
	struct hdr_mac_tdma *dh = HDR_MAC_TDMA(pktRx_);

	/* Check if any collision happened while receiving. */
	if (rx_state_ == MAC_COLL) 
		ch->error() = 1;

	SET_RX_STATE(MAC_IDLE);
  
	/* check if this packet was unicast and not intended for me, drop it.*/   
	dst = ETHER_ADDR(dh->dh_da);
	src = ETHER_ADDR(dh->dh_sa);
	size = ch->size();

	//printf("<%d>, %f, recv a packet [from %d to %d], size = %d\n", index_, NOW, src, dst, size);

	// Turn the radio off after receiving the whole packet
	radioSwitch(OFF);

	/* Ordinary operations on the incoming packet */
	// Not a pcket destinated to me.
	if ((dst != MAC_BROADCAST) && (dst != (u_int32_t)index_)) {
		drop(pktRx_);
		return;
	}
  
	/* Now forward packet upwards. */
	recvDATA(pktRx_);
}

/* After transmission a certain packet. Turn off the radio. */
void MacTdma::sendHandler(Event *e) 
{
	//  printf("<%d>, %f, send a packet finished.\n", index_, NOW);

	/* Once transmission is complete, drop the packet. 
	   p  is just for schedule a event. */
	SET_TX_STATE(MAC_IDLE);
	Packet::free((Packet *)e);
  
	// Turn off the radio after sending the whole packet
	radioSwitch(OFF);

	/* unlock IFQ. */
	if(callback_) {
		Handler *h = callback_;
		callback_ = 0;
		h->handle((Event*) 0);
	} 
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
丝袜诱惑制服诱惑色一区在线观看| 久99久精品视频免费观看| 亚洲大片精品永久免费| 国产一区二区三区高清播放| 91福利小视频| 国产日韩亚洲欧美综合| 日韩综合一区二区| 色综合久久久久久久久| 久久综合国产精品| 日韩电影免费一区| 在线亚洲人成电影网站色www| 久久精品网站免费观看| 日本欧美大码aⅴ在线播放| 色综合久久88色综合天天| 久久久不卡影院| 国内成人免费视频| 日韩一级视频免费观看在线| 亚洲国产精品一区二区www在线| 成人爱爱电影网址| 久久久精品一品道一区| 麻豆91在线看| 欧美大片在线观看一区二区| 国产成人av网站| 欧美顶级少妇做爰| 亚洲成人先锋电影| 欧美日韩在线播放一区| 一区二区在线观看免费视频播放 | 亚洲一区二区成人在线观看| 成人性生交大片免费看中文| 久久久精品综合| 国产精品1024久久| 久久―日本道色综合久久| 黄一区二区三区| 久久这里只精品最新地址| 国产乱人伦偷精品视频免下载| 精品日韩一区二区三区免费视频| 久久精品国产免费| 精品sm捆绑视频| 国产成人av一区二区三区在线 | 久久97超碰国产精品超碰| 欧美一区二区国产| 久久国产人妖系列| 久久亚洲欧美国产精品乐播 | 色悠久久久久综合欧美99| 亚洲男帅同性gay1069| 在线观看网站黄不卡| 亚洲国产aⅴ天堂久久| 欧美一区二区大片| 精品一区二区三区免费观看 | 国产成人小视频| 国产精品久久久久三级| 色综合色狠狠综合色| 香蕉乱码成人久久天堂爱免费| 欧美人妖巨大在线| 国产一区二区三区久久久| 国产精品久线观看视频| 在线视频中文字幕一区二区| 日日欢夜夜爽一区| 中文字幕不卡一区| 欧美色综合影院| 狠狠色狠狠色综合系列| 中文字幕一区二区三区四区 | 日本欧美一区二区三区| 国产视频一区不卡| 欧美在线一二三四区| 久久成人免费网站| 1024亚洲合集| 日韩美女主播在线视频一区二区三区| 国产电影一区在线| 亚洲国产日韩a在线播放| 久久欧美一区二区| 欧美在线视频日韩| 国产xxx精品视频大全| 亚洲大片精品永久免费| 亚洲国产精品99久久久久久久久 | 亚洲午夜久久久久久久久电影网 | 国产麻豆午夜三级精品| 亚洲欧美欧美一区二区三区| 精品国产乱码久久久久久牛牛 | 久久久天堂av| 欧美三级电影精品| 成人av资源在线| 免费观看在线色综合| 亚洲男女毛片无遮挡| 久久久久久久久久久久电影| 欧美日韩精品专区| 99re热这里只有精品视频| 久久精品国产久精国产爱| 亚洲一区中文在线| 国产精品免费网站在线观看| 日韩欧美国产三级电影视频| 欧美色综合天天久久综合精品| 丁香激情综合五月| 激情图片小说一区| 日韩和的一区二区| 亚洲图片欧美色图| 亚洲私人影院在线观看| 亚洲国产精品成人综合| 久久先锋资源网| 欧美一区二区三区免费大片| 欧美性生活大片视频| 91久久精品一区二区| 夫妻av一区二区| 国产一区二区按摩在线观看| 久久99久久精品| 美女免费视频一区| 免费在线看成人av| 蜜臀久久久99精品久久久久久| 香蕉成人伊视频在线观看| 亚洲乱码国产乱码精品精可以看| 国产精品动漫网站| 国产精品乱码妇女bbbb| 国产精品麻豆欧美日韩ww| 国产欧美日韩不卡| 国产精品视频一二三区| 国产精品国产三级国产普通话三级| 国产偷国产偷精品高清尤物| 国产亚洲婷婷免费| 欧美韩国日本不卡| 国产精品久久国产精麻豆99网站| 国产精品久久久久三级| 亚洲摸摸操操av| 亚洲第一av色| 麻豆国产欧美日韩综合精品二区| 精品在线免费视频| 国产成人8x视频一区二区| 99久久精品免费看国产| 欧美综合天天夜夜久久| 欧美一区二区国产| xnxx国产精品| 国产精品久久久99| 亚洲影院免费观看| 麻豆国产91在线播放| 懂色av一区二区三区蜜臀| 色综合久久久久| 欧美一区二区免费视频| 国产视频911| 亚洲男同性视频| 久久99蜜桃精品| caoporen国产精品视频| 欧美日韩mp4| 久久久蜜桃精品| 一级日本不卡的影视| 麻豆一区二区在线| 波多野结衣在线一区| 欧美日韩精品一区二区三区| 欧美va亚洲va在线观看蝴蝶网| 国产精品免费久久久久| 亚洲午夜一区二区三区| 国产成人免费xxxxxxxx| 在线精品国精品国产尤物884a| 日韩欧美一级精品久久| 国产精品国产三级国产普通话99 | 欧美另类一区二区三区| 久久综合久久综合九色| 一区二区三区视频在线看| 理论片日本一区| 色噜噜夜夜夜综合网| 久久在线免费观看| 亚洲不卡av一区二区三区| 国产成人在线色| 欧美一区二区精品久久911| 国产精品福利一区二区| 国内国产精品久久| 欧美精选一区二区| 亚洲视频在线一区| 国产一区二区三区四区五区入口| 欧美视频一区二区在线观看| 中文字幕精品—区二区四季| 美女国产一区二区| 欧美在线|欧美| 亚洲手机成人高清视频| 国产精品自拍av| 欧美成人伊人久久综合网| 亚洲国产色一区| 色就色 综合激情| 一区在线观看免费| 国产一区二区视频在线| 欧美一区国产二区| 亚洲成人黄色影院| 色婷婷狠狠综合| 中文字幕亚洲精品在线观看| 国产乱人伦精品一区二区在线观看 | 欧美性一二三区| 亚洲婷婷综合色高清在线| 成人精品一区二区三区中文字幕| 欧美大胆人体bbbb| 蜜臀av性久久久久蜜臀aⅴ流畅| 欧美亚洲禁片免费| 一区二区三区不卡视频| 成人aa视频在线观看| 国产精品视频免费| 成人毛片视频在线观看| 国产蜜臀av在线一区二区三区| 国产麻豆欧美日韩一区| 久久久国产精品不卡| 国产成人亚洲综合色影视| 久久你懂得1024| 成人黄色小视频在线观看| 中国av一区二区三区|