blob: f7b1c3da7d882a2c9a08105e5e8ddf9d4fddc119 [file] [log] [blame]
Adrian Villin4677d922024-06-14 09:32:39 +02001package hst
Maros Ondrejickadb823ed2022-12-14 16:30:04 +01002
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 (
Adrian Villin4677d922024-06-14 09:32:39 +020015 ServerInterfaceName = "srv"
16 ClientInterfaceName = "cln"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010017)
18
Adrian Villin681ff3a2024-06-07 06:45:48 -040019var vethTests = map[string][]func(s *VethsSuite){}
20var vethSoloTests = map[string][]func(s *VethsSuite){}
Adrian Villincee15aa2024-03-14 11:42:55 -040021
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010022type VethsSuite struct {
23 HstSuite
24}
25
Adrian Villin4677d922024-06-14 09:32:39 +020026func RegisterVethTests(tests ...func(s *VethsSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040027 vethTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040028}
Adrian Villin4677d922024-06-14 09:32:39 +020029func RegisterSoloVethTests(tests ...func(s *VethsSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040030 vethSoloTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040031}
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()
Adrian Villin4677d922024-06-14 09:32:39 +020036 s.ConfigureNetworkTopology("2peerVeth")
37 s.LoadContainerTopology("2peerVeth")
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010038}
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.
Adrian Villin4677d922024-06-14 09:32:39 +020046 NewStanza("session").
47 Append("enable").
Adrian Villin1fde9992024-06-24 08:14:05 -040048 Append("use-app-socket-api")
49
50 if strings.Contains(CurrentSpecReport().LeafNodeText, "InterruptMode") {
51 sessionConfig.Append("use-private-rx-mqs").Close()
52 s.Log("**********************INTERRUPT MODE**********************")
53 } else {
54 sessionConfig.Close()
55 }
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010056
57 // ... For server
Adrian Villin4677d922024-06-14 09:32:39 +020058 serverContainer := s.GetContainerByName("server-vpp")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010059
Adrian Villin4677d922024-06-14 09:32:39 +020060 serverVpp, err := serverContainer.newVppInstance(serverContainer.AllocatedCpus, sessionConfig)
61 s.AssertNotNil(serverVpp, fmt.Sprint(err))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010062
Adrian Villin4677d922024-06-14 09:32:39 +020063 s.SetupServerVpp()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010064
65 // ... For client
Adrian Villin4677d922024-06-14 09:32:39 +020066 clientContainer := s.GetContainerByName("client-vpp")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010067
Adrian Villin4677d922024-06-14 09:32:39 +020068 clientVpp, err := clientContainer.newVppInstance(clientContainer.AllocatedCpus, sessionConfig)
69 s.AssertNotNil(clientVpp, fmt.Sprint(err))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010070
71 s.setupClientVpp()
72}
73
Adrian Villin4677d922024-06-14 09:32:39 +020074func (s *VethsSuite) SetupServerVpp() {
75 serverVpp := s.GetContainerByName("server-vpp").VppInstance
76 s.AssertNil(serverVpp.Start())
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010077
Adrian Villin4677d922024-06-14 09:32:39 +020078 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010079 idx, err := serverVpp.createAfPacket(serverVeth)
Adrian Villin4677d922024-06-14 09:32:39 +020080 s.AssertNil(err, fmt.Sprint(err))
81 s.AssertNotEqual(0, idx)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010082}
83
84func (s *VethsSuite) setupClientVpp() {
Adrian Villin4677d922024-06-14 09:32:39 +020085 clientVpp := s.GetContainerByName("client-vpp").VppInstance
86 s.AssertNil(clientVpp.Start())
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010087
Adrian Villin4677d922024-06-14 09:32:39 +020088 clientVeth := s.GetInterfaceByName(ClientInterfaceName)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010089 idx, err := clientVpp.createAfPacket(clientVeth)
Adrian Villin4677d922024-06-14 09:32:39 +020090 s.AssertNil(err, fmt.Sprint(err))
91 s.AssertNotEqual(0, idx)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010092}
Adrian Villincee15aa2024-03-14 11:42:55 -040093
94var _ = Describe("VethsSuite", Ordered, ContinueOnFailure, func() {
95 var s VethsSuite
96 BeforeAll(func() {
97 s.SetupSuite()
98 })
99 BeforeEach(func() {
100 s.SetupTest()
101 })
102 AfterAll(func() {
103 s.TearDownSuite()
104
105 })
106 AfterEach(func() {
107 s.TearDownTest()
108 })
109
110 // https://onsi.github.io/ginkgo/#dynamically-generating-specs
Adrian Villin681ff3a2024-06-07 06:45:48 -0400111 for filename, tests := range vethTests {
112 for _, test := range tests {
113 test := test
114 pc := reflect.ValueOf(test).Pointer()
115 funcValue := runtime.FuncForPC(pc)
116 testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
117 It(testName, func(ctx SpecContext) {
Adrian Villin4677d922024-06-14 09:32:39 +0200118 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -0400119 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +0200120 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -0400121 }
Adrian Villincee15aa2024-03-14 11:42:55 -0400122 }
123})
124
125var _ = Describe("VethsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
126 var s VethsSuite
127 BeforeAll(func() {
128 s.SetupSuite()
129 })
130 BeforeEach(func() {
131 s.SetupTest()
132 })
133 AfterAll(func() {
134 s.TearDownSuite()
Adrian Villincee15aa2024-03-14 11:42:55 -0400135 })
136 AfterEach(func() {
137 s.TearDownTest()
138 })
139
140 // https://onsi.github.io/ginkgo/#dynamically-generating-specs
Adrian Villin681ff3a2024-06-07 06:45:48 -0400141 for filename, tests := range vethSoloTests {
142 for _, test := range tests {
143 test := test
144 pc := reflect.ValueOf(test).Pointer()
145 funcValue := runtime.FuncForPC(pc)
146 testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
147 It(testName, Label("SOLO"), func(ctx SpecContext) {
Adrian Villin4677d922024-06-14 09:32:39 +0200148 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -0400149 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +0200150 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -0400151 }
Adrian Villincee15aa2024-03-14 11:42:55 -0400152 }
153})