use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowsResourceTest method testFlowsSingleDevice.
/**
* Tests the result of a rest api GET for a device.
*/
@Test
public void testFlowsSingleDevice() {
setupMockFlows();
final Set<FlowEntry> flows = new HashSet<>();
flows.add(flow5);
flows.add(flow6);
expect(mockFlowService.getFlowEntries(anyObject())).andReturn(flows).anyTimes();
replay(mockFlowService);
replay(mockDeviceService);
final WebTarget wt = target();
final String response = wt.path("flows/" + deviceId3).request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
assertThat(result.names().get(0), is("flows"));
final JsonArray jsonFlows = result.get("flows").asArray();
assertThat(jsonFlows, notNullValue());
assertThat(jsonFlows, hasFlow(flow5));
assertThat(jsonFlows, hasFlow(flow6));
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class IntentsResourceTest method testRelatedFlowsForIntents.
/**
* Tests the result of a rest api GET for related flows for single intent.
*/
@Test
public void testRelatedFlowsForIntents() {
List<FlowEntry> flowEntries = new ArrayList<>();
flowEntries.add(flow1);
flowEntries.add(flow2);
List<List<FlowEntry>> paths = new ArrayList<>();
paths.add(flowEntries);
List<FlowRule> flowRules = new ArrayList<>();
flowRules.add(flowRule1);
flowRules.add(flowRule2);
FlowRuleIntent flowRuleIntent = new FlowRuleIntent(APP_ID, null, flowRules, new HashSet<NetworkResource>(), PathIntent.ProtectionType.PRIMARY, null);
Intent intent = new MockIntent(3L);
installableIntents.add(flowRuleIntent);
intents.add(intent);
expect(mockIntentService.getIntent(Key.of(0, APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of("0", APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of(0, APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of("0x0", APP_ID))).andReturn(null).anyTimes();
expect(mockIntentService.getInstallableIntents(intent.key())).andReturn(installableIntents).anyTimes();
replay(mockIntentService);
expect(mockFlowService.getFlowEntries(deviceId1)).andReturn(flowEntries).anyTimes();
replay(mockFlowService);
expect(mockCoreService.getAppId(APP_ID.name())).andReturn(APP_ID).anyTimes();
expect(mockCoreService.getAppId(APP_ID.id())).andReturn(APP_ID).anyTimes();
replay(mockCoreService);
final WebTarget wt = target();
// Test get using key string
final String response = wt.path("intents/relatedflows/" + APP_ID.name() + "/0").request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, matchesRelatedFlowEntries(paths, APP_ID.name()));
// Test get using numeric value
final String responseNumeric = wt.path("intents/relatedflows/" + APP_ID.name() + "/0x0").request().get(String.class);
final JsonObject resultNumeric = Json.parse(responseNumeric).asObject();
assertThat(resultNumeric, matchesRelatedFlowEntries(paths, APP_ID.name()));
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class PolatisInternalConnectivity method filterUsedPorts.
private Set<PortNumber> filterUsedPorts(Set<PortNumber> ports, Collection<FlowEntry> flowEntries) {
if (ports.isEmpty() || flowEntries.isEmpty()) {
return ports;
}
for (FlowEntry flowEntry : flowEntries) {
PortNumber inputPort = ((PortCriterion) flowEntry.selector().getCriterion(Criterion.Type.IN_PORT)).port();
ports.remove(inputPort);
PortNumber outputPort = ((OutputInstruction) flowEntry.treatment().allInstructions().get(0)).port();
ports.remove(outputPort);
log.debug("Cross-connection {}-{} removed from output port list", inputPort, outputPort);
}
log.debug("Ports after filtering out used ones: " + ports);
return ports;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class P4RuntimeFlowRuleProgrammable method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
if (!setupBehaviour("getFlowEntries()")) {
return Collections.emptyList();
}
if (driverBoolProperty(READ_FROM_MIRROR, DEFAULT_READ_FROM_MIRROR)) {
return getFlowEntriesFromMirror();
}
final ImmutableList.Builder<FlowEntry> result = ImmutableList.builder();
final List<PiTableEntry> inconsistentEntries = Lists.newArrayList();
// Read table entries from device.
final Collection<PiTableEntry> deviceEntries = getAllTableEntriesFromDevice();
if (deviceEntries == null) {
// Potential error at the client level.
return Collections.emptyList();
}
// Synchronize mirror with the device state.
tableMirror.sync(deviceId, deviceEntries);
if (deviceEntries.isEmpty()) {
// Nothing to do.
return Collections.emptyList();
}
final Map<PiTableEntryHandle, PiCounterCellData> counterCellMap = readEntryCounters(deviceEntries);
// Forge flow entries with counter values.
for (PiTableEntry entry : deviceEntries) {
final PiTableEntryHandle handle = entry.handle(deviceId);
final FlowEntry flowEntry = forgeFlowEntry(entry, handle, counterCellMap.get(handle));
if (flowEntry == null) {
// program via default_action, which cannot be removed.)
if (!isOriginalDefaultEntry(entry)) {
inconsistentEntries.add(entry);
}
} else {
result.add(flowEntry);
}
}
// Default entries need to be treated in a different way according to the spec:
// the client can modify (reset or update) them but cannot remove the entries
List<PiTableEntry> inconsistentDefaultEntries = Lists.newArrayList();
List<PiTableEntry> tempDefaultEntries = inconsistentEntries.stream().filter(PiTableEntry::isDefaultAction).collect(Collectors.toList());
inconsistentEntries.removeAll(tempDefaultEntries);
// Once we have removed the default entry from inconsistentEntries we need to
// craft for each default entry a copy without the action field. According to
// the spec leaving the action field unset will reset the original default entry.
tempDefaultEntries.forEach(piTableEntry -> {
PiTableEntry resetEntry = PiTableEntry.builder().forTable(piTableEntry.table()).build();
inconsistentDefaultEntries.add(resetEntry);
});
// Clean up of inconsistent entries.
if (!inconsistentEntries.isEmpty() || !inconsistentDefaultEntries.isEmpty()) {
WriteRequest writeRequest = client.write(p4DeviceId, pipeconf);
// Trigger remove of inconsistent entries.
if (!inconsistentEntries.isEmpty()) {
log.warn("Found {} inconsistent table entries on {}, removing them...", inconsistentEntries.size(), deviceId);
writeRequest = writeRequest.entities(inconsistentEntries, DELETE);
}
// Trigger reset of inconsistent default entries.
if (!inconsistentDefaultEntries.isEmpty()) {
log.warn("Found {} inconsistent default table entries on {}, resetting them...", inconsistentDefaultEntries.size(), deviceId);
writeRequest = writeRequest.entities(inconsistentDefaultEntries, MODIFY);
}
// Submit delete request for non-default entries and modify request
// for default entries. Updates mirror when done.
writeRequest.submit().whenComplete((response, ex) -> {
if (ex != null) {
log.error("Exception removing inconsistent table entries", ex);
} else {
log.debug("Successfully removed {} out of {} inconsistent entries", response.success().size(), response.all().size());
}
// We can use the entity as the handle does not contain the action field
// so the key will be removed even if the table entry is different
response.success().forEach(entity -> tableMirror.remove((PiTableEntryHandle) entity.handle()));
});
}
return result.build();
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class P4RuntimeTableStatisticsDiscovery method getTableStatistics.
@Override
public List<TableStatisticsEntry> getTableStatistics() {
if (!setupBehaviour("getTableStatistics()")) {
return Collections.emptyList();
}
FlowRuleService flowService = handler().get(FlowRuleService.class);
PiPipelineInterpreter interpreter = getInterpreter(handler());
PiPipelineModel model = pipeconf.pipelineModel();
List<TableStatisticsEntry> tableStatsList;
List<FlowEntry> rules = newArrayList(flowService.getFlowEntries(deviceId));
Map<PiTableId, Integer> piTableFlowCount = piFlowRuleCounting(model, interpreter, rules);
Map<PiTableId, Long> piTableMatchCount = piMatchedCounting(model, interpreter, rules);
tableStatsList = generatePiFlowTableStatistics(piTableFlowCount, piTableMatchCount, model, deviceId);
return tableStatsList;
}
Aggregations