]> git.puffer.fish Git - mirror/frr.git/commitdiff
topotests: more tests in bgp_vpnv4_noretain
authorLouis Scalbert <louis.scalbert@6wind.com>
Thu, 8 Jun 2023 11:42:30 +0000 (13:42 +0200)
committerLouis Scalbert <louis.scalbert@6wind.com>
Fri, 16 Jun 2023 12:18:34 +0000 (14:18 +0200)
Add more VRFs in bgp_vpnv4_noretain and test combinations of no-retain
/ retain and import / un-import.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
tests/topotests/bgp_vpnv4_noretain/r1/bgpd.conf
tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_all.json
tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init.json
tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init_plus_r2_vrf2.json [new file with mode: 0644]
tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init_plus_r2_vrf3.json [new file with mode: 0644]
tests/topotests/bgp_vpnv4_noretain/r1/zebra.conf
tests/topotests/bgp_vpnv4_noretain/r2/bgpd.conf
tests/topotests/bgp_vpnv4_noretain/r2/ipv4_vpn_routes_all.json
tests/topotests/bgp_vpnv4_noretain/r2/zebra.conf
tests/topotests/bgp_vpnv4_noretain/test_bgp_vpnv4_noretain.py

index 0c5a75c6d748a91d71c6f5a6f0e99eac623b795e..a30caf5c9d26123ed628650d9c54930d1c5e71db 100644 (file)
@@ -21,4 +21,22 @@ router bgp 65500 vrf vrf1
   import vpn
  exit-address-family
 !
-
+router bgp 65500 vrf vrf3
+ bgp router-id 192.0.2.1
+ address-family ipv4 unicast
+  redistribute connected
+  label vpn export 103
+  rd vpn export 192.0.2.1:3
+  rt vpn export 192.0.2.1:300
+  export vpn
+ exit-address-family
+!
+router bgp 65500 vrf vrf4
+ bgp router-id 192.0.2.1
+ address-family ipv4 unicast
+  label vpn export 104
+  rd vpn export 192.0.2.1:4
+  rt vpn import 192.0.2.1:300
+  import vpn
+ exit-address-family
+!
index 1926e86a8ca1bafb53b30664bc728ef4d988c399..e2fed4ef8200d677ed1201db2b16c50f7b9498b6 100644 (file)
                }
             ]
          },
+         "192.0.2.1:3":{
+            "10.103.0.0/24":[
+               {
+                  "valid":true,
+                  "bestpath":true,
+                  "selectionReason":"First path received",
+                  "pathFrom":"external",
+                  "prefix":"10.103.0.0",
+                  "prefixLen":24,
+                  "network":"10.103.0.0\/24",
+                  "metric":0,
+                  "weight":32768,
+                  "peerId":"(unspec)",
+                  "path":"",
+                  "origin":"incomplete",
+                  "announceNexthopSelf":true,
+                  "nhVrfName":"vrf3",
+                  "nexthops":[
+                     {
+                        "ip":"0.0.0.0",
+                        "hostname":"r1",
+                        "afi":"ipv4",
+                        "used":true
+                     }
+                  ]
+               }
+            ]
+         },
          "192.0.2.2:1":{
             "10.201.0.0/24":[
                {
                   ]
                }
             ]
+         },
+         "192.0.2.2:3":{
+            "10.203.0.0/24":[
+               {
+                  "valid":true,
+                  "bestpath":true,
+                  "selectionReason":"First path received",
+                  "pathFrom":"internal",
+                  "prefix":"10.203.0.0",
+                  "prefixLen":24,
+                  "network":"10.203.0.0\/24",
+                  "metric":0,
+                  "locPrf":100,
+                  "weight":0,
+                  "peerId":"10.125.0.2",
+                  "path":"",
+                  "origin":"incomplete",
+                  "nexthops":[
+                     {
+                        "ip":"10.125.0.2",
+                        "hostname":"r2",
+                        "afi":"ipv4",
+                        "used":true
+                     }
+                  ]
+               }
+            ]
          }
       }
    }
