From 216d2fadb8ff721be95c69a632c0222d9ae1ff72 Mon Sep 17 00:00:00 2001 From: sihuihan88 Date: Mon, 23 Jul 2018 22:19:45 -0700 Subject: [PATCH] [vs-test]: not forward routes with no-export community (#1869) * Revert "Revert "[vs-test]: not forward routes with no-export community (#1774)" (#1828)" This reverts commit 6459275397eee140892f583375558c51d7e7b613. * [no-export]: move no export test under bgp folder Signed-off-by: Sihui Han * [no-export]: increase wait time to avoid random failure Signed-off-by: Sihui Han --- .../bgp/files/{ => invalid_nexthop}/bgpd.conf | 0 .../invalid_nexthop.conf | 0 .../vs/tests/bgp/files/no_export/bgpd.conf | 13 ++++++ .../vs/tests/bgp/files/no_export/exabgp1.conf | 21 +++++++++ .../vs/tests/bgp/files/no_export/exabgp2.conf | 11 +++++ platform/vs/tests/bgp/test_invalid_nexthop.py | 4 +- platform/vs/tests/bgp/test_no_export.py | 45 +++++++++++++++++++ 7 files changed, 92 insertions(+), 2 deletions(-) rename platform/vs/tests/bgp/files/{ => invalid_nexthop}/bgpd.conf (100%) rename platform/vs/tests/bgp/files/{ => invalid_nexthop}/invalid_nexthop.conf (100%) create mode 100644 platform/vs/tests/bgp/files/no_export/bgpd.conf create mode 100644 platform/vs/tests/bgp/files/no_export/exabgp1.conf create mode 100644 platform/vs/tests/bgp/files/no_export/exabgp2.conf create mode 100644 platform/vs/tests/bgp/test_no_export.py diff --git a/platform/vs/tests/bgp/files/bgpd.conf b/platform/vs/tests/bgp/files/invalid_nexthop/bgpd.conf similarity index 100% rename from platform/vs/tests/bgp/files/bgpd.conf rename to platform/vs/tests/bgp/files/invalid_nexthop/bgpd.conf diff --git a/platform/vs/tests/bgp/files/invalid_nexthop.conf b/platform/vs/tests/bgp/files/invalid_nexthop/invalid_nexthop.conf similarity index 100% rename from platform/vs/tests/bgp/files/invalid_nexthop.conf rename to platform/vs/tests/bgp/files/invalid_nexthop/invalid_nexthop.conf diff --git a/platform/vs/tests/bgp/files/no_export/bgpd.conf b/platform/vs/tests/bgp/files/no_export/bgpd.conf new file mode 100644 index 000000000000..40322cedbc69 --- /dev/null +++ b/platform/vs/tests/bgp/files/no_export/bgpd.conf @@ -0,0 +1,13 @@ +router bgp 65501 + bgp router-id 1.1.1.1 + no bgp default ipv4-unicast + neighbor 10.0.0.1 remote-as 65502 + address-family ipv4 + neighbor 10.0.0.1 activate + maximum-paths 64 + exit-address-family + neighbor 10.0.0.3 remote-as 65503 + address-family ipv4 + neighbor 10.0.0.3 activate + maximum-paths 64 + exit-address-family diff --git a/platform/vs/tests/bgp/files/no_export/exabgp1.conf b/platform/vs/tests/bgp/files/no_export/exabgp1.conf new file mode 100644 index 000000000000..0e78bd61db42 --- /dev/null +++ b/platform/vs/tests/bgp/files/no_export/exabgp1.conf @@ -0,0 +1,21 @@ +neighbor 10.0.0.0 { + router-id 1.1.1.2; + local-address 10.0.0.1; + local-as 65502; + peer-as 65501; + group-updates false; + + family{ + ipv4 unicast; + } + + static { + route 1.1.1.1/32{ + next-hop 10.0.0.1; + community no-export; + } + route 2.2.2.2/32{ + next-hop 10.0.0.1; + } + } +} diff --git a/platform/vs/tests/bgp/files/no_export/exabgp2.conf b/platform/vs/tests/bgp/files/no_export/exabgp2.conf new file mode 100644 index 000000000000..3e67c18a82f6 --- /dev/null +++ b/platform/vs/tests/bgp/files/no_export/exabgp2.conf @@ -0,0 +1,11 @@ +neighbor 10.0.0.2 { + router-id 1.1.1.3; + local-address 10.0.0.3; + local-as 65503; + peer-as 65501; + group-updates false; + + family { + ipv4 unicast; + } +} diff --git a/platform/vs/tests/bgp/test_invalid_nexthop.py b/platform/vs/tests/bgp/test_invalid_nexthop.py index cdb67337b896..b6e7cfc86e5e 100644 --- a/platform/vs/tests/bgp/test_invalid_nexthop.py +++ b/platform/vs/tests/bgp/test_invalid_nexthop.py @@ -6,7 +6,7 @@ def test_InvalidNexthop(dvs): - dvs.copy_file("/etc/quagga/", "bgp/files/bgpd.conf") + dvs.copy_file("/etc/quagga/", "bgp/files/invalid_nexthop/bgpd.conf") dvs.runcmd("supervisorctl start bgpd") dvs.runcmd("ip addr add fc00::1/126 dev Ethernet0") dvs.runcmd("ifconfig Ethernet0 up") @@ -18,7 +18,7 @@ def test_InvalidNexthop(dvs): print dvs.runcmd("supervisorctl status") - p = dvs.servers[0].runcmd_async("exabgp -d bgp/files/invalid_nexthop.conf") + p = dvs.servers[0].runcmd_async("exabgp -d bgp/files/invalid_nexthop/invalid_nexthop.conf") time.sleep(10) diff --git a/platform/vs/tests/bgp/test_no_export.py b/platform/vs/tests/bgp/test_no_export.py new file mode 100644 index 000000000000..371d5f0b29ec --- /dev/null +++ b/platform/vs/tests/bgp/test_no_export.py @@ -0,0 +1,45 @@ +from swsscommon import swsscommon +import os +import re +import time +import json + +def test_bounce(dvs): + dvs.servers[0].runcmd("pkill -f exabgp") + dvs.copy_file("/etc/quagga/", "bgp/files/no_export/bgpd.conf") + dvs.runcmd("supervisorctl start bgpd") + dvs.runcmd("ip addr add 10.0.0.0/31 dev Ethernet0") + dvs.runcmd("ifconfig Ethernet0 up") + + dvs.runcmd("ip addr add 10.0.0.2/31 dev Ethernet4") + dvs.runcmd("ifconfig Ethernet4 up") + + dvs.servers[0].runcmd("ip addr add 10.0.0.1/31 dev eth0") + dvs.servers[0].runcmd("ifconfig eth0 up") + + dvs.servers[1].runcmd("ip addr add 10.0.0.3/31 dev eth0") + dvs.servers[1].runcmd("ifconfig eth0 up") + + time.sleep(5) + + p1 = dvs.servers[0].runcmd_async("exabgp -d bgp/files/no_export/exabgp1.conf") + p2 = dvs.servers[1].runcmd_async("exabgp -d bgp/files/no_export/exabgp2.conf") + + time.sleep(60) + + sum_res = dvs.runcmd(["vtysh", "-c", "show ip bgp sum"]) + all_route = dvs.runcmd(["vtysh", "-c", "show ip bgp"]) + announce_route = dvs.runcmd(["vtysh", "-c", "show ip bgp neighbors 10.0.0.3 advertised-routes"]) + + p1.terminate() + p1 = p1.wait() + + p2.terminate() + p2 = p2.wait() + + print sum_res + print announce_route + assert "1.1.1.1/32" in all_route + assert "1.1.1.1/32" not in announce_route + assert "2.2.2.2/32" in all_route + assert "2.2.2.2/32" in announce_route