use of org.onosproject.net.flow.FlowEntry in project fabric-tna by stratum.
the class FabricIntProgrammableTest method testSetupIntConfigWithQueueReportThreshold.
/**
* Test "setUpIntConfig" function of IntProgrammable with a config that contains
* queue report threshold config.
*/
@Test
public void testSetupIntConfigWithQueueReportThreshold() {
final IntReportConfig intConfig = getIntReportConfig(APP_ID, "/int-report-queue-report-threshold.json");
final List<FlowRule> expectRules = Lists.newArrayList();
final Capture<FlowRuleOperations> capturedOpsForCollector = newCapture();
final Capture<FlowRuleOperations> capturedOpsForSubnet = newCapture();
final Capture<FlowRuleOperations> capturedOpsForQueueThresholds = newCapture();
final Capture<FlowRule> capturedReportRules = newCapture(CaptureType.ALL);
final FlowRuleOperations expectedOpsForCollector = FlowRuleOperations.builder().add(buildCollectorWatchlistRule(LEAF_DEVICE_ID)).build();
// Queue threshold rules.
// Queue 0 has some old rules which must be removed before adding the new ones.
final List<FlowRule> queueThresholdRulesToRemove = queueReportFlows(LEAF_DEVICE_ID, 0, 0, (byte) 0);
final FlowRuleOperations.Builder opsBuilder = FlowRuleOperations.builder();
queueThresholdRulesToRemove.forEach(opsBuilder::remove);
opsBuilder.newStage();
// Add new entries for all queues.
for (byte queueId = 0; queueId < MAX_QUEUES; queueId++) {
// threshold config.
if (queueId == 0) {
queueReportFlows(LEAF_DEVICE_ID, 1888, 388, queueId).forEach(opsBuilder::add);
} else if (queueId == 7) {
// Queue 7 contains the "triggerNs" config only, the value of "resetNs"
// will be half of "triggerNs".
queueReportFlows(LEAF_DEVICE_ID, 500, 250, queueId).forEach(opsBuilder::add);
} else {
// The rest of the queues use the default queue latency threshold.
queueReportFlows(LEAF_DEVICE_ID, DEFAULT_QUEUE_REPORT_TRIGGER_LATENCY_THRESHOLD, DEFAULT_QUEUE_REPORT_RESET_LATENCY_THRESHOLD, queueId).forEach(opsBuilder::add);
}
}
final FlowRuleOperations expectedOpsForQueueThresholds = opsBuilder.build();
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_INT_INGRESS_DROP, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INVALID));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_FLOW, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_DEFLECTED, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INVALID));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_QUEUE, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, (short) (INT_REPORT_TYPE_QUEUE | INT_REPORT_TYPE_FLOW), MIRROR_TYPE_INT_REPORT));
expectRules.add(buildFilterConfigFlow(LEAF_DEVICE_ID));
List<Capture<FlowRule>> captures = Lists.newArrayList();
for (int i = 0; i < expectRules.size(); i++) {
Capture<FlowRule> flowRuleCapture = newCapture();
flowRuleService.applyFlowRules(capture(flowRuleCapture));
captures.add(flowRuleCapture);
}
// Expected steps of method calls, captures, and results.
reset(flowRuleService);
final List<FlowEntry> existingFlowEntries = queueThresholdRulesToRemove.stream().map(f -> buildFlowEntry(f)).collect(Collectors.toList());
expect(flowRuleService.getFlowEntriesById(APP_ID)).andReturn(existingFlowEntries).times(3);
flowRuleService.apply(capture(capturedOpsForCollector));
flowRuleService.apply(capture(capturedOpsForSubnet));
flowRuleService.apply(capture(capturedOpsForQueueThresholds));
flowRuleService.applyFlowRules(capture(capturedReportRules));
expectLastCall().times(expectRules.size());
replay(flowRuleService);
// Verify values.
assertTrue(intProgrammable.setUpIntConfig(intConfig));
assertFlowRuleOperationsEquals(expectedOpsForCollector, capturedOpsForCollector.getValue());
assertFlowRuleOperationsEquals(EMPTY_FLOW_RULE_OPS, capturedOpsForSubnet.getValue());
assertFlowRuleOperationsEquals(expectedOpsForQueueThresholds, capturedOpsForQueueThresholds.getValue());
for (int i = 0; i < expectRules.size(); i++) {
FlowRule expectRule = expectRules.get(i);
FlowRule actualRule = capturedReportRules.getValues().get(i);
assertTrue(expectRule.exactMatch(actualRule));
}
verify(flowRuleService);
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class VirtualNetworkFlowRuleManager method removeFlowRulesById.
@Override
public void removeFlowRulesById(ApplicationId id) {
Set<FlowRule> flowEntries = Sets.newHashSet();
for (Device d : deviceService.getDevices()) {
for (FlowEntry flowEntry : store.getFlowEntries(networkId(), d.id())) {
if (flowEntry.appId() == id.id()) {
flowEntries.add(flowEntry);
}
}
}
removeFlowRules(Iterables.toArray(flowEntries, FlowRule.class));
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class VirtualFlowsListCommand method printFlows.
/**
* Prints flows.
*
* @param d the device
* @param flows the set of flows for that device
* @param coreService core system service
*/
protected void printFlows(Device d, List<FlowEntry> flows, CoreService coreService) {
List<FlowEntry> filteredFlows = flows.stream().filter(f -> contentFilter.filter(f)).collect(Collectors.toList());
boolean empty = filteredFlows == null || filteredFlows.isEmpty();
print("deviceId=%s, flowRuleCount=%d", d.id(), empty ? 0 : filteredFlows.size());
if (empty || countOnly) {
return;
}
for (FlowEntry f : filteredFlows) {
if (shortOutput) {
print(SHORT_FORMAT, f.state(), f.bytes(), f.packets(), f.tableId(), f.priority(), f.selector().criteria(), printTreatment(f.treatment()));
} else {
ApplicationId appId = coreService.getAppId(f.appId());
print(LONG_FORMAT, Long.toHexString(f.id().value()), f.state(), f.bytes(), f.packets(), f.life(), f.liveType(), f.priority(), f.tableId(), appId != null ? appId.name() : "<none>", f.selector().criteria(), f.treatment());
}
}
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class DefaultVirtualFlowRuleProvider method virtualize.
private FlowEntry virtualize(FlowEntry flowEntry) {
FlowRule vRule = virtualizeFlowRule(flowEntry);
if (vRule == null) {
return null;
}
FlowEntry vEntry = new DefaultFlowEntry(vRule, flowEntry.state(), flowEntry.life(), flowEntry.packets(), flowEntry.bytes());
return vEntry;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class ECFlowRuleStoreTest method testAddFlow.
/**
* Tests adding a flowrule.
*/
@Test
public void testAddFlow() {
FlowEntry flowEntry = new DefaultFlowEntry(flowRule);
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());
flowStoreImpl.addOrUpdateFlowRule(flowEntry);
assertFlowsOnDevice(deviceId, 1);
FlowEntry flowEntry2 = flowStoreImpl.getFlowEntry(flowRule);
assertEquals("ADDED", flowEntry2.state().toString());
assertThat(flowStoreImpl.getTableStatistics(deviceId), notNullValue());
}
Aggregations