A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
NS_LOG_COMPONENT_DEFINE
(
"CsmaStarHelper"
);
28
29
namespace
ns3 {
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
{
39
NodeContainer
nodes (
m_hub
.
Get
(0),
m_spokes
.
Get
(i));
40
NetDeviceContainer
nd = csmaHelper.
Install
(nodes);
41
m_hubDevices
.
Add
(nd.Get (0));
42
m_spokeDevices
.
Add
(nd.Get (1));
43
}
44
}
45
46
CsmaStarHelper::~CsmaStarHelper
()
47
{
48
}
49
50
Ptr<Node>
51
CsmaStarHelper::GetHub
()
const
52
{
53
return
m_hub
.
Get
(0);
54
}
55
56
Ptr<Node>
57
CsmaStarHelper::GetSpokeNode
(uint32_t i)
const
58
{
59
return
m_spokes
.
Get
(i);
60
}
61
62
NetDeviceContainer
63
CsmaStarHelper::GetHubDevices
()
const
64
{
65
return
m_hubDevices
;
66
}
67
68
NetDeviceContainer
69
CsmaStarHelper::GetSpokeDevices
()
const
70
{
71
return
m_spokeDevices
;
72
}
73
74
Ipv4Address
75
CsmaStarHelper::GetHubIpv4Address
(uint32_t i)
const
76
{
77
return
m_hubInterfaces
.
GetAddress
(i);
78
}
79
80
Ipv4Address
81
CsmaStarHelper::GetSpokeIpv4Address
(uint32_t i)
const
82
{
83
return
m_spokeInterfaces
.
GetAddress
(i);
84
}
85
86
Ipv6Address
87
CsmaStarHelper::GetHubIpv6Address
(uint32_t i)
const
88
{
89
return
m_hubInterfaces6
.
GetAddress
(i, 1);
90
}
91
92
Ipv6Address
93
CsmaStarHelper::GetSpokeIpv6Address
(uint32_t i)
const
94
{
95
return
m_spokeInterfaces6
.
GetAddress
(i, 1);
96
}
97
98
uint32_t
99
CsmaStarHelper::SpokeCount
()
const
100
{
101
return
m_spokes
.
GetN
();
102
}
103
104
void
105
CsmaStarHelper::InstallStack
(
InternetStackHelper
stack)
106
{
107
stack.
Install
(
m_hub
);
108
stack.
Install
(
m_spokes
);
109
}
110
111
void
112
CsmaStarHelper::AssignIpv4Addresses
(
Ipv4AddressHelper
address)
113
{
114
for
(uint32_t i = 0; i <
m_spokes
.
GetN
(); ++i)
115
{
116
m_hubInterfaces
.
Add
(address.
Assign
(
m_hubDevices
.
Get
(i)));
117
m_spokeInterfaces
.
Add
(address.
Assign
(
m_spokeDevices
.
Get
(i)));
118
address.
NewNetwork
();
119
}
120
}
121
122
void
123
CsmaStarHelper::AssignIpv6Addresses
(
Ipv6Address
network,
Ipv6Prefix
prefix)
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
139
Ipv6AddressGenerator::NextNetwork
(prefix);
140
}
141
}
142
143
}
// namespace ns3
src
csma-layout
model
csma-star-helper.cc
Generated on Tue May 14 2013 11:08:19 for ns-3 by
1.8.1.2