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; |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 22 | protected int hardTimeout = 0; |
| 23 | protected int idleTimeout = 0; |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 24 | protected long flowEntryId; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 25 | |
| 26 | public FlowEntry(long sw, long srcPort, long dstPort, |
| 27 | MACAddress srcMac, MACAddress dstMac, |
| 28 | Operator operator) { |
| 29 | this.sw = sw; |
| 30 | this.match = new Match(sw, srcPort, srcMac, dstMac); |
| 31 | this.actions = new HashSet<Action>(); |
| 32 | this.actions.add(new ForwardAction(dstPort)); |
| 33 | this.operator = operator; |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 34 | this.flowEntryId = hashCode(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 35 | } |
| 36 | |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 37 | /*** |
| 38 | * Gets hard timeout value in seconds. |
| 39 | * |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 40 | * @return the hard timeout value in seconds |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 41 | */ |
| 42 | public int getHardTimeout() { |
| 43 | return hardTimeout; |
| 44 | } |
| 45 | |
| 46 | /*** |
| 47 | * Gets idle timeout value in seconds. |
| 48 | * |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 49 | * @return the idle timeout value in seconds |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 50 | */ |
| 51 | public int getIdleTimeout() { |
| 52 | return idleTimeout; |
| 53 | } |
| 54 | |
| 55 | /*** |
| 56 | * Sets hard timeout value in seconds. |
| 57 | * |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 58 | * @param the hard timeout value in seconds |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 59 | */ |
| 60 | public void setHardTimeout(int hardTimeout) { |
| 61 | this.hardTimeout = hardTimeout; |
| 62 | } |
| 63 | |
| 64 | /*** |
| 65 | * Sets idle timeout value in seconds. |
| 66 | * |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 67 | * @param the idle timeout value in seconds |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 68 | */ |
| 69 | public void setIdleTimeout(int idleTimeout) { |
| 70 | this.idleTimeout = idleTimeout; |
| 71 | } |
| 72 | |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 73 | /*** |
| 74 | * Gets flowEntryId. |
| 75 | * |
| 76 | * @param the flowEntryId to be set in cookie |
| 77 | */ |
| 78 | public long getFlowEntryId() { |
| 79 | return flowEntryId; |
| 80 | } |
| 81 | |
| 82 | /*** |
| 83 | * Sets flowEntryId. |
| 84 | * |
| 85 | * @param the flowEntryId to be set in cookie |
| 86 | */ |
| 87 | public void setFlowEntryId(long flowEntryId) { |
| 88 | this.flowEntryId = flowEntryId; |
| 89 | } |
| 90 | |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 91 | @Override |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 92 | public String toString() { |
| 93 | return match + "->" + actions; |
| 94 | } |
| 95 | |
| 96 | public long getSwitch() { |
| 97 | return sw; |
| 98 | } |
| 99 | |
| 100 | public Operator getOperator() { |
| 101 | return operator; |
| 102 | } |
| 103 | |
| 104 | public void setOperator(Operator op) { |
| 105 | operator = op; |
| 106 | } |
| 107 | |
| 108 | public net.onrc.onos.core.util.FlowEntry getFlowEntry() { |
| 109 | net.onrc.onos.core.util.FlowEntry entry = new net.onrc.onos.core.util.FlowEntry(); |
| 110 | entry.setDpid(new Dpid(sw)); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 111 | entry.setFlowEntryId(new FlowEntryId(flowEntryId)); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 112 | entry.setFlowEntryMatch(match.getFlowEntryMatch()); |
| 113 | FlowEntryActions flowEntryActions = new FlowEntryActions(); |
| 114 | for (Action action : actions) { |
| 115 | flowEntryActions.addAction(action.getFlowEntryAction()); |
| 116 | } |
| 117 | entry.setFlowEntryActions(flowEntryActions); |
| 118 | switch (operator) { |
| 119 | case ADD: |
| 120 | entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_MODIFY); |
| 121 | break; |
| 122 | case REMOVE: |
| 123 | entry.setFlowEntryUserState(FlowEntryUserState.FE_USER_DELETE); |
| 124 | break; |
| 125 | default: |
| 126 | break; |
| 127 | } |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 128 | entry.setIdleTimeout(idleTimeout); |
| 129 | entry.setHardTimeout(hardTimeout); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 130 | return entry; |
| 131 | } |
| 132 | |
| 133 | |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 134 | @Override |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 135 | public int hashCode() { |
| 136 | return match.hashCode(); |
| 137 | } |
| 138 | |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 139 | @Override |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 140 | public boolean equals(Object o) { |
| 141 | if (!(o instanceof FlowEntry)) { |
| 142 | return false; |
| 143 | } |
| 144 | FlowEntry other = (FlowEntry) o; |
| 145 | // Note: we should not consider the operator for this comparison |
| 146 | return this.match.equals(other.match) |
| 147 | && this.actions.containsAll(other.actions) |
| 148 | && other.actions.containsAll(this.actions); |
| 149 | } |
Brian O'Connor | 6dc44e9 | 2014-02-24 21:23:46 -0800 | [diff] [blame] | 150 | } |