~ubuntu-branches/ubuntu/quantal/ns3/quantal

« back to all changes in this revision

Viewing changes to ns-3.12.1/src/tap-bridge/examples/tap-wifi-virtual-machine.py

  • Committer: Package Import Robot
  • Author(s): YunQiang Su, Aron Xu, YunQiang Su, Upstream
  • Date: 2012-01-06 00:35:42 UTC
  • mfrom: (10.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20120106003542-vcn5g03mhapm991h
Tags: 3.13+dfsg-1
[ Aron Xu ]:
        add tag binary and binary-indep, 
  for not build doc when --binary-arch (Closes: #654493).
[ YunQiang Su ]
        add waf 1.5/1.6 source to debian directory, 
  and build waf from there (Closes: #642217).
[ Upstream ]
  Successfully link with --as-needed option (Closes: #642225).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
import ns.core
21
 
import ns.internet
22
 
import ns.mobility
23
 
import ns.network
24
 
import ns.tap_bridge
25
 
import ns.wifi
26
 
 
27
 
def main(argv):
28
 
    #
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.
32
 
    #
33
 
    ns.core.GlobalValue.Bind("SimulatorImplementationType", ns.core.StringValue("ns3::RealtimeSimulatorImpl"))
34
 
    ns.core.GlobalValue.Bind("ChecksumEnabled", ns.core.BooleanValue("true"))
35
 
 
36
 
    #
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 
39
 
    # the right side.
40
 
    #
41
 
    nodes = ns.network.NodeContainer()
42
 
    nodes.Create (2);
43
 
 
44
 
    #
45
 
    # We're going to use 802.11 A so set up a wifi helper to reflect that.
46
 
    #
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"));
50
 
 
51
 
    #
52
 
    # No reason for pesky access points, so we'll use an ad-hoc network.
53
 
    #
54
 
    wifiMac = ns.wifi.NqosWifiMacHelper.Default()
55
 
    wifiMac.SetType ("ns3::AdhocWifiMac");
56
 
 
57
 
    #
58
 
    # Configure the physcial layer.
59
 
    #
60
 
    wifiChannel = ns.wifi.YansWifiChannelHelper.Default()
61
 
    wifiPhy = ns.wifi.YansWifiPhyHelper.Default()
62
 
    wifiPhy.SetChannel(wifiChannel.Create())
63
 
 
64
 
    #
65
 
    # Install the wireless devices onto our ghost nodes.
66
 
    #
67
 
    devices = wifi.Install(wifiPhy, wifiMac, nodes)
68
 
 
69
 
    #
70
 
    # We need location information since we are talking about wifi, so add a
71
 
    # constant position to the ghost nodes.
72
 
    #
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)
80
 
 
81
 
    #
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.
88
 
    #
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));
93
 
 
94
 
    #
95
 
    # Connect the right side tap to the right side wifi device on the right-side
96
 
    # ghost node.
97
 
    #
98
 
    tapBridge.SetAttribute ("DeviceName", ns.core.StringValue ("tap-right"));
99
 
    tapBridge.Install (nodes.Get (1), devices.Get (1));
100
 
 
101
 
    #
102
 
    # Run the simulation for ten minutes to give the user time to play around
103
 
    #
104
 
    ns.core.Simulator.Stop (ns.core.Seconds (600));
105
 
    ns.core.Simulator.Run(signal_check_frequency = -1)
106
 
    ns.core.Simulator.Destroy()
107
 
    return 0
108
 
 
109
 
if __name__ == '__main__':
110
 
    sys.exit(main(sys.argv))
111