+ summary_text = NATUtil.show_nat44_summary(node)
+ summary_lines = summary_text.splitlines()
+ # Output from VPP v22.02 and before, delete when no longer needed.
+ pattern_2202 = f"total {proto_l} sessions:"
+ if pattern_2202 in summary_text:
+ for line in summary_lines:
+ if pattern_2202 not in line:
+ continue
+ return int(line.split(u":", 1)[1].strip())
+ # Post-2202, the proto info and session info are not on the same line.
+ found = False
+ for line in summary_lines:
+ if not found:
+ if f"{proto_l} sessions:" in line:
+ found = True
+ continue
+ # Proto is found, find the line we are interested in.
+ 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)
+ timed_out_part = timed_out_part.split(u")", 1)[0]
+ total_count = int(total_part.split(u":", 1)[1].strip())
+ timed_out_count = int(timed_out_part.split(u":", 1)[1].strip())
+ active_count = total_count - timed_out_count
+ return active_count
+ raise RuntimeError(u"Unknown format of show nat44 summary")