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

📄 patch.mac

📁 ns2网络仿真中超宽带的实现
💻 MAC
📖 第 1 页 / 共 5 页
字号:
+	} ++	return totalInterferencePower;+}++void+InterferencePhy::insertInterferenceListEntry(double start, double end, double power, double sync)+{+	InterferenceListEntry *prev = 0;+	InterferenceListEntry *i = first_ifpkt;++	//printf("%12.11f insert\n", Scheduler::instance().clock());+	// look for free slot+	while (i) {+		if (i->used) {+			prev = i;+			i = i->next;+		} else {+			break;+		}+	}+	if (i == 0) {+		i = new InterferenceListEntry;+		if (prev)+			prev->next = i;+		else+			first_ifpkt = i;+		i->next = 0;+	}+	i->receivedPower = power;+	i->rxStartTime = start;+	i->rxEndTime = end;+	i->used = 1;+	i->syncCoefficient = sync;+}++/*+void+InterferencePhy::removeInterferenceListEntry(InterferenceListEntry *prev, InterferenceListEntry *current)+{+	assert(current);+	// set last to previous entry (or to 0 if it was the only entry)+	if (current == last_ifpkt)+		last_ifpkt = prev;+	if (current == first_ifpkt) {+		first_ifpkt = current->next;+	} else {+		assert(prev);+		prev->next = current->next;	+	}+	delete current;		+}+*/++double+InterferencePhy::txtime(Packet *p)+{+	struct hdr_cmn *ch = HDR_CMN(p);+	double t = ch->txtime();+	assert(t > 0.0);+	return t;+}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/interference-phy.h mac/interference-phy.h--- /home/rmerz/NS/ns-allinone-2.26/ns-2.26/mac/interference-phy.h	1970-01-01 01:00:00.000000000 +0100+++ mac/interference-phy.h	2004-02-17 12:08:52.000000000 +0100@@ -0,0 +1,168 @@+/* -*-	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/interference-phy.h,v 1.7 2004/01/28 13:25:19 widmer Exp $+ *+ * Ported from CMU/Monarch's code, nov'98 -Padma Haldar.+ *+ * interference-phy.h+ * -- a SharedMedia network interface+ */++#ifndef ns_InterferencePhy_h+#define ns_InterferencePhy_h++#include "packet.h"+#include "timer-handler.h"+#include "wireless-phy.h"+#include "modulation.h"+#include "mod_codedppm.h"++//#define min(x, y)       ((x) < (y) ? (x) : (y))+//#define max(x, y)       ((x) > (y) ? (x) : (y))++#define POWER_SPECTRAL_DENSITY 4e-21++// we see an erasure if interference power is 9x received power+// (<-- 3x difference in energy)+#define ERASURE_COEFFICIENT 25++enum PhyState {+	PHY_IDLE	= 0x0000,+	PHY_RECV 	= 0x0010,+	PHY_SEND 	= 0x0100,+	PHY_COLL	= 0x1000+};++/* + * to speed up simulations we never free entries but reuse unused+ * ones (-> have list of max. # of concurrent packets)+ */+struct InterferenceListEntry {+	InterferenceListEntry *next;+	double receivedPower;+	double rxEndTime;+	double rxStartTime;+	double syncCoefficient;+	int used;+};++class InterferencePhy;++class PhyIdleTimer : public TimerHandler {+public:+	PhyIdleTimer(InterferencePhy *p) : TimerHandler() { phy_ = p; }+	virtual void expire(Event *e);+protected:+	InterferencePhy *phy_;+};	++class PhyRecvTimer : public TimerHandler {+public:+	PhyRecvTimer(InterferencePhy *p) : TimerHandler() { phy_ = p; }+	virtual void expire(Event *e);+protected:+	InterferencePhy *phy_;+};	++class InterferencePhy : public WirelessPhy {+	friend class PhyIdleTimer;+	friend class PhyRecvTimer;+public:+	InterferencePhy();+	virtual int command(int argc, const char*const* argv);+	+	virtual void recv(Packet* p, Handler* h);+	virtual int sendUp(Packet *p);+	inline int is_idle() { return if_state == PHY_IDLE; }+	inline int best_code() {+		CodedPPM* cppm = dynamic_cast<CodedPPM*>(modulation_);+		return (cppm ? (cppm->bestCode()) : -1);+	}++	inline float CACDMApower() {+		CodedPPM* cppm = dynamic_cast<CodedPPM*>(modulation_);+		return (cppm ? (cppm->CACDMApower()) : -1);+	}++	inline int& tx_ths() { return (tx_ths_); }+	inline int& rx_ths() { return (rx_ths_); }+	inline int& own_ths() { return (own_ths_); }+	inline int& code_id() { return (code_id_); }+	inline double bitrate() { return bitrate_; }+	inline double ppm_rate(int code) {+		CodedPPM* cppm = dynamic_cast<CodedPPM*>(modulation_);+		return (cppm ? (cppm->ppm_rate(code)) : -1);+	}+	inline void setPt(double p) { Pt_ = p; }+	inline double getPt() { return Pt_; }++	inline double getRxEnd() { return rxEnd; }++protected:+	double maxInterferencePower();+	double avgInterferencePower();+	double syncOverlap(double sync);+	double avgErasures();++	void insertInterferenceListEntry(double start, double end, double power, double sync);+	//void removeInterferenceListEntry(InterferenceListEntry *prev, InterferenceListEntry *current);+	double txtime(Packet *p);++	void idle_handler();+	void recv_handler();++	//InterferenceListEntry *last_ifpkt;+	InterferenceListEntry *first_ifpkt;      /* head of interference list */+	Packet *pktRx_;                          /* packet currently being received */+	double rxStart;                          /* start time of packet reception */+	double rxEnd;                            /* end time of packet reception */+	double rxPower;                          /* receive power in W */+	double frequency_range_;                 /* bandwidth in Hz */+	double noise_factor_;                    /* noise factor (of receiver) in dB */+	double bitrate_;                         /* coded bitrate on channel */+	int erasure_coefficient_;                /* received energy higher than expected by this factor -> erasure */+	int use_timehopping_;                    /* node uses quasi-orthogonal TH thss */++	// the THS is set by the MAC layer+	int tx_ths_;                             /* TH sequence used for transmissions */+	int rx_ths_;                             /* TH sequence node is listening on */+	int own_ths_;                            /* node always listens on own TH sequence as well */+	int code_id_;                            /* index of the code (for error correction) */++	PhyState if_state;+	PhyIdleTimer idle_timer;+	PhyRecvTimer recv_timer;+};++#endif /* ns_InterferencePhy_h */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.h mac/mac-802_11.h--- /home/rmerz/NS/ns-allinone-2.26/ns-2.26/mac/mac-802_11.h	2003-02-26 23:08:56.000000000 +0100+++ mac/mac-802_11.h	2004-02-17 13:53:44.000000000 +0100@@ -301,7 +301,7 @@ 	} 	double txtime(Packet *p); 	double txtime(double psz, double drt);-	double txtime(int bytes) { /* clobber inherited txtime() */ abort(); }+	double txtime(int bytes) { /* clobber inherited txtime() */ abort(); return 0;}  	inline void inc_cw() { 		cw_ = (cw_ << 1) + 1;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.cc mac/mac-802_11-if.cc--- /home/rmerz/NS/ns-allinone-2.26/ns-2.26/mac/mac-802_11-if.cc	1970-01-01 01:00:00.000000000 +0100+++ mac/mac-802_11-if.cc	2004-01-30 16:33:07.000000000 +0100@@ -0,0 +1,1514 @@+/* -*-	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.cc,v 1.2 2003/11/20 10:43:52 widmer Exp $+ *+ * Ported from CMU/Monarch's code, nov'98 -Padma.+ */++#include "delay.h"+#include "connector.h"+#include "packet.h"+#include "random.h"+#include "mobilenode.h"++// #define DEBUG 99++#include "arp.h"+#include "ll.h"+#include "mac.h"+#include "mac-802_11-if.h"+#include "cmu-trace.h"+++// XXX Can't we make these macros inline methods? Otherwise why should we have+// inline methods at all??++#define CHECK_BACKOFF_TIMER()						\+{									\+	if(is_idle() && mhBackoff_.paused())				\+		mhBackoff_.resume(difs_);				\+	if(! is_idle() && mhBackoff_.busy() && ! mhBackoff_.paused())	\+		mhBackoff_.pause();					\+}++#define TRANSMIT(p, t)                                                  \+{                                                                       \+	tx_active_ = 1;                                                  \+                                                                        \+        /*                                                              \+         * If I'm transmitting without doing CS, such as when           \+         * sending an ACK, any incoming packet will be "missed"         \+         * and hence, must be discarded.                                \+         */                                                             \+        if(rx_state_ != MAC_IDLE) {                                      \+		assert(0); /* JCW */                                        \+                struct hdr_mac802_11 *dh = HDR_MAC802_11(p);                  \+                                                                        \+                assert(dh->dh_fc.fc_type == MAC_Type_Control);          \+                assert(dh->dh_fc.fc_subtype == MAC_Subtype_ACK);        \+                                                                        \+                assert(pktRx_);                                          \+                struct hdr_cmn *ch = HDR_CMN(pktRx_);                    \+                                                                        \+                ch->error() = 1;        /* force packet discard */      \+        }                                                               \+                                                                        \+        /*                                                              \+         * pass the packet on the "interface" which will in turn        \+         * place the packet on the channel.                             \+         *                                                              \+         * NOTE: a handler is passed along so that the Network          \+         *       Interface can distinguish between incoming and         \+         *       outgoing packets.                                      \+         */                                                             \+        downtarget_->recv(p->copy(), this);                             \+                                                                        \+        mhSend_.start(t);                                                \+                                                                        \+	mhIF_.start(txtime(p));                                         \+}++#define SET_RX_STATE(x)			\+{					\+	rx_state_ = (x);		\+	CHECK_BACKOFF_TIMER();		\+}++#define SET_TX_STATE(x)				\+{						\+	tx_state_ = (x);			\+	CHECK_BACKOFF_TIMER();			\+}++/* ======================================================================+   Global Variables+   ====================================================================== */++static PHY_MIB PMIB =+{+	DSSS_CWMin, DSSS_CWMax, DSSS_SlotTime, DSSS_CCATime,+	DSSS_RxTxTurnaroundTime, DSSS_SIFSTime, DSSS_PreambleLength,+	DSSS_PLCPHeaderLength, DSSS_PLCPDataRate+};	++static MAC_MIB MMIB =+{+	MAC_IF_RTSThreshold, MAC_ShortRetryLimit,+	MAC_LongRetryLimit, MAC_FragmentationThreshold,+	MAC_MaxTransmitMSDULifetime, MAC_MaxReceiveLifetime,+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0+};++/* ======================================================================+   TCL Hooks for the simulator+   ====================================================================== */+static class Mac802_11_ifClass : public TclClass {+public:+	Mac802_11_ifClass() : TclClass("Mac/802_11_if") {}+	TclObject* create(int, const char*const*) {+		return (new Mac802_11_if(&PMIB, &MMIB));+	}+} class_mac802_11_if;+++/* ======================================================================+   Mac Class Functions+   ====================================================================== */+Mac802_11_if::Mac802_11_if(PHY_MIB *p, MAC_MIB *m) : Mac(), mhIF_(this), mhNav_(this), mhRecv_(this), mhSend_(this), mhDefer_(this, p->SlotTime), mhBackoff_(this, p->SlotTime)+{+	macmib_ = m;+	phymib_ = p;+	+	nav_ = 0.0;+	+	tx_state_ = rx_state_ = MAC_IDLE;+	tx_active_ = 0;+	+	pktRTS_ = 0;+	pktCTRL_ = 0;++	cw_ = phymib_->CWMin;+	ssrc_ = slrc_ = 0;+	+	sifs_ = phymib_->SIFSTime;+	pifs_ = sifs_ + phymib_->SlotTime;+	difs_ = sifs_ + 2*phymib_->SlotTime;+	+	// see (802.11-1999, 9.2.10) +	eifs_ = sifs_ + (8 * ETHER_ACK_LEN / phymib_->PLCPDataRate) + difs_;+	+	tx_sifs_ = sifs_ - phymib_->RxTxTurnaroundTime;+	tx_pifs_ = tx_sifs_ + phymib_->SlotTime;+	tx_difs_ = tx_sifs_ + 2 * phymib_->SlotTime;+	+	sta_seqno_ = 1;+	cache_ = 0;+	cache_node_count_ = 0;+	+	// chk if basic/data rates are set+	// otherwise use bandwidth_ as default;+	+	Tcl& tcl = Tcl::instance();+	tcl.evalf("Mac/802_11_if set basicRate_");+	if (strcmp(tcl.result(), "0") != 0) +		bind_bw("basicRate_", &basicRate_);+	else+		basicRate_ = bandwidth_;++	tcl.evalf("Mac/802_11_if set dataRate_");+	if (strcmp(tcl.result(), "0") != 0) +		bind_bw("dataRate_", &dataRate_);+	else+		dataRate_ = bandwidth_;+}+++int+Mac802_11_if::command(int argc, const char*const* argv)+{+	if (argc == 3) {+		if (strcmp(argv[1], "log-target") == 0) {+			logtarget_ = (NsObject*) TclObject::lookup(argv[2]);+			if(logtarget_ == 0)+				return TCL_ERROR;+			return TCL_OK;+		} else if(strcmp(argv[1], "nodes") == 0) {+			if(cache_) return TCL_ERROR;

⌨️ 快捷键说明

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