blob: da2beb0605da9e12d580ebcbb0a18c0966d00edc [file] [log] [blame]
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001from vpp_object import VppObject
Neale Ranns947ea622018-06-07 23:48:20 -07002import socket
3
4
5class IGMP_MODE:
6 ROUTER = 0
7 HOST = 1
8
9
10class IGMP_FILTER:
11 INCLUDE = 1
12 EXCLUDE = 0
13
14
15def find_igmp_state(states, itf, gaddr, saddr):
16 for s in states:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020017 if (
18 s.sw_if_index == itf.sw_if_index
19 and str(s.gaddr) == gaddr
20 and str(s.saddr) == saddr
21 ):
Neale Ranns947ea622018-06-07 23:48:20 -070022 return True
23 return False
24
25
26def wait_for_igmp_event(test, timeout, itf, gaddr, saddr, ff):
27 ev = test.vapi.wait_for_event(timeout, "igmp_event")
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020028 if (
29 ev.sw_if_index == itf.sw_if_index
30 and str(ev.gaddr) == gaddr
31 and str(ev.saddr) == saddr
32 and ev.filter == ff
33 ):
Neale Ranns947ea622018-06-07 23:48:20 -070034 return True
35 return False
Jakub Grajciar7b867a82017-12-08 16:28:42 +010036
37
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020038class IgmpSG:
Neale Ranns947ea622018-06-07 23:48:20 -070039 def __init__(self, gaddr, saddrs):
Jakub Grajciar7b867a82017-12-08 16:28:42 +010040 self.gaddr = gaddr
Neale Ranns947ea622018-06-07 23:48:20 -070041 self.gaddr_p = socket.inet_pton(socket.AF_INET, gaddr)
42 self.saddrs = saddrs
43 self.saddrs_p = []
44 self.saddrs_encoded = []
45 for s in saddrs:
46 ss = socket.inet_pton(socket.AF_INET, s)
47 self.saddrs_p.append(ss)
Ole Troan8c8acc02018-11-27 10:05:23 +010048 self.saddrs_encoded.append(ss)
Jakub Grajciar7b867a82017-12-08 16:28:42 +010049
50
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020051class IgmpRecord:
Neale Ranns947ea622018-06-07 23:48:20 -070052 def __init__(self, sg, type):
53 self.sg = sg
54 self.type = type
55
56
57class VppHostState(VppObject):
58 def __init__(self, test, filter, sw_if_index, sg):
Jakub Grajciar7b867a82017-12-08 16:28:42 +010059 self._test = test
60 self.sw_if_index = sw_if_index
Neale Ranns947ea622018-06-07 23:48:20 -070061 self.filter = filter
62 self.sg = sg
Jakub Grajciar7b867a82017-12-08 16:28:42 +010063
64 def add_vpp_config(self):
Neale Ranns947ea622018-06-07 23:48:20 -070065 self._test.vapi.igmp_listen(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020066 self.filter, self.sw_if_index, self.sg.saddrs_encoded, self.sg.gaddr_p
67 )
Jakub Grajciar7b867a82017-12-08 16:28:42 +010068
69 def remove_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020070 self._test.vapi.igmp_listen(self.filter, self.sw_if_index, [], self.sg.gaddr_p)
Jakub Grajciar7b867a82017-12-08 16:28:42 +010071
Jakub Grajciar7b867a82017-12-08 16:28:42 +010072 def object_id(self):
Neale Ranns947ea622018-06-07 23:48:20 -070073 return "%s:%d" % (self.sg, self.sw_if_index)
Jakub Grajciar7b867a82017-12-08 16:28:42 +010074
75 def query_vpp_config(self):
76 return self._test.vapi.igmp_dump()