use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes in project bgpcep by opendaylight.
the class BGPParserTest method testIPv6Nlri.
/*
* Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST.
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 80 <- length (128) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 69 <- total path attribute length (105)
* 40 <- attribute flags
* 01 <- attribute type code (origin)
* 01 <- attribute length
* 00 <- Origin value (IGP)
* 40 <- attribute flags
* 02 <- attribute type code (as path)
* 06 <- attribute length
* 02 <- AS_SEQUENCE
* 01 <- path segment count
* 00 00 fd e9 <- path segment value (65001)
* 40 <- attribute flags
* 03 <- attribute type code (next hop)
* 04 <- attribute length
* 0a 00 00 00 <- next hop value (10.0.0.0)
* 80 <- attribute flags
* 04 <- attribute type code (multi exit disc)
* 04 <- attribute length
* 00 00 00 00 <- value
* 80 <- attribute flags
* 09 <- attribute type code (originator id)
* 04 <- attribute length
* 7f 00 00 01 <- value (localhost ip)
* 80 <- attribute flags
* 0a <- attribute type code (cluster list)
* 08 <- attribute length
* 01 02 03 04 <- value
* 05 06 07 08 <- value
* 80 <- attribute flags
* 0e <- attribute type code (mp reach nlri)
* 40 <- attribute length
* 00 02 <- AFI (Ipv6)
* 01 <- SAFI (Unicast)
* 20 <- length of next hop
* 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 <- global
* fe 80 00 00 00 00 00 00 c0 01 0b ff fe 7e 00 <- link local
* 00 <- reserved
*
* //NLRI
* 40 20 01 0d b8 00 01 00 02 <- IPv6 Prefix (2001:db8:1:2:: / 64)
* 40 20 01 0d b8 00 01 00 01 <- IPv6 Prefix (2001:db8:1:1:: / 64)
* 40 20 01 0d b8 00 01 00 00 <- IPv6 Prefix (2001:db8:1:: / 64)
*
*/
@Test
public void testIPv6Nlri() throws Exception {
final Update message = (Update) messageRegistry.parseMessage(Unpooled.wrappedBuffer(input), null);
// check fields
assertNull(message.getWithdrawnRoutes());
final UpdateBuilder builder = new UpdateBuilder();
// check NLRI
final List<Ipv6Prefixes> prefs = new ArrayList<>();
prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1:2::/64")).build());
prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1:1::/64")).build());
prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1::/64")).build());
assertNull(message.getNlri());
// attributes
final List<AsNumber> asNumbers = new ArrayList<>();
asNumbers.add(new AsNumber(65001L));
final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
final Ipv6NextHopCase nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new Ipv4Address("1.2.3.4")), new ClusterIdentifier(new Ipv4Address("5.6.7.8")));
// check path attributes
final Attributes attrs = message.getAttributes();
final AttributesBuilder paBuilder = new AttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
paBuilder.setOriginatorId(new OriginatorIdBuilder().setOriginator(new Ipv4Address("127.0.0.1")).build());
assertEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId());
paBuilder.setClusterId(new ClusterIdBuilder().setCluster(clusters).build());
assertEquals(paBuilder.getClusterId(), attrs.getClusterId());
final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
mpBuilder.setAfi(Ipv6AddressFamily.class);
mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
mpBuilder.setCNextHop(nextHop);
mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(prefs).build()).build()).build());
paBuilder.addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mpBuilder.build()).build());
assertEquals(paBuilder.getAugmentation(Attributes1.class).getMpReachNlri(), attrs.getAugmentation(Attributes1.class).getMpReachNlri());
paBuilder.setUnrecognizedAttributes(Collections.emptyList());
// check API message
builder.setAttributes(paBuilder.build());
assertEquals(builder.build(), message);
final ByteBuf buffer = Unpooled.buffer();
messageRegistry.serializeMessage(message, buffer);
assertArrayEquals(input, ByteArray.readAllBytes(buffer));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes in project bgpcep by opendaylight.
the class IPv6RIBSupport method extractPrefixes.
private List<Ipv6Prefixes> extractPrefixes(final Collection<MapEntryNode> routes) {
final List<Ipv6Prefixes> prefs = new ArrayList<>(routes.size());
for (final MapEntryNode route : routes) {
final String prefix = (String) NormalizedNodes.findNode(route, routePrefixIdentifier()).get().getValue();
prefs.add(new Ipv6PrefixesBuilder().setPathId(PathIdUtil.buildPathId(route, routePathIdNid())).setPrefix(new Ipv6Prefix(prefix)).build());
}
return prefs;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes in project bgpcep by opendaylight.
the class AbstractFlowspecL3vpnRIBSupport method buildWithdrawnDestination.
@Nonnull
@Override
protected DestinationType buildWithdrawnDestination(@Nonnull final Collection<MapEntryNode> routes) {
final MapEntryNode routesCont = Iterables.getOnlyElement(routes);
final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid());
final RouteDistinguisher rd = extractRouteDistinguisher(routesCont, this.routeDistinguisherNID);
return this.nlriParser.createWithdrawnDestinationType(new Object[] { rd, this.nlriParser.extractFlowspec(Iterables.getOnlyElement(routes)) }, pathId);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes in project bgpcep by opendaylight.
the class AdjRibInWriter method updateRoutes.
void updateRoutes(final MpReachNlri nlri, final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes attributes) {
final TablesKey key = new TablesKey(nlri.getAfi(), nlri.getSafi());
final TableContext ctx = this.tables.get(key);
if (ctx == null) {
LOG.debug("No table for {}, not accepting NLRI {}", key, nlri);
return;
}
final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction();
ctx.writeRoutes(tx, nlri, attributes);
LOG.trace("Write routes {}", nlri);
Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
LOG.trace("Write routes {}, succeed", nlri);
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("Write routes failed", throwable);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes in project bgpcep by opendaylight.
the class AbstractBestPathSelector method isExistingPathBetter.
/**
* Chooses best route according to BGP best path selection.
*
* @param state attributes of the new route
* @return true if the existing path is better, false if the new path is better
*/
protected boolean isExistingPathBetter(@Nonnull final BestPathState state) {
/*
* 2. prefer path with higher LOCAL_PREF
*
* FIXME: for eBGP cases (when the LOCAL_PREF is missing), we should assign a policy-based preference
* before we ever get here.
*/
if (this.bestState.getLocalPref() == null && state.getLocalPref() != null) {
return true;
}
if (this.bestState.getLocalPref() != null && state.getLocalPref() == null) {
return false;
}
if (state.getLocalPref() != null && state.getLocalPref() > this.bestState.getLocalPref()) {
return false;
}
if (state.getLocalPref() != null && state.getLocalPref() < this.bestState.getLocalPref()) {
return true;
}
// 4. prefer the path with the shortest AS_PATH.
if (this.bestState.getAsPathLength() != state.getAsPathLength()) {
return this.bestState.getAsPathLength() < state.getAsPathLength();
}
// - IGP is lower than Exterior Gateway Protocol (EGP), and EGP is lower than INCOMPLETE
if (!this.bestState.getOrigin().equals(state.getOrigin())) {
final BgpOrigin bo = this.bestState.getOrigin();
final BgpOrigin no = state.getOrigin();
// This trick relies on the order in which the values are declared in the model.
return no.ordinal() > bo.ordinal();
}
// FIXME: we should be able to cache the best AS
final Long bestAs = this.bestState.getPeerAs();
final Long newAs = state.getPeerAs();
/*
* Checks 6 and 7 are mutually-exclusive, as MEDs are comparable
* only when the routes originated from the same AS. On the other
* hand, when they are from the same AS, they are in the same iBGP/eBGP
* relationship.
*
*/
if (bestAs.equals(newAs)) {
// 6. prefer the path with the lowest multi-exit discriminator (MED)
if (this.bestState.getMultiExitDisc() != null || state.getMultiExitDisc() != null) {
final Long bmed = this.bestState.getMultiExitDisc();
final Long nmed = state.getMultiExitDisc();
return nmed > bmed;
}
} else {
/*
* 7. prefer eBGP over iBGP paths
*
* EBGP is peering between two different AS, whereas IBGP is between same AS (Autonomous System),
* so we just compare the AS numbers to our AS.
*
* FIXME: we should know this information from the peer directly.
*/
if (this.ourAs != bestAs && this.ourAs == newAs) {
return true;
}
}
/*
* 10. Prefer the route that comes from the BGP router with the lowest router ID.
*
* This is normally guaranteed by the iteration order of our caller, which runs selection
* in the order of increasing router ID, but RFC-4456 Route Reflection throws a wrench into that.
*
* With RFC-5004, this gets a bit easier, because it completely eliminates step f) and later :-)
*
* RFC-5004 states that this algorithm should end here and select existing path over new path in the
* best path selection process. Benefits are listed in the RFC: @see http://tools.ietf.org/html/rfc500
* - This algorithm SHOULD NOT be applied when either path is from a BGP Confederation peer.
* - not applicable, we don't deal with confederation peers
* - The algorithm SHOULD NOT be applied when both paths are from peers with an identical BGP identifier
* (i.e., there exist parallel BGP sessions between two BGP speakers).
* - not applicable, BUG-2631 prevents parallel sessions to be created.
*/
return true;
}
Aggregations