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

Method ToLocal

internal/pkg/table/path.go:1280–1330  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1278}
1279
1280func (p *Path) ToLocal() *Path {
1281 var newFamily bgp.Family
1282 nlri := p.GetNlri()
1283 f := p.GetFamily()
1284 switch f {
1285 case bgp.RF_IPv4_VPN, bgp.RF_IPv6_VPN:
1286 n := nlri.(*bgp.LabeledVPNIPAddrPrefix)
1287 nlri, _ = bgp.NewIPAddrPrefix(n.Prefix)
1288 if f == bgp.RF_IPv4_VPN {
1289 newFamily = bgp.RF_IPv4_UC
1290 } else {
1291 newFamily = bgp.RF_IPv6_UC
1292 }
1293 case bgp.RF_FS_IPv4_VPN, bgp.RF_FS_IPv6_VPN:
1294 n := nlri.(*bgp.FlowSpecNLRI)
1295 newFamily = bgp.RF_FS_IPv4_UC
1296 if f == bgp.RF_FS_IPv6_VPN {
1297 newFamily = bgp.RF_FS_IPv6_UC
1298 }
1299 nlri, _ = bgp.NewFlowSpecUnicast(newFamily, n.Value)
1300 default:
1301 return p
1302 }
1303 path := NewPath(newFamily, p.OriginInfo().source, bgp.PathNLRI{NLRI: nlri}, p.IsWithdraw, p.GetPathAttrs(), p.GetTimestamp(), false)
1304 switch f {
1305 case bgp.RF_IPv4_VPN, bgp.RF_IPv6_VPN:
1306 path.delPathAttr(bgp.BGP_ATTR_TYPE_EXTENDED_COMMUNITIES)
1307 case bgp.RF_FS_IPv4_VPN, bgp.RF_FS_IPv6_VPN:
1308 extcomms := path.GetExtCommunities()
1309 newExtComms := make([]bgp.ExtendedCommunityInterface, 0, len(extcomms))
1310 for _, extComm := range extcomms {
1311 _, subType := extComm.GetTypes()
1312 if subType == bgp.EC_SUBTYPE_ROUTE_TARGET {
1313 continue
1314 }
1315 newExtComms = append(newExtComms, extComm)
1316 }
1317 path.SetExtCommunities(newExtComms, true)
1318 }
1319
1320 if f == bgp.RF_IPv4_VPN {
1321 nh := path.GetNexthop()
1322 path.delPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
1323 pa, _ := bgp.NewPathAttributeNextHop(nh)
1324 path.setPathAttr(pa)
1325 }
1326 path.IsNexthopInvalid = p.IsNexthopInvalid
1327 path.localID = p.localID
1328 path.remoteID = p.remoteID
1329 return path
1330}
1331
1332func (p *Path) updateHash() {
1333 hash := fnv1a.Init64

Callers 4

prePolicyFilterpathMethod · 0.80
filteredPathForPeerFunction · 0.80
InfoMethod · 0.80
SelectMethod · 0.80

Calls 15

GetNlriMethod · 0.95
GetFamilyMethod · 0.95
OriginInfoMethod · 0.95
GetPathAttrsMethod · 0.95
GetTimestampMethod · 0.95
delPathAttrMethod · 0.95
GetExtCommunitiesMethod · 0.95
SetExtCommunitiesMethod · 0.95
GetNexthopMethod · 0.95
setPathAttrMethod · 0.95
NewIPAddrPrefixFunction · 0.92
NewFlowSpecUnicastFunction · 0.92

Tested by

no test coverage detected