Skip to content

Commit

Permalink
Added autotests that emulate reading the routing table from bird
Browse files Browse the repository at this point in the history
  • Loading branch information
stal76 committed Feb 12, 2025
1 parent d9dd79c commit a0292f3
Show file tree
Hide file tree
Showing 15 changed files with 348 additions and 0 deletions.
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
}
]
}
70 changes: 70 additions & 0 deletions autotest/units/001_one_port/082_bird_import/controlplane3.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_3.sock",
"vrf": "default",
"delay": 2
},
{
"socket": "/tmp/yanet-bird-master6_3.sock",
"vrf": "default",
"delay": 2
}
]
}
89 changes: 89 additions & 0 deletions autotest/units/001_one_port/082_bird_import/gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from scapy.all import *
from scapy.contrib.mpls import MPLS


def write_pcap(filename, *packetsList):
if len(packetsList) == 0:
writer=PcapWriter(filename)
return

PcapWriter(filename)

for packets in packetsList:
if type(packets) == list:
for packet in packets:
packet.time = 0
wrpcap(filename, [p for p in packet], append=True)
else:
packets.time = 0
wrpcap(filename, [p for p in packets], append=True)


'''
At the first stage, the routing table should be as follows:
route 0.0.0.0/0 via 10.10.10.1;
route 1.0.0.0/8 via 10.10.10.2;
route 2.0.0.0/8 via 10.10.10.3;
route ::/0 via 10::1;
route 1::/64 via 10::2;
route 2::/64 via 10::3;
'''

write_pcap("001-send.pcap",
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:01")/Dot1Q(vlan=100)/IP(dst="1.0.0.127", src="11.0.0.1")/ICMP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:01")/Dot1Q(vlan=100)/IP(dst="1.1.0.127", src="11.0.0.1")/ICMP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:01")/Dot1Q(vlan=100)/IP(dst="2.0.0.127", src="11.0.0.1")/ICMP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:01")/Dot1Q(vlan=100)/IP(dst="3.0.0.127", src="11.0.0.1")/ICMP(),

Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:01")/Dot1Q(vlan=100)/IPv6(dst="1::1", src="11::1")/ICMP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:01")/Dot1Q(vlan=100)/IPv6(dst="1::1:1", src="11::1")/ICMP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:01")/Dot1Q(vlan=100)/IPv6(dst="2::1", src="11::1")/ICMP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:01")/Dot1Q(vlan=100)/IPv6(dst="3::1", src="11::1")/ICMP(),
)

write_pcap("001-expect.pcap",
Ether(dst="00:00:00:33:33:33", src="00:11:22:33:44:55")/Dot1Q(vlan=300)/IP(dst="1.0.0.127", src="11.0.0.1", ttl=63)/ICMP(),
Ether(dst="00:00:00:33:33:33", src="00:11:22:33:44:55")/Dot1Q(vlan=300)/IP(dst="1.1.0.127", src="11.0.0.1", ttl=63)/ICMP(),
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IP(dst="2.0.0.127", src="11.0.0.1", ttl=63)/ICMP(),
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IP(dst="3.0.0.127", src="11.0.0.1", ttl=63)/ICMP(),

Ether(dst="00:00:00:33:33:33", src="00:11:22:33:44:55")/Dot1Q(vlan=300)/IPv6(dst="1::1", src="11::1", hlim=63)/ICMP(),
Ether(dst="00:00:00:33:33:33", src="00:11:22:33:44:55")/Dot1Q(vlan=300)/IPv6(dst="1::1:1", src="11::1", hlim=63)/ICMP(),
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IPv6(dst="2::1", src="11::1", hlim=63)/ICMP(),
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IPv6(dst="3::1", src="11::1", hlim=63)/ICMP(),
)

'''
At the second stage, the following changes occur:
del route 2.0.0.0/8 via 10.10.10.3;
add route 1.0.0.0/16 via 10.10.10.3;
The routing table should be as follows:
route 0.0.0.0/0 via 10.10.10.1;
route 1.0.0.0/8 via 10.10.10.2;
route 1.0.0.0/16 via 10.10.10.3;
route ::/0 via 10::1;
route 1::/64 via 10::2;
route 1::/120 via 10::3;
'''


write_pcap("002-expect.pcap",
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IP(dst="1.0.0.127", src="11.0.0.1", ttl=63)/ICMP(),
Ether(dst="00:00:00:33:33:33", src="00:11:22:33:44:55")/Dot1Q(vlan=300)/IP(dst="1.1.0.127", src="11.0.0.1", ttl=63)/ICMP(),
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IP(dst="2.0.0.127", src="11.0.0.1", ttl=63)/ICMP(),
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IP(dst="3.0.0.127", src="11.0.0.1", ttl=63)/ICMP(),

Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IPv6(dst="1::1", src="11::1", hlim=63)/ICMP(),
Ether(dst="00:00:00:33:33:33", src="00:11:22:33:44:55")/Dot1Q(vlan=300)/IPv6(dst="1::1:1", src="11::1", hlim=63)/ICMP(),
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IPv6(dst="2::1", src="11::1", hlim=63)/ICMP(),
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IPv6(dst="3::1", src="11::1", hlim=63)/ICMP(),
)

'''
At the third stage, all routes are deleted and the routing table should be empty.
'''

0 comments on commit a0292f3

Please sign in to comment.