diff --git a/switchlink/.gitignore b/switchlink/.gitignore new file mode 100644 index 0000000..9a699dd --- /dev/null +++ b/switchlink/.gitignore @@ -0,0 +1 @@ +switchlink_db_test/ diff --git a/switchlink/BUILD.bazel b/switchlink/BUILD.bazel index 9a54ed2..3a6c75d 100644 --- a/switchlink/BUILD.bazel +++ b/switchlink/BUILD.bazel @@ -13,6 +13,23 @@ OVS_DEFINES = select({ "//conditions:default": [], }) +cc_library( + name = "switchlink", + srcs = [ + ":switchlink_address", + ":switchlink_db", + ":switchlink_globals", + ":switchlink_link", + ":switchlink_main", + ":switchlink_neigh", + ":switchlink_route", + ":switchlink_utils", + ] + select({ + "//flags:es2k_target": [":switchlink_validate_driver"], + "//conditions:default": [], + }), +) + krnlmon_cc_library( name = "switchlink_address", srcs = ["switchlink_address.c"], @@ -38,15 +55,14 @@ cc_test( krnlmon_cc_library( name = "switchlink_db", - srcs = [ - "switchlink_db.c", - "switchlink_db.h", - "switchlink_db_int.h", - ], + srcs = ["switchlink_db.c"], + hdrs = ["switchlink_db.h"], deps = [ + ":switchlink_db_int", + ":switchlink_db_types", + ":switchlink_defs", ":switchlink_int", ":switchlink_link_types", - ":switchlink_types", "@target_utils", "@target_utils//:tommyds", "@target_utils//:xxhash", @@ -54,27 +70,48 @@ krnlmon_cc_library( ) krnlmon_cc_library( - name = "switchlink_globals", - srcs = ["switchlink_globals.c"], - hdrs = ["switchlink_globals.h"], - deps = [":switchlink_types"], + name = "switchlink_db_int", + hdrs = ["switchlink_db_int.h"], + deps = [ + ":switchlink_db_types", + "@target_utils//:tommyds", + ], ) krnlmon_cc_library( - name = "switchlink_types", - srcs = ["switchlink.h"], # rename + name = "switchlink_db_types", + hdrs = ["switchlink_db_types.h"], deps = [ + ":switchlink_link_types", + ":switchlink_types", + ], +) + +krnlmon_cc_library( + name = "switchlink_defs", + hdrs = ["switchlink_defs.h"], + deps = [ + ":switchlink_types", "//switchutils:switch_utils", ], ) +krnlmon_cc_library( + name = "switchlink_globals", + srcs = ["switchlink_globals.c"], + hdrs = ["switchlink_globals.h"], + deps = [ + ":switchlink_defs", + ], +) + krnlmon_cc_library( name = "switchlink_handlers", srcs = ["switchlink_handlers.h"], linkopts = ["-lnl-3"], deps = [ ":switchlink_db", - ":switchlink_types", + ":switchlink_defs", "//:krnlmon_options", "@nl-3", ], @@ -90,11 +127,11 @@ krnlmon_cc_library( srcs = ["switchlink_link.c"], defines = OVS_DEFINES, deps = [ + ":switchlink_defs", ":switchlink_globals", ":switchlink_handlers", ":switchlink_int", ":switchlink_link_types", - ":switchlink_types", "//:krnlmon_options", "//switchutils:switch_log", ], @@ -129,8 +166,8 @@ krnlmon_cc_library( "-lpthread", ], deps = [ + ":switchlink_defs", ":switchlink_int", - ":switchlink_types", "//switchutils:switch_log", "@nl-3", "@target_sys", @@ -141,10 +178,11 @@ krnlmon_cc_library( name = "switchlink_neigh", srcs = ["switchlink_neigh.c"], deps = [ + ":switchlink_db", + ":switchlink_defs", ":switchlink_globals", ":switchlink_handlers", ":switchlink_int", - ":switchlink_types", "//switchutils:switch_log", ], ) @@ -182,6 +220,11 @@ cc_test( ], ) +krnlmon_cc_library( + name = "switchlink_types", + hdrs = ["switchlink_types.h"], +) + krnlmon_cc_library( name = "switchlink_utils", srcs = ["switchlink_utils.c"], @@ -198,20 +241,3 @@ krnlmon_cc_library( ":switchlink_int", ], ) - -cc_library( - name = "switchlink", - srcs = [ - ":switchlink_address", - ":switchlink_db", - ":switchlink_globals", - ":switchlink_link", - ":switchlink_main", - ":switchlink_neigh", - ":switchlink_route", - ":switchlink_utils", - ] + select({ - "//flags:es2k_target": [":switchlink_validate_driver"], - "//conditions:default": [], - }), -) diff --git a/switchlink/CMakeLists.txt b/switchlink/CMakeLists.txt index 7128f3d..a20a377 100644 --- a/switchlink/CMakeLists.txt +++ b/switchlink/CMakeLists.txt @@ -10,7 +10,8 @@ add_library(switchlink_o OBJECT switchlink_db.c switchlink_db.h switchlink_db_int.h - switchlink.h + switchlink_db_types.h + switchlink_defs.h switchlink_globals.c switchlink_globals.h switchlink_handlers.h @@ -21,6 +22,7 @@ add_library(switchlink_o OBJECT switchlink_main.h switchlink_neigh.c switchlink_route.c + switchlink_types.h switchlink_utils.c switchlink_utils.h $ diff --git a/switchlink/sai/BUILD.bazel b/switchlink/sai/BUILD.bazel index 30ce796..74da0a3 100644 --- a/switchlink/sai/BUILD.bazel +++ b/switchlink/sai/BUILD.bazel @@ -23,7 +23,7 @@ krnlmon_cc_library( ":switchlink_init_sai", "//switchlink:switchlink_db", "//switchlink:switchlink_handlers", - "//switchlink:switchlink_types", + "//switchlink:switchlink_defs", ], ) @@ -92,7 +92,7 @@ krnlmon_cc_library( deps = [ "//:krnlmon_options", "//switchlink:switchlink_db", - "//switchlink:switchlink_types", + "//switchlink:switchlink_defs", "//switchlink:switchlink_utils", "//switchsai:saiinternal", ], diff --git a/switchlink/switchlink_db.c b/switchlink/switchlink_db.c index 8f7451f..b541456 100644 --- a/switchlink/switchlink_db.c +++ b/switchlink/switchlink_db.c @@ -23,8 +23,8 @@ #include #include -#include "switchlink.h" #include "switchlink_db_int.h" +#include "switchlink_defs.h" #include "switchlink_int.h" #include "switchlink_link_types.h" #include "xxHash/xxhash.h" diff --git a/switchlink/switchlink_db.h b/switchlink/switchlink_db.h index c3e73c1..7c36be3 100644 --- a/switchlink/switchlink_db.h +++ b/switchlink/switchlink_db.h @@ -19,127 +19,10 @@ #ifndef __SWITCHLINK_DB_H__ #define __SWITCHLINK_DB_H__ -#include - -#include "switchlink.h" -#include "switchlink_link_types.h" - -#define SWITCHLINK_INTERFACE_NAME_LEN_MAX 32 -#define SWITCHLINK_ECMP_NUM_MEMBERS_MAX 16 - -typedef enum { - SWITCHLINK_DB_STATUS_SUCCESS, - SWITCHLINK_DB_STATUS_ITEM_NOT_FOUND, -} switchlink_db_status_t; - -typedef struct switchlink_db_tuntap_info_ { - char ifname[SWITCHLINK_INTERFACE_NAME_LEN_MAX]; - uint32_t ifindex; - switchlink_handle_t tunp_h; - switchlink_mac_addr_t mac_addr; - switchlink_link_type_t link_type; - // struct tuntap_flags { - // bool _enabled; - // uint8_t _mode; - //} flags; -} switchlink_db_tuntap_info_t; - -typedef struct switchlink_db_interface_info_ { - char ifname[SWITCHLINK_INTERFACE_NAME_LEN_MAX]; - uint32_t ifindex; - uint16_t port_id; - switchlink_handle_t intf_h; - switchlink_intf_type_t intf_type; - switchlink_link_type_t link_type; - switchlink_handle_t vrf_h; - switchlink_handle_t bridge_h; - switchlink_handle_t stp_h; - switchlink_handle_t lag_h; - switchlink_handle_t vlan_member_h; - switchlink_handle_t stp_port_h; - switchlink_mac_addr_t mac_addr; - switchlink_ip_addr_t intf_ip; - struct interface_flags { - bool ipv4_unicast_enabled; - bool ipv6_unicast_enabled; - bool ipv4_multicast_enabled; - bool ipv6_multicast_enabled; - uint8_t ipv4_urpf_mode; - uint8_t ipv6_urpf_mode; - } flags; - // LAG attributes - uint8_t bond_mode; - uint8_t oper_state; - uint32_t active_slave; -} switchlink_db_interface_info_t; - -typedef struct switchlink_db_bridge_info_ { - switchlink_handle_t bridge_h; - switchlink_handle_t vrf_h; - switchlink_handle_t stp_h; - switchlink_mac_addr_t mac_addr; -} switchlink_db_bridge_info_t; - -typedef struct switchlink_db_neigh_info_ { - switchlink_handle_t vrf_h; - switchlink_handle_t nhop_h; - switchlink_handle_t intf_h; - switchlink_ip_addr_t ip_addr; - switchlink_mac_addr_t mac_addr; -} switchlink_db_neigh_info_t; - -typedef struct switchlink_db_nexthop_info_ { - switchlink_handle_t vrf_h; - switchlink_handle_t nhop_h; -#if defined(DPDK_TARGET) - switchlink_handle_t nhop_member_h; -#endif - switchlink_handle_t intf_h; - switchlink_ip_addr_t ip_addr; - uint32_t using_by; -} switchlink_db_nexthop_info_t; - -typedef struct switchlink_db_ecmp_info_ { - switchlink_handle_t ecmp_h; - uint8_t num_nhops; - switchlink_handle_t nhops[SWITCHLINK_ECMP_NUM_MEMBERS_MAX]; - switchlink_handle_t nhop_member_handles[SWITCHLINK_ECMP_NUM_MEMBERS_MAX]; -} switchlink_db_ecmp_info_t; - -typedef struct switchlink_db_route_info_ { - switchlink_handle_t vrf_h; - switchlink_ip_addr_t ip_addr; - bool ecmp; - switchlink_handle_t nhop_h; - switchlink_handle_t intf_h; -} switchlink_db_route_info_t; - -typedef struct switchlink_db_tunnel_interface_info_ { - char ifname[SWITCHLINK_INTERFACE_NAME_LEN_MAX]; - switchlink_handle_t orif_h; - switchlink_handle_t urif_h; - switchlink_handle_t tnl_term_h; - switchlink_ip_addr_t src_ip; - switchlink_ip_addr_t dst_ip; - switchlink_link_type_t link_type; - uint32_t ifindex; - uint32_t vni_id; - uint16_t dst_port; - uint8_t ttl; -} switchlink_db_tunnel_interface_info_t; - -/*** LAG member structure ***/ -typedef struct switchlink_db_lag_member_info_ { - char ifname[SWITCHLINK_INTERFACE_NAME_LEN_MAX]; - uint32_t ifindex; - uint8_t oper_state; - uint8_t slave_state; - switchlink_handle_t lag_member_h; - switchlink_handle_t lag_h; - switchlink_mac_addr_t mac_addr; - switchlink_mac_addr_t perm_hwaddr; - bool is_lacp_member; -} switchlink_db_lag_member_info_t; +#include + +#include "switchlink_db_types.h" +#include "switchlink_defs.h" /*** interface ***/ extern switchlink_db_status_t switchlink_db_add_interface( diff --git a/switchlink/switchlink_db_int.h b/switchlink/switchlink_db_int.h index 2a230eb..7b98a76 100644 --- a/switchlink/switchlink_db_int.h +++ b/switchlink/switchlink_db_int.h @@ -18,6 +18,9 @@ #ifndef __SWITCHLINK_DB_INT_H__ #define __SWITCHLINK_DB_INT_H__ +#include + +#include "switchlink_db_types.h" #include "tommyds/tommyhashlin.h" #include "tommyds/tommylist.h" #include "tommyds/tommytrieinp.h" diff --git a/switchlink/switchlink_db_types.h b/switchlink/switchlink_db_types.h new file mode 100644 index 0000000..7737785 --- /dev/null +++ b/switchlink/switchlink_db_types.h @@ -0,0 +1,145 @@ +/* + * Copyright 2013-present Barefoot Networks, Inc. + * Copyright 2022-2024 Intel Corporation. + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ + +#ifndef __SWITCHLINK_DB_TYPES_H__ +#define __SWITCHLINK_DB_TYPES_H__ + +#include +#include + +#include "switchlink_link_types.h" +#include "switchlink_types.h" + +#define SWITCHLINK_INTERFACE_NAME_LEN_MAX 32 +#define SWITCHLINK_ECMP_NUM_MEMBERS_MAX 16 + +typedef enum { + SWITCHLINK_DB_STATUS_SUCCESS, + SWITCHLINK_DB_STATUS_ITEM_NOT_FOUND, +} switchlink_db_status_t; + +typedef struct switchlink_db_tuntap_info_ { + char ifname[SWITCHLINK_INTERFACE_NAME_LEN_MAX]; + uint32_t ifindex; + switchlink_handle_t tunp_h; + switchlink_mac_addr_t mac_addr; + switchlink_link_type_t link_type; + // struct tuntap_flags { + // bool _enabled; + // uint8_t _mode; + //} flags; +} switchlink_db_tuntap_info_t; + +typedef struct switchlink_db_interface_info_ { + char ifname[SWITCHLINK_INTERFACE_NAME_LEN_MAX]; + uint32_t ifindex; + uint16_t port_id; + switchlink_handle_t intf_h; + switchlink_intf_type_t intf_type; + switchlink_link_type_t link_type; + switchlink_handle_t vrf_h; + switchlink_handle_t bridge_h; + switchlink_handle_t stp_h; + switchlink_handle_t lag_h; + switchlink_handle_t vlan_member_h; + switchlink_handle_t stp_port_h; + switchlink_mac_addr_t mac_addr; + switchlink_ip_addr_t intf_ip; + struct interface_flags { + bool ipv4_unicast_enabled; + bool ipv6_unicast_enabled; + bool ipv4_multicast_enabled; + bool ipv6_multicast_enabled; + uint8_t ipv4_urpf_mode; + uint8_t ipv6_urpf_mode; + } flags; + // LAG attributes + uint8_t bond_mode; + uint8_t oper_state; + uint32_t active_slave; +} switchlink_db_interface_info_t; + +typedef struct switchlink_db_bridge_info_ { + switchlink_handle_t bridge_h; + switchlink_handle_t vrf_h; + switchlink_handle_t stp_h; + switchlink_mac_addr_t mac_addr; +} switchlink_db_bridge_info_t; + +typedef struct switchlink_db_neigh_info_ { + switchlink_handle_t vrf_h; + switchlink_handle_t nhop_h; + switchlink_handle_t intf_h; + switchlink_ip_addr_t ip_addr; + switchlink_mac_addr_t mac_addr; +} switchlink_db_neigh_info_t; + +typedef struct switchlink_db_nexthop_info_ { + switchlink_handle_t vrf_h; + switchlink_handle_t nhop_h; +#if defined(DPDK_TARGET) + switchlink_handle_t nhop_member_h; +#endif + switchlink_handle_t intf_h; + switchlink_ip_addr_t ip_addr; + uint32_t using_by; +} switchlink_db_nexthop_info_t; + +typedef struct switchlink_db_ecmp_info_ { + switchlink_handle_t ecmp_h; + uint8_t num_nhops; + switchlink_handle_t nhops[SWITCHLINK_ECMP_NUM_MEMBERS_MAX]; + switchlink_handle_t nhop_member_handles[SWITCHLINK_ECMP_NUM_MEMBERS_MAX]; +} switchlink_db_ecmp_info_t; + +typedef struct switchlink_db_route_info_ { + switchlink_handle_t vrf_h; + switchlink_ip_addr_t ip_addr; + bool ecmp; + switchlink_handle_t nhop_h; + switchlink_handle_t intf_h; +} switchlink_db_route_info_t; + +typedef struct switchlink_db_tunnel_interface_info_ { + char ifname[SWITCHLINK_INTERFACE_NAME_LEN_MAX]; + switchlink_handle_t orif_h; + switchlink_handle_t urif_h; + switchlink_handle_t tnl_term_h; + switchlink_ip_addr_t src_ip; + switchlink_ip_addr_t dst_ip; + switchlink_link_type_t link_type; + uint32_t ifindex; + uint32_t vni_id; + uint16_t dst_port; + uint8_t ttl; +} switchlink_db_tunnel_interface_info_t; + +/*** LAG member structure ***/ +typedef struct switchlink_db_lag_member_info_ { + char ifname[SWITCHLINK_INTERFACE_NAME_LEN_MAX]; + uint32_t ifindex; + uint8_t oper_state; + uint8_t slave_state; + switchlink_handle_t lag_member_h; + switchlink_handle_t lag_h; + switchlink_mac_addr_t mac_addr; + switchlink_mac_addr_t perm_hwaddr; + bool is_lacp_member; +} switchlink_db_lag_member_info_t; + +#endif /* __SWITCHLINK_DB_TYPES_H__ */ diff --git a/switchlink/switchlink_defs.h b/switchlink/switchlink_defs.h new file mode 100644 index 0000000..554b5af --- /dev/null +++ b/switchlink/switchlink_defs.h @@ -0,0 +1,30 @@ +/* + * Copyright 2013-present Barefoot Networks, Inc. + * Copyright 2022-2024 Intel Corporation. + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ + +#ifndef __SWITCHLINK_DEFS_H__ +#define __SWITCHLINK_DEFS_H__ + +#include + +#include "switchlink_types.h" +#include "switchutils/switch_utils.h" + +#define switchlink_malloc(x, c) malloc((x) * (c)) +#define switchlink_free(x) free(x) + +#endif /* __SWITCHLINK_DEFS_H__ */ diff --git a/switchlink/switchlink_globals.h b/switchlink/switchlink_globals.h index 15e47f3..c2abf7d 100644 --- a/switchlink/switchlink_globals.h +++ b/switchlink/switchlink_globals.h @@ -7,7 +7,7 @@ #ifndef __SWITCHLINK_GLOBALS_H__ #define __SWITCHLINK_GLOBALS_H__ -#include "switchlink.h" +#include "switchlink_defs.h" extern switchlink_handle_t g_default_vrf_h; extern switchlink_handle_t g_default_bridge_h; diff --git a/switchlink/switchlink_handlers.h b/switchlink/switchlink_handlers.h index 7f8d3fd..63a9653 100644 --- a/switchlink/switchlink_handlers.h +++ b/switchlink/switchlink_handlers.h @@ -23,8 +23,8 @@ #include #include "krnlmon_options.h" -#include "switchlink/switchlink.h" #include "switchlink/switchlink_db.h" +#include "switchlink/switchlink_defs.h" extern void switchlink_init_api(void); diff --git a/switchlink/switchlink_link.c b/switchlink/switchlink_link.c index 783bb76..f4f7d19 100644 --- a/switchlink/switchlink_link.c +++ b/switchlink/switchlink_link.c @@ -23,7 +23,7 @@ #include #include "krnlmon_options.h" -#include "switchlink.h" +#include "switchlink_defs.h" #include "switchlink_globals.h" #include "switchlink_handlers.h" #include "switchlink_int.h" diff --git a/switchlink/switchlink_link_types.h b/switchlink/switchlink_link_types.h index 228282a..90e0168 100644 --- a/switchlink/switchlink_link_types.h +++ b/switchlink/switchlink_link_types.h @@ -1,6 +1,6 @@ /* * Copyright 2013-present Barefoot Networks, Inc. - * Copyright 2022-2023 Intel Corporation. + * Copyright 2022-2024 Intel Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,8 @@ * limitations under the License. */ -#ifndef __SWITCHLINK_LINK_H__ -#define __SWITCHLINK_LINK_H__ +#ifndef __SWITCHLINK_LINK_TYPES_H__ +#define __SWITCHLINK_LINK_TYPES_H__ typedef enum { SWITCHLINK_INTF_TYPE_NONE, @@ -47,4 +47,4 @@ typedef enum { SWITCHLINK_BOND_MODE_BALANCE_ALB, } switchlink_bond_mode_t; -#endif /* __SWITCHLINK_LINK_H__ */ +#endif /* __SWITCHLINK_LINK_TYPES_H__ */ diff --git a/switchlink/switchlink_main.c b/switchlink/switchlink_main.c index ab2dd84..6ce901f 100644 --- a/switchlink/switchlink_main.c +++ b/switchlink/switchlink_main.c @@ -36,7 +36,7 @@ #include #include -#include "switchlink.h" +#include "switchlink_defs.h" #include "switchlink_int.h" #include "switchutils/switch_log.h" diff --git a/switchlink/switchlink_neigh.c b/switchlink/switchlink_neigh.c index e4896b0..5cf2b53 100644 --- a/switchlink/switchlink_neigh.c +++ b/switchlink/switchlink_neigh.c @@ -20,7 +20,8 @@ #include #include -#include "switchlink.h" +#include "switchlink_db.h" +#include "switchlink_defs.h" #include "switchlink_globals.h" #include "switchlink_handlers.h" #include "switchlink_int.h" diff --git a/switchlink/switchlink_route.c b/switchlink/switchlink_route.c index f7f31de..8b81e10 100644 --- a/switchlink/switchlink_route.c +++ b/switchlink/switchlink_route.c @@ -20,7 +20,7 @@ #include #include -#include "switchlink.h" +#include "switchlink_defs.h" #include "switchlink_globals.h" #include "switchlink_handlers.h" #include "switchlink_int.h" diff --git a/switchlink/switchlink.h b/switchlink/switchlink_types.h similarity index 83% rename from switchlink/switchlink.h rename to switchlink/switchlink_types.h index c651390..8905d9a 100644 --- a/switchlink/switchlink.h +++ b/switchlink/switchlink_types.h @@ -16,16 +16,11 @@ * limitations under the License. */ -#ifndef __SWITCHLINK_H__ -#define __SWITCHLINK_H__ +#ifndef __SWITCHLINK_TYPES_H__ +#define __SWITCHLINK_TYPES_H__ #include -#include - -#include "switchutils/switch_utils.h" - -#define switchlink_malloc(x, c) malloc((x) * (c)) -#define switchlink_free(x) free(x) +#include #define SWITCH_LINK_INVALID_HANDLE 0x0 @@ -48,4 +43,4 @@ enum switchlink_nhop_using_by { SWITCHLINK_NHOP_FROM_ROUTE = 1 << 1, }; -#endif /* __SWITCHLINK_H__ */ +#endif /* __SWITCHLINK_TYPES_H__ */