use of org.onosproject.net.flow.StoredFlowEntry in project onos by opennetworkinglab.
the class FlowBucket method remove.
/**
* Removes the given flow rule from the bucket.
*
* @param rule the rule to remove
* @param term the term in which the change occurred
* @param clock the logical clock
* @return the removed flow entry
*/
public FlowEntry remove(FlowEntry rule, long term, LogicalClock clock) {
final AtomicReference<FlowEntry> removedRule = new AtomicReference<>();
flowBucket.computeIfPresent(rule.id(), (flowId, flowEntries) -> {
flowEntries.computeIfPresent((StoredFlowEntry) rule, (k, stored) -> {
if (rule instanceof DefaultFlowEntry) {
DefaultFlowEntry toRemove = (DefaultFlowEntry) rule;
if (stored instanceof DefaultFlowEntry) {
DefaultFlowEntry storedEntry = (DefaultFlowEntry) stored;
if (toRemove.created() < storedEntry.created()) {
LOGGER.debug("Trying to remove more recent flow entry {} (stored: {})", toRemove, stored);
// the key is not updated, removedRule remains null
return stored;
}
}
}
removedRule.set(stored);
return null;
});
return flowEntries.isEmpty() ? null : flowEntries;
});
if (removedRule.get() != null) {
recordUpdate(term, clock.getTimestamp());
return removedRule.get();
} else {
return null;
}
}
use of org.onosproject.net.flow.StoredFlowEntry in project onos by opennetworkinglab.
the class FlowRuleManagerTest method flowRemoved.
@Test
public void flowRemoved() {
FlowRule f1 = addFlowRule(1);
FlowRule f2 = addFlowRule(2);
StoredFlowEntry fe1 = new DefaultFlowEntry(f1);
FlowEntry fe2 = new DefaultFlowEntry(f2);
providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2));
service.removeFlowRules(f1);
// FIXME modification of "stored" flow entry outside of store
fe1.setState(FlowEntryState.REMOVED);
providerService.flowRemoved(fe1);
validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_REMOVE_REQUESTED, RULE_REMOVED);
providerService.flowRemoved(fe1);
validateEvents();
FlowRule f3 = flowRule(3, 3);
FlowEntry fe3 = new DefaultFlowEntry(f3);
service.applyFlowRules(f3);
providerService.pushFlowMetrics(DID, Collections.singletonList(fe3));
validateEvents(RULE_ADD_REQUESTED, RULE_ADDED, RULE_UPDATED);
providerService.flowRemoved(fe3);
validateEvents();
}
use of org.onosproject.net.flow.StoredFlowEntry in project onos by opennetworkinglab.
the class FlowEntryWithLoadTest method testConstructionDEfaultLoad.
@Test
public void testConstructionDEfaultLoad() {
ConnectPoint cp = NetTestTools.connectPoint("id1", 1);
StoredFlowEntry fe = new MockFlowEntry(FlowEntry.FlowLiveType.IMMEDIATE);
FlowEntryWithLoad underTest;
fe = new MockFlowEntry(FlowEntry.FlowLiveType.IMMEDIATE);
underTest = new FlowEntryWithLoad(cp, fe);
assertThat(underTest.connectPoint(), is(cp));
assertThat(underTest.load(), instanceOf(DefaultLoad.class));
assertThat(underTest.storedFlowEntry(), is(fe));
fe = new MockFlowEntry(FlowEntry.FlowLiveType.LONG);
underTest = new FlowEntryWithLoad(cp, fe);
assertThat(underTest.connectPoint(), is(cp));
assertThat(underTest.load(), instanceOf(DefaultLoad.class));
fe = new MockFlowEntry(FlowEntry.FlowLiveType.MID);
underTest = new FlowEntryWithLoad(cp, fe);
assertThat(underTest.connectPoint(), is(cp));
assertThat(underTest.load(), instanceOf(DefaultLoad.class));
fe = new MockFlowEntry(FlowEntry.FlowLiveType.SHORT);
underTest = new FlowEntryWithLoad(cp, fe);
assertThat(underTest.connectPoint(), is(cp));
assertThat(underTest.load(), instanceOf(DefaultLoad.class));
fe = new MockFlowEntry(FlowEntry.FlowLiveType.UNKNOWN);
underTest = new FlowEntryWithLoad(cp, fe);
assertThat(underTest.connectPoint(), is(cp));
assertThat(underTest.load(), instanceOf(DefaultLoad.class));
}
use of org.onosproject.net.flow.StoredFlowEntry in project onos by opennetworkinglab.
the class VirtualNetworkFlowRuleManagerTest method flowRemoved.
@Test
public void flowRemoved() {
FlowRule f1 = addFlowRule(1);
FlowRule f2 = addFlowRule(2);
StoredFlowEntry fe1 = new DefaultFlowEntry(f1);
FlowEntry fe2 = new DefaultFlowEntry(f2);
providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1, fe2));
vnetFlowRuleService1.removeFlowRules(f1);
// FIXME modification of "stored" flow entry outside of store
fe1.setState(FlowEntry.FlowEntryState.REMOVED);
providerService1.flowRemoved(fe1);
validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_REMOVE_REQUESTED, RULE_REMOVED);
providerService1.flowRemoved(fe1);
validateEvents(listener1);
FlowRule f3 = flowRule(3, 3);
FlowEntry fe3 = new DefaultFlowEntry(f3);
vnetFlowRuleService1.applyFlowRules(f3);
providerService1.pushFlowMetrics(VDID1, Collections.singletonList(fe3));
validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADDED, RULE_UPDATED);
providerService1.flowRemoved(fe3);
validateEvents(listener1);
}
use of org.onosproject.net.flow.StoredFlowEntry in project onos by opennetworkinglab.
the class DistributedVirtualFlowRuleStore method addOrUpdateFlowRuleInternal.
private FlowRuleEvent addOrUpdateFlowRuleInternal(NetworkId networkId, FlowEntry rule) {
// check if this new rule is an update to an existing entry
StoredFlowEntry stored = flowTable.getFlowEntry(networkId, rule);
if (stored != null) {
// FIXME modification of "stored" flow entry outside of flow table
stored.setBytes(rule.bytes());
stored.setLife(rule.life(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
stored.setLiveType(rule.liveType());
stored.setPackets(rule.packets());
stored.setLastSeen();
if (stored.state() == FlowEntry.FlowEntryState.PENDING_ADD) {
stored.setState(FlowEntry.FlowEntryState.ADDED);
return new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADDED, rule);
}
return new FlowRuleEvent(FlowRuleEvent.Type.RULE_UPDATED, rule);
}
// TODO: Confirm if this behavior is correct. See SimpleFlowRuleStore
// TODO: also update backup if the behavior is correct.
flowTable.add(networkId, rule);
return null;
}
Aggregations