Skip to content

Commit

Permalink
Fixing indents
Browse files Browse the repository at this point in the history
  • Loading branch information
PINS Working Group authored and donNewtonAlpha committed Nov 19, 2021
1 parent be3c4d8 commit 789f9e7
Show file tree
Hide file tree
Showing 4 changed files with 685 additions and 624 deletions.
181 changes: 91 additions & 90 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
extern "C" {
extern "C"
{
#include "sai.h"
#include "saistatus.h"
}

#include <chrono>
#include <fstream>
#include <getopt.h>
#include <inttypes.h>
#include <iostream>
#include <unordered_map>
#include <map>
#include <memory>
#include <thread>
#include <chrono>
#include <getopt.h>
#include <unistd.h>
#include <inttypes.h>
#include <sstream>
#include <stdexcept>
#include <stdlib.h>
#include <string.h>
#include <thread>
#include <unistd.h>
#include <unordered_map>

#include <sys/time.h>
#include "timestamp.h"
#include <sys/time.h>

#include <sairedis.h>
#include <logger.h>
#include <sairedis.h>

#include "gearboxutils.h"
#include "notifications.h"
#include "orchdaemon.h"
#include "sai_serialize.h"
#include "saihelper.h"
#include "notifications.h"
#include <signal.h>
#include "warm_restart.h"
#include "gearboxutils.h"
#include <signal.h>

using namespace std;
using namespace swss;

extern sai_switch_api_t *sai_switch_api;
extern sai_router_interface_api_t *sai_router_intfs_api;

#define UNREFERENCED_PARAMETER(P) (P)
#define UNREFERENCED_PARAMETER(P) (P)

#define UNDERLAY_RIF_DEFAULT_MTU 9100

Expand All @@ -51,7 +52,7 @@ MacAddress gVxlanMacAddress;

extern size_t gMaxBulkSize;

#define DEFAULT_BATCH_SIZE 128
#define DEFAULT_BATCH_SIZE 128
int gBatchSize = DEFAULT_BATCH_SIZE;

bool gSairedisRecord = true;
Expand Down Expand Up @@ -84,10 +85,13 @@ string gMyAsicName = "";

void usage()
{
cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-f swss_rec_filename] [-j sairedis_rec_filename] [-b batch_size] [-m MAC] [-i INST_ID] [-s] [-z mode] [-k bulk_size]" << endl;
cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-f swss_rec_filename] [-j "
"sairedis_rec_filename] [-b batch_size] [-m MAC] [-i INST_ID] [-s] [-z mode] [-k bulk_size]"
<< endl;
cout << " -h: display this message" << endl;
cout << " -r record_type: record orchagent logs with type (default 7)" << endl;
cout << " Bit 0: sairedis.rec, Bit 1: swss.rec, Bit 2: responsepublisher.rec. For example:" << endl;
cout << " Bit 0: sairedis.rec, Bit 1: swss.rec, Bit 2: responsepublisher.rec. For example:"
<< endl;
cout << " 0: do not record logs" << endl;
cout << " 1: record SAI call sequence as sairedis.rec" << endl;
cout << " 2: record SwSS task sequence as swss.rec" << endl;
Expand Down Expand Up @@ -136,17 +140,17 @@ void syncd_apply_view()
* Create and initialize the external Gearbox PHYs. Upon success, store the
* new PHY OID in the database to be used later when creating the Gearbox
* ports.
*/
*/
void init_gearbox_phys(DBConnector *applDb)
{
Table* tmpGearboxTable = new Table(applDb, "_GEARBOX_TABLE");
Table *tmpGearboxTable = new Table(applDb, "_GEARBOX_TABLE");
map<int, gearbox_phy_t> gearboxPhyMap;
GearboxUtils gearbox;

if (gearbox.isGearboxEnabled(tmpGearboxTable))
{
gearboxPhyMap = gearbox.loadPhyMap(tmpGearboxTable);
SWSS_LOG_DEBUG("BOX: gearboxPhyMap size = %d.", (int) gearboxPhyMap.size());
SWSS_LOG_DEBUG("BOX: gearboxPhyMap size = %d.", (int)gearboxPhyMap.size());

for (auto it = gearboxPhyMap.begin(); it != gearboxPhyMap.end(); ++it)
{
Expand All @@ -158,9 +162,11 @@ void init_gearbox_phys(DBConnector *applDb)
}
else
{
SWSS_LOG_NOTICE("BOX: Created new PHY phy_id:%d phy_oid:%s.", it->second.phy_id, it->second.phy_oid.c_str());
tmpGearboxTable->hset("phy:"+to_string(it->second.phy_id), "phy_oid", it->second.phy_oid.c_str());
tmpGearboxTable->hset("phy:"+to_string(it->second.phy_id), "firmware_major_version", it->second.firmware_major_version.c_str());
SWSS_LOG_NOTICE("BOX: Created new PHY phy_id:%d phy_oid:%s.", it->second.phy_id,
it->second.phy_oid.c_str());
tmpGearboxTable->hset("phy:" + to_string(it->second.phy_id), "phy_oid", it->second.phy_oid.c_str());
tmpGearboxTable->hset("phy:" + to_string(it->second.phy_id), "firmware_major_version",
it->second.firmware_major_version.c_str());
}
}
}
Expand All @@ -173,14 +179,14 @@ void getCfgSwitchType(DBConnector *cfgDb, string &switch_type)

if (!cfgDeviceMetaDataTable.hget("localhost", "switch_type", switch_type))
{
//Switch type is not configured. Consider it default = "switch" (regular switch)
// Switch type is not configured. Consider it default = "switch" (regular switch)
switch_type = "switch";
}

if (switch_type != "voq" && switch_type != "fabric" && switch_type != "switch")
{
SWSS_LOG_ERROR("Invalid switch type %s configured", switch_type.c_str());
//If configured switch type is none of the supported, assume regular switch
// If configured switch type is none of the supported, assume regular switch
switch_type = "switch";
}
}
Expand All @@ -193,14 +199,14 @@ bool getSystemPortConfigList(DBConnector *cfgDb, DBConnector *appDb, vector<sai_

if (gMySwitchType != "voq")
{
//Non VOQ switch. Nothing to read
// Non VOQ switch. Nothing to read
return true;
}

string value;
if (!cfgDeviceMetaDataTable.hget("localhost", "switch_id", value))
{
//VOQ switch id is not configured.
// VOQ switch id is not configured.
SWSS_LOG_ERROR("VOQ switch id is not configured");
return false;
}
Expand All @@ -216,7 +222,7 @@ bool getSystemPortConfigList(DBConnector *cfgDb, DBConnector *appDb, vector<sai_

if (!cfgDeviceMetaDataTable.hget("localhost", "max_cores", value))
{
//VOQ max cores is not configured.
// VOQ max cores is not configured.
SWSS_LOG_ERROR("VOQ max cores is not configured");
return false;
}
Expand Down Expand Up @@ -261,7 +267,7 @@ bool getSystemPortConfigList(DBConnector *cfgDb, DBConnector *appDb, vector<sai_
vector<string> spKeys;
cfgSystemPortTable.getKeys(spKeys);

//Retrieve system port configurations
// Retrieve system port configurations
vector<FieldValueTuple> spFv;
sai_system_port_config_t sysport;
for (auto &k : spKeys)
Expand Down Expand Up @@ -301,14 +307,14 @@ bool getSystemPortConfigList(DBConnector *cfgDb, DBConnector *appDb, vector<sai_
continue;
}
}
//Add to system port config list
// Add to system port config list
sysportcfglist.push_back(sysport);

//Also push to APP DB
// Also push to APP DB
appSystemPortTable.set(k, spFv);
}

SWSS_LOG_NOTICE("Created System Port config list for %d system ports", (int32_t) sysportcfglist.size());
SWSS_LOG_NOTICE("Created System Port config list for %d system ports", (int32_t)sysportcfglist.size());

return true;
}
Expand All @@ -334,7 +340,7 @@ int main(int argc, char **argv)
string record_location = ".";
string swss_rec_filename = "swss.rec";
string sairedis_rec_filename = "sairedis.rec";
int record_type = 7; // All recordings enabled by default.
int record_type = 7; // All recordings enabled by default.

