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

📄 patch.mac

📁 ns2网络仿真中超宽带的实现
💻 MAC
📖 第 1 页 / 共 5 页
字号:
+	 *  it probably won't even see this packet.  However, the+	 *  "air" around me is BUSY so I need to let the packet+	 *  proceed.  Just set the error flag in the common header+	 *  to that the packet gets thrown away.+	 */+	if(tx_active_ && hdr->error() == 0) {+		hdr->error() = 1;+	}++	if(rx_state_ == MAC_IDLE) {+		SET_RX_STATE(MAC_RECV);+		pktRx_ = p;++		/*+		 * Schedule the reception of this packet, in+		 * txtime seconds.+		 */+		recv_timer(); // JCW+		//mhRecv_.start(txtime(p));+	} else {+		/*+		 *  If the power of the incoming packet is smaller than the+		 *  power of the packet currently being received by at least+                 *  the capture threshold, then we ignore the new packet.+		 */+		assert(0); // JCW+		if(pktRx_->txinfo_.RxPr / p->txinfo_.RxPr >= p->txinfo_.CPThresh) {+			capture(p);+		} else {+			collision(p);+		}+	}+}++void+Mac802_11_if::recv_timer()+{+	u_int32_t src; +	hdr_cmn *ch = HDR_CMN(pktRx_);+	hdr_mac802_11 *mh = HDR_MAC802_11(pktRx_);+	u_int32_t dst = ETHER_ADDR(mh->dh_da);+	// XXX debug+	//struct cts_frame *cf = (struct cts_frame*)pktRx_->access(hdr_mac::offset_);+	//u_int32_t src = ETHER_ADDR(mh->dh_sa);+	+	u_int8_t  type = mh->dh_fc.fc_type;+	u_int8_t  subtype = mh->dh_fc.fc_subtype;++	assert(pktRx_);+	assert(rx_state_ == MAC_RECV || rx_state_ == MAC_COLL);+	+        /*+         *  If the interface is in TRANSMIT mode when this packet+         *  "arrives", then I would never have seen it and should+         *  do a silent discard without adjusting the NAV.+         */+        if(tx_active_) {+                Packet::free(pktRx_);+                goto done;+        }++	/*+	 * Handle collisions.+	 */+	if(rx_state_ == MAC_COLL) {+		discard(pktRx_, DROP_MAC_COLLISION);+		set_nav(usec(eifs_));+		goto done;+	}++	/*+	 * Check to see if this packet was received with enough+	 * bit errors that the current level of FEC still could not+	 * fix all of the problems - ie; after FEC, the checksum still+	 * failed.+	 */+	if( ch->error() ) {+		Packet::free(pktRx_);+		set_nav(usec(eifs_));+		goto done;+	}++	/*+	 * IEEE 802.11 specs, section 9.2.5.6+	 *	- update the NAV (Network Allocation Vector)+	 */+	if(dst != (u_int32_t)index_) {+		set_nav(mh->dh_duration);+	}++        /* tap out - */+        if (tap_ && type == MAC_Type_Data &&+            MAC_Subtype_Data == subtype ) +		tap_->tap(pktRx_);+	/*+	 * Adaptive Fidelity Algorithm Support - neighborhood infomation +	 * collection+	 *+	 * Hacking: Before filter the packet, log the neighbor node+	 * I can hear the packet, the src is my neighbor+	 */+	if (netif_->node()->energy_model() && +	    netif_->node()->energy_model()->adaptivefidelity()) {+		src = ETHER_ADDR(mh->dh_sa);+		netif_->node()->energy_model()->add_neighbor(src);+	}+	/*+	 * Address Filtering+	 */+	if(dst != (u_int32_t)index_ && dst != MAC_BROADCAST) {+		/*+		 *  We don't want to log this event, so we just free+		 *  the packet instead of calling the drop routine.+		 */+		discard(pktRx_, "---");+		goto done;+	}++	switch(type) {++	case MAC_Type_Management:+		discard(pktRx_, DROP_MAC_PACKET_ERROR);+		goto done;+		break;++	case MAC_Type_Control:+		switch(subtype) {+		case MAC_Subtype_RTS:+			recvRTS(pktRx_);+			break;+		case MAC_Subtype_CTS:+			recvCTS(pktRx_);+			break;+		case MAC_Subtype_ACK:+			recvACK(pktRx_);+			break;+		default:+			fprintf(stderr,"recvTimer1:Invalid MAC Control Subtype %x\n",+				subtype);+			exit(1);+		}+		break;+	case MAC_Type_Data:+		switch(subtype) {+		case MAC_Subtype_Data:+			recvDATA(pktRx_);+			break;+		default:+			fprintf(stderr, "recv_timer2:Invalid MAC Data Subtype %x\n",+				subtype);+			exit(1);+		}+		break;+	default:+		fprintf(stderr, "recv_timer3:Invalid MAC Type %x\n", subtype);+		exit(1);+	}+ done:+	pktRx_ = 0;+	rx_resume();+}+++void+Mac802_11_if::recvRTS(Packet *p)+{+	struct rts_frame *rf = (struct rts_frame*)p->access(hdr_mac::offset_);++	if(tx_state_ != MAC_IDLE) {+		discard(p, DROP_MAC_BUSY);+		return;+	}++	/*+	 *  If I'm responding to someone else, discard this RTS.+	 */+	if(pktCTRL_) {+		discard(p, DROP_MAC_BUSY);+		return;+	}++	sendCTS(ETHER_ADDR(rf->rf_ta), rf->rf_duration);++	/*+	 *  Stop deferring - will be reset in tx_resume().+	 */+	if(mhDefer_.busy()) mhDefer_.stop();++	tx_resume();++	mac_log(p);+}++/*+ * txtime()	- pluck the precomputed tx time from the packet header+ */+double+Mac802_11_if::txtime(Packet *p)+ {+	 struct hdr_cmn *ch = HDR_CMN(p);+	 double t = ch->txtime();+	 if (t < 0.0) {+		 drop(p, "XXX");+ 		exit(1);+	 }+	 return t;+ }++ +/*+ * txtime()	- calculate tx time for packet of size "psz" bytes + *		  at rate "drt" bps+ */+double+Mac802_11_if::txtime(double psz, double drt)+{+	double dsz = psz - PLCP_HDR_LEN;+	int plcp_hdr = PLCP_HDR_LEN << 3;+	int datalen = (int)dsz << 3;+	+	double t = (((double)plcp_hdr)/phymib_->PLCPDataRate) + (((double)datalen)/drt);+	return(t);+}++++void+Mac802_11_if::recvCTS(Packet *p)+{+	if(tx_state_ != MAC_RTS) {+		discard(p, DROP_MAC_INVALID_STATE);+		return;+	}++	assert(pktRTS_);+	Packet::free(pktRTS_); pktRTS_ = 0;++	assert(pktTx_);+	// debug+	//struct hdr_mac802_11 *mh = HDR_MAC802_11(pktTx_);+	//printf("(%d):recvCTS:pktTx_-%x,mac-subtype-%d & pktCTS_:%x\n",index_,pktTx_,mh->dh_fc.fc_subtype,p);+	+	mhSend_.stop();++	/*+	 * The successful reception of this CTS packet implies+	 * that our RTS was successful.  Hence, we can reset+	 * the Short Retry Count and the CW.+	 */+	//ssrc_ = 0;+	//rst_cw();++	tx_resume();++	mac_log(p);+}++void+Mac802_11_if::recvDATA(Packet *p)+{+	struct hdr_mac802_11 *dh = HDR_MAC802_11(p);+	u_int32_t dst, src, size;++	{	struct hdr_cmn *ch = HDR_CMN(p);++		dst = ETHER_ADDR(dh->dh_da);+		src = ETHER_ADDR(dh->dh_sa);+		size = ch->size();++		/*+		 * Adjust the MAC packet size - ie; strip+		 * off the mac header+		 */+		ch->size() -= ETHER_HDR_LEN11;+		ch->num_forwards() += 1;+	}++	/*+	 *  If we sent a CTS, clean up...+	 */+	if(dst != MAC_BROADCAST) {+		if(size >= macmib_->RTSThreshold) {+			if (tx_state_ == MAC_CTS) {+				assert(pktCTRL_);+				Packet::free(pktCTRL_); pktCTRL_ = 0;+				mhSend_.stop();+				/*+				 * Our CTS got through.+				 */+				//printf("(%d): RECVING DATA!\n",index_);+				//ssrc_ = 0;+				//rst_cw();+			}+			else {+				discard(p, DROP_MAC_BUSY);+				//printf("(%d)..discard DATA\n",index_);+				return;+			}+			sendACK(src);+			tx_resume();+		}+		/*+		 *  We did not send a CTS and there's no+		 *  room to buffer an ACK.+		 */+		else {+			if(pktCTRL_) {+				discard(p, DROP_MAC_BUSY);+				return;+			}+			sendACK(src);+			if(mhSend_.busy() == 0)+				tx_resume();+		}+	}++	/* ============================================================+	    Make/update an entry in our sequence number cache.+	   ============================================================ */++	/* Changed by Debojyoti Dutta. This upper loop of if{}else was +	   suggested by Joerg Diederich <dieder@ibr.cs.tu-bs.de>. +	   Changed on 19th Oct'2000 */++        if(dst != MAC_BROADCAST) {+                if (src < (u_int32_t) cache_node_count_) {+                        Host *h = &cache_[src];++                        if(h->seqno && h->seqno == dh->dh_scontrol) {+                                discard(p, DROP_MAC_DUPLICATE);+                                return;+                        }+                        h->seqno = dh->dh_scontrol;+                } else {+			static int count = 0;+			if (++count <= 10) {+				printf ("MAC_802_11_if: accessing MAC cache_ array out of range (src %u, dst %u, size %d)!\n", src, dst, cache_node_count_);+				if (count == 10)+					printf ("[suppressing additional MAC cache_ warnings]\n");+			};+		};+	}++	/*++	 *  Pass the packet up to the link-layer.+	 *  XXX - we could schedule an event to account+	 *  for this processing delay.+	 */+	//p->incoming = 1;+	// XXXXX NOTE: use of incoming flag has been depracated; In order to track direction of pkt flow, direction_ in hdr_cmn is used instead. see packet.h for details. +	+	uptarget_->recv(p, (Handler*) 0);+}+++void+Mac802_11_if::recvACK(Packet *p)+{+	+	struct hdr_cmn *ch = HDR_CMN(p);++	if(tx_state_ != MAC_SEND) {+	discard(p, DROP_MAC_INVALID_STATE);+	return;+	}+	//printf("(%d)...................recving ACK:%x\n",index_,p);+	assert(pktTx_);+	Packet::free(pktTx_); pktTx_ = 0;++	mhSend_.stop();++	/*+	 * The successful reception of this ACK packet implies+	 * that our DATA transmission was successful.  Hence,+	 * we can reset the Short/Long Retry Count and the CW.+	 */+	if((u_int32_t) ch->size() <= macmib_->RTSThreshold)+		ssrc_ = 0;+	else+		slrc_ = 0;++	/*+	 * Backoff before sending again.+	 */+	rst_cw();+	assert(mhBackoff_.busy() == 0);+	mhBackoff_.start(cw_, is_idle());++	tx_resume();++	mac_log(p);+}diff -Naur --ignore-matching-lines='Version Date' --ignore-matching-lines=cvsroot --ignore-matching-lines=CVSROOT /home/rmerz/NS/ns-allinone-2.26/ns-2.26/mac/mac-802_11-if.h mac/mac-802_11-if.h--- /home/rmerz/NS/ns-allinone-2.26/ns-2.26/mac/mac-802_11-if.h	1970-01-01 01:00:00.000000000 +0100+++ mac/mac-802_11-if.h	2004-01-30 16:33:07.000000000 +0100@@ -0,0 +1,227 @@+/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*-+ *+ * Copyright (c) 1997 Regents of the University of California.+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or without+ * modification, are permitted provided that the following conditions+ * are met:+ * 1. Redistributions of source code must retain the above copyright+ *    notice, this list of conditions and the following disclaimer.+ * 2. Redistributions in binary form must reproduce the above copyright+ *    notice, this list of conditions and the following disclaimer in the+ *    documentation and/or other materials provided with the distribution.+ * 3. All advertising materials mentioning features or use of this software+ *    must display the following acknowledgement:+ *	This product includes software developed by the Computer Systems+ *	Engineering Group at Lawrence Berkeley Laboratory.+ * 4. Neither the name of the University nor of the Laboratory may be used+ *    to endorse or promote products derived from this software without+ *    specific prior written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF+ * SUCH DAMAGE.+ *+ * $Header: /usr/local/cvsroot/ns-2_26/mac/mac-802_11-if.h,v 1.3 2003/11/21 18:06:56 widmer Exp $+ *+ * Ported from CMU/Monarch's code, nov'98 -Padma.+ * wireless-mac-802_11.h+ */++#ifndef ns_mac_80211_if_h+#define ns_mac_80211_if_h++#include "mac-timers-if.h"+#include "marshall.h"+#include "mac-802_11.h"++// JCW+#include "interference-phy.h"++/*+ * IEEE 802.11 Spec, section 11.4.4.2+ *      - default values for the MAC Attributes+ */+//#define MAC_IF_RTSThreshold		10000		// bytes+#define MAC_IF_RTSThreshold		0		// bytes++/* ======================================================================+   The actua

⌨️ 快捷键说明

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