Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASIC temperature sensors support #694

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions orchagent/flexcounterorch.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <unordered_map>
#include "flexcounterorch.h"
#include "portsorch.h"
#include "switchorch.h"
#include "select.h"
#include "notifier.h"
#include "redisclient.h"
Expand All @@ -16,6 +17,7 @@ unordered_map<string, string> flexCounterGroupMap =
{"PORT", PORT_STAT_COUNTER_FLEX_COUNTER_GROUP},
{"QUEUE", QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP},
{"PFCWD", PFC_WD_FLEX_COUNTER_GROUP},
{"SENSORS", SWITCH_SENSORS_FLEX_GROUP},
};


Expand Down
60 changes: 60 additions & 0 deletions orchagent/switchorch.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include <map>
#include <tuple>

#include "switchorch.h"
#include "schema.h"
#include "converter.h"
#include "sai_serialize.h"
#include "notifier.h"
#include "notificationproducer.h"

Expand All @@ -28,19 +31,76 @@ const map<string, sai_packet_action_t> packet_action_map =
{"trap", SAI_PACKET_ACTION_TRAP}
};

#define SWITCH_SENSORS_FLEX_POLL_MSECS "15000"

static const vector<sai_switch_attr_t> SwitchSensorIds =
{
SAI_SWITCH_ATTR_MAX_TEMP,
SAI_SWITCH_ATTR_AVERAGE_TEMP,
SAI_SWITCH_ATTR_TEMP_LIST
};

SwitchOrch::SwitchOrch(DBConnector *db, string tableName) :
Orch(db, tableName),
m_db(db)
{
m_restartCheckNotificationConsumer = new NotificationConsumer(db, "RESTARTCHECK");
auto restartCheckNotifier = new Notifier(m_restartCheckNotificationConsumer, this, "RESTARTCHECK");
Orch::addExecutor(restartCheckNotifier);

m_flex_db = shared_ptr<DBConnector>(new DBConnector(FLEX_COUNTER_DB, DBConnector::DEFAULT_UNIXSOCKET, 0));
m_flexCounterTable = shared_ptr<ProducerTable>(new ProducerTable(m_flex_db.get(), FLEX_COUNTER_TABLE));
m_flexCounterGroupTable = shared_ptr<ProducerTable>(new ProducerTable(m_flex_db.get(), FLEX_COUNTER_GROUP_TABLE));
}

string SwitchOrch::getSwitchSensorsFlexCounterTableKey(string key)
{
return string(SWITCH_SENSORS_FLEX_GROUP) + ":" + key;
}

void SwitchOrch::addSwitchSensorsToFlexCounters()
{
SWSS_LOG_ENTER();

try
{
vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(POLL_INTERVAL_FIELD, SWITCH_SENSORS_FLEX_POLL_MSECS);
fieldValues.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
m_flexCounterGroupTable->set(SWITCH_SENSORS_FLEX_GROUP, fieldValues);
}

catch (...)
{
SWSS_LOG_WARN("SWITCH Sensors flex counter groups was not set");
}

/* Add switch to flex_counter for updating sensors */
const auto id = sai_serialize_object_id(gSwitchId);
string key = getSwitchSensorsFlexCounterTableKey(id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string key = SWITCH_SENSORS_FLEX_GROUP + id;
i think it would be clearer

std::string delimiter = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the std::

std::ostringstream counters_stream;
for (const auto &id: SwitchSensorIds)
{
counters_stream << delimiter << sai_serialize_switch_attr(id);
delimiter = ",";
}

vector<FieldValueTuple> fields;
fields.clear();
fields.emplace_back(SWITCH_SENSOR_ID_LIST, counters_stream.str());

m_flexCounterTable->set(key, fields);

SWSS_LOG_NOTICE("Added SWITCH Sensors to Flex Counters");
}

void SwitchOrch::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();

addSwitchSensorsToFlexCounters();

auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
Expand Down
9 changes: 9 additions & 0 deletions orchagent/switchorch.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#pragma once

#include "orch.h"
#include "producertable.h"

#define SWITCH_SENSORS_FLEX_GROUP "SWITCH_SENSORS"

struct WarmRestartCheck
{
Expand All @@ -22,11 +25,17 @@ class SwitchOrch : public Orch
bool setAgingFDB(uint32_t sec);
private:
void doTask(Consumer &consumer);
std::string getSwitchSensorsFlexCounterTableKey(std::string);
void addSwitchSensorsToFlexCounters();

NotificationConsumer* m_restartCheckNotificationConsumer;
void doTask(NotificationConsumer& consumer);
DBConnector *m_db;

shared_ptr<DBConnector> m_flex_db = nullptr;
shared_ptr<ProducerTable> m_flexCounterTable = nullptr;
shared_ptr<ProducerTable> m_flexCounterGroupTable = nullptr;

// Information contained in the request from
// external program for orchagent pre-shutdown state check
WarmRestartCheck m_warmRestartCheck = {false, false, false};
Expand Down