forked from sonic-net/sonic-pins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of Thinkit (sonic-net#210)
- Loading branch information
1 parent
c478b38
commit 39e53a4
Showing
5 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Copyright 2020 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. | ||
# | ||
# Thinkit is a set of interfaces to enable PINS testing to be infrastructure agnostic. | ||
|
||
load("@bazel_skylib//rules:build_test.bzl", "build_test") | ||
load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test", "diff_test") | ||
load("//p4_pdpi:pdgen.bzl", "p4_pd_proto") | ||
load("@com_github_p4lang_p4c//:bazel/p4_library.bzl", "p4_library") | ||
|
||
package( | ||
default_visibility = ["//visibility:public"], | ||
licenses = ["notice"], | ||
) | ||
|
||
cc_library( | ||
name = "thinkit", | ||
deps = [ | ||
":mirror_testbed", | ||
":switch", | ||
":test_environment", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "switch", | ||
hdrs = ["switch.h"], | ||
deps = [ | ||
"@com_github_grpc_grpc//:grpc++", | ||
"@com_github_p4lang_p4runtime//:p4runtime_cc_grpc", | ||
"@com_google_absl//absl/status:statusor", | ||
"@com_google_absl//absl/strings", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "mirror_testbed", | ||
hdrs = ["mirror_testbed.h"], | ||
deps = [ | ||
":switch", | ||
":test_environment", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "test_environment", | ||
hdrs = ["test_environment.h"], | ||
deps = [ | ||
"@com_google_absl//absl/status", | ||
"@com_google_absl//absl/strings", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "ssh_client", | ||
hdrs = ["ssh_client.h"], | ||
deps = [ | ||
"@com_google_absl//absl/status", | ||
"@com_google_absl//absl/status:statusor", | ||
"@com_google_absl//absl/strings", | ||
"@com_google_absl//absl/time", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# ThinKit | ||
|
||
A set of interfaces that define access to systems under test and surrounding | ||
topology to allow infrastructure-agnostic tests to be written and reused. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2020, Google Inc. | ||
// | ||
// 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 THINKIT_MIRROR_TESTBED_H_ | ||
#define THINKIT_MIRROR_TESTBED_H_ | ||
|
||
#include "thinkit/switch.h" | ||
#include "thinkit/test_environment.h" | ||
|
||
namespace thinkit { | ||
|
||
// The MirrorTestbed interface represents a testbed topology with two | ||
// P4RT-capable switches connected back-to-back. | ||
class MirrorTestbed { | ||
public: | ||
virtual ~MirrorTestbed() {} | ||
|
||
// Returns the control switch (switch connected to the SUT (system under | ||
// test)). | ||
virtual Switch& ControlSwitch() = 0; | ||
|
||
// Returns the SUT (system under test) switch. | ||
virtual Switch& Sut() = 0; | ||
|
||
// Returns the test environment. | ||
virtual TestEnvironment& Environment() = 0; | ||
}; | ||
|
||
} // namespace thinkit | ||
|
||
#endif // THINKIT_MIRROR_TESTBED_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2020, Google Inc. | ||
// | ||
// 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 THINKIT_SWITCH_H_ | ||
#define THINKIT_SWITCH_H_ | ||
|
||
#include <cstdint> | ||
#include <memory> | ||
|
||
#include "absl/status/statusor.h" | ||
#include "absl/strings/string_view.h" | ||
#include "p4/v1/p4runtime.grpc.pb.h" | ||
#include "proto/gnmi/gnmi.grpc.pb.h" | ||
|
||
namespace thinkit { | ||
|
||
// The Switch interface represents a P4RT-capable switch that can be connected | ||
// to in a blackbox fashion. | ||
class Switch { | ||
public: | ||
virtual ~Switch() {} | ||
|
||
// Returns the chassis name of the switch. This should be a reachable | ||
// hostname to the switch. | ||
virtual absl::string_view ChassisName() = 0; | ||
|
||
// Returns the P4Runtime device ID of the switch. | ||
virtual uint32_t DeviceId() = 0; | ||
|
||
// Creates and returns a stub to the P4Runtime service. | ||
virtual absl::StatusOr<std::unique_ptr<p4::v1::P4Runtime::Stub>> | ||
CreateP4RuntimeStub() = 0; | ||
|
||
// Creates and returns a stub to the gNMI service. | ||
virtual absl::StatusOr<std::unique_ptr<gnmi::gNMI::Stub>> | ||
CreateGnmiStub() = 0; | ||
}; | ||
|
||
} // namespace thinkit | ||
|
||
#endif // THINKIT_SWITCH_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2020, Google Inc. | ||
// | ||
// 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 THINKIT_TEST_ENVIRONMENT_H_ | ||
#define THINKIT_TEST_ENVIRONMENT_H_ | ||
|
||
#include "absl/status/status.h" | ||
#include "absl/strings/string_view.h" | ||
|
||
namespace thinkit { | ||
|
||
// The TestEnvironment interface represents the underlying test infrastructure | ||
// to which a test might want to pass additional debug information to. | ||
class TestEnvironment { | ||
public: | ||
virtual ~TestEnvironment() {} | ||
|
||
// Stores a test artifact with the specified filename and contents. Overwrites | ||
// existing files. | ||
virtual absl::Status StoreTestArtifact(absl::string_view filename, | ||
absl::string_view contents) = 0; | ||
|
||
// Appends contents to an existing test artifact with the specified filename. | ||
// Creates a new file if it doesn't exist. | ||
virtual absl::Status AppendToTestArtifact(absl::string_view filename, | ||
absl::string_view contents) = 0; | ||
}; | ||
|
||
} // namespace thinkit | ||
|
||
#endif // THINKIT_TEST_ENVIRONMENT_H_ |