+ def insert_interface_stats(self, pps_list):
+ """Insert interface stats to a list of packet path stats.
+
+ pps_list: a list of packet path stats instances indexed by chain index
+
+ This function will insert the packet path stats for the traffic gen ports 0 and 1
+ with itemized per chain tx/rx counters.
+ There will be as many packet path stats as chains.
+ Each packet path stats will have exactly 2 InterfaceStats for port 0 and port 1
+ self.pps_list:
+ [
+ PacketPathStats(InterfaceStats(chain 0, port 0), InterfaceStats(chain 0, port 1)),
+ PacketPathStats(InterfaceStats(chain 1, port 0), InterfaceStats(chain 1, port 1)),
+ ...
+ ]
+ """
+ def get_if_stats(chain_idx):
+ return [InterfaceStats('p' + str(port), self.tool)
+ for port in range(2)]
+ # keep the list of list of interface stats indexed by the chain id
+ self.ifstats = [get_if_stats(chain_idx)
+ for chain_idx in range(self.config.service_chain_count)]
+ # note that we need to make a copy of the ifs list so that any modification in the
+ # list from pps will not change the list saved in self.ifstats
+ self.pps_list = [PacketPathStats(list(ifs)) for ifs in self.ifstats]
+ # insert the corresponding pps in the passed list
+ pps_list.extend(self.pps_list)
+
+ def update_interface_stats(self, diff=False):
+ """Update all interface stats.
+
+ diff: if False, simply refresh the interface stats values with latest values
+ if True, diff the interface stats with the latest values
+ Make sure that the interface stats inserted in insert_interface_stats() are updated
+ with proper values.
+ self.ifstats:
+ [
+ [InterfaceStats(chain 0, port 0), InterfaceStats(chain 0, port 1)],
+ [InterfaceStats(chain 1, port 0), InterfaceStats(chain 1, port 1)],
+ ...
+ ]
+ """
+ if diff:
+ stats = self.gen.get_stats()
+ for chain_idx, ifs in enumerate(self.ifstats):
+ # each ifs has exactly 2 InterfaceStats and 2 Latency instances
+ # corresponding to the
+ # port 0 and port 1 for the given chain_idx
+ # Note that we cannot use self.pps_list[chain_idx].if_stats to pick the
+ # interface stats for the pps because it could have been modified to contain
+ # additional interface stats
+ self.gen.get_stream_stats(stats, ifs, self.pps_list[chain_idx].latencies, chain_idx)
+ # special handling for vxlan
+ # in case of vxlan, flow stats are not available so all rx counters will be
+ # zeros when the total rx port counter is non zero.
+ # in that case,
+ for port in range(2):
+ total_rx = 0
+ for ifs in self.ifstats:
+ total_rx += ifs[port].rx
+ if total_rx == 0:
+ # check if the total port rx from Trex is also zero
+ port_rx = stats[port]['rx']['total_pkts']
+ if port_rx:
+ # the total rx for all chains from port level stats is non zero
+ # which means that the per-chain stats are not available
+ if len(self.ifstats) == 1:
+ # only one chain, simply report the port level rx to the chain rx stats
+ self.ifstats[0][port].rx = port_rx
+ else:
+ for ifs in self.ifstats:
+ # mark this data as unavailable
+ ifs[port].rx = None
+ # pitch in the total rx only in the last chain pps
+ self.ifstats[-1][port].rx_total = port_rx
+