aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/io
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2019-05-09 11:26:31 +0200
committerJordan Augé <jordan.auge+fdio@cisco.com>2019-05-09 11:26:31 +0200
commit3e2cd52a6ae2345a44f39761beb5315a45832d95 (patch)
tree14f55c9fd58003faed83a3d47756a46d97c09322 /hicn-light/src/hicn/io
parentc8e6bdf4282c34fd3199cdeec42895cbbc05d9c1 (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/io')
-rw-r--r--hicn-light/src/hicn/io/hicnConnection.c41
-rw-r--r--hicn-light/src/hicn/io/ioOperations.c17
-rw-r--r--hicn-light/src/hicn/io/ioOperations.h48
-rw-r--r--hicn-light/src/hicn/io/streamConnection.c41
-rw-r--r--hicn-light/src/hicn/io/udpConnection.c41
5 files changed, 188 insertions, 0 deletions
diff --git a/hicn-light/src/hicn/io/hicnConnection.c b/hicn-light/src/hicn/io/hicnConnection.c
index 3c6f0612c..c6831df57 100644
--- a/hicn-light/src/hicn/io/hicnConnection.c
+++ b/hicn-light/src/hicn/io/hicnConnection.c
@@ -72,6 +72,11 @@ typedef struct hicn_state {
unsigned id;
unsigned delay;
+
+ /* This information would better be stored in the connection data structure
+ * but it is currently not reachable from within the implementation. */
+ connection_state_t state;
+ connection_state_t admin_state;
} _HicnState;
// Prototypes
@@ -87,6 +92,10 @@ static void _destroy(IoOperations **opsPtr);
static list_connections_type _getConnectionType(const IoOperations *ops);
static Ticks _sendProbe(IoOperations *ops, unsigned probeType,
uint8_t *message);
+static connection_state_t _getState(const IoOperations *ops);
+static void _setState(IoOperations *ops, connection_state_t state);
+static connection_state_t _getAdminState(const IoOperations *ops);
+static void _setAdminState(IoOperations *ops, connection_state_t admin_state);
/*
* This assigns a unique pointer to the void * which we use
@@ -114,6 +123,10 @@ static IoOperations _template = {
.class = &_streamConnection_Class,
.getConnectionType = &_getConnectionType,
.sendProbe = &_sendProbe,
+ .getState = &_getState,
+ .setState = &_setState,
+ .getAdminState = &_getAdminState,
+ .setAdminState = &_setAdminState,
};
// =================================================================
@@ -546,3 +559,31 @@ static void _setConnectionState(_HicnState *hicnConnState, bool isUp) {
return;
}
}
+
+static connection_state_t _getState(const IoOperations *ops) {
+ parcAssertNotNull(ops, "Parameter must be non-null");
+ const _HicnState *hicnConnState =
+ (const _HicnState *)ioOperations_GetClosure(ops);
+ return hicnConnState->state;
+}
+
+static void _setState(IoOperations *ops, connection_state_t state) {
+ parcAssertNotNull(ops, "Parameter must be non-null");
+ _HicnState *hicnConnState =
+ (_HicnState *)ioOperations_GetClosure(ops);
+ hicnConnState->state = state;
+}
+
+static connection_state_t _getAdminState(const IoOperations *ops) {
+ parcAssertNotNull(ops, "Parameter must be non-null");
+ const _HicnState *hicnConnState =
+ (const _HicnState *)ioOperations_GetClosure(ops);
+ return hicnConnState->admin_state;
+}
+
+static void _setAdminState(IoOperations *ops, connection_state_t admin_state) {
+ parcAssertNotNull(ops, "Parameter must be non-null");
+ _HicnState *hicnConnState =
+ (_HicnState *)ioOperations_GetClosure(ops);
+ hicnConnState->admin_state = admin_state;
+}
diff --git a/hicn-light/src/hicn/io/ioOperations.c b/hicn-light/src/hicn/io/ioOperations.c
index a9b763448..5693f86c5 100644
--- a/hicn-light/src/hicn/io/ioOperations.c
+++ b/hicn-light/src/hicn/io/ioOperations.c
@@ -66,3 +66,20 @@ Ticks ioOperations_SendProbe(IoOperations *ops, unsigned probeType,
uint8_t *message) {
return ops->sendProbe(ops, probeType, message);
}
+
+
+connection_state_t ioOperations_GetState(const IoOperations *ops) {
+ return ops->getState(ops);
+}
+
+void ioOperations_SetState(IoOperations *ops, connection_state_t state) {
+ ops->setState(ops, state);
+}
+
+connection_state_t ioOperations_GetAdminState(const IoOperations *ops) {
+ return ops->getAdminState(ops);
+}
+
+void ioOperations_SetAdminState(IoOperations *ops, connection_state_t admin_state) {
+ ops->setAdminState(ops, admin_state);
+}
diff --git a/hicn-light/src/hicn/io/ioOperations.h b/hicn-light/src/hicn/io/ioOperations.h
index c5e58d8b2..7a48b7e3e 100644
--- a/hicn-light/src/hicn/io/ioOperations.h
+++ b/hicn-light/src/hicn/io/ioOperations.h
@@ -26,6 +26,7 @@
#ifndef io_h
#define io_h
+#include <hicn/core/connectionState.h>
#include <hicn/core/message.h>
#include <hicn/core/ticks.h>
#include <hicn/io/addressPair.h>
@@ -58,6 +59,14 @@ typedef struct io_ops IoOperations;
* IoOperations.
* @constant getConnectionType Returns the type of connection (TCP, UDP, L2,
* etc.) of the underlying connection.
+ * @constant getState Returns the current state of the connection (redundant
+ * with isUp for added for completeness of the API).
+ * @constant setState Allows to mark the current state of a connection.
+ * @constant getAdminState Returns the administrative state of a connection (as
+ * requested by the user, which might occasionally differ from the current
+ * state).
+ * @constant setAdminState Allows to set the administrative state of a
+ * connection.
* @discussion <#Discussion#>
*/
struct io_ops {
@@ -74,6 +83,10 @@ struct io_ops {
const void *(*class)(const IoOperations *ops);
list_connections_type (*getConnectionType)(const IoOperations *ops);
Ticks (*sendProbe)(IoOperations *ops, unsigned probeType, uint8_t *message);
+ connection_state_t (*getState)(const IoOperations *ops);
+ void (*setState)(IoOperations *ops, connection_state_t state);
+ connection_state_t (*getAdminState)(const IoOperations *ops);
+ void (*setAdminState)(IoOperations *ops, connection_state_t admin_state);
};
/**
@@ -365,4 +378,39 @@ list_connections_type ioOperations_GetConnectionType(const IoOperations *ops);
Ticks ioOperations_SendProbe(IoOperations *ops, unsigned probeType,
uint8_t *message);
+
+/**
+ * Returns the current state of the connection
+ *
+ * @param [in] ops The connection implementation.
+ *
+ * @return Connection state (connection_state_t).
+ */
+connection_state_t ioOperations_GetState(const IoOperations *ops);
+
+/**
+ * Sets the current state of the connection
+ *
+ * @param [in] ops The connection implementation.
+ * @param [in] state New state to set (connection_state_t).
+ */
+void ioOperations_SetState(IoOperations *ops, connection_state_t state);
+
+/**
+ * Returns the administrative state of the connection
+ *
+ * @param [in] ops The connection implementation.
+ *
+ * @return Connection state (connection_state_t).
+ */
+connection_state_t ioOperations_GetAdminState(const IoOperations *ops);
+
+/**
+ * Sets the administrative state of the connection
+ *
+ * @param [in] ops The connection implementation.
+ * @param [in] state New state to set (connection_state_t).
+ */
+void ioOperations_SetAdminState(IoOperations *ops, connection_state_t admin_state);
+
#endif // io_h
diff --git a/hicn-light/src/hicn/io/streamConnection.c b/hicn-light/src/hicn/io/streamConnection.c
index 465e0c326..1c868c611 100644
--- a/hicn-light/src/hicn/io/streamConnection.c
+++ b/hicn-light/src/hicn/io/streamConnection.c
@@ -60,6 +60,11 @@ typedef struct stream_state {
unsigned id;
size_t nextMessageLength;
+
+ /* This information would better be stored in the connection data structure
+ * but it is currently not reachable from within the implementation. */
+ connection_state_t state;
+ connection_state_t admin_state;
} _StreamState;
// Prototypes
@@ -81,6 +86,10 @@ static list_connections_type _streamConnection_GetConnectionType(
const IoOperations *ops);
static Ticks _sendProbe(IoOperations *ops, unsigned probeType,
uint8_t *message);
+static connection_state_t _streamConnection_getState(const IoOperations *ops);
+static void _streamConnection_setState(IoOperations *ops, connection_state_t state);
+static connection_state_t _streamConnection_getAdminState(const IoOperations *ops);
+static void _streamConnection_setAdminState(IoOperations *ops, connection_state_t admin_state);
/*
* This assigns a unique pointer to the void * which we use
@@ -108,6 +117,10 @@ static IoOperations _template = {
.class = &_streamConnection_Class,
.getConnectionType = &_streamConnection_GetConnectionType,
.sendProbe = &_sendProbe,
+ .getState = &_streamConnection_getState,
+ .setState = &_streamConnection_setState,
+ .getAdminState = &_streamConnection_getAdminState,
+ .setAdminState = &_streamConnection_setAdminState,
};
IoOperations *streamConnection_AcceptConnection(Forwarder *forwarder, int fd,
@@ -687,3 +700,31 @@ static void _conn_eventcb(PARCEventQueue *event, PARCEventQueueEventType events,
/* None of the other events can happen here, since we haven't enabled
* timeouts */
}
+
+static connection_state_t _streamConnection_getState(const IoOperations *ops) {
+ parcAssertNotNull(ops, "Parameter must be non-null");
+ const _StreamState *stream =
+ (const _StreamState *)ioOperations_GetClosure(ops);
+ return stream->state;
+}
+
+static void _streamConnection_setState(IoOperations *ops, connection_state_t state) {
+ parcAssertNotNull(ops, "Parameter must be non-null");
+ _StreamState *stream =
+ (_StreamState *)ioOperations_GetClosure(ops);
+ stream->state = state;
+}
+
+static connection_state_t _streamConnection_getAdminState(const IoOperations *ops) {
+ parcAssertNotNull(ops, "Parameter must be non-null");
+ const _StreamState *stream =
+ (const _StreamState *)ioOperations_GetClosure(ops);
+ return stream->admin_state;
+}
+
+static void _streamConnection_setAdminState(IoOperations *ops, connection_state_t admin_state) {
+ parcAssertNotNull(ops, "Parameter must be non-null");
+ _StreamState *stream =
+ (_StreamState *)ioOperations_GetClosure(ops);
+ stream->admin_state = admin_state;
+}
diff --git a/hicn-light/src/hicn/io/udpConnection.c b/hicn-light/src/hicn/io/udpConnection.c
index 69cbea0e1..fb1865df3 100644
--- a/hicn-light/src/hicn/io/udpConnection.c
+++ b/hicn-light/src/hicn/io/udpConnection.c
@@ -57,6 +57,11 @@ typedef struct udp_state {
unsigned id;
unsigned delay;
+
+ /* This information would better be stored in the connection data structure
+ * but it is currently not reachable from within the implementation. */
+ connection_state_t state;
+ connection_state_t admin_state;
} _UdpState;
// Prototypes
@@ -72,6 +77,10 @@ static void _destroy(IoOperations **opsPtr);
static list_connections_type _getConnectionType(const IoOperations *ops);
static Ticks _sendProbe(IoOperations *ops, unsigned probeType,
uint8_t *message);
+static connection_state_t _getState(const IoOperations *ops);
+static void _setState(IoOperations *ops, connection_state_t state);
+static connection_state_t _getAdminState(const IoOperations *ops);
+static void _setAdminState(IoOperations *ops, connection_state_t admin_state);
/*
* This assigns a unique pointer to the void * which we use
@@ -99,6 +108,10 @@ static IoOperations _template = {
.class = &_streamConnection_Class,
.getConnectionType = &_getConnectionType,
.sendProbe = &_sendProbe,
+ .getState = &_getState,
+ .setState = &_setState,
+ .getAdminState = &_getAdminState,
+ .setAdminState = &_setAdminState,
};
// =================================================================
@@ -394,3 +407,31 @@ static void _setConnectionState(_UdpState *udpConnState, bool isUp) {
return;
}
}
+
+static connection_state_t _getState(const IoOperations *ops) {
+ parcAssertNotNull(ops, "Parameter must be non-null");
+ const _UdpState *udpConnState =
+ (const _UdpState *)ioOperations_GetClosure(ops);
+ return udpConnState->state;
+}
+
+static void _setState(IoOperations *ops, connection_state_t state) {
+ parcAssertNotNull(ops, "Parameter must be non-null");
+ _UdpState *udpConnState =
+ (_UdpState *)ioOperations_GetClosure(ops);
+ udpConnState->state = state;
+}
+
+static connection_state_t _getAdminState(const IoOperations *ops) {
+ parcAssertNotNull(ops, "Parameter must be non-null");
+ const _UdpState *udpConnState =
+ (const _UdpState *)ioOperations_GetClosure(ops);
+ return udpConnState->admin_state;
+}
+
+static void _setAdminState(IoOperations *ops, connection_state_t admin_state) {
+ parcAssertNotNull(ops, "Parameter must be non-null");
+ _UdpState *udpConnState =
+ (_UdpState *)ioOperations_GetClosure(ops);
+ udpConnState->admin_state = admin_state;
+}