Skip to content

Commit ba29ae9

Browse files
lakshmi-nexthopsaravanan-nexthop
authored andcommitted
Orchagent changes needed to support single ASIC VOQ Fixed-System (sonic-net#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 b88a5c2 commit ba29ae9

11 files changed

Lines changed: 492 additions & 28 deletions

File tree

.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

@@ -1006,7 +1008,7 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector<table_name_wi
10061008
Orch::addExecutor(portHostTxReadyNotificatier);
10071009
}
10081010

1009-
if (gMySwitchType == "voq")
1011+
if (isChassisDbInUse())
10101012
{
10111013
string tableName;
10121014
//Add subscriber to process system LAG (System PortChannel) table
@@ -6040,7 +6042,7 @@ void PortsOrch::doLagMemberTask(Consumer &consumer)
60406042
}
60416043
}
60426044

6043-
if ((gMySwitchType == "voq") && (port.m_type != Port::SYSTEM))
6045+
if (isChassisDbInUse() && (port.m_type != Port::SYSTEM))
60446046
{
60456047
//Sync to SYSTEM_LAG_MEMBER_TABLE of CHASSIS_APP_DB
60466048
voqSyncAddLagMember(lag, port, status);
@@ -7658,13 +7660,16 @@ bool PortsOrch::addLag(string lag_alias, uint32_t spa_id, int32_t switch_id)
76587660
switch_id = gVoqMySwitchId;
76597661
system_lag_alias = gMyHostName + "|" + gMyAsicName + "|" + lag_alias;
76607662

7661-
// Allocate unique lag id
7662-
spa_id = m_lagIdAllocator->lagIdAdd(system_lag_alias, 0);
7663-
7664-
if ((int32_t)spa_id <= 0)
7663+
if (gMultiAsicVoq)
76657664
{
7666-
SWSS_LOG_ERROR("Failed to allocate unique LAG id for local lag %s rv:%d", lag_alias.c_str(), spa_id);
7667-
return false;
7665+
// Allocate unique lag id
7666+
spa_id = m_lagIdAllocator->lagIdAdd(system_lag_alias, 0);
7667+
7668+
if ((int32_t)spa_id <= 0)
7669+
{
7670+
SWSS_LOG_ERROR("Failed to allocate unique LAG id for local lag %s rv:%d", lag_alias.c_str(), spa_id);
7671+
return false;
7672+
}
76687673
}
76697674
}
76707675

@@ -7776,7 +7781,7 @@ bool PortsOrch::removeLag(Port lag)
77767781

77777782
m_counterLagTable->hdel("", lag.m_alias);
77787783

