alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.flow; |
| 2 | |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 3 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 4 | |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame^] | 5 | import java.util.Objects; |
| 6 | |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 7 | import org.onlab.onos.net.DeviceId; |
| 8 | |
| 9 | public class DefaultFlowRule implements FlowRule { |
| 10 | |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 11 | private final DeviceId deviceId; |
| 12 | private final int priority; |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 13 | private final TrafficSelector selector; |
| 14 | private final TrafficTreatment treatment; |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 15 | private final FlowId id; |
| 16 | private final long created; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame^] | 17 | private final long life; |
| 18 | private final long idle; |
| 19 | private final long packets; |
| 20 | private final long bytes; |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 21 | |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 22 | |
| 23 | public DefaultFlowRule(DeviceId deviceId, |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 24 | TrafficSelector selector, TrafficTreatment treatment, int priority) { |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 25 | this.deviceId = deviceId; |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 26 | this.priority = priority; |
| 27 | this.selector = selector; |
| 28 | this.treatment = treatment; |
alshabib | 9704490 | 2014-09-18 14:52:16 -0700 | [diff] [blame] | 29 | this.life = 0; |
| 30 | this.idle = 0; |
| 31 | this.packets = 0; |
| 32 | this.bytes = 0; |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 33 | this.id = FlowId.valueOf(this.hashCode()); |
| 34 | this.created = System.currentTimeMillis(); |
| 35 | } |
| 36 | |
alshabib | 9704490 | 2014-09-18 14:52:16 -0700 | [diff] [blame] | 37 | public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, |
| 38 | TrafficTreatment treatment, int priority, |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame^] | 39 | long life, long idle, long packets, long bytes, Integer flowId) { |
| 40 | this.deviceId = deviceId; |
| 41 | this.priority = priority; |
| 42 | this.selector = selector; |
| 43 | this.treatment = treatment; |
| 44 | |
| 45 | this.id = FlowId.valueOf(flowId); |
| 46 | |
alshabib | 9704490 | 2014-09-18 14:52:16 -0700 | [diff] [blame] | 47 | this.life = life; |
| 48 | this.idle = idle; |
| 49 | this.packets = packets; |
| 50 | this.bytes = bytes; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame^] | 51 | this.created = System.currentTimeMillis(); |
alshabib | 9704490 | 2014-09-18 14:52:16 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 55 | @Override |
| 56 | public FlowId id() { |
| 57 | return id; |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public int priority() { |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 62 | return priority; |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public DeviceId deviceId() { |
| 67 | return deviceId; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public TrafficSelector selector() { |
| 72 | return selector; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public TrafficTreatment treatment() { |
| 77 | return treatment; |
| 78 | } |
| 79 | |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 80 | @Override |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 81 | public long lifeMillis() { |
alshabib | 9704490 | 2014-09-18 14:52:16 -0700 | [diff] [blame] | 82 | return life; |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public long idleMillis() { |
alshabib | 9704490 | 2014-09-18 14:52:16 -0700 | [diff] [blame] | 87 | return idle; |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public long packets() { |
alshabib | 9704490 | 2014-09-18 14:52:16 -0700 | [diff] [blame] | 92 | return packets; |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public long bytes() { |
alshabib | 9704490 | 2014-09-18 14:52:16 -0700 | [diff] [blame] | 97 | return bytes; |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Override |
| 101 | /* |
| 102 | * The priority and statistics can change on a given treatment and selector |
| 103 | * |
| 104 | * (non-Javadoc) |
| 105 | * @see java.lang.Object#equals(java.lang.Object) |
| 106 | */ |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 107 | public int hashCode() { |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame^] | 108 | return Objects.hash(deviceId, selector, treatment); |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | @Override |
| 112 | /* |
| 113 | * The priority and statistics can change on a given treatment and selector |
| 114 | * |
| 115 | * (non-Javadoc) |
| 116 | * @see java.lang.Object#equals(java.lang.Object) |
| 117 | */ |
| 118 | public boolean equals(Object obj) { |
| 119 | if (obj instanceof FlowRule) { |
| 120 | DefaultFlowRule that = (DefaultFlowRule) obj; |
| 121 | if (!this.deviceId().equals(that.deviceId())) { |
| 122 | return false; |
| 123 | } |
| 124 | if (!this.treatment().equals(that.treatment())) { |
| 125 | return false; |
| 126 | } |
| 127 | if (!this.selector().equals(that.selector())) { |
| 128 | return false; |
| 129 | } |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 130 | return true; |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 131 | } |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 132 | return false; |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 135 | @Override |
| 136 | public String toString() { |
| 137 | return toStringHelper(this) |
| 138 | .add("id", id) |
| 139 | .add("deviceId", deviceId) |
| 140 | .add("priority", priority) |
| 141 | .add("selector", selector) |
| 142 | .add("treatment", treatment) |
| 143 | .add("created", created) |
| 144 | .toString(); |
| 145 | } |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 146 | |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame^] | 147 | |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 148 | } |