Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 1 | package net.onrc.onos.intent; |
| 2 | |
| 3 | import java.util.HashSet; |
| 4 | import java.util.Set; |
| 5 | |
| 6 | import net.floodlightcontroller.util.MACAddress; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 7 | import net.onrc.onos.intent.IntentOperation.Operator; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 8 | import net.onrc.onos.ofcontroller.networkgraph.Port; |
| 9 | import net.onrc.onos.ofcontroller.networkgraph.Switch; |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 10 | import net.onrc.onos.ofcontroller.util.Dpid; |
| 11 | import net.onrc.onos.ofcontroller.util.FlowEntryActions; |
| 12 | import net.onrc.onos.ofcontroller.util.FlowEntryId; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 13 | import net.onrc.onos.ofcontroller.util.FlowEntryUserState; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 14 | |
| 15 | /** |
| 16 | * |
| 17 | * @author Brian O'Connor <bocon@onlab.us> |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | public class FlowEntry { |
| 22 | protected Switch sw; |
| 23 | protected Match match; |
| 24 | protected Set<Action> actions; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 25 | protected Operator operator; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 26 | |
| 27 | public FlowEntry(Switch sw, Port srcPort, Port dstPort, |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 28 | MACAddress srcMac, MACAddress dstMac, |
| 29 | Operator operator) { |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 30 | 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'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 34 | this.operator = operator; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | public String toString() { |
| 38 | return match + "->" + actions; |
| 39 | } |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 40 | |
| 41 | public Switch getSwitch() { |
| 42 | return sw; |
| 43 | } |
| 44 | |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 45 | public Operator getOperator() { |
| 46 | return operator; |
| 47 | } |
| 48 | |
| 49 | public void setOperator(Operator op) { |
| 50 | operator = op; |
| 51 | } |
| 52 | |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 53 | 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'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 63 | 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'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 71 | return entry; |
| 72 | } |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 73 | |
| 74 | //TODO: implement hash for cookie |
| 75 | //TODO: implement equals (don't include operator!) |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 76 | } |