@@ -40,20 +40,23 @@ var (
40
40
RemoteAddress : fmt .Sprintf ("%s:%d" , normalizedIp , serverPort ),
41
41
Role : "ROLE_CLIENT" ,
42
42
SocketFamily : "SOCKET_FAMILY_UNKNOWN" ,
43
- CloseTimestamp : "Not nill time" ,
43
+ CloseTimestamp : types . NotNilTimestamp ,
44
44
}
45
45
46
46
inactiveUnnormalizedConnectionEgress = types.NetworkInfo {
47
47
LocalAddress : "" ,
48
48
RemoteAddress : fmt .Sprintf ("%s:%d" , externalIp , serverPort ),
49
49
Role : "ROLE_CLIENT" ,
50
50
SocketFamily : "SOCKET_FAMILY_UNKNOWN" ,
51
- CloseTimestamp : "Not nill time" ,
51
+ CloseTimestamp : types . NotNilTimestamp ,
52
52
}
53
53
54
54
runtimeConfigDir = "/tmp/collector-test"
55
55
runtimeConfigFile = filepath .Join (runtimeConfigDir , "/runtime_config.yaml" )
56
56
collectorIP = "localhost"
57
+
58
+ ingressIP = "223.42.0.1"
59
+ ingressPort = 1337
57
60
)
58
61
59
62
type RuntimeConfigFileTestSuite struct {
@@ -72,47 +75,42 @@ func (s *RuntimeConfigFileTestSuite) setRuntimeConfig(config types.RuntimeConfig
72
75
s .writeRuntimeConfig (runtimeConfigFile , config .String ())
73
76
}
74
77
75
- func (s * RuntimeConfigFileTestSuite ) runBerserkerContainers () (client , server string ) {
78
+ func (s * RuntimeConfigFileTestSuite ) runNetworkDirectionContainers () (client , server string ) {
79
+
80
+ serverCmd := fmt .Sprintf ("/scripts/prepare-tap.sh -a %s -o && nc -lk %s %d" , ingressIP , ingressIP , ingressPort )
76
81
containerID , err := s .Executor ().StartContainer (
77
82
config.ContainerStartConfig {
78
- Name : "external-connection-ingress-client " ,
83
+ Name : "external-connection-ingress-server " ,
79
84
Image : config .Images ().QaImageByKey ("performance-berserker" ),
80
85
Privileged : true ,
81
86
NetworkMode : "host" ,
82
87
Entrypoint : []string {
83
- "/scripts/init.sh" ,
84
- },
85
- Env : map [string ]string {
86
- "RUST_LOG" : "DEBUG" ,
87
- "IS_CLIENT" : "true" ,
88
+ "sh" , "-c" , serverCmd ,
88
89
},
89
90
},
90
91
)
91
92
s .Require ().NoError (err )
92
- client = common .ContainerShortID (containerID )
93
+ server = common .ContainerShortID (containerID )
93
94
95
+ clientCmd := fmt .Sprintf ("sleep 10; while true; do nc -zv %s %d; sleep 60; done" , ingressIP , ingressPort )
94
96
containerID , err = s .Executor ().StartContainer (
95
97
config.ContainerStartConfig {
96
- Name : "external-connection-ingress-server " ,
98
+ Name : "external-connection-ingress-client " ,
97
99
Image : config .Images ().QaImageByKey ("performance-berserker" ),
98
100
Privileged : true ,
99
101
NetworkMode : "host" ,
100
102
Entrypoint : []string {
101
- "/scripts/init.sh" ,
102
- },
103
- Env : map [string ]string {
104
- "RUST_LOG" : "DEBUG" ,
105
- "IS_CLIENT" : "false" ,
103
+ "sh" , "-c" , clientCmd ,
106
104
},
107
105
},
108
106
)
109
107
s .Require ().NoError (err )
110
- server = common .ContainerShortID (containerID )
108
+ client = common .ContainerShortID (containerID )
111
109
112
110
return client , server
113
111
}
114
112
115
- func (s * RuntimeConfigFileTestSuite ) teardownBerserkerContainers () {
113
+ func (s * RuntimeConfigFileTestSuite ) teardownNetworkDirectionContainers () {
116
114
s .cleanupContainers ("external-connection-ingress-server" , "external-connection-ingress-client" )
117
115
}
118
116
@@ -254,12 +252,8 @@ func (s *RuntimeConfigFileTestSuite) TestRuntimeConfigFileInvalid() {
254
252
}
255
253
256
254
func (s * RuntimeConfigFileTestSuite ) TestRuntimeConfigNetworkIngress () {
257
- client , server := s .runBerserkerContainers ()
258
- defer s .teardownBerserkerContainers ()
259
-
260
- // assert.AssertNoRuntimeConfig(s.T(), collectorIP)
261
- // expectedConnections := []types.NetworkInfo{activeNormalizedConnectionEgress}
262
- // s.Require().True(s.Sensor().ExpectSameElementsConnections(s.T(), server, 10*time.Second, expectedConnections...))
255
+ client , server := s .runNetworkDirectionContainers ()
256
+ defer s .teardownNetworkDirectionContainers ()
263
257
264
258
s .setRuntimeConfig (types.RuntimeConfig {
265
259
Networking : types.NetworkConfig {
@@ -270,22 +264,51 @@ func (s *RuntimeConfigFileTestSuite) TestRuntimeConfigNetworkIngress() {
270
264
},
271
265
})
272
266
273
- common .Sleep (45 * time .Second )
267
+ // Expect both open and close events for the non-aggregated
268
+ // ingress connection. If Collector is aggregating to 255.255.255.255
269
+ // this will fail.
270
+ // We are not concerned with event ordering in this test.
271
+ expectedIngressConnections := []types.NetworkInfo {
272
+ {
273
+ LocalAddress : fmt .Sprintf (":%d" , ingressPort ),
274
+ RemoteAddress : ingressIP ,
275
+ Role : "ROLE_SERVER" ,
276
+ SocketFamily : "SOCKET_FAMILY_UNKNOWN" ,
277
+ CloseTimestamp : types .NotNilTimestamp ,
278
+ },
279
+ {
280
+ LocalAddress : fmt .Sprintf (":%d" , ingressPort ),
281
+ RemoteAddress : ingressIP ,
282
+ Role : "ROLE_SERVER" ,
283
+ SocketFamily : "SOCKET_FAMILY_UNKNOWN" ,
284
+ CloseTimestamp : types .NilTimestamp ,
285
+ },
286
+ }
274
287
275
- fmt .Println (s .Sensor ().Connections (client ))
276
- fmt .Println ("===========" )
277
- fmt .Println (s .Sensor ().Connections (server ))
288
+ expectedEgressConnections := []types.NetworkInfo {
289
+ {
290
+ LocalAddress : "" ,
291
+ RemoteAddress : fmt .Sprintf ("%s:%d" , normalizedIp , ingressPort ),
292
+ Role : "ROLE_CLIENT" ,
293
+ SocketFamily : "SOCKET_FAMILY_UNKNOWN" ,
294
+ CloseTimestamp : types .NotNilTimestamp ,
295
+ },
296
+ {
297
+ LocalAddress : "" ,
298
+ RemoteAddress : fmt .Sprintf ("%s:%d" , normalizedIp , ingressPort ),
299
+ Role : "ROLE_CLIENT" ,
300
+ SocketFamily : "SOCKET_FAMILY_UNKNOWN" ,
301
+ CloseTimestamp : types .NilTimestamp ,
302
+ },
303
+ }
278
304
279
- // assert.AssertExternalIps(s.T(), "ENABLED", collectorIP)
280
- // expectedConnections = append(expectedConnections, activeUnnormalizedConnectionEgress, inactiveNormalizedConnectionEgress)
281
- // common.Sleep(3 * time.Second) // Sleep so that collector has a chance to report connections
282
- // s.Require().True(s.Sensor().ExpectSameElementsConnections(s.T(), client, 10*time.Second, expectedConnections...))
305
+ s .Sensor ().ExpectConnections (s .T (), client , 30 * time .Second , expectedEgressConnections ... )
306
+ s .Sensor ().ExpectConnections (s .T (), server , 30 * time .Second , expectedIngressConnections ... )
283
307
}
284
308
285
309
func (s * RuntimeConfigFileTestSuite ) TestRuntimeConfigNetworkEgress () {
286
- assert .AssertNoRuntimeConfig (s .T (), collectorIP )
287
- expectedConnections := []types.NetworkInfo {activeNormalizedConnectionEgress }
288
- s .Require ().True (s .Sensor ().ExpectSameElementsConnections (s .T (), s .EgressClientContainer , 10 * time .Second , expectedConnections ... ))
310
+ client , server := s .runNetworkDirectionContainers ()
311
+ defer s .teardownNetworkDirectionContainers ()
289
312
290
313
s .setRuntimeConfig (types.RuntimeConfig {
291
314
Networking : types.NetworkConfig {
@@ -296,12 +319,99 @@ func (s *RuntimeConfigFileTestSuite) TestRuntimeConfigNetworkEgress() {
296
319
},
297
320
})
298
321
299
- assert .AssertExternalIps (s .T (), "ENABLED" , collectorIP )
300
- expectedConnections = append (expectedConnections , activeUnnormalizedConnectionEgress , inactiveNormalizedConnectionEgress )
301
- common .Sleep (3 * time .Second ) // Sleep so that collector has a chance to report connections
302
- s .Require ().True (s .Sensor ().ExpectSameElementsConnections (s .T (), s .EgressClientContainer , 10 * time .Second , expectedConnections ... ))
322
+ // Expect both open and close events for the non-aggregated
323
+ // egress connection. If Collector is aggregating to 255.255.255.255
324
+ // this will fail.
325
+ // We are not concerned with event ordering in this test.
326
+ expectedEgressConnections := []types.NetworkInfo {
327
+ {
328
+ LocalAddress : "" ,
329
+ RemoteAddress : fmt .Sprintf ("%s:%d" , ingressIP , ingressPort ),
330
+ Role : "ROLE_CLIENT" ,
331
+ SocketFamily : "SOCKET_FAMILY_UNKNOWN" ,
332
+ CloseTimestamp : types .NotNilTimestamp ,
333
+ },
334
+ {
335
+ LocalAddress : "" ,
336
+ RemoteAddress : fmt .Sprintf ("%s:%d" , ingressIP , ingressPort ),
337
+ Role : "ROLE_CLIENT" ,
338
+ SocketFamily : "SOCKET_FAMILY_UNKNOWN" ,
339
+ CloseTimestamp : types .NilTimestamp ,
340
+ },
341
+ }
342
+
343
+ expectedIngressConnections := []types.NetworkInfo {
344
+ {
345
+ LocalAddress : fmt .Sprintf (":%d" , ingressPort ),
346
+ RemoteAddress : normalizedIp ,
347
+ Role : "ROLE_SERVER" ,
348
+ SocketFamily : "SOCKET_FAMILY_UNKNOWN" ,
349
+ CloseTimestamp : types .NotNilTimestamp ,
350
+ },
351
+ {
352
+ LocalAddress : fmt .Sprintf (":%d" , ingressPort ),
353
+ RemoteAddress : normalizedIp ,
354
+ Role : "ROLE_SERVER" ,
355
+ SocketFamily : "SOCKET_FAMILY_UNKNOWN" ,
356
+ CloseTimestamp : types .NilTimestamp ,
357
+ },
358
+ }
359
+
360
+ s .Require ().True (s .Sensor ().ExpectConnections (s .T (), client , 30 * time .Second , expectedEgressConnections ... ))
361
+ s .Require ().True (s .Sensor ().ExpectConnections (s .T (), server , 30 * time .Second , expectedIngressConnections ... ))
303
362
}
304
363
305
364
func (s * RuntimeConfigFileTestSuite ) TestRuntimeConfigNetworkBoth () {
365
+ client , server := s .runNetworkDirectionContainers ()
366
+ defer s .teardownNetworkDirectionContainers ()
367
+
368
+ s .setRuntimeConfig (types.RuntimeConfig {
369
+ Networking : types.NetworkConfig {
370
+ ExternalIps : types.ExternalIpsConfig {
371
+ Enabled : "ENABLED" ,
372
+ Direction : "BOTH" ,
373
+ },
374
+ },
375
+ })
376
+
377
+ // Expect both open and close events for the non-aggregated
378
+ // egress and ingress connections. If Collector is aggregating to 255.255.255.255
379
+ // this will fail.
380
+ // We are not concerned with event ordering in this test.
381
+ expectedEgressConnections := []types.NetworkInfo {
382
+ {
383
+ LocalAddress : "" ,
384
+ RemoteAddress : fmt .Sprintf ("%s:%d" , ingressIP , ingressPort ),
385
+ Role : "ROLE_CLIENT" ,
386
+ SocketFamily : "SOCKET_FAMILY_UNKNOWN" ,
387
+ CloseTimestamp : types .NotNilTimestamp ,
388
+ },
389
+ {
390
+ LocalAddress : "" ,
391
+ RemoteAddress : fmt .Sprintf ("%s:%d" , ingressIP , ingressPort ),
392
+ Role : "ROLE_CLIENT" ,
393
+ SocketFamily : "SOCKET_FAMILY_UNKNOWN" ,
394
+ CloseTimestamp : types .NilTimestamp ,
395
+ },
396
+ }
397
+
398
+ expectedIngressConnections := []types.NetworkInfo {
399
+ {
400
+ LocalAddress : fmt .Sprintf (":%d" , ingressPort ),
401
+ RemoteAddress : ingressIP ,
402
+ Role : "ROLE_SERVER" ,
403
+ SocketFamily : "SOCKET_FAMILY_UNKNOWN" ,
404
+ CloseTimestamp : types .NotNilTimestamp ,
405
+ },
406
+ {
407
+ LocalAddress : fmt .Sprintf (":%d" , ingressPort ),
408
+ RemoteAddress : ingressIP ,
409
+ Role : "ROLE_SERVER" ,
410
+ SocketFamily : "SOCKET_FAMILY_UNKNOWN" ,
411
+ CloseTimestamp : types .NilTimestamp ,
412
+ },
413
+ }
306
414
415
+ s .Require ().True (s .Sensor ().ExpectConnections (s .T (), client , 30 * time .Second , expectedEgressConnections ... ))
416
+ s .Require ().True (s .Sensor ().ExpectConnections (s .T (), server , 30 * time .Second , expectedIngressConnections ... ))
307
417
}
0 commit comments