7 "github.com/edwarnicke/exechelper"
10 func testProxyHttpTcp(s *NsSuite, proto string) error {
11 const outputFile = "test.data"
12 const srcFile = "httpTestFile"
13 const fileSize = "10M"
14 stopServer := make(chan struct{}, 1)
15 serverRunning := make(chan struct{}, 1)
20 err := exechelper.Run(fmt.Sprintf("ip netns exec %s truncate -s %s %s", serverNetns, fileSize, srcFile))
21 s.assertNil(err, "failed to run truncate command: " + fmt.Sprint(err))
22 defer func() { os.Remove(srcFile) }()
24 s.log("test file created...")
26 go s.startHttpServer(serverRunning, stopServer, ":666", serverNetns)
27 // TODO better error handling and recovery
30 defer func(chan struct{}) {
31 stopServer <- struct{}{}
34 s.log("http server started...")
36 clientVeth := s.netInterfaces[clientInterface]
37 c := fmt.Sprintf("ip netns exec %s wget --no-proxy --retry-connrefused"+
38 " --retry-on-http-error=503 --tries=10 -O %s ", clientNetns, outputFile)
40 c += " --secure-protocol=TLSv1_3 --no-check-certificate https://"
42 c += fmt.Sprintf("%s:555/%s", clientVeth.ip4AddressString(), srcFile)
44 _, err = exechelper.CombinedOutput(c)
46 defer func() { os.Remove(outputFile) }()
48 s.assertNil(err, "failed to run wget: '%s', cmd: %s", err, c)
49 stopServer <- struct{}{}
51 s.assertNil(assertFileSize(outputFile, srcFile))
55 func configureVppProxy(s *NsSuite, proto string) {
56 serverVeth := s.netInterfaces[serverInterface]
57 clientVeth := s.netInterfaces[clientInterface]
59 testVppProxy := s.getContainerByName("vpp").vppInstance
60 output := testVppProxy.vppctl(
61 "test proxy server server-uri %s://%s/555 client-uri tcp://%s/666",
63 clientVeth.ip4AddressString(),
64 serverVeth.peer.ip4AddressString(),
66 s.log("proxy configured...", output)
69 func (s *NsSuite) TestVppProxyHttpTcp() {
71 configureVppProxy(s, proto)
72 err := testProxyHttpTcp(s, proto)
76 func (s *NsSuite) TestVppProxyHttpTls() {
78 configureVppProxy(s, proto)
79 err := testProxyHttpTcp(s, proto)
83 func configureEnvoyProxy(s *NsSuite) {
84 envoyContainer := s.getContainerByName("envoy")
85 err := envoyContainer.create()
86 s.assertNil(err, "Error creating envoy container: %s", err)
88 serverVeth := s.netInterfaces[serverInterface]
92 Server: serverVeth.peer.ip4AddressString(),
94 envoyContainer.createConfig(
95 "/etc/envoy/envoy.yaml",
96 "resources/envoy/proxy.yaml",
99 s.assertNil(envoyContainer.start())
102 func (s *NsSuite) TestEnvoyProxyHttpTcp() {
103 configureEnvoyProxy(s)
104 err := testProxyHttpTcp(s, "tcp")
105 s.assertNil(err, err)