码迷,mamicode.com
首页 > 系统相关 > 详细

Ubuntu10.04中间Leach协议一键安装

时间:2015-07-21 09:03:46      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:

半天后,尝试,引用网络上的零散资源,成品博客Leach协议ubuntu10.04在安装(12.04也可以在右侧安装,然而,实施效果的不,求解决~~),并制作了补丁。

一个关键的安装步骤如下面:

1.在用户文件夹创建一个新的文件夹,所谓随机。忠告“Leach”。

2.将一键安装包中的文件拷贝到Leach目录中。

3.运行脚本:./leach-install.sh

中间过程可能须要输入管理员权限的password。请依据自己设定输入。

因为无法上传附件,我在此将补丁文件和脚本贴出来,假设有须要安装包的。能够联系我。

1.补丁文件

diff -u -r ns-2.35-old/apps/app.cc ns-2.35/apps/app.cc
--- ns-2.35-old/apps/app.cc	1999-03-04 10:21:34.000000000 +0800
+++ ns-2.35/apps/app.cc	2014-05-13 19:59:14.636571596 +0800
@@ -50,6 +50,9 @@
 
 Application::Application() : enableRecv_(0), enableResume_(0)
 {
+#ifdef MIT_uAMPS
+	enableRecv_ = 1;
+#endif
 }
 
 
@@ -120,6 +123,22 @@
 	tcl.evalf("%s recv %d", name_, nbytes);
 }
 
+#ifdef MIT_uAMPS
+void Application::recv(int link_dst, int data_size, char* meta_data, int sender)
+{
+	if (! enableRecv_)
+		return;
+	Tcl& tcl = Tcl::instance();
+	tcl.evalf("%s recv %d %d %d %s", name_, link_dst, sender, data_size, meta_data);
+}
+void Application::recv(char* ch_index)
+{
+	if (! enableRecv_)
+		return;
+	Tcl& tcl = Tcl::instance();
+	tcl.evalf("%s recv %s", name_, ch_index);
+}
+#endif
 
 void Application::resume()
 {
diff -u -r ns-2.35-old/apps/app.h ns-2.35/apps/app.h
--- ns-2.35-old/apps/app.h	1999-09-28 11:46:27.000000000 +0800
+++ ns-2.35/apps/app.h	2014-05-13 19:58:00.964434062 +0800
@@ -50,6 +50,10 @@
 	Application();
 	virtual void send(int nbytes);
 	virtual void recv(int nbytes);
+#ifdef MIT_uAMPS
+	virtual void recv(int sendto, int data_size, char* meta_data, int sender);
+	virtual void recv(char* ch_index);
+#endif
 	virtual void resume();
 
 protected:
鍙湪 ns-2.35 瀛樺湪锛歛utoconf.h
diff -u -r ns-2.35-old/common/mobilenode.cc ns-2.35/common/mobilenode.cc
--- ns-2.35-old/common/mobilenode.cc	2006-02-22 21:21:52.000000000 +0800
+++ ns-2.35/common/mobilenode.cc	2014-05-13 20:01:14.620430927 +0800
@@ -338,6 +338,14 @@
 		"M %.5f %d (%.2f, %.2f, %.2f), (%.2f, %.2f), %.2f",
 		s.clock(), address_, X_, Y_, Z_, destX_, destY_, speed_);
 	log_target_->pt_->dump();
+#ifdef MIT_uAMPS
+#if 0
+	sprintf(log_target->buffer(),
+		"M %.5f %d (%.2f, %.2f, %.2f), (%.2f, %.2f), %.2f",
+		s.clock(), index_, X, Y, Z, destX, destY, speed);
+	log_target->dump();
+#endif
+#endif
 }
 
 
diff -u -r ns-2.35-old/common/packet.cc ns-2.35/common/packet.cc
--- ns-2.35-old/common/packet.cc	2008-02-18 11:39:02.000000000 +0800
+++ ns-2.35/common/packet.cc	2014-05-13 20:02:50.244395619 +0800
@@ -60,6 +60,9 @@
 int Packet::hdrlen_ = 0;		// size of a packet‘s header
 Packet* Packet::free_;			// free list
 int hdr_cmn::offset_;			// static offset of common header
+#ifdef MIT_uAMPS
+int hdr_rca::offset_;			// static offset of rca header
+#endif
 int hdr_flags::offset_;			// static offset of flags header
 
 
@@ -135,6 +138,18 @@
 	};
 } class_cmnhdr;
 
