blob: bb051e2ca0fd0eddf6c52759cc30bf05df21ae14 [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;
Ray Milkey269ffb92014-04-03 14:43:30 -070024
25 public FlowEntry(long sw, long srcPort, long dstPort,
26 MACAddress srcMac, MACAddress dstMac,
27 Operator operator) {
28 this.sw = sw;
29 this.match = new Match(sw, srcPort, srcMac, dstMac);
30 this.actions = new HashSet<Action>();
31 this.actions.add(new ForwardAction(dstPort));
32 this.operator = operator;
TeruU30c0c932014-05-15 16:47:41 -070033
Ray Milkey269ffb92014-04-03 14:43:30 -070034 }
35
TeruU30c0c932014-05-15 16:47:41 -070036 /***
37 * Gets hard timeout value in seconds.
38 *
39 * @return hardTimeout
40 */
41 public int getHardTimeout() {
42 return hardTimeout;
43 }
44
45 /***
46 * Gets idle timeout value in seconds.
47 *
48 * @return idleTimeout
49 */
50 public int getIdleTimeout() {
51 return idleTimeout;
52 }
53
54 /***
55 * Sets hard timeout value in seconds.
56 *
57 * @param hardTimeout
58 */
59 public void setHardTimeout(int hardTimeout) {
60 this.hardTimeout = hardTimeout;
61 }
62
63 /***
64 * Sets idle timeout value in seconds.
65 *
66 * @param idleTimeout
67 */
68 public void setIdleTimeout(int idleTimeout) {
69 this.idleTimeout = idleTimeout;
70 }
71
72 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070073 public String toString() {
74 return match + "->" + actions;
75 }
76
77 public long getSwitch() {
78 return sw;
79 }
80
81 public Operator getOperator() {
82 return operator;
83 }
84
85 public void setOperator(Operator op) {
86 operator = op;
87 }
88
89 public net.onrc.onos.core.util.FlowEntry getFlowEntry() {
90 net.onrc.onos.core.util.FlowEntry entry = new net.onrc.onos.core.util.FlowEntry();
91 entry.setDpid(new Dpid(sw));
92 entry.setFlowEntryId(new FlowEntryId(hashCode())); // naive, but useful for now
93 entry.setFlowEntryMatch(match.getFlowEntryMatch());
94 FlowEntryActions flowEntryActions = new FlowEntryActions();
95 for (Action action : actions) {
96 flowEntryActions.addAction(action.getFlowEntryAction());
97 }
98 entry.setFlowEntryActions(flowEntryActions);
99 switch (operator) {
100 case ADD:
101 entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_MODIFY);
102 break;
103 case REMOVE:
104 entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_DELETE);
105 break;
106 default:
107 break;
108 }
TeruU30c0c932014-05-15 16:47:41 -0700109 entry.setIdleTimeout(idleTimeout);
110 entry.setHardTimeout(hardTimeout);
Ray Milkey269ffb92014-04-03 14:43:30 -0700111 return entry;
112 }
113
114
TeruU30c0c932014-05-15 16:47:41 -0700115 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -0700116 public int hashCode() {
117 return match.hashCode();
118 }
119
TeruU30c0c932014-05-15 16:47:41 -0700120 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -0700121 public boolean equals(Object o) {
122 if (!(o instanceof FlowEntry)) {
123 return false;
124 }
125 FlowEntry other = (FlowEntry) o;
126 // Note: we should not consider the operator for this comparison
127 return this.match.equals(other.match)
128 && this.actions.containsAll(other.actions)
129 && other.actions.containsAll(this.actions);
130 }
Brian O'Connor6dc44e92014-02-24 21:23:46 -0800131}