summaryrefslogtreecommitdiffstats
path: root/ctrl/libhicnctrl
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
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')
-rw-r--r--ctrl/libhicnctrl/includes/hicn/ctrl/api.h4
-rw-r--r--[-rwxr-xr-x]ctrl/libhicnctrl/includes/hicn/ctrl/commands.h79
-rw-r--r--ctrl/libhicnctrl/src/api.c30
-rw-r--r--ctrl/libhicnctrl/src/cli.c347
4 files changed, 337 insertions, 123 deletions
diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h
index 62cf98927..7b57a6323 100644
--- a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h
+++ b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h
@@ -69,6 +69,7 @@
#include <stdint.h>
#include <hicn/util/ip_address.h>
+#include <hicn/ctrl/commands.h>
#include "face.h"
#define HICN_DEFAULT_PORT 9695
@@ -380,8 +381,7 @@ int hc_sock_reset(hc_sock_t * s);
#define NULLTERM 1
#endif
-#define SYMBOLIC_NAME_LEN 16 /* NULL-terminated right ? */
-#define INTERFACE_LEN 16
+#define INTERFACE_LEN IFNAMSIZ
#define MAXSZ_HC_NAME_ SYMBOLIC_NAME_LEN
#define MAXSZ_HC_NAME MAXSZ_HC_NAME_ + NULLTERM
diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h b/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h
index e69c93932..a5bc15e8a 100755..100644
--- a/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h
+++ b/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h
@@ -31,18 +31,16 @@
#include <stdint.h>
#include <stdlib.h>
+#include <hicn/util/ip_address.h>
#ifdef WITH_POLICY
#include <hicn/policy.h>
#endif /* WITH_POLICY */
+#define SYMBOLIC_NAME_LEN 16
+
typedef struct in6_addr ipv6_addr_t;
typedef uint32_t ipv4_addr_t;
-union commandAddr {
- ipv4_addr_t ipv4;
- ipv6_addr_t ipv6;
-};
-
typedef enum {
REQUEST_LIGHT = 0xc0, // this is a command
RESPONSE_LIGHT,
@@ -115,9 +113,9 @@ typedef struct {
typedef enum { ETHER_MODE, IP_MODE, HICN_MODE } listener_mode;
typedef struct {
- char symbolic[16];
- char interfaceName[16];
- union commandAddr address;
+ char symbolic[SYMBOLIC_NAME_LEN];
+ char interfaceName[SYMBOLIC_NAME_LEN];
+ ip_address_t address;
uint16_t port;
// uint16_t etherType;
uint8_t addressType;
@@ -125,15 +123,15 @@ typedef struct {
uint8_t connectionType;
} add_listener_command;
-// SIZE=40
+// SIZE=56
//========== [01] ADD CONNECTION ==========
typedef struct {
- char symbolic[16];
- //char interfaceName[16];
- union commandAddr remoteIp;
- union commandAddr localIp;
+ char symbolic[SYMBOLIC_NAME_LEN];
+ //char interfaceName[SYMBOLIC_NAME_LEN];
+ ip_address_t remoteIp;
+ ip_address_t localIp;
uint16_t remotePort;
uint16_t localPort;
uint8_t ipType;
@@ -168,17 +166,17 @@ typedef struct {
uint32_t connid;
uint8_t state;
uint8_t admin_state;
- char interfaceName[16];
- char connectionName[16];
+ char interfaceName[SYMBOLIC_NAME_LEN];
+ char connectionName[SYMBOLIC_NAME_LEN];
} list_connections_command;
-// SIZE=64
+// SIZE=80
//========== [03] ADD ROUTE ==========
typedef struct {
- char symbolicOrConnid[16];
- union commandAddr address;
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+ ip_address_t address;
uint16_t cost;
uint8_t addressType;
uint8_t len;
@@ -189,7 +187,7 @@ typedef struct {
//========== [04] LIST ROUTE ==========
typedef struct {
- union commandAddr address;
+ ip_address_t address;
uint32_t connid;
uint16_t cost;
uint8_t addressType;
@@ -199,30 +197,29 @@ typedef struct {
// SIZE=24
//========== [05] REMOVE CONNECTION ==========
-
typedef struct {
- char symbolicOrConnid[16];
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
} remove_connection_command;
//========== [06] REMOVE LISTENER ==========
typedef struct {
- char symbolicOrListenerid[16];
+ char symbolicOrListenerid[SYMBOLIC_NAME_LEN];
} remove_listener_command;
// SIZE=16
-//========== [06] REMOVE ROUTE ==========
+//========== [07] REMOVE ROUTE ==========
typedef struct {
- char symbolicOrConnid[16];
- union commandAddr address;
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+ ip_address_t address;
uint8_t addressType;
uint8_t len;
} remove_route_command;
// SIZE=36
-//========== [07] CACHE STORE ==========
+//========== [08] CACHE STORE ==========
typedef struct {
uint8_t activate;
@@ -230,7 +227,7 @@ typedef struct {
// SIZE=1
-//========== [08] CACHE SERVE ==========
+//========== [09] CACHE SERVE ==========
typedef struct {
uint8_t activate;
@@ -238,20 +235,18 @@ typedef struct {
// SIZE=1
-//========== [09] SET STRATEGY ==========
+//========== [10] SET STRATEGY ==========
typedef enum {
SET_STRATEGY_LOADBALANCER,
SET_STRATEGY_RANDOM,
SET_STRATEGY_RANDOM_PER_DASH_SEGMENT,
SET_STRATEGY_LOADBALANCER_WITH_DELAY,
- SET_STRATEGY_LOADBALANCER_BY_RATE,
- SET_STRATEGY_LOADBALANCER_BEST_ROUTE,
LAST_STRATEGY_VALUE
} strategy_type;
typedef struct {
- union commandAddr address;
+ ip_address_t address;
uint8_t strategyType;
uint8_t addressType;
uint8_t len;
@@ -262,7 +257,7 @@ typedef struct {
//========== [11] SET WLDR ==========
typedef struct {
- char symbolicOrConnid[16];
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
uint8_t activate;
} set_wldr_command;
@@ -271,8 +266,8 @@ typedef struct {
//========== [12] ADD PUNTING ==========
typedef struct {
- char symbolicOrConnid[16];
- union commandAddr address;
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+ ip_address_t address;
uint8_t addressType;
uint8_t len;
} add_punting_command;
@@ -282,9 +277,9 @@ typedef struct {
//========== [13] LIST LISTENER ==========
typedef struct {
- union commandAddr address;
- char listenerName[16];
- char interfaceName[16];
+ ip_address_t address;
+ char listenerName[SYMBOLIC_NAME_LEN];
+ char interfaceName[SYMBOLIC_NAME_LEN];
uint32_t connid;
uint16_t port;
uint8_t addressType;
@@ -310,7 +305,7 @@ typedef struct {
// SIZE=1
typedef struct {
- char symbolicOrConnid[16];
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
uint8_t admin_state;
uint8_t pad8[3];
} connection_set_admin_state_command;
@@ -318,27 +313,27 @@ typedef struct {
#ifdef WITH_POLICY
typedef struct {
- union commandAddr address;
+ ip_address_t address;
uint8_t addressType;
uint8_t len;
policy_t policy;
} add_policy_command;
typedef struct {
- union commandAddr address;
+ ip_address_t address;
uint8_t addressType;
uint8_t len;
policy_t policy;
} list_policies_command;
typedef struct {
- union commandAddr address;
+ ip_address_t address;
uint8_t addressType;
uint8_t len;
} remove_policy_command;
typedef struct {
- char symbolicOrConnid[16];
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
uint8_t admin_state;
policy_tags_t tags;
} update_connection_command;
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);