A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::EthernetHeader Class Reference

Packet header for Ethernet. More...

#include "ethernet-header.h"

+ Inheritance diagram for ns3::EthernetHeader:
+ Collaboration diagram for ns3::EthernetHeader:

Public Member Functions

 EthernetHeader ()
 Construct a null ethernet header By default, does not add or remove an ethernet preamble.
 
 EthernetHeader (bool hasPreamble)
 Construct a null ethernet header.
 
uint32_t Deserialize (Buffer::Iterator start) override
 
Mac48Address GetDestination () const
 
uint32_t GetHeaderSize () const
 
TypeId GetInstanceTypeId () const override
 Get the most derived TypeId for this Object.
 
uint16_t GetLengthType () const
 
ethernet_header_t GetPacketType () const
 
uint64_t GetPreambleSfd () const
 
uint32_t GetSerializedSize () const override
 
Mac48Address GetSource () const
 
void Print (std::ostream &os) const override
 
void Serialize (Buffer::Iterator start) const override
 
void SetDestination (Mac48Address destination)
 
void SetLengthType (uint16_t size)
 
void SetPreambleSfd (uint64_t preambleSfd)
 
void SetSource (Mac48Address source)
 
- Public Member Functions inherited from ns3::Header
 ~Header () override
 
virtual uint32_t Deserialize (Buffer::Iterator start, Buffer::Iterator end)
 Deserialize the object from a buffer iterator.
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor.
 
void GetAttribute (std::string name, AttributeValue &value, bool permissive=false) const
 Get the value of an attribute, raising fatal errors if unsuccessful.
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising errors.
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful.
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors.
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context.
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context.
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context.
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context.
 

Static Public Member Functions

static TypeId GetTypeId ()
 Get the type ID.
 
- Static Public Member Functions inherited from ns3::Header
static TypeId GetTypeId ()
 Get the type ID.
 
- Static Public Member Functions inherited from ns3::Chunk
static TypeId GetTypeId ()
 Get the type ID.
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId ()
 Get the type ID.
 

Private Attributes

Mac48Address m_destination
 Destination address.
 
bool m_enPreambleSfd
 If false, the preamble/sfd are not serialised/deserialised.
 
uint16_t m_lengthType
 Length or type of the packet.
 
uint64_t m_preambleSfd
 Value of the Preamble/SFD fields.
 
Mac48Address m_source
 Source address.
 

Static Private Attributes

static const int LENGTH_SIZE = 2
 size of the length_type header field
 
static const int MAC_ADDR_SIZE = 6
 size of src/dest addr header fields
 
static const int PREAMBLE_SIZE = 8
 size of the preamble_sfd header field
 

Additional Inherited Members

- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes.
 
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed.
 

Detailed Description

Packet header for Ethernet.

Introspection did not find any typical Config paths.

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.


No Attributes are defined for this type.
No TraceSources are defined for this type.
Group: Network

Size of this type is 40 bytes (on a 64-bit architecture).

Definition at line 45 of file ethernet-header.h.

Constructor & Destructor Documentation

◆ EthernetHeader() [1/2]

ns3::EthernetHeader::EthernetHeader ( bool hasPreamble)

Construct a null ethernet header.

Parameters
hasPreambleif true, insert and remove an ethernet preamble from the packet, if false, does not insert and remove it.

Definition at line 27 of file ethernet-header.cc.

References NS_LOG_FUNCTION.

◆ EthernetHeader() [2/2]

ns3::EthernetHeader::EthernetHeader ( )

Construct a null ethernet header By default, does not add or remove an ethernet preamble.

Definition at line 34 of file ethernet-header.cc.

References NS_LOG_FUNCTION.

Member Function Documentation

◆ Deserialize()

uint32_t ns3::EthernetHeader::Deserialize ( Buffer::Iterator start)
overridevirtual
Parameters
startan iterator which points to where the header should read from.
Returns
the number of bytes read.

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.

Note that data is not actually removed from the buffer to which the iterator points. Both Packet::RemoveHeader() and Packet::PeekHeader() call Deserialize(), but only the RemoveHeader() has additional statements to remove the header bytes from the underlying buffer and associated metadata.

Implements ns3::Header.

Definition at line 171 of file ethernet-header.cc.

References GetSerializedSize(), m_destination, m_enPreambleSfd, m_lengthType, m_source, NS_LOG_FUNCTION, ns3::ReadFrom(), ns3::Buffer::Iterator::ReadNtohU16(), and ns3::Buffer::Iterator::ReadU64().

