/** * Prints a DataDataRecord * @param sourceID SourceID of the exporting process * @param dataTemplateInfo Pointer to a structure defining the DataTemplate used * @param length Length of the data block supplied * @param data Pointer to a data block containing all variable fields */ void IpfixPrinter::onDataDataRecord(IpfixDataDataRecord* record) { boost::shared_ptr<IpfixRecord::DataTemplateInfo> dataTemplateInfo = record->dataTemplateInfo; int i; /* we need a FieldInfo for printIPv4 */ IpfixRecord::FieldInfo::Type tmpInfo = {0, 4, false, 0}; // length=4 for IPv4 address printf("\n-+--- DataDataRecord (Template id=%u from ", dataTemplateInfo->templateId); if(record->sourceID->exporterAddress.len == 4) printIPv4(tmpInfo, &record->sourceID->exporterAddress.ip[0]); else printf("non-IPv4 address"); printf(":%d (", record->sourceID->exporterPort); tmpInfo.length = 1; // length=1 for protocol identifier printProtocol(tmpInfo, &record->sourceID->protocol); printf(") )\n"); printf(" `- fixed data\n"); for (i = 0; i < dataTemplateInfo->dataCount; i++) { printf(" ' `- "); printFieldData(dataTemplateInfo->dataInfo[i].type, (dataTemplateInfo->data + dataTemplateInfo->dataInfo[i].offset)); printf("\n"); } printf(" `- variable data\n"); for (i = 0; i < dataTemplateInfo->fieldCount; i++) { printf(" ' `- "); printFieldData(dataTemplateInfo->fieldInfo[i].type, (record->data + dataTemplateInfo->fieldInfo[i].offset)); printf("\n"); } printf(" `---\n\n"); record->removeReference(); }
/** * Prints a DataRecord * @param sourceID SourceID of the exporting process * @param dataTemplateInfo Pointer to a structure defining the DataTemplate used * @param length Length of the data block supplied * @param data Pointer to a data block containing all variable fields */ void IpfixPrinter::onDataRecord(IpfixDataRecord* record) { int i; /* we need a FieldInfo for printIPv4 */ IpfixRecord::FieldInfo::Type tmpInfo = {0, 4, false, 0}; // length=4 for IPv4 address boost::shared_ptr<IpfixRecord::DataTemplateInfo> dataTemplateInfo; switch (outputType) { case LINE: printf("ERROR: one line record not implemented for IpfixDataRecords\n"); //printOneLineRecord(record); break; case TREE: dataTemplateInfo = record->templateInfo; printf("\n-+--- DataRecord (Template id=%u from ", dataTemplateInfo->templateId); if(record->sourceID->exporterAddress.len == 4) printIPv4(tmpInfo, &record->sourceID->exporterAddress.ip[0]); else printf("non-IPv4 address"); printf(":%d (", record->sourceID->exporterPort); tmpInfo.length = 1; // length=1 for protocol identifier printProtocol(tmpInfo, &record->sourceID->protocol); printf(") )\n"); printf(" `- fixed data\n"); for (i = 0; i < dataTemplateInfo->dataCount; i++) { printf(" ' `- "); printFieldData(dataTemplateInfo->dataInfo[i].type, (dataTemplateInfo->data + dataTemplateInfo->dataInfo[i].offset)); printf("\n"); } printf(" `- variable data\n"); for (i = 0; i < dataTemplateInfo->fieldCount; i++) { printf(" ' `- "); printFieldData(dataTemplateInfo->fieldInfo[i].type, (record->data + dataTemplateInfo->fieldInfo[i].offset)); printf("\n"); } printf(" `---\n\n"); break; case TABLE: printTableRecord(record); break; case NONE: break; } record->removeReference(); }
/** * Prints a DataTemplate * @param sourceID SourceID of the exporting process * @param dataTemplateInfo Pointer to a structure defining the DataTemplate used */ void IpfixPrinter::onTemplate(IpfixTemplateRecord* record) { int i; /* we need a FieldInfo for printIPv4 */ IpfixRecord::FieldInfo::Type tmpInfo = {0, 4, false, 0}; // length=4 for IPv4 address printf("\n-+--- Template (id=%u) from ", record->templateInfo->templateId); if (record->sourceID) { if (record->sourceID->exporterAddress.len == 4) printIPv4(tmpInfo, &record->sourceID->exporterAddress.ip[0]); else printf("non-IPv4 address"); printf(":%d (", record->sourceID->exporterPort); tmpInfo.length = 1; // length=1 for protocol identifier printProtocol(tmpInfo, &record->sourceID->protocol); printf(")\n"); } else { printf("no sourceID given in template"); } printf(" `- fixed data\n"); for (i = 0; i < record->templateInfo->dataCount; i++) { printf(" ' `- "); printFieldData(record->templateInfo->dataInfo[i].type, (record->templateInfo->data + record->templateInfo->dataInfo[i].offset)); printf("\n"); } printf(" `---\n\n"); record->removeReference(); }
/** * Prints a DataRecord * @param sourceID SourceID of the exporting process * @param dataTemplateInfo Pointer to a structure defining the DataTemplate used * @param length Length of the data block supplied * @param data Pointer to a data block containing all variable fields */ void IpfixPrinter::onDataRecord(IpfixDataRecord* record) { if (lineOutput) { printOneLineRecord(record); } else { int i; /* we need a FieldInfo for printIPv4 */ IpfixRecord::FieldInfo::Type tmpInfo = {0, 4, false, 0}; // length=4 for IPv4 address printf("\n-+--- DataRecord (Template id=%u from ", record->templateInfo->templateId); if(record->sourceID->exporterAddress.len == 4) printIPv4(tmpInfo, &record->sourceID->exporterAddress.ip[0]); else printf("non-IPv4 address"); printf(":%d (", record->sourceID->exporterPort); tmpInfo.length = 1; // length=1 for protocol identifier printProtocol(tmpInfo, &record->sourceID->protocol); printf(") )\n"); printf(" `- variable data\n"); for (i = 0; i < record->templateInfo->fieldCount; i++) { printf(" ' `- "); printFieldData(record->templateInfo->fieldInfo[i].type, (record->data + record->templateInfo->fieldInfo[i].offset)); printf("\n"); } } record->removeReference(); }
/** * prints record as a tree */ void IpfixPrinter::printTreeRecord(IpfixDataRecord* record) { int i; switch(record->templateInfo->setId) { case TemplateInfo::NetflowTemplate: fprintf(fh, "\n-+--- Netflow Data Record (id=%u) from ", record->templateInfo->templateId); break; case TemplateInfo::NetflowOptionsTemplate: fprintf(fh, "\n-+--- Netflow Options Data Record (id=%u) from ", record->templateInfo->templateId); break; case TemplateInfo::IpfixTemplate: fprintf(fh, "\n-+--- Ipfix Data Record (id=%u) from ", record->templateInfo->templateId); break; case TemplateInfo::IpfixOptionsTemplate: fprintf(fh, "\n-+--- Ipfix Options Data Record (id=%u) from ", record->templateInfo->templateId); break; case TemplateInfo::IpfixDataTemplate: fprintf(fh, "\n-+--- Ipfix Data Data Record (id=%u, preceding=%u) from ", record->templateInfo->templateId, record->templateInfo->preceding); break; default: msg(MSG_ERROR, "IpfixPrinter: Template with unknown setid=%u", record->templateInfo->setId); } if (record->sourceID) { if (record->sourceID->exporterAddress.len == 4) printIPv4(*(uint32_t*)(&record->sourceID->exporterAddress.ip[0])); else fprintf(fh, "non-IPv4 address"); fprintf(fh, ":%u (", record->sourceID->exporterPort); printProtocol(record->sourceID->protocol); fprintf(fh, ")\n"); } else { fprintf(fh, "no sourceID given"); } if(record->templateInfo->setId == TemplateInfo::IpfixDataTemplate) { fprintf(fh, " `- fixed data\n"); for (i = 0; i < record->templateInfo->dataCount; i++) { fprintf(fh, " ' `- "); printFieldData(record->templateInfo->dataInfo[i].type, (record->templateInfo->data + record->templateInfo->dataInfo[i].offset)); fprintf(fh, "\n"); } } if(record->templateInfo->setId == TemplateInfo::IpfixOptionsTemplate) { fprintf(fh, " `- variable scope data\n"); for(i = 0; i < record->templateInfo->scopeCount; i++) { fprintf(fh, " ' `- "); printFieldData(record->templateInfo->scopeInfo[i].type, (record->data + record->templateInfo->scopeInfo[i].offset)); fprintf(fh, "\n"); } } fprintf(fh, " `- variable data\n"); for (i = 0; i < record->templateInfo->fieldCount; i++) { fprintf(fh, " ' `- "); printFieldData(record->templateInfo->fieldInfo[i].type, (record->data + record->templateInfo->fieldInfo[i].offset)); fprintf(fh, "\n"); } fprintf(fh, " `---\n\n"); }
/** * Prints a Template * @param sourceID SourceID of the exporting process * @param templateInfo Pointer to a structure defining the Template used */ void IpfixPrinter::onTemplate(IpfixTemplateRecord* record) { boost::shared_ptr<TemplateInfo> templateInfo; switch (outputType) { case LINE: case TREE: templateInfo = record->templateInfo; switch(templateInfo->setId) { case TemplateInfo::NetflowTemplate: fprintf(fh, "\n-+--- Netflow Template (id=%u, uniqueId=%u) from ", templateInfo->templateId, templateInfo->getUniqueId()); break; case TemplateInfo::NetflowOptionsTemplate: fprintf(fh, "\n-+--- Netflow Options Template (id=%u, uniqueId=%u) from ", templateInfo->templateId, templateInfo->getUniqueId()); break; case TemplateInfo::IpfixTemplate: fprintf(fh, "\n-+--- Ipfix Template (id=%u, uniqueId=%u) from ", templateInfo->templateId, templateInfo->getUniqueId()); break; case TemplateInfo::IpfixOptionsTemplate: fprintf(fh, "\n-+--- Ipfix Options Template (id=%u, uniqueId=%u) from ", templateInfo->templateId, templateInfo->getUniqueId()); break; case TemplateInfo::IpfixDataTemplate: fprintf(fh, "\n-+--- Ipfix Data Template (id=%u, preceding=%u, uniqueId=%u) from ", templateInfo->templateId, templateInfo->preceding, templateInfo->getUniqueId()); break; default: msg(MSG_ERROR, "IpfixPrinter: Template with unknown setId=%u, uniqueId=%u", templateInfo->setId, templateInfo->getUniqueId()); } if (record->sourceID) { if (record->sourceID->exporterAddress.len == 4) printIPv4(*(uint32_t*)(&record->sourceID->exporterAddress.ip[0])); else fprintf(fh, "non-IPv4 address"); fprintf(fh, ":%u (", record->sourceID->exporterPort); printProtocol(record->sourceID->protocol); fprintf(fh, ")\n"); } else { fprintf(fh, "no sourceID given in template"); } if (templateInfo->setId == TemplateInfo::IpfixTemplate) { for (int i = 0; i < templateInfo->fieldCount; i++) { TemplateInfo::FieldInfo* fi = &templateInfo->fieldInfo[i]; fprintf(fh, " ' `- %s\n", fi->type.toString().c_str()); } } // print fixed data in the case of a data template if(templateInfo->setId == TemplateInfo::IpfixDataTemplate) { fprintf(fh, " `- fixed data\n"); for (int i = 0; i < templateInfo->dataCount; i++) { fprintf(fh, " ' `- "); printFieldData(templateInfo->dataInfo[i].type, (templateInfo->data + templateInfo->dataInfo[i].offset)); fprintf(fh, "\n"); } } fprintf(fh, " `---\n\n"); break; case TABLE: case NONE: break; } record->removeReference(); }