-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathipfix_test.go
85 lines (71 loc) · 2.61 KB
/
ipfix_test.go
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestMapToJson(t *testing.T) {
myMap := map[string]interface{}{
"packetDeltaCount": "6",
"flowStartMilliseconds": "2017-08-16 15:19:57 -0400 EDT",
"destinationTransportPort": "137",
"ingressInterface": "67108865",
"protocolIdentifier": "17",
"ipClassOfService": "0",
"maximumTTL": "128",
"sourceIPv4Address": "192.168.103.73",
"destinationIPv4Address": "192.168.103.255",
"flowEndMilliseconds": "2017-08-16 15:19:59 -0400 EDT",
"sourceTransportPort": "137",
"egressInterface": "12620",
"layer2SegmentId": "72057594037934957",
"flowDirection": "1",
"vmware_888": "2",
"paddingOctets": "[0]",
"octetDeltaCount": "468",
"nsxSegmentId": "7021",
"flowEndReason": "1",
"tcpControlBits": "0",
"vmware_890": "3",
"vmware_889": "1",
}
jsonStr := mapToJSON(myMap)
expected := "{\"destinationIPv4Address\":\"192.168.103.255\"," +
"\"destinationTransportPort\":\"137\",\"egressInterface\":\"12620\"," +
"\"flowDirection\":\"1\"," +
"\"flowEndMilliseconds\":\"2017-08-16 15:19:59 -0400 EDT\"," +
"\"flowEndReason\":\"1\"," +
"\"flowStartMilliseconds\":\"2017-08-16 15:19:57 -0400 EDT\"," +
"\"ingressInterface\":\"67108865\",\"ipClassOfService\":\"0\"," +
"\"layer2SegmentId\":\"72057594037934957\",\"maximumTTL\":\"128\"," +
"\"nsxSegmentId\":\"7021\",\"octetDeltaCount\":\"468\"," +
"\"packetDeltaCount\":\"6\",\"paddingOctets\":\"[0]\"," +
"\"protocolIdentifier\":\"17\"," +
"\"sourceIPv4Address\":\"192.168.103.73\"," +
"\"sourceTransportPort\":\"137\",\"tcpControlBits\":\"0\"," +
"\"vmware_888\":\"2\",\"vmware_889\":\"1\",\"vmware_890\":\"3\"}"
if jsonStr != expected {
t.Error(
"Expected", expected,
"got", jsonStr,
)
}
}
func TestInitIpfixContext(t *testing.T) {
c := initIpfixContext()
assert.NotNil(t, c)
assert.NotNil(t, c.session)
assert.NotNil(t, c.interpreter)
}
func TestInitIpfixVendors(t *testing.T) {
assert.Empty(t, globalServerOptions.vendors)
c := initIpfixContext()
initIpfixVendors(c.interpreter)
globalServerOptions.vendors = []string{VendorVmwareNSX}
initIpfixVendors(c.interpreter)
globalServerOptions.vendors = []string{VendorVmwareVDS}
initIpfixVendors(c.interpreter)
globalServerOptions.vendors = []string{VendorNokia}
initIpfixVendors(c.interpreter)
globalServerOptions.vendors = []string{VendorVmwareVDS, VendorVmwareNSX, VendorNokia}
initIpfixVendors(c.interpreter)
}