Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DanG100 committed Nov 30, 2023
1 parent 95ce32e commit 0e6d206
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 78 deletions.
12 changes: 3 additions & 9 deletions dataplane/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@

package config

import (
"github.com/spf13/viper"

fwdpb "github.com/openconfig/lemming/proto/forwarding"
)

const (
// NetDevForwardingType configures the forwarding type of a SAI netdev hostif. Options are (KERNEL and TAP).
NetDevForwardingType = "dataplane.netDevType"
)

func init() {
viper.Set(NetDevForwardingType, fwdpb.PortType_name[int32(fwdpb.PortType_PORT_TYPE_KERNEL)])
}
// func init() {
// viper.Set(NetDevForwardingType, fwdpb.PortType_name[int32(fwdpb.PortType_PORT_TYPE_KERNEL)])
// }
1 change: 1 addition & 0 deletions dataplane/dplanerc/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ func (ni *Reconciler) setupPorts(ctx context.Context) error {
if i.Name == "lo" || i.Name == "eth0" || strings.HasSuffix(i.Name, internalSuffix) {
continue
}
log.Info("creating interfaces for %v", i.Name)
ocIntf := ocInterface{
name: i.Name,
subintf: 0,
Expand Down
17 changes: 11 additions & 6 deletions dataplane/dplanerc/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ func MustWildcardQuery() ygnmi.WildcardQuery[*dpb.Route] {

func (ni *Reconciler) StartRoute(ctx context.Context, client *ygnmi.Client) error {
ctx, cancelFn := context.WithCancel(ctx)

w := ygnmi.WatchAll(ctx, client, MustWildcardQuery(), func(v *ygnmi.Value[*dpb.Route]) error {
route, present := v.Val()
prefix, err := netip.ParsePrefix(v.Path.Elem[2].Key["prefix"])
if err != nil {
log.Warningf("failed to parse cidr: %v", err)
return ygnmi.Continue
}
log.Infof("got route update entry: %v", prefix)
ipBytes := prefix.Masked().Addr().AsSlice()
mask := net.CIDRMask(prefix.Bits(), len(ipBytes)*8)

Expand All @@ -78,6 +78,7 @@ func (ni *Reconciler) StartRoute(ctx context.Context, client *ygnmi.Client) erro
}

if !present {
log.Infof("removing route: %v", prefix)
_, err := ni.routeClient.RemoveRouteEntry(ctx, &saipb.RemoveRouteEntryRequest{
Entry: entry,
})
Expand All @@ -86,7 +87,7 @@ func (ni *Reconciler) StartRoute(ctx context.Context, client *ygnmi.Client) erro
}
return ygnmi.Continue
}

log.Infof("starting route add: %v", prefix)
rReq := saipb.CreateRouteEntryRequest{
Entry: entry,
PacketAction: saipb.PacketAction_PACKET_ACTION_FORWARD.Enum(),
Expand All @@ -100,6 +101,7 @@ func (ni *Reconciler) StartRoute(ctx context.Context, client *ygnmi.Client) erro
if _, err := ni.routeClient.CreateRouteEntry(ctx, &rReq); err != nil {
log.Warningf("failed to create route: %v", err)
}
log.Infof("done connected route add: %v", &rReq)
return ygnmi.Continue
}
var hopID uint64
Expand Down Expand Up @@ -172,13 +174,13 @@ func (ni *Reconciler) createNextHop(ctx context.Context, hop *dpb.NextHop) (uint
if err != nil {
return 0, err
}
log.Infof("created next hop add: %v", &hopReq)
if hop.GetGue() != nil {
acts, err := gueActions(hop.GetGue())
if err != nil {
return 0, err
}
// TODO: Ideally, this would use the SAI tunnel, but it's not currently supported.
_, err = ni.fwdClient.TableEntryAdd(ctx, &fwdpb.TableEntryAddRequest{
actReq := &fwdpb.TableEntryAddRequest{
ContextId: &fwdpb.ContextId{Id: ni.contextID},
TableId: &fwdpb.TableId{ObjectId: &fwdpb.ObjectId{Id: engine.NHActionTable}},
EntryDesc: &fwdpb.EntryDesc{Entry: &fwdpb.EntryDesc_Exact{
Expand All @@ -190,18 +192,21 @@ func (ni *Reconciler) createNextHop(ctx context.Context, hop *dpb.NextHop) (uint
},
}},
Actions: acts,
})
}
// TODO: Ideally, this would use the SAI tunnel, but it's not currently supported.
_, err = ni.fwdClient.TableEntryAdd(ctx, actReq)
if err != nil {
return 0, err
}
log.Infof("created gue actions add: %v", actReq)
}
return resp.Oid, nil
}

func gueActions(gueHeaders *dpb.GUE) ([]*fwdpb.ActionDesc, error) {
var ip gopacket.SerializableLayer
var headerID fwdpb.PacketHeaderId
if len(gueHeaders.SrcIp) == 4 {
if !gueHeaders.IsV6 {
ip = &layers.IPv4{
Version: 4,
IHL: 5,
Expand Down
10 changes: 9 additions & 1 deletion dataplane/internal/kernel/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package kernel
import (
"fmt"
"net"
"sort"

"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -117,7 +118,14 @@ func (k *Interfaces) CreateTAP(name string) (int, error) {

// GetAll returns all interfaces.
func (k *Interfaces) GetAll() ([]net.Interface, error) {
return net.Interfaces()
ifaces, err := net.Interfaces()
if err != nil {
return nil, err
}
sort.Slice(ifaces, func(i, j int) bool {
return ifaces[i].Name < ifaces[j].Name
})
return ifaces, nil
}

// GetByName returns all interfaces.
Expand Down
119 changes: 64 additions & 55 deletions proto/dataplane/dataplane.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proto/dataplane/dataplane.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ message GUE {
bytes src_ip = 1;
bytes dst_ip = 2;
uint32 dst_port = 3;
bool is_v6 = 4;
}

message NextHop {
Expand Down
19 changes: 12 additions & 7 deletions sysrib/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,23 +409,28 @@ func resolvedRouteToRouteRequest(r *ResolvedRoute) (*dpb.Route, error) {
NextHopIp: nh.Address,
}
if nh.HasGUE() {
if pfx.Addr().Is4() || pfx.Addr().Is4In6() {
if !nh.GUEHeaders.isV6 {
dnh.Encap = &dpb.NextHop_Gue{
Gue: &dpb.GUE{
SrcIp: nh.GUEHeaders.srcIP4[:],
DstIp: nh.GUEHeaders.dstIP4[:],
DstPort: uint32(nh.GUEHeaders.dstPortv4),
SrcIp: nh.GUEHeaders.srcIP4[:],
DstIp: nh.GUEHeaders.dstIP4[:],
IsV6: nh.GUEHeaders.isV6,
},
}
} else {
dnh.Encap = &dpb.NextHop_Gue{
Gue: &dpb.GUE{
SrcIp: nh.GUEHeaders.srcIP6[:],
DstIp: nh.GUEHeaders.dstIP6[:],
DstPort: uint32(nh.GUEHeaders.dstPortv6),
SrcIp: nh.GUEHeaders.srcIP6[:],
DstIp: nh.GUEHeaders.dstIP6[:],
IsV6: nh.GUEHeaders.isV6,
},
}
}
if pfx.Addr().Is4() || pfx.Addr().Is4In6() {
dnh.GetGue().DstPort = uint32(nh.GUEHeaders.dstPortv4)
} else {
dnh.GetGue().DstPort = uint32(nh.GUEHeaders.dstPortv6)
}
}
nexthops.Hops = append(nexthops.Hops, dnh)
nexthops.Weights = append(nexthops.Weights, nh.Weight)
Expand Down

0 comments on commit 0e6d206

Please sign in to comment.