Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.intent; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 2 | |
| 3 | import java.util.HashSet; |
| 4 | import java.util.Set; |
| 5 | |
| 6 | import net.floodlightcontroller.util.MACAddress; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 7 | import net.onrc.onos.core.intent.IntentOperation.Operator; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 8 | import net.onrc.onos.core.util.Dpid; |
| 9 | import net.onrc.onos.core.util.FlowEntryActions; |
| 10 | import net.onrc.onos.core.util.FlowEntryId; |
| 11 | import net.onrc.onos.core.util.FlowEntryUserState; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 12 | |
| 13 | /** |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 14 | * @author Brian O'Connor <bocon@onlab.us> |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | public class FlowEntry { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 18 | protected long sw; |
| 19 | protected Match match; |
| 20 | protected Set<Action> actions; |
| 21 | protected Operator operator; |
| 22 | |
| 23 | public FlowEntry(long sw, long srcPort, long dstPort, |
| 24 | MACAddress srcMac, MACAddress dstMac, |
| 25 | Operator operator) { |
| 26 | this.sw = sw; |
| 27 | this.match = new Match(sw, srcPort, srcMac, dstMac); |
| 28 | this.actions = new HashSet<Action>(); |
| 29 | this.actions.add(new ForwardAction(dstPort)); |
| 30 | this.operator = operator; |
| 31 | } |
| 32 | |
| 33 | public String toString() { |
| 34 | return match + "->" + actions; |
| 35 | } |
| 36 | |
| 37 | public long getSwitch() { |
| 38 | return sw; |
| 39 | } |
| 40 | |
| 41 | public Operator getOperator() { |
| 42 | return operator; |
| 43 | } |
| 44 | |
| 45 | public void setOperator(Operator op) { |
| 46 | operator = op; |
| 47 | } |
| 48 | |
| 49 | public net.onrc.onos.core.util.FlowEntry getFlowEntry() { |
| 50 | net.onrc.onos.core.util.FlowEntry entry = new net.onrc.onos.core.util.FlowEntry(); |
| 51 | entry.setDpid(new Dpid(sw)); |
| 52 | entry.setFlowEntryId(new FlowEntryId(hashCode())); // naive, but useful for now |
| 53 | entry.setFlowEntryMatch(match.getFlowEntryMatch()); |
| 54 | FlowEntryActions flowEntryActions = new FlowEntryActions(); |
| 55 | for (Action action : actions) { |
| 56 | flowEntryActions.addAction(action.getFlowEntryAction()); |
| 57 | } |
| 58 | entry.setFlowEntryActions(flowEntryActions); |
| 59 | switch (operator) { |
| 60 | case ADD: |
| 61 | entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_MODIFY); |
| 62 | break; |
| 63 | case REMOVE: |
| 64 | entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_DELETE); |
| 65 | break; |
| 66 | default: |
| 67 | break; |
| 68 | } |
| 69 | return entry; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | public int hashCode() { |
| 74 | return match.hashCode(); |
| 75 | } |
| 76 | |
| 77 | public boolean equals(Object o) { |
| 78 | if (!(o instanceof FlowEntry)) { |
| 79 | return false; |
| 80 | } |
| 81 | FlowEntry other = (FlowEntry) o; |
| 82 | // Note: we should not consider the operator for this comparison |
| 83 | return this.match.equals(other.match) |
| 84 | && this.actions.containsAll(other.actions) |
| 85 | && other.actions.containsAll(this.actions); |
| 86 | } |
Brian O'Connor | 6dc44e9 | 2014-02-24 21:23:46 -0800 | [diff] [blame] | 87 | } |