Packet header for Ethernet. More...
#include <ethernet-header.h>
Public Member Functions | |
EthernetHeader (bool hasPreamble) | |
Construct a null ethernet header. | |
EthernetHeader () | |
Construct a null ethernet header By default, does not add or remove an ethernet preamble. | |
void | SetLengthType (uint16_t size) |
void | SetSource (Mac48Address source) |
void | SetDestination (Mac48Address destination) |
void | SetPreambleSfd (uint64_t preambleSfd) |
uint16_t | GetLengthType (void) const |
ethernet_header_t | GetPacketType (void) const |
Mac48Address | GetSource (void) const |
Mac48Address | GetDestination (void) const |
uint64_t | GetPreambleSfd () const |
uint32_t | GetHeaderSize () const |
virtual TypeId | GetInstanceTypeId (void) const |
virtual void | Print (std::ostream &os) const |
virtual uint32_t | GetSerializedSize (void) const |
virtual void | Serialize (Buffer::Iterator start) const |
virtual uint32_t | Deserialize (Buffer::Iterator start) |
Static Public Member Functions | |
static TypeId | GetTypeId (void) |
This method returns the TypeId associated to ns3::EthernetHeader. | |
Private Attributes | |
bool | m_enPreambleSfd |
size of src/dest addr header fields | |
uint64_t | m_preambleSfd |
uint16_t | m_lengthType |
Value of the Preamble/SFD fields. | |
Mac48Address | m_source |
Length or type of the packet. | |
Mac48Address | m_destination |
Source address. | |
Static Private Attributes | |
static const int | PREAMBLE_SIZE = 8 |
static const int | LENGTH_SIZE = 2 |
size of the preamble_sfd header field | |
static const int | MAC_ADDR_SIZE = 6 |
size of the length_type header field |
Packet header for Ethernet.
This class can be used to add a header to an ethernet packet that will specify the source and destination addresses and the length of the packet. Eventually the class will be improved to also support VLAN tags in packet headers.
Definition at line 50 of file ethernet-header.h.
ns3::EthernetHeader::EthernetHeader | ( | bool | hasPreamble | ) |
Construct a null ethernet header.
hasPreamble | if true, insert and remove an ethernet preamble from the packet, if false, does not insert and remove it. |
Definition at line 35 of file ethernet-header.cc.
ns3::EthernetHeader::EthernetHeader | ( | ) |
Construct a null ethernet header By default, does not add or remove an ethernet preamble.
Definition at line 40 of file ethernet-header.cc.
uint32_t ns3::EthernetHeader::Deserialize | ( | Buffer::Iterator | start | ) | [virtual] |
start | an iterator which points to where the header should written. |
This method is used by Packet::RemoveHeader to re-create a header from the byte buffer of a packet. The data read is expected to match bit-for-bit the representation of this header in real networks.
Implements ns3::Header.
Definition at line 156 of file ethernet-header.cc.
References GetSerializedSize(), m_destination, m_enPreambleSfd, m_lengthType, m_source, ns3::ReadFrom(), ns3::Buffer::Iterator::ReadNtohU16(), and ns3::Buffer::Iterator::ReadU64().
Mac48Address ns3::EthernetHeader::GetDestination | ( | void | ) | const |
Definition at line 84 of file ethernet-header.cc.
References m_destination.
Referenced by ns3::EmuNetDevice::ForwardUp(), ns3::CsmaNetDevice::ProcessHeader(), and ns3::CsmaNetDevice::Receive().
uint32_t ns3::EthernetHeader::GetHeaderSize | ( | void | ) | const |
Definition at line 96 of file ethernet-header.cc.
References GetSerializedSize().
TypeId ns3::EthernetHeader::GetInstanceTypeId | ( | void | ) | const [virtual] |
This method is typically implemented by ns3::Object::GetInstanceTypeId but some classes which derive from ns3::ObjectBase directly have to implement it themselves.
Implements ns3::ObjectBase.
Definition at line 112 of file ethernet-header.cc.
References GetTypeId().
uint16_t ns3::EthernetHeader::GetLengthType | ( | void | ) | const |
Definition at line 51 of file ethernet-header.cc.
References m_lengthType.
Referenced by ns3::CsmaNetDevice::ProcessHeader(), and ns3::CsmaNetDevice::Receive().
ethernet_header_t ns3::EthernetHeader::GetPacketType | ( | void | ) | const |
Definition at line 90 of file ethernet-header.cc.
References ns3::LENGTH.
uint64_t ns3::EthernetHeader::GetPreambleSfd | ( | void | ) | const |
Definition at line 62 of file ethernet-header.cc.
References m_preambleSfd.
uint32_t ns3::EthernetHeader::GetSerializedSize | ( | void | ) | const [virtual] |
This method is used by Packet::AddHeader to store a header into the byte buffer of a packet. This method should return the number of bytes which are needed to store the full header data by Serialize.
Implements ns3::Header.
Definition at line 130 of file ethernet-header.cc.
References LENGTH_SIZE, m_enPreambleSfd, MAC_ADDR_SIZE, and PREAMBLE_SIZE.
Referenced by Deserialize(), and GetHeaderSize().
Mac48Address ns3::EthernetHeader::GetSource | ( | void | ) | const |
Definition at line 73 of file ethernet-header.cc.
References m_source.
Referenced by ns3::EmuNetDevice::ForwardUp(), and ns3::CsmaNetDevice::Receive().
TypeId ns3::EthernetHeader::GetTypeId | ( | void | ) | [static] |
This method returns the TypeId associated to ns3::EthernetHeader.
No Attributes defined for this type.
No TraceSources defined for this type.
Reimplemented from ns3::Header.
Definition at line 103 of file ethernet-header.cc.
References ns3::TypeId::SetParent().
Referenced by GetInstanceTypeId().
void ns3::EthernetHeader::Print | ( | std::ostream & | os | ) | const [virtual] |
This method is used by Packet::Print to print the content of a trailer as ascii data to a c++ output stream. Although the trailer is free to format its output as it wishes, it is recommended to follow a few rules to integrate with the packet pretty printer: start with flags, small field values located between a pair of parens. Values should be separated by whitespace. Follow the parens with the important fields, separated by whitespace. i.e.: (field1 val1 field2 val2 field3 val3) field4 val4 field5 val5
Implements ns3::Header.
Definition at line 117 of file ethernet-header.cc.
References m_destination, m_enPreambleSfd, m_lengthType, m_preambleSfd, and m_source.
void ns3::EthernetHeader::Serialize | ( | Buffer::Iterator | start | ) | const [virtual] |
start | an iterator which points to where the header should be written. |
This method is used by Packet::AddHeader to store a header into the byte buffer of a packet. The data written is expected to match bit-for-bit the representation of this header in a real network.
Implements ns3::Header.
Definition at line 143 of file ethernet-header.cc.
References m_destination, m_enPreambleSfd, m_lengthType, m_preambleSfd, m_source, ns3::Buffer::Iterator::WriteHtonU16(), ns3::WriteTo(), and ns3::Buffer::Iterator::WriteU64().
void ns3::EthernetHeader::SetDestination | ( | Mac48Address | destination | ) |
destination | The destination address of this packet. |
Definition at line 79 of file ethernet-header.cc.
References m_destination.
Referenced by ns3::CsmaNetDevice::AddHeader(), and ns3::EmuNetDevice::SendFrom().
void ns3::EthernetHeader::SetLengthType | ( | uint16_t | size | ) |
size | The size of the payload in bytes |
Definition at line 46 of file ethernet-header.cc.
References m_lengthType.
Referenced by ns3::CsmaNetDevice::AddHeader(), and ns3::EmuNetDevice::SendFrom().
void ns3::EthernetHeader::SetPreambleSfd | ( | uint64_t | preambleSfd | ) |
preambleSfd | The value that the preambleSfd field should take |
Definition at line 57 of file ethernet-header.cc.
References m_preambleSfd.
void ns3::EthernetHeader::SetSource | ( | Mac48Address | source | ) |
source | The source address of this packet |
Definition at line 68 of file ethernet-header.cc.
References m_source.
Referenced by ns3::CsmaNetDevice::AddHeader(), and ns3::EmuNetDevice::SendFrom().
const int ns3::EthernetHeader::LENGTH_SIZE = 2 [static, private] |
size of the preamble_sfd header field
Definition at line 114 of file ethernet-header.h.
Referenced by GetSerializedSize().
Source address.
Definition at line 124 of file ethernet-header.h.
Referenced by Deserialize(), GetDestination(), Print(), Serialize(), and SetDestination().
bool ns3::EthernetHeader::m_enPreambleSfd [private] |
size of src/dest addr header fields
If false, the preamble/sfd are not serialised/deserialised.
Definition at line 120 of file ethernet-header.h.
Referenced by Deserialize(), GetSerializedSize(), Print(), and Serialize().
uint16_t ns3::EthernetHeader::m_lengthType [private] |
Value of the Preamble/SFD fields.
Definition at line 122 of file ethernet-header.h.
Referenced by Deserialize(), GetLengthType(), Print(), Serialize(), and SetLengthType().
uint64_t ns3::EthernetHeader::m_preambleSfd [private] |
Definition at line 121 of file ethernet-header.h.
Referenced by GetPreambleSfd(), Print(), Serialize(), and SetPreambleSfd().
Mac48Address ns3::EthernetHeader::m_source [private] |
Length or type of the packet.
Definition at line 123 of file ethernet-header.h.
Referenced by Deserialize(), GetSource(), Print(), Serialize(), and SetSource().
const int ns3::EthernetHeader::MAC_ADDR_SIZE = 6 [static, private] |
size of the length_type header field
Definition at line 115 of file ethernet-header.h.
Referenced by GetSerializedSize().
const int ns3::EthernetHeader::PREAMBLE_SIZE = 8 [static, private] |
Definition at line 113 of file ethernet-header.h.
Referenced by GetSerializedSize().