import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
/**
* Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015.
public FlowRegistryKeyFactory() {
}
- public static FlowRegistryKey create(Flow flow) {
+ public static FlowRegistryKey create(final Flow flow) {
return new FlowRegistryKeyDto(flow);
}
private final Match match;
public FlowRegistryKeyDto(final Flow flow) {
+ //TODO: mandatory flow input values (or default values) should be specified via yang model
tableId = Preconditions.checkNotNull(flow.getTableId(), "flow tableId must not be null");
- priority = Preconditions.checkNotNull(flow.getPriority(), "flow priority must not be null");
- match = Preconditions.checkNotNull(flow.getMatch(), "Match value must not be null");
+ priority = MoreObjects.firstNonNull(flow.getPriority(), OFConstants.DEFAULT_FLOW_PRIORITY);
+ match = flow.getMatch()==null? new MatchBuilder().build(): flow.getMatch();
cookie = MoreObjects.firstNonNull(flow.getCookie(), OFConstants.DEFAULT_FLOW_COOKIE).getValue();
}
@Override
public boolean equals(final Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o) {
+ return true;
+ }
- final FlowRegistryKeyDto that = (FlowRegistryKeyDto) o;
+ if (o == null || !(o instanceof FlowRegistryKey)) {
+ return false;
+ }
- if (priority != that.priority) return false;
- if (tableId != that.tableId) return false;
- if (!match.equals(that.match)) return false;
+ final FlowRegistryKey that = (FlowRegistryKey) o;
- return true;
+ return getPriority() == that.getPriority() &&
+ getTableId() == that.getTableId() &&
+ getMatch().equals(that.getMatch());
}
@Override
public int hashCode() {
- int result = (int) tableId;
+ int result = tableId;
result = 31 * result + priority;
result = 31 * result + match.hashCode();
return result;
public BigInteger getCookie() {
return cookie;
}
+
+ @Override
+ public Match getMatch() {
+ return match;
+ }
}
}