2 * Copyright (c) 2013 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.controller.forwardingrulesmanager;
11 import java.io.Serializable;
12 import java.util.Date;
14 import org.opendaylight.controller.sal.core.ContainerFlow;
15 import org.opendaylight.controller.sal.core.Node;
16 import org.opendaylight.controller.sal.flowprogrammer.Flow;
17 import org.opendaylight.controller.sal.match.Match;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * Represents a flow applications request Forwarding Rules Manager to install on
23 * a network node. A FlowEntry is constituted of a flow (match + actions), the
24 * target network node, and the flow name. It also includes a group name. For
25 * instance the flows constituting a policy all share the same group name.
27 public class FlowEntry implements Cloneable, Serializable {
28 protected static final Logger logger = LoggerFactory
29 .getLogger(FlowEntry.class);
30 private static final long serialVersionUID = 1L;
31 private static final Logger log = LoggerFactory.getLogger(FlowEntry.class);
32 private String groupName; // group name
33 private String flowName; // flow name (may be null)
34 private Node node; // network node where to install the flow
35 private Flow flow; // match + action
37 public FlowEntry(String groupName, String flowName, Flow flow, Node node) {
38 this.groupName = groupName;
41 this.flowName = (flowName != null) ? flowName : constructFlowName();
44 public String getGroupName() {
48 public void setGroupName(String name) {
49 this.groupName = name;
53 * Return the actual Flow contained in this entry
57 public Flow getFlow() {
61 public Node getNode() {
65 public void setNode(Node n) {
69 public String getFlowName() {
73 public void setFlowName(String n) {
78 public FlowEntry clone() {
79 FlowEntry cloned = null;
81 cloned = (FlowEntry) super.clone();
82 cloned.flow = this.flow.clone();
83 } catch (CloneNotSupportedException e) {
84 log.warn("exception in clone", e);
90 public int hashCode() {
93 result = prime * result + ((flow == null) ? 0 : flow.hashCode());
94 result = prime * result
95 + ((flowName == null) ? 0 : flowName.hashCode());
96 result = prime * result
97 + ((groupName == null) ? 0 : groupName.hashCode());
98 result = prime * result + ((node == null) ? 0 : node.hashCode());
103 public boolean equals(Object obj) {
108 if (getClass() != obj.getClass())
110 FlowEntry other = (FlowEntry) obj;
112 if (other.flow != null)
114 } else if (!flow.equals(other.flow))
116 if (flowName == null) {
117 if (other.flowName != null)
119 } else if (!flowName.equals(other.flowName))
121 if (groupName == null) {
122 if (other.groupName != null)
124 } else if (!groupName.equals(other.groupName))
127 if (other.node != null)
129 } else if (!node.equals(other.node))
135 public String toString() {
136 return "FlowEntry[flowName = " + flowName + ", groupName = "
137 + groupName + ",node = " + node + ", flow = " + flow + "]";
140 private String constructFlowName() {
141 return this.groupName + "_" + new Date().toString();
144 public boolean equalsByNodeAndName(Node node, String flowName) {
145 return this.node.equals(node) && this.flowName.equals(flowName);
149 * Merges the current Flow with the passed Container Flow
151 * Note: Container Flow merging is not an injective function. Be m1 and m2
152 * two different matches, and be f() the flow merge function, such that y1 =
153 * f(m1) and y2 = f(m2) are the two merged matches, we may have: y1 = y2
156 * @param containerFlow
157 * @return this merged FlowEntry
159 public FlowEntry mergeWith(ContainerFlow containerFlow) {
160 Match myMatch = flow.getMatch();
162 // Based on this flow direction, rearrange the match
163 Match match = containerFlow.getMatch();
166 myMatch.mergeWithFilter(match);
168 // Replace this Flow's match with merged version
169 flow.setMatch(myMatch);