diff --git a/model/libc-ns3.h b/model/libc-ns3.h index 3294921f..e0b56371 100644 --- a/model/libc-ns3.h +++ b/model/libc-ns3.h @@ -305,6 +305,7 @@ NATIVE (popen) NATIVE (pclose) NATIVE (getgroups) NATIVE (setgroups) +NATIVE (group_member) NATIVE (confstr) NATIVE (sync) NATIVE (link) @@ -725,6 +726,8 @@ NATIVE (regerror) // iconv.h NATIVE (iconv_open) +NATIVE (iconv) +NATIVE (iconv_close) // glob.h NATIVE (glob) @@ -738,6 +741,9 @@ NATIVE (error) NATIVE (dl_iterate_phdr) NATIVE (__libc_start_main) +NATIVE (__stpcpy_chk) +NATIVE (__freading) + #undef DCE #undef DCET diff --git a/myscripts/dce-emu-wget/dce-emu-wget.cc b/myscripts/dce-emu-wget/dce-emu-wget.cc new file mode 100644 index 00000000..7a621014 --- /dev/null +++ b/myscripts/dce-emu-wget/dce-emu-wget.cc @@ -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 = CreateObject (); + + // + // 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 device = devices.Get (0); + device->SetAttribute ("Address", Mac48AddressValue ("e0:9d:31:28:c2:34")); + + // Ptr queue = CreateObject (); + // 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 = node->GetObject (); + 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 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."); +} diff --git a/myscripts/dce-emu-wget/misc-tools.cc b/myscripts/dce-emu-wget/misc-tools.cc new file mode 100644 index 00000000..013f024e --- /dev/null +++ b/myscripts/dce-emu-wget/misc-tools.cc @@ -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 n, int x, int y, int z) +{ + Ptr loc = CreateObject (); + n->AggregateObject (loc); + Vector locVec2 (x, y, z); + loc->SetPosition (locVec2); +} + + +void RunIp (Ptr 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, 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 (); +} +} diff --git a/myscripts/dce-emu-wget/misc-tools.h b/myscripts/dce-emu-wget/misc-tools.h new file mode 100644 index 00000000..2fca6951 --- /dev/null +++ b/myscripts/dce-emu-wget/misc-tools.h @@ -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 n, int x, int y, int z); + +void RunIp (Ptr node, Time at, std::string str); + +void AddAddress (Ptr node, Time at, const char *name, const char *address); + +std::string Ipv4AddressToString (Ipv4Address ad); +} + +#endif // MISC_TOOLS_H diff --git a/myscripts/dce-emu-wget/wscript b/myscripts/dce-emu-wget/wscript new file mode 100644 index 00000000..a6902e67 --- /dev/null +++ b/myscripts/dce-emu-wget/wscript @@ -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'] + ) + diff --git a/ns3waf/__init__.py b/ns3waf/__init__.py index b21c7d4b..45086f12 100644 --- a/ns3waf/__init__.py +++ b/ns3waf/__init__.py @@ -147,17 +147,23 @@ 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) @@ -165,26 +171,39 @@ def _check_dependencies(conf, required, mandatory): 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: @@ -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 \ diff --git a/waf b/waf index 7ceee167..a1c5c961 100755 --- a/waf +++ b/waf @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # encoding: latin-1 # Thomas Nagy, 2005-2018 # diff --git a/wscript b/wscript index ed25e6a8..08449e46 100755 --- a/wscript +++ b/wscript @@ -130,6 +130,10 @@ def configure(conf): conf.env.prepend_value('LINKFLAGS', '-Wl,--no-as-needed') conf.env.append_value('LINKFLAGS', '-pthread') + + conf.env.append_value('LINKFLAGS', '-L/home/wahoo/Documents/research/ns-3-allinone/ns-3-dev/build/lib/') #MA quick hack + #conf.env.append_value('LINKFLAGS', '-ldl') # MA trying to fix a problem + conf.check (lib='dl', mandatory = True) conf.check_cc(fragment='int main() {__get_cpu_features();}\n', msg='Checking for glibc get_cpu_features', define_name='HAVE_GETCPUFEATURES', mandatory=False) conf.check_cc(fragment='int main() {secure_getenv("test");}\n', msg='Checking for glibc secure_getenv', define_name='HAVE_SECURE_GETENV', mandatory=False) @@ -529,7 +533,9 @@ def build_a_script(bld, name, needed = [], **kw): kw['features'] = 'cxx cxxprogram' if bld.env['NS3_ENABLE_STATIC']: for module in kw['use']: + # print("[DEBUG] kw[use] = ", kw['use']) kw['linkflags'] = kw.get('linkflags', []) + # print("[DEBUG] kw.get(linkflags,[]) = ", kw.get('linkflags',[])) # XXX pkg-config doesn't give the proper order of whole-archive option.. if 'dce' in module.lower(): continue @@ -541,7 +547,10 @@ def build_a_script(bld, name, needed = [], **kw): continue kw['linkflags'] += ['-ldl'] kw['linkflags'] += ['-Wl,--whole-archive,-Bstatic'] - kw['linkflags'] += bld.env['STLIB_ST_%s' % module.upper()] + # print(bld.env['STLIB_ST_%s' % module.upper()]) + kw['linkflags'] += [bld.env['STLIB_ST_%s' % module.upper()]] + # print() + program = bld(**kw) program.is_ns3_program = True bld.env.append_value('NS3_RUNNABLE_PROGRAMS', name) @@ -571,6 +580,7 @@ def add_myscripts(bld): if os.path.isdir(os.path.join('myscripts', dir)): bld.recurse(os.path.join('myscripts', dir)) elif dir.endswith(".cc"): + print("[DEBUG] attempting to build ", dir) bld.build_a_script('dce', needed = bld.env['NS3_MODULES_FOUND'] + ['dce'], target='bin/' + os.path.splitext(dir)[0], @@ -816,7 +826,7 @@ def build(bld): # and forward to the dce_* code bld.shlib(source = ['model/libc.cc', 'model/libc-setup.cc', 'model/libc-global-variables.cc'], target='lib/c-ns3', - cxxflags=['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch'], + cxxflags=['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch', '/usr/lib/x86_64-linux-gnu/libdl.a'], # MA: modified this bit defines=['LIBSETUP=libc_setup'], linkflags=['-nostdlib', '-fno-profile-arcs', '-Wl,--version-script=' + os.path.join('model', 'libc.version'),