Search in sources :

Example 1 with ClusterIdSet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev200120.cluster.id.set.ClusterIdSet in project bgpcep by opendaylight.

the class MatchClusterIdSetHandler method matchClusterIdCondition.

private boolean matchClusterIdCondition(final ClusterIdentifier localClusterId, final ClusterId clusterId, final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev200120.match.cluster.id.set.condition.grouping.MatchClusterIdSetCondition matchClusterIdSetCondition) {
    final ClusterIdSet clusterIdSet = this.sets.getUnchecked(StringUtils.substringBetween(matchClusterIdSetCondition.getClusterIdSet(), "=\"", "\""));
    if (clusterIdSet == null) {
        return false;
    }
    final MatchSetOptionsType matchOption = matchClusterIdSetCondition.getMatchSetOptions();
    if (clusterId != null) {
        List<ClusterIdentifier> newList = new ArrayList<>();
        if (clusterIdSet.getClusterId() != null) {
            newList.addAll(clusterIdSet.getClusterId());
        }
        if (clusterIdSet.getLocal() != null) {
            newList.add(localClusterId);
        }
        final List<ClusterIdentifier> matchClusterList = clusterId.getCluster();
        if (matchOption.equals(MatchSetOptionsType.ALL)) {
            return matchClusterList.containsAll(newList) && newList.containsAll(matchClusterList);
        }
        final boolean noneInCommon = Collections.disjoint(matchClusterList, newList);
        if (matchOption.equals(MatchSetOptionsType.ANY)) {
            return !noneInCommon;
        } else if (matchOption.equals(MatchSetOptionsType.INVERT)) {
            return noneInCommon;
        }
    } else if (matchOption.equals(MatchSetOptionsType.INVERT)) {
        return true;
    }
    return false;
}
Also used : MatchSetOptionsType(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.MatchSetOptionsType) ArrayList(java.util.ArrayList) ClusterIdSet(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev200120.cluster.id.set.ClusterIdSet) ClusterIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.ClusterIdentifier)

Example 2 with ClusterIdSet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev200120.cluster.id.set.ClusterIdSet in project bgpcep by opendaylight.

the class MatchClusterIdSetHandler method loadSets.

private ClusterIdSet loadSets(final String key) throws ExecutionException, InterruptedException {
    final ReadOnlyTransaction tr = this.dataBroker.newReadOnlyTransaction();
    final Optional<ClusterIdSet> result = tr.read(LogicalDatastoreType.CONFIGURATION, CLUSTERS_ID_SETS_IID.child(ClusterIdSet.class, new ClusterIdSetKey(key))).get();
    return result.orNull();
}
Also used : ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ClusterIdSet(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.cluster.id.set.ClusterIdSet) ClusterIdSetKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.cluster.id.set.ClusterIdSetKey)

Example 3 with ClusterIdSet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev200120.cluster.id.set.ClusterIdSet in project bgpcep by opendaylight.

the class MatchClusterIdSetHandler method matchClusterIdCondition.

private boolean matchClusterIdCondition(final ClusterIdentifier localClusterId, final ClusterId clusterId, final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.match.cluster.id.set.condition.grouping.MatchClusterIdSetCondition matchClusterIdSetCondition) {
    final ClusterIdSet clusterIdSet = this.sets.getUnchecked(StringUtils.substringBetween(matchClusterIdSetCondition.getClusterIdSet(), "=\"", "\""));
    if (clusterIdSet == null) {
        return false;
    }
    final MatchSetOptionsType matchOption = matchClusterIdSetCondition.getMatchSetOptions();
    if (clusterId != null) {
        List<ClusterIdentifier> newList = new ArrayList<>();
        if (clusterIdSet.getClusterId() != null) {
            newList.addAll(clusterIdSet.getClusterId());
        }
        if (clusterIdSet.getLocal() != null) {
            newList.add(localClusterId);
        }
        final List<ClusterIdentifier> matchClusterList = clusterId.getCluster();
        if (matchOption.equals(MatchSetOptionsType.ALL)) {
            return matchClusterList.containsAll(newList) && newList.containsAll(matchClusterList);
        }
        final boolean noneInCommon = Collections.disjoint(matchClusterList, newList);
        if (matchOption.equals(MatchSetOptionsType.ANY)) {
            return !noneInCommon;
        } else if (matchOption.equals(MatchSetOptionsType.INVERT)) {
            return noneInCommon;
        }
    } else if (matchOption.equals(MatchSetOptionsType.INVERT)) {
        return true;
    }
    return false;
}
Also used : MatchSetOptionsType(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.MatchSetOptionsType) ArrayList(java.util.ArrayList) ClusterIdSet(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.cluster.id.set.ClusterIdSet) ClusterIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier)

Aggregations

ArrayList (java.util.ArrayList)2 MatchSetOptionsType (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.MatchSetOptionsType)2 ClusterIdSet (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.cluster.id.set.ClusterIdSet)2 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)1 ClusterIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier)1 ClusterIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.ClusterIdentifier)1 ClusterIdSetKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.cluster.id.set.ClusterIdSetKey)1 ClusterIdSet (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev200120.cluster.id.set.ClusterIdSet)1