blob: 061eee07d1fa435831fc1fc8c2e11850528e729c [file] [log] [blame]
Maros Ondrejickadb823ed2022-12-14 16:30:04 +01001package main
2
3import (
4 "time"
5)
6
adrianvillin28bd8f02024-02-13 06:00:02 -05007// These correspond to names used in yaml config
Maros Ondrejickaffa3f602023-01-26 10:07:29 +01008const (
adrianvillinfbf5f2b2024-02-13 03:26:25 -05009 serverInterfaceName = "srv"
10 clientInterfaceName = "cln"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010011)
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
Filip Tehlar608d0062023-04-28 10:29:47 +020028 var sessionConfig Stanza
29 sessionConfig.
Maros Ondrejickae7625d02023-02-28 16:55:01 +010030 newStanza("session").
31 append("enable").
32 append("use-app-socket-api").close()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010033
34 // ... For server
35 serverContainer := s.getContainerByName("server-vpp")
36
Filip Tehlar608d0062023-04-28 10:29:47 +020037 cpus := s.AllocateCpus()
adrianvillin7c675472024-02-12 02:44:53 -050038 serverVpp, err := serverContainer.newVppInstance(cpus, sessionConfig)
39 s.assertNotNil(serverVpp, err)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010040
41 s.setupServerVpp()
42
43 // ... For client
44 clientContainer := s.getContainerByName("client-vpp")
45
Filip Tehlar608d0062023-04-28 10:29:47 +020046 cpus = s.AllocateCpus()
adrianvillin7c675472024-02-12 02:44:53 -050047 clientVpp, err := clientContainer.newVppInstance(cpus, sessionConfig)
48 s.assertNotNil(clientVpp, err)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010049
50 s.setupClientVpp()
51}
52
53func (s *VethsSuite) setupServerVpp() {
54 serverVpp := s.getContainerByName("server-vpp").vppInstance
Filip Tehlar56e17cf2024-01-11 17:17:33 +010055 s.assertNil(serverVpp.start())
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010056
adrianvillin28bd8f02024-02-13 06:00:02 -050057 serverVeth := s.getInterfaceByName(serverInterfaceName)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010058 idx, err := serverVpp.createAfPacket(serverVeth)
adrianvillin7c675472024-02-12 02:44:53 -050059 s.assertNil(err, err)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010060 s.assertNotEqual(0, idx)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010061}
62
63func (s *VethsSuite) setupClientVpp() {
64 clientVpp := s.getContainerByName("client-vpp").vppInstance
Filip Tehlar56e17cf2024-01-11 17:17:33 +010065 s.assertNil(clientVpp.start())
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010066
adrianvillin28bd8f02024-02-13 06:00:02 -050067 clientVeth := s.getInterfaceByName(clientInterfaceName)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010068 idx, err := clientVpp.createAfPacket(clientVeth)
adrianvillin7c675472024-02-12 02:44:53 -050069 s.assertNil(err, err)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010070 s.assertNotEqual(0, idx)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010071}