Skip to content

BGP

ANTA catalog for routing-bgp tests

BGP test functions

verify_bgp_evpn_count(device, result, number) async

Verifies all EVPN BGP sessions are established (default VRF) and the actual number of BGP EVPN neighbors is the one we expect (default VRF).

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required
number int

The expected number of BGP EVPN neighbors in the default VRF.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “skipped” if the number parameter is missing
TestResult
  • result = “success” if all EVPN BGP sessions are Established and if the actual number of BGP EVPN neighbors is the one we expect.
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/routing/bgp.py
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
@anta_test
@check_bgp_family_enable("evpn")
async def verify_bgp_evpn_count(
    device: InventoryDevice, result: TestResult, number: int
) -> TestResult:
    """
    Verifies all EVPN BGP sessions are established (default VRF)
    and the actual number of BGP EVPN neighbors is the one we expect (default VRF).

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.
        number (int): The expected number of BGP EVPN neighbors in the default VRF.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "skipped" if the `number` parameter is missing
        * result = "success" if all EVPN BGP sessions are Established and if the actual
                             number of BGP EVPN neighbors is the one we expect.
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    if not number:
        result.is_skipped(
            "verify_bgp_evpn_count could not run because number was not supplied."
        )
        return result

    response = await device.session.cli(command="show bgp evpn summary", ofmt="json")
    logger.debug(f"query result is: {response}")

    peers = response["vrfs"]["default"]["peers"]

    if len(peers) == number:
        result.is_success()
    else:
        result.is_failure()
        if len(peers) != number:
            result.messages.append(
                f"Expecting {number} BGP EVPN peers and got {len(peers)}"
            )

    return result

verify_bgp_evpn_state(device, result) async

Verifies all EVPN BGP sessions are established (default VRF).

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “skipped” if no BGP EVPN peers are returned by the device
TestResult
  • result = “success” if all EVPN BGP sessions are established.
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/routing/bgp.py
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
@anta_test
@check_bgp_family_enable("evpn")
async def verify_bgp_evpn_state(device: InventoryDevice, result: TestResult) -> TestResult:

    """
    Verifies all EVPN BGP sessions are established (default VRF).

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "skipped" if no BGP EVPN peers are returned by the device
        * result = "success" if all EVPN BGP sessions are established.
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    response = await device.session.cli(command="show bgp evpn summary", ofmt="json")
    logger.debug(f"query result is: {response}")

    bgp_vrfs = response["vrfs"]

    peers = bgp_vrfs["default"]["peers"]
    non_established_peers = [
        peer
        for peer, peer_dict in peers.items()
        if peer_dict["peerState"] != "Established"
    ]

    if not non_established_peers:
        result.is_success()
    else:
        result.is_failure(
            f"The following EVPN peers are not established: {non_established_peers}"
        )

    return result

verify_bgp_ipv4_unicast_count(device, result, number, vrf='default') async

Verifies all IPv4 unicast BGP sessions are established and all BGP messages queues for these sessions are empty and the actual number of BGP IPv4 unicast neighbors is the one we expect.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required
number int

Expected number of BGP IPv4 unicast neighbors

required
vrf(str)

