Search in sources :

Example 1 with Algorithm

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Algorithm 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;
}
Also used : BgpOrigin(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin)

Example 2 with Algorithm

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Algorithm in project bgpcep by opendaylight.

the class SrNodeAttributesParser method parseSrAlgorithms.

public static SrAlgorithm parseSrAlgorithms(final ByteBuf buffer) {
    final SrAlgorithmBuilder builder = new SrAlgorithmBuilder();
    final List<Algorithm> algs = new ArrayList<>();
    while (buffer.isReadable()) {
        algs.add(Algorithm.forValue(buffer.readUnsignedByte()));
    }
    builder.setAlgorithms(algs);
    return builder.build();
}
Also used : ArrayList(java.util.ArrayList) SrAlgorithmBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.state.SrAlgorithmBuilder) Algorithm(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Algorithm) SrAlgorithm(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.state.SrAlgorithm)

Example 3 with Algorithm

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Algorithm in project lispflowmapping by opendaylight.

the class LispMapCacheStringifier method prettyPrintKeys.

@SuppressWarnings("unchecked")
public static String prettyPrintKeys(ILispDAO dao) {
    final StringBuilder sb = new StringBuilder();
    final IRowVisitor innerVisitor = (new IRowVisitor() {

        public void visitRow(Object keyId, String valueKey, Object value) {
            switch(valueKey) {
                case SubKeys.AUTH_KEY:
                    String eid = LispAddressStringifier.getString((Eid) keyId);
                    sb.append("     ");
                    sb.append(eid);
                    int padLen = Math.max(2, Constants.INET6_ADDRSTRLEN - eid.length());
                    sb.append(Stringifier.getSpacesAsString(padLen));
                    MappingAuthkey authKey = (MappingAuthkey) value;
                    String hmac = LispKeyIDEnum.valueOf(authKey.getKeyType().shortValue()).getAuthenticationName();
                    sb.append(hmac);
                    sb.append(Stringifier.getSpacesAsString(Math.max(2, 22 - hmac.length())));
                    sb.append(authKey.getKeyString());
                    sb.append("\n");
                    break;
                default:
                    break;
            }
        }
    });
    dao.getAll(new IRowVisitor() {

        String lastKey = "";

        public void visitRow(Object keyId, String valueKey, Object value) {
            String key = keyId.getClass().getSimpleName() + "#" + keyId;
            if (!lastKey.equals(key)) {
                sb.append("Instance ID " + keyId + "\n");
                sb.append("  -> EID                                           HMAC Algorithm        Shared Key\n");
            }
            if (valueKey.equals(SubKeys.VNI)) {
                ((ILispDAO) value).getAll(innerVisitor);
            }
            lastKey = key;
        }
    });
    return sb.toString();
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) IRowVisitor(org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor) MappingAuthkey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey)

Example 4 with Algorithm

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Algorithm in project lispflowmapping by opendaylight.

the class MappingSystem method mergeNegativePrefixes.

/*
     * Merges adjacent negative prefixes and notifies their subscribers.
     */
private void mergeNegativePrefixes(Eid eid) {
    LOG.debug("Merging negative prefixes starting from EID {}", LispAddressStringifier.getString(eid));
    // If we delete nodes while we walk up the radix trie the algorithm will give incorrect results, because
    // removals rearrange relationships in the trie. So we save prefixes to be removed into a HashMap.
    Map<Eid, MappingData> mergedMappings = new HashMap<>();
    Eid currentNode = smc.getSiblingPrefix(eid);
    MappingData mapping = (MappingData) smc.getMapping(null, currentNode);
    if (mapping != null && mapping.isNegative().or(false)) {
        mergedMappings.put(currentNode, mapping);
    } else {
        return;
    }
    Eid previousNode = currentNode;
    currentNode = smc.getVirtualParentSiblingPrefix(currentNode);
    while (currentNode != null) {
        mapping = (MappingData) smc.getMapping(null, currentNode);
        if (mapping != null && mapping.isNegative().or(false)) {
            mergedMappings.put(currentNode, mapping);
        } else {
            break;
        }
        previousNode = currentNode;
        currentNode = smc.getVirtualParentSiblingPrefix(previousNode);
    }
    for (Eid key : mergedMappings.keySet()) {
        removeSbMapping(key, mergedMappings.get(key));
    }
    smc.removeMapping(eid);
    addNegativeMapping(getVirtualParent(previousNode));
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData)

Aggregations

Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IRowVisitor (org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor)1 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)1 MappingAuthkey (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey)1 SrAlgorithm (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.state.SrAlgorithm)1 SrAlgorithmBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.state.SrAlgorithmBuilder)1 Algorithm (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Algorithm)1 BgpOrigin (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin)1