blob: 3f86697fff5021c2c39b60e3afb1e6228e641d58 [file] [log] [blame]
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -07001package org.onlab.onos.net.flow;
2
3import org.onlab.onos.net.DeviceId;
4
5public class DefaultFlowEntry extends DefaultFlowRule implements FlowEntry {
6
7 private final int priority;
8 private final long created;
9 private final FlowId id;
10
11 public DefaultFlowEntry(DefaultFlowEntry entry) {
12 super(entry.deviceId(), entry.selector(), entry.treatment());
13 this.priority = entry.priority;
14 this.created = entry.created;
15 this.id = entry.id;
16 }
17
18 public DefaultFlowEntry(DeviceId deviceId, TrafficSelector selector,
19 TrafficTreatment treatment, int priority) {
20 super(deviceId, selector, treatment);
21 this.priority = priority;
22 this.created = System.currentTimeMillis();
23 this.id = FlowId.valueOf(this.hashCode());
24 }
25
26 @Override
27 public FlowId id() {
28 return null;
29 }
30
31 @Override
32 public int priority() {
33 return priority;
34 }
35
36 @Override
37 public long lifeMillis() {
38 return (created - System.currentTimeMillis());
39 }
40
41 @Override
42 public long idleMillis() {
43 return 0;
44 }
45
46 @Override
47 public long packets() {
48 return 0;
49 }
50
51 @Override
52 public long bytes() {
53 return 0;
54 }
55
56 @Override
57 /*
58 * currently uses the parts that definitely have a defined hashcode...
59 *
60 * (non-Javadoc)
61 * @see java.lang.Object#hashCode()
62 */
63 public int hashCode() {
64 final int prime = 31;
65 int result = prime * this.deviceId().hashCode();
66 result = prime * result + Long.valueOf(this.created).hashCode();
67 return result;
68 }
69
70 @Override
71 /*
72 * The priority and statistics can change on a given treatment and selector
73 *
74 * (non-Javadoc)
75 * @see java.lang.Object#equals(java.lang.Object)
76 */
77 public boolean equals(Object obj) {
78 if (obj instanceof DefaultFlowEntry) {
79 DefaultFlowEntry that = (DefaultFlowEntry) obj;
80 if (!this.id.equals(that.id())) {
81 return false;
82 }
83 return super.equals(obj);
84 }
85 return false;
86 }
87
88}