-
Notifications
You must be signed in to change notification settings - Fork 543
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
Modify coppmgr mergeConfig to support preserving copp tables through reboot. #2548
Merged
liat-grozovik
merged 11 commits into
sonic-net:master
from
arfeigin:preserve_copp_tables2
Jan 1, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f1d88c8
Modify coppmgr mergeConfig to support preserving copp tables through …
arfeigin 6720422
Minor modifications
arfeigin c1797c6
Move merge preserved copp logic to dedicated function
arfeigin f4287b8
Merge preserved copp after trap_ids add to trap_group, use del instea…
arfeigin bb7c412
refactor last change
arfeigin 288c298
minor fixes
arfeigin f346b19
Removed unused map
arfeigin 76c1a12
Fixes according to CR comments
arfeigin 1fe47c3
Add unit test for COPP changes
dprital 9446114
Add system function retrun code check in CoppMgrTest
liorghub f3806c9
Update copp_ut.cpp
arfeigin 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
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,111 @@ | ||
{ | ||
"COPP_GROUP": { | ||
"default": { | ||
"queue": "0", | ||
"meter_type":"packets", | ||
"mode":"sr_tcm", | ||
"cir":"600", | ||
"cbs":"600", | ||
"red_action":"drop" | ||
}, | ||
"queue4_group1": { | ||
"trap_action":"trap", | ||
"trap_priority":"4", | ||
"queue": "4" | ||
}, | ||
"queue4_group2": { | ||
"trap_action":"copy", | ||
"trap_priority":"4", | ||
"queue": "4", | ||
"meter_type":"packets", | ||
"mode":"sr_tcm", | ||
"cir":"600", | ||
"cbs":"600", | ||
"red_action":"drop" | ||
}, | ||
"queue4_group3": { | ||
"trap_action":"trap", | ||
"trap_priority":"4", | ||
"queue": "4" | ||
}, | ||
"queue1_group1": { | ||
"trap_action":"trap", | ||
"trap_priority":"1", | ||
"queue": "1", | ||
"meter_type":"packets", | ||
"mode":"sr_tcm", | ||
"cir":"6000", | ||
"cbs":"6000", | ||
"red_action":"drop" | ||
}, | ||
"queue1_group2": { | ||
"trap_action":"trap", | ||
"trap_priority":"1", | ||
"queue": "1", | ||
"meter_type":"packets", | ||
"mode":"sr_tcm", | ||
"cir":"600", | ||
"cbs":"600", | ||
"red_action":"drop" | ||
}, | ||
"queue2_group1": { | ||
"cbs": "1000", | ||
"cir": "1000", | ||
"genetlink_mcgrp_name": "packets", | ||
"genetlink_name": "psample", | ||
"meter_type": "packets", | ||
"mode": "sr_tcm", | ||
"queue": "2", | ||
"red_action": "drop", | ||
"trap_action": "trap", | ||
"trap_priority": "1" | ||
|
||
} | ||
}, | ||
"COPP_TRAP": { | ||
"bgp": { | ||
"trap_ids": "bgp,bgpv6", | ||
"trap_group": "queue4_group1" | ||
}, | ||
"lacp": { | ||
"trap_ids": "lacp", | ||
"trap_group": "queue4_group1", | ||
"always_enabled": "true" | ||
}, | ||
"arp": { | ||
"trap_ids": "arp_req,arp_resp,neigh_discovery", | ||
"trap_group": "queue4_group2", | ||
"always_enabled": "true" | ||
}, | ||
"lldp": { | ||
"trap_ids": "lldp", | ||
"trap_group": "queue4_group3" | ||
}, | ||
"dhcp_relay": { | ||
"trap_ids": "dhcp,dhcpv6", | ||
"trap_group": "queue4_group3" | ||
}, | ||
"udld": { | ||
"trap_ids": "udld", | ||
"trap_group": "queue4_group3", | ||
"always_enabled": "true" | ||
}, | ||
"ip2me": { | ||
"trap_ids": "ip2me", | ||
"trap_group": "queue1_group1", | ||
"always_enabled": "true" | ||
}, | ||
"macsec": { | ||
"trap_ids": "eapol", | ||
"trap_group": "queue4_group3" | ||
}, | ||
"nat": { | ||
"trap_ids": "src_nat_miss,dest_nat_miss", | ||
"trap_group": "queue1_group2" | ||
}, | ||
"sflow": { | ||
"trap_group": "queue2_group1", | ||
"trap_ids": "sample_packet" | ||
} | ||
} | ||
} |
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,76 @@ | ||
#include "gtest/gtest.h" | ||
#include <string> | ||
#include "schema.h" | ||
#include "warm_restart.h" | ||
#include "ut_helper.h" | ||
#include "coppmgr.h" | ||
#include "coppmgr.cpp" | ||
#include <fstream> | ||
#include <streambuf> | ||
using namespace std; | ||
using namespace swss; | ||
|
||
void create_init_file() | ||
{ | ||
int status = system("sudo mkdir /etc/sonic/"); | ||
ASSERT_EQ(status, 0); | ||
|
||
status = system("sudo chmod 777 /etc/sonic/"); | ||
ASSERT_EQ(status, 0); | ||
|
||
status = system("sudo cp copp_cfg.json /etc/sonic/"); | ||
ASSERT_EQ(status, 0); | ||
} | ||
|
||
void cleanup() | ||
{ | ||
int status = system("sudo rm -rf /etc/sonic/"); | ||
ASSERT_EQ(status, 0); | ||
} | ||
|
||
TEST(CoppMgrTest, CoppTest) | ||
{ | ||
create_init_file(); | ||
|
||
const vector<string> cfg_copp_tables = { | ||
CFG_COPP_TRAP_TABLE_NAME, | ||
CFG_COPP_GROUP_TABLE_NAME, | ||
CFG_FEATURE_TABLE_NAME, | ||
}; | ||
|
||
WarmStart::initialize("coppmgrd", "swss"); | ||
WarmStart::checkWarmStart("coppmgrd", "swss"); | ||
|
||
DBConnector cfgDb("CONFIG_DB", 0); | ||
DBConnector appDb("APPL_DB", 0); | ||
DBConnector stateDb("STATE_DB", 0); | ||
|
||
/* The test will set an entry with queue1_group1|cbs value which differs from the init value | ||
* found in the copp_cfg.json file. Then coppmgr constructor will be called and it will detect | ||
* that there is already an entry for queue1_group1|cbs with different value and it should be | ||
* overwritten with the init value. | ||
* hget will verify that this indeed happened. | ||
*/ | ||
Table coppTable = Table(&appDb, APP_COPP_TABLE_NAME); | ||
coppTable.set("queue1_group1", | ||
{ | ||
{"cbs", "6100"}, | ||
{"cir", "6000"}, | ||
{"meter_type", "packets"}, | ||
{"mode", "sr_tcm"}, | ||
{"queue", "1"}, | ||
{"red_action", "drop"}, | ||
{"trap_action", "trap"}, | ||
{"trap_priority", "1"}, | ||
{"trap_ids", "ip2me"} | ||
}); | ||
|
||
CoppMgr coppmgr(&cfgDb, &appDb, &stateDb, cfg_copp_tables); | ||
|
||
string overide_val; | ||
coppTable.hget("queue1_group1", "cbs",overide_val); | ||
EXPECT_EQ( overide_val, "6000"); | ||
|
||
cleanup(); | ||
} | ||
|
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.
seems this code covers case where new copp entry has a field that preserved does not. isn't it missing a case where preserved copp entry had a field that new copp entry does not carry anymore?
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.
Good catch, I missed it.
I guess this can be done easily by comparing the sizes of fvs and preserved_fvs. I will test and raise a new PR with this fix.
Comparing sizes will be sufficient since if sizes differ it says that there is at least one difference so it is not a duplicate and the preserved entry should be deleted and new entry set.
In case the size of both is equal but some of the fields differs it will be caught then iterating over fvs.
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.
yeah, size check should work.