A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
point-to-point-star.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 */
4
5// Implement an object to create a star topology.
6
8
9#include "ns3/constant-position-mobility-model.h"
10#include "ns3/ipv6-address-generator.h"
11#include "ns3/log.h"
12#include "ns3/node-list.h"
13#include "ns3/point-to-point-net-device.h"
14#include "ns3/vector.h"
15
16#include <cmath>
17#include <iostream>
18#include <sstream>
19
20namespace ns3
21{
22
23NS_LOG_COMPONENT_DEFINE("PointToPointStarHelper");
24
26{
27 m_hub.Create(1);
28 m_spokes.Create(numSpokes);
29
30 for (uint32_t i = 0; i < m_spokes.GetN(); ++i)
31 {
32 NetDeviceContainer nd = p2pHelper.Install(m_hub.Get(0), m_spokes.Get(i));
33 m_hubDevices.Add(nd.Get(0));
34 m_spokeDevices.Add(nd.Get(1));
35 }
36}
37
41
44{
45 return m_hub.Get(0);
46}
47
53
59
65
71
77
83
84void
86{
87 stack.Install(m_hub);
88 stack.Install(m_spokes);
89}
90
91void
93{
94 for (uint32_t i = 0; i < m_spokes.GetN(); ++i)
95 {
96 m_hubInterfaces.Add(address.Assign(m_hubDevices.Get(i)));
97 m_spokeInterfaces.Add(address.Assign(m_spokeDevices.Get(i)));
98 address.NewNetwork();
99 }
100}
101
102void
104{
105 Ipv6AddressGenerator::Init(addrBase, prefix);
106 Ipv6Address v6network;
107 Ipv6AddressHelper addressHelper;
108
109 for (uint32_t i = 0; i < m_spokes.GetN(); ++i)
110 {
111 v6network = Ipv6AddressGenerator::GetNetwork(prefix);
112 addressHelper.SetBase(v6network, prefix);
113
114 Ipv6InterfaceContainer ic = addressHelper.Assign(m_hubDevices.Get(i));
116 ic = addressHelper.Assign(m_spokeDevices.Get(i));
118
120 }
121}
122
123void
124PointToPointStarHelper::BoundingBox(double ulx, double uly, double lrx, double lry)
125{
126 double xDist;
127 double yDist;
128 if (lrx > ulx)
129 {
130 xDist = lrx - ulx;
131 }
132 else
133 {
134 xDist = ulx - lrx;
135 }
136 if (lry > uly)
137 {
138 yDist = lry - uly;
139 }
140 else
141 {
142 yDist = uly - lry;
143 }
144
145 // Place the hub
146 Ptr<Node> hub = m_hub.Get(0);
148 if (!hubLoc)
149 {
151 hub->AggregateObject(hubLoc);
152 }
153 Vector hubVec(ulx + xDist / 2.0, uly + yDist / 2.0, 0);
154 hubLoc->SetPosition(hubVec);
155
156 double spokeDist;
157 if (xDist > yDist)
158 {
159 spokeDist = yDist / 4.0;
160 }
161 else
162 {
163 spokeDist = xDist / 4.0;
164 }
165
166 double theta = 2 * M_PI / m_spokes.GetN();
167 for (uint32_t i = 0; i < m_spokes.GetN(); ++i)
168 {
169 Ptr<Node> spokeNode = m_spokes.Get(i);
171 spokeNode->GetObject<ConstantPositionMobilityModel>();
172 if (!spokeLoc)
173 {
175 spokeNode->AggregateObject(spokeLoc);
176 }
177 Vector spokeVec(hubVec.x + std::cos(theta * i) * spokeDist,
178 hubVec.y + std::sin(theta * i) * spokeDist,
179 0);
180 spokeLoc->SetPosition(spokeVec);
181 }
182}
183
184} // 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.
Ipv4 addresses are stored in host order in this class.
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.
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.
Build a set of PointToPointNetDevice objects.
NetDeviceContainer Install(NodeContainer c)
Ptr< Node > GetSpokeNode(uint32_t i) const
Ipv6InterfaceContainer m_hubInterfaces6
IPv6 hub interfaces.
void InstallStack(InternetStackHelper stack)
Ipv4Address GetSpokeIpv4Address(uint32_t i) const
NodeContainer m_spokes
Spoke nodes.
NetDeviceContainer m_hubDevices
Hub node NetDevices.
Ipv4InterfaceContainer m_spokeInterfaces
IPv4 spoke nodes interfaces.
PointToPointStarHelper(uint32_t numSpokes, PointToPointHelper p2pHelper)
Create a PointToPointStarHelper in order to easily create star topologies using p2p links.
Ipv4InterfaceContainer m_hubInterfaces
IPv4 hub interfaces.
Ipv4Address GetHubIpv4Address(uint32_t i) const
void AssignIpv6Addresses(Ipv6Address network, Ipv6Prefix prefix)
Ipv6Address GetSpokeIpv6Address(uint32_t i) const
void BoundingBox(double ulx, double uly, double lrx, double lry)
Sets up the node canvas locations for every node in the star.
void AssignIpv4Addresses(Ipv4AddressHelper address)
Ipv6Address GetHubIpv6Address(uint32_t i) const
Ipv6InterfaceContainer m_spokeInterfaces6
IPv6 spoke nodes interfaces.
NetDeviceContainer m_spokeDevices
Spoke nodes NetDevices.
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.