index 855ae1c2c92d93f98cc010d7aa5cda7121dbe52c..a6f789282c677e4b40481b337ea1b58970b2ad60 100644 (file)
                }
             ]
          },
+         "192.0.2.1:3":{
+            "10.103.0.0/24":[
+               {
+                  "valid":true,
+                  "bestpath":true,
+                  "selectionReason":"First path received",
+                  "pathFrom":"external",
+                  "prefix":"10.103.0.0",
+                  "prefixLen":24,
+                  "network":"10.103.0.0\/24",
+                  "metric":0,
+                  "weight":32768,
+                  "peerId":"(unspec)",
+                  "path":"",
+                  "origin":"incomplete",
+                  "announceNexthopSelf":true,
+                  "nhVrfName":"vrf3",
+                  "nexthops":[
+                     {
+                        "ip":"0.0.0.0",
+                        "hostname":"r1",
+                        "afi":"ipv4",
+                        "used":true
+                     }
+                  ]
+               }
+            ]
+         },
          "192.0.2.2:1":{
             "10.201.0.0/24":[
                {
diff --git a/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init_plus_r2_vrf2.json b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init_plus_r2_vrf2.json
new file mode 100644 (file)
index 0000000..4877beb
--- /dev/null
@@ -0,0 +1,121 @@
+{
+   "vrfId":0,
+   "vrfName":"default",
+   "routerId":"192.0.2.1",
+   "defaultLocPrf":100,
+   "localAS":65500,
+   "routes":{
+      "routeDistinguishers":{
+         "192.0.2.1:1":{
+            "10.101.0.0/24":[
+               {
+                  "valid":true,
+                  "bestpath":true,
+                  "selectionReason":"First path received",
+                  "pathFrom":"external",
+                  "prefix":"10.101.0.0",
+                  "prefixLen":24,
+                  "network":"10.101.0.0\/24",
+                  "metric":0,
+                  "weight":32768,
+                  "peerId":"(unspec)",
+                  "path":"",
+                  "origin":"incomplete",
+                  "announceNexthopSelf":true,
+                  "nhVrfName":"vrf1",
+                  "nexthops":[
+                     {
+                        "ip":"0.0.0.0",
+                        "hostname":"r1",
+                        "afi":"ipv4",
+                        "used":true
+                     }
+                  ]
+               }
+            ]
+         },
+         "192.0.2.1:3":{
+            "10.103.0.0/24":[
+               {
+                  "valid":true,
+                  "bestpath":true,
+                  "selectionReason":"First path received",
+                  "pathFrom":"external",
+                  "prefix":"10.103.0.0",
+                  "prefixLen":24,
+                  "network":"10.103.0.0\/24",
+                  "metric":0,
+                  "weight":32768,
+                  "peerId":"(unspec)",
+                  "path":"",
+                  "origin":"incomplete",
+                  "announceNexthopSelf":true,
+                  "nhVrfName":"vrf3",
+                  "nexthops":[
+                     {
+                        "ip":"0.0.0.0",
+                        "hostname":"r1",
+                        "afi":"ipv4",
+                        "used":true
+                     }
+                  ]
+               }
+            ]
+         },
+         "192.0.2.2:1":{
+            "10.201.0.0/24":[
+               {
+                  "valid":true,
+                  "bestpath":true,
+                  "selectionReason":"First path received",
+                  "pathFrom":"internal",
+                  "prefix":"10.201.0.0",
+                  "prefixLen":24,
+                  "network":"10.201.0.0\/24",
+                  "metric":0,
+                  "locPrf":100,
+                  "weight":0,
+                  "peerId":"10.125.0.2",
+                  "path":"",
+                  "origin":"incomplete",
+                  "nexthops":[
+                     {
+                        "ip":"10.125.0.2",
+                        "hostname":"r2",
+                        "afi":"ipv4",
+                        "used":true
+                     }
+                  ]
+               }
+            ]
+         },
+         "192.0.2.2:2":{
+            "10.202.0.0/24":[
+               {
+                  "valid":true,
+                  "bestpath":true,
+                  "selectionReason":"First path received",
+                  "pathFrom":"internal",
+                  "prefix":"10.202.0.0",
+                  "prefixLen":24,
+                  "network":"10.202.0.0\/24",
+                  "metric":0,
+                  "locPrf":100,
+                  "weight":0,
+                  "peerId":"10.125.0.2",
+                  "path":"",
+                  "origin":"incomplete",
+                  "nexthops":[
+                     {
+                        "ip":"10.125.0.2",
+                        "hostname":"r2",
+                        "afi":"ipv4",
+                        "used":true
+                     }
+                  ]
+               }
+            ]
+         }
+      }
+   }
+}
diff --git a/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init_plus_r2_vrf3.json b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init_plus_r2_vrf3.json
new file mode 100644 (file)
index 0000000..f05c12b
--- /dev/null
@@ -0,0 +1,121 @@
+{
+   "vrfId":0,
+   "vrfName":"default",
+   "routerId":"192.0.2.1",
+   "defaultLocPrf":100,
+   "localAS":65500,
+   "routes":{
+      "routeDistinguishers":{
+         "192.0.2.1:1":{
+            "10.101.0.0/24":[
+               {
+                  "valid":true,
+                  "bestpath":true,
+                  "selectionReason":"First path received",
+                  "pathFrom":"external",
+                  "prefix":"10.101.0.0",
+                  "prefixLen":24,
+                  "network":"10.101.0.0\/24",
+                  "metric":0,
+                  "weight":32768,
+                  "peerId":"(unspec)",
+                  "path":"",
+                  "origin":"incomplete",
+                  "announceNexthopSelf":true,
+                  "nhVrfName":"vrf1",
+                  "nexthops":[
+                     {
+                        "ip":"0.0.0.0",
+                        "hostname":"r1",
+                        "afi":"ipv4",
+                        "used":true
+                     }
+                  ]
+               }
+            ]
+         },
+         "192.0.2.1:3":{
+            "10.103.0.0/24":[
+               {
+                  "valid":true,
+                  "bestpath":true,
+                  "selectionReason":"First path received",
+                  "pathFrom":"external",
+                  "prefix":"10.103.0.0",
+                  "prefixLen":24,
+                  "network":"10.103.0.0\/24",
+                  "metric":0,
+                  "weight":32768,
+                  "peerId":"(unspec)",
+                  "path":"",
+                  "origin":"incomplete",
+                  "announceNexthopSelf":true,
+                  "nhVrfName":"vrf3",
+                  "nexthops":[
+                     {
+                        "ip":"0.0.0.0",
+                        "hostname":"r1",
+                        "afi":"ipv4",
+                        "used":true
+                     }
+                  ]
+               }
+            ]
+         },
+         "192.0.2.2:1":{
+            "10.201.0.0/24":[
+               {
+                  "valid":true,
+                  "bestpath":true,
+                  "selectionReason":"First path received",
+                  "pathFrom":"internal",
+                  "prefix":"10.201.0.0",
+                  "prefixLen":24,
+                  "network":"10.201.0.0\/24",
+                  "metric":0,
+                  "locPrf":100,
+                  "weight":0,
+                  "peerId":"10.125.0.2",
+                  "path":"",
+                  "origin":"incomplete",
+                  "nexthops":[
+                     {
+                        "ip":"10.125.0.2",
+                        "hostname":"r2",
+                        "afi":"ipv4",
+                        "used":true
+                     }
+                  ]
+               }
+            ]
+         },
+         "192.0.2.2:3":{
+            "10.203.0.0/24":[
+               {
+                  "valid":true,
+                  "bestpath":true,
+                  "selectionReason":"First path received",
+                  "pathFrom":"internal",
+                  "prefix":"10.203.0.0",
+                  "prefixLen":24,
+                  "network":"10.203.0.0\/24",
+                  "metric":0,
+                  "locPrf":100,
+                  "weight":0,
+                  "peerId":"10.125.0.2",
+                  "path":"",
+                  "origin":"incomplete",
+                  "nexthops":[
+                     {
+                        "ip":"10.125.0.2",
+                        "hostname":"r2",
+                        "afi":"ipv4",
+                        "used":true
+                     }
+                  ]
+               }
+            ]
+         }
+      }
+   }
+}
index 4f641e512e8fdd0e1d60ed3cbfeadc7f2433fc98..f99cfafe32191e5c80a4150ff1539b8ba266ab5a 100644 (file)
@@ -11,3 +11,6 @@ interface r1-eth0
 interface r1-eth1 vrf vrf1
  ip address 10.101.0.1/24
 !
+interface r1-eth3 vrf vrf3
+ ip address 10.103.0.1/24
+!
\ No newline at end of file
index 1ffbfe8b698383e8f7e04c032b8ad6bf24db8ad5..a5c13e0343dd67988500e3a93055012b9003759b 100644 (file)
@@ -32,3 +32,13 @@ router bgp 65500 vrf vrf2
   import vpn
  exit-address-family
 !
+router bgp 65500 vrf vrf3
+ bgp router-id 192.0.2.2
+ address-family ipv4 unicast
+  redistribute connected
+  label vpn export 203
+  rd vpn export 192.0.2.2:3
+  rt vpn export 192.0.2.2:300
+  export vpn
+ exit-address-family
+!
index 79304a5e5526d2ff3eb45e70b0b7f339cac3ccd6..f94bea2e222bb06fe454578849fc4c8bf5774081 100644 (file)
           }
         ]
       },
