summaryrefslogtreecommitdiffstats
path: root/extras/hs-test/suite_veth_test.go
blob: bb703df69818c20f66a921dd28718f5c67199926 (plain)
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
package main

import (
	"time"
)

const (
	// These correspond to names used in yaml config
	serverInterfaceName = "vppsrv"
	clientInterfaceName = "vppcln"
)

type VethsSuite struct {
	HstSuite
}

func (s *VethsSuite) SetupSuite() {
	time.Sleep(1 * time.Second)
	s.HstSuite.SetupSuite()
	s.configureNetworkTopology("2peerVeth")
	s.loadContainerTopology("2peerVeth")
}

func (s *VethsSuite) SetupTest() {
	s.HstSuite.SetupTest()

	// Setup test conditions

	var sessionConfig Stanza
	sessionConfig.
		newStanza("session").
		append("enable").
		append("use-app-socket-api").close()

	// ... For server
	serverContainer := s.getContainerByName("server-vpp")

	cpus := s.AllocateCpus()
	serverVpp, _ := serverContainer.newVppInstance(cpus, sessionConfig)
	s.assertNotNil(serverVpp)

	s.setupServerVpp()

	// ... For client
	clientContainer := s.getContainerByName("client-vpp")

	cpus = s.AllocateCpus()
	clientVpp, _ := clientContainer.newVppInstance(cpus, sessionConfig)
	s.assertNotNil(clientVpp)

	s.setupClientVpp()
}

func (s *VethsSuite) setupServerVpp() {
	serverVpp := s.getContainerByName("server-vpp").vppInstance

	err := serverVpp.start()
	s.assertNil(err)

	serverVeth := s.netInterfaces[serverInterfaceName]
	idx, err := serverVpp.createAfPacket(serverVeth)
	s.assertNil(err)
	s.assertNotEqual(0, idx)

	namespaceSecret := "1"
	err = serverVpp.addAppNamespace(1, idx, namespaceSecret)
	s.assertNil(err)
}

func (s *VethsSuite) setupClientVpp() {
	clientVpp := s.getContainerByName("client-vpp").vppInstance

	err := clientVpp.start()
	s.assertNil(err)

	clientVeth := s.netInterfaces[clientInterfaceName]
	idx, err := clientVpp.createAfPacket(clientVeth)
	s.assertNil(err)
	s.assertNotEqual(0, idx)

	clientNamespaceSecret := "2"
	err = clientVpp.addAppNamespace(2, idx, clientNamespaceSecret)
	s.assertNil(err)
}