diff options
Diffstat (limited to 'ctrl/libhicnctrl')
-rw-r--r-- | ctrl/libhicnctrl/examples/Makefile | 2 | ||||
-rw-r--r-- | ctrl/libhicnctrl/examples/update_priority.c | 60 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl/api.h | 5 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl/commands.h | 4 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/api.c | 39 |
5 files changed, 93 insertions, 17 deletions
diff --git a/ctrl/libhicnctrl/examples/Makefile b/ctrl/libhicnctrl/examples/Makefile index 641936f4f..ad0e46a1e 100644 --- a/ctrl/libhicnctrl/examples/Makefile +++ b/ctrl/libhicnctrl/examples/Makefile @@ -9,7 +9,7 @@ EXEC = $(SRC:.c=) all: $(EXEC) -${EXEC}: $(SRC) +%:%.c $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) .PHONY: clean mrproper diff --git a/ctrl/libhicnctrl/examples/update_priority.c b/ctrl/libhicnctrl/examples/update_priority.c new file mode 100644 index 000000000..d350f71c9 --- /dev/null +++ b/ctrl/libhicnctrl/examples/update_priority.c @@ -0,0 +1,60 @@ +/* + * 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 examples/update_priority.c + * \brief libhicnctrl sample code : face priority update + */ + +#include <stdlib.h> +#include <stdio.h> + +#include <hicn/ctrl.h> +#include <hicn/util/log.h> + +int main(int argc, char **argv) +{ + if (argc != 3) { + fprintf(stderr, "Usage: %s FACE_ID PRIORITY\n", argv[0]); + exit(EXIT_FAILURE); + } + unsigned face_id = atoi(argv[1]); + unsigned priority = atoi(argv[2]); + char face_id_s[SYMBOLIC_NAME_LEN]; + + hc_sock_t * socket = hc_sock_create(); + if (!socket){ + DEBUG("Error creating libhicnctrl socket"); + goto ERR_SOCK; + } + + if (hc_sock_connect(socket) < 0){ + DEBUG("Error connecting to forwarder"); + goto ERR; + } + + snprintf(face_id_s, SYMBOLIC_NAME_LEN, "%d", face_id); + if (hc_face_set_priority(socket, face_id_s, priority) < 0) { + DEBUG("Error setting face priority"); + goto ERR; + } + + DEBUG("Face priority updated successfully"); + +ERR: + hc_sock_free(socket); +ERR_SOCK: + return 0; +} diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h index c9c2f0da8..e522f33a6 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h @@ -571,6 +571,11 @@ int hc_face_delete(hc_sock_t * s, hc_face_t * face); int hc_face_list(hc_sock_t * s, hc_data_t ** pdata); int hc_face_list_async(hc_sock_t * s); //, hc_data_t ** pdata); +int hc_face_set_admin_state(hc_sock_t * s, const char * conn_id_or_name, face_state_t state); +#ifdef WITH_POLICY +int hc_face_set_priority(hc_sock_t * s, const char * conn_id_or_name, uint32_t priority); +#endif /* WITH_POLICY */ + #define foreach_face(VAR, data) foreach_type(hc_face_t, VAR, data) #define MAX_FACE_ID 255 diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h b/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h index 520559ccf..c250216f0 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h @@ -167,10 +167,6 @@ typedef struct { add_connection_command connectionData; 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; diff --git a/ctrl/libhicnctrl/src/api.c b/ctrl/libhicnctrl/src/api.c index 2d8ee40f0..84c3390e5 100644 --- a/ctrl/libhicnctrl/src/api.c +++ b/ctrl/libhicnctrl/src/api.c @@ -625,6 +625,9 @@ hc_sock_recv(hc_sock_t * s) return rc; } +/* + * Returns -99 in case of internal error, -1 in case of API command failure + */ int hc_sock_process(hc_sock_t * s, hc_data_t ** data) { @@ -646,11 +649,11 @@ hc_sock_process(hc_sock_t * s, hc_data_t ** data) hc_sock_request_t * request = NULL; if (hc_sock_map_get(s->map, msg->hdr.seqNum, &request) < 0) { ERROR("[hc_sock_process] Error searching for matching request"); - return -1; + return -99; } if (!request) { ERROR("[hc_sock_process] No request matching received sequence number"); - return -1; + return -99; } s->remaining = msg->hdr.length; @@ -665,6 +668,7 @@ hc_sock_process(hc_sock_t * s, hc_data_t ** data) assert(!data); hc_data_set_error(request->data); s->cur_request = request; + err = -1; break; case RESPONSE_LIGHT: assert(data); @@ -681,7 +685,7 @@ hc_sock_process(hc_sock_t * s, hc_data_t ** data) break; default: ERROR("[hc_sock_process] Invalid response received"); - return -1; + return -99; } available -= sizeof(hc_msg_header_t); @@ -702,15 +706,15 @@ hc_sock_process(hc_sock_t * s, hc_data_t ** data) int rc; rc = hc_data_ensure_available(s->cur_request->data, num_chunks); if (rc < 0) - return -1; + return -99; for (int i = 0; i < num_chunks; i++) { u8 * dst = hc_data_get_next(s->cur_request->data); if (!dst) - return -1; + return -99; rc = s->cur_request->parse(s->buf + s->roff + i * s->cur_request->data->in_element_size, dst); if (rc < 0) - err = -1; /* FIXME we let the loop complete (?) */ + err = -99; /* FIXME we let the loop complete (?) */ s->cur_request->data->size++; } } @@ -721,7 +725,7 @@ hc_sock_process(hc_sock_t * s, hc_data_t ** data) if (s->remaining == 0) { if (hc_sock_map_remove(s->map, s->cur_request->seq, NULL) < 0) { ERROR("[hc_sock_process] Error removing request from map"); - return -1; + return -99; } hc_data_set_complete(s->cur_request->data); if (data) @@ -890,9 +894,20 @@ hc_execute_command(hc_sock_t * s, hc_msg_t * msg, size_t msg_len, */ if (hc_sock_recv(s) < 0) continue; //break; - if (hc_sock_process(s, pdata) < 0) { - ERROR("[hc_execute_command] Error processing socket results"); - goto ERR_PROCESS; + int rc = hc_sock_process(s, pdata); + switch(rc) { + case 0: + break; + case -1: + ret = rc; + break; + case -99: + ERROR("[hc_execute_command] Error processing socket results"); + goto ERR_PROCESS; + break; + default: + ERROR("[hc_execute_command] Unexpected return value"); + goto ERR_PROCESS; } } @@ -909,7 +924,7 @@ ERR_REQUEST: ERR_SEQ: hc_data_free(data); ERR_DATA: - return -1; + return -99; } /*----------------------------------------------------------------------------* @@ -1665,7 +1680,7 @@ _hc_connection_set_priority(hc_sock_t * s, const char * conn_id_or_name, } msg = { .hdr = { .messageType = REQUEST_LIGHT, - .commandID = CONNECTION_SET_ADMIN_STATE, + .commandID = CONNECTION_SET_PRIORITY, .length = 1, .seqNum = 0, }, |