aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2019-11-21 00:38:09 +0100
committerJordan Augé <jordan.auge+fdio@cisco.com>2019-11-21 00:51:06 +0100
commitae6f3b8e1f55fc4bb7807c293850d3cb46cab1fd (patch)
treefcc8cc1f42a21e8d6da3051ccfcb161c90cd02c8
parent275b80b81746cdf5fc9b8299e7441c9d0d8718de (diff)
[HICN-379] Add face priority support in face manager
Change-Id: Iae19e016aae833b4bc95ff6d91d51b188f398e25 Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
-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.c39
-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
9 files changed, 99 insertions, 29 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,
},
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;