A Discrete-Event Network Simulator
API
point-to-point-dumbbell.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  * Author: George F. Riley<riley@ece.gatech.edu>
17  */
18 
19 // Implement an object to create a dumbbell topology.
20 
21 #include <cmath>
22 #include <iostream>
23 #include <sstream>
24 
25 // ns3 includes
26 #include "ns3/log.h"
27 #include "ns3/point-to-point-dumbbell.h"
28 #include "ns3/constant-position-mobility-model.h"
29 
30 #include "ns3/node-list.h"
31 #include "ns3/point-to-point-net-device.h"
32 #include "ns3/vector.h"
33 #include "ns3/ipv6-address-generator.h"
34 
35 namespace ns3 {
36 
37 NS_LOG_COMPONENT_DEFINE ("PointToPointDumbbellHelper");
38 
40  PointToPointHelper leftHelper,
41  uint32_t nRightLeaf,
42  PointToPointHelper rightHelper,
43  PointToPointHelper bottleneckHelper)
44 {
45  // Create the bottleneck routers
46  m_routers.Create (2);
47  // Create the leaf nodes
48  m_leftLeaf.Create (nLeftLeaf);
49  m_rightLeaf.Create (nRightLeaf);
50 
51  // Add the link connecting routers
52  m_routerDevices = bottleneckHelper.Install (m_routers);
53  // Add the left side links
54  for (uint32_t i = 0; i < nLeftLeaf; ++i)
55  {
56  NetDeviceContainer c = leftHelper.Install (m_routers.Get (0),
57  m_leftLeaf.Get (i));
58  m_leftRouterDevices.Add (c.Get (0));
59  m_leftLeafDevices.Add (c.Get (1));
60  }
61  // Add the right side links
62  for (uint32_t i = 0; i < nRightLeaf; ++i)
63  {
64  NetDeviceContainer c = rightHelper.Install (m_routers.Get (1),
65  m_rightLeaf.Get (i));
67  m_rightLeafDevices.Add (c.Get (1));
68  }
69 }
70 
72 {
73 }
74 
76 { // Get the left side bottleneck router
77  return m_routers.Get (0);
78 }
79 
81 { // Get the i'th left side leaf
82  return m_leftLeaf.Get (i);
83 }
84 
86 { // Get the right side bottleneck router
87  return m_routers.Get (1);
88 }
89 
91 { // Get the i'th right side leaf
92  return m_rightLeaf.Get (i);
93 }
94 
96 {
98 }
99 
101 {
103 }
104 
106 {
107  return m_leftLeafInterfaces6.GetAddress (i, 1);
108 }
109 
111 {
112  return m_rightLeafInterfaces6.GetAddress (i, 1);
113 }
114 
116 { // Number of left side nodes
117  return m_leftLeaf.GetN ();
118 }
119 
121 { // Number of right side nodes
122  return m_rightLeaf.GetN ();
123 }
124 
126 {
127  stack.Install (m_routers);
128  stack.Install (m_leftLeaf);
129  stack.Install (m_rightLeaf);
130 }
131 
133  Ipv4AddressHelper rightIp,
134  Ipv4AddressHelper routerIp)
135 {
136  // Assign the router network
138  // Assign to left side
139  for (uint32_t i = 0; i < LeftCount (); ++i)
140  {
141  NetDeviceContainer ndc;
142  ndc.Add (m_leftLeafDevices.Get (i));
143  ndc.Add (m_leftRouterDevices.Get (i));
144  Ipv4InterfaceContainer ifc = leftIp.Assign (ndc);
145  m_leftLeafInterfaces.Add (ifc.Get (0));
146  m_leftRouterInterfaces.Add (ifc.Get (1));
147  leftIp.NewNetwork ();
148  }
149  // Assign to right side
150  for (uint32_t i = 0; i < RightCount (); ++i)
151  {
152  NetDeviceContainer ndc;
153  ndc.Add (m_rightLeafDevices.Get (i));
154  ndc.Add (m_rightRouterDevices.Get (i));
155  Ipv4InterfaceContainer ifc = rightIp.Assign (ndc);
156  m_rightLeafInterfaces.Add (ifc.Get (0));
157  m_rightRouterInterfaces.Add (ifc.Get (1));
158  rightIp.NewNetwork ();
159  }
160 }
161 
163 {
164  // Assign the router network
165  Ipv6AddressGenerator::Init (addrBase, prefix);
166  Ipv6Address v6network;
167  Ipv6AddressHelper addressHelper;
168 
169  v6network = Ipv6AddressGenerator::GetNetwork (prefix);
170  addressHelper.SetBase (v6network, prefix);
171  m_routerInterfaces6 = addressHelper.Assign (m_routerDevices);
173 
174  // Assign to left side
175  for (uint32_t i = 0; i < LeftCount (); ++i)
176  {
177  v6network = Ipv6AddressGenerator::GetNetwork (prefix);
178  addressHelper.SetBase (v6network, prefix);
179 
180  NetDeviceContainer ndc;
181  ndc.Add (m_leftLeafDevices.Get (i));
182  ndc.Add (m_leftRouterDevices.Get (i));
183  Ipv6InterfaceContainer ifc = addressHelper.Assign (ndc);
185  m_leftLeafInterfaces6.Add ((*it).first, (*it).second);
186  it++;
187  m_leftRouterInterfaces6.Add ((*it).first, (*it).second);
189  }
190  // Assign to right side
191  for (uint32_t i = 0; i < RightCount (); ++i)
192  {
193  v6network = Ipv6AddressGenerator::GetNetwork (prefix);
194  addressHelper.SetBase (v6network, prefix);
195 
196  NetDeviceContainer ndc;
197  ndc.Add (m_rightLeafDevices.Get (i));
198  ndc.Add (m_rightRouterDevices.Get (i));
199  Ipv6InterfaceContainer ifc = addressHelper.Assign (ndc);
201  m_rightLeafInterfaces6.Add ((*it).first, (*it).second);
202  it++;
203  m_rightRouterInterfaces6.Add ((*it).first, (*it).second);
205  }
206 }
207 
208 
209 void PointToPointDumbbellHelper::BoundingBox (double ulx, double uly, // Upper left x/y
210  double lrx, double lry) // Lower right x/y
211 {
212  double xDist;
213  double yDist;
214  if (lrx > ulx)
215  {
216  xDist = lrx - ulx;
217  }
218  else
219  {
220  xDist = ulx - lrx;
221  }
222  if (lry > uly)
223  {
224  yDist = lry - uly;
225  }
226  else
227  {
228  yDist = uly - lry;
229  }
230 
231  double xAdder = xDist / 3.0;
232  double thetaL = M_PI / (LeftCount () + 1.0);
233  double thetaR = M_PI / (RightCount () + 1.0);
234 
235  // Place the left router
236  Ptr<Node> lr = GetLeft ();
238  if (loc == 0)
239  {
240  loc = CreateObject<ConstantPositionMobilityModel> ();
241  lr->AggregateObject (loc);
242  }
243  Vector lrl (ulx + xAdder, uly + yDist/2.0, 0);
244  loc->SetPosition (lrl);
245 
246  // Place the right router
247  Ptr<Node> rr = GetRight ();
249  if (loc == 0)
250  {
251  loc = CreateObject<ConstantPositionMobilityModel> ();
252  rr->AggregateObject (loc);
253  }
254  Vector rrl (ulx + xAdder * 2, uly + yDist/2.0, 0); // Right router location
255  loc->SetPosition (rrl);
256 
257  // Place the left leaf nodes
258  double theta = -M_PI_2 + thetaL;
259  for (uint32_t l = 0; l < LeftCount (); ++l)
260  {
261  // Make them in a circular pattern to make all line lengths the same
262  // Special case when theta = 0, to be sure we get a straight line
263  if ((LeftCount () % 2) == 1)
264  { // Count is odd, see if we are in middle
265  if (l == (LeftCount () / 2))
266  {
267  theta = 0.0;
268  }
269  }
270  Ptr<Node> ln = GetLeft (l);
272  if (loc == 0)
273  {
274  loc = CreateObject<ConstantPositionMobilityModel> ();
275  ln->AggregateObject (loc);
276  }
277  Vector lnl (lrl.x - std::cos (theta) * xAdder,
278  lrl.y + std::sin (theta) * xAdder, 0); // Left Node Location
279  // Insure did not exceed bounding box
280  if (lnl.y < uly)
281  {
282  lnl.y = uly; // Set to upper left y
283  }
284  if (lnl.y > lry)
285  {
286  lnl.y = lry; // Set to lower right y
287  }
288  loc->SetPosition (lnl);
289  theta += thetaL;
290  }
291  // Place the right nodes
292  theta = -M_PI_2 + thetaR;
293  for (uint32_t r = 0; r < RightCount (); ++r)
294  {
295  // Special case when theta = 0, to be sure we get a straight line
296  if ((RightCount () % 2) == 1)
297  { // Count is odd, see if we are in middle
298  if (r == (RightCount () / 2))
299  {
300  theta = 0.0;
301  }
302  }
303  Ptr<Node> rn = GetRight (r);
305  if (loc == 0)
306  {
307  loc = CreateObject<ConstantPositionMobilityModel> ();
308  rn->AggregateObject (loc);
309  }
310  Vector rnl (rrl.x + std::cos (theta) * xAdder, // Right node location
311  rrl.y + std::sin (theta) * xAdder, 0);
312  // Insure did not exceed bounding box
313  if (rnl.y < uly)
314  {
315  rnl.y = uly; // Set to upper left y
316  }
317  if (rnl.y > lry)
318  {
319  rnl.y = lry; // Set to lower right y
320  }
321  loc->SetPosition (rnl);
322  theta += thetaR;
323  }
324 }
325 
326 } // namespace ns3
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
NetDeviceContainer m_leftRouterDevices
Left router NetDevices.
Ipv4Address GetRightIpv4Address(uint32_t i) const
Keep track of a set of IPv6 interfaces.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4InterfaceContainer m_leftLeafInterfaces
Left Leaf interfaces (IPv4)
Ipv6Address GetRightIpv6Address(uint32_t i) const
NetDeviceContainer Install(NodeContainer c)
void BoundingBox(double ulx, double uly, double lrx, double lry)
Sets up the node canvas locations for every node in the dumbbell.
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...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
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.
NetDeviceContainer m_rightRouterDevices
Right router NetDevices.
Iterator Begin(void) const
Get an iterator which refers to the first pair in the container.
Ipv4InterfaceContainer m_rightLeafInterfaces
Right Leaf interfaces (IPv4)
Ipv6InterfaceContainer m_leftLeafInterfaces6
Left Leaf interfaces (IPv6)
NetDeviceContainer m_leftLeafDevices
Left Leaf NetDevices.
stack
Definition: first.py:34
Ipv4InterfaceContainer m_routerInterfaces
Router interfaces (IPv4)
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
std::vector< std::pair< Ptr< Ipv6 >, uint32_t > >::const_iterator Iterator
Container Const Iterator for pairs of Ipv6 smart pointer / Interface Index.
Ipv6InterfaceContainer m_rightLeafInterfaces6
Right Leaf interfaces (IPv6)
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ipv6InterfaceContainer m_rightRouterInterfaces6
Right router interfaces (IPv6)
holds a vector of ns3::NetDevice pointers
NodeContainer m_leftLeaf
Left Leaf nodes.
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Ipv4InterfaceContainer m_leftRouterInterfaces
Left router interfaces (IPv4)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void AssignIpv4Addresses(Ipv4AddressHelper leftIp, Ipv4AddressHelper rightIp, Ipv4AddressHelper routerIp)
Ipv4Address GetLeftIpv4Address(uint32_t i) const
Ipv6Address GetLeftIpv6Address(uint32_t i) const
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
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:49
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
NetDeviceContainer m_routerDevices
Routers NetDevices.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv6InterfaceContainer m_leftRouterInterfaces6
Left router interfaces (IPv6)
void InstallStack(InternetStackHelper stack)
Ipv4InterfaceContainer m_rightRouterInterfaces
Right router interfaces (IPv4)
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Describes an IPv6 prefix.
Definition: ipv6-address.h:428
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 AssignIpv6Addresses(Ipv6Address network, Ipv6Prefix prefix)
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
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...
static Ipv6Address GetNetwork(const Ipv6Prefix prefix)
Get the current network of the given Ipv6Prefix.
NodeContainer m_rightLeaf
Right Leaf nodes.
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_rightLeafDevices
Right Leaf NetDevices.
Ipv6InterfaceContainer m_routerInterfaces6
Router interfaces (IPv6)