Skip to content

Commit

Permalink
Merge branch 'main' into gnmi_helper7
Browse files Browse the repository at this point in the history
  • Loading branch information
kishanps authored Aug 8, 2024
2 parents 2463456 + 7504393 commit 5362ee5
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/basic_traffic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ cc_test(

cc_library(
name = "basic_traffic",
testonly = True,
srcs = ["basic_traffic.cc"],
hdrs = ["basic_traffic.h"],
deps = [
Expand Down
5 changes: 5 additions & 0 deletions lib/pins_control_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ absl::StatusOr<absl::flat_hash_set<std::string>> PinsControlDevice::GetUpLinks(

absl::Status PinsControlDevice::CheckUp() { return SwitchReady(*sut_); }

absl::Status PinsControlDevice::ValidatePortsUp(
absl::Span<const std::string> interfaces) {
return PortsUp(*sut_, interfaces);
}

absl::StatusOr<std::vector<std::string>>
PinsControlDevice::FilterCollateralDownOnAdminDownInterfaces(
absl::Span<const std::string> interfaces) {
Expand Down
3 changes: 3 additions & 0 deletions lib/pins_control_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class PinsControlDevice : public thinkit::ControlDevice {
absl::Span<const std::string> interfaces) override;

absl::Status CheckUp() override;

absl::Status ValidatePortsUp(
absl::Span<const std::string> interfaces) override;

absl::StatusOr<std::vector<std::string>>
FilterCollateralDownOnAdminDownInterfaces(
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ cc_test(

cc_library(
name = "generic_testbed_utils",
testonly = True,
srcs = ["generic_testbed_utils.cc"],
hdrs = ["generic_testbed_utils.h"],
deps = [
"//gutil:status",
"//lib/gnmi:gnmi_helper",
"//lib/validator:validator_lib",
"//thinkit:generic_testbed",
"//thinkit:switch",
"//thinkit/proto:generic_testbed_cc_proto",
Expand All @@ -81,6 +82,7 @@ cc_test(
"//gutil:status_matchers",
"//gutil:testing",
"//thinkit:generic_testbed",
"//thinkit:mock_control_device",
"//thinkit:mock_generic_testbed",
"//thinkit:mock_switch",
"//thinkit/proto:generic_testbed_cc_proto",
Expand Down
13 changes: 13 additions & 0 deletions lib/utils/generic_testbed_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "artifacts/otg.pb.h"
#include "gutil/status.h"
#include "lib/gnmi/gnmi_helper.h"
#include "lib/validator/validator_lib.h"
#include "thinkit/generic_testbed.h"
#include "thinkit/proto/generic_testbed.pb.h"
#include "thinkit/switch.h"
Expand Down Expand Up @@ -146,6 +147,18 @@ absl::StatusOr<std::vector<InterfaceLink>> GetUpLinks(
return up_links;
}

absl::Status ValidateTestbedPortsUp(thinkit::GenericTestbed& testbed) {
auto sut_status =
PortsUp(testbed.Sut(), FromTestbed(GetAllConnectedInterfaces, testbed));
auto control_interfaces =
GetPeerInterfaces(FromTestbed(GetAllControlLinks, testbed));
absl::Status control_status =
testbed.ControlDevice().ValidatePortsUp(control_interfaces);

RETURN_IF_ERROR(sut_status);
return control_status;
}

absl::StatusOr<Layer1::Speed::Enum> GetLayer1SpeedFromBitsPerSecond(
int64_t bits_per_second) {
// Map keyed on openconfig speed in bits per second to value in OTG layer 1
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/generic_testbed_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ absl::StatusOr<std::vector<std::string>> GetUpInterfaces(
absl::StatusOr<std::vector<InterfaceLink>> GetUpLinks(
decltype(GetAllControlLinks) get_links, thinkit::GenericTestbed& testbed);

// Checks whether all connected ports of SUT and connected Control Switch
// interfaces are up.
absl::Status ValidateTestbedPortsUp(thinkit::GenericTestbed& testbed);

// Returns a speed enum to set in the OTG layer 1 config for a given speed in
// bits per second.
absl::StatusOr<otg::Layer1::Speed::Enum> GetLayer1SpeedFromBitsPerSecond(
Expand Down
1 change: 0 additions & 1 deletion thinkit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ cc_library(
hdrs = ["control_device.h"],
deps = [
":packet_generation_finalizer",
"@com_github_gnoi//diag:diag_cc_grpc_proto",
"@com_github_gnoi//diag:diag_cc_proto",
"@com_github_grpc_grpc//:grpc++",
"@com_google_absl//absl/container:flat_hash_set",
Expand Down
5 changes: 5 additions & 0 deletions thinkit/control_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "absl/time/time.h"
#include "absl/types/span.h"
#include "diag/diag.grpc.pb.h"
#include "diag/diag.grpc.pb.h"
#include "diag/diag.pb.h"
#include "thinkit/packet_generation_finalizer.h"

Expand Down Expand Up @@ -111,6 +112,10 @@ class ControlDevice {
// device is ready after a reboot.
virtual absl::Status CheckUp() = 0;

// Checks if the given control device ports are up.
virtual absl::Status ValidatePortsUp(
absl::Span<const std::string> interfaces) = 0;

// Return the subset of the given interfaces that, when admin-disabled, do not
// cause link flaps on the other interfaces on the same physical port.
virtual absl::StatusOr<std::vector<std::string>>
Expand Down
2 changes: 2 additions & 0 deletions thinkit/mock_control_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class MockControlDevice : public ControlDevice {
MOCK_METHOD(absl::StatusOr<absl::flat_hash_set<std::string>>, GetUpLinks,
(absl::Span<const std::string> sut_ports), (override));
MOCK_METHOD(absl::Status, CheckUp, (), (override));
MOCK_METHOD(absl::Status, ValidatePortsUp,
(absl::Span<const std::string> interfaces), (override));
MOCK_METHOD(absl::StatusOr<std::vector<std::string>>,
FilterCollateralDownOnAdminDownInterfaces,
(absl::Span<const std::string> interfaces), (override));
Expand Down

0 comments on commit 5362ee5

Please sign in to comment.