A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
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
import
ns.core
22
import
ns.csma
23
import
ns.internet
24
import
ns.network
25
import
ns.tap_bridge
26
27
def
main(argv):
28
29
ns.core.CommandLine().Parse(argv)
30
31
#
32
# We are interacting with the outside, real, world. This means we have to
33
# interact in real-time and therefore we have to use the real-time simulator
34
# and take the time to calculate checksums.
35
#
36
ns.core.GlobalValue.Bind(
"SimulatorImplementationType"
, ns.core.StringValue(
"ns3::RealtimeSimulatorImpl"
))
37
ns.core.GlobalValue.Bind(
"ChecksumEnabled"
, ns.core.BooleanValue(
"true"
))
38
39
#
40
# Create two ghost nodes. The first will represent the virtual machine host
41
# on the left side of the network; and the second will represent the VM on
42
# the right side.
43
#
44
nodes = ns.network.NodeContainer()
45
nodes.Create (2)
46
47
#
48
# Use a CsmaHelper to get a CSMA channel created, and the needed net
49
# devices installed on both of the nodes. The data rate and delay for the
50
# channel can be set through the command-line parser.
51
#
52
csma = ns.csma.CsmaHelper()
53
devices = csma.Install(nodes)
54
55
#
56
# Use the TapBridgeHelper to connect to the pre-configured tap devices for
57
# the left side. We go with "UseLocal" mode since the wifi devices do not
58
# support promiscuous mode (because of their natures0. This is a special
59
# case mode that allows us to extend a linux bridge into ns-3 IFF we will
60
# only see traffic from one other device on that bridge. That is the case
61
# for this configuration.
62
#
63
tapBridge = ns.tap_bridge.TapBridgeHelper()
64
tapBridge.SetAttribute (
"Mode"
, ns.core.StringValue (
"UseLocal"
))
65
tapBridge.SetAttribute (
"DeviceName"
, ns.core.StringValue (
"tap-left"
))
66
tapBridge.Install (nodes.Get (0), devices.Get (0))
67
68
#
69
# Connect the right side tap to the right side wifi device on the right-side
70
# ghost node.
71
#
72
tapBridge.SetAttribute (
"DeviceName"
, ns.core.StringValue (
"tap-right"
))
73
tapBridge.Install (nodes.Get (1), devices.Get (1))
74
75
#
76
# Run the simulation for ten minutes to give the user time to play around
77
#
78
ns.core.Simulator.Stop (ns.core.Seconds (600))
79
ns.core.Simulator.Run(signal_check_frequency = -1)
80
ns.core.Simulator.Destroy()
81
return
0
82
83
if
__name__ ==
'__main__'
:
84
sys.exit(main(sys.argv))
src
tap-bridge
examples
tap-csma-virtual-machine.py
Generated on Tue Feb 6 2024 19:21:27 for ns-3 by
1.9.1