Using fixbuf to read from IPFIX Files as a Collecting Process is very much like the Export case.
Create an fbInfoModel_t using fbInfoModelAlloc(). If needed, add any vendor-specific information elements using fbInfoModelAddElement(), fbInfoModelAddElementArray(), fbInfoModelReadXMLFile(), or fbInfoModelReadXMLData().
Create an fbSession_t state container using fbSessionAlloc().
For each type of record you expect to read, create an internal template to describe it: Use fbTemplateAlloc() to allocate the template and fbTemplateAppendSpecArray(), fbTemplateAppendSpec(), fbTemplateAppend(), fbTemplateAppendArraySpecId(), or fbTemplateAppendSpecId(), to specify its elements. Unlike when exporting data, external templates do not need to be added for collection as they are defined by the templates in the file.
Use fbSessionAddTemplate() to add each Template to the Session.
Create the fbCollector_t to encapsulate the file, using the fbCollectorAllocFP() or fbCollectorAllocFile() calls. (For network collection, see Network Collectors).
With an fbSession_t and an fbCollector_t available, create a Buffer (fBuf_t) for reading via fBufAllocForCollection().
To read all records using a single template, set the internal template with fBufSetInternalTemplate(). Call fBufNext() to read records from the IPFIX Messages in the input stream until it returns FALSE.
To vary the internal template depending on the external template, the main reading loop is slightly different. First call fBufNextCollectionTemplate() to examine the template of the next record, then use fBufSetInternalTemplate() and fBufNext() to get that record.
By default, fBufNext() will consume an IPFIX Message from the input stream when the end of the message buffer is reached on read. The fBufSetAutomaticNextMessage() call can be used to modify this behavior, causing fBufNext() to return FB_ERROR_EOM when at end of message. Use this if your application requires manual control of message collection. In this case, fBufNextMessage() will consume a Message from the input stream.
Complete sample_collector.c
program:
Previous: Exporter Usage | Next: Template Definition