@@ -46,11 +46,7 @@ import (
4646)
4747
4848var (
49- gVLanID uint32 = 4999
50- gMemIfID uint32
51- gMacInstanceID uint32
52- gIPInstanceID uint32
53- log = logroot .StandardLogger ()
49+ log = logroot .StandardLogger ()
5450)
5551
5652type 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
6774type 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)
96106func 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)
103115func 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
0 commit comments