()
| 1278 | } |
| 1279 | |
| 1280 | func (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 | |
| 1332 | func (p *Path) updateHash() { |
| 1333 | hash := fnv1a.Init64 |
no test coverage detected