MCPcopy
hub / github.com/osrg/gobgp / UnmarshalNLRI

Function UnmarshalNLRI

pkg/apiutil/attribute.go:1650–2048  ·  view source on GitHub ↗
(rf bgp.Family, an *api.NLRI)

Source from the content-addressed store, hash-verified

1648}
1649
1650func UnmarshalNLRI(rf bgp.Family, an *api.NLRI) (bgp.NLRI, error) {
1651 var nlri bgp.NLRI
1652
1653 switch n := an.GetNlri().(type) {
1654 case *api.NLRI_Prefix:
1655 v := n.Prefix
1656 prefix, err := netip.ParsePrefix(fmt.Sprintf("%s/%d", v.Prefix, v.PrefixLen))
1657 if err != nil {
1658 return nil, err
1659 }
1660 nlri, err = bgp.NewIPAddrPrefix(prefix)
1661 if err != nil {
1662 return nil, err
1663 }
1664 case *api.NLRI_LabeledPrefix:
1665 v := n.LabeledPrefix
1666 prefix, err := netip.ParsePrefix(fmt.Sprintf("%s/%d", v.Prefix, v.PrefixLen))
1667 if err != nil {
1668 return nil, err
1669 }
1670 nlri, _ = bgp.NewLabeledIPAddrPrefix(prefix, *bgp.NewMPLSLabelStack(v.Labels...))
1671 case *api.NLRI_Encapsulation:
1672 v := n.Encapsulation
1673 addr, err := netip.ParseAddr(v.Address)
1674 if err != nil {
1675 return nil, err
1676 }
1677 nlri, _ = bgp.NewEncapNLRI(addr)
1678 case *api.NLRI_Vpls:
1679 v := n.Vpls
1680 if rf == bgp.RF_VPLS {
1681 rd, err := UnmarshalRD(v.Rd)
1682 if err != nil {
1683 return nil, err
1684 }
1685 nlri = bgp.NewVPLSNLRI(
1686 rd,
1687 uint16(v.VeId),
1688 uint16(v.VeBlockOffset),
1689 uint16(v.VeBlockSize),
1690 v.LabelBlockBase)
1691 }
1692 case *api.NLRI_EvpnEthernetAd:
1693 v := n.EvpnEthernetAd
1694 if rf == bgp.RF_EVPN {
1695 rd, err := UnmarshalRD(v.Rd)
1696 if err != nil {
1697 return nil, err
1698 }
1699 esi, err := unmarshalESI(v.Esi)
1700 if err != nil {
1701 return nil, err
1702 }
1703 nlri = bgp.NewEVPNEthernetAutoDiscoveryRoute(rd, *esi, v.EthernetTag, v.Label)
1704 }
1705 case *api.NLRI_EvpnMacadv:
1706 v := n.EvpnMacadv
1707 if rf == bgp.RF_EVPN {

Callers 2

UnmarshalNLRIsFunction · 0.85
GetNativeNlriFunction · 0.85

Calls 15

NewIPAddrPrefixFunction · 0.92
NewLabeledIPAddrPrefixFunction · 0.92
NewMPLSLabelStackFunction · 0.92
NewEncapNLRIFunction · 0.92
NewVPLSNLRIFunction · 0.92
NewEVPNIPPrefixRouteFunction · 0.92
NewSRPolicyFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…