A Discrete-Event Network Simulator
API
csma-star-helper.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 <iostream>
18 #include <sstream>
19 
20 // ns3 includes
21 #include "ns3/csma-star-helper.h"
22 #include "ns3/node-list.h"
23 #include "ns3/point-to-point-net-device.h"
24 #include "ns3/vector.h"
25 #include "ns3/log.h"
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("CsmaStarHelper");
30 
31 CsmaStarHelper::CsmaStarHelper (uint32_t numSpokes,
32  CsmaHelper csmaHelper)
33 {
34  m_hub.Create (1);
35  m_spokes.Create (numSpokes);
36 
37  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
38  {
40  NetDeviceContainer nd = csmaHelper.Install (nodes);
41  m_hubDevices.Add (nd.Get (0));
42  m_spokeDevices.Add (nd.Get (1));
43  }
44 }
45 
47 {
48 }
49 
52 {
53  return m_hub.Get (0);
54 }
55 
57 CsmaStarHelper::GetSpokeNode (uint32_t i) const
58 {
59  return m_spokes.Get (i);
60 }
61 
64 {
65  return m_hubDevices;
66 }
67 
70 {
71  return m_spokeDevices;
72 }
73 
76 {
77  return m_hubInterfaces.GetAddress (i);
78 }
79 
82 {
83  return m_spokeInterfaces.GetAddress (i);
84 }
85 
88 {
89  return m_hubInterfaces6.GetAddress (i, 1);
90 }
91 
94 {
95  return m_spokeInterfaces6.GetAddress (i, 1);
96 }
97 
98 uint32_t
100 {
101  return m_spokes.GetN ();
102 }
103 
104 void
106 {
107  stack.Install (m_hub);
108  stack.Install (m_spokes);
109 }
110 
111 void
113 {
114  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
115  {
116  m_hubInterfaces.Add (address.Assign (m_hubDevices.Get (i)));
118  address.NewNetwork ();
119  }
120 }
121 
122 void
124 {
125  Ipv6AddressGenerator::Init(network, prefix);
126  Ipv6Address v6network;
127  Ipv6AddressHelper addressHelper;
128 
129  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
130  {
131  v6network = Ipv6AddressGenerator::GetNetwork (prefix);
132  addressHelper.SetBase (v6network, prefix);
133 
134  Ipv6InterfaceContainer ic = addressHelper.Assign (m_hubDevices.Get (i));
135  m_hubInterfaces6.Add (ic);
136  ic = addressHelper.Assign (m_spokeDevices.Get (i));
137  m_spokeInterfaces6.Add (ic);
138 
140  }
141 }
142 
143 } // namespace ns3
Ipv6Address GetSpokeIpv6Address(uint32_t i) const
void AssignIpv4Addresses(Ipv4AddressHelper address)
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
void InstallStack(InternetStackHelper stack)
Keep track of a set of IPv6 interfaces.
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.
Ipv6Address GetHubIpv6Address(uint32_t i) const
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
uint32_t SpokeCount() const
aggregate IP/TCP/UDP functionality to existing Nodes.
NodeContainer m_hub
NodeContainer for the hub node.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
CsmaStarHelper(uint32_t numSpokes, CsmaHelper csmaHelper)
Create a CsmaStarHelper in order to easily create star topologies using Csma links.
NodeContainer m_spokes
NodeContainer for the spokes nodes.
Ptr< Node > GetHub() const
stack
Definition: first.py:34
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
nodes
Definition: first.py:25
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.
holds a vector of ns3::NetDevice pointers
NetDeviceContainer GetHubDevices() const
Ipv4InterfaceContainer m_hubInterfaces
Ipv4InterfaceContainer for the hub IPv4 interfaces.
NetDeviceContainer m_spokeDevices
NetDeviceContainer for the spokes nodes NetDevices.
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
NetDeviceContainer GetSpokeDevices() const
NetDeviceContainer m_hubDevices
NetDeviceContainer for the hub node NetDevices.
Ipv4InterfaceContainer m_spokeInterfaces
Ipv4InterfaceContainer for the spokes IPv4 interfaces.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
address
Definition: first.py:37
void AssignIpv6Addresses(Ipv6Address network, Ipv6Prefix prefix)
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
build a set of CsmaNetDevice objects
Definition: csma-helper.h:46
Helper class to auto-assign global IPv6 unicast addresses.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
Definition: csma-helper.cc:217
Ptr< Node > GetSpokeNode(uint32_t i) const
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
Ipv4Address GetHubIpv4Address(uint32_t i) const
Ipv6InterfaceContainer m_spokeInterfaces6
Ipv6InterfaceContainer for the spokes IPv6 interfaces.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ipv4Address GetSpokeIpv4Address(uint32_t i) const
Describes an IPv6 prefix.
Definition: ipv6-address.h:428
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ipv6InterfaceContainer m_hubInterfaces6
Ipv6InterfaceContainer for the hub IPv6 interfaces.
static Ipv6Address GetNetwork(const Ipv6Prefix prefix)
Get the current network of the given Ipv6Prefix.