diff options
Diffstat (limited to 'ctrl/libhicnctrl')
-rw-r--r-- | ctrl/libhicnctrl/examples/create_face.c | 3 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl/api.h | 5 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl/commands.h | 13 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl/face.h | 1 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl/route.h | 1 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/api.c | 85 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/cli.c | 2 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/face.c | 1 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/route.c | 10 |
9 files changed, 110 insertions, 11 deletions
diff --git a/ctrl/libhicnctrl/examples/create_face.c b/ctrl/libhicnctrl/examples/create_face.c index dcacaeff1..5f92f5906 100644 --- a/ctrl/libhicnctrl/examples/create_face.c +++ b/ctrl/libhicnctrl/examples/create_face.c @@ -107,7 +107,10 @@ int main() { .remote_port = 6000, .admin_state = FACE_STATE_UNDEFINED, .state = FACE_STATE_UNDEFINED, +#ifdef WITH_POLICY + .priority = 0, .tags = POLICY_TAGS_EMPTY, +#endif /* WITH_POLICY */ }, }; if (netdevice_set_name(&face.face.netdevice, if_name) < 0) { diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h index b3032d0f3..c9c2f0da8 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h @@ -498,6 +498,7 @@ typedef struct { u16 remote_port; /* .rw */ hc_connection_state_t admin_state; /* .rw */ #ifdef WITH_POLICY + uint32_t priority; /* .rw */ policy_tags_t tags; /* .rw */ #endif /* WITH_POLICY */ hc_connection_state_t state; /* .r. */ @@ -523,8 +524,9 @@ int hc_connection_validate(const hc_connection_t * connection); int hc_connection_cmp(const hc_connection_t * c1, const hc_connection_t * c2); int hc_connection_parse(void * in, hc_connection_t * connection); -#ifdef WITH_POLICY int hc_connection_set_admin_state(hc_sock_t * s, const char * conn_id_or_name, face_state_t state); +#ifdef WITH_POLICY +int hc_connection_set_priority(hc_sock_t * s, const char * conn_id_or_name, uint32_t priority); #endif /* WITH_POLICY */ #define foreach_connection(VAR, data) foreach_type(hc_connection_t, VAR, data) @@ -599,6 +601,7 @@ int hc_route_parse(void * in, hc_route_t * route); int hc_route_create(hc_sock_t * s, hc_route_t * route); int hc_route_delete(hc_sock_t * s, hc_route_t * route); int hc_route_list(hc_sock_t * s, hc_data_t ** pdata); +int hc_route_list_async(hc_sock_t * s); #define foreach_route(VAR, data) foreach_type(hc_route_t, VAR, data) diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h b/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h index a5bc15e8a..520559ccf 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h @@ -75,6 +75,7 @@ typedef enum { LIST_POLICIES, REMOVE_POLICY, UPDATE_CONNECTION, + CONNECTION_SET_PRIORITY, #endif /* WITH_POLICY */ LAST_COMMAND_VALUE } command_id; @@ -138,6 +139,7 @@ typedef struct { uint8_t connectionType; uint8_t admin_state; #ifdef WITH_POLICY + uint32_t priority; policy_tags_t tags; #endif /* WITH_POLICY */ } add_connection_command; @@ -166,6 +168,9 @@ typedef struct { uint32_t connid; uint8_t state; uint8_t admin_state; +#ifdef WITH_POLICY + uint32_t priority; +#endif /* WITH_POLICY */ char interfaceName[SYMBOLIC_NAME_LEN]; char connectionName[SYMBOLIC_NAME_LEN]; } list_connections_command; @@ -335,9 +340,15 @@ typedef struct { typedef struct { char symbolicOrConnid[SYMBOLIC_NAME_LEN]; uint8_t admin_state; + uint32_t priority; policy_tags_t tags; } update_connection_command; +typedef struct { + char symbolicOrConnid[SYMBOLIC_NAME_LEN]; + uint32_t priority; +} connection_set_priority_command; + #endif /* WITH_POLICY */ //===== size of commands ====== @@ -394,6 +405,8 @@ static inline int payloadLengthDaemon(command_id id) { return sizeof(remove_policy_command); case UPDATE_CONNECTION: return sizeof(update_connection_command); + case CONNECTION_SET_PRIORITY: + return sizeof(connection_set_priority_command); #endif /* WITH_POLICY */ case LAST_COMMAND_VALUE: return 0; diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/face.h b/ctrl/libhicnctrl/includes/hicn/ctrl/face.h index 5c1fecd55..f0a8045de 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/face.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/face.h @@ -153,6 +153,7 @@ typedef struct { face_state_t admin_state; face_state_t state; #ifdef WITH_POLICY + uint32_t priority; policy_tags_t tags; /**< \see policy_tag_t */ #endif /* WITH_POLICY */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/route.h b/ctrl/libhicnctrl/includes/hicn/ctrl/route.h index f67cccf93..2b96d22cc 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/route.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/route.h @@ -31,6 +31,7 @@ typedef struct hicn_route_s hicn_route_t; #define MAXSZ_ROUTE MAXSZ_ROUTE_ + NULLTERM hicn_route_t * hicn_route_create(ip_prefix_t * prefix, face_id_t face_id, route_cost_t cost); +hicn_route_t * hicn_route_dup(const hicn_route_t * route); void hicn_route_free(hicn_route_t * route); int hicn_route_cmp(const hicn_route_t * route1, const hicn_route_t * route2); diff --git a/ctrl/libhicnctrl/src/api.c b/ctrl/libhicnctrl/src/api.c index 6c9b54a92..14ee69b53 100644 --- a/ctrl/libhicnctrl/src/api.c +++ b/ctrl/libhicnctrl/src/api.c @@ -715,7 +715,6 @@ hc_sock_process(hc_sock_t * s, hc_data_t ** data) available -= num_chunks * s->cur_request->data->in_element_size; s->roff += num_chunks * s->cur_request->data->in_element_size; if (s->remaining == 0) { - printf("done, sock map remove\n"); if (hc_sock_map_remove(s->map, s->cur_request->seq, NULL) < 0) { ERROR("[hc_sock_process] Error removing request from map"); return -1; @@ -856,7 +855,6 @@ hc_execute_command(hc_sock_t * s, hc_msg_t * msg, size_t msg_len, ERROR("[hc_execute_command] Could not get next sequence number"); goto ERR_SEQ; } - printf("Sending message with seq %d\n", seq); /* Create state used to process the request */ hc_sock_request_t * request = NULL; @@ -867,7 +865,6 @@ hc_execute_command(hc_sock_t * s, hc_msg_t * msg, size_t msg_len, } /* Add state to map */ - printf("sock map add\n"); if (hc_sock_map_add(s->map, seq, request) < 0) { ERROR("[hc_execute_command] Error adding request state to map"); goto ERR_MAP; @@ -1272,6 +1269,7 @@ _hc_connection_create(hc_sock_t * s, hc_connection_t * connection, bool async) .connectionType = (u8)map_to_connection_type[connection->type], .admin_state = connection->admin_state, #ifdef WITH_POLICY + .priority = connection->priority, .tags = connection->tags, #endif /* WITH_POLICY */ } @@ -1549,6 +1547,7 @@ hc_connection_parse(void * in, hc_connection_t * connection) .remote_port = ntohs(cmd->connectionData.remotePort), .admin_state = cmd->connectionData.admin_state, #ifdef WITH_POLICY + .priority = cmd->connectionData.priority, .tags = cmd->connectionData.tags, #endif /* WITH_POLICY */ .state = state, @@ -1649,6 +1648,56 @@ hc_connection_set_admin_state_async(hc_sock_t * s, const char * conn_id_or_name, return _hc_connection_set_admin_state(s, conn_id_or_name, state, true); } +int +_hc_connection_set_priority(hc_sock_t * s, const char * conn_id_or_name, + uint32_t priority, bool async) +{ + int rc; + DEBUG("[hc_connection_set_priority] connection_id/name=%s priority=%d async=%s", + conn_id_or_name, priority, BOOLSTR(async)); + struct { + header_control_message hdr; + connection_set_priority_command payload; + } msg = { + .hdr = { + .messageType = REQUEST_LIGHT, + .commandID = CONNECTION_SET_ADMIN_STATE, + .length = 1, + .seqNum = 0, + }, + .payload = { + .priority = priority, + }, + }; + rc = snprintf(msg.payload.symbolicOrConnid, SYMBOLIC_NAME_LEN, "%s", conn_id_or_name); + if (rc >= SYMBOLIC_NAME_LEN) + WARN("[_hc_connection_set_priority] Unexpected truncation of symbolic name string"); + + hc_command_params_t params = { + .cmd = ACTION_SET, + .cmd_id = CONNECTION_SET_PRIORITY, + .size_in = sizeof(connection_set_priority_command), + .size_out = 0, + .parse = NULL, + }; + + return hc_execute_command(s, (hc_msg_t*)&msg, sizeof(msg), ¶ms, NULL, async); +} + +int +hc_connection_set_priority(hc_sock_t * s, const char * conn_id_or_name, + uint32_t priority) +{ + return _hc_connection_set_priority(s, conn_id_or_name, priority, false); +} + +int +hc_connection_set_priority_async(hc_sock_t * s, const char * conn_id_or_name, + uint32_t priority) +{ + return _hc_connection_set_priority(s, conn_id_or_name, priority, true); +} + /*----------------------------------------------------------------------------* * Routes *----------------------------------------------------------------------------*/ @@ -1815,9 +1864,9 @@ hc_route_list(hc_sock_t * s, hc_data_t ** pdata) } int -hc_route_list_async(hc_sock_t * s, hc_data_t ** pdata) +hc_route_list_async(hc_sock_t * s) { - return _hc_route_list(s, pdata, true); + return _hc_route_list(s, NULL, true); } /* ROUTE PARSE */ @@ -1927,6 +1976,7 @@ hc_face_to_connection(const hc_face_t * face, hc_connection_t * connection, bool .admin_state = face_state_to_connection_state(f->admin_state), .state = face_state_to_connection_state(f->state), #ifdef WITH_POLICY + .priority = f->priority, .tags = f->tags, #endif /* WITH_POLICY */ }; @@ -1946,6 +1996,7 @@ hc_face_to_connection(const hc_face_t * face, hc_connection_t * connection, bool .admin_state = face_state_to_connection_state(f->admin_state), .state = face_state_to_connection_state(f->state), #ifdef WITH_POLICY + .priority = f->priority, .tags = f->tags, #endif /* WITH_POLICY */ }; @@ -1968,6 +2019,7 @@ hc_face_to_connection(const hc_face_t * face, hc_connection_t * connection, bool .admin_state = face_state_to_connection_state(f->admin_state), .state = face_state_to_connection_state(f->state), #ifdef WITH_POLICY + .priority = f->priority, .tags = f->tags, #endif /* WITH_POLICY */ }; @@ -1978,6 +2030,8 @@ hc_face_to_connection(const hc_face_t * face, hc_connection_t * connection, bool } else { memset(connection->name, 0, SYMBOLIC_NAME_LEN); } + snprintf(connection->interface_name, INTERFACE_LEN, "%s", + f->netdevice.name); break; default: return -1; @@ -2011,6 +2065,7 @@ hc_connection_to_face(const hc_connection_t * connection, hc_face_t * face) .admin_state = connection_state_to_face_state(connection->admin_state), .state = connection_state_to_face_state(connection->state), #ifdef WITH_POLICY + .priority = connection->priority, .tags = connection->tags, #endif /* WITH_POLICY */ }, @@ -2029,6 +2084,7 @@ hc_connection_to_face(const hc_connection_t * connection, hc_face_t * face) .admin_state = connection_state_to_face_state(connection->admin_state), .state = connection_state_to_face_state(connection->state), #ifdef WITH_POLICY + .priority = connection->priority, .tags = connection->tags, #endif /* WITH_POLICY */ }, @@ -2046,6 +2102,7 @@ hc_connection_to_face(const hc_connection_t * connection, hc_face_t * face) .admin_state = connection_state_to_face_state(connection->admin_state), .state = connection_state_to_face_state(connection->state), #ifdef WITH_POLICY + .priority = connection->priority, .tags = connection->tags, #endif /* WITH_POLICY */ }, @@ -2366,7 +2423,7 @@ hc_connection_parse_to_face(void * in, hc_face_t * face) int -hc_face_list_async(hc_sock_t * s) //, hc_data_t ** pdata) +hc_face_list_async(hc_sock_t * s) { struct { header_control_message hdr; @@ -2451,19 +2508,22 @@ hc_face_snprintf(char * s, size_t size, hc_face_t * face) if (rc < 0) return rc; - return snprintf(s, size, "[#%d %s] %s %s %s %s/%s (%s)", + return snprintf(s, size, "[#%d %s] %s %s %s %s %s/%s [%d] (%s)", face->id, face->name, + face->face.netdevice.index != NETDEVICE_UNDEFINED_INDEX ? face->face.netdevice.name : "*", face_type_str[face->face.type], local, remote, face_state_str[face->face.state], face_state_str[face->face.admin_state], + face->face.priority, tags); #else - return snprintf(s, size, "[#%d %s] %s %s %s %s/%s", + return snprintf(s, size, "[#%d %s] %s %s %s %s %s/%s", face->id, face->name, + face->face.netdevice.index != NETDEVICE_UNDEFINED_INDEX ? face->face.netdevice.name : "*", face_type_str[face->face.type], local, remote, @@ -2473,12 +2533,19 @@ hc_face_snprintf(char * s, size_t size, hc_face_t * face) } int -hc_face_set_admin_state(hc_sock_t * s, const char * conn_id_or_name, // XXX wrong identifier +hc_face_set_admin_state(hc_sock_t * s, const char * conn_id_or_name, face_state_t admin_state) { return hc_connection_set_admin_state(s, conn_id_or_name, admin_state); } +int +hc_face_set_priority(hc_sock_t * s, const char * conn_id_or_name, + uint32_t priority) +{ + return hc_connection_set_priority(s, conn_id_or_name, priority); +} + /*----------------------------------------------------------------------------* * Punting *----------------------------------------------------------------------------*/ diff --git a/ctrl/libhicnctrl/src/cli.c b/ctrl/libhicnctrl/src/cli.c index a171f7045..879454c3a 100644 --- a/ctrl/libhicnctrl/src/cli.c +++ b/ctrl/libhicnctrl/src/cli.c @@ -379,7 +379,7 @@ parse_options(int argc, char *argv[], hc_command_t * command) case OBJECT_FACE: switch(command->action) { case ACTION_CREATE: - if ((argc - optind != 6) && (argc - optind != 7)) { + if ((argc - optind != 5) && (argc - optind != 6)) { usage_face_create(argv[0], true, false); goto ERR_PARAM; } diff --git a/ctrl/libhicnctrl/src/face.c b/ctrl/libhicnctrl/src/face.c index 41ff58f81..0e25890da 100644 --- a/ctrl/libhicnctrl/src/face.c +++ b/ctrl/libhicnctrl/src/face.c @@ -129,6 +129,7 @@ netdevice_get_name(const netdevice_t * netdevice, const char ** name) int netdevice_set_name(netdevice_t * netdevice, const char * name) { + memset(netdevice->name, 0, sizeof(netdevice->name)); int rc = snprintf(netdevice->name, IFNAMSIZ, "%s", name); if (rc < 0) return -1; diff --git a/ctrl/libhicnctrl/src/route.c b/ctrl/libhicnctrl/src/route.c index 61434871b..703b4763f 100644 --- a/ctrl/libhicnctrl/src/route.c +++ b/ctrl/libhicnctrl/src/route.c @@ -43,6 +43,16 @@ hicn_route_create(ip_prefix_t * prefix, face_id_t face_id, route_cost_t cost) return route; } +hicn_route_t * +hicn_route_dup(const hicn_route_t * route) +{ + hicn_route_t * new_route = malloc(sizeof(hicn_route_t)); + if (!route) + return NULL; + memcpy(new_route, route, sizeof(hicn_route_t)); + return new_route; +} + void hicn_route_free(hicn_route_t * route) { free(route); |