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 |
| 8 | |
| 9 | |
| 10 | def find_udp_encap(test, id): |
| 11 | encaps = test.vapi.udp_encap_dump() |
| 12 | for e in encaps: |
| 13 | if id == e.id: |
| 14 | return True |
| 15 | return False |
| 16 | |
| 17 | |
| 18 | class VppUdpEncap(VppObject): |
| 19 | |
| 20 | def __init__(self, |
| 21 | test, |
| 22 | id, |
| 23 | src_ip, |
| 24 | dst_ip, |
| 25 | src_port, |
| 26 | dst_port, |
| 27 | table_id=0, |
| 28 | is_ip6=0): |
| 29 | self._test = test |
| 30 | self.id = id |
| 31 | self.table_id = table_id |
| 32 | self.is_ip6 = is_ip6 |
| 33 | self.src_ip_s = src_ip |
| 34 | self.dst_ip_s = dst_ip |
| 35 | if is_ip6: |
| 36 | self.src_ip = inet_pton(AF_INET6, src_ip) |
| 37 | self.dst_ip = inet_pton(AF_INET6, dst_ip) |
| 38 | else: |
| 39 | self.src_ip = inet_pton(AF_INET, src_ip) |
| 40 | self.dst_ip = inet_pton(AF_INET, dst_ip) |
| 41 | self.src_port = src_port |
| 42 | self.dst_port = dst_port |
| 43 | |
| 44 | def add_vpp_config(self): |
| 45 | self._test.vapi.udp_encap_add_del( |
| 46 | self.id, |
| 47 | self.src_ip, |
| 48 | self.dst_ip, |
| 49 | self.src_port, |
| 50 | self.dst_port, |
| 51 | self.table_id, |
| 52 | is_ip6=self.is_ip6, |
| 53 | is_add=1) |
| 54 | self._test.registry.register(self, self._test.logger) |
| 55 | |
| 56 | def remove_vpp_config(self): |
| 57 | self._test.vapi.udp_encap_add_del( |
| 58 | self.id, |
| 59 | self.src_ip, |
| 60 | self.dst_ip, |
| 61 | self.src_port, |
| 62 | self.dst_port, |
| 63 | self.table_id, |
| 64 | is_ip6=self.is_ip6, |
| 65 | is_add=0) |
| 66 | |
| 67 | def query_vpp_config(self): |
| 68 | return find_udp_encap(self._test, self.id) |
| 69 | |
| 70 | def __str__(self): |
| 71 | return self.object_id() |
| 72 | |
| 73 | def object_id(self): |
| 74 | return ("udp-encap-%d" % self.id) |