blob: bdca9a8ca18c0e782ff02d8c14d4a19b81109489 [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
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:
Neale Rannsd0df49f2018-08-08 01:06:40 -070013 if ue.id == e.udp_encap.id \
Ole Troan0bcad322018-12-11 13:04:01 +010014 and ue.src_ip == str(e.udp_encap.src_ip) \
15 and ue.dst_ip == str(e.udp_encap.dst_ip) \
Neale Rannsd0df49f2018-08-08 01:06:40 -070016 and e.udp_encap.dst_port == ue.dst_port \
17 and e.udp_encap.src_port == ue.src_port:
Neale Ranns810086d2017-11-05 16:26:46 -080018 return True
Neale Rannsd0df49f2018-08-08 01:06:40 -070019
Neale Ranns810086d2017-11-05 16:26:46 -080020 return False
21
22
23class VppUdpEncap(VppObject):
24
25 def __init__(self,
26 test,
Neale Ranns810086d2017-11-05 16:26:46 -080027 src_ip,
28 dst_ip,
29 src_port,
30 dst_port,
Neale Rannsd0df49f2018-08-08 01:06:40 -070031 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -080032 self._test = test
Neale Ranns810086d2017-11-05 16:26:46 -080033 self.table_id = table_id
Neale Ranns810086d2017-11-05 16:26:46 -080034 self.src_ip_s = src_ip
35 self.dst_ip_s = dst_ip
Ole Troan0bcad322018-12-11 13:04:01 +010036 self.src_ip = src_ip
37 self.dst_ip = dst_ip
Neale Ranns810086d2017-11-05 16:26:46 -080038 self.src_port = src_port
39 self.dst_port = dst_port
40
41 def add_vpp_config(self):
Neale Ranns9c0a3c42018-09-07 08:57:41 -070042 r = self._test.vapi.udp_encap_add(
Ole Troan0bcad322018-12-11 13:04:01 +010043 self.src_ip,
44 self.dst_ip,
Neale Ranns810086d2017-11-05 16:26:46 -080045 self.src_port,
46 self.dst_port,
Neale Rannsd0df49f2018-08-08 01:06:40 -070047 self.table_id)
Neale Ranns9c0a3c42018-09-07 08:57:41 -070048 self.id = r.id
Neale Ranns810086d2017-11-05 16:26:46 -080049 self._test.registry.register(self, self._test.logger)
50
51 def remove_vpp_config(self):
Neale Rannsd0df49f2018-08-08 01:06:40 -070052 self._test.vapi.udp_encap_del(self.id)
Neale Ranns810086d2017-11-05 16:26:46 -080053
54 def query_vpp_config(self):
Neale Rannsd0df49f2018-08-08 01:06:40 -070055 return find_udp_encap(self._test, self)
Neale Ranns810086d2017-11-05 16:26:46 -080056
Neale Ranns810086d2017-11-05 16:26:46 -080057 def object_id(self):
58 return ("udp-encap-%d" % self.id)
Neale Ranns9c0a3c42018-09-07 08:57:41 -070059
60 def get_stats(self):
61 c = self._test.statistics.get_counter("/net/udp-encap")
62 return c[0][self.id]