This repository has been archived by the owner on Aug 3, 2020. It is now read-only.
forked from ligato/vpp-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
span_vppcalls.go
80 lines (66 loc) · 2.13 KB
/
span_vppcalls.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package vpp1908
import (
"fmt"
"github.com/ligato/vpp-agent/plugins/vpp/binapi/vpp1908/span"
"github.com/ligato/vpp-agent/plugins/vpp/ifplugin/vppcalls"
)
// SetSpan enables or disables SPAN on interface
func (h *InterfaceVppHandler) setSpan(ifIdxFrom, ifIdxTo uint32, state, isL2 uint8) error {
req := &span.SwInterfaceSpanEnableDisable{
SwIfIndexFrom: ifIdxFrom,
SwIfIndexTo: ifIdxTo,
State: state,
IsL2: isL2,
}
reply := &span.SwInterfaceSpanEnableDisableReply{}
if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil {
return err
}
return nil
}
// AddSpan enables SPAN on interface
func (h *InterfaceVppHandler) AddSpan(ifIdxFrom, ifIdxTo uint32, direction, isL2 uint8) error {
return h.setSpan(ifIdxFrom, ifIdxTo, direction, isL2)
}
// DelSpan disables SPAN on interface
func (h *InterfaceVppHandler) DelSpan(ifIdxFrom, ifIdxTo uint32, isL2 uint8) error {
return h.setSpan(ifIdxFrom, ifIdxTo, 0, isL2)
}
// DumpSpan dumps all SPAN table
func (h *InterfaceVppHandler) DumpSpan() ([]*vppcalls.InterfaceSpanDetails, error) {
var spans []*vppcalls.InterfaceSpanDetails
isL2Spans, err := h.dumpSpan(&span.SwInterfaceSpanDump{IsL2: 1})
if err != nil {
return nil, err
}
spans = append(spans, isL2Spans...)
isNotL2Spans, err := h.dumpSpan(&span.SwInterfaceSpanDump{IsL2: 0})
if err != nil {
return nil, err
}
spans = append(spans, isNotL2Spans...)
return spans, nil
}
// dumpIsL2Span returns only SPANs with or without L2 set
func (h *InterfaceVppHandler) dumpSpan(msg *span.SwInterfaceSpanDump) ([]*vppcalls.InterfaceSpanDetails, error) {
var spans []*vppcalls.InterfaceSpanDetails
reqCtx := h.callsChannel.SendMultiRequest(msg)
for {
spanDetails := &span.SwInterfaceSpanDetails{}
stop, err := reqCtx.ReceiveReply(spanDetails)
if stop {
break
}
if err != nil {
return nil, fmt.Errorf("failed to dump span: %v", err)
}
span := &vppcalls.InterfaceSpanDetails{
SwIfIndexFrom: spanDetails.SwIfIndexFrom,
SwIfIndexTo: spanDetails.SwIfIndexTo,
Direction: spanDetails.State,
IsL2: spanDetails.IsL2,
}
spans = append(spans, span)
}
return spans, nil
}