forked from sonic-net/sonic-buildimage
-
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.
Modify coppmgr mergeConfig to support preserving copp tables through …
…reboot. (sonic-net#2548) This PR should be merged together with sonic-net/sonic-utilities#2524 and is required to 202205 and 202211. This PR implements [fastboot] Preserve CoPP table HLD to improve fastboot flow (sonic-net/SONiC#1107). - What I did Modified coppmgr mergeConfig logic to support preserving copp tables contents through reboot. Handle duplicates, overwrites, unsupported keys preserved and new keys. According to sonic-net/SONiC#1107 - Why I did it To shorten dataplane downtime on fast-reboot. - How I verified it Manual tests (community fast-reboot test)
- Loading branch information
Showing
5 changed files
with
246 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
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(); | ||
} | ||
|