VRF to verify. default is “default”.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “skipped” if the number or vrf parameter is missing
TestResult
  • result = “success” if all IPv4 unicast BGP sessions are established and if all BGP messages queues for these sessions are empty and if the actual number of BGP IPv4 unicast neighbors is equal to `number.
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/routing/bgp.py
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
@anta_test
@check_bgp_family_enable("ipv4")
async def verify_bgp_ipv4_unicast_count(
    device: InventoryDevice, result: TestResult, number: int, vrf: str = "default"
) -> TestResult:
    """
    Verifies all IPv4 unicast BGP sessions are established
    and all BGP messages queues for these sessions are empty
    and the actual number of BGP IPv4 unicast neighbors is the one we expect.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.
        number (int): Expected number of BGP IPv4 unicast neighbors
        vrf(str): VRF to verify. default is "default".

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "skipped" if the `number` or `vrf` parameter is missing
        * result = "success" if all IPv4 unicast BGP sessions are established
                             and if all BGP messages queues for these sessions are empty
                             and if the actual number of BGP IPv4 unicast neighbors is equal to `number.
        * result = "failure" otherwise.
        * result = "error" if any exception is caught
    """
    if not number or not vrf:
        result.is_skipped(
            "verify_bgp_ipv4_unicast_count could not run because number of vrf was not supplied"
        )
        return result

    response = await device.session.cli(
        command=f"show bgp ipv4 unicast summary vrf {vrf}", ofmt="json"
    )
    logger.debug(f"query result is: {response}")

    bgp_vrfs = response["vrfs"]

    peer_state_issue = {}
    peer_number = len(bgp_vrfs[vrf]["peers"])

    for peer in bgp_vrfs[vrf]["peers"]:
        if (
            (bgp_vrfs[vrf]["peers"][peer]["peerState"] != "Established")
            or (bgp_vrfs[vrf]["peers"][peer]["inMsgQueue"] != 0)
            or (bgp_vrfs[vrf]["peers"][peer]["outMsgQueue"] != 0)
        ):
            peer_state_issue[peer] = {
                "peerState": bgp_vrfs[vrf]["peers"][peer]["peerState"],
                "inMsgQueue": bgp_vrfs[vrf]["peers"][peer]["inMsgQueue"],
                "outMsgQueue": bgp_vrfs[vrf]["peers"][peer]["outMsgQueue"],
            }

    if peer_number == number:
        result.is_success()
    else:
        result.is_failure()
        if peer_number != number:
            result.is_failure(
                f"Expecting {number} BGP peer in vrf {vrf} and got {peer_number}"
            )

    return result

verify_bgp_ipv4_unicast_state(device, result) async

Verifies all IPv4 unicast BGP sessions are established (for all VRF) and all BGP messages queues for these sessions are empty (for all VRF).

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “skipped” if no BGP vrf are returned by the device
TestResult
  • result = “success” if all IPv4 unicast BGP sessions are established (for all VRF) and all BGP messages queues for these sessions are empty (for all VRF).
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/routing/bgp.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
@anta_test
@check_bgp_family_enable("ipv4")
async def verify_bgp_ipv4_unicast_state(
    device: InventoryDevice, result: TestResult
) -> TestResult:
    """
    Verifies all IPv4 unicast BGP sessions are established (for all VRF)
    and all BGP messages queues for these sessions are empty (for all VRF).

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "skipped" if no BGP vrf are returned by the device
        * result = "success" if all IPv4 unicast BGP sessions are established (for all VRF)
                             and all BGP messages queues for these sessions are empty (for all VRF).
        * result = "failure" otherwise.
        * result = "error" if any exception is caught
    """
    response = await device.session.cli(
        command="show bgp ipv4 unicast summary vrf all", ofmt="json"
    )
    logger.debug(f"query result is: {response}")

    bgp_vrfs = response["vrfs"]

    state_issue: Dict[str, Any] = {}
    for vrf in bgp_vrfs:
        for peer in bgp_vrfs[vrf]["peers"]:
            if (
                (bgp_vrfs[vrf]["peers"][peer]["peerState"] != "Established")
                or (bgp_vrfs[vrf]["peers"][peer]["inMsgQueue"] != 0)
                or (bgp_vrfs[vrf]["peers"][peer]["outMsgQueue"] != 0)
            ):
                vrf_dict = state_issue.setdefault(vrf, {})
                vrf_dict.update(
                    {
                        peer: {
                            "peerState": bgp_vrfs[vrf]["peers"][peer]["peerState"],
                            "inMsgQueue": bgp_vrfs[vrf]["peers"][peer]["inMsgQueue"],
                            "outMsgQueue": bgp_vrfs[vrf]["peers"][peer]["outMsgQueue"],
                        }
                    }
                )

    if not state_issue:
        result.is_success()
    else:
        result.is_failure(f"Some IPv4 Unicast BGP Peer are not up: {state_issue}")

    return result

verify_bgp_ipv6_unicast_state(device, result) async

Verifies all IPv6 unicast BGP sessions are established (for all VRF) and all BGP messages queues for these sessions are empty (for all VRF).

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “skipped” if no BGP vrf are returned by the device
TestResult
  • result = “success” if all IPv6 unicast BGP sessions are established (for all VRF) and all BGP messages queues for these sessions are empty (for all VRF).
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/routing/bgp.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
@anta_test
@check_bgp_family_enable("ipv6")
async def verify_bgp_ipv6_unicast_state(
    device: InventoryDevice, result: TestResult
) -> TestResult:
    """
    Verifies all IPv6 unicast BGP sessions are established (for all VRF)
    and all BGP messages queues for these sessions are empty (for all VRF).

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "skipped" if no BGP vrf are returned by the device
        * result = "success" if all IPv6 unicast BGP sessions are established (for all VRF)
                             and all BGP messages queues for these sessions are empty (for all VRF).
        * result = "failure" otherwise.
        * result = "error" if any exception is caught
    """
    response = await device.session.cli(
        command="show bgp ipv6 unicast summary vrf all", ofmt="json"
    )

    logger.debug(f"query result is: {response}")
    bgp_vrfs = response["vrfs"]

    state_issue: Dict[str, Any] = {}
    for vrf in bgp_vrfs:
        for peer in bgp_vrfs[vrf]["peers"]:
            if (
                (bgp_vrfs[vrf]["peers"][peer]["peerState"] != "Established")
                or (bgp_vrfs[vrf]["peers"][peer]["inMsgQueue"] != 0)
                or (bgp_vrfs[vrf]["peers"][peer]["outMsgQueue"] != 0)
            ):
                vrf_dict = state_issue.setdefault(vrf, {})
                vrf_dict.update(
                    {
                        peer: {
                            "peerState": bgp_vrfs[vrf]["peers"][peer]["peerState"],
                            "inMsgQueue": bgp_vrfs[vrf]["peers"][peer]["inMsgQueue"],
                            "outMsgQueue": bgp_vrfs[vrf]["peers"][peer]["outMsgQueue"],
                        }
                    }
                )

    if not state_issue:
        result.is_success()
    else:
        result.is_failure(f"Some IPv6 Unicast BGP Peer are not up: {state_issue}")

    return result

verify_bgp_rtc_count(device, result, number) async

Verifies all RTC BGP sessions are established (default VRF) and the actual number of BGP RTC neighbors is the one we expect (default VRF).

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required
number int

The expected number of BGP RTC neighbors (default VRF).

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “skipped” if the number parameter is missing
TestResult
  • result = “success” if all RTC BGP sessions are established and if the actual number of BGP RTC neighbors is the one we expect.
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/routing/bgp.py
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
@anta_test
@check_bgp_family_enable("rtc")
async def verify_bgp_rtc_count(
    device: InventoryDevice, result: TestResult, number: int
) -> TestResult:
    """
    Verifies all RTC BGP sessions are established (default VRF)
    and the actual number of BGP RTC neighbors is the one we expect (default VRF).

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.
        number (int): The expected number of BGP RTC neighbors (default VRF).

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "skipped" if the `number` parameter is missing
        * result = "success" if all RTC BGP sessions are established
                             and if the actual number of BGP RTC neighbors is the one we expect.
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    if not number:
        result.is_skipped(
            "verify_bgp_rtc_count could not run because number was not supplied"
        )
        return result

    response = await device.session.cli(command="show bgp rt-membership summary", ofmt="json")
    logger.debug(f"query result is: {response}")

    peers = response["vrfs"]["default"]["peers"]
    non_established_peers = [
        peer
        for peer, peer_dict in peers.items()
        if peer_dict["peerState"] != "Established"
    ]

    if not non_established_peers and len(peers) == number:
        result.is_success()
    else:
        result.is_failure()
        if len(peers) != number:
            result.is_failure(f"Expecting {number} BGP RTC peers and got {len(peers)}")

    return result

verify_bgp_rtc_state(device, result) async

Verifies all RTC BGP sessions are established (default VRF).

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “skipped” if no BGP RTC peers are returned by the device
TestResult
  • result = “success” if all RTC BGP sessions are Established.
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/routing/bgp.py
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
@anta_test
@check_bgp_family_enable("rtc")
async def verify_bgp_rtc_state(device: InventoryDevice, result: TestResult) -> TestResult:
    """
    Verifies all RTC BGP sessions are established (default VRF).

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "skipped" if no BGP RTC peers are returned by the device
        * result = "success" if all RTC BGP sessions are Established.
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    response = await device.session.cli(command="show bgp rt-membership summary", ofmt="json")
    logger.debug(f"query result is: {response}")

    peers = response["vrfs"]["default"]["peers"]
    non_established_peers = [
        peer
        for peer, peer_dict in peers.items()
        if peer_dict["peerState"] != "Established"
    ]

    if not non_established_peers:
        result.is_success()
    else:
        result.is_failure(
            f"The following RTC peers are not established: {non_established_peers}"
        )

    return result

Last update: September 5, 2022