Skip to content

Commit 9ee5b9f

Browse files
committed
changef bfd dump + added bfd to rest
Signed-off-by: Vladimir Lavor <[email protected]>
1 parent d6c86a1 commit 9ee5b9f

12 files changed

+488
-386
lines changed

cmd/vpp-agent-ctl/data_cmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (ctl *VppAgentCtl) createBfdSession() {
190190
{
191191
Interface: "memif1",
192192
Enabled: true,
193-
SourceAddress: "192.168.1.2",
193+
SourceAddress: "172.125.40.1",
194194
DestinationAddress: "20.10.0.5",
195195
RequiredMinRxInterval: 8,
196196
DesiredMinTxInterval: 3,

plugins/rest/plugin_impl_rest.go

+24-28
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ import (
2020
"git.fd.io/govpp.git/api"
2121
"github.com/ligato/cn-infra/flavors/local"
2222
"github.com/ligato/cn-infra/rpc/rest"
23+
"github.com/ligato/cn-infra/utils/safeclose"
2324
"github.com/ligato/vpp-agent/plugins/govppmux"
2425
"github.com/ligato/vpp-agent/plugins/vpp"
2526
aclvppcalls "github.com/ligato/vpp-agent/plugins/vpp/aclplugin/vppcalls"
26-
"github.com/ligato/vpp-agent/plugins/vpp/ifplugin/ifaceidx"
2727
ifvppcalls "github.com/ligato/vpp-agent/plugins/vpp/ifplugin/vppcalls"
28-
"github.com/ligato/vpp-agent/plugins/vpp/l2plugin/l2idx"
2928
l2vppcalls "github.com/ligato/vpp-agent/plugins/vpp/l2plugin/vppcalls"
3029
"github.com/ligato/vpp-agent/plugins/vpp/model/acl"
3130
"github.com/ligato/vpp-agent/plugins/vpp/model/interfaces"
@@ -51,13 +50,10 @@ type Plugin struct {
5150
vppChan api.Channel
5251
dumpChan api.Channel
5352

54-
// Indexes
55-
ifIndexes ifaceidx.SwIfIndex
56-
bdIndexes l2idx.BDIndex
57-
5853
// Handlers
5954
aclHandler aclvppcalls.AclVppRead
6055
ifHandler ifvppcalls.IfVppRead
56+
bfdHandler ifvppcalls.BfdVppRead
6157
bdHandler l2vppcalls.BridgeDomainVppRead
6258
fibHandler l2vppcalls.FibVppRead
6359
xcHandler l2vppcalls.XConnectVppRead
@@ -78,6 +74,10 @@ type indexItem struct {
7874

7975
// Init initializes the Rest Plugin
8076
func (plugin *Plugin) Init() (err error) {
77+
// Check VPP dependency
78+
if plugin.VPP == nil {
79+
return fmt.Errorf("REST plugin requires VPP plugin API")
80+
}
8181
// VPP channels
8282
if plugin.vppChan, err = plugin.GoVppmux.NewAPIChannel(); err != nil {
8383
return err
@@ -86,10 +86,8 @@ func (plugin *Plugin) Init() (err error) {
8686
return err
8787
}
8888
// Indexes
89-
if plugin.VPP != nil {
90-
plugin.ifIndexes = plugin.VPP.GetSwIfIndexes()
91-
plugin.bdIndexes = plugin.VPP.GetBDIndexes()
92-
}
89+
ifIndexes := plugin.VPP.GetSwIfIndexes()
90+
bdIndexes := plugin.VPP.GetBDIndexes()
9391

9492
// Initialize handlers
9593
if plugin.aclHandler, err = aclvppcalls.NewAclVppHandler(plugin.vppChan, plugin.dumpChan, nil); err != nil {
@@ -98,21 +96,18 @@ func (plugin *Plugin) Init() (err error) {
9896
if plugin.ifHandler, err = ifvppcalls.NewIfVppHandler(plugin.vppChan, plugin.Log, nil); err != nil {
9997
return err
10098
}
101-
if plugin.ifIndexes != nil {
102-
if plugin.bdHandler, err = l2vppcalls.NewBridgeDomainVppHandler(plugin.vppChan, plugin.ifIndexes, plugin.Log, nil); err != nil {
103-
return err
104-
}
99+
if plugin.bfdHandler, err = ifvppcalls.NewBfdVppHandler(plugin.vppChan, ifIndexes, plugin.Log, nil); err != nil {
100+
return err
105101
}
106-
if plugin.ifIndexes != nil && plugin.bdIndexes != nil {
107-
if plugin.fibHandler, err = l2vppcalls.NewFibVppHandler(plugin.vppChan, plugin.dumpChan, make(chan *l2vppcalls.FibLogicalReq),
108-
plugin.ifIndexes, plugin.bdIndexes, plugin.Log, nil); err != nil {
109-
return err
110-
}
102+
if plugin.bdHandler, err = l2vppcalls.NewBridgeDomainVppHandler(plugin.vppChan, ifIndexes, plugin.Log, nil); err != nil {
103+
return err
111104
}
112-
if plugin.ifIndexes != nil {
113-
if plugin.xcHandler, err = l2vppcalls.NewXConnectVppHandler(plugin.vppChan, plugin.ifIndexes, plugin.Log, nil); err != nil {
114-
return err
115-
}
105+
if plugin.fibHandler, err = l2vppcalls.NewFibVppHandler(plugin.vppChan, plugin.dumpChan, make(chan *l2vppcalls.FibLogicalReq),
106+
ifIndexes, bdIndexes, plugin.Log, nil); err != nil {
107+
return err
108+
}
109+
if plugin.xcHandler, err = l2vppcalls.NewXConnectVppHandler(plugin.vppChan, ifIndexes, plugin.Log, nil); err != nil {
110+
return err
116111
}
117112

118113
plugin.indexItems = []indexItem{
@@ -148,10 +143,11 @@ func (plugin *Plugin) AfterInit() (err error) {
148143
if err := plugin.registerInterfaceHandlers(); err != nil {
149144
return err
150145
}
151-
if plugin.bdHandler != nil {
152-
if err := plugin.registerL2Handlers(); err != nil {
153-
return err
154-
}
146+
if err := plugin.registerBfdHandlers(); err != nil {
147+
return err
148+
}
149+
if err := plugin.registerL2Handlers(); err != nil {
150+
return err
155151
}
156152

157153
plugin.HTTPHandlers.RegisterHTTPHandler("/arps", plugin.arpGetHandler, "GET")
@@ -170,5 +166,5 @@ func (plugin *Plugin) AfterInit() (err error) {
170166

171167
// Close is used to clean up resources used by Plugin
172168
func (plugin *Plugin) Close() (err error) {
173-
return nil
169+
return safeclose.Close(plugin.vppChan, plugin.dumpChan)
174170
}

plugins/rest/rest_handlers.go

+24
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
aclcalls "github.com/ligato/vpp-agent/plugins/vpp/aclplugin/vppcalls"
3333
l3plugin "github.com/ligato/vpp-agent/plugins/vpp/l3plugin/vppcalls"
3434
"github.com/ligato/vpp-agent/plugins/vpp/model/acl"
35+
"github.com/ligato/vpp-agent/plugins/vpp/model/bfd"
3536
"github.com/ligato/vpp-agent/plugins/vpp/model/interfaces"
3637
"github.com/ligato/vpp-agent/plugins/vpp/model/l2"
3738
)
@@ -142,6 +143,29 @@ func (plugin *Plugin) registerInterfaceHandlers() error {
142143
return nil
143144
}
144145

146+
func (plugin *Plugin) registerBfdHandlers() error {
147+
// GET BFD configuration
148+
if err := plugin.registerHTTPHandler(bfd.RestBfdKey(), GET, func() (interface{}, error) {
149+
return plugin.bfdHandler.DumpBfdSingleHop()
150+
}); err != nil {
151+
return err
152+
}
153+
// GET BFD sessions
154+
if err := plugin.registerHTTPHandler(bfd.RestSessionKey(), GET, func() (interface{}, error) {
155+
return plugin.bfdHandler.DumpBfdSessions()
156+
}); err != nil {
157+
return err
158+
}
159+
// GET BFD authentication keys
160+
if err := plugin.registerHTTPHandler(bfd.RestAuthKeysKey(), GET, func() (interface{}, error) {
161+
return plugin.bfdHandler.DumpBfdAuthKeys()
162+
}); err != nil {
163+
return err
164+
}
165+
166+
return nil
167+
}
168+
145169
// Registers L2 plugin REST handlers
146170
func (plugin *Plugin) registerL2Handlers() error {
147171
// GET bridge domain IDs

plugins/vpp/ifplugin/bfd_config.go

+35-88
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (plugin *BFDConfigurator) Init(logger logging.PluginLogger, goVppMux govppm
8181
}
8282

8383
// VPP API handler
84-
if plugin.bfdHandler, err = vppcalls.NewBfdVppHandler(plugin.vppChan, plugin.log, plugin.stopwatch); err != nil {
84+
if plugin.bfdHandler, err = vppcalls.NewBfdVppHandler(plugin.vppChan, plugin.ifIndexes, plugin.log, plugin.stopwatch); err != nil {
8585
return err
8686
}
8787

@@ -244,45 +244,6 @@ func (plugin *BFDConfigurator) DeleteBfdSession(bfdInput *bfd.SingleHopBFD_Sessi
244244
return nil
245245
}
246246

247-
// DumpBfdSessions returns a list of all configured BFD sessions
248-
func (plugin *BFDConfigurator) DumpBfdSessions() ([]*bfd.SingleHopBFD_Session, error) {
249-
var bfdSessionList []*bfd.SingleHopBFD_Session
250-
251-
bfdList, err := plugin.bfdHandler.DumpBfdUDPSessions()
252-
if err != nil {
253-
return bfdSessionList, err
254-
}
255-
256-
var wasError error
257-
for _, bfdItem := range bfdList {
258-
// find interface
259-
ifName, _, found := plugin.ifIndexes.LookupName(bfdItem.SwIfIndex)
260-
if !found {
261-
plugin.log.Warnf("required interface %v not found for BFD", bfdItem.SwIfIndex)
262-
}
263-
264-
// Prepare IPv4 IP addresses
265-
var dstAddr net.IP = bfdItem.PeerAddr[:4]
266-
var srcAddr net.IP = bfdItem.LocalAddr[:4]
267-
268-
bfdSessionList = append(bfdSessionList, &bfd.SingleHopBFD_Session{
269-
Interface: ifName,
270-
DestinationAddress: dstAddr.To4().String(),
271-
SourceAddress: srcAddr.To4().String(),
272-
Enabled: true,
273-
DesiredMinTxInterval: bfdItem.DesiredMinTx,
274-
RequiredMinRxInterval: bfdItem.RequiredMinRx,
275-
DetectMultiplier: uint32(bfdItem.DetectMult),
276-
Authentication: &bfd.SingleHopBFD_Session_Authentication{
277-
KeyId: uint32(bfdItem.BfdKeyID),
278-
AdvertisedKeyId: uint32(bfdItem.BfdKeyID),
279-
},
280-
})
281-
}
282-
283-
return bfdSessionList, wasError
284-
}
285-
286247
// ConfigureBfdAuthKey crates new authentication key which can be used for BFD session
287248
func (plugin *BFDConfigurator) ConfigureBfdAuthKey(bfdAuthKey *bfd.SingleHopBFD_Key) error {
288249
plugin.log.Infof("Configuring BFD authentication key with ID %v", bfdAuthKey.Id)
@@ -311,17 +272,21 @@ func (plugin *BFDConfigurator) ModifyBfdAuthKey(oldInput *bfd.SingleHopBFD_Key,
311272
if err != nil {
312273
return fmt.Errorf("error while verifying authentication key usage. Id: %d: %v", oldInput.Id, err)
313274
}
314-
if len(sessionList) != 0 {
275+
if sessionList != nil && len(sessionList.Session) != 0 {
315276
// Authentication Key is used and cannot be removed directly
316-
for _, bfds := range sessionList {
317-
sourceAddr := net.HardwareAddr(bfds.LocalAddr).String()
318-
destAddr := net.HardwareAddr(bfds.PeerAddr).String()
319-
err := plugin.bfdHandler.DeleteBfdUDPSession(bfds.SwIfIndex, sourceAddr, destAddr)
277+
for _, bfds := range sessionList.Session {
278+
sourceAddr := net.HardwareAddr(bfds.SourceAddress).String()
279+
destAddr := net.HardwareAddr(bfds.DestinationAddress).String()
280+
ifIdx, _, found := plugin.ifIndexes.LookupIdx(bfds.Interface)
281+
if !found {
282+
plugin.log.Warnf("Modify BFD auth key: interface index for %s not found", bfds.Interface)
283+
}
284+
err := plugin.bfdHandler.DeleteBfdUDPSession(ifIdx, sourceAddr, destAddr)
320285
if err != nil {
321286
return err
322287
}
323288
}
324-
plugin.log.Debugf("%v session(s) temporary removed", len(sessionList))
289+
plugin.log.Debugf("%v session(s) temporary removed", len(sessionList.Session))
325290
}
326291

327292
err = plugin.bfdHandler.DeleteBfdUDPAuthenticationKey(oldInput)
@@ -334,14 +299,18 @@ func (plugin *BFDConfigurator) ModifyBfdAuthKey(oldInput *bfd.SingleHopBFD_Key,
334299
}
335300

336301
// Recreate BFD sessions if necessary
337-
if len(sessionList) != 0 {
338-
for _, bfdSession := range sessionList {
339-
err := plugin.bfdHandler.AddBfdUDPSessionFromDetails(bfdSession, plugin.keysIndexes)
302+
if sessionList != nil && len(sessionList.Session) != 0 {
303+
for _, bfdSession := range sessionList.Session {
304+
ifIdx, _, found := plugin.ifIndexes.LookupIdx(bfdSession.Interface)
305+
if !found {
306+
plugin.log.Warnf("Modify BFD auth key: interface index for %s not found", bfdSession.Interface)
307+
}
308+
err := plugin.bfdHandler.AddBfdUDPSession(bfdSession, ifIdx, plugin.keysIndexes)
340309
if err != nil {
341310
return err
342311
}
343312
}
344-
plugin.log.Debugf("%v session(s) recreated", len(sessionList))
313+
plugin.log.Debugf("%v session(s) recreated", len(sessionList.Session))
345314
}
346315

347316
return nil
@@ -357,17 +326,19 @@ func (plugin *BFDConfigurator) DeleteBfdAuthKey(bfdInput *bfd.SingleHopBFD_Key)
357326
return fmt.Errorf("error while verifying authentication key usage. Id: %v", bfdInput.Id)
358327
}
359328

360-
if len(sessionList) != 0 {
329+
if sessionList != nil && len(sessionList.Session) != 0 {
361330
// Authentication Key is used and cannot be removed directly
362-
for _, bfds := range sessionList {
363-
sourceAddr := net.IP(bfds.LocalAddr[0:4]).String()
364-
destAddr := net.IP(bfds.PeerAddr[0:4]).String()
365-
err := plugin.bfdHandler.DeleteBfdUDPSession(bfds.SwIfIndex, sourceAddr, destAddr)
331+
for _, bfds := range sessionList.Session {
332+
ifIdx, _, found := plugin.ifIndexes.LookupIdx(bfds.Interface)
333+
if !found {
334+
plugin.log.Warnf("Delete BFD auth key: interface index for %s not found", bfds.Interface)
335+
}
336+
err := plugin.bfdHandler.DeleteBfdUDPSession(ifIdx, bfds.SourceAddress, bfds.DestinationAddress)
366337
if err != nil {
367338
return err
368339
}
369340
}
370-
plugin.log.Debugf("%v session(s) temporary removed", len(sessionList))
341+
plugin.log.Debugf("%v session(s) temporary removed", len(sessionList.Session))
371342
}
372343
err = plugin.bfdHandler.DeleteBfdUDPAuthenticationKey(bfdInput)
373344
if err != nil {
@@ -377,46 +348,22 @@ func (plugin *BFDConfigurator) DeleteBfdAuthKey(bfdInput *bfd.SingleHopBFD_Key)
377348
plugin.keysIndexes.UnregisterName(authKeyIDAsString)
378349
plugin.log.Debugf("BFD authentication key with id %v unregistered", bfdInput.Id)
379350
// Recreate BFD sessions if necessary
380-
if len(sessionList) != 0 {
381-
for _, bfdSession := range sessionList {
382-
err := plugin.bfdHandler.AddBfdUDPSessionFromDetails(bfdSession, plugin.keysIndexes)
351+
if sessionList != nil && len(sessionList.Session) != 0 {
352+
for _, bfdSession := range sessionList.Session {
353+
ifIdx, _, found := plugin.ifIndexes.LookupIdx(bfdSession.Interface)
354+
if !found {
355+
plugin.log.Warnf("Delete BFD auth key: interface index for %s not found", bfdSession.Interface)
356+
}
357+
err := plugin.bfdHandler.AddBfdUDPSession(bfdSession, ifIdx, plugin.keysIndexes)
383358
if err != nil {
384359
return err
385360
}
386361
}
387-
plugin.log.Debugf("%v session(s) recreated", len(sessionList))
362+
plugin.log.Debugf("%v session(s) recreated", len(sessionList.Session))
388363
}
389364
return nil
390365
}
391366

392-
// DumpBFDAuthKeys returns a list of all configured authentication keys
393-
func (plugin *BFDConfigurator) DumpBFDAuthKeys() ([]*bfd.SingleHopBFD_Key, error) {
394-
var bfdAuthKeyList []*bfd.SingleHopBFD_Key
395-
396-
keys, err := plugin.bfdHandler.DumpBfdKeys()
397-
if err != nil {
398-
return bfdAuthKeyList, err
399-
}
400-
401-
for _, key := range keys {
402-
// resolve authentication type
403-
var authType bfd.SingleHopBFD_Key_AuthenticationType
404-
if key.AuthType == 4 {
405-
authType = bfd.SingleHopBFD_Key_KEYED_SHA1
406-
} else {
407-
authType = bfd.SingleHopBFD_Key_METICULOUS_KEYED_SHA1
408-
}
409-
410-
bfdAuthKeyList = append(bfdAuthKeyList, &bfd.SingleHopBFD_Key{
411-
Id: key.ConfKeyID,
412-
AuthKeyIndex: key.ConfKeyID,
413-
AuthenticationType: authType,
414-
})
415-
}
416-
417-
return bfdAuthKeyList, nil
418-
}
419-
420367
// ConfigureBfdEchoFunction is used to setup BFD Echo function on existing interface
421368
func (plugin *BFDConfigurator) ConfigureBfdEchoFunction(bfdInput *bfd.SingleHopBFD_EchoFunction) error {
422369
plugin.log.Infof("Configuring BFD echo function for source interface %v", bfdInput.EchoSourceInterface)

0 commit comments

Comments
 (0)