00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2007 Emmanuelle Laprise 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca> 00019 */ 00020 00021 #ifndef ETHERNET_HEADER_H 00022 #define ETHERNET_HEADER_H 00023 00024 #include "ns3/header.h" 00025 #include <string> 00026 #include "ns3/mac48-address.h" 00027 00028 namespace ns3 { 00029 00030 /** 00031 * Types of ethernet packets. Indicates the type of the current 00032 * header. 00033 */ 00034 enum ethernet_header_t { 00035 LENGTH, /**< Basic ethernet packet, no tags, type/length field 00036 indicates packet length or IP/ARP packet */ 00037 VLAN, /**< Single tagged packet. Header includes VLAN tag */ 00038 QINQ /**< Double tagged packet. Header includes two VLAN tags */ 00039 }; 00040 /** 00041 * \ingroup node 00042 * 00043 * \brief Packet header for Ethernet 00044 * 00045 * This class can be used to add a header to an ethernet packet that 00046 * will specify the source and destination addresses and the length of 00047 * the packet. Eventually the class will be improved to also support 00048 * VLAN tags in packet headers. 00049 */ 00050 class EthernetHeader : public Header 00051 { 00052 public: 00053 00054 /** 00055 * \brief Construct a null ethernet header 00056 * \param hasPreamble if true, insert and remove an ethernet preamble from the 00057 * packet, if false, does not insert and remove it. 00058 */ 00059 EthernetHeader (bool hasPreamble); 00060 /** 00061 * \brief Construct a null ethernet header 00062 * By default, does not add or remove an ethernet preamble 00063 */ 00064 EthernetHeader (); 00065 /** 00066 * \param size The size of the payload in bytes 00067 */ 00068 void SetLengthType (uint16_t size); 00069 /** 00070 * \param source The source address of this packet 00071 */ 00072 void SetSource (Mac48Address source); 00073 /** 00074 * \param destination The destination address of this packet. 00075 */ 00076 void SetDestination (Mac48Address destination); 00077 /** 00078 * \param preambleSfd The value that the preambleSfd field should take 00079 */ 00080 void SetPreambleSfd (uint64_t preambleSfd); 00081 /** 00082 * \return The size of the payload in bytes 00083 */ 00084 uint16_t GetLengthType (void) const; 00085 /** 00086 * \return The type of packet (only basic Ethernet is currently supported) 00087 */ 00088 ethernet_header_t GetPacketType (void) const; 00089 /** 00090 * \return The source address of this packet 00091 */ 00092 Mac48Address GetSource (void) const; 00093 /** 00094 * \return The destination address of this packet 00095 */ 00096 Mac48Address GetDestination (void) const; 00097 /** 00098 * \return The value of the PreambleSfd field 00099 */ 00100 uint64_t GetPreambleSfd () const; 00101 /** 00102 * \return The size of the header 00103 */ 00104 uint32_t GetHeaderSize() const; 00105 00106 static TypeId GetTypeId (void); 00107 virtual TypeId GetInstanceTypeId (void) const; 00108 virtual void Print (std::ostream &os) const; 00109 virtual uint32_t GetSerializedSize (void) const; 00110 virtual void Serialize (Buffer::Iterator start) const; 00111 virtual uint32_t Deserialize (Buffer::Iterator start); 00112 private: 00113 static const int PREAMBLE_SIZE = 8; /// size of the preamble_sfd header field 00114 static const int LENGTH_SIZE = 2; /// size of the length_type header field 00115 static const int MAC_ADDR_SIZE = 6; /// size of src/dest addr header fields 00116 00117 /** 00118 * If false, the preamble/sfd are not serialised/deserialised. 00119 */ 00120 bool m_enPreambleSfd; 00121 uint64_t m_preambleSfd; /// Value of the Preamble/SFD fields 00122 uint16_t m_lengthType; /// Length or type of the packet 00123 Mac48Address m_source; /// Source address 00124 Mac48Address m_destination; /// Destination address 00125 }; 00126 00127 }; // namespace ns3 00128 00129 00130 #endif /* ETHERNET_HEADER_H */