A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
ipv4-interface-container.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008 INRIA
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Mathieu Lacage <mathieu.lacage@cutebugs.net>
7
*/
8
9
#ifndef IPV4_INTERFACE_CONTAINER_H
10
#define IPV4_INTERFACE_CONTAINER_H
11
12
#include "ns3/ipv4-address.h"
13
#include "ns3/ipv4.h"
14
15
#include <stdint.h>
16
#include <vector>
17
18
namespace
ns3
19
{
20
21
/**
22
* @ingroup ipv4
23
*
24
* @brief holds a vector of std::pair of Ptr<Ipv4> and interface index.
25
*
26
* Typically ns-3 Ipv4Interfaces are installed on devices using an Ipv4 address
27
* helper. The helper's Assign() method takes a NetDeviceContainer which holds
28
* some number of Ptr<NetDevice>. For each of the NetDevices in the
29
* NetDeviceContainer the helper will find the associated Ptr<Node> and
30
* Ptr<Ipv4>. It makes sure that an interface exists on the node for the
31
* device and then adds an Ipv4Address according to the address helper settings
32
* (incrementing the Ipv4Address somehow as it goes). The helper then converts
33
* the Ptr<Ipv4> and the interface index to a std::pair and adds them to a
34
* container -- a container of this type.
35
*
36
* The point is then to be able to implicitly associate an index into the
37
* original NetDeviceContainer (that identifies a particular net device) with
38
* an identical index into the Ipv4InterfaceContainer that has a std::pair with
39
* the Ptr<Ipv4> and interface index you need to play with the interface.
40
*
41
* @see Ipv4AddressHelper
42
* @see Ipv4
43
*/
44
class
Ipv4InterfaceContainer
45
{
46
public
:
47
/**
48
* @brief Container Const Iterator for pairs of Ipv4 smart pointer / Interface Index.
49
*/
50
typedef
std::vector<std::pair<Ptr<Ipv4>,
uint32_t
>>::const_iterator
Iterator
;
51
52
/**
53
* Create an empty Ipv4InterfaceContainer.
54
*/
55
Ipv4InterfaceContainer
();
56
57
/**
58
* Concatenate the entries in the other container with ours.
59
* @param other container
60
*/
61
void
Add
(
const
Ipv4InterfaceContainer
& other);
62
63
/**
64
* @brief Get an iterator which refers to the first pair in the
65
* container.
66
*
67
* Pairs can be retrieved from the container in two ways. First,
68
* directly by an index into the container, and second, using an iterator.
69
* This method is used in the iterator method and is typically used in a
70
* for-loop to run through the pairs
71
*
72
* @code
73
* for (auto i = container.Begin(); i != container.End(); ++i)
74
* {
75
* std::pair<Ptr<Ipv4>, uint32_t> pair = *i;
76
* method(pair.first, pair.second); // use the pair
77
* }
78
* @endcode
79
*
80
* @returns an iterator which refers to the first pair in the container.
81
*/
82
Iterator
Begin
()
const
;
83
84
/**
85
* @brief Get an iterator which indicates past-the-last Node in the
86
* container.
87
*
88
* Nodes can be retrieved from the container in two ways. First,
89
* directly by an index into the container, and second, using an iterator.
90
* This method is used in the iterator method and is typically used in a
91
* for-loop to run through the Nodes
92
*
93
* @code
94
* for (auto i = container.Begin(); i != container.End(); ++i)
95
* {
96
* std::pair<Ptr<Ipv4>, uint32_t> pair = *i;
97
* method(pair.first, pair.second); // use the pair
98
* }
99
* @endcode
100
*
101
* @returns an iterator which indicates an ending condition for a loop.
102
*/
103
Iterator
End
()
const
;
104
105
/**
106
* @returns the number of Ptr<Ipv4> and interface pairs stored in this
107
* Ipv4InterfaceContainer.
108
*
109
* Pairs can be retrieved from the container in two ways. First,
110
* directly by an index into the container, and second, using an iterator.
111
* This method is used in the direct method and is typically used to
112
* define an ending condition in a for-loop that runs through the stored
113
* Nodes
114
*
115
* @code
116
* uint32_t nNodes = container.GetN ();
117
* for (uint32_t i = 0 i < nNodes; ++i)
118
* {
119
* std::pair<Ptr<Ipv4>, uint32_t> pair = container.Get (i);
120
* method (pair.first, pair.second); // use the pair
121
* }
122
* @endcode
123
*
124
* @returns the number of Ptr<Node> stored in this container.
125
*/
126
uint32_t
GetN
()
const
;
127
128
/**
129
* @param i index of ipInterfacePair in container
130
* @param j interface address index (if interface has multiple addresses)
131
* @returns the IPv4 address of the j'th address of the interface
132
* corresponding to index i.
133
*
134
* If the second parameter is omitted, the zeroth indexed address of
135
* the interface is returned. Unless IP aliasing is being used on
136
* the interface, the second parameter may typically be omitted.
137
*/
138
Ipv4Address
GetAddress
(
uint32_t
i,
uint32_t
j = 0)
const
;
139
140
/**
141
* @brief Set a metric for the given interface
142
* @param i Interface index
143
* @param metric the interface metric
144
*/
145
void
SetMetric
(
uint32_t
i, uint16_t metric);
146
147
/**
148
* Manually add an entry to the container consisting of the individual parts
149
* of an entry std::pair.
150
*
151
* @param ipv4 pointer to Ipv4 object
152
* @param interface interface index of the Ipv4Interface to add to the container
153
*/
154
void
Add
(
Ptr<Ipv4>
ipv4,
uint32_t
interface);
155
156
/**
157
* Manually add an entry to the container consisting of a previously composed
158
* entry std::pair.
159
*
160
* @param ipInterfacePair the pair of a pointer to Ipv4 object and interface index of the
161
* Ipv4Interface to add to the container
162
*/
163
void
Add
(std::pair<
Ptr<Ipv4>
,
uint32_t
> ipInterfacePair);
164
165
/**
166
* Manually add an entry to the container consisting of the individual parts
167
* of an entry std::pair.
168
*
169
* @param ipv4Name std:string referring to the saved name of an Ipv4 Object that
170
* has been previously named using the Object Name Service.
171
* @param interface interface index of the Ipv4Interface to add to the container
172
*/
173
void
Add
(std::string ipv4Name,
uint32_t
interface);
174
175
/**
176
* Get the std::pair of an Ptr<Ipv4> and interface stored at the location
177
* specified by the index.
178
*
179
* @param i the index of the container entry to retrieve.
180
* @return the std::pair of a Ptr<Ipv4> and an interface index
181
*
182
* @note The returned Ptr<Ipv4> cannot be used directly to fetch the
183
* Ipv4Interface using the returned index (the GetInterface () method
184
* is provided in class Ipv4L3Protocol, and not class Ipv4). An
185
* example usage is provided below.
186
*
187
* @code
188
* Ipv4InterfaceContainer c;
189
* ...
190
* std::pair<Ptr<Ipv4>, uint32_t> returnValue = c.Get (0);
191
* Ptr<Ipv4> ipv4 = returnValue.first;
192
* uint32_t index = returnValue.second;
193
* Ptr<Ipv4Interface> iface = DynamicCast<Ipv4L3Protocol> (ipv4)->GetInterface (index);
194
* @endcode
195
*/
196
std::pair<Ptr<Ipv4>,
uint32_t
>
Get
(
uint32_t
i)
const
;
197
198
private
:
199
/**
200
* @brief Container for pairs of Ipv4 smart pointer / Interface Index.
201
*/
202
typedef
std::vector<std::pair<Ptr<Ipv4>,
uint32_t
>>
InterfaceVector
;
203
204
/**
205
* @brief List of IPv4 stack and interfaces index.
206
*/
207
InterfaceVector
m_interfaces
;
208
};
209
210
}
// namespace ns3
211
212
#endif
/* IPV4_INTERFACE_CONTAINER_H */
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:32
ns3::Ipv4InterfaceContainer::Iterator
std::vector< std::pair< Ptr< Ipv4 >, uint32_t > >::const_iterator Iterator
Container Const Iterator for pairs of Ipv4 smart pointer / Interface Index.
Definition
ipv4-interface-container.h:50
ns3::Ipv4InterfaceContainer::InterfaceVector
std::vector< std::pair< Ptr< Ipv4 >, uint32_t > > InterfaceVector
Container for pairs of Ipv4 smart pointer / Interface Index.
Definition
ipv4-interface-container.h:202
ns3::Ipv4InterfaceContainer::End
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Definition
ipv4-interface-container.cc:37
ns3::Ipv4InterfaceContainer::Get
std::pair< Ptr< Ipv4 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr<Ipv4> and interface stored at the location specified by the index.
Definition
ipv4-interface-container.cc:84
ns3::Ipv4InterfaceContainer::SetMetric
void SetMetric(uint32_t i, uint16_t metric)
Set a metric for the given interface.
Definition
ipv4-interface-container.cc:57
ns3::Ipv4InterfaceContainer::m_interfaces
InterfaceVector m_interfaces
List of IPv4 stack and interfaces index.
Definition
ipv4-interface-container.h:207
ns3::Ipv4InterfaceContainer::Add
void Add(const Ipv4InterfaceContainer &other)
Concatenate the entries in the other container with ours.
Definition
ipv4-interface-container.cc:22
ns3::Ipv4InterfaceContainer::GetAddress
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Definition
ipv4-interface-container.cc:49
ns3::Ipv4InterfaceContainer::Begin
Iterator Begin() const
Get an iterator which refers to the first pair in the container.
Definition
ipv4-interface-container.cc:31
ns3::Ipv4InterfaceContainer::Ipv4InterfaceContainer
Ipv4InterfaceContainer()
Create an empty Ipv4InterfaceContainer.
Definition
ipv4-interface-container.cc:17
ns3::Ipv4InterfaceContainer::GetN
uint32_t GetN() const
Definition
ipv4-interface-container.cc:43
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:70
uint32_t
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
internet
helper
ipv4-interface-container.h
Generated on
for ns-3 by
1.15.0