use of org.onosproject.net.flow.FlowRuleEvent in project onos by opennetworkinglab.
the class SimpleFlowRuleStore method addOrUpdateFlowRule.
@Override
public FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule) {
// check if this new rule is an update to an existing entry
List<StoredFlowEntry> entries = getFlowEntries(rule.deviceId(), rule.id());
synchronized (entries) {
for (StoredFlowEntry stored : entries) {
if (stored.equals(rule)) {
synchronized (stored) {
// FIXME modification of "stored" flow entry outside of flow table
stored.setBytes(rule.bytes());
stored.setLife(rule.life());
stored.setPackets(rule.packets());
if (stored.state() == FlowEntryState.PENDING_ADD) {
stored.setState(FlowEntryState.ADDED);
// TODO: Do we need to change `rule` state?
return new FlowRuleEvent(Type.RULE_ADDED, rule);
}
return new FlowRuleEvent(Type.RULE_UPDATED, rule);
}
}
}
}
// should not reach here
// storeFlowRule was expected to be called
log.error("FlowRule was not found in store {} to update", rule);
// flowEntries.put(did, rule);
return null;
}
use of org.onosproject.net.flow.FlowRuleEvent in project onos by opennetworkinglab.
the class FlowRuleManagerTest method validateEvents.
private void validateEvents(FlowRuleEvent.Type... events) {
if (events == null) {
assertTrue("events generated", listener.events.isEmpty());
}
int i = 0;
System.err.println("events :" + listener.events);
for (FlowRuleEvent e : listener.events) {
assertEquals("unexpected event", events[i], e.type());
i++;
}
assertEquals("mispredicted number of events", events.length, listener.events.size());
listener.events.clear();
}
use of org.onosproject.net.flow.FlowRuleEvent in project onos by opennetworkinglab.
the class DistributedVirtualFlowRuleStore method removeFlowRuleInternal.
private FlowRuleEvent removeFlowRuleInternal(VirtualFlowEntry rule) {
final DeviceId deviceId = rule.flowEntry().deviceId();
// This is where one could mark a rule as removed and still keep it in the store.
final FlowEntry removed = flowTable.remove(rule.networkId(), deviceId, rule.flowEntry());
// rule may be partial rule that is missing treatment, we should use rule from store instead
return removed != null ? new FlowRuleEvent(RULE_REMOVED, removed) : null;
}
use of org.onosproject.net.flow.FlowRuleEvent 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;
}
use of org.onosproject.net.flow.FlowRuleEvent in project onos by opennetworkinglab.
the class SimpleVirtualFlowRuleStore method removeFlowRule.
@Override
public FlowRuleEvent removeFlowRule(NetworkId networkId, FlowEntry rule) {
// This is where one could mark a rule as removed and still keep it in the store.
final DeviceId did = rule.deviceId();
List<StoredFlowEntry> entries = getFlowEntries(networkId, did, rule.id());
synchronized (entries) {
if (entries.remove(rule)) {
return new FlowRuleEvent(RULE_REMOVED, rule);
}
}
return null;
}
Aggregations