blob: 13bfa21e547459e4a4bfcce701bf926793761c5d [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'Connor7f8e3012014-02-15 23:59:29 -08008import net.onrc.onos.ofcontroller.networkgraph.Port;
9import net.onrc.onos.ofcontroller.networkgraph.Switch;
Brian O'Connor67c6e662014-02-17 15:20:44 -080010import net.onrc.onos.ofcontroller.util.Dpid;
11import net.onrc.onos.ofcontroller.util.FlowEntryActions;
12import net.onrc.onos.ofcontroller.util.FlowEntryId;
Brian O'Connor12861f72014-02-19 20:40:32 -080013import net.onrc.onos.ofcontroller.util.FlowEntryUserState;
Brian O'Connor7f8e3012014-02-15 23:59:29 -080014
15/**
16 *
17 * @author Brian O'Connor <bocon@onlab.us>
18 *
19 */
20
21public class FlowEntry {
22 protected Switch sw;
23 protected Match match;
24 protected Set<Action> actions;
Brian O'Connor12861f72014-02-19 20:40:32 -080025 protected Operator operator;
Brian O'Connor7f8e3012014-02-15 23:59:29 -080026
27 public FlowEntry(Switch sw, Port srcPort, Port dstPort,
Brian O'Connor12861f72014-02-19 20:40:32 -080028 MACAddress srcMac, MACAddress dstMac,
29 Operator operator) {
Brian O'Connor7f8e3012014-02-15 23:59:29 -080030 this.sw = sw;
31 this.match = new Match(sw, srcPort, srcMac, dstMac);
32 this.actions = new HashSet<Action>();
33 this.actions.add(new ForwardAction(dstPort));
Brian O'Connor12861f72014-02-19 20:40:32 -080034 this.operator = operator;
Brian O'Connor7f8e3012014-02-15 23:59:29 -080035 }
36
37 public String toString() {
38 return match + "->" + actions;
39 }
Brian O'Connor67c6e662014-02-17 15:20:44 -080040
41 public Switch getSwitch() {
42 return sw;
43 }
44
Brian O'Connor12861f72014-02-19 20:40:32 -080045 public Operator getOperator() {
46 return operator;
47 }
48
49 public void setOperator(Operator op) {
50 operator = op;
51 }
52
Brian O'Connor67c6e662014-02-17 15:20:44 -080053 public net.onrc.onos.ofcontroller.util.FlowEntry getFlowEntry() {
54 net.onrc.onos.ofcontroller.util.FlowEntry entry = new net.onrc.onos.ofcontroller.util.FlowEntry();
55 entry.setDpid(new Dpid(sw.getDpid()));
56 entry.setFlowEntryId(new FlowEntryId(0)); // all zero for now
57 entry.setFlowEntryMatch(match.getFlowEntryMatch());
58 FlowEntryActions flowEntryActions = new FlowEntryActions();
59 for(Action action : actions) {
60 flowEntryActions.addAction(action.getFlowEntryAction());
61 }
62 entry.setFlowEntryActions(flowEntryActions);
Brian O'Connor12861f72014-02-19 20:40:32 -080063 switch(operator) {
64 case ADD:
65 entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_MODIFY);
66 break;
67 case REMOVE:
68 entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_DELETE);
69 break;
70 }
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}