From afb93e816d902dcaa0c41f68f91ff4b2a8cd2d53 Mon Sep 17 00:00:00 2001 From: kishanps Date: Tue, 19 Dec 2023 11:19:42 -0800 Subject: [PATCH] [Thinkit] Create interfaces, structs, and enums to be used in PINs NSF tests.Implement the various traffic generator helpers for PINs NSF tests. --- .../system/nsf/interfaces/BUILD.bazel | 62 +++++++++++ .../nsf/interfaces/component_validator.h | 105 ++++++++++++++++++ .../system/nsf/interfaces/flow_programmer.h | 43 +++++++ .../system/nsf/interfaces/test_params.h | 42 +++++++ .../system/nsf/interfaces/traffic_helper.h | 44 ++++++++ .../system/nsf/traffic_helpers/BUILD.bazel | 42 +++++++ .../system/nsf/traffic_helpers/dvaas_helper.h | 40 +++++++ .../system/nsf/traffic_helpers/otg_helper.h | 42 +++++++ 8 files changed, 420 insertions(+) create mode 100644 tests/integration/system/nsf/interfaces/BUILD.bazel create mode 100644 tests/integration/system/nsf/interfaces/component_validator.h create mode 100644 tests/integration/system/nsf/interfaces/flow_programmer.h create mode 100644 tests/integration/system/nsf/interfaces/test_params.h create mode 100644 tests/integration/system/nsf/interfaces/traffic_helper.h create mode 100644 tests/integration/system/nsf/traffic_helpers/BUILD.bazel create mode 100644 tests/integration/system/nsf/traffic_helpers/dvaas_helper.h create mode 100644 tests/integration/system/nsf/traffic_helpers/otg_helper.h diff --git a/tests/integration/system/nsf/interfaces/BUILD.bazel b/tests/integration/system/nsf/interfaces/BUILD.bazel new file mode 100644 index 00000000..7ef4559a --- /dev/null +++ b/tests/integration/system/nsf/interfaces/BUILD.bazel @@ -0,0 +1,62 @@ +# Copyright 2024 Google LLC +# +# 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 +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This package contains the interfaces, structs, and enums to be used in PINs NSF tests. + +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + +cc_library( + name = "flow_programmer", + testonly = True, + hdrs = ["flow_programmer.h"], + deps = [ + "//thinkit:generic_testbed", + "@com_google_absl//absl/status", + ], +) + +cc_library( + name = "traffic_helper", + hdrs = ["traffic_helper.h"], + deps = [ + "//thinkit:generic_testbed", + "@com_google_absl//absl/status", + ], +) + +cc_library( + name = "component_validator", + testonly = True, + hdrs = ["component_validator.h"], + deps = [ + "//thinkit:generic_testbed", + "@com_google_absl//absl/status", + "@com_google_absl//absl/strings:string_view", + ], +) + +cc_library( + name = "test_params", + testonly = True, + hdrs = ["test_params.h"], + deps = [ + ":component_validator", + ":flow_programmer", + ":traffic_helper", + "//thinkit:generic_testbed_fixture", + ], +) diff --git a/tests/integration/system/nsf/interfaces/component_validator.h b/tests/integration/system/nsf/interfaces/component_validator.h new file mode 100644 index 00000000..f92235f7 --- /dev/null +++ b/tests/integration/system/nsf/interfaces/component_validator.h @@ -0,0 +1,105 @@ +// Copyright 2024 Google LLC +// +// 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef PINS_TESTS_INTEGRATION_SYSTEM_NSF_INTERFACES_COMPONENT_VALIDATOR_H_ +#define PINS_TESTS_INTEGRATION_SYSTEM_NSF_INTERFACES_COMPONENT_VALIDATOR_H_ + +#include "absl/status/status.h" +#include "absl/strings/string_view.h" +#include "thinkit/generic_testbed.h" + +namespace pins_test { + +// Interface to provide a mechanism to implement component-level validations +// during NSF integration tests. +// +// The different methods of this interface are called *after* the corresponding +// operation is performed during the test. +// +// Eg. After every flow programming operation, the `OnFlowProgram` method is +// called. +// +// The given `version` is the image version of the software stack running on the +// SUT at the time the function is called. +// +// The given `testbed` can be used by the implementation to interact with the +// SUT, ControlDevice, TrafficClient, or the test environment. +// +// Typically an implementation of the `ComponentValidator` would grab and store +// some state which is specific to a particular component and/or validate it +// against such a previously stored component-specific state. +// +// Note that it can also be used for other kinds of validations that do not +// necessarily involve grabbing or validating state from the SUT. +// +// Eg. We can use these methods to track performance by calculating the time +// difference between function calls. +class ComponentValidator { + public: + virtual ~ComponentValidator() = default; + + // Called before starting every NSF test. + virtual absl::Status OnInit(absl::string_view version, + thinkit::GenericTestbed& testbed) { + return absl::OkStatus(); + } + + // Called after programming flows on SUT. + virtual absl::Status OnFlowProgram(absl::string_view version, + thinkit::GenericTestbed& testbed) { + return absl::OkStatus(); + } + + // Called after starting traffic from the Control Device or the Traffic + // Generator in the testbed. + virtual absl::Status OnStartTraffic(absl::string_view version, + thinkit::GenericTestbed& testbed) { + return absl::OkStatus(); + } + + // Called after an upgrade is performed on the SUT. + virtual absl::Status OnUpgrade(absl::string_view version, + thinkit::GenericTestbed& testbed) { + return absl::OkStatus(); + } + + // Called after a successful NSF reboot of the SUT. + virtual absl::Status OnNsfReboot(absl::string_view version, + thinkit::GenericTestbed& testbed) { + return absl::OkStatus(); + } + + // Called after pushing config on the SUT. + virtual absl::Status OnConfigPush(absl::string_view version, + thinkit::GenericTestbed& testbed) { + return absl::OkStatus(); + } + + // Called after stopping traffic from the Control Device or the Traffic + // Generator in the testbed. + virtual absl::Status OnStopTraffic(absl::string_view version, + thinkit::GenericTestbed& testbed) { + return absl::OkStatus(); + } + + // Called after clearing up flows from the SUT. + virtual absl::Status OnFlowCleanup(absl::string_view version, + thinkit::GenericTestbed& testbed) { + return absl::OkStatus(); + } +}; + +} // namespace pins_test + +#endif // PINS_TESTS_INTEGRATION_SYSTEM_NSF_INTERFACES_COMPONENT_VALIDATOR_H_ diff --git a/tests/integration/system/nsf/interfaces/flow_programmer.h b/tests/integration/system/nsf/interfaces/flow_programmer.h new file mode 100644 index 00000000..3726a8b1 --- /dev/null +++ b/tests/integration/system/nsf/interfaces/flow_programmer.h @@ -0,0 +1,43 @@ +// Copyright 2024 Google LLC +// +// 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef PINS_TESTS_INTEGRATION_SYSTEM_NSF_INTERFACES_FLOW_PROGRAMMER_H_ +#define PINS_TESTS_INTEGRATION_SYSTEM_NSF_INTERFACES_FLOW_PROGRAMMER_H_ + +#include "absl/status/status.h" +#include "thinkit/generic_testbed.h" + +namespace pins_test { + +enum class IpVersion { kIpv4, kIpv6 }; +enum class Protocol { kTcp, kUdp }; + +// Interface to program or clear flows on the SUT of the given `testbed` during +// NSF integration tests. +class FlowProgrammer { + public: + virtual ~FlowProgrammer() = default; + + // Programs a predefined flow on the SUT based on the given IP version and + // protocol. + virtual absl::Status ProgramFlows(IpVersion ip_version, Protocol protocol, + thinkit::GenericTestbed& testbed) = 0; + + // Clears all flows on the SUT. + virtual absl::Status ClearFlows(thinkit::GenericTestbed& testbed) = 0; +}; + +} // namespace pins_test + +#endif // PINS_TESTS_INTEGRATION_SYSTEM_NSF_INTERFACES_FLOW_PROGRAMMER_H_ diff --git a/tests/integration/system/nsf/interfaces/test_params.h b/tests/integration/system/nsf/interfaces/test_params.h new file mode 100644 index 00000000..02f0c10e --- /dev/null +++ b/tests/integration/system/nsf/interfaces/test_params.h @@ -0,0 +1,42 @@ +// Copyright 2024 Google LLC +// +// 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef PINS_TESTS_INTEGRATION_SYSTEM_NSF_INTERFACES_TEST_PARAMS_H_ +#define PINS_TESTS_INTEGRATION_SYSTEM_NSF_INTERFACES_TEST_PARAMS_H_ + +#include +#include + +#include "tests/integration/system/nsf/interfaces/component_validator.h" +#include "tests/integration/system/nsf/interfaces/flow_programmer.h" +#include "tests/integration/system/nsf/interfaces/traffic_helper.h" +#include "thinkit/generic_testbed_fixture.h" + +namespace pins_test { + +// Struct to hold test parameters to be injected in PINs NSF integration tests. +// +// Note that the `name` is used as the name of the instantiation of the +// parameterized NSF integration test. +struct NsfTestParams { + std::string name; + FlowProgrammer* flow_programmer; + TrafficHelper* traffic_helper; + thinkit::GenericTestbedInterface* testbed_interface; + std::vector component_validators; +}; + +} // namespace pins_test + +#endif // PINS_TESTS_INTEGRATION_SYSTEM_NSF_INTERFACES_TEST_PARAMS_H_ diff --git a/tests/integration/system/nsf/interfaces/traffic_helper.h b/tests/integration/system/nsf/interfaces/traffic_helper.h new file mode 100644 index 00000000..cac0393b --- /dev/null +++ b/tests/integration/system/nsf/interfaces/traffic_helper.h @@ -0,0 +1,44 @@ +// Copyright 2024 Google LLC +// +// 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef PINS_TESTS_INTEGRATION_SYSTEM_NSF_INTERFACES_TRAFFIC_HELPER_H_ +#define PINS_TESTS_INTEGRATION_SYSTEM_NSF_INTERFACES_TRAFFIC_HELPER_H_ + +#include "absl/status/status.h" +#include "thinkit/generic_testbed.h" + +namespace pins_test { + +// Interface to control traffic in the given `testbed` during NSF integration +// test. +class TrafficHelper { + public: + virtual ~TrafficHelper() = default; + + // Starts traffic with a predefined traffic configuration from a Control + // Device or Traffic Generator in the testbed. + virtual absl::Status StartTraffic(thinkit::GenericTestbed& testbed) = 0; + + // Stops traffic in the testbed. + virtual absl::Status StopTraffic(thinkit::GenericTestbed& testbed) = 0; + + // Validates traffic in the testbed. + // Needs to be called *after* `StopTraffic()` is called. + virtual absl::Status ValidateTraffic(int error_percentage, + thinkit::GenericTestbed& testbed) = 0; +}; + +} // namespace pins_test + +#endif // PINS_TESTS_INTEGRATION_SYSTEM_NSF_INTERFACES_TRAFFIC_HELPER_H_ diff --git a/tests/integration/system/nsf/traffic_helpers/BUILD.bazel b/tests/integration/system/nsf/traffic_helpers/BUILD.bazel new file mode 100644 index 00000000..685879de --- /dev/null +++ b/tests/integration/system/nsf/traffic_helpers/BUILD.bazel @@ -0,0 +1,42 @@ +# Copyright 2024 Google LLC +# +# 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 +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This package implements the various traffic generator helpers for PINs NSF tests. + +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + +cc_library( + name = "dvaas_helper", + testonly = True, + hdrs = ["dvaas_helper.h"], + deps = [ + "//tests/integration/system/nsf/interfaces:traffic_helper", + "//thinkit:generic_testbed", + "@com_google_absl//absl/status", + ], +) + +cc_library( + name = "otg_helper", + testonly = True, + hdrs = ["otg_helper.h"], + deps = [ + "//tests/integration/system/nsf/interfaces:traffic_helper", + "//thinkit:generic_testbed", + "@com_google_absl//absl/status", + ], +) diff --git a/tests/integration/system/nsf/traffic_helpers/dvaas_helper.h b/tests/integration/system/nsf/traffic_helpers/dvaas_helper.h new file mode 100644 index 00000000..2a564e90 --- /dev/null +++ b/tests/integration/system/nsf/traffic_helpers/dvaas_helper.h @@ -0,0 +1,40 @@ +// Copyright 2024 Google LLC +// +// 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef PINS_TESTS_INTEGRATION_SYSTEM_NSF_TRAFFIC_HELPERS_DVAAS_HELPER_H_ +#define PINS_TESTS_INTEGRATION_SYSTEM_NSF_TRAFFIC_HELPERS_DVAAS_HELPER_H_ + +#include "absl/status/status.h" +#include "tests/integration/system/nsf/interfaces/traffic_helper.h" +#include "thinkit/generic_testbed.h" + +namespace pins_test { + +class DvaasHelper : public TrafficHelper { + public: + absl::Status StartTraffic(thinkit::GenericTestbed& testbed) override { + return absl::OkStatus(); + }; + absl::Status StopTraffic(thinkit::GenericTestbed& testbed) override { + return absl::OkStatus(); + }; + absl::Status ValidateTraffic(int error_margin, + thinkit::GenericTestbed& testbed) override { + return absl::OkStatus(); + }; +}; + +} // namespace pins_test + +#endif // PINS_TESTS_INTEGRATION_SYSTEM_NSF_TRAFFIC_HELPERS_DVAAS_HELPER_H_ diff --git a/tests/integration/system/nsf/traffic_helpers/otg_helper.h b/tests/integration/system/nsf/traffic_helpers/otg_helper.h new file mode 100644 index 00000000..6772ab37 --- /dev/null +++ b/tests/integration/system/nsf/traffic_helpers/otg_helper.h @@ -0,0 +1,42 @@ +// Copyright 2024 Google LLC +// +// 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef PINS_TESTS_INTEGRATION_SYSTEM_NSF_TRAFFIC_HELPERS_OTG_HELPER_H_ +#define PINS_TESTS_INTEGRATION_SYSTEM_NSF_TRAFFIC_HELPERS_OTG_HELPER_H_ + +#include "absl/status/status.h" +#include "tests/integration/system/nsf/interfaces/traffic_helper.h" +#include "thinkit/generic_testbed.h" + +namespace pins_test { + +class OtgHelper : public TrafficHelper { + ~OtgHelper() override = default; + + public: + absl::Status StartTraffic(thinkit::GenericTestbed& testbed) override { + return absl::OkStatus(); + }; + absl::Status StopTraffic(thinkit::GenericTestbed& testbed) override { + return absl::OkStatus(); + }; + absl::Status ValidateTraffic(int error_margin, + thinkit::GenericTestbed& testbed) override { + return absl::OkStatus(); + }; +}; + +} // namespace pins_test + +#endif // PINS_TESTS_INTEGRATION_SYSTEM_NSF_TRAFFIC_HELPERS_OTG_HELPER_H_