blob: 56d23cc45dc2433db5d2f9c939f6a2925027370a [file] [log] [blame]
Neale Ranns810086d2017-11-05 16:26:46 -08001"""
2 UDP encap objects
3"""
4
5from vpp_object import *
6from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
7
8
9def find_udp_encap(test, id):
10 encaps = test.vapi.udp_encap_dump()
11 for e in encaps:
12 if id == e.id:
13 return True
14 return False
15
16
17class VppUdpEncap(VppObject):
18
19 def __init__(self,
20 test,
21 id,
22 src_ip,
23 dst_ip,
24 src_port,
25 dst_port,
26 table_id=0,
27 is_ip6=0):
28 self._test = test
29 self.id = id
30 self.table_id = table_id
31 self.is_ip6 = is_ip6
32 self.src_ip_s = src_ip
33 self.dst_ip_s = dst_ip
34 if is_ip6:
35 self.src_ip = inet_pton(AF_INET6, src_ip)
36 self.dst_ip = inet_pton(AF_INET6, dst_ip)
37 else:
38 self.src_ip = inet_pton(AF_INET, src_ip)
39 self.dst_ip = inet_pton(AF_INET, dst_ip)
40 self.src_port = src_port
41 self.dst_port = dst_port
42
43 def add_vpp_config(self):
44 self._test.vapi.udp_encap_add_del(
45 self.id,
46 self.src_ip,
47 self.dst_ip,
48 self.src_port,
49 self.dst_port,
50 self.table_id,
51 is_ip6=self.is_ip6,
52 is_add=1)
53 self._test.registry.register(self, self._test.logger)
54
55 def remove_vpp_config(self):
56 self._test.vapi.udp_encap_add_del(
57 self.id,
58 self.src_ip,
59 self.dst_ip,
60 self.src_port,
61 self.dst_port,
62 self.table_id,
63 is_ip6=self.is_ip6,
64 is_add=0)
65
66 def query_vpp_config(self):
67 return find_udp_encap(self._test, self.id)
68
69 def __str__(self):
70 return self.object_id()
71
72 def object_id(self):
73 return ("udp-encap-%d" % self.id)