This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
tango-kni/common/test/test_cmsg.cpp

50 lines
1.6 KiB
C++

#include "kni_utils.h"
#include "kni_cmsg.h"
int main(){
//init
struct kni_cmsg *cmsg = kni_cmsg_init();
//set
uint32_t value = 0x12345678;
int ret = kni_cmsg_set(cmsg, TFE_CMSG_TCP_RESTORE_SEQ, (const unsigned char*)(&value), 4);
printf("kni_cmsg_set: ret is %d\n", ret);
//get TCP_RESTORE_INFO_TLV_SEQ
uint16_t size = -1;
unsigned char *value1 = NULL;
ret = kni_cmsg_get(cmsg, TFE_CMSG_TCP_RESTORE_SEQ, &size, &value1);
printf("kni_cmsg_get: ret is %d, type is TCP_RESTORE_INFO_TLV_SEQ, value is 0x%02x, value_size is %d\n", ret, ((uint32_t*)value1)[0], size);
//get_serialize_size
size = kni_cmsg_serialize_size_get(cmsg);
printf("kni_cmsg_serialize_size_get: size is %d\n", size);
//serialize
unsigned char buff[size];
uint16_t serialize_len = -1;
ret = kni_cmsg_serialize(cmsg, buff, size, &serialize_len);
printf("kni_cmsg_serialize: ret is %d, serialize_len is %d, serialize result is: ", ret, serialize_len);
for(int i = 0; i < serialize_len; i++){
printf("%02x ", buff[i]);
}
printf("\n");
kni_cmsg_destroy(cmsg);
printf("kni_cmsg_destroy cmsg\n");
//deserialize
struct kni_cmsg *cmsg1 = NULL;
ret = kni_cmsg_deserialize(buff, serialize_len, &cmsg1);
printf("kni_cmsg_deserialize: ret is %d\n", ret);
//get TCP_RESTORE_INFO_TLV_SEQ
size = -1;
unsigned char *value2 = NULL;
ret = kni_cmsg_get(cmsg1, TFE_CMSG_TCP_RESTORE_SEQ, &size, &value2);
printf("kni_cmsg_get: ret is %d, type is TCP_RESTORE_INFO_TLV_SEQ, value is 0x%02x, value_size is %d\n", ret, ((uint32_t*)value2)[0], size);
kni_cmsg_destroy(cmsg1);
printf("kni_cmsg_destroy cmsg1\n");
}