diff options
Diffstat (limited to 'ctrl/libhicnctrl/includes/hicn/ctrl/objects')
13 files changed, 622 insertions, 0 deletions
diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects/active_interface.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/active_interface.h new file mode 100644 index 000000000..56a1d8cd5 --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/active_interface.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021-2022 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 objects/active_interface.h + * \brief Route. + */ + +#ifndef HICNCTRL_OBJECTS_ACTIVE_INTERFACE_H +#define HICNCTRL_OBJECTS_ACTIVE_INTERFACE_H + +#include <hicn/ctrl/objects/face.h> + +typedef struct { + hicn_ip_prefix_t prefix; + netdevice_flags_t interface_types; +} hc_active_interface_t; + +#define foreach_active_interface(VAR, data) \ + foreach_type(hc_active_interface_t, VAR, data) + +// XXX WRONG +#define MAXSZ_HC_ACTIVE_INTERFACE_ \ + MAXSZ_FACE_ID + 1 + MAXSZ_COST + 1 + MAXSZ_IP_ADDRESS + 1 + MAXSZ_LEN +#define MAXSZ_HC_ACTIVE_INTERFACE MAXSZ_HC_ACTIVE_INTERFACE_ + NULLTERM + +int hc_active_interface_snprintf(char *s, size_t size, + const hc_active_interface_t *active_interface); +int hc_active_interface_validate(const hc_active_interface_t *active_interface, + bool allow_partial); + +#endif diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects/base.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/base.h new file mode 100644 index 000000000..fc40f680e --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/base.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2021-2022 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 base.h + * \brief Base definitions for objects. + */ +#ifndef HICNCTRL_OBJECTS_BASE +#define HICNCTRL_OBJECTS_BASE + +#define INTERFACE_LEN 16 + +#endif /* HICNCTRL_OBJECTS_BASE */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects/cache.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/cache.h new file mode 100644 index 000000000..1f8691be6 --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/cache.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021-2022 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 objects/cache.h + * \brief Cache. + */ + +#ifndef HICNCTRL_OBJECTS_CACHE_H +#define HICNCTRL_OBJECTS_CACHE_H + +typedef struct { + uint8_t serve; // 1 = on, 0 = off + uint8_t store; // 1 = on, 0 = off +} hc_cache_t; + +typedef struct { + bool store; + bool serve; + size_t cs_size; + size_t num_stale_entries; +} hc_cache_info_t; + +int hc_cache_snprintf(char *s, size_t size, const hc_cache_info_t *cache_info); + +#endif /* HICNCTRL_OBJECTS_CACHE_H */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects/connection.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/connection.h new file mode 100644 index 000000000..771b48c20 --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/connection.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021-2022 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 objects/connection.h + * \brief Connection. + */ + +#ifndef HICNCTRL_OBJECTS_CONNECTION_H +#define HICNCTRL_OBJECTS_CONNECTION_H + +#include <stdint.h> +#include <hicn/face.h> + +#include "base.h" + +/* + * NOTE : + * - interface_name is mainly used to derive listeners from connections, + * but is not itself used to create connections. + */ +typedef struct { + uint32_t id; /* Kr. */ + char name[SYMBOLIC_NAME_LEN]; /* K.w */ + char interface_name[INTERFACE_LEN]; /* Kr. */ + netdevice_type_t netdevice_type; /* .r. */ + face_type_t type; /* .rw */ + int family; /* .rw */ + hicn_ip_address_t local_addr; /* .rw */ + uint16_t local_port; /* .rw */ + hicn_ip_address_t remote_addr; /* .rw */ + uint16_t remote_port; /* .rw */ + face_state_t admin_state; /* .rw */ + uint32_t priority; /* .rw */ + policy_tags_t tags; /* .rw */ + face_state_t state; /* .r. */ +} hc_connection_t; + +#define foreach_connection(VAR, data) foreach_type(hc_connection_t, VAR, data) + +#define MAXSZ_HC_CONNECTION_ \ + MAXSZ_FACE_STATE_ + INTERFACE_LEN + SPACE + 2 * MAXSZ_URL_ + \ + MAXSZ_FACE_TYPE_ + SPACES(3) +#define MAXSZ_HC_CONNECTION MAXSZ_HC_CONNECTION_ + NULLTERM + +int hc_connection_validate(const hc_connection_t *connection, + bool allow_partial); +int hc_connection_cmp(const hc_connection_t *c1, const hc_connection_t *c2); +int hc_connection_snprintf(char *s, size_t size, + const hc_connection_t *connection); + +#endif /* HICNCTRL_OBJECTS_CONNECTION_H */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects/face.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/face.h new file mode 100644 index 000000000..1aa122f37 --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/face.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021 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 objects/face.h + * \brief Face. + * + * A face is an abstraction introduced by the control library to abstract the + * forwarder implementation details. It encompasses connections and listeners + * and ensures the right dependencies are enforced, eg that we always have a + * listener when a connection is created. + */ + +#ifndef HICNCTRL_OBJECTS_FACE_H +#define HICNCTRL_OBJECTS_FACE_H + +#include <hicn/face.h> + +#include "base.h" + +typedef face_t hc_face_t; + +#define foreach_face(VAR, data) foreach_type(hc_face_t, VAR, data) + +#define MAX_FACE_ID 255 +#define MAXSZ_FACE_ID_ 3 +#define MAXSZ_FACE_ID MAXSZ_FACE_ID_ + NULLTERM +#define MAXSZ_FACE_NAME_ SYMBOLIC_NAME_LEN +#define MAXSZ_FACE_NAME MAXSZ_FACE_NAME_ + NULLTERM + +#define MAXSZ_HC_FACE_ \ + MAXSZ_FACE_ID_ + MAXSZ_FACE_NAME_ + MAXSZ_FACE_ + 5 + HOTFIXMARGIN +#define MAXSZ_HC_FACE MAXSZ_HC_FACE_ + NULLTERM + +int hc_face_snprintf(char *s, size_t size, const hc_face_t *face); + +#endif /* HICNCTRL_OBJECTS_FACE_H */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects/listener.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/listener.h new file mode 100644 index 000000000..0fb74f558 --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/listener.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021-2022 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 objects/listener.h + * \brief Listener. + */ + +#ifndef HICNCTRL_OBJECTS_LISTENER_H +#define HICNCTRL_OBJECTS_LISTENER_H + +#include <stddef.h> // offsetof +#include <stdint.h> +#include <hicn/face.h> + +#include "base.h" + +// FIXME the listener should not require any port for hICN... +typedef struct { + char name[SYMBOLIC_NAME_LEN]; /* K.w */ + char interface_name[INTERFACE_LEN]; /* Kr. */ + uint32_t id; /* Kr. */ + face_type_t type; /* .rw */ + int family; /* .rw */ + hicn_ip_address_t local_addr; /* .rw */ + uint16_t local_port; /* .rw */ +} hc_listener_t; + +int hc_listener_validate(const hc_listener_t *listener, bool allow_partial); +int hc_listener_cmp(const hc_listener_t *l1, const hc_listener_t *l2); + +#define foreach_listener(VAR, data) foreach_type(hc_listener_t, VAR, data) + +#define MAXSZ_HC_LISTENER_ \ + INTERFACE_LEN + SPACE + MAXSZ_URL_ + SPACE + MAXSZ_FACE_TYPE_ +#define MAXSZ_HC_LISTENER MAXSZ_HC_LISTENER_ + NULLTERM + +int hc_listener_snprintf(char *s, size_t size, const hc_listener_t *listener); + +#endif /* HICNCTRL_OBJECTS_LISTENER_H */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects/mapme.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/mapme.h new file mode 100644 index 000000000..3eda1bfaa --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/mapme.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021-2023 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 objects/mapme.h + * \brief MAP-Me. + */ + +#ifndef HICNCTRL_OBJECTS_MAPME_H +#define HICNCTRL_OBJECTS_MAPME_H + +typedef enum { + MAPME_TARGET_ENABLE, + MAPME_TARGET_DISCOVERY, + MAPME_TARGET_TIMESCALE, + MAPME_TARGET_RETX, +} mapme_target_t; + +static inline mapme_target_t mapme_target_from_str(char *mapme_target_str) { + if (strcasecmp(mapme_target_str, "enable") == 0) + return MAPME_TARGET_ENABLE; + else if (strcasecmp(mapme_target_str, "discovery") == 0) + return MAPME_TARGET_DISCOVERY; + else if (strcasecmp(mapme_target_str, "timescale") == 0) + return MAPME_TARGET_TIMESCALE; + else + return MAPME_TARGET_RETX; +} + +#define MAX_MAPME_ARG_LEN 30 + +typedef struct { + mapme_target_t target; + // Command argument stored as a string + // before being parsed into 'enabled' or 'timescale' + char unparsed_arg[MAX_MAPME_ARG_LEN]; + + uint8_t enabled; // 1 = on, 0 = off + uint32_t timescale; // Milliseconds + + hicn_ip_address_t address; + uint8_t family; + uint8_t len; + uint32_t face_id; +} hc_mapme_t; + +#endif /* HICNCTRL_OBJECTS_MAPME_H */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects/policy.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/policy.h new file mode 100644 index 000000000..437387e4a --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/policy.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021-2022 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 objects/policy.h + * \brief Policy. + */ + +#ifndef HICNCTRL_OBJECTS_POLICY_H +#define HICNCTRL_OBJECTS_POLICY_H + +typedef struct { + int family; /* Krw */ + hicn_ip_address_t remote_addr; /* krw */ + uint8_t len; /* krw */ + hicn_policy_t policy; /* .rw */ +} hc_policy_t; + +#define foreach_policy(VAR, data) foreach_type(hc_policy_t, VAR, data) + +/* TODO */ +#define MAXSZ_HC_POLICY_ 0 +#define MAXSZ_HC_POLICY MAXSZ_HC_POLICY_ + NULLTERM + +int hc_policy_snprintf(char *s, size_t size, hc_policy_t *policy); +int hc_policy_validate(const hc_policy_t *policy); + +#endif /* HICNCTRL_OBJECTS_POLICY_H */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects/punting.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/punting.h new file mode 100644 index 000000000..d18e596b1 --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/punting.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021-2022 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 objects/punting.h + * \brief Punting + */ + +#ifndef HICNCTRL_OBJECTS_PUNTING_H +#define HICNCTRL_OBJECTS_PUNTING_H + +typedef struct { + face_id_t face_id; /* Kr. */ // XXX listener id, could be NULL for all ? + int family; /* Krw */ + hicn_ip_address_t prefix; /* krw */ + u8 prefix_len; /* krw */ +} hc_punting_t; + +int hc_punting_validate(const hc_punting_t *punting); +int hc_punting_cmp(const hc_punting_t *c1, const hc_punting_t *c2); + +#define foreach_punting(VAR, data) foreach_type(hc_punting_t, VAR, data) + +#define MAXSZ_HC_PUNTING_ 0 +#define MAXSZ_HC_PUNTING MAXSZ_HC_PUNTING_ + NULLTERM + +int hc_punting_snprintf(char *s, size_t size, hc_punting_t *punting); + +#endif /* HICNCTRL_OBJECTS_PUNTING_H */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects/route.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/route.h new file mode 100644 index 000000000..fb68e9430 --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/route.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021-2022 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 objects/route.h + * \brief Route. + */ + +#ifndef HICNCTRL_OBJECTS_ROUTE_H +#define HICNCTRL_OBJECTS_ROUTE_H + +#include <hicn/ctrl/objects/face.h> + +typedef struct { + face_id_t face_id; /* Kr. ID (used when face and face_name == NULL) */ + char face_name[SYMBOLIC_NAME_LEN]; /* Kr. a name or an ID (if integer), used + if face is NULL */ + int family; /* Krw */ + hicn_ip_address_t remote_addr; /* krw */ + uint8_t len; /* krw */ + uint16_t cost; /* .rw */ + hc_face_t face; /* use by default if not NULL, otherwise look at face_name, + then face_id */ +} hc_route_t; + +#define foreach_route(VAR, data) foreach_type(hc_route_t, VAR, data) + +#define MAX_COST 65535 +#define MAXSZ_COST 5 +#define MAX_LEN 255 +#define MAXSZ_LEN 3 + +#define MAXSZ_HC_ROUTE_ \ + MAXSZ_FACE_ID + 1 + MAXSZ_COST + 1 + MAXSZ_IP_ADDRESS + 1 + MAXSZ_LEN +#define MAXSZ_HC_ROUTE MAXSZ_HC_ROUTE_ + NULLTERM + +int hc_route_snprintf(char *s, size_t size, const hc_route_t *route); +int hc_route_validate(const hc_route_t *route, bool allow_partial); + +#endif /* HICNCTRL_OBJECTS_ROUTE_H */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects/stats.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/stats.h new file mode 100644 index 000000000..31c590dee --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/stats.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021-2022 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 objects/stats.h + * \brief Stats. + */ + +#ifndef HICNCTRL_OBJECTS_STATS_H +#define HICNCTRL_OBJECTS_STATS_H + +#define MAXSZ_HC_STATS 600 + +typedef hicn_light_stats_t hc_stats_t; +typedef connection_stats_t hc_face_stats_t; + +#endif /* HICNCTRL_OBJECTS_STATS_H */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects/strategy.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/strategy.h new file mode 100644 index 000000000..208f4620b --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/strategy.h @@ -0,0 +1,46 @@ + +/* + * Copyright (c) 2021-2022 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 objects/strategy.h + * \brief Strategy. + */ + +#ifndef HICNCTRL_OBJECTS_STRATEGY_H +#define HICNCTRL_OBJECTS_STRATEGY_H + +#include <hicn/strategy.h> + +#define MAXSZ_STRATEGY_NAME 255 + +typedef struct { + // The name is not set by the controller + // but populated by the daemon + char name[MAXSZ_STRATEGY_NAME]; + strategy_type_t type; + hicn_ip_address_t address, local_address; + int family, local_family; + u8 len, local_len; +} hc_strategy_t; + +#define foreach_strategy(VAR, data) foreach_type(hc_strategy_t, VAR, data) + +#define MAXSZ_HC_STRATEGY_ MAXSZ_STRATEGY_NAME +#define MAXSZ_HC_STRATEGY MAXSZ_HC_STRATEGY_ + NULLTERM + +int hc_strategy_snprintf(char *s, size_t size, const hc_strategy_t *strategy); + +#endif /* HICNCTRL_OBJECTS_STRATEGY_H */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects/subscription.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/subscription.h new file mode 100644 index 000000000..861341160 --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/subscription.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2021-2022 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 objects/subscription.h + * \brief Subscription. + */ + +#ifndef HICNCTRL_OBJECTS_SUBSCRIPTION_H +#define HICNCTRL_OBJECTS_SUBSCRIPTION_H + +#include <limits.h> +#include <stddef.h> +#include <hicn/ctrl/object_type.h> + +#undef PUNTING // TODO(eloparco): Undefined to avoid collisions + // Fix the collision + +// Used only to create 'hc_topic_t' +typedef struct { +#define _(x) char x; + foreach_object_type +#undef _ +} object_offset_t; + +// Flags for topic subscriptions +typedef enum { +#define _(x) TOPIC_##x = (1 << offsetof(object_offset_t, x)), + foreach_object_type +#undef _ + TOPIC_ALL = INT_MAX, +} hc_topic_t; + +static inline hc_object_type_t object_from_topic(hc_topic_t topic) { +#define _(x) \ + if (topic == TOPIC_##x) return OBJECT_TYPE_##x; + foreach_object_type +#undef _ + return OBJECT_TYPE_UNDEFINED; +} + +static inline hc_topic_t topic_from_object_type(hc_object_type_t object_type) { + if (object_type == OBJECT_TYPE_UNDEFINED) return TOPIC_ALL; +#define _(x) \ + if (object_type == OBJECT_TYPE_##x) return TOPIC_##x; + foreach_object_type +#undef _ + return TOPIC_UNDEFINED; +} + +#define NUM_TOPICS OBJECT_TYPE_N // Because a topic is created for each object +#define ALL_TOPICS ~0 + +// Subscriptions +typedef uint32_t hc_topics_t; +typedef struct { + hc_topics_t topics; +} hc_subscription_t; + +#if 0 +typedef struct { + netdevice_type_t interface_type; +} hc_event_interface_update_t; + +typedef struct { + ip_prefix_t prefix; + netdevice_type_t interface_type; +} hc_event_active_interface_update_t; +#endif + +#endif /* HICNCTRL_OBJECTS_SUBSCRIPTION_H */ |