+#ifdef MIT_uAMPS
+
+class RCAHeaderClass : public PacketHeaderClass {
+public:
+    RCAHeaderClass() : PacketHeaderClass("PacketHeader/RCA",
+               sizeof(hdr_rca)) {
+      bind_offset(&hdr_rca::offset_);
+    }
+} class_rcahdr;
+
+#endif
+
 class FlagsHeaderClass : public PacketHeaderClass {
 public:
 	FlagsHeaderClass() : PacketHeaderClass("PacketHeader/Flags",
diff -u -r ns-2.35-old/common/packet.h ns-2.35/common/packet.h
--- ns-2.35-old/common/packet.h	2010-05-10 06:28:41.000000000 +0800
+++ ns-2.35/common/packet.h	2014-05-13 20:08:09.208346200 +0800
@@ -61,6 +61,10 @@
 #define HDR_IP(p)       (hdr_ip::access(p))
 #define HDR_RTP(p)      (hdr_rtp::access(p))
 #define HDR_TCP(p)      (hdr_tcp::access(p))
+#ifdef MIT_uAMPS
+#define HDR_RCA(p)      ((struct hdr_rca*)(p)->access(hdr_rca::offset_))
+#define HDR_MACSensor(p) 	((struct hdr_macSensor*)(p)->access(hdr_mac::offset_))
+#endif
 #define HDR_SCTP(p)     (hdr_sctp::access(p))
 #define HDR_SR(p)       (hdr_sr::access(p))
 #define HDR_TFRC(p)     (hdr_tfrc::access(p))
@@ -198,9 +202,12 @@
 
         // M-DART packets
 static const packet_t PT_MDART = 72;
-	
+
+#ifdef MIT_uAMPS
+static const packet_t PT_RCA = 73;
+#endif
         // insert new packet types here
-static packet_t       PT_NTYPE = 73; // This MUST be the LAST one
+static packet_t       PT_NTYPE = 74; // This MUST be the LAST one
 
 enum packetClass
 {
@@ -416,7 +423,9 @@
 		name_[PT_DCCP_CLOSE]="DCCP_Close";
 		name_[PT_DCCP_CLOSEREQ]="DCCP_CloseReq";
 		name_[PT_DCCP_RESET]="DCCP_Reset";
-
+#ifdef MIT_uAMPS
+		name_[PT_RCA] = "rca";
+#endif
 		name_[PT_NTYPE]= "undefined";
 	}
 	static int addPacket(char *name);
@@ -553,7 +562,9 @@
 	 * 
          */
         u_int8_t        incoming;
-
+#ifdef MIT_uAMPS
+  	 static void PrintRcHeader(Packet *p, char *layer);
+#endif
 	//monarch extns end;
 };
 
@@ -670,6 +681,48 @@
 	inline ModulationScheme& mod_scheme() { return (mod_scheme_); }
 };
 
+#ifdef MIT_uAMPS
+
+struct hdr_rca {
+  int msg_type_;
+  char meta_[1000]; 
+  int meta_size_;
+	float dist_to_dest_;
+	int dist_est_;
+  int rca_src_;
+  int rca_mac_dst_;
+  int rca_link_dst_;
+	int code_;
+
+	static int offset_;	// offset for this header
+  inline static int& offset() { return offset_; }
+  inline static hdr_rca* access(Packet* p) {
+    return (hdr_rca*) p->access(offset_);
+  }
+
+  /* per-field member functions */
+  inline int& msg_type() { return (msg_type_); }
+  inline int& meta_size() { return (meta_size_); }
+  inline float& get_dist() { return (dist_to_dest_); }
+  inline int& dist_est() { return (dist_est_); }
+  inline void set_meta(const char* data) {
+    meta_size_ = strlen(data);
+		if (meta_size_ > maxmetasize()) {
+			printf("Error:  Meta size %d too large (max = %d).\n", meta_size_, maxmetasize());
+			exit(1);
+		}
+    memcpy(meta_, data, meta_size_+1);
+  }
+  inline char* const meta() { return (meta_); }
+  inline int maxmetasize() { return (sizeof(meta_)); }
+  inline int& rca_src() { return (rca_src_); }
+  inline int& rca_mac_dst() { return (rca_mac_dst_); }
+  inline int& rca_link_dst() { return (rca_link_dst_); }
+  inline int& get_code() { return (code_); }
+
+};
+
+#endif
 
 class PacketHeaderClass : public TclClass {
 protected:
@@ -699,6 +752,10 @@
 		assert(p->fflag_ == FALSE);
 		free_ = p->next_;
 		assert(p->data_ == 0);
+#ifdef MIT_uAMPS
+  	hdr_rca* rca_hdr = HDR_RCA(p);
+  	rca_hdr->meta_size_ = 0;
+#endif
 		p->uid_ = 0;
 		p->time_ = 0;
 	} else {
@@ -718,6 +775,17 @@
 	return (p);
 }
 
