Skip to content

Commit

Permalink
added changes that allow dce to run by building it with waf
Browse files Browse the repository at this point in the history
  • Loading branch information
mas2tg committed Jan 15, 2021
1 parent 94de508 commit 1be9e25
Show file tree
Hide file tree
Showing 8 changed files with 335 additions and 9 deletions.
6 changes: 6 additions & 0 deletions model/libc-ns3.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ NATIVE (popen)
NATIVE (pclose)
NATIVE (getgroups)
NATIVE (setgroups)
NATIVE (group_member)
NATIVE (confstr)
NATIVE (sync)
NATIVE (link)
Expand Down Expand Up @@ -725,6 +726,8 @@ NATIVE (regerror)

// iconv.h
NATIVE (iconv_open)
NATIVE (iconv)
NATIVE (iconv_close)

// glob.h
NATIVE (glob)
Expand All @@ -738,6 +741,9 @@ NATIVE (error)

NATIVE (dl_iterate_phdr)
NATIVE (__libc_start_main)
NATIVE (__stpcpy_chk)
NATIVE (__freading)


#undef DCE
#undef DCET
Expand Down
218 changes: 218 additions & 0 deletions myscripts/dce-emu-wget/dce-emu-wget.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/* -*- 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 script is derived from the example of usage of EMU of NS-3 named emu-ping.cc
// you can find the original script in directory under ns-3 sources : src/emu/examples
//
// Allow ns-3 to ping a real host somewhere, using emulation mode
//
// ------------
// | node n0 |
// | |
// | --- |
// | | | |
// | |emu| |
// | | | |
// | --- |
// | | |
// ----|-------
// |
// (device on host system, set to promiscuous mode)
// |
// --------- (Internet) -------
//
// To use this example:
// 1) You need to decide on a physical device on your real system, and either
// overwrite the hard-configured device name below (eth0) or pass this
// device name in as a command-line argument
// 2) The host device must be set to promiscuous mode
// (e.g. "sudo ifconfig eth0 promisc")
// 3) Be aware that ns-3 will generate a fake mac address, and that in
// some enterprise networks, this may be considered bad form to be
// sending packets out of your device with "unauthorized" mac addresses
// 4) You will need to assign an IP address to the ns-3 simulation node that
// is consistent with the subnet that is active on the host device's link.
// That is, you will have to assign an IP address to the ns-3 node as if
// it were on your real subnet. Search for "Ipv4Address localIp" and
// replace the string "1.2.3.4" with a valid IP address.
// 5) You will need to configure a default route in the ns-3 node to tell it
// how to get off of your subnet. One thing you could do is a
// 'netstat -rn' command and find the IP address of the default gateway
// on your host. Search for "Ipv4Address gateway" and replace the string
// "1.2.3.4" string with the gateway IP address.
#include "ns3/abort.h"
#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/network-module.h"
#include "ns3/fd-net-device-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/ipv4-list-routing-helper.h"
#include "ns3/dce-module.h"
#include "misc-tools.h"

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("DcePingEmulationExample");

int
main (int argc, char *argv[])
{
NS_LOG_INFO ("DCE Ping Emulation Example");

std::string deviceName ("wlp3s0");
std::string remote ("172.217.12.110"); // google.com
std::string local ("10.3.1.215");
std::string sLocalMask ("255.255.255.0");
//
// Allow the user to override any of the defaults at run-time, via
// command-line arguments
//
CommandLine cmd;
cmd.AddValue ("deviceName", "Device name", deviceName);
cmd.AddValue ("remote", "Remote IP address (dotted decimal only please)", remote);
cmd.AddValue ("local", "Local IP address (dotted decimal only please)", local);
cmd.AddValue ("localmask", "Local mask address (dotted decimal only please)", sLocalMask);
cmd.Parse (argc, argv);

Ipv4Address remoteIp (remote.c_str ());
Ipv4Address localIp (local.c_str ());
NS_ABORT_MSG_IF (localIp == "1.2.3.4", "You must change the local IP address before running this example");

Ipv4Mask localMask (sLocalMask.c_str ());

//
// Since we are using a real piece of hardware we need to use the realtime
// simulator.
//
GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));

//
// Since we are going to be talking to real-world machines, we need to enable
// calculation of checksums in our protocols.
//
GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));

//
// In such a simple topology, the use of the helper API can be a hindrance
// so we drop down into the low level API and do it manually.
//
// First we need a single node.
//
NS_LOG_INFO ("Create Node");
Ptr<Node> node = CreateObject<Node> ();

//
// Create an emu device, allocate a MAC address and point the device to the
// Linux device name. The device needs a transmit queueing discipline so
// create a droptail queue and give it to the device. Finally, "install"
// the device into the node.
//
// Do understand that the ns-3 allocated MAC address will be sent out over
// your network since the emu net device will spoof it. By default, this
// address will have an Organizationally Unique Identifier (OUI) of zero.
// The Internet Assigned Number Authority IANA
//
// http://www.iana.org/assignments/ethernet-numbers
//
// reports that this OUI is unassigned, and so should not conflict with
// real hardware on your net. It may raise all kinds of red flags in a
// real environment to have packets from a device with an obviously bogus
// OUI flying around. Be aware.
//
NS_LOG_INFO ("Create Device");
EmuFdNetDeviceHelper emu;
emu.SetDeviceName (deviceName);
NetDeviceContainer devices = emu.Install (node);
Ptr<NetDevice> device = devices.Get (0);
device->SetAttribute ("Address", Mac48AddressValue ("e0:9d:31:28:c2:34"));

// Ptr<Queue> queue = CreateObject<DropTailQueue> ();
// device->SetQueue (queue);
// node->AddDevice (device);

//
// Add a default internet stack to the node. This gets us the ns-3 versions
// of ARP, IPv4, ICMP, UDP and TCP.
//
NS_LOG_INFO ("Add Internet Stack");
InternetStackHelper internetStackHelper;
internetStackHelper.Install (node);

NS_LOG_INFO ("Create IPv4 Interface");
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
uint32_t interface = ipv4->AddInterface (device);
Ipv4InterfaceAddress address = Ipv4InterfaceAddress (localIp, localMask);
ipv4->AddAddress (interface, address);
ipv4->SetMetric (interface, 1);
ipv4->SetUp (interface);

//
// When the ping application sends its ICMP packet, it will happily send it
// down the ns-3 protocol stack. We set the IP address of the destination
// to the address corresponding to example.com above. This address is off
// our local network so we have got to provide some kind of default route
// to ns-3 to be able to get that ICMP packet forwarded off of our network.
//
// You have got to provide an IP address of a real host that you can send
// real packets to and have them forwarded off of your local network. One
// thing you could do is a 'netstat -rn' command and find the IP address of
// the default gateway on your host and add it below, replacing the
// "1.2.3.4" string.
//
Ipv4Address gateway ("10.3.1.1");
NS_ABORT_MSG_IF (gateway == "1.2.3.4", "You must change the gateway IP address before running this example");

Ipv4StaticRoutingHelper ipv4RoutingHelper;
Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4);
staticRouting->SetDefaultRoute (gateway, interface);

DceManagerHelper dceManager;

dceManager.Install (node);

DceApplicationHelper dce;
ApplicationContainer apps;

dce.SetStackSize (1 << 20);

// Launch ping on node 0
dce.SetBinary ("wget");
dce.ResetArguments ();
dce.ResetEnvironment ();
//dce.AddArgument ("https://img.webmd.com/dtmcms/live/webmd/consumer_assets/site_images/article_thumbnails/other/cat_relaxing_on_patio_other/1800x1200_cat_relaxing_on_patio_other.jpg");
dce.AddArgument ("http://www.columbia.edu/~fdc/picture-of-something.jpg");
//dce.AddArgument ("-n");
//dce.AddArgument ("-s 1000");
//dce.AddArgument (remote);

apps = dce.Install (node);
apps.Start (Seconds (1.0));

//
// Enable a promiscuous pcap trace to see what is coming and going on our device.
//
emu.EnablePcap ("emu-wget", device, true);

//
// Now, do the actual emulation.
//
NS_LOG_INFO ("Run Emulation.");
Simulator::Stop (Seconds (12.0));
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
}
42 changes: 42 additions & 0 deletions myscripts/dce-emu-wget/misc-tools.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "misc-tools.h"
#include "ns3/constant-position-mobility-model.h"
//#include "ns3/applications-module.h"
#include "ns3/dce-module.h"

namespace ns3 {

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


void RunIp (Ptr<Node> node, Time at, std::string str)
{
DceApplicationHelper process;
ApplicationContainer apps;
process.SetBinary ("ip");
process.SetStackSize (1 << 16);
process.ResetArguments ();
process.ParseArguments (str.c_str ());
apps = process.Install (node);
apps.Start (at);
}

void AddAddress (Ptr<Node> node, Time at, const char *name, const char *address)
{
std::ostringstream oss;
oss << "-f inet addr add " << address << " dev " << name;
RunIp (node, at, oss.str ());
}

std::string Ipv4AddressToString (Ipv4Address ad)
{
std::ostringstream oss;
ad.Print (oss);
return oss.str ();
}
}
17 changes: 17 additions & 0 deletions myscripts/dce-emu-wget/misc-tools.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef MISC_TOOLS_H
#define MISC_TOOLS_H
#include "ns3/network-module.h"
#include "ns3/core-module.h"

namespace ns3 {

void setPos (Ptr<Node> n, int x, int y, int z);

void RunIp (Ptr<Node> node, Time at, std::string str);

void AddAddress (Ptr<Node> node, Time at, const char *name, const char *address);

std::string Ipv4AddressToString (Ipv4Address ad);
}

#endif // MISC_TOOLS_H
13 changes: 13 additions & 0 deletions myscripts/dce-emu-wget/wscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-

import ns3waf

def configure(conf):
ns3waf.check_modules(conf, ['core', 'internet', 'point-to-point', 'fd-net-device'], mandatory = True)

def build(bld):
bld.build_a_script('dce', needed = ['core', 'internet', 'point-to-point', 'fd-net-device', 'dce', 'netanim' ],
target='bin/dce-emu-wget',
source=['dce-emu-wget.cc', 'misc-tools.cc']
)

32 changes: 26 additions & 6 deletions ns3waf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,44 +147,63 @@ def build_ns3_libname(version, module, profile):

def _check_dependencies(conf, required, mandatory):
found = []
libcore = build_ns3_libname("*", "core", conf.env['LIB_SUFFIX'])
ns3_dir_pkgconfig = conf.env['NS3_DIR'] + '/lib/pkgconfig'

libcore = build_ns3_libname("ns3-dev", "core", conf.env['LIB_SUFFIX']) # MA: changed
ns3_dir_pkgconfig = conf.env['NS3_DIR'] # + '/lib/pkgconfig' # MA: changed
print("[DEBUG] ns3_dir_pkgconfig:" + ns3_dir_pkgconfig)
match_pkg = ""

if not 'NS3_VERSION' in conf.env:

pcfiles = glob.glob(ns3_dir_pkgconfig + '/' + libcore + ".pc")
pcfiles_names = ns3_dir_pkgconfig + '/src/core/' + libcore + ".pc"
#print("[DEBUG] pcfiles_names:", pcfiles_names)
pcfiles = glob.glob(pcfiles_names) #MA: changed
print("pcfiles:", pcfiles)
print("len(pcfiles):", len(pcfiles))
if len(pcfiles) > 1:
Logs.errors("Too many candidates, DCE should only see one ns-3 version.")
return
elif len(pcfiles) == 1:
match_pkg = os.path.basename(pcfiles[0])
print("[DEBUG] match_pkg is", match_pkg)
lib = re.search("(ns[0-9][\.\-][dev0-9\.]+)", match_pkg)
if lib.group(0) is None:
Logs.error("Could not find version for the match %s" % match_pkg)
return

version = lib.group(0)
conf.env['NS3_VERSION'] = version
#print("got here")
else:
Logs.error("Could not find " + libcore)
return

#TODO: either pass my_path as a parameter for _check_dependencies OR make my_path a global variable that is set by whoever calls _check_dependencies
mypath = os.environ.get("PKG_CONFIG_PATH") #construct all necessary paths before the next for loop
my_deps = "antenna buildings csma-layout fd-net-device lr-wpan netanim point-to-point spectrum topology-read wave aodv config-store dsdv flow-monitor lte network point-to-point-layout stats traffic-control wifi applications core dsr internet mesh nix-vector-routing propagation tap-bridge uan wimax bridge csma energy internet-apps mobility olsr sixlowpan test virtual-net-device".split()
for my_dep in my_deps:
if len(my_dep) > 0:
new_dep_path = ns3_dir_pkgconfig + '/src/' + my_dep
#print("[DEBUG] adding " + new_dep_path + " to mypath")
mypath = ":".join([mypath, new_dep_path])


for module in required:
if module in conf.env['NS3_MODULES_FOUND']:
continue
libname = build_ns3_libname(conf.env['NS3_VERSION'], module.lower(), conf.env['LIB_SUFFIX'])

retval = conf.check_cfg(package=libname,
args='--cflags --libs' + (' --static' if conf.env['NS3_ENABLE_STATIC'] else ''),
mandatory=mandatory,
msg="Checking for %s (%s)" % (libname, "mandatory" if mandatory else "optional"),
uselib_store='NS3_%s' % module.upper(),
pkg_config_path=":".join([os.environ.get("PKG_CONFIG_PATH"), ns3_dir_pkgconfig])
pkg_config_path=mypath
)

if retval is not None:
# XXX pkg-config doesn't give the proper order of whole-archive option..
if conf.env['NS3_ENABLE_STATIC']:
libname = 'STLIB_ST_NS3_%s' % module.upper()
print("[DEBUG] match_pkg is", match_pkg)
conf.env[libname] = '-l%s' % (match_pkg.replace('libns3', 'ns3'))
for lib in conf.env['LIB_NS3_%s' % module.upper()]:
if 'ns3' in lib:
Expand Down Expand Up @@ -312,6 +331,7 @@ def _build_library(bld, name, *k, **kw):
if not bld.env['NS3_ENABLE_STATIC']:
if bld.env['CXX_NAME'] in ['gcc', 'icc'] and bld.env['WL_SONAME_SUPPORTED']:
linkflags.append('-Wl,--soname=%s' % _c_libname(bld, name))
print(linkflags)
pass
elif bld.env['CXX_NAME'] in ['gcc', 'icc'] and \
os.uname()[4] == 'x86_64' and \
Expand Down
Loading

0 comments on commit 1be9e25

Please sign in to comment.