diff --git a/examples/tap/tap-csma-virtual-machine.cc b/examples/tap/tap-csma-virtual-machine.cc index 518ae6ca8..e9eeb77b9 100644 --- a/examples/tap/tap-csma-virtual-machine.cc +++ b/examples/tap/tap-csma-virtual-machine.cc @@ -56,10 +56,7 @@ // | | // | | // =============== -// CSMA LAN 10.0.0 -// -// The CSMA device on node zero is: 10.0.0.1 -// The CSMA device on node one is: 10.0.0.2 +// CSMA LAN // #include #include diff --git a/examples/tap/tap-csma-virtual-machine.py b/examples/tap/tap-csma-virtual-machine.py new file mode 100644 index 000000000..10c812841 --- /dev/null +++ b/examples/tap/tap-csma-virtual-machine.py @@ -0,0 +1,76 @@ +# -*- Mode: Python; -*- +# +# Copyright 2010 University of Washington +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation; +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +import sys +import ns3 + +def main(argv): + # + # We are interacting with the outside, real, world. This means we have to + # interact in real-time and therefore we have to use the real-time simulator + # and take the time to calculate checksums. + # + ns3.GlobalValue.Bind("SimulatorImplementationType", ns3.StringValue("ns3::RealtimeSimulatorImpl")) + ns3.GlobalValue.Bind("ChecksumEnabled", ns3.BooleanValue("true")) + + # + # Create two ghost nodes. The first will represent the virtual machine host + # on the left side of the network; and the second will represent the VM on + # the right side. + # + nodes = ns3.NodeContainer() + nodes.Create (2) + + # + # Use a CsmaHelper to get a CSMA channel created, and the needed net + # devices installed on both of the nodes. The data rate and delay for the + # channel can be set through the command-line parser. + # + csma = ns3.CsmaHelper() + devices = csma.Install(nodes) + + # + # Use the TapBridgeHelper to connect to the pre-configured tap devices for + # the left side. We go with "UseLocal" mode since the wifi devices do not + # support promiscuous mode (because of their natures0. This is a special + # case mode that allows us to extend a linux bridge into ns-3 IFF we will + # only see traffic from one other device on that bridge. That is the case + # for this configuration. + # + tapBridge = ns3.TapBridgeHelper() + tapBridge.SetAttribute ("Mode", ns3.StringValue ("UseLocal")) + tapBridge.SetAttribute ("DeviceName", ns3.StringValue ("tap-left")) + tapBridge.Install (nodes.Get (0), devices.Get (0)) + + # + # Connect the right side tap to the right side wifi device on the right-side + # ghost node. + # + tapBridge.SetAttribute ("DeviceName", ns3.StringValue ("tap-right")) + tapBridge.Install (nodes.Get (1), devices.Get (1)) + + # + # Run the simulation for ten minutes to give the user time to play around + # + ns3.Simulator.Stop (ns3.Seconds (600)) + ns3.Simulator.Run(signal_check_frequency = -1) + ns3.Simulator.Destroy() + return 0 + +if __name__ == '__main__': + sys.exit(main(sys.argv)) diff --git a/examples/tap/tap-wifi-virtual-machine.cc b/examples/tap/tap-wifi-virtual-machine.cc index fb52858f5..919e94992 100644 --- a/examples/tap/tap-wifi-virtual-machine.cc +++ b/examples/tap/tap-wifi-virtual-machine.cc @@ -55,7 +55,7 @@ // | | // ((*)) ((*)) // -// Wifi LAN 10.0.0 +// Wifi LAN // // ((*)) // | @@ -66,10 +66,6 @@ // | point | // +--------+ // -// The wifi device on node zero is: 10.0.0.1 -// The wifi device on node one is: 10.0.0.2 -// The wifi device (AP) is: 10.0.0.3 -// #include #include diff --git a/examples/tap/tap-wifi-virtual-machine.py b/examples/tap/tap-wifi-virtual-machine.py new file mode 100644 index 000000000..42539327a --- /dev/null +++ b/examples/tap/tap-wifi-virtual-machine.py @@ -0,0 +1,106 @@ +# -*- Mode: Python; -*- +# +# Copyright 2010 University of Washington +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation; +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +import sys +import ns3 + +def main(argv): + # + # We are interacting with the outside, real, world. This means we have to + # interact in real-time and therefore we have to use the real-time simulator + # and take the time to calculate checksums. + # + ns3.GlobalValue.Bind("SimulatorImplementationType", ns3.StringValue("ns3::RealtimeSimulatorImpl")) + ns3.GlobalValue.Bind("ChecksumEnabled", ns3.BooleanValue("true")) + + # + # Create two ghost nodes. The first will represent the virtual machine host + # on the left side of the network; and the second will represent the VM on + # the right side. + # + nodes = ns3.NodeContainer() + nodes.Create (2); + + # + # We're going to use 802.11 A so set up a wifi helper to reflect that. + # + wifi = ns3.WifiHelper.Default() + wifi.SetStandard (ns3.WIFI_PHY_STANDARD_80211a); + wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", ns3.StringValue ("wifia-54mbs")); + + # + # No reason for pesky access points, so we'll use an ad-hoc network. + # + wifiMac = ns3.NqosWifiMacHelper.Default() + wifiMac.SetType ("ns3::AdhocWifiMac"); + + # + # Configure the physcial layer. + # + wifiChannel = ns3.YansWifiChannelHelper.Default() + wifiPhy = ns3.YansWifiPhyHelper.Default() + wifiPhy.SetChannel(wifiChannel.Create()) + + # + # Install the wireless devices onto our ghost nodes. + # + devices = wifi.Install(wifiPhy, wifiMac, nodes) + + # + # We need location information since we are talking about wifi, so add a + # constant position to the ghost nodes. + # + mobility = ns3.MobilityHelper() + positionAlloc = ns3.ListPositionAllocator() + positionAlloc.Add(ns3.Vector(0.0, 0.0, 0.0)) + positionAlloc.Add(ns3.Vector(5.0, 0.0, 0.0)) + mobility.SetPositionAllocator(positionAlloc) + mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel") + mobility.Install(nodes) + + # + # Use the TapBridgeHelper to connect to the pre-configured tap devices for + # the left side. We go with "UseLocal" mode since the wifi devices do not + # support promiscuous mode (because of their natures0. This is a special + # case mode that allows us to extend a linux bridge into ns-3 IFF we will + # only see traffic from one other device on that bridge. That is the case + # for this configuration. + # + tapBridge = ns3.TapBridgeHelper() + tapBridge.SetAttribute ("Mode", ns3.StringValue ("UseLocal")); + tapBridge.SetAttribute ("DeviceName", ns3.StringValue ("tap-left")); + tapBridge.Install (nodes.Get (0), devices.Get (0)); + + # + # Connect the right side tap to the right side wifi device on the right-side + # ghost node. + # + tapBridge.SetAttribute ("DeviceName", ns3.StringValue ("tap-right")); + tapBridge.Install (nodes.Get (1), devices.Get (1)); + + # + # Run the simulation for ten minutes to give the user time to play around + # + ns3.Simulator.Stop (ns3.Seconds (600)); + ns3.Simulator.Run(signal_check_frequency = -1) + ns3.Simulator.Destroy() + return 0 + +if __name__ == '__main__': + sys.exit(main(sys.argv)) + diff --git a/examples/tap/virtual-network-setup.sh b/examples/tap/virtual-network-setup.sh new file mode 100755 index 000000000..929c6ffe2 --- /dev/null +++ b/examples/tap/virtual-network-setup.sh @@ -0,0 +1,16 @@ +#!/bin/sh +brctl addbr br-left +brctl addbr br-right +tunctl -t tap-left +tunctl -t tap-right +ifconfig tap-left 0.0.0.0 promisc up +ifconfig tap-right 0.0.0.0 promisc up +brctl addif br-left tap-left +ifconfig br-left up +brctl addif br-right tap-right +ifconfig br-right up +pushd /proc/sys/net/bridge +for f in bridge-nf-*; do echo 0 > $f; done +popd +lxc-create -n left -f lxc-left.conf +lxc-create -n right -f lxc-right.conf diff --git a/examples/tap/virtual-network-teardown.sh b/examples/tap/virtual-network-teardown.sh new file mode 100755 index 000000000..21f26e31d --- /dev/null +++ b/examples/tap/virtual-network-teardown.sh @@ -0,0 +1,13 @@ +#!/bin/sh +lxc-destroy -n left +lxc-destroy -n right +ifconfig br-left down +ifconfig br-right down +brctl delif br-left tap-left +brctl delif br-right tap-right +brctl delbr br-left +brctl delbr br-right +ifconfig tap-left down +ifconfig tap-right down +tunctl -d tap-left +tunctl -d tap-right