blob: 94cf88af00dd660ef98ec16fd59f85f58e5dbc0e [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
26 public FlowEntry(long sw, long srcPort, long dstPort,
27 MACAddress srcMac, MACAddress dstMac,
28 Operator operator) {
29 this.sw = sw;
30 this.match = new Match(sw, srcPort, srcMac, dstMac);
31 this.actions = new HashSet<Action>();
32 this.actions.add(new ForwardAction(dstPort));
33 this.operator = operator;
TeruU9e530662014-05-18 11:49:37 -070034 this.flowEntryId = hashCode();
Ray Milkey269ffb92014-04-03 14:43:30 -070035 }
36
TeruU30c0c932014-05-15 16:47:41 -070037 /***
38 * Gets hard timeout value in seconds.
39 *
TeruU9e530662014-05-18 11:49:37 -070040 * @return the hard timeout value in seconds
TeruU30c0c932014-05-15 16:47:41 -070041 */
42 public int getHardTimeout() {
43 return hardTimeout;
44 }
45
46 /***
47 * Gets idle timeout value in seconds.
48 *
TeruU9e530662014-05-18 11:49:37 -070049 * @return the idle timeout value in seconds
TeruU30c0c932014-05-15 16:47:41 -070050 */
51 public int getIdleTimeout() {
52 return idleTimeout;
53 }
54
55 /***
56 * Sets hard timeout value in seconds.
57 *
TeruU9e530662014-05-18 11:49:37 -070058 * @param the hard timeout value in seconds
TeruU30c0c932014-05-15 16:47:41 -070059 */
60 public void setHardTimeout(int hardTimeout) {
61 this.hardTimeout = hardTimeout;
62 }
63
64 /***
65 * Sets idle timeout value in seconds.
66 *
TeruU9e530662014-05-18 11:49:37 -070067 * @param the idle timeout value in seconds
TeruU30c0c932014-05-15 16:47:41 -070068 */
69 public void setIdleTimeout(int idleTimeout) {
70 this.idleTimeout = idleTimeout;
71 }
72
TeruU9e530662014-05-18 11:49:37 -070073 /***
74 * Gets flowEntryId.
75 *
76 * @param the flowEntryId to be set in cookie
77 */
78 public long getFlowEntryId() {
79 return flowEntryId;
80 }
81
82 /***
83 * Sets flowEntryId.
84 *
85 * @param the flowEntryId to be set in cookie
86 */
87 public void setFlowEntryId(long flowEntryId) {
88 this.flowEntryId = flowEntryId;
89 }
90
TeruU30c0c932014-05-15 16:47:41 -070091 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070092 public String toString() {
93 return match + "->" + actions;
94 }
95
96 public long getSwitch() {
97 return sw;
98 }
99
100 public Operator getOperator() {
101 return operator;
102 }
103
104 public void setOperator(Operator op) {
105 operator = op;
106 }
107
108 public net.onrc.onos.core.util.FlowEntry getFlowEntry() {
109 net.onrc.onos.core.util.FlowEntry entry = new net.onrc.onos.core.util.FlowEntry();
110 entry.setDpid(new Dpid(sw));
TeruU9e530662014-05-18 11:49:37 -0700111 entry.setFlowEntryId(new FlowEntryId(flowEntryId));
Ray Milkey269ffb92014-04-03 14:43:30 -0700112 entry.setFlowEntryMatch(match.getFlowEntryMatch());
113 FlowEntryActions flowEntryActions = new FlowEntryActions();
114 for (Action action : actions) {
115 flowEntryActions.addAction(action.getFlowEntryAction());
116 }
117 entry.setFlowEntryActions(flowEntryActions);
118 switch (operator) {
119 case ADD:
120 entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_MODIFY);
121 break;
122 case REMOVE:
123 entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_DELETE);
124 break;
125 default:
126 break;
127 }
TeruU30c0c932014-05-15 16:47:41 -0700128 entry.setIdleTimeout(idleTimeout);
129 entry.setHardTimeout(hardTimeout);
Ray Milkey269ffb92014-04-03 14:43:30 -0700130 return entry;
131 }
132
133
TeruU30c0c932014-05-15 16:47:41 -0700134 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -0700135 public int hashCode() {
136 return match.hashCode();
137 }
138
TeruU30c0c932014-05-15 16:47:41 -0700139 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -0700140 public boolean equals(Object o) {
141 if (!(o instanceof FlowEntry)) {
142 return false;
143 }
144 FlowEntry other = (FlowEntry) o;
145 // Note: we should not consider the operator for this comparison
146 return this.match.equals(other.match)
147 && this.actions.containsAll(other.actions)
148 && other.actions.containsAll(this.actions);
149 }
Brian O'Connor6dc44e92014-02-24 21:23:46 -0800150}