blob: bc857e2b137899f28cc4bfa3b34a2463334d0646 [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 Spinleraa659472019-10-23 09:26:48 -05004#include "data_interface.hpp"
Matt Spinlercb6b0592019-07-16 15:58:51 -05005#include "private_header.hpp"
Matt Spinlerb8323632019-09-20 15:11:04 -05006#include "registry.hpp"
Matt Spinlerbd716f02019-10-15 10:54:11 -05007#include "src.hpp"
Matt Spinlercb6b0592019-07-16 15:58:51 -05008#include "user_header.hpp"
9
10#include <memory>
11#include <vector>
12
13namespace openpower
14{
15namespace pels
16{
17
18/** @class PEL
19 *
20 * @brief This class represents a specific event log format referred to as a
21 * Platform Event Log.
22 *
23 * Every field in a PEL are in structures call sections, of which there are
24 * several types. Some sections are required, and some are optional. In some
25 * cases there may be more than one instance of a section type.
26 *
27 * The only two required sections for every type of PEL are the Private Header
28 * section and User Header section, which must be in the first and second
29 * positions, respectively.
30 *
31 * Every section starts with an 8 byte section header, which has the section
32 * size and type, among other things.
33 *
34 * This class represents all sections with objects.
35 *
Matt Spinlerbd716f02019-10-15 10:54:11 -050036 * The class can be constructed:
37 * - From a full formed flattened PEL.
38 * - From scratch based on an OpenBMC event and its corresponding PEL message
39 * registry entry.
Matt Spinlerb8323632019-09-20 15:11:04 -050040 *
Matt Spinlercb6b0592019-07-16 15:58:51 -050041 * The data() method allows one to retrieve the PEL as a vector<uint8_t>. This
42 * is the format in which it is stored and transmitted.
43 */
44class PEL
45{
46 public:
47 PEL() = delete;
48 ~PEL() = default;
49 PEL(const PEL&) = delete;
50 PEL& operator=(const PEL&) = delete;
51 PEL(PEL&&) = delete;
52 PEL& operator=(PEL&&) = delete;
53
54 /**
55 * @brief Constructor
56 *
57 * Build a PEL from raw data.
58 *
Matt Spinler07eefc52019-09-26 11:18:26 -050059 * Note: Neither this nor the following constructor can take a const vector&
60 * because the Stream class that is used to read from the vector cannot take
61 * a const. The alternative is to make a copy of the data, but as PELs can
62 * be up to 16KB that is undesireable.
63 *
Matt Spinlercb6b0592019-07-16 15:58:51 -050064 * @param[in] data - The PEL data
65 */
Matt Spinler07eefc52019-09-26 11:18:26 -050066 PEL(std::vector<uint8_t>& data);
Matt Spinlercb6b0592019-07-16 15:58:51 -050067
68 /**
69 * @brief Constructor
70 *
71 * Build a PEL from the raw data.
72 *
73 * @param[in] data - the PEL data
74 * @param[in] obmcLogID - the corresponding OpenBMC event log ID
75 */
Matt Spinler07eefc52019-09-26 11:18:26 -050076 PEL(std::vector<uint8_t>& data, uint32_t obmcLogID);
Matt Spinlercb6b0592019-07-16 15:58:51 -050077
78 /**
Matt Spinlerb8323632019-09-20 15:11:04 -050079 * @brief Constructor
80 *
81 * Creates a PEL from an OpenBMC event log and its message
82 * registry entry.
83 *
84 * @param[in] entry - The message registry entry for this error
85 * @param[in] obmcLogID - ID of corresponding OpenBMC event log
86 * @param[in] timestamp - Timestamp from the event log
87 * @param[in] severity - Severity from the event log
Matt Spinlerbd716f02019-10-15 10:54:11 -050088 * @param[in] additionalData - The AdditionalData contents
Matt Spinleraa659472019-10-23 09:26:48 -050089 * @param[in] dataIface - The data interface object
Matt Spinlerb8323632019-09-20 15:11:04 -050090 */
91 PEL(const openpower::pels::message::Entry& entry, uint32_t obmcLogID,
Matt Spinlerbd716f02019-10-15 10:54:11 -050092 uint64_t timestamp, phosphor::logging::Entry::Level severity,
Matt Spinleraa659472019-10-23 09:26:48 -050093 const AdditionalData& additionalData,
94 const DataInterfaceBase& dataIface);
Matt Spinlerb8323632019-09-20 15:11:04 -050095
96 /**
Matt Spinlercb6b0592019-07-16 15:58:51 -050097 * @brief Convenience function to return the log ID field from the
98 * Private Header section.
99 *
100 * @return uint32_t - the ID
101 */
102 uint32_t id() const
103 {
104 return _ph->id();
105 }
106
107 /**
108 * @brief Convenience function to return the PLID field from the
109 * Private Header section.
110 *
111 * @return uint32_t - the PLID
112 */
113 uint32_t plid() const
114 {
115 return _ph->plid();
116 }
117
118 /**
119 * @brief Convenience function to return the OpenBMC event log ID field
120 * from the Private Header section.
121 *
122 * @return uint32_t - the OpenBMC event log ID
123 */
124 uint32_t obmcLogID() const
125 {
126 return _ph->obmcLogID();
127 }
128
129 /**
130 * @brief Convenience function to return the commit time field from
131 * the Private Header section.
132 *
133 * @return BCDTime - the timestamp
134 */
135 BCDTime commitTime() const
136 {
137 return _ph->commitTimestamp();
138 }
139
140 /**
141 * @brief Convenience function to return the create time field from
142 * the Private Header section.
143 *
144 * @return BCDTime - the timestamp
145 */
146 BCDTime createTime() const
147 {
148 return _ph->createTimestamp();
149 }
150
151 /**
152 * @brief Gives access to the Private Header section class
153 *
154 * @return std::unique_ptr<PrivateHeader>& the private header
155 */
156 std::unique_ptr<PrivateHeader>& privateHeader()
157 {
158 return _ph;
159 }
160
161 /**
162 * @brief Gives access to the User Header section class
163 *
164 * @return std::unique_ptr<UserHeader>& the user header
165 */
166 std::unique_ptr<UserHeader>& userHeader()
167 {
168 return _uh;
169 }
170
171 /**
Matt Spinlerbd716f02019-10-15 10:54:11 -0500172 * @brief Gives access to the primary SRC's section class
173 *
174 * This is technically an optional section, so the return
175 * value is an std::optional<SRC*>.
176 *
177 * @return std::optional<SRC*> - the SRC section object
178 */
179 std::optional<SRC*> primarySRC() const;
180
181 /**
Matt Spinler131870c2019-09-25 13:29:04 -0500182 * @brief Returns the optional sections, which is everything but
183 * the Private and User Headers.
184 *
185 * @return const std::vector<std::unique_ptr<Section>>&
186 */
187 const std::vector<std::unique_ptr<Section>>& optionalSections() const
188 {
189 return _optionalSections;
190 }
191
192 /**
Matt Spinlercb6b0592019-07-16 15:58:51 -0500193 * @brief Returns the PEL data.
194 *
195 * @return std::vector<uint8_t> - the raw PEL data
196 */
197 std::vector<uint8_t> data();
198
199 /**
200 * @brief Says if the PEL is valid (the sections are all valid)
201 *
202 * @return bool - if the PEL is valid
203 */
204 bool valid() const;
205
206 /**
207 * @brief Sets the commit timestamp to the current time
208 */
209 void setCommitTime();
210
211 /**
212 * @brief Sets the error log ID field to a unique ID.
213 */
214 void assignID();
215
216 private:
217 /**
218 * @brief Builds the section objects from a PEL data buffer
219 *
Matt Spinler07eefc52019-09-26 11:18:26 -0500220 * Note: The data parameter cannot be const for the same reasons
221 * as listed in the constructor.
222 *
223 * @param[in] data - The PEL data
Matt Spinlercb6b0592019-07-16 15:58:51 -0500224 * @param[in] obmcLogID - The OpenBMC event log ID to use for that
225 * field in the Private Header.
226 */
Matt Spinler07eefc52019-09-26 11:18:26 -0500227 void populateFromRawData(std::vector<uint8_t>& data, uint32_t obmcLogID);
Matt Spinlercb6b0592019-07-16 15:58:51 -0500228
229 /**
230 * @brief Flattens the PEL objects into the buffer
231 *
232 * @param[out] pelBuffer - What the data will be written to
233 */
234 void flatten(std::vector<uint8_t>& pelBuffer);
235
236 /**
237 * @brief The PEL Private Header section
238 */
239 std::unique_ptr<PrivateHeader> _ph;
240
241 /**
242 * @brief The PEL User Header section
243 */
244 std::unique_ptr<UserHeader> _uh;
245
246 /**
Matt Spinler131870c2019-09-25 13:29:04 -0500247 * @brief Holds all sections by the PH and UH.
248 */
249 std::vector<std::unique_ptr<Section>> _optionalSections;
Matt Spinlercb6b0592019-07-16 15:58:51 -0500250};
251
252} // namespace pels
253} // namespace openpower