Skip to content

Commit

Permalink
punt socket path resolution and L3 'ALL' case (#1382)
Browse files Browse the repository at this point in the history
punt socket path resolution and L3 'ALL' case
  • Loading branch information
ondrej-fabry committed Jun 7, 2019
2 parents b37d994 + 8963124 commit a0345b6
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 51 deletions.
5 changes: 4 additions & 1 deletion plugins/configurator/dump.go
Expand Up @@ -302,10 +302,13 @@ func (svc *dumpService) DumpPunt() (punts []*vpp_punt.ToHost, err error) {
if svc.puntHandler == nil {
return nil, errors.New("puntHandler is not available")
}
punts, err = svc.puntHandler.DumpRegisteredPuntSockets()
dump, err := svc.puntHandler.DumpRegisteredPuntSockets()
if err != nil {
return nil, err
}
for _, puntDetails := range dump {
punts = append(punts, puntDetails.PuntData)
}

return punts, nil
}
Expand Down
52 changes: 46 additions & 6 deletions plugins/vpp/puntplugin/descriptor/punt_to_host.go
Expand Up @@ -164,21 +164,61 @@ 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")

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

for _, pSocket := range pSockets {
// 1. Find NB equivalent of the punt entry with L3 set to 'ALL'. If found, cache
// the VPP entry. If not found, add to retrieved values.
var cachedIpv4, cachedIpv6 []*vppcalls.PuntDetails
Retrieved:
for _, fromVPP := range socks {
for _, fromNB := range correlate {
if fromNB.Value.L3Protocol != punt.L3Protocol_ALL {
continue
}
if fromVPP.PuntData.Port == fromNB.Value.Port &&
fromVPP.PuntData.L4Protocol == fromNB.Value.L4Protocol {
if fromVPP.PuntData.L3Protocol == punt.L3Protocol_IPv4 {
cachedIpv4 = append(cachedIpv4, fromVPP)
}
if fromVPP.PuntData.L3Protocol == punt.L3Protocol_IPv6 {
cachedIpv6 = append(cachedIpv6, fromVPP)
}
continue Retrieved
}
}
retrieved = append(retrieved, adapter.PuntToHostKVWithMetadata{
Key: models.Key(pSocket),
Value: pSocket,
Key: models.Key(fromVPP.PuntData),
Value: fromVPP.PuntData,
Origin: kvs.FromNB,
})
}

for _, rt := range retrieved {
d.log.Warnf("retrieved: %v", rt)
// 2. Find pairs of the same config.
//
// Note: only if both, IPv4 and IPv6 exists the entry is added. Cached IPv4
// without IPv6 (and all remaining IPv6) are ignored, causing agent to configure
// the missing one and re-configure the existing one.
for _, cachedIPv4Punt := range cachedIpv4 {
// look for IPv6 counterpart
var found bool
for _, cachedIPv6Punt := range cachedIpv6 {
if cachedIPv4Punt.PuntData.L4Protocol == cachedIPv6Punt.PuntData.L4Protocol &&
cachedIPv4Punt.PuntData.Port == cachedIPv6Punt.PuntData.Port {
found = true
}
}
// Store as 'ALL entry'
if found {
cachedIPv4Punt.PuntData.L3Protocol = punt.L3Protocol_ALL
retrieved = append(retrieved, adapter.PuntToHostKVWithMetadata{
Key: models.Key(cachedIPv4Punt.PuntData),
Value: cachedIPv4Punt.PuntData,
Origin: kvs.FromNB,
})
}
}

return retrieved, nil
Expand Down
8 changes: 7 additions & 1 deletion plugins/vpp/puntplugin/vppcalls/punt_vppcalls.go
Expand Up @@ -22,6 +22,12 @@ 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 @@ -43,7 +49,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() ([]*punt.ToHost, error)
DumpRegisteredPuntSockets() ([]*PuntDetails, error)
}

var Versions = map[string]HandlerVersion{}
Expand Down
36 changes: 22 additions & 14 deletions plugins/vpp/puntplugin/vppcalls/vpp1901/dump_vppcalls.go
Expand Up @@ -18,14 +18,15 @@ 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 []*vpp_punt.ToHost, err error) {
func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vppcalls.PuntDetails, err error) {
// TODO: use dumps from binapi
if _, err := h.dumpPunts(false); err != nil {
h.log.Errorf("punt dump failed: %v", err)
Expand All @@ -40,8 +41,11 @@ func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vpp_punt.ToHost,
h.log.Errorf("punt socket dump failed: %v", err)
}

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

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

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

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),
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),
},
})
}

return punts, nil
}

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

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

Expand Down
36 changes: 22 additions & 14 deletions plugins/vpp/puntplugin/vppcalls/vpp1904/dump_vppcalls.go
Expand Up @@ -18,14 +18,15 @@ 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 []*vpp_punt.ToHost, err error) {
func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vppcalls.PuntDetails, err error) {
// TODO: use dumps from binapi
if _, err := h.dumpPunts(false); err != nil {
h.log.Errorf("punt dump failed: %v", err)
Expand All @@ -40,8 +41,11 @@ func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vpp_punt.ToHost,
h.log.Errorf("punt socket dump failed: %v", err)
}

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

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

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

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),
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),
},
})
}

return punts, nil
}

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

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

Expand Down
29 changes: 14 additions & 15 deletions plugins/vpp/puntplugin/vppcalls/vpp1908/dump_vppcalls.go
Expand Up @@ -15,14 +15,13 @@
package vpp1908

import (
"bytes"

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 []*vpp_punt.ToHost, err error) {
func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vppcalls.PuntDetails, 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 @@ -34,7 +33,7 @@ func (h *PuntVppHandler) DumpRegisteredPuntSockets() (punts []*vpp_punt.ToHost,
return punts, nil
}

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

req := h.callsChannel.SendMultiRequest(&punt.PuntSocketDump{
Expand All @@ -52,19 +51,19 @@ func (h *PuntVppHandler) dumpPuntSockets() (punts []*vpp_punt.ToHost, err error)
h.log.Debugf(" - dumped punt socket (%s): %+v", d.Pathname, d.Punt)

puntL4Data := d.Punt.Punt.GetL4()
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")),
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),
SocketPath: vppConfigSocketPath,
},
// TODO dumped socket path (configured) can be stored in metadata
//SocketPath: string(bytes.Trim(d.Pathname, "\x00")),
})
}

for _, puntd := range punts {
h.log.Warnf("punts: %v", puntd)
}

return punts, nil
}

Expand All @@ -88,7 +87,7 @@ func parseL4Proto(p punt.IPProto) vpp_punt.L4Protocol {
return vpp_punt.L4Protocol_UNDEFINED_L4
}

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

req := h.callsChannel.SendMultiRequest(&punt.PuntReasonDump{})
Expand Down
9 changes: 9 additions & 0 deletions plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go
Expand Up @@ -26,6 +26,10 @@ import (

const PuntSocketHeaderVersion = 1

// Socket path from the VPP startup config file, returned when a punt socket
// is retrieved. Limited to single entry as supported in the VPP.
var vppConfigSocketPath string

// AddPunt configures new punt entry
func (h *PuntVppHandler) AddPunt(p *punt.ToHost) error {
return errors.Errorf("passive punt add is currently not available")
Expand Down Expand Up @@ -84,6 +88,11 @@ func (h *PuntVppHandler) RegisterPuntSocket(p *punt.ToHost) (pathName string, er
}
}

// VPP startup config socket path name is always the same
if vppConfigSocketPath == "" {
vppConfigSocketPath = pathName
}

return
}

Expand Down

0 comments on commit a0345b6

Please sign in to comment.