p802_15_4trace.cc
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:7k
源码类别:

通讯编程

开发平台:

Visual C++

  1. /********************************************/
  2. /*     NS2 Simulator for IEEE 802.15.4      */
  3. /*           (per P802.15.4/D18)            */
  4. /*------------------------------------------*/
  5. /* by:        Jianliang Zheng               */
  6. /*        (zheng@ee.ccny.cuny.edu)          */
  7. /*              Myung J. Lee                */
  8. /*          (lee@ccny.cuny.edu)             */
  9. /*        ~~~~~~~~~~~~~~~~~~~~~~~~~         */
  10. /*           SAIT-CUNY Joint Lab            */
  11. /********************************************/
  12. // File:  p802_15_4trace.cc
  13. // Mode:  C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t
  14. // $Header: /cvsroot/nsnam/ns-2/wpan/p802_15_4trace.cc,v 1.2 2005/01/25 23:29:16 haldar Exp $
  15. /*
  16.  * Copyright (c) 2003-2004 Samsung Advanced Institute of Technology and
  17.  * The City University of New York. All rights reserved.
  18.  *
  19.  * Redistribution and use in source and binary forms, with or without
  20.  * modification, are permitted provided that the following conditions
  21.  * are met:
  22.  * 1. Redistributions of source code must retain the above copyright
  23.  *    notice, this list of conditions and the following disclaimer.
  24.  * 2. Redistributions in binary form must reproduce the above copyright
  25.  *    notice, this list of conditions and the following disclaimer in the
  26.  *    documentation and/or other materials provided with the distribution.
  27.  * 3. All advertising materials mentioning features or use of this software
  28.  *    must display the following acknowledgement:
  29.  * This product includes software developed by the Joint Lab of Samsung 
  30.  *      Advanced Institute of Technology and The City University of New York.
  31.  * 4. Neither the name of Samsung Advanced Institute of Technology nor of 
  32.  *    The City University of New York may be used to endorse or promote 
  33.  *    products derived from this software without specific prior written 
  34.  *    permission.
  35.  *
  36.  * THIS SOFTWARE IS PROVIDED BY THE JOINT LAB OF SAMSUNG ADVANCED INSTITUTE
  37.  * OF TECHNOLOGY AND THE CITY UNIVERSITY OF NEW YORK ``AS IS'' AND ANY EXPRESS 
  38.  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
  39.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 
  40.  * NO EVENT SHALL SAMSUNG ADVANCED INSTITUTE OR THE CITY UNIVERSITY OF NEW YORK 
  41.  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  42.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
  43.  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  44.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
  45.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
  46.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47.  */
  48. #include <packet.h>
  49. #include <mac.h>
  50. #include <mac-802_11.h>
  51. #include "p802_15_4trace.h"
  52. //ns-2.27 changed 'dh_sa' to 'dh_ta' and 'dh_da' to 'dh_ra' in mac-802_11.h/cc
  53. #define dh_sa dh_ta
  54. #define dh_da dh_ra
  55. #define use_hdr_802_11_for_trace
  56. #ifndef use_hdr_802_11_for_trace
  57. int p802_15_4macSA(Packet *p)
  58. {
  59. struct hdr_mac *mh = HDR_MAC(p);
  60. return mh->macSA();
  61. }
  62. int p802_15_4macDA(Packet *p)
  63. {
  64. struct hdr_mac *mh = HDR_MAC(p);
  65. return mh->macDA();
  66. }
  67. u_int16_t p802_15_4hdr_type(Packet *p)
  68. {
  69. struct hdr_mac *mh = HDR_MAC(p);
  70. return mh->hdr_type();
  71. }
  72. int p802_15_4hdr_dst(char* hdr,int dst)
  73. {
  74. struct hdr_mac *mh = (struct hdr_mac*) hdr;
  75. if(dst > -2)
  76. mh->macDA_ = dst;
  77. return mh->macDA();
  78. }
  79. int p802_15_4hdr_src(char* hdr,int src)
  80. {
  81. struct hdr_mac *mh = (struct hdr_mac*) hdr;
  82. if(src > -2)
  83. mh->macSA_ = src;
  84. return mh->macSA();
  85. }
  86. int p802_15_4hdr_type(char* hdr, u_int16_t type)
  87. {
  88. struct hdr_mac *mh = (struct hdr_mac*) hdr;
  89. if (type)
  90. mh->hdr_type_ = type;
  91. return mh->hdr_type();
  92. }
  93. void p802_15_4hdrDATA(Packet *p)
  94. {
  95. ; //nothing to do
  96. }
  97. void p802_15_4hdrACK(Packet *p)
  98. {
  99. ; //nothing to do
  100. }
  101. void p802_15_4hdrBeacon(Packet *p)
  102. {
  103. ; //nothing to do
  104. }
  105. void p802_15_4hdrCommand(Packet *p, u_int16_t type)
  106. {
  107. ; //nothing to do
  108. }
  109. #else
  110. int p802_15_4macSA(Packet *p)
  111. {
  112. struct hdr_mac802_11 *mh = HDR_MAC802_11(p);
  113. return ETHER_ADDR(mh->dh_sa);
  114. }
  115. int p802_15_4macDA(Packet *p)
  116. {
  117. struct hdr_mac802_11 *mh = HDR_MAC802_11(p);
  118. return ETHER_ADDR(mh->dh_da);
  119. }
  120. u_int16_t p802_15_4hdr_type(Packet *p)
  121. {
  122. struct hdr_mac802_11 *mh = HDR_MAC802_11(p);
  123. return GET2BYTE(mh->dh_body);
  124. }
  125. int p802_15_4hdr_dst(char* hdr,int dst)
  126. {
  127. struct hdr_mac802_11 *mh = (struct hdr_mac802_11*) hdr;
  128. if(dst > -2)
  129. STORE4BYTE(&dst, (mh->dh_da));
  130. return ETHER_ADDR(mh->dh_da);
  131. }
  132. int p802_15_4hdr_src(char* hdr,int src)
  133. {
  134. struct hdr_mac802_11 *mh = (struct hdr_mac802_11*) hdr;
  135. if(src > -2)
  136. STORE4BYTE(&src, (mh->dh_sa));
  137. return ETHER_ADDR(mh->dh_sa);
  138. }
  139. int p802_15_4hdr_type(char* hdr, u_int16_t type)
  140. {
  141. struct hdr_mac802_11 *mh = (struct hdr_mac802_11*) hdr;
  142. if(type)
  143. STORE2BYTE(&type,(mh->dh_body));
  144. return GET2BYTE(mh->dh_body);
  145. }
  146. void p802_15_4hdrDATA(Packet *p)
  147. {
  148. struct hdr_mac802_11* mh = HDR_MAC802_11(p);
  149. //ch->size() += ETHER_HDR_LEN11;
  150. mh->dh_fc.fc_protocol_version = MAC_ProtocolVersion;
  151. mh->dh_fc.fc_type = MAC_Type_Data;
  152. mh->dh_fc.fc_subtype = MAC_Subtype_Data;
  153. }
  154. void p802_15_4hdrACK(Packet *p)
  155. {
  156. struct ack_frame *af = (struct ack_frame*)p->access(hdr_mac::offset_);
  157. af->af_fc.fc_protocol_version = MAC_ProtocolVersion;
  158.   af->af_fc.fc_type = MAC_Type_Control;
  159.   af->af_fc.fc_subtype = MAC_Subtype_ACK;
  160. }
  161. void p802_15_4hdrBeacon(Packet *p)
  162. {
  163. struct hdr_mac802_11* mh = HDR_MAC802_11(p);
  164. mh->dh_fc.fc_protocol_version = MAC_ProtocolVersion;
  165. mh->dh_fc.fc_type = MAC_Type_Control; //doesn't really matter
  166. mh->dh_fc.fc_subtype = MAC_Subtype_Beacon;
  167. }
  168. void p802_15_4hdrCommand(Packet *p, u_int16_t type)
  169. {
  170. struct hdr_mac802_11* mh = HDR_MAC802_11(p);
  171. mh->dh_fc.fc_protocol_version = MAC_ProtocolVersion;
  172. mh->dh_fc.fc_type = MAC_Type_Control; //doesn't really matter
  173. mh->dh_fc.fc_subtype = type;
  174. }
  175. #endif
  176. const char *wpan_pName(Packet *p)
  177. {
  178. struct hdr_cmn *ch = HDR_CMN(p);
  179. struct hdr_mac802_11 *mh = HDR_MAC802_11(p);
  180. return
  181. ((ch->ptype() == PT_MAC) ? (
  182.   (mh->dh_fc.fc_subtype == MAC_Subtype_Beacon) ? "M_BEACON"  : //Beacon
  183.   (mh->dh_fc.fc_subtype == MAC_Subtype_Command_AssoReq) ? "M_CM1_AssoReq"  : //CMD: Association request
  184.   (mh->dh_fc.fc_subtype == MAC_Subtype_Command_AssoRsp) ? "M_CM2_AssoRsp"  : //CMD: Association response
  185.   (mh->dh_fc.fc_subtype == MAC_Subtype_Command_DAssNtf) ? "M_CM3_DisaNtf"  : //CMD: Disassociation notification
  186.   (mh->dh_fc.fc_subtype == MAC_Subtype_Command_DataReq) ? "M_CM4_DataReq"  : //CMD: Data request
  187.   (mh->dh_fc.fc_subtype == MAC_Subtype_Command_PIDCNtf) ? "M_CM5_PidCNtf"  : //CMD: PAN ID conflict notification
  188.   (mh->dh_fc.fc_subtype == MAC_Subtype_Command_OrphNtf) ? "M_CM6_OrphNtf"  : //CMD: Orphan notification
  189.   (mh->dh_fc.fc_subtype == MAC_Subtype_Command_BconReq) ? "M_CM7_Bcn-Req"  : //CMD: Beacon request
  190.   (mh->dh_fc.fc_subtype == MAC_Subtype_Command_CoorRea) ? "M_CM8_CoorRal"  : //CMD: Coordinator realignment
  191.   (mh->dh_fc.fc_subtype == MAC_Subtype_Command_GTSReq) ?  "M_CM9_GTS-Req"  : //CMD: GTS request
  192.   (mh->dh_fc.fc_subtype == MAC_Subtype_ACK) ? "M_ACK"  : //Acknowledgement
  193.   "M_UNKN"
  194.   ) : packet_info.name(ch->ptype()));
  195. }
  196. // End of file: p802_15_4trace.cc