From 4f1374bae6fe62eebe5705bc6b1883a14786d1de Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Wed, 22 Apr 2020 13:01:22 -0700 Subject: [PATCH 1/4] SAI 3.7 Supports multiple ASIC instances. This change is needed for orchagent to accept the instance ID which is fills in HARDWARE_INFO and passes to switch create. --- orchagent/main.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 2f32743997..6419c1fed3 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -13,6 +13,8 @@ extern "C" { #include #include #include +#include +#include #include #include "timestamp.h" @@ -114,15 +116,20 @@ int main(int argc, char **argv) int opt; sai_status_t status; + char *asic_inst_info = NULL; string record_location = "."; - while ((opt = getopt(argc, argv, "b:m:r:d:hs")) != -1) + while ((opt = getopt(argc, argv, "b:m:r:d:i:hs")) != -1) { switch (opt) { case 'b': gBatchSize = atoi(optarg); break; + case 'i': + asic_inst_info = (char *)calloc(strlen(optarg)+1, sizeof(char)); + memcpy(asic_inst_info, optarg, strlen(optarg)); + break; case 'm': gMacAddress = MacAddress(optarg); break; @@ -182,7 +189,6 @@ int main(int argc, char **argv) attr.id = SAI_SWITCH_ATTR_INIT_SWITCH; attr.value.booldata = true; attrs.push_back(attr); - attr.id = SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY; attr.value.ptr = (void *)on_fdb_event; attrs.push_back(attr); @@ -226,6 +232,10 @@ int main(int argc, char **argv) sai_switch_api->set_switch_attribute(gSwitchId, &attr); } + attr.id = SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO; + attr.value.s8list.count = (uint32_t)(strlen(asic_inst_info)+1); + attr.value.s8list.list = (int8_t*)asic_inst_info; + attrs.push_back(attr); status = sai_switch_api->create_switch(&gSwitchId, (uint32_t)attrs.size(), attrs.data()); if (status != SAI_STATUS_SUCCESS) @@ -233,7 +243,7 @@ int main(int argc, char **argv) SWSS_LOG_ERROR("Failed to create a switch, rv:%d", status); exit(EXIT_FAILURE); } - SWSS_LOG_NOTICE("Create a switch, id:%" PRIu64, gSwitchId); + SWSS_LOG_NOTICE("Create a switch ( SAI asic instance : %s ), id:%" PRIu64, asic_inst_info, gSwitchId); /* Get switch source MAC address if not provided */ if (!gMacAddress) From 873dac535b1d94aa49cc288cfaa920436d8a6e29 Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Wed, 22 Apr 2020 13:12:50 -0700 Subject: [PATCH 2/4] Update the usage help string with the new option [-i INST_ID] --- orchagent/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 6419c1fed3..118654f7ec 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -59,7 +59,7 @@ string gRecordFile; void usage() { - cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-b batch_size] [-m MAC] [-s]" << endl; + cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-b batch_size] [-m MAC] [-i INST_ID] [-s]" << endl; cout << " -h: display this message" << endl; cout << " -r record_type: record orchagent logs with type (default 3)" << endl; cout << " 0: do not record logs" << endl; @@ -69,6 +69,7 @@ void usage() cout << " -d record_location: set record logs folder location (default .)" << endl; cout << " -b batch_size: set consumer table pop operation batch size (default 128)" << endl; cout << " -m MAC: set switch MAC address" << endl; + cout << " -i INST_ID: set the ASIC instance ID in multi-asic platform" << endl; cout << " -s: enable synchronous mode" << endl; } From c7ca0d9e8afd892c9e1c1a0cc71ba4d602e8e096 Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Wed, 22 Apr 2020 14:52:54 -0700 Subject: [PATCH 3/4] Changed naming convention for variable and additional checks. --- orchagent/main.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 118654f7ec..96f4b35607 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -51,6 +51,7 @@ bool gSwssRecord = true; bool gLogRotate = false; bool gSaiRedisLogRotate = false; bool gSyncMode = false; +char *gAsicInstance = NULL; extern bool gIsNatSupported; @@ -117,7 +118,6 @@ int main(int argc, char **argv) int opt; sai_status_t status; - char *asic_inst_info = NULL; string record_location = "."; while ((opt = getopt(argc, argv, "b:m:r:d:i:hs")) != -1) @@ -128,8 +128,8 @@ int main(int argc, char **argv) gBatchSize = atoi(optarg); break; case 'i': - asic_inst_info = (char *)calloc(strlen(optarg)+1, sizeof(char)); - memcpy(asic_inst_info, optarg, strlen(optarg)); + gAsicInstance = (char *)calloc(strlen(optarg)+1, sizeof(char)); + memcpy(gAsicInstance, optarg, strlen(optarg)); break; case 'm': gMacAddress = MacAddress(optarg); @@ -233,10 +233,13 @@ int main(int argc, char **argv) sai_switch_api->set_switch_attribute(gSwitchId, &attr); } - attr.id = SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO; - attr.value.s8list.count = (uint32_t)(strlen(asic_inst_info)+1); - attr.value.s8list.list = (int8_t*)asic_inst_info; - attrs.push_back(attr); + if(gAsicInstance) + { + attr.id = SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO; + attr.value.s8list.count = (uint32_t)(strlen(gAsicInstance)+1); + attr.value.s8list.list = (int8_t*)gAsicInstance; + attrs.push_back(attr); + } status = sai_switch_api->create_switch(&gSwitchId, (uint32_t)attrs.size(), attrs.data()); if (status != SAI_STATUS_SUCCESS) @@ -244,7 +247,7 @@ int main(int argc, char **argv) SWSS_LOG_ERROR("Failed to create a switch, rv:%d", status); exit(EXIT_FAILURE); } - SWSS_LOG_NOTICE("Create a switch ( SAI asic instance : %s ), id:%" PRIu64, asic_inst_info, gSwitchId); + SWSS_LOG_NOTICE("Create a switch, id:%" PRIu64, gSwitchId); /* Get switch source MAC address if not provided */ if (!gMacAddress) From c926fb5d0253b788d3c276d4fb490db1d00e940e Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Wed, 22 Apr 2020 21:35:56 -0700 Subject: [PATCH 4/4] Updated for comments --- orchagent/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 96f4b35607..ce87a3802c 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -70,7 +70,7 @@ void usage() cout << " -d record_location: set record logs folder location (default .)" << endl; cout << " -b batch_size: set consumer table pop operation batch size (default 128)" << endl; cout << " -m MAC: set switch MAC address" << endl; - cout << " -i INST_ID: set the ASIC instance ID in multi-asic platform" << endl; + cout << " -i INST_ID: set the ASIC instance_id in multi-asic platform" << endl; cout << " -s: enable synchronous mode" << endl; } @@ -233,7 +233,7 @@ int main(int argc, char **argv) sai_switch_api->set_switch_attribute(gSwitchId, &attr); } - if(gAsicInstance) + if (gAsicInstance) { attr.id = SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO; attr.value.s8list.count = (uint32_t)(strlen(gAsicInstance)+1);