device flow registry - initial implementation
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / flow / registry / FlowHashDto.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.impl.flow.registry;
10
11 import org.opendaylight.openflowplugin.api.openflow.flow.registry.FlowHash;
12 import org.opendaylight.openflowplugin.impl.util.HashUtil;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
15
16 /**
17  * Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015.
18  */
19 public class FlowHashDto implements FlowHash {
20
21     private long hashCode;
22
23     public FlowHashDto(Flow flow) {
24         calculateHash(flow);
25     }
26
27     private long calculateHash(Flow flow) {
28         long hash = 0;
29         Match match = flow.getMatch();
30         hash = HashUtil.calculateMatchHash(match);
31         hash += flow.getPriority();
32         hash += flow.getTableId();
33         hash += flow.getCookie().hashCode();
34         return hash;
35     }
36
37
38     @Override
39     public boolean equals(final Object obj) {
40         if (!(obj instanceof FlowHash)) {
41             return false;
42         }
43         if (this.hashCode == ((FlowHash) obj).getHash()) {
44             return true;
45         }
46         return false;
47     }
48
49     @Override
50     public long getHash() {
51         return hashCode;
52     }
53 }