A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
tap-csma-virtual-machine.py
Go to the documentation of this file.
1
# -*- Mode: Python; -*-
2
#
3
# Copyright 2010 University of Washington
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License version 2 as
7
# published by the Free Software Foundation;
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
#
18
19
import
sys
20
21
try
:
22
from
ns
import
ns
23
except
ModuleNotFoundError:
24
raise
SystemExit(
25
"Error: ns3 Python module not found;"
26
" Python bindings may not be enabled"
27
" or your PYTHONPATH might not be properly configured"
28
)
29
30
31
def
main(argv):
32
ns.CommandLine().Parse(argv)
33
34
#
35
# We are interacting with the outside, real, world. This means we have to
36
# interact in real-time and therefore we have to use the real-time simulator
37
# and take the time to calculate checksums.
38
#
39
ns.GlobalValue.Bind(
"SimulatorImplementationType"
, ns.StringValue(
"ns3::RealtimeSimulatorImpl"
))
40
ns.GlobalValue.Bind(
"ChecksumEnabled"
, ns.BooleanValue(
True
))
41
42
#
43
# Create two ghost nodes. The first will represent the virtual machine host
44
# on the left side of the network; and the second will represent the VM on
45
# the right side.
46
#
47
nodes = ns.NodeContainer()
48
nodes.Create(2)
49
50
#
51
# Use a CsmaHelper to get a CSMA channel created, and the needed net
52
# devices installed on both of the nodes. The data rate and delay for the
53
# channel can be set through the command-line parser.
54
#
55
csma = ns.CsmaHelper()
56
devices = csma.Install(nodes)
57
58
#
59
# Use the TapBridgeHelper to connect to the pre-configured tap devices for
60
# the left side. We go with "UseLocal" mode since the wifi devices do not
61
# support promiscuous mode (because of their natures0. This is a special
62
# case mode that allows us to extend a linux bridge into ns-3 IFF we will
63
# only see traffic from one other device on that bridge. That is the case
64
# for this configuration.
65
#
66
tapBridge = ns.TapBridgeHelper()
67
tapBridge.SetAttribute(
"Mode"
, ns.StringValue(
"UseLocal"
))
68
tapBridge.SetAttribute(
"DeviceName"
, ns.StringValue(
"tap-left"
))
69
tapBridge.Install(nodes.Get(0), devices.Get(0))
70
71
#
72
# Connect the right side tap to the right side wifi device on the right-side
73
# ghost node.
74
#
75
tapBridge.SetAttribute(
"DeviceName"
, ns.StringValue(
"tap-right"
))
76
tapBridge.Install(nodes.Get(1), devices.Get(1))
77
78
#
79
# Run the simulation for ten minutes to give the user time to play around
80
#
81
ns.Simulator.Stop(ns.Seconds(600))
82
ns.Simulator.Run()
# signal_check_frequency = -1
83
ns.Simulator.Destroy()
84
return
0
85
86
87
if
__name__ ==
"__main__"
:
88
sys.exit(main(sys.argv))
src
tap-bridge
examples
tap-csma-virtual-machine.py
Generated on Tue May 28 2024 23:39:31 for ns-3 by
1.9.6