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 \ |
| 19 | s.gaddr.address == socket.inet_pton(socket.AF_INET, gaddr) and \ |
| 20 | s.saddr.address == socket.inet_pton(socket.AF_INET, saddr): |
| 21 | return True |
| 22 | return False |
| 23 | |
| 24 | |
| 25 | def wait_for_igmp_event(test, timeout, itf, gaddr, saddr, ff): |
| 26 | ev = test.vapi.wait_for_event(timeout, "igmp_event") |
| 27 | if ev.sw_if_index == itf.sw_if_index and \ |
| 28 | ev.gaddr.address == socket.inet_pton(socket.AF_INET, gaddr) and \ |
| 29 | ev.saddr.address == socket.inet_pton(socket.AF_INET, saddr) and \ |
| 30 | ev.filter == ff: |
| 31 | return True |
| 32 | return False |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 33 | |
| 34 | |
| 35 | class IgmpSG(): |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame^] | 36 | def __init__(self, gaddr, saddrs): |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 37 | self.gaddr = gaddr |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame^] | 38 | self.gaddr_p = socket.inet_pton(socket.AF_INET, gaddr) |
| 39 | self.saddrs = saddrs |
| 40 | self.saddrs_p = [] |
| 41 | self.saddrs_encoded = [] |
| 42 | for s in saddrs: |
| 43 | ss = socket.inet_pton(socket.AF_INET, s) |
| 44 | self.saddrs_p.append(ss) |
| 45 | self.saddrs_encoded.append({'address': ss}) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 46 | |
| 47 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame^] | 48 | class IgmpRecord(): |
| 49 | def __init__(self, sg, type): |
| 50 | self.sg = sg |
| 51 | self.type = type |
| 52 | |
| 53 | |
| 54 | class VppHostState(VppObject): |
| 55 | def __init__(self, test, filter, sw_if_index, sg): |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 56 | self._test = test |
| 57 | self.sw_if_index = sw_if_index |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame^] | 58 | self.filter = filter |
| 59 | self.sg = sg |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 60 | |
| 61 | def add_vpp_config(self): |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame^] | 62 | self._test.vapi.igmp_listen( |
| 63 | self.filter, self.sw_if_index, |
| 64 | self.sg.saddrs_encoded, self.sg.gaddr_p) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 65 | |
| 66 | def remove_vpp_config(self): |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame^] | 67 | self._test.vapi.igmp_listen( |
| 68 | self.filter, |
| 69 | self.sw_if_index, |
| 70 | [], |
| 71 | self.sg.gaddr_p) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 72 | |
| 73 | def __str__(self): |
| 74 | return self.object_id() |
| 75 | |
| 76 | def object_id(self): |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame^] | 77 | return "%s:%d" % (self.sg, self.sw_if_index) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 78 | |
| 79 | def query_vpp_config(self): |
| 80 | return self._test.vapi.igmp_dump() |