alshabib

the real return of the flowentry

Change-Id: I9ec244710345dbae193613ab95f473a888d7d771
1 +package org.onlab.onos.net.flow;
2 +
3 +import static com.google.common.base.MoreObjects.toStringHelper;
4 +import static org.slf4j.LoggerFactory.getLogger;
5 +
6 +import org.onlab.onos.net.DeviceId;
7 +import org.slf4j.Logger;
8 +
9 +public class DefaultFlowEntry extends DefaultFlowRule implements FlowEntry {
10 +
11 + private final Logger log = getLogger(getClass());
12 +
13 + private long life;
14 + private long packets;
15 + private long bytes;
16 + private FlowEntryState state;
17 +
18 + private long lastSeen = -1;
19 +
20 +
21 + public DefaultFlowEntry(DeviceId deviceId, TrafficSelector selector,
22 + TrafficTreatment treatment, int priority, FlowEntryState state,
23 + long life, long packets, long bytes, long flowId,
24 + int timeout) {
25 + super(deviceId, selector, treatment, priority, flowId, timeout);
26 + this.state = state;
27 + this.life = life;
28 + this.packets = packets;
29 + this.bytes = bytes;
30 + this.lastSeen = System.currentTimeMillis();
31 + }
32 +
33 + public DefaultFlowEntry(FlowRule rule, FlowEntryState state,
34 + long life, long packets, long bytes) {
35 + super(rule);
36 + this.state = state;
37 + this.life = life;
38 + this.packets = packets;
39 + this.bytes = bytes;
40 + this.lastSeen = System.currentTimeMillis();
41 + }
42 +
43 + public DefaultFlowEntry(FlowRule rule) {
44 + super(rule);
45 + this.state = FlowEntryState.PENDING_ADD;
46 + this.life = 0;
47 + this.packets = 0;
48 + this.bytes = 0;
49 + this.lastSeen = System.currentTimeMillis();
50 + }
51 +
52 + @Override
53 + public long life() {
54 + return life;
55 + }
56 +
57 + @Override
58 + public long packets() {
59 + return packets;
60 + }
61 +
62 + @Override
63 + public long bytes() {
64 + return bytes;
65 + }
66 +
67 + @Override
68 + public FlowEntryState state() {
69 + return this.state;
70 + }
71 +
72 + @Override
73 + public long lastSeen() {
74 + return lastSeen;
75 + }
76 +
77 + @Override
78 + public void setLastSeen() {
79 + this.lastSeen = System.currentTimeMillis();
80 + }
81 +
82 + @Override
83 + public void setState(FlowEntryState newState) {
84 + this.state = newState;
85 + }
86 +
87 + @Override
88 + public void setLife(long life) {
89 + this.life = life;
90 + }
91 +
92 + @Override
93 + public void setPackets(long packets) {
94 + this.packets = packets;
95 + }
96 +
97 + @Override
98 + public void setBytes(long bytes) {
99 + this.bytes = bytes;
100 + }
101 +
102 + @Override
103 + public String toString() {
104 + return toStringHelper(this)
105 + .add("rule", super.toString())
106 + .add("state", state)
107 + .toString();
108 + }
109 +
110 +
111 +}
1 +package org.onlab.onos.net.flow;
2 +
3 +
4 +/**
5 + * Represents a generalized match & action pair to be applied to
6 + * an infrastucture device.
7 + */
8 +public interface FlowEntry extends FlowRule {
9 +
10 +
11 + public enum FlowEntryState {
12 +
13 + /**
14 + * Indicates that this rule has been submitted for addition.
15 + * Not necessarily in the flow table.
16 + */
17 + PENDING_ADD,
18 +
19 + /**
20 + * Rule has been added which means it is in the flow table.
21 + */
22 + ADDED,
23 +
24 + /**
25 + * Flow has been marked for removal, might still be in flow table.
26 + */
27 + PENDING_REMOVE,
28 +
29 + /**
30 + * Flow has been removed from flow table and can be purged.
31 + */
32 + REMOVED
33 + }
34 +
35 + /**
36 + * Returns the flow entry state.
37 + *
38 + * @return flow entry state
39 + */
40 + FlowEntryState state();
41 +
42 + /**
43 + * Returns the number of milliseconds this flow rule has been applied.
44 + *
45 + * @return number of millis
46 + */
47 + long life();
48 +
49 + /**
50 + * Returns the number of packets this flow rule has matched.
51 + *
52 + * @return number of packets
53 + */
54 + long packets();
55 +
56 + /**
57 + * Returns the number of bytes this flow rule has matched.
58 + *
59 + * @return number of bytes
60 + */
61 + long bytes();
62 +
63 + /**
64 + * When this flow entry was last deemed active.
65 + * @return epoch time of last activity
66 + */
67 + long lastSeen();
68 +
69 + /**
70 + * Sets the last active epoch time.
71 + */
72 + void setLastSeen();
73 +
74 + /**
75 + * Sets the new state for this entry.
76 + * @param newState new flow entry state.
77 + */
78 + void setState(FlowEntryState newState);
79 +
80 + /**
81 + * Sets how long this entry has been entered in the system.
82 + * @param life epoch time
83 + */
84 + void setLife(long life);
85 +
86 + /**
87 + * Number of packets seen by this entry.
88 + * @param packets a long value
89 + */
90 + void setPackets(long packets);
91 +
92 + /**
93 + * Number of bytes seen by this rule.
94 + * @param bytes a long value
95 + */
96 + void setBytes(long bytes);
97 +
98 +}