use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class ECFlowRuleStoreTest method testRemoveFlow.
/**
* Tests flow removal.
*/
@Test
public void testRemoveFlow() {
Iterable<FlowEntry> flows1 = flowStoreImpl.getFlowEntries(deviceId);
for (FlowEntry flow : flows1) {
flowStoreImpl.removeFlowRule(flow);
}
assertFlowsOnDevice(deviceId, 0);
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class ECFlowRuleStoreTest method testStoreBatch.
/**
* Tests initial state of flowrule.
*/
@Test
public void testStoreBatch() {
FlowRuleOperation op = new FlowRuleOperation(flowRule, FlowRuleOperation.Type.ADD);
Multimap<DeviceId, FlowRuleBatchEntry> perDeviceBatches = ArrayListMultimap.create();
perDeviceBatches.put(op.rule().deviceId(), new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, op.rule()));
FlowRuleBatchOperation b = new FlowRuleBatchOperation(perDeviceBatches.get(deviceId), deviceId, 1);
flowStoreImpl.storeBatch(b);
FlowEntry flowEntry1 = flowStoreImpl.getFlowEntry(flowRule);
assertEquals("PENDING_ADD", flowEntry1.state().toString());
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class ECFlowRuleStoreTest method testPurgeFlowAppId.
/**
* Tests purge flow for a device and an application.
*/
@Test
public void testPurgeFlowAppId() {
FlowEntry flowEntry1 = new DefaultFlowEntry(flowRule1);
flowStoreImpl.addOrUpdateFlowRule(flowEntry1);
FlowEntry flowEntry2 = new DefaultFlowEntry(flowRule2);
flowStoreImpl.addOrUpdateFlowRule(flowEntry2);
FlowEntry flowEntry3 = new DefaultFlowEntry(flowRule3);
flowStoreImpl.addOrUpdateFlowRule(flowEntry3);
assertFlowsOnDevice(deviceId, 2);
assertFlowsOnDevice(deviceId2, 1);
flowStoreImpl.purgeFlowRules(deviceId, APP_ID_2);
assertFlowsOnDevice(deviceId, 1);
assertFlowsOnDevice(deviceId2, 1);
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class ECFlowRuleStoreTest method assertFlowsOnDevice.
private void assertFlowsOnDevice(DeviceId deviceId, int nFlows) {
Iterable<FlowEntry> flows1 = flowStoreImpl.getFlowEntries(deviceId);
int sum1 = 0;
for (FlowEntry flowEntry : flows1) {
sum1++;
}
assertThat(sum1, is(nFlows));
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class DistributedFlowStatisticStore method updateFlowStatistic.
@Override
public synchronized void updateFlowStatistic(FlowEntry rule) {
ConnectPoint cp = buildConnectPoint(rule);
if (cp == null) {
return;
}
Set<FlowEntry> curr = current.get(cp);
if (curr == null) {
addFlowStatistic(rule);
} else {
Optional<FlowEntry> f = curr.stream().filter(c -> rule.equals(c)).findAny();
if (f.isPresent() && rule.bytes() < f.get().bytes()) {
log.debug("DistributedFlowStatisticStore:updateFlowStatistic():" + " Invalid Flow Update! Will be removed!!" + " curr flowId=" + Long.toHexString(rule.id().value()) + ", prev flowId=" + Long.toHexString(f.get().id().value()) + ", curr bytes=" + rule.bytes() + ", prev bytes=" + f.get().bytes() + ", curr life=" + rule.life() + ", prev life=" + f.get().life() + ", curr lastSeen=" + rule.lastSeen() + ", prev lastSeen=" + f.get().lastSeen());
// something is wrong! invalid flow entry, so delete it
removeFlowStatistic(rule);
return;
}
Set<FlowEntry> prev = previous.get(cp);
if (prev == null) {
prev = new HashSet<>();
previous.put(cp, prev);
}
// previous one is exist
if (f.isPresent()) {
// remove old one and add new one
prev.remove(rule);
if (!prev.add(f.get())) {
log.debug("DistributedFlowStatisticStore:updateFlowStatistic():" + " flowId={}, add failed into previous.", Long.toHexString(rule.id().value()));
}
}
// remove old one and add new one
curr.remove(rule);
if (!curr.add(rule)) {
log.debug("DistributedFlowStatisticStore:updateFlowStatistic():" + " flowId={}, add failed into current.", Long.toHexString(rule.id().value()));
}
}
}
Aggregations