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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
// Suite for Envoy proxy testing
//
// The topology consists of 4 containers: curl (client), VPP (session layer), Envoy (proxy), nginx (target HTTP server).
// VPP has 2 tap interfaces configured, one for client network and second for server/target network.
package hst
import (
"fmt"
. "github.com/onsi/ginkgo/v2"
"reflect"
"runtime"
"strings"
)
const (
VppContainerName = "vpp"
EnvoyProxyContainerName = "envoy-vcl"
)
type EnvoyProxySuite struct {
HstSuite
nginxPort uint16
proxyPort uint16
maxTimeout int
}
var envoyProxyTests = map[string][]func(s *EnvoyProxySuite){}
var envoyProxySoloTests = map[string][]func(s *EnvoyProxySuite){}
func RegisterEnvoyProxyTests(tests ...func(s *EnvoyProxySuite)) {
envoyProxyTests[getTestFilename()] = tests
}
func RegisterEnvoyProxySoloTests(tests ...func(s *EnvoyProxySuite)) {
envoyProxySoloTests[getTestFilename()] = tests
}
func (s *EnvoyProxySuite) SetupSuite() {
s.HstSuite.SetupSuite()
s.LoadNetworkTopology("2taps")
s.LoadContainerTopology("envoyProxy")
if *IsVppDebug {
s.maxTimeout = 600
} else {
s.maxTimeout = 60
}
}
func (s *EnvoyProxySuite) SetupTest() {
s.HstSuite.SetupTest()
// VPP
var sessionConfig Stanza
sessionConfig.
NewStanza("session").
Append("enable").
Append("use-app-socket-api").
Append("evt_qs_memfd_seg").
Append("event-queue-length 100000")
vppContainer := s.GetContainerByName(VppContainerName)
vpp, err := vppContainer.newVppInstance(vppContainer.AllocatedCpus, sessionConfig)
s.AssertNotNil(vpp, fmt.Sprint(err))
s.AssertNil(vpp.Start())
clientInterface := s.GetInterfaceByName(ClientTapInterfaceName)
s.AssertNil(vpp.createTap(clientInterface, 1))
serverInterface := s.GetInterfaceByName(ServerTapInterfaceName)
s.AssertNil(vpp.createTap(serverInterface, 2))
vppContainer.Exec("chmod 777 -R %s", vppContainer.GetContainerWorkDir())
// nginx HTTP server
nginxContainer := s.GetTransientContainerByName(NginxServerContainerName)
s.AssertNil(nginxContainer.Create())
s.nginxPort = 80
nginxSettings := struct {
LogPrefix string
Address string
Port uint16
Timeout int
}{
LogPrefix: nginxContainer.Name,
Address: serverInterface.Ip4AddressString(),
Port: s.nginxPort,
Timeout: s.maxTimeout,
}
nginxContainer.CreateConfig(
"/nginx.conf",
"./resources/nginx/nginx_server.conf",
nginxSettings,
)
s.AssertNil(nginxContainer.Start())
// Envoy
envoyContainer := s.GetContainerByName(EnvoyProxyContainerName)
s.AssertNil(envoyContainer.Create())
s.proxyPort = 8080
envoySettings := struct {
LogPrefix string
ServerAddress string
ServerPort uint16
ProxyPort uint16
}{
LogPrefix: envoyContainer.Name,
ServerAddress: serverInterface.Ip4AddressString(),
ServerPort: s.nginxPort,
ProxyPort: s.proxyPort,
}
envoyContainer.CreateConfig(
"/etc/envoy/envoy.yaml",
"resources/envoy/proxy.yaml",
envoySettings,
)
s.AssertNil(envoyContainer.Start())
// Add Ipv4 ARP entry for nginx HTTP server, otherwise first request fail (HTTP error 503)
arp := fmt.Sprintf("set ip neighbor %s %s %s",
serverInterface.Peer.Name(),
serverInterface.Ip4AddressString(),
serverInterface.HwAddress)
vppContainer.VppInstance.Vppctl(arp)
}
func (s *EnvoyProxySuite) TearDownTest() {
if CurrentSpecReport().Failed() {
s.CollectNginxLogs(NginxServerContainerName)
s.CollectEnvoyLogs(EnvoyProxyContainerName)
}
s.HstSuite.TearDownTest()
}
func (s *EnvoyProxySuite) ProxyPort() uint16 {
return s.proxyPort
}
func (s *EnvoyProxySuite) ProxyAddr() string {
return s.GetInterfaceByName(ClientTapInterfaceName).Peer.Ip4AddressString()
}
func (s *EnvoyProxySuite) CurlDownloadResource(uri string) {
args := fmt.Sprintf("-w @/tmp/write_out_download --max-time %d --insecure --noproxy '*' --remote-name --output-dir /tmp %s", s.maxTimeout, uri)
writeOut, log := s.RunCurlContainer(args)
s.AssertContains(writeOut, "GET response code: 200")
s.AssertNotContains(log, "bytes remaining to read")
s.AssertNotContains(log, "Operation timed out")
}
func (s *EnvoyProxySuite) CurlUploadResource(uri, file string) {
args := fmt.Sprintf("-w @/tmp/write_out_upload --max-time %d --insecure --noproxy '*' -T %s %s", s.maxTimeout, file, uri)
writeOut, log := s.RunCurlContainer(args)
s.AssertContains(writeOut, "PUT response code: 201")
s.AssertNotContains(log, "Operation timed out")
}
var _ = Describe("EnvoyProxySuite", Ordered, ContinueOnFailure, func() {
var s EnvoyProxySuite
BeforeAll(func() {
s.SetupSuite()
})
BeforeEach(func() {
s.SetupTest()
})
AfterAll(func() {
s.TearDownSuite()
})
AfterEach(func() {
s.TearDownTest()
})
for filename, tests := range envoyProxyTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, func(ctx SpecContext) {
s.Log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(SuiteTimeout))
}
}
})
var _ = Describe("EnvoyProxySuiteSolo", Ordered, ContinueOnFailure, func() {
var s EnvoyProxySuite
BeforeAll(func() {
s.SetupSuite()
})
BeforeEach(func() {
s.SetupTest()
})
AfterAll(func() {
s.TearDownSuite()
})
AfterEach(func() {
s.TearDownTest()
})
for filename, tests := range envoyProxySoloTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, Label("SOLO"), func(ctx SpecContext) {
s.Log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(SuiteTimeout))
}
}
})
|