A Discrete-Event Network Simulator
API
point-to-point-star.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  */
16 
17 // Implement an object to create a star topology.
18 
19 #include <cmath>
20 #include <iostream>
21 #include <sstream>
22 
23 // ns3 includes
24 #include "ns3/log.h"
25 #include "ns3/point-to-point-star.h"
26 #include "ns3/constant-position-mobility-model.h"
27 
28 #include "ns3/node-list.h"
29 #include "ns3/point-to-point-net-device.h"
30 #include "ns3/vector.h"
31 #include "ns3/ipv6-address-generator.h"
32 
33 namespace ns3 {
34 
35 NS_LOG_COMPONENT_DEFINE ("PointToPointStarHelper");
36 
38  PointToPointHelper p2pHelper)
39 {
40  m_hub.Create (1);
41  m_spokes.Create (numSpokes);
42 
43  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
44  {
45  NetDeviceContainer nd = p2pHelper.Install (m_hub.Get (0), m_spokes.Get (i));
46  m_hubDevices.Add (nd.Get (0));
47  m_spokeDevices.Add (nd.Get (1));
48  }
49 }
50 
52 {
53 }
54 
57 {
58  return m_hub.Get (0);
59 }
60 
63 {
64  return m_spokes.Get (i);
65 }
66 
69 {
70  return m_hubInterfaces.GetAddress (i);
71 }
72 
75 {
76  return m_spokeInterfaces.GetAddress (i);
77 }
78 
81 {
82  return m_hubInterfaces6.GetAddress (i, 1);
83 }
84 
87 {
88  return m_spokeInterfaces6.GetAddress (i, 1);
89 }
90 
91 uint32_t
93 {
94  return m_spokes.GetN ();
95 }
96 
97 void
99 {
100  stack.Install (m_hub);
101  stack.Install (m_spokes);
102 }
103 
104 void
106 {
107  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
108  {
109  m_hubInterfaces.Add (address.Assign (m_hubDevices.Get (i)));
111  address.NewNetwork ();
112  }
113 }
114 
115 void
117 {
118  Ipv6AddressGenerator::Init (addrBase, prefix);
119  Ipv6Address v6network;
120  Ipv6AddressHelper addressHelper;
121 
122  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
123  {
124  v6network = Ipv6AddressGenerator::GetNetwork (prefix);
125  addressHelper.SetBase (v6network, prefix);
126 
127  Ipv6InterfaceContainer ic = addressHelper.Assign (m_hubDevices.Get (i));
128  m_hubInterfaces6.Add (ic);
129  ic = addressHelper.Assign (m_spokeDevices.Get (i));
130  m_spokeInterfaces6.Add (ic);
131 
133  }
134 }
135 
136 void
137 PointToPointStarHelper::BoundingBox (double ulx, double uly,
138  double lrx, double lry)
139 {
140  double xDist;
141  double yDist;
142  if (lrx > ulx)
143  {
144  xDist = lrx - ulx;
145  }
146  else
147  {
148  xDist = ulx - lrx;
149  }
150  if (lry > uly)
151  {
152  yDist = lry - uly;
153  }
154  else
155  {
156  yDist = uly - lry;
157  }
158 
159  // Place the hub
160  Ptr<Node> hub = m_hub.Get (0);
162  if (hubLoc == 0)
163  {
164  hubLoc = CreateObject<ConstantPositionMobilityModel> ();
165  hub->AggregateObject (hubLoc);
166  }
167  Vector hubVec (ulx + xDist/2.0, uly + yDist/2.0, 0);
168  hubLoc->SetPosition (hubVec);
169 
170  double spokeDist;
171  if (xDist > yDist)
172  {
173  spokeDist = yDist/4.0;
174  }
175  else
176  {
177  spokeDist = xDist/4.0;
178  }
179 
180  double theta = 2*M_PI/m_spokes.GetN ();
181  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
182  {
183  Ptr<Node> spokeNode = m_spokes.Get (i);
185  if (spokeLoc == 0)
186  {
187  spokeLoc = CreateObject<ConstantPositionMobilityModel> ();
188  spokeNode->AggregateObject (spokeLoc);
189  }
190  Vector spokeVec (hubVec.x + std::cos (theta*i) * spokeDist,
191  hubVec.y + std::sin (theta*i) * spokeDist,
192  0);
193  spokeLoc->SetPosition (spokeVec);
194  }
195 }
196 
197 } // namespace ns3
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::PointToPointStarHelper::AssignIpv6Addresses
void AssignIpv6Addresses(Ipv6Address network, Ipv6Prefix prefix)
Definition: point-to-point-star.cc:116
ns3::PointToPointStarHelper::GetHubIpv6Address
Ipv6Address GetHubIpv6Address(uint32_t i) const
Definition: point-to-point-star.cc:80
ns3::ConstantPositionMobilityModel
Mobility model for which the current position does not change once it has been set and until it is se...
Definition: constant-position-mobility-model.h:33
ns3::PointToPointStarHelper::SpokeCount
uint32_t SpokeCount() const
Definition: point-to-point-star.cc:92
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition: ipv4-address-helper.h:48
ns3::PointToPointStarHelper::GetSpokeNode
Ptr< Node > GetSpokeNode(uint32_t i) const
Definition: point-to-point-star.cc:62
ns3::Ipv6AddressGenerator::GetNetwork
static Ipv6Address GetNetwork(const Ipv6Prefix prefix)
Get the current network of the given Ipv6Prefix.
Definition: ipv6-address-generator.cc:696
ns3::PointToPointStarHelper::m_hubInterfaces6
Ipv6InterfaceContainer m_hubInterfaces6
IPv6 hub interfaces.
Definition: point-to-point-star.h:148
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
ns3::PointToPointStarHelper::GetHub
Ptr< Node > GetHub() const
Definition: point-to-point-star.cc:56
ns3::PointToPointHelper::Install
NetDeviceContainer Install(NodeContainer c)
Definition: point-to-point-helper.cc:222
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::Ipv6Address
Describes an IPv6 address.
Definition: ipv6-address.h:50
ns3::NodeContainer::GetN
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
Definition: node-container.cc:88
ns3::Ipv6AddressHelper::SetBase
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Definition: ipv6-address-helper.cc:69
ns3::PointToPointStarHelper::m_spokeInterfaces
Ipv4InterfaceContainer m_spokeInterfaces
IPv4 spoke nodes interfaces.
Definition: point-to-point-star.h:147
ns3::Ipv6AddressHelper
Helper class to auto-assign global IPv6 unicast addresses.
Definition: ipv6-address-helper.h:83
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition: node-container.cc:98
ns3::PointToPointStarHelper::PointToPointStarHelper
PointToPointStarHelper(uint32_t numSpokes, PointToPointHelper p2pHelper)
Create a PointToPointStarHelper in order to easily create star topologies using p2p links.
Definition: point-to-point-star.cc:37
ns3::PointToPointStarHelper::~PointToPointStarHelper
~PointToPointStarHelper()
Definition: point-to-point-star.cc:51
ns3::Ipv6AddressHelper::Assign
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Definition: ipv6-address-helper.cc:210
ns3::PointToPointStarHelper::GetSpokeIpv4Address
Ipv4Address GetSpokeIpv4Address(uint32_t i) const
Definition: point-to-point-star.cc:74
ns3::Ptr< Node >
ns3::Ipv6AddressGenerator::NextNetwork
static Ipv6Address NextNetwork(const Ipv6Prefix prefix)
Get the next network according to the given Ipv6Prefix.
Definition: ipv6-address-generator.cc:687
first.stack
stack
Definition: first.py:41
ns3::Ipv6InterfaceContainer::GetAddress
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
Definition: ipv6-interface-container.cc:57
ns3::Object::AggregateObject
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
ns3::Ipv6InterfaceContainer
Keep track of a set of IPv6 interfaces.
Definition: ipv6-interface-container.h:42
ns3::NodeContainer::Get
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Definition: node-container.cc:93
first.address
address
Definition: first.py:44
ns3::PointToPointStarHelper::BoundingBox
void BoundingBox(double ulx, double uly, double lrx, double lry)
Sets up the node canvas locations for every node in the star.
Definition: point-to-point-star.cc:137
ns3::Ipv6InterfaceContainer::Add
void Add(Ptr< Ipv6 > ipv6, uint32_t interface)
Add a couple IPv6/interface.
Definition: ipv6-interface-container.cc:64
ns3::PointToPointStarHelper::m_spokes
NodeContainer m_spokes
Spoke nodes.
Definition: point-to-point-star.h:144
ns3::PointToPointStarHelper::m_hubInterfaces
Ipv4InterfaceContainer m_hubInterfaces
IPv4 hub interfaces.
Definition: point-to-point-star.h:146
ns3::Ipv4InterfaceContainer::Add
void Add(const Ipv4InterfaceContainer &other)
Concatenate the entries in the other container with ours.
Definition: ipv4-interface-container.cc:32
ns3::PointToPointStarHelper::GetSpokeIpv6Address
Ipv6Address GetSpokeIpv6Address(uint32_t i) const
Definition: point-to-point-star.cc:86
ns3::PointToPointStarHelper::m_hub
NodeContainer m_hub
Hub node.
Definition: point-to-point-star.h:142
ns3::PointToPointStarHelper::m_hubDevices
NetDeviceContainer m_hubDevices
Hub node NetDevices.
Definition: point-to-point-star.h:143
ns3::PointToPointHelper
Build a set of PointToPointNetDevice objects.
Definition: point-to-point-helper.h:45
ns3::Ipv4InterfaceContainer::GetAddress
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Definition: ipv4-interface-container.cc:59
ns3::PointToPointStarHelper::m_spokeDevices
NetDeviceContainer m_spokeDevices
Spoke nodes NetDevices.
Definition: point-to-point-star.h:145
ns3::PointToPointStarHelper::m_spokeInterfaces6
Ipv6InterfaceContainer m_spokeInterfaces6
IPv6 spoke nodes interfaces.
Definition: point-to-point-star.h:149
ns3::PointToPointStarHelper::InstallStack
void InstallStack(InternetStackHelper stack)
Definition: point-to-point-star.cc:98
ns3::PointToPointStarHelper::GetHubIpv4Address
Ipv4Address GetHubIpv4Address(uint32_t i) const
Definition: point-to-point-star.cc:68
ns3::Ipv6AddressGenerator::Init
static void Init(const Ipv6Address net, const Ipv6Prefix prefix, const Ipv6Address interfaceId="::1")
Initialise the base network and interfaceId for the generator.
Definition: ipv6-address-generator.cc:675
ns3::PointToPointStarHelper::AssignIpv4Addresses
void AssignIpv4Addresses(Ipv4AddressHelper address)
Definition: point-to-point-star.cc:105
ns3::Ipv6Prefix
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition: internet-stack-helper.h:88
ns3::NetDeviceContainer::Get
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Definition: net-device-container.cc:62
ns3::NetDeviceContainer::Add
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Definition: net-device-container.cc:67