building flowrules
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
index 6801e8a..564416c 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
@@ -12,6 +12,10 @@
private final TrafficTreatment treatment;
private final FlowId id;
private final long created;
+ private long life;
+ private long idle;
+ private long packets;
+ private long bytes;
public DefaultFlowRule(DeviceId deviceId,
@@ -20,10 +24,26 @@
this.priority = priority;
this.selector = selector;
this.treatment = treatment;
+ this.life = 0;
+ this.idle = 0;
+ this.packets = 0;
+ this.bytes = 0;
this.id = FlowId.valueOf(this.hashCode());
this.created = System.currentTimeMillis();
}
+ // TODO: Decide whether to take the flowId from the underlying flowentry.
+ public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
+ TrafficTreatment treatment, int priority,
+ long life, long idle, long packets, long bytes) {
+ this(deviceId, selector, treatment, priority);
+ this.life = life;
+ this.idle = idle;
+ this.packets = packets;
+ this.bytes = bytes;
+ }
+
+
@Override
public FlowId id() {
return id;
@@ -51,25 +71,22 @@
@Override
public long lifeMillis() {
- return (created - System.currentTimeMillis());
+ return life;
}
@Override
public long idleMillis() {
- // TODO Auto-generated method stub
- return 0;
+ return idle;
}
@Override
public long packets() {
- // TODO Auto-generated method stub
- return 0;
+ return packets;
}
@Override
public long bytes() {
- // TODO Auto-generated method stub
- return 0;
+ return bytes;
}
@Override
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java
index b8aa0c2..0277695 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java
@@ -1,6 +1,5 @@
package org.onlab.onos.net.flow;
-import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.provider.Provider;
/**
@@ -26,14 +25,4 @@
*/
void removeFlowRule(FlowRule... flowRules);
-
- /**
- * Returns the collection of flow entries currently applied on the given
- * device.
- *
- * @param deviceId device identifier
- * @return collection of flow entries
- */
- Iterable<FlowRule> getFlowMetrics(DeviceId deviceId);
-
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProviderService.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProviderService.java
index 661b195..f5b31f8 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProviderService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProviderService.java
@@ -29,4 +29,13 @@
*/
void flowAdded(FlowRule flowRule);
+ /**
+ * Pushes the collection of flow entries currently applied on the given
+ * device.
+ *
+ * @param deviceId device identifier
+ * @return collection of flow entries
+ */
+ void pushFlowMetrics(Iterable<FlowRule> flowEntries);
+
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/criteria/Criteria.java b/core/api/src/main/java/org/onlab/onos/net/flow/criteria/Criteria.java
index 9cae5f9..9a5fffa 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/criteria/Criteria.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/criteria/Criteria.java
@@ -75,7 +75,7 @@
* @param vlanPcp vlan pcp value
* @return match criterion
*/
- public static Criterion matchVlanId(Byte vlanPcp) {
+ public static Criterion matchVlanPcp(Byte vlanPcp) {
return new VlanPcpCriterion(vlanPcp);
}
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManager.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManager.java
index 7181f02..7003271 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManager.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManager.java
@@ -1,5 +1,6 @@
package org.onlab.onos.net.trivial.flow.impl;
+import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.ArrayList;
@@ -27,8 +28,6 @@
import org.onlab.onos.net.provider.AbstractProviderService;
import org.slf4j.Logger;
-import static com.google.common.base.Preconditions.checkNotNull;
-
@Component(immediate = true)
@Service
public class SimpleFlowRuleManager
@@ -110,8 +109,8 @@
}
private class InternalFlowRuleProviderService
- extends AbstractProviderService<FlowRuleProvider>
- implements FlowRuleProviderService {
+ extends AbstractProviderService<FlowRuleProvider>
+ implements FlowRuleProviderService {
protected InternalFlowRuleProviderService(FlowRuleProvider provider) {
super(provider);
@@ -157,6 +156,12 @@
eventDispatcher.post(event);
}
}
+
+ @Override
+ public void pushFlowMetrics(Iterable<FlowRule> flowEntries) {
+ // TODO Auto-generated method stub
+
+ }
}
}
diff --git a/core/trivial/src/test/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManagerTest.java b/core/trivial/src/test/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManagerTest.java
index 1cf8a9f..0bee5b3 100644
--- a/core/trivial/src/test/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManagerTest.java
+++ b/core/trivial/src/test/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManagerTest.java
@@ -4,6 +4,8 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADDED;
+import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
import java.util.ArrayList;
import java.util.List;
@@ -39,8 +41,6 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
-import static org.onlab.onos.net.flow.FlowRuleEvent.Type.*;
-
/**
* Test codifying the flow rule service & flow rule provider service contracts.
*/
@@ -79,7 +79,7 @@
public void tearDown() {
registry.unregister(provider);
assertFalse("provider should not be registered",
- registry.getProviders().contains(provider.id()));
+ registry.getProviders().contains(provider.id()));
service.removeListener(listener);
mgr.deactivate();
mgr.eventDispatcher = null;
@@ -253,17 +253,12 @@
public void removeFlowRule(FlowRule... flowRules) {
}
- @Override
- public Iterable<FlowRule> getFlowMetrics(DeviceId deviceId) {
- return null;
- }
-
}
private class TestSelector implements TrafficSelector {
//for controlling hashcode uniqueness;
- private int testval;
+ private final int testval;
public TestSelector(int val) {
testval = val;
@@ -291,7 +286,7 @@
private class TestTreatment implements TrafficTreatment {
//for controlling hashcode uniqueness;
- private int testval;
+ private final int testval;
public TestTreatment(int val) {
testval = val;
diff --git a/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/OpenFlowRuleProvider.java b/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/OpenFlowRuleProvider.java
index 81e138f..73e00bb 100644
--- a/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/OpenFlowRuleProvider.java
+++ b/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/OpenFlowRuleProvider.java
@@ -2,6 +2,7 @@
import static org.slf4j.LoggerFactory.getLogger;
+import java.util.List;
import java.util.Map;
import org.apache.felix.scr.annotations.Activate;
@@ -24,10 +25,15 @@
import org.onlab.onos.openflow.controller.OpenFlowSwitch;
import org.onlab.onos.openflow.controller.OpenFlowSwitchListener;
import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
+import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
+import org.projectfloodlight.openflow.protocol.OFFlowStatsReply;
import org.projectfloodlight.openflow.protocol.OFMessage;
import org.projectfloodlight.openflow.protocol.OFPortStatus;
+import org.projectfloodlight.openflow.protocol.OFStatsReply;
+import org.projectfloodlight.openflow.protocol.OFStatsType;
import org.slf4j.Logger;
+import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
@@ -94,12 +100,6 @@
}
- @Override
- public Iterable<FlowRule> getFlowMetrics(DeviceId deviceId) {
- // TODO Auto-generated method stub
- return null;
- }
-
//TODO: InternalFlowRuleProvider listening to stats and error and flowremoved.
// possibly barriers as well. May not be internal at all...
@@ -118,7 +118,6 @@
@Override
public void switchRemoved(Dpid dpid) {
collectors.remove(dpid).stop();
-
}
@Override
@@ -136,6 +135,7 @@
providerService.flowRemoved(fr);
break;
case STATS_REPLY:
+ pushFlowMetrics(dpid, (OFStatsReply) msg);
break;
case BARRIER_REPLY:
case ERROR:
@@ -145,6 +145,18 @@
}
+ private void pushFlowMetrics(Dpid dpid, OFStatsReply stats) {
+ if (stats.getStatsType() != OFStatsType.FLOW) {
+ return;
+ }
+ final OFFlowStatsReply replies = (OFFlowStatsReply) stats;
+ final List<FlowRule> entries = Lists.newLinkedList();
+ for (OFFlowStatsEntry reply : replies.getEntries()) {
+ entries.add(new FlowRuleBuilder(dpid, reply).build());
+ }
+ providerService.pushFlowMetrics(entries);
+ }
+
}