diff options
Diffstat (limited to 'hicn-light/src/hicn/core')
-rw-r--r-- | hicn-light/src/hicn/core/connection.c | 46 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/connection.h | 11 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/messageHandler.h | 115 |
3 files changed, 81 insertions, 91 deletions
diff --git a/hicn-light/src/hicn/core/connection.c b/hicn-light/src/hicn/core/connection.c index c1d143f70..c2ac71a5f 100644 --- a/hicn-light/src/hicn/core/connection.c +++ b/hicn-light/src/hicn/core/connection.c @@ -38,11 +38,7 @@ struct connection { unsigned refCount; - bool probing_active; - unsigned probing_interval; unsigned counter; - Ticks last_sent; - Ticks delay; bool wldrAutoStart; // if true, wldr can be set automatically // by default this value is set to true. @@ -66,13 +62,9 @@ Connection *connection_Create(IoOperations *ops) { conn->ops = ops; conn->refCount = 1; conn->wldr = NULL; - conn->probing_active = false; conn->wldrAutoStart = true; - conn->probing_interval = 0; 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); @@ -138,19 +130,6 @@ bool connection_SendIOVBuffer(const Connection *conn, struct iovec *msg, return ioOperations_SendIOVBuffer(conn->ops, msg, size); } -static void _sendProbe(Connection *conn, unsigned probeType, uint8_t *message) { - parcAssertNotNull(conn, "Parameter conn must be non-null"); - - if (probeType == PACKET_TYPE_PROBE_REQUEST) { - Ticks now = ioOperations_SendProbe(conn->ops, probeType, message); - if (now != 0) { - conn->last_sent = now; - } - } else { - ioOperations_SendProbe(conn->ops, probeType, message); - } -} - bool connection_SendBuffer(const Connection *conn, u8 * buffer, size_t length) { struct iovec iov[1]; @@ -159,33 +138,20 @@ bool connection_SendBuffer(const Connection *conn, u8 * buffer, size_t length) return connection_SendIOVBuffer(conn, iov, 1); } -void connection_Probe(Connection *conn) { - _sendProbe(conn, PACKET_TYPE_PROBE_REQUEST, NULL); +void connection_Probe(Connection *conn, uint8_t * probe) { + ioOperations_SendProbe(conn->ops, probe); } -void connection_HandleProbe(Connection *conn, uint8_t *probe, - Ticks actualTime) { +void connection_HandleProbe(Connection *conn, uint8_t *probe){ parcAssertNotNull(conn, "Parameter conn must be non-null"); parcAssertNotNull(probe, "Parameter pkt must be non-null"); - uint8_t probeType = messageHandler_GetProbePacketType(probe); - if (probeType == PACKET_TYPE_PROBE_REQUEST) { - _sendProbe(conn, PACKET_TYPE_PROBE_REPLY, probe); - } else if (probeType == PACKET_TYPE_PROBE_REPLY) { - Ticks delay = actualTime - conn->last_sent; - if (delay == 0) { - delay = 1; - } - if (delay < conn->delay) { - conn->delay = delay; - } - } else { - printf("receivde unkwon probe type\n"); + if(messageHandler_IsInterest(probe)){ + messageHandler_CreateProbeReply(probe, HF_INET6_TCP); + ioOperations_SendProbe(conn->ops, probe); } } -uint64_t connection_GetDelay(Connection *conn) { return (uint64_t)conn->delay; } - IoOperations *connection_GetIoOperations(const Connection *conn) { return conn->ops; } diff --git a/hicn-light/src/hicn/core/connection.h b/hicn-light/src/hicn/core/connection.h index d0d093064..b6513ea1a 100644 --- a/hicn-light/src/hicn/core/connection.h +++ b/hicn-light/src/hicn/core/connection.h @@ -46,10 +46,6 @@ typedef enum { #include <hicn/policy.h> #endif /* WITH_POLICY */ -// packet types for probing -#define PACKET_TYPE_PROBE_REQUEST 5 -#define PACKET_TYPE_PROBE_REPLY 6 - struct connection; typedef struct connection Connection; @@ -156,12 +152,9 @@ const void *connection_Class(const Connection *conn); bool connection_ReSend(const Connection *conn, Message *message, bool notification); -void connection_Probe(Connection *conn); - -void connection_HandleProbe(Connection *conn, uint8_t *message, - Ticks actualTime); +void connection_Probe(Connection *conn, uint8_t *probe); -uint64_t connection_GetDelay(Connection *conn); +void connection_HandleProbe(Connection *conn, uint8_t *message); void connection_AllowWldrAutoStart(Connection *conn, bool allow); diff --git a/hicn-light/src/hicn/core/messageHandler.h b/hicn-light/src/hicn/core/messageHandler.h index e2f0140e5..0bf6bebbe 100644 --- a/hicn-light/src/hicn/core/messageHandler.h +++ b/hicn-light/src/hicn/core/messageHandler.h @@ -63,6 +63,8 @@ #define CONNECTION_ID_UNDEFINED -1 +#define BFD_PORT 3784 + static inline uint8_t messageHandler_GetIPPacketType(const uint8_t *message) { return HICN_IP_VERSION(message); } @@ -491,23 +493,6 @@ static inline bool messageHandler_HasWldr(const uint8_t *message) { return false; } -static inline uint8_t messageHandler_GetProbePacketType( - const uint8_t *message) { - const uint8_t *icmp_ptr; - switch (messageHandler_GetIPPacketType(message)) { - case IPv6_TYPE: - icmp_ptr = message + IPV6_HDRLEN; - break; - case IPv4_TYPE: - icmp_ptr = message + IPV4_HDRLEN; - break; - default: - return 0; - } - - return ((_icmp_header_t *)icmp_ptr)->code; -} - static inline uint32_t messageHandler_GetPathLabel(const uint8_t *message) { if (!messageHandler_IsTCP(message)) return 0; @@ -707,31 +692,77 @@ static inline void messageHandler_SetWldrNotification(uint8_t *notification, } } -static inline void messageHandler_SetProbePacket(uint8_t *message, - uint8_t probeType, - struct in6_addr *src, - struct in6_addr *dst) { - hicn_header_t *h = (hicn_header_t *)message; - *h = (hicn_header_t){ - .v6 = { - .ip = - { - .version_class_flow = - htonl((IPV6_DEFAULT_VERSION << 28) | - (IPV6_DEFAULT_TRAFFIC_CLASS << 20) | - (IPV6_DEFAULT_FLOW_LABEL & 0xfffff)), - .len = htons(ICMP_HDRLEN), - .nxt = IPPROTO_ICMPV6, - .hlim = 5, // this should be 1, but ... just to be safe - }, - .icmp = - { - .type = ICMP_LB_TYPE, - .code = probeType, - }, - }}; - messageHandler_SetSource_IPv6(message, src); - messageHandler_SetDestination_IPv6(message, dst); +static inline uint8_t * messageHandler_CreateProbePacket(hicn_format_t format, + uint32_t probe_lifetime){ + size_t header_length; + hicn_packet_get_header_length_from_format(format, &header_length); + + uint8_t *pkt = parcMemory_AllocateAndClear(header_length); + + hicn_packet_init_header(format, (hicn_header_t *) pkt); + + hicn_packet_set_dst_port((hicn_header_t *) pkt, BFD_PORT); + hicn_interest_set_lifetime ((hicn_header_t *) pkt, probe_lifetime); + + return pkt; +} + +static inline void messageHandler_CreateProbeReply(uint8_t * probe, + hicn_format_t format){ + + hicn_name_t probe_name; + hicn_interest_get_name (format, + (const hicn_header_t *) probe, &probe_name); + ip_address_t probe_locator; + hicn_interest_get_locator (format, + (const hicn_header_t *) probe, &probe_locator); + + uint16_t src_prt; + uint16_t dst_prt; + hicn_packet_get_src_port((const hicn_header_t *) probe, &src_prt); + hicn_packet_get_dst_port((const hicn_header_t *) probe, &dst_prt); + hicn_packet_set_src_port((hicn_header_t *) probe, dst_prt); + hicn_packet_set_dst_port((hicn_header_t *) probe, src_prt); + + hicn_data_set_name (format, (hicn_header_t *) probe, &probe_name); + hicn_data_set_locator (format, (hicn_header_t *) probe, &probe_locator); + hicn_data_set_expiry_time ((hicn_header_t *) probe, 0); +} + +static inline hicn_name_t * messageHandler_CreateProbeName(const ip_prefix_t *address){ + hicn_name_t * name = parcMemory_AllocateAndClear(sizeof(hicn_name_t)); + hicn_name_create_from_ip_prefix(address, 0, name); + return name; +} + +static inline void messageHandler_SetProbeName(uint8_t * probe, hicn_format_t format, + hicn_name_t * name, uint32_t seq){ + hicn_name_set_seq_number (name, seq); + hicn_interest_set_name(format, (hicn_header_t *) probe, name); +} + +static inline bool messageHandler_IsAProbe(const uint8_t *packet){ + uint16_t src_prt; + uint16_t dst_prt; + hicn_packet_get_src_port ((const hicn_header_t *) packet, &src_prt); + hicn_packet_get_dst_port ((const hicn_header_t *) packet, &dst_prt); + + if(dst_prt == BFD_PORT){ + //interest probe + return true; + } + + if(src_prt == BFD_PORT){ + //data (could be a probe) + uint32_t expiry_time; + hicn_data_get_expiry_time ((const hicn_header_t *) packet, &expiry_time); + if(expiry_time == 0){ + //this is a probe + return true; + } + } + + return false; } #endif // Metis_metis_MessageHandler |