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.openflowplugin.impl.registry.flow;
11 import com.google.common.base.MoreObjects;
12 import com.google.common.base.Preconditions;
13 import java.math.BigInteger;
14 import org.opendaylight.openflowplugin.api.OFConstants;
15 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
20 * Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015.
22 public class FlowRegistryKeyFactory {
25 public FlowRegistryKeyFactory() {
28 public static FlowRegistryKey create(final Flow flow) {
29 return new FlowRegistryKeyDto(flow);
32 private static final class FlowRegistryKeyDto implements FlowRegistryKey {
34 private final short tableId;
35 private final int priority;
36 private final BigInteger cookie;
37 private final Match match;
39 public FlowRegistryKeyDto(final Flow flow) {
40 //TODO: mandatory flow input values (or default values) should be specified via yang model
41 tableId = Preconditions.checkNotNull(flow.getTableId(), "flow tableId must not be null");
42 priority = MoreObjects.firstNonNull(flow.getPriority(), OFConstants.DEFAULT_FLOW_PRIORITY);
43 match = Preconditions.checkNotNull(flow.getMatch(), "Match value must not be null");
44 cookie = MoreObjects.firstNonNull(flow.getCookie(), OFConstants.DEFAULT_FLOW_COOKIE).getValue();
48 public boolean equals(final Object o) {
53 if (o == null || !(o instanceof FlowRegistryKey)) {
57 final FlowRegistryKey that = (FlowRegistryKey) o;
59 return getPriority() == that.getPriority() &&
60 getTableId() == that.getTableId() &&
61 getMatch().equals(that.getMatch());
65 public int hashCode() {
67 result = 31 * result + priority;
68 result = 31 * result + match.hashCode();
73 public short getTableId() {
78 public int getPriority() {
83 public BigInteger getCookie() {
88 public Match getMatch() {