diff options
author | Jordan Augé <jordan.auge+fdio@cisco.com> | 2019-07-26 23:20:30 +0200 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2019-07-29 17:13:35 +0200 |
commit | 0a1c6b5565e20167d1f1f33a5a8b597f420b18b0 (patch) | |
tree | 98c5da8f231fbd3dc2ce6502040e29c8333d9ffc /hicn-light/src/hicn/core | |
parent | 05ca0aa8f612ee48fb66d4dbebe596b7f1e03181 (diff) |
[HICN-252] Add per-application policy framework to hicn-light forwarder
Change-Id: I0531cd7a7de179581295ae34766c81cd9cf3e172
Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Co-authored-by: Mauro Sardara <msardara@cisco.com>
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 | 24 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/connectionTable.c | 2 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/connectionTable.h | 2 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/forwarder.c | 42 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/forwarder.h | 38 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/mapMe.c | 210 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/mapMe.h | 17 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/message.c | 1 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/messageHandler.h | 73 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/name.c | 6 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/name.h | 4 |
12 files changed, 313 insertions, 152 deletions
diff --git a/hicn-light/src/hicn/core/connection.c b/hicn-light/src/hicn/core/connection.c index d9b2770b9..2f50dbf7f 100644 --- a/hicn-light/src/hicn/core/connection.c +++ b/hicn-light/src/hicn/core/connection.c @@ -27,6 +27,9 @@ #include <parc/algol/parc_Memory.h> #include <parc/assert/parc_Assert.h> +#ifdef WITH_POLICY +#include <hicn/utils/policy.h> +#endif /* WITH_POLICY */ struct connection { const AddressPair *addressPair; @@ -46,6 +49,11 @@ struct connection { // file/hicnLightControl) this value is set to false so // that a base station can not disable wldr at the client Wldr *wldr; + +#ifdef WITH_POLICY + policy_tags_t tags; +#endif /* WITH_POLICY */ + }; Connection *connection_Create(IoOperations *ops) { @@ -68,6 +76,10 @@ Connection *connection_Create(IoOperations *ops) { /* By default, a connection will aim at the UP state */ connection_SetAdminState(conn, CONNECTION_STATE_UP); +#ifdef WITH_POLICY + conn->tags = POLICY_TAGS_EMPTY; +#endif /* WITH_POLICY */ + return conn; } @@ -316,3 +328,37 @@ void connection_SetAdminState(Connection *conn, connection_state_t admin_state) return; ioOperations_SetAdminState(conn->ops, admin_state); } + +#ifdef WITH_POLICY + +void connection_AddTag(Connection *conn, policy_tag_t tag) +{ + policy_tags_add(&conn->tags, tag); +} + +void connection_RemoveTag(Connection *conn, policy_tag_t tag) +{ + policy_tags_remove(&conn->tags, tag); +} + +policy_tags_t connection_GetTags(const Connection *conn) +{ + return conn->tags; +} + +void connection_SetTags(Connection *conn, policy_tags_t tags) +{ + conn->tags = tags; +} + +void connection_ClearTags(Connection *conn) +{ + conn->tags = POLICY_TAGS_EMPTY; +} + +int connection_HasTag(const Connection *conn, policy_tag_t tag) +{ + return policy_tags_has(conn->tags, tag); +} + +#endif /* WITH_POLICY */ diff --git a/hicn-light/src/hicn/core/connection.h b/hicn-light/src/hicn/core/connection.h index df1c780a1..c007a1a26 100644 --- a/hicn-light/src/hicn/core/connection.h +++ b/hicn-light/src/hicn/core/connection.h @@ -29,6 +29,21 @@ #include <hicn/io/ioOperations.h> #include <hicn/utils/address.h> +#ifdef WITH_MAPME +typedef enum { + CONNECTION_EVENT_CREATE, + CONNECTION_EVENT_DELETE, + CONNECTION_EVENT_UPDATE, + CONNECTION_EVENT_SET_UP, + CONNECTION_EVENT_SET_DOWN, +} connection_event_t; + +#endif /* WITH_MAPME */ + +#ifdef WITH_POLICY +#include <hicn/utils/policy.h> +#endif /* WITH_POLICY */ + // packet types for probing #define PACKET_TYPE_PROBE_REQUEST 5 #define PACKET_TYPE_PROBE_REPLY 6 @@ -168,4 +183,13 @@ connection_state_t connection_GetAdminState(const Connection *conn); void connection_SetAdminState(Connection *conn, connection_state_t admin_state); +#ifdef WITH_POLICY +void connection_AddTag(Connection *conn, policy_tag_t tag); +void connection_RemoveTag(Connection *conn, policy_tag_t tag); +policy_tags_t connection_GetTags(const Connection *conn); +void connection_SetTags(Connection *conn, policy_tags_t tags); +void connection_ClearTags(Connection *conn); +int connection_HasTag(const Connection *conn, policy_tag_t tag); +#endif /* WITH_POLICY */ + #endif // connection_h diff --git a/hicn-light/src/hicn/core/connectionTable.c b/hicn-light/src/hicn/core/connectionTable.c index 0a1301328..f8589c12b 100644 --- a/hicn-light/src/hicn/core/connectionTable.c +++ b/hicn-light/src/hicn/core/connectionTable.c @@ -206,7 +206,7 @@ const Connection *connectionTable_FindByAddressPair(ConnectionTable *table, return (Connection *)parcHashCodeTable_Get(table->indexByAddressPair, pair); } -const Connection *connectionTable_FindById(ConnectionTable *table, +const Connection *connectionTable_FindById(const ConnectionTable *table, unsigned id) { parcAssertNotNull(table, "Parameter table must be non-null"); return (Connection *)parcHashCodeTable_Get(table->storageTableById, &id); diff --git a/hicn-light/src/hicn/core/connectionTable.h b/hicn-light/src/hicn/core/connectionTable.h index bd8f553c2..548ef8e6e 100644 --- a/hicn-light/src/hicn/core/connectionTable.h +++ b/hicn-light/src/hicn/core/connectionTable.h @@ -84,7 +84,7 @@ const Connection *connectionTable_FindByAddressPair(ConnectionTable *table, * @abstract Find a connection by its numeric id. * @return NULL if not found */ -const Connection *connectionTable_FindById(ConnectionTable *table, unsigned id); +const Connection *connectionTable_FindById(const ConnectionTable *table, unsigned id); /** * @function connectionTable_GetEntries diff --git a/hicn-light/src/hicn/core/forwarder.c b/hicn-light/src/hicn/core/forwarder.c index c8cac98ba..c9527bb49 100644 --- a/hicn-light/src/hicn/core/forwarder.c +++ b/hicn-light/src/hicn/core/forwarder.c @@ -313,7 +313,11 @@ Dispatcher *forwarder_GetDispatcher(Forwarder *forwarder) { return forwarder->dispatcher; } +#ifdef WITH_POLICY +ConnectionTable *forwarder_GetConnectionTable(const Forwarder *forwarder) { +#else ConnectionTable *forwarder_GetConnectionTable(Forwarder *forwarder) { +#endif /* WITH_POLICY */ parcAssertNotNull(forwarder, "Parameter must be non-null"); return forwarder->connectionTable; } @@ -412,6 +416,7 @@ bool forwarder_AddOrUpdateRoute(Forwarder *forwarder, return res; } + bool forwarder_RemoveRoute(Forwarder *forwarder, remove_route_command *control, unsigned ifidx) { parcAssertNotNull(forwarder, "Parameter hicn-light must be non-null"); @@ -421,6 +426,25 @@ bool forwarder_RemoveRoute(Forwarder *forwarder, remove_route_command *control, return messageProcessor_RemoveRoute(forwarder->processor, control, ifidx); } +#ifdef WITH_POLICY + +bool forwarder_AddOrUpdatePolicy(Forwarder *forwarder, + add_policy_command *control) { + parcAssertNotNull(forwarder, "Parameter forwarder must be non-null"); + parcAssertNotNull(control, "Parameter control must be non-null"); + + return messageProcessor_AddOrUpdatePolicy(forwarder->processor, control); +} + +bool forwarder_RemovePolicy(Forwarder *forwarder, remove_policy_command *control) { + parcAssertNotNull(forwarder, "Parameter forwarder must be non-null"); + parcAssertNotNull(control, "Parameter control must be non-null"); + + return messageProcessor_RemovePolicy(forwarder->processor, control); +} + +#endif /* WITH_POLICY */ + void forwarder_RemoveConnectionIdFromRoutes(Forwarder *forwarder, unsigned connectionId) { parcAssertNotNull(forwarder, "Parameter hicn-light must be non-null"); @@ -504,16 +528,22 @@ FIB *forwarder_getFib(Forwarder *forwarder) { return messageProcessor_getFib(forwarder->processor); } -void forwarder_onConnectionAdded(Forwarder *forwarder, const Connection *conn) { - mapMe_onConnectionAdded(forwarder->mapme, conn); +void forwarder_onConnectionEvent(Forwarder *forwarder, const Connection *conn, connection_event_t event) { +#ifdef WITH_POLICY + messageProcessor_onConnectionEvent(forwarder->processor, conn, event); +#else + mapMe_onConnectionEvent(forwarder->mapme, conn, event); +#endif /* WITH_POLICY */ } -void forwarder_onConnectionRemoved(Forwarder *forwarder, - const Connection *conn) {} - -void forwarder_ProcessMapMe(Forwarder *forwarder, uint8_t *msgBuffer, +void forwarder_ProcessMapMe(Forwarder *forwarder, const uint8_t *msgBuffer, unsigned conn_id) { mapMe_Process(forwarder->mapme, msgBuffer, conn_id); } +MapMe * +forwarder_getMapmeInstance(const Forwarder *forwarder) { + return forwarder->mapme; +} + #endif /* WITH_MAPME */ diff --git a/hicn-light/src/hicn/core/forwarder.h b/hicn-light/src/hicn/core/forwarder.h index c1b279d2e..b8e68f0e4 100644 --- a/hicn-light/src/hicn/core/forwarder.h +++ b/hicn-light/src/hicn/core/forwarder.h @@ -156,7 +156,11 @@ ListenerSet *forwarder_GetListenerSet(Forwarder *forwarder); * @retval null An error * */ +#ifdef WITH_POLICY +ConnectionTable *forwarder_GetConnectionTable(const Forwarder *forwarder); +#else ConnectionTable *forwarder_GetConnectionTable(Forwarder *forwarder); +#endif /* WITH_POLICY */ /** * Returns a Tick-based clock @@ -209,6 +213,20 @@ bool forwarder_AddOrUpdateRoute(Forwarder *forwarder, bool forwarder_RemoveRoute(Forwarder *forwarder, remove_route_command *control, unsigned ifidx); +#ifdef WITH_POLICY +/** + * @function forwarder_AddOrUpdatePolicy + * @abstract Adds or updates a policy on the message processor + */ +bool forwarder_AddOrUpdatePolicy(Forwarder *forwarder, add_policy_command *control); + +/** + * @function forwarder_RemovePolicy + * @abstract Removes a policy from the message processor + */ +bool forwarder_RemovePolicy(Forwarder *forwarder, remove_policy_command *control); +#endif /* WITH_POLICY */ + /** * Removes a connection id from all routes */ @@ -260,23 +278,14 @@ hicn_socket_helper_t *forwarder_GetHicnSocketHelper(Forwarder *forwarder); FIB *forwarder_getFib(Forwarder *forwarder); /** - * @function forwarder_onConnectionAdded + * @function forwarder_onConnectionEvent * @abstract Callback fired upon addition of a new connection through the * control protocol. * @param [in] forwarder - Pointer to the hICN forwarder. * @param [in] conn - Pointer to the newly added connection. + * @param [in] event - Connection event */ -void forwarder_onConnectionAdded(Forwarder *forwarder, const Connection *conn); - -/** - * @function forwarder_onConnectionRemoved - * @abstract Callback fired upon removal of a connection through the control - * protocol. - * @param [in] forwarder - Pointer to the hICN forwarder. - * @param [in] conn - Pointer to the removed connection. - */ -void forwarder_onConnectionRemoved(Forwarder *forwarder, - const Connection *conn); +void forwarder_onConnectionEvent(Forwarder *forwarder, const Connection *conn, connection_event_t event); /** * @function forwarder_ProcessMapMe @@ -286,9 +295,12 @@ void forwarder_onConnectionRemoved(Forwarder *forwarder, * @param [in] msgBuffer - MAP-Me buffer * @param [in] conn_id - Ingress connection id */ -void forwarder_ProcessMapMe(Forwarder *forwarder, uint8_t *msgBuffer, +void forwarder_ProcessMapMe(Forwarder *forwarder, const uint8_t *msgBuffer, unsigned conn_id); +struct mapme; +struct mapme * forwarder_getMapmeInstance(const Forwarder *forwarder); + #endif /* WITH_MAPME */ #endif // forwarder_h diff --git a/hicn-light/src/hicn/core/mapMe.c b/hicn-light/src/hicn/core/mapMe.c index 74ff1ed96..865841f67 100644 --- a/hicn-light/src/hicn/core/mapMe.c +++ b/hicn-light/src/hicn/core/mapMe.c @@ -24,6 +24,7 @@ #include <hicn/core/mapMe.h> #include <stdio.h> // printf +#include <hicn/core/connection.h> #include <hicn/core/connectionList.h> #include <hicn/core/forwarder.h> #include <hicn/core/logger.h> @@ -87,8 +88,6 @@ static MapMe MapMeDefault = {.retx = MAPME_DEFAULT_RETX, /******************************************************************************/ -#include <hicn/core/connection.h> - bool mapMe_Init(MapMe **mapme, Forwarder *forwarder) { *mapme = malloc(sizeof(MapMe)); if (!mapme) goto ERR_MALLOC; @@ -98,12 +97,9 @@ bool mapMe_Init(MapMe **mapme, Forwarder *forwarder) { (*mapme)->forwarder = forwarder; - /* Install hook on Face events to onConnectionAdded */ - // see. config/configuration.c - - /* Install hook for signalization processing. See : - * - io/hicnListener.c - * - src/core/connection.{c,h} + /* As there is no face table and no related events, we need to install hooks + * in various places in the forwarder, where both control commands and + * signalization are processed. */ return true; @@ -117,20 +113,20 @@ ERR_MALLOC: ******************************************************************************/ #define INVALID_SEQ 0 -#define INIT_SEQ 1 +#define INIT_SEQ 0 typedef struct { uint32_t seq; PARCHashMap *nexthops; /* Update/Notification heuristic */ - Ticks lastAckedUpdate; // XXX This is only for producer !!! + Ticks lastAckedUpdate; } MapMeTFIB; static MapMeTFIB *mapMeTFIB_Create() { MapMeTFIB *tfib; tfib = malloc(sizeof(MapMeTFIB)); if (!tfib) goto ERR_MALLOC; - tfib->seq = 0; + tfib->seq = INIT_SEQ; tfib->lastAckedUpdate = 0; tfib->nexthops = parcHashMap_Create(); if (!tfib->nexthops) goto ERR_HASHMAP; @@ -239,7 +235,7 @@ static Message *mapMe_createMessage(const MapMe *mapme, const Name *name, INFO(mapme, "[MAP-Me] Creating MAP-Me packet"); size_t len = hicn_mapme_create_packet(icmp_pkt, &prefix, params); - if (len != 0) { + if (len == 0) { ERR(mapme, "[MAP-Me] Failed to create mapme packet through lib"); goto ERR_CREATE; } @@ -341,7 +337,6 @@ static bool mapMe_setFacePending(const MapMe *mapme, const Name *name, // set the timer. // - in the network, we always forward an IU, and never an IN if (is_first || send) { - // XXX mapme_params_t params = { .protocol = IPPROTO_IPV6, .type = is_first ? mapMe_getTypeFromHeuristic(mapme, fibEntry) : UPDATE, @@ -357,7 +352,11 @@ static bool mapMe_setFacePending(const MapMe *mapme, const Name *name, const Connection *conn = connectionTable_FindById((ConnectionTable *)table, conn_id); if (conn) { - INFO(mapme, "[MAP-Me] Sending MAP-Me packet"); + const Name * name = message_GetName(special_interest); + char * name_str = name_ToString(name); + INFO(mapme, "[MAP-Me] Sending MAP-Me packet name=%s seq=%d conn=%d", + name_str, params.seq, conn_id); + free(name_str); connection_ReSend(conn, special_interest, NOT_A_NOTIFICATION); } else { INFO(mapme, "[MAP-Me] Stopped retransmissions as face went down"); @@ -439,42 +438,85 @@ static bool mapMe_hasLocalNextHops(const MapMe *mapme, /* * Callback called everytime a new connection is created by the control protocol */ -void mapMe_onConnectionAdded(const MapMe *mapme, const Connection *conn_added) { - /* bool ret; */ - FibEntryList *fiblist; +void mapMe_onConnectionEvent(const MapMe *mapme, const Connection *conn_added, connection_event_t event) { + switch(event) { + case CONNECTION_EVENT_CREATE: + case CONNECTION_EVENT_SET_UP: + { + FibEntryList *fiblist; + + /* Ignore local connections corresponding to applications for now */ + if (connection_IsLocal(conn_added)) + return; + + unsigned conn_added_id = connection_GetConnectionId(conn_added); + INFO(mapme, "[MAP-Me] New connection %d", conn_added_id); + + /* + * Iterate on FIB to find locally served prefix + * Ideally, we want to avoid a FIB scan everytime a face is added/removed + */ + fiblist = forwarder_GetFibEntries(mapme->forwarder); + for (size_t i = 0; i < fibEntryList_Length(fiblist); i++) { + FibEntry *fibEntry = (FibEntry *)fibEntryList_Get(fiblist, i); + const Name *name = fibEntry_GetPrefix(fibEntry); + + /* Skip entries that have no local connection as next hop */ + if (!mapMe_hasLocalNextHops(mapme, fibEntry)) + continue; + + /* This entry corresponds to a locally served prefix, set + * Special Interest */ + if (!TFIB(fibEntry)) /* Create TFIB associated to FIB entry */ + mapMe_CreateTFIB(fibEntry); + TFIB(fibEntry)->seq++; + + char *name_str = name_ToString(name); + INFO(mapme, "[MAP-Me] sending IU/IN for name %s on connection %d", name_str, + conn_added_id); + free(name_str); + + mapMe_setFacePending(mapme, name, fibEntry, conn_added_id, true, true, 0); + } + break; + } + case CONNECTION_EVENT_DELETE: + case CONNECTION_EVENT_SET_DOWN: + case CONNECTION_EVENT_UPDATE: + break; + } +} +#ifdef WITH_POLICY +void mapMe_onPolicyUpdate(const MapMe *mapme, const Connection *conn_selected, FibEntry * fibEntry) +{ /* Ignore local connections corresponding to applications for now */ - if (connection_IsLocal(conn_added)) return; + if (connection_IsLocal(conn_selected)) + return; - unsigned conn_added_id = connection_GetConnectionId(conn_added); - INFO(mapme, "[MAP-Me] New connection %d", conn_added_id); + unsigned conn_selected_id = connection_GetConnectionId(conn_selected); + INFO(mapme, "[MAP-Me] New connection %d", conn_selected_id); - /* - * Iterate on FIB to find locally served prefix - * Ideally, we want to avoid a FIB scan everytime a face is added/removed - */ - fiblist = forwarder_GetFibEntries(mapme->forwarder); - for (size_t i = 0; i < fibEntryList_Length(fiblist); i++) { - FibEntry *fibEntry = (FibEntry *)fibEntryList_Get(fiblist, i); - const Name *name = fibEntry_GetPrefix(fibEntry); - - /* Skip entries that have no local connection as next hop */ - if (!mapMe_hasLocalNextHops(mapme, fibEntry)) continue; - - /* This entry corresponds to a locally served prefix, set - * Special Interest */ - if (!TFIB(fibEntry)) /* Create TFIB associated to FIB entry */ - mapMe_CreateTFIB(fibEntry); - TFIB(fibEntry)->seq++; - - char *name_str = name_ToString(name); - INFO(mapme, "[MAP-Me] sending IU/IN for name %s on connection %d", name_str, - conn_added_id); - free(name_str); - - mapMe_setFacePending(mapme, name, fibEntry, conn_added_id, true, true, 0); - } + const Name *name = fibEntry_GetPrefix(fibEntry); + + /* Skip entries that have no local connection as next hop */ + if (!mapMe_hasLocalNextHops(mapme, fibEntry)) + return; + + /* This entry corresponds to a locally served prefix, set + * Special Interest */ + if (!TFIB(fibEntry)) /* Create TFIB associated to FIB entry */ + mapMe_CreateTFIB(fibEntry); + TFIB(fibEntry)->seq++; + + char *name_str = name_ToString(name); + INFO(mapme, "[MAP-Me] sending IU/IN for name %s on connection %d", name_str, + conn_selected_id); + free(name_str); + + mapMe_setFacePending(mapme, name, fibEntry, conn_selected_id, true, true, 0); } +#endif /* WITH_POLICY */ /*------------------------------------------------------------------------------ * Special Interest handling @@ -497,6 +539,7 @@ static bool mapMe_onSpecialInterest(const MapMe *mapme, bool rv; Name *name = name_CreateFromPacket(msgBuffer, MessagePacketType_Interest); + name_setLen(name, prefix->len); char *name_str = name_ToString(name); INFO(mapme, "[MAP-Me] Ack'ed Special Interest on connection %d - prefix=%s type=XX " @@ -530,12 +573,34 @@ static bool mapMe_onSpecialInterest(const MapMe *mapme, */ strategy_type fwdStrategy = LAST_STRATEGY_VALUE; + /* + * It might also be due to the announcement of a more specific prefix. In + * that case we need to perform a FIB lookup to find the next hops to which + * the message should be propagated. + */ +#ifdef WITH_POLICY + fibEntry = fibEntry_Create(name, fwdStrategy, mapme->forwarder); +#else fibEntry = fibEntry_Create(name, fwdStrategy); - fibEntry_AddNexthopByConnectionId(fibEntry, conn_in_id); +#endif /* WITH_POLICY */ + FibEntry *lpm = fib_LPM(fib, name); mapMe_CreateTFIB(fibEntry); - TFIB(fibEntry)->seq = seq; // INIT_SEQ; fib_Add(fib, fibEntry); - return true; // with proper seq, we are done + if (!lpm) { + TFIB(fibEntry)->seq = seq; + fibEntry_AddNexthop(fibEntry, conn_in_id); + return true; + } + + /* + * We make a clone of the FIB entry (zero'ing the sequence number ?) with + * the more specific name, and proceed as usual. Worst case we clone the + * default route... + */ + const NumberSet *lpm_nexthops = fibEntry_GetNexthops(lpm); + for (size_t i = 0; i < numberSet_Length(lpm_nexthops); i++) { + fibEntry_AddNexthop(fibEntry, numberSet_GetItem(lpm_nexthops, i)); + } } else if (!TFIB(fibEntry)) { /* Create TFIB associated to FIB entry */ @@ -613,7 +678,7 @@ static bool mapMe_onSpecialInterest(const MapMe *mapme, INFO(mapme, "[MAP-Me] - Replaced next hops by connection %d", conn_id); fibEntry_RemoveNexthopByConnectionId(fibEntry, conn_id); } - fibEntry_AddNexthopByConnectionId(fibEntry, conn_in_id); + fibEntry_AddNexthop(fibEntry, conn_in_id); INFO(mapme, "[MAP-Me] - (2/3) processing next hops"); bool complete = true; @@ -658,7 +723,7 @@ static bool mapMe_onSpecialInterest(const MapMe *mapme, INFO(mapme, "[MAP-Me] - Adding multipath next hop on connection %d", conn_in_id); - fibEntry_AddNexthopByConnectionId(fibEntry, conn_in_id); + fibEntry_AddNexthop(fibEntry, conn_in_id); } else { // seq < fibSeq /* @@ -688,11 +753,19 @@ void mapMe_onSpecialInterestAck(const MapMe *mapme, const uint8_t *msgBuffer, mapme_params_t *params) { INFO(mapme, "[MAP-Me] Receive IU/IN Ack on connection %d", conn_in_id); - const Name *name = - name_CreateFromPacket(msgBuffer, MessagePacketType_Interest); + const Name * name = + name_CreateFromPacket(msgBuffer, MessagePacketType_ContentObject); + name_setLen(name, prefix->len); + char * name_str = name_ToString(name); + INFO(mapme, "[MAP-Me] Received ack for name prefix=%s seq=%d on conn id=%d", + name_str, params->seq, conn_in_id); + free(name_str); FIB *fib = forwarder_getFib(mapme->forwarder); FibEntry *fibEntry = fib_Contains(fib, name); + if (!fibEntry) { + return; + } parcAssertNotNull(fibEntry, "No corresponding FIB entry for name contained in IU Ack"); @@ -758,23 +831,21 @@ void mapMe_onSpecialInterestAck(const MapMe *mapme, const uint8_t *msgBuffer, /* * Returns true iif the message corresponds to a MAP-Me packet */ -bool mapMe_isMapMe(const uint8_t *msgBuffer) { - uint8_t next_header = messageHandler_NextHeaderType(msgBuffer); - - const uint8_t *icmp_ptr; - if (next_header == IPPROTO_ICMP) { - icmp_ptr = msgBuffer + IPV4_HDRLEN; - } else if (next_header == IPPROTO_ICMPV6) { - icmp_ptr = msgBuffer + IPV6_HDRLEN; - } else { - return false; +bool mapMe_isMapMe(const uint8_t *packet) { + hicn_mapme_header_t * mapme = (hicn_mapme_header_t*)packet; + + switch(HICN_IP_VERSION(packet)) { + case 4: + if (mapme->v4.ip.protocol != IPPROTO_ICMP) + return false; + return HICN_IS_MAPME(mapme->v4.icmp_rd.type, mapme->v4.icmp_rd.code); + case 6: + if (mapme->v6.ip.nxt != IPPROTO_ICMPV6) + return false; + return HICN_IS_MAPME(mapme->v6.icmp_rd.type, mapme->v6.icmp_rd.code); + default: + return false; } - - uint8_t type = ((_icmp_header_t *)icmp_ptr)->type; - uint8_t code = ((_icmp_header_t *)icmp_ptr)->code; - if (HICN_IS_MAPME(type, code)) return true; - - return false; } /** @@ -794,7 +865,6 @@ void mapMe_Process(const MapMe *mapme, const uint8_t *msgBuffer, mapme_params_t params; hicn_mapme_parse_packet(msgBuffer, &prefix, ¶ms); - // XXX Dispatch message dependenging on type switch (params.type) { case UPDATE: case NOTIFICATION: @@ -805,7 +875,7 @@ void mapMe_Process(const MapMe *mapme, const uint8_t *msgBuffer, mapMe_onSpecialInterestAck(mapme, msgBuffer, conn_id, &prefix, ¶ms); break; default: - printf("E:Unknown message\n"); + ERR(mapme, "[MAP-Me] Unknown message"); break; } } diff --git a/hicn-light/src/hicn/core/mapMe.h b/hicn-light/src/hicn/core/mapMe.h index a99d4710b..7ea90d299 100644 --- a/hicn-light/src/hicn/core/mapMe.h +++ b/hicn-light/src/hicn/core/mapMe.h @@ -26,9 +26,9 @@ #include <stdbool.h> #include <stdint.h> -#include <hicn/io/hicnListener.h> - #include <hicn/hicn.h> +#include <hicn/core/forwarder.h> +#include <hicn/core/connection.h> #include <hicn/utils/commands.h> struct mapme; @@ -63,14 +63,23 @@ void mapMe_Process(const MapMe *mapme, const uint8_t *msgBuffer, unsigned conn_id); /** - * @function mapMe_onConnectionAdded + * @function mapMe_onConnectionEvent * @abstract Callback following the addition of the face though the control * protocol. * @discussion This callback triggers the sending of control packets by MAP-Me. * @param [in] mapme - Pointer to the MAP-Me data structure. * @param [in] conn - The newly added connection. + * @param [in] event - Connection event + */ +void mapMe_onConnectionEvent(const MapMe *mapme, const Connection *conn, connection_event_t event); + +#ifdef WITH_POLICY + +/** + * @function mapMe_onPolicyUpdate */ -void mapMe_onConnectionAdded(const MapMe *mapme, const Connection *conn); +void mapMe_onPolicyUpdate(const MapMe *mapme, const Connection *conn_added, FibEntry * fibEntry); +#endif /* WITH_POLICY */ /** * @function mapMe_getNextHops diff --git a/hicn-light/src/hicn/core/message.c b/hicn-light/src/hicn/core/message.c index b0140eda4..5d0d04ae4 100644 --- a/hicn-light/src/hicn/core/message.c +++ b/hicn-light/src/hicn/core/message.c @@ -220,7 +220,6 @@ Message *message_CreateWldrNotification(Message *original, uint16_t expected, // set notification stuff. messageHandler_SetWldrNotification( message->messageHead, original->messageHead, expected, lastReceived); - // XXX: what about the checksum? return message; } diff --git a/hicn-light/src/hicn/core/messageHandler.h b/hicn-light/src/hicn/core/messageHandler.h index c1fc0481a..74535d80f 100644 --- a/hicn-light/src/hicn/core/messageHandler.h +++ b/hicn-light/src/hicn/core/messageHandler.h @@ -55,6 +55,11 @@ #include <hicn/core/forwarder.h> +#ifdef WITH_MAPME +#include <hicn/core/mapMe.h> +#include <hicn/socket/api.h> +#endif /* WITH_MAPME */ + #define CONNECTION_ID_UNDEFINED -1 static inline uint8_t messageHandler_GetIPPacketType(const uint8_t *message) { @@ -168,76 +173,32 @@ static inline uint8_t messageHandler_NextHeaderType(const uint8_t *message) { /* Forward declarations */ static inline void * messageHandler_GetSource(const uint8_t *message); - -/* Helpers */ - -// NOTE: this function is generalized from the one in hICN listener and takes a -// forwarder as parameter -static inline -const Connection * -_getConnectionFromPacket(Forwarder * forwarder, Address * localAddress, Address *packetSourceAddress) -{ - if (!packetSourceAddress) - return NULL; - - AddressPair *pair = addressPair_Create(localAddress, - packetSourceAddress); - const Connection * conn = connectionTable_FindByAddressPair( - forwarder_GetConnectionTable(forwarder), pair); - addressPair_Release(&pair); - - return conn; -} - -static inline -Address * -_createAddressFromPacket(const uint8_t *msgBuffer) -{ - Address *packetAddr = NULL; - if (messageHandler_GetIPPacketType(msgBuffer) == IPv6_TYPE) { - struct sockaddr_in6 addr_in6; - addr_in6.sin6_family = AF_INET6; - addr_in6.sin6_port = htons(1234); - addr_in6.sin6_flowinfo = 0; - addr_in6.sin6_scope_id = 0; - memcpy(&addr_in6.sin6_addr, - (struct in6_addr *)messageHandler_GetSource(msgBuffer), 16); - packetAddr = addressCreateFromInet6(&addr_in6); - } else if (messageHandler_GetIPPacketType(msgBuffer) == IPv4_TYPE) { - struct sockaddr_in addr_in; - addr_in.sin_family = AF_INET; - addr_in.sin_port = htons(1234); - memcpy(&addr_in.sin_addr, - (struct in_addr *)messageHandler_GetSource(msgBuffer), 4); - packetAddr = addressCreateFromInet(&addr_in); - } - return packetAddr; -} - -/* Hooks */ - -/* ... */ +static inline void *messageHandler_GetDestination(const uint8_t *message); /* Main hook handler */ /** * \brief Handle incoming messages * \param [in] forwarder - Reference to the Forwarder instance - * \param [in] connection_id - A hint on the connection ID on which the packet - * was received, CONNECTION_ID_UNDEFINED (-1) otherwise. - * \param [in] localAddress - Local listener address - * \param [in] messsage - Buffer possibly containing a hooked message + * \param [in] packet - Packet buffer + * \param [in] conn_id - A hint on the connection ID on which the packet + * was received * \return Flag indicating whether the packet matched a hook and was * (successfully or not) processed. */ static inline bool messageHandler_handleHooks(Forwarder * forwarder, - int connection_id, Address * localAddress, const uint8_t * message) + const uint8_t * packet, int conn_id) { - /* ... */ +#ifdef WITH_MAPME + if (mapMe_isMapMe(packet)) { + forwarder_ProcessMapMe(forwarder, packet, conn_id); + goto END; + } +#endif /* WITH_MAPME */ return false; -#if 0 // Enable and jump here when a handler has successfully processed the packet +#if 1 // Enable and jump here when a handler has successfully processed the packet END: return true; #endif diff --git a/hicn-light/src/hicn/core/name.c b/hicn-light/src/hicn/core/name.c index ed3432ec5..8cf8dacbc 100644 --- a/hicn-light/src/hicn/core/name.c +++ b/hicn-light/src/hicn/core/name.c @@ -234,3 +234,9 @@ char *name_ToString(const Name *name) { void name_setLen(const Name *name, uint8_t len) { nameBitvector_setLen(name->content_name, len); } + +#ifdef WITH_POLICY +uint32_t name_GetSuffix(const Name * name) { + return name->segment; +} +#endif /* WITH_POLICY */ diff --git a/hicn-light/src/hicn/core/name.h b/hicn-light/src/hicn/core/name.h index 8ab75cf05..4eb80cf36 100644 --- a/hicn-light/src/hicn/core/name.h +++ b/hicn-light/src/hicn/core/name.h @@ -102,4 +102,8 @@ void name_setLen(const Name *name, uint8_t len); Name *name_CreateFromAddress(address_type addressType, union commandAddr addr, uint8_t len); +#ifdef WITH_POLICY +uint32_t name_GetSuffix(const Name * name); +#endif /* WITH_POLICY */ + #endif // name_h |