summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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.c43
-rw-r--r--hicn-light/src/hicn/config/configuration.c4
-rw-r--r--hicn-light/src/hicn/config/controlListConnections.c6
-rw-r--r--hicn-light/src/hicn/core/connection.c4
-rw-r--r--hicn-light/src/hicn/utils/commands.h4
11 files changed, 104 insertions, 32 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 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 1a5bd8cee..84c3390e5 100644
--- a/ctrl/libhicnctrl/src/api.c
+++ b/ctrl/libhicnctrl/src/api.c
@@ -521,6 +521,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);
@@ -623,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)
{
@@ -644,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;
@@ -663,12 +668,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 */
@@ -677,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);
@@ -698,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++;
}
}
@@ -717,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)
@@ -886,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;
}
}
@@ -905,7 +924,7 @@ ERR_REQUEST:
ERR_SEQ:
hc_data_free(data);
ERR_DATA:
- return -1;
+ return -99;
}
/*----------------------------------------------------------------------------*
@@ -1661,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,
},
diff --git a/hicn-light/src/hicn/config/configuration.c b/hicn-light/src/hicn/config/configuration.c
index f135dcc5a..0466189cb 100644
--- a/hicn-light/src/hicn/config/configuration.c
+++ b/hicn-light/src/hicn/config/configuration.c
@@ -698,7 +698,7 @@ struct iovec *configuration_ProcessConnectionList(Configuration *config,
listConnectionsCommand->state =
connection_IsUp(original) ? IFACE_UP : IFACE_DOWN;
- listConnectionsCommand->admin_state =
+ listConnectionsCommand->connectionData.admin_state =
(connection_GetAdminState(original) == CONNECTION_STATE_UP) ? IFACE_UP : IFACE_DOWN;
listConnectionsCommand->connectionData.connectionType =
ioOperations_GetConnectionType(connection_GetIoOperations(original));
@@ -706,7 +706,7 @@ struct iovec *configuration_ProcessConnectionList(Configuration *config,
listConnectionsCommand->connectionData.admin_state = connection_GetAdminState(original);
#ifdef WITH_POLICY
- listConnectionsCommand->priority = connection_GetPriority(original);
+ listConnectionsCommand->connectionData.priority = connection_GetPriority(original);
listConnectionsCommand->connectionData.tags = connection_GetTags(original);
#endif /* WITH_POLICY */
diff --git a/hicn-light/src/hicn/config/controlListConnections.c b/hicn-light/src/hicn/config/controlListConnections.c
index 0613ac4f9..cbed8a79c 100644
--- a/hicn-light/src/hicn/config/controlListConnections.c
+++ b/hicn-light/src/hicn/config/controlListConnections.c
@@ -109,7 +109,7 @@ static CommandReturn _controlListConnections_Execute(CommandParser *parser,
commandOutputMain =
parcMemory_Allocate(sizeof(char *) * receivedHeader->length);
for (size_t j = 0; j < receivedHeader->length; j++) {
- commandOutputMain[j] = parcMemory_Allocate(sizeof(char) * 128);
+ commandOutputMain[j] = parcMemory_Allocate(sizeof(char) * 256);
}
}
@@ -147,8 +147,8 @@ foreach_policy_tag
*s = '\0';
parcBufferComposer_Format(
- composer, "%5d %10s %12s %6s %40s %40s %5s [%d] [%s]", listConnectionsCommand->connid, listConnectionsCommand->connectionName,
- stateString[listConnectionsCommand->admin_state],
+ composer, "%5d %10s %12s %6s %40s %40s %5s [%6d] [%s]", listConnectionsCommand->connid, listConnectionsCommand->connectionName,
+ stateString[listConnectionsCommand->connectionData.admin_state],
stateString[listConnectionsCommand->state], sourceString,
destinationString,
connTypeString[listConnectionsCommand->connectionData.connectionType],
diff --git a/hicn-light/src/hicn/core/connection.c b/hicn-light/src/hicn/core/connection.c
index 8ec38f75f..c1d143f70 100644
--- a/hicn-light/src/hicn/core/connection.c
+++ b/hicn-light/src/hicn/core/connection.c
@@ -337,7 +337,7 @@ uint32_t connection_GetPriority(const Connection *conn)
{
parcAssertNotNull(conn, "Parameter conn must be non-null");
if (!conn->ops)
- return CONNECTION_STATE_UNDEFINED;
+ return 0;
return ioOperations_GetPriority(conn->ops);
}
@@ -346,8 +346,6 @@ void connection_SetPriority(Connection *conn, uint32_t priority)
parcAssertNotNull(conn, "Parameter conn must be non-null");
if (!conn->ops)
return;
- if ((priority != CONNECTION_STATE_UP) && (priority != CONNECTION_STATE_DOWN))
- return;
ioOperations_SetPriority(conn->ops, priority);
}
#endif /* WITH_POLICY */
diff --git a/hicn-light/src/hicn/utils/commands.h b/hicn-light/src/hicn/utils/commands.h
index 520559ccf..c250216f0 100644
--- a/hicn-light/src/hicn/utils/commands.h
+++ b/hicn-light/src/hicn/utils/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;