blob: 374e5d61f37f7567c5defdbfa7c472d95cd6b028 [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'Connor67c6e662014-02-17 15:20:44 -080054 entry.setFlowEntryId(new FlowEntryId(0)); // all zero for now
55 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
74 //TODO: implement hash for cookie
75 //TODO: implement equals (don't include operator!)
Brian O'Connor7f8e3012014-02-15 23:59:29 -080076}