-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhistogram.h
57 lines (46 loc) · 1.62 KB
/
histogram.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//---------------------------------------------------------------------------------------------
//
// Copyright (c) 2018, fmad engineering llc
//
// The Creative Commons BY-NC 4.0 International License see LICENSE file for details
//
// Histogram generation logic based on pcap
//
//---------------------------------------------------------------------------------------------
#ifndef _PCAP2JSON_HISTOGRAM_H__
#define _PCAP2JSON_HISTOGRAM_H__
typedef struct PacketInfo_t
{
u32 TSDiff; // 32bit ns time delta between packets
u16 PktSize; // total packet size in length
} __attribute__((packed)) PacketInfo_t;
typedef struct PacketInfoBulk_t
{
u16 Max;
u16 Pos;
PacketInfo_t *PktInfo;
struct PacketInfoBulk_t *Next;
} PacketInfoBulk_t;
#define SET_VLAN_BIT(H, VLANIdx) ((H)->VLAN = ((H)->VLAN | (1 << VLANIdx)))
#define GET_VLAN_BIT(H, VLANIdx) (((H)->VLAN >> VLANIdx) & 1)
#define SET_MPLS_BIT(H, MPLSIdx) ((H)->MPLS = ((H)->MPLS | (1 << MPLSIdx)))
#define GET_MPLS_BIT(H, MPLSIdx) (((H)->MPLS >> MPLSIdx) & 1)
#define HISTOGRAM_SIG_V1 0x01010101
typedef struct HistogramDump_t
{
u32 signature;
u32 FlowID;
u16 MACProto;
u8 IPProto;
u8 IPDSCP;
u8 VLAN :3; // bits for VLAN0, VLAN1 and VLAN2
u8 MPLS :3; // bits for MPLS0, MPLS1 and MPLS2
u8 Flags :2; // unused for now
u64 FirstTS;
u64 TotalPkt;
PacketInfo_t pad[0];
} __attribute__((packed)) HistogramDump_t;
PacketInfoBulk_t* PktInfo_BulkAlloc(u32 MaxPkts);
void PktInfo_Insert(PacketInfoBulk_t **p, u16 Len, u64 Tdiff);
int PktInfo_HistogramPrint(FILE *FP, HistogramDump_t *H, PacketInfoBulk_t *P);
#endif