Skip to content

Commit 10c634a

Browse files
committed
feat(agent): support direct static routes
Signed-off-by: Emanuele Di Pascale <emanuele@githedgehog.com>
1 parent 0c0402c commit 10c634a

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

pkg/agent/dozer/bcm/spec_vrf.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -625,22 +625,34 @@ var specVRFStaticRouteEnforcer = &DefaultValueEnforcer[string, *dozer.SpecVRFSta
625625
nextHops := map[string]*oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static_NextHops_NextHop{}
626626

627627
for _, nextHop := range value.NextHops {
628-
index := nextHop.IP
628+
var index string
629+
switch {
630+
case nextHop.Interface != nil && nextHop.IP != "":
631+
index = fmt.Sprintf("%s_%s", *nextHop.Interface, nextHop.IP)
632+
case nextHop.Interface != nil:
633+
index = *nextHop.Interface
634+
case nextHop.IP != "":
635+
index = nextHop.IP
636+
default:
637+
return nil, errors.New("next hop must have at least one of interface or IP defined")
638+
}
629639
var ifaceRef *oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static_NextHops_NextHop_InterfaceRef
630640
if nextHop.Interface != nil {
631-
index = fmt.Sprintf("%s_%s", *nextHop.Interface, nextHop.IP)
632641
ifaceRef = &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static_NextHops_NextHop_InterfaceRef{
633642
Config: &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static_NextHops_NextHop_InterfaceRef_Config{
634643
Interface: nextHop.Interface,
635644
},
636645
}
637646
}
638-
647+
var nh oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static_NextHops_NextHop_Config_NextHop_Union
648+
if nextHop.IP != "" {
649+
nh = oc.UnionString(nextHop.IP)
650+
}
639651
nextHops[index] = &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static_NextHops_NextHop{
640652
Index: pointer.To(index),
641653
Config: &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static_NextHops_NextHop_Config{
642654
Index: pointer.To(index),
643-
NextHop: oc.UnionString(nextHop.IP),
655+
NextHop: nh,
644656
},
645657
InterfaceRef: ifaceRef,
646658
}
@@ -943,20 +955,20 @@ func unmarshalOCVRFs(ocVal *oc.OpenconfigNetworkInstance_NetworkInstances) (map[
943955
nextHops := []dozer.SpecVRFStaticRouteNextHop{}
944956
if staticRoute.NextHops != nil {
945957
for _, nextHop := range staticRoute.NextHops.NextHop {
946-
if nextHop.Config == nil || nextHop.Config.NextHop == nil {
947-
continue
948-
}
949-
950958
var iface *string
959+
ip := ""
960+
951961
if nextHop.InterfaceRef != nil && nextHop.InterfaceRef.Config != nil {
952962
iface = nextHop.InterfaceRef.Config.Interface
953963
}
954-
955-
ip := ""
956-
if union, ok := nextHop.Config.NextHop.(oc.UnionString); ok {
957-
ip = string(union)
958-
} else {
959-
return nil, errors.Errorf("invalid next hop %v for %s", nextHop, prefix)
964+
if nextHop.Config != nil && nextHop.Config.NextHop != nil {
965+
if union, ok := nextHop.Config.NextHop.(oc.UnionString); ok {
966+
ip = string(union)
967+
}
968+
}
969+
if iface == nil && ip == "" {
970+
// this should never happen, should we error out?
971+
continue
960972
}
961973

962974
nextHops = append(nextHops, dozer.SpecVRFStaticRouteNextHop{

0 commit comments

Comments
 (0)