use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpOrigin in project bgpcep by opendaylight.
the class OriginAttributeParser method parseAttribute.
@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder, final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPTreatAsWithdrawException {
final int readable = buffer.readableBytes();
if (readable != 1) {
throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR, "ORIGIN attribute is expected to have size 1, but has %s", readable);
}
final byte rawOrigin = buffer.readByte();
final BgpOrigin borigin = BgpOrigin.forValue(UnsignedBytes.toInt(rawOrigin));
if (borigin == null) {
throw errorHandling.reportError(BGPError.ORIGIN_ATTR_NOT_VALID, "Unknown ORIGIN type %s", rawOrigin);
}
switch(borigin) {
case Egp:
builder.setOrigin(EGP);
return;
case Igp:
builder.setOrigin(IGP);
return;
case Incomplete:
builder.setOrigin(INC);
return;
default:
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpOrigin 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) {
// 0. draft-uttaro-idr-bgp-persistence-04 defines "depreferenced" paths
final boolean stateDepref = state.isDepreferenced();
if (this.bestState.isDepreferenced() != stateDepref) {
return stateDepref;
}
// 1. prefer path with accessible nexthop
// - we assume that all nexthops are accessible
/*
* 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.
*/
final Uint32 bestLocal = this.bestState.getLocalPref();
final Uint32 stateLocal = state.getLocalPref();
if (stateLocal != null) {
if (bestLocal == null) {
return true;
}
final int cmp = stateLocal.compareTo(bestLocal);
if (cmp != 0) {
return cmp < 0;
}
} else if (bestLocal != null) {
return false;
}
// 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 == newAs) {
// 6. prefer the path with the lowest multi-exit discriminator (MED)
final Boolean cmp = firstLower(this.bestState.getMultiExitDisc(), state.getMultiExitDisc());
if (cmp != null) {
return cmp;
}
} 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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpOrigin in project bgpcep by opendaylight.
the class GracefulRestartTest method insertRoutes.
private static void insertRoutes(final List<Ipv4Prefix> ipv4prefixes, final Ipv4AddressNoZone ipv4NeighborAddress, final List<Ipv6Prefix> ipv6prefixes, final Ipv6AddressNoZone ipv6NeighborAddress, final BGPSessionImpl session, final BgpOrigin peerRole) {
if (ipv4prefixes == null && ipv6prefixes == null) {
waitFutureSuccess(session.writeAndFlush(BgpPeerUtil.createEndOfRib(TABLES_KEY)));
waitFutureSuccess(session.writeAndFlush(BgpPeerUtil.createEndOfRib(IPV6_TABLES_KEY)));
return;
}
if (ipv4prefixes != null && !ipv4prefixes.isEmpty()) {
final MpReachNlri reachIpv4 = PeerUtil.createMpReachNlri(new IpAddressNoZone(ipv4NeighborAddress), ipv4prefixes.stream().map(IpPrefix::new).collect(Collectors.toList()));
final Update update1 = PeerUtil.createUpdate(peerRole, Collections.emptyList(), 100, reachIpv4, null);
waitFutureSuccess(session.writeAndFlush(update1));
}
if (ipv6prefixes != null && !ipv4prefixes.isEmpty()) {
final MpReachNlri reachIpv6 = PeerUtil.createMpReachNlri(new IpAddressNoZone(ipv6NeighborAddress), ipv6prefixes.stream().map(IpPrefix::new).collect(Collectors.toList()));
final Update update2 = PeerUtil.createUpdate(peerRole, Collections.emptyList(), 100, reachIpv6, null);
waitFutureSuccess(session.writeAndFlush(update2));
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpOrigin in project bgpcep by opendaylight.
the class PeerUtil method createUpdate.
static Update createUpdate(final BgpOrigin bgpOrigin, final List<Segments> pathSegments, // FIXME: consider using Uint32
final long preference, final MpReachNlri mpReach, final MpUnreachNlri mpUnreach) {
final Origin origin = new OriginBuilder().setValue(bgpOrigin).build();
final AsPath asPath = new AsPathBuilder().setSegments(pathSegments).build();
final LocalPref localPref = new LocalPrefBuilder().setPref(Uint32.valueOf(preference)).build();
final AttributesBuilder attributeBuilder = new AttributesBuilder().setOrigin(origin).setAsPath(asPath).setLocalPref(localPref);
if (mpReach != null) {
attributeBuilder.addAugmentation(new AttributesReachBuilder().setMpReachNlri(mpReach).build());
}
if (mpUnreach != null) {
attributeBuilder.addAugmentation(new AttributesUnreachBuilder().setMpUnreachNlri(mpUnreach).build());
}
return new UpdateBuilder().setAttributes(new AttributesBuilder().setOrigin(origin).setAsPath(asPath).setLocalPref(localPref).addAugmentation(new AttributesReachBuilder().setMpReachNlri(mpReach).build()).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpOrigin in project bgpcep by opendaylight.
the class OriginAttributeParser method parseAttribute.
@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) throws BGPDocumentedException {
final byte rawOrigin = buffer.readByte();
final BgpOrigin borigin = BgpOrigin.forValue(UnsignedBytes.toInt(rawOrigin));
if (borigin == null) {
throw new BGPDocumentedException("Unknown Origin type.", BGPError.ORIGIN_ATTR_NOT_VALID, new byte[] { (byte) 0x01, (byte) 0x01, rawOrigin });
}
switch(borigin) {
case Egp:
builder.setOrigin(EGP);
return;
case Igp:
builder.setOrigin(IGP);
return;
case Incomplete:
builder.setOrigin(INC);
return;
default:
return;
}
}
Aggregations