-
Notifications
You must be signed in to change notification settings - Fork 208
/
client.go
59 lines (45 loc) · 1.36 KB
/
client.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
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package tests
import (
"context"
"fmt"
"github.com/cilium/cilium-cli/connectivity/check"
)
// ClientToClient sends an ICMP packet from each client Pod
// to each client Pod in the test context.
func ClientToClient() check.Scenario {
return &clientToClient{}
}
// clientToClient implements a Scenario.
type clientToClient struct{}
func (s *clientToClient) Name() string {
return "client-to-client"
}
func (s *clientToClient) Run(ctx context.Context, t *check.Test) {
var i int
ct := t.Context()
for _, src := range ct.ClientPods() {
src := src // copy to avoid memory aliasing when using reference
for _, dst := range ct.ClientPods() {
if src.Pod.Status.PodIP == dst.Pod.Status.PodIP {
// Currently we only get flows once per IP,
// skip pings to self.
continue
}
dst := dst // copy to avoid memory aliasing when using reference
t.ForEachIPFamily(func(ipFam check.IPFamily) {
t.NewAction(s, fmt.Sprintf("ping-%d", i), &src, &dst, ipFam).Run(func(a *check.Action) {
a.ExecInPod(ctx, ct.PingCommand(dst, ipFam))
a.ValidateFlows(ctx, src, a.GetEgressRequirements(check.FlowParameters{
Protocol: check.ICMP,
}))
a.ValidateFlows(ctx, dst, a.GetIngressRequirements(check.FlowParameters{
Protocol: check.ICMP,
}))
})
})
i++
}
}
}