blob: 209115f2c3ff094d01e5964f31a787251a580d8f [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 \
Neale Rannsc0a93142018-09-05 15:42:26 -070015 and ue.src_ip == e.udp_encap.src_ip \
16 and ue.dst_ip == e.udp_encap.dst_ip \
Neale Rannsd0df49f2018-08-08 01:06:40 -070017 and e.udp_encap.dst_port == ue.dst_port \
18 and e.udp_encap.src_port == ue.src_port:
Neale Ranns810086d2017-11-05 16:26:46 -080019 return True
Neale Rannsd0df49f2018-08-08 01:06:40 -070020
Neale Ranns810086d2017-11-05 16:26:46 -080021 return False
22
23
24class VppUdpEncap(VppObject):
25
26 def __init__(self,
27 test,
Neale Ranns810086d2017-11-05 16:26:46 -080028 src_ip,
29 dst_ip,
30 src_port,
31 dst_port,
Neale Rannsd0df49f2018-08-08 01:06:40 -070032 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -080033 self._test = test
Neale Ranns810086d2017-11-05 16:26:46 -080034 self.table_id = table_id
Neale Ranns810086d2017-11-05 16:26:46 -080035 self.src_ip_s = src_ip
36 self.dst_ip_s = dst_ip
Neale Rannsd0df49f2018-08-08 01:06:40 -070037 self.src_ip = VppIpAddress(src_ip)
38 self.dst_ip = VppIpAddress(dst_ip)
Neale Ranns810086d2017-11-05 16:26:46 -080039 self.src_port = src_port
40 self.dst_port = dst_port
41
42 def add_vpp_config(self):
Neale Ranns9c0a3c42018-09-07 08:57:41 -070043 r = self._test.vapi.udp_encap_add(
Neale Rannsd0df49f2018-08-08 01:06:40 -070044 self.src_ip.encode(),
45 self.dst_ip.encode(),
Neale Ranns810086d2017-11-05 16:26:46 -080046 self.src_port,
47 self.dst_port,
Neale Rannsd0df49f2018-08-08 01:06:40 -070048 self.table_id)
Neale Ranns9c0a3c42018-09-07 08:57:41 -070049 self.id = r.id
Neale Ranns810086d2017-11-05 16:26:46 -080050 self._test.registry.register(self, self._test.logger)
51
52 def remove_vpp_config(self):
Neale Rannsd0df49f2018-08-08 01:06:40 -070053 self._test.vapi.udp_encap_del(self.id)
Neale Ranns810086d2017-11-05 16:26:46 -080054
55 def query_vpp_config(self):
Neale Rannsd0df49f2018-08-08 01:06:40 -070056 return find_udp_encap(self._test, self)
Neale Ranns810086d2017-11-05 16:26:46 -080057
58 def __str__(self):
59 return self.object_id()
60
61 def object_id(self):
62 return ("udp-encap-%d" % self.id)
Neale Ranns9c0a3c42018-09-07 08:57:41 -070063
64 def get_stats(self):
65 c = self._test.statistics.get_counter("/net/udp-encap")
66 return c[0][self.id]