+      "192.0.2.1:3": {
+        "10.103.0.0/24": [
+          {
+            "valid": true,
+            "bestpath": true,
+            "selectionReason": "First path received",
+            "pathFrom": "internal",
+            "prefix": "10.103.0.0",
+            "prefixLen": 24,
+            "network": "10.103.0.0/24",
+            "metric": 0,
+            "locPrf": 100,
+            "weight": 0,
+            "peerId": "10.125.0.1",
+            "path": "",
+            "origin": "incomplete",
+            "nexthops": [
+              {
+                "ip": "10.125.0.1",
+                "hostname": "r1",
+                "afi": "ipv4",
+                "used": true
+              }
+            ]
+          }
+        ]
+      },
       "192.0.2.2:1": {
         "10.201.0.0/24": [
           {
             ]
           }
         ]
+      },
+      "192.0.2.2:3": {
+        "10.203.0.0/24": [
+          {
+            "valid": true,
+            "bestpath": true,
+            "selectionReason": "First path received",
+            "pathFrom": "external",
+            "prefix": "10.203.0.0",
+            "prefixLen": 24,
+            "network": "10.203.0.0/24",
+            "metric": 0,
+            "weight": 32768,
+            "peerId": "(unspec)",
+            "path": "",
+            "origin": "incomplete",
+            "announceNexthopSelf": true,
+            "nhVrfName": "vrf3",
+            "nexthops": [
+              {
+                "ip": "0.0.0.0",
+                "hostname": "r2",
+                "afi": "ipv4",
+                "used": true
+              }
+            ]
+          }
+        ]
       }
     }
   }
