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