A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
arp-header.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
9#ifndef ARP_HEADER_H
10#define ARP_HEADER_H
11
12#include "ns3/address.h"
13#include "ns3/header.h"
14#include "ns3/ipv4-address.h"
15
16namespace ns3
17{
18/**
19 * @ingroup arp
20 * @brief The packet header for an ARP packet
21 */
22class ArpHeader : public Header
23{
24 public:
25 /**
26 * @brief Enumeration listing the possible ARP types
27 *
28 * These ARP types are part of the standard ARP packet format as defined in Section
29 * "Definitions" of \RFC{826}.
30 */
31 enum ArpType_e : uint16_t
32 {
35 };
36
37 /**
38 * @brief Enumeration listing the supported hardware types
39 *
40 * \RFC{826} specifies that the Hardware Type field in the ARP packet indicates the type
41 of hardware used.
42 * For the full list of Hardware Types, refer to:
43 * https://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml
44 */
45 enum class HardwareType : uint16_t
46 {
47 UNKNOWN = 0,
48 ETHERNET = 1,
49 EUI_64 = 27,
50 };
51
52 /**
53 * @brief Set the ARP request parameters
54 * @param sourceHardwareAddress the source hardware address
55 * @param sourceProtocolAddress the source IP address
56 * @param destinationHardwareAddress the destination hardware address (usually the
57 * broadcast address)
58 * @param destinationProtocolAddress the destination IP address
59 */
60 void SetRequest(Address sourceHardwareAddress,
61 Ipv4Address sourceProtocolAddress,
62 Address destinationHardwareAddress,
63 Ipv4Address destinationProtocolAddress);
64 /**
65 * @brief Set the ARP reply parameters
66 * @param sourceHardwareAddress the source hardware address
67 * @param sourceProtocolAddress the source IP address
68 * @param destinationHardwareAddress the destination hardware address (usually the
69 * broadcast address)
70 * @param destinationProtocolAddress the destination IP address
71 */
72 void SetReply(Address sourceHardwareAddress,
73 Ipv4Address sourceProtocolAddress,
74 Address destinationHardwareAddress,
75 Ipv4Address destinationProtocolAddress);
76
77 /**
78 * @brief Determines the hardware type based on the length of the address.
79 *
80 * This method determines the hardware type based on the length of the address.
81 * It supports two common hardware address lengths:
82 * - 6 bytes: Assumed to be Ethernet.
83 * - 8 bytes: Assumed to be EUI-64.
84 *
85 * If the length of the address does not match these common lengths, the method defaults
86 * to Unknown hardware type.
87 *
88 * @param address The address whose length is used to determine the hardware type.
89 * @return The corresponding hardware type.
90 */
91 HardwareType DetermineHardwareType(const Address& address) const;
92
93 /**
94 * @brief Check if the ARP is a request
95 * @returns true if it is a request
96 */
97 bool IsRequest() const;
98
99 /**
100 * @brief Check if the ARP is a reply
101 * @returns true if it is a reply
102 */
103 bool IsReply() const;
104
105 /**
106 * @brief Get the hardware type
107 * @return the hardware type
108 */
109 HardwareType GetHardwareType() const;
110
111 /**
112 * @brief Returns the source hardware address
113 * @returns the source hardware address
114 */
116
117 /**
118 * @brief Returns the destination hardware address
119 * @returns the destination hardware address
120 */
122
123 /**
124 * @brief Returns the source IP address
125 * @returns the source IP address
126 */
128
129 /**
130 * @brief Returns the destination IP address
131 * @returns the destination IP address
132 */
134
135 /**
136 * @brief Get the type ID.
137 * @return the object TypeId
138 */
139 static TypeId GetTypeId();
140 TypeId GetInstanceTypeId() const override;
141 void Print(std::ostream& os) const override;
142 uint32_t GetSerializedSize() const override;
143 void Serialize(Buffer::Iterator start) const override;
144 uint32_t Deserialize(Buffer::Iterator start) override;
145
146 HardwareType m_hardwareType; //!< hardware type
147 ArpType_e m_type; //!< type of the ICMP packet
148 Address m_macSource; //!< hardware source address
149 Address m_macDest; //!< hardware destination address
150 Ipv4Address m_ipv4Source; //!< IP source address
151 Ipv4Address m_ipv4Dest; //!< IP destination address
152};
153
154/**
155 * @brief Stream insertion operator.
156 *
157 * @param os The reference to the output stream
158 * @param hardwareType the hardware type
159 * @return The reference to the output stream.
160 */
161std::ostream& operator<<(std::ostream& os, ArpHeader::HardwareType hardwareType);
162
163} // namespace ns3
164
165#endif /* ARP_HEADER_H */
a polymophic address class
Definition address.h:90
The packet header for an ARP packet.
Definition arp-header.h:23
uint32_t Deserialize(Buffer::Iterator start) override
Address m_macSource
hardware source address
Definition arp-header.h:148
HardwareType GetHardwareType() const
Get the hardware type.
Definition arp-header.cc:85
void Print(std::ostream &os) const override
ArpType_e m_type
type of the ICMP packet
Definition arp-header.h:147
void SetReply(Address sourceHardwareAddress, Ipv4Address sourceProtocolAddress, Address destinationHardwareAddress, Ipv4Address destinationProtocolAddress)
Set the ARP reply parameters.
Definition arp-header.cc:39
bool IsReply() const
Check if the ARP is a reply.
Definition arp-header.cc:78
bool IsRequest() const
Check if the ARP is a request.
Definition arp-header.cc:71
Address GetDestinationHardwareAddress() const
Returns the destination hardware address.
Definition arp-header.cc:99
Ipv4Address GetDestinationIpv4Address() const
Returns the destination IP address.
void SetRequest(Address sourceHardwareAddress, Ipv4Address sourceProtocolAddress, Address destinationHardwareAddress, Ipv4Address destinationProtocolAddress)
Set the ARP request parameters.
Definition arp-header.cc:23
Address m_macDest
hardware destination address
Definition arp-header.h:149
HardwareType
Enumeration listing the supported hardware types.
Definition arp-header.h:46
void Serialize(Buffer::Iterator start) const override
Ipv4Address m_ipv4Dest
IP destination address.
Definition arp-header.h:151
Ipv4Address GetSourceIpv4Address() const
Returns the source IP address.
HardwareType DetermineHardwareType(const Address &address) const
Determines the hardware type based on the length of the address.
Definition arp-header.cc:55
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
static TypeId GetTypeId()
Get the type ID.
HardwareType m_hardwareType
hardware type
Definition arp-header.h:146
Ipv4Address m_ipv4Source
IP source address.
Definition arp-header.h:150
uint32_t GetSerializedSize() const override
Address GetSourceHardwareAddress() const
Returns the source hardware address.
Definition arp-header.cc:92
ArpType_e
Enumeration listing the possible ARP types.
Definition arp-header.h:32
iterator in a Buffer instance
Definition buffer.h:89
Protocol header serialization and deserialization.
Definition header.h:33
Ipv4 addresses are stored in host order in this class.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148