index 72cc10b6c2228c61989a1a7e0f1b95a3cf082c3f..057a3614c7eb39b333b27f43d19d3aa4227ca808 100644 (file)
@@ -14,3 +14,6 @@ interface r2-eth1 vrf vrf1
 interface r2-eth2 vrf vrf2
  ip address 10.202.0.2/24
 !
+interface r2-eth3 vrf vrf3
+ ip address 10.203.0.1/24
+!
index 94acd62f6d1e1c6f51958d0d3a133d33cc7b4d63..f665040f7faa320332eca5505ec1599f9479c1e9 100644 (file)
@@ -55,6 +55,18 @@ def build_topo(tgen):
     switch = tgen.add_switch("s4")
     switch.add_link(tgen.gears["r2"])
 
+    switch = tgen.add_switch("s5")
+    switch.add_link(tgen.gears["r1"])
+
+    switch = tgen.add_switch("s6")
+    switch.add_link(tgen.gears["r2"])
+
+    switch = tgen.add_switch("s7")
+    switch.add_link(tgen.gears["r1"])
+
+    switch = tgen.add_switch("s8")
+    switch.add_link(tgen.gears["r2"])
+
 
 def _populate_iface():
     tgen = get_topogen()
@@ -65,12 +77,18 @@ def _populate_iface():
         "ip link set dev vrf1 up",
         "ip link set dev {0}-eth1 master vrf1",
         "echo 1 > /proc/sys/net/mpls/conf/vrf1/input",
