diff options
author | Jordan Augé <jordan.auge+fdio@cisco.com> | 2019-05-09 11:26:31 +0200 |
---|---|---|
committer | Jordan Augé <jordan.auge+fdio@cisco.com> | 2019-05-09 11:26:31 +0200 |
commit | 3e2cd52a6ae2345a44f39761beb5315a45832d95 (patch) | |
tree | 14f55c9fd58003faed83a3d47756a46d97c09322 /hicn-light/src/hicn/core | |
parent | c8e6bdf4282c34fd3199cdeec42895cbbc05d9c1 (diff) |
[HICN-192] Add interface to administratively set a connection up and down
Change-Id: I8d00262fd8601328a50d0e2a6bef952031246818
Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Diffstat (limited to 'hicn-light/src/hicn/core')
-rw-r--r-- | hicn-light/src/hicn/core/CMakeLists.txt | 3 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/connection.c | 38 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/connection.h | 9 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/connectionState.h | 37 |
4 files changed, 85 insertions, 2 deletions
diff --git a/hicn-light/src/hicn/core/CMakeLists.txt b/hicn-light/src/hicn/core/CMakeLists.txt index 1d7dc03e9..a29409af6 100644 --- a/hicn-light/src/hicn/core/CMakeLists.txt +++ b/hicn-light/src/hicn/core/CMakeLists.txt @@ -15,6 +15,7 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR) list(APPEND HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/connectionManager.h + ${CMAKE_CURRENT_SOURCE_DIR}/connectionState.h ${CMAKE_CURRENT_SOURCE_DIR}/ticks.h ${CMAKE_CURRENT_SOURCE_DIR}/connectionList.h ${CMAKE_CURRENT_SOURCE_DIR}/connectionTable.h @@ -52,4 +53,4 @@ list(APPEND SOURCE_FILES ) set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE) -set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE)
\ No newline at end of file +set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE) diff --git a/hicn-light/src/hicn/core/connection.c b/hicn-light/src/hicn/core/connection.c index 61db61ba7..a5d5fb5b9 100644 --- a/hicn-light/src/hicn/core/connection.c +++ b/hicn-light/src/hicn/core/connection.c @@ -18,6 +18,7 @@ #include <stdio.h> #include <hicn/core/connection.h> +#include <hicn/core/connectionState.h> #include <hicn/core/messageHandler.h> #include <hicn/core/ticks.h> #include <hicn/core/wldr.h> @@ -45,7 +46,6 @@ struct connection { // file/hicnLightControl) this value is set to false so // that a base station can not disable wldr at the client Wldr *wldr; - }; Connection *connection_Create(IoOperations *ops) { @@ -64,6 +64,10 @@ Connection *connection_Create(IoOperations *ops) { conn->counter = 0; conn->last_sent = 0; conn->delay = INT_MAX; + + /* By default, a connection will aim at the UP state */ + connection_SetAdminState(conn, CONNECTION_STATE_UP); + return conn; } @@ -280,3 +284,35 @@ void connection_HandleWldrNotification(Connection *conn, Message *message) { if (conn->wldr != NULL) wldr_HandleWldrNotification(conn->wldr, conn, message); } + +connection_state_t connection_GetState(const Connection *conn) +{ + parcAssertNotNull(conn, "Parameter conn must be non-null"); + if (!conn->ops) + return CONNECTION_STATE_UNDEFINED; + return ioOperations_GetState(conn->ops); +} + +void connection_SetState(Connection *conn, connection_state_t state) +{ + parcAssertNotNull(conn, "Parameter conn must be non-null"); + if (!conn->ops) + return; + ioOperations_SetState(conn->ops, state); +} + +connection_state_t connection_GetAdminState(const Connection *conn) +{ + parcAssertNotNull(conn, "Parameter conn must be non-null"); + if (!conn->ops) + return CONNECTION_STATE_UNDEFINED; + return ioOperations_GetAdminState(conn->ops); +} + +void connection_SetAdminState(Connection *conn, connection_state_t admin_state) +{ + parcAssertNotNull(conn, "Parameter conn must be non-null"); + if (!conn->ops) + return; + ioOperations_SetAdminState(conn->ops, admin_state); +} diff --git a/hicn-light/src/hicn/core/connection.h b/hicn-light/src/hicn/core/connection.h index 9d7cd7c93..204c4668f 100644 --- a/hicn-light/src/hicn/core/connection.h +++ b/hicn-light/src/hicn/core/connection.h @@ -25,6 +25,7 @@ #ifndef connection_h #define connection_h #include <src/hicn/config.h> +#include <hicn/core/connectionState.h> #include <hicn/io/ioOperations.h> #include <hicn/utils/address.h> @@ -159,4 +160,12 @@ void connection_DetectLosses(Connection *conn, Message *message); void connection_HandleWldrNotification(Connection *conn, Message *message); +connection_state_t connection_GetState(const Connection *conn); + +void connection_SetState(Connection *conn, connection_state_t state); + +connection_state_t connection_GetAdminState(const Connection *conn); + +void connection_SetAdminState(Connection *conn, connection_state_t admin_state); + #endif // connection_h diff --git a/hicn-light/src/hicn/core/connectionState.h b/hicn-light/src/hicn/core/connectionState.h new file mode 100644 index 000000000..9daa15c9c --- /dev/null +++ b/hicn-light/src/hicn/core/connectionState.h @@ -0,0 +1,37 @@ +/* + * 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 connection_state.h + * @brief Represents the state of a connection + * + */ + +#ifndef connection_state_h +#define connection_state_h + +#define foreach_connection_state \ + _(UNDEFINED) \ + _(DOWN) \ + _(UP) \ + _(N) + +typedef enum { +#define _(x) CONNECTION_STATE_ ## x, +foreach_connection_state +#undef _ +} connection_state_t; + +#endif /* connection_state_h */ |