A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
rip-header.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Universita' di Firenze, Italy
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7 */
8
9#ifndef RIP_HEADER_H
10#define RIP_HEADER_H
11
12#include "ipv4-header.h"
13
14#include "ns3/header.h"
15#include "ns3/ipv4-address.h"
16#include "ns3/packet.h"
17
18#include <list>
19
20namespace ns3
21{
22
23/**
24 * @ingroup rip
25 * @brief Rip v2 Routing Table Entry (RTE) - see \RFC{2453}.
26 */
27class RipRte : public Header
28{
29 public:
30 RipRte();
31
32 /**
33 * @brief Get the type ID.
34 * @return The object TypeId.
35 */
36 static TypeId GetTypeId();
37
38 /**
39 * @brief Return the instance type identifier.
40 * @return Instance type ID.
41 */
42 TypeId GetInstanceTypeId() const override;
43
44 void Print(std::ostream& os) const override;
45
46 /**
47 * @brief Get the serialized size of the packet.
48 * @return Size.
49 */
50 uint32_t GetSerializedSize() const override;
51
52 /**
53 * @brief Serialize the packet.
54 * @param start Buffer iterator.
55 */
56 void Serialize(Buffer::Iterator start) const override;
57
58 /**
59 * @brief Deserialize the packet.
60 * @param start Buffer iterator.
61 * @return Size of the packet.
62 */
64
65 /**
66 * @brief Set the prefix.
67 * @param prefix The prefix.
68 */
69 void SetPrefix(Ipv4Address prefix);
70
71 /**
72 * @brief Get the prefix.
73 * @returns The prefix.
74 */
75 Ipv4Address GetPrefix() const;
76
77 /**
78 * @brief Set the subnet mask.
79 * @param subnetMask The subnet mask.
80 */
81 void SetSubnetMask(Ipv4Mask subnetMask);
82
83 /**
84 * @brief Get the subnet mask.
85 * @returns The subnet mask.
86 */
87 Ipv4Mask GetSubnetMask() const;
88
89 /**
90 * @brief Set the route tag.
91 * @param routeTag The route tag.
92 */
93 void SetRouteTag(uint16_t routeTag);
94
95 /**
96 * @brief Get the route tag.
97 * @returns The route tag.
98 */
99 uint16_t GetRouteTag() const;
100
101 /**
102 * @brief Set the route metric.
103 * @param routeMetric The route metric.
104 */
105 void SetRouteMetric(uint32_t routeMetric);
106
107 /**
108 * @brief Get the route metric.
109 * @returns The route metric.
110 */
111 uint32_t GetRouteMetric() const;
112
113 /**
114 * @brief Set the next hop.
115 * @param nextHop The next hop.
116 */
117 void SetNextHop(Ipv4Address nextHop);
118
119 /**
120 * @brief Get the next hop.
121 * @returns The next hop.
122 */
123 Ipv4Address GetNextHop() const;
124
125 private:
126 uint16_t m_tag; //!< Route tag.
127 Ipv4Address m_prefix; //!< Advertised prefix.
128 Ipv4Mask m_subnetMask; //!< Subnet mask.
129 Ipv4Address m_nextHop; //!< Next hop.
130 uint32_t m_metric; //!< Route metric.
131};
132
133/**
134 * @brief Stream insertion operator.
135 *
136 * @param os the reference to the output stream
137 * @param h the Routing Table Entry
138 * @returns the reference to the output stream
139 */
140std::ostream& operator<<(std::ostream& os, const RipRte& h);
141
142/**
143 * @ingroup rip
144 * @brief RipHeader - see \RFC{2453}
145 */
146class RipHeader : public Header
147{
148 public:
149 RipHeader();
150
151 /**
152 * @brief Get the type ID.
153 * @return the object TypeId
154 */
155 static TypeId GetTypeId();
156
157 /**
158 * @brief Return the instance type identifier.
159 * @return instance type ID
160 */
161 TypeId GetInstanceTypeId() const override;
162
163 void Print(std::ostream& os) const override;
164
165 /**
166 * @brief Get the serialized size of the packet.
167 * @return size
168 */
169 uint32_t GetSerializedSize() const override;
170
171 /**
172 * @brief Serialize the packet.
173 * @param start Buffer iterator
174 */
175 void Serialize(Buffer::Iterator start) const override;
176
177 /**
178 * @brief Deserialize the packet.
179 * @param start Buffer iterator
180 * @return size of the packet
181 */
182 uint32_t Deserialize(Buffer::Iterator start) override;
183
184 /**
185 * Commands to be used in Rip headers
186 */
188 {
189 REQUEST = 0x1,
190 RESPONSE = 0x2,
191 };
192
193 /**
194 * @brief Set the command
195 * @param command the command
196 */
197 void SetCommand(Command_e command);
198
199 /**
200 * @brief Get the command
201 * @returns the command
202 */
203 Command_e GetCommand() const;
204
205 /**
206 * @brief Add a RTE to the message
207 * @param rte the RTE
208 */
209 void AddRte(RipRte rte);
210
211 /**
212 * @brief Clear all the RTEs from the header
213 */
214 void ClearRtes();
215
216 /**
217 * @brief Get the number of RTE included in the message
218 * @returns the number of RTE in the message
219 */
220 uint16_t GetRteNumber() const;
221
222 /**
223 * @brief Get the list of the RTEs included in the message
224 * @returns the list of the RTEs in the message
225 */
226 std::list<RipRte> GetRteList() const;
227
228 private:
229 uint8_t m_command; //!< command type
230 std::list<RipRte> m_rteList; //!< list of the RTEs in the message
231};
232
233/**
234 * @brief Stream insertion operator.
235 *
236 * @param os the reference to the output stream
237 * @param h the Rip header
238 * @returns the reference to the output stream
239 */
240std::ostream& operator<<(std::ostream& os, const RipHeader& h);
241
242} // namespace ns3
243
244#endif /* Rip_HEADER_H */
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 class to represent an Ipv4 address mask
RipHeader - see RFC 2453
Definition rip-header.h:147
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
void Print(std::ostream &os) const override
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
uint16_t GetRteNumber() const
Get the number of RTE included in the message.
void AddRte(RipRte rte)
Add a RTE to the message.
std::list< RipRte > m_rteList
list of the RTEs in the message
Definition rip-header.h:230
void SetCommand(Command_e command)
Set the command.
Command_e
Commands to be used in Rip headers.
Definition rip-header.h:188
uint8_t m_command
command type
Definition rip-header.h:229
void ClearRtes()
Clear all the RTEs from the header.
static TypeId GetTypeId()
Get the type ID.
std::list< RipRte > GetRteList() const
Get the list of the RTEs included in the message.
Command_e GetCommand() const
Get the command.
Rip v2 Routing Table Entry (RTE) - see RFC 2453 .
Definition rip-header.h:28
Ipv4Mask GetSubnetMask() const
Get the subnet mask.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Definition rip-header.cc:59
void SetSubnetMask(Ipv4Mask subnetMask)
Set the subnet mask.
Ipv4Address m_prefix
Advertised prefix.
Definition rip-header.h:127
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Definition rip-header.cc:53
uint32_t m_metric
Route metric.
Definition rip-header.h:130
Ipv4Mask m_subnetMask
Subnet mask.
Definition rip-header.h:128
void SetRouteMetric(uint32_t routeMetric)
Set the route metric.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
Definition rip-header.cc:71
uint16_t m_tag
Route tag.
Definition rip-header.h:126
void SetPrefix(Ipv4Address prefix)
Set the prefix.
Definition rip-header.cc:92
Ipv4Address GetNextHop() const
Get the next hop.
void Print(std::ostream &os) const override
Definition rip-header.cc:45
uint32_t GetRouteMetric() const
Get the route metric.
static TypeId GetTypeId()
Get the type ID.
Definition rip-header.cc:31
Ipv4Address GetPrefix() const
Get the prefix.
Definition rip-header.cc:98
uint16_t GetRouteTag() const
Get the route tag.
Ipv4Address m_nextHop
Next hop.
Definition rip-header.h:129
void SetRouteTag(uint16_t routeTag)
Set the route tag.
void SetNextHop(Ipv4Address nextHop)
Set the next hop.
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
Definition rip-header.cc:39
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