Skip to content

Commit

Permalink
Added autotests for vrf
Browse files Browse the repository at this point in the history
  • Loading branch information
stal76 committed Dec 22, 2024
1 parent a180c58 commit 79639b4
Show file tree
Hide file tree
Showing 27 changed files with 827 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
68 changes: 68 additions & 0 deletions autotest/units/001_one_port/078_vrf_route/autotest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
steps:
- cli:
- rib static insert default 0.0.0.0/0 200.0.10.1
- rib static insert default 1.0.0.0/24 200.0.20.1
- rib static insert default 2.0.0.0/24 200.0.40.1
- rib static insert red 0.0.0.0/0 200.0.30.1
- rib static insert red 1.0.0.0/24 200.0.10.1
- rib static insert red 2.0.0.0/24 200.0.20.1
- rib static insert white 1.0.0.0/24 200.0.40.1
- rib static insert white 1.0.0.16/28 200.0.10.1
- rib static insert white 1.0.0.16/30 200.0.20.1
- cli:
- rib static insert default ::/0 c0de::10:1
- rib static insert default 7e01::/64 c0de::20:1
- rib static insert default 7e02::/64 c0de::40:1
- rib static insert red ::/0 c0de::30:1
- rib static insert red 7e01::/64 c0de::10:1
- rib static insert red 7e02::/64 c0de::20:1
- rib static insert white 7e01::/64 c0de::40:1
- rib static insert white 7e01::/96 c0de::10:1
- rib static insert white 7e01::/128 c0de::20:1
- cli:
- rib prefixes

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

- cli:
- rib static remove default 1.0.0.0/24 200.0.20.1
- rib static remove red 0.0.0.0/0 200.0.30.1
- rib static remove white 1.0.0.16/30 200.0.20.1
- rib static remove default 7e01::/64 c0de::20:1
- rib static remove red ::/0 c0de::30:1
- rib static remove white 7e01::/128 c0de::20:1
- cli:
- rib prefixes

- sendPackets:
- port: kni0
send: 003-send.pcap
expect: 003-expect.pcap
- sendPackets:
- port: kni0
send: 004-send.pcap
expect: 004-expect.pcap

- cli:
- rib static remove default 0.0.0.0/0 200.0.10.1
- rib static remove default 2.0.0.0/24 200.0.40.1
- rib static remove red 1.0.0.0/24 200.0.10.1
- rib static remove red 2.0.0.0/24 200.0.20.1
- rib static remove white 1.0.0.0/24 200.0.40.1
- rib static remove white 1.0.0.16/28 200.0.10.1
- cli:
- rib static remove default ::/0 c0de::10:1
- rib static remove default 7e02::/64 c0de::40:1
- rib static remove red 7e01::/64 c0de::10:1
- rib static remove red 7e02::/64 c0de::20:1
- rib static remove white 7e01::/64 c0de::40:1
- rib static remove white 7e01::/96 c0de::10:1
- cli:
- rib prefixes
67 changes: 67 additions & 0 deletions autotest/units/001_one_port/078_vrf_route/controlplane.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"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",
"vrf": "red"
},
"lp0.400": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "400",
"macAddress": "00:11:22:33:44:55",
"nextModule": "route0",
"vrf": "white"
},
"route0": {
"type": "route",
"interfaces": {
"kni0.100": {
"ipv4Prefix": "200.0.10.0/24",
"neighborIPv4Address": "200.0.10.1",
"neighborIPv6Address": "c0de::10:1",
"neighborMacAddress": "00:00:00:11:11:11",
"nextModule": "lp0.100"
},
"kni0.200": {
"ipv4Prefix": "200.0.20.0/24",
"neighborIPv4Address": "200.0.20.1",
"neighborIPv6Address": "c0de::20:1",
"neighborMacAddress": "00:00:00:22:22:22",
"nextModule": "lp0.200"
},
"kni0.300": {
"ipv4Prefix": "200.0.30.0/24",
"neighborIPv4Address": "200.0.30.1",
"neighborIPv6Address": "c0de::30:1",
"neighborMacAddress": "00:00:00:33:33:33",
"nextModule": "lp0.300"
},
"kni0.400": {
"ipv4Prefix": "200.0.40.0/24",
"neighborIPv4Address": "200.0.40.1",
"neighborIPv6Address": "c0de::40:1",
"neighborMacAddress": "00:00:00:44:44:44",
"nextModule": "lp0.400"
}
}
}
}
}
174 changes: 174 additions & 0 deletions autotest/units/001_one_port/078_vrf_route/gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#!/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:
PcapWriter(filename)._write_header(Ether())
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)

