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

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

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

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

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

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

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

1.补丁文件

  1. diff -u -r ns-2.35-old/apps/app.cc ns-2.35/apps/app.cc
  2. --- ns-2.35-old/apps/app.cc 1999-03-04 10:21:34.000000000 +0800
  3. +++ ns-2.35/apps/app.cc 2014-05-13 19:59:14.636571596 +0800
  4. @@ -50,6 +50,9 @@
  5.  
  6. Application::Application() : enableRecv_(0), enableResume_(0)
  7. {
  8. +#ifdef MIT_uAMPS
  9. + enableRecv_ = 1;
  10. +#endif
  11. }
  12.  
  13. @@ -120,6 +123,22 @@
  14. tcl.evalf("%s recv %d", name_, nbytes);
  15. }
  16.  
  17. +#ifdef MIT_uAMPS
  18. +void Application::recv(int link_dst, int data_size, char* meta_data, int sender)
  19. +{
  20. + if (! enableRecv_)
  21. + return;
  22. + Tcl& tcl = Tcl::instance();
  23. + tcl.evalf("%s recv %d %d %d %s", name_, link_dst, sender, data_size, meta_data);
  24. +}
  25. +void Application::recv(char* ch_index)
  26. +{
  27. + if (! enableRecv_)
  28. + return;
  29. + Tcl& tcl = Tcl::instance();
  30. + tcl.evalf("%s recv %s", name_, ch_index);
  31. +}
  32. +#endif
  33.  
  34. void Application::resume()
  35. {
  36. diff -u -r ns-2.35-old/apps/app.h ns-2.35/apps/app.h
  37. --- ns-2.35-old/apps/app.h 1999-09-28 11:46:27.000000000 +0800
  38. +++ ns-2.35/apps/app.h 2014-05-13 19:58:00.964434062 +0800
  39. @@ -50,6 +50,10 @@
  40. Application();
  41. virtual void send(int nbytes);
  42. virtual void recv(int nbytes);
  43. +#ifdef MIT_uAMPS
  44. + virtual void recv(int sendto, int data_size, char* meta_data, int sender);
  45. + virtual void recv(char* ch_index);
  46. +#endif
  47. virtual void resume();
  48.  
  49. protected:
  50. 鍙湪 ns-2.35 瀛樺湪锛歛utoconf.h
  51. diff -u -r ns-2.35-old/common/mobilenode.cc ns-2.35/common/mobilenode.cc
  52. --- ns-2.35-old/common/mobilenode.cc 2006-02-22 21:21:52.000000000 +0800
  53. +++ ns-2.35/common/mobilenode.cc 2014-05-13 20:01:14.620430927 +0800
  54. @@ -338,6 +338,14 @@
  55. "M %.5f %d (%.2f, %.2f, %.2f), (%.2f, %.2f), %.2f",
  56. s.clock(), address_, X_, Y_, Z_, destX_, destY_, speed_);
  57. log_target_->pt_->dump();
  58. +#ifdef MIT_uAMPS
  59. +#if 0
  60. + sprintf(log_target->buffer(),
  61. + "M %.5f %d (%.2f, %.2f, %.2f), (%.2f, %.2f), %.2f",
  62. + s.clock(), index_, X, Y, Z, destX, destY, speed);
  63. + log_target->dump();
  64. +#endif
  65. +#endif
  66. }
  67.  
  68. diff -u -r ns-2.35-old/common/packet.cc ns-2.35/common/packet.cc
  69. --- ns-2.35-old/common/packet.cc 2008-02-18 11:39:02.000000000 +0800
  70. +++ ns-2.35/common/packet.cc 2014-05-13 20:02:50.244395619 +0800
  71. @@ -60,6 +60,9 @@
  72. int Packet::hdrlen_ = 0; // size of a packet's header
  73. Packet* Packet::free_; // free list
  74. int hdr_cmn::offset_; // static offset of common header
  75. +#ifdef MIT_uAMPS
  76. +int hdr_rca::offset_; // static offset of rca header
  77. +#endif
  78. int hdr_flags::offset_; // static offset of flags header
  79.  
  80. @@ -135,6 +138,18 @@
  81. };
  82. } class_cmnhdr;
  83.  
  84. +#ifdef MIT_uAMPS
  85. +
  86. +class RCAHeaderClass : public PacketHeaderClass {
  87. +public:
  88. + RCAHeaderClass() : PacketHeaderClass("PacketHeader/RCA",
  89. + sizeof(hdr_rca)) {
  90. + bind_offset(&hdr_rca::offset_);
  91. + }
  92. +} class_rcahdr;
  93. +
  94. +#endif
  95. +
  96. class FlagsHeaderClass : public PacketHeaderClass {
  97. public:
  98. FlagsHeaderClass() : PacketHeaderClass("PacketHeader/Flags",
  99. diff -u -r ns-2.35-old/common/packet.h ns-2.35/common/packet.h
  100. --- ns-2.35-old/common/packet.h 2010-05-10 06:28:41.000000000 +0800
  101. +++ ns-2.35/common/packet.h 2014-05-13 20:08:09.208346200 +0800
  102. @@ -61,6 +61,10 @@
  103. #define HDR_IP(p) (hdr_ip::access(p))
  104. #define HDR_RTP(p) (hdr_rtp::access(p))
  105. #define HDR_TCP(p) (hdr_tcp::access(p))
  106. +#ifdef MIT_uAMPS
  107. +#define HDR_RCA(p) ((struct hdr_rca*)(p)->access(hdr_rca::offset_))
  108. +#define HDR_MACSensor(p) ((struct hdr_macSensor*)(p)->access(hdr_mac::offset_))
  109. +#endif
  110. #define HDR_SCTP(p) (hdr_sctp::access(p))
  111. #define HDR_SR(p) (hdr_sr::access(p))
  112. #define HDR_TFRC(p) (hdr_tfrc::access(p))
  113. @@ -198,9 +202,12 @@
  114.  
  115. // M-DART packets
  116. static const packet_t PT_MDART = 72;
  117. -
  118. +
  119. +#ifdef MIT_uAMPS
  120. +static const packet_t PT_RCA = 73;
  121. +#endif
  122. // insert new packet types here
  123. -static packet_t PT_NTYPE = 73; // This MUST be the LAST one
  124. +static packet_t PT_NTYPE = 74; // This MUST be the LAST one
  125.  
  126. enum packetClass
  127. {
  128. @@ -416,7 +423,9 @@
  129. name_[PT_DCCP_CLOSE]="DCCP_Close";
  130. name_[PT_DCCP_CLOSEREQ]="DCCP_CloseReq";
  131. name_[PT_DCCP_RESET]="DCCP_Reset";
  132. -
  133. +#ifdef MIT_uAMPS
  134. + name_[PT_RCA] = "rca";
  135. +#endif
  136. name_[PT_NTYPE]= "undefined";
  137. }
  138. static int addPacket(char *name);
  139. @@ -553,7 +562,9 @@
  140. *
  141. */
  142. u_int8_t incoming;
  143. -
  144. +#ifdef MIT_uAMPS
  145. + static void PrintRcHeader(Packet *p, char *layer);
  146. +#endif
  147. //monarch extns end;
  148. };
  149.  
  150. @@ -670,6 +681,48 @@
  151. inline ModulationScheme& mod_scheme() { return (mod_scheme_); }
  152. };
  153.  
  154. +#ifdef MIT_uAMPS
  155. +
  156. +struct hdr_rca {
  157. + int msg_type_;
  158. + char meta_[1000];
  159. + int meta_size_;
  160. + float dist_to_dest_;
  161. + int dist_est_;
  162. + int rca_src_;
  163. + int rca_mac_dst_;
  164. + int rca_link_dst_;
  165. + int code_;
  166. +
  167. + static int offset_; // offset for this header
  168. + inline static int& offset() { return offset_; }
  169. + inline static hdr_rca* access(Packet* p) {
  170. + return (hdr_rca*) p->access(offset_);
  171. + }
  172. +
  173. + /* per-field member functions */
  174. + inline int& msg_type() { return (msg_type_); }
  175. + inline int& meta_size() { return (meta_size_); }
  176. + inline float& get_dist() { return (dist_to_dest_); }
  177. + inline int& dist_est() { return (dist_est_); }
  178. + inline void set_meta(const char* data) {
  179. + meta_size_ = strlen(data);
  180. + if (meta_size_ > maxmetasize()) {
  181. + printf("Error: Meta size %d too large (max = %d).\n", meta_size_, maxmetasize());
  182. + exit(1);
  183. + }
  184. + memcpy(meta_, data, meta_size_+1);
  185. + }
  186. + inline char* const meta() { return (meta_); }
  187. + inline int maxmetasize() { return (sizeof(meta_)); }
  188. + inline int& rca_src() { return (rca_src_); }
  189. + inline int& rca_mac_dst() { return (rca_mac_dst_); }
  190. + inline int& rca_link_dst() { return (rca_link_dst_); }
  191. + inline int& get_code() { return (code_); }
  192. +
  193. +};
  194. +
  195. +#endif
  196.  
  197. class PacketHeaderClass : public TclClass {
  198. protected:
  199. @@ -699,6 +752,10 @@
  200. assert(p->fflag_ == FALSE);
  201. free_ = p->next_;
  202. assert(p->data_ == 0);
  203. +#ifdef MIT_uAMPS
  204. + hdr_rca* rca_hdr = HDR_RCA(p);
  205. + rca_hdr->meta_size_ = 0;
  206. +#endif
  207. p->uid_ = 0;
  208. p->time_ = 0;
  209. } else {
  210. @@ -718,6 +775,17 @@
  211. return (p);
  212. }
  213.  
  214. +#ifdef MIT_uAMPS
  215. +inline void Packet::PrintRcHeader(Packet *p, char *layer)
  216. +{
  217. + hdr_cmn *hdr = HDR_CMN(p);
  218. + hdr_rca *rca_hdr = HDR_RCA(p);
  219. +
  220. + 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());
  221. +
  222. +}
  223. +#endif
  224. +
  225. /*
  226. * Allocate an n byte data buffer to an existing packet
  227. *
  228. @@ -817,7 +885,15 @@
  229. if (data_)
  230. p->data_ = data_->copy();
  231. p->txinfo_.init(&txinfo_);
  232. -
  233. +#ifdef MIT_uAMPS
  234. + hdr_rca* ch = HDR_RCA(this);
  235. + hdr_rca* new_ch = HDR_RCA(p);
  236. +
  237. + if (ch->meta_size_) {
  238. + new_ch->meta_size_ = ch->meta_size_;
  239. + memcpy(new_ch->meta_, ch->meta_, ch->meta_size_+1);
  240. + }
  241. +#endif
  242. return (p);
  243. }
  244.  
  245. 鍙湪 ns-2.35 瀛樺湪锛歝onfig.log
  246. 鍙湪 ns-2.35 瀛樺湪锛歝onfig.status
  247. 鍙湪 ns-2.35 瀛樺湪锛歡en
  248. 鍙湪 ns-2.35/indep-utils/cmu-scen-gen/setdest 瀛樺湪锛歝alcdest
  249. 鍙湪 ns-2.35/indep-utils/cmu-scen-gen/setdest 瀛樺湪锛歁akefile
  250. 鍙湪 ns-2.35/indep-utils/webtrace-conv/dec 瀛樺湪锛歁akefile
  251. 鍙湪 ns-2.35/indep-utils/webtrace-conv/epa 瀛樺湪锛歁akefile
  252. 鍙湪 ns-2.35/indep-utils/webtrace-conv/nlanr 瀛樺湪锛歁akefile
  253. 鍙湪 ns-2.35/indep-utils/webtrace-conv/ucb 瀛樺湪锛歁akefile
  254. 鍙湪 ns-2.35 瀛樺湪锛歭each_test
  255. diff -u -r ns-2.35-old/mac/channel.cc ns-2.35/mac/channel.cc
  256. --- ns-2.35-old/mac/channel.cc 2009-01-03 05:50:24.000000000 +0800
  257. +++ ns-2.35/mac/channel.cc 2014-05-13 20:10:13.372687539 +0800
  258. @@ -121,7 +121,16 @@
  259. ((Phy*) obj)->setchnl(this);
  260. return TCL_OK;
  261. }
  262. -
  263. +#ifdef MIT_uAMPS
  264. + /*
  265. + * When nodes are dead (e.g., they have run out of energy),
  266. + * they must be removed from the network.
  267. + */
  268. + else if(strcmp(argv[1], "removeif") == 0) {
  269. + ((Phy*) obj)->deletechnl(&ifhead_);
  270. + return TCL_OK;
  271. + }
  272. +#endif
  273. // add interface for grid_keeper_
  274. /*else if(strncasecmp(argv[1], "grid_keeper", 5) == 0) {
  275. grid_keeper_ = (GridKeeper*)obj;
  276. diff -u -r ns-2.35-old/mac/ll.h ns-2.35/mac/ll.h
  277. --- ns-2.35-old/mac/ll.h 2010-03-08 13:54:52.000000000 +0800
  278. +++ ns-2.35/mac/ll.h 2014-05-13 20:11:32.300421165 +0800
  279. @@ -52,6 +52,9 @@
  280. };
  281.  
  282. struct hdr_ll {
  283. +#ifdef MIT_uAMPS
  284. +public:
  285. +#endif
  286. LLFrameType lltype_; // link-layer frame type
  287. int seqno_; // sequence number
  288. int ackno_; // acknowledgement number
  289. @@ -105,7 +108,9 @@
  290. int seqno_; // link-layer sequence number
  291. int ackno_; // ACK received so far
  292. int macDA_; // destination MAC address
  293. -
  294. +#ifdef MIT_uAMPS
  295. + double mindelay_;
  296. +#endif
  297. Queue* ifq_; // interface queue
  298. Mac* mac_; // MAC object
  299. LanRouter* lanrouter_; // for lookups of the next hop
  300. 鍙湪 ns-2.35/mac 瀛樺湪锛歮ac-sensor.cc
  301. 鍙湪 ns-2.35/mac 瀛樺湪锛歮ac-sensor.h
  302. 鍙湪 ns-2.35/mac 瀛樺湪锛歮ac-sensor-timers.cc
  303. 鍙湪 ns-2.35/mac 瀛樺湪锛歮ac-sensor-timers.h
  304. diff -u -r ns-2.35-old/mac/phy.cc ns-2.35/mac/phy.cc
  305. --- ns-2.35-old/mac/phy.cc 2005-09-19 07:33:33.000000000 +0800
  306. +++ ns-2.35/mac/phy.cc 2014-05-13 20:17:43.501993087 +0800
  307. @@ -57,6 +57,13 @@
  308. channel_ = 0;
  309. node_ = 0;
  310. head_ = 0;
  311. +#ifdef MIT_uAMPS
  312. + /* Keep track of when transmission ends for carrier sense. */
  313. + /* Since CDMA can be used with CSMA, need to keep track of when
  314. + transmissions from each CDMA code will end. */
  315. + cs_end_ = new double[1000];
  316. + for (int i=0; i<1000; i++) cs_end_[i] = 0;
  317. +#endif
  318. }
  319.  
  320. int
  321. diff -u -r ns-2.35-old/mac/phy.h ns-2.35/mac/phy.h
  322. --- ns-2.35-old/mac/phy.h 2000-08-17 08:03:38.000000000 +0800
  323. +++ ns-2.35/mac/phy.h 2014-05-13 20:45:37.292391713 +0800
  324. @@ -90,6 +90,12 @@
  325. LIST_INSERT_HEAD(head, this, chnl_link_);
  326. //channel_ = chnl;
  327. }
  328. +#ifdef MIT_uAMPS
  329. + inline void deletechnl(struct if_head *head) {
  330. + LIST_REMOVE(this, chnl_link_);
  331. + //delete channel_;
  332. + }
  333. +#endif
  334. // list of all network interfaces on a node
  335. Phy* nextnode(void) const { return node_link_.le_next; }
  336. inline void insertnode(struct if_head* head) {
  337. @@ -136,7 +142,11 @@
  338.  
  339. double bandwidth_; // bit rate
  340. Channel *channel_; // the channel for output
  341. -
  342. +#ifdef MIT_uAMPS
  343. + double *cs_end_; // time when carrier sence will end per code
  344. +public:
  345. + inline double csEnd(int code) { return cs_end_[code]; }
  346. +#endif
  347. };
  348.  
  349. diff -u -r ns-2.35-old/mac/wireless-phy.cc ns-2.35/mac/wireless-phy.cc
  350. --- ns-2.35-old/mac/wireless-phy.cc 2007-09-04 12:32:18.000000000 +0800
  351. +++ ns-2.35/mac/wireless-phy.cc 2014-05-13 20:48:04.392443613 +0800
  352. @@ -75,6 +75,25 @@
  353.  
  354. WirelessPhy::WirelessPhy() : Phy(), sleep_timer_(this), status_(IDLE)
  355. {
  356. +#ifdef MIT_uAMPS
  357. + alive_ = 1; // 0 = dead, 1 = alive
  358. + bandwidth_ = 1000000; // 100 Mbps
  359. + Efriss_amp_ = 100 * 1e-12; // Friss amp energy (J/bit/m^2)
  360. + Etwo_ray_amp_ = 0.013 * 1e-12; // Two-ray amp energy (J/bit/m^4)
  361. + EXcvr_ = 50 * 1e-9; // Xcvr energy (J/bit)
  362. + // Use this base threshold to get a "hearing radius" of ~ 1 m
  363. + Pfriss_amp_ = Efriss_amp_ * bandwidth_; // Friss power (W/m^2)
  364. + Ptwo_ray_amp_ = Etwo_ray_amp_ * bandwidth_; // Two-ray power (W/m^4)
  365. + PXcvr_ = EXcvr_ * bandwidth_; // Xcvr power (W)
  366. + sleep_ = 0; // 0 = awake, 1 = asleep
  367. + ss_ = 1; // amount of spreading
  368. + time_finish_rcv_ = 0;
  369. + dist_ = 0; // approx. distance to transmitter
  370. + energy_ = 0;
  371. +#else
  372. + bandwidth_ = 2*1e6; // 2 Mb
  373. + Pt_ = pow(10, 2.45) * 1e-3; // 24.5 dbm, ~ 281.8mw
  374. +#endif
  375. /*
  376. * It sounds like 10db should be the capture threshold.
  377. *
  378. @@ -97,7 +116,16 @@
  379. bind("Pt_", &Pt_);
  380. bind("freq_", &freq_);
  381. bind("L_", &L_);
  382. -
  383. +#ifdef MIT_uAMPS
  384. + bind("alive_",&alive_);
  385. + bind("bandwidth_",&bandwidth_);
  386. + bind("Efriss_amp_", &Efriss_amp_);
  387. + bind("Etwo_ray_amp_", &Etwo_ray_amp_);
  388. + bind("EXcvr_", &EXcvr_);
  389. + bind("sleep_",&sleep_);
  390. + bind("ss_",&ss_);
  391. + bind("dist_",&dist_);
  392. +#endif
  393. lambda_ = SPEED_OF_LIGHT / freq_;
  394.  
  395. node_ = 0;
  396. @@ -196,6 +224,12 @@
  397. node_ = (Node *)obj;
  398. return TCL_OK;
  399. }
  400. +#ifdef MIT_uAMPS
  401. + else if (strcasecmp(argv[1], "attach-energy") == 0) {
  402. + energy_ = (EnergyResource*) obj;
  403. + return TCL_OK;
  404. + }
  405. +#endif
  406. }
  407. return Phy::command(argc,argv);
  408. }
  409. @@ -207,7 +241,47 @@
  410. * Sanity Check
  411. */
  412. assert(initialized());
  413. -
  414. +#ifdef MIT_uAMPS
  415. + /*
  416. + * The power for transmission depends on the distance between
  417. + * the transmitter and the receiver. If this distance is
  418. + * less than the crossover distance:
  419. + * (c_d)^2 = 16 * PI^2 * L * hr^2 * ht^2
  420. + * ---------------------------------
  421. + * lambda^2
  422. + * the power falls off using the Friss equation. Otherwise, the
  423. + * power falls off using the two-ray ground reflection model.
  424. + * Therefore, the power for transmission of a bit is:
  425. + * Pt = Pfriss_amp_*d^2 if d < c_d
  426. + * Pt = Ptwo_ray_amp_*d^4 if d >= c_d.
  427. + * The total power dissipated per bit is PXcvr_ + Pt.
  428. + */
  429. + hdr_cmn *ch = HDR_CMN(p);
  430. + hdr_rca *rca_hdr = HDR_RCA(p);
  431. + double d = rca_hdr->get_dist();
  432. + double hr, ht; // height of recv and xmit antennas
  433. + double tX, tY, tZ; // transmitter location
  434. + ((MobileNode *)node_)->getLoc(&tX, &tY, &tZ);
  435. + ht = tZ + ant_->getZ();
  436. + hr = ht; // assume receiving node and antenna at same height
  437. + double crossover_dist = sqrt((16 * PI * PI * L_ * ht * ht * hr * hr)
  438. + / (lambda_ * lambda_));
  439. + if (d < crossover_dist)
  440. + if (d > 1)
  441. + Pt_ = Efriss_amp_ * bandwidth_ * d * d;
  442. + else
  443. + // Pfriss_amp_ is the minimum transmit amplifier power.
  444. + Pt_ = Efriss_amp_ * bandwidth_;
  445. + else
  446. + Pt_ = Etwo_ray_amp_ * bandwidth_ * d * d * d * d;
  447. + PXcvr_ = EXcvr_ * bandwidth_;
  448. +
  449. + if (energy_)
  450. + {
  451. + if (energy_->remove(pktEnergy(Pt_, PXcvr_, ch->size())) != 0)
  452. + alive_ = 0;
  453. + }
  454. +#endif
  455. if (em()) {
  456. //node is off here...
  457. if (Is_node_on() != true ) {
  458. @@ -317,7 +391,24 @@
  459. PacketStamp s;
  460. double Pr;
  461. int pkt_recvd = 0;
  462. -
  463. +#ifdef MIT_uAMPS
  464. + hdr_cmn *ch = HDR_CMN(p);
  465. + hdr_rca *rca_hdr = HDR_RCA(p);
  466. + /*
  467. + * Record when this packet ends and its code.
  468. + */
  469. + int code = rca_hdr->get_code();
  470. + cs_end_[code] = Scheduler::instance().clock() + txtime(p);
  471. + /*
  472. + * If the node is asleep, drop the packet.
  473. + */
  474. + if (sleep_) {
  475. + //printf("Sleeping node... carrier sense ends at %f\n", cs_end_);
  476. + //fflush(stdout);
  477. + pkt_recvd = 0;
  478. + goto DONE;
  479. + }
  480. +#endif
  481. Pr = p->txinfo_.getTxPr();
  482.  
  483. // if the node is in sleeping mode, drop the packet simply
  484. @@ -367,7 +458,44 @@
  485. hdr_cmn *hdr = HDR_CMN(p);
  486. hdr->error() = modulation_->BitError(Pr);
  487. }
  488. -
  489. +#ifdef MIT_uAMPS
  490. + /*
  491. + * Only remove energy from nodes that are awake and not currently
  492. + * transmitting a packet.
  493. + */
  494. + if (Scheduler::instance().clock() >= time_finish_rcv_) {
  495. + PXcvr_ = EXcvr_ * bandwidth_;
  496. + if (energy_)
  497. + {
  498. + if (energy_->remove(pktEnergy((double)0, PXcvr_,ch->size())) != 0)
  499. + alive_ = 0;
  500. + }
  501. + time_finish_rcv_ = Scheduler::instance().clock() + txtime(p);
  502. + }
  503. + /*
  504. + * Determine approximate distance of node transmitting node
  505. + * from received power.
  506. + */
  507. + double hr, ht; // height of recv and xmit antennas
  508. + double rX, rY, rZ; // receiver location
  509. + double d1, d2;
  510. + double crossover_dist, Pt, M;
  511. + ((MobileNode *)node_)->getLoc(&rX, &rY, &rZ);
  512. + hr = rZ + ant_->getZ();
  513. + ht = hr; // assume transmitting node antenna at same height
  514. +
  515. + crossover_dist = sqrt((16 * PI * PI * L_ * ht * ht * hr * hr)
  516. + / (lambda_ * lambda_));
  517. + Pt = p->txinfo_.getTxPr();
  518. + M = lambda_ / (4 * PI);
  519. + d1 = sqrt( (Pt * M * M) / (L_ * Pr) );
  520. + d2 = sqrt(sqrt( (Pt * hr * hr * ht * ht) / Pr) );
  521. + if (d1 < crossover_dist)
  522. + dist_ = d1;
  523. + else
  524. + dist_ = d2;
  525. + rca_hdr->dist_est() = (int) ceil(dist_);
  526. +#endif
  527. /*
  528. * The MAC layer must be notified of the packet reception
  529. * now - ie; when the first bit has been detected - so that
  530. @@ -600,3 +728,23 @@
  531.  
  532. sleep_timer_.resched(10.0);
  533. }
  534. +
  535. +#ifdef MIT_uAMPS
  536. +double
  537. +WirelessPhy::pktEnergy(double pt, double pxcvr, int nbytes)
  538. +{
  539. +
  540. + /*
  541. + * Energy (in Joules) is power (in Watts=Joules/sec) divided by
  542. + * bandwidth (in bits/sec) multiplied by the number of bytes, times 8 bits.
  543. + */
  544. + // If data has been spread, power per DATA bit should be the same
  545. + // as if there was no spreading ==> divide transmit power
  546. + // by spreading factor.
  547. + double bits = (double) nbytes * 8;
  548. + pt /= ss_;
  549. + double j = bits * (pt + pxcvr) / bandwidth_;
  550. + return(j);
  551. +}
  552. +
  553. +#endif
  554. diff -u -r ns-2.35-old/mac/wireless-phy.h ns-2.35/mac/wireless-phy.h
  555. --- ns-2.35-old/mac/wireless-phy.h 2007-01-30 13:00:50.000000000 +0800
  556. +++ ns-2.35/mac/wireless-phy.h 2014-05-13 21:07:12.060482931 +0800
  557. @@ -48,7 +48,9 @@
  558. #include "phy.h"
  559. #include "mobilenode.h"
  560. #include "timer-handler.h"
  561. -
  562. +#ifdef MIT_uAMPS
  563. +#include <mit/rca/energy.h>
  564. +#endif
  565. class Phy;
  566. class Propagation;
  567. class WirelessPhy;
  568. @@ -121,11 +123,30 @@
  569. double CPThresh_; // capture threshold (db)
  570.  
  571. Antenna *ant_;
  572. +#ifdef MIT_uAMPS
  573. + EnergyResource *energy_; // Energy resource
  574. + int alive_; // 0 = dead, 1 = alive
  575. +//endif
  576. +//ifdef MIT_uAMPS_temp
  577. + double Efriss_amp_; // Xmit amp energy (J/bit/m^2)
  578. + double Etwo_ray_amp_; // Xmit amp energy (J/bit/m^4)
  579. + double EXcvr_; // Xcvr energy (J/bit)
  580. + double Pfriss_amp_; // Friss base transmission power (W/m^2)
  581. + double Ptwo_ray_amp_; // Two-ray base transmission power (W/m^4)
  582. + double PXcvr_; // Xcvr Power (W)
  583. + int sleep_; // 0 = awake, 1 = asleep
  584. + int ss_; // amount of spreading
  585. + double time_finish_rcv_;
  586. + double dist_; // approx. distance to transmitter
  587. +private:
  588. + double pktEnergy(double pt, double pxcvr, int nbytes);
  589. +#endif
  590. +protected:
  591. Propagation *propagation_; // Propagation Model
  592. Modulation *modulation_; // Modulation Schem
  593.  
  594. // Why phy has a node_ and this guy has it all over again??
  595.  
  596. -// MobileNode* node_; // Mobile Node to which interface is attached .
  597. + //MobileNode* node_; // Mobile Node to which interface is attached .
  598.  
  599. enum ChannelStatus { SLEEP, IDLE, RECV, SEND };
  600. bool node_on_; // on-off status of this node
  601. 鍙湪 ns-2.35 瀛樺湪锛歁akefile
  602. diff -u -r ns-2.35-old/Makefile.in ns-2.35/Makefile.in
  603. --- ns-2.35-old/Makefile.in 2011-10-24 00:29:54.000000000 +0800
  604. +++ ns-2.35/Makefile.in 2014-05-13 20:36:28.672410926 +0800
  605. @@ -59,7 +59,7 @@
  606. LDFLAGS = @LDFLAGS@
  607. LDOUT = -o $(BLANK)
  608.  
  609. -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
  610. +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
  611.  
  612. INCLUDES = \
  613. -I. @V_INCLUDE_X11@ \
  614. @@ -72,7 +72,7 @@
  615. -I./diffusion3/lib/nr -I./diffusion3/ns \
  616. -I./diffusion3/filter_core -I./asim/ -I./qs \
  617. -I./diffserv -I./satellite \
  618. - -I./wpan
  619. + -I./wpan -I./mit/rca -I./mit/uAMPS
  620.  
  621. LIB = \
  622. @@ -333,6 +333,9 @@
  623. wpan/p802_15_4sscs.o wpan/p802_15_4timer.o \
  624. wpan/p802_15_4trace.o wpan/p802_15_4transac.o \
  625. apps/pbc.o \
  626. + mit/rca/energy.o mit/rca/rcagent.o \
  627. + mit/rca/rca-ll.o mit/rca/resource.o \
  628. + mac/mac-sensor-timers.o mac/mac-sensor.o mit/uAMPS/bsagent.o \
  629. @V_STLOBJ@
  630.  
  631. 鍙湪 ns-2.35 瀛樺湪锛歮it
  632. 鍙湪 ns-2.35/tcl/ex 瀛樺湪锛?94demo.nam
  633. 鍙湪 ns-2.35/tcl/ex 瀛樺湪锛?94demo.tr
  634. 鍙湪 ns-2.35/tcl/ex 瀛樺湪锛歭each-wireless.tcl
  635. 鍙湪 ns-2.35/tcl/lib 瀛樺湪锛歯s-autoconf.tcl
  636. diff -u -r ns-2.35-old/tcl/lib/ns-default.tcl ns-2.35/tcl/lib/ns-default.tcl
  637. --- ns-2.35-old/tcl/lib/ns-default.tcl 2010-07-04 06:45:45.000000000 +0800
  638. +++ ns-2.35/tcl/lib/ns-default.tcl 2014-05-13 21:13:13.196383783 +0800
  639. @@ -1590,3 +1590,11 @@
  640.  
  641. Agent/MDART set macFailed_ true
  642. Agent/MDART set etxMetric_ true
  643. +
  644. +#Phy/WirelessPhy set alive_ 1
  645. +#Phy/WirelessPhy set Efriss_amp_ 100 * 1e-12
  646. +#Phy/WirelessPhy set Etwo_ray_amp_
  647. +#Phy/WirelessPhy set EXcvr_
  648. +#Phy/WirelessPhy set sleep_
  649. +#Phy/WirelessPhy set ss_
  650. +#Phy/WirelessPhy set dist_
  651. 鍙湪 ns-2.35/tcl/mobility 瀛樺湪锛歭each-c.tcl
  652. 鍙湪 ns-2.35/tcl/mobility 瀛樺湪锛歭each.tcl
  653. 鍙湪 ns-2.35/tcl/mobility 瀛樺湪锛歮te.tcl
  654. 鍙湪 ns-2.35/tcl/mobility 瀛樺湪锛歴tat-clus.tcl
  655. 鍙湪 ns-2.35 瀛樺湪锛歵est
  656. diff -u -r ns-2.35-old/trace/cmu-trace.cc ns-2.35/trace/cmu-trace.cc
  657. --- ns-2.35-old/trace/cmu-trace.cc 2011-10-03 06:32:35.000000000 +0800
  658. +++ ns-2.35/trace/cmu-trace.cc 2014-05-13 20:31:31.096823052 +0800
  659. @@ -64,6 +64,9 @@
  660. //</zheng: add for 802.15.4>
  661.  
  662. #include "diffusion/diff_header.h" // DIFFUSION -- Chalermek
  663. +#ifdef MIT_uAMPS
  664. +#include <mit/rca/rcagent.h>
  665. +#endif
  666.  
  667. PacketTracer::PacketTracer() : next_(0)
  668. @@ -1415,6 +1418,11 @@
  669. case PT_ARP:
  670. format_arp(p, offset);
  671. break;
  672. +#ifdef MIT_uAMPS
  673. + case PT_RCA:
  674. + format_rca(p,offset);
  675. + break;
  676. +#endif
  677. default:
  678. format_ip(p, offset);
  679. offset = strlen(pt_->buffer());
  680. @@ -1451,6 +1459,10 @@
  681. case PT_CBR:
  682. format_rtp(p, offset);
  683. break;
  684. +#ifdef MIT_uAMPS
  685. + case PT_RCA:
  686. + break;
  687. +#endif
  688. case PT_DIFF:
  689. break;
  690. case PT_GAF:
  691. @@ -1603,3 +1615,40 @@
  692. duration_scaling_factor_ = atof(tcl.result());
  693. }
  694. //</zheng>
  695. +
  696. +#ifdef MIT_uAMPS
  697. +void
  698. +CMUTrace::format_rca(Packet *p, int offset)
  699. +{
  700. + struct hdr_rca *rca_hdr = HDR_RCA(p);
  701. + char op = (char) type_;
  702. +
  703. + switch (rca_hdr->msg_type())
  704. + {
  705. + case ADV:
  706. + op = ADV_CHAR;
  707. + break;
  708. +
  709. + case REQ:
  710. + op = REQ_CHAR;
  711. + break;
  712. +
  713. + case DATA:
  714. + op = DATA_CHAR;
  715. + break;
  716. +
  717. + default:
  718. + //printf("format_rca: Warning, unknown meta-data type %d\n",rca_hdr->msg_type());
  719. + op = (char) type_;
  720. + break;
  721. + }
  722. +
  723. + sprintf(pt_->buffer() + offset, "------- [%c %d %d %d] ",
  724. + op,
  725. + rca_hdr->rca_src(),
  726. + rca_hdr->rca_link_dst(),
  727. + rca_hdr->rca_mac_dst()
  728. + );
  729. + return;
  730. +}
  731. +#endif
  732. diff -u -r ns-2.35-old/trace/cmu-trace.h ns-2.35/trace/cmu-trace.h
  733. --- ns-2.35-old/trace/cmu-trace.h 2010-05-10 06:28:41.000000000 +0800
  734. +++ ns-2.35/trace/cmu-trace.h 2014-05-13 20:32:22.196397952 +0800
  735. @@ -56,7 +56,11 @@
  736.  
  737. // change wrt Mike's code
  738. #define EOT 'x'
  739. -
  740. +#ifdef MIT_uAMPS
  741. +#define ADV_CHAR 'A'
  742. +#define REQ_CHAR 'R'
  743. +#define DATA_CHAR 'D'
  744. +#endif
  745.  
  746. #define TR_ROUTER 0x01
  747. @@ -161,7 +165,9 @@
  748. void format_aodv(Packet *p, int offset);
  749. void format_aomdv(Packet *p, int offset);
  750. void format_mdart(Packet *p, int offset);
  751. -
  752. +#ifdef MIT_uAMPS
  753. + void format_rca(Packet *p, int offset);
  754. +#endif
  755. // This holds all the tracers added at run-time
  756. static PacketTracer *pktTrc_;

