2017-11-17 14:38:18 +01:00
|
|
|
#!/usr/bin/env python
|
2017-11-05 16:26:46 -08:00
|
|
|
"""
|
|
|
|
UDP encap objects
|
|
|
|
"""
|
|
|
|
|
2019-02-28 09:00:09 -08:00
|
|
|
from vpp_object import VppObject
|
2017-11-05 16:26:46 -08:00
|
|
|
from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
|
|
|
|
|
|
|
|
|
2018-08-08 01:06:40 -07:00
|
|
|
def find_udp_encap(test, ue):
|
2017-11-05 16:26:46 -08:00
|
|
|
encaps = test.vapi.udp_encap_dump()
|
|
|
|
for e in encaps:
|
2018-08-08 01:06:40 -07:00
|
|
|
if ue.id == e.udp_encap.id \
|
2018-12-11 13:04:01 +01:00
|
|
|
and ue.src_ip == str(e.udp_encap.src_ip) \
|
|
|
|
and ue.dst_ip == str(e.udp_encap.dst_ip) \
|
2018-08-08 01:06:40 -07:00
|
|
|
and e.udp_encap.dst_port == ue.dst_port \
|
|
|
|
and e.udp_encap.src_port == ue.src_port:
|
2017-11-05 16:26:46 -08:00
|
|
|
return True
|
2018-08-08 01:06:40 -07:00
|
|
|
|
2017-11-05 16:26:46 -08:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
class VppUdpEncap(VppObject):
|
|
|
|
|
|
|
|
def __init__(self,
|
|
|
|
test,
|
|
|
|
src_ip,
|
|
|
|
dst_ip,
|
|
|
|
src_port,
|
|
|
|
dst_port,
|
2018-08-08 01:06:40 -07:00
|
|
|
table_id=0):
|
2017-11-05 16:26:46 -08:00
|
|
|
self._test = test
|
|
|
|
self.table_id = table_id
|
|
|
|
self.src_ip_s = src_ip
|
|
|
|
self.dst_ip_s = dst_ip
|
2018-12-11 13:04:01 +01:00
|
|
|
self.src_ip = src_ip
|
|
|
|
self.dst_ip = dst_ip
|
2017-11-05 16:26:46 -08:00
|
|
|
self.src_port = src_port
|
|
|
|
self.dst_port = dst_port
|
|
|
|
|
|
|
|
def add_vpp_config(self):
|
2018-09-07 08:57:41 -07:00
|
|
|
r = self._test.vapi.udp_encap_add(
|
2018-12-11 13:04:01 +01:00
|
|
|
self.src_ip,
|
|
|
|
self.dst_ip,
|
2017-11-05 16:26:46 -08:00
|
|
|
self.src_port,
|
|
|
|
self.dst_port,
|
2018-08-08 01:06:40 -07:00
|
|
|
self.table_id)
|
2018-09-07 08:57:41 -07:00
|
|
|
self.id = r.id
|
2017-11-05 16:26:46 -08:00
|
|
|
self._test.registry.register(self, self._test.logger)
|
|
|
|
|
|
|
|
def remove_vpp_config(self):
|
2018-08-08 01:06:40 -07:00
|
|
|
self._test.vapi.udp_encap_del(self.id)
|
2017-11-05 16:26:46 -08:00
|
|
|
|
|
|
|
def query_vpp_config(self):
|
2018-08-08 01:06:40 -07:00
|
|
|
return find_udp_encap(self._test, self)
|
2017-11-05 16:26:46 -08:00
|
|
|
|
|
|
|
def object_id(self):
|
|
|
|
return ("udp-encap-%d" % self.id)
|
2018-09-07 08:57:41 -07:00
|
|
|
|
|
|
|
def get_stats(self):
|
|
|
|
c = self._test.statistics.get_counter("/net/udp-encap")
|
|
|
|
return c[0][self.id]
|