Merge "Fix bulk sync in SwitchMananger."
[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 org.opendaylight.controller.sal.core.ContainerFlow;
12 import org.opendaylight.controller.sal.core.Node;
13
14 /**
15  * The flow database object representing the flow entry to install on the
16  * network node. It contains the original flow entry FRM was requested to
17  * install, the container flow with which that entry had to be merged and the
18  * resultant merged flow entry, which is the one that was eventually installed
19  * on the network node
20  *
21  * Note: If the container flow is null, the install entry will be a clone of the
22  * original entry
23  *
24  */
25 public class FlowEntryInstall {
26     private FlowEntry original;
27     private ContainerFlow cFlow;
28     private FlowEntry install;
29     transient private long requestId; // async request id
30     transient private boolean deletePending;
31
32     public FlowEntryInstall(FlowEntry original, ContainerFlow cFlow) {
33         this.original = original;
34         this.cFlow = cFlow;
35         this.install = (cFlow == null) ? original.clone() : original
36                 .mergeWith(cFlow);
37         deletePending = false;
38         requestId = 0;
39     }
40
41     @Override
42     public int hashCode() {
43         final int prime = 31;
44         int result = 1;
45         result = prime * result + ((cFlow == null) ? 0 : cFlow.hashCode());
46         result = prime * result + ((install == null) ? 0 : install.hashCode());
47         result = prime * result
48                 + ((original == null) ? 0 : original.hashCode());
49         return result;
50     }
51
52     @Override
53     public boolean equals(Object obj) {
54         if (this == obj)
55             return true;
56         if (obj == null)
57             return false;
58         if (getClass() != obj.getClass())
59             return false;
60         FlowEntryInstall other = (FlowEntryInstall) obj;
61         if (cFlow == null) {
62             if (other.cFlow != null)
63                 return false;
64         } else if (!cFlow.equals(other.cFlow))
65             return false;
66         if (install == null) {
67             if (other.install != null)
68                 return false;
69         } else if (!install.equals(other.install))
70             return false;
71         if (original == null) {
72             if (other.original != null)
73                 return false;
74         } else if (!original.equals(other.original))
75             return false;
76         return true;
77     }
78
79     public String getFlowName() {
80         return original.getFlowName();
81     }
82
83     public String getGroupName() {
84         return original.getGroupName();
85     }
86
87     public Node getNode() {
88         return original.getNode();
89     }
90
91     public boolean equalsByNodeAndName(Node node, String flowName) {
92         return original.equalsByNodeAndName(node, flowName);
93     }
94
95     public FlowEntry getOriginal() {
96         return original;
97     }
98
99     public ContainerFlow getContainerFlow() {
100         return cFlow;
101     }
102
103     public FlowEntry getInstall() {
104         return install;
105     }
106
107     public boolean isDeletePending() {
108         return deletePending;
109     }
110
111     public void toBeDeleted() {
112         this.deletePending = true;
113     }
114
115     public void setRequestId(long rid) {
116         this.requestId = rid;
117     }
118
119     public long getRequestId() {
120         return requestId;
121     }
122
123     @Override
124     public String toString() {
125         return "[Install = " + install + " Original = " + original + " cFlow = "
126                 + cFlow + " rid = " + requestId + "]";
127     }
128 }