Debian Codegraph @

tests/test_addr.py

raw
1 # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
2 # Copyright (c) 2019 Mellanox Technologies, Inc. All rights reserved. See COPYING file
3
4 import unittest
5 import errno
6
7 from pyverbs.pyverbs_error import PyverbsError, PyverbsRDMAError
8 from tests.base import PyverbsAPITestCase
9 from pyverbs.addr import AHAttr, AH
10 import pyverbs.device as d
11 from pyverbs.libibverbs_enums import ibv_port_state, IBV_LINK_LAYER_ETHERNET, IBV_LINK_LAYER_INFINIBAND
12 from pyverbs.pd import PD
13 import tests.utils as u
14
15
16 class AHTest(PyverbsAPITestCase):
17 """
18 Test various functionalities of the AH class.
19 """
20 def verify_link_layer_ether(self, ctx):
21 """
22 Aux function to verify link layer
23 """
24 link_layer = ctx.query_port(self.ib_port).link_layer
25 if link_layer != IBV_LINK_LAYER_ETHERNET:
26 raise unittest.SkipTest(f'Link layer of port={self.ib_port} is {d.translate_link_layer(link_layer)} , skip RoCE test')
27
28 def verify_state(self, ctx):
29 """
30 Aux function to verify port state
31 """
32 state = ctx.query_port(self.ib_port).state
33 if state != ibv_port_state.IBV_PORT_ACTIVE and state != ibv_port_state.IBV_PORT_INIT:
34 raise unittest.SkipTest(f'Port {self.ib_port} is not up, can not create AH')
35
36 def test_create_ah(self):
37 """
38 Test ibv_create_ah.
39 """
40 self.verify_state(self.ctx)
41 gr = u.get_global_route(self.ctx, gid_index=self.gid_index, port_num=self.ib_port)
42 port_attrs = self.ctx.query_port(self.ib_port)
43 dlid = port_attrs.lid if port_attrs.link_layer == IBV_LINK_LAYER_INFINIBAND else 0
44 ah_attr = AHAttr(dlid=dlid, gr=gr, is_global=1, port_num=self.ib_port)
45 pd = PD(self.ctx)
46 try:
47 AH(pd, attr=ah_attr)
48 except PyverbsRDMAError as ex:
49 if ex.error_code == errno.EOPNOTSUPP:
50 raise unittest.SkipTest('Create AH is not supported')
51 raise ex
52
53 def test_create_ah_roce(self):
54 """
55 Verify that AH can't be created without GRH in RoCE
56 """
57 self.verify_link_layer_ether(self.ctx)
58 self.verify_state(self.ctx)
59 pd = PD(self.ctx)
60 ah_attr = AHAttr(is_global=0, port_num=self.ib_port)
61 try:
62 AH(pd, attr=ah_attr)
63 except PyverbsRDMAError as ex:
64 if ex.error_code == errno.EOPNOTSUPP:
65 raise unittest.SkipTest('Create AH is not supported')
66 assert 'Failed to create AH' in str(ex)
67 else:
68 raise PyverbsError(f'Successfully created a non-global AH on RoCE port={self.ib_port}')
69
70 def test_destroy_ah(self):
71 """
72 Test ibv_destroy_ah.
73 """
74 self.verify_state(self.ctx)
75 gr = u.get_global_route(self.ctx, gid_index=self.gid_index, port_num=self.ib_port)
76 port_attrs = self.ctx.query_port(self.ib_port)
77 dlid = port_attrs.lid if port_attrs.link_layer == IBV_LINK_LAYER_INFINIBAND else 0
78 ah_attr = AHAttr(dlid=dlid, gr=gr, is_global=1, port_num=self.ib_port)
79 pd = PD(self.ctx)
80 try:
81 with AH(pd, attr=ah_attr) as ah:
82 ah.close()
83 except PyverbsRDMAError as ex:
84 if ex.error_code == errno.EOPNOTSUPP:
85 raise unittest.SkipTest('Create AH is not supported')
86 raise ex