ns-3 PLC model
model/plc-header.h
00001 /*
00002  * plc-header.h
00003  *
00004  *  Created on: 2012-05-25
00005  *      Author: deadlock
00006  */
00007 
00008 #ifndef PLC_HEADER_H_
00009 #define PLC_HEADER_H_
00010 
00011 #include <limits>
00012 
00013 #include <ns3/mac48-address.h>
00014 #include <ns3/header.h>
00015 #include <ns3/tag.h>
00016 #include <ns3/nstime.h>
00017 
00018 #include "plc-defs.h"
00019 
00020 namespace ns3 {
00021 
00022 #define MAX_PPDU_SYMBOLS std::numeric_limits<uint16_t>::max()
00023 
00024 class PLC_Preamble : public Header
00025 {
00026 public:
00027         static TypeId GetTypeId (void);
00028 
00029         PLC_Preamble(void);
00030         ~PLC_Preamble(void);
00031 
00032         static void SetDuration (Time duration);
00033         static Time GetDuration (void);
00034 
00035         virtual uint32_t GetSerializedSize (void) const;
00036         virtual TypeId GetInstanceTypeId (void) const;
00037         virtual void Serialize (Buffer::Iterator start) const;
00038         virtual uint32_t Deserialize (Buffer::Iterator start);
00039         virtual void Print (std::ostream &os) const;
00040 
00041 private:
00042         static Time preamble_duration;
00043 };
00044 
00045 class PLC_PhyFrameControlHeader : public Header
00046 {
00047 public:
00048         enum DelimiterType
00049         {
00050                 DATA,
00051                 ACK,
00052                 NACK
00053         };
00054 
00055         static TypeId GetTypeId (void);
00056 
00057         PLC_PhyFrameControlHeader (void);
00058         ~PLC_PhyFrameControlHeader (void);
00059 
00060         void SetDelimiterType (DelimiterType type) { m_delimiter_type = (uint8_t) type; }
00061         DelimiterType GetDelimiterType (void) { return (DelimiterType) m_delimiter_type; }
00062         void SetPayloadSymbols (uint16_t symbols) { m_payload_symbols = symbols; }
00063         uint16_t GetPayloadSymbols (void) { return m_payload_symbols; }
00064         void SetPayloadMcs (ModulationAndCodingType mcs) { m_payload_mcs = mcs; }
00065         ModulationAndCodingType GetPayloadMcs (void) { return (ModulationAndCodingType) m_payload_mcs; }
00066         void SetFccs (uint8_t fccs) { m_fccs = fccs; }
00067         uint8_t GetFccs (void) { return m_fccs; }
00068 
00069         virtual uint32_t GetSerializedSize (void) const;
00070         virtual TypeId GetInstanceTypeId (void) const;
00071         virtual void Serialize (Buffer::Iterator start) const;
00072         virtual uint32_t Deserialize (Buffer::Iterator start);
00073         virtual void Print (std::ostream &os) const;
00074 
00075 private:
00076         uint8_t m_delimiter_type;
00077         uint16_t m_payload_symbols;
00078         uint8_t m_payload_mcs;
00079         uint8_t m_fccs; // frame control check sequence
00080 };
00081 
00082 std::ostream& operator<<(std::ostream& os, PLC_PhyFrameControlHeader::DelimiterType type);
00083 
00084 class PLC_PhyRatelessFrameControlHeader : public Header
00085 {
00086 public:
00087         enum DelimiterType
00088         {
00089                 DATA,
00090                 ACK,
00091                 NACK
00092         };
00093 
00094         static TypeId GetTypeId (void);
00095 
00096         PLC_PhyRatelessFrameControlHeader (void);
00097         ~PLC_PhyRatelessFrameControlHeader (void);
00098 
00099         void SetDelimiterType (DelimiterType type) { m_delimiter_type = (uint8_t) type; }
00100         DelimiterType GetDelimiterType (void) { return (DelimiterType) m_delimiter_type; }
00101         void SetPayloadSymbols (uint16_t symbols) { m_payload_symbols = symbols; }
00102         uint16_t GetPayloadSymbols (void) { return m_payload_symbols; }
00103         void SetPayloadMcs (ModulationAndCodingType mcs) { m_payload_mcs = mcs; }
00104         ModulationAndCodingType GetPayloadMcs (void) { return (ModulationAndCodingType) m_payload_mcs; }
00105         void SetFccs (uint8_t fccs) { m_fccs = fccs; }
00106         uint8_t GetFccs (void) { return m_fccs; }
00107         void SetPrngSeed (uint16_t prng_seed) { m_prng_seed = prng_seed; }
00108         uint16_t GetPrngSeed (void) { return m_prng_seed; }
00109         void SetNumBlocks (uint32_t num_blocks) { m_num_blocks = num_blocks; }
00110         uint32_t GetNumBlocks (void) { return m_num_blocks; }
00111 
00112         virtual uint32_t GetSerializedSize (void) const;
00113         virtual TypeId GetInstanceTypeId (void) const;
00114         virtual void Serialize (Buffer::Iterator start) const;
00115         virtual uint32_t Deserialize (Buffer::Iterator start);
00116         virtual void Print (std::ostream &os) const;
00117 
00118 private:
00119         uint8_t m_delimiter_type;
00120         uint16_t m_payload_symbols;
00121         uint8_t m_payload_mcs;
00122         uint16_t m_prng_seed;
00123         uint32_t m_num_blocks;
00124         uint8_t m_fccs; // frame control check sequence
00125 };
00126 
00127 class PLC_MacHeader : public Header
00128 {
00129 public:
00130         enum MacHdrType {
00131                 DATA,
00132                 ACK,
00133                 NACK
00134         };
00135 
00136         static TypeId GetTypeId (void);
00137 
00138         PLC_MacHeader(void);
00139         ~PLC_MacHeader(void);
00140 
00141         void SetDstAddress(Mac48Address addr);
00142         void SetSrcAddress(Mac48Address addr);
00143         void SetType(MacHdrType type);
00144         void SetSequenceNumber(uint16_t sqn);
00145         void SetMessageLength(uint32_t length);
00146 
00147         Mac48Address GetDstAddress(void) const;
00148         Mac48Address GetSrcAddress(void) const;
00149         MacHdrType GetType(void) const;
00150         uint16_t GetSequenceNumber(void) const;
00151         uint32_t GetMessageLength(void) const;
00152 
00153         virtual uint32_t GetSerializedSize (void) const;
00154         virtual TypeId GetInstanceTypeId (void) const;
00155         virtual void Serialize (Buffer::Iterator start) const;
00156         virtual uint32_t Deserialize (Buffer::Iterator start);
00157         virtual void Print (std::ostream &os) const;
00158 
00159         bool operator==(PLC_MacHeader& hdr)
00160         {
00161                 return (hdr.m_dst_address == m_dst_address && hdr.m_src_address == m_src_address && hdr.m_msg_sqn == m_msg_sqn);
00162         }
00163 
00164 private:
00165         Mac48Address m_dst_address;
00166         Mac48Address m_src_address;
00167         uint8_t m_flags;
00168         uint16_t m_msg_sqn;
00169         uint32_t m_msg_length;
00170 };
00171 
00172 }
00173 
00174 #endif /* PLC_HEADER_H_ */
 All Classes Functions Variables Enumerations