forked from sonic-net/sonic-swss-common
-
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.
Add batch ops and StatusCode for PINS / P4Runtime
* Add batch set/delete() to ProducerStateTable * Add StatusCode enum and functions to convert between string and enum values. * Allow exists() to check for whitespace. This is only to allow whitespace when we check for existence. We can already create entries with whitespace. * Add SWSS return code SWSS_RC_UNIMPLEMENTED * Fix json error, refer to nlohmann/json#590 Submission containing materials of a third party: Copyright Google LLC; Licensed under Apache 2.0 Co-authored-by: Akarsh Gupta <[email protected]> Co-authored-by: Jay Hu <[email protected]> Co-authored-by: Manali Kumar <[email protected]> Co-authored-by: Robert J. Halstead <[email protected]> Co-authored-by: Runming Wu <[email protected]> Co-authored-by: Yilan Ji <[email protected]> Signed-off-by: Don Newton [email protected]
- Loading branch information
Showing
7 changed files
with
227 additions
and
6 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
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
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
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
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,70 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
#include <string> | ||
|
||
namespace swss { | ||
|
||
enum class StatusCode { | ||
SWSS_RC_SUCCESS, | ||
SWSS_RC_INVALID_PARAM, | ||
SWSS_RC_DEADLINE_EXCEEDED, | ||
SWSS_RC_UNAVAIL, | ||
SWSS_RC_NOT_FOUND, | ||
SWSS_RC_NO_MEMORY, | ||
SWSS_RC_EXISTS, | ||
SWSS_RC_PERMISSION_DENIED, | ||
SWSS_RC_FULL, | ||
SWSS_RC_IN_USE, | ||
SWSS_RC_INTERNAL, | ||
SWSS_RC_UNIMPLEMENTED, | ||
SWSS_RC_UNKNOWN, | ||
}; | ||
|
||
static std::map<StatusCode, std::string> statusCodeMapping = { | ||
{StatusCode::SWSS_RC_SUCCESS, "SWSS_RC_SUCCESS"}, | ||
{StatusCode::SWSS_RC_INVALID_PARAM, "SWSS_RC_INVALID_PARAM"}, | ||
{StatusCode::SWSS_RC_DEADLINE_EXCEEDED, "SWSS_RC_DEADLINE_EXCEEDED"}, | ||
{StatusCode::SWSS_RC_UNAVAIL, "SWSS_RC_UNAVAIL"}, | ||
{StatusCode::SWSS_RC_NOT_FOUND, "SWSS_RC_NOT_FOUND"}, | ||
{StatusCode::SWSS_RC_NO_MEMORY, "SWSS_RC_NO_MEMORY"}, | ||
{StatusCode::SWSS_RC_EXISTS, "SWSS_RC_EXISTS"}, | ||
{StatusCode::SWSS_RC_PERMISSION_DENIED, "SWSS_RC_PERMISSION_DENIED"}, | ||
{StatusCode::SWSS_RC_FULL, "SWSS_RC_FULL"}, | ||
{StatusCode::SWSS_RC_IN_USE, "SWSS_RC_IN_USE"}, | ||
{StatusCode::SWSS_RC_INTERNAL, "SWSS_RC_INTERNAL"}, | ||
{StatusCode::SWSS_RC_UNIMPLEMENTED, "SWSS_RC_UNIMPLEMENTED"}, | ||
{StatusCode::SWSS_RC_UNKNOWN, "SWSS_RC_UNKNOWN"}, | ||
}; | ||
|
||
static std::map<std::string, StatusCode> StatusCodeLookup = { | ||
{"SWSS_RC_SUCCESS", StatusCode::SWSS_RC_SUCCESS}, | ||
{"SWSS_RC_INVALID_PARAM", StatusCode::SWSS_RC_INVALID_PARAM}, | ||
{"SWSS_RC_DEADLINE_EXCEEDED", StatusCode::SWSS_RC_DEADLINE_EXCEEDED}, | ||
{"SWSS_RC_UNAVAIL", StatusCode::SWSS_RC_UNAVAIL}, | ||
{"SWSS_RC_NOT_FOUND", StatusCode::SWSS_RC_NOT_FOUND}, | ||
{"SWSS_RC_NO_MEMORY", StatusCode::SWSS_RC_NO_MEMORY}, | ||
{"SWSS_RC_EXISTS", StatusCode::SWSS_RC_EXISTS}, | ||
{"SWSS_RC_PERMISSION_DENIED", StatusCode::SWSS_RC_PERMISSION_DENIED}, | ||
{"SWSS_RC_FULL", StatusCode::SWSS_RC_FULL}, | ||
{"SWSS_RC_IN_USE", StatusCode::SWSS_RC_IN_USE}, | ||
{"SWSS_RC_INTERNAL", StatusCode::SWSS_RC_INTERNAL}, | ||
{"SWSS_RC_UNIMPLEMENTED", StatusCode::SWSS_RC_UNIMPLEMENTED}, | ||
{"SWSS_RC_UNKNOWN", StatusCode::SWSS_RC_UNKNOWN}, | ||
}; | ||
|
||
inline std::string statusCodeToStr(const StatusCode& status) { | ||
if (statusCodeMapping.find(status) == statusCodeMapping.end()) { | ||
return "SWSS_RC_UNKNOWN"; | ||
} | ||
return statusCodeMapping.at(status); | ||
} | ||
|
||
inline StatusCode strToStatusCode(const std::string& status) { | ||
if (StatusCodeLookup.find(status) == StatusCodeLookup.end()) { | ||
return StatusCode::SWSS_RC_UNKNOWN; | ||
} | ||
return StatusCodeLookup.at(status); | ||
} | ||
|
||
} // namespace swss |
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
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,19 @@ | ||
#include "common/status_code_util.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace { | ||
|
||
using swss::StatusCode; | ||
|
||
TEST(StatusCodeUtilTest, StatusCodeUtilTest) { | ||
for (int i = static_cast<int>(StatusCode::SWSS_RC_SUCCESS); | ||
i <= static_cast<int>(StatusCode::SWSS_RC_UNKNOWN); ++i) { | ||
StatusCode original = static_cast<StatusCode>(i); | ||
StatusCode final = swss::strToStatusCode(statusCodeToStr(original)); | ||
EXPECT_EQ(original, final); | ||
} | ||
EXPECT_EQ(StatusCode::SWSS_RC_UNKNOWN, swss::strToStatusCode("invalid")); | ||
} | ||
|
||
} // namespace |