2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.groupbasedpolicy.dto;
11 import java.util.Collections;
12 import java.util.HashSet;
13 import java.util.List;
16 import javax.annotation.Nonnull;
17 import javax.annotation.Nullable;
18 import javax.annotation.concurrent.Immutable;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.endpoint.identification.constraints.EndpointIdentificationConstraints;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.endpoint.identification.constraints.endpoint.identification.constraints.l3.endpoint.identification.constraints.PrefixConstraint;
26 * Represents constraints for an endpoint.
29 public class EndpointConstraint {
31 private final ConditionSet conditionSet;
32 private final Set<PrefixConstraint> l3EpPrefixes;
34 public EndpointConstraint(
35 @Nullable ConditionSet conditionSet,
36 @Nullable EndpointIdentificationConstraints consEpIdentificationConstraint) {
37 if (conditionSet == null) {
38 this.conditionSet = ConditionSet.EMPTY;
40 this.conditionSet = conditionSet;
42 if (consEpIdentificationConstraint == null
43 || consEpIdentificationConstraint
44 .getL3EndpointIdentificationConstraints() == null
45 || consEpIdentificationConstraint
46 .getL3EndpointIdentificationConstraints()
47 .getPrefixConstraint() == null) {
48 l3EpPrefixes = Collections.emptySet();
50 l3EpPrefixes = new HashSet<>(consEpIdentificationConstraint
51 .getL3EndpointIdentificationConstraints()
52 .getPrefixConstraint());
58 * {@code null} means empty list
59 * @return {@code true} endpoint's conditions match against conditions from
62 public boolean conditionsMatch(
63 @Nullable final List<ConditionName> epConditions) {
64 if (epConditions == null) {
66 .matches(Collections.<ConditionName> emptyList());
68 return conditionSet.matches(epConditions);
71 public @Nonnull ConditionSet getConditionSet() {
75 public @Nonnull Set<PrefixConstraint> getL3EpPrefixes() {
79 public static Set<IpPrefix> getIpPrefixesFrom(
80 Set<PrefixConstraint> prefixConstraints) {
81 Set<IpPrefix> ipPrefixes = new HashSet<>();
82 for (PrefixConstraint prefixConstraint : prefixConstraints) {
83 ipPrefixes.add(prefixConstraint.getIpPrefix());
89 public int hashCode() {
92 result = prime * result
93 + ((conditionSet == null) ? 0 : conditionSet.hashCode());
94 result = prime * result
95 + ((l3EpPrefixes == null) ? 0 : l3EpPrefixes.hashCode());
100 public boolean equals(Object obj) {
105 if (getClass() != obj.getClass())
107 EndpointConstraint other = (EndpointConstraint) obj;
108 if (conditionSet == null) {
109 if (other.conditionSet != null)
111 } else if (!conditionSet.equals(other.conditionSet))
113 if (l3EpPrefixes == null) {
114 if (other.l3EpPrefixes != null)
116 } else if (!l3EpPrefixes.equals(other.l3EpPrefixes))