Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions autotest/autotest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <arpa/inet.h>
#include <cstring>
#include <fcntl.h>
#include <pcap.h>
#include <sys/shm.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -1481,6 +1482,12 @@ void tAutotest::mainThread()

result = step_dumpPackets(yamlStep["dumpPackets"], configFilePath);
}
else if (yamlStep["bird"])
{
YANET_LOG_DEBUG("step: bird\n");

result = step_bird(yamlStep["bird"], configFilePath);
}
else
{
YANET_LOG_ERROR("unknown step\n");
Expand All @@ -1505,6 +1512,8 @@ void tAutotest::mainThread()
std::abort();
}

stopBirdThreads();

YANET_LOG_PRINT(ANSI_COLOR_GREEN "done '%s'\n\n" ANSI_COLOR_RESET, configFilePath.data());
fflush(stdout);
fflush(stderr);
Expand Down Expand Up @@ -2000,6 +2009,116 @@ bool tAutotest::step_dumpPackets(const YAML::Node& yamlStep,
return true;
}

void copyAllFromFileToSocket(int fd_file, int fd_socket)
{
struct sockaddr_in6 address;
socklen_t addressLength = sizeof(address);
memset((char*)&address, 0, sizeof(address));
int clientSocket = accept(fd_socket, (struct sockaddr*)&address, &addressLength);
if (clientSocket < 0)
{
YANET_LOG_ERROR("error on accept socket %d: %s\n", errno, strerror(errno));
return;
}

uint8_t buffer[64];
ssize_t was_read;
while (was_read = read(fd_file, buffer, sizeof(buffer)), was_read > 0)
{
ssize_t totalSend = 0;
while (totalSend < was_read)
{
int ret = send(clientSocket, buffer + totalSend, was_read - totalSend, MSG_NOSIGNAL);
if (ret <= 0)
{
YANET_LOG_ERROR("error send %d: %s\n", errno, strerror(errno));
return;
}
totalSend += ret;
}
}

if (was_read < 0)
{
YANET_LOG_ERROR("error read %d: %s\n", errno, strerror(errno));
}
else
{
YANET_LOG_DEBUG("stopping thread copy from bird data\n");
}
}

bool tAutotest::step_bird(const YAML::Node& yamlStep,
const std::string& path)
{
for (const auto& yamlBird : yamlStep)
{
std::string filename_data = path + "/" + yamlBird["data"].as<std::string>();
std::string filename_sock = yamlBird["sock"].as<std::string>();
YANET_LOG_DEBUG("run bird on file data: %s, socket: %s\n", filename_data.c_str(), filename_sock.c_str());

// Open file
int fd_file = open(filename_data.c_str(), O_RDONLY);
if (fd_file < 0)
{
YANET_LOG_ERROR("error '%d: %s' open file: %s\n", fd_file, strerror(fd_file), filename_data.c_str());
return false;
}
birdDescriptors.push_back(fd_file);

// Prepare socket
int fd_socket = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd_socket < 0)
{
YANET_LOG_ERROR("error create socket %d: %s\n", fd_socket, strerror(fd_socket));
return false;
}

sockaddr_un address;
memset((char*)&address, 0, sizeof(address));
address.sun_family = AF_UNIX;
strncpy(address.sun_path, filename_sock.c_str(), sizeof(address.sun_path) - 1);
address.sun_path[sizeof(address.sun_path) - 1] = 0;

unlink(filename_sock.c_str());

if (bind(fd_socket, (struct sockaddr*)&address, sizeof(address)) < 0)
{
YANET_LOG_ERROR("error bind socket on: %s\n", filename_sock.c_str());
return false;
}

if (listen(fd_socket, 64) < 0)
{
YANET_LOG_ERROR("error listen socket on: %s\n", filename_sock.c_str());
return false;
}
birdDescriptors.push_back(fd_socket);

birdThreads.emplace_back([fd_file, fd_socket]() {
copyAllFromFileToSocket(fd_file, fd_socket);
});
}

return true;
}

void tAutotest::stopBirdThreads()
{
for (int fd : birdDescriptors)
{
close(fd);
}

for (auto& thread : birdThreads)
{
if (thread.joinable())
{
thread.join();
}
}
}

void tAutotest::fflushSharedMemory()
{
size_t size = std::get<0>(rawShmInfo);
Expand Down
5 changes: 5 additions & 0 deletions autotest/autotest.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ class tAutotest
bool step_reload_async(const YAML::Node& yamlStep);
bool step_echo(const YAML::Node& yamlStep);
bool step_dumpPackets(const YAML::Node& yamlStep, const std::string& path);
bool step_bird(const YAML::Node& yamlStep, const std::string& path);

eResult initSockets();
eResult initSharedMemory();
void fflushSharedMemory();
void stopBirdThreads();

bool step_memorize_counter_value(const YAML::Node& yamlStep);
bool step_diff_with_kept_counter_value(const YAML::Node& yamlStep);
Expand Down Expand Up @@ -129,6 +131,9 @@ class tAutotest
std::string memorized_counter_name;
uint32_t memorized_coreId;
uint64_t memorized_counter_value;

std::vector<std::thread> birdThreads;
std::vector<int> birdDescriptors;
};

