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 #include <cmath>
18 #include <iostream>
19 #include <sstream>
20 
21 // ns3 includes
22 #include "ns3/log.h"
23 #include "ns3/point-to-point-star.h"
24 #include "ns3/constant-position-mobility-model.h"
25 
26 #include "ns3/node-list.h"
27 #include "ns3/point-to-point-net-device.h"
28 #include "ns3/vector.h"
29 #include "ns3/ipv6-address-generator.h"
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("PointToPointStarHelper");
34 
36  PointToPointHelper p2pHelper)
37 {
38  m_hub.Create (1);
39  m_spokes.Create (numSpokes);
40 
41  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
42  {
43  NetDeviceContainer nd = p2pHelper.Install (m_hub.Get (0), m_spokes.Get (i));
44  m_hubDevices.Add (nd.Get (0));
45  m_spokeDevices.Add (nd.Get (1));
46  }
47 }
48 
50 {
51 }
52 
55 {
56  return m_hub.Get (0);
57 }
58 
61 {
62  return m_spokes.Get (i);
63 }
64 
67 {
68  return m_hubInterfaces.GetAddress (i);
69 }
70 
73 {
74  return m_spokeInterfaces.GetAddress (i);
75 }
76 
79 {
80  return m_hubInterfaces6.GetAddress (i, 1);
81 }
82 
85 {
86  return m_spokeInterfaces6.GetAddress (i, 1);
87 }
88 
89 uint32_t
91 {
92  return m_spokes.GetN ();
93 }
94 
95 void
97 {
98  stack.Install (m_hub);
99  stack.Install (m_spokes);
100 }
101 
102 void
104 {
105  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
106  {
107  m_hubInterfaces.Add (address.Assign (m_hubDevices.Get (i)));
109  address.NewNetwork ();
110  }
111 }
112 
113 void
115 {
116  Ipv6AddressGenerator::Init (addrBase, prefix);
117  Ipv6Address v6network;
118  Ipv6AddressHelper addressHelper;
119 
120  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
121  {
122  v6network = Ipv6AddressGenerator::GetNetwork (prefix);
123  addressHelper.SetBase (v6network, prefix);
124 
125  Ipv6InterfaceContainer ic = addressHelper.Assign (m_hubDevices.Get (i));
126  m_hubInterfaces6.Add (ic);
127  ic = addressHelper.Assign (m_spokeDevices.Get (i));
128  m_spokeInterfaces6.Add (ic);
129 
131  }
132 }
133 
134 void
135 PointToPointStarHelper::BoundingBox (double ulx, double uly,
136  double lrx, double lry)
137 {
138  double xDist;
139  double yDist;
140  if (lrx > ulx)
141  {
142  xDist = lrx - ulx;
143  }
144  else
145  {
146  xDist = ulx - lrx;
147  }
148  if (lry > uly)
149  {
150  yDist = lry - uly;
151  }
152  else
153  {
154  yDist = uly - lry;
155  }
156 
157  // Place the hub
158  Ptr<Node> hub = m_hub.Get (0);
160  if (hubLoc == 0)
161  {
162  hubLoc = CreateObject<ConstantPositionMobilityModel> ();
163  hub->AggregateObject (hubLoc);
164  }
165  Vector hubVec (ulx + xDist/2.0, uly + yDist/2.0, 0);
166  hubLoc->SetPosition (hubVec);
167 
168  double spokeDist;
169  if (xDist > yDist)
170  {
171  spokeDist = yDist/4.0;
172  }
173  else
174  {
175  spokeDist = xDist/4.0;
176  }
177 
178  double theta = 2*M_PI/m_spokes.GetN ();
179  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
180  {
181  Ptr<Node> spokeNode = m_spokes.Get (i);
183  if (spokeLoc == 0)
184  {
185  spokeLoc = CreateObject<ConstantPositionMobilityModel> ();
186  spokeNode->AggregateObject (spokeLoc);
187  }
188  Vector spokeVec (hubVec.x + std::cos (theta*i) * spokeDist,
189  hubVec.y + std::sin (theta*i) * spokeDist,
190  0);
191  spokeLoc->SetPosition (spokeVec);
192  }
193 }
194 
195 } // namespace ns3
void AssignIpv4Addresses(Ipv4AddressHelper address)
Keep track of a set of IPv6 interfaces.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
NetDeviceContainer Install(NodeContainer c)
void AssignIpv6Addresses(Ipv6Address network, Ipv6Prefix prefix)
void Add(const Ipv4InterfaceContainer &other)
Concatenate the entries in the other container with ours.
void Add(Ptr< Ipv6 > ipv6, uint32_t interface)
Add a couple IPv6/interface.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
Mobility model for which the current position does not change once it has been set and until it is se...
NetDeviceContainer m_spokeDevices
Spoke nodes NetDevices.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
aggregate IP/TCP/UDP functionality to existing Nodes.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Build a set of PointToPointNetDevice objects.
PointToPointStarHelper(uint32_t numSpokes, PointToPointHelper p2pHelper)
Create a PointToPointStarHelper in order to easily create star topologies using p2p links...
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Ipv6InterfaceContainer m_hubInterfaces6
IPv6 hub interfaces.
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
Ipv6Address GetHubIpv6Address(uint32_t i) const
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
holds a vector of ns3::NetDevice pointers
Ptr< Node > GetSpokeNode(uint32_t i) const
Ipv6Address GetSpokeIpv6Address(uint32_t i) const
Ipv4InterfaceContainer m_spokeInterfaces
IPv4 spoke nodes interfaces.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
NodeContainer m_spokes
Spoke nodes.
Ipv6InterfaceContainer m_spokeInterfaces6
IPv6 spoke nodes interfaces.
tuple stack
Definition: first.py:34
Helper class to auto-assign global IPv6 unicast addresses.
static Ipv6Address NextNetwork(const Ipv6Prefix prefix)
Get the next network according to the given Ipv6Prefix.
static void Init(const Ipv6Address net, const Ipv6Prefix prefix, const Ipv6Address interfaceId="::1")
Initialise the base network and interfaceId for the generator.
Describes an IPv6 address.
Definition: ipv6-address.h:48
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4Address GetSpokeIpv4Address(uint32_t i) const
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Describes an IPv6 prefix.
Definition: ipv6-address.h:394
Ipv4Address NewNetwork(void)
Increment the network number and reset the IP address counter to the base value provided in the SetBa...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void BoundingBox(double ulx, double uly, double lrx, double lry)
Sets up the node canvas locations for every node in the star.
NetDeviceContainer m_hubDevices
Hub node NetDevices.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
NodeContainer m_hub
Hub node.
tuple address
Definition: first.py:37
static Ipv6Address GetNetwork(const Ipv6Prefix prefix)
Get the current network of the given Ipv6Prefix.
void InstallStack(InternetStackHelper stack)
Ipv4Address GetHubIpv4Address(uint32_t i) const
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
Ipv4InterfaceContainer m_hubInterfaces
IPv4 hub interfaces.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const