Commit 545ca383 authored by Håvard Moås's avatar Håvard Moås
Browse files

Update IPFIXLIB to add data export of num of exported ipfix messages and...

Update IPFIXLIB to add data export of num of exported ipfix messages and bytes, havard.mork@gmail.com

git-svn-id: file:///home/svn/mapi/branches/haavardm-mapi@74 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 3c22c2d7
......@@ -674,6 +674,11 @@ void addPktToHash(np_ctxt_t *npctxt,
setPayload(npctxt, bkt, payload, payloadLen, 0);
bkt->src2dstTcpFlags |= flags; /* Do not move this line before updateTcpFlags(...) */
if(bkt->dst2srcTcpFlagsFirst == (unsigned short)-1) {
// Only update for first packet.
bkt->dst2srcTcpFlagsFirst = flags;
}
updatePacketSizeStats(npctxt,bkt,len,0);
if(npctxt->bitrateCalcEnabled!=0) {
updateBitrateCalculation(npctxt,bkt,len, stamp,0,0);
......@@ -836,6 +841,9 @@ void addPktToHash(np_ctxt_t *npctxt,
bkt->dst2srcBitrateAverager10msPos = 0;
bkt->src2dstTcpFlagsFirst = flags;
bkt->dst2srcTcpFlagsFirst = (unsigned short)-1;
bkt->src2dstMinPktSize = bkt->dst2srcMinPktSize = 0xFFFF;
bkt->src2dstMaxPktSize = bkt->dst2srcMaxPktSize = 0x0000;
updatePacketSizeStats(npctxt,bkt,len,0);
......
......@@ -314,6 +314,10 @@ typedef struct {
u_int64_t notsent_pkts;
u_int64_t notsent_octets;
/* Number (and size) of IPFIX messages that have been exported */
u_int64_t exportedOctetTotalCount;
u_int64_t exportedMessageTotalCount;
/* Number of seconds that one flow may be queued for export. Old flows aren't */
/* exported in order to avoid congestion. This is max num of seconds to keep. */
u_int32_t maxExportQueueLatency;
......
......@@ -285,6 +285,10 @@ printStats(np_ctxt_t *npctxt)
}
}
if(npctxt->notsent_flows > 0ull) {
traceEvent(npctxt, TRACE_INFO, "Total non-exported flows due to congestion: %ull", npctxt->notsent_flows);
}
npctxt->maxBucketSearch = 0; /* reset */
if (npctxt->usePcap) {
......@@ -426,6 +430,9 @@ sendNetFlow(np_ctxt_t *npctxt, const void *buffer, u_int32_t bufferLength,
{
u_int32_t rc;
npctxt->exportedOctetTotalCount = npctxt->exportedOctetTotalCount + (u_int64_t)bufferLength;
npctxt->exportedMessageTotalCount = npctxt->exportedMessageTotalCount + (u_int64_t)1;
#ifdef DEBUG
traceEvent(npctxt, TRACE_INFO, "==>> sendNetFlow(%d)", bufferLength);
#endif
......@@ -643,12 +650,14 @@ sendNetFlowIPFIXtemplate(np_ctxt_t *npctxt)
templateDef.templateId = htons(259);
bufLen = 0;
npctxt->ipfixHeader.length = sizeof(IPFIXFlowHeader) + sizeof(templateDef) + templateBufBegin;
npctxt->ipfixHeader.exportTime = time(NULL);
npctxt->ipfixHeader.length = htons(sizeof(IPFIXFlowHeader) + sizeof(templateDef) + templateBufBegin);
npctxt->ipfixHeader.exportTime = htonl(time(NULL));
memcpy(&buf[bufLen], &npctxt->ipfixHeader, sizeof(npctxt->ipfixHeader));
bufLen += sizeof npctxt->ipfixHeader;
memcpy(&buf[bufLen], &templateDef, sizeof(V9Template)); bufLen += sizeof(V9Template);
memcpy(&buf[bufLen], templateBuffer, templateBufBegin); bufLen += templateBufBegin;
memcpy(&buf[bufLen], &templateDef, sizeof(V9Template));
bufLen += sizeof(V9Template);
memcpy(&buf[bufLen], templateBuffer, templateBufBegin);
bufLen += templateBufBegin;
sendNetFlow(npctxt, (const void *)buf, bufLen, 0);
}
......@@ -772,7 +781,8 @@ sendNetFlowV9(np_ctxt_t *npctxt, u_char lastFlow)
memcpy(&flowBuffer[bufLen], &npctxt->v9Header, sizeof npctxt->v9Header);
bufLen += sizeof(npctxt->v9Header);
memcpy(&flowBuffer[bufLen], &flowSet, sizeof(flowSet)); bufLen += sizeof(flowSet);
memcpy(&flowBuffer[bufLen], &flowSet, sizeof(flowSet));
bufLen += sizeof(flowSet);
memcpy(&flowBuffer[bufLen], npctxt->npBuffer, npctxt->bufferLen);
bufLen += npctxt->bufferLen;
......@@ -801,7 +811,8 @@ sendNetFlowIPFIX(np_ctxt_t *npctxt, u_char lastFlow)
npctxt->ipfixHeader.exportTime = time(NULL);
memcpy(&flowBuffer[bufLen], &npctxt->ipfixHeader, sizeof npctxt->ipfixHeader);
bufLen += sizeof(npctxt->ipfixHeader);
memcpy(&flowBuffer[bufLen], &flowSet, sizeof(flowSet)); bufLen += sizeof(flowSet);
memcpy(&flowBuffer[bufLen], &flowSet, sizeof(flowSet));
bufLen += sizeof(flowSet);
memcpy(&flowBuffer[bufLen], npctxt->npBuffer, npctxt->bufferLen);
bufLen += npctxt->bufferLen;
......@@ -1159,6 +1170,9 @@ npInitContext(void)
npctxt->notsent_pkts = 0;
npctxt->notsent_octets = 0;
npctxt->exportedOctetTotalCount = 0;
npctxt->exportedMessageTotalCount = 0;
// Attempt to get own IP address
if (gethostname(ac, sizeof(ac))==0) {
struct hostent *phe = gethostbyname(ac);
......
......@@ -94,6 +94,7 @@ typedef struct hashBucket {
u_char src2dstTos, dst2srcTos;
u_int16_t vlanId;
unsigned short src2dstTcpFlags, dst2srcTcpFlags;
unsigned short src2dstTcpFlagsFirst, dst2srcTcpFlagsFirst;
u_char src2dstFingerprint[FINGERPRINT_LEN], dst2srcFingerprint[FINGERPRINT_LEN];
/* **************** */
u_long bytesSent, pktSent;
......
......@@ -54,6 +54,7 @@
#define FID_SUM_PKT_LENGTH 32795
#define FID_QSUM_PKT_DIST 32796
#define FID_QSUM_PKT_LENGTH 32797
#define FID_CONNDIRECTION 32798
#ifndef __KERNEL__
......@@ -704,9 +705,9 @@ static V9TemplateId ver9_templates[] = {
{ 37, 2, "FLOW_INACTIVE_TIMEOUT" },
{ 38, 1, "ENGINE_TYPE" }, // not ipfix
{ 39, 1, "ENGINE_ID" }, // not ipfix
{ 40, 4, "TOTAL_BYTES_EXP" },
{ 41, 4, "TOTAL_PKTS_EXP" },
{ 42, 4, "TOTAL_FLOWS_EXP" },
{ 40, 8, "TOTAL_BYTES_EXP" },
{ 41, 8, "TOTAL_PKTS_EXP" },
{ 42, 8, "TOTAL_FLOWS_EXP" },
// NOT 43-59
{ 60, 1, "IP_PROTOCOL_VERSION" },
//{ 61, 1, "DIRECTION" },
......@@ -787,6 +788,7 @@ static V9TemplateId ver9_templates[] = {
{ FID_SUM_PKT_LENGTH, 8, "SUM_PKT_LENGTH" },
{ FID_QSUM_PKT_DIST, 8, "QSUM_PKT_DIST" },
{ FID_QSUM_PKT_LENGTH, 8, "QSUM_PKT_LENGTH" },
{ FID_CONNDIRECTION, 1, "CONN_DIRECTION" },
{ 0, 0, NULL }
};
......@@ -1157,13 +1159,13 @@ static void handleTemplate(np_ctxt_t *npctxt, V9TemplateId *theTemplate,
copyInt8(engineId, outBuffer, outBufferBegin, outBufferMax);
break;
case 40: /* TOTAL_BYTES_EXP */
copyInt32(0, outBuffer, outBufferBegin, outBufferMax); /* FIX */
copyInt64(npctxt->exportedOctetTotalCount, outBuffer, outBufferBegin, outBufferMax);
break;
case 41: /* TOTAL_PKTS_EXP */
copyInt32(0, outBuffer, outBufferBegin, outBufferMax); /* FIX */
copyInt64(npctxt->exportedMessageTotalCount, outBuffer, outBufferBegin, outBufferMax);
break;
case 42: /* TOTAL_FLOWS_EXP */
copyInt32(0, outBuffer, outBufferBegin, outBufferMax); /* FIX */
copyInt64(0, outBuffer, outBufferBegin, outBufferMax); /* FIX */
break;
case 60: /* IP_PROTOCOL_VERSION */
copyInt8(4, outBuffer, outBufferBegin, outBufferMax); /* FIX */
......@@ -1467,6 +1469,23 @@ static void handleTemplate(np_ctxt_t *npctxt, V9TemplateId *theTemplate,
case FID_QSUM_PKT_LENGTH:
copyInt64(direction==0?theFlow->src2dst_expval_pktlength_x2:theFlow->dst2src_expval_pktlength_x2, outBuffer, outBufferBegin,outBufferMax);
break;
case FID_CONNDIRECTION:
{
unsigned short flags = direction==0?theFlow->src2dstTcpFlagsFirst:
theFlow->dst2srcTcpFlagsFirst;
if((flags & TH_SYN)!=0 && (flags & TH_ACK)==0) {
/* Connection request */
copyInt8(0, outBuffer, outBufferBegin,outBufferMax);
} else if((flags & TH_SYN)!=0 && (flags & TH_ACK)!=0) {
/* Connection request response */
copyInt8(1, outBuffer, outBufferBegin,outBufferMax);
} else {
/* Unknown, perhaps in-sequence packet */
copyInt8(0xFF, outBuffer, outBufferBegin,outBufferMax);
}
}
break;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment