blob: 7aa3d76c190bb783ed61e3d390473894348f3f57 [file] [log] [blame]
Brian O'Connor7f8e3012014-02-15 23:59:29 -08001package net.onrc.onos.intent;
2
3import java.util.HashSet;
4import java.util.Set;
5
6import net.floodlightcontroller.util.MACAddress;
Brian O'Connor12861f72014-02-19 20:40:32 -08007import net.onrc.onos.intent.IntentOperation.Operator;
Brian O'Connor67c6e662014-02-17 15:20:44 -08008import net.onrc.onos.ofcontroller.util.Dpid;
9import net.onrc.onos.ofcontroller.util.FlowEntryActions;
10import net.onrc.onos.ofcontroller.util.FlowEntryId;
Brian O'Connor12861f72014-02-19 20:40:32 -080011import net.onrc.onos.ofcontroller.util.FlowEntryUserState;
Brian O'Connor7f8e3012014-02-15 23:59:29 -080012
13/**
14 *
15 * @author Brian O'Connor <bocon@onlab.us>
16 *
17 */
18
19public class FlowEntry {
Brian O'Connor488e5ed2014-02-20 19:50:01 -080020 protected long sw;
Brian O'Connor7f8e3012014-02-15 23:59:29 -080021 protected Match match;
22 protected Set<Action> actions;
Brian O'Connor12861f72014-02-19 20:40:32 -080023 protected Operator operator;
Brian O'Connor7f8e3012014-02-15 23:59:29 -080024
Brian O'Connor488e5ed2014-02-20 19:50:01 -080025 public FlowEntry(long sw, long srcPort, long dstPort,
Brian O'Connor12861f72014-02-19 20:40:32 -080026 MACAddress srcMac, MACAddress dstMac,
27 Operator operator) {
Brian O'Connor7f8e3012014-02-15 23:59:29 -080028 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));
Brian O'Connor12861f72014-02-19 20:40:32 -080032 this.operator = operator;
Brian O'Connor7f8e3012014-02-15 23:59:29 -080033 }
34
35 public String toString() {
36 return match + "->" + actions;
37 }
Brian O'Connor67c6e662014-02-17 15:20:44 -080038
Brian O'Connor488e5ed2014-02-20 19:50:01 -080039 public long getSwitch() {
Brian O'Connor67c6e662014-02-17 15:20:44 -080040 return sw;
41 }
42
Brian O'Connor12861f72014-02-19 20:40:32 -080043 public Operator getOperator() {
44 return operator;
45 }
46
47 public void setOperator(Operator op) {
48 operator = op;
49 }
50
Brian O'Connor67c6e662014-02-17 15:20:44 -080051 public net.onrc.onos.ofcontroller.util.FlowEntry getFlowEntry() {
52 net.onrc.onos.ofcontroller.util.FlowEntry entry = new net.onrc.onos.ofcontroller.util.FlowEntry();
Brian O'Connor488e5ed2014-02-20 19:50:01 -080053 entry.setDpid(new Dpid(sw));
Brian O'Connor6dc44e92014-02-24 21:23:46 -080054 entry.setFlowEntryId(new FlowEntryId(hashCode())); // naive, but useful for now
Brian O'Connor67c6e662014-02-17 15:20:44 -080055 entry.setFlowEntryMatch(match.getFlowEntryMatch());
56 FlowEntryActions flowEntryActions = new FlowEntryActions();
57 for(Action action : actions) {
58 flowEntryActions.addAction(action.getFlowEntryAction());
59 }
60 entry.setFlowEntryActions(flowEntryActions);
Brian O'Connor12861f72014-02-19 20:40:32 -080061 switch(operator) {
62 case ADD:
63 entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_MODIFY);
64 break;
65 case REMOVE:
66 entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_DELETE);
67 break;
Brian O'Connor488e5ed2014-02-20 19:50:01 -080068 default:
69 break;
Brian O'Connor12861f72014-02-19 20:40:32 -080070 }
Brian O'Connor67c6e662014-02-17 15:20:44 -080071 return entry;
72 }
Brian O'Connor12861f72014-02-19 20:40:32 -080073
Brian O'Connor6dc44e92014-02-24 21:23:46 -080074
75 public int hashCode() {
76 return match.hashCode();
77 }
78
79 public boolean equals(Object o) {
80 if(!(o instanceof FlowEntry)) {
81 return false;
82 }
83 FlowEntry other = (FlowEntry) o;
84 // Note: we should not consider the operator for this comparison
85 return this.match.equals(other.match)
86 && this.actions.containsAll(other.actions)
87 && other.actions.containsAll(this.actions);
88 }
89}