A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-mac-trailer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 The Boeing Company
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author:
7 * kwong yin <kwong-sang.yin@boeing.com>
8 * Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
9 * Erwan Livolant <erwan.livolant@inria.fr>
10 */
11
12#ifndef LR_WPAN_MAC_TRAILER_H
13#define LR_WPAN_MAC_TRAILER_H
14
15#include <ns3/trailer.h>
16
17namespace ns3
18{
19
20class Packet;
21
22namespace lrwpan
23{
24
25/**
26 * \ingroup lr-wpan
27 *
28 * Represent the Mac Trailer with the Frame Check Sequence field.
29 */
31{
32 public:
33 /**
34 * Get the type ID.
35 *
36 * \return the object TypeId
37 */
38 static TypeId GetTypeId();
39
40 /**
41 * Default constructor for a MAC trailer with disabled FCS calculation.
42 */
44
45 // Inherited from the Trailer class.
46 TypeId GetInstanceTypeId() const override;
47 void Print(std::ostream& os) const override;
48 uint32_t GetSerializedSize() const override;
49 void Serialize(Buffer::Iterator start) const override;
51
52 /**
53 * Get this trailers FCS value. If FCS calculation is disabled for this
54 * trailer, the returned value is always 0.
55 *
56 * \return the FCS value.
57 */
58 uint16_t GetFcs() const;
59
60 /**
61 * Calculate and set the FCS value based on the given packet.
62 *
63 * \param p the packet for which the FCS should be calculated
64 */
66
67 /**
68 * Check the FCS of a given packet against the FCS value stored in the
69 * trailer. The packet itself should contain no trailer. If FCS calculation is
70 * disabled for this trailer, CheckFcs() will always return true.
71 *
72 * \param p the packet to be checked
73 * \return false, if the FCS values do not match, true otherwise
74 */
76
77 /**
78 * Enable or disable FCS calculation for this trailer.
79 *
80 * \param enable flag, indicating if FCS calculation should be enabled or not
81 */
82 void EnableFcs(bool enable);
83
84 /**
85 * Query if FCS calculation is enabled for this trailer.
86 *
87 * \return true, if FCS calculation is enabled, false otherwise.
88 */
89 bool IsFcsEnabled() const;
90
91 private:
92 /**
93 * Calculate the 16-bit FCS value.
94 * CRC16-CCITT with a generator polynomial = ^16 + ^12 + ^5 + 1, LSB first and
95 * initial value = 0x0000.
96 *
97 * \param data the checksum will be calculated over this data
98 * \param length the length of the data
99 * \return the checksum
100 */
101 uint16_t GenerateCrc16(uint8_t* data, int length);
102
103 /**
104 * The FCS value stored in this trailer.
105 */
106 uint16_t m_fcs;
107
108 /**
109 * Only if m_calcFcs is true, FCS values will be calculated and used in the
110 * trailer
111 */
113};
114
115} // namespace lrwpan
116} // namespace ns3
117
118#endif /* LR_WPAN_MAC_TRAILER_H */
iterator in a Buffer instance
Definition buffer.h:89
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
Represent the Mac Trailer with the Frame Check Sequence field.
void Serialize(Buffer::Iterator start) const override
bool IsFcsEnabled() const
Query if FCS calculation is enabled for this trailer.
void EnableFcs(bool enable)
Enable or disable FCS calculation for this trailer.
uint32_t Deserialize(Buffer::Iterator start) override
void SetFcs(Ptr< const Packet > p)
Calculate and set the FCS value based on the given packet.
uint32_t GetSerializedSize() const override
bool CheckFcs(Ptr< const Packet > p)
Check the FCS of a given packet against the FCS value stored in the trailer.
bool m_calcFcs
Only if m_calcFcs is true, FCS values will be calculated and used in the trailer.
uint16_t m_fcs
The FCS value stored in this trailer.
LrWpanMacTrailer()
Default constructor for a MAC trailer with disabled FCS calculation.
uint16_t GetFcs() const
Get this trailers FCS value.
static TypeId GetTypeId()
Get the type ID.
uint16_t GenerateCrc16(uint8_t *data, int length)
Calculate the 16-bit FCS value.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void Print(std::ostream &os) const override
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]