summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hicn-light/src/hicn/config/configurationListeners.c119
-rw-r--r--hicn-light/src/hicn/config/controlAddListener.c46
-rw-r--r--hicn-light/src/hicn/io/udpListener.c19
-rw-r--r--hicn-light/src/hicn/io/udpListener.h7
-rw-r--r--hicn-light/src/hicn/utils/commands.h4
-rw-r--r--lib/src/compat.c2
-rw-r--r--lib/src/compat.h2
-rw-r--r--libtransport/src/hicn/transport/core/content_object.cc11
-rw-r--r--libtransport/src/hicn/transport/core/interest.cc8
-rw-r--r--libtransport/src/hicn/transport/core/name.cc69
-rw-r--r--libtransport/src/hicn/transport/core/name.h20
-rw-r--r--libtransport/src/hicn/transport/core/packet.cc5
-rw-r--r--libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc9
-rw-r--r--libtransport/src/hicn/transport/http/server_publisher.cc2
-rw-r--r--libtransport/src/hicn/transport/interfaces/socket_producer.cc27
-rw-r--r--libtransport/src/hicn/transport/interfaces/socket_producer.h6
-rw-r--r--libtransport/src/hicn/transport/utils/content_store.cc6
-rw-r--r--libtransport/src/hicn/transport/utils/content_store.h2
-rw-r--r--utils/src/hiperf.cc18
19 files changed, 279 insertions, 103 deletions
diff --git a/hicn-light/src/hicn/config/configurationListeners.c b/hicn-light/src/hicn/config/configurationListeners.c
index a16c434f5..97e7dbb87 100644
--- a/hicn-light/src/hicn/config/configurationListeners.c
+++ b/hicn-light/src/hicn/config/configurationListeners.c
@@ -211,6 +211,20 @@ static bool _addEther(Configuration *config, add_listener_command *control,
return false;
}
+#ifdef __linux__
+/*
+ * Create a new IPV4/TCP listener.
+ *
+ * @param [in,out] forwarder The hicn-light forwarder instance
+ * @param [in] addr4 The ipv4 address in network byte order
+ * @param [in] port The port number in network byte order
+ * @param [in] interfaceName The name of the interface to bind the socket
+ *
+ * return true if success, false otherwise
+ */
+static bool _setupTcpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
+ uint16_t *port, const char *interfaceName) {
+#else
/*
* Create a new IPV4/TCP listener.
*
@@ -222,6 +236,7 @@ static bool _addEther(Configuration *config, add_listener_command *control,
*/
static bool _setupTcpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
uint16_t *port) {
+#endif
bool success = false;
struct sockaddr_in addr;
@@ -239,6 +254,21 @@ static bool _setupTcpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
return success;
}
+
+#ifdef __linux__
+/*
+ * Create a new IPV4/UDP listener.
+ *
+ * @param [in,out] forwarder The hicn-light forwarder instance
+ * @param [in] addr4 The ipv4 address in network byte order
+ * @param [in] port The port number in network byte order
+ * @param [in] interfaceName The name of the interface to bind the socket
+ *
+ * return true if success, false otherwise
+ */
+static bool _setupUdpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
+ uint16_t *port, char *interfaceName) {
+#else
/*
* Create a new IPV4/UDP listener.
*
@@ -250,6 +280,7 @@ static bool _setupTcpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
*/
static bool _setupUdpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
uint16_t *port) {
+#endif
bool success = false;
struct sockaddr_in addr;
@@ -258,7 +289,11 @@ static bool _setupUdpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
addr.sin_port = *port;
addr.sin_addr.s_addr = *addr4;
+#ifdef __linux__
+ ListenerOps *ops = udpListener_CreateInet(forwarder, addr, interfaceName);
+#else
ListenerOps *ops = udpListener_CreateInet(forwarder, addr);
+#endif
if (ops) {
success = listenerSet_Add(forwarder_GetListenerSet(forwarder), ops);
parcAssertTrue(success, "Failed to add UDP listener on %s to ListenerSet",
@@ -267,6 +302,22 @@ static bool _setupUdpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
return success;
}
+
+#ifdef __linux__
+/*
+ * Create a new IPV6/TCP listener.
+ *
+ * @param [in,out] forwarder The hicn-light forwarder instance
+ * @param [in] addr6 The ipv6 address in network byte order
+ * @param [in] port The port number in network byte order
+ * @param [in] interfaceName The name of the interface to bind the socket
+ *
+ * return true if success, false otherwise
+ */
+static bool _setupTcpListenerOnInet6Light(Forwarder *forwarder,
+ ipv6_addr_t *addr6, uint16_t *port, char *interfaceName,
+ uint32_t scopeId) {
+#else
/*
* Create a new IPV6/TCP listener.
*
@@ -279,6 +330,7 @@ static bool _setupUdpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
static bool _setupTcpListenerOnInet6Light(Forwarder *forwarder,
ipv6_addr_t *addr6, uint16_t *port,
uint32_t scopeId) {
+#endif
bool success = false;
struct sockaddr_in6 addr;
@@ -297,6 +349,21 @@ static bool _setupTcpListenerOnInet6Light(Forwarder *forwarder,
return success;
}
+
+#ifdef __linux__
+/*
+ * Create a new IPV6/UDP listener.
+ *
+ * @param [in,out] forwarder The hicn-light forwarder instance
+ * @param [in] addr6 The ipv6 address in network byte order
+ * @param [in] port The port number in network byte order
+ * @param [in] interfaceName The name of the interface to bind the socket
+ *
+ * return true if success, false otherwise
+ */
+static bool _setupUdpListenerOnInet6Light(Forwarder *forwarder,
+ ipv6_addr_t *addr6, uint16_t *port, char *interfaceName) {
+#else
/*
* Create a new IPV6/UDP listener.
*
@@ -308,6 +375,7 @@ static bool _setupTcpListenerOnInet6Light(Forwarder *forwarder,
*/
static bool _setupUdpListenerOnInet6Light(Forwarder *forwarder,
ipv6_addr_t *addr6, uint16_t *port) {
+#endif
bool success = false;
struct sockaddr_in6 addr;
@@ -317,7 +385,11 @@ static bool _setupUdpListenerOnInet6Light(Forwarder *forwarder,
addr.sin6_addr = *addr6;
addr.sin6_scope_id = 0;
+#ifdef __linux__
+ ListenerOps *ops = udpListener_CreateInet6(forwarder, addr, interfaceName);
+#else
ListenerOps *ops = udpListener_CreateInet6(forwarder, addr);
+#endif
if (ops) {
success = listenerSet_Add(forwarder_GetListenerSet(forwarder), ops);
parcAssertTrue(success, "Failed to add UDP6 listener on %s to ListenerSet",
@@ -391,6 +463,18 @@ bool _addIP(Configuration *config, add_listener_command *control,
switch (control->addressType) {
case ADDR_INET: {
+
+#ifdef __linux__
+ if (control->connectionType == UDP_CONN) {
+ success =
+ _setupUdpListenerOnInet(configuration_GetForwarder(config),
+ &control->address.ipv4, &control->port, control->interfaceName);
+ } else if (control->connectionType == TCP_CONN) {
+ success =
+ _setupTcpListenerOnInet(configuration_GetForwarder(config),
+ &control->address.ipv4, &control->port, control->interfaceName);
+ }
+#else
if (control->connectionType == UDP_CONN) {
success =
_setupUdpListenerOnInet(configuration_GetForwarder(config),
@@ -400,10 +484,22 @@ bool _addIP(Configuration *config, add_listener_command *control,
_setupTcpListenerOnInet(configuration_GetForwarder(config),
&control->address.ipv4, &control->port);
}
+#endif
break;
}
case ADDR_INET6: {
+#ifdef __linux__
+ if (control->connectionType == UDP_CONN) {
+ success = _setupUdpListenerOnInet6Light(
+ configuration_GetForwarder(config), &control->address.ipv6,
+ &control->port, control->interfaceName);
+ } else if (control->connectionType == TCP_CONN) {
+ success = _setupTcpListenerOnInet6Light(
+ configuration_GetForwarder(config), &control->address.ipv6,
+ &control->port, control->interfaceName, 0);
+ }
+#else
if (control->connectionType == UDP_CONN) {
success = _setupUdpListenerOnInet6Light(
configuration_GetForwarder(config), &control->address.ipv6,
@@ -413,6 +509,7 @@ bool _addIP(Configuration *config, add_listener_command *control,
configuration_GetForwarder(config), &control->address.ipv6,
&control->port, 0);
}
+#endif
break;
}
@@ -524,21 +621,30 @@ struct iovec *configurationListeners_AddPunting(Configuration *config,
static void _setupListenersOnAddress(Forwarder *forwarder,
const Address *address, uint16_t port,
- const char *interfaceName) {
+ char *interfaceName) {
address_type type = addressGetType(address);
switch (type) {
case ADDR_INET: {
struct sockaddr_in tmp;
addressGetInet(address, &tmp);
+#ifdef __linux__
+ _setupTcpListenerOnInet(forwarder, &tmp.sin_addr.s_addr, &port, interfaceName);
+#else
_setupTcpListenerOnInet(forwarder, &tmp.sin_addr.s_addr, &port);
+#endif
break;
}
case ADDR_INET6: {
struct sockaddr_in6 tmp;
addressGetInet6(address, &tmp);
+#ifdef __linux__
+ _setupTcpListenerOnInet6Light(forwarder, &tmp.sin6_addr, &port, interfaceName,
+ tmp.sin6_scope_id);
+#else
_setupTcpListenerOnInet6Light(forwarder, &tmp.sin6_addr, &port,
tmp.sin6_scope_id);
+#endif
break;
}
@@ -570,7 +676,7 @@ void configurationListeners_SetupAll(const Configuration *config, uint16_t port,
// Do not start on link address
if (addressGetType(address) != ADDR_LINK) {
_setupListenersOnAddress(forwarder, address, port,
- interfaceGetName(iface));
+ (char *)interfaceGetName(iface));
}
}
}
@@ -583,9 +689,16 @@ void configurationListeners_SetutpLocalIPv4(const Configuration *config,
Forwarder *forwarder = configuration_GetForwarder(config);
in_addr_t addr = inet_addr("127.0.0.1");
uint16_t network_byte_order_port = htons(port);
-
+#ifdef __linux__
+ char *loopback_interface = "lo";
+ _setupUdpListenerOnInet(forwarder, (ipv4_addr_t *)&(addr),
+ &network_byte_order_port, loopback_interface);
+ _setupTcpListenerOnInet(forwarder, (ipv4_addr_t *)&(addr),
+ &network_byte_order_port, loopback_interface);
+#else
_setupUdpListenerOnInet(forwarder, (ipv4_addr_t *)&(addr),
&network_byte_order_port);
_setupTcpListenerOnInet(forwarder, (ipv4_addr_t *)&(addr),
&network_byte_order_port);
+#endif
}
diff --git a/hicn-light/src/hicn/config/controlAddListener.c b/hicn-light/src/hicn/config/controlAddListener.c
index 7fdf46228..d84b8049b 100644
--- a/hicn-light/src/hicn/config/controlAddListener.c
+++ b/hicn-light/src/hicn/config/controlAddListener.c
@@ -58,14 +58,22 @@ static const int _indexProtocol = 2;
static const int _indexSymbolic = 3;
static const int _indexAddress = 4;
static const int _indexPort = 5;
+#ifdef __linux__
+static const int _indexInterfaceName = 6;
+#endif
static CommandReturn _controlAddListener_HelpExecute(CommandParser *parser,
CommandOps *ops,
PARCList *args) {
printf("commands:\n");
printf(" add listener hicn <symbolic> <localAddress> \n");
- printf(" add listener udp <symbolic> <localAddress> <port> \n");
- printf(" add listener tcp <symbolic> <localAddress> <port> \n");
+#ifdef __linux__
+ printf(" add listener udp <symbolic> <localAddress> <port> <interface>\n");
+ printf(" add listener tcp <symbolic> <localAddress> <port> <interface>\n");
+#else
+ printf(" add listener udp <symbolic> <localAddress> <port>\n");
+ printf(" add listener tcp <symbolic> <localAddress> <port>\n");
+#endif
printf("\n");
printf(
" symbolic: User defined name for listener, must start with "
@@ -75,6 +83,8 @@ static CommandReturn _controlAddListener_HelpExecute(CommandParser *parser,
" localAddress: IPv4 or IPv6 address (or prefix protocol = hicn) "
"assigend to the local interface\n");
printf(" port: Udp port\n");
+
+ printf(" interface: interface\n");
printf("\n");
printf("Notes:\n");
printf(" The symblic name must be unique or the source will reject it.\n");
@@ -84,10 +94,17 @@ static CommandReturn _controlAddListener_HelpExecute(CommandParser *parser,
return CommandReturn_Success;
}
+#ifdef __linux__
+static CommandReturn _CreateListener(CommandParser *parser, CommandOps *ops,
+ const char *symbolic, const char *addr,
+ const char *port, const char *interfaceName, listener_mode mode,
+ connection_type type) {
+#else
static CommandReturn _CreateListener(CommandParser *parser, CommandOps *ops,
const char *symbolic, const char *addr,
const char *port, listener_mode mode,
connection_type type) {
+#endif
ControlState *state = ops->closure;
// allocate command payload
@@ -109,6 +126,9 @@ static CommandReturn _CreateListener(CommandParser *parser, CommandOps *ops,
}
// Fill remaining payload fields
+#ifdef __linux__
+ memcpy(addListenerCommand->interfaceName, interfaceName, 16);
+#endif
addListenerCommand->listenerMode = mode;
addListenerCommand->connectionType = type;
addListenerCommand->port = htons((uint16_t)atoi(port));
@@ -129,7 +149,11 @@ static CommandReturn _CreateListener(CommandParser *parser, CommandOps *ops,
static CommandReturn _controlAddListener_Execute(CommandParser *parser,
CommandOps *ops,
PARCList *args) {
+#ifdef __linux__
+ if (parcList_Size(args) != 5 && parcList_Size(args) != 7) {
+#else
if (parcList_Size(args) != 5 && parcList_Size(args) != 6) {
+#endif
_controlAddListener_HelpExecute(parser, ops, args);
return CommandReturn_Failure;
}
@@ -146,6 +170,9 @@ static CommandReturn _controlAddListener_Execute(CommandParser *parser,
}
const char *host = parcList_GetAtIndex(args, _indexAddress);
+#ifdef __linux__
+ const char *interfaceName = parcList_GetAtIndex(args, _indexInterfaceName);
+#endif
const char *protocol = parcList_GetAtIndex(args, _indexProtocol);
if ((strcasecmp("hicn", protocol) == 0)) {
@@ -154,18 +181,33 @@ static CommandReturn _controlAddListener_Execute(CommandParser *parser,
// here we discard the prefix len if it exists, since we don't use it in
// code but we let libhicn to find the right ip address.
+#ifdef __linux__
+ return _CreateListener(parser, ops, symbolic, host, port, interfaceName, HICN_MODE,
+ HICN_CONN);
+#else
return _CreateListener(parser, ops, symbolic, host, port, HICN_MODE,
HICN_CONN);
+#endif
}
const char *port = parcList_GetAtIndex(args, _indexPort);
if ((strcasecmp("udp", protocol) == 0)) {
+#ifdef __linux__
+ return _CreateListener(parser, ops, symbolic, host, port, interfaceName, IP_MODE,
+ UDP_CONN);
+#else
return _CreateListener(parser, ops, symbolic, host, port, IP_MODE,
UDP_CONN);
+#endif
} else if ((strcasecmp("tcp", protocol) == 0)) {
+#ifdef __linux__
+ return _CreateListener(parser, ops, symbolic, host, port, interfaceName, IP_MODE,
+ TCP_CONN);
+#else
return _CreateListener(parser, ops, symbolic, host, port, IP_MODE,
TCP_CONN);
+#endif
} else {
_controlAddListener_HelpExecute(parser, ops, args);
return CommandReturn_Failure;
diff --git a/hicn-light/src/hicn/io/udpListener.c b/hicn-light/src/hicn/io/udpListener.c
index 3d3455f41..3dd4b466c 100644
--- a/hicn-light/src/hicn/io/udpListener.c
+++ b/hicn-light/src/hicn/io/udpListener.c
@@ -70,8 +70,13 @@ static ListenerOps udpTemplate = {.context = NULL,
static void _readcb(int fd, PARCEventType what, void *udpVoid);
+#ifdef __linux__
+ListenerOps *udpListener_CreateInet6(Forwarder *forwarder,
+ struct sockaddr_in6 sin6, const char *interfaceName) {
+#else
ListenerOps *udpListener_CreateInet6(Forwarder *forwarder,
struct sockaddr_in6 sin6) {
+#endif
ListenerOps *ops = NULL;
UdpListener *udp = parcMemory_AllocateAndClear(sizeof(UdpListener));
@@ -112,7 +117,12 @@ ListenerOps *udpListener_CreateInet6(Forwarder *forwarder,
parcAssertFalse(failure, "failed to set REUSEADDR on socket(%d)", errno);
failure = bind(udp->udp_socket, (struct sockaddr *)&sin6, sizeof(sin6));
+
if (failure == 0) {
+#ifdef __linux__
+ setsockopt(udp->udp_socket, SOL_SOCKET, SO_BINDTODEVICE,
+ interfaceName, strlen(interfaceName) + 1);
+#endif
udp->udp_event =
dispatcher_CreateNetworkEvent(forwarder_GetDispatcher(forwarder), true,
_readcb, (void *)udp, udp->udp_socket);
@@ -153,8 +163,13 @@ ListenerOps *udpListener_CreateInet6(Forwarder *forwarder,
return ops;
}
+#ifdef __linux__
+ListenerOps *udpListener_CreateInet(Forwarder *forwarder,
+ struct sockaddr_in sin, const char *interfaceName) {
+#else
ListenerOps *udpListener_CreateInet(Forwarder *forwarder,
struct sockaddr_in sin) {
+#endif
ListenerOps *ops = NULL;
UdpListener *udp = parcMemory_AllocateAndClear(sizeof(UdpListener));
@@ -195,6 +210,10 @@ ListenerOps *udpListener_CreateInet(Forwarder *forwarder,
failure = bind(udp->udp_socket, (struct sockaddr *)&sin, sizeof(sin));
if (failure == 0) {
+#ifdef __linux__
+ setsockopt(udp->udp_socket, SOL_SOCKET, SO_BINDTODEVICE,
+ interfaceName, strlen(interfaceName) + 1);
+#endif
udp->udp_event =
dispatcher_CreateNetworkEvent(forwarder_GetDispatcher(forwarder), true,
_readcb, (void *)udp, udp->udp_socket);
diff --git a/hicn-light/src/hicn/io/udpListener.h b/hicn-light/src/hicn/io/udpListener.h
index 1ad3f77fe..81d191eab 100644
--- a/hicn-light/src/hicn/io/udpListener.h
+++ b/hicn-light/src/hicn/io/udpListener.h
@@ -27,9 +27,16 @@
struct udp_listener;
typedef struct udp_listener UdpListener;
+#ifdef __linux__
+ListenerOps *udpListener_CreateInet6(Forwarder *forwarder,
+ struct sockaddr_in6 sin6, const char *if_bind);
+ListenerOps *udpListener_CreateInet(Forwarder *forwarder,
+ struct sockaddr_in sin, const char *if_bind);
+#else
ListenerOps *udpListener_CreateInet6(Forwarder *forwarder,
struct sockaddr_in6 sin6);
ListenerOps *udpListener_CreateInet(Forwarder *forwarder,
struct sockaddr_in sin);
+#endif
// void udpListener_SetPacketType(ListenerOps *ops, MessagePacketType type);
#endif // udpListener_h
diff --git a/hicn-light/src/hicn/utils/commands.h b/hicn-light/src/hicn/utils/commands.h
index 236a75a33..96415d8da 100644
--- a/hicn-light/src/hicn/utils/commands.h
+++ b/hicn-light/src/hicn/utils/commands.h
@@ -105,7 +105,9 @@ typedef enum { ETHER_MODE, IP_MODE, HICN_MODE } listener_mode;
typedef struct {
char symbolic[16];
- // char interfaceName[16];
+#ifdef __linux__
+ char interfaceName[16];
+#endif
union commandAddr address;
uint16_t port;
// uint16_t etherType;
diff --git a/lib/src/compat.c b/lib/src/compat.c
index 63431a384..633037a0f 100644
--- a/lib/src/compat.c
+++ b/lib/src/compat.c
@@ -1033,7 +1033,7 @@ hicn_data_get_name (hicn_format_t format, const hicn_header_t * data,
int
hicn_data_set_name (hicn_format_t format, hicn_header_t * data,
- hicn_name_t * name)
+ const hicn_name_t * name)
{
int ret_err = hicn_packet_set_ece (data); //data packet -> ece flag set
if (ret_err < 0)
diff --git a/lib/src/compat.h b/lib/src/compat.h
index e174414a4..7228843bb 100644
--- a/lib/src/compat.h
+++ b/lib/src/compat.h
@@ -423,7 +423,7 @@ int hicn_interest_reset_for_hash (hicn_format_t format,
int hicn_data_get_name (hicn_format_t format, const hicn_header_t * data,
hicn_name_t * name);
int hicn_data_set_name (hicn_format_t format, hicn_header_t * data,
- hicn_name_t * name);
+ const hicn_name_t * name);
int hicn_data_get_locator (hicn_format_t format, const hicn_header_t * data,
ip_address_t * ip_address);
int hicn_data_set_locator (hicn_format_t format, hicn_header_t * data,
diff --git a/libtransport/src/hicn/transport/core/content_object.cc b/libtransport/src/hicn/transport/core/content_object.cc
index 764d753cd..83b545c05 100644
--- a/libtransport/src/hicn/transport/core/content_object.cc
+++ b/libtransport/src/hicn/transport/core/content_object.cc
@@ -33,10 +33,8 @@ namespace core {
ContentObject::ContentObject(const Name &name, Packet::Format format)
: Packet(format) {
-
if (TRANSPORT_EXPECT_FALSE(
- hicn_data_set_name(format, packet_start_, name.getStructReference()) <
- 0)) {
+ hicn_data_set_name(format, packet_start_, &name.name_) < 0)) {
throw errors::RuntimeException("Error filling the packet name.");
}
@@ -99,7 +97,8 @@ void ContentObject::replace(MemBufPtr &&buffer) {
const Name &ContentObject::getName() const {
if (!name_) {
if (hicn_data_get_name(format_, packet_start_,
- (hicn_name_t *)name_.getStructReference()) < 0) {
+ (hicn_name_t *)name_.getConstStructReference()) <
+ 0) {
throw errors::MalformedPacketException();
}
}
@@ -110,8 +109,8 @@ const Name &ContentObject::getName() const {
Name &ContentObject::getWritableName() { return const_cast<Name &>(getName()); }
void ContentObject::setName(const Name &name) {
- if (hicn_data_set_name(format_, packet_start_, name.getStructReference()) <
- 0) {
+ if (hicn_data_set_name(format_, packet_start_,
+ name.getConstStructReference()) < 0) {
throw errors::RuntimeException("Error setting content object name.");
}
diff --git a/libtransport/src/hicn/transport/core/interest.cc b/libtransport/src/hicn/transport/core/interest.cc
index e7d47d565..60ab10967 100644
--- a/libtransport/src/hicn/transport/core/interest.cc
+++ b/libtransport/src/hicn/transport/core/interest.cc
@@ -34,7 +34,7 @@ namespace core {
Interest::Interest(const Name &interest_name, Packet::Format format)
: Packet(format) {
if (hicn_interest_set_name(format_, packet_start_,
- interest_name.getStructReference()) < 0) {
+ interest_name.getConstStructReference()) < 0) {
throw errors::MalformedPacketException();
}
@@ -44,7 +44,6 @@ Interest::Interest(const Name &interest_name, Packet::Format format)
}
}
-
#ifdef __ANDROID__
Interest::Interest(hicn_format_t format) : Interest(Name("0::0|0"), format) {}
#else
@@ -85,7 +84,8 @@ void Interest::replace(MemBufPtr &&buffer) {
const Name &Interest::getName() const {
if (!name_) {
if (hicn_interest_get_name(format_, packet_start_,
- (hicn_name_t *)name_.getStructReference()) < 0) {
+ (hicn_name_t *)name_.getConstStructReference()) <
+ 0) {
throw errors::MalformedPacketException();
}
}
@@ -97,7 +97,7 @@ Name &Interest::getWritableName() { return const_cast<Name &>(getName()); }
void Interest::setName(const Name &name) {
if (hicn_interest_set_name(format_, packet_start_,
- name.getStructReference()) < 0) {
+ name.getConstStructReference()) < 0) {
throw errors::RuntimeException("Error setting interest name.");
}
diff --git a/libtransport/src/hicn/transport/core/name.cc b/libtransport/src/hicn/transport/core/name.cc
index 867d3a755..0621eeeb5 100644
--- a/libtransport/src/hicn/transport/core/name.cc
+++ b/libtransport/src/hicn/transport/core/name.cc
@@ -24,21 +24,22 @@ namespace transport {
namespace core {
-Name::Name() { name_ = createEmptyName(); }
+Name::Name() { name_ = {}; }
Name::Name(int family, const uint8_t *ip_address, std::uint32_t suffix)
- : name_(createEmptyName()) {
+ : name_({}) {
+ name_.type = HNT_UNSPEC;
std::size_t length;
uint8_t *dst = NULL;
if (family == AF_INET) {
- dst = name_->ip4.prefix_as_u8;
+ dst = name_.ip4.prefix_as_u8;
length = IPV4_ADDR_LEN;
- name_->type = HNT_CONTIGUOUS_V4;
+ name_.type = HNT_CONTIGUOUS_V4;
} else if (family == AF_INET6) {
- dst = name_->ip6.prefix_as_u8;
+ dst = name_.ip6.prefix_as_u8;
length = IPV6_ADDR_LEN;
- name_->type = HNT_CONTIGUOUS_V6;
+ name_.type = HNT_CONTIGUOUS_V6;
} else {
throw errors::RuntimeException("Specified name family does not exist.");
}
@@ -48,9 +49,8 @@ Name::Name(int family, const uint8_t *ip_address, std::uint32_t suffix)
}
Name::Name(const char *name, uint32_t segment) {
- name_ = createEmptyName();
-
- if (hicn_name_create(name, segment, name_.get()) < 0) {
+ name_.type = HNT_UNSPEC;
+ if (hicn_name_create(name, segment, &name_) < 0) {
throw errors::InvalidIpAddressException();
}
}
@@ -59,6 +59,7 @@ Name::Name(const std::string &uri, uint32_t segment)
: Name(uri.c_str(), segment) {}
Name::Name(const std::string &uri) {
+ name_.type = HNT_UNSPEC;
utils::StringTokenizer tokenizer(uri, "|");
std::string ip_address;
std::string seq_number;
@@ -71,30 +72,16 @@ Name::Name(const std::string &uri) {
seq_number = "0";
}
- name_ = createEmptyName();
-
if (hicn_name_create(ip_address.c_str(), (uint32_t)atoi(seq_number.c_str()),
- name_.get()) < 0) {
+ &name_) < 0) {
throw errors::InvalidIpAddressException();
}
}
-Name::Name(const Name &name, bool hard_copy) {
- name_ = createEmptyName();
-
- if (hard_copy) {
- if (hicn_name_copy(this->name_.get(), name.name_.get()) < 0) {
- throw errors::MalformedNameException();
- }
- } else {
- *this->name_ = *name.name_;
- }
-}
-
-Name::Name(Name &&name) : name_(std::move(name.name_)) {}
+Name::Name(const Name &name) { this->name_ = name.name_; }
Name &Name::operator=(const Name &name) {
- if (hicn_name_copy(this->name_.get(), name.name_.get()) < 0) {
+ if (hicn_name_copy(&this->name_, &name.name_) < 0) {
throw errors::MalformedNameException();
}
@@ -110,16 +97,16 @@ bool Name::operator!=(const Name &name) const {
}
Name::operator bool() const {
- return bool(hicn_name_empty((hicn_name_t *)name_.get()));
+ return bool(hicn_name_empty((hicn_name_t *)&name_));
}
bool Name::equals(const Name &name, bool consider_segment) const {
- return !hicn_name_compare(name_.get(), name.name_.get(), consider_segment);
+ return !hicn_name_compare(&name_, &name.name_, consider_segment);
}
std::string Name::toString() const {
char *name = new char[100];
- int ret = hicn_name_ntop(name_.get(), name, standard_name_string_length);
+ int ret = hicn_name_ntop(&name_, name, standard_name_string_length);
if (ret < 0) {
throw errors::MalformedNameException();
}
@@ -131,22 +118,19 @@ std::string Name::toString() const {
uint32_t Name::getHash32() const {
uint32_t hash;
- if (hicn_name_hash((hicn_name_t *)name_.get(), &hash) < 0) {
+ if (hicn_name_hash((hicn_name_t *)&name_, &hash) < 0) {
throw errors::RuntimeException("Error computing the hash of the name!");
}
return hash;
}
-void Name::clear() {
- name_.reset();
- name_ = createEmptyName();
-};
+void Name::clear() { name_.type = HNT_UNSPEC; };
-Name::Type Name::getType() const { return name_->type; }
+Name::Type Name::getType() const { return name_.type; }
uint32_t Name::getSuffix() const {
uint32_t ret = 0;
- if (hicn_name_get_seq_number((hicn_name_t *)name_.get(), &ret) < 0) {
+ if (hicn_name_get_seq_number((hicn_name_t *)&name_, &ret) < 0) {
throw errors::RuntimeException(
"Impossible to retrieve the sequence number from the name.");
}
@@ -154,7 +138,7 @@ uint32_t Name::getSuffix() const {
}
Name &Name::setSuffix(uint32_t seq_number) {
- if (hicn_name_set_seq_number(name_.get(), seq_number) < 0) {
+ if (hicn_name_set_seq_number(&name_, seq_number) < 0) {
throw errors::RuntimeException(
"Impossible to set the sequence number to the name.");
}
@@ -165,7 +149,7 @@ Name &Name::setSuffix(uint32_t seq_number) {
std::shared_ptr<Sockaddr> Name::getAddress() const {
Sockaddr *ret = nullptr;
- switch (name_->type) {
+ switch (name_.type) {
case HNT_CONTIGUOUS_V4:
case HNT_IOV_V4:
ret = (Sockaddr *)new Sockaddr4;
@@ -178,7 +162,7 @@ std::shared_ptr<Sockaddr> Name::getAddress() const {
throw errors::MalformedNameException();
}
- if (hicn_name_to_sockaddr_address((hicn_name_t *)name_.get(), ret) < 0) {
+ if (hicn_name_to_sockaddr_address((hicn_name_t *)&name_, ret) < 0) {
throw errors::MalformedNameException();
}
@@ -189,7 +173,7 @@ ip_address_t Name::toIpAddress() const {
ip_address_t ret;
std::memset(&ret, 0, sizeof(ret));
- if (hicn_name_to_ip_address(name_.get(), &ret) < 0) {
+ if (hicn_name_to_ip_address(&name_, &ret) < 0) {
throw errors::InvalidIpAddressException();
}
@@ -199,7 +183,7 @@ ip_address_t Name::toIpAddress() const {
int Name::getAddressFamily() const {
int ret = 0;
- if (hicn_name_get_family(name_.get(), &ret) < 0) {
+ if (hicn_name_get_family(&name_, &ret) < 0) {
throw errors::InvalidIpAddressException();
}
@@ -207,8 +191,7 @@ int Name::getAddressFamily() const {
}
void Name::copyToDestination(uint8_t *destination, bool include_suffix) const {
- if (hicn_name_copy_to_destination(destination, name_.get(), include_suffix) <
- 0) {
+ if (hicn_name_copy_to_destination(destination, &name_, include_suffix) < 0) {
throw errors::RuntimeException(
"Impossibe to copy the name into the "
"provided destination");
diff --git a/libtransport/src/hicn/transport/core/name.h b/libtransport/src/hicn/transport/core/name.h
index b2f913986..061371be5 100644
--- a/libtransport/src/hicn/transport/core/name.h
+++ b/libtransport/src/hicn/transport/core/name.h
@@ -67,9 +67,7 @@ class Name {
Name(const std::string &uri);
- Name(const Name &name, bool hard_copy = false);
-
- Name(Name &&name);
+ Name(const Name &name);
Name &operator=(const Name &name);
@@ -103,21 +101,13 @@ class Name {
int getAddressFamily() const;
private:
- TRANSPORT_ALWAYS_INLINE NameStruct *getStructReference() const {
- if (TRANSPORT_EXPECT_TRUE(name_ != nullptr)) {
- return name_.get();
- }
-
- return nullptr;
+ TRANSPORT_ALWAYS_INLINE const NameStruct *getConstStructReference() const {
+ return &name_;
}
- static TRANSPORT_ALWAYS_INLINE std::unique_ptr<NameStruct> createEmptyName() {
- NameStruct *name = new NameStruct;
- name->type = HNT_UNSPEC;
- return std::unique_ptr<NameStruct>(name);
- };
+ TRANSPORT_ALWAYS_INLINE NameStruct *getStructReference() { return &name_; }
- std::unique_ptr<NameStruct> name_;
+ NameStruct name_;
};
std::ostream &operator<<(std::ostream &os, const Name &name);
diff --git a/libtransport/src/hicn/transport/core/packet.cc b/libtransport/src/hicn/transport/core/packet.cc
index 04ec74660..954266664 100644
--- a/libtransport/src/hicn/transport/core/packet.cc
+++ b/libtransport/src/hicn/transport/core/packet.cc
@@ -29,7 +29,7 @@ namespace transport {
namespace core {
- const core::Name Packet::base_name("0::0|0");
+const core::Name Packet::base_name("0::0|0");
Packet::Packet(Format format)
: packet_(utils::MemBuf::create(getHeaderSizeFromFormat(format, 256))
@@ -37,8 +37,7 @@ Packet::Packet(Format format)
packet_start_(reinterpret_cast<hicn_header_t *>(packet_->writableData())),
header_head_(packet_.get()),
payload_head_(nullptr),
- format_(format){
-
+ format_(format) {
if (hicn_packet_init_header(format, packet_start_) < 0) {
throw errors::RuntimeException("Unexpected error initializing the packet.");
}
diff --git a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc
index 303b753be..61c5dfc7f 100644
--- a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc
+++ b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc
@@ -125,15 +125,14 @@ void VPPForwarderInterface::connect(bool is_consumer) {
if (!VPPForwarderInterface::memif_api_) {
VPPForwarderInterface::api_ = vpp_binary_api_init(app_name.str().c_str());
- }
-
- VPPForwarderInterface::memif_api_ =
+ VPPForwarderInterface::memif_api_ =
memif_binary_api_init(VPPForwarderInterface::api_);
+ VPPForwarderInterface::hicn_api_ =
+ hicn_binary_api_init(VPPForwarderInterface::api_);
+ }
sw_if_index_ = getMemifConfiguration();
- VPPForwarderInterface::hicn_api_ =
- hicn_binary_api_init(VPPForwarderInterface::api_);
if (is_consumer) {
consumerConnection();
}
diff --git a/libtransport/src/hicn/transport/http/server_publisher.cc b/libtransport/src/hicn/transport/http/server_publisher.cc
index 6a4bb9c48..b4deb5333 100644
--- a/libtransport/src/hicn/transport/http/server_publisher.cc
+++ b/libtransport/src/hicn/transport/http/server_publisher.cc
@@ -21,7 +21,7 @@ namespace transport {
namespace http {
HTTPServerPublisher::HTTPServerPublisher(const core::Name &content_name)
- : content_name_(content_name, true) {
+ : content_name_(content_name) {
std::string identity = "acceptor_producer";
producer_ = std::make_unique<ProducerSocket>();
// utils::Identity::generateIdentity(identity));
diff --git a/libtransport/src/hicn/transport/interfaces/socket_producer.cc b/libtransport/src/hicn/transport/interfaces/socket_producer.cc
index c85b8af32..9ca004c41 100644
--- a/libtransport/src/hicn/transport/interfaces/socket_producer.cc
+++ b/libtransport/src/hicn/transport/interfaces/socket_producer.cc
@@ -22,6 +22,8 @@ namespace transport {
namespace interface {
+namespace details {}
+
typedef std::chrono::time_point<std::chrono::steady_clock> Time;
typedef std::chrono::microseconds TimeDuration;
@@ -133,13 +135,15 @@ void ProducerSocket::produce(ContentObject &content_object) {
portal_->sendContentObject(content_object);
}
-uint32_t ProducerSocket::produce(Name content_name, const uint8_t *buf,
- size_t buffer_size, bool is_last,
- uint32_t start_offset) {
- if (TRANSPORT_EXPECT_FALSE(buffer_size == 0)) {
+uint32_t ProducerSocket::produce(Name content_name,
+ std::unique_ptr<utils::MemBuf> &&buffer,
+ bool is_last, uint32_t start_offset) {
+ if (TRANSPORT_EXPECT_FALSE(buffer->length() == 0)) {
return 0;
}
+ auto buffer_size = buffer->length();
+
const std::size_t hash_size = 32;
int bytes_segmented = 0;
@@ -198,6 +202,8 @@ uint32_t ProducerSocket::produce(Name content_name, const uint8_t *buf,
number_of_segments++;
}
+ // TODO allocate space for all the headers
+
if (making_manifest_) {
auto segment_in_manifest = static_cast<float>(
std::floor(double(data_packet_size_ - manifest_header_size -
@@ -267,9 +273,11 @@ uint32_t ProducerSocket::produce(Name content_name, const uint8_t *buf,
content_name.setSuffix(current_segment), format);
content_object->setLifetime(content_object_expiry_time_);
- if (packaged_segments == number_of_segments - 1) {
- content_object->appendPayload(&buf[bytes_segmented],
- buffer_size - bytes_segmented);
+ auto b = buffer->cloneOne();
+ b->trimStart(free_space_for_content * packaged_segments);
+ b->trimEnd(b->length());
+ if (TRANSPORT_EXPECT_FALSE(packaged_segments == number_of_segments - 1)) {
+ b->append(buffer_size - bytes_segmented);
bytes_segmented += (int)(buffer_size - bytes_segmented);
if (is_last && making_manifest_) {
@@ -279,11 +287,12 @@ uint32_t ProducerSocket::produce(Name content_name, const uint8_t *buf,
}
} else {
- content_object->appendPayload(&buf[bytes_segmented],
- free_space_for_content);
+ b->append(free_space_for_content);
bytes_segmented += (int)(free_space_for_content);
}
+ content_object->appendPayload(std::move(b));
+
if (making_manifest_) {
using namespace std::chrono_literals;
utils::CryptoHash hash = content_object->computeDigest(hash_algorithm_);
diff --git a/libtransport/src/hicn/transport/interfaces/socket_producer.h b/libtransport/src/hicn/transport/interfaces/socket_producer.h
index 744ddd86d..cd1c5a374 100644
--- a/libtransport/src/hicn/transport/interfaces/socket_producer.h
+++ b/libtransport/src/hicn/transport/interfaces/socket_producer.h
@@ -51,6 +51,12 @@ class ProducerSocket : public Socket<BasePortal>,
void connect() override;
uint32_t produce(Name content_name, const uint8_t *buffer, size_t buffer_size,
+ bool is_last = true, uint32_t start_offset = 0) {
+ return produce(content_name, utils::MemBuf::copyBuffer(buffer, buffer_size),
+ is_last, start_offset);
+ }
+
+ uint32_t produce(Name content_name, std::unique_ptr<utils::MemBuf> &&buffer,
bool is_last = true, uint32_t start_offset = 0);
void produce(ContentObject &content_object);
diff --git a/libtransport/src/hicn/transport/utils/content_store.cc b/libtransport/src/hicn/transport/utils/content_store.cc
index c3864310e..1e6b9fcea 100644
--- a/libtransport/src/hicn/transport/utils/content_store.cc
+++ b/libtransport/src/hicn/transport/utils/content_store.cc
@@ -31,7 +31,7 @@ void ContentStore::insert(
return;
}
- std::unique_lock<std::mutex> lock(cs_mutex_);
+ utils::SpinLock::Acquire locked(cs_mutex_);
if (TRANSPORT_EXPECT_FALSE(content_store_hash_table_.size() !=
fifo_list_.size())) {
@@ -64,7 +64,7 @@ void ContentStore::insert(
const std::shared_ptr<ContentObject> ContentStore::find(
const Interest &interest) {
- std::unique_lock<std::mutex> lock(cs_mutex_);
+ utils::SpinLock::Acquire locked(cs_mutex_);
auto it = content_store_hash_table_.find(interest.getName());
if (it != content_store_hash_table_.end()) {
if (std::chrono::duration_cast<std::chrono::milliseconds>(
@@ -78,7 +78,7 @@ const std::shared_ptr<ContentObject> ContentStore::find(
}
void ContentStore::erase(const Name &exact_name) {
- std::unique_lock<std::mutex> lock(cs_mutex_);
+ utils::SpinLock::Acquire locked(cs_mutex_);
auto it = content_store_hash_table_.find(exact_name);
fifo_list_.erase(it->second.second);
content_store_hash_table_.erase(exact_name);
diff --git a/libtransport/src/hicn/transport/utils/content_store.h b/libtransport/src/hicn/transport/utils/content_store.h
index ba8ee5bd2..a89403a01 100644
--- a/libtransport/src/hicn/transport/utils/content_store.h
+++ b/libtransport/src/hicn/transport/utils/content_store.h
@@ -69,7 +69,7 @@ class ContentStore {
FIFOList fifo_list_;
std::shared_ptr<ContentObject> empty_reference_;
std::size_t max_content_store_size_;
- std::mutex cs_mutex_;
+ utils::SpinLock cs_mutex_;
};
} // end namespace utils \ No newline at end of file
diff --git a/utils/src/hiperf.cc b/utils/src/hiperf.cc
index 3f9cffd0c..b62173be8 100644
--- a/utils/src/hiperf.cc
+++ b/utils/src/hiperf.cc
@@ -610,15 +610,23 @@ class HIperfServer {
void produceContent(uint32_t suffix) {
core::Name name = configuration_.name.getName();
- std::string content(configuration_.download_size, '?');
+ auto b = utils::MemBuf::create(configuration_.download_size);
+ std::memset(b->writableData(), '?', configuration_.download_size);
+ b->append(configuration_.download_size);
uint32_t total;
+ utils::TimePoint t0 = utils::SteadyClock::now();
+
total = producer_socket_->produce(
- name, reinterpret_cast<const uint8_t *>(content.data()), content.size(),
- !configuration_.multiphase_produce_, suffix);
+ name, std::move(b), !configuration_.multiphase_produce_, suffix);
- std::cout << "Written " << total << "pieces of data in output buffer"
- << std::endl;
+ utils::TimePoint t1 = utils::SteadyClock::now();
+
+ std::cout
+ << "Written " << total
+ << " data packets in output buffer (Segmentation time: "
+ << std::chrono::duration_cast<utils::Microseconds>(t1 - t0).count()
+ << " us)" << std::endl;
}
std::shared_ptr<utils::Identity> setProducerIdentity(