blob: d47bf8c52a934caa350de511164b3d4a84677a79 [file] [log] [blame]
Maros Ondrejickadb823ed2022-12-14 16:30:04 +01001package main
2
3import (
Adrian Villincee15aa2024-03-14 11:42:55 -04004 "fmt"
5 "reflect"
6 "runtime"
7 "strings"
Maros Ondrejickadb823ed2022-12-14 16:30:04 +01008 "time"
Adrian Villincee15aa2024-03-14 11:42:55 -04009
10 . "github.com/onsi/ginkgo/v2"
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010011)
12
adrianvillin28bd8f02024-02-13 06:00:02 -050013// These correspond to names used in yaml config
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010014const (
adrianvillinfbf5f2b2024-02-13 03:26:25 -050015 serverInterfaceName = "srv"
16 clientInterfaceName = "cln"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010017)
18
Adrian Villincee15aa2024-03-14 11:42:55 -040019var vethTests = []func(s *VethsSuite){}
20var vethSoloTests = []func(s *VethsSuite){}
21
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010022type VethsSuite struct {
23 HstSuite
24}
25
Adrian Villincee15aa2024-03-14 11:42:55 -040026func registerVethTests(tests ...func(s *VethsSuite)) {
27 vethTests = append(vethTests, tests...)
28}
29func registerSoloVethTests(tests ...func(s *VethsSuite)) {
30 vethSoloTests = append(vethSoloTests, tests...)
31}
32
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010033func (s *VethsSuite) SetupSuite() {
34 time.Sleep(1 * time.Second)
Filip Tehlar608d0062023-04-28 10:29:47 +020035 s.HstSuite.SetupSuite()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010036 s.configureNetworkTopology("2peerVeth")
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010037 s.loadContainerTopology("2peerVeth")
38}
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010039
40func (s *VethsSuite) SetupTest() {
Filip Tehlar608d0062023-04-28 10:29:47 +020041 s.HstSuite.SetupTest()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010042
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010043 // Setup test conditions
Filip Tehlar608d0062023-04-28 10:29:47 +020044 var sessionConfig Stanza
45 sessionConfig.
Maros Ondrejickae7625d02023-02-28 16:55:01 +010046 newStanza("session").
47 append("enable").
48 append("use-app-socket-api").close()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010049
50 // ... For server
51 serverContainer := s.getContainerByName("server-vpp")
52
Filip Tehlar608d0062023-04-28 10:29:47 +020053 cpus := s.AllocateCpus()
adrianvillin7c675472024-02-12 02:44:53 -050054 serverVpp, err := serverContainer.newVppInstance(cpus, sessionConfig)
Adrian Villincee15aa2024-03-14 11:42:55 -040055 s.assertNotNil(serverVpp, fmt.Sprint(err))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010056
57 s.setupServerVpp()
58
59 // ... For client
60 clientContainer := s.getContainerByName("client-vpp")
61
Filip Tehlar608d0062023-04-28 10:29:47 +020062 cpus = s.AllocateCpus()
adrianvillin7c675472024-02-12 02:44:53 -050063 clientVpp, err := clientContainer.newVppInstance(cpus, sessionConfig)
Adrian Villincee15aa2024-03-14 11:42:55 -040064 s.assertNotNil(clientVpp, fmt.Sprint(err))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010065
66 s.setupClientVpp()
67}
68
69func (s *VethsSuite) setupServerVpp() {
70 serverVpp := s.getContainerByName("server-vpp").vppInstance
Filip Tehlar56e17cf2024-01-11 17:17:33 +010071 s.assertNil(serverVpp.start())
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010072
adrianvillin28bd8f02024-02-13 06:00:02 -050073 serverVeth := s.getInterfaceByName(serverInterfaceName)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010074 idx, err := serverVpp.createAfPacket(serverVeth)
Adrian Villincee15aa2024-03-14 11:42:55 -040075 s.assertNil(err, fmt.Sprint(err))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010076 s.assertNotEqual(0, idx)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010077}
78
79func (s *VethsSuite) setupClientVpp() {
80 clientVpp := s.getContainerByName("client-vpp").vppInstance
Filip Tehlar56e17cf2024-01-11 17:17:33 +010081 s.assertNil(clientVpp.start())
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010082
adrianvillin28bd8f02024-02-13 06:00:02 -050083 clientVeth := s.getInterfaceByName(clientInterfaceName)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010084 idx, err := clientVpp.createAfPacket(clientVeth)
Adrian Villincee15aa2024-03-14 11:42:55 -040085 s.assertNil(err, fmt.Sprint(err))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010086 s.assertNotEqual(0, idx)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010087}
Adrian Villincee15aa2024-03-14 11:42:55 -040088
89var _ = Describe("VethsSuite", Ordered, ContinueOnFailure, func() {
90 var s VethsSuite
91 BeforeAll(func() {
92 s.SetupSuite()
93 })
94 BeforeEach(func() {
95 s.SetupTest()
96 })
97 AfterAll(func() {
98 s.TearDownSuite()
99
100 })
101 AfterEach(func() {
102 s.TearDownTest()
103 })
104
105 // https://onsi.github.io/ginkgo/#dynamically-generating-specs
106 for _, test := range vethTests {
107 test := test
108 pc := reflect.ValueOf(test).Pointer()
109 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -0400110 testName := strings.Split(funcValue.Name(), ".")[2]
111 It(testName, func(ctx SpecContext) {
112 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -0400113 test(&s)
114 }, SpecTimeout(time.Minute*5))
115 }
116})
117
118var _ = Describe("VethsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
119 var s VethsSuite
120 BeforeAll(func() {
121 s.SetupSuite()
122 })
123 BeforeEach(func() {
124 s.SetupTest()
125 })
126 AfterAll(func() {
127 s.TearDownSuite()
Adrian Villincee15aa2024-03-14 11:42:55 -0400128 })
129 AfterEach(func() {
130 s.TearDownTest()
131 })
132
133 // https://onsi.github.io/ginkgo/#dynamically-generating-specs
134 for _, test := range vethSoloTests {
135 test := test
136 pc := reflect.ValueOf(test).Pointer()
137 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -0400138 testName := strings.Split(funcValue.Name(), ".")[2]
139 It(testName, Label("SOLO"), func(ctx SpecContext) {
140 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -0400141 test(&s)
142 }, SpecTimeout(time.Minute*5))
143 }
144})