Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 1 | from vpp_object import VppObject |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 2 | import socket |
| 3 | |
| 4 | |
| 5 | class IGMP_MODE: |
| 6 | ROUTER = 0 |
| 7 | HOST = 1 |
| 8 | |
| 9 | |
| 10 | class IGMP_FILTER: |
| 11 | INCLUDE = 1 |
| 12 | EXCLUDE = 0 |
| 13 | |
| 14 | |
| 15 | def find_igmp_state(states, itf, gaddr, saddr): |
| 16 | for s in states: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 17 | if ( |
| 18 | s.sw_if_index == itf.sw_if_index |
| 19 | and str(s.gaddr) == gaddr |
| 20 | and str(s.saddr) == saddr |
| 21 | ): |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 22 | return True |
| 23 | return False |
| 24 | |
| 25 | |
| 26 | def wait_for_igmp_event(test, timeout, itf, gaddr, saddr, ff): |
| 27 | ev = test.vapi.wait_for_event(timeout, "igmp_event") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 28 | 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 Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 34 | return True |
| 35 | return False |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 36 | |
| 37 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 38 | class IgmpSG: |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 39 | def __init__(self, gaddr, saddrs): |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 40 | self.gaddr = gaddr |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 41 | 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 Troan | 8c8acc0 | 2018-11-27 10:05:23 +0100 | [diff] [blame] | 48 | self.saddrs_encoded.append(ss) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 49 | |
| 50 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 51 | class IgmpRecord: |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 52 | def __init__(self, sg, type): |
| 53 | self.sg = sg |
| 54 | self.type = type |
| 55 | |
| 56 | |
| 57 | class VppHostState(VppObject): |
| 58 | def __init__(self, test, filter, sw_if_index, sg): |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 59 | self._test = test |
| 60 | self.sw_if_index = sw_if_index |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 61 | self.filter = filter |
| 62 | self.sg = sg |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 63 | |
| 64 | def add_vpp_config(self): |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 65 | self._test.vapi.igmp_listen( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 66 | self.filter, self.sw_if_index, self.sg.saddrs_encoded, self.sg.gaddr_p |
| 67 | ) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 68 | |
| 69 | def remove_vpp_config(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 70 | self._test.vapi.igmp_listen(self.filter, self.sw_if_index, [], self.sg.gaddr_p) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 71 | |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 72 | def object_id(self): |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 73 | return "%s:%d" % (self.sg, self.sw_if_index) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 74 | |
| 75 | def query_vpp_config(self): |
| 76 | return self._test.vapi.igmp_dump() |