diff --git a/flock/bgp-secondary/bird_dest.conf b/flock/bgp-secondary/bird_dest.conf index f2fb8336..f17f3127 100644 --- a/flock/bgp-secondary/bird_dest.conf +++ b/flock/bgp-secondary/bird_dest.conf @@ -14,8 +14,8 @@ protocol kernel kernel6 { } protocol bgp LINK { - local {{ link["dest"]["ipv6"].ip }} as 2; - neighbor {{ link["src"]["ipv6"].ip }} as 1; + local {{ links["L"]["dest"]["ipv6"].ip }} as 2; + neighbor {{ links["L"]["src"]["ipv6"].ip }} as 1; ipv6 { import all; export none; diff --git a/flock/bgp-secondary/bird_src.conf b/flock/bgp-secondary/bird_src.conf index 86051baf..445f71ec 100644 --- a/flock/bgp-secondary/bird_src.conf +++ b/flock/bgp-secondary/bird_src.conf @@ -89,8 +89,8 @@ function CHECK() -> bool { } protocol bgp LINK { - local {{ link["src"]["ipv6"].ip }} as 1; - neighbor {{ link["dest"]["ipv6"].ip }} as 2; + local {{ links["L"]["src"]["ipv6"].ip }} as 1; + neighbor {{ links["L"]["dest"]["ipv6"].ip }} as 2; ipv6 { import none; export where CHECK(); diff --git a/flock/bgp-secondary/test.py b/flock/bgp-secondary/test.py index 3c4ea919..75474c27 100644 --- a/flock/bgp-secondary/test.py +++ b/flock/bgp-secondary/test.py @@ -22,6 +22,9 @@ class ThisTest(Test): "src", "dest", t=BIRDInstance, ) + self.links = { + "L": await self.link("L", "src", "dest") + } async def main(): t = ThisTest(name) @@ -29,33 +32,18 @@ async def main(): h = t.hypervisor - link, = await asyncio.gather( - 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) + print(t.links, t.src, t.dest) env = jinja2.Environment() src_conf = open("bird_src.conf", "r").read() jt = env.from_string(src_conf) 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() jt = env.from_string(dest_conf) 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(*[ h.control_socket.send_cmd("run_in", where, "./bird", "-l") diff --git a/flock/lib/BIRD/Test.py b/flock/lib/BIRD/Test.py index cd8b2515..52a48844 100644 --- a/flock/lib/BIRD/Test.py +++ b/flock/lib/BIRD/Test.py @@ -1,4 +1,5 @@ import asyncio +import ipaddress import os import pathlib import sys @@ -75,7 +76,13 @@ class BIRDInstance(CLI): self.bindir.copy(self.workdir) 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): self.name = name @@ -83,6 +90,9 @@ class Test: self._started = asyncio.Future() 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): if self._started.done(): return await self.hypervisor.control_socket.send_cmd(*args) @@ -114,3 +124,23 @@ class Test: )) 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")