+#ifdef MIT_uAMPS
+inline void Packet::PrintRcHeader(Packet *p, char *layer)
+{
+  hdr_cmn *hdr = HDR_CMN(p);
+  hdr_rca *rca_hdr = HDR_RCA(p);
+
+  printf("%s Layer received: Type=%d data_size=%d\n\tMeta = %s\n\tSource = %x\n\tTarget = %x\n\tLink_target = %x\n",layer,rca_hdr->msg_type(), hdr->size(), rca_hdr->meta(),rca_hdr->rca_src(), rca_hdr->rca_mac_dst(), rca_hdr->rca_link_dst());
+
+}
+#endif
+
 /* 
  * Allocate an n byte data buffer to an existing packet 
  * 
@@ -817,7 +885,15 @@
 	if (data_) 
 		p->data_ = data_->copy();
 	p->txinfo_.init(&txinfo_);
- 
+#ifdef MIT_uAMPS
+	hdr_rca* ch = HDR_RCA(this);
+	hdr_rca* new_ch = HDR_RCA(p);
+
+	if (ch->meta_size_) {
+		new_ch->meta_size_ = ch->meta_size_;
+  	memcpy(new_ch->meta_, ch->meta_, ch->meta_size_+1);
+	}
+#endif
 	return (p);
 }
 
鍙湪 ns-2.35 瀛樺湪锛歝onfig.log
鍙湪 ns-2.35 瀛樺湪锛歝onfig.status
鍙湪 ns-2.35 瀛樺湪锛歡en
鍙湪 ns-2.35/indep-utils/cmu-scen-gen/setdest 瀛樺湪锛歝alcdest
鍙湪 ns-2.35/indep-utils/cmu-scen-gen/setdest 瀛樺湪锛歁akefile
鍙湪 ns-2.35/indep-utils/webtrace-conv/dec 瀛樺湪锛歁akefile
鍙湪 ns-2.35/indep-utils/webtrace-conv/epa 瀛樺湪锛歁akefile
鍙湪 ns-2.35/indep-utils/webtrace-conv/nlanr 瀛樺湪锛歁akefile
鍙湪 ns-2.35/indep-utils/webtrace-conv/ucb 瀛樺湪锛歁akefile
鍙湪 ns-2.35 瀛樺湪锛歭each_test
diff -u -r ns-2.35-old/mac/channel.cc ns-2.35/mac/channel.cc
--- ns-2.35-old/mac/channel.cc	2009-01-03 05:50:24.000000000 +0800
+++ ns-2.35/mac/channel.cc	2014-05-13 20:10:13.372687539 +0800
@@ -121,7 +121,16 @@
 			((Phy*) obj)->setchnl(this);
 			return TCL_OK;
 		}
-
+#ifdef MIT_uAMPS
+		/* 
+		 * When nodes are dead (e.g., they have run out of energy), 
+		 * they must be removed from the network.
+		 */
+		else if(strcmp(argv[1], "removeif") == 0) {
+			((Phy*) obj)->deletechnl(&ifhead_);
+			return TCL_OK;
+		}
+#endif
 		// add interface for grid_keeper_
 		/*else if(strncasecmp(argv[1], "grid_keeper", 5) == 0) {
 			grid_keeper_ = (GridKeeper*)obj;
diff -u -r ns-2.35-old/mac/ll.h ns-2.35/mac/ll.h
--- ns-2.35-old/mac/ll.h	2010-03-08 13:54:52.000000000 +0800
+++ ns-2.35/mac/ll.h	2014-05-13 20:11:32.300421165 +0800
@@ -52,6 +52,9 @@
 };
 
 struct hdr_ll {
+#ifdef MIT_uAMPS
+public:
+#endif
 	LLFrameType lltype_;		// link-layer frame type
 	int seqno_;			// sequence number
 	int ackno_;			// acknowledgement number
@@ -105,7 +108,9 @@
 	int seqno_;			// link-layer sequence number
 	int ackno_;			// ACK received so far
 	int macDA_;			// destination MAC address
-	
+#ifdef MIT_uAMPS
+	double mindelay_;
+#endif	
         Queue* ifq_;			// interface queue
 	Mac*   mac_;		        // MAC object
         LanRouter* lanrouter_;          // for lookups of the next hop
鍙湪 ns-2.35/mac 瀛樺湪锛歮ac-sensor.cc
鍙湪 ns-2.35/mac 瀛樺湪锛歮ac-sensor.h
鍙湪 ns-2.35/mac 瀛樺湪锛歮ac-sensor-timers.cc
鍙湪 ns-2.35/mac 瀛樺湪锛歮ac-sensor-timers.h
diff -u -r ns-2.35-old/mac/phy.cc ns-2.35/mac/phy.cc
--- ns-2.35-old/mac/phy.cc	2005-09-19 07:33:33.000000000 +0800
+++ ns-2.35/mac/phy.cc	2014-05-13 20:17:43.501993087 +0800
@@ -57,6 +57,13 @@
 	channel_ = 0;
 	node_ = 0;
 	head_ = 0;
+#ifdef MIT_uAMPS
+	/* Keep track of when transmission ends for carrier sense. */
+	/* Since CDMA can be used with CSMA, need to keep track of when
+		 transmissions from each CDMA code will end. */
+	cs_end_ = new double[1000];
+	for (int i=0; i<1000; i++) cs_end_[i] = 0;
+#endif
 }
 
 int
