From 94350c13fe983a7cfb99dafecb0d029ed58361bf Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Wed, 27 Nov 2019 09:05:39 +0100 Subject: [HICN-420] MAP-Me code refactoring & face manager changes in support of mobility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ifde50b4c161d1bda1326f18b705f575e539aea71 Signed-off-by: Jordan Augé --- .../interfaces/android_utility/android_utility.c | 2 +- ctrl/facemgr/src/interfaces/bonjour/bonjour.c | 2 +- ctrl/facemgr/src/interfaces/dummy/dummy.c | 2 +- .../facemgr/src/interfaces/hicn_light/hicn_light.c | 71 ++++++++++++++++++++-- ctrl/facemgr/src/interfaces/netlink/netlink.c | 27 ++++---- .../priority_controller/priority_controller.c | 4 +- 6 files changed, 87 insertions(+), 21 deletions(-) (limited to 'ctrl/facemgr/src/interfaces') diff --git a/ctrl/facemgr/src/interfaces/android_utility/android_utility.c b/ctrl/facemgr/src/interfaces/android_utility/android_utility.c index e7c73df8b..47d3cd106 100644 --- a/ctrl/facemgr/src/interfaces/android_utility/android_utility.c +++ b/ctrl/facemgr/src/interfaces/android_utility/android_utility.c @@ -71,7 +71,7 @@ int au_finalize(interface_t * interface) return 0; } -int au_on_event(interface_t * interface, const facelet_t * facelet) +int au_on_event(interface_t * interface, facelet_t * facelet) { /* * This function is responsible to annotate every face we receive with the diff --git a/ctrl/facemgr/src/interfaces/bonjour/bonjour.c b/ctrl/facemgr/src/interfaces/bonjour/bonjour.c index 10e757245..40b7f5f90 100644 --- a/ctrl/facemgr/src/interfaces/bonjour/bonjour.c +++ b/ctrl/facemgr/src/interfaces/bonjour/bonjour.c @@ -133,7 +133,7 @@ ERR_MALLOC: * We reuse the callback to be triggered upon external events * TODO: move to a cleaner interface architecture later... */ -int bj_on_event(interface_t * interface, const facelet_t * facelet) +int bj_on_event(interface_t * interface, facelet_t * facelet) { bj_data_t * data = (bj_data_t*)interface->data; diff --git a/ctrl/facemgr/src/interfaces/dummy/dummy.c b/ctrl/facemgr/src/interfaces/dummy/dummy.c index 25180465e..69c336e57 100644 --- a/ctrl/facemgr/src/interfaces/dummy/dummy.c +++ b/ctrl/facemgr/src/interfaces/dummy/dummy.c @@ -106,7 +106,7 @@ int dummy_callback(interface_t * interface) return 0; } -int dummy_on_event(interface_t * interface, const facelet_t * facelet) +int dummy_on_event(interface_t * interface, facelet_t * facelet) { dummy_data_t * data = (dummy_data_t*)interface->data; UNUSED(data); diff --git a/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c b/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c index cb1a0040d..71243aea1 100644 --- a/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c +++ b/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c @@ -286,7 +286,7 @@ int hl_finalize(interface_t * interface) return 0; } -int hl_on_event(interface_t * interface, const facelet_t * facelet) +int hl_on_event(interface_t * interface, facelet_t * facelet) { hc_face_t hc_face; hc_route_t route; @@ -399,6 +399,7 @@ int hl_on_event(interface_t * interface, const facelet_t * facelet) } } } + free(route_array); break; @@ -447,9 +448,71 @@ int hl_on_event(interface_t * interface, const facelet_t * facelet) ret = -FACELET_ERROR_REASON_UNSPECIFIED_ERROR; goto ERR; } + facelet_set_admin_state_status(facelet, FACELET_ATTR_STATUS_CLEAN); INFO("Admin state updated"); } +#ifdef WITH_POLICY + if (facelet_get_netdevice_type_status(facelet) == FACELET_ATTR_STATUS_DIRTY) { + hc_face.face = *face; + hc_face_t * face_found; + + rc = hc_face_get(data->s, &hc_face, &face_found); + if (rc < 0) { + ERROR("Failed to find face\n"); + goto ERR; + } + if (!face_found) { + ERROR("Face to update has not been found"); + goto ERR; + } + char conn_id_or_name[SYMBOLIC_NAME_LEN]; + snprintf(conn_id_or_name, SYMBOLIC_NAME_LEN, "%d", face_found->id); + free(face_found); + + netdevice_type_t netdevice_type; + if (facelet_get_netdevice_type(facelet, &netdevice_type) < 0) { + ERROR("Failed to retrieve facelet netdevice_type"); + goto ERR; + } + + /* Encode netdevice type into tags */ + policy_tags_t tags = POLICY_TAGS_EMPTY; + if (facelet_has_netdevice_type(facelet)) { + netdevice_type_t netdevice_type; + if (facelet_get_netdevice_type(facelet, &netdevice_type) < 0) { + ERROR("error getting netdevice_type"); + goto ERR; + } + + + switch(netdevice_type) { + case NETDEVICE_TYPE_UNDEFINED: + case NETDEVICE_TYPE_LOOPBACK: + break; + case NETDEVICE_TYPE_WIRED: + policy_tags_add(&tags, POLICY_TAG_WIRED); + break; + case NETDEVICE_TYPE_WIFI: + policy_tags_add(&tags, POLICY_TAG_WIFI); + break; + case NETDEVICE_TYPE_CELLULAR: + policy_tags_add(&tags, POLICY_TAG_CELLULAR); + break; + default: + goto ERR; + } + } + //face->tags = tags; + + if (hc_connection_set_tags(data->s, conn_id_or_name, tags) < 0) { + ERROR("Failed to update tags"); + goto ERR; + } + facelet_set_netdevice_type_status(facelet, FACELET_ATTR_STATUS_CLEAN); + INFO("Tags updated"); + } if (facelet_get_priority_status(facelet) == FACELET_ATTR_STATUS_DIRTY) { + INFO("Updating priority..."); hc_face.face = *face; hc_face_t * face_found; @@ -472,12 +535,15 @@ int hl_on_event(interface_t * interface, const facelet_t * facelet) goto ERR; } + INFO("Changing connection %s priority to %d", conn_id_or_name, priority); if (hc_connection_set_priority(data->s, conn_id_or_name, priority) < 0) { ERROR("Failed to update priority"); goto ERR; } + facelet_set_priority_status(facelet, FACELET_ATTR_STATUS_CLEAN); INFO("Priority updated"); } +#endif /* WITH_POLICY */ break; default: @@ -568,8 +634,6 @@ int hl_callback(interface_t * interface, int fd, void * unused) /* We can ignore faces on localhost */ facelet_t * facelet = facelet_create_from_face(&f->face); - char facelet_s[MAXSZ_FACELET]; - facelet_snprintf(facelet_s, MAXSZ_FACELET, facelet); foreach_route(r, data->polled_routes) { if (r->face_id != f->id) continue; @@ -596,7 +660,6 @@ int hl_callback(interface_t * interface, int fd, void * unused) facelet_add_route(facelet, route); } - facelet_snprintf(facelet_s, MAXSZ_FACELET, facelet); facelet_set_event(facelet, FACELET_EVENT_GET); interface_raise_event(interface, facelet); } diff --git a/ctrl/facemgr/src/interfaces/netlink/netlink.c b/ctrl/facemgr/src/interfaces/netlink/netlink.c index 62d4fdf90..4d92f2511 100644 --- a/ctrl/facemgr/src/interfaces/netlink/netlink.c +++ b/ctrl/facemgr/src/interfaces/netlink/netlink.c @@ -309,13 +309,6 @@ int parse_addr(struct nlmsghdr * h, facelet_t ** facelet, return 0; } -#if 0 /* Not working for v6 */ - if (interface_name) { - assert(tba[IFLA_IFNAME]); - snprintf(interface_name, interface_name_size, "%s", (char*)RTA_DATA(tba[IFLA_IFNAME])); - } -#endif - /* See comment in parse_link */ if (interface_address) { assert(tba[IFA_ADDRESS]); @@ -324,7 +317,7 @@ int parse_addr(struct nlmsghdr * h, facelet_t ** facelet, netdevice_t * netdevice = netdevice_create_from_index(ifa->ifa_index); if (!netdevice) { - ERROR("[netlink.parse_addr] error creating netdevice '%s'", interface_name); + ERROR("[netlink.parse_addr] error creating netdevice from index '%d'", ifa->ifa_index); goto ERR_ND; } @@ -432,9 +425,9 @@ int nl_callback(interface_t * interface, int fd, void * unused) break; } - //DEBUG("Interface %s: address was removed", interface_name); + DEBUG("Interface %s: address was removed", interface_name); if (facelet) { - facelet_set_event(facelet, FACELET_EVENT_DELETE); + facelet_set_event(facelet, FACELET_EVENT_SET_DOWN); facelet_set_status(facelet, FACELET_STATUS_CLEAN); interface_raise_event(interface, facelet); } @@ -453,7 +446,7 @@ int nl_callback(interface_t * interface, int fd, void * unused) break; } - //DEBUG("Interface %s: new address was assigned: %s", interface_name, interface_address); + DEBUG("Interface %s: new address was assigned: %s", interface_name, interface_address); if (facelet) { facelet_set_event(facelet, FACELET_EVENT_UPDATE); @@ -465,6 +458,8 @@ int nl_callback(interface_t * interface, int fd, void * unused) case RTM_DELLINK: { + /* This does not always seem to be called, hence we rely on + * down, not running */ facelet_t * facelet = NULL; char interface_name[IFNAMSIZ]; if (parse_link(h, &facelet, interface_name, IFNAMSIZ, @@ -473,7 +468,7 @@ int nl_callback(interface_t * interface, int fd, void * unused) break; } - //DEBUG("Network interface %s was removed", interface_name); + DEBUG("Network interface %s was removed", interface_name); if (!facelet) break; @@ -499,7 +494,7 @@ int nl_callback(interface_t * interface, int fd, void * unused) // UP RUNNING // UP NOT RUNNING // DOWN NOT RUNNING -#if 0 +#if 1 DEBUG("New network interface %s, state: %s %s", interface_name, up ? "UP" : "DOWN", running ? "RUNNING" : "NOT_RUNNING"); @@ -523,7 +518,13 @@ int nl_callback(interface_t * interface, int fd, void * unused) interface_raise_event(interface, facelet6); #endif } else { +#if 1 + facelet_set_event(facelet, FACELET_EVENT_SET_DOWN); + facelet_set_status(facelet, FACELET_STATUS_CLEAN); + interface_raise_event(interface, facelet); +#else facelet_free(facelet); +#endif } break; } diff --git a/ctrl/facemgr/src/interfaces/priority_controller/priority_controller.c b/ctrl/facemgr/src/interfaces/priority_controller/priority_controller.c index a64796857..5452c0e85 100644 --- a/ctrl/facemgr/src/interfaces/priority_controller/priority_controller.c +++ b/ctrl/facemgr/src/interfaces/priority_controller/priority_controller.c @@ -30,6 +30,8 @@ #include "../../common.h" #include "../../interface.h" +#define PC_DEFAULT_PORT 9533 + typedef struct { int fd; } pc_data_t; @@ -58,7 +60,7 @@ int priority_controller_initialize(interface_t * interface, void * cfg) memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr("127.0.0.1"); - addr.sin_port = htons(9533); + addr.sin_port = htons(PC_DEFAULT_PORT); if (bind(data->fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { INFO("Priority controller socket bind error"); -- cgit 1.2.3-korg