Andrew Yourtchenko | 669d07d | 2017-11-17 14:38:18 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 2 | """ |
| 3 | UDP encap objects |
| 4 | """ |
| 5 | |
| 6 | from vpp_object import * |
| 7 | from socket import inet_pton, inet_ntop, AF_INET, AF_INET6 |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 8 | from vpp_ip import * |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 9 | |
| 10 | |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 11 | def find_udp_encap(test, ue): |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 12 | encaps = test.vapi.udp_encap_dump() |
| 13 | for e in encaps: |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 14 | if ue.id == e.udp_encap.id \ |
| 15 | and compare_ip_address(e.udp_encap.src_ip.un, |
| 16 | ue.src_ip.addr.ip_addr) \ |
| 17 | and compare_ip_address(e.udp_encap.dst_ip.un, |
| 18 | ue.dst_ip.addr.ip_addr) \ |
| 19 | and e.udp_encap.dst_port == ue.dst_port \ |
| 20 | and e.udp_encap.src_port == ue.src_port: |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 21 | return True |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 22 | |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 23 | return False |
| 24 | |
| 25 | |
| 26 | class VppUdpEncap(VppObject): |
| 27 | |
| 28 | def __init__(self, |
| 29 | test, |
| 30 | id, |
| 31 | src_ip, |
| 32 | dst_ip, |
| 33 | src_port, |
| 34 | dst_port, |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 35 | table_id=0): |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 36 | self._test = test |
| 37 | self.id = id |
| 38 | self.table_id = table_id |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 39 | self.src_ip_s = src_ip |
| 40 | self.dst_ip_s = dst_ip |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 41 | self.src_ip = VppIpAddress(src_ip) |
| 42 | self.dst_ip = VppIpAddress(dst_ip) |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 43 | self.src_port = src_port |
| 44 | self.dst_port = dst_port |
| 45 | |
| 46 | def add_vpp_config(self): |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 47 | self._test.vapi.udp_encap_add( |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 48 | self.id, |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 49 | self.src_ip.encode(), |
| 50 | self.dst_ip.encode(), |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 51 | self.src_port, |
| 52 | self.dst_port, |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 53 | self.table_id) |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 54 | self._test.registry.register(self, self._test.logger) |
| 55 | |
| 56 | def remove_vpp_config(self): |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 57 | self._test.vapi.udp_encap_del(self.id) |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 58 | |
| 59 | def query_vpp_config(self): |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 60 | return find_udp_encap(self._test, self) |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 61 | |
| 62 | def __str__(self): |
| 63 | return self.object_id() |
| 64 | |
| 65 | def object_id(self): |
| 66 | return ("udp-encap-%d" % self.id) |