use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.
the class LumentumSdnRoadmFlowRuleProgrammable method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
try {
snmp = new LumentumSnmpDevice(handler().data().deviceId());
} catch (IOException e) {
log.error("Failed to connect to device: ", e);
return Collections.emptyList();
}
// Line in is last but one port, line out is last
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(data().deviceId());
if (ports.size() < 2) {
return Collections.emptyList();
}
PortNumber lineIn = ports.get(ports.size() - 2).number();
PortNumber lineOut = ports.get(ports.size() - 1).number();
Collection<FlowEntry> entries = Lists.newLinkedList();
// Add rules
OID addOid = new OID(CTRL_CHANNEL_STATE + "1");
entries.addAll(fetchRules(addOid, true, lineOut).stream().map(fr -> new DefaultFlowEntry(fr, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)).collect(Collectors.toList()));
// Drop rules
OID dropOid = new OID(CTRL_CHANNEL_STATE + "2");
entries.addAll(fetchRules(dropOid, false, lineIn).stream().map(fr -> new DefaultFlowEntry(fr, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)).collect(Collectors.toList()));
return entries;
}
use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.
the class FlowEntryBuilder method createFlowEntryForFlowMod.
private FlowEntry createFlowEntryForFlowMod(FlowEntryState... state) {
FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
FlowRule.Builder builder = DefaultFlowRule.builder().forDevice(deviceId).withSelector(buildSelector()).withTreatment(buildTreatment()).withPriority(flowMod.getPriority()).withIdleTimeout(flowMod.getIdleTimeout()).withCookie(flowMod.getCookie().getValue());
if (flowMod.getVersion() != OFVersion.OF_10) {
builder.forTable(flowMod.getTableId().getValue());
}
if (afsc != null) {
FlowEntry.FlowLiveType liveType = FlowEntry.FlowLiveType.IMMEDIATE;
return new DefaultFlowEntry(builder.build(), flowState, 0, liveType, 0, 0);
} else {
return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
}
}
use of org.onosproject.net.flow.DefaultFlowEntry 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.DefaultFlowEntry in project onos by opennetworkinglab.
the class AbstractTerminalDeviceFlowRuleProgrammable method getFlowEntries.
/**
* Get the flow entries that are present on the device.
*
* @return A collection of Flow Entries
*/
@Override
public Collection<FlowEntry> getFlowEntries() {
DeviceConnectionCache cache = getConnectionCache();
if (cache.get(did()) == null) {
return ImmutableList.of();
}
List<FlowEntry> entries = new ArrayList<>();
for (FlowRule r : cache.get(did())) {
entries.add(new DefaultFlowEntry(r, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
}
return entries;
}
use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.
the class GnmiTerminalDeviceFlowRuleProgrammable method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
// TODO: currently, we store flow rules in a cluster store. Should check if rule/config exists via gNMI.
if (!setupBehaviour("getFlowEntries")) {
return Collections.emptyList();
}
DeviceConnectionCache cache = getConnectionCache();
Set<FlowRule> cachedRules = cache.get(deviceId);
if (cachedRules == null) {
return ImmutableList.of();
}
return cachedRules.stream().filter(Objects::nonNull).map(r -> new DefaultFlowEntry(r, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)).collect(Collectors.toList());
}
Aggregations