blob: 2403fbfd6ca7e960a57052d017bb36cd572aa286 [file] [log] [blame]
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001
2from vpp_object import VppObject
Neale Ranns947ea622018-06-07 23:48:20 -07003import socket
4
5
6class IGMP_MODE:
7 ROUTER = 0
8 HOST = 1
9
10
11class IGMP_FILTER:
12 INCLUDE = 1
13 EXCLUDE = 0
14
15
16def find_igmp_state(states, itf, gaddr, saddr):
17 for s in states:
18 if s.sw_if_index == itf.sw_if_index and \
Ole Troan0bcad322018-12-11 13:04:01 +010019 str(s.gaddr) == gaddr and str(s.saddr) == saddr:
Neale Ranns947ea622018-06-07 23:48:20 -070020 return True
21 return False
22
23
24def wait_for_igmp_event(test, timeout, itf, gaddr, saddr, ff):
25 ev = test.vapi.wait_for_event(timeout, "igmp_event")
26 if ev.sw_if_index == itf.sw_if_index and \
Ole Troan0bcad322018-12-11 13:04:01 +010027 str(ev.gaddr) == gaddr and str(ev.saddr) == saddr and \
Neale Ranns947ea622018-06-07 23:48:20 -070028 ev.filter == ff:
29 return True
30 return False
Jakub Grajciar7b867a82017-12-08 16:28:42 +010031
32
33class IgmpSG():
Neale Ranns947ea622018-06-07 23:48:20 -070034 def __init__(self, gaddr, saddrs):
Jakub Grajciar7b867a82017-12-08 16:28:42 +010035 self.gaddr = gaddr
Neale Ranns947ea622018-06-07 23:48:20 -070036 self.gaddr_p = socket.inet_pton(socket.AF_INET, gaddr)
37 self.saddrs = saddrs
38 self.saddrs_p = []
39 self.saddrs_encoded = []
40 for s in saddrs:
41 ss = socket.inet_pton(socket.AF_INET, s)
42 self.saddrs_p.append(ss)
Ole Troan8c8acc02018-11-27 10:05:23 +010043 self.saddrs_encoded.append(ss)
Jakub Grajciar7b867a82017-12-08 16:28:42 +010044
45
Neale Ranns947ea622018-06-07 23:48:20 -070046class IgmpRecord():
47 def __init__(self, sg, type):
48 self.sg = sg
49 self.type = type
50
51
52class VppHostState(VppObject):
53 def __init__(self, test, filter, sw_if_index, sg):
Jakub Grajciar7b867a82017-12-08 16:28:42 +010054 self._test = test
55 self.sw_if_index = sw_if_index
Neale Ranns947ea622018-06-07 23:48:20 -070056 self.filter = filter
57 self.sg = sg
Jakub Grajciar7b867a82017-12-08 16:28:42 +010058
59 def add_vpp_config(self):
Neale Ranns947ea622018-06-07 23:48:20 -070060 self._test.vapi.igmp_listen(
61 self.filter, self.sw_if_index,
62 self.sg.saddrs_encoded, self.sg.gaddr_p)
Jakub Grajciar7b867a82017-12-08 16:28:42 +010063
64 def remove_vpp_config(self):
Neale Ranns947ea622018-06-07 23:48:20 -070065 self._test.vapi.igmp_listen(
66 self.filter,
67 self.sw_if_index,
68 [],
69 self.sg.gaddr_p)
Jakub Grajciar7b867a82017-12-08 16:28:42 +010070
71 def __str__(self):
72 return self.object_id()
73
74 def object_id(self):
Neale Ranns947ea622018-06-07 23:48:20 -070075 return "%s:%d" % (self.sg, self.sw_if_index)
Jakub Grajciar7b867a82017-12-08 16:28:42 +010076
77 def query_vpp_config(self):
78 return self._test.vapi.igmp_dump()