std::string mode = "UseLocal";
std::string tapName = "tap-left";
CommandLine cmd;
cmd.AddValue ("mode", "Mode setting of TapBridge", mode);
cmd.AddValue ("tapName", "Name of the OS tap device", tapName);
cmd.Parse (argc, argv);
GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));
GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
//
// The topology has a Wifi network of four nodes on the left side. We'll make
// node zero the AP and have the other three will be the STAs.
//
NodeContainer nodesLeft;
nodesLeft.Create (4);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
Ssid ssid = Ssid ("left");
WifiHelper wifi = WifiHelper::Default ();
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
wifiMac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer devicesLeft = wifi.Install (wifiPhy, wifiMac, nodesLeft.Get (0));
wifiMac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
devicesLeft.Add (wifi.Install (wifiPhy, wifiMac, NodeContainer (nodesLeft.Get (1), nodesLeft.Get (2), nodesLeft.Get (3))));
MobilityHelper mobility;
mobility.Install (nodesLeft);
InternetStackHelper internetLeft;
internetLeft.Install (nodesLeft);
Ipv4AddressHelper ipv4Left;
ipv4Left.SetBase ("10.0.0.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesLeft = ipv4Left.Assign (devicesLeft);
TapBridgeHelper tapBridge;
tapBridge.SetAttribute ("Mode", StringValue (mode));
tapBridge.SetAttribute ("DeviceName", StringValue (tapName));
tapBridge.Install (nodesLeft.Get (0), devicesLeft.Get (0));
tapBridge.SetAttribute ("DeviceName", StringValue ("tap-right"));
tapBridge.Install (nodesLeft.Get (1), devicesLeft.Get (1));
//
// Run the simulation for ten minutes to give the user time to play around
//
Simulator::Stop (Seconds (600.));
Simulator::Run ();
Simulator::Destroy ();
#Create bridge and tap net devices
sudo brctl addbr br-left
sudo brctl addbr br-right
sudo tunctl -t tap-left
sudo tunctl -t tap-right
sudo ifconfig tap-left 0.0.0.0 promisc up
sudo ifconfig tap-right 0.0.0.0 promisc up
sudo brctl addif br-left tap-left
sudo ifconfig br-left up
sudo brctl addif br-right tap-right
sudo ifconfig br-right up
cd /proc/sys/net/bridgesudo -sfor f in bridge-nf-*; do echo 0 > $f; done
exitcd -
# Create linux containers with conf file in ns3-allinone/src/tap-bridge/examples
sudo lxc-create -n left -f lxc-left.conf
sudo lxc-create -n right -f lxc-right.conf
sudo lxc-start -n left /bin/bash
sudo lxc-start -n right /bin/bash
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- *//* * 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 */
//// This is an illustration of how one could use virtualization techniques to// allow running applications on virtual machines talking over simulated// networks.//// The actual steps required to configure the virtual machines can be rather// involved, so we don't go into that here. Please have a look at one of// our HOWTOs on the nsnam wiki for more details about how to get the // system confgured. For an example, have a look at "HOWTO Use Linux // Containers to set up virtual networks" which uses this code as an // example.//// The configuration you are after is explained in great detail in the // HOWTO, but looks like the following://// +----------+ +----------+// | virtual | | virtual |// | Linux | | Linux |// | Host | | Host |// | | | |// | eth0 | | eth0 |// +----------+ +----------+// | |// +----------+ +----------+// | Linux | | Linux |// | Bridge | | Bridge |// +----------+ +----------+// | |// +------------+ +-------------+// | "tap-" | | "tap-right" |// +------------+ +-------------+// | n0 n1 |// | +--------+ +--------+ |// +-------| tap | | tap |-------+// | bridge | | bridge |// +--------+ +--------+// | wifi | | wifi |// +--------+ +--------+// | |// ((*)) ((*))//// Wifi LAN//// ((*))// |// +--------+// | wifi |// +--------+// | access |// | point |// +--------+//
#include <iostream>#include <fstream>
#include "ns3/core-module.h"#include "ns3/network-module.h"#include "ns3/mobility-module.h"#include "ns3/point-to-point-module.h"#include "ns3/wifi-module.h"#include "ns3/internet-module.h"#include "ns3/csma-module.h"#include "ns3/applications-module.h"#include "ns3/ipv4-global-routing-helper.h"#include "ns3/tap-bridge-module.h"using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("TapWifiVirtualMachineExample");
int main (int argc, char *argv[]){
// // We are interacting with the outside, real, world. This means we have to // interact in real-time and therefore means we have to use the real-time // simulator and take the time to calculate checksums. //
GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl")); GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
std::string mode = "UseLocal"; std::string tapName = "tap-left";
CommandLine cmd; cmd.AddValue ("mode", "Mode setting of TapBridge", mode); cmd.AddValue ("tapName", "Name of the OS tap device", tapName); cmd.Parse (argc, argv);
//
// The topology has a Wifi network of four nodes on the side. We'll make
// node zero the AP and have the other three will be the STAs. //
NodeContainer nodes; nodes.Create (4);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); wifiPhy.SetChannel (wifiChannel.Create ());
Ssid ssid = Ssid ("WiFi");
WifiHelper wifi = WifiHelper::Default (); NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid));
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, nodes.Get (0));
wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid), "ActiveProbing", BooleanValue (false));
devices.Add (wifi.Install (wifiPhy, wifiMac, NodeContainer (nodes.Get (1), nodes.Get (2), nodes.Get (3))));
MobilityHelper mobility; mobility.Install (nodes);
InternetStackHelper internet; internet.Install (nodes);
Ipv4AddressHelper ipv4; ipv4.SetBase ("10.0.0.0", "255.255.255.0"); Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);
TapBridgeHelper tapBridge; tapBridge.SetAttribute ("Mode", StringValue (mode)); tapBridge.SetAttribute ("DeviceName", StringValue (tapName));
tapBridge.Install (nodes.Get (1), devices.Get (1));
tapBridge.SetAttribute ("DeviceName", StringValue ("tap-right"));
tapBridge.Install (nodes.Get (2), devices.Get (2));
// // Run the simulation for ten minutes to give the user time to play around // Simulator::Stop (Seconds (600.)); Simulator::Run (); Simulator::Destroy ();}
...