From 4844dc71a7d3699495b7733536d38c201a12ef80 Mon Sep 17 00:00:00 2001 From: "guozhongfeng.gzf" Date: Sun, 8 Dec 2024 15:30:55 +0800 Subject: [PATCH] topotests:Add test fo bgp l3vpn over srv6 te policy Signed-off-by: guozhongfeng.gzf --- .../bgp_srv6l3vpn_te_policy/ce1/bgpd.conf | 0 .../bgp_srv6l3vpn_te_policy/ce1/zebra.conf | 14 ++ .../bgp_srv6l3vpn_te_policy/ce2/bgpd.conf | 0 .../bgp_srv6l3vpn_te_policy/ce2/zebra.conf | 14 ++ .../bgp_srv6l3vpn_te_policy/ce3/bgpd.conf | 0 .../bgp_srv6l3vpn_te_policy/ce3/zebra.conf | 14 ++ .../bgp_srv6l3vpn_te_policy/ce4/bgpd.conf | 0 .../bgp_srv6l3vpn_te_policy/ce4/zebra.conf | 14 ++ .../json/vpnv4_vrf1_rib_route.json | 60 ++++++ .../json/vpnv4_vrf2_rib_route.json | 60 ++++++ .../json/vpnv6_vrf1_rib_route.json | 61 ++++++ .../json/vpnv6_vrf2_rib_route.json | 61 ++++++ .../json/vrf1_ipv4_route.json | 67 ++++++ .../json/vrf1_ipv4_route_te_policy.json | 70 ++++++ .../json/vrf1_ipv6_route.json | 67 ++++++ .../json/vrf1_ipv6_route_te_policy.json | 70 ++++++ .../json/vrf2_ipv4_route.json | 67 ++++++ .../json/vrf2_ipv4_route_te_policy.json | 70 ++++++ .../json/vrf2_ipv6_route.json | 67 ++++++ .../json/vrf2_ipv6_route_te_policy.json | 70 ++++++ .../bgp_srv6l3vpn_te_policy/p1/bgpd.conf | 17 ++ .../bgp_srv6l3vpn_te_policy/p1/zebra.conf | 30 +++ .../bgp_srv6l3vpn_te_policy/p2/bgpd.conf | 17 ++ .../bgp_srv6l3vpn_te_policy/p2/zebra.conf | 31 +++ .../bgp_srv6l3vpn_te_policy/pe1/bgpd.conf | 95 +++++++++ .../bgp_srv6l3vpn_te_policy/pe1/pathd.conf | 0 .../bgp_srv6l3vpn_te_policy/pe1/zebra.conf | 39 ++++ .../bgp_srv6l3vpn_te_policy/pe2/bgpd.conf | 88 ++++++++ .../bgp_srv6l3vpn_te_policy/pe2/pathd.conf | 10 + .../bgp_srv6l3vpn_te_policy/pe2/zebra.conf | 39 ++++ .../test_bgp_srv6l3vpn_te_policy.py | 199 ++++++++++++++++++ 31 files changed, 1411 insertions(+) create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/ce1/bgpd.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/ce1/zebra.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/ce2/bgpd.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/ce2/zebra.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/ce3/bgpd.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/ce3/zebra.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/ce4/bgpd.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/ce4/zebra.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv4_vrf1_rib_route.json create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv4_vrf2_rib_route.json create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv6_vrf1_rib_route.json create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv6_vrf2_rib_route.json create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv4_route.json create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv4_route_te_policy.json create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv6_route.json create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv6_route_te_policy.json create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv4_route.json create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv4_route_te_policy.json create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv6_route.json create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv6_route_te_policy.json create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/p1/bgpd.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/p1/zebra.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/p2/bgpd.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/p2/zebra.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/pe1/bgpd.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/pe1/pathd.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/pe1/zebra.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/pe2/bgpd.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/pe2/pathd.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/pe2/zebra.conf create mode 100644 tests/topotests/bgp_srv6l3vpn_te_policy/test_bgp_srv6l3vpn_te_policy.py diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/ce1/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/ce1/bgpd.conf new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/ce1/zebra.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/ce1/zebra.conf new file mode 100644 index 000000000000..5afbf6fdd759 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/ce1/zebra.conf @@ -0,0 +1,14 @@ +hostname ce1 +! +interface eth0 + ip address 192.168.1.2/24 + ipv6 address 1001:1::2/64 +! +ip forwarding +ipv6 forwarding +! +ip route 0.0.0.0/0 192.168.1.1 +ipv6 route ::/0 1001:1::1 +! +line vty +! diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/ce2/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/ce2/bgpd.conf new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/ce2/zebra.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/ce2/zebra.conf new file mode 100644 index 000000000000..aa37ee19d6d2 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/ce2/zebra.conf @@ -0,0 +1,14 @@ +hostname ce2 +! +interface eth0 + ip address 192.168.2.2/24 + ipv6 address 1001:2::2/64 +! +ip forwarding +ipv6 forwarding +! +ip route 0.0.0.0/0 192.168.2.1 +ipv6 route ::/0 1001:2::1 +! +line vty +! diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/ce3/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/ce3/bgpd.conf new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/ce3/zebra.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/ce3/zebra.conf new file mode 100644 index 000000000000..0dd8cde58baa --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/ce3/zebra.conf @@ -0,0 +1,14 @@ +hostname ce3 +! +interface eth0 + ip address 192.168.3.2/24 + ipv6 address 1001:3::2/64 +! +ip forwarding +ipv6 forwarding +! +ip route 0.0.0.0/0 192.168.3.1 +ipv6 route ::/0 1001:3::1 +! +line vty +! diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/ce4/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/ce4/bgpd.conf new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/ce4/zebra.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/ce4/zebra.conf new file mode 100644 index 000000000000..34fc1ca74064 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/ce4/zebra.conf @@ -0,0 +1,14 @@ +hostname ce2 +! +interface eth0 + ip address 192.168.4.2/24 + ipv6 address 1001:4::2/64 +! +ip forwarding +ipv6 forwarding +! +ip route 0.0.0.0/0 192.168.4.1 +ipv6 route ::/0 1001:4::1 +! +line vty +! diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv4_vrf1_rib_route.json b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv4_vrf1_rib_route.json new file mode 100644 index 000000000000..e1d0695a9783 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv4_vrf1_rib_route.json @@ -0,0 +1,60 @@ +{ + "1:10":{ + "prefix":"192.168.1.0/24", + "version":1, + "advertisedTo":{ + "1000::1":{ + "hostname":"pe1" + } + }, + "paths":[ + { + "aspath":{ + "string":"65501", + "segments":[ + { + "type":"as-sequence", + "list":[ + 65501 + ] + } + ], + "length":1 + }, + "origin":"incomplete", + "metric":0, + "valid":true, + "version":1, + "bestpath":{ + "overall":true, + "selectionReason":"First path received" + }, + "extendedCommunity":{ + "string":"RT:99:99 Color:01:100" + }, + "remoteLabel":"*", + "remoteSid":"2001:db8:1:1::", + "lastUpdate":{ + "epoch":"*", + "string":"*" + }, + "nexthops":[ + { + "ip":"0.0.0.0", + "hostname":"pe1", + "afi":"ipv4", + "metric":0, + "accessible":true, + "used":true + } + ], + "peer":{ + "peerId":"1000::1", + "routerId":"1.1.1.1", + "hostname":"pe1", + "type":"external" + } + } + ] + } +} diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv4_vrf2_rib_route.json b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv4_vrf2_rib_route.json new file mode 100644 index 000000000000..2308493255e9 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv4_vrf2_rib_route.json @@ -0,0 +1,60 @@ +{ + "1:20":{ + "prefix":"192.168.2.0/24", + "version":1, + "advertisedTo":{ + "1000::1":{ + "hostname":"pe1" + } + }, + "paths":[ + { + "aspath":{ + "string":"65501", + "segments":[ + { + "type":"as-sequence", + "list":[ + 65501 + ] + } + ], + "length":1 + }, + "origin":"incomplete", + "metric":0, + "valid":true, + "version":1, + "bestpath":{ + "overall":true, + "selectionReason":"First path received" + }, + "extendedCommunity":{ + "string":"RT:88:88 Color:01:200" + }, + "remoteLabel":"*", + "remoteSid":"2001:db8:1:1::", + "lastUpdate":{ + "epoch":"*", + "string":"*" + }, + "nexthops":[ + { + "ip":"0.0.0.0", + "hostname":"pe1", + "afi":"ipv4", + "metric":0, + "accessible":true, + "used":true + } + ], + "peer":{ + "peerId":"1000::1", + "routerId":"1.1.1.1", + "hostname":"pe1", + "type":"external" + } + } + ] + } +} diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv6_vrf1_rib_route.json b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv6_vrf1_rib_route.json new file mode 100644 index 000000000000..5ed7a0a6bda9 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv6_vrf1_rib_route.json @@ -0,0 +1,61 @@ +{ + "1:10":{ + "prefix":"1001:1::/64", + "version":1, + "advertisedTo":{ + "1000::1":{ + "hostname":"pe1" + } + }, + "paths":[ + { + "aspath":{ + "string":"65501", + "segments":[ + { + "type":"as-sequence", + "list":[ + 65501 + ] + } + ], + "length":1 + }, + "origin":"incomplete", + "metric":0, + "valid":true, + "version":1, + "bestpath":{ + "overall":true, + "selectionReason":"First path received" + }, + "extendedCommunity":{ + "string":"RT:99:99 Color:01:100" + }, + "remoteLabel":"*", + "remoteSid":"2001:db8:1:1::", + "lastUpdate":{ + "epoch":"*", + "string":"*" + }, + "nexthops":[ + { + "ip":"1000::1", + "hostname":"pe1", + "afi":"ipv6", + "scope":"global", + "metric":0, + "accessible":true, + "used":true + } + ], + "peer":{ + "peerId":"1000::1", + "routerId":"1.1.1.1", + "hostname":"pe1", + "type":"external" + } + } + ] + } +} \ No newline at end of file diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv6_vrf2_rib_route.json b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv6_vrf2_rib_route.json new file mode 100644 index 000000000000..f7d6a1249f4d --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vpnv6_vrf2_rib_route.json @@ -0,0 +1,61 @@ +{ + "1:20":{ + "prefix":"1001:2::/64", + "version":1, + "advertisedTo":{ + "1000::1":{ + "hostname":"pe1" + } + }, + "paths":[ + { + "aspath":{ + "string":"65501", + "segments":[ + { + "type":"as-sequence", + "list":[ + 65501 + ] + } + ], + "length":1 + }, + "origin":"incomplete", + "metric":0, + "valid":true, + "version":1, + "bestpath":{ + "overall":true, + "selectionReason":"First path received" + }, + "extendedCommunity":{ + "string":"RT:88:88 Color:01:200" + }, + "remoteLabel":"*", + "remoteSid":"2001:db8:1:1::", + "lastUpdate":{ + "epoch":"*", + "string":"*" + }, + "nexthops":[ + { + "ip":"1000::1", + "hostname":"pe1", + "afi":"ipv6", + "scope":"global", + "metric":0, + "accessible":true, + "used":true + } + ], + "peer":{ + "peerId":"1000::1", + "routerId":"1.1.1.1", + "hostname":"pe1", + "type":"external" + } + } + ] + } +} diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv4_route.json b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv4_route.json new file mode 100644 index 000000000000..a10287700a95 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv4_route.json @@ -0,0 +1,67 @@ +{ + "192.168.1.0/24":[ + { + "prefix":"192.168.1.0/24", + "prefixLen":24, + "protocol":"bgp", + "vrfId":"*", + "vrfName":"vrf1", + "selected":true, + "destSelected":true, + "distance":20, + "metric":0, + "installed":true, + "table":1, + "internalStatus":16, + "internalFlags":9, + "internalNextHopNum":"*", + "internalNextHopActiveNum":"*", + "nexthopGroupId":"*", + "installedNexthopGroupId":"*", + "uptime":"*", + "nexthops":[ + { + "flags":5, + "ip":"1000::1", + "afi":"ipv6", + "vrf":"default", + "active":true, + "recursive":true, + "labels":"*", + "weight":1, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":{ + "segs":"2001:db8:1:1:1::" + } + }, + { + "flags":3, + "fib":true, + "ip":"*", + "afi":"ipv6", + "interfaceIndex":"*", + "interfaceName":"eth1", + "resolver":true, + "vrf":"default", + "active":true, + "labels":"*", + "weight":1, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":{ + "segs":"2001:db8:1:1:1::" + } + } + ] + } + ] +} diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv4_route_te_policy.json b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv4_route_te_policy.json new file mode 100644 index 000000000000..953390b5518f --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv4_route_te_policy.json @@ -0,0 +1,70 @@ +{ + "192.168.1.0/24":[ + { + "prefix":"192.168.1.0/24", + "prefixLen":24, + "protocol":"bgp", + "vrfId":"*", + "vrfName":"vrf1", + "selected":true, + "destSelected":true, + "distance":20, + "metric":0, + "installed":true, + "table":1, + "internalStatus":16, + "internalFlags":9, + "internalNextHopNum":"*", + "internalNextHopActiveNum":"*", + "nexthopGroupId":"*", + "installedNexthopGroupId":"*", + "uptime":"*", + "nexthops":[ + { + "flags":3205, + "ip":"1000::1", + "afi":"ipv6", + "vrf":"default", + "active":true, + "recursive":true, + "labels":"*", + "weight":1, + "srteColor":100, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":[ + "2001:db8:3:3::3", + "2001:db8:1:1::1" + ] + }, + { + "flags":2051, + "fib":true, + "ip":"*", + "afi":"ipv6", + "interfaceIndex":"*", + "interfaceName":"eth1", + "resolver":true, + "vrf":"default", + "active":true, + "labels":"*", + "weight":1, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":[ + "2001:db8:3:3::3", + "2001:db8:1:1::1" + ] + } + ] + } + ] +} diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv6_route.json b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv6_route.json new file mode 100644 index 000000000000..ce71b0271014 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv6_route.json @@ -0,0 +1,67 @@ +{ + "1001:1::/64":[ + { + "prefix":"1001:1::/64", + "prefixLen":64, + "protocol":"bgp", + "vrfId":"*", + "vrfName":"vrf1", + "selected":true, + "destSelected":true, + "distance":20, + "metric":0, + "installed":true, + "table":1, + "internalStatus":"*", + "internalFlags":"*", + "internalNextHopNum":"*", + "internalNextHopActiveNum":"*", + "nexthopGroupId":"*", + "installedNexthopGroupId":"*", + "uptime":"*", + "nexthops":[ + { + "flags":5, + "ip":"1000::1", + "afi":"ipv6", + "vrf":"default", + "active":true, + "recursive":true, + "labels":"*", + "weight":1, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":{ + "segs":"2001:db8:1:1:1::" + } + }, + { + "flags":3, + "fib":true, + "ip":"*", + "afi":"ipv6", + "interfaceIndex":"*", + "interfaceName":"eth1", + "resolver":true, + "vrf":"default", + "active":true, + "labels":"*", + "weight":1, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":{ + "segs":"2001:db8:1:1:1::" + } + } + ] + } + ] +} diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv6_route_te_policy.json b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv6_route_te_policy.json new file mode 100644 index 000000000000..7afed522d9e8 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf1_ipv6_route_te_policy.json @@ -0,0 +1,70 @@ +{ + "1001:1::/64":[ + { + "prefix":"1001:1::/64", + "prefixLen":64, + "protocol":"bgp", + "vrfId":"*", + "vrfName":"vrf1", + "selected":true, + "destSelected":true, + "distance":20, + "metric":0, + "installed":true, + "table":1, + "internalStatus":16, + "internalFlags":9, + "internalNextHopNum":"*", + "internalNextHopActiveNum":"*", + "nexthopGroupId":"*", + "installedNexthopGroupId":"*", + "uptime":"*", + "nexthops":[ + { + "flags":3205, + "ip":"1000::1", + "afi":"ipv6", + "vrf":"default", + "active":true, + "recursive":true, + "labels":"*", + "weight":1, + "srteColor":100, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":[ + "2001:db8:3:3::3", + "2001:db8:1:1::1" + ] + }, + { + "flags":2051, + "fib":true, + "ip":"*", + "afi":"ipv6", + "interfaceIndex":"*", + "interfaceName":"eth1", + "resolver":true, + "vrf":"default", + "active":true, + "labels":"*", + "weight":1, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":[ + "2001:db8:3:3::3", + "2001:db8:1:1::1" + ] + } + ] + } + ] +} diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv4_route.json b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv4_route.json new file mode 100644 index 000000000000..4e7b5e029d58 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv4_route.json @@ -0,0 +1,67 @@ +{ + "192.168.2.0/24":[ + { + "prefix":"192.168.2.0/24", + "prefixLen":24, + "protocol":"bgp", + "vrfId":"*", + "vrfName":"vrf2", + "selected":true, + "destSelected":true, + "distance":20, + "metric":0, + "installed":true, + "table":2, + "internalStatus":16, + "internalFlags":9, + "internalNextHopNum":"*", + "internalNextHopActiveNum":"*", + "nexthopGroupId":"*", + "installedNexthopGroupId":"*", + "uptime":"*", + "nexthops":[ + { + "flags":5, + "ip":"1000::1", + "afi":"ipv6", + "vrf":"default", + "active":true, + "recursive":true, + "labels":"*", + "weight":1, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":{ + "segs":"2001:db8:1:1:2::" + } + }, + { + "flags":3, + "fib":true, + "ip":"*", + "afi":"ipv6", + "interfaceIndex":"*", + "interfaceName":"eth1", + "resolver":true, + "vrf":"default", + "active":true, + "labels":"*", + "weight":1, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":{ + "segs":"2001:db8:1:1:2::" + } + } + ] + } + ] +} diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv4_route_te_policy.json b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv4_route_te_policy.json new file mode 100644 index 000000000000..17d56859cca0 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv4_route_te_policy.json @@ -0,0 +1,70 @@ +{ + "192.168.2.0/24":[ + { + "prefix":"192.168.2.0/24", + "prefixLen":24, + "protocol":"bgp", + "vrfId":"*", + "vrfName":"vrf2", + "selected":true, + "destSelected":true, + "distance":20, + "metric":0, + "installed":true, + "table":2, + "internalStatus":16, + "internalFlags":9, + "internalNextHopNum":"*", + "internalNextHopActiveNum":"*", + "nexthopGroupId":"*", + "installedNexthopGroupId":"*", + "uptime":"*", + "nexthops":[ + { + "flags":3205, + "ip":"1000::1", + "afi":"ipv6", + "vrf":"default", + "active":true, + "recursive":true, + "labels":"*", + "weight":1, + "srteColor":200, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":[ + "2001:db8:4:4::4", + "2001:db8:1:1::1" + ] + }, + { + "flags":2051, + "fib":true, + "ip":"*", + "afi":"ipv6", + "interfaceIndex":"*", + "interfaceName":"eth1", + "resolver":true, + "vrf":"default", + "active":true, + "labels":"*", + "weight":1, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":[ + "2001:db8:4:4::4", + "2001:db8:1:1::1" + ] + } + ] + } + ] +} diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv6_route.json b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv6_route.json new file mode 100644 index 000000000000..2e5df058296e --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv6_route.json @@ -0,0 +1,67 @@ +{ + "1001:2::/64":[ + { + "prefix":"1001:2::/64", + "prefixLen":64, + "protocol":"bgp", + "vrfId":"*", + "vrfName":"vrf2", + "selected":true, + "destSelected":true, + "distance":20, + "metric":0, + "installed":true, + "table":2, + "internalStatus":"*", + "internalFlags":"*", + "internalNextHopNum":"*", + "internalNextHopActiveNum":"*", + "nexthopGroupId":"*", + "installedNexthopGroupId":"*", + "uptime":"*", + "nexthops":[ + { + "flags":5, + "ip":"1000::1", + "afi":"ipv6", + "vrf":"default", + "active":true, + "recursive":true, + "labels":"*", + "weight":1, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":{ + "segs":"2001:db8:1:1:2::" + } + }, + { + "flags":3, + "fib":true, + "ip":"*", + "afi":"ipv6", + "interfaceIndex":"*", + "interfaceName":"eth1", + "resolver":true, + "vrf":"default", + "active":true, + "labels":"*", + "weight":1, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":{ + "segs":"2001:db8:1:1:2::" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv6_route_te_policy.json b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv6_route_te_policy.json new file mode 100644 index 000000000000..6ce752f6da90 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/json/vrf2_ipv6_route_te_policy.json @@ -0,0 +1,70 @@ +{ + "1001:2::/64":[ + { + "prefix":"1001:2::/64", + "prefixLen":64, + "protocol":"bgp", + "vrfId":"*", + "vrfName":"vrf2", + "selected":true, + "destSelected":true, + "distance":20, + "metric":0, + "installed":true, + "table":2, + "internalStatus":16, + "internalFlags":9, + "internalNextHopNum":"*", + "internalNextHopActiveNum":"*", + "nexthopGroupId":"*", + "installedNexthopGroupId":"*", + "uptime":"*", + "nexthops":[ + { + "flags":3205, + "ip":"1000::1", + "afi":"ipv6", + "vrf":"default", + "active":true, + "recursive":true, + "labels":"*", + "weight":1, + "srteColor":200, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":[ + "2001:db8:4:4::4", + "2001:db8:1:1::1" + ] + }, + { + "flags":2051, + "fib":true, + "ip":"*", + "afi":"ipv6", + "interfaceIndex":"*", + "interfaceName":"eth1", + "resolver":true, + "vrf":"default", + "active":true, + "labels":"*", + "weight":1, + "seg6local":{ + "action":"unspec" + }, + "seg6localContext":{ + "unknown":true + }, + "seg6":[ + "2001:db8:4:4::4", + "2001:db8:1:1::1" + ] + } + ] + } + ] +} diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/p1/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/p1/bgpd.conf new file mode 100644 index 000000000000..e4a2d7e61df8 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/p1/bgpd.conf @@ -0,0 +1,17 @@ +router bgp 65503 + bgp router-id 1.1.1.1 + no bgp ebgp-requires-policy + no bgp default ipv4-unicast + neighbor 2001:1::1 remote-as 65501 + neighbor 2001:1::1 timers 3 10 + neighbor 2001:1::1 timers connect 1 + neighbor 2002:1::2 remote-as 65502 + neighbor 2002:1::2 timers 3 10 + neighbor 2002:1::2 timers connect 1 + ! + address-family ipv6 unicast + neighbor 2001:1::1 activate + neighbor 2002:1::2 activate + exit-address-family + ! +! \ No newline at end of file diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/p1/zebra.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/p1/zebra.conf new file mode 100644 index 000000000000..1d36af6c8b3c --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/p1/zebra.conf @@ -0,0 +1,30 @@ +hostname p1 +! +interface lo + ipv6 address 3000::1/64 +! +interface eth1 + ipv6 address 2001:1::2/64 +! +interface eth2 + ipv6 address 2002:1::1/64 +! +interface eth3 + ipv6 address 2002:3::2/64 +! +ip forwarding +ipv6 forwarding +! +segment-routing + srv6 + locators + locator loc1 + prefix 2001:db8:3:3::/64 + ! + ! +! +ipv6 route 2001:db8:1:1::/64 2001:1::1 +ipv6 route 2001:db8:2:2::/64 2002:1::2 +ipv6 route 2001:db8:4:4::/64 2002:3::1 +line vty +! diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/p2/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/p2/bgpd.conf new file mode 100644 index 000000000000..9a3a6a27d95b --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/p2/bgpd.conf @@ -0,0 +1,17 @@ +router bgp 65504 + bgp router-id 1.1.1.1 + no bgp ebgp-requires-policy + no bgp default ipv4-unicast + neighbor 2001:2::1 remote-as 65501 + neighbor 2001:2::1 timers 3 10 + neighbor 2001:2::1 timers connect 1 + neighbor 2002:2::2 remote-as 65502 + neighbor 2002:2::2 timers 3 10 + neighbor 2002:2::2 timers connect 1 + ! + address-family ipv6 unicast + neighbor 2001:2::1 activate + neighbor 2002:2::2 activate + exit-address-family + ! +! \ No newline at end of file diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/p2/zebra.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/p2/zebra.conf new file mode 100644 index 000000000000..cd989b89c890 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/p2/zebra.conf @@ -0,0 +1,31 @@ +hostname p2 +! +interface lo + ipv6 address 4000::1/64 +! +interface eth1 + ipv6 address 2001:2::2/64 +! +interface eth2 + ipv6 address 2002:2::1/64 +! +interface eth3 + ipv6 address 2002:3::1/64 +! +ip forwarding +ipv6 forwarding +! +segment-routing + srv6 + locators + locator loc1 + prefix 2001:db8:4:4::/64 + ! + ! +! +! +ipv6 route 2001:db8:1:1::/64 2001:2::1 +ipv6 route 2001:db8:2:2::/64 2002:2::2 +ipv6 route 2001:db8:3:3::/64 2002:3::2 +line vty +! diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/pe1/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/pe1/bgpd.conf new file mode 100644 index 000000000000..ca92a7e6f9c1 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/pe1/bgpd.conf @@ -0,0 +1,95 @@ +!debug bgp neighbor-events +!debug bgp zebra +!debug bgp update-groups +!debug bgp updates in +!debug bgp updates out +!debug bgp vpn label +!debug bgp vpn leak-from-vrf +!debug bgp vpn leak-to-vrf +!debug bgp vpn rmap-event +! +route-map color_vrf1 permit 10 + set extcommunity color 01:100 +! +route-map color_vrf2 permit 10 + set extcommunity color 01:200 +! +router bgp 65501 + bgp router-id 1.1.1.1 + no bgp ebgp-requires-policy + no bgp default ipv4-unicast + neighbor 2001:1::2 remote-as 65503 + neighbor 2001:1::2 timers 3 10 + neighbor 2001:1::2 timers connect 1 + neighbor 2001:2::2 remote-as 65504 + neighbor 2001:2::2 timers 3 10 + neighbor 2001:2::2 timers connect 1 + neighbor 2000::1 remote-as 65502 + neighbor 2000::1 timers 3 10 + neighbor 2000::1 timers connect 1 + neighbor 2000::1 ebgp-multihop 254 + neighbor 2000::1 update-source 1000::1 + neighbor 2000::1 capability extended-nexthop + ! + address-family ipv4 vpn + neighbor 2000::1 activate + exit-address-family + ! + address-family ipv6 vpn + neighbor 2000::1 activate + exit-address-family + ! + address-family ipv6 unicast + network 1000::1/64 + neighbor 2001:1::2 activate + neighbor 2001:2::2 activate + exit-address-family + + segment-routing srv6 + locator loc1 + ! +! +router bgp 65501 vrf vrf1 + bgp router-id 1.1.1.1 + no bgp ebgp-requires-policy + sid vpn per-vrf export auto + ! + address-family ipv4 unicast + nexthop vpn export 2001::1 + rd vpn export 1:10 + rt vpn both 99:99 + export vpn + route-map vpn export color_vrf1 + redistribute connected + exit-address-family + ! + address-family ipv6 unicast + rd vpn export 1:10 + rt vpn both 99:99 + export vpn + route-map vpn export color_vrf1 + redistribute connected + exit-address-family +! +router bgp 65501 vrf vrf2 + bgp router-id 1.1.1.1 + no bgp ebgp-requires-policy + sid vpn per-vrf export auto + ! + address-family ipv4 unicast + nexthop vpn export 2001::1 + rd vpn export 1:20 + rt vpn both 88:88 + export vpn + route-map vpn export color_vrf2 + redistribute connected + exit-address-family + ! + address-family ipv6 unicast + rd vpn export 1:20 + rt vpn both 88:88 + export vpn + route-map vpn export color_vrf2 + redistribute connected + exit-address-family +! diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/pe1/pathd.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/pe1/pathd.conf new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/pe1/zebra.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/pe1/zebra.conf new file mode 100644 index 000000000000..4327ab3a1938 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/pe1/zebra.conf @@ -0,0 +1,39 @@ +hostname pe1 +! +!debug zebra packet +!debug zebra dplane +!debug zebra kernel +! +interface lo + ipv6 address 1000::1/64 +! +interface eth1 + ipv6 address 2001:1::1/64 +! +interface eth2 + ipv6 address 2001:2::1/64 +! +interface eth3 vrf vrf1 + ip address 192.168.1.1/24 + ipv6 address 1001:1::1/64 +! +interface eth4 vrf vrf2 + ip address 192.168.2.1/24 + ipv6 address 1001:2::1/64 +! +segment-routing + srv6 + locators + locator loc1 + prefix 2001:db8:1:1::/64 + ! + ! +! +ip forwarding +ipv6 forwarding +! +ipv6 route 2001:db8:2:2::/64 2001:1::2 +ipv6 route 2001:db8:2:2::/64 2001:2::2 +! +line vty +! diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/pe2/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/pe2/bgpd.conf new file mode 100644 index 000000000000..d52e833ed434 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/pe2/bgpd.conf @@ -0,0 +1,88 @@ +hostname pe2 +! +!debug bgp neighbor-events +!debug bgp zebra +!debug bgp vnc verbose +!debug bgp update-groups +!debug bgp updates in +!debug bgp updates out +!debug bgp updates +!debug bgp vpn label +!debug bgp vpn leak-from-vrf +!debug bgp vpn leak-to-vrf +!debug bgp vpn rmap-event +! +route-map color permit 10 + set extcommunity color 01:200 +! +router bgp 65502 + bgp router-id 1.1.1.1 + no bgp ebgp-requires-policy + no bgp default ipv4-unicast + neighbor 2002:1::1 remote-as 65503 + neighbor 2002:1::1 timers 3 10 + neighbor 2002:1::1 timers connect 1 + neighbor 2002:2::1 remote-as 65504 + neighbor 2002:2::1 timers 3 10 + neighbor 2002:2::1 timers connect 1 + neighbor 1000::1 remote-as 65501 + neighbor 1000::1 timers 3 10 + neighbor 1000::1 timers connect 1 + neighbor 1000::1 ebgp-multihop 254 + neighbor 1000::1 update-source 2000::1 + neighbor 1000::1 capability extended-nexthop + ! + address-family ipv4 vpn + neighbor 1000::1 activate + neighbor 1000::1 route-map color out + exit-address-family + ! + address-family ipv6 vpn + neighbor 1000::1 activate + neighbor 1000::1 route-map color out + exit-address-family + ! + address-family ipv6 unicast + network 2000::1/64 + neighbor 2002:1::1 activate + neighbor 2002:2::1 activate + exit-address-family + + segment-routing srv6 + locator loc1 + ! +! +router bgp 65502 vrf vrf1 + bgp router-id 2.2.2.2 + no bgp ebgp-requires-policy + ! + address-family ipv4 unicast + nexthop vpn export 2001::2 + rd vpn export 2:10 + rt vpn both 99:99 + import vpn + exit-address-family + ! + address-family ipv6 unicast + rd vpn export 2:10 + rt vpn both 99:99 + import vpn + exit-address-family +! +router bgp 65502 vrf vrf2 + bgp router-id 2.2.2.2 + no bgp ebgp-requires-policy + ! + address-family ipv4 unicast + nexthop vpn export 2001::2 + rd vpn export 2:20 + rt vpn both 88:88 + import vpn + exit-address-family + ! + address-family ipv6 unicast + rd vpn export 2:20 + rt vpn both 88:88 + import vpn + exit-address-family +! diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/pe2/pathd.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/pe2/pathd.conf new file mode 100644 index 000000000000..1b6238b89fee --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/pe2/pathd.conf @@ -0,0 +1,10 @@ +segment-routing + traffic-eng + segment-list default + index 10 ipv6-address 2001:db8:4:4::4 + index 20 ipv6-address 2001:db8:1:1::1 + segment-list test + index 10 ipv6-address 2001:db8:3:3::3 + index 20 ipv6-address 2001:db8:1:1::1 +! +! diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/pe2/zebra.conf b/tests/topotests/bgp_srv6l3vpn_te_policy/pe2/zebra.conf new file mode 100644 index 000000000000..6bdaccd5e860 --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/pe2/zebra.conf @@ -0,0 +1,39 @@ +hostname pe2 +! +!debug zebra packet +!debug zebra dplane +!debug zebra kernel +! +interface lo + ipv6 address 2000::1/64 +! +interface eth1 + ipv6 address 2002:1::2/64 +! +interface eth2 + ipv6 address 2002:2::2/64 +! +interface eth3 vrf vrf1 + ip address 192.168.3.1/24 + ipv6 address 1001:3::1/64 +! +interface eth4 vrf vrf2 + ip address 192.168.4.1/24 + ipv6 address 1001:4::1/64 +! +segment-routing + srv6 + locators + locator loc1 + prefix 2001:db8:2:2::/64 + ! + ! +! +ip forwarding +ipv6 forwarding +! +ipv6 route 2001:db8:1:1::/64 2002:1::1 +ipv6 route 2001:db8:1:1::/64 2002:2::1 +! +line vty +! diff --git a/tests/topotests/bgp_srv6l3vpn_te_policy/test_bgp_srv6l3vpn_te_policy.py b/tests/topotests/bgp_srv6l3vpn_te_policy/test_bgp_srv6l3vpn_te_policy.py new file mode 100644 index 000000000000..9c6405ae4d2d --- /dev/null +++ b/tests/topotests/bgp_srv6l3vpn_te_policy/test_bgp_srv6l3vpn_te_policy.py @@ -0,0 +1,199 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# Part of NetDEF Topology Tests +# +# Copyright (c) 2022, Alibaba Group +# Authored by Guoguo +# + +import os +import sys +import json +import functools +import pytest + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger +from lib.common_config import required_linux_kernel_version +from lib.checkping import check_ping + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + r""" + ┌──────┐ ┌──────┐ ┌──────┐ + │ CE1 ┼─┐ ┌───┤ P1 ┼──┐ ┌─┤ CE3 │ + └──────┘ │ Vrf1 │ └───|──┘ │ │ └──────┘ + │ ┌──────┐ │ | │ ┌──────┐ │ Vrf1 + ┼─┼ PE1 ┼───┤ | ┼────┤ PE2 ┼──┤ + │ └──────┘ │ | │ └──────┘ │ Vrf2 + ┌──────┐ │ Vrf2 │ ┌───|──┐ │ │ ┌──────┐ + │ CE2 ┼─┘ └───┤ P2 ┼──┘ └─┼ CE4 │ + └──────┘ └──────┘ └──────┘ + """ + tgen.add_router("pe1") + tgen.add_router("pe2") + tgen.add_router("ce1") + tgen.add_router("ce2") + tgen.add_router("ce3") + tgen.add_router("ce4") + tgen.add_router("p1") + tgen.add_router("p2") + + tgen.add_link(tgen.gears["pe1"], tgen.gears["p1"], "eth1", "eth1") + tgen.add_link(tgen.gears["pe1"], tgen.gears["p2"], "eth2", "eth1") + tgen.add_link(tgen.gears["pe2"], tgen.gears["p1"], "eth1", "eth2") + tgen.add_link(tgen.gears["pe2"], tgen.gears["p2"], "eth2", "eth2") + tgen.add_link(tgen.gears["ce1"], tgen.gears["pe1"], "eth0", "eth3") + tgen.add_link(tgen.gears["ce2"], tgen.gears["pe1"], "eth0", "eth4") + tgen.add_link(tgen.gears["ce3"], tgen.gears["pe2"], "eth0", "eth3") + tgen.add_link(tgen.gears["ce4"], tgen.gears["pe2"], "eth0", "eth4") + tgen.add_link(tgen.gears["p1"], tgen.gears["p2"], "eth3", "eth3") + +def setup_module(mod): + result = required_linux_kernel_version("5.4.0") + if result is not True: + pytest.skip("Kernel requirements are not met") + + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + router_list = tgen.routers() + for rname, router in tgen.routers().items(): + if os.path.exists("{}/{}/setup.sh".format(CWD, rname)): + router.run("/bin/bash {}/{}/setup.sh".format(CWD, rname)) + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_PATH, os.path.join(CWD, "{}/pathd.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + + tgen.gears["pe1"].run("ip link add vrf1 type vrf table 1") + tgen.gears["pe1"].run("ip link set vrf1 up") + tgen.gears["pe1"].run("ip link add vrf2 type vrf table 2") + tgen.gears["pe1"].run("ip link set vrf2 up") + tgen.gears["pe1"].run("ip link set eth3 master vrf1") + tgen.gears["pe1"].run("ip link set eth4 master vrf2") + + tgen.gears["pe2"].run("ip link add vrf1 type vrf table 1") + tgen.gears["pe2"].run("ip link set vrf1 up") + tgen.gears["pe2"].run("ip link add vrf2 type vrf table 2") + tgen.gears["pe2"].run("ip link set vrf2 up") + tgen.gears["pe2"].run("ip link set eth3 master vrf1") + tgen.gears["pe2"].run("ip link set eth4 master vrf2") + + tgen.start_router() + + # FOR DEVELOPER: + # If you want to stop some specific line and start interactive shell, + # please use tgen.mininet_cli() to start it. + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def open_json_file(filename): + try: + with open(filename, "r") as f: + return json.load(f) + except IOError: + assert False, "Could not read file {}".format(filename) + + +def check_rib(name, cmd, expected_file): + def _check(name, cmd, expected_file): + logger.info("polling") + tgen = get_topogen() + router = tgen.gears[name] + output = json.loads(router.vtysh_cmd(cmd)) + expected = open_json_file("{}/{}".format(CWD, expected_file)) + return topotest.json_cmp(output, expected) + + logger.info('[+] check {} "{}" {}'.format(name, cmd, expected_file)) + tgen = get_topogen() + func = functools.partial(_check, name, cmd, expected_file) + _, result = topotest.run_and_expect(func, None, count=30, wait=0.5) + assert result is None, "Failed" + +def create_srv6_policy(rname, endpoint, color=100): + tgen = get_topogen() + router = tgen.gears[rname] + router.vtysh_cmd( + "configure terminal\nsegment-routing\ntraffic-eng\npolicy color {} endpoint {}".format(color, endpoint) + ) + + +def delete_srv6_policy(rname, endpoint, color=100): + tgen = get_topogen() + router = tgen.gears[rname] + router.vtysh_cmd( + "configure terminal\nsegment-routing\ntraffic-eng\nno policy color {} endpoint {}".format(color, endpoint) + ) + +def add_candidate_path(rname, endpoint, pref, name, segment_list="default", color=100): + tgen = get_topogen() + router = tgen.gears[rname] + router.vtysh_cmd( + "configure terminal\nsegment-routing\ntraffic-eng\npolicy color {} endpoint {}\ncandidate-path preference {} name {} explicit segment-list {}".format( + color, endpoint, pref, name, segment_list) + ) + + +def delete_candidate_path(rname, endpoint, pref, color=100): + tgen = get_topogen() + router = tgen.gears[rname] + router.vtysh_cmd( + "configure terminal\nsegment-routing\ntraffic-eng\npolicy color {} endpoint {}\nno candidate-path preference {}".format(color, endpoint, pref) + ) + +def test_bgp_srv6_ipv4_vpn_route(): + check_rib("pe2", "show bgp ipv4 vpn 192.168.1.0/24 json", "json/vpnv4_vrf1_rib_route.json") + check_rib("pe2", "show bgp ipv4 vpn 192.168.2.0/24 json", "json/vpnv4_vrf2_rib_route.json") + check_rib("pe2", "show ip route vrf vrf1 192.168.1.0/24 json", "json/vrf1_ipv4_route.json") + check_rib("pe2", "show ip route vrf vrf2 192.168.2.0/24 json", "json/vrf2_ipv4_route.json") + + add_candidate_path("pe2", "1000::1", 100, "test", "test", 100) + + add_candidate_path("pe2", "1000::1", 100, "default", "default", 200) + check_rib("pe2", "show ip route vrf vrf1 192.168.1.0/24 json", "json/vrf1_ipv4_route_te_policy.json") + check_rib("pe2", "show ip route vrf vrf2 192.168.2.0/24 json", "json/vrf2_ipv4_route_te_policy.json") + + delete_candidate_path("pe2", "1000::1", 100) + delete_candidate_path("pe2", "1000::1", 100, 200) + check_rib("pe2", "show ip route vrf vrf1 192.168.1.0/24 json", "json/vrf1_ipv4_route.json") + check_rib("pe2", "show ip route vrf vrf2 192.168.2.0/24 json", "json/vrf2_ipv4_route.json") + +def test_bgp_srv6_ipv6_vpn_route(): + check_rib("pe2", "show bgp ipv6 vpn 1001:1::/64 json", "json/vpnv6_vrf1_rib_route.json") + check_rib("pe2", "show bgp ipv6 vpn 1001:2::/64 json", "json/vpnv6_vrf2_rib_route.json") + check_rib("pe2", "show ipv6 route vrf vrf1 1001:1::/64 json", "json/vrf1_ipv6_route.json") + check_rib("pe2", "show ipv6 route vrf vrf2 1001:2::/64 json", "json/vrf2_ipv6_route.json") + + add_candidate_path("pe2", "1000::1", 100, "test", "test", 100) + + add_candidate_path("pe2", "1000::1", 100, "default", "default", 200) + check_rib("pe2", "show ipv6 route vrf vrf1 1001:1::/64 json", "json/vrf1_ipv6_route_te_policy.json") + check_rib("pe2", "show ipv6 route vrf vrf2 1001:2::/64 json", "json/vrf2_ipv6_route_te_policy.json") + + delete_srv6_policy("pe2", "1000::1", 100) + delete_srv6_policy("pe2", "1000::1", 200) + check_rib("pe2", "show ipv6 route vrf vrf1 1001:1::/64 json", "json/vrf1_ipv6_route.json") + check_rib("pe2", "show ipv6 route vrf vrf2 1001:2::/64 json", "json/vrf2_ipv6_route.json") + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args))