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 | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 8 | import net.onrc.onos.ofcontroller.util.Dpid; |
| 9 | import net.onrc.onos.ofcontroller.util.FlowEntryActions; |
| 10 | import net.onrc.onos.ofcontroller.util.FlowEntryId; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 11 | import net.onrc.onos.ofcontroller.util.FlowEntryUserState; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * |
| 15 | * @author Brian O'Connor <bocon@onlab.us> |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | public class FlowEntry { |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame^] | 20 | protected long sw; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 21 | protected Match match; |
| 22 | protected Set<Action> actions; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 23 | protected Operator operator; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 24 | |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame^] | 25 | public FlowEntry(long sw, long srcPort, long dstPort, |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 26 | MACAddress srcMac, MACAddress dstMac, |
| 27 | Operator operator) { |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 28 | 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'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 32 | this.operator = operator; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | public String toString() { |
| 36 | return match + "->" + actions; |
| 37 | } |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 38 | |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame^] | 39 | public long getSwitch() { |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 40 | return sw; |
| 41 | } |
| 42 | |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 43 | public Operator getOperator() { |
| 44 | return operator; |
| 45 | } |
| 46 | |
| 47 | public void setOperator(Operator op) { |
| 48 | operator = op; |
| 49 | } |
| 50 | |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 51 | 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'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame^] | 53 | entry.setDpid(new Dpid(sw)); |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 54 | 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'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 61 | 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'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame^] | 68 | default: |
| 69 | break; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 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 | } |