A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
y
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
Enumerations
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
v
w
Enumerator
a
b
c
d
e
f
h
i
l
m
n
o
p
q
r
s
t
u
v
w
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
:
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
Enumerations
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
Enumerator
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Properties
Related Functions
:
a
b
c
d
e
g
h
i
j
l
m
n
o
p
q
r
s
t
u
w
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
w
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
Enumerations
Enumerator
c
e
i
l
o
r
s
t
v
Macros
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
tap-csma-virtual-machine.cc
Go to the documentation of this file.
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License version 2 as
4
* published by the Free Software Foundation;
5
*
6
* This program is distributed in the hope that it will be useful,
7
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
* GNU General Public License for more details.
10
*
11
* You should have received a copy of the GNU General Public License
12
* along with this program; if not, write to the Free Software
13
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
*/
15
16
//
17
// This is an illustration of how one could use virtualization techniques to
18
// allow running applications on virtual machines talking over simulated
19
// networks.
20
//
21
// The actual steps required to configure the virtual machines can be rather
22
// involved, so we don't go into that here. Please have a look at one of
23
// our HOWTOs on the nsnam wiki for more details about how to get the
24
// system configured. For an example, have a look at "HOWTO Use Linux
25
// Containers to set up virtual networks" which uses this code as an
26
// example.
27
//
28
// The configuration you are after is explained in great detail in the
29
// HOWTO, but looks like the following:
30
//
31
// +----------+ +----------+
32
// | virtual | | virtual |
33
// | Linux | | Linux |
34
// | Host | | Host |
35
// | | | |
36
// | eth0 | | eth0 |
37
// +----------+ +----------+
38
// | |
39
// +----------+ +----------+
40
// | Linux | | Linux |
41
// | Bridge | | Bridge |
42
// +----------+ +----------+
43
// | |
44
// +------------+ +-------------+
45
// | "tap-left" | | "tap-right" |
46
// +------------+ +-------------+
47
// | n0 n1 |
48
// | +--------+ +--------+ |
49
// +-------| tap | | tap |-------+
50
// | bridge | | bridge |
51
// +--------+ +--------+
52
// | CSMA | | CSMA |
53
// +--------+ +--------+
54
// | |
55
// | |
56
// | |
57
// ===============
58
// CSMA LAN
59
//
60
#include "ns3/core-module.h"
61
#include "ns3/csma-module.h"
62
#include "ns3/network-module.h"
63
#include "ns3/tap-bridge-module.h"
64
65
#include <fstream>
66
#include <iostream>
67
68
using namespace
ns3
;
69
70
NS_LOG_COMPONENT_DEFINE
(
"TapCsmaVirtualMachineExample"
);
71
72
int
73
main(
int
argc,
char
* argv[])
74
{
75
CommandLine
cmd
(__FILE__);
76
cmd
.Parse(argc, argv);
77
78
//
79
// We are interacting with the outside, real, world. This means we have to
80
// interact in real-time and therefore means we have to use the real-time
81
// simulator and take the time to calculate checksums.
82
//
83
GlobalValue::Bind
(
"SimulatorImplementationType"
,
StringValue
(
"ns3::RealtimeSimulatorImpl"
));
84
GlobalValue::Bind
(
"ChecksumEnabled"
,
BooleanValue
(
true
));
85
86
//
87
// Create two ghost nodes. The first will represent the virtual machine host
88
// on the left side of the network; and the second will represent the VM on
89
// the right side.
90
//
91
NodeContainer
nodes
;
92
nodes
.
Create
(2);
93
94
//
95
// Use a CsmaHelper to get a CSMA channel created, and the needed net
96
// devices installed on both of the nodes. The data rate and delay for the
97
// channel can be set through the command-line parser. For example,
98
//
99
// ./ns3 run "tap-csma-virtual-machine --ns3::CsmaChannel::DataRate=10000000"
100
//
101
CsmaHelper
csma
;
102
NetDeviceContainer
devices
=
csma
.Install(
nodes
);
103
104
//
105
// Use the TapBridgeHelper to connect to the pre-configured tap devices for
106
// the left side. We go with "UseBridge" mode since the CSMA devices support
107
// promiscuous mode and can therefore make it appear that the bridge is
108
// extended into ns-3. The install method essentially bridges the specified
109
// tap to the specified CSMA device.
110
//
111
TapBridgeHelper
tapBridge;
112
tapBridge.
SetAttribute
(
"Mode"
,
StringValue
(
"UseBridge"
));
113
tapBridge.
SetAttribute
(
"DeviceName"
,
StringValue
(
"tap-left"
));
114
tapBridge.
Install
(
nodes
.
Get
(0),
devices
.Get(0));
115
116
//
117
// Connect the right side tap to the right side CSMA device on the right-side
118
// ghost node.
119
//
120
tapBridge.
SetAttribute
(
"DeviceName"
,
StringValue
(
"tap-right"
));
121
tapBridge.
Install
(
nodes
.
Get
(1),
devices
.Get(1));
122
123
//
124
// Run the simulation for ten minutes to give the user time to play around
125
//
126
Simulator::Stop
(
Seconds
(600.));
127
Simulator::Run
();
128
Simulator::Destroy
();
129
130
return
0;
131
}
ns3::BooleanValue
Definition:
boolean.h:37
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:232
ns3::CsmaHelper
build a set of CsmaNetDevice objects
Definition:
csma-helper.h:48
ns3::GlobalValue::Bind
static void Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
Definition:
global-value.cc:137
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition:
net-device-container.h:43
ns3::NodeContainer
keep track of a set of node pointers.
Definition:
node-container.h:40
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition:
node-container.cc:84
ns3::NodeContainer::Get
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Definition:
node-container.cc:78
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:142
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition:
simulator.cc:178
ns3::Simulator::Stop
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition:
simulator.cc:186
ns3::StringValue
Hold variables of type string.
Definition:
string.h:56
ns3::TapBridgeHelper
build TapBridge to allow ns-3 simulations to interact with Linux tap devices and processes on the Lin...
Definition:
tap-bridge-helper.h:38
ns3::TapBridgeHelper::Install
Ptr< NetDevice > Install(Ptr< Node > node, Ptr< NetDevice > nd)
This method installs a TapBridge on the specified Node and forms the bridge with the NetDevice specif...
Definition:
tap-bridge-helper.cc:61
ns3::TapBridgeHelper::SetAttribute
void SetAttribute(std::string n1, const AttributeValue &v1)
Set an attribute in the underlying TapBridge net device when these devices are automatically created.
Definition:
tap-bridge-helper.cc:46
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1326
nodes
NodeContainer nodes
Definition:
lr-wpan-bootstrap.cc:53
first.devices
devices
Definition:
first.py:42
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.csma
csma
Definition:
second.py:63
second.cmd
cmd
Definition:
second.py:40
src
tap-bridge
examples
tap-csma-virtual-machine.cc
Generated on Sun Mar 3 2024 17:11:08 for ns-3 by
1.9.1