Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor switchlink header files #169

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions switchlink/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
switchlink_db_test/
92 changes: 59 additions & 33 deletions switchlink/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -38,43 +55,63 @@ 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",
],
)

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",
],
Expand All @@ -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",
],
Expand Down Expand Up @@ -129,8 +166,8 @@ krnlmon_cc_library(
"-lpthread",
],
deps = [
":switchlink_defs",
":switchlink_int",
":switchlink_types",
"//switchutils:switch_log",
"@nl-3",
"@target_sys",
Expand All @@ -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",
],
)
Expand Down Expand Up @@ -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"],
Expand All @@ -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": [],
}),
)
4 changes: 3 additions & 1 deletion switchlink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
$<TARGET_OBJECTS:switchlink_sai_o>
Expand Down
4 changes: 2 additions & 2 deletions switchlink/sai/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ krnlmon_cc_library(
":switchlink_init_sai",
"//switchlink:switchlink_db",
"//switchlink:switchlink_handlers",
"//switchlink:switchlink_types",
"//switchlink:switchlink_defs",
],
)

Expand Down Expand Up @@ -92,7 +92,7 @@ krnlmon_cc_library(
deps = [
"//:krnlmon_options",
"//switchlink:switchlink_db",
"//switchlink:switchlink_types",
"//switchlink:switchlink_defs",
"//switchlink:switchlink_utils",
"//switchsai:saiinternal",
],
Expand Down
2 changes: 1 addition & 1 deletion switchlink/switchlink_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <stdint.h>
#include <string.h>

#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"
Expand Down
125 changes: 4 additions & 121 deletions switchlink/switchlink_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,127 +19,10 @@
#ifndef __SWITCHLINK_DB_H__
#define __SWITCHLINK_DB_H__

#include <stdbool.h>

#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 <stdint.h>

#include "switchlink_db_types.h"
#include "switchlink_defs.h"

/*** interface ***/
extern switchlink_db_status_t switchlink_db_add_interface(
Expand Down
3 changes: 3 additions & 0 deletions switchlink/switchlink_db_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#ifndef __SWITCHLINK_DB_INT_H__
#define __SWITCHLINK_DB_INT_H__

#include <stdint.h>

#include "switchlink_db_types.h"
#include "tommyds/tommyhashlin.h"
#include "tommyds/tommylist.h"
#include "tommyds/tommytrieinp.h"
Expand Down
Loading