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.
[Thinkit] Adding lib/p4rt files. (sonic-net#312)
* [Thinkit] Adding json_utils files. * [Thinkit] Adding lib/p4rt files.
- Loading branch information
1 parent
5e93bcc
commit 0052972
Showing
3 changed files
with
100 additions
and
32 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,31 @@ | ||
# 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. | ||
|
||
package( | ||
default_visibility = ["//visibility:public"], | ||
licenses = ["notice"], | ||
) | ||
|
||
cc_library( | ||
name = "p4rt_port", | ||
srcs = ["p4rt_port.cc"], | ||
hdrs = ["p4rt_port.h"], | ||
deps = [ | ||
"//p4_pdpi/string_encodings:decimal_string", | ||
"@com_google_absl//absl/status", | ||
"@com_google_absl//absl/status:statusor", | ||
"@com_google_absl//absl/strings", | ||
], | ||
) | ||
|
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,58 @@ | ||
/* | ||
* 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. | ||
*/ | ||
#include "lib/p4rt/p4rt_port.h" | ||
|
||
#include <cstdint> | ||
|
||
#include "absl/status/statusor.h" | ||
#include "absl/strings/str_cat.h" | ||
#include "absl/strings/string_view.h" | ||
#include "gutil/status.h" | ||
#include "p4_pdpi/string_encodings/decimal_string.h" | ||
|
||
namespace pins_test { | ||
|
||
absl::StatusOr<P4rtPortId> P4rtPortId::OfP4rtEncoding( | ||
absl::string_view p4rt_port_id) { | ||
ASSIGN_OR_RETURN(uint32_t p4rt_port_id_int, | ||
pdpi::DecimalStringToUint32(p4rt_port_id)); | ||
return P4rtPortId(p4rt_port_id_int); | ||
} | ||
|
||
P4rtPortId P4rtPortId::OfOpenConfigEncoding(uint32_t p4rt_port_id) { | ||
return P4rtPortId(p4rt_port_id); | ||
} | ||
|
||
uint32_t P4rtPortId::GetOpenConfigEncoding() const { return p4rt_port_id_; } | ||
|
||
std::string P4rtPortId::GetP4rtEncoding() const { | ||
return absl::StrCat(p4rt_port_id_); | ||
} | ||
|
||
bool P4rtPortId::operator==(const P4rtPortId& other) const { | ||
return p4rt_port_id_ == other.p4rt_port_id_; | ||
} | ||
|
||
bool P4rtPortId::operator<(const P4rtPortId& other) const { | ||
return p4rt_port_id_ < other.p4rt_port_id_; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, const P4rtPortId& p4rt_port_id) { | ||
return os << absl::StrCat("(p4rt_port_id: ", p4rt_port_id.GetP4rtEncoding(), | ||
")"); | ||
} | ||
|
||
} // namespace pins_test |
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