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
|
#include <MESA_prof_load.h>
#include <sc_node_common.h>
/***************************************************** Sid handle *****************************************************/
struct sid_handle * sid_handle_create(uint32_t sid_start, uint32_t sid_end)
{
if (unlikely(sid_start > sid_end))
{
MR_ERROR("The start of the sid is larger than the end of the sid.");
return NULL;
}
uint16_t capacity = sid_end - sid_start + 1;
if (unlikely(capacity > SC_SID_HANDLE_CAPACITY_MAX))
{
MR_ERROR("The capacity of the sid handle is larger than the maximum value.");
return NULL;
}
struct sid_handle * sid_handle = ZMALLOC(sizeof(struct sid_handle));
MR_VERIFY_MALLOC(sid_handle);
sid_handle->capacity = capacity;
sid_handle->sid_start = sid_start;
sid_handle->sid_end = sid_end;
return sid_handle;
}
/**
* @brief Deletes a SID handle.
*
* This function frees the memory allocated for the specified SID handle.
* If the handle is NULL, the function returns immediately without performing
* any operations. Otherwise, it frees the memory and returns RT_SUCCESS.
*
* @param sid_handle A pointer to the sid_handle structure to be deleted.
*
* @return RT_SUCCESS if the handle is successfully deleted, or RT_ERR if the handle is NULL.
*/
int sid_handle_delete(struct sid_handle * sid_handle)
{
if (sid_handle != NULL)
{
FREE(sid_handle);
return RT_SUCCESS;
}
return RT_ERR;
}
/**
* @brief Get the capacity of the SID handle.
*
* This function returns the capacity of the specified SID handle.
* If the handle is NULL, the function returns 0.
*
* @param sid_handle A pointer to the sid_handle structure.
*
* @return The capacity of the SID handle, or 0 if the handle is NULL.
*/
inline uint16_t sid_handle_capacity_get(struct sid_handle * sid_handle)
{
assert(sid_handle != NULL);
return sid_handle->capacity;
}
/**
* @brief Get the starting SID of the SID handle.
*
* This function returns the starting SID of the specified SID handle.
* If the handle is NULL, the function returns 0.
*
* @param sid_handle A pointer to the sid_handle structure.
*
* @return The starting SID of the SID handle, or 0 if the handle is NULL.
*/
inline uint32_t sid_handle_sid_start_get(struct sid_handle * sid_handle)
{
assert(sid_handle != NULL);
return sid_handle->sid_start;
}
/**
* @brief Get the ending SID of the SID handle.
*
* This function returns the ending SID of the specified SID handle.
* If the handle is NULL, the function returns 0.
*
* @param sid_handle A pointer to the sid_handle structure.
*
* @return The ending SID of the SID handle, or 0 if the handle is NULL.
*/
inline uint32_t sid_handle_sid_end_get(struct sid_handle * sid_handle)
{
assert(sid_handle != NULL);
return sid_handle->sid_end;
}
/******************************************** Network intersection adapter ********************************************/
/**
* @brief Retrieves the maximum number of adapters from the configuration.
*
* This function loads the maximum number of adapters specified in the configuration file
* using the provided key. It verifies that the loaded value is valid and does not exceed
* the predefined maximum limit (`SC_ADAPTERS_MAX`). If the value is valid, it is stored in
* the `adapters_max_out` output parameter. The function returns `RT_SUCCESS` if the value
* is successfully retrieved and valid, or `RT_ERR` if an error occurs.
*
* @param sc Pointer to the `sc_main` structure containing the configuration file and resources.
* @param key The key used to retrieve the maximum adapters value from the configuration file.
* @param adapters_max_out Pointer to where the retrieved maximum adapters value will be stored.
*
* @return RT_SUCCESS if the maximum adapters value is successfully retrieved and valid, RT_ERR otherwise.
*/
int adapters_max_get(struct sc_main * sc, const char * key, uint32_t * adapters_max_out)
{
assert(sc != NULL);
assert(key != NULL);
assert(adapters_max_out != NULL);
uint32_t adapters_max = 0;
MESA_load_profile_uint_def(sc->local_cfgfile, "limits", key, &adapters_max, 64);
if (adapters_max == 0)
{
MR_ERROR("The '%s' is invalid: %u", key, adapters_max);
return RT_ERR;
}
else if (adapters_max > SC_ADAPTERS_MAX)
{
MR_ERROR("The '%s' is larger than the maximum value: %u", key, adapters_max);
return RT_ERR;
}
*adapters_max_out = adapters_max;
return RT_SUCCESS;
}
void mrb_metadata_pktmbuf_dump(const struct rte_mbuf * m)
{
char str_metadata[1024] = {};
struct mrb_metadata * mrb_meta = mrbuf_cz_data(m, MR_NODE_CTRLZONE_ID);
snprintf(str_metadata, sizeof(str_metadata), METADATA_INFO, mrb_meta->dir, mrb_meta->packet_create_from_nf,
mrb_meta->health_check, mrb_meta->is_ctrlbuf, mrb_meta->adapter_type, mrb_meta->adapter_id,
mrb_meta->payload_offset, mrb_meta->user_0, mrb_meta->ef_link_id, mrb_meta->traffic_link_id,
mrb_meta->ef_peer_index, mrb_meta->port_ingress, mrb_meta->port_egress, mrb_meta->egress_action,
mrb_meta->session_id, mrb_meta->cur_sid, mrb_meta->sid_list.sids[0], mrb_meta->sid_list.sids[1],
mrb_meta->sid_list.sids[2], mrb_meta->sid_list.sids[3], mrb_meta->sid_list.sids[4],
mrb_meta->sid_list.sids[5], mrb_meta->sid_list.sids[6], mrb_meta->sid_list.sids[7],
mrb_meta->measurement_type);
MR_ERROR("The pkt metadata: %s", str_metadata);
rte_pktmbuf_dump(stderr, m, rte_pktmbuf_data_len(m));
return;
}
|