1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
#pragma once
#include <cJSON.h>
#include <mrb_define.h>
#include <netinet/in.h>
#include <rte_common.h>
#include <rte_ether.h>
#include <common.h>
#include <ldbc.h>
#include <sc_common.h>
#include <sc_devmgr.h>
#define MR_NODE_CTRLZONE_ID 1
#define MR_NODE_COMMON_MAX_SID_NUM 8
#define MR_NODE_COMMON_VLAN_FLIPPING_DEFAULT_ARG_NUM 2
#define MR_NODE_COMMON_ETHERFABRIC_PKT_OFFSET
/* Forward type */
enum
{
FORWARDER_TYPE_LB = 1,
FORWARDER_TYPE_VWIRE,
FORWARDER_TYPE_EF,
FORWARDER_TYPE_TERA,
FORWARDER_TYPE_LAI,
FORWARDER_TYPE_HEALTH_CHECK,
FORWARDER_TYPE_MAX
};
/* Health check for ether type */
enum eth_health_check_type
{
ETH_HEALTH_CHECK_PRIVATE = 0xAAAA,
};
/* Health check remote state */
enum health_check_remote_state
{
REMOTE_DOWN = 0,
REMOTE_UP = 1,
};
/* VWire Service Tag */
struct vwire_service_tag
{
uint8_t dir;
uint16_t fwd_table_index;
};
struct dev_node_ctx
{
struct mr_dev_desc * dev_desc;
unsigned int last_rxtx_time_in_ms;
};
struct mr_generic_ip_hdr
{
int sa_family;
union {
const struct rte_ipv4_hdr * ipv4_hdr;
const struct rte_ipv6_hdr * ipv6_hdr;
};
};
void forwarder_table_insert(uint16_t sid, uint16_t type);
#if defined(__x86_64__)
static inline void swap_mac_addr(struct rte_ether_hdr * eth_hdr)
{
/* swap eth_hdr */
__m128i mac_shfl_msk = _mm_set_epi8(15, 14, 13, 12, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6);
__m128i mac_addr = _mm_loadu_si128((__m128i *)eth_hdr);
mac_addr = _mm_shuffle_epi8(mac_addr, mac_shfl_msk);
_mm_storeu_si128((__m128i *)eth_hdr, mac_addr);
}
#elif defined(__aarch64__)
static inline void swap_mac_addr(struct rte_ether_hdr * eth_hdr)
{
struct rte_ether_addr tmp_addr;
rte_ether_addr_copy(ð_hdr->dst_addr, &tmp_addr);
rte_ether_addr_copy(ð_hdr->src_addr, ð_hdr->dst_addr);
rte_ether_addr_copy(&tmp_addr, ð_hdr->src_addr);
}
#endif
static inline int mr_is_local_addr_for_trunk(struct mr_dev_desc * dev_desc, uint16_t vlan_id,
struct mr_generic_ip_hdr * ip_hdr)
{
assert(dev_desc->dev_mode == MR_DEV_MODE_TRUNK);
for (int i = 0; i < dev_desc->nr_vlan_members; i++)
{
struct vlan_member * vlan_member = &dev_desc->vlan_members[i];
if (vlan_member->vlan_id != vlan_id)
{
continue;
}
if (ip_hdr->sa_family == vlan_member->sa_family_v4)
{
if (vlan_member->in_addr.s_addr == ip_hdr->ipv4_hdr->dst_addr)
{
return RT_SUCCESS;
}
}
else if (ip_hdr->sa_family == vlan_member->sa_family_v6)
{
if (memcmp(&vlan_member->in6_addr, &ip_hdr->ipv6_hdr->dst_addr, sizeof(struct in6_addr)) == 0)
{
return RT_SUCCESS;
}
}
}
return RT_ERR;
}
static inline int mr_is_local_addr(struct mr_dev_desc * dev_desc, struct mr_generic_ip_hdr * ip_hdr)
{
/* Currently not supporting IPv6 */
if (ip_hdr->sa_family == AF_INET)
{
if (dev_desc->in_addr.s_addr == ip_hdr->ipv4_hdr->dst_addr)
{
return RT_SUCCESS;
}
}
return RT_ERR;
}
#define MR_IS_IPV6_SOLICITED_NODE_MCAST(x) \
(x[0] == 0xFF && x[1] == 0x02 && x[2] == 0x00 && x[3] == 0x00 && x[4] == 0x00 && x[5] == 0x00 && x[6] == 0x00 && \
x[7] == 0x00 && x[8] == 0x00 && x[9] == 0x00 && x[10] == 0x00 && x[11] == 0x01 && x[12] == 0xFF)
static inline cJSON * create_uint64_array(const uint64_t * value, unsigned int nr_value)
{
struct cJSON * uint64_array = cJSON_CreateArray();
for (unsigned int i = 0; i < nr_value; i++)
{
cJSON_AddItemToArray(uint64_array, cJSON_CreateNumber(value[i]));
}
return uint64_array;
}
/***************************************************** Sid handle *****************************************************/
#define SC_SID_HANDLE_CAPACITY_MAX 256
/* Sid handle struct */
struct sid_handle
{
uint16_t capacity;
uint32_t sid_start;
uint32_t sid_end;
};
struct sid_handle * sid_handle_create(uint32_t sid_start, uint32_t sid_end);
int sid_handle_delete(struct sid_handle * sid_handle);
uint16_t sid_handle_capacity_get(struct sid_handle * sid_handle);
uint32_t sid_handle_sid_start_get(struct sid_handle * sid_handle);
uint32_t sid_handle_sid_end_get(struct sid_handle * sid_handle);
/******************************************** Network intersection adapter ********************************************/
#define SC_ADAPTERS_MAX 128
int adapters_max_get(struct sc_main * sc, const char * key, uint32_t * adapters_max_out);
#define METADATA_INFO \
"dir:%u, nf_create:%u, health_check:%u, is_ctrlbuf:%u, adapter_type:%u, adapter_id:%u, payload_offset:%u, " \
"user_0:%u, ef_link_id:%u, traffic_link_id:%u, ef_peer_index:%u, port_ingress:%u, port_egress:%u, " \
"egress_action:%u, session_id:%lu, cur_sid:%u, sids:%u,%u,%u,%u,%u,%u,%u,%u, measurement_type:%u.\n"
void mrb_metadata_pktmbuf_dump(const struct rte_mbuf * m);
|