A Discrete-Event Network Simulator
API
ethernet-header.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Emmanuelle Laprise
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
18  */
19 
20 #ifndef ETHERNET_HEADER_H
21 #define ETHERNET_HEADER_H
22 
23 #include "mac48-address.h"
24 
25 #include "ns3/header.h"
26 
27 #include <string>
28 
29 namespace ns3
30 {
31 
39 {
40  LENGTH,
42  VLAN,
43  QINQ
44 };
45 
56 class EthernetHeader : public Header
57 {
58  public:
64  EthernetHeader(bool hasPreamble);
73  void SetLengthType(uint16_t size);
77  void SetSource(Mac48Address source);
81  void SetDestination(Mac48Address destination);
85  void SetPreambleSfd(uint64_t preambleSfd);
89  uint16_t GetLengthType() const;
97  Mac48Address GetSource() const;
105  uint64_t GetPreambleSfd() const;
109  uint32_t GetHeaderSize() const;
110 
115  static TypeId GetTypeId();
116  TypeId GetInstanceTypeId() const override;
117  void Print(std::ostream& os) const override;
118  uint32_t GetSerializedSize() const override;
119  void Serialize(Buffer::Iterator start) const override;
120  uint32_t Deserialize(Buffer::Iterator start) override;
121 
122  private:
123  static const int PREAMBLE_SIZE = 8;
124  static const int LENGTH_SIZE = 2;
125  static const int MAC_ADDR_SIZE = 6;
126 
131  uint64_t m_preambleSfd;
132  uint16_t m_lengthType;
135 };
136 
137 } // namespace ns3
138 
139 #endif /* ETHERNET_HEADER_H */
iterator in a Buffer instance
Definition: buffer.h:100
Packet header for Ethernet.
uint16_t GetLengthType() const
uint16_t m_lengthType
Length or type of the packet.
uint32_t GetHeaderSize() const
bool m_enPreambleSfd
If false, the preamble/sfd are not serialised/deserialised.
uint32_t GetSerializedSize() const override
Mac48Address m_destination
Destination address.
static TypeId GetTypeId()
Get the type ID.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void SetDestination(Mac48Address destination)
static const int PREAMBLE_SIZE
size of the preamble_sfd header field
static const int MAC_ADDR_SIZE
size of src/dest addr header fields
Mac48Address m_source
Source address.
Mac48Address GetDestination() const
void Serialize(Buffer::Iterator start) const override
void SetLengthType(uint16_t size)
void SetSource(Mac48Address source)
EthernetHeader()
Construct a null ethernet header By default, does not add or remove an ethernet preamble.
ethernet_header_t GetPacketType() const
void Print(std::ostream &os) const override
uint64_t m_preambleSfd
Value of the Preamble/SFD fields.
void SetPreambleSfd(uint64_t preambleSfd)
Mac48Address GetSource() const
static const int LENGTH_SIZE
size of the length_type header field
uint64_t GetPreambleSfd() const
Protocol header serialization and deserialization.
Definition: header.h:44
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
an EUI-48 address
Definition: mac48-address.h:46
a unique identifier for an interface.
Definition: type-id.h:59
ethernet_header_t
Types of ethernet packets.
@ LENGTH
Basic ethernet packet, no tags, type/length field indicates packet length or IP/ARP packet.
@ VLAN
Single tagged packet.
@ QINQ
Double tagged packet.
Every class exported by the ns3 library is enclosed in the ns3 namespace.