A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
csma-star-helper.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 */
4
5#include "csma-star-helper.h"
6
7#include "ns3/log.h"
8#include "ns3/node-list.h"
9#include "ns3/point-to-point-net-device.h"
10#include "ns3/vector.h"
11
12#include <iostream>
13#include <sstream>
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("CsmaStarHelper");
19
21{
22 m_hub.Create(1);
23 m_spokes.Create(numSpokes);
24
25 for (uint32_t i = 0; i < m_spokes.GetN(); ++i)
26 {
28 NetDeviceContainer nd = csmaHelper.Install(nodes);
29 m_hubDevices.Add(nd.Get(0));
30 m_spokeDevices.Add(nd.Get(1));
31 }
32}
33
37
40{
41 return m_hub.Get(0);
42}
43
46{
47 return m_spokes.Get(i);
48}
49
55
61
67
73
79
85
88{
89 return m_spokes.GetN();
90}
91
92void
94{
95 stack.Install(m_hub);
96 stack.Install(m_spokes);
97}
98
99void
101{
102 for (uint32_t i = 0; i < m_spokes.GetN(); ++i)
103 {
104 m_hubInterfaces.Add(address.Assign(m_hubDevices.Get(i)));
105 m_spokeInterfaces.Add(address.Assign(m_spokeDevices.Get(i)));
106 address.NewNetwork();
107 }
108}
109
110void
112{
113 Ipv6AddressGenerator::Init(network, prefix);
114 Ipv6Address v6network;
115 Ipv6AddressHelper addressHelper;
116
117 for (uint32_t i = 0; i < m_spokes.GetN(); ++i)
118 {
119 v6network = Ipv6AddressGenerator::GetNetwork(prefix);
120 addressHelper.SetBase(v6network, prefix);
121
122 Ipv6InterfaceContainer ic = addressHelper.Assign(m_hubDevices.Get(i));
124 ic = addressHelper.Assign(m_spokeDevices.Get(i));
126
128 }
129}
130
131} // namespace ns3
build a set of CsmaNetDevice objects
Definition csma-helper.h:37
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
void AssignIpv6Addresses(Ipv6Address network, Ipv6Prefix prefix)
void InstallStack(InternetStackHelper stack)
Ipv6InterfaceContainer m_spokeInterfaces6
Ipv6InterfaceContainer for the spokes IPv6 interfaces.
NetDeviceContainer m_spokeDevices
NetDeviceContainer for the spokes nodes NetDevices.
Ipv4Address GetSpokeIpv4Address(uint32_t i) const
NodeContainer m_spokes
NodeContainer for the spokes nodes.
Ipv4Address GetHubIpv4Address(uint32_t i) const
CsmaStarHelper(uint32_t numSpokes, CsmaHelper csmaHelper)
Create a CsmaStarHelper in order to easily create star topologies using Csma links.
Ipv6Address GetHubIpv6Address(uint32_t i) const
void AssignIpv4Addresses(Ipv4AddressHelper address)
Ptr< Node > GetSpokeNode(uint32_t i) const
Ptr< Node > GetHub() const
Ipv6InterfaceContainer m_hubInterfaces6
Ipv6InterfaceContainer for the hub IPv6 interfaces.
NetDeviceContainer m_hubDevices
NetDeviceContainer for the hub node NetDevices.
Ipv4InterfaceContainer m_hubInterfaces
Ipv4InterfaceContainer for the hub IPv4 interfaces.
NetDeviceContainer GetSpokeDevices() const
uint32_t SpokeCount() const
Ipv4InterfaceContainer m_spokeInterfaces
Ipv4InterfaceContainer for the spokes IPv4 interfaces.
NodeContainer m_hub
NodeContainer for the hub node.
NetDeviceContainer GetHubDevices() const
Ipv6Address GetSpokeIpv6Address(uint32_t i) const
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.
keep track of a set of node pointers.
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.
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
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.