From a7f455fbcd3603c83413699be83ce151a5639a9a Mon Sep 17 00:00:00 2001 From: Vladimir Lavor Date: Fri, 7 Jun 2019 10:38:50 +0200 Subject: [PATCH 1/3] Revert "fix punt dump" This reverts commit b37d9946baafdb098b4fe43f7d880e09ff6184b5. --- plugins/configurator/dump.go | 5 ++- .../vpp/puntplugin/descriptor/punt_to_host.go | 12 +++---- .../vpp/puntplugin/vppcalls/punt_vppcalls.go | 8 ++++- .../vppcalls/vpp1901/dump_vppcalls.go | 36 +++++++++++-------- .../vppcalls/vpp1904/dump_vppcalls.go | 36 +++++++++++-------- .../vppcalls/vpp1908/dump_vppcalls.go | 23 ++++++------ .../vppcalls/vpp1908/punt_vppcalls.go | 4 +-- 7 files changed, 72 insertions(+), 52 deletions(-) diff --git a/plugins/configurator/dump.go b/plugins/configurator/dump.go index 12024a6265..15ce77faf6 100644 --- a/plugins/configurator/dump.go +++ b/plugins/configurator/dump.go @@ -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 } diff --git a/plugins/vpp/puntplugin/descriptor/punt_to_host.go b/plugins/vpp/puntplugin/descriptor/punt_to_host.go index 9d4971f30c..d0af9995ad 100644 --- a/plugins/vpp/puntplugin/descriptor/punt_to_host.go +++ b/plugins/vpp/puntplugin/descriptor/punt_to_host.go @@ -164,22 +164,18 @@ 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 { + for _, punt := range socks { retrieved = append(retrieved, adapter.PuntToHostKVWithMetadata{ - Key: models.Key(pSocket), - Value: pSocket, + Key: models.Key(punt.PuntData), + Value: punt.PuntData, Origin: kvs.FromNB, }) } - for _, rt := range retrieved { - d.log.Warnf("retrieved: %v", rt) - } - return retrieved, nil } diff --git a/plugins/vpp/puntplugin/vppcalls/punt_vppcalls.go b/plugins/vpp/puntplugin/vppcalls/punt_vppcalls.go index 6e164a6af7..8eb8bfbc3b 100644 --- a/plugins/vpp/puntplugin/vppcalls/punt_vppcalls.go +++ b/plugins/vpp/puntplugin/vppcalls/punt_vppcalls.go @@ -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 @@ -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{} diff --git a/plugins/vpp/puntplugin/vppcalls/vpp1901/dump_vppcalls.go b/plugins/vpp/puntplugin/vppcalls/vpp1901/dump_vppcalls.go index d96a81792e..fbd766453c 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp1901/dump_vppcalls.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp1901/dump_vppcalls.go @@ -18,6 +18,7 @@ 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 @@ -25,7 +26,7 @@ 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) @@ -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 { @@ -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" @@ -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" @@ -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), + }, }) } diff --git a/plugins/vpp/puntplugin/vppcalls/vpp1904/dump_vppcalls.go b/plugins/vpp/puntplugin/vppcalls/vpp1904/dump_vppcalls.go index b8de4eccb1..47260df61c 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp1904/dump_vppcalls.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp1904/dump_vppcalls.go @@ -18,6 +18,7 @@ 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 @@ -25,7 +26,7 @@ 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) @@ -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 { @@ -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" @@ -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" @@ -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), + }, }) } diff --git a/plugins/vpp/puntplugin/vppcalls/vpp1908/dump_vppcalls.go b/plugins/vpp/puntplugin/vppcalls/vpp1908/dump_vppcalls.go index 131468e068..0fb1303163 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp1908/dump_vppcalls.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp1908/dump_vppcalls.go @@ -19,10 +19,11 @@ 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 []*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) @@ -34,7 +35,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{ @@ -52,19 +53,17 @@ 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), + 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: string(bytes.Trim(d.Pathname, "\x00")), }) } - for _, puntd := range punts { - h.log.Warnf("punts: %v", puntd) - } - return punts, nil } @@ -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{}) diff --git a/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go b/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go index 228e41824a..c5d3ce6b53 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go @@ -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 not available") + return errors.Errorf("passive punt add is currently now 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 not available") + return errors.Errorf("passive punt del is currently now available") // return h.addDelPunt(p, false) } From e267cbcfcadec36fe017b8a97e64068c64d265c8 Mon Sep 17 00:00:00 2001 From: Vladimir Lavor Date: Fri, 7 Jun 2019 11:56:51 +0200 Subject: [PATCH 2/3] set vpp startup config path to retrieved punts Signed-off-by: Vladimir Lavor --- plugins/vpp/puntplugin/vppcalls/vpp1908/dump_vppcalls.go | 6 +++--- plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/vpp/puntplugin/vppcalls/vpp1908/dump_vppcalls.go b/plugins/vpp/puntplugin/vppcalls/vpp1908/dump_vppcalls.go index 0fb1303163..b52e402914 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp1908/dump_vppcalls.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp1908/dump_vppcalls.go @@ -15,8 +15,6 @@ 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" @@ -59,8 +57,10 @@ func (h *PuntVppHandler) dumpPuntSockets() (punts []*vppcalls.PuntDetails, err e // FIXME: L3Protocol seems to return 0 when registering ALL L3Protocol: parseL3Proto(puntL4Data.Af), L4Protocol: parseL4Proto(puntL4Data.Protocol), + SocketPath: vppConfigSocketPath, }, - SocketPath: string(bytes.Trim(d.Pathname, "\x00")), + // TODO dumped socket path (configured) can be stored in metadata + //SocketPath: string(bytes.Trim(d.Pathname, "\x00")), }) } diff --git a/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go b/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go index c5d3ce6b53..f30cfa3625 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go @@ -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 now available") @@ -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 } From 896312484397831b2551bec4372c26080ed4599f Mon Sep 17 00:00:00 2001 From: Vladimir Lavor Date: Fri, 7 Jun 2019 12:04:02 +0200 Subject: [PATCH 3/3] workaround punt L3 'ALL' case for vpp1908 Signed-off-by: Vladimir Lavor --- .../vpp/puntplugin/descriptor/punt_to_host.go | 50 +++++++++++++++++-- .../vppcalls/vpp1908/punt_vppcalls.go | 4 +- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/plugins/vpp/puntplugin/descriptor/punt_to_host.go b/plugins/vpp/puntplugin/descriptor/punt_to_host.go index d0af9995ad..85a9f97bd5 100644 --- a/plugins/vpp/puntplugin/descriptor/punt_to_host.go +++ b/plugins/vpp/puntplugin/descriptor/punt_to_host.go @@ -169,13 +169,57 @@ func (d *PuntToHostDescriptor) Retrieve(correlate []adapter.PuntToHostKVWithMeta return nil, err } - for _, punt := range socks { + // 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(punt.PuntData), - Value: punt.PuntData, + Key: models.Key(fromVPP.PuntData), + Value: fromVPP.PuntData, Origin: kvs.FromNB, }) } + // 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 } diff --git a/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go b/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go index f30cfa3625..f6fa8976ce 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls.go @@ -32,14 +32,14 @@ var vppConfigSocketPath string // 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) }