-    ]
-    cmds_list_extra = [
         "ip link add vrf2 type vrf table 20",
         "ip link set dev vrf2 up",
         "ip link set dev {0}-eth2 master vrf2",
         "echo 1 > /proc/sys/net/mpls/conf/vrf2/input",
+        "ip link add vrf3 type vrf table 30",
+        "ip link set dev vrf3 up",
+        "ip link set dev {0}-eth3 master vrf3",
+        "echo 1 > /proc/sys/net/mpls/conf/vrf3/input",
+        "ip link add vrf4 type vrf table 40",
+        "ip link set dev vrf4 up",
+        "ip link set dev {0}-eth4 master vrf4",
+        "echo 1 > /proc/sys/net/mpls/conf/vrf4/input",
     ]
 
     for cmd in cmds_list:
@@ -85,12 +103,6 @@ def _populate_iface():
         output = tgen.net["r2"].cmd(cmd.format("r2", "2", "1"))
         logger.info("output: " + output)
 
-    for cmd in cmds_list_extra:
-        input = cmd.format("r2", "2", "1")
-        logger.info("input: " + cmd)
-        output = tgen.net["r2"].cmd(cmd.format("r2", "2", "1"))
-        logger.info("output: " + output)
-
 
 def setup_module(mod):
     "Sets up the pytest environment"
@@ -226,6 +238,249 @@ router bgp 65500
     check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json")
 
 
