Merge "HA - Cache sync for forwarding.staticrouting"
[controller.git] / opendaylight / forwardingrulesmanager / api / src / main / java / org / opendaylight / controller / forwardingrulesmanager / FlowEntryInstall.java
1 /*
2  * Copyright (c) 2013 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.controller.forwardingrulesmanager;
10
11 import java.io.Serializable;
12
13 import org.opendaylight.controller.sal.core.ContainerFlow;
14 import org.opendaylight.controller.sal.core.Node;
15
16 /**
17  * The flow database object representing the flow entry to install on the
18  * network node. It contains the original flow entry FRM was requested to
19  * install, the container flow with which that entry had to be merged and the
20  * resultant merged flow entry, which is the one that was eventually installed
21  * on the network node
22  *
23  * Note: If the container flow is null, the install entry will be a clone of the
24  * original entry
25  */
26 public class FlowEntryInstall implements Serializable {
27     private static final long serialVersionUID = 1L;
28     private final FlowEntry original;
29     private final ContainerFlow cFlow;
30     private final FlowEntry install;
31     transient private long requestId; // async request id
32     transient private boolean deletePending;
33
34     public FlowEntryInstall(FlowEntry original, ContainerFlow cFlow) {
35         this.original = original;
36         this.cFlow = cFlow;
37         this.install = (cFlow == null) ? original.clone() : original.mergeWith(cFlow);
38         deletePending = false;
39         requestId = 0;
40     }
41
42     /*
43      * Given FlowEntryInstall is used as key for FRM map which contains the
44      * software view of installed entries, having its hashcode tied to the one
45      * of the installed FlowEntry which takes into account the fields which
46      * uniquely identify a flow from switch point of view: node, match and
47      * priority.
48      */
49     @Override
50     public int hashCode() {
51         return install.hashCode();
52     }
53
54     @Override
55     public boolean equals(Object obj) {
56         if (this == obj) {
57             return true;
58         }
59         if (obj == null) {
60             return false;
61         }
62         if (getClass() != obj.getClass()) {
63             return false;
64         }
65         FlowEntryInstall other = (FlowEntryInstall) obj;
66         if (install == null) {
67             if (other.install != null) {
68                 return false;
69             }
70         } else if (!install.equals(other.install)) {
71             return false;
72         }
73         return true;
74     }
75
76     public String getFlowName() {
77         return original.getFlowName();
78     }
79
80     public String getGroupName() {
81         return original.getGroupName();
82     }
83
84     public Node getNode() {
85         return original.getNode();
86     }
87
88     public boolean equalsByNodeAndName(Node node, String flowName) {
89         return original.equalsByNodeAndName(node, flowName);
90     }
91
92     public FlowEntry getOriginal() {
93         return original;
94     }
95
96     public ContainerFlow getContainerFlow() {
97         return cFlow;
98     }
99
100     public FlowEntry getInstall() {
101         return install;
102     }
103
104     public boolean isDeletePending() {
105         return deletePending;
106     }
107
108     public void toBeDeleted() {
109         this.deletePending = true;
110     }
111
112     public void setRequestId(long rid) {
113         this.requestId = rid;
114     }
115
116     public long getRequestId() {
117         return requestId;
118     }
119
120     /**
121      * Returns whether this entry is the result of an internal generated static
122      * flow
123      *
124      * @return true if internal generated static flow, false otherwise
125      */
126     public boolean isInternal() {
127         return original.isInternal();
128     }
129
130     @Override
131     public String toString() {
132         return "[Install = " + install + " Original = " + original + " cFlow = " + cFlow + " rid = " + requestId + "]";
133     }
134 }