From 93bdbe912cd290d8df03534cc41695737dad96b5 Mon Sep 17 00:00:00 2001 From: Sergei Lukianov Date: Thu, 21 Mar 2024 12:59:30 -0700 Subject: [PATCH] Switch to pointer.To helper for consistency --- pkg/agent/dozer/bcm/gnmi/client.go | 7 +- pkg/agent/dozer/bcm/plan.go | 321 +++++++++++------------ pkg/agent/dozer/bcm/plan_virtual_edge.go | 33 +-- pkg/agent/dozer/bcm/spec_acl.go | 21 +- pkg/agent/dozer/bcm/spec_comm_lists.go | 5 +- pkg/agent/dozer/bcm/spec_dhcp.go | 3 +- pkg/agent/dozer/bcm/spec_interface.go | 35 +-- pkg/agent/dozer/bcm/spec_lldp.go | 3 +- pkg/agent/dozer/bcm/spec_lst.go | 15 +- pkg/agent/dozer/bcm/spec_mclag.go | 15 +- pkg/agent/dozer/bcm/spec_nat.go | 19 +- pkg/agent/dozer/bcm/spec_ntp.go | 5 +- pkg/agent/dozer/bcm/spec_prefix_lists.go | 17 +- pkg/agent/dozer/bcm/spec_route_maps.go | 13 +- pkg/agent/dozer/bcm/spec_system.go | 21 +- pkg/agent/dozer/bcm/spec_vrf.go | 39 +-- pkg/agent/dozer/bcm/spec_vxlan.go | 17 +- pkg/agent/dozer/bcm/util.go | 4 +- pkg/util/pointer/pointer.go | 5 + 19 files changed, 304 insertions(+), 294 deletions(-) create mode 100644 pkg/util/pointer/pointer.go diff --git a/pkg/agent/dozer/bcm/gnmi/client.go b/pkg/agent/dozer/bcm/gnmi/client.go index ad358099..60543186 100644 --- a/pkg/agent/dozer/bcm/gnmi/client.go +++ b/pkg/agent/dozer/bcm/gnmi/client.go @@ -31,6 +31,7 @@ import ( "github.com/openconfig/ygot/ytypes" "github.com/pkg/errors" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) const ( @@ -119,10 +120,10 @@ func newAgentUser(ctx context.Context) ([]byte, error) { user := &oc.OpenconfigSystem_System_Aaa_Authentication_Users{ User: map[string]*oc.OpenconfigSystem_System_Aaa_Authentication_Users_User{ username: { - Username: ygot.String(username), + Username: pointer.To(username), Config: &oc.OpenconfigSystem_System_Aaa_Authentication_Users_User_Config{ - Username: ygot.String(username), - Password: ygot.String(agentPassword), + Username: pointer.To(username), + Password: pointer.To(agentPassword), Role: oc.UnionString("admin"), }, }, diff --git a/pkg/agent/dozer/bcm/plan.go b/pkg/agent/dozer/bcm/plan.go index 3e1c7f91..3a85250c 100644 --- a/pkg/agent/dozer/bcm/plan.go +++ b/pkg/agent/dozer/bcm/plan.go @@ -32,6 +32,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/manager/librarian" "go.githedgehog.com/fabric/pkg/util/iputil" + "go.githedgehog.com/fabric/pkg/util/pointer" ) const ( @@ -69,8 +70,8 @@ const ( func (p *broadcomProcessor) PlanDesiredState(ctx context.Context, agent *agentapi.Agent) (*dozer.Spec, error) { spec := &dozer.Spec{ - ZTP: boolPtr(false), - Hostname: stringPtr(agent.Name), + ZTP: pointer.To(false), + Hostname: pointer.To(agent.Name), LLDP: &dozer.SpecLLDP{}, LLDPInterfaces: map[string]*dozer.SpecLLDPInterface{}, NTP: &dozer.SpecNTP{}, @@ -83,7 +84,7 @@ func (p *broadcomProcessor) PlanDesiredState(ctx context.Context, agent *agentap Users: map[string]*dozer.SpecUser{}, VRFs: map[string]*dozer.SpecVRF{ VRF_DEFAULT: { // default VRF is always present - Enabled: boolPtr(true), + Enabled: pointer.To(true), Interfaces: map[string]*dozer.SpecVRFInterface{}, TableConnections: map[string]*dozer.SpecVRFTableConnection{}, StaticRoutes: map[string]*dozer.SpecVRFStaticRoute{}, @@ -109,7 +110,7 @@ func (p *broadcomProcessor) PlanDesiredState(ctx context.Context, agent *agentap for name, speed := range agent.Spec.Switch.PortGroupSpeeds { spec.PortGroups[name] = &dozer.SpecPortGroup{ - Speed: stringPtr(speed), + Speed: pointer.To(speed), } } @@ -255,14 +256,14 @@ func planControlLink(agent *agentapi.Agent, spec *dozer.Spec) error { prefixLen, _ := ipNet.Mask.Size() spec.Interfaces[controlIface] = &dozer.SpecInterface{ - Description: stringPtr("Control interface direct"), - Enabled: boolPtr(true), + Description: pointer.To("Control interface direct"), + Enabled: pointer.To(true), Speed: getPortSpeed(agent, controlIface), Subinterfaces: map[uint32]*dozer.SpecSubinterface{ 0: { IPs: map[string]*dozer.SpecInterfaceIP{ ip.String(): { - PrefixLen: uint8Ptr(uint8(prefixLen)), + PrefixLen: pointer.To(uint8(prefixLen)), }, }, }, @@ -280,7 +281,7 @@ func planControlLink(agent *agentapi.Agent, spec *dozer.Spec) error { NextHops: []dozer.SpecVRFStaticRouteNextHop{ { IP: ip.String(), - Interface: stringPtr(controlIface), + Interface: pointer.To(controlIface), }, }, } @@ -291,10 +292,10 @@ func planControlLink(agent *agentapi.Agent, spec *dozer.Spec) error { func planLLDP(agent *agentapi.Agent, spec *dozer.Spec) error { spec.LLDP = &dozer.SpecLLDP{ - Enabled: boolPtr(true), - HelloTimer: uint64Ptr(5), // TODO make configurable? - SystemName: stringPtr(agent.Name), - SystemDescription: stringPtr(fmt.Sprintf("Hedgehog: [control_vip=%s]", agent.Spec.Config.ControlVIP)), + Enabled: pointer.To(true), + HelloTimer: pointer.To(uint64(5)), // TODO make configurable? + SystemName: pointer.To(agent.Name), + SystemDescription: pointer.To(fmt.Sprintf("Hedgehog: [control_vip=%s]", agent.Spec.Config.ControlVIP)), } if !agent.IsSpineLeaf() { @@ -325,8 +326,8 @@ func planLLDP(agent *agentapi.Agent, spec *dozer.Spec) error { if mgmtIP != "" && iface != "" { spec.LLDPInterfaces[iface] = &dozer.SpecLLDPInterface{ - Enabled: boolPtr(true), - ManagementIPv4: stringPtr(mgmtIP), + Enabled: pointer.To(true), + ManagementIPv4: pointer.To(mgmtIP), } } } @@ -345,7 +346,7 @@ func planNTP(agent *agentapi.Agent, spec *dozer.Spec) error { addr, _ := strings.CutSuffix(agent.Spec.Config.ControlVIP, "/32") spec.NTPServers[addr] = &dozer.SpecNTPServer{ - Prefer: boolPtr(true), + Prefer: pointer.To(true), } return nil @@ -359,13 +360,13 @@ func planLoopbacks(agent *agentapi.Agent, spec *dozer.Spec) error { ipPrefixLen, _ := ipNet.Mask.Size() spec.Interfaces[LO_SWITCH] = &dozer.SpecInterface{ - Enabled: boolPtr(true), - Description: stringPtr("Switch loopback"), + Enabled: pointer.To(true), + Description: pointer.To("Switch loopback"), Subinterfaces: map[uint32]*dozer.SpecSubinterface{ 0: { IPs: map[string]*dozer.SpecInterfaceIP{ ip.String(): { - PrefixLen: uint8Ptr(uint8(ipPrefixLen)), + PrefixLen: pointer.To(uint8(ipPrefixLen)), }, }, }, @@ -379,13 +380,13 @@ func planLoopbacks(agent *agentapi.Agent, spec *dozer.Spec) error { ipPrefixLen, _ = ipNet.Mask.Size() spec.Interfaces[LO_PROTO] = &dozer.SpecInterface{ - Enabled: boolPtr(true), - Description: stringPtr("Protocol loopback"), + Enabled: pointer.To(true), + Description: pointer.To("Protocol loopback"), Subinterfaces: map[uint32]*dozer.SpecSubinterface{ 0: { IPs: map[string]*dozer.SpecInterfaceIP{ ip.String(): { - PrefixLen: uint8Ptr(uint8(ipPrefixLen)), + PrefixLen: pointer.To(uint8(ipPrefixLen)), }, }, }, @@ -400,13 +401,13 @@ func planLoopbacks(agent *agentapi.Agent, spec *dozer.Spec) error { ipPrefixLen, _ = ipNet.Mask.Size() spec.Interfaces[LO_VTEP] = &dozer.SpecInterface{ - Enabled: boolPtr(true), - Description: stringPtr("VTEP loopback"), + Enabled: pointer.To(true), + Description: pointer.To("VTEP loopback"), Subinterfaces: map[uint32]*dozer.SpecSubinterface{ 0: { IPs: map[string]*dozer.SpecInterfaceIP{ ip.String(): { - PrefixLen: uint8Ptr(uint8(ipPrefixLen)), + PrefixLen: pointer.To(uint8(ipPrefixLen)), }, }, }, @@ -468,14 +469,14 @@ func planFabricConnections(agent *agentapi.Agent, spec *dozer.Spec) error { ipPrefixLen, _ := ipNet.Mask.Size() spec.Interfaces[port] = &dozer.SpecInterface{ - Enabled: boolPtr(true), - Description: stringPtr(fmt.Sprintf("Fabric %s %s", remote, connName)), + Enabled: pointer.To(true), + Description: pointer.To(fmt.Sprintf("Fabric %s %s", remote, connName)), Speed: getPortSpeed(agent, port), Subinterfaces: map[uint32]*dozer.SpecSubinterface{ 0: { IPs: map[string]*dozer.SpecInterfaceIP{ ip.String(): { - PrefixLen: uint8Ptr(uint8(ipPrefixLen)), + PrefixLen: pointer.To(uint8(ipPrefixLen)), }, }, }, @@ -491,14 +492,14 @@ func planFabricConnections(agent *agentapi.Agent, spec *dozer.Spec) error { } spec.VRFs[VRF_DEFAULT].BGP.Neighbors[ip.String()] = &dozer.SpecVRFBGPNeighbor{ - Enabled: boolPtr(true), - Description: stringPtr(fmt.Sprintf("Fabric %s %s", remote, connName)), - RemoteAS: uint32Ptr(peerSw.ASN), - IPv4Unicast: boolPtr(true), - L2VPNEVPN: boolPtr(true), + Enabled: pointer.To(true), + Description: pointer.To(fmt.Sprintf("Fabric %s %s", remote, connName)), + RemoteAS: pointer.To(peerSw.ASN), + IPv4Unicast: pointer.To(true), + L2VPNEVPN: pointer.To(true), L2VPNEVPNImportPolicies: []string{ROUTE_MAP_BLOCK_EVPN_DEFAULT_REMOTE}, // TODO: We might later specify dedicated neighbors for this. - L2VPNEVPNAllowOwnAS: boolPtr(true), + L2VPNEVPNAllowOwnAS: pointer.To(true), } } } @@ -520,8 +521,8 @@ func planVPCLoopbacks(agent *agentapi.Agent, spec *dozer.Spec) error { for portID, port := range []string{link.Switch1.LocalPortName(), link.Switch2.LocalPortName()} { spec.Interfaces[port] = &dozer.SpecInterface{ - Enabled: boolPtr(true), - Description: stringPtr(fmt.Sprintf("VPC loopback %d.%d %s", linkID, portID, connName)), + Enabled: pointer.To(true), + Description: pointer.To(fmt.Sprintf("VPC loopback %d.%d %s", linkID, portID, connName)), Speed: getPortSpeed(agent, port), Subinterfaces: map[uint32]*dozer.SpecSubinterface{}, } @@ -553,8 +554,8 @@ func planExternals(agent *agentapi.Agent, spec *dozer.Spec) error { port := conn.External.Link.Switch.LocalPortName() spec.Interfaces[port] = &dozer.SpecInterface{ - Enabled: boolPtr(true), - Description: stringPtr(fmt.Sprintf("External %s", connName)), + Enabled: pointer.To(true), + Description: pointer.To(fmt.Sprintf("External %s", connName)), Speed: getPortSpeed(agent, port), Subinterfaces: map[uint32]*dozer.SpecSubinterface{}, } @@ -589,9 +590,9 @@ func planExternals(agent *agentapi.Agent, spec *dozer.Spec) error { spec.RouteMaps[ROUTE_MAP_BLOCK_EVPN_DEFAULT_REMOTE].Statements[fmt.Sprintf("%d", ROUTE_MAP_MAX_STATEMENT-10)] = &dozer.SpecRouteMapStatement{ Conditions: dozer.SpecRouteMapConditions{ - MatchCommunityList: stringPtr(BGP_COMM_LIST_ALL_EXTERNALS), + MatchCommunityList: pointer.To(BGP_COMM_LIST_ALL_EXTERNALS), }, - SetLocalPreference: uint32Ptr(500), + SetLocalPreference: pointer.To(uint32(500)), Result: dozer.SpecRouteMapResultAccept, } } @@ -621,7 +622,7 @@ func planExternals(agent *agentapi.Agent, spec *dozer.Spec) error { Statements: map[string]*dozer.SpecRouteMapStatement{ "10": { Conditions: dozer.SpecRouteMapConditions{ - MatchCommunityList: stringPtr(externalCommsCommList), + MatchCommunityList: pointer.To(externalCommsCommList), }, Result: dozer.SpecRouteMapResultAccept, }, @@ -646,7 +647,7 @@ func planExternals(agent *agentapi.Agent, spec *dozer.Spec) error { seq := uint32(10) for _, subnet := range ipns.Subnets { spec.ACLs[ipnsEgressAccessList(external.IPv4Namespace)].Entries[seq] = &dozer.SpecACLEntry{ - DestinationAddress: stringPtr(subnet), + DestinationAddress: pointer.To(subnet), Action: dozer.SpecACLEntryActionDrop, } seq += 10 @@ -659,25 +660,25 @@ func planExternals(agent *agentapi.Agent, spec *dozer.Spec) error { } spec.VRFs[ipnsVrfName] = &dozer.SpecVRF{ - Enabled: boolPtr(true), - // Description: stringPtr(fmt.Sprintf("IPv4NS %s", external.IPv4Namespace)), - AnycastMAC: stringPtr(ANYCAST_MAC), + Enabled: pointer.To(true), + // Description: pointer.To(fmt.Sprintf("IPv4NS %s", external.IPv4Namespace)), + AnycastMAC: pointer.To(ANYCAST_MAC), Interfaces: map[string]*dozer.SpecVRFInterface{}, StaticRoutes: map[string]*dozer.SpecVRFStaticRoute{}, TableConnections: map[string]*dozer.SpecVRFTableConnection{}, BGP: &dozer.SpecVRFBGP{ - AS: uint32Ptr(agent.Spec.Switch.ASN), - RouterID: stringPtr(protocolIP.String()), - NetworkImportCheck: boolPtr(true), + AS: pointer.To(agent.Spec.Switch.ASN), + RouterID: pointer.To(protocolIP.String()), + NetworkImportCheck: pointer.To(true), IPv4Unicast: dozer.SpecVRFBGPIPv4Unicast{ Enabled: true, - MaxPaths: uint32Ptr(getMaxPaths(agent)), + MaxPaths: pointer.To(getMaxPaths(agent)), Networks: map[string]*dozer.SpecVRFBGPNetwork{}, ImportVRFs: map[string]*dozer.SpecVRFBGPImportVRF{}, }, L2VPNEVPN: dozer.SpecVRFBGPL2VPNEVPN{ Enabled: agent.IsSpineLeaf(), - AdvertiseDefaultGw: boolPtr(true), + AdvertiseDefaultGw: pointer.To(true), }, Neighbors: map[string]*dozer.SpecVRFBGPNeighbor{}, }, @@ -693,13 +694,13 @@ func planExternals(agent *agentapi.Agent, spec *dozer.Spec) error { Statements: map[string]*dozer.SpecRouteMapStatement{ "5": { Conditions: dozer.SpecRouteMapConditions{ - MatchPrefixList: stringPtr(ipnsSubnetsPrefixListName(external.IPv4Namespace)), + MatchPrefixList: pointer.To(ipnsSubnetsPrefixListName(external.IPv4Namespace)), }, Result: dozer.SpecRouteMapResultReject, }, "10": { Conditions: dozer.SpecRouteMapConditions{ - MatchCommunityList: stringPtr(commList), + MatchCommunityList: pointer.To(commList), }, Result: dozer.SpecRouteMapResultAccept, }, @@ -718,7 +719,7 @@ func planExternals(agent *agentapi.Agent, spec *dozer.Spec) error { Statements: map[string]*dozer.SpecRouteMapStatement{ "10": { Conditions: dozer.SpecRouteMapConditions{ - MatchPrefixList: stringPtr(prefList), + MatchPrefixList: pointer.To(prefList), }, SetCommunities: []string{external.OutboundCommunity}, Result: dozer.SpecRouteMapResultAccept, @@ -747,7 +748,7 @@ func planExternals(agent *agentapi.Agent, spec *dozer.Spec) error { port := conn.External.Link.Switch.LocalPortName() var vlan *uint16 if attach.Switch.VLAN != 0 { - vlan = uint16Ptr(uint16(attach.Switch.VLAN)) + vlan = pointer.To(uint16(attach.Switch.VLAN)) } ip, ipNet, err := net.ParseCIDR(attach.Switch.IP) @@ -760,7 +761,7 @@ func planExternals(agent *agentapi.Agent, spec *dozer.Spec) error { VLAN: vlan, IPs: map[string]*dozer.SpecInterfaceIP{ ip.String(): { - PrefixLen: uint8Ptr(uint8(prefixLength)), + PrefixLen: pointer.To(uint8(prefixLength)), }, }, } @@ -772,16 +773,16 @@ func planExternals(agent *agentapi.Agent, spec *dozer.Spec) error { spec.VRFs[ipnsVrfName].Interfaces[subIfaceName] = &dozer.SpecVRFInterface{} spec.VRFs[ipnsVrfName].BGP.Neighbors[attach.Neighbor.IP] = &dozer.SpecVRFBGPNeighbor{ - Enabled: boolPtr(true), - Description: stringPtr(fmt.Sprintf("External attach %s", name)), - RemoteAS: uint32Ptr(attach.Neighbor.ASN), - IPv4Unicast: boolPtr(true), + Enabled: pointer.To(true), + Description: pointer.To(fmt.Sprintf("External attach %s", name)), + RemoteAS: pointer.To(attach.Neighbor.ASN), + IPv4Unicast: pointer.To(true), IPv4UnicastImportPolicies: []string{extInboundRouteMapName(attach.External)}, IPv4UnicastExportPolicies: []string{extOutboundRouteMapName(attach.External)}, } spec.ACLInterfaces[subIfaceName] = &dozer.SpecACLInterface{ - Egress: stringPtr(ipnsEgressAccessList(ipns)), + Egress: pointer.To(ipnsEgressAccessList(ipns)), } } @@ -806,18 +807,18 @@ func planStaticExternals(agent *agentapi.Agent, spec *dozer.Spec) error { var vlan *uint16 if cfg.VLAN != 0 { - vlan = uint16Ptr(cfg.VLAN) + vlan = pointer.To(cfg.VLAN) } spec.Interfaces[cfg.LocalPortName()] = &dozer.SpecInterface{ - Enabled: boolPtr(true), - Description: stringPtr(fmt.Sprintf("StaticExt %s", connName)), + Enabled: pointer.To(true), + Description: pointer.To(fmt.Sprintf("StaticExt %s", connName)), Subinterfaces: map[uint32]*dozer.SpecSubinterface{ uint32(cfg.VLAN): { VLAN: vlan, IPs: map[string]*dozer.SpecInterfaceIP{ ip.String(): { - PrefixLen: uint8Ptr(uint8(ipPrefixLen)), + PrefixLen: pointer.To(uint8(ipPrefixLen)), }, }, }, @@ -854,7 +855,7 @@ func planStaticExternals(agent *agentapi.Agent, spec *dozer.Spec) error { NextHops: []dozer.SpecVRFStaticRouteNextHop{ { IP: cfg.NextHop, - Interface: stringPtr(ifName), + Interface: pointer.To(ifName), }, }, } @@ -913,20 +914,20 @@ func planServerConnections(agent *agentapi.Agent, spec *dozer.Spec) error { if conn.MCLAG != nil { connType = "MCLAG" if conn.MCLAG.MTU != 0 { - mtu = uint16Ptr(conn.MCLAG.MTU) + mtu = pointer.To(conn.MCLAG.MTU) } fallback = fallback && conn.MCLAG.Fallback links = conn.MCLAG.Links } else if conn.Bundled != nil { connType = "Bundled" if conn.Bundled.MTU != 0 { - mtu = uint16Ptr(conn.Bundled.MTU) + mtu = pointer.To(conn.Bundled.MTU) } links = conn.Bundled.Links } else if conn.ESLAG != nil { connType = "ESLAG" if conn.ESLAG.MTU != 0 { - mtu = uint16Ptr(conn.ESLAG.MTU) + mtu = pointer.To(conn.ESLAG.MTU) } fallback = fallback && conn.ESLAG.Fallback links = conn.ESLAG.Links @@ -936,7 +937,7 @@ func planServerConnections(agent *agentapi.Agent, spec *dozer.Spec) error { // TODO remove when we have a way to configure MTU for port channels reliably // if mtu == nil { - mtu = uint16Ptr(agent.Spec.Config.FabricMTU - agent.Spec.Config.ServerFacingMTUOffset) + mtu = pointer.To(agent.Spec.Config.FabricMTU - agent.Spec.Config.ServerFacingMTUOffset) //} if err := conn.ValidateServerFacingMTU(agent.Spec.Config.FabricMTU, agent.Spec.Config.ServerFacingMTUOffset); err != nil { @@ -956,8 +957,8 @@ func planServerConnections(agent *agentapi.Agent, spec *dozer.Spec) error { connPortChannelName := portChannelName(portChan) connPortChannel := &dozer.SpecInterface{ - Enabled: boolPtr(true), - Description: stringPtr(fmt.Sprintf("%s %s %s", connType, link.Server.DeviceName(), connName)), + Enabled: pointer.To(true), + Description: pointer.To(fmt.Sprintf("%s %s %s", connType, link.Server.DeviceName(), connName)), TrunkVLANs: []string{}, MTU: mtu, } @@ -968,7 +969,7 @@ func planServerConnections(agent *agentapi.Agent, spec *dozer.Spec) error { DomainID: MCLAG_DOMAIN_ID, } spec.PortChannelConfigs[connPortChannelName] = &dozer.SpecPortChannelConfig{ - Fallback: boolPtr(fallback), + Fallback: pointer.To(fallback), } } else if connType == "ESLAG" { mac, err := net.ParseMAC(agent.Spec.Config.ESLAGMACBase) @@ -988,8 +989,8 @@ func planServerConnections(agent *agentapi.Agent, spec *dozer.Spec) error { mac = newMACVal[2:] spec.PortChannelConfigs[connPortChannelName] = &dozer.SpecPortChannelConfig{ - SystemMAC: stringPtr(mac.String()), - Fallback: boolPtr(fallback), + SystemMAC: pointer.To(mac.String()), + Fallback: pointer.To(fallback), } esi := strings.ReplaceAll(agent.Spec.Config.ESLAGESIPrefix+mac.String(), ":", "") @@ -1014,11 +1015,11 @@ func planServerConnections(agent *agentapi.Agent, spec *dozer.Spec) error { var mtu *uint16 if conn.Unbundled.MTU != 0 { - mtu = uint16Ptr(conn.Unbundled.MTU) + mtu = pointer.To(conn.Unbundled.MTU) } if mtu == nil { - mtu = uint16Ptr(agent.Spec.Config.FabricMTU - agent.Spec.Config.ServerFacingMTUOffset) + mtu = pointer.To(agent.Spec.Config.FabricMTU - agent.Spec.Config.ServerFacingMTUOffset) } if err := conn.ValidateServerFacingMTU(agent.Spec.Config.FabricMTU, agent.Spec.Config.ServerFacingMTUOffset); err != nil { @@ -1032,8 +1033,8 @@ func planServerConnections(agent *agentapi.Agent, spec *dozer.Spec) error { swPort := conn.Unbundled.Link.Switch spec.Interfaces[swPort.LocalPortName()] = &dozer.SpecInterface{ - Enabled: boolPtr(true), - Description: stringPtr(fmt.Sprintf("Unbundled %s %s", conn.Unbundled.Link.Server.DeviceName(), connName)), + Enabled: pointer.To(true), + Description: pointer.To(fmt.Sprintf("Unbundled %s %s", conn.Unbundled.Link.Server.DeviceName(), connName)), Speed: getPortSpeed(agent, swPort.LocalPortName()), TrunkVLANs: []string{}, MTU: mtu, @@ -1049,19 +1050,19 @@ func planDefaultVRFWithBGP(agent *agentapi.Agent, spec *dozer.Spec) error { return errors.Wrapf(err, "failed to parse protocol ip %s", agent.Spec.Switch.ProtocolIP) } - spec.VRFs[VRF_DEFAULT].AnycastMAC = stringPtr(ANYCAST_MAC) + spec.VRFs[VRF_DEFAULT].AnycastMAC = pointer.To(ANYCAST_MAC) spec.VRFs[VRF_DEFAULT].BGP = &dozer.SpecVRFBGP{ - AS: uint32Ptr(agent.Spec.Switch.ASN), - RouterID: stringPtr(ip.String()), - NetworkImportCheck: boolPtr(true), // default + AS: pointer.To(agent.Spec.Switch.ASN), + RouterID: pointer.To(ip.String()), + NetworkImportCheck: pointer.To(true), // default Neighbors: map[string]*dozer.SpecVRFBGPNeighbor{}, IPv4Unicast: dozer.SpecVRFBGPIPv4Unicast{ Enabled: true, - MaxPaths: uint32Ptr(getMaxPaths(agent)), + MaxPaths: pointer.To(getMaxPaths(agent)), }, L2VPNEVPN: dozer.SpecVRFBGPL2VPNEVPN{ Enabled: agent.IsSpineLeaf(), - AdvertiseAllVNI: boolPtr(true), + AdvertiseAllVNI: pointer.To(true), }, } spec.VRFs[VRF_DEFAULT].TableConnections = map[string]*dozer.SpecVRFTableConnection{ @@ -1084,14 +1085,14 @@ func planVXLAN(agent *agentapi.Agent, spec *dozer.Spec) error { spec.VXLANTunnels = map[string]*dozer.SpecVXLANTunnel{ VTEP_FABRIC: { - SourceIP: stringPtr(ip.String()), - SourceInterface: stringPtr(LO_VTEP), + SourceIP: pointer.To(ip.String()), + SourceInterface: pointer.To(LO_VTEP), }, } spec.VXLANEVPNNVOs = map[string]*dozer.SpecVXLANEVPNNVO{ EVPN_NVO: { - SourceVTEP: stringPtr(VTEP_FABRIC), + SourceVTEP: pointer.To(VTEP_FABRIC), }, } @@ -1150,8 +1151,8 @@ func planMCLAGDomain(agent *agentapi.Agent, spec *dozer.Spec) (bool, error) { mclagPeerPortChannelName := portChannelName(MCLAG_PEER_LINK_PORT_CHANNEL_ID) mclagPeerPortChannel := &dozer.SpecInterface{ - Description: stringPtr(fmt.Sprintf("MCLAG peer %s", mclagPeerSwitch)), - Enabled: boolPtr(true), + Description: pointer.To(fmt.Sprintf("MCLAG peer %s", mclagPeerSwitch)), + Enabled: pointer.To(true), TrunkVLANs: []string{MCLAG_PEER_LINK_TRUNK_VLAN_RANGE}, } spec.Interfaces[mclagPeerPortChannelName] = mclagPeerPortChannel @@ -1165,13 +1166,13 @@ func planMCLAGDomain(agent *agentapi.Agent, spec *dozer.Spec) (bool, error) { mclagSessionPortChannelName := portChannelName(MCLAG_SESSION_LINK_PORT_CHANNEL_ID) mclagSessionPortChannel := &dozer.SpecInterface{ - Description: stringPtr(fmt.Sprintf("MCLAG session %s", mclagPeerSwitch)), - Enabled: boolPtr(true), + Description: pointer.To(fmt.Sprintf("MCLAG session %s", mclagPeerSwitch)), + Enabled: pointer.To(true), Subinterfaces: map[uint32]*dozer.SpecSubinterface{ 0: { IPs: map[string]*dozer.SpecInterfaceIP{ sourceIP: { - PrefixLen: uint8Ptr(MCLAG_SESSION_IP_PREFIX_LEN), + PrefixLen: pointer.To(uint8(MCLAG_SESSION_IP_PREFIX_LEN)), }, }, }, @@ -1193,10 +1194,10 @@ func planMCLAGDomain(agent *agentapi.Agent, spec *dozer.Spec) (bool, error) { } spec.VRFs[VRF_DEFAULT].BGP.Neighbors[peerIP] = &dozer.SpecVRFBGPNeighbor{ - Enabled: boolPtr(true), - Description: stringPtr(fmt.Sprintf("MCLAG session %s", mclagPeerSwitch)), - PeerType: stringPtr(dozer.SpecVRFBGPNeighborPeerTypeInternal), - IPv4Unicast: boolPtr(true), + Enabled: pointer.To(true), + Description: pointer.To(fmt.Sprintf("MCLAG session %s", mclagPeerSwitch)), + PeerType: pointer.To(dozer.SpecVRFBGPNeighborPeerTypeInternal), + IPv4Unicast: pointer.To(true), } return sourceIP == MCLAG_SESSION_IP_1, nil @@ -1204,8 +1205,8 @@ func planMCLAGDomain(agent *agentapi.Agent, spec *dozer.Spec) (bool, error) { func planESLAG(agent *agentapi.Agent, spec *dozer.Spec) error { spec.VRFs[VRF_DEFAULT].EVPNMH = dozer.SpecVRFEVPNMH{ - MACHoldtime: uint32Ptr(60), - StartupDelay: uint32Ptr(60), + MACHoldtime: pointer.To(uint32(60)), + StartupDelay: pointer.To(uint32(60)), } if !agent.Spec.Role.IsLeaf() { @@ -1213,8 +1214,8 @@ func planESLAG(agent *agentapi.Agent, spec *dozer.Spec) error { } spec.LSTGroups[LST_GROUP_SPINELINK] = &dozer.SpecLSTGroup{ - AllEVPNESDownstream: boolPtr(true), - Timeout: uint16Ptr(180), + AllEVPNESDownstream: pointer.To(true), + Timeout: pointer.To(uint16(180)), } for _, conn := range agent.Spec.Connections { @@ -1294,8 +1295,8 @@ func planVPCs(agent *agentapi.Agent, spec *dozer.Spec) error { irbIface := vlanName(irbVLAN) spec.Interfaces[irbIface] = &dozer.SpecInterface{ - Enabled: boolPtr(true), - Description: stringPtr(fmt.Sprintf("VPC %s IRB", vpcName)), + Enabled: pointer.To(true), + Description: pointer.To(fmt.Sprintf("VPC %s IRB", vpcName)), } if spec.VRFs[vrfName] == nil { @@ -1372,20 +1373,20 @@ func planVPCs(agent *agentapi.Agent, spec *dozer.Spec) error { Statements: map[string]*dozer.SpecRouteMapStatement{ "1": { Conditions: dozer.SpecRouteMapConditions{ - MatchNextHopPrefixList: stringPtr(PREFIX_LIST_VPC_LOOPBACK), + MatchNextHopPrefixList: pointer.To(PREFIX_LIST_VPC_LOOPBACK), }, Result: dozer.SpecRouteMapResultReject, }, "50000": { Conditions: dozer.SpecRouteMapConditions{ - MatchCommunityList: stringPtr(vpcPeersCommList), + MatchCommunityList: pointer.To(vpcPeersCommList), }, Result: dozer.SpecRouteMapResultAccept, }, "50001": { Conditions: dozer.SpecRouteMapConditions{ - MatchCommunityList: stringPtr(NO_COMMUNITY), - MatchPrefixList: stringPtr(vpcPeersPrefixListName(vpcName)), + MatchCommunityList: pointer.To(NO_COMMUNITY), + MatchPrefixList: pointer.To(vpcPeersPrefixListName(vpcName)), }, Result: dozer.SpecRouteMapResultAccept, }, @@ -1406,20 +1407,20 @@ func planVPCs(agent *agentapi.Agent, spec *dozer.Spec) error { Statements: map[string]*dozer.SpecRouteMapStatement{ "1": { Conditions: dozer.SpecRouteMapConditions{ - MatchPrefixList: stringPtr(PREFIX_LIST_VPC_LOOPBACK), + MatchPrefixList: pointer.To(PREFIX_LIST_VPC_LOOPBACK), }, Result: dozer.SpecRouteMapResultReject, }, "5": { Conditions: dozer.SpecRouteMapConditions{ - MatchPrefixList: stringPtr(vpcSubnetsPrefixListName(vpcName)), + MatchPrefixList: pointer.To(vpcSubnetsPrefixListName(vpcName)), }, SetCommunities: []string{vpcComm}, Result: dozer.SpecRouteMapResultAccept, }, "6": { Conditions: dozer.SpecRouteMapConditions{ - MatchPrefixList: stringPtr(vpcStaticExtSubnetsPrefixListName(vpcName)), + MatchPrefixList: pointer.To(vpcStaticExtSubnetsPrefixListName(vpcName)), }, Result: dozer.SpecRouteMapResultAccept, }, @@ -1434,13 +1435,13 @@ func planVPCs(agent *agentapi.Agent, spec *dozer.Spec) error { Statements: map[string]*dozer.SpecRouteMapStatement{ "1": { Conditions: dozer.SpecRouteMapConditions{ - MatchPrefixList: stringPtr(PREFIX_LIST_VPC_LOOPBACK), + MatchPrefixList: pointer.To(PREFIX_LIST_VPC_LOOPBACK), }, Result: dozer.SpecRouteMapResultReject, }, "5": { Conditions: dozer.SpecRouteMapConditions{ - MatchPrefixList: stringPtr(vpcStaticExtSubnetsPrefixListName(vpcName)), + MatchPrefixList: pointer.To(vpcStaticExtSubnetsPrefixListName(vpcName)), }, Result: dozer.SpecRouteMapResultAccept, }, @@ -1452,21 +1453,21 @@ func planVPCs(agent *agentapi.Agent, spec *dozer.Spec) error { return errors.Wrapf(err, "failed to parse protocol ip %s", agent.Spec.Switch.ProtocolIP) } - spec.VRFs[vrfName].Enabled = boolPtr(true) - spec.VRFs[vrfName].AnycastMAC = stringPtr(ANYCAST_MAC) + spec.VRFs[vrfName].Enabled = pointer.To(true) + spec.VRFs[vrfName].AnycastMAC = pointer.To(ANYCAST_MAC) spec.VRFs[vrfName].BGP = &dozer.SpecVRFBGP{ - AS: uint32Ptr(agent.Spec.Switch.ASN), - RouterID: stringPtr(protocolIP.String()), - NetworkImportCheck: boolPtr(true), + AS: pointer.To(agent.Spec.Switch.ASN), + RouterID: pointer.To(protocolIP.String()), + NetworkImportCheck: pointer.To(true), IPv4Unicast: dozer.SpecVRFBGPIPv4Unicast{ Enabled: true, - MaxPaths: uint32Ptr(getMaxPaths(agent)), - ImportPolicy: stringPtr(importVrfRouteMap), + MaxPaths: pointer.To(getMaxPaths(agent)), + ImportPolicy: pointer.To(importVrfRouteMap), ImportVRFs: map[string]*dozer.SpecVRFBGPImportVRF{}, }, L2VPNEVPN: dozer.SpecVRFBGPL2VPNEVPN{ Enabled: agent.IsSpineLeaf(), - AdvertiseIPv4Unicast: boolPtr(true), + AdvertiseIPv4Unicast: pointer.To(true), }, } spec.VRFs[vrfName].TableConnections = map[string]*dozer.SpecVRFTableConnection{ @@ -1487,12 +1488,12 @@ func planVPCs(agent *agentapi.Agent, spec *dozer.Spec) error { return errors.Errorf("VNI for VPC %s not found", vpcName) } spec.VRFVNIMap[vrfName] = &dozer.SpecVRFVNIEntry{ - VNI: uint32Ptr(vpcVNI), + VNI: pointer.To(vpcVNI), } spec.VXLANTunnelMap[fmt.Sprintf("map_%d_%s", vpcVNI, irbIface)] = &dozer.SpecVXLANTunnelMap{ - VTEP: stringPtr(VTEP_FABRIC), - VNI: uint32Ptr(vpcVNI), - VLAN: uint16Ptr(irbVLAN), + VTEP: pointer.To(VTEP_FABRIC), + VNI: pointer.To(vpcVNI), + VLAN: pointer.To(irbVLAN), } } } @@ -1576,7 +1577,7 @@ func planVPCs(agent *agentapi.Agent, spec *dozer.Spec) error { return errors.Wrapf(err, "failed to parse subnet VLAN %s for VPC %s", subnet.VLAN, vpcName) } - spec.Interfaces[iface].AccessVLAN = uint16Ptr(uint16(vlan)) + spec.Interfaces[iface].AccessVLAN = pointer.To(uint16(vlan)) } else { if !slices.Contains(spec.Interfaces[iface].TrunkVLANs, subnet.VLAN) { spec.Interfaces[iface].TrunkVLANs = append(spec.Interfaces[iface].TrunkVLANs, subnet.VLAN) @@ -1702,15 +1703,15 @@ func planVPCs(agent *agentapi.Agent, spec *dozer.Spec) error { spec.RouteMaps[vpcExtImportVrfRouteMapName(vpc1Name)].Statements[fmt.Sprintf("%d", 10000+vni2/100)] = &dozer.SpecRouteMapStatement{ Conditions: dozer.SpecRouteMapConditions{ - MatchPrefixList: stringPtr(vpcNotSubnetsPrefixListName(vpc2Name)), - MatchSourceVRF: stringPtr(vpcVrfName(vpc2Name)), + MatchPrefixList: pointer.To(vpcNotSubnetsPrefixListName(vpc2Name)), + MatchSourceVRF: pointer.To(vpcVrfName(vpc2Name)), }, Result: dozer.SpecRouteMapResultReject, } spec.RouteMaps[vpcExtImportVrfRouteMapName(vpc2Name)].Statements[fmt.Sprintf("%d", 10000+vni1/100)] = &dozer.SpecRouteMapStatement{ Conditions: dozer.SpecRouteMapConditions{ - MatchPrefixList: stringPtr(vpcNotSubnetsPrefixListName(vpc1Name)), - MatchSourceVRF: stringPtr(vpcVrfName(vpc1Name)), + MatchPrefixList: pointer.To(vpcNotSubnetsPrefixListName(vpc1Name)), + MatchSourceVRF: pointer.To(vpcVrfName(vpc1Name)), }, Result: dozer.SpecRouteMapResultReject, } @@ -1741,15 +1742,15 @@ func planVPCs(agent *agentapi.Agent, spec *dozer.Spec) error { if remote { spec.RouteMaps[ROUTE_MAP_BLOCK_EVPN_DEFAULT_REMOTE].Statements[fmt.Sprintf("%d", uint(vni1/100))] = &dozer.SpecRouteMapStatement{ Conditions: dozer.SpecRouteMapConditions{ - MatchEVPNVNI: uint32Ptr(vni1), - MatchEVPNDefaultRoute: boolPtr(true), + MatchEVPNVNI: pointer.To(vni1), + MatchEVPNDefaultRoute: pointer.To(true), }, Result: dozer.SpecRouteMapResultReject, } spec.RouteMaps[ROUTE_MAP_BLOCK_EVPN_DEFAULT_REMOTE].Statements[fmt.Sprintf("%d", uint(vni2/100))] = &dozer.SpecRouteMapStatement{ Conditions: dozer.SpecRouteMapConditions{ - MatchEVPNVNI: uint32Ptr(vni2), - MatchEVPNDefaultRoute: boolPtr(true), + MatchEVPNVNI: pointer.To(vni2), + MatchEVPNDefaultRoute: pointer.To(true), }, Result: dozer.SpecRouteMapResultReject, } @@ -1775,7 +1776,7 @@ func planVPCs(agent *agentapi.Agent, spec *dozer.Spec) error { NextHops: []dozer.SpecVRFStaticRouteNextHop{ { IP: ip1, - Interface: stringPtr(strings.ReplaceAll(sub2, "Ethernet", "Eth")), + Interface: pointer.To(strings.ReplaceAll(sub2, "Ethernet", "Eth")), }, }, } @@ -1792,7 +1793,7 @@ func planVPCs(agent *agentapi.Agent, spec *dozer.Spec) error { NextHops: []dozer.SpecVRFStaticRouteNextHop{ { IP: ip2, - Interface: stringPtr(strings.ReplaceAll(sub1, "Ethernet", "Eth")), + Interface: pointer.To(strings.ReplaceAll(sub1, "Ethernet", "Eth")), }, }, } @@ -1849,8 +1850,8 @@ func planVPCSubnet(agent *agentapi.Agent, spec *dozer.Spec, vpcName string, vpc subnetIface := vlanName(subnetVLAN) spec.Interfaces[subnetIface] = &dozer.SpecInterface{ - Enabled: boolPtr(true), - Description: stringPtr(fmt.Sprintf("VPC %s/%s", vpcName, subnetName)), + Enabled: pointer.To(true), + Description: pointer.To(fmt.Sprintf("VPC %s/%s", vpcName, subnetName)), VLANAnycastGateway: []string{ fmt.Sprintf("%s/%d", subnetCIDR.Gateway.String(), prefixLen), }, @@ -1860,7 +1861,7 @@ func planVPCSubnet(agent *agentapi.Agent, spec *dozer.Spec, vpcName string, vpc vpcFilteringACL := vpcFilteringAccessListName(vpcName, subnetName) spec.ACLInterfaces[subnetIface] = &dozer.SpecACLInterface{ - Ingress: stringPtr(vpcFilteringACL), + Ingress: pointer.To(vpcFilteringACL), } spec.ACLs[vpcFilteringACL], err = buildVPCFilteringACL(agent, vpcName, vpc, subnetName, subnet) @@ -1876,9 +1877,9 @@ func planVPCSubnet(agent *agentapi.Agent, spec *dozer.Spec, vpcName string, vpc return errors.Errorf("VNI for VPC %s subnet %s not found", vpcName, subnetName) } spec.VXLANTunnelMap[fmt.Sprintf("map_%d_%s", subnetVNI, subnetIface)] = &dozer.SpecVXLANTunnelMap{ - VTEP: stringPtr(VTEP_FABRIC), - VNI: uint32Ptr(subnetVNI), - VLAN: uint16Ptr(subnetVLAN), + VTEP: pointer.To(VTEP_FABRIC), + VNI: pointer.To(subnetVNI), + VLAN: pointer.To(subnetVLAN), } } @@ -1898,7 +1899,7 @@ func planVPCSubnet(agent *agentapi.Agent, spec *dozer.Spec, vpcName string, vpc } spec.DHCPRelays[subnetIface] = &dozer.SpecDHCPRelay{ - SourceInterface: stringPtr(LO_SWITCH), + SourceInterface: pointer.To(LO_SWITCH), RelayAddress: []string{dhcpRelayIP.String()}, LinkSelect: true, VRFSelect: true, @@ -1919,7 +1920,7 @@ func buildVPCFilteringACL(agent *agentapi.Agent, vpcName string, vpc vpcapi.VPCS if vpc.IsSubnetRestricted(subnetName) { acl.Entries[1] = &dozer.SpecACLEntry{ - DestinationAddress: stringPtr(subnet.Subnet), + DestinationAddress: pointer.To(subnet.Subnet), Action: dozer.SpecACLEntryActionDrop, } } @@ -1967,7 +1968,7 @@ func buildVPCFilteringACL(agent *agentapi.Agent, vpcName string, vpc vpcapi.VPCS } acl.Entries[subnetID] = &dozer.SpecACLEntry{ - DestinationAddress: stringPtr(subnet), + DestinationAddress: pointer.To(subnet), Action: dozer.SpecACLEntryActionDrop, } } @@ -2053,7 +2054,7 @@ func addVPCFilteringACLEntryiesForVPC(agent *agentapi.Agent, spec *dozer.Spec, v aclName := vpcFilteringAccessListName(vpc1Name, vpc1SubnetName) if spec.ACLs[aclName] != nil { spec.ACLs[aclName].Entries[subnetID] = &dozer.SpecACLEntry{ - DestinationAddress: stringPtr(vpc2Subnet.Subnet), + DestinationAddress: pointer.To(vpc2Subnet.Subnet), Action: dozer.SpecACLEntryActionDrop, } } @@ -2138,8 +2139,8 @@ func planExternalPeerings(agent *agentapi.Agent, spec *dozer.Spec) error { importVrfRouteMap := vpcExtImportVrfRouteMapName(vpcName) spec.RouteMaps[importVrfRouteMap].Statements["5"] = &dozer.SpecRouteMapStatement{ Conditions: dozer.SpecRouteMapConditions{ - MatchPrefixList: stringPtr(ipnsSubnetsPrefixListName(vpc.IPv4Namespace)), - MatchSourceVRF: stringPtr(ipnsVrfName(vpc.IPv4Namespace)), + MatchPrefixList: pointer.To(ipnsSubnetsPrefixListName(vpc.IPv4Namespace)), + MatchSourceVRF: pointer.To(ipnsVrfName(vpc.IPv4Namespace)), }, Result: dozer.SpecRouteMapResultReject, } @@ -2156,10 +2157,10 @@ func planExternalPeerings(agent *agentapi.Agent, spec *dozer.Spec) error { } spec.RouteMaps[importVrfRouteMap].Statements[fmt.Sprintf("%d", 50000+idx)] = &dozer.SpecRouteMapStatement{ Conditions: dozer.SpecRouteMapConditions{ - MatchCommunityList: stringPtr(extInboundCommListName(externalName)), - MatchPrefixList: stringPtr(importVrfPrefixList), + MatchCommunityList: pointer.To(extInboundCommListName(externalName)), + MatchPrefixList: pointer.To(importVrfPrefixList), }, - SetLocalPreference: uint32Ptr(500), + SetLocalPreference: pointer.To(uint32(500)), Result: dozer.SpecRouteMapResultAccept, } @@ -2175,7 +2176,7 @@ func planExternalPeerings(agent *agentapi.Agent, spec *dozer.Spec) error { spec.VRFs[ipnsVrf].Interfaces[sub2] = &dozer.SpecVRFInterface{} spec.ACLInterfaces[sub1] = &dozer.SpecACLInterface{ - Egress: stringPtr(ipnsEgressAccessList(external.IPv4Namespace)), + Egress: pointer.To(ipnsEgressAccessList(external.IPv4Namespace)), } for _, subnetName := range peering.Permit.VPC.Subnets { @@ -2194,7 +2195,7 @@ func planExternalPeerings(agent *agentapi.Agent, spec *dozer.Spec) error { NextHops: []dozer.SpecVRFStaticRouteNextHop{ { IP: ip1, - Interface: stringPtr(strings.ReplaceAll(sub2, "Ethernet", "Eth")), + Interface: pointer.To(strings.ReplaceAll(sub2, "Ethernet", "Eth")), }, }, } @@ -2213,7 +2214,7 @@ func planExternalPeerings(agent *agentapi.Agent, spec *dozer.Spec) error { NextHops: []dozer.SpecVRFStaticRouteNextHop{ { IP: ip2, - Interface: stringPtr(strings.ReplaceAll(sub1, "Ethernet", "Eth")), + Interface: pointer.To(strings.ReplaceAll(sub1, "Ethernet", "Eth")), }, }, } @@ -2255,7 +2256,7 @@ func planLoopbackWorkaround(agent *agentapi.Agent, spec *dozer.Spec, loWReq stri VLAN: &vlan, IPs: map[string]*dozer.SpecInterfaceIP{ ip1: { - PrefixLen: uint8Ptr(31), + PrefixLen: pointer.To(uint8(31)), }, }, } @@ -2336,8 +2337,8 @@ func setupPhysicalInterfaceWithPortChannel(spec *dozer.Spec, name, description, } physicalIface := &dozer.SpecInterface{ - Description: stringPtr(description), - Enabled: boolPtr(true), + Description: pointer.To(description), + Enabled: pointer.To(true), Speed: getPortSpeed(agent, name), PortChannel: &portChannel, MTU: mtu, @@ -2444,15 +2445,3 @@ func communityForVPC(agent *agentapi.Agent, vpc string) (string, error) { return fmt.Sprintf("%s:%d", baseParts[0], id), nil } - -func stringPtr(s string) *string { return &s } - -func uint8Ptr(u uint8) *uint8 { return &u } - -func uint16Ptr(u uint16) *uint16 { return &u } - -func uint32Ptr(u uint32) *uint32 { return &u } - -func uint64Ptr(u uint64) *uint64 { return &u } - -func boolPtr(b bool) *bool { return &b } diff --git a/pkg/agent/dozer/bcm/plan_virtual_edge.go b/pkg/agent/dozer/bcm/plan_virtual_edge.go index 36f21050..915d0d05 100644 --- a/pkg/agent/dozer/bcm/plan_virtual_edge.go +++ b/pkg/agent/dozer/bcm/plan_virtual_edge.go @@ -23,6 +23,7 @@ import ( "github.com/pkg/errors" agentapi "go.githedgehog.com/fabric/api/agent/v1alpha2" "go.githedgehog.com/fabric/pkg/agent/dozer" + "go.githedgehog.com/fabric/pkg/util/pointer" ) func planVirtualEdge(agent *agentapi.Agent, spec *dozer.Spec) error { @@ -51,19 +52,19 @@ func planVirtualEdge(agent *agentapi.Agent, spec *dozer.Spec) error { } spec.VRFs[ipnsVrf] = &dozer.SpecVRF{ - Enabled: boolPtr(true), - // Description: stringPtr(fmt.Sprintf("IPv4NS %s", external.IPv4Namespace)), - AnycastMAC: stringPtr(ANYCAST_MAC), + Enabled: pointer.To(true), + // Description: pointer.To(fmt.Sprintf("IPv4NS %s", external.IPv4Namespace)), + AnycastMAC: pointer.To(ANYCAST_MAC), Interfaces: map[string]*dozer.SpecVRFInterface{}, StaticRoutes: map[string]*dozer.SpecVRFStaticRoute{}, TableConnections: map[string]*dozer.SpecVRFTableConnection{}, BGP: &dozer.SpecVRFBGP{ - AS: uint32Ptr(agent.Spec.Switch.ASN), - RouterID: stringPtr(protocolIP.String()), - NetworkImportCheck: boolPtr(true), + AS: pointer.To(agent.Spec.Switch.ASN), + RouterID: pointer.To(protocolIP.String()), + NetworkImportCheck: pointer.To(true), IPv4Unicast: dozer.SpecVRFBGPIPv4Unicast{ Enabled: true, - MaxPaths: uint32Ptr(getMaxPaths(agent)), + MaxPaths: pointer.To(getMaxPaths(agent)), Networks: map[string]*dozer.SpecVRFBGPNetwork{}, ImportVRFs: map[string]*dozer.SpecVRFBGPImportVRF{}, }, @@ -80,7 +81,7 @@ func planVirtualEdge(agent *agentapi.Agent, spec *dozer.Spec) error { Statements: map[string]*dozer.SpecRouteMapStatement{ "10": { Conditions: dozer.SpecRouteMapConditions{ - MatchCommunityList: stringPtr(extInboundCommListName(ipnsVrf)), + MatchCommunityList: pointer.To(extInboundCommListName(ipnsVrf)), }, Result: dozer.SpecRouteMapResultAccept, }, @@ -107,7 +108,7 @@ func planVirtualEdge(agent *agentapi.Agent, spec *dozer.Spec) error { return errors.Wrapf(err, "failed to parse external attach switch vlan %s", externalConfig.IfVlan) } - vlan := uint16Ptr(uint16(vlanVal)) + vlan := pointer.To(uint16(vlanVal)) ip, ipNet, err := net.ParseCIDR(externalConfig.IfIP) if err != nil { return errors.Wrapf(err, "failed to parse external attach switch ip %s", externalConfig.IfIP) @@ -115,14 +116,14 @@ func planVirtualEdge(agent *agentapi.Agent, spec *dozer.Spec) error { prefixLength, _ := ipNet.Mask.Size() spec.Interfaces[externalConfig.IfName] = &dozer.SpecInterface{ - Enabled: boolPtr(true), - Description: stringPtr(fmt.Sprintf("Virtual External %s", externalConfig.VRF)), + Enabled: pointer.To(true), + Description: pointer.To(fmt.Sprintf("Virtual External %s", externalConfig.VRF)), Subinterfaces: map[uint32]*dozer.SpecSubinterface{ uint32(vlanVal): { VLAN: vlan, IPs: map[string]*dozer.SpecInterfaceIP{ ip.String(): { - PrefixLen: uint8Ptr(uint8(prefixLength)), + PrefixLen: pointer.To(uint8(prefixLength)), }, }, }, @@ -134,10 +135,10 @@ func planVirtualEdge(agent *agentapi.Agent, spec *dozer.Spec) error { spec.VRFs[ipnsVrf].Interfaces[subIfaceName] = &dozer.SpecVRFInterface{} spec.VRFs[ipnsVrf].BGP.Neighbors[externalConfig.NeighborIP] = &dozer.SpecVRFBGPNeighbor{ - Enabled: boolPtr(true), - Description: stringPtr(fmt.Sprintf("External attach %s", externalConfig.VRF)), - RemoteAS: uint32Ptr(uint32(asnVal)), - IPv4Unicast: boolPtr(true), + Enabled: pointer.To(true), + Description: pointer.To(fmt.Sprintf("External attach %s", externalConfig.VRF)), + RemoteAS: pointer.To(uint32(asnVal)), + IPv4Unicast: pointer.To(true), IPv4UnicastImportPolicies: []string{extInboundRouteMapName(ipnsVrf)}, IPv4UnicastExportPolicies: []string{extOutboundRouteMapName(ipnsVrf)}, } diff --git a/pkg/agent/dozer/bcm/spec_acl.go b/pkg/agent/dozer/bcm/spec_acl.go index 628cb979..70186af3 100644 --- a/pkg/agent/dozer/bcm/spec_acl.go +++ b/pkg/agent/dozer/bcm/spec_acl.go @@ -24,6 +24,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) var specACLsEnforcer = &DefaultMapEnforcer[string, *dozer.SpecACL]{ @@ -57,7 +58,7 @@ var specACLBaseEnforcer = &DefaultValueEnforcer[string, *dozer.SpecACL]{ CreatePath: "/acl/acl-sets/acl-set", MutateDesired: func(key string, desired *dozer.SpecACL) *dozer.SpecACL { if desired != nil && desired.Description == nil { - desired.Description = ygot.String(key) // workaround to avoid skipping creation of the ACLs with empty description + desired.Description = pointer.To(key) // workaround to avoid skipping creation of the ACLs with empty description } return desired @@ -72,10 +73,10 @@ var specACLBaseEnforcer = &DefaultValueEnforcer[string, *dozer.SpecACL]{ Type: oc.OpenconfigAcl_ACL_TYPE_ACL_IPV4, Name: name, }: { - Name: ygot.String(name), + Name: pointer.To(name), Type: oc.OpenconfigAcl_ACL_TYPE_ACL_IPV4, Config: &oc.OpenconfigAcl_Acl_AclSets_AclSet_Config{ - Name: ygot.String(name), + Name: pointer.To(name), Type: oc.OpenconfigAcl_ACL_TYPE_ACL_IPV4, Description: value.Description, }, @@ -133,9 +134,9 @@ var specACLEntryEnforcer = &DefaultValueEnforcer[uint32, *dozer.SpecACLEntry]{ return &oc.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries{ AclEntry: map[uint32]*oc.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry{ seq: { - SequenceId: ygot.Uint32(seq), + SequenceId: pointer.To(seq), Config: &oc.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Config{ - SequenceId: ygot.Uint32(seq), + SequenceId: pointer.To(seq), Description: value.Description, }, Actions: &oc.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Actions{ @@ -210,13 +211,13 @@ var specACLInterfaceEnforcer = &DefaultValueEnforcer[string, *dozer.SpecACLInter return &oc.OpenconfigAcl_Acl_Interfaces{ Interface: map[string]*oc.OpenconfigAcl_Acl_Interfaces_Interface{ name: { - Id: ygot.String(name), + Id: pointer.To(name), Config: &oc.OpenconfigAcl_Acl_Interfaces_Interface_Config{ - Id: ygot.String(name), + Id: pointer.To(name), }, InterfaceRef: &oc.OpenconfigAcl_Acl_Interfaces_Interface_InterfaceRef{ Config: &oc.OpenconfigAcl_Acl_Interfaces_Interface_InterfaceRef_Config{ - Interface: ygot.String(name), + Interface: pointer.To(name), }, }, IngressAclSets: ingressAclSets, @@ -279,12 +280,12 @@ func unmarshalOCACLs(ocVal *oc.OpenconfigAcl_Acl) (map[string]*dozer.SpecACL, er if entry.Transport != nil && entry.Transport.Config != nil { if entry.Transport.Config.SourcePort != nil { if union, ok := entry.Transport.Config.SourcePort.(oc.UnionUint16); ok { - sourcePort = ygot.Uint16(uint16(union)) + sourcePort = pointer.To(uint16(union)) } } if entry.Transport.Config.DestinationPort != nil { if union, ok := entry.Transport.Config.DestinationPort.(oc.UnionUint16); ok { - destinationPort = ygot.Uint16(uint16(union)) + destinationPort = pointer.To(uint16(union)) } } } diff --git a/pkg/agent/dozer/bcm/spec_comm_lists.go b/pkg/agent/dozer/bcm/spec_comm_lists.go index 783a9bbb..bade1f6c 100644 --- a/pkg/agent/dozer/bcm/spec_comm_lists.go +++ b/pkg/agent/dozer/bcm/spec_comm_lists.go @@ -25,6 +25,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) var specCommunityListsEnforcer = &DefaultMapEnforcer[string, *dozer.SpecCommunityList]{ @@ -49,9 +50,9 @@ var specCommunityListEnforcer = &DefaultValueEnforcer[string, *dozer.SpecCommuni return &oc.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_BgpDefinedSets_CommunitySets{ CommunitySet: map[string]*oc.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_BgpDefinedSets_CommunitySets_CommunitySet{ name: { - CommunitySetName: ygot.String(name), + CommunitySetName: pointer.To(name), Config: &oc.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_BgpDefinedSets_CommunitySets_CommunitySet_Config{ - CommunitySetName: ygot.String(name), + CommunitySetName: pointer.To(name), CommunityMember: members, MatchSetOptions: oc.OpenconfigRoutingPolicy_MatchSetOptionsType_ANY, Action: oc.OpenconfigRoutingPolicyExt_RoutingPolicyExtActionType_PERMIT, diff --git a/pkg/agent/dozer/bcm/spec_dhcp.go b/pkg/agent/dozer/bcm/spec_dhcp.go index b95e7097..04afb0cd 100644 --- a/pkg/agent/dozer/bcm/spec_dhcp.go +++ b/pkg/agent/dozer/bcm/spec_dhcp.go @@ -24,6 +24,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) var specDHCPRelaysEnforcer = &DefaultMapEnforcer[string, *dozer.SpecDHCPRelay]{ @@ -50,7 +51,7 @@ var specDHCPRelayEnforcer = &DefaultValueEnforcer[string, *dozer.SpecDHCPRelay]{ return &oc.OpenconfigRelayAgent_RelayAgent_Dhcp_Interfaces{ Interface: map[string]*oc.OpenconfigRelayAgent_RelayAgent_Dhcp_Interfaces_Interface{ name: { - Id: ygot.String(name), + Id: pointer.To(name), AgentInformationOption: &oc.OpenconfigRelayAgent_RelayAgent_Dhcp_Interfaces_Interface_AgentInformationOption{ Config: &oc.OpenconfigRelayAgent_RelayAgent_Dhcp_Interfaces_Interface_AgentInformationOption_Config{ LinkSelect: linkSelect, diff --git a/pkg/agent/dozer/bcm/spec_interface.go b/pkg/agent/dozer/bcm/spec_interface.go index cc2e4738..73e4fbf1 100644 --- a/pkg/agent/dozer/bcm/spec_interface.go +++ b/pkg/agent/dozer/bcm/spec_interface.go @@ -26,6 +26,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) const ( @@ -128,8 +129,8 @@ var specInterfaceBasePortChannelsEnforcer = &DefaultValueEnforcer[string, *dozer MutateDesired: func(name string, desired *dozer.SpecInterface) *dozer.SpecInterface { if (isManagement(name) || isPhysical(name)) && desired == nil { return &dozer.SpecInterface{ - Enabled: ygot.Bool(false), - Description: ygot.String(INTERFACE_DISABLED_DESCRIPTION), + Enabled: pointer.To(false), + Description: pointer.To(INTERFACE_DISABLED_DESCRIPTION), } } return desired @@ -151,8 +152,8 @@ var specInterfaceBaseEnforcer = &DefaultValueEnforcer[string, *dozer.SpecInterfa MutateDesired: func(name string, desired *dozer.SpecInterface) *dozer.SpecInterface { if (isManagement(name) || isPhysical(name)) && desired == nil { return &dozer.SpecInterface{ - Enabled: ygot.Bool(false), - Description: ygot.String(INTERFACE_DISABLED_DESCRIPTION), + Enabled: pointer.To(false), + Description: pointer.To(INTERFACE_DISABLED_DESCRIPTION), } } return desired @@ -162,9 +163,9 @@ var specInterfaceBaseEnforcer = &DefaultValueEnforcer[string, *dozer.SpecInterfa var marshalSpecInterfaceBaseEnforcer = func(name string, value *dozer.SpecInterface) (ygot.ValidatedGoStruct, error) { val := &oc.OpenconfigInterfaces_Interfaces_Interface{ - Name: ygot.String(name), + Name: pointer.To(name), Config: &oc.OpenconfigInterfaces_Interfaces_Interface_Config{ - Name: ygot.String(name), + Name: pointer.To(name), Description: value.Description, Enabled: value.Enabled, Mtu: value.MTU, // TODO we'll not be able to unset it as we can't use replace @@ -181,7 +182,7 @@ var marshalSpecInterfaceBaseEnforcer = func(name string, value *dozer.SpecInterf val.RoutedVlan = &oc.OpenconfigInterfaces_Interfaces_Interface_RoutedVlan{ Ipv4: &oc.OpenconfigInterfaces_Interfaces_Interface_RoutedVlan_Ipv4{ Config: &oc.OpenconfigInterfaces_Interfaces_Interface_RoutedVlan_Ipv4_Config{ - Enabled: ygot.Bool(true), + Enabled: pointer.To(true), }, }, } @@ -210,11 +211,11 @@ var specInterfaceVLANIPEnforcer = &DefaultValueEnforcer[string, *dozer.SpecInter return &oc.OpenconfigInterfaces_Interfaces_Interface_RoutedVlan_Ipv4_Addresses{ Address: map[string]*oc.OpenconfigInterfaces_Interfaces_Interface_RoutedVlan_Ipv4_Addresses_Address{ name: { - Ip: ygot.String(name), + Ip: pointer.To(name), Config: &oc.OpenconfigInterfaces_Interfaces_Interface_RoutedVlan_Ipv4_Addresses_Address_Config{ - Ip: ygot.String(name), + Ip: pointer.To(name), PrefixLength: value.PrefixLen, - Secondary: ygot.Bool(false), + Secondary: pointer.To(false), }, }, }, @@ -265,9 +266,9 @@ var specInterfaceSubinterfaceBaseEnforcer = &DefaultValueEnforcer[uint32, *dozer return &oc.OpenconfigInterfaces_Interfaces_Interface_Subinterfaces{ Subinterface: map[uint32]*oc.OpenconfigInterfaces_Interfaces_Interface_Subinterfaces_Subinterface{ idx: { - Index: ygot.Uint32(idx), + Index: pointer.To(idx), Config: &oc.OpenconfigInterfaces_Interfaces_Interface_Subinterfaces_Subinterface_Config{ - Index: ygot.Uint32(idx), + Index: pointer.To(idx), }, Vlan: vlan, Ipv4: &oc.OpenconfigInterfaces_Interfaces_Interface_Subinterfaces_Subinterface_Ipv4{ @@ -300,11 +301,11 @@ var specInterfaceSubinterfaceIPEnforcer = &DefaultValueEnforcer[string, *dozer.S return &oc.OpenconfigInterfaces_Interfaces_Interface_Subinterfaces_Subinterface_Ipv4_Addresses{ Address: map[string]*oc.OpenconfigInterfaces_Interfaces_Interface_Subinterfaces_Subinterface_Ipv4_Addresses_Address{ ip: { - Ip: ygot.String(ip), + Ip: pointer.To(ip), Config: &oc.OpenconfigInterfaces_Interfaces_Interface_Subinterfaces_Subinterface_Ipv4_Addresses_Address_Config{ - Ip: ygot.String(ip), + Ip: pointer.To(ip), PrefixLength: value.PrefixLen, - Secondary: ygot.Bool(false), + Secondary: pointer.To(false), }, }, }, @@ -596,9 +597,9 @@ func unmarshalOCInterfaces(ocVal *oc.OpenconfigInterfaces_Interfaces) (map[strin if err != nil { return nil, errors.Wrapf(err, "can't parse %s", vlanID) } - vlan = ygot.Uint16(uint16(vlanVal)) + vlan = pointer.To(uint16(vlanVal)) } else if numVal, ok := vlanID.(oc.UnionUint16); ok { - vlan = ygot.Uint16(uint16(numVal)) + vlan = pointer.To(uint16(numVal)) } else { return nil, errors.Errorf("unknown vlan id type %v for %s.%d", vlanID, name, id) } diff --git a/pkg/agent/dozer/bcm/spec_lldp.go b/pkg/agent/dozer/bcm/spec_lldp.go index c0b7aad2..c6454ca8 100644 --- a/pkg/agent/dozer/bcm/spec_lldp.go +++ b/pkg/agent/dozer/bcm/spec_lldp.go @@ -22,6 +22,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) var specLLDPEnforcer = &DefaultValueEnforcer[string, *dozer.SpecLLDP]{ @@ -87,7 +88,7 @@ var specLLDPInterfaceEnforcer = &DefaultValueEnforcer[string, *dozer.SpecLLDPInt return &oc.OpenconfigLldp_Lldp_Interfaces{ Interface: map[string]*oc.OpenconfigLldp_Lldp_Interfaces_Interface{ name: { - Name: ygot.String(name), + Name: pointer.To(name), Config: &oc.OpenconfigLldp_Lldp_Interfaces_Interface_Config{ Enabled: value.Enabled, ManagementAddressIpv4: value.ManagementIPv4, diff --git a/pkg/agent/dozer/bcm/spec_lst.go b/pkg/agent/dozer/bcm/spec_lst.go index 40d0058d..696ee1f9 100644 --- a/pkg/agent/dozer/bcm/spec_lst.go +++ b/pkg/agent/dozer/bcm/spec_lst.go @@ -22,6 +22,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) var specLSTGroupsEnforcer = &DefaultMapEnforcer[string, *dozer.SpecLSTGroup]{ @@ -39,9 +40,9 @@ var specLSTGroupEnforcer = &DefaultValueEnforcer[string, *dozer.SpecLSTGroup]{ return &oc.OpenconfigLstExt_Lst_LstGroups{ LstGroup: map[string]*oc.OpenconfigLstExt_Lst_LstGroups_LstGroup{ name: { - Name: stringPtr(name), + Name: pointer.To(name), Config: &oc.OpenconfigLstExt_Lst_LstGroups_LstGroup_Config{ - Name: stringPtr(name), + Name: pointer.To(name), AllEvpnEsDownstream: value.AllEVPNESDownstream, Timeout: value.Timeout, }, @@ -101,9 +102,9 @@ var specLSTInterfaceEnforcer = &DefaultValueEnforcer[string, *dozer.SpecLSTInter groups := map[string]*oc.OpenconfigLstExt_Lst_Interfaces_Interface_UpstreamGroups_UpstreamGroup{} for _, group := range value.Groups { groups[group] = &oc.OpenconfigLstExt_Lst_Interfaces_Interface_UpstreamGroups_UpstreamGroup{ - GroupName: stringPtr(group), + GroupName: pointer.To(group), Config: &oc.OpenconfigLstExt_Lst_Interfaces_Interface_UpstreamGroups_UpstreamGroup_Config{ - GroupName: stringPtr(group), + GroupName: pointer.To(group), }, } } @@ -111,13 +112,13 @@ var specLSTInterfaceEnforcer = &DefaultValueEnforcer[string, *dozer.SpecLSTInter return &oc.OpenconfigLstExt_Lst_Interfaces{ Interface: map[string]*oc.OpenconfigLstExt_Lst_Interfaces_Interface{ id: { - Id: stringPtr(id), + Id: pointer.To(id), Config: &oc.OpenconfigLstExt_Lst_Interfaces_Interface_Config{ - Id: stringPtr(id), + Id: pointer.To(id), }, InterfaceRef: &oc.OpenconfigLstExt_Lst_Interfaces_Interface_InterfaceRef{ Config: &oc.OpenconfigLstExt_Lst_Interfaces_Interface_InterfaceRef_Config{ - Interface: stringPtr(id), + Interface: pointer.To(id), }, }, UpstreamGroups: &oc.OpenconfigLstExt_Lst_Interfaces_Interface_UpstreamGroups{ diff --git a/pkg/agent/dozer/bcm/spec_mclag.go b/pkg/agent/dozer/bcm/spec_mclag.go index 0449c6e7..d4c9fda9 100644 --- a/pkg/agent/dozer/bcm/spec_mclag.go +++ b/pkg/agent/dozer/bcm/spec_mclag.go @@ -24,6 +24,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) var specMCLAGDomainsEnforcer = &DefaultMapEnforcer[uint32, *dozer.SpecMCLAGDomain]{ @@ -41,12 +42,12 @@ var specMCLAGDomainEnforcer = &DefaultValueEnforcer[uint32, *dozer.SpecMCLAGDoma MclagDomain: map[uint32]*oc.OpenconfigMclag_Mclag_MclagDomains_MclagDomain{ id: { Config: &oc.OpenconfigMclag_Mclag_MclagDomains_MclagDomain_Config{ - DomainId: ygot.Uint32(id), - SourceAddress: ygot.String(strings.SplitN(value.SourceIP, "/", 2)[0]), // TODO is it good enough? - PeerAddress: ygot.String(strings.SplitN(value.PeerIP, "/", 2)[0]), - PeerLink: ygot.String(value.PeerLink), + DomainId: pointer.To(id), + SourceAddress: pointer.To(strings.SplitN(value.SourceIP, "/", 2)[0]), // TODO is it good enough? + PeerAddress: pointer.To(strings.SplitN(value.PeerIP, "/", 2)[0]), + PeerLink: pointer.To(value.PeerLink), }, - DomainId: ygot.Uint32(id), + DomainId: pointer.To(id), }, }, }, nil @@ -67,9 +68,9 @@ var specMCLAGInterfaceEnforcer = &DefaultValueEnforcer[string, *dozer.SpecMCLAGI return &oc.OpenconfigMclag_Mclag_Interfaces{ Interface: map[string]*oc.OpenconfigMclag_Mclag_Interfaces_Interface{ name: { - Name: ygot.String(name), + Name: pointer.To(name), Config: &oc.OpenconfigMclag_Mclag_Interfaces_Interface_Config{ - MclagDomainId: ygot.Uint32(value.DomainID), + MclagDomainId: pointer.To(value.DomainID), }, }, }, diff --git a/pkg/agent/dozer/bcm/spec_nat.go b/pkg/agent/dozer/bcm/spec_nat.go index 9796bffc..49b99a9f 100644 --- a/pkg/agent/dozer/bcm/spec_nat.go +++ b/pkg/agent/dozer/bcm/spec_nat.go @@ -25,6 +25,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) var specNATsEnforcer = &DefaultMapEnforcer[uint32, *dozer.SpecNAT]{ @@ -69,7 +70,7 @@ var specNATBaseEnforcer = &DefaultValueEnforcer[uint32, *dozer.SpecNAT]{ MutateDesired: func(id uint32, desired *dozer.SpecNAT) *dozer.SpecNAT { if id == 0 && desired == nil { desired = &dozer.SpecNAT{ - Enable: ygot.Bool(false), + Enable: pointer.To(false), } } @@ -81,9 +82,9 @@ var specNATBaseEnforcer = &DefaultValueEnforcer[uint32, *dozer.SpecNAT]{ return &oc.OpenconfigNat_Nat_Instances{ Instance: map[uint32]*oc.OpenconfigNat_Nat_Instances_Instance{ id: { - Id: ygot.Uint32(id), + Id: pointer.To(id), Config: &oc.OpenconfigNat_Nat_Instances_Instance_Config{ - Id: ygot.Uint32(id), + Id: pointer.To(id), Enable: value.Enable, }, }, @@ -106,9 +107,9 @@ var specNATPoolEnforcer = &DefaultValueEnforcer[string, *dozer.SpecNATPool]{ return &oc.OpenconfigNat_Nat_Instances_Instance_NatPool{ NatPoolEntry: map[string]*oc.OpenconfigNat_Nat_Instances_Instance_NatPool_NatPoolEntry{ name: { - PoolName: ygot.String(name), + PoolName: pointer.To(name), Config: &oc.OpenconfigNat_Nat_Instances_Instance_NatPool_NatPoolEntry_Config{ - PoolName: ygot.String(name), + PoolName: pointer.To(name), NatIp: value.Range, }, }, @@ -138,9 +139,9 @@ var specNATBindingEnforcer = &DefaultValueEnforcer[string, *dozer.SpecNATBinding return &oc.OpenconfigNat_Nat_Instances_Instance_NatAclPoolBinding{ NatAclPoolBindingEntry: map[string]*oc.OpenconfigNat_Nat_Instances_Instance_NatAclPoolBinding_NatAclPoolBindingEntry{ name: { - Name: ygot.String(name), + Name: pointer.To(name), Config: &oc.OpenconfigNat_Nat_Instances_Instance_NatAclPoolBinding_NatAclPoolBindingEntry_Config{ - Name: ygot.String(name), + Name: pointer.To(name), NatPool: value.Pool, Type: natType, }, @@ -171,9 +172,9 @@ var specNATEntryEnforcer = &DefaultValueEnforcer[string, *dozer.SpecNATEntry]{ return &oc.OpenconfigNat_Nat_Instances_Instance_NatMappingTable{ NatMappingEntry: map[string]*oc.OpenconfigNat_Nat_Instances_Instance_NatMappingTable_NatMappingEntry{ externalIP: { - ExternalAddress: ygot.String(externalIP), + ExternalAddress: pointer.To(externalIP), Config: &oc.OpenconfigNat_Nat_Instances_Instance_NatMappingTable_NatMappingEntry_Config{ - ExternalAddress: ygot.String(externalIP), + ExternalAddress: pointer.To(externalIP), InternalAddress: value.InternalAddress, Type: natType, }, diff --git a/pkg/agent/dozer/bcm/spec_ntp.go b/pkg/agent/dozer/bcm/spec_ntp.go index 0867d3b9..509413f3 100644 --- a/pkg/agent/dozer/bcm/spec_ntp.go +++ b/pkg/agent/dozer/bcm/spec_ntp.go @@ -22,6 +22,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) var specNTPEnforcer = &DefaultValueEnforcer[string, *dozer.SpecNTP]{ @@ -51,9 +52,9 @@ var specNTPServerEnforcer = &DefaultValueEnforcer[string, *dozer.SpecNTPServer]{ return &oc.OpenconfigSystem_System_Ntp_Servers{ Server: map[string]*oc.OpenconfigSystem_System_Ntp_Servers_Server{ name: { - Address: ygot.String(name), + Address: pointer.To(name), Config: &oc.OpenconfigSystem_System_Ntp_Servers_Server_Config{ - Address: ygot.String(name), + Address: pointer.To(name), Prefer: value.Prefer, }, }, diff --git a/pkg/agent/dozer/bcm/spec_prefix_lists.go b/pkg/agent/dozer/bcm/spec_prefix_lists.go index c2225b16..32bd15b3 100644 --- a/pkg/agent/dozer/bcm/spec_prefix_lists.go +++ b/pkg/agent/dozer/bcm/spec_prefix_lists.go @@ -27,6 +27,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) var specPrefixListsEnforcer = &DefaultMapEnforcer[string, *dozer.SpecPrefixList]{ @@ -62,9 +63,9 @@ var specPrefixListBaseEnforcer = &DefaultValueEnforcer[string, *dozer.SpecPrefix return &oc.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_PrefixSets{ PrefixSet: map[string]*oc.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_PrefixSets_PrefixSet{ name: { - Name: ygot.String(name), + Name: pointer.To(name), Config: &oc.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_PrefixSets_PrefixSet_Config{ - Name: ygot.String(name), + Name: pointer.To(name), Mode: oc.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_PrefixSets_PrefixSet_Config_Mode_IPV4, }, }, @@ -135,13 +136,13 @@ var specPrefixListEntryEnforcer = &DefaultValueEnforcer[uint32, *dozer.SpecPrefi IpPrefix: entry.Prefix.Prefix, MasklengthRange: maskLenRange, }: { - SequenceNumber: ygot.Uint32(seq), - IpPrefix: ygot.String(entry.Prefix.Prefix), - MasklengthRange: ygot.String(maskLenRange), + SequenceNumber: pointer.To(seq), + IpPrefix: pointer.To(entry.Prefix.Prefix), + MasklengthRange: pointer.To(maskLenRange), Config: &oc.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_PrefixSets_PrefixSet_ExtendedPrefixes_ExtendedPrefix_Config{ - SequenceNumber: ygot.Uint32(seq), - IpPrefix: ygot.String(entry.Prefix.Prefix), - MasklengthRange: ygot.String(maskLenRange), + SequenceNumber: pointer.To(seq), + IpPrefix: pointer.To(entry.Prefix.Prefix), + MasklengthRange: pointer.To(maskLenRange), Action: action, }, }, diff --git a/pkg/agent/dozer/bcm/spec_route_maps.go b/pkg/agent/dozer/bcm/spec_route_maps.go index 5a4ebdf3..e4b17e0a 100644 --- a/pkg/agent/dozer/bcm/spec_route_maps.go +++ b/pkg/agent/dozer/bcm/spec_route_maps.go @@ -25,6 +25,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) var specRouteMapsEnforcer = &DefaultMapEnforcer[string, *dozer.SpecRouteMap]{ @@ -59,9 +60,9 @@ var specRouteMapBaseEnforcer = &DefaultValueEnforcer[string, *dozer.SpecRouteMap return &oc.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions{ PolicyDefinition: map[string]*oc.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition{ name: { - Name: ygot.String(name), + Name: pointer.To(name), Config: &oc.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Config{ - Name: ygot.String(name), + Name: pointer.To(name), }, }, }, @@ -128,7 +129,7 @@ var specRouteMapStatementEnforcer = &DefaultValueEnforcer[string, *dozer.SpecRou conditions.BgpConditions.MatchEvpnSet.Config = &oc.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Conditions_BgpConditions_MatchEvpnSet_Config{} } - conditions.BgpConditions.MatchEvpnSet.Config.DefaultType5Route = ygot.Bool(true) + conditions.BgpConditions.MatchEvpnSet.Config.DefaultType5Route = pointer.To(true) } if statement.Conditions.MatchEVPNVNI != nil { if conditions.BgpConditions == nil { @@ -202,9 +203,9 @@ var specRouteMapStatementEnforcer = &DefaultValueEnforcer[string, *dozer.SpecRou statements := &oc.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_OrderedMap{} statements.Append(&oc.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement{ - Name: ygot.String(seq), + Name: pointer.To(seq), Config: &oc.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Config{ - Name: ygot.String(seq), + Name: pointer.To(seq), }, Conditions: conditions, Actions: &oc.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions{ @@ -253,7 +254,7 @@ func unmarshalOCRouteMaps(ocVal *oc.OpenconfigRoutingPolicy_RoutingPolicy) (map[ conditions := dozer.SpecRouteMapConditions{} if statement.Conditions != nil { if statement.Conditions.Config != nil && statement.Conditions.Config.InstallProtocolEq == oc.OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED { - conditions.DirectlyConnected = ygot.Bool(true) + conditions.DirectlyConnected = pointer.To(true) } if statement.Conditions.MatchPrefixSet != nil && statement.Conditions.MatchPrefixSet.Config != nil && statement.Conditions.MatchPrefixSet.Config.PrefixSet != nil { conditions.MatchPrefixList = statement.Conditions.MatchPrefixSet.Config.PrefixSet diff --git a/pkg/agent/dozer/bcm/spec_system.go b/pkg/agent/dozer/bcm/spec_system.go index 1c880092..62b508d9 100644 --- a/pkg/agent/dozer/bcm/spec_system.go +++ b/pkg/agent/dozer/bcm/spec_system.go @@ -29,6 +29,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) var specZTPEnforcer = &DefaultValueEnforcer[string, *dozer.Spec]{ @@ -65,7 +66,7 @@ func unmarshalOCZTPConfig(ocVal *oc.OpenconfigZtp_Ztp_Config) (*bool, error) { } if ocVal.AdminMode == nil { - return ygot.Bool(false), nil + return pointer.To(false), nil } return ocVal.AdminMode, nil @@ -136,9 +137,9 @@ var specPortGroupEnforcer = &DefaultValueEnforcer[string, *dozer.SpecPortGroup]{ return &oc.OpenconfigPortGroup_PortGroups{ PortGroup: map[string]*oc.OpenconfigPortGroup_PortGroups_PortGroup{ id: { - Id: ygot.String(id), + Id: pointer.To(id), Config: &oc.OpenconfigPortGroup_PortGroups_PortGroup_Config{ - Id: ygot.String(id), + Id: pointer.To(id), Speed: speed, }, }, @@ -223,10 +224,10 @@ var specPortBreakoutEnforcer = &DefaultValueEnforcer[string, *dozer.SpecPortBrea return &oc.OpenconfigPlatform_Components_Component_Port_BreakoutMode_Groups_Group{ Config: &oc.OpenconfigPlatform_Components_Component_Port_BreakoutMode_Groups_Group_Config{ - Index: ygot.Uint8(1), - NumBreakouts: ygot.Uint8(num), + Index: pointer.To(uint8(1)), + NumBreakouts: pointer.To(num), BreakoutSpeed: speed, - // NumPhysicalChannels: ygot.Uint8(0), // TODO check if it's really needed + // NumPhysicalChannels: pointer.To(0), // TODO check if it's really needed }, }, nil }, @@ -278,17 +279,17 @@ var specUserEnforcer = &DefaultValueEnforcer[string, *dozer.SpecUser]{ Marshal: func(name string, value *dozer.SpecUser) (ygot.ValidatedGoStruct, error) { var passwd, passwdHash *string if len(value.Password) == 63 && strings.HasPrefix(value.Password, "$5$") { - passwdHash = ygot.String(value.Password) + passwdHash = pointer.To(value.Password) } else { - passwd = ygot.String(value.Password) + passwd = pointer.To(value.Password) } return &oc.OpenconfigSystem_System_Aaa_Authentication_Users{ User: map[string]*oc.OpenconfigSystem_System_Aaa_Authentication_Users_User{ name: { - Username: ygot.String(name), + Username: pointer.To(name), Config: &oc.OpenconfigSystem_System_Aaa_Authentication_Users_User_Config{ - Username: ygot.String(name), + Username: pointer.To(name), Password: passwd, PasswordHashed: passwdHash, Role: oc.UnionString(value.Role), diff --git a/pkg/agent/dozer/bcm/spec_vrf.go b/pkg/agent/dozer/bcm/spec_vrf.go index 12b71334..b26aac36 100644 --- a/pkg/agent/dozer/bcm/spec_vrf.go +++ b/pkg/agent/dozer/bcm/spec_vrf.go @@ -25,6 +25,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" "golang.org/x/exp/maps" ) @@ -95,9 +96,9 @@ var specVRFBaseEnforcer = &DefaultValueEnforcer[string, *dozer.SpecVRF]{ return &oc.OpenconfigNetworkInstance_NetworkInstances{ NetworkInstance: map[string]*oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance{ name: { - Name: ygot.String(name), + Name: pointer.To(name), Config: &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Config{ - Name: ygot.String(name), + Name: pointer.To(name), Enabled: value.Enabled, Description: value.Description, }, @@ -146,12 +147,12 @@ var specVRFEVPNEthernetSegmentEnforcer = &DefaultValueEnforcer[string, *dozer.Sp return &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Evpn_EthernetSegments{ EthernetSegment: map[string]*oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Evpn_EthernetSegments_EthernetSegment{ name: { - Name: ygot.String(name), + Name: pointer.To(name), Config: &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Evpn_EthernetSegments_EthernetSegment_Config{ - Name: stringPtr(name), + Name: pointer.To(name), EsiType: oc.OpenconfigEvpn_EsiType_TYPE_0_OPERATOR_CONFIGURED, Esi: oc.UnionString(value.ESI), - Interface: stringPtr(name), + Interface: pointer.To(name), }, }, }, @@ -192,9 +193,9 @@ var specVRFInterfaceEnforcer = &DefaultValueEnforcer[string, *dozer.SpecVRFInter return &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Interfaces{ Interface: map[string]*oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Interfaces_Interface{ iface: { - Id: ygot.String(iface), + Id: pointer.To(iface), Config: &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Interfaces_Interface_Config{ - Id: ygot.String(iface), + Id: pointer.To(iface), }, }, }, @@ -385,9 +386,9 @@ var specVRFBGPNeighborEnforcer = &DefaultValueEnforcer[string, *dozer.SpecVRFBGP return &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_Bgp_Neighbors{ Neighbor: map[string]*oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_Bgp_Neighbors_Neighbor{ name: { - NeighborAddress: ygot.String(name), + NeighborAddress: pointer.To(name), Config: &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_Bgp_Neighbors_Neighbor_Config{ - NeighborAddress: ygot.String(name), + NeighborAddress: pointer.To(name), Enabled: value.Enabled, Description: value.Description, PeerAs: value.RemoteAS, @@ -434,9 +435,9 @@ var specVRFBGPNetworkEnforcer = &DefaultValueEnforcer[string, *dozer.SpecVRFBGPN return &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_Bgp_Global_AfiSafis_AfiSafi_NetworkConfig{ Network: map[string]*oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_Bgp_Global_AfiSafis_AfiSafi_NetworkConfig_Network{ prefix: { - Prefix: ygot.String(prefix), + Prefix: pointer.To(prefix), Config: &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_Bgp_Global_AfiSafis_AfiSafi_NetworkConfig_Network_Config{ - Prefix: ygot.String(prefix), + Prefix: pointer.To(prefix), }, }, }, @@ -571,9 +572,9 @@ var specVRFStaticRouteEnforcer = &DefaultValueEnforcer[string, *dozer.SpecVRFSta index := fmt.Sprintf("%s_%s", *nextHop.Interface, nextHop.IP) nextHops[index] = &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static_NextHops_NextHop{ - Index: ygot.String(index), + Index: pointer.To(index), Config: &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static_NextHops_NextHop_Config{ - Index: ygot.String(index), + Index: pointer.To(index), NextHop: oc.UnionString(nextHop.IP), }, InterfaceRef: &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static_NextHops_NextHop_InterfaceRef{ @@ -587,9 +588,9 @@ var specVRFStaticRouteEnforcer = &DefaultValueEnforcer[string, *dozer.SpecVRFSta return &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes{ Static: map[string]*oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static{ prefix: { - Prefix: ygot.String(prefix), + Prefix: pointer.To(prefix), Config: &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static_Config{ - Prefix: ygot.String(prefix), + Prefix: pointer.To(prefix), }, NextHops: &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static_NextHops{ NextHop: nextHops, @@ -697,7 +698,7 @@ func unmarshalOCVRFs(ocVal *oc.OpenconfigNetworkInstance_NetworkInstances) (map[ if l2vpnEVPN.RouteAdvertise != nil { for _, route := range l2vpnEVPN.RouteAdvertise.RouteAdvertiseList { if route.Config != nil && route.Config.AdvertiseAfiSafi == oc.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST { - bgp.L2VPNEVPN.AdvertiseIPv4Unicast = ygot.Bool(true) + bgp.L2VPNEVPN.AdvertiseIPv4Unicast = pointer.To(true) bgp.L2VPNEVPN.AdvertiseIPv4UnicastRouteMaps = route.Config.RouteMap break } @@ -745,9 +746,9 @@ func unmarshalOCVRFs(ocVal *oc.OpenconfigNetworkInstance_NetworkInstances) (map[ var peerType *string if neighbor.Config.PeerType == oc.OpenconfigBgp_PeerType_INTERNAL { - peerType = ygot.String(dozer.SpecVRFBGPNeighborPeerTypeInternal) + peerType = pointer.To(dozer.SpecVRFBGPNeighborPeerTypeInternal) } else if neighbor.Config.PeerType == oc.OpenconfigBgp_PeerType_EXTERNAL { - peerType = ygot.String(dozer.SpecVRFBGPNeighborPeerTypeExternal) + peerType = pointer.To(dozer.SpecVRFBGPNeighborPeerTypeExternal) } bgp.Neighbors[neighborName] = &dozer.SpecVRFBGPNeighbor{ @@ -868,7 +869,7 @@ func unmarshalOCVRFs(ocVal *oc.OpenconfigNetworkInstance_NetworkInstances) (map[ enabled := ocVRF.Config.Enabled if enabled == nil { - enabled = ygot.Bool(true) + enabled = pointer.To(true) } if !bgpOk { diff --git a/pkg/agent/dozer/bcm/spec_vxlan.go b/pkg/agent/dozer/bcm/spec_vxlan.go index 793bc227..0a9e5224 100644 --- a/pkg/agent/dozer/bcm/spec_vxlan.go +++ b/pkg/agent/dozer/bcm/spec_vxlan.go @@ -25,6 +25,7 @@ import ( "go.githedgehog.com/fabric/pkg/agent/dozer" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) var specVXLANTunnelsEnforcer = &DefaultMapEnforcer[string, *dozer.SpecVXLANTunnel]{ @@ -42,7 +43,7 @@ var specVXLANTunnelEnforcer = &DefaultValueEnforcer[string, *dozer.SpecVXLANTunn return &oc.SonicVxlan_SonicVxlan_VXLAN_TUNNEL{ VXLAN_TUNNEL_LIST: map[string]*oc.SonicVxlan_SonicVxlan_VXLAN_TUNNEL_VXLAN_TUNNEL_LIST{ name: { - Name: ygot.String(name), + Name: pointer.To(name), SrcIp: value.SourceIP, SrcIntf: value.SourceInterface, }, @@ -66,7 +67,7 @@ var specVXLANEVPNNVOEnforcer = &DefaultValueEnforcer[string, *dozer.SpecVXLANEVP return &oc.SonicVxlan_SonicVxlan_VXLAN_EVPN_NVO{ VXLAN_EVPN_NVO_LIST: map[string]*oc.SonicVxlan_SonicVxlan_VXLAN_EVPN_NVO_VXLAN_EVPN_NVO_LIST{ name: { - Name: ygot.String(name), + Name: pointer.To(name), SourceVtep: value.SourceVTEP, }, }, @@ -102,9 +103,9 @@ var specVXLANTunnelMapEnforcer = &DefaultValueEnforcer[string, *dozer.SpecVXLANT Name: "vtepfabric", // TODO ditto Mapname: name, }: { - Name: ygot.String("vtepfabric"), // TODO ditto - Mapname: ygot.String(name), - Vlan: ygot.String(fmt.Sprintf("Vlan%d", *value.VLAN)), + Name: pointer.To("vtepfabric"), // TODO ditto + Mapname: pointer.To(name), + Vlan: pointer.To(fmt.Sprintf("Vlan%d", *value.VLAN)), Vni: value.VNI, }, }, @@ -124,7 +125,7 @@ var specVRFVNIEnforcer = &DefaultValueEnforcer[string, *dozer.SpecVRFVNIEntry]{ DeleteWeight: ActionWeightVRFVNIDelete, Marshal: func(name string, value *dozer.SpecVRFVNIEntry) (ygot.ValidatedGoStruct, error) { return &oc.SonicVrf_SonicVrf_VRF_VRF_LIST{ - VrfName: ygot.String(name), + VrfName: pointer.To(name), Vni: value.VNI, }, nil }, @@ -183,7 +184,7 @@ func unmarshalActualVXLANs(ocVal *oc.SonicVxlan_SonicVxlan) (map[string]*dozer.S if err != nil { return nil, nil, nil, errors.Wrapf(err, "can't parse vlan %s", *vxlanTunnelMap.Vlan) } - vlan = ygot.Uint16(uint16(value)) + vlan = pointer.To(uint16(value)) } vxlanTunnelMaps[key.Mapname] = &dozer.SpecVXLANTunnelMap{ @@ -246,7 +247,7 @@ var specSuppressVLANNeighEnforcer = &DefaultValueEnforcer[string, *dozer.SpecSup return &oc.SonicVxlan_SonicVxlan_SUPPRESS_VLAN_NEIGH{ SUPPRESS_VLAN_NEIGH_LIST: map[string]*oc.SonicVxlan_SonicVxlan_SUPPRESS_VLAN_NEIGH_SUPPRESS_VLAN_NEIGH_LIST{ name: { - Name: ygot.String(name), + Name: pointer.To(name), Suppress: oc.SonicVxlan_SonicVxlan_SUPPRESS_VLAN_NEIGH_SUPPRESS_VLAN_NEIGH_LIST_Suppress_on, }, }, diff --git a/pkg/agent/dozer/bcm/util.go b/pkg/agent/dozer/bcm/util.go index 184817ce..ab6d731f 100644 --- a/pkg/agent/dozer/bcm/util.go +++ b/pkg/agent/dozer/bcm/util.go @@ -17,8 +17,8 @@ package bcm import ( "strings" - "github.com/openconfig/ygot/ygot" "go.githedgehog.com/fabric/pkg/agent/dozer/bcm/gnmi/oc" + "go.githedgehog.com/fabric/pkg/util/pointer" ) func UnmarshalPortSpeed(speedRaw oc.E_OpenconfigIfEthernet_ETHERNET_SPEED) *string { @@ -32,7 +32,7 @@ func UnmarshalPortSpeed(speedRaw oc.E_OpenconfigIfEthernet_ETHERNET_SPEED) *stri speed = strings.TrimPrefix(speed, "SPEED_") speed = strings.TrimSuffix(speed, "B") - return ygot.String(speed) + return pointer.To(speed) } func MarshalPortSpeed(speed string) (oc.E_OpenconfigIfEthernet_ETHERNET_SPEED, bool) { diff --git a/pkg/util/pointer/pointer.go b/pkg/util/pointer/pointer.go new file mode 100644 index 00000000..56d2442c --- /dev/null +++ b/pkg/util/pointer/pointer.go @@ -0,0 +1,5 @@ +package pointer + +func To[T any](val T) *T { + return &val +}