Skip to content

Commit 5671e08

Browse files
Orchagent changes needed to support single ASIC VOQ Fixed-System (#3847)
What I did Portorch, Neighorch, Intfsorch are updated to not access chassis app DB. Chassis app DB is accessed only if the chassisdb.conf is present indicating its a real chassis (not a FS VOQ) For lag creation, system lags are created as the switch is a VOQ swtich. Why I did it For a fixed system, there is no chassis DB present How I verified it Ran sonic-mgmt tests to verify BGP, LAG, functionality
1 parent b017bd3 commit 5671e08

File tree

11 files changed

+492
-28
lines changed

11 files changed

+492
-28
lines changed

.azure-pipelines/docker-sonic-vs/start.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@ else
6161
qos_cmd="-j /tmp/qos.json"
6262
fi
6363

64+
if [ -f /usr/share/sonic/single_asic_voq_fs/default_config.json ]; then
65+
sonic-cfggen -j /usr/share/sonic/single_asic_voq_fs/default_config.json --print-data > /tmp/voq.json
66+
voq_cmd="-j /tmp/voq.json"
67+
fi
68+
6469
sonic-cfggen -p /usr/share/sonic/device/$PLATFORM/$PLATFORM_CONF -k $HWSKU --print-data > /tmp/ports.json
6570
# change admin_status from up to down; Test cases dependent
6671
sed -i "s/up/down/g" /tmp/ports.json
67-
sonic-cfggen -j /etc/sonic/init_cfg.json $buffers_cmd $qos_cmd -j /tmp/ports.json --print-data > /etc/sonic/config_db.json
72+
sonic-cfggen -j /etc/sonic/init_cfg.json $buffers_cmd $qos_cmd $voq_cmd -j /tmp/ports.json --print-data > /etc/sonic/config_db.json
6873
fi
6974

7075
sonic-cfggen -t /usr/share/sonic/templates/copp_cfg.j2 > /etc/sonic/copp_cfg.json

.azure-pipelines/test-docker-sonic-vs-template.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ jobs:
180180
retry=3
181181
IMAGE_NAME=docker-sonic-vs:$(Build.DefinitionName).$(Build.BuildNumber).asan-${{ parameters.asan }}
182182
echo $all_tests | xargs -n 1 | xargs -P 8 -I TEST_MODULE sudo DEFAULT_CONTAINER_REGISTRY=publicmirror.azurecr.io/ ./run-tests.sh "$IMAGE_NAME" "$params" "TEST_MODULE" 3
183+
single_asic_voq_tests="test_portchannel.py test_neighbor.py test_route.py"
184+
echo $single_asic_voq_tests | xargs -n 1 | xargs -P 3 -I TEST_MODULE sudo ./run-tests.sh "$IMAGE_NAME" "--force-recreate-dvs --switch-mode=single_asic_voq_fs" "TEST_MODULE" 3
183185
184186
rm -rf $(Build.ArtifactStagingDirectory)/download
185187
displayName: "Run vs tests"

orchagent/intfsorch.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern NeighOrch *gNeighOrch;
3838
extern string gMySwitchType;
3939
extern int32_t gVoqMySwitchId;
4040
extern bool gTraditionalFlexCounter;
41+
extern bool isChassisDbInUse();
4142

4243
const int intfsorch_pri = 35;
4344

@@ -98,7 +99,7 @@ IntfsOrch::IntfsOrch(DBConnector *db, string tableName, VRFOrch *vrf_orch, DBCon
9899
RIF_PLUGIN_FIELD,
99100
rifRateSha);
100101

101-
if(gMySwitchType == "voq")
102+
if(isChassisDbInUse())
102103
{
103104
//Add subscriber to process VOQ system interface
104105
tableName = CHASSIS_APP_SYSTEM_INTERFACE_TABLE_NAME;
@@ -1310,7 +1311,7 @@ bool IntfsOrch::addRouterIntfs(sai_object_id_t vrf_id, Port &port, string loopba
13101311

13111312
SWSS_LOG_NOTICE("Create router interface %s MTU %u", port.m_alias.c_str(), port.m_mtu);
13121313

1313-
if(gMySwitchType == "voq")
1314+
if(isChassisDbInUse())
13141315
{
13151316
// Sync the interface of local port/LAG to the SYSTEM_INTERFACE table of CHASSIS_APP_DB
13161317
voqSyncAddIntf(port.m_alias);
@@ -1363,7 +1364,7 @@ bool IntfsOrch::removeRouterIntfs(Port &port)
13631364

13641365
SWSS_LOG_NOTICE("Remove router interface for port %s", port.m_alias.c_str());
13651366

1366-
if(gMySwitchType == "voq")
1367+
if(isChassisDbInUse())
13671368
{
13681369
// Sync the removal of interface of local port/LAG to the SYSTEM_INTERFACE table of CHASSIS_APP_DB
13691370
voqSyncDelIntf(port.m_alias);

orchagent/main.cpp

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ extern "C" {
1717
#include <stdexcept>
1818
#include <stdlib.h>
1919
#include <string.h>
20+
#include <fstream>
21+
#include <nlohmann/json.hpp>
2022

2123
#include <sys/time.h>
2224
#include <sairedis.h>
@@ -77,6 +79,12 @@ string gMyHostName = "";
7779
string gMyAsicName = "";
7880
bool gTraditionalFlexCounter = false;
7981
uint32_t create_switch_timeout = 0;
82+
bool gMultiAsicVoq = false;
83+
84+
bool isChassisDbInUse()
85+
{
86+
return gMultiAsicVoq;
87+
}
8088

8189
void usage()
8290
{
@@ -208,6 +216,18 @@ void getCfgSwitchType(DBConnector *cfgDb, string &switch_type, string &switch_su
208216

209217
}
210218

219+
bool isChassisAppDbPresent()
220+
{
221+
std::ifstream file("/etc/sonic/database_config.json");
222+
if (!file.is_open()) return false;
223+
224+
nlohmann::json db_config;
225+
file >> db_config;
226+
227+
return db_config.contains("DATABASES") &&
228+
db_config["DATABASES"].contains("CHASSIS_APP_DB");
229+
}
230+
211231
bool getSystemPortConfigList(DBConnector *cfgDb, DBConnector *appDb, vector<sai_system_port_config_t> &sysportcfglist)
212232
{
213233
Table cfgDeviceMetaDataTable(cfgDb, CFG_DEVICE_METADATA_TABLE_NAME);
@@ -617,7 +637,19 @@ int main(int argc, char **argv)
617637

618638
//Connect to CHASSIS_APP_DB in redis-server in control/supervisor card as per
619639
//connection info in database_config.json
620-
chassis_app_db = make_shared<DBConnector>("CHASSIS_APP_DB", 0, true);
640+
chassis_app_db = nullptr;
641+
if (isChassisAppDbPresent())
642+
{
643+
gMultiAsicVoq = true;
644+
try
645+
{
646+
chassis_app_db = make_shared<DBConnector>("CHASSIS_APP_DB", 0, true);
647+
}
648+
catch (const std::exception& e)
649+
{
650+
SWSS_LOG_NOTICE("CHASSIS_APP_DB not available, operating in standalone VOQ mode");
651+
}
652+
}
621653
}
622654
else if (gMySwitchType == "fabric")
623655
{
@@ -867,6 +899,11 @@ int main(int argc, char **argv)
867899
}
868900

869901
shared_ptr<OrchDaemon> orchDaemon;
902+
DBConnector *chassis_db = nullptr;
903+
if (chassis_app_db != nullptr)
904+
{
905+
chassis_db = chassis_app_db.get();
906+
}
870907

871908
/*
872909
* Declare shared pointers for dpu specific databases.
@@ -884,7 +921,7 @@ int main(int argc, char **argv)
884921

885922
else if (gMySwitchType != "fabric")
886923
{
887-
orchDaemon = make_shared<OrchDaemon>(&appl_db, &config_db, &state_db, chassis_app_db.get(), zmq_server.get());
924+
orchDaemon = make_shared<OrchDaemon>(&appl_db, &config_db, &state_db, chassis_db, zmq_server.get());
888925
if (gMySwitchType == "voq")
889926
{
890927
orchDaemon->setFabricEnabled(true);
@@ -894,7 +931,7 @@ int main(int argc, char **argv)
894931
}
895932
else
896933
{
897-
orchDaemon = make_shared<FabricOrchDaemon>(&appl_db, &config_db, &state_db, chassis_app_db.get(), zmq_server.get());
934+
orchDaemon = make_shared<FabricOrchDaemon>(&appl_db, &config_db, &state_db, chassis_db, zmq_server.get());
898935
}
899936

900937
if (gRingMode) {

orchagent/neighorch.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ extern BfdOrch *gBfdOrch;
2525
extern size_t gMaxBulkSize;
2626
extern string gMyHostName;
2727

28+
extern bool isChassisDbInUse();
29+
2830
const int neighorch_pri = 30;
2931

3032
NeighOrch::NeighOrch(DBConnector *appDb, string tableName, IntfsOrch *intfsOrch, FdbOrch *fdbOrch, PortsOrch *portsOrch, DBConnector *chassisAppDb) :
@@ -46,7 +48,7 @@ NeighOrch::NeighOrch(DBConnector *appDb, string tableName, IntfsOrch *intfsOrch,
4648
gBfdOrch->attach(this);
4749
}
4850

49-
if(gMySwitchType == "voq")
51+
if(isChassisDbInUse())
5052
{
5153
//Add subscriber to process VOQ system neigh
5254
tableName = CHASSIS_APP_SYSTEM_NEIGH_TABLE_NAME;
@@ -1230,7 +1232,7 @@ bool NeighOrch::addNeighbor(NeighborContext& ctx)
12301232
NeighborUpdate update = { neighborEntry, macAddress, true };
12311233
notify(SUBJECT_TYPE_NEIGH_CHANGE, static_cast<void *>(&update));
12321234

1233-
if(gMySwitchType == "voq")
1235+
if(isChassisDbInUse())
12341236
{
12351237
//Sync the neighbor to add to the CHASSIS_APP_DB
12361238
voqSyncAddNeigh(alias, ip_address, macAddress, neighbor_entry);
@@ -1379,7 +1381,7 @@ bool NeighOrch::removeNeighbor(NeighborContext& ctx, bool disable)
13791381
NeighborUpdate update = { neighborEntry, MacAddress(), false };
13801382
notify(SUBJECT_TYPE_NEIGH_CHANGE, static_cast<void *>(&update));
13811383

1382-
if(gMySwitchType == "voq")
1384+
if(isChassisDbInUse())
13831385
{
13841386
//Sync the neighbor to delete from the CHASSIS_APP_DB
13851387
voqSyncDelNeigh(alias, ip_address);

orchagent/p4orch/tests/test_main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ sai_object_id_t gUnderlayIfId = 0x101;
3838
string gMyAsicName = "";
3939
event_handle_t g_events_handle;
4040

41+
bool gMultiAsicVoq = false;
42+
bool isChassisDbInUse()
43+
{
44+
return gMultiAsicVoq;
45+
}
46+
4147
#define DEFAULT_BATCH_SIZE 128
4248
#define DEFAULT_MAX_BULK_SIZE 1000
4349
extern int gBatchSize;

orchagent/portsorch.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ extern int32_t gVoqMySwitchId;
6969
extern string gMyHostName;
7070
extern string gMyAsicName;
7171
extern event_handle_t g_events_handle;
72+
extern bool isChassisDbInUse();
73+
extern bool gMultiAsicVoq;
7274

7375
// defines ------------------------------------------------------------------------------------------------------------
7476

@@ -1002,7 +1004,7 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector<table_name_wi
10021004
Orch::addExecutor(portHostTxReadyNotificatier);
10031005
}
10041006

1005-
if (gMySwitchType == "voq")
1007+
if (isChassisDbInUse())
10061008
{
10071009
string tableName;
10081010
//Add subscriber to process system LAG (System PortChannel) table
@@ -5998,7 +6000,7 @@ void PortsOrch::doLagMemberTask(Consumer &consumer)
59986000
}
59996001
}
60006002

6001-
if ((gMySwitchType == "voq") && (port.m_type != Port::SYSTEM))
6003+
if (isChassisDbInUse() && (port.m_type != Port::SYSTEM))
60026004
{
60036005
//Sync to SYSTEM_LAG_MEMBER_TABLE of CHASSIS_APP_DB
60046006
voqSyncAddLagMember(lag, port, status);
@@ -7616,13 +7618,16 @@ bool PortsOrch::addLag(string lag_alias, uint32_t spa_id, int32_t switch_id)
76167618
switch_id = gVoqMySwitchId;
76177619
system_lag_alias = gMyHostName + "|" + gMyAsicName + "|" + lag_alias;
76187620

7619-
// Allocate unique lag id
7620-
spa_id = m_lagIdAllocator->lagIdAdd(system_lag_alias, 0);
7621-
7622-
if ((int32_t)spa_id <= 0)
7621+
if (gMultiAsicVoq)
76237622
{
7624-
SWSS_LOG_ERROR("Failed to allocate unique LAG id for local lag %s rv:%d", lag_alias.c_str(), spa_id);
7625-
return false;
7623+
// Allocate unique lag id
7624+
spa_id = m_lagIdAllocator->lagIdAdd(system_lag_alias, 0);
7625+
7626+
if ((int32_t)spa_id <= 0)
7627+
{
7628+
SWSS_LOG_ERROR("Failed to allocate unique LAG id for local lag %s rv:%d", lag_alias.c_str(), spa_id);
7629+
return false;
7630+
}
76267631
}
76277632
}
76287633

@@ -7734,7 +7739,7 @@ bool PortsOrch::removeLag(Port lag)
77347739

77357740
m_counterLagTable->hdel("", lag.m_alias);
77367741

7737-
if (gMySwitchType == "voq")
7742+
if (isChassisDbInUse())
77387743
{
77397744
// Free the lag id, if this is local LAG
77407745

@@ -7847,7 +7852,7 @@ bool PortsOrch::addLagMember(Port &lag, Port &port, string member_status)
78477852
LagMemberUpdate update = { lag, port, true };
78487853
notify(SUBJECT_TYPE_LAG_MEMBER_CHANGE, static_cast<void *>(&update));
78497854

7850-
if (gMySwitchType == "voq")
7855+
if (isChassisDbInUse())
78517856
{
78527857
//Sync to SYSTEM_LAG_MEMBER_TABLE of CHASSIS_APP_DB
78537858
voqSyncAddLagMember(lag, port, member_status);
@@ -7895,7 +7900,7 @@ bool PortsOrch::removeLagMember(Port &lag, Port &port)
78957900
LagMemberUpdate update = { lag, port, false };
78967901
notify(SUBJECT_TYPE_LAG_MEMBER_CHANGE, static_cast<void *>(&update));
78977902

7898-
if (gMySwitchType == "voq")
7903+
if (isChassisDbInUse())
78997904
{
79007905
//Sync to SYSTEM_LAG_MEMBER_TABLE of CHASSIS_APP_DB
79017906
voqSyncDelLagMember(lag, port);
@@ -9132,7 +9137,7 @@ void PortsOrch::updatePortOperStatus(Port &port, sai_port_oper_status_t status)
91329137
}
91339138
}
91349139

9135-
if(gMySwitchType == "voq")
9140+
if(isChassisDbInUse())
91369141
{
91379142
if (gIntfsOrch->isLocalSystemPortIntf(port.m_alias))
91389143
{
@@ -10279,7 +10284,8 @@ void PortsOrch::voqSyncAddLag (Port &lag)
1027910284

1028010285
// Sync only local lag add to CHASSIS_APP_DB
1028110286

10282-
if (switch_id != gVoqMySwitchId)
10287+
if (switch_id != gVoqMySwitchId ||
10288+
!gMultiAsicVoq)
1028310289
{
1028410290
return;
1028510291
}

tests/conftest.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
# Voq asics will have 16 fabric ports created (defined in Azure/sonic-buildimage#7629).
4545
FABRIC_NUM_PORTS = 16
4646

47+
SINGLE_ASIC_VOQ_FS = "single_asic_voq_fs"
48+
4749
def ensure_system(cmd):
4850
rc, output = subprocess.getstatusoutput(cmd)
4951
if rc:
@@ -112,6 +114,12 @@ def pytest_addoption(parser):
112114
default=False,
113115
help="Collect the test coverage information")
114116

117+
parser.addoption("--switch-mode",
118+
action="store",
119+
default=None,
120+
type=str,
121+
help="Set switch mode information")
122+
115123

116124
def random_string(size=4, chars=string.ascii_uppercase + string.digits):
117125
return "".join(random.choice(chars) for x in range(size))
@@ -293,7 +301,8 @@ def __init__(
293301
newctnname: str = None,
294302
ctnmounts: Dict[str, str] = None,
295303
buffer_model: str = None,
296-
enable_coverage: bool = False
304+
enable_coverage: bool = False,
305+
switch_mode: str = None
297306
):
298307
self.basicd = ["redis-server", "rsyslogd"]
299308
self.swssd = [
@@ -316,6 +325,7 @@ def __init__(
316325
self.vct = vct
317326
self.ctn = None
318327
self.enable_coverage = enable_coverage
328+
self.switch_mode = switch_mode
319329

320330
self.cleanup = not keeptb
321331

@@ -577,7 +587,10 @@ def check_swss_ready(self, timeout: int = 300) -> None:
577587
self.get_config_db()
578588
metadata = self.config_db.get_entry('DEVICE_METADATA|localhost', '')
579589
if metadata.get('switch_type', 'npu') in ['voq', 'fabric']:
580-
num_ports = NUM_PORTS + FABRIC_NUM_PORTS
590+
if self.switch_mode and self.switch_mode == SINGLE_ASIC_VOQ_FS:
591+
num_ports = NUM_PORTS
592+
else:
593+
num_ports = NUM_PORTS + FABRIC_NUM_PORTS
581594

582595
# Verify that all ports have been initialized and configured
583596
app_db = self.get_app_db()
@@ -597,8 +610,9 @@ def _polling_function():
597610

598611
# Verify that fabric ports are monitored in STATE_DB
599612
if metadata.get('switch_type', 'npu') in ['voq', 'fabric']:
600-
self.get_state_db()
601-
self.state_db.wait_for_n_keys("FABRIC_PORT_TABLE", FABRIC_NUM_PORTS)
613+
if not self.switch_mode or (self.switch_mode and self.switch_mode != SINGLE_ASIC_VOQ_FS):
614+
self.get_state_db()
615+
self.state_db.wait_for_n_keys("FABRIC_PORT_TABLE", FABRIC_NUM_PORTS)
602616

603617
def net_cleanup(self) -> None:
604618
"""Clean up network, remove extra links."""
@@ -1669,6 +1683,11 @@ def create_vct_ctn(self, ctndir):
16691683
vol = {}
16701684
vol[chassis_config_dir] = {"bind": "/usr/share/sonic/virtual_chassis", "mode": "ro"}
16711685

1686+
# Mount database_config.json when connect_to_chassis_db is set to 1
1687+
if defcfg.get("connect_to_chassis_db") == 1:
1688+
database_config_file = cwd + "/virtual_chassis/database_config.json"
1689+
vol[database_config_file] = {"bind": "/etc/sonic/database_config.json", "mode": "ro"}
1690+
16721691
# pass self.ns into the vs to be use for vs restarts by swss conftest.
16731692
# connection to chassbr is setup by chassis_connect.py within the vs
16741693
data = {}
@@ -1859,6 +1878,7 @@ def manage_dvs(request) -> str:
18591878
force_recreate = request.config.getoption("--force-recreate-dvs")
18601879
graceful_stop = request.config.getoption("--graceful-stop")
18611880
enable_coverage = request.config.getoption("--enable-coverage")
1881+
switch_mode = request.config.getoption("--switch-mode")
18621882

18631883
dvs = None
18641884
curr_dvs_env = [] # lgtm[py/unused-local-variable]
@@ -1890,7 +1910,13 @@ def update_dvs(log_path, new_dvs_env=[]):
18901910
dvs.get_logs()
18911911
dvs.destroy()
18921912

1893-
dvs = DockerVirtualSwitch(name, imgname, keeptb, new_dvs_env, log_path, max_cpu, forcedvs, buffer_model = buffer_model, enable_coverage=enable_coverage)
1913+
vol = {}
1914+
if switch_mode and switch_mode == SINGLE_ASIC_VOQ_FS:
1915+
cwd = os.getcwd()
1916+
voq_configs = cwd + "/single_asic_voq_fs"
1917+
vol[voq_configs] = {"bind": "/usr/share/sonic/single_asic_voq_fs", "mode": "ro"}
1918+
1919+
dvs = DockerVirtualSwitch(name, imgname, keeptb, new_dvs_env, log_path, max_cpu, forcedvs, buffer_model = buffer_model, enable_coverage=enable_coverage, ctnmounts=vol, switch_mode=switch_mode)
18941920

18951921
curr_dvs_env = new_dvs_env
18961922

0 commit comments

Comments
 (0)