aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/config
diff options
context:
space:
mode:
authorAngelo Mantellini <manangel@cisco.com>2019-07-18 18:31:46 +0200
committerAngelo Mantellini <manangel@cisco.com>2019-10-12 13:27:54 +0000
commiteefc7ae95bbd680416163e5617bada1949b32afc (patch)
tree336a4100832001b2991be007749d12ec5c28c1a0 /hicn-light/src/hicn/config
parent91304b8cb75df7cb516518b53e3c1156d0f27ba5 (diff)
[HICN-247] remove listener and bug fixing
Change-Id: I4e5419a837131680fe0e21eb295462ccb2be8613 Signed-off-by: Angelo Mantellini <manangel@cisco.com>
Diffstat (limited to 'hicn-light/src/hicn/config')
-rw-r--r--hicn-light/src/hicn/config/CMakeLists.txt2
-rw-r--r--hicn-light/src/hicn/config/configuration.c82
-rw-r--r--hicn-light/src/hicn/config/configurationListeners.c4
-rw-r--r--hicn-light/src/hicn/config/controlAddConnection.c22
-rw-r--r--hicn-light/src/hicn/config/controlAddListener.c55
-rw-r--r--hicn-light/src/hicn/config/controlListConnections.c2
-rw-r--r--hicn-light/src/hicn/config/controlRemove.c7
-rw-r--r--hicn-light/src/hicn/config/controlRemoveListener.c115
-rw-r--r--hicn-light/src/hicn/config/controlRemoveListener.h31
9 files changed, 270 insertions, 50 deletions
diff --git a/hicn-light/src/hicn/config/CMakeLists.txt b/hicn-light/src/hicn/config/CMakeLists.txt
index b1e475aee..45f36e8ff 100644
--- a/hicn-light/src/hicn/config/CMakeLists.txt
+++ b/hicn-light/src/hicn/config/CMakeLists.txt
@@ -35,6 +35,7 @@ list(APPEND HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/controlListPolicies.h
${CMAKE_CURRENT_SOURCE_DIR}/controlQuit.h
${CMAKE_CURRENT_SOURCE_DIR}/controlRemove.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveListener.h
${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveConnection.h
${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveRoute.h
${CMAKE_CURRENT_SOURCE_DIR}/controlRemovePolicy.h
@@ -78,6 +79,7 @@ list(APPEND SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/controlListPolicies.c
${CMAKE_CURRENT_SOURCE_DIR}/controlQuit.c
${CMAKE_CURRENT_SOURCE_DIR}/controlRemove.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveListener.c
${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveConnection.c
${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveRoute.c
${CMAKE_CURRENT_SOURCE_DIR}/controlRemovePolicy.c
diff --git a/hicn-light/src/hicn/config/configuration.c b/hicn-light/src/hicn/config/configuration.c
index b14ea551a..83fce748c 100644
--- a/hicn-light/src/hicn/config/configuration.c
+++ b/hicn-light/src/hicn/config/configuration.c
@@ -346,7 +346,6 @@ static void configuration_SendResponse(Configuration *config, struct iovec *msg,
if (conn == NULL) {
return;
}
-
connection_SendIOVBuffer(conn, msg, 2);
}
@@ -450,6 +449,10 @@ struct iovec *configuration_ProcessCreateTunnel(Configuration *config,
/* Hook: new connection created through the control protocol */
forwarder_onConnectionEvent(config->forwarder, conn, CONNECTION_EVENT_UPDATE);
#endif /* WITH_MAPME */
+ if (source)
+ addressDestroy(&source);
+ if (destination)
+ addressDestroy(&destination);
success = true;
#else
@@ -472,6 +475,70 @@ ERR:
return utils_CreateNack(header, control, sizeof(add_connection_command));
}
+struct iovec *configuration_ProcessRemoveListener(Configuration *config,
+ struct iovec *request,
+ unsigned ingressId) {
+ header_control_message *header = request[0].iov_base;
+ remove_listener_command *control = request[1].iov_base;
+
+ bool success = false;
+
+ const char *symbolicOrListenerid = control->symbolicOrListenerid;
+ unsigned listenerId = -1;
+ ListenerSet *listenerSet = forwarder_GetListenerSet(config->forwarder);
+ if (utils_IsNumber(symbolicOrListenerid)) {
+ // case for connid as input
+ listenerId = (unsigned)strtold(symbolicOrListenerid, NULL);
+ } else {
+ listenerId = listenerSet_FindIdByListenerName(listenerSet, symbolicOrListenerid);
+ }
+
+ if (listenerId >= 0) {
+
+ ConnectionTable *connTable = forwarder_GetConnectionTable(config->forwarder);
+ ListenerOps *listenerOps = listenerSet_FindById(listenerSet, listenerId);
+ if (listenerOps) {
+ ConnectionList *connectionList =connectionTable_GetEntries(connTable);
+ for (size_t i =0; i < connectionList_Length(connectionList); i++) {
+ Connection *connection = connectionList_Get(connectionList, i);
+ const AddressPair *addressPair = connection_GetAddressPair(connection);
+ const Address *address = addressPair_GetLocal(addressPair);
+ if (addressEquals(listenerOps->getListenAddress(listenerOps),address)) {
+ // case for connid as input
+ unsigned connid = connection_GetConnectionId(connection);
+ // remove connection from the FIB
+ forwarder_RemoveConnectionIdFromRoutes(config->forwarder, connid);
+ // remove connection
+ connectionTable_RemoveById(connTable, connid);
+ const char *symbolicConnection = symbolicNameTable_GetNameByIndex(config->symbolicNameTable,connid);
+ symbolicNameTable_Remove(config->symbolicNameTable, symbolicConnection);
+ }
+ }
+ // remove listener
+ listenerSet_RemoveById(listenerSet, listenerId);
+ success = true;
+ } else {
+ logger_Log(forwarder_GetLogger(config->forwarder), LoggerFacility_IO,
+ PARCLogLevel_Error, __func__,
+ "Listener Id not found, check list listeners");
+ }
+ }
+
+ // generate ACK/NACK
+ struct iovec *response;
+
+ if (success) { // ACK
+ response =
+ utils_CreateAck(header, control, sizeof(remove_listener_command));
+ } else { // NACK
+ response =
+ utils_CreateNack(header, control, sizeof(remove_connection_command));
+ }
+
+ return response;
+}
+
+
/**
* Add an IP-based tunnel.
*
@@ -493,7 +560,6 @@ struct iovec *configuration_ProcessRemoveTunnel(Configuration *config,
const char *symbolicOrConnid = control->symbolicOrConnid;
ConnectionTable *table = forwarder_GetConnectionTable(config->forwarder);
-
if (strcmp(symbolicOrConnid, "SELF") == 0) {
forwarder_RemoveConnectionIdFromRoutes(config->forwarder, ingressId);
connectionTable_RemoveById(table, ingressId);
@@ -515,6 +581,9 @@ struct iovec *configuration_ProcessRemoveTunnel(Configuration *config,
forwarder_RemoveConnectionIdFromRoutes(config->forwarder, connid);
// remove connection
connectionTable_RemoveById(table, connid);
+ // remove connection from symbolicNameTable
+ const char *symbolicConnection = symbolicNameTable_GetNameByIndex(config->symbolicNameTable,connid);
+ symbolicNameTable_Remove(config->symbolicNameTable, symbolicConnection);
#ifdef WITH_MAPME
/* Hook: new connection created through the control protocol */
@@ -568,6 +637,8 @@ struct iovec *configuration_ProcessRemoveTunnel(Configuration *config,
}
}
+
+
// generate ACK/NACK
struct iovec *response;
@@ -612,8 +683,8 @@ struct iovec *configuration_ProcessConnectionList(Configuration *config,
list_connections_command *listConnectionsCommand =
(list_connections_command *)(payloadResponse +
(i * sizeof(list_connections_command)));
-
// set structure fields
+
listConnectionsCommand->connid = connection_GetConnectionId(original);
const char *connectionName = symbolicNameTable_GetNameByIndex(config->symbolicNameTable, connection_GetConnectionId(original));
@@ -1202,7 +1273,6 @@ struct iovec *configuration_DispatchCommand(Configuration *config,
struct iovec *control,
unsigned ingressId) {
struct iovec *response = NULL;
-
switch (command) {
case ADD_LISTENER:
response = configurationListeners_Add(config, control, ingressId);
@@ -1229,6 +1299,10 @@ struct iovec *configuration_DispatchCommand(Configuration *config,
response = configuration_ProcessRemoveTunnel(config, control, ingressId);
break;
+ case REMOVE_LISTENER:
+ response = configuration_ProcessRemoveListener(config, control, ingressId);
+ break;
+
case REMOVE_ROUTE:
response = configuration_ProcessUnregisterHicnPrefix(config, control);
break;
diff --git a/hicn-light/src/hicn/config/configurationListeners.c b/hicn-light/src/hicn/config/configurationListeners.c
index 86d8a215a..c321007e2 100644
--- a/hicn-light/src/hicn/config/configurationListeners.c
+++ b/hicn-light/src/hicn/config/configurationListeners.c
@@ -317,6 +317,7 @@ static bool _setupTcpListenerOnInet6Light(Forwarder *forwarder, char *listenerNa
* Create a new IPV6/UDP listener.
*
* @param [in,out] forwarder The hicn-light forwarder instance
+ * @param [in] listenerName The name of the listener
* @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
@@ -615,7 +616,8 @@ 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);
- char listenerNameUdp[16] = "lo_udp";
+
+ char listenerNameUdp[16] = "lo_udp";
char listenerNameTcp[16] = "lo_tcp";
char *loopback_interface = "lo";
_setupUdpListenerOnInet(forwarder, listenerNameUdp,(ipv4_addr_t *)&(addr),
diff --git a/hicn-light/src/hicn/config/controlAddConnection.c b/hicn-light/src/hicn/config/controlAddConnection.c
index e09b61b37..eaa680bde 100644
--- a/hicn-light/src/hicn/config/controlAddConnection.c
+++ b/hicn-light/src/hicn/config/controlAddConnection.c
@@ -42,11 +42,13 @@ static CommandReturn _controlAddConnection_Execute(CommandParser *parser,
// ===================================================
+#ifdef __linux__
static CommandReturn _controlAddConnection_HicnHelpExecute(
CommandParser *parser, CommandOps *ops, PARCList *args);
static CommandReturn _controlAddConnection_HicnExecute(CommandParser *parser,
CommandOps *ops,
PARCList *args);
+#endif
static CommandReturn _controlAddConnection_UdpHelpExecute(CommandParser *parser,
CommandOps *ops,
@@ -65,11 +67,15 @@ static CommandReturn _controlAddConnection_TcpExecute(CommandParser *parser,
// ===================================================
static const char *_commandAddConnection = "add connection";
+#ifdef __linux__
static const char *_commandAddConnectionHicn = "add connection hicn";
+#endif
static const char *_commandAddConnectionUdp = "add connection udp";
static const char *_commandAddConnectionTcp = "add connection tcp";
static const char *_commandAddConnectionHelp = "help add connection";
+#ifdef __linux__
static const char *_commandAddConnectionHicnHelp = "help add connection hicn";
+#endif
static const char *_commandAddConnectionUdpHelp = "help add connection udp";
static const char *_commandAddConnectionTcpHelp = "help add connection tcp";
@@ -89,11 +95,13 @@ CommandOps *controlAddConnection_HelpCreate(ControlState *state) {
// ===================================================
+#ifdef __linux__
static CommandOps *_controlAddConnection_HicnCreate(ControlState *state) {
return commandOps_Create(state, _commandAddConnectionHicn, NULL,
_controlAddConnection_HicnExecute,
commandOps_Destroy);
}
+#endif
static CommandOps *_controlAddConnection_UdpCreate(ControlState *state) {
return commandOps_Create(state, _commandAddConnectionUdp, NULL,
@@ -108,12 +116,13 @@ static CommandOps *_controlAddConnection_TcpCreate(ControlState *state) {
}
// ===================================================
-
+#ifdef __linux__
static CommandOps *_controlAddConnection_HicnHelpCreate(ControlState *state) {
return commandOps_Create(state, _commandAddConnectionHicnHelp, NULL,
_controlAddConnection_HicnHelpExecute,
commandOps_Destroy);
}
+#endif
static CommandOps *_controlAddConnection_UdpHelpCreate(ControlState *state) {
return commandOps_Create(state, _commandAddConnectionUdpHelp, NULL,
@@ -133,7 +142,9 @@ static CommandReturn _controlAddConnection_HelpExecute(CommandParser *parser,
CommandOps *ops,
PARCList *args) {
printf("Available commands:\n");
+#ifdef __linux__
printf(" %s\n", _commandAddConnectionHicn);
+#endif
printf(" %s\n", _commandAddConnectionUdp);
printf(" %s\n", _commandAddConnectionTcp);
printf("\n");
@@ -142,14 +153,17 @@ static CommandReturn _controlAddConnection_HelpExecute(CommandParser *parser,
static void _controlAddConnection_Init(CommandParser *parser, CommandOps *ops) {
ControlState *state = ops->closure;
+#ifdef __linux__
controlState_RegisterCommand(state,
_controlAddConnection_HicnHelpCreate(state));
+#endif
controlState_RegisterCommand(state,
_controlAddConnection_UdpHelpCreate(state));
controlState_RegisterCommand(state,
_controlAddConnection_TcpHelpCreate(state));
-
+#ifdef __linux__
controlState_RegisterCommand(state, _controlAddConnection_HicnCreate(state));
+#endif
controlState_RegisterCommand(state, _controlAddConnection_UdpCreate(state));
controlState_RegisterCommand(state, _controlAddConnection_TcpCreate(state));
}
@@ -255,7 +269,9 @@ static CommandReturn _controlAddConnection_IpHelp(CommandParser *parser,
CommandOps *ops,
PARCList *args,
const char *protocol) {
+#ifdef __linux__
printf("add connection hicn <symbolic> <remote_ip> <local_ip>\n");
+#endif
printf(
"add connection udp <symbolic> <remote_ip> <port> <local_ip> <port>\n");
printf(
@@ -268,6 +284,7 @@ static CommandReturn _controlAddConnection_IpHelp(CommandParser *parser,
return CommandReturn_Success;
}
+#ifdef __linux__
static CommandReturn _controlAddConnection_HicnHelpExecute(
CommandParser *parser, CommandOps *ops, PARCList *args) {
_controlAddConnection_IpHelp(parser, ops, args, "hicn");
@@ -303,6 +320,7 @@ static CommandReturn _controlAddConnection_HicnExecute(CommandParser *parser,
return _controlAddConnection_CreateTunnel(
parser, ops, local_ip, port, remote_ip, port, HICN_CONN, symbolic);
}
+#endif
static CommandReturn _controlAddConnection_UdpHelpExecute(CommandParser *parser,
CommandOps *ops,
diff --git a/hicn-light/src/hicn/config/controlAddListener.c b/hicn-light/src/hicn/config/controlAddListener.c
index c9253425a..cfd061131 100644
--- a/hicn-light/src/hicn/config/controlAddListener.c
+++ b/hicn-light/src/hicn/config/controlAddListener.c
@@ -58,27 +58,26 @@ 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");
#ifdef __linux__
+ printf(" add listener hicn <symbolic> <localAddress> \n");
+#endif
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 "
"alpha and be alphanum\n");
+#ifdef __linux__
printf(" protocol: hicn | udp\n");
+#else
+ printf(" protocol: udp\n");
+#endif
printf(
" localAddress: IPv4 or IPv6 address (or prefix protocol = hicn) "
"assigend to the local interface\n");
@@ -88,23 +87,18 @@ static CommandReturn _controlAddListener_HelpExecute(CommandParser *parser,
printf("\n");
printf("Notes:\n");
printf(" The symblic name must be unique or the source will reject it.\n");
+#ifdef __linux__
printf(
- " If protocol = hinc: the address 0::0 indicates the main listern, "
+ " If protocol = hicn: the address 0::0 indicates the main listern, "
"for which we can set punting rules.\n");
+#endif
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,
+ const char *port, char *interfaceName, listener_mode mode,
connection_type type) {
-#endif
ControlState *state = ops->closure;
// allocate command payload
@@ -126,9 +120,7 @@ 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));
@@ -149,11 +141,7 @@ 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;
}
@@ -169,45 +157,26 @@ static CommandReturn _controlAddListener_Execute(CommandParser *parser,
return result;
}
- const char *host = parcList_GetAtIndex(args, _indexAddress);
-#ifdef __linux__
- const char *interfaceName = parcList_GetAtIndex(args, _indexInterfaceName);
-#endif
const char *protocol = parcList_GetAtIndex(args, _indexProtocol);
-
+ const char *host = parcList_GetAtIndex(args, _indexAddress);
+ char *interfaceName = parcList_GetAtIndex(args, _indexInterfaceName);
if ((strcasecmp("hicn", protocol) == 0)) {
const char *port =
"1234"; // this is a random port number that will be ignored
// 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, "hicn", 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/config/controlListConnections.c b/hicn-light/src/hicn/config/controlListConnections.c
index dbd9707ca..c8a4c1b4b 100644
--- a/hicn-light/src/hicn/config/controlListConnections.c
+++ b/hicn-light/src/hicn/config/controlListConnections.c
@@ -120,6 +120,8 @@ static CommandReturn _controlListConnections_Execute(CommandParser *parser,
#endif /* WITH_POLICY */
// Process/Print payload
+
+ printf("%5s %10s %6s %40s %40s %5s\n", "id", "name", "state", "source", "destination", "type");
for (int i = 0; i < receivedHeader->length; i++) {
list_connections_command *listConnectionsCommand =
(list_connections_command *)(receivedPayload +
diff --git a/hicn-light/src/hicn/config/controlRemove.c b/hicn-light/src/hicn/config/controlRemove.c
index af833dc8b..ef0c15934 100644
--- a/hicn-light/src/hicn/config/controlRemove.c
+++ b/hicn-light/src/hicn/config/controlRemove.c
@@ -27,6 +27,7 @@
#include <parc/algol/parc_Memory.h>
#include <hicn/config/controlRemove.h>
+#include <hicn/config/controlRemoveListener.h>
#include <hicn/config/controlRemoveConnection.h>
#include <hicn/config/controlRemovePunting.h>
#include <hicn/config/controlRemoveRoute.h>
@@ -62,6 +63,7 @@ static CommandReturn _controlRemove_HelpExecute(CommandParser *parser,
CommandOps *ops,
PARCList *args) {
CommandOps *ops_remove_connection = controlRemoveConnection_Create(NULL);
+ CommandOps *ops_remove_listener = controlRemoveListener_Create(NULL);
CommandOps *ops_remove_route = controlRemoveRoute_Create(NULL);
CommandOps *ops_remove_punting = controlRemovePunting_Create(NULL);
#ifdef WITH_POLICY
@@ -70,6 +72,7 @@ static CommandReturn _controlRemove_HelpExecute(CommandParser *parser,
printf("Available commands:\n");
printf(" %s\n", ops_remove_connection->command);
+ printf(" %s\n", ops_remove_listener->command);
printf(" %s\n", ops_remove_route->command);
printf(" %s\n", ops_remove_punting->command);
#ifdef WITH_POLICY
@@ -78,6 +81,7 @@ static CommandReturn _controlRemove_HelpExecute(CommandParser *parser,
printf("\n");
commandOps_Destroy(&ops_remove_connection);
+ commandOps_Destroy(&ops_remove_listener);
commandOps_Destroy(&ops_remove_route);
commandOps_Destroy(&ops_remove_punting);
#ifdef WITH_POLICY
@@ -90,8 +94,11 @@ static void _controlRemove_Init(CommandParser *parser, CommandOps *ops) {
ControlState *state = ops->closure;
controlState_RegisterCommand(state,
controlRemoveConnection_HelpCreate(state));
+ controlState_RegisterCommand(state,
+ controlRemoveListener_HelpCreate(state));
controlState_RegisterCommand(state, controlRemoveRoute_HelpCreate(state));
controlState_RegisterCommand(state, controlRemoveConnection_Create(state));
+ controlState_RegisterCommand(state, controlRemoveListener_Create(state));
controlState_RegisterCommand(state, controlRemoveRoute_Create(state));
controlState_RegisterCommand(state, controlRemovePunting_Create(state));
controlState_RegisterCommand(state, controlRemovePunting_HelpCreate(state));
diff --git a/hicn-light/src/hicn/config/controlRemoveListener.c b/hicn-light/src/hicn/config/controlRemoveListener.c
new file mode 100644
index 000000000..50581a8d9
--- /dev/null
+++ b/hicn-light/src/hicn/config/controlRemoveListener.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hicn/hicn-light/config.h>
+
+#include <ctype.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <parc/assert/parc_Assert.h>
+
+#include <parc/algol/parc_Memory.h>
+#include <parc/algol/parc_Network.h>
+#include <hicn/utils/address.h>
+
+#include <hicn/config/controlRemoveListener.h>
+
+#include <hicn/utils/commands.h>
+#include <hicn/utils/utils.h>
+
+static CommandReturn _controlRemoveListener_Execute(CommandParser *parser,
+ CommandOps *ops,
+ PARCList *args);
+static CommandReturn _controlRemoveListener_HelpExecute(CommandParser *parser,
+ CommandOps *ops,
+ PARCList *args);
+
+// ===================================================
+
+static const char *_commandRemoveListener = "remove listener";
+static const char *_commandRemoveListenerHelp = "help remove listener";
+
+// ====================================================
+
+CommandOps *controlRemoveListener_Create(ControlState *state) {
+ return commandOps_Create(state, _commandRemoveListener, NULL,
+ _controlRemoveListener_Execute,
+ commandOps_Destroy);
+}
+
+CommandOps *controlRemoveListener_HelpCreate(ControlState *state) {
+ return commandOps_Create(state, _commandRemoveListenerHelp, NULL,
+ _controlRemoveListener_HelpExecute,
+ commandOps_Destroy);
+}
+
+// ====================================================
+
+static CommandReturn _controlRemoveListener_HelpExecute(CommandParser *parser,
+ CommandOps *ops,
+ PARCList *args) {
+ printf("command:\n");
+ printf(" remove listener <symbolic|id>\n");
+ return CommandReturn_Success;
+}
+
+static CommandReturn _controlRemoveListener_Execute(CommandParser *parser,
+ CommandOps *ops,
+ PARCList *args) {
+ ControlState *state = ops->closure;
+
+ if (parcList_Size(args) != 3) {
+ _controlRemoveListener_HelpExecute(parser, ops, args);
+ return false;
+ }
+
+ if ((strcmp(parcList_GetAtIndex(args, 0), "remove") != 0) ||
+ (strcmp(parcList_GetAtIndex(args, 1), "listener") != 0)) {
+ _controlRemoveListener_HelpExecute(parser, ops, args);
+ return false;
+ }
+
+ const char *listenerId = parcList_GetAtIndex(args, 2);
+
+if (!utils_ValidateSymbolicName(listenerId) &&
+ !utils_IsNumber(listenerId)) {
+ printf(
+ "ERROR: Invalid symbolic or listenerId:\nsymbolic name must begin with an "
+ "alpha followed by alphanum;\nlistenerId must be an integer\n");
+ return CommandReturn_Failure;
+ }
+
+ // allocate command payload
+ remove_listener_command *removeListenerCommand =
+ parcMemory_AllocateAndClear(sizeof(remove_listener_command));
+ // fill payload
+ //removeListenerCommand->listenerId = atoi(listenerId);
+ strncpy(removeListenerCommand->symbolicOrListenerid, listenerId, strlen(listenerId));
+
+ // send message and receive response
+ struct iovec *response =
+ utils_SendRequest(state, REMOVE_LISTENER, removeListenerCommand,
+ sizeof(remove_listener_command));
+
+ if (!response) { // get NULL pointer
+ return CommandReturn_Failure;
+ }
+
+ parcMemory_Deallocate(&response); // free iovec pointer
+ return CommandReturn_Success;
+}
diff --git a/hicn-light/src/hicn/config/controlRemoveListener.h b/hicn-light/src/hicn/config/controlRemoveListener.h
new file mode 100644
index 000000000..794d1e1a9
--- /dev/null
+++ b/hicn-light/src/hicn/config/controlRemoveListener.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file control_RemoveConnection.h
+ * @brief Remove a connection from the connection table
+ *
+ * Implements the "remove connection" and "help remove connection" nodes of the
+ * CLI tree
+ *
+ */
+
+#ifndef Control_RemoveListener_h
+#define Control_RemoveListener_h
+
+#include <hicn/config/controlState.h>
+CommandOps *controlRemoveListener_Create(ControlState *state);
+CommandOps *controlRemoveListener_HelpCreate(ControlState *state);
+#endif // Control_RemoveListener_h