Skip to content

Commit

Permalink
add vrf proto to metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
  • Loading branch information
VladoLavor committed Jul 9, 2019
1 parent 1e2154d commit a07b911
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
6 changes: 4 additions & 2 deletions plugins/vpp/l3plugin/descriptor/vrf_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func (d *VrfTableDescriptor) Create(key string, vrfTable *l3.VrfTable) (metadata

// fill the metadata
metadata = &vrfidx.VRFMetadata{
Index: vrfTable.Id,
Index: vrfTable.Id,
Protocol: vrfTable.Protocol,
}

return metadata, nil
Expand Down Expand Up @@ -146,7 +147,8 @@ func (d *VrfTableDescriptor) Retrieve(correlate []adapter.VrfTableKVWithMetadata
Key: l3.VrfTableKey(table.Id, table.Protocol),
Value: table,
Metadata: &vrfidx.VRFMetadata{
Index: table.Id,
Index: table.Id,
Protocol: table.Protocol,
},
Origin: origin,
})
Expand Down
36 changes: 16 additions & 20 deletions plugins/vpp/l3plugin/vppcalls/vpp1908/route_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,22 @@ import (
// DumpRoutes implements route handler.
func (h *RouteHandler) DumpRoutes() (routes []*vppcalls.RouteDetails, err error) {
// dump routes for every VRF and for both IP versions
for _, vrfID := range h.vrfIndexes.ListAllVrfIDs() {
// IPv6
ipv6Routes, err := h.dumpRoutesForVrfAndIP(vrfID, true)
for _, vrfMeta := range h.vrfIndexes.ListAllVrfMetadata() {
ipRoutes, err := h.dumpRoutesForVrfAndIP(vrfMeta.GetIndex(), vrfMeta.GetProtocol())
if err != nil {
return nil, err
}
routes = append(routes, ipv6Routes...)
// IPv4
ipv4Routes, err := h.dumpRoutesForVrfAndIP(vrfID, false)
if err != nil {
return nil, err
}
routes = append(routes, ipv4Routes...)

routes = append(routes, ipRoutes...)
}
return routes, nil
}

// dumpRoutesForVrf returns routes for given VRF and IP versiob
func (h *RouteHandler) dumpRoutesForVrfAndIP(vrfID uint32, isIPv6 bool) (routes []*vppcalls.RouteDetails, err error) {
func (h *RouteHandler) dumpRoutesForVrfAndIP(vrfID uint32, proto l3.VrfTable_Protocol) (routes []*vppcalls.RouteDetails, err error) {
reqCtx := h.callsChannel.SendMultiRequest(&l3binapi.IPRouteDump{
Table: l3binapi.IPTable{
TableID: vrfID,
IsIP6: boolToUint(isIPv6),
IsIP6: protoToUint(proto),
},
})
for {
Expand All @@ -59,11 +51,11 @@ func (h *RouteHandler) dumpRoutesForVrfAndIP(vrfID uint32, isIPv6 bool) (routes
break
}
if err != nil {
return routes, err
return nil, err
}
ipRoute, err := h.dumpRouteIPDetails(fibDetails.Route)
if err != nil {
return routes, err
return nil, err
}
routes = append(routes, ipRoute...)
}
Expand All @@ -76,15 +68,12 @@ func (h *RouteHandler) dumpRoutesForVrfAndIP(vrfID uint32, isIPv6 bool) (routes
func (h *RouteHandler) dumpRouteIPDetails(ipRoute l3binapi.IPRoute) ([]*vppcalls.RouteDetails, error) {
// Common fields for every route path (destination IP, VRF)
var dstIP string
netIP := make([]byte, 16)
if ipRoute.Prefix.Address.Af == l3binapi.ADDRESS_IP6 {
ip6Addr := ipRoute.Prefix.Address.Un.GetIP6()
copy(netIP[:], ip6Addr[:])
dstIP = fmt.Sprintf("%s/%d", net.IP(netIP).To16().String(), uint32(ipRoute.Prefix.Len))
dstIP = fmt.Sprintf("%s/%d", net.IP(ip6Addr[:]).To16().String(), uint32(ipRoute.Prefix.Len))
} else {
ip4Addr := ipRoute.Prefix.Address.Un.GetIP4()
copy(netIP[:], ip4Addr[:])
dstIP = fmt.Sprintf("%s/%d", net.IP(netIP[:4]).To4().String(), uint32(ipRoute.Prefix.Len))
dstIP = fmt.Sprintf("%s/%d", net.IP(ip4Addr[:4]).To4().String(), uint32(ipRoute.Prefix.Len))
}

var routeDetails []*vppcalls.RouteDetails
Expand Down Expand Up @@ -212,3 +201,10 @@ func resolvePathFlags(meta *vppcalls.RouteMeta, pathFlags l3binapi.FibPathFlags)
meta.IsResolveAttached = true
}
}

func protoToUint(proto l3.VrfTable_Protocol) uint8 {
if proto == l3.VrfTable_IPV6 {
return 1
}
return 0
}
24 changes: 17 additions & 7 deletions plugins/vpp/l3plugin/vrfidx/vrfidx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package vrfidx
import (
"time"

l3 "github.com/ligato/vpp-agent/api/models/vpp/l3"

"github.com/ligato/cn-infra/idxmap"
"github.com/ligato/cn-infra/logging"

Expand All @@ -41,8 +43,9 @@ type VRFMetadataIndex interface {
// ListAllVRFs returns slice of labels of all VRFs in the mapping.
ListAllVRFs() (names []string)

// ListAllVrfIDs returns a list of VRF indexes read from VRF metadata.
ListAllVrfIDs() (idList []uint32)
// ListAllVrfMetadata returns a list of VRF metadata - ID/Proto pairs as
// read from VRF metadata.
ListAllVrfMetadata() (idList []*VRFMetadata)

// WatchVRFs allows to subscribe to watch for changes in the VRF mapping.
WatchVRFs(subscriber string, channel chan<- VRFMetadataDto)
Expand All @@ -57,14 +60,20 @@ type VRFMetadataIndexRW interface {

// VRFMetadata collects metadata for VPP VRF used in secondary lookups.
type VRFMetadata struct {
Index uint32
Index uint32
Protocol l3.VrfTable_Protocol
}

// GetIndex returns VRF index.
func (vrfm *VRFMetadata) GetIndex() uint32 {
return vrfm.Index
}

// GetProtocol returns VRF IP protocol.
func (vrfm *VRFMetadata) GetProtocol() l3.VrfTable_Protocol {
return vrfm.Protocol
}

// VRFMetadataDto represents an item sent through watch channel in VRFMetadataIndex.
// In contrast to NamedMappingGenericEvent, it contains typed VRF metadata.
type VRFMetadataDto struct {
Expand Down Expand Up @@ -127,14 +136,15 @@ func (m *vrfMetadataIndex) ListAllVRFs() (names []string) {
return m.ListAllNames()
}

// ListAllVrfIDs returns a list of VRF indexes read from VRF metadata.
func (m *vrfMetadataIndex) ListAllVrfIDs() (idList []uint32) {
// ListAllVrfMetadata returns a list of VRF metadata - ID/Proto pairs as
// read from VRF metadata.
func (m *vrfMetadataIndex) ListAllVrfMetadata() (metaList []*VRFMetadata) {
for _, vrf := range m.ListAllNames() {
vrfMeta, ok := m.nameToIndex.LookupByName(vrf)
vrfMeta, ok := m.LookupByName(vrf)
if vrfMeta == nil || !ok {
continue
}
idList = append(idList, vrfMeta.GetIndex())
metaList = append(metaList, vrfMeta)
}
return
}
Expand Down

0 comments on commit a07b911

Please sign in to comment.