A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ethernet-trailer.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_TRAILER_H
10#define ETHERNET_TRAILER_H
11
12#include "ns3/packet.h"
13#include "ns3/trailer.h"
14
15#include <string>
16
17namespace ns3
18{
19
20/**
21 * \ingroup network
22 *
23 * \brief Packet trailer for Ethernet
24 *
25 * This class can be used to add and verify the FCS at the end of an
26 * Ethernet packet.
27 */
29{
30 public:
31 /**
32 * \brief Construct a null ethernet trailer
33 */
35
36 /**
37 * \brief Enable or disable FCS checking and calculations
38 * \param enable If true, enables FCS calculations.
39 */
40 void EnableFcs(bool enable);
41
42 /**
43 * \brief Updates the Fcs Field to the correct FCS
44 * \param p Reference to a packet on which the FCS should be
45 * calculated. The packet should not currently contain an
46 * EthernetTrailer.
47 */
49
50 /**
51 * \brief Sets the FCS to a new value
52 * \param fcs New FCS value
53 */
54 void SetFcs(uint32_t fcs);
55
56 /**
57 * \return the FCS contained in this trailer
58 */
59 uint32_t GetFcs() const;
60
61 /**
62 * Calculate an FCS on the provided packet and check this value against
63 * the FCS found when the trailer was deserialized (the one in the transmitted
64 * packet).
65 *
66 * If FCS checking is disabled, this method will always
67 * return true.
68 *
69 * \param p Reference to the packet on which the FCS should be
70 * calculated. The packet should not contain an EthernetTrailer.
71 *
72 * \return Returns true if the Packet FCS matches the FCS in the trailer,
73 * false otherwise.
74 */
75 bool CheckFcs(Ptr<const Packet> p) const;
76
77 /**
78 * \return Returns the size of the trailer
79 */
81
82 /**
83 * \brief Get the type ID.
84 * \return the object TypeId
85 */
86 static TypeId GetTypeId();
87 TypeId GetInstanceTypeId() const override;
88 void Print(std::ostream& os) const override;
89 uint32_t GetSerializedSize() const override;
90 void Serialize(Buffer::Iterator end) const override;
92
93 private:
94 /**
95 * Enabled FCS calculations. If false, m_fcs is set to 0 and CheckFcs
96 * returns true.
97 */
99 uint32_t m_fcs; //!< Value of the fcs contained in the trailer
100};
101
102} // namespace ns3
103
104#endif /* ETHERNET_TRAILER_H */
iterator in a Buffer instance
Definition buffer.h:89
Packet trailer for Ethernet.
uint32_t GetFcs() const
uint32_t Deserialize(Buffer::Iterator end) override
void Print(std::ostream &os) const override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
bool CheckFcs(Ptr< const Packet > p) const
Calculate an FCS on the provided packet and check this value against the FCS found when the trailer w...
uint32_t GetSerializedSize() const override
void Serialize(Buffer::Iterator end) const override
uint32_t GetTrailerSize() const
void EnableFcs(bool enable)
Enable or disable FCS checking and calculations.
EthernetTrailer()
Construct a null ethernet trailer.
bool m_calcFcs
Enabled FCS calculations.
void CalcFcs(Ptr< const Packet > p)
Updates the Fcs Field to the correct FCS.
uint32_t m_fcs
Value of the fcs contained in the trailer.
static TypeId GetTypeId()
Get the type ID.
void SetFcs(uint32_t fcs)
Sets the FCS to a new value.
Smart pointer class similar to boost::intrusive_ptr.
Protocol trailer serialization and deserialization.
Definition trailer.h:30
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.