IPMIHost.h 4.33 KB
Newer Older
1
2
3
//================================================================================
// Name        : IPMIHost.h
// Author      : Michael Ott
Micha Müller's avatar
Micha Müller committed
4
// Contact     : info@dcdb.it
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright   : Leibniz Supercomputing Centre
// Description : Header file for IPMIHost class.
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2017-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//================================================================================
27
28
29
30

#ifndef IPMIHOST_H_
#define IPMIHOST_H_

31
32
#include "../../includes/EntityInterface.h"

33
34
35
36
#include <string>
#include <list>
#include <freeipmi/freeipmi.h>

37
38
39
40
41
/**
 * @brief Handles all connections to the same IPMI host.
 *
 * @ingroup ipmi
 */
42
class IPMIHost : public EntityInterface {
43
public:
44
45
	IPMIHost(const std::string& name = "");
	IPMIHost(const IPMIHost& other);
46
	virtual ~IPMIHost();
47
	IPMIHost& operator=(const IPMIHost& other);
48

49
50
	/* Translate recordId to SDR record */
	bool getSdrRecord(uint16_t recordId, std::vector<uint8_t>& record);
51
	/* Send raw command to BMC. Returns sensor reading as responded by BMC. */
52
	int sendRawCmd(const uint8_t* rawCmd, unsigned int rawCmdLen, void* buf, unsigned int bufLen);
53
	/* Read the sensor specified by its record id. Returns sensor reading. */
54
	double readSensorRecord(std::vector<uint8_t>& record);
55
56
57
58
59

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

	void setAuth(uint8_t auth)						{ _auth = auth; }
60
	void setHostName(const std::string& hostName)	{ _name = hostName; }
61
	void setPassword(const std::string& password)	{	_password = password; }
62
	void setCache(const std::string& cacheDir)		{ _cache = cacheDir + ".ipmiPluginSdrCache." + _name; }
63
	void setPriv(uint8_t priv)						{ _priv = priv; }
64
65
	void setCipher(const std::string& cipher)       	{ _cipher = stoi(cipher); }
	void setIpmiVersion(const std::string& ipmiVersion)	{ _ipmiVersion = stoi(ipmiVersion); }
66
67
68
69
70
71
	void setUserName(const std::string& userName)	{ _userName = userName; }
	void setSessionTimeout(uint32_t sessionTimeout) { _sessionTimeout = sessionTimeout; }
	void setRetransmissionTimeout(uint32_t retransmissionTimeout) { _retransmissionTimeout = retransmissionTimeout; }
	void setDelayNextReadUntil(uint64_t delayNextReadUntil) { _delayNextReadUntil = delayNextReadUntil; }

	uint8_t getAuth() 					const { return _auth; }
72
	const std::string& getHostName()	const { return _name; }
73
74
75
	const std::string& getPassword()	const { return _password; }
	const std::string& getCache()		const { return _cache; }
	uint8_t getPriv()					const { return _priv; }
76
77
	uint8_t getCipher()                     const { return _cipher; }
	uint8_t getIpmiVersion()		const { return _ipmiVersion; }
78
79
80
	const std::string& getUserName()	const { return _userName; }
	uint64_t getDelayNextReadUntil()	const { return _delayNextReadUntil; }

81
	void printEntityConfig(LOG_LEVEL ll) final override;
Micha Mueller's avatar
Micha Mueller committed
82

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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_sensor_read_ctx_t	_sensorReadCtx;

	std::string	_userName;
	std::string	_password;
	std::string	_cache;
	uint8_t		_auth;
	uint8_t		_priv;
101
102
	uint8_t		_cipher;
	uint8_t		_ipmiVersion;
103
104
105
	uint32_t	_sessionTimeout;
	uint32_t	_retransmissionTimeout;
	uint32_t	_errorCount;
106
	std::string _errorMsg;
107
108
	volatile uint64_t	_delayNextReadUntil;
};
109
110

#endif /* IPMIHOST_H_ */