3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.forwardingrulesmanager;
12 import java.io.Serializable;
13 import java.util.Date;
15 import org.apache.commons.lang3.builder.EqualsBuilder;
16 import org.apache.commons.lang3.builder.HashCodeBuilder;
17 import org.opendaylight.controller.sal.core.ContainerFlow;
18 import org.opendaylight.controller.sal.core.Node;
19 import org.opendaylight.controller.sal.flowprogrammer.Flow;
20 import org.opendaylight.controller.sal.match.Match;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Represents a flow applications request Forwarding Rules Manager to install
26 * on a network node. A FlowEntry is constituted of a flow (match + actions),
27 * the target network node, and the flow name. It also includes a group name.
28 * For instance the flows constituting a policy all share the same group name.
30 public class FlowEntry implements Cloneable, Serializable {
31 protected static final Logger logger = LoggerFactory
32 .getLogger(FlowEntry.class);
33 private static final long serialVersionUID = 1L;
34 private String groupName; // group name
35 private String flowName; // flow name (may be null)
36 private Node node; // network node where to install the flow
37 private Flow flow; // match + action
39 public FlowEntry(String groupName, String flowName, Flow flow, Node node) {
40 this.groupName = groupName;
43 this.flowName = (flowName != null) ? flowName : constructFlowName();
46 public String getGroupName() {
50 public void setGroupName(String name) {
51 this.groupName = name;
55 * Return the actual Flow contained in this entry
59 public Flow getFlow() {
63 public Node getNode() {
67 public void setNode(Node n) {
71 public String getFlowName() {
75 public void setFlowName(String n) {
80 public FlowEntry clone() {
81 FlowEntry cloned = null;
83 cloned = (FlowEntry) super.clone();
84 cloned.flow = this.flow.clone();
85 } catch (CloneNotSupportedException e) {
92 public int hashCode() {
93 return HashCodeBuilder.reflectionHashCode(this);
97 public boolean equals(Object obj) {
98 return EqualsBuilder.reflectionEquals(this, obj);
102 public String toString() {
103 return "FlowEntry[flowName = " + flowName + ", groupName = "
104 + groupName + ",node = " + node + ", flow = " + flow + "]";
107 private String constructFlowName() {
108 return this.groupName + "_" + new Date().toString();
111 public boolean equalsByNodeAndName(Node node, String flowName) {
112 return this.node.equals(node) && this.flowName.equals(flowName);
116 * Merges the current Flow with the passed Container Flow
118 * Note: Container Flow merging is not an injective function.
119 * Be m1 and m2 two different matches, and be f() the flow merge
120 * function, such that y1 = f(m1) and y2 = f(m2) are the two merged
121 * matches, we may have: y1 = y2
124 * @param containerFlow
125 * @return this merged FlowEntry
127 public FlowEntry mergeWith(ContainerFlow containerFlow) {
128 Match myMatch = flow.getMatch();
130 // Based on this flow direction, rearrange the match
131 Match match = containerFlow.getMatch();
134 myMatch.mergeWithFilter(match);
136 // Replace this Flow's match with merged version
137 flow.setMatch(myMatch);