X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FNATUtil.py;h=a9f760768e115226979986063c1618b6cbb098bf;hp=ceed560a04a747d149ea183b916fc811640127a9;hb=HEAD;hpb=692397148d893b22acdfdd708e4df2d5361d007a diff --git a/resources/libraries/python/NATUtil.py b/resources/libraries/python/NATUtil.py index ceed560a04..e5f530ab46 100644 --- a/resources/libraries/python/NATUtil.py +++ b/resources/libraries/python/NATUtil.py @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Cisco and/or its affiliates. +# Copyright (c) 2023 Cisco and/or its affiliates. # 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: @@ -63,9 +63,8 @@ class NATUtil: @staticmethod def enable_nat44_ed_plugin( - node, inside_vrf=0, outside_vrf=0, sessions=0, session_memory=0, - mode=u"" - ): + node, inside_vrf=0, outside_vrf=0, sessions=0, session_memory=0, + mode=u""): """Enable NAT44 plugin. :param node: DUT node. @@ -183,10 +182,9 @@ class NATUtil: """Delete and re-add the NAT range setting.""" with PapiSocketExecutor(node) as papi_exec: args_in[u"is_add"] = False - papi_exec.add(cmd, **args_in) + papi_exec.add(cmd, **args_in).get_reply(err_msg) args_in[u"is_add"] = True - papi_exec.add(cmd, **args_in) - papi_exec.get_replies(err_msg) + papi_exec.add(cmd, **args_in).get_reply(err_msg) return resetter @@ -278,7 +276,7 @@ class NATUtil: @staticmethod def get_nat44_sessions_number(node, proto): - """Get number of established NAT44 sessions from NAT44 mapping data. + """Get number of expected NAT44 sessions from NAT44 mapping data. This keyword uses output from a CLI command, so it can start failing when VPP changes the output format. @@ -287,17 +285,21 @@ class NATUtil: The current implementation supports both 2202 and post-2202 format. (The Gerrit number changing the output format is 34877.) - For TCP proto, the post-2202 format includes "timed out" - established sessions into its count of total sessions. + For TCP proto, the expected state after rampup is + some number of sessions in transitory state (VPP has seen the FINs), + and some number of sessions in established state (meaning + some FINs were lost in the last trial). + While the two states may need slightly different number of cycles + to process next packet, the current implementation considers + both of them the "fast path", so they are both counted as expected. + As the tests should fail if a session is timed-out, - the logic substracts timed out sessions for the resturned value. + the logic substracts timed out sessions for the returned value + (only available for post-2202 format). - The 2202 output reports most of TCP sessions as in "transitory" state, - as opposed to "established", but the previous CSIT logic tolerated that. - Ideally, whis keyword would add establised and transitory sessions - (but without CLOSED and WAIT_CLOSED sessions) and return that. - The current implementation simply returns "total tcp sessions" value, - to preserve the previous CSIT behavior for 2202 output. + TODO: Investigate if it is worth to insert additional rampup trials + in TPUT tests to ensure all sessions are transitory before next + measurement. :param node: DUT node. :param proto: Required protocol - TCP/UDP/ICMP. @@ -328,9 +330,7 @@ class NATUtil: found = True continue # Proto is found, find the line we are interested in. - if proto_l == u"tcp" and u"established" not in line: - continue - if u"total" not in line and u"established" not in line: + if u"total" not in line: raise RuntimeError(f"show nat summary: no {proto} total.") # We have the line with relevant numbers. total_part, timed_out_part = line.split(u"(", 1) @@ -426,10 +426,9 @@ class NATUtil: """Delete and re-add the deterministic NAT mapping.""" with PapiSocketExecutor(node) as papi_exec: args_in[u"is_add"] = False - papi_exec.add(cmd, **args_in) + papi_exec.add(cmd, **args_in).get_reply(err_msg) args_in[u"is_add"] = True - papi_exec.add(cmd, **args_in) - papi_exec.get_replies(err_msg) + papi_exec.add(cmd, **args_in).get_reply(err_msg) return resetter