blob: b89e9411e6a1f0d929c8228ad5e9cda044591831 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Neale Ranns810086d2017-11-05 16:26:46 -08002"""
3 UDP encap objects
4"""
5
Paul Vinciguerraa279d9c2019-02-28 09:00:09 -08006from vpp_object import VppObject
Neale Ranns810086d2017-11-05 16:26:46 -08007from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
8
9
Neale Rannsd0df49f2018-08-08 01:06:40 -070010def find_udp_encap(test, ue):
Neale Ranns810086d2017-11-05 16:26:46 -080011 encaps = test.vapi.udp_encap_dump()
12 for e in encaps:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020013 if (
14 ue.id == e.udp_encap.id
15 and ue.src_ip == str(e.udp_encap.src_ip)
16 and ue.dst_ip == str(e.udp_encap.dst_ip)
17 and e.udp_encap.dst_port == ue.dst_port
18 and e.udp_encap.src_port == ue.src_port
19 ):
Neale Ranns810086d2017-11-05 16:26:46 -080020 return True
Neale Rannsd0df49f2018-08-08 01:06:40 -070021
Neale Ranns810086d2017-11-05 16:26:46 -080022 return False
23
24
25class VppUdpEncap(VppObject):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020026 def __init__(self, test, src_ip, dst_ip, src_port, dst_port, table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -080027 self._test = test
Neale Ranns810086d2017-11-05 16:26:46 -080028 self.table_id = table_id
Neale Ranns810086d2017-11-05 16:26:46 -080029 self.src_ip_s = src_ip
30 self.dst_ip_s = dst_ip
Ole Troan0bcad322018-12-11 13:04:01 +010031 self.src_ip = src_ip
32 self.dst_ip = dst_ip
Neale Ranns810086d2017-11-05 16:26:46 -080033 self.src_port = src_port
34 self.dst_port = dst_port
35
36 def add_vpp_config(self):
Neale Ranns9c0a3c42018-09-07 08:57:41 -070037 r = self._test.vapi.udp_encap_add(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020038 self.src_ip, self.dst_ip, self.src_port, self.dst_port, self.table_id
39 )
Neale Ranns9c0a3c42018-09-07 08:57:41 -070040 self.id = r.id
Neale Ranns810086d2017-11-05 16:26:46 -080041 self._test.registry.register(self, self._test.logger)
42
43 def remove_vpp_config(self):
Neale Rannsd0df49f2018-08-08 01:06:40 -070044 self._test.vapi.udp_encap_del(self.id)
Neale Ranns810086d2017-11-05 16:26:46 -080045
46 def query_vpp_config(self):
Neale Rannsd0df49f2018-08-08 01:06:40 -070047 return find_udp_encap(self._test, self)
Neale Ranns810086d2017-11-05 16:26:46 -080048
Neale Ranns810086d2017-11-05 16:26:46 -080049 def object_id(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020050 return "udp-encap-%d" % self.id
Neale Ranns9c0a3c42018-09-07 08:57:41 -070051
52 def get_stats(self):
53 c = self._test.statistics.get_counter("/net/udp-encap")
54 return c[0][self.id]