@@ -77,40 +77,15 @@ func buildMockConnTrackConfig(isBidirectional bool, outputRecordType []string) *
7777 }
7878}
7979
80- func newMockRecordConnAB (srcIP string , srcPort int , dstIP string , dstPort int , protocol int , bytesAB , bytesBA , packetsAB , packetsBA , numFlowLogs float64 ) config.GenericMap {
81- return config.GenericMap {
82- "SrcAddr" : srcIP ,
83- "SrcPort" : srcPort ,
84- "DstAddr" : dstIP ,
85- "DstPort" : dstPort ,
86- "Proto" : protocol ,
87- "Bytes_AB" : bytesAB ,
88- "Bytes_BA" : bytesBA ,
89- "Packets_AB" : packetsAB ,
90- "Packets_BA" : packetsBA ,
91- "numFlowLogs" : numFlowLogs ,
92- }
93- }
94-
95- func newMockRecordConn (srcIP string , srcPort int , dstIP string , dstPort int , protocol int , bytes , packets , numFlowLogs float64 ) config.GenericMap {
96- return config.GenericMap {
97- "SrcAddr" : srcIP ,
98- "SrcPort" : srcPort ,
99- "DstAddr" : dstIP ,
100- "DstPort" : dstPort ,
101- "Proto" : protocol ,
102- "Bytes" : bytes ,
103- "Packets" : packets ,
104- "numFlowLogs" : numFlowLogs ,
105- }
106- }
107-
10880func TestTrack (t * testing.T ) {
10981 ipA := "10.0.0.1"
11082 ipB := "10.0.0.2"
11183 portA := 9001
11284 portB := 9002
11385 protocol := 6
86+ hashId := "705baa5149302fa1"
87+ hashIdAB := "705baa5149302fa1"
88+ hashIdBA := "cc40f571f40f3111"
11489
11590 flAB1 := newMockFlowLog (ipA , portA , ipB , portB , protocol , 111 , 11 )
11691 flAB2 := newMockFlowLog (ipA , portA , ipB , portB , protocol , 222 , 22 )
@@ -127,41 +102,41 @@ func TestTrack(t *testing.T) {
127102 buildMockConnTrackConfig (true , []string {"newConnection" }),
128103 []config.GenericMap {flAB1 , flAB2 , flBA3 , flBA4 },
129104 []config.GenericMap {
130- newMockRecordConnAB (ipA , portA , ipB , portB , protocol , 111 , 0 , 11 , 0 , 1 ),
105+ newMockRecordNewConnAB (ipA , portA , ipB , portB , protocol , 111 , 0 , 11 , 0 , 1 ). withHash ( hashId ). get ( ),
131106 },
132107 },
133108 {
134109 "bidirectional, output new connection and flow log" ,
135110 buildMockConnTrackConfig (true , []string {"newConnection" , "flowLog" }),
136111 []config.GenericMap {flAB1 , flAB2 , flBA3 , flBA4 },
137112 []config.GenericMap {
138- newMockRecordConnAB (ipA , portA , ipB , portB , protocol , 111 , 0 , 11 , 0 , 1 ),
139- flAB1 ,
140- flAB2 ,
141- flBA3 ,
142- flBA4 ,
113+ newMockRecordNewConnAB (ipA , portA , ipB , portB , protocol , 111 , 0 , 11 , 0 , 1 ). withHash ( hashId ). get ( ),
114+ newMockRecordFromFlowLog ( flAB1 ). withHash ( hashId ). get () ,
115+ newMockRecordFromFlowLog ( flAB2 ). withHash ( hashId ). get () ,
116+ newMockRecordFromFlowLog ( flBA3 ). withHash ( hashId ). get () ,
117+ newMockRecordFromFlowLog ( flBA4 ). withHash ( hashId ). get () ,
143118 },
144119 },
145120 {
146121 "unidirectional, output new connection" ,
147122 buildMockConnTrackConfig (false , []string {"newConnection" }),
148123 []config.GenericMap {flAB1 , flAB2 , flBA3 , flBA4 },
149124 []config.GenericMap {
150- newMockRecordConn (ipA , portA , ipB , portB , protocol , 111 , 11 , 1 ),
151- newMockRecordConn (ipB , portB , ipA , portA , protocol , 333 , 33 , 1 ),
125+ newMockRecordNewConn (ipA , portA , ipB , portB , protocol , 111 , 11 , 1 ). withHash ( hashIdAB ). get ( ),
126+ newMockRecordNewConn (ipB , portB , ipA , portA , protocol , 333 , 33 , 1 ). withHash ( hashIdBA ). get ( ),
152127 },
153128 },
154129 {
155130 "unidirectional, output new connection and flow log" ,
156131 buildMockConnTrackConfig (false , []string {"newConnection" , "flowLog" }),
157132 []config.GenericMap {flAB1 , flAB2 , flBA3 , flBA4 },
158133 []config.GenericMap {
159- newMockRecordConn (ipA , portA , ipB , portB , protocol , 111 , 11 , 1 ),
160- flAB1 ,
161- flAB2 ,
162- newMockRecordConn (ipB , portB , ipA , portA , protocol , 333 , 33 , 1 ),
163- flBA3 ,
164- flBA4 ,
134+ newMockRecordNewConn (ipA , portA , ipB , portB , protocol , 111 , 11 , 1 ). withHash ( hashIdAB ). get ( ),
135+ newMockRecordFromFlowLog ( flAB1 ). withHash ( hashIdAB ). get () ,
136+ newMockRecordFromFlowLog ( flAB2 ). withHash ( hashIdAB ). get () ,
137+ newMockRecordNewConn (ipB , portB , ipA , portA , protocol , 333 , 33 , 1 ). withHash ( hashIdBA ). get ( ),
138+ newMockRecordFromFlowLog ( flBA3 ). withHash ( hashIdBA ). get () ,
139+ newMockRecordFromFlowLog ( flBA4 ). withHash ( hashIdBA ). get () ,
165140 },
166141 },
167142 }
@@ -191,6 +166,7 @@ func TestEndConn_Bidirectional(t *testing.T) {
191166 portA := 9001
192167 portB := 9002
193168 protocol := 6
169+ hashId := "705baa5149302fa1"
194170
195171 flAB1 := newMockFlowLog (ipA , portA , ipB , portB , protocol , 111 , 11 )
196172 flAB2 := newMockFlowLog (ipA , portA , ipB , portB , protocol , 222 , 22 )
@@ -208,25 +184,25 @@ func TestEndConn_Bidirectional(t *testing.T) {
208184 startTime .Add (0 * time .Second ),
209185 []config.GenericMap {flAB1 },
210186 []config.GenericMap {
211- newMockRecordConnAB (ipA , portA , ipB , portB , protocol , 111 , 0 , 11 , 0 , 1 ),
212- flAB1 ,
187+ newMockRecordNewConnAB (ipA , portA , ipB , portB , protocol , 111 , 0 , 11 , 0 , 1 ). withHash ( hashId ). get ( ),
188+ newMockRecordFromFlowLog ( flAB1 ). withHash ( hashId ). get () ,
213189 },
214190 },
215191 {
216192 "10s: flow AB and BA" ,
217193 startTime .Add (10 * time .Second ),
218194 []config.GenericMap {flAB2 , flBA3 },
219195 []config.GenericMap {
220- flAB2 ,
221- flBA3 ,
196+ newMockRecordFromFlowLog ( flAB2 ). withHash ( hashId ). get () ,
197+ newMockRecordFromFlowLog ( flBA3 ). withHash ( hashId ). get () ,
222198 },
223199 },
224200 {
225201 "20s: flow BA" ,
226202 startTime .Add (20 * time .Second ),
227203 []config.GenericMap {flBA4 },
228204 []config.GenericMap {
229- flBA4 ,
205+ newMockRecordFromFlowLog ( flBA4 ). withHash ( hashId ). get () ,
230206 },
231207 },
232208 {
@@ -240,7 +216,7 @@ func TestEndConn_Bidirectional(t *testing.T) {
240216 startTime .Add (51 * time .Second ),
241217 nil ,
242218 []config.GenericMap {
243- newMockRecordConnAB (ipA , portA , ipB , portB , protocol , 333 , 777 , 33 , 77 , 4 ),
219+ newMockRecordEndConnAB (ipA , portA , ipB , portB , protocol , 333 , 777 , 33 , 77 , 4 ). withHash ( hashId ). get ( ),
244220 },
245221 },
246222 }
@@ -272,6 +248,8 @@ func TestEndConn_Unidirectional(t *testing.T) {
272248 portA := 9001
273249 portB := 9002
274250 protocol := 6
251+ hashIdAB := "705baa5149302fa1"
252+ hashIdBA := "cc40f571f40f3111"
275253
276254 flAB1 := newMockFlowLog (ipA , portA , ipB , portB , protocol , 111 , 11 )
277255 flAB2 := newMockFlowLog (ipA , portA , ipB , portB , protocol , 222 , 22 )
@@ -289,26 +267,26 @@ func TestEndConn_Unidirectional(t *testing.T) {
289267 startTime .Add (0 * time .Second ),
290268 []config.GenericMap {flAB1 },
291269 []config.GenericMap {
292- newMockRecordConn (ipA , portA , ipB , portB , protocol , 111 , 11 , 1 ),
293- flAB1 ,
270+ newMockRecordNewConn (ipA , portA , ipB , portB , protocol , 111 , 11 , 1 ). withHash ( hashIdAB ). get ( ),
271+ newMockRecordFromFlowLog ( flAB1 ). withHash ( hashIdAB ). get () ,
294272 },
295273 },
296274 {
297275 "10s: flow AB and BA" ,
298276 startTime .Add (10 * time .Second ),
299277 []config.GenericMap {flAB2 , flBA3 },
300278 []config.GenericMap {
301- flAB2 ,
302- newMockRecordConn (ipB , portB , ipA , portA , protocol , 333 , 33 , 1 ),
303- flBA3 ,
279+ newMockRecordFromFlowLog ( flAB2 ). withHash ( hashIdAB ). get () ,
280+ newMockRecordNewConn (ipB , portB , ipA , portA , protocol , 333 , 33 , 1 ). withHash ( hashIdBA ). get ( ),
281+ newMockRecordFromFlowLog ( flBA3 ). withHash ( hashIdBA ). get () ,
304282 },
305283 },
306284 {
307285 "20s: flow BA" ,
308286 startTime .Add (20 * time .Second ),
309287 []config.GenericMap {flBA4 },
310288 []config.GenericMap {
311- flBA4 ,
289+ newMockRecordFromFlowLog ( flBA4 ). withHash ( hashIdBA ). get () ,
312290 },
313291 },
314292 {
@@ -322,7 +300,7 @@ func TestEndConn_Unidirectional(t *testing.T) {
322300 startTime .Add (41 * time .Second ),
323301 nil ,
324302 []config.GenericMap {
325- newMockRecordConn (ipA , portA , ipB , portB , protocol , 333 , 33 , 2 ),
303+ newMockRecordEndConn (ipA , portA , ipB , portB , protocol , 333 , 33 , 2 ). withHash ( hashIdAB ). get ( ),
326304 },
327305 },
328306 {
@@ -336,7 +314,7 @@ func TestEndConn_Unidirectional(t *testing.T) {
336314 startTime .Add (51 * time .Second ),
337315 nil ,
338316 []config.GenericMap {
339- newMockRecordConn (ipB , portB , ipA , portA , protocol , 777 , 77 , 2 ),
317+ newMockRecordEndConn (ipB , portB , ipA , portA , protocol , 777 , 77 , 2 ). withHash ( hashIdBA ). get ( ),
340318 },
341319 },
342320 }
0 commit comments