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 | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 5 | import org.onlab.onos.net.DeviceId; |
| 6 | |
| 7 | public class DefaultFlowRule implements FlowRule { |
| 8 | |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame^] | 9 | private final DeviceId deviceId; |
| 10 | private final int priority; |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 11 | private final TrafficSelector selector; |
| 12 | private final TrafficTreatment treatment; |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame^] | 13 | private final FlowId id; |
| 14 | private final long created; |
| 15 | |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 16 | |
| 17 | public DefaultFlowRule(DeviceId deviceId, |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame^] | 18 | TrafficSelector selector, TrafficTreatment treatment, int priority) { |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 19 | this.deviceId = deviceId; |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame^] | 20 | this.priority = priority; |
| 21 | this.selector = selector; |
| 22 | this.treatment = treatment; |
| 23 | this.id = FlowId.valueOf(this.hashCode()); |
| 24 | this.created = System.currentTimeMillis(); |
| 25 | } |
| 26 | |
| 27 | @Override |
| 28 | public FlowId id() { |
| 29 | return id; |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public int priority() { |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame^] | 34 | return priority; |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public DeviceId deviceId() { |
| 39 | return deviceId; |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public TrafficSelector selector() { |
| 44 | return selector; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public TrafficTreatment treatment() { |
| 49 | return treatment; |
| 50 | } |
| 51 | |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 52 | @Override |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame^] | 53 | public long lifeMillis() { |
| 54 | return (created - System.currentTimeMillis()); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public long idleMillis() { |
| 59 | // TODO Auto-generated method stub |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public long packets() { |
| 65 | // TODO Auto-generated method stub |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public long bytes() { |
| 71 | // TODO Auto-generated method stub |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | /* |
| 77 | * The priority and statistics can change on a given treatment and selector |
| 78 | * |
| 79 | * (non-Javadoc) |
| 80 | * @see java.lang.Object#equals(java.lang.Object) |
| 81 | */ |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 82 | public int hashCode() { |
| 83 | final int prime = 31; |
| 84 | int result = prime * this.deviceId().hashCode(); |
| 85 | result = prime * result + selector.hashCode(); |
| 86 | result = prime * result + treatment.hashCode(); |
| 87 | return result; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | /* |
| 92 | * The priority and statistics can change on a given treatment and selector |
| 93 | * |
| 94 | * (non-Javadoc) |
| 95 | * @see java.lang.Object#equals(java.lang.Object) |
| 96 | */ |
| 97 | public boolean equals(Object obj) { |
| 98 | if (obj instanceof FlowRule) { |
| 99 | DefaultFlowRule that = (DefaultFlowRule) obj; |
| 100 | if (!this.deviceId().equals(that.deviceId())) { |
| 101 | return false; |
| 102 | } |
| 103 | if (!this.treatment().equals(that.treatment())) { |
| 104 | return false; |
| 105 | } |
| 106 | if (!this.selector().equals(that.selector())) { |
| 107 | return false; |
| 108 | } |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 109 | return true; |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 110 | } |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 111 | return false; |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame^] | 114 | @Override |
| 115 | public String toString() { |
| 116 | return toStringHelper(this) |
| 117 | .add("id", id) |
| 118 | .add("deviceId", deviceId) |
| 119 | .add("priority", priority) |
| 120 | .add("selector", selector) |
| 121 | .add("treatment", treatment) |
| 122 | .add("created", created) |
| 123 | .toString(); |
| 124 | } |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 125 | |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 126 | } |