blob: 526fe5fb9cc06c4792e06a0160c0e43e771751c5 [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;
22
23 public FlowEntry(long sw, long srcPort, long dstPort,
24 MACAddress srcMac, MACAddress dstMac,
25 Operator operator) {
26 this.sw = sw;
27 this.match = new Match(sw, srcPort, srcMac, dstMac);
28 this.actions = new HashSet<Action>();
29 this.actions.add(new ForwardAction(dstPort));
30 this.operator = operator;
31 }
32
33 public String toString() {
34 return match + "->" + actions;
35 }
36
37 public long getSwitch() {
38 return sw;
39 }
40
41 public Operator getOperator() {
42 return operator;
43 }
44
45 public void setOperator(Operator op) {
46 operator = op;
47 }
48
49 public net.onrc.onos.core.util.FlowEntry getFlowEntry() {
50 net.onrc.onos.core.util.FlowEntry entry = new net.onrc.onos.core.util.FlowEntry();
51 entry.setDpid(new Dpid(sw));
52 entry.setFlowEntryId(new FlowEntryId(hashCode())); // naive, but useful for now
53 entry.setFlowEntryMatch(match.getFlowEntryMatch());
54 FlowEntryActions flowEntryActions = new FlowEntryActions();
55 for (Action action : actions) {
56 flowEntryActions.addAction(action.getFlowEntryAction());
57 }
58 entry.setFlowEntryActions(flowEntryActions);
59 switch (operator) {
60 case ADD:
61 entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_MODIFY);
62 break;
63 case REMOVE:
64 entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_DELETE);
65 break;
66 default:
67 break;
68 }
69 return entry;
70 }
71
72
73 public int hashCode() {
74 return match.hashCode();
75 }
76
77 public boolean equals(Object o) {
78 if (!(o instanceof FlowEntry)) {
79 return false;
80 }
81 FlowEntry other = (FlowEntry) o;
82 // Note: we should not consider the operator for this comparison
83 return this.match.equals(other.match)
84 && this.actions.containsAll(other.actions)
85 && other.actions.containsAll(this.actions);
86 }
Brian O'Connor6dc44e92014-02-24 21:23:46 -080087}