2.脚本文件

  1. #!/bin/sh
  2. echo "Before installing NS2, you should ensure that the 'ns-allinone-2.35' is in '/home/<your name>/Leach'"
  3. echo "If the files is right, press any key. Otherwise, press 'Ctrl+D'"
  4. read ch
  5. sudo apt-get update
  6. sudo apt-get install libx11-dev libxmu-dev libxmu-headers libxt-dev libtool g++ patch tcl tk tcl-dev tk-dev gnuplot
  7. tar -zxvf ns-allinone-2.35.tar.gz
  8. cp -ir ns-2.35 ns-allinone-2.35/
  9. cp leach.diff ns-allinone-2.35
  10. cd ns-allinone-2.35
  11. patch -p0 < leach.diff
  12. ./install
  13. cd ..
  14. echo "The NS2 has been installed. If you want to configure '.bashrc' file automatically, press any key. Otherwise, press 'Ctrl+D'"
  15. read ch
  16. pathto=$(pwd)
  17. 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
  18. echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$pathto/ns-allinone-2.35/otcl-1.14:$pathto/ns-allinone-2.35/lib" >> ~/.bashrc
  19. echo "export LD_LIBRARY=\$LD_LIBRARY:$pathto/ns-allinone-2.35/tcl8.5.10/library" >> ~/.bashrc
  20. echo "export RCA_LIBRARY=$pathto/ns-allinone-2.35/ns-2.35/mit/rca" >> ~/.bashrc
  21. echo "export uAMPS_LIBRARY=$pathto/ns-allinone-2.35/ns-2.35/mit/uAMPS" >> ~/.bashrc
  22. echo "echo \"==================Welcome to use NS2 for Leach!=====================\"" >> ~/.bashrc
  23. echo "echo \"If you have any questions, please contact norbert_jxl AT 163.com\"" >> ~/.bashrc
  24. echo "The '.bashrc' file is configured!"

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

