diff --git a/COPYING b/COPYING index 9edc8e0f..5f100524 100644 --- a/COPYING +++ b/COPYING @@ -1,4 +1,4 @@ - Copyright (c) 2013-2015 - Adjacent Link LLC, Bridgewater, New Jersey + Copyright (c) 2013-2016 - Adjacent Link LLC, Bridgewater, New Jersey All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/Makefile.am b/Makefile.am index f0cf6c02..4a6bff1c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -82,7 +82,6 @@ EXTRA_DIST = \ ChangeLog \ NEWS \ emane.spec.in \ - PROBLEM-REPORT-FORM \ SPONSOR \ README.md \ debian \ diff --git a/PROBLEM-REPORT-FORM b/PROBLEM-REPORT-FORM deleted file mode 100644 index 662fe8f3..00000000 --- a/PROBLEM-REPORT-FORM +++ /dev/null @@ -1,93 +0,0 @@ - Please use the PRF form below to submit bug reports, problem reports, - etc., to the EMANE developers and interested users. Send to - emane-users@pf.itd.nrl.navy.mil. Please be sure to send your PRF as - plain ASCII text. - - You can subscribe to the EMANE users mailing list here: - - http://pf.itd.nrl.navy.mil/mailman/listinfo/emane-users - - Replace/remove all the explanatory text in brackets (<>) before mailing. - - PLEASE make your Subject: line as descriptive as possible. Subjects like - "EMANE bug" or "bug report" are not helpful. - -8<----------8<----------8<----------8<----------8<----------8<----------8<---- - -To: emane-users@pf.itd.nrl.navy.mil -Subject: EMANE PRF: - -[[=== SYSTEM INFORMATION ====]] - - HOST OPERATING SYSTEM: - - HOST ARCHITECTURE: - - TARGET OPERATING SYSTEM (if different): - - TARGET ARCHITECTURE (if different): - - COMPILER and COMPILER VERSION (if applicable) - - -[[=== VERSION INFORMATION ====]] - - EMANE VERSION: - - ACE VERSION: - - LIBXML2 VERSION: - - LIBPCAP_VERSION (if applicable): - - WINPCAP_VERSION (if applicable): - - EMANE ADD-ON NAMES and VERSIONS (if applicable): - - -[[== INSTALLATION INFORMATION ==] - - EMANE INSTALLATION METHOD (MAKE INSTALL, RPM, OTHER) - (if applicable): - - - - -[[=== PROBLEM INFORMATION ====]] - - TYPE (COMPILATION, INSTALLATION, EXECUTION, OTHER): - - BRIEF SUMMARY: - - - - - DETAILED DESCRIPTION: - - - - - REPEAT BY: - - - - - CONFIGURATION: - - - - - ATTACHED FILE DESCRIPTION: - - - - - SAMPLE FIX/WORKAROUND: - - - diff --git a/configure.ac b/configure.ac index fc45b269..ef9a0fda 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ %AC_COPYRIGHT([ - Copyright (c) 2013-2015 - Adjacent Link LLC, Bridgewater, New Jersey + Copyright (c) 2013-2016 - Adjacent Link LLC, Bridgewater, New Jersey All rights reserved. Redistribution and use in source and binary forms, with or without @@ -48,7 +48,6 @@ AX_CXX_COMPILE_STDCXX_11([noext],[mandatory]) AC_PROG_INSTALL -AC_LIBTOOL_WIN32_DLL AC_PROG_LIBTOOL AC_LANG([C++]) @@ -74,9 +73,6 @@ AC_ARG_WITH([testcases], [AM_CONDITIONAL(WITH_TESTCASES,false)]) -AC_ARG_VAR([ACE_CFLAGS],[C compiler flags for ACE]) -AC_ARG_VAR([ACE_LIBS], [linker flags for ACE]) - AC_ARG_VAR([pcap_CFLAGS],[C compiler flags for libpcap]) AC_ARG_VAR([pcap_LIBS], [linker flags for libpcap]) @@ -89,49 +85,8 @@ AC_CHECK_HEADER(sys/timerfd.h, [], [AC_MSG_ERROR("Missing sys/timerfd.h header")]) -_cppflags=${CPPFLAGS} -_ldflags=${LDFLAGS} - -# Checks for libraries. -if test "${ACE_CFLAGS}" != ""; then - CPPFLAGS="${ACE_CFLAGS} ${CPPFLAGS}" -fi - -if test "${ACE_LIBS}" != ""; then - LDFLAGS="${ACE_LIBS} ${LDFLAGS}" -fi - -AC_CHECK_HEADER(ace/OS_main.h, - [AC_CHECK_LIB([ACE],main,[ACE_LIBS+=' -lACE'], - [AC_MSG_ERROR("ACE not installed")])], - [AC_MSG_ERROR("Missing ACE development headers")]) - - -CPPFLAGS=${_cppflags} -LDFLAGS=${_ldflags} - -AC_SUBST(ACE_CFLAGS) -AC_SUBST(ACE_LIBS) - -PCAP_LIB_NAME=pcap - -WIN32_EXTRA_LIBADD= -WIN32_EXTRA_LDFLAGS= - -case "$host" in - *-mingw*) - CPPFLAGS="$CPPFLAGS -DWIN32" - WIN32_EXTRA_LIBADD="-lws2_32 -liphlpapi" - WIN32_EXTRA_LDFLAGS=-no-undefined - PCAP_LIB_NAME=wpcap - ;; -*) - LDFLAGS="$LDFLAGS -lpthread -ldl" - ;; -esac -AC_SUBST(WIN32_EXTRA_LIBADD) -AC_SUBST(WIN32_EXTRA_LDFLAGS) +LDFLAGS="$LDFLAGS -lpthread -ldl" _cppflags=${CPPFLAGS} _ldflags=${LDFLAGS} @@ -146,9 +101,9 @@ if test "${pcap_LIBS}" != ""; then fi AC_CHECK_HEADER(pcap.h, - [AC_CHECK_LIB([${PCAP_LIB_NAME}],pcap_open_live,[pcap_LIBS+=" -l${PCAP_LIB_NAME}"], - [AC_MSG_ERROR("${PCAP_LIB_NAME} not installed")])], - [AC_MSG_ERROR("Missing ${PCAP_LIB_NAME} development headers")]) + [AC_CHECK_LIB([pcap],pcap_open_live,[pcap_LIBS+=" -lpcap"], + [AC_MSG_ERROR("pcap not installed")])], + [AC_MSG_ERROR("Missing pcap development headers")]) CPPFLAGS=${_cppflags} @@ -186,10 +141,10 @@ CPPFLAGS="$CPPFLAGS -DVERBOSE_LOGGING" fi AC_SUBST(libemane_CFLAGS, -["${libxml2_CFLAGS} ${ACE_CFLAGS} ${protobuf_CFLAGS} ${libpcre_CFLAGS} ${libuuid_CFLAGS}"]) +["${libxml2_CFLAGS} ${protobuf_CFLAGS} ${libpcre_CFLAGS} ${libuuid_CFLAGS}"]) AC_SUBST(libemane_LIBS, -["-lemane -lrt ${libxml2_LIBS} ${ACE_LIBS} ${protobuf_LIBS} ${libpcre_LIBS} ${libuuid_LIBS}"]) +["-lemane -lrt ${libxml2_LIBS} ${protobuf_LIBS} ${libpcre_LIBS} ${libuuid_LIBS}"]) LANG=C AC_SUBST(LANG) diff --git a/debian/control b/debian/control index f362d8e8..c64e4181 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: emane Section: unknown Priority: extra Maintainer: Adjacent Link LLC -Build-Depends: debhelper (>= 8.0.0), autotools-dev,libxml2-dev, libprotobuf-dev, libpcre3-dev, libace-dev, libpcap-dev +Build-Depends: debhelper (>= 8.0.0), autotools-dev,libxml2-dev, libprotobuf-dev, libpcre3-dev, libpcap-dev Standards-Version: 3.9.3 Homepage: https://github.com/adjacentlink/emane diff --git a/emane.spec.in b/emane.spec.in index 43eea20e..b45ca222 100644 --- a/emane.spec.in +++ b/emane.spec.in @@ -191,7 +191,7 @@ make DESTDIR=${RPM_BUILD_ROOT} install find ${RPM_BUILD_ROOT} -name '*.a' -exec rm '{}' \; find ${RPM_BUILD_ROOT} -name '*.la' -exec rm '{}' \; mkdir -p ${RPM_BUILD_ROOT}%{_pkgdocdir} -install -t ${RPM_BUILD_ROOT}%{_pkgdocdir} AUTHORS %{!?_licensedir:COPYING} ChangeLog NEWS README PROBLEM-REPORT-FORM SPONSOR +install -t ${RPM_BUILD_ROOT}%{_pkgdocdir} AUTHORS %{!?_licensedir:COPYING} ChangeLog NEWS README SPONSOR %if 0%{?_licensedir:1} mkdir -p ${RPM_BUILD_ROOT}%{_licensedir}/%{name} install -t ${RPM_BUILD_ROOT}%{_licensedir}/%{name} COPYING diff --git a/include/emane/Makefile.am b/include/emane/Makefile.am index cd818c1e..f782b338 100644 --- a/include/emane/Makefile.am +++ b/include/emane/Makefile.am @@ -48,6 +48,8 @@ emaneinc_HEADERS = \ flowcontrolmanager.h \ frequencysegment.h \ frequencysegment.inl \ + inetaddr.h \ + inetaddrexception.h \ logserviceprovider.h \ logserviceprovider.inl \ maclayerimpl.h \ diff --git a/include/emane/any.h b/include/emane/any.h index 6ad31738..da04fd85 100644 --- a/include/emane/any.h +++ b/include/emane/any.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey + * Copyright (c) 2013-2015 - Adjacent Link LLC, Bridgewater, New Jersey * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,11 +34,10 @@ #define EMANEANY_HEADER_ #include "emane/anyexception.h" +#include "emane/inetaddr.h" #include -#include - namespace EMANE { /** @@ -106,7 +105,7 @@ namespace EMANE * Creates an Any instance from a unsigned 8-bit integer */ explicit Any(std::uint8_t u8Value); - + /** * Creates an Any instance from a float */ @@ -118,9 +117,9 @@ namespace EMANE explicit Any(double dValue); /** - * Creates an Any instance from an ACE_INET_Addr + * Creates an Any instance from an INETAddr */ - explicit Any(const ACE_INET_Addr & addrValue); + explicit Any(const INETAddr & addrValue); /** * Creates an Any instance from a NULL terminated string @@ -131,7 +130,7 @@ namespace EMANE * Creates an Any instance from a std::string */ explicit Any(const std::string & sValue); - + /** * Creates an Any instance from a boolean */ @@ -151,7 +150,7 @@ namespace EMANE * Destroys an instance */ ~Any(); - + /** * Gets the signed 64-bit integer Any value * @@ -159,7 +158,7 @@ namespace EMANE * * @throw AnyException if value is a different type */ - ACE_INT64 asINT64() const; + std::int64_t asINT64() const; /** * Gets the unsigned 64-bit integer Any value @@ -168,8 +167,8 @@ namespace EMANE * * @throw AnyException if value is a different type */ - ACE_UINT64 asUINT64() const; - + std::uint64_t asUINT64() const; + /** * Gets the signed 32-bit integer Any value * @@ -177,7 +176,7 @@ namespace EMANE * * @throw AnyException if value is a different type */ - ACE_INT32 asINT32() const; + std::int32_t asINT32() const; /** * Gets the unsigned 32-bit integer Any value @@ -186,7 +185,7 @@ namespace EMANE * * @throw AnyException if value is a different type */ - ACE_UINT32 asUINT32() const; + std::uint32_t asUINT32() const; /** * Gets the signed 16-bit integer Any value @@ -195,8 +194,8 @@ namespace EMANE * * @throw AnyException if value is a different type */ - ACE_INT16 asINT16() const; - + std::int16_t asINT16() const; + /** * Gets the unsigned 16-bit integer Any value * @@ -204,7 +203,7 @@ namespace EMANE * * @throw AnyException if value is a different type */ - ACE_UINT16 asUINT16() const; + std::uint16_t asUINT16() const; /** * Gets the signed 8-bit integer Any value @@ -213,7 +212,7 @@ namespace EMANE * * @throw AnyException if value is a different type */ - ACE_INT8 asINT8() const; + std::int8_t asINT8() const; /** * Gets the unsigned 8-bit integer Any value @@ -222,7 +221,7 @@ namespace EMANE * * @throw AnyException if value is a different type */ - ACE_UINT8 asUINT8() const; + std::uint8_t asUINT8() const; /** * Gets the float Any value @@ -242,15 +241,15 @@ namespace EMANE */ double asDouble() const; - + /** - * Gets the ACE_INET_Addr Any value + * Gets the INETAddr Any value * * @return value * * @throw AnyException if value is a different type */ - ACE_INET_Addr asINETAddr() const; + INETAddr asINETAddr() const; /** * Gets the boolean Any value @@ -269,19 +268,19 @@ namespace EMANE * @throw AnyException if value is a different type */ std::string asString() const; - + /** * Gets the Any type * * @return value */ Type getType() const; - + /** * Less than comparison * * @param rhs INstance to compare - + * @return @a true if less than */ bool operator<(const EMANE::Any & rhs) const; @@ -290,7 +289,7 @@ namespace EMANE * Greater than comparison * * @param rhs INstance to compare - + * @return @a true if greater than */ bool operator>(const EMANE::Any & rhs) const; @@ -299,7 +298,7 @@ namespace EMANE * Less than or equal comparison * * @param rhs INstance to compare - + * @return @a true if less than or equal */ bool operator<=(const EMANE::Any & rhs) const; @@ -308,7 +307,7 @@ namespace EMANE * Greater than or equal comparison * * @param rhs INstance to compare - + * @return @a true if greater than or equal */ bool operator>=(const EMANE::Any & rhs) const; @@ -332,11 +331,11 @@ namespace EMANE Type type_; union { - ACE_INT64 i64Value_; - ACE_UINT64 u64Value_; + std::int64_t i64Value_; + std::uint64_t u64Value_; double dValue_; std::string sValue_; - ACE_INET_Addr addrValue_; + INETAddr addrValue_; }; }; @@ -351,7 +350,7 @@ namespace EMANE : public std::false_type{}; template<> - struct is_any_convertable_nonnumeric + struct is_any_convertable_nonnumeric : public std::true_type{}; template<> diff --git a/include/emane/application/logger.h b/include/emane/application/logger.h index 2cb1697f..f88d858a 100644 --- a/include/emane/application/logger.h +++ b/include/emane/application/logger.h @@ -1,5 +1,6 @@ /* - * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey + * Copyright (c) 2013-2014,2016 - Adjacent Link LLC, Bridgewater, New + * Jersey * Copyright (c) 2011 - DRS CenGen, LLC, Columbia, Maryland * All rights reserved. * @@ -60,28 +61,14 @@ namespace EMANE */ void setLogLevel(const LogLevel level); - /** - * Redirect logging to syslog - * - * @param program the tag name of logged statements in syslog - */ - void redirectLogsToSysLog(const char *program); /** * Redirect logging to file * * @param filename the name of the destination file */ - void redirectLogsToFile(const char* filename); + void redirectLogsToFile(const char* filename); - /** - * Redirect logging to remoet logger - * - * @param program the tag name of logged statements in syslog - * @param address the address of the remote logger - */ - void redirectLogsToRemoteLogger(const char *program, - const char* address); /** * Output a log message @@ -90,7 +77,7 @@ namespace EMANE * @param fmt format string (see printf) * @param ... Variable data (see printf) */ - void log(LogLevel level, const char *fmt, ...) + void log(LogLevel level, const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); /** diff --git a/include/emane/configurationregistrar.h b/include/emane/configurationregistrar.h index d5e553fb..bcfef6b9 100644 --- a/include/emane/configurationregistrar.h +++ b/include/emane/configurationregistrar.h @@ -1,5 +1,6 @@ /* - * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey + * Copyright (c) 2013-2014,2016 - Adjacent Link LLC, Bridgewater, New + * Jersey * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -49,7 +50,7 @@ namespace EMANE * * @brief The ConfigurationRegistrar allows NEM layers to register * the configuration items they require. - * + * * @note Registration may only occur during Component::initialize() */ class ConfigurationRegistrar @@ -110,7 +111,7 @@ namespace EMANE const std::string & sRegexPattern = {}); /** - * Registers a ConfigurationValidator callable. This callable is passed + * Registers a ConfigurationValidator callable. This callable is passed * the complete list of configuration sent to an NEM during Component::configure() * and RunningStateMutable::processConfiguration(). The validator returns @a true to * indicate the configuration is valid and @a flase to indicate an error. @@ -125,7 +126,7 @@ namespace EMANE * indicate an error in the configuration. */ virtual void registerValidator(ConfigurationValidator validator) = 0; - + protected: ConfigurationRegistrar(); @@ -226,7 +227,7 @@ namespace EMANE * * Non-Numeric configuration items may have any one of the following types: * - std::string - * - ACE_INET_Addr + * - INETAddr * * @snippet src/models/mac/rfpipe/maclayer.cc configurationregistrar-registernonnumeric-snippet * @@ -250,7 +251,7 @@ namespace EMANE * An optional validator callable is used by the emulator framework to validate configuration item * relationships prior to calling @ref EMANE::Component::configure "Component::configure" or * @ref EMANE::RunningStateMutable::processConfiguration "RunningStateMutable::processConfiguration" on a - * component. + * component. * * A component can register a validator callable using @ref EMANE::ConfigurationRegistrar::registerValidator * "ConfigurationRegistrar::registerValidator". @@ -286,7 +287,7 @@ namespace EMANE * Both @ref EMANE::Component::configure "configure" and @ref EMANE::RunningStateMutable::processConfiguration * "processConfiguration" are passed a single @ref EMANE::ConfigurationUpdate "ConfigurationUpdate" parameter. * - * @snippet include/emane/configurationupdate.h configurationregistrar-configurationnameanyvalues-snippet + * @snippet include/emane/configurationupdate.h configurationregistrar-configurationnameanyvalues-snippet * * @section HandlingConfigurationItems Handling Configuration Items * diff --git a/include/emane/inetaddr.h b/include/emane/inetaddr.h new file mode 100644 index 00000000..5e13f4bc --- /dev/null +++ b/include/emane/inetaddr.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2015 - Adjacent Link LLC, Bridgewater, New Jersey + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Adjacent Link LLC nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef EMANEINETADDR_HEADER_ +#define EMANEINETADDR_HEADER_ + +#include +#include +#include +#include + +namespace EMANE +{ + class INETAddr + { + public: + INETAddr(); + + INETAddr(const std::string & sEndPoint); + + INETAddr(const std::string & sAddr, + std::uint16_t u16Port); + + INETAddr(const sockaddr_in & sockaddr); + + INETAddr(const sockaddr_in6 & sockaddr); + + /** + * Creates an INETAddr instance by copying another instance + */ + INETAddr(const INETAddr & address); + + /** + * Creates an INETAddr instance by moving another instance + */ + INETAddr(INETAddr && address); + + + ~INETAddr(); + + /** + * Sets an INETAddr instance to a copy of another instance + */ + INETAddr & operator=(const INETAddr & address); + + + /** + * Sets and INETAddr instance by moving another instance + */ + INETAddr & operator=(INETAddr && address); + + void set(const std::string & sAddress, std::uint16_t u16Port); + + void set(const std::string & sEndPoint); + + bool isIPv6() const; + + bool isIPv4() const; + + bool isAny() const; + + bool isMulticast() const; + + int getFamily() const; + + sockaddr * getSockAddr() const; + + socklen_t getAddrLength() const; + + std::string str(bool bWithPort = true) const; + + std::uint16_t getPort() const; + + private: + class Implementation; + std::unique_ptr pImpl_; + }; +} + +#endif // EMANEINETADDR_HEADER_ diff --git a/include/emane/inetaddrexception.h b/include/emane/inetaddrexception.h new file mode 100644 index 00000000..5da152e5 --- /dev/null +++ b/include/emane/inetaddrexception.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015 - Adjacent Link LLC, Bridgewater, New Jersey + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Adjacent Link LLC nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef EMANEINETADDREXCEPTION_HEADER_ +#define EMANEINETADDREXCEPTION_HEADER_ + +#include "emane/exception.h" + +namespace EMANE +{ + class INETAddrException : public Exception + { + public: + INETAddrException(const std::string & sDescription): + Exception("INETAddrException",sDescription){} + + ~INETAddrException() throw(){} + }; +} + +#endif //EMANEINETADDREXCEPTION_HEADER_ diff --git a/include/emane/statisticnonnumeric.h b/include/emane/statisticnonnumeric.h index 76614e2f..dff3e05c 100644 --- a/include/emane/statisticnonnumeric.h +++ b/include/emane/statisticnonnumeric.h @@ -1,5 +1,6 @@ /* - * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey + * Copyright (c) 2013-2014,2016 - Adjacent Link LLC, Bridgewater, New + * Jersey * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,9 +44,9 @@ namespace EMANE /** * - * @class StatisticNonNumeric + * @class StatisticNonNumeric * - * @brief A non-numeric statistic can be a std::string or an ACE::INET_Addr. + * @brief A non-numeric statistic can be a std::string or an INETAddr. * */ template @@ -65,7 +66,7 @@ namespace EMANE * @return statistic value */ T get() const; - + /** * Converts the current statistic value to an Any * @@ -74,15 +75,15 @@ namespace EMANE * @throw AnyExpception on conversion failure */ Any asAny() const override; - + /** * Clears the statistic value */ void clear() override; - + private: T value_; - + mutable std::mutex mutex_; StatisticNonNumeric(); diff --git a/include/emane/statisticregistrar.h b/include/emane/statisticregistrar.h index 1fc27c40..32390336 100644 --- a/include/emane/statisticregistrar.h +++ b/include/emane/statisticregistrar.h @@ -1,5 +1,6 @@ /* - * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey + * Copyright (c) 2013-2014,2016 - Adjacent Link LLC, Bridgewater, New + * Jersey * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -53,7 +54,7 @@ namespace EMANE * returned to the registering NEM layer. * * @note Registration may only occur during Component::initialize() - * + * */ class StatisticRegistrar { @@ -62,7 +63,7 @@ namespace EMANE * Destroys an instance */ virtual ~StatisticRegistrar(){} - + /** * Register a numeric statistic. The registered statistic * is owned by the StatisticRegistrar. @@ -131,7 +132,7 @@ namespace EMANE StatisticTable * registerTable(const std::string & sName, const StatisticTableLabels & labels, - const StatisticProperties & properties = StatisticProperties::NONE, + const StatisticProperties & properties = StatisticProperties::NONE, const std::string & sDescription = ""); @@ -172,8 +173,8 @@ namespace EMANE const StatisticTableLabels & labels, Function clearFunc, const std::string & sDescription = ""); - - + + protected: /** * Register a statistic and take ownership @@ -224,7 +225,7 @@ namespace EMANE * The @ref EMANE::StatisticRegistrar "StatisticRegistrar" is used by components to create * statistics and statistic tables. Statistics and statistic tables are owned by the emulator * framework so @ref EMANE::StatisticRegistrar::registerNumeric "StatisticRegistrar::registerNumeric", - * @ref EMANE::StatisticRegistrar::registerNonNumeric "StatisticRegistrar::registerNonNumeric" and + * @ref EMANE::StatisticRegistrar::registerNonNumeric "StatisticRegistrar::registerNonNumeric" and * @ref EMANE::StatisticRegistrar::registerTable "StatisticRegistrar::registerTable" all return * borrowed references. The framework takes care of cleaning these up after all component plugins * have been destroyed. @@ -257,7 +258,7 @@ namespace EMANE * @ref EMANE::StatisticNonNumeric "StatisticNonNumeric" template instances can be instantiated with the * following types: * - std::string - * - ACE_INET_Addr + * - INETAddr * * Statistics can be given the @ref EMANE::StatisticProperties::CLEARABLE "StatisticProperties::CLEARABLE" * property during registration. This property lets client applications clear the statistic using the @@ -288,7 +289,7 @@ namespace EMANE * bool which is used to sort the table. The template parameter defaults are usually what you want. * * @snippet src/libemane/eventtablepublisher.cc statisticservice-registertable-snippet - * + * * Just like statistics, statistic tables can be @a clearable. Clearing a statistic table is not as * straight forward as clearing a statistic. In order to manage statistic table entries you will need * to keep track of which items are in the table and what their current values are. An external clear diff --git a/include/emane/statistictable.inl b/include/emane/statistictable.inl index 53d7a120..47b29e53 100644 --- a/include/emane/statistictable.inl +++ b/include/emane/statistictable.inl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 - Adjacent Link LLC, Bridgewater, New Jersey + * Copyright (c) 2013,2015 - Adjacent Link LLC, Bridgewater, New Jersey * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,6 +31,7 @@ */ #include "emane/statistictableexception.h" +#include template EMANE::StatisticTable::StatisticTable(const StatisticTableLabels & labels): @@ -46,7 +47,7 @@ void EMANE::StatisticTable::setCell(const Key & key, const Any & any) { std::lock_guard m(mutex_); - + auto iter = table_.find(key); if(iter != table_.end()) @@ -101,7 +102,7 @@ void EMANE::StatisticTable::addRow(const Key & key, if(anys.size() == labels_.size()) { - + if(!table_.insert(std::make_pair(key,anys)).second) { throw StatisticTableException("duplicate row key"); @@ -135,11 +136,11 @@ EMANE::StatisticTableValues EMANE::StatisticTable::getValues() const { StatisticTableValues values{}; - + // lock guard block scope { std::lock_guard m(mutex_); - + std::transform(table_.begin(), table_.end(), std::back_inserter(values), @@ -154,7 +155,7 @@ EMANE::StatisticTable::getValues() const { return cmp(a1[sortIndex],a2[sortIndex]); }); - + return values; } @@ -169,7 +170,7 @@ EMANE::StatisticTable::getLabels() const template void EMANE::StatisticTable::clear() -{ +{ std::lock_guard m(mutex_); table_.clear(); } diff --git a/include/emane/utils/Makefile.am b/include/emane/utils/Makefile.am index 13fcc600..949735d2 100644 --- a/include/emane/utils/Makefile.am +++ b/include/emane/utils/Makefile.am @@ -9,12 +9,11 @@ emaneinc_HEADERS = \ parameterconvert.h \ parameterconvert.inl \ randomnumberdistribution.h \ - recvcancelable.h \ singleton.h \ - spawnmemberfunc.h \ spectrumwindowutils.h \ statistichistogramtable.h \ statistichistogramtable.inl \ + threadutils.h \ timer.h \ timer.inl \ runningaverage.h \ diff --git a/include/emane/utils/bitpool.h b/include/emane/utils/bitpool.h index 4dd2bfcb..b2f1bce8 100644 --- a/include/emane/utils/bitpool.h +++ b/include/emane/utils/bitpool.h @@ -1,5 +1,6 @@ /* - * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey + * Copyright (c) 2013-2014,2016 - Adjacent Link LLC, Bridgewater, New + * Jersey * Copyright (c) 2009-2010 - DRS CenGen, LLC, Columbia, Maryland * All rights reserved. * @@ -34,10 +35,6 @@ #ifndef BITPOOL_HEADER_ #define BITPOOL_HEADER_ -#include -#include -#include - #include "emane/types.h" #include "emane/platformserviceprovider.h" @@ -104,7 +101,7 @@ namespace EMANE float fFillRemainder_; - ACE_Thread_Mutex mutex_; + std::mutex mutex_; /** * Adds to pool @@ -123,7 +120,7 @@ namespace EMANE * @return number available in the pool * */ - std::uint64_t doDrainPool(std::uint64_t u64Request, + std::uint64_t doDrainPool(std::uint64_t u64Request, const TimePoint & requestTime, Microseconds & intervalMicroseconds); }; diff --git a/include/emane/utils/bitpool.inl b/include/emane/utils/bitpool.inl index ce0628a6..43245ba2 100644 --- a/include/emane/utils/bitpool.inl +++ b/include/emane/utils/bitpool.inl @@ -1,5 +1,6 @@ /* - * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey + * Copyright (c) 2013-2014,2016 - Adjacent Link LLC, Bridgewater, New + * Jersey * Copyright (c) 2009-2010 - DRS CenGen, LLC, Columbia, Maryland * All rights reserved. * @@ -34,10 +35,7 @@ #include "bitpool.h" #include - -#include -#include - +#include namespace { @@ -49,8 +47,8 @@ inline EMANE::Utils::BitPool::BitPool(PlatformServiceProvider * pPlatformService, NEMId id) : pPlatformService_{pPlatformService}, id_(id), - u64MaxSize_{}, - u64CurrentSize_{}, + u64MaxSize_{}, + u64CurrentSize_{}, lastRequestTime_{}, fFillRemainder_{} { } @@ -63,14 +61,14 @@ EMANE::Utils::BitPool::~BitPool() inline - void + void EMANE::Utils::BitPool::setMaxSize(std::uint64_t u64NewSize) { // lock mutex - ACE_Guard m(mutex_); + std::lock_guard m(mutex_); // size changed - if(u64NewSize != u64MaxSize_) + if(u64NewSize != u64MaxSize_) { LOGGER_VERBOSE_LOGGING(pPlatformService_->logService(), DEBUG_LEVEL, @@ -81,7 +79,7 @@ EMANE::Utils::BitPool::setMaxSize(std::uint64_t u64NewSize) u64NewSize); // new size is less than current size - if(u64CurrentSize_ > u64NewSize) + if(u64CurrentSize_ > u64NewSize) { // reduce current size u64CurrentSize_ = u64NewSize; @@ -95,14 +93,14 @@ EMANE::Utils::BitPool::setMaxSize(std::uint64_t u64NewSize) inline -std::uint64_t +std::uint64_t EMANE::Utils::BitPool::get(std::uint64_t u64Request, bool bFullFill) { // lock mutex - ACE_Guard m(mutex_); + std::lock_guard m(mutex_); // disabled - if(u64MaxSize_ == 0 || u64Request == 0) + if(u64MaxSize_ == 0 || u64Request == 0) { // nothing outstanding return 0; @@ -112,7 +110,7 @@ EMANE::Utils::BitPool::get(std::uint64_t u64Request, bool bFullFill) std::uint64_t u64Acquired{}; // try to fulfill request - while(1) + while(1) { TimePoint currentTime = Clock::now(); @@ -121,41 +119,35 @@ EMANE::Utils::BitPool::get(std::uint64_t u64Request, bool bFullFill) // make request u64Acquired += doDrainPool(u64Request - u64Acquired, currentTime, waitIntervalMicroseconds); - + LOGGER_VERBOSE_LOGGING(pPlatformService_->logService(), DEBUG_LEVEL, "NEM %03hu BitPool::%s request %ju, acquired %ju, pool remaining %ju, %4.2f%%", id_, - __func__, - u64Request, + __func__, + u64Request, u64Acquired, u64CurrentSize_, - 100.0f * (1.0f - (static_cast(u64MaxSize_ - u64CurrentSize_) / + 100.0f * (1.0f - (static_cast(u64MaxSize_ - u64CurrentSize_) / static_cast(u64MaxSize_)))); - // request fulfilled - if(!bFullFill || u64Acquired == u64Request) + // request fulfilled + if(!bFullFill || u64Acquired == u64Request) { // done break; - } - - // absolute wait time - ACE_Time_Value tvWaitTime; - - Microseconds microseconds = std::chrono::duration_cast(currentTime.time_since_epoch()) + - waitIntervalMicroseconds; - - tvWaitTime.set(microseconds.count() / 1000000.0); + } - // local mutex - ACE_Thread_Mutex mutex; + // local mutex + std::mutex mutex; // condition variable - ACE_Condition cond(mutex); + std::condition_variable cond{}; + + std::unique_lock lock(mutex); // wait here - if(cond.wait(&tvWaitTime) != -1) { + if(cond.wait_until(lock,currentTime + waitIntervalMicroseconds) != std::cv_status::timeout) { // did not time out, spurious wake up break; @@ -168,20 +160,20 @@ EMANE::Utils::BitPool::get(std::uint64_t u64Request, bool bFullFill) inline -std::uint64_t +std::uint64_t EMANE::Utils::BitPool::getCurrentSize() { // lock mutex - ACE_Guard m(mutex_); + std::lock_guard m(mutex_); return u64CurrentSize_; } inline -std::uint64_t -EMANE::Utils::BitPool::doDrainPool(std::uint64_t u64Request, - const TimePoint & requestTime, +std::uint64_t +EMANE::Utils::BitPool::doDrainPool(std::uint64_t u64Request, + const TimePoint & requestTime, Microseconds & intervalMicroseconds) { std::uint64_t u64Acquired{}; @@ -190,7 +182,7 @@ EMANE::Utils::BitPool::doDrainPool(std::uint64_t u64Request, doFillPool(requestTime); // drain the pool - if(u64Request > u64CurrentSize_) + if(u64Request > u64CurrentSize_) { // size outstanding std::uint64_t u64Outstanding{u64Request - u64CurrentSize_}; @@ -208,7 +200,7 @@ EMANE::Utils::BitPool::doDrainPool(std::uint64_t u64Request, intervalMicroseconds = std::chrono::duration_cast(DoubleSeconds{fSeconds}); // cap wait interval to fill interval - if(intervalMicroseconds > FillIntervalMicroseconds) + if(intervalMicroseconds > FillIntervalMicroseconds) { intervalMicroseconds = FillIntervalMicroseconds; } @@ -234,7 +226,7 @@ EMANE::Utils::BitPool::doDrainPool(std::uint64_t u64Request, inline -void +void EMANE::Utils::BitPool::doFillPool(const TimePoint & requestTime) { // fill the pool since last request @@ -242,29 +234,29 @@ EMANE::Utils::BitPool::doFillPool(const TimePoint & requestTime) { // time since last request Microseconds deltaTMicroseconds{std::chrono::duration_cast(requestTime - lastRequestTime_)}; - + // fill the pool depending on elapsed time - if(deltaTMicroseconds >= FillIntervalMicroseconds) + if(deltaTMicroseconds >= FillIntervalMicroseconds) { // fill to full capacity u64CurrentSize_ = u64MaxSize_; fFillRemainder_ = 0; } - else + else { // find the amount of time into the fill interval Microseconds diffMicroseconds{FillIntervalMicroseconds - (FillIntervalMicroseconds - deltaTMicroseconds)}; // accumulate fill amount for this interval - fFillRemainder_ += (static_cast(diffMicroseconds.count()) / + fFillRemainder_ += (static_cast(diffMicroseconds.count()) / static_cast(FillIntervalMicroseconds.count())) * u64MaxSize_; // have at least a whole unit if(fFillRemainder_ >= 1.0f) { std::uint64_t u64Fill{static_cast(fFillRemainder_)}; - + // fill pool if((u64CurrentSize_ + u64Fill) <= u64MaxSize_) { @@ -274,10 +266,10 @@ EMANE::Utils::BitPool::doFillPool(const TimePoint & requestTime) { u64CurrentSize_ = u64MaxSize_; } - + // keep fraction remainder fFillRemainder_ -= u64Fill; - } + } } } } diff --git a/include/emane/utils/netutils.h b/include/emane/utils/netutils.h index f4dfef1f..d7947893 100644 --- a/include/emane/utils/netutils.h +++ b/include/emane/utils/netutils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 - Adjacent Link LLC, Bridgewater, New Jersey + * Copyright (c) 2013,2016 - Adjacent Link LLC, Bridgewater, New Jersey * Copyright (c) 2008-2010 - DRS CenGen, LLC, Columbia, Maryland * All rights reserved. * @@ -34,45 +34,16 @@ #ifndef EMANEUTILSNETUTILS_HEADER_ #define EMANEUTILSNETUTILS_HEADER_ -#include -#include #include #include +#include +#include +#include namespace EMANE { namespace Utils { - /** - * @union INET_Addr - * - * @brief Definition of an ipv4/ipv6 internet address - * - */ - union INET_Addr - { - sockaddr_in in4_; -#if defined (ACE_HAS_IPV6) - sockaddr_in6 in6_; -#endif /* ACE_HAS_IPV6 */ - }; - - // Return @c true if the IP address is IPv4/IPv6 multicast address. - // Internal version of is_multicast due to bug in at least ACE version 5.6.2 - // See doc directory for available patches. - inline bool - is_multicast (const ACE_INET_Addr & addr) - { - INET_Addr *p = (INET_Addr*) addr.get_addr(); -#if defined (ACE_HAS_IPV6) - if (addr.get_type() == AF_INET6) - return p->in6_.sin6_addr.s6_addr[0] == 0xFF; -#endif /* ACE_HAS_IPV6 */ - return - ACE_NTOHL(p->in4_.sin_addr.s_addr) >= 0xE0000000 && // 224.0.0.0 - ACE_NTOHL(p->in4_.sin_addr.s_addr) <= 0xEFFFFFFF; // 239.255.255.255 - } - /** * @struct UdpHeader * @@ -82,10 +53,10 @@ namespace EMANE struct UdpHeader { - ACE_UINT16 u16Udpsrc; - ACE_UINT16 u16Udpdst; - ACE_UINT16 u16Udplen; - ACE_UINT16 u16Udpcheck; + std::uint16_t u16Udpsrc; + std::uint16_t u16Udpdst; + std::uint16_t u16Udplen; + std::uint16_t u16Udpcheck; } __attribute__((packed)); @@ -94,14 +65,14 @@ namespace EMANE * @brief ip udp protocol * */ - const ACE_UINT8 IP_PROTO_UDP = 0x11; + const std::uint8_t IP_PROTO_UDP = 0x11; /** * * @brief udp header len * */ - const ACE_UINT16 UDP_HEADER_LEN = 8; + const std::uint16_t UDP_HEADER_LEN = 8; /** @@ -110,8 +81,8 @@ namespace EMANE * @return returns the ip header version * */ - inline ACE_UINT8 - get_ip_version(ACE_UINT8 vhl) + inline std::uint8_t + get_ip_version(std::uint8_t vhl) { return ((vhl >> 4) & 0x0F); } @@ -122,8 +93,8 @@ namespace EMANE * @return returns the ip header length * */ - inline ACE_UINT8 - get_ip_hdrlen(ACE_UINT8 vhl) + inline std::uint8_t + get_ip_hdrlen(std::uint8_t vhl) { return ((vhl & 0x0F) << 2); } @@ -136,8 +107,8 @@ namespace EMANE * @return returns ipv4 dscp value * */ - inline ACE_UINT8 - get_ip_dscp(ACE_UINT8 tos) + inline std::uint8_t + get_ip_dscp(std::uint8_t tos) { return (tos >> 2); } @@ -151,8 +122,8 @@ namespace EMANE * */ - inline ACE_UINT8 - get_ip_dscp(ACE_UINT8 ver, ACE_UINT8 clas) + inline std::uint8_t + get_ip_dscp(std::uint8_t ver, std::uint8_t clas) { return (((ver & 0x0F) << 2) | (clas >> 6)); } @@ -167,16 +138,16 @@ namespace EMANE */ struct Ip4Header { - ACE_UINT8 u8Ipv4vhl; - ACE_UINT8 u8Ipv4tos; - ACE_UINT16 u16Ipv4len; - ACE_UINT16 u16Ipv4id; - ACE_UINT16 u16Ipv4frag; - ACE_UINT8 u8Ipv4hops; - ACE_UINT8 u8Ipv4proto; - ACE_UINT16 u16Ipv4check; - ACE_UINT32 u32Ipv4src; - ACE_UINT32 u32Ipv4dst; + std::uint8_t u8Ipv4vhl; + std::uint8_t u8Ipv4tos; + std::uint16_t u16Ipv4len; + std::uint16_t u16Ipv4id; + std::uint16_t u16Ipv4frag; + std::uint8_t u8Ipv4hops; + std::uint8_t u8Ipv4proto; + std::uint16_t u16Ipv4check; + std::uint32_t u32Ipv4src; + std::uint32_t u32Ipv4dst; } __attribute__((packed)); /** @@ -184,30 +155,30 @@ namespace EMANE * @brief ipv4 header len without options * */ - const ACE_UINT16 IPV4_HEADER_LEN = 20; + const std::uint16_t IPV4_HEADER_LEN = 20; /** * - * @brief ipv4 addr len + * @brief ipv4 addr len * */ - const ACE_UINT16 IPV4_ADDR_LEN = 4; + const std::uint16_t IPV4_ADDR_LEN = 4; /** * - * @brief ipv6 addr len + * @brief ipv6 addr len * */ - const ACE_UINT16 IPV6_ADDR_LEN = 16; + const std::uint16_t IPV6_ADDR_LEN = 16; /** * * @brief IPv6 ICMP Protocol * */ - const ACE_UINT8 IPV6_P_ICMP = 0x3A; + const std::uint8_t IPV6_P_ICMP = 0x3A; /** * @@ -216,7 +187,7 @@ namespace EMANE * @return returns the ip header version (hopefully version 4) * */ - inline ACE_UINT8 + inline std::uint8_t get_version(const Ip4Header *ip) { return get_ip_version(ip->u8Ipv4vhl); @@ -230,7 +201,7 @@ namespace EMANE * @return returns the ipv4 header length with options in bytes * */ - inline ACE_UINT8 + inline std::uint8_t get_hdrlen(const Ip4Header *ip) { return get_ip_hdrlen(ip->u8Ipv4vhl); @@ -244,10 +215,10 @@ namespace EMANE * @return returns the total ipv4 packet length * */ - inline ACE_UINT16 + inline std::uint16_t get_len(const Ip4Header *ip) { - return ACE_NTOHS(ip->u16Ipv4len); + return ntohs(ip->u16Ipv4len); } @@ -258,7 +229,7 @@ namespace EMANE * @return returns the dscp value * */ - inline ACE_UINT8 + inline std::uint8_t get_dscp(const Ip4Header *ip) { return get_ip_dscp(ip->u8Ipv4tos); @@ -274,17 +245,17 @@ namespace EMANE * */ inline void - addr_to_string(const ACE_UINT8 * addr, size_t addrlen, const char *delim, char *buf, size_t buflen) + addr_to_string(const std::uint8_t * addr, size_t addrlen, const char *delim, char *buf, size_t buflen) { size_t pos = 0; - for(size_t i = 0; i < addrlen; ++i) + for(size_t i = 0; i < addrlen; ++i) { - if(i < (addrlen - 1)) + if(i < (addrlen - 1)) { pos += snprintf(buf + pos, buflen - pos, "%02X%s", addr[i] & 0xFF, delim); } - else + else { pos += snprintf(buf + pos, buflen - pos, "%02X", addr[i] & 0xFF); } @@ -301,17 +272,17 @@ namespace EMANE */ struct Ip6Header { - struct { - ACE_UINT8 u8Ipv6Ver; - ACE_UINT8 u8Ipv6Class; - ACE_UINT16 u16Ipv6Flow; + struct { + std::uint8_t u8Ipv6Ver; + std::uint8_t u8Ipv6Class; + std::uint16_t u16Ipv6Flow; } vcf; - ACE_UINT16 u16Ipv6len; - ACE_UINT8 u8Ipv6next; - ACE_UINT8 u8Ipv6hops; - ACE_UINT8 Ipv6src[IPV6_ADDR_LEN]; - ACE_UINT8 Ipv6dst[IPV6_ADDR_LEN]; + std::uint16_t u16Ipv6len; + std::uint8_t u8Ipv6next; + std::uint8_t u8Ipv6hops; + std::uint8_t Ipv6src[IPV6_ADDR_LEN]; + std::uint8_t Ipv6dst[IPV6_ADDR_LEN]; } __attribute__((packed)); /** @@ -319,36 +290,36 @@ namespace EMANE * @brief ipv6 header len * */ - const ACE_UINT16 IPV6_HEADER_LEN = 40; + const std::uint16_t IPV6_HEADER_LEN = 40; /** * * @brief ipv6 max addr len * */ - const ACE_UINT16 IPV6_MAX_BIT_LEN = 128; + const std::uint16_t IPV6_MAX_BIT_LEN = 128; - inline ACE_UINT8 + inline std::uint8_t get_version(const Ip6Header *ip) { return get_ip_version(ip->vcf.u8Ipv6Ver); } - inline ACE_UINT8 + inline std::uint8_t get_hdrlen(const Ip6Header *ip) { return get_ip_hdrlen(ip->vcf.u8Ipv6Ver); } - inline ACE_UINT16 + inline std::uint16_t get_len(const Ip6Header *ip) { - return (ACE_NTOHS(ip->u16Ipv6len) + IPV6_HEADER_LEN); + return (ntohs(ip->u16Ipv6len) + IPV6_HEADER_LEN); } - inline ACE_UINT8 + inline std::uint8_t get_dscp(const Ip6Header *ip) { return get_ip_dscp(ip->vcf.u8Ipv6Ver, ip->vcf.u8Ipv6Class); @@ -361,7 +332,7 @@ namespace EMANE * @brief Ethernet hardware address length * */ - const ACE_UINT16 ETH_ALEN = 6; + const std::uint16_t ETH_ALEN = 6; /** @@ -369,7 +340,7 @@ namespace EMANE * @brief Ethernet header length. * */ - const ACE_UINT16 ETH_HEADER_LEN = 14; + const std::uint16_t ETH_HEADER_LEN = 14; /** @@ -377,14 +348,14 @@ namespace EMANE * @brief Ethernet Arp header length. * */ - const ACE_UINT16 ETHARP_HEADER_LEN = 28; + const std::uint16_t ETHARP_HEADER_LEN = 28; /** * * @brief Max ip packet len * */ - const ACE_UINT16 IP_MAX_PACKET = 0xFFFF; + const std::uint16_t IP_MAX_PACKET = 0xFFFF; /** @@ -392,7 +363,7 @@ namespace EMANE * @brief Ethernet hardware type * */ - const ACE_UINT16 ARPHRD_ETHER = 0x0001; + const std::uint16_t ARPHRD_ETHER = 0x0001; /** @@ -400,7 +371,7 @@ namespace EMANE * @brief Ethernet ipv4 protocol * */ - const ACE_UINT16 ETH_P_IPV4 = 0x0800; + const std::uint16_t ETH_P_IPV4 = 0x0800; /** @@ -408,14 +379,14 @@ namespace EMANE * @brief Ethernet arp protocol * */ - const ACE_UINT16 ETH_P_ARP = 0x0806; + const std::uint16_t ETH_P_ARP = 0x0806; /** * * @brief Ethernet ipv6 protocol * */ - const ACE_UINT16 ETH_P_IPV6 = 0x86DD; + const std::uint16_t ETH_P_IPV6 = 0x86DD; /** * @@ -425,7 +396,7 @@ namespace EMANE * */ struct EtherAddrBytes{ - ACE_UINT8 buff[ETH_ALEN]; + std::uint8_t buff[ETH_ALEN]; } __attribute__((packed)); /** @@ -436,9 +407,9 @@ namespace EMANE * */ struct EtherAddrWords{ - ACE_UINT16 word1; - ACE_UINT16 word2; - ACE_UINT16 word3; + std::uint16_t word1; + std::uint16_t word2; + std::uint16_t word3; } __attribute__((packed)); /** @@ -463,13 +434,13 @@ namespace EMANE struct EtherHeader{ union EtherAddr dst; union EtherAddr src; - ACE_UINT16 u16proto; + std::uint16_t u16proto; } __attribute__((packed)); /** * - * @param eth a pointer to an EtherHeader + * @param eth a pointer to an EtherHeader * * @return returns a pointer the src EtherAddr * @@ -482,7 +453,7 @@ namespace EMANE /** * - * @param eth a pointer to an EtherHeader + * @param eth a pointer to an EtherHeader * * @return returns a pointer the dst EtherAddr * @@ -495,22 +466,22 @@ namespace EMANE /** * - * @param eth a pointer to an EtherHeader + * @param eth a pointer to an EtherHeader * * @return returns the ether protocol id in host byte order * */ - inline ACE_UINT16 + inline std::uint16_t get_protocol(const EtherHeader *eth) { - return ACE_NTOHS(eth->u16proto); + return ntohs(eth->u16proto); } /** * - * @param addr a pointer to an EtherAddr + * @param addr a pointer to an EtherAddr * * @return returns the formatted address string * @@ -520,7 +491,7 @@ namespace EMANE { static char buf[64]; - addr_to_string((ACE_UINT8*) addr, ETH_ALEN, ":", buf, sizeof(buf)); + addr_to_string((std::uint8_t*) addr, ETH_ALEN, ":", buf, sizeof(buf)); return buf; } @@ -528,7 +499,7 @@ namespace EMANE /** * - * @param addr a pointer to an EtherAddr + * @param addr a pointer to an EtherAddr * * @return returns the formatted address string * @@ -538,7 +509,7 @@ namespace EMANE { char buf[64]; - addr_to_string((ACE_UINT8*) addr, ETH_ALEN, ":", buf, sizeof(buf)); + addr_to_string((std::uint8_t*) addr, ETH_ALEN, ":", buf, sizeof(buf)); return buf; } @@ -554,53 +525,53 @@ namespace EMANE */ struct EtherArpHeader { - ACE_UINT16 u16hwType; - ACE_UINT16 u16protocol; - ACE_UINT8 u8hwAddrLen; - ACE_UINT8 u8protoAddrLen; - ACE_UINT16 u16code; + std::uint16_t u16hwType; + std::uint16_t u16protocol; + std::uint8_t u8hwAddrLen; + std::uint8_t u8protoAddrLen; + std::uint16_t u16code; EtherAddr srcHwAddr; - ACE_UINT32 u32srcProtoAddr; + std::uint32_t u32srcProtoAddr; EtherAddr dstHwAddr; - ACE_UINT32 u32dstProtoAddr; + std::uint32_t u32dstProtoAddr; } __attribute__((packed)); /** * - * @param arp a pointer to an EtherArpHeader + * @param arp a pointer to an EtherArpHeader * * @return returns the hardware type * */ - inline ACE_UINT16 + inline std::uint16_t get_hwtype(const EtherArpHeader *arp) { - return ACE_NTOHS(arp->u16hwType); + return ntohs(arp->u16hwType); } /** * - * @param arp a pointer to an EtherArpHeader + * @param arp a pointer to an EtherArpHeader * * @return returns the protocol id in host byte order * */ - inline ACE_UINT16 + inline std::uint16_t get_protocol(const EtherArpHeader *arp) { - return ACE_NTOHS(arp->u16protocol); + return ntohs(arp->u16protocol); } /** * - * @param arp a pointer to an EtherArpHeader + * @param arp a pointer to an EtherArpHeader * * @return returns the hardware address len * */ - inline ACE_UINT8 + inline std::uint8_t get_hwaddrlen(const EtherArpHeader *arp) { return (arp->u8hwAddrLen); @@ -609,12 +580,12 @@ namespace EMANE /** * - * @param arp a pointer to an EtherArpHeader + * @param arp a pointer to an EtherArpHeader * * @return returns the protocol addresss len * */ - inline ACE_UINT8 + inline std::uint8_t get_protoaddrlen(const EtherArpHeader *arp) { return (arp->u8protoAddrLen); @@ -622,21 +593,21 @@ namespace EMANE /** * - * @param arp a pointer to an EtherArpHeader + * @param arp a pointer to an EtherArpHeader * * @return returns the arp code in host byte order * */ - inline ACE_UINT16 + inline std::uint16_t get_code(const EtherArpHeader *arp) { - return ACE_NTOHS(arp->u16code); + return ntohs(arp->u16code); } /** * - * @param arp a pointer to an EtherArpHeader + * @param arp a pointer to an EtherArpHeader * * @return returns the src (requestor) hardware address * @@ -650,7 +621,7 @@ namespace EMANE /** * - * @param arp a pointer to an EtherArpHeader + * @param arp a pointer to an EtherArpHeader * * @return returns the destination (responder) hardware address * @@ -663,12 +634,12 @@ namespace EMANE /** * - * @param arp a pointer to an EtherArpHeader + * @param arp a pointer to an EtherArpHeader * * @return returns the src (requestor) protocol address * */ - inline ACE_UINT32 + inline std::uint32_t get_srcprotoaddr(const EtherArpHeader *arp) { return (arp->u32srcProtoAddr); @@ -677,12 +648,12 @@ namespace EMANE /** * - * @param arp a pointer to an EtherArpHeader + * @param arp a pointer to an EtherArpHeader * * @return returns the (responder) destination protocol address * */ - inline ACE_UINT32 + inline std::uint32_t get_dstprotoaddr(const EtherArpHeader *arp) { return (arp->u32dstProtoAddr); @@ -694,7 +665,7 @@ namespace EMANE * @brief Ethernet arp request * */ - const ACE_UINT16 ETH_ARPOP_REQUEST = 0x0001; + const std::uint16_t ETH_ARPOP_REQUEST = 0x0001; /** @@ -702,7 +673,7 @@ namespace EMANE * @brief Ethernet arp reply * */ - const ACE_UINT16 ETH_ARPOP_REPLY = 0x0002; + const std::uint16_t ETH_ARPOP_REPLY = 0x0002; @@ -713,29 +684,29 @@ namespace EMANE * @return returns the derived NEM id * */ - inline ACE_UINT16 + inline std::uint16_t ethaddr4_to_id (const EtherAddr *addr) { // multicast mac - static ACE_UINT8 MulticastMacAddr[3] = {0x01, 0x00, 0x5E}; + static std::uint8_t MulticastMacAddr[3] = {0x01, 0x00, 0x5E}; // broadcast mac - static ACE_UINT8 BroadcastMacAddr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + static std::uint8_t BroadcastMacAddr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // multicast - if(ACE_OS::memcmp(addr->bytes.buff, MulticastMacAddr, 3) == 0) + if(memcmp(addr->bytes.buff, MulticastMacAddr, 3) == 0) { - return ACE_NTOHS(0xFFFF); + return ntohs(0xFFFF); } // broadcast - else if(ACE_OS::memcmp(addr->bytes.buff, BroadcastMacAddr, 6) == 0) + else if(memcmp(addr->bytes.buff, BroadcastMacAddr, 6) == 0) { - return ACE_NTOHS(0xFFFF); + return ntohs(0xFFFF); } // unicast - else - { - return ACE_NTOHS(addr->words.word3); + else + { + return ntohs(addr->words.word3); } } @@ -747,29 +718,29 @@ namespace EMANE * @return returns the derived NEM id * */ - inline ACE_UINT16 + inline std::uint16_t ethaddr6_to_id (const EtherAddr *addr) { // multicast mac - static ACE_UINT8 MulticastMacAddr[2] = {0x33, 0x33}; + static std::uint8_t MulticastMacAddr[2] = {0x33, 0x33}; // broadcast mac - static ACE_UINT8 BroadcastMacAddr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + static std::uint8_t BroadcastMacAddr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // multicast - if(ACE_OS::memcmp(addr->bytes.buff, MulticastMacAddr, 2) == 0) + if(memcmp(addr->bytes.buff, MulticastMacAddr, 2) == 0) { - return ACE_NTOHS(0xFFFF); + return ntohs(0xFFFF); } // broadcast - else if(ACE_OS::memcmp(addr->bytes.buff, BroadcastMacAddr, 6) == 0) + else if(memcmp(addr->bytes.buff, BroadcastMacAddr, 6) == 0) { - return ACE_NTOHS(0xFFFF); + return ntohs(0xFFFF); } // unicast - else - { - return ACE_NTOHS(addr->words.word3); + else + { + return ntohs(addr->words.word3); } } @@ -780,11 +751,11 @@ namespace EMANE * @return returns the prefix length in bits * */ - inline ACE_UINT8 + inline std::uint8_t get_prefixlen (const in6_addr *prefix) { - ACE_UINT8 len = 0; - ACE_UINT8 *u8ptr = (ACE_UINT8 *) prefix; + std::uint8_t len = 0; + std::uint8_t *u8ptr = (std::uint8_t *) prefix; while ((*u8ptr == 0xff) && len < IPV6_MAX_BIT_LEN) { @@ -794,7 +765,7 @@ namespace EMANE if (len < IPV6_MAX_BIT_LEN) { - ACE_UINT8 byte = *u8ptr; + std::uint8_t byte = *u8ptr; while (byte) { len++; @@ -812,16 +783,16 @@ namespace EMANE * @param buflen length of buffer * @param prev running sum * - * @return returns the 16 bit one’s complement of the one’s complement + * @return returns the 16 bit one’s complement of the one’s complement * sum of all 16 bit words in the buffer * */ - inline ACE_UINT16 - inet_cksum (const void * buf, int buflen, ACE_UINT16 prev = 0) + inline std::uint16_t + inet_cksum (const void * buf, int buflen, std::uint16_t prev = 0) { - ACE_UINT32 sum = 0; - ACE_UINT16 *w = (ACE_UINT16 *) buf; + std::uint32_t sum = 0; + std::uint16_t *w = (std::uint16_t *) buf; while (buflen > 1) { sum += *w; @@ -830,7 +801,7 @@ namespace EMANE } if (buflen) { - ACE_UINT8 *byte = (ACE_UINT8 *) w; + std::uint8_t *byte = (std::uint8_t *) w; sum += *byte; } @@ -840,16 +811,16 @@ namespace EMANE } /** - * @struct IP6ICMPHeader + * @struct IP6ICMPHeader * * @brief Definition of the IPv6 ICMP header. * */ struct IP6ICMPHeader { - ACE_UINT8 u8Type; - ACE_UINT8 u8Code; - ACE_UINT16 u16Checksum; - ACE_UINT32 u32Flags; + std::uint8_t u8Type; + std::uint8_t u8Code; + std::uint16_t u16Checksum; + std::uint32_t u32Flags; sockaddr_in6 targetAddr; } __attribute__((packed)); @@ -858,14 +829,14 @@ namespace EMANE * @brief IPv6 ICMP Neighbor Soliciation * */ - const ACE_UINT8 IP6_ICMP_NEIGH_SOLICIT = 135; - + const std::uint8_t IP6_ICMP_NEIGH_SOLICIT = 135; + /** * * @brief IPv6 ICMP Neighbor Advertisement * */ - const ACE_UINT8 IP6_ICMP_NEIGH_ADVERT = 136; + const std::uint8_t IP6_ICMP_NEIGH_ADVERT = 136; /** * @param val the frequency in Hz @@ -875,7 +846,7 @@ namespace EMANE * */ - inline std::string formatFrequency(const ACE_UINT64 val, const int precision = 6) + inline std::string formatFrequency(const std::uint64_t val, const int precision = 6) { std::stringstream ss; @@ -899,7 +870,7 @@ namespace EMANE { ss << (fFrequency / 1e+9) << " GHz"; } - else + else { ss << (fFrequency / 1e+12) << " THz"; } @@ -916,8 +887,8 @@ namespace EMANE std::string str = sInput; std::vector strVector; - - while ((pzToken = ACE_OS::strtok (iTokenCount == 0 ? &str[0] : NULL, pzDelimeter)) != NULL) + + while ((pzToken = strtok (iTokenCount == 0 ? &str[0] : NULL, pzDelimeter)) != NULL) { ++iTokenCount; diff --git a/include/emane/utils/parameterconvert.h b/include/emane/utils/parameterconvert.h index ad2dafec..f04d917a 100644 --- a/include/emane/utils/parameterconvert.h +++ b/include/emane/utils/parameterconvert.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey + * Copyright (c) 2013-2015 - Adjacent Link LLC, Bridgewater, New Jersey * Copyright (c) 2009 - DRS CenGen, LLC, Columbia, Maryland * All rights reserved. * @@ -35,13 +35,11 @@ #define EMANEUTILSPARAMETERCONVERT_HEADER_ #include "emane/exception.h" - +#include "emane/inetaddr.h" #include #include #include -#include - namespace EMANE { namespace Utils @@ -67,7 +65,7 @@ namespace EMANE public: ConversionException(const std::string & sDescription): Exception("ConvertionException",sDescription){} - + ~ConversionException() throw(){} }; @@ -77,12 +75,12 @@ namespace EMANE * @param sParameter Value as a string */ ParameterConvert(const std::string & sParameter); - + /** * Destroys an instance */ ~ParameterConvert(); - + /** * Convert parameter string to an std::int64_t * @@ -111,7 +109,7 @@ namespace EMANE std::uint64_t toUINT64(std::uint64_t u64Min = std::numeric_limits::min(), std::uint64_t u64Max = std::numeric_limits::max()) const; - + /** * Convert parameter string to an std::int32_t * @@ -153,7 +151,7 @@ namespace EMANE */ std::int16_t toINT16(std::int16_t i16Min = std::numeric_limits::min(), std::int16_t i16Max = std::numeric_limits::max()) const; - + /** * Convert parameter string to an std::uint16_t * @@ -225,14 +223,14 @@ namespace EMANE double dMax = std::numeric_limits::max()) const; /** - * Convert parameter string to an ACE_INET_Addr + * Convert parameter string to an INETAddr * - * @return ACE_INET_Addr value + * @return INETAddr value * * @exception ConversionException Thrown when an error is encountered during * conversion either to input format or out of range value. */ - ACE_INET_Addr toINETAddr() const; + INETAddr toINETAddr() const; /** * Convert parameter string to an bool diff --git a/include/emane/utils/parameterconvert.inl b/include/emane/utils/parameterconvert.inl index 9324437f..085ff3be 100644 --- a/include/emane/utils/parameterconvert.inl +++ b/include/emane/utils/parameterconvert.inl @@ -1,4 +1,5 @@ /* + * Copyright (c) 2015 - Adjacent Link LLC, Bridgewater, New Jersey * Copyright (c) 2009,2012 - DRS CenGen, LLC, Columbia, Maryland * All rights reserved. * @@ -32,15 +33,16 @@ #include #include +#include namespace { std::string scaleNumericalStringRepresentation(const std::string & sValue) { std::string sTmpParameter(sValue); - + std::uint8_t u8PowerOf10 = 0; - + switch(*(sValue.end() - 1)) { case 'G': @@ -58,17 +60,17 @@ namespace u8PowerOf10 = 3; break; } - + if(u8PowerOf10 != 0) { // location of decimal point, if exists std::string::size_type indexPoint = sTmpParameter.find(".",0); - + if(indexPoint != std::string::npos) { - std::string::size_type numberOfDigitsAfterPoint = + std::string::size_type numberOfDigitsAfterPoint = sTmpParameter.size() - indexPoint - 1; - + if(numberOfDigitsAfterPoint > u8PowerOf10) { // need to move the decimal point, enough digits are present @@ -80,7 +82,7 @@ namespace // need to append 0s sTmpParameter.append(u8PowerOf10 - numberOfDigitsAfterPoint,'0'); } - + // remove original decimal point sTmpParameter.erase(indexPoint,1); } @@ -138,7 +140,7 @@ std::int64_t EMANE::Utils::ParameterConvert::toINT64(std::int64_t i64Min, std::i throw ConversionException(sstream.str()); } } - + return llValue; } @@ -146,7 +148,7 @@ inline std::uint64_t EMANE::Utils::ParameterConvert::toUINT64(std::uint64_t u64Min, std::uint64_t u64Max) const { unsigned long long ullValue = 0; - + if(sParameter_.empty()) { throw ConversionException("Empty string in numeric conversion"); @@ -156,12 +158,12 @@ std::uint64_t EMANE::Utils::ParameterConvert::toUINT64(std::uint64_t u64Min, std std::string sTmpParameter(scaleNumericalStringRepresentation(sParameter_)); char * pEnd = 0; - + //Clear errno before making call because Ubuntu does not //clear it when a call is made errno = 0; - ullValue = ACE_OS::strtoull(sTmpParameter.c_str(),&pEnd,0); + ullValue = strtoull(sTmpParameter.c_str(),&pEnd,0); if(errno == ERANGE || ullValue < u64Min || @@ -178,7 +180,7 @@ std::uint64_t EMANE::Utils::ParameterConvert::toUINT64(std::uint64_t u64Min, std throw ConversionException(sstream.str()); } } - + return ullValue; } @@ -244,33 +246,15 @@ bool EMANE::Utils::ParameterConvert::toBool() const } inline -ACE_INET_Addr EMANE::Utils::ParameterConvert::toINETAddr() const +EMANE::INETAddr EMANE::Utils::ParameterConvert::toINETAddr() const { - size_t pos = sParameter_.rfind("/"); + INETAddr addr; - if(pos == std::string::npos) + try { - // only used ':' as a port seperator for - // hostname or IPv4 addresses - if(std::count(sParameter_.begin(), - sParameter_.end(), - ':') == 1) - { - pos = sParameter_.rfind(":"); - } + addr.set(sParameter_); } - - std::string sAddress{sParameter_}; - std::uint16_t u16Port{}; - ACE_INET_Addr addr; - - if(pos != std::string::npos) - { - sAddress = sParameter_.substr(0,pos); - u16Port = ParameterConvert(sParameter_.substr(pos+1)).toUINT16(); - } - - if(addr.set(u16Port,sAddress.c_str()) == -1) + catch(...) { std::stringstream sstream; sstream<<"'"< -#include - -namespace -{ - template - class Func - { - public: - T & r_; - ACE_THR_FUNC_RETURN (T::*f_)(); - Func(T & r, ACE_THR_FUNC_RETURN (T::*f)()):r_(r),f_(f){}; - }; - - template - ACE_THR_FUNC_RETURN start_routine (void * arg) - { - std::unique_ptr> p(reinterpret_cast *>(arg)); - return (p->r_.*(p->f_))(); - } -} - -namespace EMANE -{ - namespace Utils - { - /** - * Create a new thread, which executes @a member function of class @a T. - * - * @return Unique group id used to control other threads added to the same group - * or -1 on failure - * - * @note See ACE Thread_Manager documentation - * - * @deprecated This fucntion will disappear soon. Use std::thread. - */ - template - int spawn(T & ref, - ACE_THR_FUNC_RETURN (T::*method)(), - ACE_thread_t *t_thread = 0, - ACE_hthread_t *t_handle = 0, - long flags = THR_NEW_LWP|THR_JOINABLE|THR_INHERIT_SCHED, - long priority = ACE_DEFAULT_THREAD_PRIORITY, - ACE_Base_Thread_Adapter * thread_adapter = 0, - void *stack = 0, - size_t stack_size = ACE_DEFAULT_THREAD_STACKSIZE, - const char** thr_name = 0) - { - return ACE_OS::thr_create(&start_routine, - new Func(ref,method), - flags, - t_thread, - t_handle, - priority, - stack, - stack_size, - thread_adapter, - thr_name); - } - } -} - -#endif //EMANEUTILSSPAWNMEMBERFUNC_HEADER_ diff --git a/include/emane/utils/recvcancelable.h b/include/emane/utils/threadutils.h similarity index 52% rename from include/emane/utils/recvcancelable.h rename to include/emane/utils/threadutils.h index 8aa5966b..e0d4be9c 100644 --- a/include/emane/utils/recvcancelable.h +++ b/include/emane/utils/threadutils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 - DRS CenGen, LLC, Columbia, Maryland + * Copyright (c) 2016 - Adjacent Link LLC, Bridgewater, New Jersey * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -12,7 +12,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * * Neither the name of DRS CenGen, LLC nor the names of its + * * Neither the name of Adjacent Link LLC nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -30,59 +30,43 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EMANEUTILSRECVCANCELABLE_HEADER_ -#define EMANEUTILSRECVCANCELABLE_HEADER_ +#ifndef EMANETHREADUTILS_HEADER_ +#define EMANETHREADUTILS_HEADER_ -#include +#include +#include namespace EMANE { - namespace Utils + namespace ThreadUtils { - /** - * Utility function for turning a blocking read call into a cancellation point in OSX - * - * @param ref ACE socket reference - * @param buf Output buffer - * @param n Output buffer size - * @param addr Reference to hold sender's address - * @param flags socket read flags - * - * @return number bytes read - */ - template - ssize_t recvCancelable(T & ref, void * buf, size_t n, ACE_Addr &addr, int flags = 0) + inline + int elevate(std::thread & thread) { -#ifdef __APPLE__ - - // on OSX the recv system call is not cancelable. So threads - // blocking on a recv will not be cleaned up on an ACE_OS::thr_cancel - // and will be unjoinable with an ACE_OS::thr_join. Although not - // listed as a cancellation point, select is cancelable - at least during - // testing on OSX 10.5.7 (Leopard)... + std::thread::native_handle_type handle{thread.native_handle()}; - fd_set rfds; + int iPolicy{}; - ACE_HANDLE handle = ref.get_handle(); - - FD_ZERO(&rfds); + sched_param param; - FD_SET(handle,&rfds); + int iRet{}; - if(ACE_OS::select(handle+1,&rfds)) + iRet = pthread_getschedparam(handle,&iPolicy,¶m); + + if(!iRet) { - return ref.recv(buf,n,addr,flags); + iRet = pthread_setschedprio(handle,param.sched_priority+1); } - return -1; - -#else - - return ref.recv(buf,n,addr,flags); + return iRet; + } -#endif + inline + int cancel(std::thread & thread) + { + return pthread_cancel(thread.native_handle()); } } } -#endif // EMANEUTILSRECVCANCELABLE_HEADER_ +#endif // EMANETHREADUTILS_HEADER_ diff --git a/src/agents/gpsdlocation/Makefile.am b/src/agents/gpsdlocation/Makefile.am index e9da94f7..4d5d8618 100644 --- a/src/agents/gpsdlocation/Makefile.am +++ b/src/agents/gpsdlocation/Makefile.am @@ -2,7 +2,6 @@ lib_LTLIBRARIES = libgpsdlocationagent.la libgpsdlocationagent_la_CPPFLAGS= \ -I@top_srcdir@/include \ - $(ACE_CFLAGS) \ $(AM_CFLAGS) libgpsdlocationagent_la_SOURCES= \ @@ -15,12 +14,7 @@ EXTRA_DIST= \ BUILT_SOURCES = \ gpsdlocationagent.xml -libgpsdlocationagent_la_LIBADD= \ - $(WIN32_EXTRA_LIBADD) - libgpsdlocationagent_la_LDFLAGS= \ - $(WIN32_EXTRA_LDFLAGS) \ - $(ACE_LIBS) \ -lutil \ -avoid-version diff --git a/src/agents/gpsdlocation/agent.cc b/src/agents/gpsdlocation/agent.cc index c3581bbf..49e589c1 100644 --- a/src/agents/gpsdlocation/agent.cc +++ b/src/agents/gpsdlocation/agent.cc @@ -1,5 +1,6 @@ /* - * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey + * Copyright (c) 2013-2014,2016 - Adjacent Link LLC, Bridgewater, New + * Jersey * Copyright (c) 2008-2009 - DRS CenGen, LLC, Columbia, Maryland * All rights reserved. * @@ -39,21 +40,14 @@ #include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __APPLE__ -#include -#else -#include -#endif - -EMANE::Agents::GPSDLocation::Agent::Agent(NEMId nemId, +#include +#include +#include +#include +#include +#include + +EMANE::Agents::GPSDLocation::Agent::Agent(NEMId nemId, PlatformServiceProvider *pPlatformService): EventAgent{nemId, pPlatformService}, nemId_{nemId}, @@ -74,24 +68,13 @@ void EMANE::Agents::GPSDLocation::Agent::initialize(Registrar & registrar) { auto & configRegistrar = registrar.configurationRegistrar(); - configRegistrar.registerNonNumeric("gpsdcontrolsocket", - ConfigurationProperties::DEFAULT, - {"/tmp/gpsd.control"}, - "GPSd Control Socket."); - configRegistrar.registerNonNumeric("pseudoterminalfile", ConfigurationProperties::DEFAULT, - {"/tmp/gpsdlocation.pty"}, + {"/tmp/gps.pty"}, "File to write the name of the created pseudo term."); - - configRegistrar.registerNumeric("gpsdconnectionenabled", - ConfigurationProperties::DEFAULT, - {false}, - "Enable active connection to GPSd."); - auto & eventRegistrar = registrar.eventRegistrar(); - + eventRegistrar.registerEvent(Events::LocationEvent::IDENTIFIER); } @@ -99,18 +82,10 @@ void EMANE::Agents::GPSDLocation::Agent::configure(const ConfigurationUpdate & u { for(const auto & item : update) { - if(item.first == "gpsdcontrolsocket") - { - sGPSDControlSocket_ = item.second[0].asString(); - } - else if(item.first == "pseudoterminalfile") + if(item.first == "pseudoterminalfile") { sPseudoTerminalFile_ = item.second[0].asString(); } - else if(item.first == "gpsdconnectionenabled") - { - bGPSDConnectionEnabled_ = item.second[0].asBool(); - } else { throw makeException("GPSDLocation::Agent: " @@ -123,137 +98,65 @@ void EMANE::Agents::GPSDLocation::Agent::configure(const ConfigurationUpdate & u void EMANE::Agents::GPSDLocation::Agent::start() { - char pzName[MAXPATHLEN]{}; - ACE_LSOCK_Stream gpsdControlStream; - ACE_LSOCK_Connector connect; - - if(bGPSDConnectionEnabled_) - { - gpsdControlAddr_.set(sGPSDControlSocket_.c_str()); - - if(connect.connect(gpsdControlStream,gpsdControlAddr_) == -1) - { - std::stringstream ssDescription; - ssDescription<<"unable to open GPSD control socket"<timerService().scheduleTimedEvent(Clock::now() + interval, nullptr, interval); - LOGGER_VERBOSE_LOGGING(pPlatformService_->logService(), DEBUG_LEVEL, "Timer Scheduled"); + LOGGER_VERBOSE_LOGGING(pPlatformService_->logService(), DEBUG_LEVEL, "Timer Scheduled"); } void EMANE::Agents::GPSDLocation::Agent::stop() { - if(!sClientPTTYName_.empty()) - { - if(bGPSDConnectionEnabled_) - { - ACE_LSOCK_Stream gpsdControlStream; - ACE_LSOCK_Connector connect; - - if(connect.connect(gpsdControlStream,gpsdControlAddr_) != -1) - { - std::string sTmp = sClientPTTYName_; - sTmp.append(1,'-'); - sTmp.push_back('\n'); - gpsdControlStream.send(sTmp.c_str(),sTmp.length()); - } - } + // remove the pseudo terminal filename file + LOGGER_VERBOSE_LOGGING(pPlatformService_->logService(), DEBUG_LEVEL, "unlink %s", + sPseudoTerminalFile_.c_str()); - // remove the pseudo terminal filename file - pseudoTerminalNameFile_.unlink(); - } + unlink(sPseudoTerminalFile_.c_str()); pPlatformService_->timerService().cancelTimedEvent(timerId_); } @@ -262,7 +165,7 @@ void EMANE::Agents:: GPSDLocation::Agent::destroy() throw() {} -void EMANE::Agents::GPSDLocation::Agent::processEvent(const EventId & eventId, +void EMANE::Agents::GPSDLocation::Agent::processEvent(const EventId & eventId, const Serialization & serialization) { LOGGER_STANDARD_LOGGING(pPlatformService_->logService(), @@ -273,16 +176,16 @@ void EMANE::Agents::GPSDLocation::Agent::processEvent(const EventId & eventId, if(eventId == Events::LocationEvent::IDENTIFIER) { Events::LocationEvent event{serialization}; - + const auto & locations = event.getLocations(); - + auto iter = std::find_if(locations.begin(), locations.end(), [this](const Events::Location & p) { return p.getNEMId() == nemId_; }); - + if(iter != locations.end()) { const auto & position = iter->getPosition(); @@ -300,7 +203,7 @@ void EMANE::Agents::GPSDLocation::Agent::processEvent(const EventId & eventId, bHaveInitialVelocity_ = true; } } - } + } } void EMANE::Agents::GPSDLocation::Agent::processTimedEvent(TimerEventId, @@ -312,8 +215,8 @@ void EMANE::Agents::GPSDLocation::Agent::processTimedEvent(TimerEventId, if(bHaveInitialPosition_) { sendSpoofedNMEA(dLatitudeDegrees_,dLongitudeDegrees_,dAltitudeMeters_); - - LOGGER_STANDARD_LOGGING(pPlatformService_->logService(), + + LOGGER_STANDARD_LOGGING(pPlatformService_->logService(), DEBUG_LEVEL, "gpsdlocationaganet NEM: %hu lat: %lf lon: %lf alt:%lf", nemId_, @@ -350,23 +253,23 @@ void EMANE::Agents::GPSDLocation::Agent::sendSpoofedNMEA(double dLatitude, doub char cLatitudeHemisphere = (dLatitude > 0) ? 'N' : 'S'; char cLongitudeHemisphere = (dLongitude > 0) ? 'E' : 'W'; - + if(dLatitude < 0) { dLatitude *= -1; } - + if(dLongitude < 0) { dLongitude *= -1; } - + int iLongitudeDegrees = static_cast(dLongitude); int iLatitudeDegrees = static_cast(dLatitude); - + double dLongitudeMinutes = (dLongitude - iLongitudeDegrees) * 60.0; double dLatitudeMinutes = (dLatitude - iLatitudeDegrees) * 60.0; - + int iLongitudeMinutes = static_cast(dLongitudeMinutes); int iLatitudeMinutes = static_cast(dLatitudeMinutes); @@ -378,15 +281,15 @@ void EMANE::Agents::GPSDLocation::Agent::sendSpoofedNMEA(double dLatitude, doub double dVerticalDOP = 1.3; double dGeoidalHeight = -34.0; - + dLongitudeMinutes -= iLongitudeMinutes; dLatitudeMinutes -= iLatitudeMinutes; - + dLongitudeMinutes *= 10000; dLatitudeMinutes *= 10000; - - ACE_OS::time(&t); - ACE_OS::gmtime_r(&t,&tmval); + + time(&t); + gmtime_r(&t,&tmval); /* NMEA GGA */ snprintf(buf,sizeof(buf),"$GPGGA,%02d%02d%02d,%02d%02d.%04d,%c,%03d%02d.%04d,%c,%d,%02d,%.1f,%.1f,M,%.1f,M,,", @@ -407,7 +310,7 @@ void EMANE::Agents::GPSDLocation::Agent::sendSpoofedNMEA(double dLatitude, doub dAltitude, dGeoidalHeight ); - + doCheckSumNMEA(buf,sizeof(buf)); write(masterPTY_,buf,strlen(buf)); @@ -430,7 +333,7 @@ void EMANE::Agents::GPSDLocation::Agent::sendSpoofedNMEA(double dLatitude, doub (tmval.tm_year + 1900) % 100, cLongitudeHemisphere ); - + doCheckSumNMEA(buf,sizeof(buf)); write(masterPTY_,buf,strlen(buf)); @@ -441,10 +344,10 @@ void EMANE::Agents::GPSDLocation::Agent::sendSpoofedNMEA(double dLatitude, doub doCheckSumNMEA(buf,sizeof(buf)); write(masterPTY_,buf,strlen(buf)); - - - for(int i = 0; i < NUM_GSV_STRINGS; ++i) - { + + + for(int i = 0; i < NUM_GSV_STRINGS; ++i) + { const int a = (NUM_SV_PER_STRING * i) + 0; const int b = (NUM_SV_PER_STRING * i) + 1; const int c = (NUM_SV_PER_STRING * i) + 2; @@ -459,7 +362,7 @@ void EMANE::Agents::GPSDLocation::Agent::sendSpoofedNMEA(double dLatitude, doub b + 2, elv[b], azm[b], snr[b], c + 3, elv[c], azm[c], snr[c], d + 4, elv[d], azm[d], snr[d]); - + doCheckSumNMEA(buf,sizeof(buf)); write(masterPTY_,buf,strlen(buf)); } @@ -493,14 +396,14 @@ void EMANE::Agents::GPSDLocation::Agent::doCheckSumNMEA(char *buf, size_t len) char foo[6] = {0}; char chksum = buf[1]; - + for(unsigned int i = 2; i < strlen(buf); ++i) { chksum ^= buf[i]; } - + snprintf(foo, sizeof(foo), "*%02X\r\n", static_cast(chksum)); - + strncat(buf, foo, len - strlen(buf) - 1); } diff --git a/src/agents/gpsdlocation/agent.h b/src/agents/gpsdlocation/agent.h index d36d587c..7b7b4fb9 100644 --- a/src/agents/gpsdlocation/agent.h +++ b/src/agents/gpsdlocation/agent.h @@ -1,5 +1,6 @@ /* - * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey + * Copyright (c) 2013-2014,2016 - Adjacent Link LLC, Bridgewater, New + * Jersey * Copyright (c) 2008 - DRS CenGen, LLC, Columbia, Maryland * All rights reserved. * @@ -39,9 +40,6 @@ #include -#include -#include - namespace EMANE { namespace Agents @@ -58,39 +56,35 @@ namespace EMANE public: Agent(NEMId nemId, PlatformServiceProvider *pPlatformService); - + ~Agent(); - + void initialize(Registrar & registrar) override; - + void configure(const ConfigurationUpdate & update) override; - + void start() override; - + void stop() override; - + void destroy() throw() override; void processEvent(const EventId&, const Serialization &) override; - + void processTimedEvent(TimerEventId eventId, const TimePoint & expireTime, const TimePoint & scheduleTime, const TimePoint & fireTime, const void * arg) override; - + private: NEMId nemId_; - ACE_UNIX_Addr gpsdControlAddr_; - ACE_SOCK_Stream gpsdClientStream_; int masterPTY_; int slavePTY_; std::string sClientPTTYName_; std::string sPseudoTerminalFile_; - std::string sGPSDControlSocket_; - bool bGPSDConnectionEnabled_; - ACE_FILE_IO pseudoTerminalNameFile_; + std::string sPseudoTerminalNameFile_; bool bHaveInitialPosition_; bool bHaveInitialVelocity_; double dLatitudeDegrees_; @@ -99,7 +93,7 @@ namespace EMANE double dAzimuthDegrees_; double dMagnitudeMetersPerSecond_; TimerEventId timerId_; - + /** * Convert position in to NMEA strings and send to gpsd via pseudo terminal * @@ -118,7 +112,7 @@ namespace EMANE * */ void sendSpoofedGPVTG(double dAzimuth, double dMagnitude); - + void doCheckSumNMEA(char *buf, size_t len); }; } diff --git a/src/applications/emaneeventd/eventagentdirector.cc b/src/applications/emaneeventd/eventagentdirector.cc index d129507d..457a628a 100644 --- a/src/applications/emaneeventd/eventagentdirector.cc +++ b/src/applications/emaneeventd/eventagentdirector.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey + * Copyright (c) 2013-2015 - Adjacent Link LLC, Bridgewater, New Jersey * Copyright (c) 2009 - DRS CenGen, LLC, Columbia, Maryland * All rights reserved. * @@ -34,19 +34,19 @@ #include "eventagentdirector.h" #include -#include + /* * Constructor * * @param filename reference to the base XML filename * @param builder reference to the EventAgentBuilder */ -EMANE::Application::EventAgentDirector::EventAgentDirector(const std::string & filename, +EMANE::Application::EventAgentDirector::EventAgentDirector(const std::string & filename, EventAgentBuilder & builder): eventDaemonConfig_(filename), builder_(builder) {} - + /* * Destructor */ @@ -66,17 +66,16 @@ EMANE::Application::EventAgentDirector::construct(const uuid_t & uuid) /* Now go through each event generator configuration and build appropriately */ EventAgents agents; - + for(const auto & pLayerConfig : eventDaemonConfig_.getAgents()) { agents.push_back(builder_.buildEventAgent(nemId, pLayerConfig->getLibrary(), pLayerConfig->getConfigurationUpdateRequest())); } - + /* Build Event Agent Manager */ return builder_.buildEventAgentManager(uuid, agents, eventDaemonConfig_.getConfigurationUpdateRequest()); } - diff --git a/src/applications/emaneinfo/emaneinfo.cc b/src/applications/emaneinfo/emaneinfo.cc index fe134070..ccd1c331 100644 --- a/src/applications/emaneinfo/emaneinfo.cc +++ b/src/applications/emaneinfo/emaneinfo.cc @@ -1,5 +1,6 @@ /* - * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey + * Copyright (c) 2013-2014,2016 - Adjacent Link LLC, Bridgewater, New + * Jersey * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -51,15 +52,7 @@ #include #include #include - -#include -#include -#include -#include - -#include -#include -#include +#include void usage(); @@ -75,46 +68,35 @@ T * createManager() return pManager; } -int ACE_TMAIN(int argc, ACE_TCHAR * argv[]) +int main(int argc, char * argv[]) { EMANE::Application::initialize(); try { - const ACE_TCHAR options[] = ACE_TEXT(":vhcm"); - - ACE_Get_Opt cmd_opts(argc,argv,options); - - if(cmd_opts.long_option(ACE_TEXT("help"),'h') == -1) + std::vector