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
# SPDX-License-Identifier: GPL-2.0-only
6
#
7
8
import
sys
9
10
try
:
11
from
ns
import
ns
12
except
ModuleNotFoundError:
13
raise
SystemExit(
14
"Error: ns3 Python module not found;"
15
" Python bindings may not be enabled"
16
" or your PYTHONPATH might not be properly configured"
17
)
18
19
20
def
main(argv):
21
ns.CommandLine().Parse(argv)
22
23
#
24
# We are interacting with the outside, real, world. This means we have to
25
# interact in real-time and therefore we have to use the real-time simulator
26
# and take the time to calculate checksums.
27
#
28
ns.GlobalValue.Bind(
"SimulatorImplementationType"
, ns.StringValue(
"ns3::RealtimeSimulatorImpl"
))
29
ns.GlobalValue.Bind(
"ChecksumEnabled"
, ns.BooleanValue(
True
))
30
31
#
32
# Create two ghost nodes. The first will represent the virtual machine host
33
# on the left side of the network; and the second will represent the VM on
34
# the right side.
35
#
36
nodes = ns.NodeContainer()
37
nodes.Create(2)
38
39
#
40
# Use a CsmaHelper to get a CSMA channel created, and the needed net
41
# devices installed on both of the nodes. The data rate and delay for the
42
# channel can be set through the command-line parser.
43
#
44
csma = ns.CsmaHelper()
45
devices = csma.Install(nodes)
46
47
#
48
# Use the TapBridgeHelper to connect to the pre-configured tap devices for
49
# the left side. We go with "UseLocal" mode since the wifi devices do not
50
# support promiscuous mode (because of their natures0. This is a special
51
# case mode that allows us to extend a linux bridge into ns-3 IFF we will
52
# only see traffic from one other device on that bridge. That is the case
53
# for this configuration.
54
#
55
tapBridge = ns.TapBridgeHelper()
56
tapBridge.SetAttribute(
"Mode"
, ns.StringValue(
"UseLocal"
))
57
tapBridge.SetAttribute(
"DeviceName"
, ns.StringValue(
"tap-left"
))
58
tapBridge.Install(nodes.Get(0), devices.Get(0))
59
60
#
61
# Connect the right side tap to the right side wifi device on the right-side
62
# ghost node.
63
#
64
tapBridge.SetAttribute(
"DeviceName"
, ns.StringValue(
"tap-right"
))
65
tapBridge.Install(nodes.Get(1), devices.Get(1))
66
67
#
68
# Run the simulation for ten minutes to give the user time to play around
69
#
70
ns.Simulator.Stop(ns.Seconds(600))
71
ns.Simulator.Run()
# signal_check_frequency = -1
72
ns.Simulator.Destroy()
73
return
0
74
75
76
if
__name__ ==
"__main__"
:
77
sys.exit(main(sys.argv))
src
tap-bridge
examples
tap-csma-virtual-machine.py
Generated on Fri Nov 8 2024 13:59:06 for ns-3 by
1.11.0