blob: 022cecf5711ec876a124a89d8be9783e795d8281 [file] [log] [blame]
Jonathan Hartaa380972014-04-03 10:24:46 -07001package net.onrc.onos.core.intent;
Brian O'Connor7f8e3012014-02-15 23:59:29 -08002
3import java.util.HashSet;
4import java.util.Set;
5
6import net.floodlightcontroller.util.MACAddress;
Jonathan Hartaa380972014-04-03 10:24:46 -07007import net.onrc.onos.core.intent.IntentOperation.Operator;
Jonathan Hart23701d12014-04-03 10:45:48 -07008import net.onrc.onos.core.util.Dpid;
9import net.onrc.onos.core.util.FlowEntryActions;
10import net.onrc.onos.core.util.FlowEntryId;
11import net.onrc.onos.core.util.FlowEntryUserState;
Brian O'Connor7f8e3012014-02-15 23:59:29 -080012
13/**
Brian O'Connor7f8e3012014-02-15 23:59:29 -080014 * @author Brian O'Connor <bocon@onlab.us>
Brian O'Connor7f8e3012014-02-15 23:59:29 -080015 */
16
17public class FlowEntry {
Ray Milkey269ffb92014-04-03 14:43:30 -070018 protected long sw;
19 protected Match match;
20 protected Set<Action> actions;
21 protected Operator operator;
TeruU30c0c932014-05-15 16:47:41 -070022 protected int hardTimeout = 0;
23 protected int idleTimeout = 0;
TeruU9e530662014-05-18 11:49:37 -070024 protected long flowEntryId;
Ray Milkey269ffb92014-04-03 14:43:30 -070025
Komal Shah399a2922014-05-28 01:57:40 -070026// CHECKSTYLE:OFF suppress the warning about too many parameters
Ray Milkey269ffb92014-04-03 14:43:30 -070027 public FlowEntry(long sw, long srcPort, long dstPort,
28 MACAddress srcMac, MACAddress dstMac,
Komal Shah399a2922014-05-28 01:57:40 -070029 int srcIpAddress, int dstIpAddress,
Ray Milkey269ffb92014-04-03 14:43:30 -070030 Operator operator) {
Komal Shah399a2922014-05-28 01:57:40 -070031// CHECKSTYLE:ON
Ray Milkey269ffb92014-04-03 14:43:30 -070032 this.sw = sw;
Komal Shah399a2922014-05-28 01:57:40 -070033 this.match = new Match(sw, srcPort, srcMac, dstMac, srcIpAddress, dstIpAddress);
Ray Milkey269ffb92014-04-03 14:43:30 -070034 this.actions = new HashSet<Action>();
35 this.actions.add(new ForwardAction(dstPort));
36 this.operator = operator;
TeruU9e530662014-05-18 11:49:37 -070037 this.flowEntryId = hashCode();
Ray Milkey269ffb92014-04-03 14:43:30 -070038 }
39
TeruU30c0c932014-05-15 16:47:41 -070040 /***
41 * Gets hard timeout value in seconds.
42 *
TeruU9e530662014-05-18 11:49:37 -070043 * @return the hard timeout value in seconds
TeruU30c0c932014-05-15 16:47:41 -070044 */
45 public int getHardTimeout() {
46 return hardTimeout;
47 }
48
49 /***
50 * Gets idle timeout value in seconds.
51 *
TeruU9e530662014-05-18 11:49:37 -070052 * @return the idle timeout value in seconds
TeruU30c0c932014-05-15 16:47:41 -070053 */
54 public int getIdleTimeout() {
55 return idleTimeout;
56 }
57
58 /***
59 * Sets hard timeout value in seconds.
60 *
TeruU9e530662014-05-18 11:49:37 -070061 * @param the hard timeout value in seconds
TeruU30c0c932014-05-15 16:47:41 -070062 */
63 public void setHardTimeout(int hardTimeout) {
64 this.hardTimeout = hardTimeout;
65 }
66
67 /***
68 * Sets idle timeout value in seconds.
69 *
TeruU9e530662014-05-18 11:49:37 -070070 * @param the idle timeout value in seconds
TeruU30c0c932014-05-15 16:47:41 -070071 */
72 public void setIdleTimeout(int idleTimeout) {
73 this.idleTimeout = idleTimeout;
74 }
75
TeruU9e530662014-05-18 11:49:37 -070076 /***
77 * Gets flowEntryId.
78 *
79 * @param the flowEntryId to be set in cookie
80 */
81 public long getFlowEntryId() {
82 return flowEntryId;
83 }
84
85 /***
86 * Sets flowEntryId.
87 *
88 * @param the flowEntryId to be set in cookie
89 */
90 public void setFlowEntryId(long flowEntryId) {
91 this.flowEntryId = flowEntryId;
92 }
93
TeruU30c0c932014-05-15 16:47:41 -070094 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070095 public String toString() {
96 return match + "->" + actions;
97 }
98
99 public long getSwitch() {
100 return sw;
101 }
102
103 public Operator getOperator() {
104 return operator;
105 }
106
107 public void setOperator(Operator op) {
108 operator = op;
109 }
110
111 public net.onrc.onos.core.util.FlowEntry getFlowEntry() {
112 net.onrc.onos.core.util.FlowEntry entry = new net.onrc.onos.core.util.FlowEntry();
113 entry.setDpid(new Dpid(sw));
TeruU9e530662014-05-18 11:49:37 -0700114 entry.setFlowEntryId(new FlowEntryId(flowEntryId));
Ray Milkey269ffb92014-04-03 14:43:30 -0700115 entry.setFlowEntryMatch(match.getFlowEntryMatch());
116 FlowEntryActions flowEntryActions = new FlowEntryActions();
117 for (Action action : actions) {
118 flowEntryActions.addAction(action.getFlowEntryAction());
119 }
120 entry.setFlowEntryActions(flowEntryActions);
121 switch (operator) {
122 case ADD:
123 entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_MODIFY);
124 break;
125 case REMOVE:
126 entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_DELETE);
127 break;
128 default:
129 break;
130 }
TeruU30c0c932014-05-15 16:47:41 -0700131 entry.setIdleTimeout(idleTimeout);
132 entry.setHardTimeout(hardTimeout);
Ray Milkey269ffb92014-04-03 14:43:30 -0700133 return entry;
134 }
135
136
TeruU30c0c932014-05-15 16:47:41 -0700137 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -0700138 public int hashCode() {
139 return match.hashCode();
140 }
141
TeruU30c0c932014-05-15 16:47:41 -0700142 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -0700143 public boolean equals(Object o) {
144 if (!(o instanceof FlowEntry)) {
145 return false;
146 }
147 FlowEntry other = (FlowEntry) o;
148 // Note: we should not consider the operator for this comparison
149 return this.match.equals(other.match)
150 && this.actions.containsAll(other.actions)
151 && other.actions.containsAll(this.actions);
152 }
Brian O'Connor6dc44e92014-02-24 21:23:46 -0800153}