A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ethernet-header.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 Emmanuelle Laprise
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
7 */
8
9#ifndef ETHERNET_HEADER_H
10#define ETHERNET_HEADER_H
11
12#include "mac48-address.h"
13
14#include "ns3/header.h"
15
16#include <string>
17
18namespace ns3
19{
20
21/**
22 * @ingroup network
23 *
24 * Types of ethernet packets. Indicates the type of the current
25 * header.
26 */
28{
29 LENGTH, /**< Basic ethernet packet, no tags, type/length field
30 indicates packet length or IP/ARP packet */
31 VLAN, /**< Single tagged packet. Header includes VLAN tag */
32 QINQ /**< Double tagged packet. Header includes two VLAN tags */
33};
34
35/**
36 * @ingroup network
37 *
38 * @brief Packet header for Ethernet
39 *
40 * This class can be used to add a header to an ethernet packet that
41 * will specify the source and destination addresses and the length of
42 * the packet. Eventually the class will be improved to also support
43 * VLAN tags in packet headers.
44 */
45class EthernetHeader : public Header
46{
47 public:
48 /**
49 * @brief Construct a null ethernet header
50 * @param hasPreamble if true, insert and remove an ethernet preamble from the
51 * packet, if false, does not insert and remove it.
52 */
53 EthernetHeader(bool hasPreamble);
54 /**
55 * @brief Construct a null ethernet header
56 * By default, does not add or remove an ethernet preamble
57 */
59 /**
60 * @param size The size of the payload in bytes
61 */
62 void SetLengthType(uint16_t size);
63 /**
64 * @param source The source address of this packet
65 */
66 void SetSource(Mac48Address source);
67 /**
68 * @param destination The destination address of this packet.
69 */
70 void SetDestination(Mac48Address destination);
71 /**
72 * @param preambleSfd The value that the preambleSfd field should take
73 */
74 void SetPreambleSfd(uint64_t preambleSfd);
75 /**
76 * @return The size of the payload in bytes
77 */
78 uint16_t GetLengthType() const;
79 /**
80 * @return The type of packet (only basic Ethernet is currently supported)
81 */
83 /**
84 * @return The source address of this packet
85 */
86 Mac48Address GetSource() const;
87 /**
88 * @return The destination address of this packet
89 */
91 /**
92 * @return The value of the PreambleSfd field
93 */
94 uint64_t GetPreambleSfd() const;
95 /**
96 * @return The size of the header
97 */
98 uint32_t GetHeaderSize() const;
99
100 /**
101 * @brief Get the type ID.
102 * @return the object TypeId
103 */
104 static TypeId GetTypeId();
105 TypeId GetInstanceTypeId() const override;
106 void Print(std::ostream& os) const override;
107 uint32_t GetSerializedSize() const override;
108 void Serialize(Buffer::Iterator start) const override;
109 uint32_t Deserialize(Buffer::Iterator start) override;
110
111 private:
112 static const int PREAMBLE_SIZE = 8; //!< size of the preamble_sfd header field
113 static const int LENGTH_SIZE = 2; //!< size of the length_type header field
114 static const int MAC_ADDR_SIZE = 6; //!< size of src/dest addr header fields
115
116 /**
117 * If false, the preamble/sfd are not serialised/deserialised.
118 */
120 uint64_t m_preambleSfd; //!< Value of the Preamble/SFD fields
121 uint16_t m_lengthType; //!< Length or type of the packet
122 Mac48Address m_source; //!< Source address
123 Mac48Address m_destination; //!< Destination address
124};
125
126} // namespace ns3
127
128#endif /* ETHERNET_HEADER_H */
iterator in a Buffer instance
Definition buffer.h:89
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
uint32_t Deserialize(Buffer::Iterator start) 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:33
an EUI-48 address
a unique identifier for an interface.
Definition type-id.h:48
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.