增加流标签

This commit is contained in:
崔一鸣
2019-05-21 17:14:07 +08:00
parent 1e58549e8a
commit 85aee8ba55
6 changed files with 97 additions and 26 deletions

View File

@@ -112,6 +112,8 @@ static struct tcp_restore_info_header* tcp_restore_info_header_new(struct pme_in
tcp_restore_info_tlv_add(TCP_RESTORE_INFO_TLV_SACK_SERVER, 1, pmeinfo->server_tcpopt->sack, (char*)header, &offset, &nr_tlvs);
tcp_restore_info_tlv_add(TCP_RESTORE_INFO_TLV_TS_CLIENT, 1, pmeinfo->client_tcpopt->ts, (char*)header, &offset, &nr_tlvs);
tcp_restore_info_tlv_add(TCP_RESTORE_INFO_TLV_TS_SERVER, 1, pmeinfo->server_tcpopt->ts, (char*)header, &offset, &nr_tlvs);
uint8_t protocol_type = pmeinfo->protocol == KNI_PROTOCOL_SSL ? 0x1 : 0x0;
tcp_restore_info_tlv_add(TCP_RESTORE_INFO_TLV_PROTOCOL, 1, protocol_type, (char*)header, &offset, &nr_tlvs);
header->__magic__[0] = 0x4d;
header->__magic__[1] = 0x5a;
header->nr_tlvs = htons(nr_tlvs);
@@ -168,7 +170,8 @@ static int send_to_tfe(struct kni_marsio_handle *handle, char *raw_data, int raw
marsio_buff_t *tx_buffs[BURST_MAX];
unsigned int ret = 1;
//TODO: marsio配置文件: 2500
int alloc_ret = marsio_buff_malloc_device(handle->dev_handler, tx_buffs, ret, 0, thread_seq);
//thread_seq实际上是网卡队列一个线程对应一个网卡队列, 并不是线程号和网卡队列号一一对应假设线程号是tid网卡队列为n那么tid % n就是网卡队列号
int alloc_ret = marsio_buff_malloc_device(handle->dev_eth_handler, tx_buffs, ret, 0, thread_seq);
if (alloc_ret < 0){
KNI_LOG_ERROR(logger, "Failed at alloc marsio buffer, ret is %d, thread_seq is %d", ret, thread_seq);
return -1;
@@ -177,7 +180,7 @@ static int send_to_tfe(struct kni_marsio_handle *handle, char *raw_data, int raw
unsigned char ethernet_header[14] = {0xfe, 0x65, 0xb7, 0x03, 0x50, 0xbd, 0xe8, 0x61, 0x1f, 0x13, 0x70, 0x7a, 0x08, 0x00};
memcpy(dst_data, ethernet_header, 14);
memcpy((char*)dst_data + 14, raw_data, raw_len);
marsio_send_burst(handle->dev_sendpath, thread_seq, tx_buffs, ret);
marsio_send_burst(handle->dev_eth_sendpath, thread_seq, tx_buffs, ret);
return 0;
}
@@ -391,17 +394,47 @@ static void kni_marsio_destroy(struct kni_marsio_handle *handle){
FREE(&handle);
}
void * thread_tfe_receiver(void* args){
struct tfe_receiver_args *_args = (struct tfe_receiver_args*)args;
//void *logger = _args->logger;
struct kni_marsio_handle *marsio_handle = _args->marsio_handle;
marsio_buff_t * rx_buff[BURST_MAX];
int nr_burst = 1;
//实际上是网卡队列id
int thread_seq = 0;
while(true){
//从tfe上收
int ret = marsio_recv_burst(marsio_handle->dev_eth_handler, thread_seq, rx_buff, nr_burst);
if(ret <= 0){
continue;
}
//打上标签
struct mr_tunnat_ctrlzone mr_ctrlzone;
mr_ctrlzone.action |= TUNNAT_CZ_ACTION_ENCAP_INNER | TUNNAT_CZ_ACTION_ENCAP_OUTER;
for(int i = 0; i < ret; i++){
marsio_buff_ctrlzone_set(rx_buff[i], 0, &mr_ctrlzone, sizeof(struct mr_tunnat_ctrlzone));
}
//发送给vxlan
marsio_send_burst_with_options(marsio_handle->dev_vxlan_sendpath, thread_seq, rx_buff, 1, MARSIO_SEND_OPT_FAST);
}
return NULL;
}
static struct kni_marsio_handle* kni_marsio_init(const char* profile){
void *logger = g_kni_handle->logger;
const char* section = "marsio";
char appsym[KNI_SYMBOL_MAX];
char dev_symbol[KNI_SYMBOL_MAX];
char dev_eth_symbol[KNI_SYMBOL_MAX];
char dev_vxlan_symbol[KNI_SYMBOL_MAX];
MESA_load_profile_string_def(profile, section, "appsym", appsym, sizeof(appsym), "unknown");
MESA_load_profile_string_def(profile, section, "dev_symbol", dev_symbol, sizeof(dev_symbol), "unknown");
KNI_LOG_INFO(logger, "MESA_prof_load, [%s]:\n appsym: %s\n dev_symbol: %s", section, appsym, dev_symbol);
MESA_load_profile_string_def(profile, section, "dev_eth_symbol", dev_eth_symbol, sizeof(dev_eth_symbol), "unknown");
MESA_load_profile_string_def(profile, section, "dev_vxlan_symbol", dev_vxlan_symbol, sizeof(dev_vxlan_symbol), "unknown");
KNI_LOG_INFO(logger, "MESA_prof_load, [%s]:\n appsym: %s\n dev_eth_symbol: %s\n dev_vxlan_symbol: %s",
section, appsym, dev_eth_symbol, dev_vxlan_symbol);
struct mr_instance *instance = marsio_create();
if(instance == NULL){
KNI_LOG_ERROR(logger, "Failed at marsio_create");
KNI_LOG_ERROR(logger, "Failed at create marsio instance");
return NULL;
}
unsigned int opt_value = 1;
@@ -409,24 +442,49 @@ static struct kni_marsio_handle* kni_marsio_init(const char* profile){
//uint64_t cpu_mask = 0x3c; //??
//marsio_option_set(handle->instance, MARSIO_OPT_THREAD_MASK, &cpu_mask, sizeof(cpu_mask));
marsio_init(instance, appsym);
//设为sapp线程数
int nr_thread = g_iThreadNum;
struct mr_vdev * dev_handler = marsio_open_device(instance, dev_symbol, nr_thread, nr_thread);
if(dev_handler == NULL){
KNI_LOG_ERROR(logger, "Failed at marsio_open_device, dev_symbol is %s, nr_thread is %d", dev_symbol, nr_thread);
//eth_handler有一个线程收, g_iThreadNum个线程发
struct mr_vdev *dev_eth_handler = marsio_open_device(instance, dev_eth_symbol, 1, g_iThreadNum);
if(dev_eth_handler == NULL){
KNI_LOG_ERROR(logger, "Failed at marsio_open_device, dev_symbol is %s", dev_eth_symbol);
return NULL;
}
struct mr_sendpath * dev_sendpath = marsio_sendpath_create_by_vdev(dev_handler);
if(dev_sendpath == NULL){
KNI_LOG_ERROR(logger, "Failed at marsio_sendpath_create_by_vdev");
//vxlan_handler有0个线程收, 1个线程发
struct mr_vdev *dev_vxlan_handler = marsio_open_device(instance, dev_vxlan_symbol, 0, 1);
if(dev_vxlan_handler == NULL){
KNI_LOG_ERROR(logger, "Failed at marsio_open_device, dev_symbol is %s", dev_vxlan_symbol);
return NULL;
}
struct mr_sendpath * dev_eth_sendpath = marsio_sendpath_create_by_vdev(dev_eth_handler);
if(dev_eth_sendpath == NULL){
KNI_LOG_ERROR(logger, "Failed at create marsio sendpath, dev_symbol is %s", dev_eth_symbol);
return NULL;
}
struct mr_sendpath * dev_vxlan_sendpath = marsio_sendpath_create_by_vdev(dev_vxlan_handler);
if(dev_eth_sendpath == NULL){
KNI_LOG_ERROR(logger, "Failed at create marsio sendpath, dev_symbol is %s", dev_vxlan_symbol);
return NULL;
}
struct kni_marsio_handle *handle = ALLOC(struct kni_marsio_handle, 1);
handle->instance = instance;
handle->dev_handler = dev_handler;
handle->dev_sendpath = dev_sendpath;
handle->dev_eth_handler = dev_eth_handler;
handle->dev_eth_sendpath = dev_eth_sendpath;
handle->dev_vxlan_handler = dev_vxlan_handler;
handle->dev_vxlan_sendpath = dev_vxlan_sendpath;
//暂时不用调
//marsio_thread_init(mr_instance);
//创建线程从tfe收包然后打上标签发送给vxlan_user
pthread_t thread_id;
struct tfe_receiver_args *args = ALLOC(struct tfe_receiver_args, 1);
args->logger = logger;
args->marsio_handle = handle;
int ret = pthread_create(&thread_id, NULL, thread_tfe_receiver, (void *)args);
if(unlikely(ret != 0)){
KNI_LOG_ERROR(logger, "Failed at pthread_create, name is thread_tfe_receiver, ret is %d", ret);
exit(EXIT_FAILURE);
}
return handle;
}