]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp-default-ipv4-ipv6-unicast/test_bgp-default-ipv4-ipv6-unicast.py
Merge pull request #8553 from idryzhov/fix-bgp-get
[mirror_frr.git] / tests / topotests / bgp-default-ipv4-ipv6-unicast / test_bgp-default-ipv4-ipv6-unicast.py
CommitLineData
484ff489
DA
1#!/usr/bin/env python
2
3#
4# Copyright (c) 2021 by
5# Donatas Abraitis <donatas.abraitis@gmail.com>
6#
7# Permission to use, copy, modify, and/or distribute this software
8# for any purpose with or without fee is hereby granted, provided
9# that the above copyright notice and this permission notice appear
10# in all copies.
11#
12# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
19# OF THIS SOFTWARE.
20#
21
22"""
23Test if `bgp default ipv4-unicast` and `bgp default ipv6-unicast`
24commands work as expected.
25
26STEP 1: 'Check if neighbor 192.168.255.254 is enabled for ipv4 address-family only'
27STEP 2: 'Check if neighbor 192.168.255.254 is enabled for ipv6 address-family only'
28STEP 3: 'Check if neighbor 192.168.255.254 is enabled for ipv4 and ipv6 address-families'
29"""
30
31import os
32import sys
33import json
34import pytest
35import functools
36
37CWD = os.path.dirname(os.path.realpath(__file__))
38sys.path.append(os.path.join(CWD, "../"))
39
40# pylint: disable=C0413
41from lib import topotest
42from lib.topogen import Topogen, TopoRouter, get_topogen
43from lib.topolog import logger
44from mininet.topo import Topo
45from lib.common_config import step
46
47
48class TemplateTopo(Topo):
49 def build(self, *_args, **_opts):
50 tgen = get_topogen(self)
51
52 for routern in range(1, 5):
53 tgen.add_router("r{}".format(routern))
54
55 switch = tgen.add_switch("s1")
56 switch.add_link(tgen.gears["r1"])
57 switch.add_link(tgen.gears["r2"])
58 switch.add_link(tgen.gears["r3"])
59 switch.add_link(tgen.gears["r4"])
60
61
62def setup_module(mod):
63 tgen = Topogen(TemplateTopo, mod.__name__)
64 tgen.start_topology()
65
66 router_list = tgen.routers()
67
68 for i, (rname, router) in enumerate(router_list.items(), 1):
69 router.load_config(
70 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
71 )
72 router.load_config(
73 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
74 )
75
76 tgen.start_router()
77
78
79def teardown_module(mod):
80 tgen = get_topogen()
81 tgen.stop_topology()
82
83
84def test_bgp_default_ipv4_ipv6_unicast():
85 tgen = get_topogen()
86
87 if tgen.routers_have_failure():
88 pytest.skip(tgen.errors)
89
90 step("Check if neighbor 192.168.255.254 is enabled for ipv4 address-family only")
91
92 def _bgp_neighbor_ipv4_af_only():
93 tgen.gears["r1"].vtysh_cmd(
94 "conf t\nrouter bgp\nneighbor 192.168.255.254 remote-as external"
95 )
96
97 output = json.loads(tgen.gears["r1"].vtysh_cmd("show bgp summary json"))
98
99 if "ipv4Unicast" in output and "ipv6Unicast" not in output:
100 return True
101 return False
102
103 assert _bgp_neighbor_ipv4_af_only() == True
104
105 step("Check if neighbor 192.168.255.254 is enabled for ipv6 address-family only")
106
107 def _bgp_neighbor_ipv6_af_only():
108 tgen.gears["r2"].vtysh_cmd(
109 "conf t\nrouter bgp\nneighbor 192.168.255.254 remote-as external"
110 )
111
112 output = json.loads(tgen.gears["r2"].vtysh_cmd("show bgp summary json"))
113
114 if "ipv4Unicast" not in output and "ipv6Unicast" in output:
115 return True
116 return False
117
118 assert _bgp_neighbor_ipv6_af_only() == True
119
120 step(
121 "Check if neighbor 192.168.255.254 is enabled for ipv4 and ipv6 address-families"
122 )
123
124 def _bgp_neighbor_ipv4_and_ipv6_af():
125 tgen.gears["r3"].vtysh_cmd(
126 "conf t\nrouter bgp\nneighbor 192.168.255.254 remote-as external"
127 )
128
129 output = json.loads(tgen.gears["r3"].vtysh_cmd("show bgp summary json"))
130
131 if "ipv4Unicast" in output and "ipv6Unicast" in output:
132 return True
133 return False
134
135 assert _bgp_neighbor_ipv4_and_ipv6_af() == True
136
137
138if __name__ == "__main__":
139 args = ["-s"] + sys.argv[1:]
140 sys.exit(pytest.main(args))