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

import (
	"time"
)

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

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, err := serverContainer.newVppInstance(cpus, sessionConfig)
	s.assertNotNil(serverVpp, err)

	s.setupServerVpp()

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

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

	s.setupClientVpp()
}

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

	serverVeth := s.getInterfaceByName(serverInterfaceName)
	idx, err := serverVpp.createAfPacket(serverVeth)
	s.assertNil(err, err)
	s.assertNotEqual(0, idx)
}

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

	clientVeth := s.getInterfaceByName(clientInterfaceName)
	idx, err := clientVpp.createAfPacket(clientVeth)
	s.assertNil(err, err)
	s.assertNotEqual(0, idx)
}