+ Here is the call graph for this function:

◆ GetDestination()

Mac48Address ns3::EthernetHeader::GetDestination ( ) const
Returns
The destination address of this packet

Definition at line 91 of file ethernet-header.cc.

References m_destination, and NS_LOG_FUNCTION.

Referenced by ns3::TapBridge::Filter(), ns3::FdNetDevice::ForwardUp(), ns3::CsmaNetDevice::Receive(), ns3::TapBridge::ReceiveFromBridgedDevice(), ns3::Ipv4L3ClickProtocol::SendDown(), ns3::PyViz::TraceNetDevPromiscRxCsma(), and ns3::PyViz::TraceNetDevTxCsma().

+ Here is the caller graph for this function:

◆ GetHeaderSize()

uint32_t ns3::EthernetHeader::GetHeaderSize ( ) const
Returns
The size of the header

Definition at line 105 of file ethernet-header.cc.

References GetSerializedSize(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ GetInstanceTypeId()

TypeId ns3::EthernetHeader::GetInstanceTypeId ( ) const
overridevirtual

Get the most derived TypeId for this Object.

This method is typically implemented by ns3::Object::GetInstanceTypeId but some classes which derive from ns3::ObjectBase directly have to implement it themselves.

Returns
The TypeId associated to the most-derived type of this instance.

Implements ns3::ObjectBase.

Definition at line 122 of file ethernet-header.cc.

References GetTypeId().

+ Here is the call graph for this function:

◆ GetLengthType()

uint16_t ns3::EthernetHeader::GetLengthType ( ) const
Returns
The size of the payload in bytes

Definition at line 49 of file ethernet-header.cc.

References m_lengthType, and NS_LOG_FUNCTION.

Referenced by ns3::TapBridge::Filter(), ns3::FdNetDevice::ForwardUp(), ns3::CsmaNetDevice::Receive(), ns3::TapBridge::ReceiveFromBridgedDevice(), and ns3::Ipv4L3ClickProtocol::SendDown().

+ Here is the caller graph for this function:

◆ GetPacketType()

ethernet_header_t ns3::EthernetHeader::GetPacketType ( ) const
Returns
The type of packet (only basic Ethernet is currently supported)

Definition at line 98 of file ethernet-header.cc.

References ns3::LENGTH, and NS_LOG_FUNCTION.

◆ GetPreambleSfd()

uint64_t ns3::EthernetHeader::GetPreambleSfd ( ) const
Returns
The value of the PreambleSfd field

Definition at line 63 of file ethernet-header.cc.

References m_preambleSfd, and NS_LOG_FUNCTION.

◆ GetSerializedSize()

uint32_t ns3::EthernetHeader::GetSerializedSize ( ) const
overridevirtual
Returns
the expected size of the header.

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 142 of file ethernet-header.cc.

References LENGTH_SIZE, m_enPreambleSfd, MAC_ADDR_SIZE, NS_LOG_FUNCTION, and PREAMBLE_SIZE.

Referenced by Deserialize(), ns3::TapBridge::Filter(), ns3::FdNetDevice::ForwardUp(), and GetHeaderSize().

+ Here is the caller graph for this function:

◆ GetSource()

Mac48Address ns3::EthernetHeader::GetSource ( ) const
Returns
The source address of this packet

Definition at line 77 of file ethernet-header.cc.

References m_source, and NS_LOG_FUNCTION.

Referenced by ns3::TapBridge::Filter(), ns3::FdNetDevice::ForwardUp(), ns3::CsmaNetDevice::Receive(), ns3::TapBridge::ReceiveFromBridgedDevice(), and ns3::PyViz::TraceNetDevRxCsma().

+ Here is the caller graph for this function:

◆ GetTypeId()

TypeId ns3::EthernetHeader::GetTypeId ( )
static

Get the type ID.

Returns
the object TypeId

Definition at line 112 of file ethernet-header.cc.

References ns3::TypeId::SetParent().

Referenced by GetInstanceTypeId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Print()

void ns3::EthernetHeader::Print ( std::ostream & os) const
overridevirtual
Parameters
osoutput stream This method is used by Packet::Print to print the content of a header as ascii data to a c++ output stream. Although the header 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 128 of file ethernet-header.cc.

References m_destination, m_enPreambleSfd, m_lengthType, m_preambleSfd, m_source, and NS_LOG_FUNCTION.

◆ Serialize()

void ns3::EthernetHeader::Serialize ( Buffer::Iterator start) const
overridevirtual
Parameters
startan 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 156 of file ethernet-header.cc.

References m_destination, m_enPreambleSfd, m_lengthType, m_preambleSfd, m_source, NS_LOG_FUNCTION, ns3::Buffer::Iterator::WriteHtonU16(), ns3::WriteTo(), and ns3::Buffer::Iterator::WriteU64().

+ Here is the call graph for this function:

◆ SetDestination()

void ns3::EthernetHeader::SetDestination ( Mac48Address destination)
Parameters
destinationThe destination address of this packet.

Definition at line 84 of file ethernet-header.cc.

References m_destination, and NS_LOG_FUNCTION.

Referenced by ns3::CsmaNetDevice::AddHeader(), ns3::Ipv4L3ClickProtocol::Receive(), ns3::TapBridge::ReceiveFromBridgedDevice(), and ns3::FdNetDevice::SendFrom().

+ Here is the caller graph for this function:

◆ SetLengthType()

void ns3::EthernetHeader::SetLengthType ( uint16_t size)
Parameters
sizeThe size of the payload in bytes

Definition at line 42 of file ethernet-header.cc.

References m_lengthType, and NS_LOG_FUNCTION.

Referenced by ns3::CsmaNetDevice::AddHeader(), ns3::Ipv4L3ClickProtocol::Receive(), ns3::TapBridge::ReceiveFromBridgedDevice(), and ns3::FdNetDevice::SendFrom().

+ Here is the caller graph for this function:

◆ SetPreambleSfd()

void ns3::EthernetHeader::SetPreambleSfd ( uint64_t preambleSfd)
Parameters
preambleSfdThe value that the preambleSfd field should take

Definition at line 56 of file ethernet-header.cc.

References m_preambleSfd, and NS_LOG_FUNCTION.

◆ SetSource()

void ns3::EthernetHeader::SetSource ( Mac48Address source)
Parameters
sourceThe source address of this packet

Definition at line 70 of file ethernet-header.cc.

References m_source, and NS_LOG_FUNCTION.

Referenced by ns3::CsmaNetDevice::AddHeader(), ns3::Ipv4L3ClickProtocol::Receive(), ns3::TapBridge::ReceiveFromBridgedDevice(), and ns3::FdNetDevice::SendFrom().

+ Here is the caller graph for this function:

Member Data Documentation

◆ LENGTH_SIZE

const int ns3::EthernetHeader::LENGTH_SIZE = 2
staticprivate

size of the length_type header field

Definition at line 113 of file ethernet-header.h.

Referenced by GetSerializedSize().

◆ m_destination

Mac48Address ns3::EthernetHeader::m_destination
private

Destination address.

Definition at line 123 of file ethernet-header.h.

Referenced by Deserialize(), GetDestination(), Print(), Serialize(), and SetDestination().

◆ m_enPreambleSfd

bool ns3::EthernetHeader::m_enPreambleSfd
private

If false, the preamble/sfd are not serialised/deserialised.

Definition at line 119 of file ethernet-header.h.

Referenced by Deserialize(), GetSerializedSize(), Print(), and Serialize().

◆ m_lengthType

uint16_t ns3::EthernetHeader::m_lengthType
private

Length or type of the packet.

Definition at line 121 of file ethernet-header.h.

Referenced by Deserialize(), GetLengthType(), Print(), Serialize(), and SetLengthType().

◆ m_preambleSfd

uint64_t ns3::EthernetHeader::m_preambleSfd
private

Value of the Preamble/SFD fields.

Definition at line 120 of file ethernet-header.h.

Referenced by GetPreambleSfd(), Print(), Serialize(), and SetPreambleSfd().

◆ m_source

Mac48Address ns3::EthernetHeader::m_source
private

Source address.

Definition at line 122 of file ethernet-header.h.

Referenced by Deserialize(), GetSource(), Print(), Serialize(), and SetSource().

◆ MAC_ADDR_SIZE

const int ns3::EthernetHeader::MAC_ADDR_SIZE = 6
staticprivate

size of src/dest addr header fields

Definition at line 114 of file ethernet-header.h.

Referenced by GetSerializedSize().

◆ PREAMBLE_SIZE

const int ns3::EthernetHeader::PREAMBLE_SIZE = 8
staticprivate

size of the preamble_sfd header field

Definition at line 112 of file ethernet-header.h.

Referenced by GetSerializedSize().


The documentation for this class was generated from the following files: