A Discrete-Event Network Simulator
API
tap-wifi-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
19import sys
20from ns import ns
21
22def main(argv):
23
24 ns.core.CommandLine().Parse(argv)
25
26 #
27 # We are interacting with the outside, real, world. This means we have to
28 # interact in real-time and therefore we have to use the real-time simulator
29 # and take the time to calculate checksums.
30 #
31 ns.core.GlobalValue.Bind("SimulatorImplementationType", ns.core.StringValue("ns3::RealtimeSimulatorImpl"))
32 ns.core.GlobalValue.Bind("ChecksumEnabled", ns.core.BooleanValue(True))
33
34 #
35 # Create two ghost nodes. The first will represent the virtual machine host
36 # on the left side of the network; and the second will represent the VM on
37 # the right side.
38 #
39 nodes = ns.network.NodeContainer()
40 nodes.Create (2);
41
42 #
43 # We're going to use 802.11 A so set up a wifi helper to reflect that.
44 #
45 wifi = ns.wifi.WifiHelper()
46 wifi.SetStandard (ns.wifi.WIFI_STANDARD_80211a);
47 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", ns.core.StringValue ("OfdmRate54Mbps"));
48
49 #
50 # No reason for pesky access points, so we'll use an ad-hoc network.
51 #
52 wifiMac = ns.wifi.WifiMacHelper()
53 wifiMac.SetType ("ns3::AdhocWifiMac");
54
55 #
56 # Configure the physical layer.
57 #
58 wifiChannel = ns.wifi.YansWifiChannelHelper.Default()
59 wifiPhy = ns.wifi.YansWifiPhyHelper()
60 wifiPhy.SetChannel(wifiChannel.Create())
61
62 #
63 # Install the wireless devices onto our ghost nodes.
64 #
65 devices = wifi.Install(wifiPhy, wifiMac, nodes)
66
67 #
68 # We need location information since we are talking about wifi, so add a
69 # constant position to the ghost nodes.
70 #
71 mobility = ns.mobility.MobilityHelper()
72 positionAlloc = ns.mobility.ListPositionAllocator()
73 positionAlloc.Add(ns.core.Vector(0.0, 0.0, 0.0))
74 positionAlloc.Add(ns.core.Vector(5.0, 0.0, 0.0))
75 mobility.SetPositionAllocator(positionAlloc)
76 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel")
77 mobility.Install(nodes)
78
79 #
80 # Use the TapBridgeHelper to connect to the pre-configured tap devices for
81 # the left side. We go with "UseLocal" mode since the wifi devices do not
82 # support promiscuous mode (because of their natures0. This is a special
83 # case mode that allows us to extend a linux bridge into ns-3 IFF we will
84 # only see traffic from one other device on that bridge. That is the case
85 # for this configuration.
86 #
87 tapBridge = ns.tap_bridge.TapBridgeHelper()
88 tapBridge.SetAttribute ("Mode", ns.core.StringValue ("UseLocal"));
89 tapBridge.SetAttribute ("DeviceName", ns.core.StringValue ("tap-left"));
90 tapBridge.Install (nodes.Get (0), devices.Get (0));
91
92 #
93 # Connect the right side tap to the right side wifi device on the right-side
94 # ghost node.
95 #
96 tapBridge.SetAttribute ("DeviceName", ns.core.StringValue ("tap-right"));
97 tapBridge.Install (nodes.Get (1), devices.Get (1));
98
99 #
100 # Run the simulation for ten minutes to give the user time to play around
101 #
102 ns.core.Simulator.Stop (ns.core.Seconds (600));
103 ns.core.Simulator.Run()#signal_check_frequency = -1
104 ns.core.Simulator.Destroy()
105 return 0
106
107if __name__ == '__main__':
108 sys.exit(main(sys.argv))
109