summaryrefslogtreecommitdiffstats
path: root/test/vpp_srv6_mobile.py
blob: 33b6a6905ec420eee2019f5a05e4dcca7ed26045 (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
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
133
134
135
136
from vpp_object import VppObject
from socket import inet_pton, inet_ntop, AF_INET, AF_INET6


class SRv6MobileNhtype:
    SRV6_NHTYPE_API_NONE = 0
    SRV6_NHTYPE_API_IPV4 = 1
    SRV6_NHTYPE_API_IPV6 = 2
    SRV6_NHTYPE_API_NON_IP = 3


class VppSRv6MobileLocalSID(VppObject):
    """
    SRv6 LocalSID
    """

    def __init__(
        self,
        test,
        localsid_prefix,
        behavior,
        fib_table=0,
        local_fib_table=0,
        drop_in=0,
        nhtype=SRv6MobileNhtype.SRV6_NHTYPE_API_NONE,
        sr_prefix="",
        v4src_addr="",
        v4src_position=0,
    ):
        self._test = test
        self.localsid_prefix = localsid_prefix
        self.behavior = behavior
        self.fib_table = fib_table
        self.local_fib_table = local_fib_table
        self.drop_in = drop_in
        self.nhtype = nhtype
        self.sr_prefix = sr_prefix
        self.v4src_addr = v4src_addr
        self.v4src_position = v4src_position
        self._configured = False

    def add_vpp_config(self):
        self._test.vapi.sr_mobile_localsid_add_del(
            localsid_prefix=self.localsid_prefix,
            behavior=self.behavior,
            fib_table=self.fib_table,
            local_fib_table=self.local_fib_table,
            drop_in=self.drop_in,
            sr_prefix=self.sr_prefix,
            v4src_addr=self.v4src_addr,
            v4src_position=self.v4src_position,
            is_del=0,
        )
        self._configured = True

    def remove_vpp_config(self):
        self._test.vapi.sr_mobile_localsid_add_del(
            localsid_prefix=self.localsid_prefix,
            behavior=self.behavior,
            fib_table=self.fib_table,
            local_fib_table=self.local_fib_table,
            drop_in=self.drop_in,
            sr_prefix=self.sr_prefix,
            v4src_addr=self.v4src_addr,
            v4src_position=self.v4src_position,
            is_del=1,
        )
        self._configured = False

    def query_vpp_config(self):
        return self._configured

    def object_id(self):
        return "%d;%s,%s" % (self.fib_table, self.localsid_prefix, self.behavior)


class VppSRv6MobilePolicy(VppObject):
    """
    SRv6 Policy
    """

    def __init__(
        self,
        test,
        bsid_addr,
        sr_prefix,
        v6src_prefix,
        behavior,
        fib_table=0,
        local_fib_table=0,
        encap_src=None,
        drop_in=0,
        nhtype=SRv6MobileNhtype.SRV6_NHTYPE_API_NONE,
    ):
        self._test = test
        self.bsid_addr = bsid_addr
        self.sr_prefix = sr_prefix
        self.v6src_prefix = v6src_prefix
        self.behavior = behavior
        self.fib_table = fib_table
        self.local_fib_table = local_fib_table
        self.drop_in = drop_in
        self.nhtype = nhtype
        self.encap_src = encap_src
        self._configured = False

    def add_vpp_config(self):
        self._test.vapi.sr_mobile_policy_add(
            bsid_addr=self.bsid_addr,
            sr_prefix=self.sr_prefix,
            v6src_prefix=self.v6src_prefix,
            behavior=self.behavior,
            fib_table=self.fib_table,
            local_fib_table=self.local_fib_table,
            encap_src=self.encap_src,
            drop_in=self.drop_in,
            nhtype=self.nhtype,
        )
        self._configured = True

    def remove_vpp_config(self):
        self._test.vapi.sr_policy_del(self.bsid_addr)
        self._configured = False

    def query_vpp_config(self):
        # no API to query SR Policies
        # use _configured flag for now
        return self._configured

    def object_id(self):
        return "%d;%s-><%s>;%d" % (
            self.sr_type,
            self.bsid,
            ",".join(self.segments),
            self.is_encap,
        )