blob: 002f9f4023a9a412760c57e09a90e31fce930978 [file] [log] [blame]
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01001#!/usr/bin/env python
Neale Ranns810086d2017-11-05 16:26:46 -08002"""
3 UDP encap objects
4"""
5
6from vpp_object import *
7from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
Neale Rannsd0df49f2018-08-08 01:06:40 -07008from vpp_ip import *
Neale Ranns810086d2017-11-05 16:26:46 -08009
10
Neale Rannsd0df49f2018-08-08 01:06:40 -070011def find_udp_encap(test, ue):
Neale Ranns810086d2017-11-05 16:26:46 -080012 encaps = test.vapi.udp_encap_dump()
13 for e in encaps:
Neale Rannsd0df49f2018-08-08 01:06:40 -070014 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 Ranns810086d2017-11-05 16:26:46 -080021 return True
Neale Rannsd0df49f2018-08-08 01:06:40 -070022
Neale Ranns810086d2017-11-05 16:26:46 -080023 return False
24
25
26class VppUdpEncap(VppObject):
27
28 def __init__(self,
29 test,
30 id,
31 src_ip,
32 dst_ip,
33 src_port,
34 dst_port,
Neale Rannsd0df49f2018-08-08 01:06:40 -070035 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -080036 self._test = test
37 self.id = id
38 self.table_id = table_id
Neale Ranns810086d2017-11-05 16:26:46 -080039 self.src_ip_s = src_ip
40 self.dst_ip_s = dst_ip
Neale Rannsd0df49f2018-08-08 01:06:40 -070041 self.src_ip = VppIpAddress(src_ip)
42 self.dst_ip = VppIpAddress(dst_ip)
Neale Ranns810086d2017-11-05 16:26:46 -080043 self.src_port = src_port
44 self.dst_port = dst_port
45
46 def add_vpp_config(self):
Neale Rannsd0df49f2018-08-08 01:06:40 -070047 self._test.vapi.udp_encap_add(
Neale Ranns810086d2017-11-05 16:26:46 -080048 self.id,
Neale Rannsd0df49f2018-08-08 01:06:40 -070049 self.src_ip.encode(),
50 self.dst_ip.encode(),
Neale Ranns810086d2017-11-05 16:26:46 -080051 self.src_port,
52 self.dst_port,
Neale Rannsd0df49f2018-08-08 01:06:40 -070053 self.table_id)
Neale Ranns810086d2017-11-05 16:26:46 -080054 self._test.registry.register(self, self._test.logger)
55
56 def remove_vpp_config(self):
Neale Rannsd0df49f2018-08-08 01:06:40 -070057 self._test.vapi.udp_encap_del(self.id)
Neale Ranns810086d2017-11-05 16:26:46 -080058
59 def query_vpp_config(self):
Neale Rannsd0df49f2018-08-08 01:06:40 -070060 return find_udp_encap(self._test, self)
Neale Ranns810086d2017-11-05 16:26:46 -080061
62 def __str__(self):
63 return self.object_id()
64
65 def object_id(self):
66 return ("udp-encap-%d" % self.id)