1
# -*- Mode: Python; -*-
3
# Copyright 2010 University of Washington
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;
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.
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
29
# We are interacting with the outside, real, world. This means we have to
30
# interact in real-time and therefore we have to use the real-time simulator
31
# and take the time to calculate checksums.
33
ns.core.GlobalValue.Bind("SimulatorImplementationType", ns.core.StringValue("ns3::RealtimeSimulatorImpl"))
34
ns.core.GlobalValue.Bind("ChecksumEnabled", ns.core.BooleanValue("true"))
37
# Create two ghost nodes. The first will represent the virtual machine host
38
# on the left side of the network; and the second will represent the VM on
41
nodes = ns.network.NodeContainer()
45
# We're going to use 802.11 A so set up a wifi helper to reflect that.
47
wifi = ns.wifi.WifiHelper.Default()
48
wifi.SetStandard (ns.wifi.WIFI_PHY_STANDARD_80211a);
49
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", ns.core.StringValue ("OfdmRate54Mbps"));
52
# No reason for pesky access points, so we'll use an ad-hoc network.
54
wifiMac = ns.wifi.NqosWifiMacHelper.Default()
55
wifiMac.SetType ("ns3::AdhocWifiMac");
58
# Configure the physcial layer.
60
wifiChannel = ns.wifi.YansWifiChannelHelper.Default()
61
wifiPhy = ns.wifi.YansWifiPhyHelper.Default()
62
wifiPhy.SetChannel(wifiChannel.Create())
65
# Install the wireless devices onto our ghost nodes.
67
devices = wifi.Install(wifiPhy, wifiMac, nodes)
70
# We need location information since we are talking about wifi, so add a
71
# constant position to the ghost nodes.
73
mobility = ns.mobility.MobilityHelper()
74
positionAlloc = ns.mobility.ListPositionAllocator()
75
positionAlloc.Add(ns.core.Vector(0.0, 0.0, 0.0))
76
positionAlloc.Add(ns.core.Vector(5.0, 0.0, 0.0))
77
mobility.SetPositionAllocator(positionAlloc)
78
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel")
79
mobility.Install(nodes)
82
# Use the TapBridgeHelper to connect to the pre-configured tap devices for
83
# the left side. We go with "UseLocal" mode since the wifi devices do not
84
# support promiscuous mode (because of their natures0. This is a special
85
# case mode that allows us to extend a linux bridge into ns-3 IFF we will
86
# only see traffic from one other device on that bridge. That is the case
87
# for this configuration.
89
tapBridge = ns.tap_bridge.TapBridgeHelper()
90
tapBridge.SetAttribute ("Mode", ns.core.StringValue ("UseLocal"));
91
tapBridge.SetAttribute ("DeviceName", ns.core.StringValue ("tap-left"));
92
tapBridge.Install (nodes.Get (0), devices.Get (0));
95
# Connect the right side tap to the right side wifi device on the right-side
98
tapBridge.SetAttribute ("DeviceName", ns.core.StringValue ("tap-right"));
99
tapBridge.Install (nodes.Get (1), devices.Get (1));
102
# Run the simulation for ten minutes to give the user time to play around
104
ns.core.Simulator.Stop (ns.core.Seconds (600));
105
ns.core.Simulator.Run(signal_check_frequency = -1)
106
ns.core.Simulator.Destroy()
109
if __name__ == '__main__':
110
sys.exit(main(sys.argv))