A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
point-to-point-dumbbell.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 * Author: George F. Riley<riley@ece.gatech.edu>
5 */
6
7// Implement an object to create a dumbbell topology.
8
10
11#include "ns3/constant-position-mobility-model.h"
12#include "ns3/ipv6-address-generator.h"
13#include "ns3/log.h"
14#include "ns3/node-list.h"
15#include "ns3/point-to-point-net-device.h"
16#include "ns3/vector.h"
17
18#include <cmath>
19#include <iostream>
20#include <sstream>
21
22namespace ns3
23{
24
25NS_LOG_COMPONENT_DEFINE("PointToPointDumbbellHelper");
26
28 PointToPointHelper leftHelper,
29 uint32_t nRightLeaf,
30 PointToPointHelper rightHelper,
31 PointToPointHelper bottleneckHelper)
32{
33 // Create the bottleneck routers
35 // Create the leaf nodes
36 m_leftLeaf.Create(nLeftLeaf);
37 m_rightLeaf.Create(nRightLeaf);
38
39 // Add the link connecting routers
40 m_routerDevices = bottleneckHelper.Install(m_routers);
41 // Add the left side links
42 for (uint32_t i = 0; i < nLeftLeaf; ++i)
43 {
47 }
48 // Add the right side links
49 for (uint32_t i = 0; i < nRightLeaf; ++i)
50 {
51 NetDeviceContainer c = rightHelper.Install(m_routers.Get(1), m_rightLeaf.Get(i));
54 }
55}
56
60
63{ // Get the left side bottleneck router
64 return m_routers.Get(0);
65}
66
69{ // Get the i'th left side leaf
70 return m_leftLeaf.Get(i);
71}
72
75{ // Get the right side bottleneck router
76 return m_routers.Get(1);
77}
78
81{ // Get the i'th right side leaf
82 return m_rightLeaf.Get(i);
83}
84
90
96
102
108
111{ // Number of left side nodes
112 return m_leftLeaf.GetN();
113}
114
117{ // Number of right side nodes
118 return m_rightLeaf.GetN();
119}
120
121void
123{
124 stack.Install(m_routers);
125 stack.Install(m_leftLeaf);
126 stack.Install(m_rightLeaf);
127}
128
129void
131 Ipv4AddressHelper rightIp,
132 Ipv4AddressHelper routerIp)
133{
134 // Assign the router network
136 // Assign to left side
137 for (uint32_t i = 0; i < LeftCount(); ++i)
138 {
140 ndc.Add(m_leftLeafDevices.Get(i));
142 Ipv4InterfaceContainer ifc = leftIp.Assign(ndc);
145 leftIp.NewNetwork();
146 }
147 // Assign to right side
148 for (uint32_t i = 0; i < RightCount(); ++i)
149 {
151 ndc.Add(m_rightLeafDevices.Get(i));
153 Ipv4InterfaceContainer ifc = rightIp.Assign(ndc);
156 rightIp.NewNetwork();
157 }
158}
159
160void
162{
163 // Assign the router network
164 Ipv6AddressGenerator::Init(addrBase, prefix);
165 Ipv6Address v6network;
166 Ipv6AddressHelper addressHelper;
167
168 v6network = Ipv6AddressGenerator::GetNetwork(prefix);
169 addressHelper.SetBase(v6network, prefix);
172
173 // Assign to left side
174 for (uint32_t i = 0; i < LeftCount(); ++i)
175 {
176 v6network = Ipv6AddressGenerator::GetNetwork(prefix);
177 addressHelper.SetBase(v6network, prefix);
178
180 ndc.Add(m_leftLeafDevices.Get(i));
182 Ipv6InterfaceContainer ifc = addressHelper.Assign(ndc);
183 auto it = ifc.Begin();
184 m_leftLeafInterfaces6.Add((*it).first, (*it).second);
185 it++;
186 m_leftRouterInterfaces6.Add((*it).first, (*it).second);
188 }
189 // Assign to right side
190 for (uint32_t i = 0; i < RightCount(); ++i)
191 {
192 v6network = Ipv6AddressGenerator::GetNetwork(prefix);
193 addressHelper.SetBase(v6network, prefix);
194
196 ndc.Add(m_rightLeafDevices.Get(i));
198 Ipv6InterfaceContainer ifc = addressHelper.Assign(ndc);
199 auto it = ifc.Begin();
200 m_rightLeafInterfaces6.Add((*it).first, (*it).second);
201 it++;
202 m_rightRouterInterfaces6.Add((*it).first, (*it).second);
204 }
205}
206
207void
209 double uly, // Upper left x/y
210 double lrx,
211 double lry) const // Lower right x/y
212{
213 double xDist;
214 double yDist;
215 if (lrx > ulx)
216 {
217 xDist = lrx - ulx;
218 }
219 else
220 {
221 xDist = ulx - lrx;
222 }
223 if (lry > uly)
224 {
225 yDist = lry - uly;
226 }
227 else
228 {
229 yDist = uly - lry;
230 }
231
232 double xAdder = xDist / 3.0;
233 double thetaL = M_PI / (LeftCount() + 1.0);
234 double thetaR = M_PI / (RightCount() + 1.0);
235
236 // Place the left router
237 Ptr<Node> lr = GetLeft();
239 if (!loc)
240 {
242 lr->AggregateObject(loc);
243 }
244 Vector lrl(ulx + xAdder, uly + yDist / 2.0, 0);
245 loc->SetPosition(lrl);
246
247 // Place the right router
248 Ptr<Node> rr = GetRight();
249 loc = rr->GetObject<ConstantPositionMobilityModel>();
250 if (!loc)
251 {
253 rr->AggregateObject(loc);
254 }
255 Vector rrl(ulx + xAdder * 2, uly + yDist / 2.0, 0); // Right router location
256 loc->SetPosition(rrl);
257
258 // Place the left leaf nodes
259 double theta = -M_PI_2 + thetaL;
260 for (uint32_t l = 0; l < LeftCount(); ++l)
261 {
262 // Make them in a circular pattern to make all line lengths the same
263 // Special case when theta = 0, to be sure we get a straight line
264 if ((LeftCount() % 2) == 1)
265 { // Count is odd, see if we are in middle
266 if (l == (LeftCount() / 2))
267 {
268 theta = 0.0;
269 }
270 }
271 Ptr<Node> ln = GetLeft(l);
272 loc = ln->GetObject<ConstantPositionMobilityModel>();
273 if (!loc)
274 {
276 ln->AggregateObject(loc);
277 }
278 Vector lnl(lrl.x - std::cos(theta) * xAdder,
279 lrl.y + std::sin(theta) * xAdder,
280 0); // Left Node Location
281 // Insure did not exceed bounding box
282 if (lnl.y < uly)
283 {
284 lnl.y = uly; // Set to upper left y
285 }
286 if (lnl.y > lry)
287 {
288 lnl.y = lry; // Set to lower right y
289 }
290 loc->SetPosition(lnl);
291 theta += thetaL;
292 }
293 // Place the right nodes
294 theta = -M_PI_2 + thetaR;
295 for (uint32_t r = 0; r < RightCount(); ++r)
296 {
297 // Special case when theta = 0, to be sure we get a straight line
298 if ((RightCount() % 2) == 1)
299 { // Count is odd, see if we are in middle
300 if (r == (RightCount() / 2))
301 {
302 theta = 0.0;
303 }
304 }
305 Ptr<Node> rn = GetRight(r);
306 loc = rn->GetObject<ConstantPositionMobilityModel>();
307 if (!loc)
308 {
310 rn->AggregateObject(loc);
311 }
312 Vector rnl(rrl.x + std::cos(theta) * xAdder, // Right node location
313 rrl.y + std::sin(theta) * xAdder,
314 0);
315 // Insure did not exceed bounding box
316 if (rnl.y < uly)
317 {
318 rnl.y = uly; // Set to upper left y
319 }
320 if (rnl.y > lry)
321 {
322 rnl.y = lry; // Set to lower right y
323 }
324 loc->SetPosition(rnl);
325 theta += thetaR;
326 }
327}
328
329} // 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.
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.
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.
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.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Every class exported by the ns3 library is enclosed in the ns3 namespace.