summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/README.md191
-rw-r--r--cmake/Modules/BuildMacros.cmake21
-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/core/message.c2
-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--hicn-plugin/CMakeLists.txt8
-rw-r--r--hicn-plugin/README.md7
-rw-r--r--hicn-plugin/src/cli.c73
-rw-r--r--lib/src/compat.c2
-rw-r--r--lib/src/compat.h2
-rw-r--r--libtransport/src/hicn/transport/CMakeLists.txt4
-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/protocols/CMakeLists.txt2
-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.cc25
27 files changed, 448 insertions, 249 deletions
diff --git a/apps/README.md b/apps/README.md
index bee6545a6..eefb68be1 100644
--- a/apps/README.md
+++ b/apps/README.md
@@ -82,73 +82,110 @@ We consider the following topology, consisting on two linux VM which are able to
```
Install the hICN suite on two linux VM. This tutorial makes use of Ubuntu 18.04, but it could easily be adapted to other platforms.
-You can either install the hICN stack using binaries or compile the code. In this tutorial we will build the code from source.
+You can either install the hICN stack using binaries or compile the code. In this tutorial we will make use of docker container and binaries packages.
-```bash
-$ curl -s https://packagecloud.io/install/repositories/fdio/release/script.deb.sh | sudo bash
-$ apt-get install -y git \
- cmake \
- build-essential \
- libasio-dev \
- libcurl4-openssl-dev \
- libparc-dev \
- --no-install-recommends
+The client will use of the hicn-light forwarder, which is lightweight and tailored for devices such as android and laptops.
+The server will use the hicn-plugin of vpp, which guarantees better performances and it is the best choice for server applications.
+
+Keep in mind that on the same system the stack based on vpp forwarder cannot coexist with the stack based on hicn light.
+
+For running the hicn-plugin at the server there are two main alternatives:
+
+- Use a docker container
+- Run the hicn-plugin directly in a VM or Bare Metal Server
-$ mkdir hicn-suite && cd hicn-suite
-$ git clone https://github.com/FDio/hicn hicn-src
-$ mkdir hicn-build && cd hicn-build
-$ cmake ../hicn-src -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../hicn-install -DBUILD_APPS=ON
-$ make -j 4 install
-$ export HICN_ROOT=${PWD}/../hicn-install
+#### Docker
+
+Install docker in the server VM:
+
+```bash
+server$ sudo apt-get update
+server$ sudo apt-get install \
+ apt-transport-https \
+ ca-certificates \
+ curl \
+ gnupg-agent \
+ software-properties-common
+
+server$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
+server$ sudo add-apt-repository \
+ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
+ $(lsb_release -cs) \
+ stable"
+server$ sudo apt-get update
+server$ sudo apt-get install docker-ce docker-ce-cli containerd.io
```
-It should install the hICN suite under hicn-install.
+Run the hicn-http-proxy container. Here we use a public server [example.com](example.com) as origin:
-#### hICN stack based on hicn-light forwarder with UDP faces
+```bash
+server$ docker run -e ORIGIN_ADDRESS=example.com \
+ -e ORIGIN_PORT=80 \
+ -e CACHE_SIZE=10000 \
+ -e HICN_MTU=1200 \
+ -e FIRST_IPV6_WORD=c001 \
+ -e HICN_PREFIX=http://webserver \
+ --privileged \
+ --name vhttpproxy \
+ -d icnteam/vhttpproxy
+```
-##### Server Configuration
+Create a hicn private network:
-Open a new terminal on the machine where you want to run the HTTP server and install apache2 http server:
+```bash
+server$ GATEWAY=192.168.0.254
+server$ docker network create --subnet 192.168.0.0/24 --gateway ${GATEWAY} hicn-network
+```
+
+Connect the proxy container to the hicn network:
```bash
-server$ sudo apt-get install -y apache2
-server$ sudo systemctl start apache2
+server$ docker network connect hicn-network vhttpproxy
```
-Create a configuration file for the hicn-light forwarder. Here we are configuring UDP faces.
+Connect the hicn network to the vpp forwarder:
```bash
-server$ mkdir -p ${HICN_ROOT}/etc
-server$ LOCAL_IP="10.0.0.1" # Put here the actual IPv4 of the local interface
-server$ LOCAL_PORT="12345"
-server$ cat << EOF > ${HICN_ROOT}/etc/hicn-light.conf
-add listener udp list0 ${LOCAL_IP} ${LOCAL_PORT}
-EOF
+server$ IP_ADDRESS=$(docker inspect -f "{{with index .NetworkSettings.Networks \"hicn-network\"}}{{.IPAddress}}{{end}}" vhttpproxy)
+server$ INTERFACE=$(docker exec -it vhttpproxy ifconfig | grep -B 1 ${IP_ADDRESS} | awk 'NR==1 {gsub(":","",$1); print $1}')
+server$ docker exec -it vhttpproxy ip addr flush dev ${INTERFACE}
+server$ docker exec -it vhttpproxy ethtool -K ${INTERFACE} tx off rx off ufo off gso off gro off tso off
+server$ docker exec -it vhttpproxy vppctl create host-interface name ${INTERFACE}
+server$ docker exec -it vhttpproxy vppctl set interface state host-${INTERFACE} up
+server$ docker exec -it vhttpproxy vppctl set interface ip address host-${INTERFACE} ${IP_ADDRESS}/24
+server$ docker exec -it vhttpproxy vppctl ip route add 10.0.0.0/24 via ${GATEWAY} host-eth1
```
-Start the hicn-light forwarder
+Set the punting:
```bash
-server$ sudo ${HICN_ROOT}/bin/hicn-light-daemon --daemon --capacity 1000 --log-file ${HICN_ROOT}/hicn-light.log --config ${HICN_ROOT}/etc/hicn-light.conf
+server$ PORT=12345
+server$ docker exec -it vhttpproxy vppctl hicn punting add prefix c001::/16 intfc host-${INTERFACE} type udp4 src_port ${PORT} dst_port ${PORT}
```
-Run the [hicn-http-proxy](#hicn-http-proxy). Assuming the http origin is listening on port 80:
+Docker containers are cool, but sometimes they do not allow you to do simple operations like expose ports while the container is already running. But we have a workaround for this :)
```bash
-server$ ${HICN_ROOT}/bin/hicn-http-proxy -a 127.0.0.1 -p 80 -c 10000 -m 1200 -P c001 http://webserver
+server$ sudo iptables -t nat -A DOCKER -p udp --dport ${PORT} -j DNAT --to-destination ${IP_ADDRESS}:${PORT}
+server$ sudo iptables -t nat -A POSTROUTING -j MASQUERADE -p udp --source ${IP_ADDRESS} --destination ${IP_ADDRESS} --dport ${PORT}
+server$ sudo iptables -A DOCKER -j ACCEPT -p udp --destination ${IP_ADDRESS} --dport ${PORT}
```
-##### Client Configuration
+In the client, install the hicn stack:
-Create a configuration file for the hicn-light forwarder. Here we are configuring UDP faces.
+```bash
+client$ sudo apt-get install -y hicn-light hicn-apps
+```
+
+Create a configuration file for the hicn-light forwarder. Here we are configuring UDP faces:
```bash
-client$ mkdir -p ${HICN_ROOT}/etc
+client$ mkdir -p ${HOME}/etc
client$ LOCAL_IP="10.0.0.2" # Put here the actual IPv4 of the local interface
client$ LOCAL_PORT="12345"
client$ REMOTE_IP="10.0.0.1" # Put here the actual IPv4 of the remote interface
client$ REMOTE_PORT="12345"
-client$ cat << EOF > ${HICN_ROOT}/etc/hicn-light.conf
+client$ cat << EOF > ${HOME}/etc/hicn-light.conf
add listener udp list0 ${LOCAL_IP} ${LOCAL_PORT}
add connection udp conn0 ${REMOTE_IP} ${REMOTE_PORT} ${LOCAL_IP} ${LOCAL_PORT}
add route conn0 c001::/16 1
@@ -158,39 +195,74 @@ EOF
Run the hicn-light forwarder
```bash
-client$ sudo ${HICN_ROOT}/bin/hicn-light-daemon --daemon --capacity 1000 --log-file ${HICN_ROOT}/hicn-light.log --config ${HICN_ROOT}/etc/hicn-light.conf
+client$ sudo /usr/bin/hicn-light-daemon --daemon --capacity 1000 --log-file ${HOME}/hicn-light.log --config ${HOME}/etc/hicn-light.conf
```
Run the http client [higet](#higet) and print the http response on stdout:
```bash
-client$ ${HICN_ROOT}/bin/higet -O - http://webserver/index.html -P c001
-EOF
+client$ /usr/bin/higet -O - http://webserver/index.html -P c001
```
-#### Using hicn-light forwarder with hICN faces
+#### Host/VM
-For sending hICN packets directly over the network, using hicn faces, change the configuration of the two forwarders and restart them.
+You can install the hicn-plugin of vpp on your VM and directly use DPDK compatible nics, forwarding hicn packets directly over the network. DPDK compatible nics can be used inside a container as well.
+
+```bash
+server$ sudo apt-get install -y hicn-plugin vpp-plugin-dpdk hicn-apps-memif
+```
-##### Server Configuration
+It will install all the required deps (vpp, hicn apps and libraries compiled for communicating with vpp using shared memories). Configure VPP following the steps described [here](https://github.com/FDio/hicn/blob/master/hicn-plugin/README.md#configure-vpp).
+
+This tutorial assumes you configured two interfaces in your server VM:
+
+- One interface which uses the DPDK driver, to be used by VPP
+- One interface which is still owned by the kernel
+
+The DPDK interface will be used for connecting the server with the hicn client, while the other interface will guarantee connectivity to the applications running in the VM, including the hicn-http-proxy. If you run the commands:
```bash
-server$ mkdir -p ${HICN_ROOT}/etc
-server$ LOCAL_IP="9001::1"
-server$ cat << EOF > ${HICN_ROOT}/etc/hicn-light.conf
-add listener hicn lst 0::0
-add punting lst c001::/16
-add listener hicn list0 ${LOCAL_IP}
-EOF
+server$ sudo systemctl restart vpp
+server$ vppctl show int
+```
+
+The output must show the dpdk interface owned by VPP:
+
+```text
+ Name Idx State MTU (L3/IP4/IP6/MPLS) Counter Count
+GigabitEthernetb/0/0 1 down 9000/0/0/0
+local0 0 down 0/0/0/0
+```
+
+If the interface is down, bring it up and assign the correct ip address to it:
+
+```bash
+server$ vppctl set int state GigabitEthernetb/0/0 up
+server$ vppctl set interface ip address GigabitEthernetb/0/0 9001::1/64
+```
+
+Take care of replacing the interface name (`GigabitEthernetb/0/0`) with the actual name of your interface.
+
+Now enable the hicn plugin and set the punting for the hicn packets:
+
+```bash
+server$ vppctl hicn control start
+server$ vppctl hicn punting add prefix c001::/16 intfc GigabitEthernetb/0/0 type ip
```
-#### Client Configuration
+Run the hicn-http-proxy app:
```bash
-client$ mkdir -p ${HICN_ROOT}/etc
+server$ sudo /usr/bin/hicn-http-proxy -a example.com -p 80 -c 10000 -m 1200 -P c001 http://webserver
+```
+
+Configure the client for sending hicn packets without any udp encapsulation:
+
+```bash
+client$ mkdir -p ${HOME}/etc
client$ LOCAL_IP="9001::2"
client$ REMOTE_IP="9001::1"
-client$ cat << EOF > ${HICN_ROOT}/etc/hicn-light.conf
+client$ cat << EOF > ${HOME}/etc/hicn-light.conf
add listener hicn lst 0::0
add punting lst c001::/16
add listener hicn list0 ${LOCAL_IP}
@@ -199,6 +271,19 @@ add route conn0 c001::/16 1
EOF
```
+Restart the forwarder:
+
+```bash
+client$ sudo killall -INT hicn-light-daemon
+client$ sudo /usr/bin/hicn-light-daemon --daemon --capacity 1000 --log-file ${HOME}/hicn-light.log --config ${HOME}/etc/hicn-light.conf
+```
+
+Retrieve a web page:
+
+```bash
+client$ /usr/bin/higet -O - http://webserver/index.html -P c001
+```
+
## License
This software is distributed under the following license:
diff --git a/cmake/Modules/BuildMacros.cmake b/cmake/Modules/BuildMacros.cmake
index e7244d2bc..3e681b425 100644
--- a/cmake/Modules/BuildMacros.cmake
+++ b/cmake/Modules/BuildMacros.cmake
@@ -15,6 +15,8 @@
# Utils for building libraries and executables
#
+include(GNUInstallDirs)
+
macro(build_executable exec)
cmake_parse_arguments(ARG
"NO_INSTALL"
@@ -29,7 +31,7 @@ macro(build_executable exec)
set_target_properties(${exec}
PROPERTIES
- INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
+ INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
INSTALL_RPATH_USE_LINK_PATH TRUE
ARCHIVE_OUTPUT_DIRECTORY "${BUILD_ROOT}/lib"
LIBRARY_OUTPUT_DIRECTORY "${BUILD_ROOT}/lib"
@@ -56,7 +58,12 @@ macro(build_executable exec)
endif()
if(NOT ARG_NO_INSTALL)
- install(TARGETS ${exec} RUNTIME DESTINATION bin COMPONENT ${ARG_COMPONENT})
+ install(
+ TARGETS ${exec}
+ RUNTIME
+ DESTINATION ${CMAKE_INSTALL_BINDIR}
+ COMPONENT ${ARG_COMPONENT}
+ )
endif()
endmacro()
@@ -99,7 +106,7 @@ macro(build_library lib)
set_target_properties(${library}
PROPERTIES
- INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
+ INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
INSTALL_RPATH_USE_LINK_PATH TRUE
ARCHIVE_OUTPUT_DIRECTORY "${BUILD_ROOT}/lib"
LIBRARY_OUTPUT_DIRECTORY "${BUILD_ROOT}/lib"
@@ -138,9 +145,9 @@ macro(build_library lib)
install(
TARGETS ${library}
- RUNTIME DESTINATION bin
- ARCHIVE DESTINATION lib
- LIBRARY DESTINATION lib
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT ${ARG_COMPONENT}
)
@@ -173,7 +180,7 @@ macro(build_library lib)
endif()
install(
FILES ${file}
- DESTINATION include/${ARG_INSTALL_ROOT_DIR}/${dir}
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${ARG_INSTALL_ROOT_DIR}/${dir}
COMPONENT ${COMPONENT}
)
endforeach()
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/core/message.c b/hicn-light/src/hicn/core/message.c
index ef8fa5d91..b0140eda4 100644
--- a/hicn-light/src/hicn/core/message.c
+++ b/hicn-light/src/hicn/core/message.c
@@ -288,6 +288,8 @@ bool message_HasContentExpiryTime(const Message *message) {
uint64_t message_GetContentExpiryTimeTicks(const Message *message) {
parcAssertNotNull(message, "Parameter message must be non-null");
uint64_t expire = messageHandler_GetContentExpiryTime(message->messageHead);
+ if(expire == 0)
+ return message->receiveTime;
return message->receiveTime + forwarder_NanosToTicks(expire * 1000000ULL);
}
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/hicn-plugin/CMakeLists.txt b/hicn-plugin/CMakeLists.txt
index be71b36a3..8c859cdd9 100644
--- a/hicn-plugin/CMakeLists.txt
+++ b/hicn-plugin/CMakeLists.txt
@@ -14,6 +14,8 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(hicn-plugin)
+include(GNUInstallDirs)
+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules/"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/"
@@ -195,7 +197,7 @@ if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "Release")
endif (NOT CMAKE_BUILD_TYPE)
-SET(HICN_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/lib CACHE STRING "hicn_install_prefix")
+SET(HICN_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} CACHE STRING "hicn_install_prefix")
if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -march=native -O3 -g")
@@ -274,9 +276,9 @@ install(TARGETS hicn_api_test_plugin
COMPONENT ${HICN_PLUGIN})
install(FILES ${HICN_API_TEST_HEADER_FILES} ${HICN_API_GENERATED_FILES}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/vpp_plugins/hicn
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/vpp_plugins/hicn
COMPONENT ${HICN_PLUGIN})
install(FILES ${HICN_VAPI_GENERATED_FILES}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/vapi
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/vapi
COMPONENT ${HICN_PLUGIN})
diff --git a/hicn-plugin/README.md b/hicn-plugin/README.md
index 7a7b02271..2208f5ada 100644
--- a/hicn-plugin/README.md
+++ b/hicn-plugin/README.md
@@ -248,13 +248,6 @@ hicn fib {{add | delete } prefix <prefix> face <face_id> } | set strategy <strat
<strategy_id> :set a strategy for the corresponding prefix
```
-`hicn mapme`: enable and disable mapme.
-
-```
-hicn mapme {enable|disable|set <param> <value>}
-```
-
-
`hicn pgen client`: set an vpp forwarder as an hicn packet generator client
```
diff --git a/hicn-plugin/src/cli.c b/hicn-plugin/src/cli.c
index 54344bd7b..8af56dcba 100644
--- a/hicn-plugin/src/cli.c
+++ b/hicn-plugin/src/cli.c
@@ -34,7 +34,6 @@
#include "route.h"
#include "punt.h"
#include "hicn_api.h"
-#include "mapme.h"
extern ip_version_t ipv4;
extern ip_version_t ipv6;
@@ -710,71 +709,6 @@ hicn_cli_punting_command_fn (vlib_main_t * vm, unformat_input_t * main_input,
(ret));
}
-static clib_error_t *
-hicn_cli_mapme_command_fn (vlib_main_t * vm, unformat_input_t * main_input,
- vlib_cli_command_t * cmd)
-{
- hicn_mgmt_mapme_op_e mapme_op = HICN_MGMT_MAPME_OP_NONE;
- unsigned int subnet_mask = 0;
- ip46_address_t prefix;
- u32 sw_if_index = ~0;
- int ret = 0;
- vnet_main_t *vnm = NULL;
-
- vnm = vnet_get_main ();
-
- unformat_input_t _line_input, *line_input = &_line_input;
- if (!unformat_user (main_input, unformat_line_input, line_input))
- {
- return (0);
- }
- while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (line_input, "add"))
- {
- mapme_op = HICN_MGMT_MAPME_OP_CREATE;
- }
- else if (unformat (line_input, "delete"))
- {
- mapme_op = HICN_MGMT_MAPME_OP_DELETE;
- }
- else if (unformat (line_input, "intfc %U",
- unformat_vnet_sw_interface, vnm, &sw_if_index))
- {;
- }
- else if (unformat
- (line_input, "prefix %U/%d", unformat_ip46_address,
- &prefix, IP46_TYPE_ANY, &subnet_mask))
- {;
- }
- else
- {
- return (clib_error_return (0, "invalid option"));
- }
- }
-
- if (mapme_op == HICN_MGMT_MAPME_OP_CREATE
- && (ip46_address_is_zero (&prefix) || sw_if_index == ~0))
- {
- return (clib_error_return
- (0, "Please specify valid prefix and interface"));
- }
- else if ((mapme_op == HICN_MGMT_MAPME_OP_DELETE) &&
- ip46_address_is_zero (&prefix))
- {
- return (clib_error_return
- (0, "Please specify valid prefix and optionally an interface"));
- }
- else if (mapme_op == HICN_MGMT_MAPME_OP_NONE)
- {
- return (clib_error_return
- (0, "Please specify valid operation, add or delete"));
- }
- return (ret == HICN_ERROR_NONE) ? clib_error_return (0, "Punting %s",
- get_error_string (ret))
- : clib_error_return (0, get_error_string (ret));
-}
-
/*
* cli handler for 'pgen'
*/
@@ -1226,13 +1160,6 @@ VLIB_CLI_COMMAND(hicn_cli_punting_command, static)=
.function = hicn_cli_punting_command_fn,
};
-VLIB_CLI_COMMAND(hicn_cli_mapme_command, static)=
-{
- .path = "hicn mapme",
- .short_help = "hicn mapme {enable|disable|set <param> <value>}",
- .function = hicn_cli_mapme_command_fn,
-};
-
/* cli declaration for 'hicn pgen client' */
VLIB_CLI_COMMAND(hicn_cli_pgen_client_set_command, static)=
{
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/CMakeLists.txt b/libtransport/src/hicn/transport/CMakeLists.txt
index b6be3f77a..3b5e9a15f 100644
--- a/libtransport/src/hicn/transport/CMakeLists.txt
+++ b/libtransport/src/hicn/transport/CMakeLists.txt
@@ -13,6 +13,8 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+include(GNUInstallDirs)
+
set(ASIO_STANDALONE 1)
add_subdirectory(core)
@@ -26,7 +28,7 @@ add_subdirectory(utils)
configure_file("config.h.in" "config.h" @ONLY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h
- DESTINATION include/hicn/transport
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hicn/transport
COMPONENT lib${LIBTRANSPORT}-dev
)
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/protocols/CMakeLists.txt b/libtransport/src/hicn/transport/protocols/CMakeLists.txt
index 84a4d5279..23aeca9bf 100644
--- a/libtransport/src/hicn/transport/protocols/CMakeLists.txt
+++ b/libtransport/src/hicn/transport/protocols/CMakeLists.txt
@@ -57,7 +57,7 @@ set(TRANSPORT_CONFIG
install(
FILES ${TRANSPORT_CONFIG}
- DESTINATION etc/hicn
+ DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/hicn
COMPONENT lib${LIBTRANSPORT}
)
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 66cd559cb..b62173be8 100644
--- a/utils/src/hiperf.cc
+++ b/utils/src/hiperf.cc
@@ -565,13 +565,18 @@ class HIperfServer {
content_objects_index_(0),
mask_((std::uint16_t)(1 << log2_content_object_buffer_size) - 1),
#ifndef _WIN32
- input_(io_service_, ::dup(STDIN_FILENO)),
+ input_(io_service_),
rtc_running_(false)
#endif
{
std::string buffer(configuration_.payload_size_, 'X');
std::cout << "Producing contents under name " << conf.name.getName()
<< std::endl;
+#ifndef _WIN32
+ if (configuration_.interactive_) {
+ input_.assign(::dup(STDIN_FILENO));
+ }
+#endif
for (int i = 0; i < (1 << log2_content_object_buffer_size); i++) {
content_objects_[i] = std::make_shared<ContentObject>(
@@ -605,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(