blob: 29a7978714ce4796598920df1bdbae60e0b467ab [file] [log] [blame]
Matt Spinlercb6b0592019-07-16 15:58:51 -05001#pragma once
2
Matt Spinlerb8323632019-09-20 15:11:04 -05003#include "additional_data.hpp"
Matt Spinlercb6b0592019-07-16 15:58:51 -05004#include "private_header.hpp"
Matt Spinlerb8323632019-09-20 15:11:04 -05005#include "registry.hpp"
Matt Spinlercb6b0592019-07-16 15:58:51 -05006#include "user_header.hpp"
7
8#include <memory>
9#include <vector>
10
11namespace openpower
12{
13namespace pels
14{
15
16/** @class PEL
17 *
18 * @brief This class represents a specific event log format referred to as a
19 * Platform Event Log.
20 *
21 * Every field in a PEL are in structures call sections, of which there are
22 * several types. Some sections are required, and some are optional. In some
23 * cases there may be more than one instance of a section type.
24 *
25 * The only two required sections for every type of PEL are the Private Header
26 * section and User Header section, which must be in the first and second
27 * positions, respectively.
28 *
29 * Every section starts with an 8 byte section header, which has the section
30 * size and type, among other things.
31 *
32 * This class represents all sections with objects.
33 *
34 * The available constructors are:
35 * - PEL(const std::vector<uint8_t>& data) - build this object out of a fully
36 * formed flattened PEL.
37 *
Matt Spinlerb8323632019-09-20 15:11:04 -050038 * - PEL(const openpower::pels::message::Entry& entry,
39 * uint32_t obmcLogID,
40 * uint64_t timestamp,
41 * phosphor::logging::Entry::Level severity)
42 * - build this object from an OpenBMC event log.
43 *
Matt Spinlercb6b0592019-07-16 15:58:51 -050044 * The data() method allows one to retrieve the PEL as a vector<uint8_t>. This
45 * is the format in which it is stored and transmitted.
46 */
47class PEL
48{
49 public:
50 PEL() = delete;
51 ~PEL() = default;
52 PEL(const PEL&) = delete;
53 PEL& operator=(const PEL&) = delete;
54 PEL(PEL&&) = delete;
55 PEL& operator=(PEL&&) = delete;
56
57 /**
58 * @brief Constructor
59 *
60 * Build a PEL from raw data.
61 *
62 * @param[in] data - The PEL data
63 */
64 PEL(const std::vector<uint8_t>& data);
65
66 /**
67 * @brief Constructor
68 *
69 * Build a PEL from the raw data.
70 *
71 * @param[in] data - the PEL data
72 * @param[in] obmcLogID - the corresponding OpenBMC event log ID
73 */
74 PEL(const std::vector<uint8_t>& data, uint32_t obmcLogID);
75
76 /**
Matt Spinlerb8323632019-09-20 15:11:04 -050077 * @brief Constructor
78 *
79 * Creates a PEL from an OpenBMC event log and its message
80 * registry entry.
81 *
82 * @param[in] entry - The message registry entry for this error
83 * @param[in] obmcLogID - ID of corresponding OpenBMC event log
84 * @param[in] timestamp - Timestamp from the event log
85 * @param[in] severity - Severity from the event log
86 */
87 PEL(const openpower::pels::message::Entry& entry, uint32_t obmcLogID,
88 uint64_t timestamp, phosphor::logging::Entry::Level severity);
89
90 /**
Matt Spinlercb6b0592019-07-16 15:58:51 -050091 * @brief Convenience function to return the log ID field from the
92 * Private Header section.
93 *
94 * @return uint32_t - the ID
95 */
96 uint32_t id() const
97 {
98 return _ph->id();
99 }
100
101 /**
102 * @brief Convenience function to return the PLID field from the
103 * Private Header section.
104 *
105 * @return uint32_t - the PLID
106 */
107 uint32_t plid() const
108 {
109 return _ph->plid();
110 }
111
112 /**
113 * @brief Convenience function to return the OpenBMC event log ID field
114 * from the Private Header section.
115 *
116 * @return uint32_t - the OpenBMC event log ID
117 */
118 uint32_t obmcLogID() const
119 {
120 return _ph->obmcLogID();
121 }
122
123 /**
124 * @brief Convenience function to return the commit time field from
125 * the Private Header section.
126 *
127 * @return BCDTime - the timestamp
128 */
129 BCDTime commitTime() const
130 {
131 return _ph->commitTimestamp();
132 }
133
134 /**
135 * @brief Convenience function to return the create time field from
136 * the Private Header section.
137 *
138 * @return BCDTime - the timestamp
139 */
140 BCDTime createTime() const
141 {
142 return _ph->createTimestamp();
143 }
144
145 /**
146 * @brief Gives access to the Private Header section class
147 *
148 * @return std::unique_ptr<PrivateHeader>& the private header
149 */
150 std::unique_ptr<PrivateHeader>& privateHeader()
151 {
152 return _ph;
153 }
154
155 /**
156 * @brief Gives access to the User Header section class
157 *
158 * @return std::unique_ptr<UserHeader>& the user header
159 */
160 std::unique_ptr<UserHeader>& userHeader()
161 {
162 return _uh;
163 }
164
165 /**
Matt Spinler131870c2019-09-25 13:29:04 -0500166 * @brief Returns the optional sections, which is everything but
167 * the Private and User Headers.
168 *
169 * @return const std::vector<std::unique_ptr<Section>>&
170 */
171 const std::vector<std::unique_ptr<Section>>& optionalSections() const
172 {
173 return _optionalSections;
174 }
175
176 /**
Matt Spinlercb6b0592019-07-16 15:58:51 -0500177 * @brief Returns the PEL data.
178 *
179 * @return std::vector<uint8_t> - the raw PEL data
180 */
181 std::vector<uint8_t> data();
182
183 /**
184 * @brief Says if the PEL is valid (the sections are all valid)
185 *
186 * @return bool - if the PEL is valid
187 */
188 bool valid() const;
189
190 /**
191 * @brief Sets the commit timestamp to the current time
192 */
193 void setCommitTime();
194
195 /**
196 * @brief Sets the error log ID field to a unique ID.
197 */
198 void assignID();
199
200 private:
201 /**
202 * @brief Builds the section objects from a PEL data buffer
203 *
204 * @param[in] obmcLogID - The OpenBMC event log ID to use for that
205 * field in the Private Header.
206 */
207 void populateFromRawData(uint32_t obmcLogID);
208
209 /**
210 * @brief Flattens the PEL objects into the buffer
211 *
212 * @param[out] pelBuffer - What the data will be written to
213 */
214 void flatten(std::vector<uint8_t>& pelBuffer);
215
216 /**
217 * @brief The PEL Private Header section
218 */
219 std::unique_ptr<PrivateHeader> _ph;
220
221 /**
222 * @brief The PEL User Header section
223 */
224 std::unique_ptr<UserHeader> _uh;
225
226 /**
227 * @brief The PEL itself.
228 *
229 * This should be able to be removed when this class is able to
230 * serialize/deserialize a complete PEL from its objects, as
231 * then there will be no need to keep around the data anymore.
232 */
233 std::vector<uint8_t> _rawPEL;
Matt Spinlerb8323632019-09-20 15:11:04 -0500234
235 /**
236 * @brief If the PEL came from a flattened data stream.
237 */
238 bool _fromStream = false;
Matt Spinler131870c2019-09-25 13:29:04 -0500239
240 /**
241 * @brief Holds all sections by the PH and UH.
242 */
243 std::vector<std::unique_ptr<Section>> _optionalSections;
Matt Spinlercb6b0592019-07-16 15:58:51 -0500244};
245
246} // namespace pels
247} // namespace openpower