mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 17:51:53 +00:00
Flock tests: autonumbering links hidden into the lib
This commit is contained in:
parent
f98bc285c4
commit
d84d2d64cd
@ -14,8 +14,8 @@ protocol kernel kernel6 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protocol bgp LINK {
|
protocol bgp LINK {
|
||||||
local {{ link["dest"]["ipv6"].ip }} as 2;
|
local {{ links["L"]["dest"]["ipv6"].ip }} as 2;
|
||||||
neighbor {{ link["src"]["ipv6"].ip }} as 1;
|
neighbor {{ links["L"]["src"]["ipv6"].ip }} as 1;
|
||||||
ipv6 {
|
ipv6 {
|
||||||
import all;
|
import all;
|
||||||
export none;
|
export none;
|
||||||
|
@ -89,8 +89,8 @@ function CHECK() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protocol bgp LINK {
|
protocol bgp LINK {
|
||||||
local {{ link["src"]["ipv6"].ip }} as 1;
|
local {{ links["L"]["src"]["ipv6"].ip }} as 1;
|
||||||
neighbor {{ link["dest"]["ipv6"].ip }} as 2;
|
neighbor {{ links["L"]["dest"]["ipv6"].ip }} as 2;
|
||||||
ipv6 {
|
ipv6 {
|
||||||
import none;
|
import none;
|
||||||
export where CHECK();
|
export where CHECK();
|
||||||
|
@ -22,6 +22,9 @@ class ThisTest(Test):
|
|||||||
"src", "dest",
|
"src", "dest",
|
||||||
t=BIRDInstance,
|
t=BIRDInstance,
|
||||||
)
|
)
|
||||||
|
self.links = {
|
||||||
|
"L": await self.link("L", "src", "dest")
|
||||||
|
}
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
t = ThisTest(name)
|
t = ThisTest(name)
|
||||||
@ -29,33 +32,18 @@ async def main():
|
|||||||
|
|
||||||
h = t.hypervisor
|
h = t.hypervisor
|
||||||
|
|
||||||
link, = await asyncio.gather(
|
print(t.links, t.src, t.dest)
|
||||||
h.control_socket.send_cmd("link", "L", {
|
|
||||||
"machines": {
|
|
||||||
"src": { "name": "L" },
|
|
||||||
"dest": { "name": "L" },
|
|
||||||
},
|
|
||||||
"ipv6": "2001:db8:0:1::/64",
|
|
||||||
"ipv4": "10.0.1.0/29",
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
for m in link:
|
|
||||||
for i in ("ipv4", "ipv6"):
|
|
||||||
link[m][i] = ipaddress.ip_interface(link[m][i])
|
|
||||||
|
|
||||||
print(link, t.src, t.dest)
|
|
||||||
|
|
||||||
env = jinja2.Environment()
|
env = jinja2.Environment()
|
||||||
src_conf = open("bird_src.conf", "r").read()
|
src_conf = open("bird_src.conf", "r").read()
|
||||||
jt = env.from_string(src_conf)
|
jt = env.from_string(src_conf)
|
||||||
with open(t.src.workdir / "bird.conf", "w") as f:
|
with open(t.src.workdir / "bird.conf", "w") as f:
|
||||||
f.write(jt.render( link=link ))
|
f.write(jt.render( links=t.links ))
|
||||||
|
|
||||||
dest_conf = open("bird_dest.conf", "r").read()
|
dest_conf = open("bird_dest.conf", "r").read()
|
||||||
jt = env.from_string(dest_conf)
|
jt = env.from_string(dest_conf)
|
||||||
with open(t.dest.workdir / "bird.conf", "w") as f:
|
with open(t.dest.workdir / "bird.conf", "w") as f:
|
||||||
f.write(jt.render( link=link ))
|
f.write(jt.render( links=t.links ))
|
||||||
|
|
||||||
print(await asyncio.gather(*[
|
print(await asyncio.gather(*[
|
||||||
h.control_socket.send_cmd("run_in", where, "./bird", "-l")
|
h.control_socket.send_cmd("run_in", where, "./bird", "-l")
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import ipaddress
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import sys
|
import sys
|
||||||
@ -75,7 +76,13 @@ class BIRDInstance(CLI):
|
|||||||
self.bindir.copy(self.workdir)
|
self.bindir.copy(self.workdir)
|
||||||
|
|
||||||
class Test:
|
class Test:
|
||||||
machines_start = {}
|
ipv6_prefix = ipaddress.ip_network("2001:db8::/32")
|
||||||
|
ipv4_prefix = ipaddress.ip_network("192.0.2.0/24")
|
||||||
|
|
||||||
|
ipv6_link_pxlen = 64
|
||||||
|
ipv4_link_pxlen = 28
|
||||||
|
|
||||||
|
# 198.51.100.0/24, 203.0.113.0/24
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
@ -83,6 +90,9 @@ class Test:
|
|||||||
self._started = asyncio.Future()
|
self._started = asyncio.Future()
|
||||||
self._starting = False
|
self._starting = False
|
||||||
|
|
||||||
|
self.ipv6_pxgen = self.ipv6_prefix.subnets(new_prefix=self.ipv6_link_pxlen)
|
||||||
|
self.ipv4_pxgen = self.ipv4_prefix.subnets(new_prefix=self.ipv4_link_pxlen)
|
||||||
|
|
||||||
async def hcom(self, *args):
|
async def hcom(self, *args):
|
||||||
if self._started.done():
|
if self._started.done():
|
||||||
return await self.hypervisor.control_socket.send_cmd(*args)
|
return await self.hypervisor.control_socket.send_cmd(*args)
|
||||||
@ -114,3 +124,23 @@ class Test:
|
|||||||
)) for n,i in zip(names, info)
|
)) for n,i in zip(names, info)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
async def link(self, name, *machines):
|
||||||
|
match len(machines):
|
||||||
|
case 0:
|
||||||
|
raise Exception("Link with no machines? HOW?!")
|
||||||
|
case 1:
|
||||||
|
raise NotImplementedError("dummy link")
|
||||||
|
case 2:
|
||||||
|
linfo = await self.hcom("link", name, {
|
||||||
|
"machines": { m: { "name": name } for m in machines },
|
||||||
|
"ipv6": str(next(self.ipv6_pxgen)),
|
||||||
|
"ipv4": str(next(self.ipv4_pxgen)),
|
||||||
|
})
|
||||||
|
for m in machines:
|
||||||
|
for i in ("ipv4", "ipv6"):
|
||||||
|
linfo[m][i] = ipaddress.ip_interface(linfo[m][i])
|
||||||
|
|
||||||
|
return linfo
|
||||||
|
|
||||||
|
case _:
|
||||||
|
raise NotImplementedError("virtual bridge")
|
||||||
|
Loading…
Reference in New Issue
Block a user