aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/IncrementUtil.py
diff options
context:
space:
mode:
authorJuraj Linkeš <juraj.linkes@pantheon.tech>2021-06-24 17:58:23 +0200
committerVratko Polak <vrpolak@cisco.com>2021-07-28 11:14:27 +0000
commit75eb3abbac136bd6e9fb47f595b4f7b8a8294038 (patch)
treee166477da88ac8de5bdc89aaee0e4cbc91648f9c /resources/libraries/python/IncrementUtil.py
parent8843893ca7531cbb2212a5ed79882909c8374381 (diff)
IPsec: add nth matching SPD entry outbound TCs
Add testcases with plain ipv4 forwarding with 1, 10, 100 and 1000 SPD entries on outbound traffic in both directions both directions. Only match the last SPD entry and process others before the matching entry. Add testcases only without flow cache optimization. Refactor the Python functions that add SPD entries: - Unify the args in functions that add one and multiple entries. - For multiple entries, add the ability to pass an object that will handle how values in each iteration (i.e. for each entry) are modified. Change-Id: I061922eec6acc75a4e115202c07e72d89bf1f4d3 Signed-off-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
Diffstat (limited to 'resources/libraries/python/IncrementUtil.py')
-rw-r--r--resources/libraries/python/IncrementUtil.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/resources/libraries/python/IncrementUtil.py b/resources/libraries/python/IncrementUtil.py
new file mode 100644
index 0000000000..fca0839ac0
--- /dev/null
+++ b/resources/libraries/python/IncrementUtil.py
@@ -0,0 +1,74 @@
+# Copyright (c) 2021 PANTHEON.tech s.r.o.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Increment utilities library."""
+
+
+class ObjIncrement(object):
+ """
+ An iterator class used to generate incremented values in each iteration
+ or when inc_fmt is called.
+
+ Subclasses should override:
+ _incr: when a simple '+' binary operation isn't sufficient.
+ _str_fmt: when a simple str representation of the incremented object
+ isn't the proper format.
+ """
+ def __init__(self, initial_value, increment):
+ """
+ :param initial_value: The first value to be returned.
+ :param increment: Each iteration/inc_fmt call will return the previous
+ value incremented by this.
+ :type initial_value: object supporting the '+' binary operation
+ :type increment: object supporting the '+' binary operation
+ """
+ self._value = initial_value
+ self._increment = increment
+
+ def _incr(self):
+ """
+ This function will be called in each iteration/inc_fmt call. Subclasses
+ should override this when their object is incremented differently.
+ The function must compute the next iterated value and store it in
+ self._value.
+ """
+ self._value += self._increment
+
+ def __next__(self):
+ """
+ Each iteration returns the current object and stores the incremented
+ object (which will be returned in the next iteration). The first
+ iteration returns the initial value.
+ """
+ return_value = self._value
+ self._incr()
+ return return_value
+
+ def __iter__(self):
+ return self
+
+ def _str_fmt(self):
+ """
+ The string representation is a standard string representation of the
+ incremented object. Subclasses may override this for a different
+ string representation.
+ """
+ return str(self._value)
+
+ def inc_fmt(self):
+ """
+ Return a string representation and increment the current value.
+ """
+ return_value = self._str_fmt()
+ self._incr()
+ return return_value