Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions src/tap-bridge/examples/tap-csma-virtual-machine-parsa.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// DO-NOT-REMOVE begin-copyright-block
// QFlex consists of several software components that are governed by various
// licensing terms, in addition to software that was developed internally.
// Anyone interested in using QFlex needs to fully understand and abide by the
// licenses governing all the software components.
//
// ### Software developed externally (not by the QFlex group)
//
// * [NS-3] (https://www.gnu.org/copyleft/gpl.html)
// * [QEMU] (http://wiki.qemu.org/License)
// * [SimFlex] (http://parsa.epfl.ch/simflex/)
// * [GNU PTH] (https://www.gnu.org/software/pth/)
//
// ### Software developed internally (by the QFlex group)
// **QFlex License**
//
// QFlex
// Copyright (c) 2020, Parallel Systems Architecture Lab, EPFL
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Parallel Systems Architecture Laboratory, EPFL,
// nor the names of its contributors may be used to endorse or promote
// products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE PARALLEL SYSTEMS ARCHITECTURE LABORATORY,
// EPFL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// DO-NOT-REMOVE end-copyright-block

//
// 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
//
#include <iostream>
#include <fstream>

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/tap-bridge-module.h"
#include <stdio.h>

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("TapCsmaVirtualMachineExample");

int
main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);

int numnodes = argc-1;

//
// 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));

//
// 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.
//
NodeContainer nodes;
nodes.Create (numnodes);

//
// 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. For example,
//
// ./waf --run "tap=csma-virtual-machine --ns3::CsmaChannel::DataRate=10000000"
//
CsmaHelper csma;
NetDeviceContainer devices = csma.Install (nodes);

//
// Use the TapBridgeHelper to connect to the pre-configured tap devices for
// the left side. We go with "UseBridge" mode since the CSMA devices support
// promiscuous mode and can therefore make it appear that the bridge is
// extended into ns-3. The install method essentially bridges the specified
// tap to the specified CSMA device.
//
TapBridgeHelper tapBridge;
tapBridge.SetAttribute ("Mode", StringValue ("UseBridge"));

for (int i =1; i <= numnodes; ++i)
{
tapBridge.SetAttribute ("DeviceName", StringValue (argv[i]));
tapBridge.Install (nodes.Get (i-1), devices.Get (i-1));
}
//
// Run the simulation for ten minutes to give the user time to play around
//
//Simulator::Stop (Seconds (60000.)); // 1000 minutes
Simulator::Run ();
Simulator::Destroy ();
}
47 changes: 47 additions & 0 deletions src/tap-bridge/examples/wscript
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
# DO-NOT-REMOVE begin-copyright-block
# QFlex consists of several software components that are governed by various
# licensing terms, in addition to software that was developed internally.
# Anyone interested in using QFlex needs to fully understand and abide by the
# licenses governing all the software components.
#
# ### Software developed externally (not by the QFlex group)
#
# * [NS-3] (https://www.gnu.org/copyleft/gpl.html)
# * [QEMU] (http://wiki.qemu.org/License)
# * [SimFlex] (http://parsa.epfl.ch/simflex/)
# * [GNU PTH] (https://www.gnu.org/software/pth/)
#
# ### Software developed internally (by the QFlex group)
# **QFlex License**
#
# QFlex
# Copyright (c) 2020, Parallel Systems Architecture Lab, EPFL
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of the Parallel Systems Architecture Laboratory, EPFL,
# nor the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE PARALLEL SYSTEMS ARCHITECTURE LABORATORY,
# EPFL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# DO-NOT-REMOVE end-copyright-block

## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-

def build(bld):
Expand All @@ -7,6 +52,8 @@ def build(bld):
obj.source = 'tap-csma.cc'
obj = bld.create_ns3_program('tap-csma-virtual-machine', ['csma', 'tap-bridge', 'internet'])
obj.source = 'tap-csma-virtual-machine.cc'
obj = bld.create_ns3_program('tap-csma-virtual-machine-parsa', ['csma', 'tap-bridge', 'internet'])
obj.source = 'tap-csma-virtual-machine-parsa.cc'
bld.register_ns3_script('tap-csma-virtual-machine.py', ['csma', 'tap-bridge', 'internet'])
obj = bld.create_ns3_program('tap-wifi-virtual-machine', ['csma', 'tap-bridge', 'internet', 'wifi', 'mobility'])
obj.source = 'tap-wifi-virtual-machine.cc'
Expand Down