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
tap-csma-virtual-machine.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
//
18
// This is an illustration of how one could use virtualization techniques to
19
// allow running applications on virtual machines talking over simulated
20
// networks.
21
//
22
// The actual steps required to configure the virtual machines can be rather
23
// involved, so we don't go into that here. Please have a look at one of
24
// our HOWTOs on the nsnam wiki for more details about how to get the
25
// system confgured. For an example, have a look at "HOWTO Use Linux
26
// Containers to set up virtual networks" which uses this code as an
27
// example.
28
//
29
// The configuration you are after is explained in great detail in the
30
// HOWTO, but looks like the following:
31
//
32
// +----------+ +----------+
33
// | virtual | | virtual |
34
// | Linux | | Linux |
35
// | Host | | Host |
36
// | | | |
37
// | eth0 | | eth0 |
38
// +----------+ +----------+
39
// | |
40
// +----------+ +----------+
41
// | Linux | | Linux |
42
// | Bridge | | Bridge |
43
// +----------+ +----------+
44
// | |
45
// +------------+ +-------------+
46
// | "tap-left" | | "tap-right" |
47
// +------------+ +-------------+
48
// | n0 n1 |
49
// | +--------+ +--------+ |
50
// +-------| tap | | tap |-------+
51
// | bridge | | bridge |
52
// +--------+ +--------+
53
// | CSMA | | CSMA |
54
// +--------+ +--------+
55
// | |
56
// | |
57
// | |
58
// ===============
59
// CSMA LAN
60
//
61
#include <iostream>
62
#include <fstream>
63
64
#include "ns3/core-module.h"
65
#include "ns3/network-module.h"
66
#include "ns3/csma-module.h"
67
#include "ns3/tap-bridge-module.h"
68
69
using namespace
ns3;
70
71
NS_LOG_COMPONENT_DEFINE
(
"TapCsmaVirtualMachineExample"
);
72
73
int
74
main
(
int
argc,
char
*argv[])
75
{
76
CommandLine
cmd;
77
cmd.
Parse
(argc, argv);
78
79
//
80
// We are interacting with the outside, real, world. This means we have to
81
// interact in real-time and therefore means we have to use the real-time
82
// simulator and take the time to calculate checksums.
83
//
84
GlobalValue::Bind
(
"SimulatorImplementationType"
,
StringValue
(
"ns3::RealtimeSimulatorImpl"
));
85
GlobalValue::Bind
(
"ChecksumEnabled"
,
BooleanValue
(
true
));
86
87
//
88
// Create two ghost nodes. The first will represent the virtual machine host
89
// on the left side of the network; and the second will represent the VM on
90
// the right side.
91
//
92
NodeContainer
nodes
;
93
nodes.
Create
(2);
94
95
//
96
// Use a CsmaHelper to get a CSMA channel created, and the needed net
97
// devices installed on both of the nodes. The data rate and delay for the
98
// channel can be set through the command-line parser. For example,
99
//
100
// ./waf --run "tap=csma-virtual-machine --ns3::CsmaChannel::DataRate=10000000"
101
//
102
CsmaHelper
csma;
103
NetDeviceContainer
devices
= csma.
Install
(nodes);
104
105
//
106
// Use the TapBridgeHelper to connect to the pre-configured tap devices for
107
// the left side. We go with "UseBridge" mode since the CSMA devices support
108
// promiscuous mode and can therefore make it appear that the bridge is
109
// extended into ns-3. The install method essentially bridges the specified
110
// tap to the specified CSMA device.
111
//
112
TapBridgeHelper
tapBridge;
113
tapBridge.
SetAttribute
(
"Mode"
,
StringValue
(
"UseBridge"
));
114
tapBridge.
SetAttribute
(
"DeviceName"
,
StringValue
(
"tap-left"
));
115
tapBridge.
Install
(nodes.
Get
(0), devices.
Get
(0));
116
117
//
118
// Connect the right side tap to the right side CSMA device on the right-side
119
// ghost node.
120
//
121
tapBridge.
SetAttribute
(
"DeviceName"
,
StringValue
(
"tap-right"
));
122
tapBridge.
Install
(nodes.
Get
(1), devices.
Get
(1));
123
124
//
125
// Run the simulation for ten minutes to give the user time to play around
126
//
127
Simulator::Stop
(Seconds (600.));
128
Simulator::Run
();
129
Simulator::Destroy
();
130
}
ns3::TapBridgeHelper::SetAttribute
void SetAttribute(std::string n1, const AttributeValue &v1)
Definition:
tap-bridge-helper.cc:45
ns3::BooleanValue
Hold a bool native type.
Definition:
boolean.h:38
first.devices
tuple devices
Definition:
first.py:32
ns3::NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
ns3::StringValue
hold variables of type string
Definition:
string.h:19
ns3::NetDeviceContainer::Get
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr
stored in this container at a given index.
Definition:
net-device-container.cc:62
ns3::Simulator::Run
static void Run(void)
Run the simulation until one of:
Definition:
simulator.cc:157
ns3::CsmaHelper::Install
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
Definition:
csma-helper.cc:215
main
int main(int argc, char *argv[])
Definition:
tap-csma-virtual-machine.cc:74
first.nodes
tuple nodes
Definition:
first.py:25
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition:
net-device-container.h:41
ns3::GlobalValue::Bind
static void Bind(std::string name, const AttributeValue &value)
Definition:
global-value.cc:150
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:152
ns3::Simulator::Destroy
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition:
simulator.cc:121
ns3::NodeContainer
keep track of a set of node pointers.
Definition:
node-container.h:38
ns3::CsmaHelper
build a set of CsmaNetDevice objects
Definition:
csma-helper.h:46
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::Simulator::Stop
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition:
simulator.cc:165
ns3::NodeContainer::Get
Ptr< Node > Get(uint32_t i) const
Get the Ptr
stored in this container at a given index.
Definition:
node-container.cc:88
ns3::CommandLine::Parse
void Parse(int argc, char *argv[])
Parse the program arguments.
Definition:
command-line.cc:104
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:36
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:93
src
tap-bridge
examples
tap-csma-virtual-machine.cc
Generated on Sat Apr 19 2014 14:07:09 for ns-3 by
1.8.6