-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: save flow statistical information into hash table
- Loading branch information
Showing
10 changed files
with
406 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2021 Chenming C (ccm@ccm.ink) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
#ifndef SMART_OFFLOAD_FLOW_META_H | ||
#define SMART_OFFLOAD_FLOW_META_H | ||
|
||
#include <rte_flow.h> | ||
|
||
/** | ||
* The data structure to save statistical information of flow. | ||
*/ | ||
struct flow_meta { | ||
/* Use the number of cycles of CPU as the time*/ | ||
uint64_t create_at; | ||
/* Total size of flow */ | ||
uint32_t flow_size; | ||
/* Total amount of packets in a flow */ | ||
uint32_t packet_amount; | ||
/* Has created rte_flow to offload flow or not */ | ||
bool is_offload; | ||
/* The rte_flow to handle this flow */ | ||
struct rte_flow *flow; | ||
}; | ||
|
||
struct flow_meta *create_flow_meta(uint32_t pkt_len); | ||
|
||
#endif //SMART_OFFLOAD_FLOW_META_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2021 Chenming C (ccm@ccm.ink) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
#ifndef SMART_OFFLOAD_HASH_KEY_H | ||
#define SMART_OFFLOAD_HASH_KEY_H | ||
|
||
/* check the instruction support for hash function */ | ||
#if defined(RTE_ARCH_X86) || defined(__ARM_FEATURE_CRC32) | ||
#define EM_HASH_CRC 1 | ||
#endif | ||
|
||
#ifdef EM_HASH_CRC | ||
#include <rte_hash_crc.h> | ||
#define DEFAULT_HASH_FUNC rte_hash_crc | ||
#else | ||
#include <rte_jhash.h> | ||
#define DEFAULT_HASH_FUNC rte_jhash | ||
#endif | ||
|
||
/** | ||
* The width of wide instruction for load data. | ||
*/ | ||
typedef __m128i xmm_t; | ||
|
||
#define IPV6_ADDR_LEN 16 | ||
|
||
struct ipv4_5tuple { | ||
uint32_t ip_dst; | ||
uint32_t ip_src; | ||
uint16_t port_dst; | ||
uint16_t port_src; | ||
uint8_t proto; | ||
} __rte_packed; | ||
|
||
/** | ||
* The key of the flow hash table. | ||
*/ | ||
union ipv4_5tuple_host { | ||
struct { | ||
uint8_t pad0; | ||
uint8_t proto; | ||
uint16_t pad1; | ||
uint32_t ip_src; | ||
uint32_t ip_dst; | ||
uint16_t port_src; | ||
uint16_t port_dst; | ||
}; | ||
xmm_t xmm; | ||
}; | ||
|
||
|
||
/** | ||
* The hash function to generate the real hash key. | ||
* | ||
* @param data The key used as the key of flow table. | ||
* @param data_len The length of key. | ||
* @param init_val | ||
* @return The real hash key. | ||
*/ | ||
static inline uint32_t ipv4_hash_crc(const void *data, __rte_unused uint32_t data_len, | ||
uint32_t init_val) { | ||
const union ipv4_5tuple_host *k; | ||
uint32_t t; | ||
const uint32_t *p; | ||
|
||
k = data; | ||
t = k->proto; | ||
p = (const uint32_t *) &k->port_src; | ||
|
||
#ifdef EM_HASH_CRC | ||
init_val = rte_hash_crc_4byte(t, init_val); | ||
init_val = rte_hash_crc_4byte(k->ip_src, init_val); | ||
init_val = rte_hash_crc_4byte(k->ip_dst, init_val); | ||
init_val = rte_hash_crc_4byte(*p, init_val); | ||
#else | ||
init_val = rte_jhash_1word(t, init_val); | ||
init_val = rte_jhash_1word(k->ip_src, init_val); | ||
init_val = rte_jhash_1word(k->ip_dst, init_val); | ||
init_val = rte_jhash_1word(*p, init_val); | ||
#endif | ||
|
||
return init_val; | ||
} | ||
|
||
static void convert_ipv4_5tuple(struct ipv4_5tuple *key1, | ||
union ipv4_5tuple_host *key2) { | ||
key2->ip_dst = rte_cpu_to_be_32(key1->ip_dst); | ||
key2->ip_src = rte_cpu_to_be_32(key1->ip_src); | ||
key2->port_dst = rte_cpu_to_be_16(key1->port_dst); | ||
key2->port_src = rte_cpu_to_be_16(key1->port_src); | ||
key2->proto = key1->proto; | ||
key2->pad0 = 0; | ||
key2->pad1 = 0; | ||
} | ||
|
||
#endif //SMART_OFFLOAD_HASH_KEY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2021 Chenming C (ccm@ccm.ink) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
#include <rte_malloc.h> | ||
#include "flow_meta.h" | ||
|
||
struct flow_meta * create_flow_meta(uint32_t pkt_len){ | ||
struct flow_meta *data = rte_zmalloc("flow_table_data", sizeof(struct flow_meta), 0); | ||
data->create_at = rte_rdtsc(); // The number of cycles of CPU. One cycle is 1/rte_get_tsc_hz() second. | ||
data->flow_size = pkt_len; | ||
data->packet_amount = 1; | ||
data->flow = NULL; | ||
data->is_offload = false; | ||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.