vppcom简介
vppcom(Vector Packet Processing Communication)是一个用于在 VPP(Vector Packet Processing)网络平台上进行通信的框架。VPP 是一个高性能、可扩展的网络数据包处理平台,用于构建网络功能,如路由、交换、防火墙等。VPP 通过在用户空间处理数据包,实现了高吞吐量和低延迟的网络数据包处理。
VPPCom 则是 VPP 平台上的通信库,它为应用程序提供了一套 API,使得应用程序能够利用 VPP 平台的性能和功能来进行网络通信。VPPCom 的主要特点和功能包括:
高性能通信:VPPCom 基于 VPP 平台,允许应用程序在用户空间中执行网络数据包的处理,从而实现高性能、低延迟的通信。
通用性:VPPCom 提供了通用的网络通信接口,可以用于构建各种应用程序,包括网络应用、通信应用、数据中心应用等。
支持多种协议:VPPCom 支持多种网络协议,包括 TCP、UDP、IP,使得应用程序能够进行各种类型的网络通信。
易于使用:VPPCom 提供了简单易用的 API,使得应用程序能够轻松地与 VPP 平台进行交互,实现网络数据包的发送和接收。
跨平台:VPPCom 提供了跨平台的支持,可以在不同的操作系统上使用,从而使得应用程序能够在不同环境下进行网络通信。
与 VPP 集成:VPPCom 与 VPP 平台紧密集成,可以利用 VPP 的功能来加速数据包处理和通信。
需要注意的是,VPPCom 是为了简化应用程序与 VPP 平台之间的通信而设计的通信库,主要用于应用程序的网络通信。而 VPP 则是一个更大的网络数据包处理平台,用于构建网络功能和服务。
VCL(VPP Communication Library)是 Vector Packet Processing(VPP)项目中的通信库,而 VPPCom(Vector Packet Processing Communication)则是 VPP 项目中的通信库的一部分,用于提供用户空间应用程序与 VPP 数据平面之间的通信接口。实际上,VPPCom 是 VCL 的一种具体实现,可以说 VPPCom 就是 VCL 在 VPP 中的实现版本。
vppcom主要特点和优势
高性能通信接口:VPPCom 提供了高性能的通信接口,允许应用程序通过零拷贝方式与 VPP 数据平面进行通信。这种方式可以显著降低数据包处理的延迟,提高整体通信性能。
零拷贝技术:VPPCom 利用了零拷贝技术,避免了数据包在用户空间和内核空间之间的不必要拷贝。这在高速网络通信中尤为重要,能够降低CPU负载并提升系统吞吐量。
灵活性和扩展性:VPPCom 提供了丰富的 API,支持多种通信模式和协议。它可以轻松适应不同类型的应用场景,包括高性能网络服务、虚拟化环境等。此外,VPPCom 还支持扩展插件,允许开发者根据需要定制和扩展功能。
连接管理和状态监测:VPPCom 提供了连接管理和状态监测功能,使应用程序能够轻松地管理网络连接、监测连接状态,并执行相关操作,如连接建立、断开等。
VCL库简介
具体来说,VCL(VPP Communication Library)是一个通信库,用于在 VPP 平台上构建应用程序的用户空间通信功能。它提供了一组 API,使得应用程序能够通过 VPP 数据平面进行网络通信,发送和接收数据包。VCL 负责处理应用程序与 VPP 数据平面之间的通信细节,包括数据包的传输、缓冲管理、连接管理等。
而 VPPCom(Vector Packet Processing Communication)是 VPP 平台中的 VCL 的具体实现,它实际上就是 VPP 中的通信库。VPPCom 提供了用于构建用户空间应用程序的 API,通过这些 API,应用程序可以利用 VPP 数据平面的性能和功能来进行高性能的网络通信。
因此,可以将 VCL 看作是通信库的概念,而 VPPCom 则是在 VPP 平台上的具体实现,用于提供应用程序与 VPP 数据平面之间的高性能通信接口
了解这几本原理后,我们简单写一个vppcom的tcp server 与 client,框架大概是这样的:
vpp tcp client :vppcom client.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <vcl/vppcom.h>
// vppcom
// ./vppcom_client 192.168.0.29 8888
int main(int argc, char *argv[]) {
int rv = 0;
printf("vppcom server: %d\n", argc);
if (argc < 3) return -1;
struct sockaddr_in servaddr;
memset(&servaddr, 0, sizeof(struct sockaddr_in ));
servaddr.sin_family = AF_INET;
//servaddr.sin_addr
inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
servaddr.sin_port = atoi(argv[2]);
rv = vppcom_app_create("vppcom_server\n");
if (rv) {
printf("vppcom_app_create\n");
return -1;
}
int connfd = vppcom_session_create(VPPCOM_PROTO_TCP, 0);
if (connfd < 0) {
return -1;
}
printf("vppcom_session_create: %s, %s\n", argv[1], argv[2]);
vppcom_endpt_t endpt;
memset(&endpt, 0, sizeof(endpt));
endpt.is_ip4 = 1;
endpt.ip = (uint8_t*)&servaddr.sin_addr;
endpt.port = htons(servaddr.sin_port); //
rv = vppcom_session_connect(connfd, &endpt);
if (rv < 0) {
printf("vppcom_session_bind failed\n");
return -1;
}
char *str = "vppcomclient\n";
rv = vppcom_session_write(connfd, str, strlen(str));
if (rv < 0) {
printf("vppcom_session_accept failed\n");
return -1;
}
char buffer[1024] = {0};
rv = vppcom_session_read(connfd, buffer, sizeof(buffer));
if (rv < 0) {
printf("vppcom_session_accept failed\n");
return -1;
}
printf("Received from client length: %d , %s\n", rv, buffer);
vppcom_session_close(connfd);
vppcom_app_destroy();
return 0;
}
vpp server :vppcom_server.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <vcl/vppcom.h>
// vppcom
// ./vppcom_server 192.168.0.29 8888
int main(int argc, char *argv[]) {
int rv = 0;
printf("vppcom server: %d\n", argc);
if (argc < 3) return -1;
struct sockaddr_in servaddr;
memset(&servaddr, 0, sizeof(struct sockaddr_in ));
servaddr.sin_family = AF_INET;
//servaddr.sin_addr
inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
servaddr.sin_port = atoi(argv[2]);
rv = vppcom_app_create("vppcom_server\n");
if (rv) {
printf("vppcom_app_create\n");
return -1;
}
int listenfd = vppcom_session_create(VPPCOM_PROTO_TCP, 0);
if (listenfd < 0) {
return -1;
}
printf("vppcom_session_create: %s, %s\n", argv[1], argv[2]);
vppcom_endpt_t endpt;
memset(&endpt, 0, sizeof(endpt));
endpt.is_ip4 = 1;
endpt.ip = (uint8_t*)&servaddr.sin_addr;
endpt.port = htons(servaddr.sin_port); //
rv = vppcom_session_bind(listenfd, &endpt);
if (rv < 0) {
printf("vppcom_session_bind failed\n");
return -1;
}
rv = vppcom_session_listen(listenfd, 10);
if (rv < 0) {
printf("vppcom_session_listen failed\n");
return -1;
}
vppcom_endpt_t clientpt;
int clientfd = vppcom_session_accept(listenfd, &clientpt, 0);
if (clientfd < 0) {
printf("vppcom_session_accept failed\n");
return -1;
}
char buffer[1024] = {0};
rv = vppcom_session_read(clientfd, buffer, sizeof(buffer));
if (rv < 0) {
printf("vppcom_session_accept failed\n");
return -1;
}
printf("Received from client length: %d , %s\n", rv, buffer);
rv = vppcom_session_write(clientfd, buffer, rv);
vppcom_session_close(clientfd);
vppcom_app_destroy();
return 0;
}