summaryrefslogtreecommitdiffstats
path: root/test/vpp_vxlan_gpe_tunnel.py
blob: 2826c29c6b397d84cdcd67fd17d00e97c685aa3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
68
69
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
from vpp_interface import VppInterface
from vpp_papi import VppEnum


INDEX_INVALID = 0xFFFFFFFF
DEFAULT_PORT = 4790
UNDEFINED_PORT = 0


def find_vxlan_gpe_tunnel(test, src, dst, s_port, d_port, vni):
    ts = test.vapi.vxlan_gpe_tunnel_v2_dump(INDEX_INVALID)

    src_port = DEFAULT_PORT
    if s_port != UNDEFINED_PORT:
        src_port = s_port

    dst_port = DEFAULT_PORT
    if d_port != UNDEFINED_PORT:
        dst_port = d_port

    for t in ts:
        if (
            src == str(t.local)
            and dst == str(t.remote)
            and src_port == t.local_port
            and dst_port == t.remote_port
            and t.vni == vni
        ):
            return t.sw_if_index
    return INDEX_INVALID


class VppVxlanGpeTunnel(VppInterface):
    """
    VPP VXLAN GPE interface
    """

    def __init__(
        self,
        test,
        src_addr,
        dst_addr,
        vni,
        src_port=UNDEFINED_PORT,
        dst_port=UNDEFINED_PORT,
        mcast_sw_if_index=INDEX_INVALID,
        encap_vrf_id=None,
        decap_vrf_id=None,
        protocol=3,
    ):
        """Create VXLAN GPE Tunnel interface"""
        super(VppVxlanGpeTunnel, self).__init__(test)
        self.src = src_addr
        self.dst = dst_addr
        self.vni = vni
        self.src_port = src_port
        self.dst_port = dst_port
        self.mcast_sw_if_index = mcast_sw_if_index
        self.encap_vrf_id = encap_vrf_id
        self.decap_vrf_id = decap_vrf_id
        self.protocol = 3

    def add_vpp_config(self):
        reply = self.test.vapi.vxlan_gpe_add_del_tunnel_v2(
            is_add=1,
            local=self.src,
            remote=self.dst,
            vni=self.vni,
            local_port=self.src_port,
            remote_port=self.dst_port,
            mcast_sw_if_index=self.mcast_sw_if_index,
            encap_vrf_id=self.encap_vrf_id,
            decap_vrf_id=self.decap_vrf_id,
            protocol=self.protocol,
        )
        self.set_sw_if_index(reply.sw_if_index)
        self._test.registry.register(self, self._test.logger)

    def remove_vpp_config(self):
        self.test.vapi.vxlan_gpe_add_del_tunnel_v2(
            is_add=0,
            local=self.src,
            remote=self.dst,
            vni=self.vni,
            local_port=self.src_port,
            remote_port=self.dst_port,
            mcast_sw_if_index=self.mcast_sw_if_index,
            encap_vrf_id=self.encap_vrf_id,
            decap_vrf_id=self.decap_vrf_id,
            protocol=self.protocol,
        )

    def query_vpp_config(self):
        return INDEX_INVALID != find_vxlan_gpe_tunnel(
            self._test, self.src, self.dst, self.src_port, self.dst_port, self.vni
        )

    def object_id(self):
        return "vxlan-%d-%d-%s-%s" % (self.sw_if_index, self.vni, self.src, self.dst)
ove_vpp_config() # read (check not in sw if dump, ip4 fib, ip6 fib) if_dump = self.vapi.sw_interface_dump() fib4_dump = self.vapi.ip_fib_dump() for i in loopbacks: self.assertFalse(i.is_interface_config_in_dump(if_dump)) self.assertFalse(i.is_ip4_entry_in_fib_dump(fib4_dump)) # check not ping stream = self.create_icmp_stream(self.pg0, loopbacks) self.pg0.add_stream(stream) self.pg_enable_capture(self.pg_interfaces) self.pg_start() self.pg0.assert_nothing_captured() def test_down(self): # create loopbacks = self.create_loopback_interfaces(20) for i in loopbacks: i.local_ip4_prefix_len = 32 i.config_ip4() i.admin_up() # disable for i in loopbacks: i.admin_down() i.unconfig_ip4() # read (check not in sw if dump, ip4 fib, ip6 fib) if_dump = self.vapi.sw_interface_dump() fib4_dump = self.vapi.ip_fib_dump() for i in loopbacks: self.assertTrue(i.is_interface_config_in_dump(if_dump)) self.assertFalse(i.is_ip4_entry_in_fib_dump(fib4_dump)) # check not ping stream = self.create_icmp_stream(self.pg0, loopbacks) self.pg0.add_stream(stream) self.pg_enable_capture(self.pg_interfaces) self.pg_start() self.pg0.assert_nothing_captured() if __name__ == '__main__': unittest.main(testRunner=VppTestRunner)