use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.
the class SimpleVirtualFlowRuleStore method storeFlowRuleInternal.
private void storeFlowRuleInternal(NetworkId networkId, FlowRule rule) {
StoredFlowEntry f = new DefaultFlowEntry(rule);
final DeviceId did = f.deviceId();
final FlowId fid = f.id();
List<StoredFlowEntry> existing = getFlowEntries(networkId, did, fid);
synchronized (existing) {
for (StoredFlowEntry fe : existing) {
if (fe.equals(rule)) {
// was already there? ignore
return;
}
}
// new flow rule added
existing.add(f);
}
}
use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.
the class VirtualNetworkFlowRuleManagerTest method purgeFlowRules.
@Test
public void purgeFlowRules() {
FlowRule f1 = addFlowRule(1);
FlowRule f2 = addFlowRule(2);
FlowRule f3 = addFlowRule(3);
assertEquals("3 rules should exist", 3, flowCount(vnetFlowRuleService1));
FlowEntry fe1 = new DefaultFlowEntry(f1);
FlowEntry fe2 = new DefaultFlowEntry(f2);
FlowEntry fe3 = new DefaultFlowEntry(f3);
providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1, fe2, fe3));
validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_ADDED);
vnetFlowRuleService1.purgeFlowRules(VDID1);
assertEquals("0 rule should exist", 0, flowCount(vnetFlowRuleService1));
}
use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.
the class VirtualNetworkFlowRuleManagerTest method getFlowEntries.
@Test
public void getFlowEntries() {
assertTrue("store should be empty", Sets.newHashSet(vnetFlowRuleService1.getFlowEntries(VDID1)).isEmpty());
assertTrue("store should be empty", Sets.newHashSet(vnetFlowRuleService2.getFlowEntries(VDID1)).isEmpty());
FlowRule f1 = addFlowRule(1);
FlowRule f2 = addFlowRule(2);
FlowEntry fe1 = new DefaultFlowEntry(f1);
FlowEntry fe2 = new DefaultFlowEntry(f2);
assertEquals("2 rules should exist", 2, flowCount(vnetFlowRuleService1));
assertEquals("0 rules should exist", 0, flowCount(vnetFlowRuleService2));
providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1, fe2));
validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED);
addFlowRule(1);
assertEquals("should still be 2 rules", 2, flowCount(vnetFlowRuleService1));
System.err.println("events :" + listener1.events);
assertEquals("0 rules should exist", 0, flowCount(vnetFlowRuleService2));
providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1));
validateEvents(listener1, RULE_UPDATED, RULE_UPDATED);
}
use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.
the class FlowEntryCodec method decode.
@Override
public FlowEntry decode(ObjectNode json, CodecContext context) {
checkNotNull(json, "JSON object cannot be null");
// decode FlowRule-specific fields using the FlowRule codec
FlowRule flowRule = context.codec(FlowRule.class).decode(json, context);
JsonNode stateNode = json.get(STATE);
FlowEntry.FlowEntryState state = (null == stateNode) ? FlowEntry.FlowEntryState.ADDED : FlowEntry.FlowEntryState.valueOf(stateNode.asText());
JsonNode lifeNode = json.get(LIFE);
long life = (null == lifeNode) ? 0 : lifeNode.asLong();
JsonNode liveTypeNode = json.get(LIVE_TYPE);
FlowEntry.FlowLiveType liveType = (null == liveTypeNode) ? FlowEntry.FlowLiveType.UNKNOWN : FlowEntry.FlowLiveType.valueOf(liveTypeNode.asText());
JsonNode packetsNode = json.get(PACKETS);
long packets = (null == packetsNode) ? 0 : packetsNode.asLong();
JsonNode bytesNode = json.get(BYTES);
long bytes = (null == bytesNode) ? 0 : bytesNode.asLong();
return new DefaultFlowEntry(flowRule, state, life, liveType, packets, bytes);
}
use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.
the class SimpleFlowRuleStore method storeFlowRuleInternal.
private void storeFlowRuleInternal(FlowRule rule) {
StoredFlowEntry f = new DefaultFlowEntry(rule);
final DeviceId did = f.deviceId();
final FlowId fid = f.id();
List<StoredFlowEntry> existing = getFlowEntries(did, fid);
synchronized (existing) {
for (StoredFlowEntry fe : existing) {
if (fe.equals(rule)) {
// was already there? ignore
return;
}
}
// new flow rule added
existing.add(f);
}
}
Aggregations