OpenCSD - CoreSight Trace Decode Library 1.8.3
Loading...
Searching...
No Matches
trc_pkt_proc_base.h
Go to the documentation of this file.
1
7
8
9/*
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of the copyright holder nor the names of its contributors
21 * may be used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef ARM_TRC_PKT_PROC_BASE_H_INCLUDED
37#define ARM_TRC_PKT_PROC_BASE_H_INCLUDED
38
39#include <new>
40
45
46#include "trc_component.h"
47#include "comp_attach_pt_t.h"
49
56
57
58
68{
69public:
70 TrcPktProcI(const char *component_name);
71 TrcPktProcI(const char *component_name, int instIDNum);
72 virtual ~TrcPktProcI() {};
73
77 const ocsd_trc_index_t index,
78 const uint32_t dataBlockSize,
79 const uint8_t *pDataBlock,
80 uint32_t *numBytesProcessed) = 0;
81
83 virtual void resetStats() = 0;
84protected:
85
86 /* implementation packet processing interface */
87
90 const uint32_t dataBlockSize,
91 const uint8_t *pDataBlock,
92 uint32_t *numBytesProcessed) = 0;
93
98 virtual const bool isBadPacket() const = 0;
99};
100
101inline TrcPktProcI::TrcPktProcI(const char *component_name) :
102 TraceComponent(component_name)
103{
104}
105
106inline TrcPktProcI::TrcPktProcI(const char *component_name, int instIDNum) :
107 TraceComponent(component_name,instIDNum)
108{
109}
110
127template <class P, class Pt, class Pc>
129{
130public:
131 TrcPktProcBase(const char *component_name);
132 TrcPktProcBase(const char *component_name, int instIDNum);
133 virtual ~TrcPktProcBase();
134
141 const ocsd_trc_index_t index,
142 const uint32_t dataBlockSize,
143 const uint8_t *pDataBlock,
144 uint32_t *numBytesProcessed);
145
146
147/* component attachment points */
148
153
156
157/* protocol configuration */
159 virtual ocsd_err_t setProtocolConfig(const Pc *config);
161 virtual const Pc *getProtocolConfig() const { return m_config; };
162
163/* stats block access - derived class must init stats for the block to be returned. */
165 virtual void resetStats(); /* reset the counts - operates separately from decoder reset. */
166
167protected:
168
169 /* data output functions */
171
173 const P *pkt,
174 const uint32_t size,
175 const uint8_t *p_data);
176
177 void indexPacket(const ocsd_trc_index_t index_sop, const Pt *packet_type);
178
179 ocsd_datapath_resp_t outputOnAllInterfaces(const ocsd_trc_index_t index_sop, const P *pkt, const Pt *pkt_type, std::vector<uint8_t> &pktdata);
180
181 ocsd_datapath_resp_t outputOnAllInterfaces(const ocsd_trc_index_t index_sop, const P *pkt, const Pt *pkt_type, const uint8_t *pktdata, uint32_t pktlen);
182
186 const bool hasRawMon() const;
187
188 /* the protocol configuration */
189 const Pc *m_config;
190
191 void ClearConfigObj(); // remove our copy of the config
192
193 const bool checkInit(); // return true if init (configured and at least one output sink attached), false otherwise.
194
195 /* stats block updates - called by derived protocol specific decoder */
196 void statsAddTotalCount(const uint64_t count) { m_stats.channel_total += count; };
197 void statsAddUnsyncCount(const uint64_t count) { m_stats.channel_unsynced += count; };
198 void statsAddBadSeqCount(const uint32_t count) { m_stats.bad_sequence_errs += count; };
199 void statsAddBadHdrCount(const uint32_t count) { m_stats.bad_header_errs += count; };
200 void statsInit() { m_stats_init = true; }; /* mark stats as in use */
201
202
203private:
204 /* decode control */
205 ocsd_datapath_resp_t Reset(const ocsd_trc_index_t index);
206 ocsd_datapath_resp_t Flush();
208
211
213
214 bool m_b_is_init;
215
216 /* decode statistics block */
217 ocsd_decode_stats_t m_stats;
218 bool m_stats_init; /*< true if the specific decoder is using the stats */
219
220};
221
222template<class P,class Pt, class Pc> TrcPktProcBase<P, Pt, Pc>::TrcPktProcBase(const char *component_name) :
223 TrcPktProcI(component_name),
224 m_config(0),
225 m_b_is_init(false),
226 m_stats_init(false)
227{
228 resetStats();
229}
230
231template<class P,class Pt, class Pc> TrcPktProcBase<P, Pt, Pc>::TrcPktProcBase(const char *component_name, int instIDNum) :
232 TrcPktProcI(component_name, instIDNum),
233 m_config(0),
234 m_b_is_init(false),
235 m_stats_init(false)
236{
237 resetStats();
238}
239
240template<class P,class Pt, class Pc> TrcPktProcBase<P, Pt, Pc>::~TrcPktProcBase()
241{
243}
244
246 const ocsd_trc_index_t index,
247 const uint32_t dataBlockSize,
248 const uint8_t *pDataBlock,
249 uint32_t *numBytesProcessed)
250{
252
253 switch(op)
254 {
255 case OCSD_OP_DATA:
256 if((dataBlockSize == 0) || (pDataBlock == 0) || (numBytesProcessed == 0))
257 {
258 if(numBytesProcessed)
259 *numBytesProcessed = 0; // ensure processed bytes value set to 0.
260 LogError(ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_INVALID_PARAM_VAL,"Packet Processor: Zero length data block or NULL pointer error\n"));
262 }
263 else
264 resp = processData(index,dataBlockSize,pDataBlock,numBytesProcessed);
265 break;
266
267 case OCSD_OP_EOT:
268 resp = EOT();
269 break;
270
271 case OCSD_OP_FLUSH:
272 resp = Flush();
273 break;
274
275 case OCSD_OP_RESET:
276 resp = Reset(index);
277 break;
278
279 default:
280 LogError(ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_INVALID_PARAM_VAL,"Packet Processor : Unknown Datapath operation\n"));
282 break;
283 }
284 return resp;
285}
286
287
288template<class P,class Pt, class Pc> ocsd_datapath_resp_t TrcPktProcBase<P, Pt, Pc>::Reset(const ocsd_trc_index_t index)
289{
291
292 // reset the trace decoder attachment on main data path.
293 if(m_pkt_out_i.hasAttachedAndEnabled())
294 resp = m_pkt_out_i.first()->PacketDataIn(OCSD_OP_RESET,index,0);
295
296 // reset the packet processor implmentation
297 if(!OCSD_DATA_RESP_IS_FATAL(resp))
298 resp = onReset();
299
300 // packet monitor
301 if(m_pkt_raw_mon_i.hasAttachedAndEnabled())
302 m_pkt_raw_mon_i.first()->RawPacketDataMon(OCSD_OP_RESET,index,0,0,0);
303
304 return resp;
305}
306
307template<class P,class Pt, class Pc> ocsd_datapath_resp_t TrcPktProcBase<P, Pt, Pc>::Flush()
308{
311
312 // the trace decoder attachment on main data path.
313 if(m_pkt_out_i.hasAttachedAndEnabled())
314 resp = m_pkt_out_i.first()->PacketDataIn(OCSD_OP_FLUSH,0,0); // flush up the data path first.
315
316 // if the connected components are flushed, not flush this one.
317 if(OCSD_DATA_RESP_IS_CONT(resp))
318 resplocal = onFlush(); // local flush
319
320 return (resplocal > resp) ? resplocal : resp;
321}
322
323template<class P,class Pt, class Pc> ocsd_datapath_resp_t TrcPktProcBase<P, Pt, Pc>::EOT()
324{
325 ocsd_datapath_resp_t resp = onEOT(); // local EOT - mark any part packet as incomplete type and prepare to send
326
327 // the trace decoder attachment on main data path.
328 if(m_pkt_out_i.hasAttachedAndEnabled() && !OCSD_DATA_RESP_IS_FATAL(resp))
329 resp = m_pkt_out_i.first()->PacketDataIn(OCSD_OP_EOT,0,0);
330
331 // packet monitor
332 if(m_pkt_raw_mon_i.hasAttachedAndEnabled())
333 m_pkt_raw_mon_i.first()->RawPacketDataMon(OCSD_OP_EOT,0,0,0,0);
334
335 return resp;
336}
337
338template<class P,class Pt, class Pc> ocsd_datapath_resp_t TrcPktProcBase<P, Pt, Pc>::outputDecodedPacket(const ocsd_trc_index_t index, const P *pkt)
339{
341
342 // bad packet filter.
344 return resp;
345
346 // send a complete packet over the primary data path
347 if(m_pkt_out_i.hasAttachedAndEnabled())
348 resp = m_pkt_out_i.first()->PacketDataIn(OCSD_OP_DATA,index,pkt);
349 return resp;
350}
351
352template<class P,class Pt, class Pc> void TrcPktProcBase<P, Pt, Pc>::outputRawPacketToMonitor(
353 const ocsd_trc_index_t index_sop,
354 const P *pkt,
355 const uint32_t size,
356 const uint8_t *p_data)
357{
358 // never output 0 sized packets.
359 if(size == 0)
360 return;
361
362 // bad packet filter.
364 return;
365
366 // packet monitor - this cannot return CONT / WAIT, but does get the raw packet data.
367 if(m_pkt_raw_mon_i.hasAttachedAndEnabled())
368 m_pkt_raw_mon_i.first()->RawPacketDataMon(OCSD_OP_DATA,index_sop,pkt,size,p_data);
369}
370
371template<class P,class Pt, class Pc> const bool TrcPktProcBase<P, Pt, Pc>::hasRawMon() const
372{
373 return m_pkt_raw_mon_i.hasAttachedAndEnabled();
374}
375
376template<class P,class Pt, class Pc> void TrcPktProcBase<P, Pt, Pc>::indexPacket(const ocsd_trc_index_t index_sop, const Pt *packet_type)
377{
378 // packet indexer - cannot return CONT / WAIT, just gets the current index and type.
379 if(m_pkt_indexer_i.hasAttachedAndEnabled())
380 m_pkt_indexer_i.first()->TracePktIndex(index_sop,packet_type);
381}
382
383template<class P,class Pt, class Pc> ocsd_datapath_resp_t TrcPktProcBase<P, Pt, Pc>::outputOnAllInterfaces(const ocsd_trc_index_t index_sop, const P *pkt, const Pt *pkt_type, std::vector<uint8_t> &pktdata)
384{
385 indexPacket(index_sop,pkt_type);
386 if(pktdata.size() > 0) // prevent out of range errors for 0 length vector.
387 outputRawPacketToMonitor(index_sop,pkt,(uint32_t)pktdata.size(),&pktdata[0]);
388 return outputDecodedPacket(index_sop,pkt);
389}
390
391template<class P,class Pt, class Pc> ocsd_datapath_resp_t TrcPktProcBase<P, Pt, Pc>::outputOnAllInterfaces(const ocsd_trc_index_t index_sop, const P *pkt, const Pt *pkt_type, const uint8_t *pktdata, uint32_t pktlen)
392{
393 indexPacket(index_sop,pkt_type);
394 outputRawPacketToMonitor(index_sop,pkt,pktlen,pktdata);
395 return outputDecodedPacket(index_sop,pkt);
396}
397
398template<class P,class Pt, class Pc> ocsd_err_t TrcPktProcBase<P, Pt, Pc>::setProtocolConfig(const Pc *config)
399{
401 if(config != 0)
402 {
404 m_config = new (std::nothrow) Pc(*config);
405 if(m_config != 0)
406 err = onProtocolConfig();
407 else
408 err = OCSD_ERR_MEM;
409 }
410 return err;
411}
412
413template<class P,class Pt, class Pc> void TrcPktProcBase<P, Pt, Pc>::ClearConfigObj()
414{
415 if(m_config)
416 {
417 delete m_config;
418 m_config = 0;
419 }
420}
421
422template<class P,class Pt, class Pc> const bool TrcPktProcBase<P, Pt, Pc>::checkInit()
423{
424 if(!m_b_is_init)
425 {
426 if( (m_config != 0) &&
427 (m_pkt_out_i.hasAttached() || m_pkt_raw_mon_i.hasAttached())
428 )
429 m_b_is_init = true;
430 }
431 return m_b_is_init;
432}
433
434template<class P,class Pt, class Pc> ocsd_err_t TrcPktProcBase<P, Pt, Pc>::getStatsBlock(ocsd_decode_stats_t **pp_stats)
435{
436
437 *pp_stats = &m_stats;
438 return m_stats_init ? OCSD_OK : OCSD_ERR_NOT_INIT;
439}
440
441template<class P,class Pt, class Pc> void TrcPktProcBase<P, Pt, Pc>::resetStats()
442{
443 m_stats.version = OCSD_VER_NUM;
444 m_stats.revision = OCSD_STATS_REVISION;
445 m_stats.channel_total = 0;
446 m_stats.channel_unsynced = 0;
447 m_stats.bad_header_errs = 0;
448 m_stats.bad_sequence_errs = 0;
449 m_stats.demux.frame_bytes = 0;
450 m_stats.demux.no_id_bytes = 0;
451 m_stats.demux.valid_id_bytes = 0;
452}
453
455
456#endif // ARM_TRC_PKT_PROC_BASE_H_INCLUDED
457
458/* End of File trc_pkt_proc_base.h */
const uint32_t getComponentOpMode() const
TraceComponent(const std::string &name)
void LogError(const ocsdError &Error)
void statsAddBadSeqCount(const uint32_t count)
void statsAddUnsyncCount(const uint64_t count)
virtual const Pc * getProtocolConfig() const
componentAttachPt< IPktDataIn< P > > * getPacketOutAttachPt()
Attachement point for the protocol packet output.
void statsAddTotalCount(const uint64_t count)
componentAttachPt< ITrcPktIndexer< Pt > > * getTraceIDIndexerAttachPt()
Attachment point for a packet indexer.
componentAttachPt< IPktRawDataMon< P > > * getRawPacketMonAttachPt()
Attachment point for the protocol packet monitor.
void statsAddBadHdrCount(const uint32_t count)
virtual ocsd_datapath_resp_t TraceDataIn(const ocsd_datapath_op_t op, const ocsd_trc_index_t index, const uint32_t dataBlockSize, const uint8_t *pDataBlock, uint32_t *numBytesProcessed)=0
virtual ocsd_datapath_resp_t processData(const ocsd_trc_index_t index, const uint32_t dataBlockSize, const uint8_t *pDataBlock, uint32_t *numBytesProcessed)=0
Implementation function for the OCSD_OP_DATA operation.
virtual ocsd_datapath_resp_t onFlush()=0
Implementation function for the OCSD_OP_FLUSH operation.
virtual ocsd_err_t getStatsBlock(ocsd_decode_stats_t **pp_stats)=0
virtual const bool isBadPacket() const =0
check if the current packet is an error / bad packet
virtual ocsd_err_t onProtocolConfig()=0
Called when the configuration object is passed to the decoder.
virtual void resetStats()=0
virtual ocsd_datapath_resp_t onReset()=0
Implementation function for the OCSD_OP_RESET operation.
virtual ocsd_datapath_resp_t onEOT()=0
Implementation function for the OCSD_OP_EOT operation.
virtual ~TrcPktProcI()
Single component interface pointer attachment point.
OpenCSD : Component attachment point interface class.
#define OCSD_DATA_RESP_IS_FATAL(x)
#define OCSD_STATS_REVISION
uint32_t ocsd_trc_index_t
enum _ocsd_datapath_resp_t ocsd_datapath_resp_t
struct _ocsd_decode_stats ocsd_decode_stats_t
#define OCSD_DATA_RESP_IS_CONT(x)
#define OCSD_VER_NUM
enum _ocsd_datapath_op_t ocsd_datapath_op_t
enum _ocsd_err_t ocsd_err_t
#define OCSD_OPFLG_PKTPROC_NOMON_BAD_PKTS
#define OCSD_OPFLG_PKTPROC_NOFWD_BAD_PKTS
@ OCSD_OK
@ OCSD_ERR_INVALID_PARAM_VAL
@ OCSD_ERR_NOT_INIT
@ OCSD_ERR_MEM
@ OCSD_RESP_CONT
@ OCSD_RESP_FATAL_INVALID_PARAM
@ OCSD_RESP_FATAL_INVALID_OP
@ OCSD_OP_EOT
@ OCSD_OP_FLUSH
@ OCSD_OP_DATA
@ OCSD_OP_RESET
@ OCSD_ERR_SEV_ERROR
ocsd_datapath_resp_t outputOnAllInterfaces(const ocsd_trc_index_t index_sop, const P *pkt, const Pt *pkt_type, std::vector< uint8_t > &pktdata)
void outputRawPacketToMonitor(const ocsd_trc_index_t index_sop, const P *pkt, const uint32_t size, const uint8_t *p_data)
virtual ocsd_err_t getStatsBlock(ocsd_decode_stats_t **pp_stats)
TrcPktProcI(const char *component_name)
void indexPacket(const ocsd_trc_index_t index_sop, const Pt *packet_type)
virtual ocsd_err_t setProtocolConfig(const Pc *config)
< Set the protocol specific configuration for the decoder.
const bool hasRawMon() const
virtual ~TrcPktProcBase()
const bool checkInit()
virtual ocsd_datapath_resp_t TraceDataIn(const ocsd_datapath_op_t op, const ocsd_trc_index_t index, const uint32_t dataBlockSize, const uint8_t *pDataBlock, uint32_t *numBytesProcessed)
TrcPktProcBase(const char *component_name)
ocsd_datapath_resp_t outputDecodedPacket(const ocsd_trc_index_t index_sop, const P *pkt)
virtual void resetStats()
OpenCSD : Base trace decode component.