7779-
if (gMySwitchType == "voq")
7784+
if (isChassisDbInUse())
77807785
{
77817786
// Free the lag id, if this is local LAG
77827787

@@ -7889,7 +7894,7 @@ bool PortsOrch::addLagMember(Port &lag, Port &port, string member_status)
78897894
LagMemberUpdate update = { lag, port, true };
78907895
notify(SUBJECT_TYPE_LAG_MEMBER_CHANGE, static_cast<void *>(&update));
78917896

7892-
if (gMySwitchType == "voq")
7897+
if (isChassisDbInUse())
78937898
{
78947899
//Sync to SYSTEM_LAG_MEMBER_TABLE of CHASSIS_APP_DB
78957900
voqSyncAddLagMember(lag, port, member_status);
@@ -7937,7 +7942,7 @@ bool PortsOrch::removeLagMember(Port &lag, Port &port)
79377942
LagMemberUpdate update = { lag, port, false };
79387943
notify(SUBJECT_TYPE_LAG_MEMBER_CHANGE, static_cast<void *>(&update));
79397944

7940-
if (gMySwitchType == "voq")
7945+
if (isChassisDbInUse())
79417946
{
79427947
//Sync to SYSTEM_LAG_MEMBER_TABLE of CHASSIS_APP_DB
79437948
voqSyncDelLagMember(lag, port);
@@ -9174,7 +9179,7 @@ void PortsOrch::updatePortOperStatus(Port &port, sai_port_oper_status_t status)
91749179
}
91759180
}
91769181

9177-
if(gMySwitchType == "voq")
9182+
if(isChassisDbInUse())
91789183
{
91799184
if (gIntfsOrch->isLocalSystemPortIntf(port.m_alias))
91809185
{
@@ -10398,7 +10403,8 @@ void PortsOrch::voqSyncAddLag (Port &lag)
1039810403

1039910404
// Sync only local lag add to CHASSIS_APP_DB
1040010405

10401-
if (switch_id != gVoqMySwitchId)
10406+
if (switch_id != gVoqMySwitchId ||
10407+
!gMultiAsicVoq)
1040210408
{
1040310409
return;
1040410410
}

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))
@@ -294,7 +302,8 @@ def __init__(
294302
newctnname: str = None,
295303
ctnmounts: Dict[str, str] = None,
296304
buffer_model: str = None,
297-
enable_coverage: bool = False
305+
enable_coverage: bool = False,
306+
switch_mode: str = None
298307
):
299308
self.basicd = ["redis-server", "rsyslogd"]
300309
self.swssd = [
@@ -317,6 +326,7 @@ def __init__(
317326
self.vct = vct
318327
self.ctn = None
319328
self.enable_coverage = enable_coverage
329+
self.switch_mode = switch_mode
320330

321331
self.cleanup = not keeptb
322332

@@ -583,7 +593,10 @@ def check_swss_ready(self, timeout: int = 300) -> None:
583593
self.get_config_db()
584594
metadata = self.config_db.get_entry('DEVICE_METADATA|localhost', '')
585595
if metadata.get('switch_type', 'npu') in ['voq', 'fabric']:
586-
num_ports = NUM_PORTS + FABRIC_NUM_PORTS
596+
if self.switch_mode and self.switch_mode == SINGLE_ASIC_VOQ_FS:
597+
num_ports = NUM_PORTS
598+
else:
599+
num_ports = NUM_PORTS + FABRIC_NUM_PORTS
587600

588601
# Verify that all ports have been initialized and configured
589602
app_db = self.get_app_db()
@@ -603,8 +616,9 @@ def _polling_function():
603616

604617
# Verify that fabric ports are monitored in STATE_DB
605618
if metadata.get('switch_type', 'npu') in ['voq', 'fabric']:
606-
self.get_state_db()
607-
self.state_db.wait_for_n_keys("FABRIC_PORT_TABLE", FABRIC_NUM_PORTS)
619+
if not self.switch_mode or (self.switch_mode and self.switch_mode != SINGLE_ASIC_VOQ_FS):
620+
self.get_state_db()
621+
self.state_db.wait_for_n_keys("FABRIC_PORT_TABLE", FABRIC_NUM_PORTS)
608622

609623
def net_cleanup(self) -> None:
610624
"""Clean up network, remove extra links."""
@@ -1690,6 +1704,11 @@ def create_vct_ctn(self, ctndir):
16901704
vol = {}
16911705
vol[chassis_config_dir] = {"bind": "/usr/share/sonic/virtual_chassis", "mode": "ro"}
16921706

1707+
# Mount database_config.json when connect_to_chassis_db is set to 1
1708+
if defcfg.get("connect_to_chassis_db") == 1:
1709+
database_config_file = cwd + "/virtual_chassis/database_config.json"
1710+
vol[database_config_file] = {"bind": "/etc/sonic/database_config.json", "mode": "ro"}
1711+
16931712
# pass self.ns into the vs to be use for vs restarts by swss conftest.
16941713
# connection to chassbr is setup by chassis_connect.py within the vs
16951714
data = {}
@@ -1880,6 +1899,7 @@ def manage_dvs(request) -> str:
18801899
force_recreate = request.config.getoption("--force-recreate-dvs")
18811900
graceful_stop = request.config.getoption("--graceful-stop")
18821901
enable_coverage = request.config.getoption("--enable-coverage")
1902+
switch_mode = request.config.getoption("--switch-mode")
18831903

18841904
dvs = None
18851905
curr_dvs_env = [] # lgtm[py/unused-local-variable]
@@ -1911,7 +1931,13 @@ def update_dvs(log_path, new_dvs_env=[]):
19111931
dvs.get_logs()
19121932
dvs.destroy()
19131933

1914-
dvs = DockerVirtualSwitch(name, imgname, keeptb, new_dvs_env, log_path, max_cpu, forcedvs, buffer_model = buffer_model, enable_coverage=enable_coverage)
1934+
vol = {}
1935+
if switch_mode and switch_mode == SINGLE_ASIC_VOQ_FS:
1936+
cwd = os.getcwd()
1937+
voq_configs = cwd + "/single_asic_voq_fs"
1938+
vol[voq_configs] = {"bind": "/usr/share/sonic/single_asic_voq_fs", "mode": "ro"}
1939+
1940+
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)
19151941

19161942
curr_dvs_env = new_dvs_env
19171943

0 commit comments

Comments
 (0)