aboutsummaryrefslogtreecommitdiffstats
path: root/ctrl
diff options
context:
space:
mode:
Diffstat (limited to 'ctrl')
-rw-r--r--ctrl/facemgr/src/api.c1
-rw-r--r--ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c3
-rw-r--r--ctrl/libhicnctrl/examples/Makefile2
-rw-r--r--ctrl/libhicnctrl/examples/update_priority.c60
-rw-r--r--ctrl/libhicnctrl/includes/hicn/ctrl/api.h5
-rw-r--r--ctrl/libhicnctrl/includes/hicn/ctrl/commands.h4
-rw-r--r--ctrl/libhicnctrl/src/api.c45
7 files changed, 99 insertions, 21 deletions
diff --git a/ctrl/facemgr/src/api.c b/ctrl/facemgr/src/api.c
index dfb23db3b..13b811288 100644
--- a/ctrl/facemgr/src/api.c
+++ b/ctrl/facemgr/src/api.c
@@ -2087,7 +2087,6 @@ facemgr_list_facelets_json(const facemgr_t * facemgr, char ** buffer)
if (size != 0 && cur >= s + size)
goto END;
}
- free(facelet_array);
rc = snprintf(cur, s + size - cur, "]}\n");
if (rc < 0)
diff --git a/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c b/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c
index a6cd44fe0..4ba4c5b1f 100644
--- a/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c
+++ b/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c
@@ -101,7 +101,6 @@ int hl_process_state(interface_t * interface)
}
data->state = HL_STATE_FACES_SENT;
break;
- break;
case HL_STATE_FACES_RECEIVED:
data->state = HL_STATE_IDLE;
@@ -601,7 +600,7 @@ int hl_callback(interface_t * interface, int fd, void * unused)
facelet_set_event(facelet, FACELET_EVENT_GET);
interface_raise_event(interface, facelet);
}
-
+ hc_data_free(results);
hc_data_free(data->polled_routes);
data->polled_routes = NULL;
data->state = HL_STATE_FACES_RECEIVED;
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 b6d2686b7..eba80bdb3 100644
--- a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h
+++ b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h
@@ -568,6 +568,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 5afecf7e6..8540addcf 100644
--- a/ctrl/libhicnctrl/src/api.c
+++ b/ctrl/libhicnctrl/src/api.c
@@ -520,6 +520,8 @@ hc_sock_free(hc_sock_t * s)
} else {
for (unsigned i = 0; i < n; i++) {
hc_sock_request_t * request = request_array[i];
+ if (hc_sock_map_remove(s->map, request->seq, NULL) < 0)
+ ERROR("[hc_sock_process] Error removing request from map");
hc_sock_request_free(request);
}
free(request_array);
@@ -622,6 +624,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)
{
@@ -643,11 +648,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;
@@ -662,12 +667,15 @@ 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);
if (s->remaining == 0) {
hc_data_set_complete(request->data);
*data = request->data;
+ if (hc_sock_map_remove(s->map, request->seq, NULL) < 0)
+ ERROR("[hc_sock_process] Error removing request from map");
hc_sock_request_free(request);
} else {
/* We only remember it if there is still data to parse */
@@ -676,7 +684,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);
@@ -697,15 +705,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++;
}
}
@@ -716,7 +724,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)
@@ -881,9 +889,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;
}
}
@@ -899,7 +918,7 @@ ERR_MAP:
ERR_REQUEST:
hc_data_free(data);
ERR_DATA:
- return -1;
+ return -99;
}
/*----------------------------------------------------------------------------*
@@ -1655,7 +1674,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,
},
@@ -2302,7 +2321,7 @@ hc_face_delete(hc_sock_t * s, hc_face_t * face)
int rc = hc_face_snprintf(face_s, MAXSZ_HC_FACE, face);
if (rc >= MAXSZ_HC_FACE)
WARN("[hc_face_delete] Unexpected truncation of face string");
- DEBUG("[hc_face_delete] face=%s");
+ DEBUG("[hc_face_delete] face=%s", face_s);
hc_connection_t connection;
if (hc_face_to_connection(face, &connection, false) < 0) {