blob: bb703df69818c20f66a921dd28718f5c67199926 [file] [log] [blame]
Maros Ondrejickadb823ed2022-12-14 16:30:04 +01001package main
2
3import (
4 "time"
5)
6
Maros Ondrejickaffa3f602023-01-26 10:07:29 +01007const (
8 // These correspond to names used in yaml config
9 serverInterfaceName = "vppsrv"
10 clientInterfaceName = "vppcln"
11)
12
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010013type VethsSuite struct {
14 HstSuite
15}
16
17func (s *VethsSuite) SetupSuite() {
18 time.Sleep(1 * time.Second)
Filip Tehlar608d0062023-04-28 10:29:47 +020019 s.HstSuite.SetupSuite()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010020 s.configureNetworkTopology("2peerVeth")
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010021 s.loadContainerTopology("2peerVeth")
22}
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010023
24func (s *VethsSuite) SetupTest() {
Filip Tehlar608d0062023-04-28 10:29:47 +020025 s.HstSuite.SetupTest()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010026
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010027 // Setup test conditions
28
Filip Tehlar608d0062023-04-28 10:29:47 +020029 var sessionConfig Stanza
30 sessionConfig.
Maros Ondrejickae7625d02023-02-28 16:55:01 +010031 newStanza("session").
32 append("enable").
33 append("use-app-socket-api").close()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010034
35 // ... For server
36 serverContainer := s.getContainerByName("server-vpp")
37
Filip Tehlar608d0062023-04-28 10:29:47 +020038 cpus := s.AllocateCpus()
39 serverVpp, _ := serverContainer.newVppInstance(cpus, sessionConfig)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010040 s.assertNotNil(serverVpp)
41
42 s.setupServerVpp()
43
44 // ... For client
45 clientContainer := s.getContainerByName("client-vpp")
46
Filip Tehlar608d0062023-04-28 10:29:47 +020047 cpus = s.AllocateCpus()
48 clientVpp, _ := clientContainer.newVppInstance(cpus, sessionConfig)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010049 s.assertNotNil(clientVpp)
50
51 s.setupClientVpp()
52}
53
54func (s *VethsSuite) setupServerVpp() {
55 serverVpp := s.getContainerByName("server-vpp").vppInstance
56
57 err := serverVpp.start()
58 s.assertNil(err)
59
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010060 serverVeth := s.netInterfaces[serverInterfaceName]
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010061 idx, err := serverVpp.createAfPacket(serverVeth)
62 s.assertNil(err)
63 s.assertNotEqual(0, idx)
64
65 namespaceSecret := "1"
66 err = serverVpp.addAppNamespace(1, idx, namespaceSecret)
67 s.assertNil(err)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010068}
69
70func (s *VethsSuite) setupClientVpp() {
71 clientVpp := s.getContainerByName("client-vpp").vppInstance
72
73 err := clientVpp.start()
74 s.assertNil(err)
75
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010076 clientVeth := s.netInterfaces[clientInterfaceName]
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010077 idx, err := clientVpp.createAfPacket(clientVeth)
78 s.assertNil(err)
79 s.assertNotEqual(0, idx)
80
81 clientNamespaceSecret := "2"
82 err = clientVpp.addAppNamespace(2, idx, clientNamespaceSecret)
83 s.assertNil(err)
84}