p802_15_4trace.cc

Go to the documentation of this file.
00001 /********************************************/
00002 /*     NS2 Simulator for IEEE 802.15.4      */
00003 /*           (per P802.15.4/D18)            */
00004 /*------------------------------------------*/
00005 /* by:        Jianliang Zheng               */
00006 /*        (zheng@ee.ccny.cuny.edu)          */
00007 /*              Myung J. Lee                */
00008 /*          (lee@ccny.cuny.edu)             */
00009 /*        ~~~~~~~~~~~~~~~~~~~~~~~~~         */
00010 /*           SAIT-CUNY Joint Lab            */
00011 /********************************************/
00012 
00013 // File:  p802_15_4trace.cc
00014 // Mode:  C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t
00015 
00016 // $Header: /nfs/jade/vint/CVSROOT/ns-2/wpan/p802_15_4trace.cc,v 1.2 2005/01/25 23:29:16 haldar Exp $
00017 
00018 /*
00019  * Copyright (c) 2003-2004 Samsung Advanced Institute of Technology and
00020  * The City University of New York. All rights reserved.
00021  *
00022  * Redistribution and use in source and binary forms, with or without
00023  * modification, are permitted provided that the following conditions
00024  * are met:
00025  * 1. Redistributions of source code must retain the above copyright
00026  *    notice, this list of conditions and the following disclaimer.
00027  * 2. Redistributions in binary form must reproduce the above copyright
00028  *    notice, this list of conditions and the following disclaimer in the
00029  *    documentation and/or other materials provided with the distribution.
00030  * 3. All advertising materials mentioning features or use of this software
00031  *    must display the following acknowledgement:
00032  *  This product includes software developed by the Joint Lab of Samsung 
00033  *      Advanced Institute of Technology and The City University of New York.
00034  * 4. Neither the name of Samsung Advanced Institute of Technology nor of 
00035  *    The City University of New York may be used to endorse or promote 
00036  *    products derived from this software without specific prior written 
00037  *    permission.
00038  *
00039  * THIS SOFTWARE IS PROVIDED BY THE JOINT LAB OF SAMSUNG ADVANCED INSTITUTE
00040  * OF TECHNOLOGY AND THE CITY UNIVERSITY OF NEW YORK ``AS IS'' AND ANY EXPRESS 
00041  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00042  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 
00043  * NO EVENT SHALL SAMSUNG ADVANCED INSTITUTE OR THE CITY UNIVERSITY OF NEW YORK 
00044  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00045  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
00046  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
00047  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00048  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
00049  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00050  */
00051 
00052 
00053 #include <packet.h>
00054 #include <mac.h>
00055 #include <mac-802_11.h>
00056 #include "p802_15_4trace.h"
00057 
00058 //ns-2.27 changed 'dh_sa' to 'dh_ta' and 'dh_da' to 'dh_ra' in mac-802_11.h/cc
00059 #define dh_sa dh_ta
00060 #define dh_da dh_ra
00061 
00062 #define use_hdr_802_11_for_trace
00063 
00064 #ifndef use_hdr_802_11_for_trace
00065 
00066 int p802_15_4macSA(Packet *p)
00067 {
00068     struct hdr_mac *mh = HDR_MAC(p);
00069     return mh->macSA();
00070 }
00071 
00072 int p802_15_4macDA(Packet *p)
00073 {
00074     struct hdr_mac *mh = HDR_MAC(p);
00075     return mh->macDA();
00076 }
00077 
00078 u_int16_t p802_15_4hdr_type(Packet *p)
00079 {
00080     struct hdr_mac *mh = HDR_MAC(p);
00081     return mh->hdr_type();
00082 }
00083 
00084 int p802_15_4hdr_dst(char* hdr,int dst)
00085 {
00086     struct hdr_mac *mh = (struct hdr_mac*) hdr;
00087     if(dst > -2)
00088         mh->macDA_ = dst;
00089     return mh->macDA();
00090 }
00091 
00092 int p802_15_4hdr_src(char* hdr,int src)
00093 {
00094     struct hdr_mac *mh = (struct hdr_mac*) hdr;
00095     if(src > -2)
00096         mh->macSA_ = src;
00097     return mh->macSA();
00098 }
00099 
00100 int p802_15_4hdr_type(char* hdr, u_int16_t type)
00101 {
00102     struct hdr_mac *mh = (struct hdr_mac*) hdr;
00103     if (type)
00104         mh->hdr_type_ = type;
00105     return mh->hdr_type();
00106 }
00107 
00108 void p802_15_4hdrDATA(Packet *p)
00109 {
00110     ;   //nothing to do
00111 }
00112 
00113 void p802_15_4hdrACK(Packet *p)
00114 {
00115     ;   //nothing to do
00116 }
00117 
00118 void p802_15_4hdrBeacon(Packet *p)
00119 {
00120     ;   //nothing to do
00121 }
00122 
00123 void p802_15_4hdrCommand(Packet *p, u_int16_t type)
00124 {
00125     ;   //nothing to do
00126 }
00127 
00128 #else
00129 
00130 int p802_15_4macSA(Packet *p)
00131 {
00132     struct hdr_mac802_11 *mh = HDR_MAC802_11(p);
00133     return ETHER_ADDR(mh->dh_sa);
00134     
00135 }
00136 
00137 int p802_15_4macDA(Packet *p)
00138 {
00139     struct hdr_mac802_11 *mh = HDR_MAC802_11(p);
00140     return ETHER_ADDR(mh->dh_da);
00141 }
00142 
00143 u_int16_t p802_15_4hdr_type(Packet *p)
00144 {
00145     struct hdr_mac802_11 *mh = HDR_MAC802_11(p);
00146     return GET2BYTE(mh->dh_body);
00147 }
00148 
00149 int p802_15_4hdr_dst(char* hdr,int dst)
00150 {
00151     struct hdr_mac802_11 *mh = (struct hdr_mac802_11*) hdr;
00152     if(dst > -2)
00153         STORE4BYTE(&dst, (mh->dh_da));
00154     return ETHER_ADDR(mh->dh_da);
00155 }
00156 
00157 int p802_15_4hdr_src(char* hdr,int src)
00158 {
00159     struct hdr_mac802_11 *mh = (struct hdr_mac802_11*) hdr;
00160     if(src > -2)
00161         STORE4BYTE(&src, (mh->dh_sa));
00162     return ETHER_ADDR(mh->dh_sa);
00163 }
00164 
00165 int p802_15_4hdr_type(char* hdr, u_int16_t type)
00166 {
00167     struct hdr_mac802_11 *mh = (struct hdr_mac802_11*) hdr;
00168     if(type)
00169         STORE2BYTE(&type,(mh->dh_body));
00170     return GET2BYTE(mh->dh_body);
00171 }
00172 
00173 void p802_15_4hdrDATA(Packet *p)
00174 {
00175     struct hdr_mac802_11* mh = HDR_MAC802_11(p);
00176 
00177     //ch->size() += ETHER_HDR_LEN11;
00178 
00179     mh->dh_fc.fc_protocol_version = MAC_ProtocolVersion;
00180     mh->dh_fc.fc_type = MAC_Type_Data;
00181     mh->dh_fc.fc_subtype = MAC_Subtype_Data;
00182 }
00183 
00184 void p802_15_4hdrACK(Packet *p)
00185 {
00186     struct ack_frame *af = (struct ack_frame*)p->access(hdr_mac::offset_);
00187 
00188     af->af_fc.fc_protocol_version = MAC_ProtocolVersion;
00189     af->af_fc.fc_type = MAC_Type_Control;
00190     af->af_fc.fc_subtype = MAC_Subtype_ACK;
00191 }
00192 
00193 void p802_15_4hdrBeacon(Packet *p)
00194 {
00195     struct hdr_mac802_11* mh = HDR_MAC802_11(p);
00196 
00197     mh->dh_fc.fc_protocol_version = MAC_ProtocolVersion;
00198     mh->dh_fc.fc_type = MAC_Type_Control;       //doesn't really matter
00199     mh->dh_fc.fc_subtype = MAC_Subtype_Beacon;
00200 }
00201 
00202 void p802_15_4hdrCommand(Packet *p, u_int16_t type)
00203 {
00204     struct hdr_mac802_11* mh = HDR_MAC802_11(p);
00205 
00206     mh->dh_fc.fc_protocol_version = MAC_ProtocolVersion;
00207     mh->dh_fc.fc_type = MAC_Type_Control;       //doesn't really matter
00208     mh->dh_fc.fc_subtype = type;
00209 }
00210 
00211 #endif
00212 
00213 const char *wpan_pName(Packet *p)
00214 {
00215     struct hdr_cmn *ch = HDR_CMN(p);
00216     struct hdr_mac802_11 *mh = HDR_MAC802_11(p);
00217     return
00218     ((ch->ptype() == PT_MAC) ? (
00219       (mh->dh_fc.fc_subtype == MAC_Subtype_Beacon) ? "M_BEACON"  :          //Beacon
00220       (mh->dh_fc.fc_subtype == MAC_Subtype_Command_AssoReq) ? "M_CM1_AssoReq"  :    //CMD: Association request
00221       (mh->dh_fc.fc_subtype == MAC_Subtype_Command_AssoRsp) ? "M_CM2_AssoRsp"  :    //CMD: Association response
00222       (mh->dh_fc.fc_subtype == MAC_Subtype_Command_DAssNtf) ? "M_CM3_DisaNtf"  :    //CMD: Disassociation notification
00223       (mh->dh_fc.fc_subtype == MAC_Subtype_Command_DataReq) ? "M_CM4_DataReq"  :    //CMD: Data request
00224       (mh->dh_fc.fc_subtype == MAC_Subtype_Command_PIDCNtf) ? "M_CM5_PidCNtf"  :    //CMD: PAN ID conflict notification
00225       (mh->dh_fc.fc_subtype == MAC_Subtype_Command_OrphNtf) ? "M_CM6_OrphNtf"  :    //CMD: Orphan notification
00226       (mh->dh_fc.fc_subtype == MAC_Subtype_Command_BconReq) ? "M_CM7_Bcn-Req"  :    //CMD: Beacon request
00227       (mh->dh_fc.fc_subtype == MAC_Subtype_Command_CoorRea) ? "M_CM8_CoorRal"  :    //CMD: Coordinator realignment
00228       (mh->dh_fc.fc_subtype == MAC_Subtype_Command_GTSReq) ?  "M_CM9_GTS-Req"  :    //CMD: GTS request
00229       (mh->dh_fc.fc_subtype == MAC_Subtype_ACK) ? "M_ACK"  :            //Acknowledgement
00230       "M_UNKN"
00231       ) : packet_info.name(ch->ptype()));
00232 }
00233 
00234 // End of file: p802_15_4trace.cc

Generated on Tue Mar 6 16:47:48 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6