Commit 71c070b1 authored by Micha Mueller's avatar Micha Mueller
Browse files

WIP2: Add plugin for Omni-path

parent a4351bc0
......@@ -17,7 +17,7 @@ CXXFLAGS = -std=c++11 -DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG -DBOOST_NETWORK_EN
LIBS = -L../deps/mosquitto_build/lib -L$(DCDBDEPLOYPATH)/lib/ -ldl -lmosquitto -lboost_system -lboost_thread -lboost_log_setup -lboost_log -lpthread -lcrypto -lssl -lcppnetlib-server-parsers -lcppnetlib-uri -rdynamic
OBJS = src/dcdbpusher.o src/Configuration.o src/MQTTPusher.o src/HttpsServer.o
PLUGINS_BASE = libdcdbplugin_pdu libdcdbplugin_sysfs libdcdbplugin_ipmi libdcdbplugin_bacnet libdcdbplugin_snmp
PLUGINS_BASE = libdcdbplugin_pdu libdcdbplugin_sysfs libdcdbplugin_ipmi libdcdbplugin_bacnet libdcdbplugin_snmp libdcdbplugin_opa
ifeq ($(OS),Darwin)
BACNET_PORT = bsd
......@@ -89,3 +89,6 @@ libdcdbplugin_bacnet.$(LIBEXT): src/sensors/bacnet/BACnetSingleSensor.o src/sens
libdcdbplugin_snmp.$(LIBEXT): src/sensors/snmp/SNMPSingleSensor.o src/sensors/snmp/SNMPConnection.o src/sensors/snmp/SNMPConfigurator.o
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system -lnetsnmp -lnetsnmpagent
libdcdbplugin_opa.$(LIBEXT): src/sensors/opa/OpaSingleSensor.o src/sensors/opa/OpaConfigurator.o src/sensors/opa/OpaSensorGroup.o
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system -lopamgt -libverbs -libumad -lssl
;comments in config files are indicated by a semicolon
global {
mqttPrefix /FF112233445566778899AABBFFFF
;add here other global attributes for your plugin
}
sensorTemplates {
;define here template sensors
sensor temp1 {
interval 1000
minValues 3
pluginAtt 1234
cntData portXmitData
}
}
sensors {
;define here the actual singleSensors for your plugin
sensor sens1 {
sensor XmitDat1 {
default temp1
hfiNum 1
portNum 1
mqttsuffix 0001
;add other attributes your plugin requires for a sensor
}
sensor XmitDat2 {
default temp1
mqttsuffix 0002
hfiNum 1
portNum 2
}
}
groups {
;define here the sensor groups for your plugin
group g1 {
;specify group attributes here
group p1 {
interval 1000
mqttprefix 01
hfiNum 1
portNum 1
sensor rcvDat {
default temp1
mqttsuffix 00
cntData portRcvData
}
sensor rcvPkt {
mqttsuffix 00
cntData portRcvPkts
}
;define sensors belonging to the group below
sensor gSens {
sensor linkDown {
mqttsuffix 00
cntData linkDowned
}
}
}
......@@ -40,7 +40,7 @@ bool ${PLUGIN_NAME}Configurator::derivedReadConfig(boost::property_tree::iptree&
}
}
//read remaining values
if(readSensorBase(*${PLUGIN_NAME_LWC}Sensor, sensor.second)) {
if(readSingleSensor(*${PLUGIN_NAME_LWC}Sensor, sensor.second)) {
_sensors.push_back(${PLUGIN_NAME_LWC}Sensor);
} else {
LOG(warning) << " Sensor \"" << sensor.second.data() << "\" has bad values! Ignoring...";
......@@ -59,7 +59,7 @@ cat << EOF >> ${PLUGIN_NAME}Configurator.cpp
if (STRCMP(group, "group")) {
LOG(debug) << "Group \"" << group.second.data() << "\"";
if (!group.second.empty()) {
${PLUGIN_NAME}SensorGroup ${PLUGIN_NAME_LWC}Group = new ${PLUGIN_NAME}SensorGroup(group.second.data());
${PLUGIN_NAME}SensorGroup* ${PLUGIN_NAME_LWC}Group = new ${PLUGIN_NAME}SensorGroup(group.second.data());
/*
* TODO
......@@ -74,7 +74,7 @@ cat << EOF >> ${PLUGIN_NAME}Configurator.cpp
}
//read remaining values
if (!readSensorInterface(${PLUGIN_NAME_LWC}Group, group.second)) {
if (!readSensorInterface(*${PLUGIN_NAME_LWC}Group, group.second)) {
LOG(warning) << " SensorGroup \"" << group.second.data() << "\" has bad values!";
}
......
......@@ -88,7 +88,7 @@ void ${PLUGIN_NAME}SensorGroup::read() {
#endif
}
} catch (const std::exception& e) {
LOG(error) << "Sensorgroup" << _groupName << " could not read value";
LOG(error) << "Sensorgroup" << _groupName << " could not read value: " << e.what();
return;
}
......
......@@ -7,16 +7,40 @@
#include "OpaConfigurator.h"
OpaConfigurator::OpaConfigurator() {}
OpaConfigurator::OpaConfigurator() {
//set up enum-map to map string from cfgFile to an enum value defined in OpaSensorBase.h
_enumCntData["portXmitData"] = portXmitData;
_enumCntData["portRcvData"] = portRcvData;
_enumCntData["portXmitPkts"] = portXmitPkts;
_enumCntData["portRcvPkts"] = portRcvPkts;
_enumCntData["portMulticastXmitPkts"] = portMulticastXmitPkts;
_enumCntData["portMulticastRcvPkts"] = portMulticastRcvPkts;
_enumCntData["localLinkIntegrityErrors"]= localLinkIntegrityErrors;
_enumCntData["fmConfigErrors"] = fmConfigErrors;
_enumCntData["portRcvErrors"] = portRcvErrors;
_enumCntData["excessiveBufferOverruns"] = excessiveBufferOverruns;
_enumCntData["portRcvConstraintErrors"] = portRcvConstraintErrors;
_enumCntData["portRcvSwitchRelayErrors"]= portRcvSwitchRelayErrors;
_enumCntData["portXmitDiscards"] = portXmitDiscards;
_enumCntData["portXmitConstraintErrors"]= portXmitConstraintErrors;
_enumCntData["portRcvRemotePhysicalErrors"] = portRcvRemotePhysicalErrors;
_enumCntData["swPortCongestion"] = swPortCongestion;
_enumCntData["portXmitWait"] = portXmitWait;
_enumCntData["portRcvFECN"] = portRcvFECN;
_enumCntData["portRcvBECN"] = portRcvBECN;
_enumCntData["portXmitTimeCong"] = portXmitTimeCong;
_enumCntData["portXmitWastedBW"] = portXmitWastedBW;
_enumCntData["portXmitWaitData"] = portXmitWaitData;
_enumCntData["portRcvBubble"] = portRcvBubble;
_enumCntData["portMarkFECN"] = portMarkFECN;
_enumCntData["linkErrorRecovery"] = linkErrorRecovery;
_enumCntData["linkDowned"] = linkDowned;
_enumCntData["uncorrectableErrors"] = uncorrectableErrors;
}
OpaConfigurator::~OpaConfigurator() {}
bool OpaConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
/*
* TODO
* If neccessary, read in other plugin specific stuff
*/
//read one sensor at a time
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensor, cfg.get_child("sensors")) {
if (STRCMP(sensor, "sensor")) {
......@@ -36,8 +60,25 @@ bool OpaConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
LOG(warning) << "Template sensor \"" << defaultS.get().data() << "\" not found! Using standard values.";
}
}
//check if hfiNum is given
boost::optional<boost::property_tree::iptree&> hfiNum = sensor.second.get_child_optional("hfiNum");
if (hfiNum) { //hfiNum given
opaSensor->setHfiNum(stoi(hfiNum.get().data()));
} else {
LOG(warning) << " Sensor \"" << sensor.second.data() << "\" has no hfiNum specified! Ignoring...";
continue;
}
//check if portNum is given
boost::optional<boost::property_tree::iptree&> portNum = sensor.second.get_child_optional("portNum");
if (portNum) { //portNum given
opaSensor->setPortNum(stoull(portNum.get().data()));
} else {
LOG(warning) << " Sensor \"" << sensor.second.data() << "\" has no portNum specified! Ignoring...";
continue;
}
//read remaining values
if(readSensorBase(*opaSensor, sensor.second)) {
if(readSingleSensor(*opaSensor, sensor.second)) {
_sensors.push_back(opaSensor);
} else {
LOG(warning) << " Sensor \"" << sensor.second.data() << "\" has bad values! Ignoring...";
......@@ -51,12 +92,24 @@ bool OpaConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
if (STRCMP(group, "group")) {
LOG(debug) << "Group \"" << group.second.data() << "\"";
if (!group.second.empty()) {
OpaSensorGroup opaGroup = new OpaSensorGroup(group.second.data());
OpaSensorGroup* opaGroup = new OpaSensorGroup(group.second.data());
/*
* TODO
* Read in other plugin specific group attributes
*/
//check if hfiNum is given
boost::optional<boost::property_tree::iptree&> hfiNum = group.second.get_child_optional("hfiNum");
if (hfiNum) { //hfiNum given
opaGroup->setHfiNum(stoi(hfiNum.get().data()));
} else {
LOG(warning) << " SensorGroup \"" << group.second.data() << "\" has no hfiNum specified! Ignoring...";
continue;
}
//check if portNum is given
boost::optional<boost::property_tree::iptree&> portNum = group.second.get_child_optional("portNum");
if (portNum) { //portNum given
opaGroup->setPortNum(stoull(portNum.get().data()));
} else {
LOG(warning) << " SensorGroup \"" << group.second.data() << "\" has no portNum specified! Ignoring...";
continue;
}
//read mqttPart if present
std::string mqttPart = "";
......@@ -66,7 +119,7 @@ bool OpaConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
}
//read remaining values
if (!readSensorInterface(opaGroup, group.second)) {
if (!readSensorInterface(*opaGroup, group.second)) {
LOG(warning) << " SensorGroup \"" << group.second.data() << "\" has bad values!";
}
......@@ -93,28 +146,18 @@ bool OpaConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
bool OpaConfigurator::derivedReadSensorBase(OpaSensorBase& sensor, boost::property_tree::iptree& config) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
/*
* TODO
* Read in plugin specific sensor attributes
*/
if (STRCMP(val, "mqttsuffix")) {
sensor.setMqtt(val.second.data());
/* Example code:
} else if (STRCMP(val, ("stringAttribute"))) {
sensor.setStringAttribute(val.second.data());
} else if (STRCMP(val, "intAttribute")) {
sensor.setIntAttribute(stoi(val.second.data())); */
} else if (STRCMP(val, "cntData")) {
enumMap_t::iterator it = _enumCntData.find(val.second.data());
if(it != _enumCntData.end()) {
sensor.setCounterData(it->second);
LOG(debug) << " cntData: " << val.second.data() << " (= " << sensor.getType() << ")";
} else {
LOG(warning) << " cntData \"" << val.second.data() << "\" not known.";
return false;
}
}
}
/*
* TODO
* Print the read in values for debugging
*/
/*
LOG(debug) << " stringAtt: " << sensor.getStringAttribute();
LOG(debug) << " intAtt : " << sensor.getIntAttribute();
*/
return true;
}
......@@ -15,6 +15,8 @@
class OpaConfigurator : public ConfiguratorTemplate<OpaSensorBase, OpaSingleSensor> {
typedef std::map<std::string, unsigned int> enumMap_t;
public:
OpaConfigurator();
virtual ~OpaConfigurator();
......@@ -24,6 +26,9 @@ protected:
void derivedReReadConfig() override { /* nothing to overwrite */ }
void derivedSetGlobalSettings(const pluginSettings_t& pluginSettings) override { /* nothing to overwrite */ }
bool derivedReadSensorBase(OpaSensorBase& sensor, boost::property_tree::iptree& config) override;
private:
enumMap_t _enumCntData;
};
extern "C" ConfiguratorInterface* create() {
......
......@@ -37,14 +37,14 @@ enum PORT_COUNTER_DATA {
portMarkFECN = 23,
linkErrorRecovery = 24,
linkDowned = 25,
uncorrectableErrors = 26,
uncorrectableErrors = 26
};
class OpaSensorBase : virtual public SensorBase {
public:
OpaSensorBase(const std::string& name) :
SensorBase(name),
_counterData(-1) {}
_counterData(999) {}
virtual ~OpaSensorBase() {}
......
......@@ -18,11 +18,6 @@ void OpaSensorGroup::init(boost::asio::io_service& io) {
_cacheSize = _cacheInterval / _interval + 1;
_timer.reset(new boost::asio::deadline_timer(io, boost::posix_time::seconds(0)));
/*
* TODO
* Init plugin specific stuff
*/
for (auto s : _sensors) {
s->initSensor(_cacheSize);
}
......@@ -35,10 +30,18 @@ void OpaSensorGroup::start() {
return;
}
/*
* TODO
* Start plugin specific stuff
*/
if (omgt_open_port_by_num(&_port, _hfiNum, _portNum, NULL) != OMGT_STATUS_SUCCESS) {
LOG(error) << "Sensorgroup " << _groupName << " failed to open port or initialize PA connection";
_port = nullptr;
return;
}
if (omgt_pa_get_image_info(_port, _imageID, &_imageInfo)) {
LOG(error) << "Sensorgroup " << _groupName << " failed to get PA image";
omgt_close_port(_port);
_port = nullptr;
return;
}
_keepRunning = 1;
_pendingTasks++;
......@@ -49,10 +52,10 @@ void OpaSensorGroup::start() {
void OpaSensorGroup::stop() {
_keepRunning = 0;
/*
* TODO
* Stop plugin specific stuff
*/
if (_port) {
omgt_close_port(_port);
_port = nullptr;
}
LOG(info) << "Sensorgroup " << _groupName << " stopped.";
}
......@@ -62,19 +65,105 @@ void OpaSensorGroup::read() {
reading.timestamp = getTimestamp();
try {
STL_PORT_COUNTERS_DATA portCounters;
if (omgt_pa_get_port_stats(_port, _imageID, 1, _portNum, &_imageID, &portCounters, NULL, 0, 1)) {
throw std::runtime_error("Failed to get port counters");
}
for(auto s : _sensors) {
reading.value = /*
* TODO
* Read a value for every sensor affiliated with this group and store
* it with the appropriate sensor.
*/ 0;
switch(s->getCounterData()) {
case(portXmitData) :
reading.value = portCounters.portXmitData;
break;
case(portRcvData) :
reading.value = portCounters.portRcvData;
break;
case(portXmitPkts) :
reading.value = portCounters.portXmitPkts;
break;
case(portRcvPkts) :
reading.value = portCounters.portRcvPkts;
break;
case(portMulticastXmitPkts) :
reading.value = portCounters.portMulticastXmitPkts;
break;
case(portMulticastRcvPkts) :
reading.value = portCounters.portMulticastRcvPkts;
break;
case(localLinkIntegrityErrors) :
reading.value = portCounters.localLinkIntegrityErrors;
break;
case(fmConfigErrors) :
reading.value = portCounters.fmConfigErrors;
break;
case(portRcvErrors) :
reading.value = portCounters.portRcvErrors;
break;
case(excessiveBufferOverruns) :
reading.value = portCounters.excessiveBufferOverruns;
break;
case(portRcvConstraintErrors) :
reading.value = portCounters.portRcvConstraintErrors;
break;
case(portRcvSwitchRelayErrors) :
reading.value = portCounters.portRcvSwitchRelayErrors;
break;
case(portXmitDiscards) :
reading.value = portCounters.portXmitDiscards;
break;
case(portXmitConstraintErrors) :
reading.value = portCounters.portXmitConstraintErrors;
break;
case(portRcvRemotePhysicalErrors) :
reading.value = portCounters.portRcvRemotePhysicalErrors;
break;
case(swPortCongestion) :
reading.value = portCounters.swPortCongestion;
break;
case(portXmitWait) :
reading.value = portCounters.portXmitWait;
break;
case(portRcvFECN) :
reading.value = portCounters.portRcvFECN;
break;
case(portRcvBECN) :
reading.value = portCounters.portRcvBECN;
break;
case(portXmitTimeCong) :
reading.value = portCounters.portXmitTimeCong;
break;
case(portXmitWastedBW) :
reading.value = portCounters.portXmitWastedBW;
break;
case(portXmitWaitData) :
reading.value = portCounters.portXmitWaitData;
break;
case(portRcvBubble) :
reading.value = portCounters.portRcvBubble;
break;
case(portMarkFECN) :
reading.value = portCounters.portMarkFECN;
break;
case(linkErrorRecovery) :
reading.value = portCounters.linkErrorRecovery;
break;
case(linkDowned) :
reading.value = portCounters.linkDowned;
break;
case(uncorrectableErrors) :
reading.value = portCounters.uncorrectableErrors;
break;
default:
throw std::runtime_error("Unknown counter data");
break;
}
s->storeReading(reading, _cacheIndex);
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << ": \"" << reading.value << "\"";
#endif
}
} catch (const std::exception& e) {
LOG(error) << "Sensorgroup" << _groupName << " could not read value";
LOG(error) << "Sensorgroup" << _groupName << " could not read value: " << e.what();
return;
}
......
Append to PLUGINS_BASE variable: libdcdbplugin_opa
Append at end of Makefile:
libdcdbplugin_opa.$(LIBEXT): src/sensors/opa/OpaSingleSensor.o src/sensors/opa/OpaConfigurator.o src/sensors/opa/OpaSensorGroup.o
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system
NOTE: Probably you will have to append further libraries to the linker for your plugin to compile
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment