alshabib

the real return of the flowentry

Change-Id: I9ec244710345dbae193613ab95f473a888d7d771
package org.onlab.onos.net.flow;
import static com.google.common.base.MoreObjects.toStringHelper;
import static org.slf4j.LoggerFactory.getLogger;
import org.onlab.onos.net.DeviceId;
import org.slf4j.Logger;
public class DefaultFlowEntry extends DefaultFlowRule implements FlowEntry {
private final Logger log = getLogger(getClass());
private long life;
private long packets;
private long bytes;
private FlowEntryState state;
private long lastSeen = -1;
public DefaultFlowEntry(DeviceId deviceId, TrafficSelector selector,
TrafficTreatment treatment, int priority, FlowEntryState state,
long life, long packets, long bytes, long flowId,
int timeout) {
super(deviceId, selector, treatment, priority, flowId, timeout);
this.state = state;
this.life = life;
this.packets = packets;
this.bytes = bytes;
this.lastSeen = System.currentTimeMillis();
}
public DefaultFlowEntry(FlowRule rule, FlowEntryState state,
long life, long packets, long bytes) {
super(rule);
this.state = state;
this.life = life;
this.packets = packets;
this.bytes = bytes;
this.lastSeen = System.currentTimeMillis();
}
public DefaultFlowEntry(FlowRule rule) {
super(rule);
this.state = FlowEntryState.PENDING_ADD;
this.life = 0;
this.packets = 0;
this.bytes = 0;
this.lastSeen = System.currentTimeMillis();
}
@Override
public long life() {
return life;
}
@Override
public long packets() {
return packets;
}
@Override
public long bytes() {
return bytes;
}
@Override
public FlowEntryState state() {
return this.state;
}
@Override
public long lastSeen() {
return lastSeen;
}
@Override
public void setLastSeen() {
this.lastSeen = System.currentTimeMillis();
}
@Override
public void setState(FlowEntryState newState) {
this.state = newState;
}
@Override
public void setLife(long life) {
this.life = life;
}
@Override
public void setPackets(long packets) {
this.packets = packets;
}
@Override
public void setBytes(long bytes) {
this.bytes = bytes;
}
@Override
public String toString() {
return toStringHelper(this)
.add("rule", super.toString())
.add("state", state)
.toString();
}
}
package org.onlab.onos.net.flow;
/**
* Represents a generalized match & action pair to be applied to
* an infrastucture device.
*/
public interface FlowEntry extends FlowRule {
public enum FlowEntryState {
/**
* Indicates that this rule has been submitted for addition.
* Not necessarily in the flow table.
*/
PENDING_ADD,
/**
* Rule has been added which means it is in the flow table.
*/
ADDED,
/**
* Flow has been marked for removal, might still be in flow table.
*/
PENDING_REMOVE,
/**
* Flow has been removed from flow table and can be purged.
*/
REMOVED
}
/**
* Returns the flow entry state.
*
* @return flow entry state
*/
FlowEntryState state();
/**
* Returns the number of milliseconds this flow rule has been applied.
*
* @return number of millis
*/
long life();
/**
* Returns the number of packets this flow rule has matched.
*
* @return number of packets
*/
long packets();
/**
* Returns the number of bytes this flow rule has matched.
*
* @return number of bytes
*/
long bytes();
/**
* When this flow entry was last deemed active.
* @return epoch time of last activity
*/
long lastSeen();
/**
* Sets the last active epoch time.
*/
void setLastSeen();
/**
* Sets the new state for this entry.
* @param newState new flow entry state.
*/
void setState(FlowEntryState newState);
/**
* Sets how long this entry has been entered in the system.
* @param life epoch time
*/
void setLife(long life);
/**
* Number of packets seen by this entry.
* @param packets a long value
*/
void setPackets(long packets);
/**
* Number of bytes seen by this rule.
* @param bytes a long value
*/
void setBytes(long bytes);
}