-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep attribute order in bulk mode #1659
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#include "ut_helper.h" | ||
#include "bulker.h" | ||
|
||
extern sai_route_api_t *sai_route_api; | ||
|
||
namespace bulker_test | ||
{ | ||
using namespace std; | ||
|
||
struct BulkerTest : public ::testing::Test | ||
{ | ||
BulkerTest() | ||
{ | ||
} | ||
|
||
void SetUp() override | ||
{ | ||
ASSERT_EQ(sai_route_api, nullptr); | ||
sai_route_api = new sai_route_api_t(); | ||
} | ||
|
||
void TearDown() override | ||
{ | ||
delete sai_route_api; | ||
sai_route_api = nullptr; | ||
} | ||
}; | ||
|
||
TEST_F(BulkerTest, BulkerAttrOrder) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Did this unit test fail old code? |
||
{ | ||
// Create bulker | ||
EntityBulker<sai_route_api_t> gRouteBulker(sai_route_api); | ||
deque<sai_status_t> object_statuses; | ||
|
||
// Create a dummy route entry | ||
sai_route_entry_t route_entry; | ||
route_entry.destination.addr_family = SAI_IP_ADDR_FAMILY_IPV4; | ||
route_entry.destination.addr.ip4 = htonl(0x0a00000f); | ||
route_entry.destination.mask.ip4 = htonl(0xffffff00); | ||
route_entry.vr_id = 0x0; | ||
route_entry.switch_id = 0x0; | ||
|
||
// Set packet action for route first | ||
sai_attribute_t route_attr; | ||
route_attr.id = SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION; | ||
route_attr.value.s32 = SAI_PACKET_ACTION_FORWARD; | ||
|
||
object_statuses.emplace_back(); | ||
gRouteBulker.set_entry_attribute(&object_statuses.back(), &route_entry, &route_attr); | ||
|
||
// Set next hop for route | ||
route_attr.id = SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID; | ||
route_attr.value.oid = SAI_NULL_OBJECT_ID; | ||
|
||
object_statuses.emplace_back(); | ||
gRouteBulker.set_entry_attribute(&object_statuses.back(), &route_entry, &route_attr); | ||
|
||
// Check number of routes in bulk | ||
ASSERT_EQ(gRouteBulker.setting_entries_count(), 1); | ||
|
||
// Confirm the order of attributes in bulk is the same as being set | ||
auto const& attrs = gRouteBulker.setting_entries[route_entry]; | ||
ASSERT_EQ(attrs.size(), 2); | ||
auto ia = attrs.begin(); | ||
ASSERT_EQ(ia->first.id, SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION); | ||
ASSERT_EQ(ia->first.value.s32, SAI_PACKET_ACTION_FORWARD); | ||
ia++; | ||
ASSERT_EQ(ia->first.id, SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID); | ||
ASSERT_EQ(ia->first.value.oid, SAI_NULL_OBJECT_ID); | ||
|
||
// Clear the bulk | ||
gRouteBulker.clear(); | ||
object_statuses.clear(); | ||
|
||
// Check the bulker has been cleared | ||
ASSERT_EQ(gRouteBulker.setting_entries_count(), 0); | ||
|
||
// Test the inverse order | ||
// Set next hop for route first | ||
route_attr.id = SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID; | ||
route_attr.value.oid = SAI_NULL_OBJECT_ID; | ||
|
||
object_statuses.emplace_back(); | ||
gRouteBulker.set_entry_attribute(&object_statuses.back(), &route_entry, &route_attr); | ||
|
||
// Set packet action for route | ||
route_attr.id = SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION; | ||
route_attr.value.s32 = SAI_PACKET_ACTION_FORWARD; | ||
|
||
object_statuses.emplace_back(); | ||
gRouteBulker.set_entry_attribute(&object_statuses.back(), &route_entry, &route_attr); | ||
|
||
// Check number of routes in bulk | ||
ASSERT_EQ(gRouteBulker.setting_entries_count(), 1); | ||
|
||
// Confirm the order of attributes in bulk is the same as being set | ||
auto const& attrs_reverse = gRouteBulker.setting_entries[route_entry]; | ||
ASSERT_EQ(attrs_reverse.size(), 2); | ||
ia = attrs_reverse.begin(); | ||
ASSERT_EQ(ia->first.id, SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID); | ||
ASSERT_EQ(ia->first.value.oid, SAI_NULL_OBJECT_ID); | ||
ia++; | ||
ASSERT_EQ(ia->first.id, SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION); | ||
ASSERT_EQ(ia->first.value.s32, SAI_PACKET_ACTION_FORWARD); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One advantage or map structure is possible to merge setting operation on the same entry and same attribute. Is it still required? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does not seem very necessary to merge the operations for the same attribute and the same entry because of the following reasons:
PACKET_ACTION
andNEXT_HOP_ID
, each gets to set only once in the routeorch logic.