summaryrefslogtreecommitdiffstats
path: root/ctrl/libhicnctrl/src
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2019-11-07 16:42:01 +0100
committerJordan Augé <jordan.auge+fdio@cisco.com>2019-11-08 01:36:45 +0100
commit1bf749aa3e4b0ccc40057b2587af5211926a1431 (patch)
tree1e59105d64e7dc13f4f1cd4ae8437bb8bb932292 /ctrl/libhicnctrl/src
parenta30d495f6e91f3bed0420bf76c19315fe0de8801 (diff)
[HICN-385] fix route removal in hicnctrl, code uniformization in hicn-light control api
Change-Id: Id097368dcde993775f206623195cc5aa57b4fe12 Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Diffstat (limited to 'ctrl/libhicnctrl/src')
-rw-r--r--ctrl/libhicnctrl/src/api.c30
-rw-r--r--ctrl/libhicnctrl/src/cli.c347
2 files changed, 298 insertions, 79 deletions
diff --git a/ctrl/libhicnctrl/src/api.c b/ctrl/libhicnctrl/src/api.c
index 783245e8a..2955e2e71 100644
--- a/ctrl/libhicnctrl/src/api.c
+++ b/ctrl/libhicnctrl/src/api.c
@@ -906,9 +906,7 @@ _hc_listener_create(hc_sock_t * s, hc_listener_t * listener, bool async)
.seqNum = 0,
},
.payload = {
- .address = {
- .ipv6 = listener->local_addr.v6.as_in6addr,
- },
+ .address = listener->local_addr,
.port = htons(listener->local_port),
.addressType = (u8)map_to_addr_type[listener->family],
.listenerMode = (u8)map_to_listener_mode[listener->type],
@@ -1174,9 +1172,8 @@ _hc_connection_create(hc_sock_t * s, hc_connection_t * connection, bool async)
.seqNum = 0,
},
.payload = {
- /* we use IPv6 which is the longest address */
- .remoteIp.ipv6 = connection->remote_addr.v6.as_in6addr,
- .localIp.ipv6 = connection->local_addr.v6.as_in6addr,
+ .remoteIp = connection->remote_addr,
+ .localIp = connection->local_addr,
.remotePort = htons(connection->remote_port),
.localPort = htons(connection->local_port),
.ipType = (u8)map_to_addr_type[connection->family],
@@ -1405,9 +1402,11 @@ hc_connection_parse(void * in, hc_connection_t * connection)
.id = cmd->connid,
.type = type,
.family = family,
- .local_addr = UNION_CAST(cmd->connectionData.localIp, ip_address_t),
+ .local_addr = cmd->connectionData.localIp,
+ //.local_addr = UNION_CAST(cmd->connectionData.localIp, ip_address_t),
.local_port = ntohs(cmd->connectionData.localPort),
- .remote_addr = UNION_CAST(cmd->connectionData.remoteIp, ip_address_t),
+ .remote_addr = cmd->connectionData.remoteIp,
+ //.remote_addr = UNION_CAST(cmd->connectionData.remoteIp, ip_address_t),
.remote_port = ntohs(cmd->connectionData.remotePort),
.admin_state = cmd->connectionData.admin_state,
#ifdef WITH_POLICY
@@ -1521,8 +1520,7 @@ _hc_route_create(hc_sock_t * s, hc_route_t * route, bool async)
.seqNum = 0,
},
.payload = {
- /* we use IPv6 which is the longest address */
- .address.ipv6 = route->remote_addr.v6.as_in6addr,
+ .address = route->remote_addr,
.cost = route->cost,
.addressType = (u8)map_to_addr_type[route->family],
.len = route->len,
@@ -1577,8 +1575,7 @@ _hc_route_delete(hc_sock_t * s, hc_route_t * route, bool async)
.seqNum = 0,
},
.payload = {
- /* we use IPv6 which is the longest address */
- .address.ipv6 = route->remote_addr.v6.as_in6addr,
+ .address = route->remote_addr,
.addressType = (u8)map_to_addr_type[route->family],
.len = route->len,
}
@@ -2286,8 +2283,7 @@ _hc_punting_create(hc_sock_t * s, hc_punting_t * punting, bool async)
.seqNum = 0,
},
.payload = {
- /* we use IPv6 which is the longest address */
- .address.ipv6 = punting->prefix.v6.as_in6addr,
+ .address = punting->prefix,
.addressType = (u8)map_to_addr_type[punting->family],
.len = punting->prefix_len,
}
@@ -2567,8 +2563,7 @@ _hc_policy_create(hc_sock_t * s, hc_policy_t * policy, bool async)
.seqNum = 0,
},
.payload = {
- /* we use IPv6 which is the longest address */
- .address.ipv6 = policy->remote_addr.v6.as_in6addr,
+ .address = policy->remote_addr,
.addressType = (u8)map_to_addr_type[policy->family],
.len = policy->len,
.policy = policy->policy,
@@ -2617,8 +2612,7 @@ _hc_policy_delete(hc_sock_t * s, hc_policy_t * policy, bool async)
.seqNum = 0,
},
.payload = {
- /* we use IPv6 which is the longest address */
- .address.ipv6 = policy->remote_addr.v6.as_in6addr,
+ .address = policy->remote_addr,
.addressType = (u8)map_to_addr_type[policy->family],
.len = policy->len,
}
diff --git a/ctrl/libhicnctrl/src/cli.c b/ctrl/libhicnctrl/src/cli.c
index 81400f8ee..a171f7045 100644
--- a/ctrl/libhicnctrl/src/cli.c
+++ b/ctrl/libhicnctrl/src/cli.c
@@ -48,41 +48,217 @@ foreach_object
#undef _
} hc_object_t;
+void
+usage_header()
+{
+ fprintf(stderr, "Usage:\n");
+}
+
+void
+usage_face_create(const char * prog, bool header, bool verbose)
+{
+
+ if (header)
+ usage_header();
+ fprintf(stderr, "%s -f TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", prog);
+ if (verbose)
+ fprintf(stderr, " Create a face on specified address and port.\n");
+}
+
+void
+usage_face_delete(const char * prog, bool header, bool verbose)
+{
+ if (header)
+ usage_header();
+ fprintf(stderr, "%s -df ID\n", prog);
+ //fprintf(stderr, "%s -df NAME\n", prog);
+ fprintf(stderr, "%s -df TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", prog);
+ if (verbose)
+ fprintf(stderr, " Delete a face...\n");
+}
+
+void
+usage_face_list(const char * prog, bool header, bool verbose)
+{
+ if (header)
+ usage_header();
+ fprintf(stderr, "%s -F\n", prog);
+ if (verbose)
+ fprintf(stderr, " List all faces.\n");
+}
+
+void
+usage_face(const char * prog, bool header, bool verbose)
+{
+ usage_face_create(prog, header, verbose);
+ usage_face_delete(prog, header, verbose);
+ usage_face_list(prog, header, verbose);
+}
+
+void
+usage_route_create(const char * prog, bool header, bool verbose)
+{
+ if (header)
+ usage_header();
+ fprintf(stderr, "%s -r FACE_ID PREFIX [COST]\n", prog);
+ //fprintf(stderr, "%s -r [FACE_ID|NAME] PREFIX [COST]\n", prog);
+ if (verbose)
+ fprintf(stderr, " Create a route...\n");
+}
+
+void
+usage_route_delete(const char * prog, bool header, bool verbose)
+{
+ if (header)
+ usage_header();
+ fprintf(stderr, "%s -dr FACE_ID PREFIX\n", prog);
+ //fprintf(stderr, "%s -dr [FACE_ID|NAME] PREFIX\n", prog);
+ if (verbose)
+ fprintf(stderr, " Delete a route...\n");
+}
+
+void
+usage_route_list(const char * prog, bool header, bool verbose)
+{
+ if (header)
+ usage_header();
+ fprintf(stderr, "%s -R\n", prog);
+ if (verbose)
+ fprintf(stderr, " List all routes.\n");
+}
+
+void
+usage_route(const char * prog, bool header, bool verbose)
+{
+ usage_route_create(prog, header, verbose);
+ usage_route_delete(prog, header, verbose);
+ usage_route_list(prog, header, verbose);
+}
+
+void
+usage_forwarding_strategy_create(const char * prog, bool header, bool verbose)
+{
+ if (header)
+ usage_header();
+}
+void
+usage_forwarding_strategy_delete(const char * prog, bool header, bool verbose)
+{
+ if (header)
+ usage_header();
+}
+
+void
+usage_forwarding_strategy_list(const char * prog, bool header, bool verbose)
+{
+ if (header)
+ usage_header();
+ fprintf(stderr, "%s -S\n", prog);
+ if (verbose)
+ fprintf(stderr, " List all availble forwarding strategies.\n");
+}
+
+void
+usage_forwarding_strategy(const char * prog, bool header, bool verbose)
+{
+ usage_forwarding_strategy_create(prog, header, verbose);
+ usage_forwarding_strategy_delete(prog, header, verbose);
+ usage_forwarding_strategy_list(prog, header, verbose);
+}
+
+void
+usage_listener_create(const char * prog, bool header, bool verbose)
+{
+ if (header)
+ usage_header();
+ fprintf(stderr, "%s -l NAME TYPE LOCAL_ADDRESS LOCAL_PORT [INTERFACE_NAME]\n", prog);
+ if (verbose)
+ fprintf(stderr, " Create a listener on specified address and port.\n");
+}
+
+void
+usage_listener_delete(const char * prog, bool header, bool verbose)
+{
+ if (header)
+ usage_header();
+ fprintf(stderr, "%s -dl ID\n", prog);
+ fprintf(stderr, "%s -dl NAME\n", prog);
+ fprintf(stderr, "%s -dl TYPE LOCAL_ADDRESS LOCAL_PORT [INTERFACE_NAME]\n", prog);
+ if (verbose)
+ fprintf(stderr, " Delete a listener...\n");
+}
+
+void
+usage_listener_list(const char * prog, bool header, bool verbose)
+{
+ if (header)
+ usage_header();
+ fprintf(stderr, "%s -L\n", prog);
+ if (verbose)
+ fprintf(stderr, " List all listeners.\n");
+}
+
+void
+usage_listener(const char * prog, bool header, bool verbose)
+{
+ usage_listener_create(prog, header, verbose);
+ usage_listener_delete(prog, header, verbose);
+ usage_listener_list(prog, header, verbose);
+}
+void
+usage_connection_create(const char * prog, bool header, bool verbose)
+{
+ if (header)
+ usage_header();
+ fprintf(stderr, "%s -c NAME TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", prog);
+ if (verbose)
+ fprintf(stderr, " Create a connection on specified address and port.\n");
+}
+
+void
+usage_connection_delete(const char * prog, bool header, bool verbose)
+{
+ if (header)
+ usage_header();
+ fprintf(stderr, "%s -dc ID\n", prog);
+ fprintf(stderr, "%s -dc NAME\n", prog);
+ fprintf(stderr, "%s -dc TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", prog);
+ if (verbose)
+ fprintf(stderr, " Delete a connection...\n");
+}
+
+void
+usage_connection_list(const char * prog, bool header, bool verbose)
+{
+ if (header)
+ usage_header();
+ fprintf(stderr, "%s -C\n", prog);
+ if (verbose)
+ fprintf(stderr, " List all connections.\n");
+}
+
+void
+usage_connection(const char * prog, bool header, bool verbose)
+{
+ usage_connection_create(prog, header, verbose);
+ usage_connection_delete(prog, header, verbose);
+ usage_connection_list(prog, header, verbose);
+}
+
void usage(const char * prog)
{
fprintf(stderr, "Usage: %s [ [-d] [-f|-l|-c|-r] PARAMETERS | [-F|-L|-C|-R] ]\n", prog);
fprintf(stderr, "\n");
fprintf(stderr, "High-level commands\n");
fprintf(stderr, "\n");
- fprintf(stderr, "%s -f <NAME> <TYPE> <LOCAL_ADDRESS> <LOCAL_PORT> <REMOTE_ADDRESS> <REMOTE_PORT>\n", prog);
- fprintf(stderr, " Create a face on specified address and port.\n");
- fprintf(stderr, "%s -fc ...\n", prog);
- fprintf(stderr, " Delete a face...\n");
- fprintf(stderr, "%s -F\n", prog);
- fprintf(stderr, " List all faces.\n");
- fprintf(stderr, "%s -r ...>\n", prog);
- fprintf(stderr, " Create a route...\n");
- fprintf(stderr, "%s -dr ...\n", prog);
- fprintf(stderr, " Delete a route...\n");
- fprintf(stderr, "%s -R\n", prog);
- fprintf(stderr, " List all routes.\n");
- fprintf(stderr, "%s -S\n", prog);
- fprintf(stderr, " List all availble forwarding strategies.\n");
+ usage_face(prog, false, true);
+ usage_route(prog, false, true);
+ usage_forwarding_strategy(prog, false, true);
fprintf(stderr, "\n");
fprintf(stderr, "Low level commands (hicn-light specific)\n");
fprintf(stderr, "\n");
- fprintf(stderr, "%s -l <NAME> <TYPE> <ADDRESS> <PORT> <INTERFACE_NAME>\n", prog);
- fprintf(stderr, " Create a listener on specified address and port.\n");
- fprintf(stderr, "%s -dl ...\n", prog);
- fprintf(stderr, " Delete a listener...\n");
- fprintf(stderr, "%s -L\n", prog);
- fprintf(stderr, " List all listeners.\n");
- fprintf(stderr, "%s -c <NAME> <TYPE> <LOCAL_ADDRESS> <LOCAL_PORT> <REMOTE_ADDRESS> <REMOTE_PORT>\n", prog);
- fprintf(stderr, " Create a connection on specified address and port.\n");
- fprintf(stderr, "%s -dc ...\n", prog);
- fprintf(stderr, " Delete a connection...\n");
- fprintf(stderr, "%s -C\n", prog);
- fprintf(stderr, " List all connections.\n");
+ usage_listener(prog, false, true);
+ usage_connection(prog, false, true);
}
typedef struct {
@@ -147,7 +323,6 @@ parse_options(int argc, char *argv[], hc_command_t * command)
{
command->object = OBJECT_UNDEFINED;
command->action = ACTION_CREATE;
- int nargs = -1; /* unset */
int opt;
int family;
@@ -167,32 +342,26 @@ parse_options(int argc, char *argv[], hc_command_t * command)
break;
case 'r':
command->object = OBJECT_ROUTE;
- nargs = 0; // XXX
break;
case 'F':
command->action = ACTION_LIST;
command->object = OBJECT_FACE;
- nargs = 0;
break;
case 'L':
command->action = ACTION_LIST;
command->object = OBJECT_LISTENER;
- nargs = 0;
break;
case 'C':
command->action = ACTION_LIST;
command->object = OBJECT_CONNECTION;
- nargs = 0;
break;
case 'R':
command->action = ACTION_LIST;
command->object = OBJECT_ROUTE;
- nargs = 0;
break;
case 'S':
command->action = ACTION_LIST;
command->object = OBJECT_STRATEGY;
- nargs = 0;
break;
default: /* "h" */
usage(argv[0]);
@@ -205,17 +374,13 @@ parse_options(int argc, char *argv[], hc_command_t * command)
return -1;
}
- if (nargs == 0)
- return 0;
-
/* Parse and validate parameters for add/delete */
switch(command->object) {
case OBJECT_FACE:
switch(command->action) {
case ACTION_CREATE:
if ((argc - optind != 6) && (argc - optind != 7)) {
- fprintf(stderr, "Usage:\n");
- fprintf(stderr, "%s -f TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", argv[0]);
+ usage_face_create(argv[0], true, false);
goto ERR_PARAM;
}
/* NAME will be autogenerated (and currently not used) */
@@ -242,10 +407,7 @@ parse_options(int argc, char *argv[], hc_command_t * command)
break;
case ACTION_DELETE:
if ((argc - optind != 1) && (argc - optind != 5) && (argc - optind != 6)) {
- fprintf(stderr, "Usage:\n");
- fprintf(stderr, "%s -ld ID\n", argv[0]);
- //fprintf(stderr, "%s -ld NAME\n", argv[0]);
- fprintf(stderr, "%s -ld TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", argv[0]);
+ usage_face_delete(argv[0], true, false);
goto ERR_PARAM;
}
@@ -281,6 +443,14 @@ parse_options(int argc, char *argv[], hc_command_t * command)
}
}
break;
+
+ case ACTION_LIST:
+ if (argc - optind != 0) {
+ usage_face_list(argv[0], true, false);
+ goto ERR_PARAM;
+ }
+ break;
+
default:
goto ERR_COMMAND;
break;
@@ -290,11 +460,51 @@ parse_options(int argc, char *argv[], hc_command_t * command)
case OBJECT_ROUTE:
switch(command->action) {
case ACTION_CREATE:
- goto ERR_COMMAND;
+ if ((argc - optind != 2) && (argc - optind != 3)) {
+ usage_route_create(argv[0], true, false);
+ goto ERR_PARAM;
+ }
+
+ command->route.face_id = atoi(argv[optind++]);
+
+ {
+ ip_prefix_t prefix;
+ ip_prefix_pton(argv[optind++], &prefix);
+ command->route.family = prefix.family;
+ command->route.remote_addr = prefix.address;
+ command->route.len = prefix.len;
+ }
+
+ if (argc != optind) {
+ printf("parse cost\n");
+ command->route.cost = atoi(argv[optind++]);
+ }
break;
+
case ACTION_DELETE:
- goto ERR_COMMAND;
+ if (argc - optind != 2) {
+ usage_route_delete(argv[0], true, false);
+ goto ERR_PARAM;
+ }
+
+ command->route.face_id = atoi(argv[optind++]);
+
+ {
+ ip_prefix_t prefix;
+ ip_prefix_pton(argv[optind++], &prefix);
+ command->route.family = prefix.family;
+ command->route.remote_addr = prefix.address;
+ command->route.len = prefix.len;
+ }
break;
+
+ case ACTION_LIST:
+ if (argc - optind != 0) {
+ usage_route_list(argv[0], true, false);
+ goto ERR_PARAM;
+ }
+ break;
+
default:
goto ERR_COMMAND;
break;
@@ -304,6 +514,10 @@ parse_options(int argc, char *argv[], hc_command_t * command)
case OBJECT_STRATEGY:
switch(command->action) {
case ACTION_LIST:
+ if (argc - optind != 0) {
+ usage_forwarding_strategy_list(argv[0], true, false);
+ goto ERR_PARAM;
+ }
break;
default:
goto ERR_COMMAND;
@@ -315,8 +529,7 @@ parse_options(int argc, char *argv[], hc_command_t * command)
switch(command->action) {
case ACTION_CREATE:
if ((argc - optind != 4) && (argc - optind != 5)) {
- fprintf(stderr, "Usage:\n");
- fprintf(stderr, "%s -l NAME TYPE LOCAL_ADDRESS LOCAL_PORT [INTERFACE_NAME]\n", argv[0]);
+ usage_listener_create(argv[0], true, false);
goto ERR_PARAM;
}
snprintf(command->listener.name, SYMBOLIC_NAME_LEN, "%s", argv[optind++]);
@@ -336,10 +549,7 @@ parse_options(int argc, char *argv[], hc_command_t * command)
case ACTION_DELETE:
if ((argc - optind != 1) && (argc - optind != 3) && (argc - optind != 4)) {
- fprintf(stderr, "Usage:\n");
- fprintf(stderr, "%s -ld ID\n", argv[0]);
- fprintf(stderr, "%s -ld NAME\n", argv[0]);
- fprintf(stderr, "%s -ld TYPE LOCAL_ADDRESS LOCAL_PORT [INTERFACE_NAME]\n", argv[0]);
+ usage_listener_delete(argv[0], true, false);
goto ERR_PARAM;
}
@@ -370,6 +580,13 @@ parse_options(int argc, char *argv[], hc_command_t * command)
}
break;
+ case ACTION_LIST:
+ if (argc - optind != 0) {
+ usage_listener_list(argv[0], true, false);
+ goto ERR_PARAM;
+ }
+ break;
+
default:
goto ERR_COMMAND;
break;
@@ -381,8 +598,7 @@ parse_options(int argc, char *argv[], hc_command_t * command)
case ACTION_CREATE:
/* NAME TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT */
if ((argc - optind != 6) && (argc - optind != 7)) {
- fprintf(stderr, "Usage:\n");
- fprintf(stderr, "%s -c NAME TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", argv[0]);
+ usage_connection_create(argv[0], true, false);
goto ERR_PARAM;
}
snprintf(command->connection.name, SYMBOLIC_NAME_LEN, "%s", argv[optind++]);
@@ -403,12 +619,10 @@ parse_options(int argc, char *argv[], hc_command_t * command)
command->connection.remote_port = atoi(argv[optind++]);
break;
+
case ACTION_DELETE:
if ((argc - optind != 1) && (argc - optind != 5) && (argc - optind != 6)) {
- fprintf(stderr, "Usage:\n");
- fprintf(stderr, "%s -ld ID\n", argv[0]);
- fprintf(stderr, "%s -ld NAME\n", argv[0]);
- fprintf(stderr, "%s -ld TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", argv[0]);
+ usage_connection_delete(argv[0], true, false);
goto ERR_PARAM;
}
@@ -441,6 +655,14 @@ parse_options(int argc, char *argv[], hc_command_t * command)
command->connection.remote_port = atoi(argv[optind++]);
}
break;
+
+ case ACTION_LIST:
+ if (argc - optind != 0) {
+ usage_connection_list(argv[0], true, false);
+ goto ERR_PARAM;
+ }
+ break;
+
default:
goto ERR_COMMAND;
break;
@@ -516,11 +738,17 @@ int main(int argc, char *argv[])
case OBJECT_ROUTE:
switch(command.action) {
case ACTION_CREATE:
- die(COMMAND, "Not implemented.");
+ if (hc_route_create(s, &command.route) < 0)
+ die(COMMAND, "Error creating route");
+ printf("OK\n");
break;
+
case ACTION_DELETE:
- die(COMMAND, "Not implemented.");
+ if (hc_route_delete(s, &command.route) < 0)
+ die(COMMAND, "Error creating route");
+ printf("OK\n");
break;
+
case ACTION_LIST:
if (hc_route_list(s, &data) < 0)
die(COMMAND, "Error getting routes.");
@@ -629,9 +857,6 @@ int main(int argc, char *argv[])
break;
}
-
- /* ROUTES */
-
ERR_COMMAND:
ERR_CONNECT:
hc_sock_free(s);