+def test_bgp_no_retain_step3():
+    """
+    Apply and check no bgp retain route-target all on r1
+    """
+    rname = "r1"
+
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    router = tgen.gears["r1"]
+    router.vtysh_cmd(
+        "configure\nrouter bgp 65500\naddress-family ipv4 vpn\nno bgp retain route-target all\n"
+    )
+
+    check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init.json")
+    check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json")
+
+
+def test_bgp_no_retain_add_vrf2_step4():
+    """
+    Add vrf2 on r1 and check bgp vpnv4 table
+    """
+
+    rname = "r1"
+    cfg = """
+configure
+router bgp 65500 vrf vrf2
+ bgp router-id 192.0.2.1
+ address-family ipv4 unicast
+  redistribute connected
+  label vpn export 102
+  rd vpn export 192.0.2.1:200
+  rt vpn import 192.0.2.2:200
+  import vpn
+ exit-address-family
+!
+"""
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    router = tgen.gears[rname]
+    router.vtysh_cmd(cfg)
+
+    check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init_plus_r2_vrf2.json")
+    check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json")
+
+
+def test_bgp_no_retain_unimport_vrf2_step5():
+    """
+    Unimport to vrf2 on r1 and check bgp vpnv4 table
+    """
+
+    rname = "r1"
+    cfg = """
+configure
+router bgp 65500 vrf vrf2
+ address-family ipv4 unicast
+  no import vpn
+ exit-address-family
+!
+"""
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    router = tgen.gears[rname]
+    router.vtysh_cmd(cfg)
+
+    check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init.json")
+    check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json")
+
+
+def test_bgp_no_retain_import_vrf2_step6():
+    """
+    Re-import to vrf2 on r1 and check bgp vpnv4 table
+    """
+
+    rname = "r1"
+    cfg = """
+configure
+router bgp 65500 vrf vrf2
+ address-family ipv4 unicast
+  import vpn
+ exit-address-family
+!
+"""
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    router = tgen.gears[rname]
+    router.vtysh_cmd(cfg)
+
+    check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init_plus_r2_vrf2.json")
+    check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json")
+
+
+def test_bgp_no_retain_import_vrf1_step7():
+    """
+    Import r2 vrf1 into r1 vrf2 and check bgp vpnv4 table
+    """
+
+    rname = "r1"
+    cfg = """
+configure
+router bgp 65500 vrf vrf2
+ address-family ipv4 unicast
+  rt vpn import 192.0.2.1:100
+ exit-address-family
+!
+"""
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    router = tgen.gears[rname]
+    router.vtysh_cmd(cfg)
+
+    check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init.json")
+    check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json")
+
+
+def test_bgp_no_retain_import_vrf3_step8():
+    """
+    Import r2 vrf3 into r1 vrf2 and check bgp vpnv4 table
+    """
+
+    rname = "r1"
+    cfg = """
+configure
+router bgp 65500 vrf vrf2
+ address-family ipv4 unicast
+  rt vpn import 192.0.2.2:300
+ exit-address-family
+!
+"""
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    router = tgen.gears[rname]
+    router.vtysh_cmd(cfg)
+
+    check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init_plus_r2_vrf3.json")
+    check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json")
+
+
+def test_bgp_no_retain_unimport_vrf3_step9():
+    """
+    Un-import r2 vrf3 into r1 vrf2 and check bgp vpnv4 table
+    """
+
+    rname = "r1"
+    cfg = """
+configure
+router bgp 65500 vrf vrf2
+ address-family ipv4 unicast
+  no rt vpn import 192.0.2.2:300
+ exit-address-family
+!
+"""
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    router = tgen.gears[rname]
+    router.vtysh_cmd(cfg)
+
+    check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init.json")
+    check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json")
+
+
+def test_bgp_no_retain_import_vrf3_step10():
+    """
+    Import r2 vrf3 into r1 vrf2 and check bgp vpnv4 table
+    """
+
+    rname = "r1"
+    cfg = """
+configure
+router bgp 65500 vrf vrf2
+ address-family ipv4 unicast
+  rt vpn import 192.0.2.2:300
+ exit-address-family
+!
+"""
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    router = tgen.gears[rname]
+    router.vtysh_cmd(cfg)
+
+    check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init_plus_r2_vrf3.json")
+    check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json")
+
+
+def test_bgp_no_retain_remove_vrf2_step11():
+    """
+    Import r2 vrf3 into r1 vrf2 and check bgp vpnv4 table
+    """
+
+    rname = "r1"
+    cfg = """
+configure
+no router bgp 65500 vrf vrf2
+"""
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    router = tgen.gears[rname]
+    router.vtysh_cmd(cfg)
+
+    check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init.json")
+    check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json")
+
+
+def test_bgp_retain_step12():
+    """
+    Configure retain and check bgp vpnv4 table
+    """
+
+    rname = "r1"
+    cfg = """
+configure
+router bgp 65500
+ address-family ipv4 vpn
+  bgp retain route-target all
+"""
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    router = tgen.gears[rname]
+    router.vtysh_cmd(cfg)
+
+    check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_all.json")
+    check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json")
+
+
 def test_memory_leak():
     "Run the memory leak test and report results."
     tgen = get_topogen()