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