Ubuntu10.04中间Leach协议一键安装的更多相关文章

  1. 【2022.04.19】Docker-compose一键安装mirai,搭建QQ机器人最快方法

    先用官方的脚本安装下docker curl -sSL https://get.docker.com/ | sh 安装docker-compose curl -L "https://githu ...

  2. [Ubuntu] ubuntu10.04系统维护之Wine的安装

    在介绍安装wine之前,我想是有必要先介绍一下Wine的.当然,如果是Liunx的高手,我想是没必要看的,但是对于笔者这样的菜鸟级人物还是需要看一下的. Wine是一款Liunx下的模拟器软件,但是W ...

  3. 【转】Ubuntu10.04上编译Android源码(Build Android source in Ubuntu10.04 Platform)

    原文网址:http://blog.csdn.net/chenyafei617/article/details/6570928 一.Introduction 今天我们就来谈谈如何在Ubuntu平台上面编 ...

  4. ubuntu10.04 建V

    ubuntu10.04架设vpn服 vpn 安装:  pptpd:apt-get install pptpd 1. 配置网络IP地址,编辑 vim /etc/pptpd.conf ,去掉下面两行前面# ...

  5. ubuntu10.04 安装配置tftp服务

    tftpd-hpa 是一个功能增强的TFTP服务器.它提供了很多TFTP的增强功能,它已经被移植到大多数的现代UNIX系统. 1.安装 sudo apt-get install tftpd-hpa t ...

  6. ubuntu10.04编译安装LAMP

    ubuntu10.04编译安装LAMP以及简单wordpress的使用 : http://linuxme.blog.51cto.com/1850814/971631 一.源码安装LAMP 网上有一堆关 ...

  7. u盘安装ubuntu10.04 server.txt

    10.04 先将 ubuntu server 的 iso 放到优盘上,然后在提示无法找到光驱时,按 alt+f2 打开一个新的 console 窗口,将 iso mount 上,具体操作如下: ls ...

  8. u盘安装ubuntu10.04 、11.04 server

    10.04 先将 ubuntu server 的 iso 放到优盘上,然后在提示无法找到光驱时,按 alt+f2 打开一个新的 console 窗口,将 iso mount 上,具体操作如下: ls ...

  9. ubuntu10.04 svn安装方法

    ubuntu10.04 svn安装方法:sudo apt-get install subversion sudo apt-get install libneon27-dev orsudo apt-ge ...

