@Test public void testGetNeighborAs() { BgpRouteEntry bgpRouteEntry = generateBgpRouteEntry(); assertThat(bgpRouteEntry.getNeighborAs(), is(1L)); Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24"); Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8"); byte origin = BgpConstants.Update.Origin.IGP; ArrayList<BgpRouteEntry.PathSegment> pathSegments = new ArrayList<>(); BgpRouteEntry.AsPath asPath = new BgpRouteEntry.AsPath(pathSegments); long localPref = 100; long multiExitDisc = 20; bgpRouteEntry = new BgpRouteEntry(bgpSession, prefix, nextHop, origin, asPath, localPref); bgpRouteEntry.setMultiExitDisc(multiExitDisc); assertThat(bgpRouteEntry.getNeighborAs(), is(BgpConstants.BGP_AS_0)); }
long getNeighborAs() { PathSegment firstPathSegment = null; if (isLocalRoute()) { return BgpConstants.BGP_AS_0; } for (PathSegment pathSegment : asPath.getPathSegments()) { if ((pathSegment.getType() == BgpConstants.Update.AsPath.AS_SET) || (pathSegment.getType() == BgpConstants.Update.AsPath.AS_SEQUENCE)) { firstPathSegment = pathSegment; break; } } if (firstPathSegment == null) { return BgpConstants.BGP_AS_0; } if (firstPathSegment.getSegmentAsNumbers().isEmpty()) { return BgpConstants.BGP_AS_0; } return firstPathSegment.getSegmentAsNumbers().get(0); }
BgpRouteEntry extends RouteEntry { long getNeighborAs() { PathSegment firstPathSegment = null; if (isLocalRoute()) { return BgpConstants.BGP_AS_0; } for (PathSegment pathSegment : asPath.getPathSegments()) { if ((pathSegment.getType() == BgpConstants.Update.AsPath.AS_SET) || (pathSegment.getType() == BgpConstants.Update.AsPath.AS_SEQUENCE)) { firstPathSegment = pathSegment; break; } } if (firstPathSegment == null) { return BgpConstants.BGP_AS_0; } if (firstPathSegment.getSegmentAsNumbers().isEmpty()) { return BgpConstants.BGP_AS_0; } return firstPathSegment.getSegmentAsNumbers().get(0); } }
BgpRouteEntry extends RouteEntry { long getNeighborAs() { PathSegment firstPathSegment = null; if (isLocalRoute()) { return BgpConstants.BGP_AS_0; } for (PathSegment pathSegment : asPath.getPathSegments()) { if ((pathSegment.getType() == BgpConstants.Update.AsPath.AS_SET) || (pathSegment.getType() == BgpConstants.Update.AsPath.AS_SEQUENCE)) { firstPathSegment = pathSegment; break; } } if (firstPathSegment == null) { return BgpConstants.BGP_AS_0; } if (firstPathSegment.getSegmentAsNumbers().isEmpty()) { return BgpConstants.BGP_AS_0; } return firstPathSegment.getSegmentAsNumbers().get(0); } BgpRouteEntry(BgpSession bgpSession, IpPrefix prefix,
                         IpAddress nextHop, byte origin,
                         BgpRouteEntry.AsPath asPath, long localPref); }
BgpRouteEntry extends RouteEntry { long getNeighborAs() { PathSegment firstPathSegment = null; if (isLocalRoute()) { return BgpConstants.BGP_AS_0; } for (PathSegment pathSegment : asPath.getPathSegments()) { if ((pathSegment.getType() == BgpConstants.Update.AsPath.AS_SET) || (pathSegment.getType() == BgpConstants.Update.AsPath.AS_SEQUENCE)) { firstPathSegment = pathSegment; break; } } if (firstPathSegment == null) { return BgpConstants.BGP_AS_0; } if (firstPathSegment.getSegmentAsNumbers().isEmpty()) { return BgpConstants.BGP_AS_0; } return firstPathSegment.getSegmentAsNumbers().get(0); } BgpRouteEntry(BgpSession bgpSession, IpPrefix prefix,
                         IpAddress nextHop, byte origin,
                         BgpRouteEntry.AsPath asPath, long localPref); BgpSession getBgpSession(); byte getOrigin(); BgpRouteEntry.AsPath getAsPath(); long getLocalPref(); long getMultiExitDisc(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); }
BgpRouteEntry extends RouteEntry { long getNeighborAs() { PathSegment firstPathSegment = null; if (isLocalRoute()) { return BgpConstants.BGP_AS_0; } for (PathSegment pathSegment : asPath.getPathSegments()) { if ((pathSegment.getType() == BgpConstants.Update.AsPath.AS_SET) || (pathSegment.getType() == BgpConstants.Update.AsPath.AS_SEQUENCE)) { firstPathSegment = pathSegment; break; } } if (firstPathSegment == null) { return BgpConstants.BGP_AS_0; } if (firstPathSegment.getSegmentAsNumbers().isEmpty()) { return BgpConstants.BGP_AS_0; } return firstPathSegment.getSegmentAsNumbers().get(0); } BgpRouteEntry(BgpSession bgpSession, IpPrefix prefix,
                         IpAddress nextHop, byte origin,
                         BgpRouteEntry.AsPath asPath, long localPref); BgpSession getBgpSession(); byte getOrigin(); BgpRouteEntry.AsPath getAsPath(); long getLocalPref(); long getMultiExitDisc(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString();  }