Skip to content

Instantly share code, notes, and snippets.

@thehajime
Last active December 27, 2015 05:29
Show Gist options
  • Save thehajime/7274852 to your computer and use it in GitHub Desktop.
Save thehajime/7274852 to your computer and use it in GitHub Desktop.
mswim 2013 demonstration: patch for ns-3-dce (54522b2a6868)
# HG changeset patch
# Parent be0c6459871fd508ae98beef511c752933e94f9c
diff -r be0c6459871f example/dce-mptcp-handoff-v6.cc
--- a/example/dce-mptcp-handoff-v6.cc Tue Oct 15 12:34:15 2013 +0900
+++ b/example/dce-mptcp-handoff-v6.cc Fri Nov 01 21:02:30 2013 +0900
@@ -80,13 +80,13 @@
Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
x->SetAttribute ("Min", DoubleValue (0.0));
x->SetAttribute ("Max", DoubleValue (100.0));
- r_position->SetX (85);
+ r_position->SetX (30);
r_position->SetY (100);
r_position->SetRho (x);
mobility.SetPositionAllocator (r_position);
mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
- "Bounds", RectangleValue (Rectangle (0, 100, 30, 60)),
- "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=10.0]"),
+ "Bounds", RectangleValue (Rectangle (-50, 150, 30, 60)),
+ "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=30.0]"),
"Pause", StringValue ("ns3::ConstantRandomVariable[Constant=0.2]"));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (mn);
diff -r be0c6459871f example/dce-mptcp-lte-wifi-v6.cc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/example/dce-mptcp-lte-wifi-v6.cc Fri Nov 01 21:02:30 2013 +0900
@@ -0,0 +1,335 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+
+//
+// Handoff scenario with Multipath TCPed iperf
+//
+// Simulation Topology:
+// Scenario: MN moves from under AR1 to AR2 (Wi-Fi AP), changing its IP address.
+// during movement, MN keeps iperf session to SV.
+//
+// +----------+
+// | SV |
+// +----+-----+
+// |
+// sim1|
+// sim2 +----+--+--+ sim0
+// +-----| R |------+
+// | +----------+ |
+// | |
+// | |
+// |sim0 |sim0
+// +----+---+ +----+---+
+// | AR1 | | LTE BS |
+// +---+----+ +----+---+
+// |sim1 |sim1
+// | +----------------+
+// ::::: (always in range)
+// |sim1 |sim1 |
+// +---------+ (Movement) +--------+ |
+// | MN | <=====> | MN +-----------+
+// +---------+ +--------+ sim0 (LteUe)
+
+#include "ns3/network-module.h"
+#include "ns3/core-module.h"
+#include "ns3/internet-module.h"
+#include "ns3/dce-module.h"
+#include "ns3/point-to-point-helper.h"
+#include "ns3/wifi-module.h"
+#include "ns3/lte-module.h"
+#include "ns3/yans-wifi-helper.h"
+#include "ns3/nqos-wifi-mac-helper.h"
+#include "ns3/mobility-module.h"
+#include "ns3/quagga-helper.h"
+
+
+using namespace ns3;
+NS_LOG_COMPONENT_DEFINE ("DceMptcpLteWifiV6");
+
+
+static void AddAddress (Ptr<Node> node, Time at, const char *name, const char *address)
+{
+ std::ostringstream oss;
+ oss << "-f inet6 addr add " << address << " dev " << name;
+ LinuxStackHelper::RunIp (node, at, oss.str ());
+}
+
+void setPos (Ptr<Node> n, int x, int y, int z)
+{
+ Ptr<ConstantPositionMobilityModel> loc = CreateObject<ConstantPositionMobilityModel> ();
+ n->AggregateObject (loc);
+ Vector locVec2 (x, y, z);
+ loc->SetPosition (locVec2);
+}
+
+int main (int argc, char *argv[])
+{
+ CommandLine cmd;
+ double errRate = 0.00;
+ cmd.AddValue ("errRate", "Rcv error rate.", errRate);
+ cmd.Parse (argc, argv);
+
+ GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
+ NodeContainer mn, sv, ar, ltebs, router;
+ sv.Create (1);
+ router.Create (1);
+ ar.Create (1);
+ mn.Create (1);
+
+ MobilityHelper mobility;
+ Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
+ positionAlloc->Add (Vector (50.0, -75.0, 0.0)); // SV
+ positionAlloc->Add (Vector (50.0, -50.0, 0.0)); // R
+ positionAlloc->Add (Vector (0.0, 10.0, 0.0)); // AR1
+ // positionAlloc->Add (Vector (100.0, 10.0, 0.0)); // LTE-BS
+ mobility.SetPositionAllocator (positionAlloc);
+ mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+ mobility.Install (sv);
+ mobility.Install (router);
+ mobility.Install (ar);
+
+ Ptr<ns3::RandomDiscPositionAllocator> r_position =
+ CreateObject<RandomDiscPositionAllocator> ();
+ Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
+ x->SetAttribute ("Min", DoubleValue (0.0));
+ x->SetAttribute ("Max", DoubleValue (200.0));
+ r_position->SetX (30);
+ r_position->SetY (80);
+ r_position->SetRho (x);
+ mobility.SetPositionAllocator (r_position);
+ mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
+ "Bounds", RectangleValue (Rectangle (-200, 60, 0, 70)),
+ "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=30.0]"),
+ "Pause", StringValue ("ns3::ConstantRandomVariable[Constant=0.2]"));
+ // mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+ mobility.Install (mn);
+
+
+ // LTE
+ Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
+ Ptr<EpcHelper> epcHelper = CreateObject<EpcHelper> ();
+
+ // Down link: MN1 <-> LTE-BS
+ NodeContainer enbNodes;
+ enbNodes.Create(1);
+ lteHelper->SetEpcHelper (epcHelper);
+ Ptr<Node> pgw = epcHelper->GetPgwNode ();
+ setPos (enbNodes.Get (0), 90, -10, 0);
+
+ NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes);
+ NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (mn.Get (0));
+
+ // LTE-BS <-> R
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ Ptr<RateErrorModel> em1 =
+ CreateObjectWithAttributes<RateErrorModel> ("RanVar", StringValue ("ns3::UniformRandomVariable[Min=0.0,Max=1.0]"),
+ "ErrorRate", DoubleValue (errRate),
+ "ErrorUnit", EnumValue (RateErrorModel::ERROR_UNIT_PACKET)
+ );
+ // Up link
+ NetDeviceContainer dev1 = p2p.Install (NodeContainer (router.Get (0), pgw));
+ dev1.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (em1));
+
+ // backend
+ NetDeviceContainer dev2 = p2p.Install (NodeContainer (sv.Get (0), router.Get (0)));
+ dev2.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (em1));
+
+ p2p.Install (NodeContainer (router.Get (0), ar.Get (0)));
+
+ // Wi-Fi
+ WifiHelper wifi = WifiHelper::Default ();
+ NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();
+ YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
+ YansWifiChannelHelper phyChannel = YansWifiChannelHelper::Default ();
+ wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
+ wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
+
+ // setup Wifi sta.
+ phy.SetChannel (phyChannel.Create ());
+ Ssid ssid1 = Ssid ("wifi-ap1");
+ mac.SetType ("ns3::StaWifiMac",
+ "Ssid", SsidValue (ssid1),
+ "ActiveProbing", BooleanValue (false));
+ wifi.Install (phy, mac, mn);
+ // setup ap.
+ mac.SetType ("ns3::ApWifiMac",
+ "Ssid", SsidValue (ssid1));
+ wifi.Install (phy, mac, ar.Get (0));
+
+
+ DceManagerHelper dceMng;
+ DceApplicationHelper dce;
+ LinuxStackHelper stack;
+ dceMng.SetNetworkStack ("ns3::LinuxSocketFdFactory",
+ "Library", StringValue ("liblinux.so"));
+ dceMng.SetLoader ("ns3::DlmLoaderFactory");
+ dceMng.SetTaskManagerAttribute ("FiberManagerType",
+ StringValue ("UcontextFiberManager"));
+ dceMng.Install (mn);
+ dceMng.Install (router);
+ dceMng.Install (sv);
+ dceMng.Install (ar);
+ stack.Install (mn);
+ stack.Install (sv);
+ stack.Install (router);
+ stack.Install (ar);
+
+ // Prefix configuration
+ std::string sv_sim0 ("2001:1:2:3::1/64");
+ std::string sv_sim0_v4 ("10.0.0.1/24");
+
+ // For SV
+ AddAddress (sv.Get (0), Seconds (0.1), "sim0", sv_sim0.c_str ());
+ LinuxStackHelper::RunIp (sv.Get (0), Seconds (0.1), "addr add 10.0.0.1/24 dev sim0");
+ LinuxStackHelper::RunIp (sv.Get (0), Seconds (0.11), "link set lo up");
+ LinuxStackHelper::RunIp (sv.Get (0), Seconds (0.11), "link set sim0 up");
+ LinuxStackHelper::RunIp (sv.Get (0), Seconds (3.15), "-4 route add default via 10.0.0.2 dev sim0");
+ LinuxStackHelper::RunIp (sv.Get (0), Seconds (3.15), "-6 route add default via 2001:1:2:3::2 dev sim0");
+
+ // For R (router)
+ LinuxStackHelper::RunIp (router.Get (0), Seconds (0.11), "link set lo up");
+ LinuxStackHelper::RunIp (router.Get (0), Seconds (0.1), "addr add 10.0.0.2/24 dev sim1");
+ AddAddress (router.Get (0), Seconds (0.1), "sim1", "2001:1:2:3::2/64");
+ LinuxStackHelper::RunIp (router.Get (0), Seconds (0.11), "link set sim1 up");
+ AddAddress (router.Get (0), Seconds (0.1), "sim2", "2001:1:2:1::1/64");
+ LinuxStackHelper::RunIp (router.Get (0), Seconds (0.11), "link set sim2 up");
+ LinuxStackHelper::RunIp (router.Get (0), Seconds (0.1), "route add 7.0.0.0/24 via 10.1.0.2 dev sim0");
+ LinuxStackHelper::RunIp (router.Get (0), Seconds (0.11), "link set sim0 up");
+ LinuxStackHelper::RunIp (router.Get (0), Seconds (3.15), "-6 route add 2001:1:2:4::/64 via 2001:1:2:1::2 dev sim2");
+ stack.SysctlSet (router, ".net.ipv6.conf.all.forwarding", "1");
+
+ // For AR1 (the intermediate node)
+ AddAddress (ar.Get (0), Seconds (0.1), "sim0", "2001:1:2:1::2/64");
+ LinuxStackHelper::RunIp (ar.Get (0), Seconds (0.11), "link set lo up");
+ LinuxStackHelper::RunIp (ar.Get (0), Seconds (0.11), "link set sim0 up");
+ LinuxStackHelper::RunIp (ar.Get (0), Seconds (3.15), "-6 route add 2001:1:2:3::/64 via 2001:1:2:1::1 dev sim0");
+ AddAddress (ar.Get (0), Seconds (0.12), "sim1", "2001:1:2:4::2/64");
+ LinuxStackHelper::RunIp (ar.Get (0), Seconds (0.13), "link set sim1 up");
+ stack.SysctlSet (ar, ".net.ipv6.conf.all.forwarding", "1");
+
+ // For AR2 (the intermediate node)
+#if 0
+ AddAddress (ar.Get (1), Seconds (0.1), "sim0", "2001:1:2:2::2/64");
+ LinuxStackHelper::RunIp (ar.Get (1), Seconds (0.11), "link set lo up");
+ LinuxStackHelper::RunIp (ar.Get (1), Seconds (0.11), "link set sim0 up");
+ LinuxStackHelper::RunIp (ar.Get (1), Seconds (3.15), "-6 route add 2001:1:2:3::/64 via 2001:1:2:2::1 dev sim0");
+ AddAddress (ar.Get (1), Seconds (0.12), "sim1", "2001:1:2:7::2/64");
+ LinuxStackHelper::RunIp (ar.Get (1), Seconds (0.13), "link set sim1 up");
+#endif
+
+ // For LTE-BS
+ // Assign ip addresses
+ Ipv4InterfaceContainer if1;
+ if1 = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevs));
+ lteHelper->Attach (ueLteDevs.Get(0), enbLteDevs.Get(0));
+
+ // setup ip routes
+ std::ostringstream cmd_oss;
+ cmd_oss.str ("");
+ cmd_oss << "rule add from " << if1.GetAddress (0, 0) << " table " << 1;
+ LinuxStackHelper::RunIp (mn.Get (0), Seconds (0.1), cmd_oss.str ().c_str ());
+ cmd_oss.str ("");
+ cmd_oss << "route add default via " << "7.0.0.1 " << " dev sim" << 0 << " table " << 1;
+ LinuxStackHelper::RunIp (mn.Get (0), Seconds (0.1), cmd_oss.str ().c_str ());
+ LinuxStackHelper::RunIp (mn.Get (0), Seconds (0.1), "route add default via 7.0.0.1 dev sim0");
+
+ // LTE-BS <-> R
+ // Assign ip addresses
+ Ipv4AddressHelper address1;
+ address1.SetBase ("10.1.0.0", "255.255.255.0");
+ if1 = address1.Assign (dev1);
+ address1.NewNetwork ();
+
+ // LinuxStackHelper::RunIp (pgw, Seconds (1.0), "route add 10.0.0.0/24 via 10.1.0.1 dev sim0");
+ Ipv4StaticRoutingHelper ipv4RoutingHelper;
+ Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (pgw->GetObject<Ipv4> ());
+ remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("10.0.0.0"), Ipv4Mask ("255.255.255.0"),
+ Ipv4Address ("10.1.0.1"), 3);
+
+ // setup ip routes
+#if 0
+ cmd_oss.str ("");
+ cmd_oss << "rule add from " << if1.GetAddress (0, 0) << " table " << (1);
+ LinuxStackHelper::RunIp (sv.Get (0), Seconds (0.1), cmd_oss.str ().c_str ());
+ cmd_oss.str ("");
+ cmd_oss << "route add 10.2." << 0 << ".0/24 dev sim" << 0 << " scope link table " << (1);
+ LinuxStackHelper::RunIp (sv.Get (0), Seconds (0.1), cmd_oss.str ().c_str ());
+#endif
+ setPos (pgw, 100, -10, 0);
+
+ // For MN
+ LinuxStackHelper::RunIp (mn.Get (0), Seconds (0.11), "link set lo up");
+ LinuxStackHelper::RunIp (mn.Get (0), Seconds (0.11), "link set sim0 up");
+ LinuxStackHelper::RunIp (mn.Get (0), Seconds (0.11), "link set sim1 up");
+ LinuxStackHelper::RunIp (mn.Get (0), Seconds (0.20), "-6 rule add from 2001:1:2:4:200:ff:fe00:a table 2");
+ LinuxStackHelper::RunIp (mn.Get (0), Seconds (0.20), "route add default via fe80::200:ff:fe00:b dev sim1 table 2");
+ LinuxStackHelper::RunIp (mn.Get (0), Seconds (0.20), "route add default via fe80::200:ff:fe00:b dev sim1");
+ // disable default injection from ra
+ stack.SysctlSet (mn, ".net.ipv6.conf.sim1.accept_ra_defrtr", "0");
+
+ // LinuxStackHelper::PopulateRoutingTables ();
+
+ // debug
+ LinuxStackHelper::RunIp (sv.Get (0), Seconds (4.0), "addr list");
+ LinuxStackHelper::RunIp (ar.Get (0), Seconds (4.1), "addr list");
+ LinuxStackHelper::RunIp (mn.Get (0), Seconds (40.2), "addr list");
+ LinuxStackHelper::RunIp (sv.Get (0), Seconds (20.0), "route show table all");
+ LinuxStackHelper::RunIp (router.Get (0), Seconds (20.0), "route show table all");
+ LinuxStackHelper::RunIp (mn.Get (0), Seconds (49.0), "route show table all");
+ LinuxStackHelper::RunIp (mn.Get (0), Seconds (49.0), "-6 rule show");
+ LinuxStackHelper::RunIp (mn.Get (0), Seconds (10.0), "route show table all");
+ LinuxStackHelper::RunIp (mn.Get (0), Seconds (10.1), "route get 2001:1:2:3::1 from 2001:1:2:4:200:ff:fe00:a");
+
+ stack.SysctlSet (mn, ".net.mptcp.mptcp_debug", "1");
+ stack.SysctlSet (sv, ".net.mptcp.mptcp_debug", "1");
+
+ {
+ ApplicationContainer apps;
+ QuaggaHelper quagga;
+ dce.SetStackSize (1 << 20);
+
+ // SV
+ dce.SetBinary ("iperf");
+ dce.ResetArguments ();
+ dce.ResetEnvironment ();
+ dce.AddArgument ("-V");
+ dce.AddArgument ("-s");
+ dce.AddArgument ("-P");
+ dce.AddArgument ("1");
+ dce.AddArgument ("-i");
+ dce.AddArgument ("1");
+ apps = dce.Install (sv);
+ apps.Start (Seconds (4));
+
+ // MN
+ dce.SetBinary ("iperf");
+ dce.ResetArguments ();
+ dce.ResetEnvironment ();
+ dce.AddArgument ("-V");
+ dce.AddArgument ("-c");
+ std::string sv_addr = sv_sim0_v4;
+ sv_addr.replace (sv_addr.find ("/"), 3, "\0 ");
+ dce.AddArgument (sv_addr);
+ dce.AddArgument ("-i");
+ dce.AddArgument ("1");
+ dce.AddArgument ("--time");
+ dce.AddArgument ("10000");
+ apps = dce.Install (mn);
+ apps.Start (Seconds (6.0));
+
+ // AR
+ quagga.EnableRadvd (ar.Get (0), "sim1", "2001:1:2:4::/64");
+ quagga.EnableZebraDebug (ar);
+ quagga.Install (ar);
+ }
+
+ phy.EnablePcapAll ("dce-mptcp-lte-wifi-v6");
+ p2p.EnablePcapAll ("dce-mptcp-lte-wifi-v6");
+
+ // Simulator::Stop (Seconds (50.0));
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
diff -r be0c6459871f example/matplotlib-mptcp-lte-wifi-v6.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/example/matplotlib-mptcp-lte-wifi-v6.py Fri Nov 01 21:02:30 2013 +0900
@@ -0,0 +1,58 @@
+from matplotlib.pylab import *
+import time
+import numpy as np
+import subprocess
+
+
+# interaction mode needs to be turned off
+ion()
+
+fig = gcf()
+fig.canvas.set_window_title('Multipath TCP Throughput')
+
+while(True): # we'll limit ourselves to 5 seconds.
+ clf()
+ time.sleep (1)
+
+ # lte
+ with open('/tmp/tcp-lte.dat', 'w') as f:
+ p = subprocess.Popen(['/usr/local/bin/tcpstat', '-r', 'dce-mptcp-lte-wifi-v6-4-3.pcap', '-o', '%R %b\n', '1'],
+ stdout=f)
+ p.wait ()
+ subplot(311)
+ x,y = loadtxt('/tmp/tcp-lte.dat',delimiter=' ',unpack=True,
+ dtype = {'names': ('time', 'bw'), 'formats':('i9', 'f9')})
+ line, = plot(x,y/(1000*1000), 'b-', label='LTE')
+ legend (loc = 'upper left')
+ ylim (ymax=10)
+ ylabel ('Throughput (Mbps)')
+
+ # wifi
+ with open('/tmp/tcp-wifi.dat', 'w') as f:
+ p = subprocess.Popen(['/usr/local/bin/tcpstat', '-r', 'dce-mptcp-lte-wifi-v6-2-0.pcap', '-o', '%R %b\n', '1'],
+ stdout=f)
+ p.wait ()
+ subplot(312)
+ x,y = loadtxt('/tmp/tcp-wifi.dat',delimiter=' ',unpack=True,
+ dtype = {'names': ('time', 'bw'), 'formats':('i9', 'f9')})
+ line, = plot(x,y/(1000*1000), 'r-', label='Wi-Fi')
+ legend (loc = 'upper left')
+ ylim (ymax=10)
+ ylabel ('Throughput (Mbps)')
+
+ # aggregated
+ with open('/tmp/tcp-aggr.dat', 'w') as f:
+ p = subprocess.Popen(['/usr/local/bin/tcpstat', '-r', 'dce-mptcp-lte-wifi-v6-0-0.pcap', '-o', '%R %b\n', '1'],
+ stdout=f)
+ p.wait ()
+ subplot(313)
+ x,y = loadtxt('/tmp/tcp-aggr.dat',delimiter=' ',unpack=True,
+ dtype = {'names': ('time', 'bw'), 'formats':('i9', 'f9')})
+ line, = plot(x,y/(1000*1000), 'g-', label='Aggregated')
+ legend (loc = 'upper left')
+ ylim (ymax=10)
+ ylabel ('Throughput (Mbps)')
+
+ xlabel ('Time (sec)')
+ draw()
+ show()
diff -r be0c6459871f wscript
--- a/wscript Tue Oct 15 12:34:15 2013 +0900
+++ b/wscript Fri Nov 01 21:02:30 2013 +0900
@@ -351,7 +351,7 @@
# target='bin/dce-cout-bug',
# source=['example/dce-cout-bug.cc'])
-def build_dce_kernel_examples(module):
+def build_dce_kernel_examples(module, bld):
module.add_example(needed = ['core', 'internet', 'dce', 'point-to-point'],
target='bin/dce-udp-perf',
source=['example/dce-udp-perf.cc'])
@@ -405,6 +405,11 @@
target='bin/dce-mptcp-lte-wifi',
source=['example/dce-mptcp-lte-wifi.cc'])
+ module.add_example(needed = ['core', 'network', 'dce', 'point-to-point', 'mobility', 'wifi', 'lte', 'dce-quagga'],
+ target='bin/dce-mptcp-lte-wifi-v6',
+ linkflags = ['-Wl,--dynamic-linker=' + os.path.abspath (bld.env['ELF_LOADER_PATH'] + '/ldso')],
+ source=['example/dce-mptcp-lte-wifi-v6.cc'])
+
module.add_example(needed = ['core', 'network', 'dce', 'point-to-point', 'applications'],
target='bin/dce-cradle-simple',
source=['example/dce-cradle-simple.cc'])
@@ -618,7 +623,7 @@
name='netlink')
if bld.env['KERNEL_STACK']:
- build_dce_kernel_examples(module)
+ build_dce_kernel_examples(module, bld)
# build test-runner
module.add_example(target='bin/test-runner',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment