add example for linux containers
This commit is contained in:
1 parent
acb120543a
commit
df784ebd94
4 files changed
+131
No files matched your search
@@ -0,0 +1,7 @@
|
||||
# Container with network virtualized using a pre-configured bridge named br0 and
|
||||
# veth pair virtual network devices
|
||||
lxc.utsname = left
|
||||
lxc.network.type = veth
|
||||
lxc.network.flags = up
|
||||
lxc.network.link = br-left
|
||||
lxc.network.ipv4 = 10.0.2.100/24
|
||||
@@ -0,0 +1,7 @@
|
||||
# Container with network virtualized using a pre-configured bridge named br0 and
|
||||
# veth pair virtual network devices
|
||||
lxc.utsname = right
|
||||
lxc.network.type = veth
|
||||
lxc.network.flags = up
|
||||
lxc.network.link = br-right
|
||||
lxc.network.ipv4 = 10.0.2.101/24
|
||||
@@ -0,0 +1,115 @@
|
||||
/* -*- 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-left" | | "tap-right" |
|
||||
// +------------+ +-------------+
|
||||
// | n0 n1 |
|
||||
// | +--------+ +--------+ |
|
||||
// +-------| tap | | tap |-------+
|
||||
// | bridge | | bridge |
|
||||
// +--------+ +--------+
|
||||
// | CSMA | | CSMA |
|
||||
// +--------+ +--------+
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// ===============
|
||||
// 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
|
||||
//
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "ns3/simulator-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/wifi-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("TapCsmaVirtualMachineExample");
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
CommandLine cmd;
|
||||
cmd.Parse (argc, argv);
|
||||
|
||||
GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));
|
||||
GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
|
||||
|
||||
NodeContainer nodes;
|
||||
nodes.Create (2);
|
||||
|
||||
CsmaHelper csma;
|
||||
csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
|
||||
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
|
||||
|
||||
NetDeviceContainer devices = csma.Install (nodes);
|
||||
|
||||
InternetStackHelper stack;
|
||||
stack.Install (nodes);
|
||||
|
||||
Ipv4AddressHelper addresses;
|
||||
addresses.SetBase ("10.0.2.0", "255.255.255.0", "0.0.0.100");
|
||||
Ipv4InterfaceContainer interfaces = addresses.Assign (devices);
|
||||
|
||||
TapBridgeHelper tapBridge;
|
||||
tapBridge.SetAttribute ("Mode", StringValue ("UseBridge"));
|
||||
tapBridge.SetAttribute ("DeviceName", StringValue ("tap-left"));
|
||||
tapBridge.Install (nodes.Get (0), devices.Get (0));
|
||||
|
||||
tapBridge.SetAttribute ("DeviceName", StringValue ("tap-right"));
|
||||
tapBridge.Install (nodes.Get (1), devices.Get (1));
|
||||
|
||||
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
|
||||
|
||||
Simulator::Stop (Seconds (600.));
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
}
|
||||
@@ -5,5 +5,7 @@ def build(bld):
|
||||
if env['ENABLE_TAP']:
|
||||
obj = bld.create_ns3_program('tap-csma', ['csma', 'tap-bridge', 'internet-stack'])
|
||||
obj.source = 'tap-csma.cc'
|
||||
obj = bld.create_ns3_program('tap-csma-virtual-machine', ['csma', 'tap-bridge', 'internet-stack'])
|
||||
obj.source = 'tap-csma-virtual-machine.cc'
|
||||
obj = bld.create_ns3_program('tap-wifi-dumbbell', ['wifi', 'csma', 'point-to-point', 'tap-bridge', 'internet-stack'])
|
||||
obj.source = 'tap-wifi-dumbbell.cc'
|
||||
Reference in new issue
Block a user