diff -u -r ns-2.35-old/mac/phy.h ns-2.35/mac/phy.h
--- ns-2.35-old/mac/phy.h	2000-08-17 08:03:38.000000000 +0800
+++ ns-2.35/mac/phy.h	2014-05-13 20:45:37.292391713 +0800
@@ -90,6 +90,12 @@
 		LIST_INSERT_HEAD(head, this, chnl_link_);
 		//channel_ = chnl;
 	}
+#ifdef MIT_uAMPS
+	inline void deletechnl(struct if_head *head) {
+		LIST_REMOVE(this, chnl_link_);
+		//delete channel_;
+	}
+#endif
 	// list of all network interfaces on a node
 	Phy* nextnode(void) const { return node_link_.le_next; }
 	inline void insertnode(struct if_head* head) {
@@ -136,7 +142,11 @@
 	
 	double bandwidth_;                   // bit rate
 	Channel         *channel_;    // the channel for output
-
+#ifdef MIT_uAMPS
+	double *cs_end_;  // time when carrier sence will end per code
+public:
+	inline double csEnd(int code) { return cs_end_[code]; }
+#endif
 };
 
 
diff -u -r ns-2.35-old/mac/wireless-phy.cc ns-2.35/mac/wireless-phy.cc
--- ns-2.35-old/mac/wireless-phy.cc	2007-09-04 12:32:18.000000000 +0800
+++ ns-2.35/mac/wireless-phy.cc	2014-05-13 20:48:04.392443613 +0800
@@ -75,6 +75,25 @@
 
 WirelessPhy::WirelessPhy() : Phy(), sleep_timer_(this), status_(IDLE)
 {
+#ifdef MIT_uAMPS
+  alive_ = 1;   	// 0 = dead, 1 = alive
+  bandwidth_ = 1000000;                // 100 Mbps
+  Efriss_amp_ = 100 * 1e-12;           // Friss amp energy (J/bit/m^2)
+  Etwo_ray_amp_ = 0.013 * 1e-12;       // Two-ray amp energy (J/bit/m^4)
+  EXcvr_ = 50 * 1e-9;                  // Xcvr energy (J/bit)
+  // Use this base threshold to get a "hearing radius" of ~ 1 m
+  Pfriss_amp_ = Efriss_amp_ * bandwidth_;      // Friss power (W/m^2)
+  Ptwo_ray_amp_ = Etwo_ray_amp_ * bandwidth_;  // Two-ray power (W/m^4)
+  PXcvr_ = EXcvr_ * bandwidth_;        // Xcvr power (W)
+  sleep_ = 0;                          // 0 = awake, 1 = asleep
+  ss_ = 1;                             // amount of spreading
+  time_finish_rcv_ = 0;                            
+  dist_ = 0;                           // approx. distance to transmitter 
+  energy_ = 0;   
+#else
+  bandwidth_ = 2*1e6;                 // 2 Mb
+  Pt_ = pow(10, 2.45) * 1e-3;         // 24.5 dbm, ~ 281.8mw
+#endif	
 	/*
 	 *  It sounds like 10db should be the capture threshold.
 	 *
@@ -97,7 +116,16 @@
 	bind("Pt_", &Pt_);
 	bind("freq_", &freq_);
 	bind("L_", &L_);
-	
+#ifdef MIT_uAMPS
+  bind("alive_",&alive_);
+  bind("bandwidth_",&bandwidth_);
+  bind("Efriss_amp_", &Efriss_amp_);
+  bind("Etwo_ray_amp_", &Etwo_ray_amp_);
+  bind("EXcvr_", &EXcvr_); 
+  bind("sleep_",&sleep_);
+  bind("ss_",&ss_);
+  bind("dist_",&dist_);
+#endif	
 	lambda_ = SPEED_OF_LIGHT / freq_;
 
 	node_ = 0;
@@ -196,6 +224,12 @@
 			node_ = (Node *)obj;
 			return TCL_OK;
 		}
+#ifdef MIT_uAMPS
+    else if (strcasecmp(argv[1], "attach-energy") == 0) {
+      energy_ = (EnergyResource*) obj;
+      return TCL_OK;
+    }
+#endif
 	}
 	return Phy::command(argc,argv);
 }
@@ -207,7 +241,47 @@
 	 * Sanity Check
 	 */
 	assert(initialized());
-	
+#ifdef MIT_uAMPS
+  /* 
+   * The power for transmission depends on the distance between
+   * the transmitter and the receiver.  If this distance is
+   * less than the crossover distance:
+   *       (c_d)^2 =  16 * PI^2 * L * hr^2 * ht^2
+   *               ---------------------------------
+   *                           lambda^2
+   * the power falls off using the Friss equation.  Otherwise, the
+   * power falls off using the two-ray ground reflection model.
+   * Therefore, the power for transmission of a bit is:
+   *      Pt = Pfriss_amp_*d^2 if d < c_d
+   *      Pt = Ptwo_ray_amp_*d^4 if d >= c_d. 
+   * The total power dissipated per bit is PXcvr_ + Pt.
+   */
+  hdr_cmn *ch = HDR_CMN(p);
+  hdr_rca *rca_hdr = HDR_RCA(p);
+  double d = rca_hdr->get_dist();
+  double hr, ht;        // height of recv and xmit antennas
+  double tX, tY, tZ;    // transmitter location 
+  ((MobileNode *)node_)->getLoc(&tX, &tY, &tZ); 
+  ht = tZ + ant_->getZ();
+  hr = ht;              // assume receiving node and antenna at same height
+  double crossover_dist = sqrt((16 * PI * PI * L_ * ht * ht * hr * hr) 
+                             / (lambda_ * lambda_));
+  if (d < crossover_dist) 
+    if (d > 1)
+       Pt_ = Efriss_amp_ * bandwidth_ * d * d;
+    else 
+      // Pfriss_amp_ is the minimum transmit amplifier power.
+      Pt_ = Efriss_amp_ * bandwidth_;
+  else
+    Pt_ = Etwo_ray_amp_ * bandwidth_ * d * d * d * d;
+  PXcvr_ = EXcvr_ * bandwidth_;
+
+  if (energy_)
+  { 
+    if (energy_->remove(pktEnergy(Pt_, PXcvr_, ch->size())) != 0) 
+      alive_ = 0;
+  }
+#endif
 	if (em()) {
 			//node is off here...
 			if (Is_node_on() != true ) {
@@ -317,7 +391,24 @@
 	PacketStamp s;
 	double Pr;
 	int pkt_recvd = 0;
-
+#ifdef MIT_uAMPS
+  hdr_cmn *ch = HDR_CMN(p);
+  hdr_rca *rca_hdr = HDR_RCA(p);
+  /* 
+   * Record when this packet ends and its code.
+   */
+  int code = rca_hdr->get_code();
+  cs_end_[code] = Scheduler::instance().clock() + txtime(p);
+  /* 
+   * If the node is asleep, drop the packet. 
+   */
+  if (sleep_) {
+      //printf("Sleeping node... carrier sense ends at %f\n", cs_end_);
+      //fflush(stdout);
+      pkt_recvd = 0;
+      goto DONE;
+  } 
+#endif 
 	Pr = p->txinfo_.getTxPr();
 	
 	// if the node is in sleeping mode, drop the packet simply
@@ -367,7 +458,44 @@
 		hdr_cmn *hdr = HDR_CMN(p);
 		hdr->error() = modulation_->BitError(Pr);
 	}
-	
+#ifdef MIT_uAMPS
+  /* 
+   * Only remove energy from nodes that are awake and not currently
+   * transmitting a packet.
+   */
+  if (Scheduler::instance().clock() >= time_finish_rcv_) {
+    PXcvr_ = EXcvr_ * bandwidth_;
+    if (energy_)
+    { 
+      if (energy_->remove(pktEnergy((double)0, PXcvr_,ch->size())) != 0)
+        alive_ = 0;
+    }
+    time_finish_rcv_ = Scheduler::instance().clock() + txtime(p);
+  }
+  /*
+   * Determine approximate distance of node transmitting node 
+   * from received power.
+   */
+  double hr, ht;        // height of recv and xmit antennas
+  double rX, rY, rZ;    // receiver location
+  double d1, d2;
+  double crossover_dist, Pt, M;
+  ((MobileNode *)node_)->getLoc(&rX, &rY, &rZ);
+  hr = rZ + ant_->getZ();
+  ht = hr;              // assume transmitting node antenna at same height
+
+  crossover_dist = sqrt((16 * PI * PI * L_ * ht * ht * hr * hr)
+                             / (lambda_ * lambda_));
+  Pt = p->txinfo_.getTxPr();
+  M = lambda_ / (4 * PI);
+  d1 = sqrt( (Pt * M * M) / (L_ * Pr) );
+  d2 = sqrt(sqrt( (Pt * hr * hr * ht * ht) / Pr) );
+  if (d1 < crossover_dist)
+    dist_ = d1;
+  else
+    dist_ = d2;
+  rca_hdr->dist_est() = (int) ceil(dist_);
+#endif	
 	/*
 	 * The MAC layer must be notified of the packet reception
 	 * now - ie; when the first bit has been detected - so that
@@ -600,3 +728,23 @@
 	
 	sleep_timer_.resched(10.0);
 }
+
+#ifdef MIT_uAMPS
+double
+WirelessPhy::pktEnergy(double pt, double pxcvr, int nbytes)
+{
+
+  /* 
+   * Energy (in Joules) is power (in Watts=Joules/sec) divided by 
+   * bandwidth (in bits/sec) multiplied by the number of bytes, times 8 bits.
+   */
+  // If data has been spread, power per DATA bit should be the same
+  // as if there was no spreading ==> divide transmit power
+  // by spreading factor.
+  double bits = (double) nbytes * 8;
+  pt /= ss_;
+  double j = bits * (pt + pxcvr) / bandwidth_;
+  return(j);
+}
+
+#endif
diff -u -r ns-2.35-old/mac/wireless-phy.h ns-2.35/mac/wireless-phy.h
--- ns-2.35-old/mac/wireless-phy.h	2007-01-30 13:00:50.000000000 +0800
+++ ns-2.35/mac/wireless-phy.h	2014-05-13 21:07:12.060482931 +0800
@@ -48,7 +48,9 @@
 #include "phy.h"
 #include "mobilenode.h"
 #include "timer-handler.h"
-
+#ifdef MIT_uAMPS
+#include <mit/rca/energy.h>
+#endif
 class Phy;
 class Propagation;
 class WirelessPhy;
@@ -121,11 +123,30 @@
 	double CPThresh_;	// capture threshold (db)
   
 	Antenna *ant_;
+#ifdef MIT_uAMPS
+	EnergyResource *energy_;  // Energy resource
+	int alive_;		// 0 = dead, 1 = alive
+//endif
+//ifdef MIT_uAMPS_temp
+	double Efriss_amp_;	// Xmit amp energy (J/bit/m^2)
+	double Etwo_ray_amp_;	// Xmit amp energy (J/bit/m^4)
+	double EXcvr_;		// Xcvr energy (J/bit)
+	double Pfriss_amp_;	// Friss base transmission power (W/m^2)
+	double Ptwo_ray_amp_;	// Two-ray base transmission power (W/m^4)
+	double PXcvr_;      	// Xcvr Power (W)
+	int sleep_;		// 0 = awake, 1 = asleep
+	int ss_;		// amount of spreading
+	double time_finish_rcv_;			
+	double dist_;	        // approx. distance to transmitter
+private:
+	double pktEnergy(double pt, double pxcvr, int nbytes);
+#endif
+protected:
 	Propagation *propagation_;	// Propagation Model
 	Modulation *modulation_;	// Modulation Schem
 
 	// Why phy has a node_ and this guy has it all over again??

-// MobileNode* node_; // Mobile Node to which interface is attached . + //MobileNode* node_; // Mobile Node to which interface is attached . enum ChannelStatus { SLEEP, IDLE, RECV, SEND }; bool node_on_; // on-off status of this node 鍙湪 ns-2.35 瀛樺湪锛歁akefile diff -u -r ns-2.35-old/Makefile.in ns-2.35/Makefile.in --- ns-2.35-old/Makefile.in 2011-10-24 00:29:54.000000000 +0800 +++ ns-2.35/Makefile.in 2014-05-13 20:36:28.672410926 +0800 @@ -59,7 +59,7 @@ LDFLAGS = @LDFLAGS@ LDOUT = -o $(BLANK) -DEFINE = -DTCP_DELAY_BIND_ALL -DNO_TK @V_DEFINE@ @V_DEFINES@ @DEFS@ -DNS_DIFFUSION -DSMAC_NO_SYNC -DCPP_NAMESPACE=@CPP_NAMESPACE@ -DUSE_SINGLE_ADDRESS_SPACE -Drng_test +DEFINE = -DTCP_DELAY_BIND_ALL -DNO_TK @V_DEFINE@ @V_DEFINES@ @DEFS@ -DNS_DIFFUSION -DSMAC_NO_SYNC -DCPP_NAMESPACE=@CPP_NAMESPACE@ -DUSE_SINGLE_ADDRESS_SPACE -Drng_test -DMIT_uAMPS INCLUDES = -I. @V_INCLUDE_X11@ @@ -72,7 +72,7 @@ -I./diffusion3/lib/nr -I./diffusion3/ns -I./diffusion3/filter_core -I./asim/ -I./qs -I./diffserv -I./satellite - -I./wpan + -I./wpan -I./mit/rca -I./mit/uAMPS LIB = @@ -333,6 +333,9 @@ wpan/p802_15_4sscs.o wpan/p802_15_4timer.o wpan/p802_15_4trace.o wpan/p802_15_4transac.o apps/pbc.o + mit/rca/energy.o mit/rca/rcagent.o + mit/rca/rca-ll.o mit/rca/resource.o + mac/mac-sensor-timers.o mac/mac-sensor.o mit/uAMPS/bsagent.o @V_STLOBJ@ 鍙湪 ns-2.35 瀛樺湪锛歮it 鍙湪 ns-2.35/tcl/ex 瀛樺湪锛?94demo.nam 鍙湪 ns-2.35/tcl/ex 瀛樺湪锛?94demo.tr 鍙湪 ns-2.35/tcl/ex 瀛樺湪锛歭each-wireless.tcl 鍙湪 ns-2.35/tcl/lib 瀛樺湪锛歯s-autoconf.tcl diff -u -r ns-2.35-old/tcl/lib/ns-default.tcl ns-2.35/tcl/lib/ns-default.tcl --- ns-2.35-old/tcl/lib/ns-default.tcl 2010-07-04 06:45:45.000000000 +0800 +++ ns-2.35/tcl/lib/ns-default.tcl 2014-05-13 21:13:13.196383783 +0800 @@ -1590,3 +1590,11 @@ Agent/MDART set macFailed_ true Agent/MDART set etxMetric_ true + +#Phy/WirelessPhy set alive_ 1 +#Phy/WirelessPhy set Efriss_amp_ 100 * 1e-12 +#Phy/WirelessPhy set Etwo_ray_amp_ +#Phy/WirelessPhy set EXcvr_ +#Phy/WirelessPhy set sleep_ +#Phy/WirelessPhy set ss_ +#Phy/WirelessPhy set dist_ 鍙湪 ns-2.35/tcl/mobility 瀛樺湪锛歭each-c.tcl 鍙湪 ns-2.35/tcl/mobility 瀛樺湪锛歭each.tcl 鍙湪 ns-2.35/tcl/mobility 瀛樺湪锛歮te.tcl 鍙湪 ns-2.35/tcl/mobility 瀛樺湪锛歴tat-clus.tcl 鍙湪 ns-2.35 瀛樺湪锛歵est diff -u -r ns-2.35-old/trace/cmu-trace.cc ns-2.35/trace/cmu-trace.cc --- ns-2.35-old/trace/cmu-trace.cc 2011-10-03 06:32:35.000000000 +0800 +++ ns-2.35/trace/cmu-trace.cc 2014-05-13 20:31:31.096823052 +0800 @@ -64,6 +64,9 @@ //</zheng: add for 802.15.4> #include "diffusion/diff_header.h" // DIFFUSION -- Chalermek +#ifdef MIT_uAMPS +#include <mit/rca/rcagent.h> +#endif PacketTracer::PacketTracer() : next_(0) @@ -1415,6 +1418,11 @@ case PT_ARP: format_arp(p, offset); break; +#ifdef MIT_uAMPS + case PT_RCA: + format_rca(p,offset); + break; +#endif default: format_ip(p, offset); offset = strlen(pt_->buffer()); @@ -1451,6 +1459,10 @@ case PT_CBR: format_rtp(p, offset); break; +#ifdef MIT_uAMPS + case PT_RCA: + break; +#endif case PT_DIFF: break; case PT_GAF: @@ -1603,3 +1615,40 @@ duration_scaling_factor_ = atof(tcl.result()); } //</zheng> + +#ifdef MIT_uAMPS +void +CMUTrace::format_rca(Packet *p, int offset) +{ + struct hdr_rca *rca_hdr = HDR_RCA(p); + char op = (char) type_; + + switch (rca_hdr->msg_type()) + { + case ADV: + op = ADV_CHAR; + break; + + case REQ: + op = REQ_CHAR; + break; + + case DATA: + op = DATA_CHAR; + break; + + default: + //printf("format_rca: Warning, unknown meta-data type %d\n",rca_hdr->msg_type()); + op = (char) type_; + break; + } + + sprintf(pt_->buffer() + offset, "------- [%c %d %d %d] ", + op, + rca_hdr->rca_src(), + rca_hdr->rca_link_dst(), + rca_hdr->rca_mac_dst() + ); + return; +} +#endif diff -u -r ns-2.35-old/trace/cmu-trace.h ns-2.35/trace/cmu-trace.h --- ns-2.35-old/trace/cmu-trace.h 2010-05-10 06:28:41.000000000 +0800 +++ ns-2.35/trace/cmu-trace.h 2014-05-13 20:32:22.196397952 +0800 @@ -56,7 +56,11 @@ // change wrt Mike‘s code #define EOT ‘x‘ - +#ifdef MIT_uAMPS +#define ADV_CHAR ‘A‘ +#define REQ_CHAR ‘R‘ +#define DATA_CHAR ‘D‘ +#endif #define TR_ROUTER 0x01 @@ -161,7 +165,9 @@ void format_aodv(Packet *p, int offset); void format_aomdv(Packet *p, int offset); void format_mdart(Packet *p, int offset); - +#ifdef MIT_uAMPS + void format_rca(Packet *p, int offset); +#endif // This holds all the tracers added at run-time static PacketTracer *pktTrc_;


 

2.脚本文件

#!/bin/sh
echo "Before installing NS2, you should ensure that the ‘ns-allinone-2.35‘ is in ‘/home/<your name>/Leach‘"
echo "If the files is right, press any key. Otherwise, press ‘Ctrl+D‘"
read ch
sudo apt-get update
sudo apt-get install libx11-dev libxmu-dev libxmu-headers libxt-dev libtool g++ patch tcl tk tcl-dev tk-dev gnuplot
tar -zxvf ns-allinone-2.35.tar.gz
cp -ir ns-2.35 ns-allinone-2.35/
cp leach.diff ns-allinone-2.35
cd ns-allinone-2.35
patch -p0 < leach.diff
./install
cd ..
echo "The NS2 has been installed. If you want to configure ‘.bashrc‘ file automatically, press any key. Otherwise, press ‘Ctrl+D‘"
read ch
pathto=$(pwd)
echo "export PATH=\$PATH:$pathto/ns-allinone-2.35/bin:$pathto/ns-allinone-2.35/tcl8.5.10/unix:$pathto/ns-allinone-2.35/tk8.5.10/unix" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$pathto/ns-allinone-2.35/otcl-1.14:$pathto/ns-allinone-2.35/lib" >> ~/.bashrc
echo "export LD_LIBRARY=\$LD_LIBRARY:$pathto/ns-allinone-2.35/tcl8.5.10/library" >> ~/.bashrc
echo "export RCA_LIBRARY=$pathto/ns-allinone-2.35/ns-2.35/mit/rca" >> ~/.bashrc
echo "export uAMPS_LIBRARY=$pathto/ns-allinone-2.35/ns-2.35/mit/uAMPS" >> ~/.bashrc
echo "echo \"==================Welcome to use NS2 for Leach!=====================\"" >> ~/.bashrc
echo "echo \"If you have any questions, please contact norbert_jxl AT 163.com\"" >> ~/.bashrc
echo "The ‘.bashrc‘ file is configured!"


 

版权声明:本文博客原创文章,博客,未经同意,不得转载。

Ubuntu10.04中间Leach协议一键安装

标签:

原文地址:http://www.cnblogs.com/mengfanrong/p/4663347.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!