bool readTimeLimited(int fd, u_char* data, ssize_t len, std::chrono::system_clock::time_point time_to_give_up);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ steps:
- port: kni0
send: 002-send.pcap
expect: 002-expect.pcap
- cli:
- rib static remove default 1.0.0.0/24 4444::1 1100 10000
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
49 changes: 49 additions & 0 deletions autotest/units/001_one_port/082_bird_import/autotest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
steps:
- cli:
- rib prefixes
- bird:
- data: bird-master4_1.dat
sock: /tmp/yanet-bird-master4_1.sock
- data: bird-master6_1.dat
sock: /tmp/yanet-bird-master6_1.sock
- sleep: 5
- cli:
- rib prefixes

- sendPackets:
- port: kni0
send: 001-send.pcap
expect: 001-expect.pcap


- bird:
- data: bird-master4_2.dat
sock: /tmp/yanet-bird-master4_2.sock
- data: bird-master6_2.dat
sock: /tmp/yanet-bird-master6_2.sock
- sleep: 1
- reload: controlplane2.conf
- sleep: 5
- cli:
- rib prefixes

- sendPackets:
- port: kni0
send: 001-send.pcap
expect: 002-expect.pcap

- bird:
- data: bird-master4_3.dat
sock: /tmp/yanet-bird-master4_3.sock
- data: bird-master6_3.dat
sock: /tmp/yanet-bird-master6_3.sock
- sleep: 1
- reload: controlplane3.conf
- sleep: 5
- cli:
- rib prefixes

- sendPackets:
- port: kni0
send: 001-send.pcap
expect: 003-expect.pcap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
70 changes: 70 additions & 0 deletions autotest/units/001_one_port/082_bird_import/controlplane.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"modules": {
"lp0.100": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "100",
"macAddress": "00:11:22:33:44:55",
"nextModule": "route0"
},
"lp0.200": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "200",
"macAddress": "00:11:22:33:44:55",
"nextModule": "route0"
},
"lp0.300": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "300",
"macAddress": "00:11:22:33:44:55",
"nextModule": "route0"
},
"lp0.400": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "400",
"macAddress": "00:11:22:33:44:55",
"nextModule": "route0"
},
"route0": {
"type": "route",
"interfaces": {
"kni0.100": {
"nextModule": "lp0.100"
},
"kni0.200": {
"neighborIPv4Address": "10.10.10.1",
"neighborIPv6Address": "10::1",
"neighborMacAddress": "00:00:00:22:22:22",
"nextModule": "lp0.200"
},
"kni0.300": {
"neighborIPv4Address": "10.10.10.2",
"neighborIPv6Address": "10::2",
"neighborMacAddress": "00:00:00:33:33:33",
"nextModule": "lp0.300"
},
"kni0.400": {
"neighborIPv4Address": "10.10.10.3",
"neighborIPv6Address": "10::3",
"neighborMacAddress": "00:00:00:44:44:44",
"nextModule": "lp0.400"
}
}
}
},
"bird_import": [
{
"socket": "/tmp/yanet-bird-master4_1.sock",
"vrf": "default",
"delay": 2
},
{
"socket": "/tmp/yanet-bird-master6_1.sock",
"vrf": "default",
"delay": 2
}
]
}
70 changes: 70 additions & 0 deletions autotest/units/001_one_port/082_bird_import/controlplane2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"modules": {
"lp0.100": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "100",
"macAddress": "00:11:22:33:44:55",
"nextModule": "route0"
},
"lp0.200": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "200",
"macAddress": "00:11:22:33:44:55",
"nextModule": "route0"
},
"lp0.300": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "300",
"macAddress": "00:11:22:33:44:55",
"nextModule": "route0"
},
"lp0.400": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "400",
"macAddress": "00:11:22:33:44:55",
"nextModule": "route0"
},
"route0": {
"type": "route",
"interfaces": {
"kni0.100": {
"nextModule": "lp0.100"
},
"kni0.200": {
"neighborIPv4Address": "10.10.10.1",
"neighborIPv6Address": "10::1",
"neighborMacAddress": "00:00:00:22:22:22",
"nextModule": "lp0.200"
},
"kni0.300": {
"neighborIPv4Address": "10.10.10.2",
"neighborIPv6Address": "10::2",
"neighborMacAddress": "00:00:00:33:33:33",
"nextModule": "lp0.300"
},
"kni0.400": {
"neighborIPv4Address": "10.10.10.3",
"neighborIPv6Address": "10::3",
"neighborMacAddress": "00:00:00:44:44:44",
"nextModule": "lp0.400"
}
}
}
},
"bird_import": [
{
"socket": "/tmp/yanet-bird-master4_2.sock",
"vrf": "default",
"delay": 2
},
{
"socket": "/tmp/yanet-bird-master6_2.sock",
"vrf": "default",
"delay": 2
}
]
}
Loading