while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hsz:k:")) != -1)
{
Expand All @@ -343,30 +349,30 @@ int main(int argc, char **argv)
case 'b':
gBatchSize = atoi(optarg);
break;
case 'i':
case 'i': {
// Limit asic instance string max length
size_t len = strnlen(optarg, SAI_MAX_HARDWARE_ID_LEN);
// Check if input is longer and warn
if (len == SAI_MAX_HARDWARE_ID_LEN && optarg[len + 1] != '\0')
{
// Limit asic instance string max length
size_t len = strnlen(optarg, SAI_MAX_HARDWARE_ID_LEN);
// Check if input is longer and warn
if (len == SAI_MAX_HARDWARE_ID_LEN && optarg[len+1] != '\0')
{
SWSS_LOG_WARN("ASIC instance_id length > SAI_MAX_HARDWARE_ID_LEN, LIMITING !!");
}
// If longer, truncate into a string
gAsicInstance.assign(optarg, len);
SWSS_LOG_WARN("ASIC instance_id length > SAI_MAX_HARDWARE_ID_LEN, LIMITING !!");
}
break;
// If longer, truncate into a string
gAsicInstance.assign(optarg, len);
}
break;
case 'm':
gMacAddress = MacAddress(optarg);
break;
case 'r':
// Disable all recordings if atoi() fails i.e. returns 0 due to
// invalid command line argument.
record_type = atoi(optarg);
if (record_type < 0 || record_type > 7) {
usage();
exit(EXIT_FAILURE);
}
// Disable all recordings if atoi() fails i.e. returns 0 due to
// invalid command line argument.
record_type = atoi(optarg);
if (record_type < 0 || record_type > 7)
{
usage();
exit(EXIT_FAILURE);
}
break;
case 'd':
record_location = optarg;
Expand Down Expand Up @@ -399,20 +405,19 @@ int main(int argc, char **argv)
sairedis_rec_filename = optarg;
}
break;
case 'k':
case 'k': {
auto limit = atoi(optarg);
if (limit > 0)
{
auto limit = atoi(optarg);
if (limit > 0)
{
gMaxBulkSize = limit;
SWSS_LOG_NOTICE("Setting maximum bulk size in bulk mode as %zu", gMaxBulkSize);
}
else
{
SWSS_LOG_ERROR("Invalid input for maximum bulk size in bulk mode: %d. Ignoring.", limit);
}
gMaxBulkSize = limit;
SWSS_LOG_NOTICE("Setting maximum bulk size in bulk mode as %zu", gMaxBulkSize);
}
break;
else
{
SWSS_LOG_ERROR("Invalid input for maximum bulk size in bulk mode: %d. Ignoring.", limit);
}
}
break;
default: /* '?' */
exit(EXIT_FAILURE);
}
Expand All @@ -434,12 +439,9 @@ int main(int argc, char **argv)
attrs.push_back(attr);

