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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18 */
19
20#ifndef RIP_HEADER_H
21#define RIP_HEADER_H
22
23#include "ipv4-header.h"
24
25#include "ns3/header.h"
26#include "ns3/ipv4-address.h"
27#include "ns3/packet.h"
28
29#include <list>
30
31namespace ns3
32{
33
34/**
35 * \ingroup rip
36 * \brief Rip v2 Routing Table Entry (RTE) - see \RFC{2453}.
37 */
38class RipRte : public Header
39{
40 public:
41 RipRte();
42
43 /**
44 * \brief Get the type ID.
45 * \return The object TypeId.
46 */
47 static TypeId GetTypeId();
48
49 /**
50 * \brief Return the instance type identifier.
51 * \return Instance type ID.
52 */
53 TypeId GetInstanceTypeId() const override;
54
55 void Print(std::ostream& os) const override;
56
57 /**
58 * \brief Get the serialized size of the packet.
59 * \return Size.
60 */
61 uint32_t GetSerializedSize() const override;
62
63 /**
64 * \brief Serialize the packet.
65 * \param start Buffer iterator.
66 */
67 void Serialize(Buffer::Iterator start) const override;
68
69 /**
70 * \brief Deserialize the packet.
71 * \param start Buffer iterator.
72 * \return Size of the packet.
73 */
75
76 /**
77 * \brief Set the prefix.
78 * \param prefix The prefix.
79 */
80 void SetPrefix(Ipv4Address prefix);
81
82 /**
83 * \brief Get the prefix.
84 * \returns The prefix.
85 */
86 Ipv4Address GetPrefix() const;
87
88 /**
89 * \brief Set the subnet mask.
90 * \param subnetMask The subnet mask.
91 */
92 void SetSubnetMask(Ipv4Mask subnetMask);
93
94 /**
95 * \brief Get the subnet mask.
96 * \returns The subnet mask.
97 */
98 Ipv4Mask GetSubnetMask() const;
99
100 /**
101 * \brief Set the route tag.
102 * \param routeTag The route tag.
103 */
104 void SetRouteTag(uint16_t routeTag);
105
106 /**
107 * \brief Get the route tag.
108 * \returns The route tag.
109 */
110 uint16_t GetRouteTag() const;
111
112 /**
113 * \brief Set the route metric.
114 * \param routeMetric The route metric.
115 */
116 void SetRouteMetric(uint32_t routeMetric);
117
118 /**
119 * \brief Get the route metric.
120 * \returns The route metric.
121 */
122 uint32_t GetRouteMetric() const;
123
124 /**
125 * \brief Set the next hop.
126 * \param nextHop The next hop.
127 */
128 void SetNextHop(Ipv4Address nextHop);
129
130 /**
131 * \brief Get the next hop.
132 * \returns The next hop.
133 */
134 Ipv4Address GetNextHop() const;
135
136 private:
137 uint16_t m_tag; //!< Route tag.
138 Ipv4Address m_prefix; //!< Advertised prefix.
139 Ipv4Mask m_subnetMask; //!< Subnet mask.
140 Ipv4Address m_nextHop; //!< Next hop.
141 uint32_t m_metric; //!< Route metric.
142};
143
144/**
145 * \brief Stream insertion operator.
146 *
147 * \param os the reference to the output stream
148 * \param h the Routing Table Entry
149 * \returns the reference to the output stream
150 */
151std::ostream& operator<<(std::ostream& os, const RipRte& h);
152
153/**
154 * \ingroup rip
155 * \brief RipHeader - see \RFC{2453}
156 */
157class RipHeader : public Header
158{
159 public:
160 RipHeader();
161
162 /**
163 * \brief Get the type ID.
164 * \return the object TypeId
165 */
166 static TypeId GetTypeId();
167
168 /**
169 * \brief Return the instance type identifier.
170 * \return instance type ID
171 */
172 TypeId GetInstanceTypeId() const override;
173
174 void Print(std::ostream& os) const override;
175
176 /**
177 * \brief Get the serialized size of the packet.
178 * \return size
179 */
180 uint32_t GetSerializedSize() const override;
181
182 /**
183 * \brief Serialize the packet.
184 * \param start Buffer iterator
185 */
186 void Serialize(Buffer::Iterator start) const override;
187
188 /**
189 * \brief Deserialize the packet.
190 * \param start Buffer iterator
191 * \return size of the packet
192 */
193 uint32_t Deserialize(Buffer::Iterator start) override;
194
195 /**
196 * Commands to be used in Rip headers
197 */
199 {
200 REQUEST = 0x1,
201 RESPONSE = 0x2,
202 };
203
204 /**
205 * \brief Set the command
206 * \param command the command
207 */
208 void SetCommand(Command_e command);
209
210 /**
211 * \brief Get the command
212 * \returns the command
213 */
214 Command_e GetCommand() const;
215
216 /**
217 * \brief Add a RTE to the message
218 * \param rte the RTE
219 */
220 void AddRte(RipRte rte);
221
222 /**
223 * \brief Clear all the RTEs from the header
224 */
225 void ClearRtes();
226
227 /**
228 * \brief Get the number of RTE included in the message
229 * \returns the number of RTE in the message
230 */
231 uint16_t GetRteNumber() const;
232
233 /**
234 * \brief Get the list of the RTEs included in the message
235 * \returns the list of the RTEs in the message
236 */
237 std::list<RipRte> GetRteList() const;
238
239 private:
240 uint8_t m_command; //!< command type
241 std::list<RipRte> m_rteList; //!< list of the RTEs in the message
242};
243
244/**
245 * \brief Stream insertion operator.
246 *
247 * \param os the reference to the output stream
248 * \param h the Rip header
249 * \returns the reference to the output stream
250 */
251std::ostream& operator<<(std::ostream& os, const RipHeader& h);
252
253} // namespace ns3
254
255#endif /* Rip_HEADER_H */
iterator in a Buffer instance
Definition: buffer.h:100
Protocol header serialization and deserialization.
Definition: header.h:44
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
RipHeader - see RFC 2453
Definition: rip-header.h:158
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Definition: rip-header.cc:215
void Print(std::ostream &os) const override
Definition: rip-header.cc:197
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
Definition: rip-header.cc:191
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
Definition: rip-header.cc:231
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Definition: rip-header.cc:208
uint16_t GetRteNumber() const
Get the number of RTE included in the message.
Definition: rip-header.cc:294
void AddRte(RipRte rte)
Add a RTE to the message.
Definition: rip-header.cc:282
std::list< RipRte > m_rteList
list of the RTEs in the message
Definition: rip-header.h:241
void SetCommand(Command_e command)
Set the command.
Definition: rip-header.cc:270
Command_e
Commands to be used in Rip headers.
Definition: rip-header.h:199
uint8_t m_command
command type
Definition: rip-header.h:240
void ClearRtes()
Clear all the RTEs from the header.
Definition: rip-header.cc:288
static TypeId GetTypeId()
Get the type ID.
Definition: rip-header.cc:181
std::list< RipRte > GetRteList() const
Get the list of the RTEs included in the message.
Definition: rip-header.cc:300
Command_e GetCommand() const
Get the command.
Definition: rip-header.cc:276
Rip v2 Routing Table Entry (RTE) - see RFC 2453.
Definition: rip-header.h:39
Ipv4Mask GetSubnetMask() const
Get the subnet mask.
Definition: rip-header.cc:121
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Definition: rip-header.cc:70
void SetSubnetMask(Ipv4Mask subnetMask)
Set the subnet mask.
Definition: rip-header.cc:115
Ipv4Address m_prefix
Advertised prefix.
Definition: rip-header.h:138
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Definition: rip-header.cc:64
uint32_t m_metric
Route metric.
Definition: rip-header.h:141
Ipv4Mask m_subnetMask
Subnet mask.
Definition: rip-header.h:139
void SetRouteMetric(uint32_t routeMetric)
Set the route metric.
Definition: rip-header.cc:139
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
Definition: rip-header.cc:82
uint16_t m_tag
Route tag.
Definition: rip-header.h:137
void SetPrefix(Ipv4Address prefix)
Set the prefix.
Definition: rip-header.cc:103
Ipv4Address GetNextHop() const
Get the next hop.
Definition: rip-header.cc:157
void Print(std::ostream &os) const override
Definition: rip-header.cc:56
uint32_t GetRouteMetric() const
Get the route metric.
Definition: rip-header.cc:145
static TypeId GetTypeId()
Get the type ID.
Definition: rip-header.cc:42
Ipv4Address GetPrefix() const
Get the prefix.
Definition: rip-header.cc:109
uint16_t GetRouteTag() const
Get the route tag.
Definition: rip-header.cc:133
Ipv4Address m_nextHop
Next hop.
Definition: rip-header.h:140
void SetRouteTag(uint16_t routeTag)
Set the route tag.
Definition: rip-header.cc:127
void SetNextHop(Ipv4Address nextHop)
Set the next hop.
Definition: rip-header.cc:151
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
Definition: rip-header.cc:50
a unique identifier for an interface.
Definition: type-id.h:59
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:159