A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
point-to-point-dumbbell.cc
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation;
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 *
15 * Author: George F. Riley<riley@ece.gatech.edu>
16 */
17
18// Implement an object to create a dumbbell topology.
19
21
22#include "ns3/constant-position-mobility-model.h"
23#include "ns3/ipv6-address-generator.h"
24#include "ns3/log.h"
25#include "ns3/node-list.h"
26#include "ns3/point-to-point-net-device.h"
27#include "ns3/vector.h"
28
29#include <cmath>
30#include <iostream>
31#include <sstream>
32
33namespace ns3
34{
35
36NS_LOG_COMPONENT_DEFINE("PointToPointDumbbellHelper");
37
39 PointToPointHelper leftHelper,
40 uint32_t nRightLeaf,
41 PointToPointHelper rightHelper,
42 PointToPointHelper bottleneckHelper)
43{
44 // Create the bottleneck routers
46 // Create the leaf nodes
47 m_leftLeaf.Create(nLeftLeaf);
48 m_rightLeaf.Create(nRightLeaf);
49
50 // Add the link connecting routers
51 m_routerDevices = bottleneckHelper.Install(m_routers);
52 // Add the left side links
53 for (uint32_t i = 0; i < nLeftLeaf; ++i)
54 {
58 }
59 // Add the right side links
60 for (uint32_t i = 0; i < nRightLeaf; ++i)
61 {
62 NetDeviceContainer c = rightHelper.Install(m_routers.Get(1), m_rightLeaf.Get(i));
65 }
66}
67
69{
70}
71
74{ // Get the left side bottleneck router
75 return m_routers.Get(0);
76}
77
80{ // Get the i'th left side leaf
81 return m_leftLeaf.Get(i);
82}
83
86{ // Get the right side bottleneck router
87 return m_routers.Get(1);
88}
89
92{ // Get the i'th right side leaf
93 return m_rightLeaf.Get(i);
94}
95
98{
100}
101
104{
106}
107
110{
112}
113
116{
118}
119
122{ // Number of left side nodes
123 return m_leftLeaf.GetN();
124}
125
128{ // Number of right side nodes
129 return m_rightLeaf.GetN();
130}
131
132void
134{
135 stack.Install(m_routers);
136 stack.Install(m_leftLeaf);
137 stack.Install(m_rightLeaf);
138}
139
140void
142 Ipv4AddressHelper rightIp,
143 Ipv4AddressHelper routerIp)
144{
145 // Assign the router network
147 // Assign to left side
148 for (uint32_t i = 0; i < LeftCount(); ++i)
149 {
151 ndc.Add(m_leftLeafDevices.Get(i));
153 Ipv4InterfaceContainer ifc = leftIp.Assign(ndc);
156 leftIp.NewNetwork();
157 }
158 // Assign to right side
159 for (uint32_t i = 0; i < RightCount(); ++i)
160 {
162 ndc.Add(m_rightLeafDevices.Get(i));
164 Ipv4InterfaceContainer ifc = rightIp.Assign(ndc);
167 rightIp.NewNetwork();
168 }
169}
170
171void
173{
174 // Assign the router network
175 Ipv6AddressGenerator::Init(addrBase, prefix);
176 Ipv6Address v6network;
177 Ipv6AddressHelper addressHelper;
178
179 v6network = Ipv6AddressGenerator::GetNetwork(prefix);
180 addressHelper.SetBase(v6network, prefix);
183
184 // Assign to left side
185 for (uint32_t i = 0; i < LeftCount(); ++i)
186 {
187 v6network = Ipv6AddressGenerator::GetNetwork(prefix);
188 addressHelper.SetBase(v6network, prefix);
189
191 ndc.Add(m_leftLeafDevices.Get(i));
193 Ipv6InterfaceContainer ifc = addressHelper.Assign(ndc);
194 auto it = ifc.Begin();
195 m_leftLeafInterfaces6.Add((*it).first, (*it).second);
196 it++;
197 m_leftRouterInterfaces6.Add((*it).first, (*it).second);
199 }
200 // Assign to right side
201 for (uint32_t i = 0; i < RightCount(); ++i)
202 {
203 v6network = Ipv6AddressGenerator::GetNetwork(prefix);
204 addressHelper.SetBase(v6network, prefix);
205
207 ndc.Add(m_rightLeafDevices.Get(i));
209 Ipv6InterfaceContainer ifc = addressHelper.Assign(ndc);
210 auto it = ifc.Begin();
211 m_rightLeafInterfaces6.Add((*it).first, (*it).second);
212 it++;
213 m_rightRouterInterfaces6.Add((*it).first, (*it).second);
215 }
216}
217
218void
220 double uly, // Upper left x/y
221 double lrx,
222 double lry) const // Lower right x/y
223{
224 double xDist;
225 double yDist;
226 if (lrx > ulx)
227 {
228 xDist = lrx - ulx;
229 }
230 else
231 {
232 xDist = ulx - lrx;
233 }
234 if (lry > uly)
235 {
236 yDist = lry - uly;
237 }
238 else
239 {
240 yDist = uly - lry;
241 }
242
243 double xAdder = xDist / 3.0;
244 double thetaL = M_PI / (LeftCount() + 1.0);
245 double thetaR = M_PI / (RightCount() + 1.0);
246
247 // Place the left router
248 Ptr<Node> lr = GetLeft();
250 if (!loc)
251 {
252 loc = CreateObject<ConstantPositionMobilityModel>();
253 lr->AggregateObject(loc);
254 }
255 Vector lrl(ulx + xAdder, uly + yDist / 2.0, 0);
256 loc->SetPosition(lrl);
257
258 // Place the right router
259 Ptr<Node> rr = GetRight();
260 loc = rr->GetObject<ConstantPositionMobilityModel>();
261 if (!loc)
262 {
263 loc = CreateObject<ConstantPositionMobilityModel>();
264 rr->AggregateObject(loc);
265 }
266 Vector rrl(ulx + xAdder * 2, uly + yDist / 2.0, 0); // Right router location
267 loc->SetPosition(rrl);
268
269 // Place the left leaf nodes
270 double theta = -M_PI_2 + thetaL;
271 for (uint32_t l = 0; l < LeftCount(); ++l)
272 {
273 // Make them in a circular pattern to make all line lengths the same
274 // Special case when theta = 0, to be sure we get a straight line
275 if ((LeftCount() % 2) == 1)
276 { // Count is odd, see if we are in middle
277 if (l == (LeftCount() / 2))
278 {
279 theta = 0.0;
280 }
281 }
282 Ptr<Node> ln = GetLeft(l);
283 loc = ln->GetObject<ConstantPositionMobilityModel>();
284 if (!loc)
285 {
286 loc = CreateObject<ConstantPositionMobilityModel>();
287 ln->AggregateObject(loc);
288 }
289 Vector lnl(lrl.x - std::cos(theta) * xAdder,
290 lrl.y + std::sin(theta) * xAdder,
291 0); // Left Node Location
292 // Insure did not exceed bounding box
293 if (lnl.y < uly)
294 {
295 lnl.y = uly; // Set to upper left y
296 }
297 if (lnl.y > lry)
298 {
299 lnl.y = lry; // Set to lower right y
300 }
301 loc->SetPosition(lnl);
302 theta += thetaL;
303 }
304 // Place the right nodes
305 theta = -M_PI_2 + thetaR;
306 for (uint32_t r = 0; r < RightCount(); ++r)
307 {
308 // Special case when theta = 0, to be sure we get a straight line
309 if ((RightCount() % 2) == 1)
310 { // Count is odd, see if we are in middle
311 if (r == (RightCount() / 2))
312 {
313 theta = 0.0;
314 }
315 }
316 Ptr<Node> rn = GetRight(r);
317 loc = rn->GetObject<ConstantPositionMobilityModel>();
318 if (!loc)
319 {
320 loc = CreateObject<ConstantPositionMobilityModel>();
321 rn->AggregateObject(loc);
322 }
323 Vector rnl(rrl.x + std::cos(theta) * xAdder, // Right node location
324 rrl.y + std::sin(theta) * xAdder,
325 0);
326 // Insure did not exceed bounding box
327 if (rnl.y < uly)
328 {
329 rnl.y = uly; // Set to upper left y
330 }
331 if (rnl.y > lry)
332 {
333 rnl.y = lry; // Set to lower right y
334 }
335 loc->SetPosition(rnl);
336 theta += thetaR;
337 }
338}
339
340} // namespace ns3
Mobility model for which the current position does not change once it has been set and until it is se...
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4Address NewNetwork()
Increment the network number and reset the IP address counter to the base value provided in the SetBa...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
holds a vector of std::pair of Ptr<Ipv4> and interface index.
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.
void Add(const Ipv4InterfaceContainer &other)
Concatenate the entries in the other container with ours.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
static void Init(const Ipv6Address net, const Ipv6Prefix prefix, const Ipv6Address interfaceId="::1")
Initialise the base network and interfaceId for the generator.
static Ipv6Address GetNetwork(const Ipv6Prefix prefix)
Get the current network of the given Ipv6Prefix.
static Ipv6Address NextNetwork(const Ipv6Prefix prefix)
Get the next network according to the given Ipv6Prefix.
Helper class to auto-assign global IPv6 unicast addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Describes an IPv6 address.
Definition: ipv6-address.h:49
Keep track of a set of IPv6 interfaces.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
void Add(Ptr< Ipv6 > ipv6, uint32_t interface)
Add a couple IPv6/interface.
Iterator Begin() const
Get an iterator which refers to the first pair in the container.
Describes an IPv6 prefix.
Definition: ipv6-address.h:455
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
uint32_t GetN() const
Get the number of Ptr<Node> stored in this container.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ipv6InterfaceContainer m_leftLeafInterfaces6
Left Leaf interfaces (IPv6)
Ipv6InterfaceContainer m_rightLeafInterfaces6
Right Leaf interfaces (IPv6)
Ipv4InterfaceContainer m_rightRouterInterfaces
Right router interfaces (IPv4)
PointToPointDumbbellHelper(uint32_t nLeftLeaf, PointToPointHelper leftHelper, uint32_t nRightLeaf, PointToPointHelper rightHelper, PointToPointHelper bottleneckHelper)
Create a PointToPointDumbbellHelper in order to easily create dumbbell topologies using p2p links.
NetDeviceContainer m_leftRouterDevices
Left router NetDevices.
Ipv6InterfaceContainer m_rightRouterInterfaces6
Right router interfaces (IPv6)
Ipv4InterfaceContainer m_routerInterfaces
Router interfaces (IPv4)
void AssignIpv4Addresses(Ipv4AddressHelper leftIp, Ipv4AddressHelper rightIp, Ipv4AddressHelper routerIp)
NetDeviceContainer m_routerDevices
Routers NetDevices.
NetDeviceContainer m_rightRouterDevices
Right router NetDevices.
NodeContainer m_rightLeaf
Right Leaf nodes.
Ipv4InterfaceContainer m_leftRouterInterfaces
Left router interfaces (IPv4)
Ipv4Address GetRightIpv4Address(uint32_t i) const
Ipv6Address GetLeftIpv6Address(uint32_t i) const
Ipv4Address GetLeftIpv4Address(uint32_t i) const
void InstallStack(InternetStackHelper stack)
Ipv6InterfaceContainer m_leftRouterInterfaces6
Left router interfaces (IPv6)
NetDeviceContainer m_leftLeafDevices
Left Leaf NetDevices.
Ipv6Address GetRightIpv6Address(uint32_t i) const
Ipv6InterfaceContainer m_routerInterfaces6
Router interfaces (IPv6)
Ipv4InterfaceContainer m_rightLeafInterfaces
Right Leaf interfaces (IPv4)
void AssignIpv6Addresses(Ipv6Address network, Ipv6Prefix prefix)
NodeContainer m_leftLeaf
Left Leaf nodes.
NetDeviceContainer m_rightLeafDevices
Right Leaf NetDevices.
void BoundingBox(double ulx, double uly, double lrx, double lry) const
Sets up the node canvas locations for every node in the dumbbell.
Ipv4InterfaceContainer m_leftLeafInterfaces
Left Leaf interfaces (IPv4)
Build a set of PointToPointNetDevice objects.
NetDeviceContainer Install(NodeContainer c)
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Every class exported by the ns3 library is enclosed in the ns3 namespace.