Skip to content

Commit c67469f

Browse files
authored
Merge pull request #2 from jozef-slezak/master
Wrap global sequencers of L2 drivers to a struct (because auto tests) + added assertions
2 parents 3b93ede + 07db6b1 commit c67469f

File tree

7 files changed

+125
-35
lines changed

7 files changed

+125
-35
lines changed

controller/cnpdriver/sfcctlr_l2_driver.go

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ import (
4646
)
4747

4848
var (
49-
gVLanID uint32 = 4999
50-
gMemIfID uint32
51-
gMacInstanceID uint32
52-
gIPInstanceID uint32
53-
log = logroot.StandardLogger()
49+
log = logroot.StandardLogger()
5450
)
5551

5652
type sfcCtlrL2CNPDriver struct {
@@ -62,6 +58,17 @@ type sfcCtlrL2CNPDriver struct {
6258
reconcileBefore reconcileCacheType
6359
reconcileAfter reconcileCacheType
6460
reconcileInProgress bool
61+
seq sequencer
62+
}
63+
64+
// sequencer groups all sequences used by L2 driver.
65+
// (instead of using global variables that caused
66+
// problems while running automated tests)
67+
type sequencer struct {
68+
VLanID uint32
69+
MemIfID uint32
70+
MacInstanceID uint32
71+
IPInstanceID uint32
6572
}
6673

6774
type heToEEStateType struct {
@@ -93,13 +100,18 @@ type reconcileCacheType struct {
93100
l3Routes map[string]l3.StaticRoutes_Route
94101
}
95102

103+
// NewRemoteClientTxn new vpp-agent remote client instance on top of key-val DB (ETCD)
104+
// <microserviceLabel> that identifies a specific vpp-agent that needs to be configured
105+
// <dbFactory> returns new instance of DataBroker for accessing key-val DB (ETCD)
96106
func NewRemoteClientTxn(microserviceLabel string, dbFactory func(string) keyval.ProtoBroker) linux.DataChangeDSL {
97107
prefix := servicelabel.GetDifferentAgentPrefix(microserviceLabel)
98108
broker := dbFactory(prefix)
99109
return remoteclient.DataChangeRequestDB(broker)
100110
}
101111

102-
// Init the driver/mode for Native SFC Controller L2 Container Networking Policy
112+
// NewSfcCtlrL2CNPDriver creates new driver/mode for Native SFC Controller L2 Container Networking Policy
113+
// <name> of the driver/plugin
114+
// <dbFactory> returns new instance of DataBroker for accessing key-val DB (ETCD)
103115
func NewSfcCtlrL2CNPDriver(name string, dbFactory func(string) keyval.ProtoBroker) *sfcCtlrL2CNPDriver {
104116

105117
cnpd := &sfcCtlrL2CNPDriver{}
@@ -110,6 +122,8 @@ func NewSfcCtlrL2CNPDriver(name string, dbFactory func(string) keyval.ProtoBroke
110122
cnpd.initL2CNPCache()
111123
cnpd.initReconcileCache()
112124

125+
cnpd.seq.VLanID = 4999
126+
113127
return cnpd
114128
}
115129

@@ -421,8 +435,8 @@ func (cnpd *sfcCtlrL2CNPDriver) WireHostEntityToExternalEntity(he *controller.Ho
421435

422436
// create the vxlan i'f before the BD
423437
ifName := "IF_VXLAN_H2E_" + he.Name + "_" + ee.Name
424-
gVLanID++ // track these at some point
425-
vlanIf, err := cnpd.vxLanCreate(he.Name, ifName, gVLanID, he.LoopbackIpv4, ee.HostVxlan.SourceIpv4)
438+
cnpd.seq.VLanID++ // track these at some point
439+
vlanIf, err := cnpd.vxLanCreate(he.Name, ifName, cnpd.seq.VLanID, he.LoopbackIpv4, ee.HostVxlan.SourceIpv4)
426440
if err != nil {
427441
log.Error("WireHostEntityToExternalEntity: error creating vxlan: '%s'", ifName)
428442
return err
@@ -496,8 +510,8 @@ func (cnpd *sfcCtlrL2CNPDriver) WireInternalsForHostEntity(he *controller.HostEn
496510
var loopbackMacAddress string
497511

498512
if he.LoopbackMacAddr == "" { // if not supplied, generate one
499-
gMacInstanceID++
500-
loopbackMacAddress = formatMacAddress(gMacInstanceID)
513+
cnpd.seq.MacInstanceID++
514+
loopbackMacAddress = formatMacAddress(cnpd.seq.MacInstanceID)
501515

502516
} else {
503517
loopbackMacAddress = he.LoopbackMacAddr
@@ -942,7 +956,7 @@ func (cnpd *sfcCtlrL2CNPDriver) createMemIfPair(sfc *controller.SfcEntity, hostN
942956

943957
// for now just incr the memIfIndex for each pair of memIfs (vnf, vswitch)
944958
// vswitch is master of the (vswitch/vnf) pair
945-
gMemIfID++
959+
cnpd.seq.MemIfID++
946960

947961
var macAddress string
948962
var ipv4Address string
@@ -952,8 +966,8 @@ func (cnpd *sfcCtlrL2CNPDriver) createMemIfPair(sfc *controller.SfcEntity, hostN
952966
if vnfChainElement.Ipv4Addr == "" {
953967
if generateAddresses {
954968
if sfc.SfcIpv4Prefix == "" {
955-
gIPInstanceID++
956-
ipv4Address = formatIpv4Address(gIPInstanceID) + "/24"
969+
cnpd.seq.IPInstanceID++
970+
ipv4Address = formatIpv4Address(cnpd.seq.IPInstanceID) + "/24"
957971
}
958972
}
959973
} else {
@@ -962,24 +976,24 @@ func (cnpd *sfcCtlrL2CNPDriver) createMemIfPair(sfc *controller.SfcEntity, hostN
962976

963977
if vnfChainElement.MacAddr == "" {
964978
if generateAddresses {
965-
gMacInstanceID++
966-
macAddress = formatMacAddress(gMacInstanceID)
979+
cnpd.seq.MacInstanceID++
980+
macAddress = formatMacAddress(cnpd.seq.MacInstanceID)
967981
}
968982
} else {
969983
macAddress = vnfChainElement.MacAddr
970984
}
971985

972986
// create a memif in the vnf container
973987
memIfName := vnfChainElement.PortLabel
974-
if _, err := cnpd.memIfCreate(vnfChainElement.Container, memIfName, gMemIfID,
988+
if _, err := cnpd.memIfCreate(vnfChainElement.Container, memIfName, cnpd.seq.MemIfID,
975989
false, ipv4Address, macAddress); err != nil {
976990
log.Error("createMemIfPair: error creating memIf for container: '%s'", memIfName)
977991
return "", err
978992
}
979993

980994
// now create a memif for the vpp switch
981995
memIfName = "IF_MEMIF_VSWITCH_" + vnfChainElement.Container + "_" + vnfChainElement.PortLabel
982-
memIf, err := cnpd.memIfCreate(vnfChainElement.EtcdVppSwitchKey, memIfName, gMemIfID,
996+
memIf, err := cnpd.memIfCreate(vnfChainElement.EtcdVppSwitchKey, memIfName, cnpd.seq.MemIfID,
983997
true, "", "")
984998
if err != nil {
985999
log.Error("createMemIfPair: error creating memIf for vpp switch: '%s'", memIf.Name)
@@ -1030,16 +1044,16 @@ func (cnpd *sfcCtlrL2CNPDriver) createAFPacketVEthPair(sfc *controller.SfcEntity
10301044
// TODO: figure out how ipam, and macam should be done, for now just start at 1 and increment :-(
10311045
if vnfChainElement.Ipv4Addr == "" {
10321046
if sfc.SfcIpv4Prefix == "" {
1033-
gIPInstanceID++
1034-
ipv4Address = formatIpv4Address(gIPInstanceID) + "/24"
1047+
cnpd.seq.IPInstanceID++
1048+
ipv4Address = formatIpv4Address(cnpd.seq.IPInstanceID) + "/24"
10351049
}
10361050
} else {
10371051
ipv4Address = vnfChainElement.Ipv4Addr + "/24"
10381052
}
10391053
}
10401054
if vnfChainElement.MacAddr == "" {
1041-
gMacInstanceID++
1042-
macAddress = formatMacAddress(gMacInstanceID)
1055+
cnpd.seq.MacInstanceID++
1056+
macAddress = formatMacAddress(cnpd.seq.MacInstanceID)
10431057

10441058
} else {
10451059
macAddress = vnfChainElement.MacAddr
@@ -1070,7 +1084,7 @@ func (cnpd *sfcCtlrL2CNPDriver) createAFPacketVEthPair(sfc *controller.SfcEntity
10701084
afPktIf1, err := cnpd.afPacketCreate(vnfChainElement.Container, vnfChainElement.PortLabel,
10711085
veth1Name, "", "")
10721086
if err != nil {
1073-
log.Error("createAFPacketVEthPair: error creating memIf for vpp switch: '%s'", afPktIf1.Name)
1087+
log.Error("createAFPacketVEthPair: error creating afpacket for vpp switch: '%s'", afPktIf1.Name)
10741088
return "", err
10751089
}
10761090
}
@@ -1079,7 +1093,7 @@ func (cnpd *sfcCtlrL2CNPDriver) createAFPacketVEthPair(sfc *controller.SfcEntity
10791093
afPktName := "IF_AFPIF_VSWITCH_" + vnfChainElement.Container + "_" + vnfChainElement.PortLabel
10801094
afPktIf2, err := cnpd.afPacketCreate(vnfChainElement.EtcdVppSwitchKey, afPktName, veth2Name, "", "")
10811095
if err != nil {
1082-
log.Error("createAFPacketVEthPair: error creating memIf for vpp switch: '%s'", afPktIf2.Name)
1096+
log.Error("createAFPacketVEthPair: error creating afpacket for vpp switch: '%s'", afPktIf2.Name)
10831097
return "", err
10841098
}
10851099

tests/go/itest/agent_test_helpers.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,16 @@ func (t *Then) VppAgentCfgContains(micorserviceLabel string, interfaceBDEtc ...p
163163
found, _, err := db.GetValue(key, ifaceExist)
164164
gomega.Expect(found).Should(gomega.BeTrue(), "interface not found "+key)
165165
gomega.Expect(err).Should(gomega.BeNil(), "error reading "+key)
166-
//TODO enable after gettring rid of globals
167-
// gomega.Expect(ifaceExist).Should(gomega.BeEquivalentTo(ifaceExpected), "error reading "+key)
166+
gomega.Expect(ifaceExist).Should(gomega.BeEquivalentTo(ifaceExpected), "error reading "+key)
168167
case *l2.BridgeDomains_BridgeDomain:
168+
bdExpected := expected.(*l2.BridgeDomains_BridgeDomain)
169+
bdActual := &l2.BridgeDomains_BridgeDomain{}
170+
171+
key := l2.BridgeDomainKey(bdExpected.Name)
172+
found, _, err := db.GetValue(key, bdActual)
173+
gomega.Expect(found).Should(gomega.BeTrue(), "bd not found "+key)
174+
gomega.Expect(err).Should(gomega.BeNil(), "error reading "+key)
175+
gomega.Expect(bdActual).Should(gomega.BeEquivalentTo(bdExpected), "error reading "+key)
169176
}
170177
}
171178
}

tests/go/itest/basic_tcs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func (t *basicTCSuite) TC01ResyncEmptyVpp1Agent(sfcCfg *sfccore.YamlConfig, vppA
3434
t.Then.VppAgentCfgContains("HOST-1", vppAgentCfg...)
3535
t.Then.HTTPGetEntities(sfcCfg)
3636
}
37+
3738
// TC02HTTPPostasserts that vpp agent writes properly vpp-agent configuration
3839
// This TC assumes that vpp-agent configuration was empty before the test.
3940
// Then SFC Controller starts and after that SFC Controller is configured via REST HTTP posts.
@@ -46,4 +47,4 @@ func (t *basicTCSuite) TC02HTTPPost(sfcCfg *sfccore.YamlConfig, vppAgentCfg ...
4647
t.Given.ConfigSFCviaREST(sfcCfg)
4748
t.Then.VppAgentCfgContains("HOST-1", vppAgentCfg...)
4849
t.Then.HTTPGetEntities(sfcCfg)
49-
}
50+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package linuxtestdata
2+
3+
import (
4+
"github.com/ligato/vpp-agent/plugins/linuxplugin/model/interfaces"
5+
)
6+
7+
var Agent1Veth01 = interfaces.LinuxInterfaces_Interface{
8+
Name: "agent1_afpacket",
9+
Enabled: true,
10+
//PhysAddress: "02:00:00:00:00:02",
11+
Mtu: 1500,
12+
Type: interfaces.LinuxInterfaces_VETH,
13+
//IpAddresses: []string{"10.0.0.10/24"},
14+
Veth: &interfaces.LinuxInterfaces_Interface_Veth{
15+
PeerIfName: "_agent1_",
16+
},
17+
}

tests/go/itest/run_all_test.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"github.com/ligato/sfc-controller/tests/go/itest/sfctestdata"
88
//"github.com/ligato/sfc-controller/tests/go/itest/vpptestdata"
99
"github.com/ligato/sfc-controller/tests/go/itest/vpptestdata"
10+
"github.com/ligato/sfc-controller/tests/go/itest/linuxtestdata"
11+
"github.com/golang/protobuf/proto"
1012
)
1113

1214
// Test runs all TC methods of multiple test suites in sequence
@@ -15,16 +17,20 @@ func Test(t *testing.T) {
1517

1618
go func() {
1719
t.Run("basic_tcs", func(t *testing.T) {
18-
suite := &basicTCSuite{T: t}
20+
VPP1MEMIF2_Loopback_VETH := []proto.Message{&vpptestdata.VPP1MEMIF1,
21+
&vpptestdata.VPP1MEMIF2,
22+
&vpptestdata.Agent1Afpacket01,
23+
&vpptestdata.Agent1Loopback,
24+
&linuxtestdata.Agent1Veth01,
25+
&vpptestdata.BD_INTERNAL_EW_HOST1}
26+
1927
t.Run("TC01ResyncEmptyVpp1Agent", func(t *testing.T) {
20-
suite.TC01ResyncEmptyVpp1Agent(&sfctestdata.VPP1MEMIF2,
21-
&vpptestdata.VPP1MEMIF1,
22-
)
28+
suite := &basicTCSuite{T: t}
29+
suite.TC01ResyncEmptyVpp1Agent(&sfctestdata.VPP1MEMIF2_Loopback_VETH, VPP1MEMIF2_Loopback_VETH...)
2330
})
2431
t.Run("TC02HTTPPost", func(t *testing.T) {
25-
suite.TC02HTTPPost(&sfctestdata.VPP1MEMIF2,
26-
&vpptestdata.VPP1MEMIF1,
27-
)
32+
suite := &basicTCSuite{T: t}
33+
suite.TC02HTTPPost(&sfctestdata.VPP1MEMIF2_Loopback_VETH, VPP1MEMIF2_Loopback_VETH...)
2834
})
2935
})
3036
doneChan <- struct{}{}

tests/go/itest/sfctestdata/basic_data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/ligato/sfc-controller/controller/model/controller"
66
)
77

8-
var VPP1MEMIF2 = sfccore.YamlConfig{
8+
var VPP1MEMIF2_Loopback_VETH = sfccore.YamlConfig{
99
HEs: []controller.HostEntity{{
1010
Name: "HOST-1",
1111
//mgmnt_ip_address: "192.168.0.1",

tests/go/itest/vpptestdata/basic_data.go

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package vpptestdata
22

33
import (
44
"github.com/ligato/vpp-agent/plugins/defaultplugins/ifplugin/model/interfaces"
5+
"github.com/ligato/vpp-agent/plugins/defaultplugins/l2plugin/model/l2"
56
)
67

78
var VPP1MEMIF1 = interfaces.Interfaces_Interface{
@@ -29,4 +30,48 @@ var VPP1MEMIF2 = interfaces.Interfaces_Interface{
2930
Id: 2,
3031
SocketFilename: "/tmp/memif.sock",
3132
Master: true,
32-
},}
33+
}}
34+
35+
var BD_INTERNAL_EW_HOST1 = l2.BridgeDomains_BridgeDomain{
36+
Name: "BD_INTERNAL_EW_HOST-1",
37+
Flood: true,
38+
UnknownUnicastFlood: true,
39+
Forward: true,
40+
Learn: true,
41+
ArpTermination: false,
42+
MacAge: 0,
43+
Interfaces: []*l2.BridgeDomains_BridgeDomain_Interfaces{
44+
{Name: "IF_MEMIF_VSWITCH__vpp1_memif1"},
45+
{Name: "IF_MEMIF_VSWITCH__vpp1_memif2"},
46+
{Name: "IF_AFPIF_VSWITCH__agent1_afpacket1"}},
47+
ArpTerminationTable: nil,
48+
}
49+
50+
//time="2017-10-06 11:35:03.62305" level=info msg="ReconcileEnd: add BD key to etcd:
51+
// /vnf-agent/HOST-1/vpp/config/v1/bd/BD_INTERNAL_EW_HOST-1
52+
//
53+
54+
//time= "2017-10-06 11:55:55.48623" level = info msg = "{[name:"agent1_afpacket" enabled:true phys_address:"02:00:00:00:00:02" mtu:1500 namespace:<type:MICROSERVICE_REF_NS > veth:<peer_if_name:"_agent1_" > ]}" loc = "cnpdriver/sfcctlr_l2_driver.go(1394)" logger = defaultLogger tag = 00000000
55+
//TODO time = "2017-10-06 11:55:55.49223" level = info msg = "ReconcileEnd: add i/f key to etcd: /vnf-agent/HOST-1/vpp/config/v1/interface/GigabitEthernet13/0/0{GigabitEthernet13/0/0 ETHERNET_CSMACD true 1500 [8.42.0.2] <nil> <nil> <nil> <nil>}" loc = "cnpdriver/sfcctlr_l2_driver.go(235)" logger = defaultLogger tag = 00000000
56+
57+
var Agent1Afpacket01 = interfaces.Interfaces_Interface{
58+
Name: "IF_AFPIF_VSWITCH__agent1_afpacket1",
59+
Enabled: true,
60+
//PhysAddress: "02:00:00:00:00:02",
61+
Mtu: 1500,
62+
Type: interfaces.InterfaceType_AF_PACKET_INTERFACE,
63+
//IpAddresses: []string{"10.0.0.10/24"},
64+
Afpacket: &interfaces.Interfaces_Interface_Afpacket{
65+
HostIfName: "_agent1_",
66+
},
67+
//namespace:<type:MICROSERVICE_REF_NS > veth:<peer_if_name:"_agent1_" >
68+
}
69+
70+
var Agent1Loopback = interfaces.Interfaces_Interface{
71+
Name: "IF_LOOPBACK_H_HOST-1",
72+
Enabled: true,
73+
PhysAddress: "02:00:00:AA:BB:00",
74+
Mtu: 1500,
75+
Type: interfaces.InterfaceType_SOFTWARE_LOOPBACK,
76+
IpAddresses: []string{"6.0.0.100"},
77+
}

0 commit comments

Comments
 (0)