Skip to content

Commit

Permalink
[Thinkit] Create interfaces, structs, and enums to be used in PINs NS…
Browse files Browse the repository at this point in the history
…F tests.Implement the various traffic generator helpers for PINs NSF tests.
  • Loading branch information
kishanps authored and VSuryaprasad-HCL committed Jan 7, 2025
1 parent 0be826e commit 8e8ec62
Show file tree
Hide file tree
Showing 8 changed files with 420 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/integration/system/nsf/interfaces/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
105 changes: 105 additions & 0 deletions tests/integration/system/nsf/interfaces/component_validator.h
Original file line number Diff line number Diff line change
@@ -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_
43 changes: 43 additions & 0 deletions tests/integration/system/nsf/interfaces/flow_programmer.h
Original file line number Diff line number Diff line change
@@ -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_
42 changes: 42 additions & 0 deletions tests/integration/system/nsf/interfaces/test_params.h
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <vector>

#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<ComponentValidator*> component_validators;
};

} // namespace pins_test

#endif // PINS_TESTS_INTEGRATION_SYSTEM_NSF_INTERFACES_TEST_PARAMS_H_
44 changes: 44 additions & 0 deletions tests/integration/system/nsf/interfaces/traffic_helper.h
Original file line number Diff line number Diff line change
@@ -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_
42 changes: 42 additions & 0 deletions tests/integration/system/nsf/traffic_helpers/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
40 changes: 40 additions & 0 deletions tests/integration/system/nsf/traffic_helpers/dvaas_helper.h
Original file line number Diff line number Diff line change
@@ -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_
Loading

0 comments on commit 8e8ec62

Please sign in to comment.