Skip to content

Commit cb99ae2

Browse files
kishanpsSRAVANI KANASANI
authored andcommitted
Add port counters to all frontpanel qos tests, collect them
Signed-off-by: SRAVANI KANASANI <[email protected]>
1 parent 8716b1f commit cb99ae2

File tree

3 files changed

+178
-1
lines changed

3 files changed

+178
-1
lines changed

lib/gnmi/gnmi_helper.cc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,52 @@ GetAllInterfaceCounters(gnmi::gNMI::StubInterface& gnmi_stub) {
22802280
return counters;
22812281
}
22822282

2283+
Counters Counters::operator-(const Counters& other) const {
2284+
return Counters{
2285+
in_pkts - other.in_pkts,
2286+
out_pkts - other.out_pkts,
2287+
in_octets - other.in_octets,
2288+
out_octets - other.out_octets,
2289+
in_unicast_pkts - other.in_unicast_pkts,
2290+
out_unicast_pkts - other.out_unicast_pkts,
2291+
in_multicast_pkts - other.in_multicast_pkts,
2292+
out_multicast_pkts - other.out_multicast_pkts,
2293+
in_broadcast_pkts - other.in_broadcast_pkts,
2294+
out_broadcast_pkts - other.out_broadcast_pkts,
2295+
in_errors - other.in_errors,
2296+
out_errors - other.out_errors,
2297+
in_discards - other.in_discards,
2298+
out_discards - other.out_discards,
2299+
in_buffer_discards - other.in_buffer_discards,
2300+
in_maxsize_exceeded - other.in_maxsize_exceeded,
2301+
in_fcs_errors - other.in_fcs_errors,
2302+
in_ipv4_pkts - other.in_ipv4_pkts,
2303+
out_ipv4_pkts - other.out_ipv4_pkts,
2304+
in_ipv6_pkts - other.in_ipv6_pkts,
2305+
out_ipv6_pkts - other.out_ipv6_pkts,
2306+
in_ipv6_discarded_pkts - other.in_ipv6_discarded_pkts,
2307+
out_ipv6_discarded_pkts - other.out_ipv6_discarded_pkts,
2308+
timestamp_ns - other.timestamp_ns,
2309+
};
2310+
}
2311+
2312+
absl::StatusOr<Counters> GetCountersForInterface(
2313+
absl::string_view interface_name, gnmi::gNMI::StubInterface& gnmi_stub) {
2314+
ASSIGN_OR_RETURN(
2315+
std::string interface_info,
2316+
GetGnmiStatePathInfo(
2317+
&gnmi_stub,
2318+
absl::StrCat("interfaces/interface[name=", interface_name, "]"),
2319+
"openconfig-interfaces:interface"));
2320+
ASSIGN_OR_RETURN(json interface_json, json_yang::ParseJson(interface_info));
2321+
if (!interface_json.is_array() || interface_json.empty()) {
2322+
return absl::InternalError(absl::StrCat(
2323+
"Expecting counters for interface ", interface_name,
2324+
" to have a non-zero JSON array, but got: ", interface_info));
2325+
}
2326+
return GetCountersForInterface(interface_json[0]);
2327+
}
2328+
22832329
absl::StatusOr<uint64_t> GetBadIntervalsCounter(
22842330
absl::string_view interface_name, gnmi::gNMI::StubInterface& gnmi_stub) {
22852331
ASSIGN_OR_RETURN(json port_counters_json,

lib/gnmi/gnmi_helper.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,50 @@ struct Counters {
164164
std::optional<uint64_t> carrier_transitions;
165165
uint64_t timestamp_ns = 0;
166166
std::optional<BlackholePortCounters> blackhole_counters;
167+
// Returns the difference between two counters.
168+
Counters operator-(const Counters& other) const;
169+
template <typename Sink>
170+
friend void AbslStringify(Sink& sink, const Counters& c) {
171+
absl::Format(&sink, "in_pkts: %v\n", c.in_pkts);
172+
absl::Format(&sink, "out_pkts: %v\n", c.out_pkts);
173+
absl::Format(&sink, "in_octets: %v\n", c.in_octets);
174+
absl::Format(&sink, "out_octets: %v\n", c.out_octets);
175+
absl::Format(&sink, "in_unicast_pkts: %v\n", c.in_unicast_pkts);
176+
absl::Format(&sink, "out_unicast_pkts: %v\n", c.out_unicast_pkts);
177+
absl::Format(&sink, "in_multicast_pkts: %v\n", c.in_multicast_pkts);
178+
absl::Format(&sink, "out_multicast_pkts: %v\n", c.out_multicast_pkts);
179+
absl::Format(&sink, "in_broadcast_pkts: %v\n", c.in_broadcast_pkts);
180+
absl::Format(&sink, "out_broadcast_pkts: %v\n", c.out_broadcast_pkts);
181+
absl::Format(&sink, "in_errors: %v\n", c.in_errors);
182+
absl::Format(&sink, "out_errors: %v\n", c.out_errors);
183+
absl::Format(&sink, "in_discards: %v\n", c.in_discards);
184+
absl::Format(&sink, "out_discards: %v\n", c.out_discards);
185+
absl::Format(&sink, "in_buffer_discards: %v\n", c.in_buffer_discards);
186+
absl::Format(&sink, "in_maxsize_exceeded: %v\n", c.in_maxsize_exceeded);
187+
absl::Format(&sink, "in_fcs_errors: %v\n", c.in_fcs_errors);
188+
absl::Format(&sink, "in_ipv4_pkts: %v\n", c.in_ipv4_pkts);
189+
absl::Format(&sink, "out_ipv4_pkts: %v\n", c.out_ipv4_pkts);
190+
absl::Format(&sink, "in_ipv6_pkts: %v\n", c.in_ipv6_pkts);
191+
absl::Format(&sink, "out_ipv6_pkts: %v\n", c.out_ipv6_pkts);
192+
absl::Format(&sink, "in_ipv6_discarded_pkts: %v\n",
193+
c.in_ipv6_discarded_pkts);
194+
absl::Format(&sink, "out_ipv6_discarded_pkts: %v\n",
195+
c.out_ipv6_discarded_pkts);
196+
if (c.carrier_transitions.has_value()) {
197+
absl::Format(&sink, "carrier_transitions: %v\n", *c.carrier_transitions);
198+
}
199+
absl::Format(&sink, "timestamp_ns: %v\n", c.timestamp_ns);
200+
if (c.blackhole_counters.has_value()) {
201+
absl::Format(&sink, "blackhole_counters.in_discard_events: %v\n",
202+
c.blackhole_counters.value().in_discard_events);
203+
absl::Format(&sink, "blackhole_counters.out_discard_events: %v\n",
204+
c.blackhole_counters.value().out_discard_events);
205+
absl::Format(&sink, "blackhole_counters.in_error_events: %v\n",
206+
c.blackhole_counters.value().in_error_events);
207+
absl::Format(&sink, "blackhole_counters.fec_not_correctable_events: %v\n",
208+
c.blackhole_counters.value().fec_not_correctable_events);
209+
}
210+
}
167211
};
168212

169213
struct BlackholeSwitchCounters {
@@ -627,6 +671,10 @@ absl::StatusOr<std::string> GetPortPfcRxEnable(
627671
absl::StatusOr<absl::flat_hash_map<std::string, Counters>>
628672
GetAllInterfaceCounters(gnmi::gNMI::StubInterface& gnmi_stub);
629673

674+
// Gets counters for an interface.
675+
absl::StatusOr<Counters> GetCountersForInterface(
676+
absl::string_view interface_name, gnmi::gNMI::StubInterface& gnmi_stub);
677+
630678
// Gets blackhole counters for an interface.
631679
absl::StatusOr<BlackholePortCounters> GetBlackholePortCounters(
632680
absl::string_view interface_name, gnmi::gNMI::StubInterface& gnmi_stub);

tests/qos/frontpanel_qos_test.cc

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ TEST_P(FrontpanelQosTest,
741741
(kDscpsByQueueName == kDscpsByMulticastQueueName);
742742

743743
QueueCounters kInitialQueueCounters;
744+
Counters kInitialPortCounters;
744745
// Actual testing -- inject test IPv4 and IPv6 packets for each DSCP,
745746
// and check the behavior is as eexpted.
746747
constexpr int kMaxDscp = 63;
@@ -785,6 +786,9 @@ TEST_P(FrontpanelQosTest,
785786
ASSERT_OK_AND_ASSIGN(
786787
kInitialQueueCounters,
787788
GetGnmiQueueCounters(kSutEgressPort, kTargetQueue, *gnmi_stub));
789+
ASSERT_OK_AND_ASSIGN(
790+
kInitialPortCounters,
791+
GetCountersForInterface(kSutEgressPort, *gnmi_stub));
788792
}
789793
// Configure & start test packet flow.
790794
const std::string kTrafficName =
@@ -904,6 +908,17 @@ TEST_P(FrontpanelQosTest,
904908
} while (TotalPacketsForQueue(delta_counters) <
905909
kIxiaTrafficStats.num_tx_frames() &&
906910
absl::Now() < kDeadline);
911+
ASSERT_OK_AND_ASSIGN(
912+
Counters final_port_counters,
913+
GetCountersForInterface(kSutEgressPort, *gnmi_stub));
914+
915+
SCOPED_TRACE(
916+
absl::StrCat("port counters incremented by ",
917+
kInitialPortCounters - final_port_counters));
918+
SCOPED_TRACE(
919+
absl::StrCat("Initial port counters: ", kInitialPortCounters));
920+
SCOPED_TRACE(
921+
absl::StrCat("Final port counters: ", final_port_counters));
907922
LOG(INFO) << "queue counters incremented by " << delta_counters;
908923
LOG(INFO) << "Queue Counters.\nBefore: "
909924
<< ToString(kInitialQueueCounters)
@@ -1238,6 +1253,9 @@ TEST_P(FrontpanelQosTest, WeightedRoundRobinWeightsAreRespected) {
12381253
ASSERT_OK_AND_ASSIGN(sut_p4rt, pdpi::P4RuntimeSession::Create(sut));
12391254
}
12401255
// Start traffic.
1256+
Counters kInitialPortCounters;
1257+
ASSERT_OK_AND_ASSIGN(kInitialPortCounters,
1258+
GetCountersForInterface(kSutEgressPort, *gnmi_stub));
12411259
LOG(INFO) << "starting traffic";
12421260
ASSERT_OK(ixia::StartTraffic(traffic_items, kIxiaHandle, *testbed));
12431261
auto stop_traffic = absl::Cleanup(
@@ -1255,6 +1273,14 @@ TEST_P(FrontpanelQosTest, WeightedRoundRobinWeightsAreRespected) {
12551273
// weights.
12561274
ASSERT_OK_AND_ASSIGN(const ixia::TrafficStats kTrafficStats,
12571275
ixia::GetAllTrafficItemStats(kIxiaHandle, *testbed));
1276+
1277+
ASSERT_OK_AND_ASSIGN(Counters final_port_counters,
1278+
GetCountersForInterface(kSutEgressPort, *gnmi_stub));
1279+
1280+
SCOPED_TRACE(absl::StrCat("port counters incremented by ",
1281+
final_port_counters - kInitialPortCounters));
1282+
SCOPED_TRACE(absl::StrCat("Initial port counters: ", kInitialPortCounters));
1283+
SCOPED_TRACE(absl::StrCat("Final port counters: ", final_port_counters));
12581284
absl::flat_hash_map<std::string, int64_t> num_rx_frames_by_queue;
12591285
for (auto &[traffic_item_name, stats] :
12601286
Ordered(kTrafficStats.stats_by_traffic_item())) {
@@ -1685,6 +1711,18 @@ TEST_P(FrontpanelQosTest, StrictQueuesAreStrictlyPrioritized) {
16851711
LOG(INFO) << "NSF reboot complete, sending traffic again to ensure "
16861712
"the forwarding traffic is not disrupted.";
16871713
}
1714+
bool not_after_nsf_reboot =
1715+
!GetParam().nsf_reboot ||
1716+
test_operation == TestOperations::NsfRebootAndTrafficTest;
1717+
Counters kInitialPortCounters;
1718+
if (not_after_nsf_reboot) {
1719+
// Get initial port counters after NSF Reboot is complete since
1720+
// gnmi calls cannot be made during NSF reboot.
1721+
ASSERT_OK_AND_ASSIGN(
1722+
kInitialPortCounters,
1723+
GetCountersForInterface(kSutEgressPort, *gnmi_stub));
1724+
}
1725+
16881726
// Run traffic for a while, then obtain stats.
16891727
LOG(INFO) << "starting traffic (" << traffic_items.size() << " items)";
16901728
// Occasionally the Ixia API cannot keep up and starting traffic
@@ -1703,6 +1741,23 @@ TEST_P(FrontpanelQosTest, StrictQueuesAreStrictlyPrioritized) {
17031741
ASSERT_OK_AND_ASSIGN(
17041742
const ixia::TrafficStats kTrafficStats,
17051743
ixia::GetAllTrafficItemStats(kIxiaHandle, *testbed));
1744+
1745+
if (not_after_nsf_reboot) {
1746+
// Get port counters after NSF Reboot is complete since
1747+
// gnmi calls cannot be made during NSF reboot.
1748+
ASSERT_OK_AND_ASSIGN(
1749+
Counters final_port_counters,
1750+
GetCountersForInterface(kSutEgressPort, *gnmi_stub));
1751+
1752+
SCOPED_TRACE(
1753+
absl::StrCat("port counters incremented by ",
1754+
final_port_counters - kInitialPortCounters));
1755+
SCOPED_TRACE(
1756+
absl::StrCat("Initial port counters: ", kInitialPortCounters));
1757+
SCOPED_TRACE(
1758+
absl::StrCat("Final port counters: ", final_port_counters));
1759+
}
1760+
17061761
LOG(INFO) << "validating traffic stats against expectation";
17071762
double bytes_per_second_received = 0;
17081763
for (auto &[traffic_item, stats] :
@@ -2127,6 +2182,9 @@ TEST_P(FrontpanelQosTest, TestWredEcnMarking) {
21272182

21282183
ResetEcnTestPacketCounters(packet_receive_info);
21292184

2185+
Counters kInitialPortCounters;
2186+
ASSERT_OK_AND_ASSIGN(kInitialPortCounters,
2187+
GetCountersForInterface(kSutOutPort, *gnmi_stub));
21302188
ASSERT_OK(pins::TryUpToNTimes(3, /*delay=*/absl::Seconds(1), [&] {
21312189
return pins_test::ixia::StartTraffic(ixia_setup_result.traffic_refs,
21322190
ixia_setup_result.topology_ref,
@@ -2163,13 +2221,27 @@ TEST_P(FrontpanelQosTest, TestWredEcnMarking) {
21632221
// Wait for a bit to collect queue statistics.
21642222
constexpr absl::Duration kQueueStatsWaitTime = absl::Seconds(5);
21652223
absl::SleepFor(kQueueStatsWaitTime);
2224+
2225+
ASSERT_OK_AND_ASSIGN(Counters final_port_counters,
2226+
GetCountersForInterface(kSutOutPort, *gnmi_stub));
2227+
2228+
SCOPED_TRACE(absl::StrCat("port counters incremented by ",
2229+
final_port_counters - kInitialPortCounters));
2230+
SCOPED_TRACE(
2231+
absl::StrCat("Initial port counters: ", kInitialPortCounters));
2232+
SCOPED_TRACE(
2233+
absl::StrCat("Final port counters: ", final_port_counters));
21662234

21672235
// Read counters of the target queue.
21682236
ASSERT_OK_AND_ASSIGN(
21692237
const QueueCounters queue_counters_after_test_packet,
21702238
GetGnmiQueueCounters(/*port=*/kSutOutPort,
21712239
/*queue=*/target_queue, *gnmi_stub));
2172-
2240+
2241+
SCOPED_TRACE(absl::StrCat("Queue counters before test packet: ",
2242+
ToString(queue_counters_before_test_packet)));
2243+
SCOPED_TRACE(absl::StrCat("Queue counters after test packet: ",
2244+
ToString(queue_counters_after_test_packet)));
21732245
// This test expects WRED config to only mark packets and not
21742246
// drop. Expect no drops in target queue and queue transmit
21752247
// counter increments.
@@ -2525,6 +2597,10 @@ TEST_P(FrontpanelBufferTest, BufferCarving) {
25252597
ASSERT_OK(DoNsfRebootAndWaitForSwitchReadyOrRecover(
25262598
testbed.get(), *GetParam().default_params.ssh_client_for_nsf));
25272599
}
2600+
Counters kInitialPortCounters;
2601+
ASSERT_OK_AND_ASSIGN(kInitialPortCounters,
2602+
GetCountersForInterface(kSutEgressPort, *gnmi_stub));
2603+
25282604
// Start traffic.
25292605
LOG(INFO) << "starting traffic";
25302606
ASSERT_OK(ixia::StartTraffic(traffic_items, kIxiaHandle, *testbed));
@@ -2536,6 +2612,13 @@ TEST_P(FrontpanelBufferTest, BufferCarving) {
25362612
// config.
25372613
ASSERT_OK_AND_ASSIGN(const ixia::TrafficStats kTrafficStats,
25382614
ixia::GetAllTrafficItemStats(kIxiaHandle, *testbed));
2615+
2616+
ASSERT_OK_AND_ASSIGN(Counters final_port_counters,
2617+
GetCountersForInterface(kSutEgressPort, *gnmi_stub));
2618+
SCOPED_TRACE(absl::StrCat("port counters incremented by ",
2619+
final_port_counters - kInitialPortCounters));
2620+
SCOPED_TRACE(absl::StrCat("Initial port counters: ", kInitialPortCounters));
2621+
SCOPED_TRACE(absl::StrCat("Final port counters: ", final_port_counters));
25392622

25402623
absl::flat_hash_map<int, int64_t> rx_frames_by_buffer_config;
25412624
for (auto &[traffic_item_name, stats] :

0 commit comments

Comments
 (0)