// Initialize recording parameters.
gSairedisRecord =
(record_type & SAIREDIS_RECORD_ENABLE) == SAIREDIS_RECORD_ENABLE;
gSairedisRecord = (record_type & SAIREDIS_RECORD_ENABLE) == SAIREDIS_RECORD_ENABLE;
gSwssRecord = (record_type & SWSS_RECORD_ENABLE) == SWSS_RECORD_ENABLE;
gResponsePublisherRecord =
(record_type & RESPONSE_PUBLISHER_RECORD_ENABLE) ==
RESPONSE_PUBLISHER_RECORD_ENABLE;
gResponsePublisherRecord = (record_type & RESPONSE_PUBLISHER_RECORD_ENABLE) == RESPONSE_PUBLISHER_RECORD_ENABLE;

/* Disable/enable SwSS recording */
if (gSwssRecord)
Expand All @@ -455,19 +457,19 @@ int main(int argc, char **argv)
}

// Disable/Enable response publisher recording.
if (gResponsePublisherRecord) {
gResponsePublisherRecordFile =
record_location + "/" + "responsepublisher.rec";
gResponsePublisherRecordOfs.open(gResponsePublisherRecordFile,
std::ofstream::out | std::ofstream::app);
if (!gResponsePublisherRecordOfs.is_open()) {
SWSS_LOG_ERROR("Failed to open Response Publisher recording file %s",
gResponsePublisherRecordFile.c_str());
gResponsePublisherRecord = false;
} else {
gResponsePublisherRecordOfs << getTimestamp() << "|recording started"
<< endl;
}
if (gResponsePublisherRecord)
{
gResponsePublisherRecordFile = record_location + "/" + "responsepublisher.rec";
gResponsePublisherRecordOfs.open(gResponsePublisherRecordFile, std::ofstream::out | std::ofstream::app);
if (!gResponsePublisherRecordOfs.is_open())
{
SWSS_LOG_ERROR("Failed to open Response Publisher recording file %s", gResponsePublisherRecordFile.c_str());
gResponsePublisherRecord = false;
}
else
{
gResponsePublisherRecordOfs << getTimestamp() << "|recording started" << endl;
}
}

attr.id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY;
Expand Down Expand Up @@ -524,8 +526,7 @@ int main(int argc, char **argv)
// Get info required for VOQ system and connect to CHASSISS_APP_DB
shared_ptr<DBConnector> chassis_app_db;
vector<sai_system_port_config_t> sysportconfiglist;
if ((gMySwitchType == "voq") &&
(getSystemPortConfigList(&config_db, &appl_db, sysportconfiglist)))
if ((gMySwitchType == "voq") && (getSystemPortConfigList(&config_db, &appl_db, sysportconfiglist)))
{
attr.id = SAI_SWITCH_ATTR_TYPE;
attr.value.u32 = SAI_SWITCH_TYPE_VOQ;
Expand All @@ -539,7 +540,7 @@ int main(int argc, char **argv)
attr.value.u32 = gVoqMaxCores;
attrs.push_back(attr);

gCfgSystemPorts = (uint32_t) sysportconfiglist.size();
gCfgSystemPorts = (uint32_t)sysportconfiglist.size();
if (gCfgSystemPorts)
{
attr.id = SAI_SWITCH_ATTR_SYSTEM_PORT_CONFIG_LIST;
Expand All @@ -553,8 +554,8 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}

//Connect to CHASSIS_APP_DB in redis-server in control/supervisor card as per
//connection info in database_config.json
// Connect to CHASSIS_APP_DB in redis-server in control/supervisor card as per
// connection info in database_config.json
chassis_app_db = make_shared<DBConnector>("CHASSIS_APP_DB", 0, true);
}
else if (gMySwitchType == "fabric")
Expand All @@ -578,7 +579,6 @@ int main(int argc, char **argv)
}
SWSS_LOG_NOTICE("Create a switch, id:%" PRIu64, gSwitchId);


if (gMySwitchType != "fabric")
{
/* Get switch source MAC address if not provided */
Expand Down Expand Up @@ -642,7 +642,8 @@ int main(int argc, char **argv)
underlay_intf_attr.value.u32 = UNDERLAY_RIF_DEFAULT_MTU;
underlay_intf_attrs.push_back(underlay_intf_attr);

status = sai_router_intfs_api->create_router_interface(&gUnderlayIfId, gSwitchId, (uint32_t)underlay_intf_attrs.size(), underlay_intf_attrs.data());
status = sai_router_intfs_api->create_router_interface(
&gUnderlayIfId, gSwitchId, (uint32_t)underlay_intf_attrs.size(), underlay_intf_attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create underlay router interface %d", status);
Expand Down Expand Up @@ -677,9 +678,9 @@ int main(int argc, char **argv)
}

/*
* In syncd view comparison solution, apply view has been sent
* immediately after restore is done
*/
* In syncd view comparison solution, apply view has been sent
* immediately after restore is done
*/
if (!WarmStart::isWarmStart())
{
syncd_apply_view();
Expand Down
Loading

0 comments on commit 789f9e7

Please sign in to comment.