IPMIHost.h 3.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*
 * IPMIConnection.h
 *
 *  Created on: 18 Jan 2017
 *      Author: ottmi
 */

#ifndef IPMIHOST_H_
#define IPMIHOST_H_

11
#include "../../Logging.h"
12

13
14
15
#include <string>
#include <list>
#include <freeipmi/freeipmi.h>
16
#include <boost/asio.hpp>
17
18
19

namespace DCDB {

20
21
22
23
24
25
26
27
	class IPMIHost {
	public:
		IPMIHost(const std::string& hostName, uint32_t retransmissionTimeout, uint32_t sessionTimeout);
		virtual ~IPMIHost();

		/* Send raw command to BMC. Returns sensor reading as responded by BMC. */
		uint64_t sendRawCmd(const std::vector<uint8_t>& rawCmd, uint16_t start, uint16_t stop);
		/* Read the sensor specified by its record id. Returns sensor reading. */
28
		double readSensor_recordId(uint16_t recordId);
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

		void increaseErrorCount();
		const uint64_t getDelayFactor() const;

		uint8_t getAuth() const {
			return _auth;
		}

		void setAuth(uint8_t auth) {
			_auth = auth;
		}

		const std::string& getHostName() const {
			return _hostName;
		}

		void setHostName(const std::string& hostName) {
			_hostName = hostName;
		}

		const std::string& getPassword() const {
			return _password;
		}

		void setPassword(const std::string& password) {
			_password = password;
		}

57
58
59
60
61
62
63
64
		const std::string& getCache() const {
			return _cache;
		}

		void setCache(const std::string& cacheDir) {
			_cache = cacheDir + ".ipmiPluginSdrCache." + _hostName;
		}

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
		uint8_t getPriv() const {
			return _priv;
		}

		void setPriv(uint8_t priv) {
			_priv = priv;
		}

		const std::string& getUserName() const {
		return _userName;
		}

		void setUserName(const std::string& userName) {
			_userName = userName;
		}

		const std::string& getMqttPrefix() const {
			return _mqttPrefix;
		}

		void setMqttPrefix(const std::string& mqttPrefix) {
			_mqttPrefix = mqttPrefix;
			if (_mqttPrefix.front() != '/') {
				_mqttPrefix.insert(0, "/");
			}
			if (_mqttPrefix.back() == '/') {
				_mqttPrefix.erase(_mqttPrefix.size()-1);
			}
		}

		void initalizeStrand(boost::asio::io_service& io);

		boost::asio::io_service::strand* getStrand() const {
			return _strand;
		}

		uint64_t getDelayNextReadUntil() const {
			return _delayNextReadUntil;
		}

		void setDelayNextReadUntil(uint64_t delayNextReadUntil) {
			_delayNextReadUntil = delayNextReadUntil;
		}

	private:
		/* Open/close connection to BMC (sets/destroys _ipmiCtx) */
		int connect();
		int disconnect();

		/* Open and create/destroy SDR cache (sets/destroys _sdrCtx and _sensorReadCtx) */
		void createSdrCache();
		void destroySdrCache();

		/* Various context structs, required to make use of FreeIPMI */
		ipmi_ctx_t		_ipmiCtx;
		ipmi_sdr_ctx_t	_sdrCtx;
		ipmi_sensor_read_ctx_t	_sensorReadCtx;

		std::string	_hostName;
		std::string	_userName;
		std::string	_password;
126
		std::string	_cache;
127
128
129
130
131
132
		uint8_t		_auth;
		uint8_t		_priv;
		std::string	_mqttPrefix;
		uint32_t	_sessionTimeout;
		uint32_t	_retransmissionTimeout;
		boost::asio::io_service::strand*	_strand;
133
		boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
134
135
136
		uint32_t	_errorCount;
		volatile uint64_t	_delayNextReadUntil;
	};
137
138
139
140

} /* namespace DCDB */

#endif /* IPMIHOST_H_ */