# IPv4

def write_pcap_ipv4(filename):
write_pcap(filename,
# vlan 100, 200 - default vrf
#
# 0.0.0.0/0 -> 200.0.10.1
# 1.0.0.0/24 -> 200.0.20.1 ! only in 001
# 2.0.0.0/24 -> 200.0.40.1
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="1.0.0.1", src="222.222.222.222", ttl=64)/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="2.0.0.1", src="222.222.222.222", ttl=64)/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="3.0.0.1", src="222.222.222.222", ttl=64)/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=200)/IP(dst="1.0.0.1", src="222.222.222.222", ttl=64)/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=200)/IP(dst="2.0.0.1", src="222.222.222.222", ttl=64)/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=200)/IP(dst="3.0.0.1", src="222.222.222.222", ttl=64)/TCP(),

# vlan 300 - vrf "red"
#
# 0.0.0.0/0 -> 200.0.30.1 ! only in 001
# 1.0.0.0/24 -> 200.0.10.1
# 2.0.0.0/24 -> 200.0.20.1
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=300)/IP(dst="1.0.0.1", src="222.222.222.222", ttl=64)/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=300)/IP(dst="2.0.0.1", src="222.222.222.222", ttl=64)/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=300)/IP(dst="3.0.0.1", src="222.222.222.222", ttl=64)/TCP(),

# vlan 400 - vrf "white"
#
# 1.0.0.0/24 -> 200.0.40.1
# 1.0.0.16/28 -> 200.0.10.1 ! only in 001
# 1.0.0.16/30 -> 200.0.20.2
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=400)/IP(dst="1.0.0.1", src="222.222.222.222", ttl=64)/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=400)/IP(dst="1.0.0.17", src="222.222.222.222", ttl=64)/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=400)/IP(dst="1.0.0.21", src="222.222.222.222", ttl=64)/TCP(),
# no route for these 2 packets:
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=400)/IP(dst="2.0.0.1", src="222.222.222.222", ttl=64)/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=400)/IP(dst="3.0.0.1", src="222.222.222.222", ttl=64)/TCP())

write_pcap_ipv4("001-send.pcap")
write_pcap("001-expect.pcap",
# vlan 100, 200 - default vrf
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IP(dst="1.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IP(dst="2.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="3.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IP(dst="1.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IP(dst="2.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="3.0.0.1", src="222.222.222.222", ttl=63)/TCP(),

# vlan 300 - vrf "red"
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="1.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IP(dst="2.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:33:33:33", src="00:11:22:33:44:55")/Dot1Q(vlan=300)/IP(dst="3.0.0.1", src="222.222.222.222", ttl=63)/TCP(),

# vlan 400 - vrf "white"
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IP(dst="1.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IP(dst="1.0.0.17", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="1.0.0.21", src="222.222.222.222", ttl=63)/TCP())

write_pcap_ipv4("003-send.pcap")
write_pcap("003-expect.pcap",
# vlan 100, 200 - default vrf
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="1.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IP(dst="2.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="3.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="1.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IP(dst="2.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="3.0.0.1", src="222.222.222.222", ttl=63)/TCP(),

# vlan 300 - vrf "red"
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="1.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IP(dst="2.0.0.1", src="222.222.222.222", ttl=63)/TCP(),

# vlan 400 - vrf "white"
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IP(dst="1.0.0.1", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="1.0.0.17", src="222.222.222.222", ttl=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="1.0.0.21", src="222.222.222.222", ttl=63)/TCP())

# IPv6

def write_pcap_ipv6(filename):
write_pcap(filename,
# vlan 100, 200 - default vrf
#
# ::/0 -> c0de::10:1
# 7e01::/64 -> c0de::20:1 ! only in 001
# 7e02::/64 -> c0de::40:1
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IPv6(dst="7e01::1", src="2222::2222")/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IPv6(dst="7e02::1", src="2222::2222")/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IPv6(dst="7e03::1", src="2222::2222")/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=200)/IPv6(dst="7e01::1", src="2222::2222")/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=200)/IPv6(dst="7e02::1", src="2222::2222")/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=200)/IPv6(dst="7e03::1", src="2222::2222")/TCP(),

# vlan 300 - vrf "red"
#
# ::/0 -> c0de::30:1 ! only in 001
# 7e01::/64 -> c0de::10:1
# 7e02::/64 -> c0de::20:1
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=300)/IPv6(dst="7e01::1", src="2222::2222")/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=300)/IPv6(dst="7e02::1", src="2222::2222")/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=300)/IPv6(dst="7e03::1", src="2222::2222")/TCP(),

# vlan 400 - vrf "white"
#
# 7e01::/64 -> c0de::40:1
# 7e01::/96 -> c0de::10:1
# 7e01::/128 -> c0de::20:1 ! only in 001
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=400)/IPv6(dst="7e01:0::1:0:0:1", src="2222::2222")/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=400)/IPv6(dst="7e01::1", src="2222::2222")/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=400)/IPv6(dst="7e01::0", src="2222::2222")/TCP(),
# no route for these 2 packets:
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=400)/IPv6(dst="7e02::1", src="2222::2222")/TCP(),
Ether(dst="00:11:22:33:44:55", src="00:00:00:11:11:11")/Dot1Q(vlan=400)/IPv6(dst="7e03::1", src="2222::2222")/TCP())

write_pcap_ipv6("002-send.pcap")
write_pcap("002-expect.pcap",
# vlan 100, 200 - default vrf
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IPv6(dst="7e01::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IPv6(dst="7e02::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="7e03::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IPv6(dst="7e01::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IPv6(dst="7e02::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="7e03::1", src="2222::2222", hlim=63)/TCP(),

# vlan 300 - vrf "red"
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="7e01::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IPv6(dst="7e02::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:33:33:33", src="00:11:22:33:44:55")/Dot1Q(vlan=300)/IPv6(dst="7e03::1", src="2222::2222", hlim=63)/TCP(),

# vlan 400 - vrf "white"
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IPv6(dst="7e01:0::1:0:0:1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="7e01::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IPv6(dst="7e01::0", src="2222::2222", hlim=63)/TCP())

write_pcap_ipv6("004-send.pcap")
write_pcap("004-expect.pcap",
# vlan 100, 200 - default vrf
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="7e01::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IPv6(dst="7e02::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="7e03::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="7e01::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IPv6(dst="7e02::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="7e03::1", src="2222::2222", hlim=63)/TCP(),

# vlan 300 - vrf "red"
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="7e01::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:22:22:22", src="00:11:22:33:44:55")/Dot1Q(vlan=200)/IPv6(dst="7e02::1", src="2222::2222", hlim=63)/TCP(),

# vlan 400 - vrf "white"
Ether(dst="00:00:00:44:44:44", src="00:11:22:33:44:55")/Dot1Q(vlan=400)/IPv6(dst="7e01:0::1:0:0:1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="7e01::1", src="2222::2222", hlim=63)/TCP(),
Ether(dst="00:00:00:11:11:11", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="7e01::0", src="2222::2222", hlim=63)/TCP())
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
steps:
- ipv4Update: "0.0.0.0/0 -> 200.0.0.1"
- ipv6Update: "::/0 -> fe80::1"
- cli:
- rib static insert red 0.0.0.0/0 200.0.0.1
- rib static insert blue 0.0.0.0/0 200.0.0.1
- rib static insert white ::/0 fe80::1
- rib static insert green ::/0 fe80::1
- rib prefixes
- sendPackets:
- port: kni0
send: 001-send.pcap
expect: 001-expect.pcap
- sendPackets:
- port: kni0
send: 002-send.pcap
expect: 002-expect.pcap
- sendPackets:
- port: kni0
send: 003-send.pcap
expect: 003-expect.pcap
- cli:
- counter interface_lookupMisses
Loading

0 comments on commit 79639b4

Please sign in to comment.