blob: c3038ca3727f7e16a39c0701187c8b72869d33fb [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
Adrian Villinb9464cd2024-05-27 09:52:59 -040053 serverVpp, err := serverContainer.newVppInstance(serverContainer.allocatedCpus, sessionConfig)
Adrian Villincee15aa2024-03-14 11:42:55 -040054 s.assertNotNil(serverVpp, fmt.Sprint(err))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010055
56 s.setupServerVpp()
57
58 // ... For client
59 clientContainer := s.getContainerByName("client-vpp")
60
Adrian Villinb9464cd2024-05-27 09:52:59 -040061 clientVpp, err := clientContainer.newVppInstance(clientContainer.allocatedCpus, sessionConfig)
Adrian Villincee15aa2024-03-14 11:42:55 -040062 s.assertNotNil(clientVpp, fmt.Sprint(err))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010063
64 s.setupClientVpp()
65}
66
67func (s *VethsSuite) setupServerVpp() {
68 serverVpp := s.getContainerByName("server-vpp").vppInstance
Filip Tehlar56e17cf2024-01-11 17:17:33 +010069 s.assertNil(serverVpp.start())
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010070
adrianvillin28bd8f02024-02-13 06:00:02 -050071 serverVeth := s.getInterfaceByName(serverInterfaceName)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010072 idx, err := serverVpp.createAfPacket(serverVeth)
Adrian Villincee15aa2024-03-14 11:42:55 -040073 s.assertNil(err, fmt.Sprint(err))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010074 s.assertNotEqual(0, idx)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010075}
76
77func (s *VethsSuite) setupClientVpp() {
78 clientVpp := s.getContainerByName("client-vpp").vppInstance
Filip Tehlar56e17cf2024-01-11 17:17:33 +010079 s.assertNil(clientVpp.start())
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010080
adrianvillin28bd8f02024-02-13 06:00:02 -050081 clientVeth := s.getInterfaceByName(clientInterfaceName)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010082 idx, err := clientVpp.createAfPacket(clientVeth)
Adrian Villincee15aa2024-03-14 11:42:55 -040083 s.assertNil(err, fmt.Sprint(err))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010084 s.assertNotEqual(0, idx)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010085}
Adrian Villincee15aa2024-03-14 11:42:55 -040086
87var _ = Describe("VethsSuite", Ordered, ContinueOnFailure, func() {
88 var s VethsSuite
89 BeforeAll(func() {
90 s.SetupSuite()
91 })
92 BeforeEach(func() {
93 s.SetupTest()
94 })
95 AfterAll(func() {
96 s.TearDownSuite()
97
98 })
99 AfterEach(func() {
100 s.TearDownTest()
101 })
102
103 // https://onsi.github.io/ginkgo/#dynamically-generating-specs
104 for _, test := range vethTests {
105 test := test
106 pc := reflect.ValueOf(test).Pointer()
107 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -0400108 testName := strings.Split(funcValue.Name(), ".")[2]
109 It(testName, func(ctx SpecContext) {
110 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -0400111 test(&s)
112 }, SpecTimeout(time.Minute*5))
113 }
114})
115
116var _ = Describe("VethsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
117 var s VethsSuite
118 BeforeAll(func() {
119 s.SetupSuite()
120 })
121 BeforeEach(func() {
122 s.SetupTest()
123 })
124 AfterAll(func() {
125 s.TearDownSuite()
Adrian Villincee15aa2024-03-14 11:42:55 -0400126 })
127 AfterEach(func() {
128 s.TearDownTest()
129 })
130
131 // https://onsi.github.io/ginkgo/#dynamically-generating-specs
132 for _, test := range vethSoloTests {
133 test := test
134 pc := reflect.ValueOf(test).Pointer()
135 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -0400136 testName := strings.Split(funcValue.Name(), ".")[2]
137 It(testName, Label("SOLO"), func(ctx SpecContext) {
138 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -0400139 test(&s)
140 }, SpecTimeout(time.Minute*5))
141 }
142})