blob: 33b6a6905ec420eee2019f5a05e4dcca7ed26045 [file] [log] [blame]
Takeru Hayasaka68ac2442022-10-28 04:26:05 +09001from vpp_object import VppObject
2from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
3
4
5class SRv6MobileNhtype:
6 SRV6_NHTYPE_API_NONE = 0
7 SRV6_NHTYPE_API_IPV4 = 1
8 SRV6_NHTYPE_API_IPV6 = 2
9 SRV6_NHTYPE_API_NON_IP = 3
10
11
12class VppSRv6MobileLocalSID(VppObject):
13 """
14 SRv6 LocalSID
15 """
16
17 def __init__(
18 self,
19 test,
20 localsid_prefix,
21 behavior,
22 fib_table=0,
23 local_fib_table=0,
24 drop_in=0,
25 nhtype=SRv6MobileNhtype.SRV6_NHTYPE_API_NONE,
26 sr_prefix="",
27 v4src_addr="",
28 v4src_position=0,
29 ):
30 self._test = test
31 self.localsid_prefix = localsid_prefix
32 self.behavior = behavior
33 self.fib_table = fib_table
34 self.local_fib_table = local_fib_table
35 self.drop_in = drop_in
36 self.nhtype = nhtype
37 self.sr_prefix = sr_prefix
38 self.v4src_addr = v4src_addr
39 self.v4src_position = v4src_position
40 self._configured = False
41
42 def add_vpp_config(self):
43 self._test.vapi.sr_mobile_localsid_add_del(
44 localsid_prefix=self.localsid_prefix,
45 behavior=self.behavior,
46 fib_table=self.fib_table,
47 local_fib_table=self.local_fib_table,
48 drop_in=self.drop_in,
49 sr_prefix=self.sr_prefix,
50 v4src_addr=self.v4src_addr,
51 v4src_position=self.v4src_position,
52 is_del=0,
53 )
54 self._configured = True
55
56 def remove_vpp_config(self):
57 self._test.vapi.sr_mobile_localsid_add_del(
58 localsid_prefix=self.localsid_prefix,
59 behavior=self.behavior,
60 fib_table=self.fib_table,
61 local_fib_table=self.local_fib_table,
62 drop_in=self.drop_in,
63 sr_prefix=self.sr_prefix,
64 v4src_addr=self.v4src_addr,
65 v4src_position=self.v4src_position,
66 is_del=1,
67 )
68 self._configured = False
69
70 def query_vpp_config(self):
71 return self._configured
72
73 def object_id(self):
74 return "%d;%s,%s" % (self.fib_table, self.localsid_prefix, self.behavior)
75
76
77class VppSRv6MobilePolicy(VppObject):
78 """
79 SRv6 Policy
80 """
81
82 def __init__(
83 self,
84 test,
85 bsid_addr,
86 sr_prefix,
87 v6src_prefix,
88 behavior,
89 fib_table=0,
90 local_fib_table=0,
91 encap_src=None,
92 drop_in=0,
93 nhtype=SRv6MobileNhtype.SRV6_NHTYPE_API_NONE,
94 ):
95 self._test = test
96 self.bsid_addr = bsid_addr
97 self.sr_prefix = sr_prefix
98 self.v6src_prefix = v6src_prefix
99 self.behavior = behavior
100 self.fib_table = fib_table
101 self.local_fib_table = local_fib_table
102 self.drop_in = drop_in
103 self.nhtype = nhtype
104 self.encap_src = encap_src
105 self._configured = False
106
107 def add_vpp_config(self):
108 self._test.vapi.sr_mobile_policy_add(
109 bsid_addr=self.bsid_addr,
110 sr_prefix=self.sr_prefix,
111 v6src_prefix=self.v6src_prefix,
112 behavior=self.behavior,
113 fib_table=self.fib_table,
114 local_fib_table=self.local_fib_table,
115 encap_src=self.encap_src,
116 drop_in=self.drop_in,
117 nhtype=self.nhtype,
118 )
119 self._configured = True
120
121 def remove_vpp_config(self):
122 self._test.vapi.sr_policy_del(self.bsid_addr)
123 self._configured = False
124
125 def query_vpp_config(self):
126 # no API to query SR Policies
127 # use _configured flag for now
128 return self._configured
129
130 def object_id(self):
131 return "%d;%s-><%s>;%d" % (
132 self.sr_type,
133 self.bsid,
134 ",".join(self.segments),
135 self.is_encap,
136 )