diff --git a/src/test/perf/perf-pcap.cc b/src/test/perf/perf-pcap.cc new file mode 100644 index 000000000..aaef727a5 --- /dev/null +++ b/src/test/perf/perf-pcap.cc @@ -0,0 +1,74 @@ +/* -*- 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 + */ + +#include +#include + +#include "ns3/simulator-module.h" +#include "ns3/node-module.h" +#include "ns3/core-module.h" +#include "ns3/helper-module.h" + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("PerfPcap"); + +bool g_addheader = false; +RadiotapHeader g_header; +Time g_t(0.); + +static void +WritePacket (Ptr file, Ptr packet) +{ + if (g_addheader) + { + Ptr p = packet->Copy (); + p->AddHeader (g_header); + file->Write (g_t, p); + } + else + { + file->Write (g_t, packet); + } +} + +int +main (int argc, char *argv[]) +{ + CommandLine cmd; + cmd.AddValue ("addheader", "Add a header to the traces to trigger a deep copy", g_addheader); + cmd.Parse (argc, argv); + + PcapHelper pcapHelper; + Ptr file = pcapHelper.CreateFile ("perf-pcap.pcap", "w", 9999); + + Ptr p = Create (1024); + + NS_LOG_UNCOND ("timing pcap file write of 1K packet"); + NS_LOG_UNCOND ("g_addheader = " << g_addheader); + + SystemWallClockMs ms; + ms.Start (); + + for (uint32_t i = 0; i < 100000; ++i) + { + WritePacket (file, p); + } + + uint64_t et = ms.End (); + + NS_LOG_UNCOND ("elapsed time = " << et); +} diff --git a/src/test/perf/waf b/src/test/perf/waf new file mode 100755 index 000000000..4283ec141 --- /dev/null +++ b/src/test/perf/waf @@ -0,0 +1 @@ +exec "`dirname "$0"`"/../../../waf "$@" diff --git a/src/test/perf/wscript b/src/test/perf/wscript new file mode 100644 index 000000000..91fef671b --- /dev/null +++ b/src/test/perf/wscript @@ -0,0 +1,14 @@ +## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- + +def configure(conf): + pass + +def build(bld): + obj = bld.create_ns3_module('perf') + headers = bld.new_task_gen('ns3header') + headers.module = 'perf' + + obj = bld.create_ns3_program('perf-pcap', ['core', 'simulator', 'internet-stack']) + obj.source = 'perf-pcap.cc' + + diff --git a/src/test/wscript b/src/test/wscript index 494c1df3c..0052dd464 100644 --- a/src/test/wscript +++ b/src/test/wscript @@ -1,5 +1,8 @@ ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- +def configure(conf): + conf.sub_config('perf') + def build(bld): test = bld.create_ns3_module('test', ['core']) test.source = [ diff --git a/src/wscript b/src/wscript index 7b2b298ad..252867421 100644 --- a/src/wscript +++ b/src/wscript @@ -44,6 +44,7 @@ all_modules = ( 'applications/ping6', 'applications/radvd', 'test', + 'test/perf', 'test/ns3tcp', 'test/ns3wifi', 'contrib/flow-monitor', @@ -72,6 +73,7 @@ def configure(conf): conf.sub_config('contrib') conf.sub_config('internet-stack') conf.sub_config('helper') + conf.sub_config('test') blddir = os.path.abspath(os.path.join(conf.blddir, conf.env.variant())) conf.env.append_value('NS3_MODULE_PATH', blddir)