随机推荐

  1. AM335x(TQ335x)学习笔记——u-boot-2014.10移植

    根据最近移植u-boot-2014.10至TQ335x,基于这样的假设am335x evm移植.不是很多地方需要改变. 因为TI的am335x evm开发了使用eeprom船上保存配置信息.它使用不同 ...

  2. Java Swing创建自定义闪屏:在闪屏上添加Swing进度条控件(转)

    本文将讲解如何做一个类似MyEclipse启动画面的闪屏,为Java Swing应用程序增添魅力. 首先看一下效果图吧, 原理很简单,就是创建一个Dialog,Dialog有一个进度条和一个Label ...

  3. python使用smtplib库和smtp.qq.com邮件服务器发送邮件(转)

    使用qq的邮件服务器需要注意的两个地方主要是: 1.协议问题 使用465端口 SSL 协议 2.口令问题 出现SMTPAuthenticationError 主要的原因就是口令和帐号信息不对,这里我们 ...

  4. hdu 5045 费用流

    滚动建图,最大费用流(每次仅仅有就10个点的二分图).复杂度,m/n*(n^2)(n<=10),今年网络赛唯一网络流题,被队友状压DP秒了....难道网络流要逐渐退出历史舞台???.... #i ...

  5. Codeforces 110B-Lucky String(技能)

    B. Lucky String time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  6. 多于ListView同步滚动

    简介: 发展过程中可能遇到的2一个或多个其他listview为了用相应的关系保持滚动的情况下一起,本文演示了这种效应为大家. 功效: 实现原理: 在滚动当中不论什么一个ListView的时候,同一时候 ...

  7. VC和gcc在保证功能static对线程安全的差异变量

    VC和gcc不同,不能保证静态变量的线程安全性.这就给我们的程序带来了非常大的安全隐患和诸多不便.这一点应该引起我们的重视!尤其是在构造函数耗时比較长的时候.非常可能给程序带来意想不到的结果.本文从測 ...

  8. Qt原始资源形象问题后删除

        这些天Qt请项目超市收银系统,作为练一练手,无论如何,亦休闲亦无关,做几乎同样的.旨在取代以前的资源图片, 是什么改变了,码里面的路径都改了.还是编译只是去,总是提示这样一个错误. <s ...

  9. HDU4893:Wow! Such Sequence!(段树lazy)

    Problem Description Recently, Doge got a funny birthday present from his new friend, Protein Tiger f ...

  10. NSOJ 畅通工程(并查集)

    某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可). ...