diff --git a/example/dce-netperf.cc b/example/dce-netperf.cc new file mode 100644 index 00000000..a7432abd --- /dev/null +++ b/example/dce-netperf.cc @@ -0,0 +1,172 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2018 NITK Surathkal + * + * 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 + * + * Author: Sourabh Jain + * Mohit P. Tahiliani + */ + +#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-module.h" +#include "ns3/applications-module.h" +#include "ns3/netanim-module.h" +#include "ns3/constant-position-mobility-model.h" +#include "ccnx/misc-tools.h" + +using namespace ns3; +NS_LOG_COMPONENT_DEFINE ("DceNetperf"); +// =========================================================================== +// +// node 0 node 1 +// +----------------+ +----------------+ +// | | | | +// +----------------+ +----------------+ +// | 10.1.1.1 | | 10.1.1.2 | +// +----------------+ +----------------+ +// | point-to-point | | point-to-point | +// +----------------+ +----------------+ +// | | +// +---------------------+ +// 5 Mbps, 2 ms +// +// 2 nodes : netperf and netserver .... +// +// =========================================================================== + +int main (int argc, char *argv[]) +{ + std::string stack = "ns3"; + bool useUdp = 0; + std::string bandWidth = "1m"; + CommandLine cmd; + cmd.AddValue ("stack", "Name of IP stack: ns3/linux/freebsd.", stack); + cmd.AddValue ("udp", "Use UDP. Default false (0)", useUdp); + cmd.AddValue ("bw", "BandWidth. Default 1m.", bandWidth); + cmd.Parse (argc, argv); + + NodeContainer nodes; + nodes.Create (2); + + PointToPointHelper pointToPoint; + pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); + pointToPoint.SetChannelAttribute ("Delay", StringValue ("1ms")); + + NetDeviceContainer devices; + devices = pointToPoint.Install (nodes); + + DceManagerHelper dceManager; + dceManager.SetTaskManagerAttribute ("FiberManagerType", StringValue ("UcontextFiberManager")); + + if (stack == "ns3") + { + InternetStackHelper stack; + stack.Install (nodes); + dceManager.Install (nodes); + } + else if (stack == "linux") + { +#ifdef KERNEL_STACK + dceManager.SetNetworkStack ("ns3::LinuxSocketFdFactory", "Library", StringValue ("liblinux.so")); + dceManager.Install (nodes); + LinuxStackHelper stack; + stack.Install (nodes); +#else + NS_LOG_ERROR ("Linux kernel stack for DCE is not available. build with dce-linux module."); + // silently exit + return 0; +#endif + } + else if (stack == "freebsd") + { +#ifdef KERNEL_STACK + dceManager.SetNetworkStack ("ns3::FreeBSDSocketFdFactory", "Library", StringValue ("libfreebsd.so")); + dceManager.Install (nodes); + FreeBSDStackHelper stack; + stack.Install (nodes); +#else + NS_LOG_ERROR ("FreeBSD kernel stack for DCE is not available. build with dce-freebsd module."); + // silently exit + return 0; +#endif + } + + Ipv4AddressHelper address; + address.SetBase ("10.1.1.0", "255.255.255.252"); + Ipv4InterfaceContainer interfaces = address.Assign (devices); + + // setup ip routes + Ipv4GlobalRoutingHelper::PopulateRoutingTables (); +#ifdef KERNEL_STACK + if (stack == "linux") + { + LinuxStackHelper::PopulateRoutingTables (); + } +#endif + + + DceApplicationHelper dce; + ApplicationContainer apps; + + dce.SetStackSize (1 << 20); + + dce.SetBinary ("netperf"); + dce.ResetArguments (); + dce.ResetEnvironment (); + dce.AddArgument ("-P"); + dce.AddArgument ("0"); + dce.AddArgument ("-v"); + dce.AddArgument ("0"); + dce.AddArgument ("-D"); + dce.AddArgument ("-0.20"); + dce.AddArgument ("-4"); + dce.AddArgument ("-H"); + dce.AddArgument ("10.1.1.2"); + dce.AddArgument ("-p"); + dce.AddArgument ("12685"); + dce.AddArgument ("-t"); + dce.AddArgument ("TCP_STREAM"); + dce.AddArgument ("-l"); + dce.AddArgument ("10"); + + apps = dce.Install (nodes.Get (0)); + apps.Start (Seconds (3.0)); + apps.Stop (Seconds(20)); + + dce.SetBinary ("netserver"); + dce.ResetArguments (); + dce.ResetEnvironment (); + dce.AddArgument ("-D"); + dce.AddArgument ("-f"); + dce.AddArgument ("-p"); + dce.AddArgument ("12685"); + + apps = dce.Install (nodes.Get (1)); + apps.Start (Seconds (0.6)); + + pointToPoint.EnablePcapAll ("netperf-" + stack, false); + + setPos (nodes.Get (0), 1, 10, 0); + setPos (nodes.Get (1), 50,10, 0); + + Simulator::Stop (Seconds (40.0)); + Simulator::Run (); + Simulator::Destroy (); + + return 0; +} diff --git a/utils/dce-netperf.patch b/utils/dce-netperf.patch new file mode 100644 index 00000000..73909701 --- /dev/null +++ b/utils/dce-netperf.patch @@ -0,0 +1,34 @@ +diff --git a/src/nettest_omni.c b/src/nettest_omni.c +index 852eeb1..51a3d7a 100644 +--- a/src/nettest_omni.c ++++ b/src/nettest_omni.c +@@ -5429,6 +5429,29 @@ recv_omni() + exit(1); + } + #endif /* TCP_DEFER_ACCEPT */ ++ struct sockaddr_storage addr_source; ++ int addr_source_len = sizeof(addr_source); ++ if (getsockname(s_listen, (struct sockaddr *) &addr_source, &addr_source_len) == SOCKET_ERROR) { ++ netperf_response.content.serv_errno = errno; ++ close(s_listen); ++ send_response(); ++ if (debug) { ++ fprintf(where,"netperfserver: %s could not get socket addr.\n",__FUNCTION__); ++ fflush(where); ++ } ++ exit(1); ++ } ++ ++ if (bind(s_listen, (struct sockaddr *) &addr_source, sizeof(addr_source)) == SOCKET_ERROR) { ++ netperf_response.content.serv_errno = errno; ++ close(s_listen); ++ send_response(); ++ if (debug) { ++ fprintf(where,"netperfserver: %s could not bind.\n",__FUNCTION__); ++ fflush(where); ++ } ++ exit(1); ++ } + if (listen(s_listen, backlog) == SOCKET_ERROR) { + netperf_response.content.serv_errno = errno; + close(s_listen); diff --git a/wscript b/wscript index 8edaa946..3552cce1 100644 --- a/wscript +++ b/wscript @@ -394,6 +394,10 @@ def build_dce_examples(module, bld): target='bin/dce-iperf', source=['example/dce-iperf.cc', 'example/ccnx/misc-tools.cc']) + module.add_example(needed = ['core', 'internet', 'dce', 'point-to-point', 'netanim', 'csma'], + target='bin/dce-netperf', + source=['example/dce-netperf.cc', 'example/ccnx/misc-tools.cc']) + module.add_example(needed = ['core', 'internet', 'dce', 'point-to-point', 'netanim', 'csma', 'fd-net-device'], target='bin/dce-iperf-emulation', source=['example/dce-iperf-emulation.cc', 'example/ccnx/misc-tools.cc'])