From ff09e07ae8146758c71e8ae39e2bf21d6af613ed Mon Sep 17 00:00:00 2001 From: Markuu-s Date: Sat, 28 Dec 2024 16:01:08 +0300 Subject: [PATCH] Add bird in Autotest. --- autotest/autotest.cpp | 46 ++++++++++++++ autotest/autotest.h | 2 + .../units/001_one_port/077_bird/autotest.yaml | 8 +++ .../001_one_port/077_bird/bird/bird.conf | 61 +++++++++++++++++++ .../001_one_port/077_bird/controlplane.conf | 42 +++++++++++++ 5 files changed, 159 insertions(+) create mode 100644 autotest/units/001_one_port/077_bird/autotest.yaml create mode 100644 autotest/units/001_one_port/077_bird/bird/bird.conf create mode 100644 autotest/units/001_one_port/077_bird/controlplane.conf diff --git a/autotest/autotest.cpp b/autotest/autotest.cpp index 1930d955..9268892b 100644 --- a/autotest/autotest.cpp +++ b/autotest/autotest.cpp @@ -1487,6 +1487,16 @@ 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 if (yamlStep["birdc"]) + { + YANET_LOG_DEBUG("step: birdc\n"); + } else { YANET_LOG_ERROR("unknown step\n"); @@ -2006,6 +2016,42 @@ bool tAutotest::step_dumpPackets(const YAML::Node& yamlStep, return true; } +bool tAutotest::step_bird(const YAML::Node& yamlStep, + const std::string& path) +{ + std::string confPath; + for (const auto& yamlIter : yamlStep) + { + confPath = yamlIter.as(); + } + + if (!confPath.empty()) + { + const std::string execCommand = "bird -c " + path + confPath; + + std::string resExec = exec(execCommand.c_str()); + + printf("%s", resExec.data()); + + return true; + } + return false; +} + +bool tAutotest::step_birdc(const YAML::Node& yamlStep) +{ + std::string command = "birdc "; + for (const auto& yamlIter : yamlStep) + { + command += yamlIter.as() + " "; + } + + auto res_birdc = exec(command.c_str()); + + printf("birdc:\n %s\n", res_birdc.data()); + return true; +} + void tAutotest::fflushSharedMemory() { size_t size = std::get<0>(rawShmInfo); diff --git a/autotest/autotest.h b/autotest/autotest.h index edd2c840..f25fe715 100644 --- a/autotest/autotest.h +++ b/autotest/autotest.h @@ -69,6 +69,8 @@ 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); + bool step_birdc(const YAML::Node& yamlStep); eResult initSockets(); eResult initSharedMemory(); diff --git a/autotest/units/001_one_port/077_bird/autotest.yaml b/autotest/units/001_one_port/077_bird/autotest.yaml new file mode 100644 index 00000000..4caa1fa0 --- /dev/null +++ b/autotest/units/001_one_port/077_bird/autotest.yaml @@ -0,0 +1,8 @@ +steps: +- bird: + - bird/bird.conf +- birdc: + - show route +- sleep: 20 +- cli: + - rib prefixes diff --git a/autotest/units/001_one_port/077_bird/bird/bird.conf b/autotest/units/001_one_port/077_bird/bird/bird.conf new file mode 100644 index 00000000..e152e7b2 --- /dev/null +++ b/autotest/units/001_one_port/077_bird/bird/bird.conf @@ -0,0 +1,61 @@ +/* + * This is a simple example configuration file with no aim for completeness. + * See documentation for full description. + */ + +# Router ID in IPv4 format +router id 62.168.0.1; + +# Load device information from kernel. +protocol device {} + +# Generate direct routes for interfaces. Useful on BSD. +protocol direct { + ipv4; + disabled; +} + +protocol direct { + ipv6; + disabled; +} + +# Feed routes to kernel FIB +protocol kernel { + ipv4 { export all; import all; }; + learn; # Learn all routes from the kernel +# scan time 10; # Scan kernel tables every 10 seconds +} + +protocol kernel { + ipv6 { import all; }; + learn; +} + +# Static route feed +protocol static { + ipv4 { export all; }; + route 10.0.0.0/24 via 192.168.1.32; + route 10.10.0.0/16 blackhole; + route 10.20.0.0/20 via 192.168.1.22; + route 10.30.50.0/28 prohibit; +} + +protocol static { + ipv6 { export all; }; + route 2001:db8:1::/48 via 5555::6666; + route 2001:db8:2::/48 blackhole; + route 2001:db8:3::/48 prohibit; + route 2001:db8:4::/48 unreachable; +} + +protocol export { + table master4; + socket "/var/tmp/bird-master4.sock"; +} + +protocol export { + table master6; + socket "/var/tmp/bird-master6.sock"; +} + diff --git a/autotest/units/001_one_port/077_bird/controlplane.conf b/autotest/units/001_one_port/077_bird/controlplane.conf new file mode 100644 index 00000000..6f37692d --- /dev/null +++ b/autotest/units/001_one_port/077_bird/controlplane.conf @@ -0,0 +1,42 @@ +{ + "modules": { + "lp0.100": { + "type": "logicalPort", + "physicalPort": "kni0", + "vlanId": "100", + "macAddress": "00:11:22:33:44:55", + "nextModule": "vrf0" + }, + "lp0.200": { + "type": "logicalPort", + "physicalPort": "kni0", + "vlanId": "200", + "macAddress": "00:11:22:33:44:55", + "nextModule": "vrf0" + }, + "vrf0": { + "type": "route", + "interfaces": { + "kni0.100": { + "nextModule": "lp0.100" + }, + "kni0.200": { + "ipv4Prefix": "200.0.0.2/24", + "neighborIPv4Address": "200.0.0.1", + "neighborMacAddress": "00:00:00:11:11:11", + "nextModule": "lp0.200" + } + }, + "birdImport": [ + { + "socket": "/var/tmp/bird-master4.sock", + "vrf": "master4" + }, + { + "socket": "/var/tmp/bird-master6.sock", + "vrf": "master6" + } + ] + } + } +}