Skip to content

Commit

Permalink
fix punt dump for all vpp versions (#1379)
Browse files Browse the repository at this point in the history
* fix dump punt log
* fix punt dump for all vpp versions

Signed-off-by: Vladimir Lavor <[email protected]>
  • Loading branch information
VladoLavor authored and ondrej-fabry committed Jun 10, 2019
1 parent bacb59e commit 36636ab
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 72 deletions.
5 changes: 1 addition & 4 deletions plugins/configurator/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,10 @@ func (svc *dumpService) DumpPunt() (punts []*vpp_punt.ToHost, err error) {
if svc.puntHandler == nil {
return nil, errors.New("puntHandler is not available")
}
dump, err := svc.puntHandler.DumpRegisteredPuntSockets()
punts, err = svc.puntHandler.DumpRegisteredPuntSockets()
if err != nil {
return nil, err
}
for _, puntDetails := range dump {
punts = append(punts, puntDetails.PuntData)
}

return punts, nil
}
Expand Down
8 changes: 4 additions & 4 deletions plugins/vpp/puntplugin/descriptor/punt_to_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ func (d *PuntToHostDescriptor) Retrieve(correlate []adapter.PuntToHostKVWithMeta
// TODO dump for punt and punt socket register missing in api
d.log.Info("Dump punt/socket register is not supported by the VPP")

socks, err := d.puntHandler.DumpRegisteredPuntSockets()
pSockets, err := d.puntHandler.DumpRegisteredPuntSockets()
if err != nil {
return nil, err
}

for _, punt := range socks {
for _, pSocket := range pSockets {
retrieved = append(retrieved, adapter.PuntToHostKVWithMetadata{
Key: models.Key(punt.PuntData),
Value: punt.PuntData,
Key: models.Key(pSocket),
Value: pSocket,
Origin: kvs.FromNB,
})
}
Expand Down
8 changes: 1 addition & 7 deletions plugins/vpp/puntplugin/vppcalls/punt_vppcalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ import (
"github.com/ligato/vpp-agent/plugins/vpp/ifplugin/ifaceidx"
)

// PuntDetails includes proto-modelled punt object and its socket path
type PuntDetails struct {
PuntData *punt.ToHost
SocketPath string
}

// PuntVppAPI provides methods for managing VPP punt configuration.
type PuntVppAPI interface {
PuntVPPRead
Expand All @@ -49,7 +43,7 @@ type PuntVppAPI interface {
// PuntVPPRead provides read methods for punt
type PuntVPPRead interface {
// DumpPuntRegisteredSockets returns all punt socket registrations known to the VPP agent
DumpRegisteredPuntSockets() ([]*PuntDetails, error)
DumpRegisteredPuntSockets() ([]*punt.ToHost, error)
}

var Versions = map[string]HandlerVersion{}
Expand Down
36 changes: 14 additions & 22 deletions plugins/vpp/puntplugin/vppcalls/vpp1901/dump_vppcalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ import (
"github.com/ligato/vpp-agent/api/models/vpp"
"github.com/ligato/vpp-agent/api/models/vpp/punt"
"github.com/ligato/vpp-agent/plugins/vpp/binapi/vpp1901/punt"
"github.com/ligato/vpp-agent/plugins/vpp/puntplugin/vppcalls"
)

// FIXME: temporary solutions for providing data in dump
var socketPathMap = make(map[uint32]*vpp.PuntToHost)

// DumpRegisteredPuntSockets returns punt to host via registered socket entries
// TODO since the binary API is not available, all data are read from local cache for now
func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vppcalls.PuntDetails, err error) {
func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vpp_punt.ToHost, err error) {
// TODO: use dumps from binapi
if _, err := h.dumpPunts(false); err != nil {
h.log.Errorf("punt dump failed: %v", err)
Expand All @@ -41,11 +40,8 @@ func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vppcalls.PuntDeta
h.log.Errorf("punt socket dump failed: %v", err)
}

for _, punt := range socketPathMap {
punts = append(punts, &vppcalls.PuntDetails{
PuntData: punt,
SocketPath: punt.SocketPath,
})
for _, puntData := range socketPathMap {
punts = append(punts, puntData)
}

if len(punts) > 0 {
Expand All @@ -55,7 +51,7 @@ func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vppcalls.PuntDeta
return punts, nil
}

func (h *PuntVppHandler) dumpPuntSockets(ipv6 bool) (punts []*vppcalls.PuntDetails, err error) {
func (h *PuntVppHandler) dumpPuntSockets(ipv6 bool) (punts []*vpp_punt.ToHost, err error) {
var info = "IPv4"
if ipv6 {
info = "IPv6"
Expand All @@ -76,20 +72,18 @@ func (h *PuntVppHandler) dumpPuntSockets(ipv6 bool) (punts []*vppcalls.PuntDetai
}
h.log.Debugf(" - dumped punt socket (%s): %+v", d.Pathname, d.Punt)

punts = append(punts, &vppcalls.PuntDetails{
PuntData: &vpp_punt.ToHost{
Port: uint32(d.Punt.L4Port),
// FIXME: L3Protocol seems to return 0 when registering ALL
L3Protocol: parseL3Proto(d.Punt.IPv),
L4Protocol: parseL4Proto(d.Punt.L4Protocol),
},
punts = append(punts, &vpp_punt.ToHost{
Port: uint32(d.Punt.L4Port),
// FIXME: L3Protocol seems to return 0 when registering ALL
L3Protocol: parseL3Proto(d.Punt.IPv),
L4Protocol: parseL4Proto(d.Punt.L4Protocol),
})
}

return punts, nil
}

func (h *PuntVppHandler) dumpPunts(ipv6 bool) (punts []*vppcalls.PuntDetails, err error) {
func (h *PuntVppHandler) dumpPunts(ipv6 bool) (punts []*vpp_punt.ToHost, err error) {
var info = "IPv4"
if ipv6 {
info = "IPv6"
Expand All @@ -110,12 +104,10 @@ func (h *PuntVppHandler) dumpPunts(ipv6 bool) (punts []*vppcalls.PuntDetails, er
}
h.log.Debugf(" - dumped punt: %+v", d.Punt)

punts = append(punts, &vppcalls.PuntDetails{
PuntData: &vpp_punt.ToHost{
Port: uint32(d.Punt.L4Port),
L3Protocol: parseL3Proto(d.Punt.IPv),
L4Protocol: parseL4Proto(d.Punt.L4Protocol),
},
punts = append(punts, &vpp_punt.ToHost{
Port: uint32(d.Punt.L4Port),
L3Protocol: parseL3Proto(d.Punt.IPv),
L4Protocol: parseL4Proto(d.Punt.L4Protocol),
})
}

Expand Down
36 changes: 14 additions & 22 deletions plugins/vpp/puntplugin/vppcalls/vpp1904/dump_vppcalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ import (
"github.com/ligato/vpp-agent/api/models/vpp"
vpp_punt "github.com/ligato/vpp-agent/api/models/vpp/punt"
"github.com/ligato/vpp-agent/plugins/vpp/binapi/vpp1904/punt"
"github.com/ligato/vpp-agent/plugins/vpp/puntplugin/vppcalls"
)

// FIXME: temporary solutions for providing data in dump
var socketPathMap = make(map[uint32]*vpp.PuntToHost)

// DumpRegisteredPuntSockets returns punt to host via registered socket entries
// TODO since the binary API is not available, all data are read from local cache for now
func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vppcalls.PuntDetails, err error) {
func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vpp_punt.ToHost, err error) {
// TODO: use dumps from binapi
if _, err := h.dumpPunts(false); err != nil {
h.log.Errorf("punt dump failed: %v", err)
Expand All @@ -41,11 +40,8 @@ func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vppcalls.PuntDeta
h.log.Errorf("punt socket dump failed: %v", err)
}

for _, punt := range socketPathMap {
punts = append(punts, &vppcalls.PuntDetails{
PuntData: punt,
SocketPath: punt.SocketPath,
})
for _, puntData := range socketPathMap {
punts = append(punts, puntData)
}

if len(punts) > 0 {
Expand All @@ -55,7 +51,7 @@ func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vppcalls.PuntDeta
return punts, nil
}

func (h *PuntVppHandler) dumpPuntSockets(ipv6 bool) (punts []*vppcalls.PuntDetails, err error) {
func (h *PuntVppHandler) dumpPuntSockets(ipv6 bool) (punts []*vpp_punt.ToHost, err error) {
var info = "IPv4"
if ipv6 {
info = "IPv6"
Expand All @@ -76,20 +72,18 @@ func (h *PuntVppHandler) dumpPuntSockets(ipv6 bool) (punts []*vppcalls.PuntDetai
}
h.log.Debugf(" - dumped punt socket (%s): %+v", d.Pathname, d.Punt)

punts = append(punts, &vppcalls.PuntDetails{
PuntData: &vpp_punt.ToHost{
Port: uint32(d.Punt.L4Port),
// FIXME: L3Protocol seems to return 0 when registering ALL
L3Protocol: parseL3Proto(d.Punt.IPv),
L4Protocol: parseL4Proto(d.Punt.L4Protocol),
},
punts = append(punts, &vpp_punt.ToHost{
Port: uint32(d.Punt.L4Port),
// FIXME: L3Protocol seems to return 0 when registering ALL
L3Protocol: parseL3Proto(d.Punt.IPv),
L4Protocol: parseL4Proto(d.Punt.L4Protocol),
})
}

return punts, nil
}

func (h *PuntVppHandler) dumpPunts(ipv6 bool) (punts []*vppcalls.PuntDetails, err error) {
func (h *PuntVppHandler) dumpPunts(ipv6 bool) (punts []*vpp_punt.ToHost, err error) {
var info = "IPv4"
if ipv6 {
info = "IPv6"
Expand All @@ -110,12 +104,10 @@ func (h *PuntVppHandler) dumpPunts(ipv6 bool) (punts []*vppcalls.PuntDetails, er
}
h.log.Debugf(" - dumped punt: %+v", d.Punt)

punts = append(punts, &vppcalls.PuntDetails{
PuntData: &vpp_punt.ToHost{
Port: uint32(d.Punt.L4Port),
L3Protocol: parseL3Proto(d.Punt.IPv),
L4Protocol: parseL4Proto(d.Punt.L4Protocol),
},
punts = append(punts, &vpp_punt.ToHost{
Port: uint32(d.Punt.L4Port),
L3Protocol: parseL3Proto(d.Punt.IPv),
L4Protocol: parseL4Proto(d.Punt.L4Protocol),
})
}

Expand Down
19 changes: 8 additions & 11 deletions plugins/vpp/puntplugin/vppcalls/vpp1908/dump_vppcalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ import (

vpp_punt "github.com/ligato/vpp-agent/api/models/vpp/punt"
"github.com/ligato/vpp-agent/plugins/vpp/binapi/vpp1908/punt"
"github.com/ligato/vpp-agent/plugins/vpp/puntplugin/vppcalls"
)

// DumpRegisteredPuntSockets returns punt to host via registered socket entries
func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vppcalls.PuntDetails, err error) {
func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vpp_punt.ToHost, err error) {
// TODO: use set_punt dumps from binapi
if _, err := h.dumpPunts(); err != nil {
h.log.Errorf("punt dump failed: %v", err)
Expand All @@ -35,7 +34,7 @@ func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vppcalls.PuntDeta
return punts, nil
}

func (h *PuntVppHandler) dumpPuntSockets() (punts []*vppcalls.PuntDetails, err error) {
func (h *PuntVppHandler) dumpPuntSockets() (punts []*vpp_punt.ToHost, err error) {
h.log.Debug("=> dumping punt sockets")

req := h.callsChannel.SendMultiRequest(&punt.PuntSocketDump{
Expand All @@ -53,13 +52,11 @@ func (h *PuntVppHandler) dumpPuntSockets() (punts []*vppcalls.PuntDetails, err e
h.log.Debugf(" - dumped punt socket (%s): %+v", d.Pathname, d.Punt)

puntL4Data := d.Punt.Punt.GetL4()
punts = append(punts, &vppcalls.PuntDetails{
PuntData: &vpp_punt.ToHost{
Port: uint32(puntL4Data.Port),
// FIXME: L3Protocol seems to return 0 when registering ALL
L3Protocol: parseL3Proto(puntL4Data.Af),
L4Protocol: parseL4Proto(puntL4Data.Protocol),
},
punts = append(punts, &vpp_punt.ToHost{
Port: uint32(puntL4Data.Port),
// FIXME: L3Protocol seems to return 0 when registering ALL
L3Protocol: parseL3Proto(puntL4Data.Af),
L4Protocol: parseL4Proto(puntL4Data.Protocol),
SocketPath: string(bytes.Trim(d.Pathname, "\x00")),
})
}
Expand Down Expand Up @@ -87,7 +84,7 @@ func parseL4Proto(p punt.IPProto) vpp_punt.L4Protocol {
return vpp_punt.L4Protocol_UNDEFINED_L4
}

func (h *PuntVppHandler) dumpPunts() (punts []*vppcalls.PuntDetails, err error) {
func (h *PuntVppHandler) dumpPunts() (punts []*vpp_punt.ToHost, err error) {
h.log.Debugf("=> dumping punts")

req := h.callsChannel.SendMultiRequest(&punt.PuntReasonDump{})
Expand Down
4 changes: 2 additions & 2 deletions plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ const PuntSocketHeaderVersion = 1

// AddPunt configures new punt entry
func (h *PuntVppHandler) AddPunt(p *punt.ToHost) error {
return errors.Errorf("passive punt add is currently now available")
return errors.Errorf("passive punt add is currently not available")

// return h.addDelPunt(p, true)
}

// DeletePunt removes punt entry
func (h *PuntVppHandler) DeletePunt(p *punt.ToHost) error {
return errors.Errorf("passive punt del is currently now available")
return errors.Errorf("passive punt del is currently not available")

// return h.addDelPunt(p, false)
}
Expand Down

0 comments on commit 36636ab

Please sign in to comment.