use of org.onosproject.net.flow.FlowRuleService 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;
}
use of org.onosproject.net.flow.FlowRuleService in project fabric-tna by stratum.
the class FabricIntProgrammableTest method setup.
@Before
public void setup() {
FabricCapabilities capabilities = createMock(FabricCapabilities.class);
expect(capabilities.isArchTna()).andReturn(!this.isArchV1model).anyTimes();
expect(capabilities.isArchV1model()).andReturn(this.isArchV1model).anyTimes();
expect(capabilities.hasHashedTable()).andReturn(true).anyTimes();
expect(capabilities.supportDoubleVlanTerm()).andReturn(false).anyTimes();
expect(capabilities.hwPipeCount()).andReturn(4).anyTimes();
replay(capabilities);
// Services mock
flowRuleService = createMock(FlowRuleService.class);
groupService = createMock(GroupService.class);
netcfgService = createMock(NetworkConfigService.class);
coreService = createMock(CoreService.class);
hostService = createMock(HostService.class);
expect(coreService.getAppId(anyString())).andReturn(APP_ID).anyTimes();
expect(netcfgService.getConfig(LEAF_DEVICE_ID, SegmentRoutingDeviceConfig.class)).andReturn(getSrConfig(LEAF_DEVICE_ID, "/sr.json")).anyTimes();
expect(netcfgService.getConfig(SPINE_DEVICE_ID, SegmentRoutingDeviceConfig.class)).andReturn(getSrConfig(SPINE_DEVICE_ID, "/sr-spine.json")).anyTimes();
expect(hostService.getHostsByIp(COLLECTOR_IP)).andReturn(ImmutableSet.of(COLLECTOR_HOST)).anyTimes();
replay(coreService, netcfgService, hostService);
DriverHandler driverHandler = createMock(DriverHandler.class);
expect(driverHandler.get(FlowRuleService.class)).andReturn(flowRuleService).anyTimes();
expect(driverHandler.get(GroupService.class)).andReturn(groupService).anyTimes();
expect(driverHandler.get(NetworkConfigService.class)).andReturn(netcfgService).anyTimes();
expect(driverHandler.get(CoreService.class)).andReturn(coreService).anyTimes();
expect(driverHandler.get(HostService.class)).andReturn(hostService).anyTimes();
replay(driverHandler);
driverData = createMock(DriverData.class);
expect(driverData.deviceId()).andReturn(LEAF_DEVICE_ID).anyTimes();
replay(driverData);
intProgrammable = partialMockBuilder(FabricIntProgrammable.class).addMockedMethod("getFieldSize").createMock();
expect(intProgrammable.getFieldSize(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_QUEUE_LATENCY_THRESHOLDS, P4InfoConstants.HDR_HOP_LATENCY_UPPER)).andReturn(16).anyTimes();
expect(intProgrammable.getFieldSize(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_QUEUE_LATENCY_THRESHOLDS, P4InfoConstants.HDR_HOP_LATENCY_LOWER)).andReturn(16).anyTimes();
replay(intProgrammable);
TestUtils.setField(intProgrammable, "capabilities", capabilities);
TestUtils.setField(intProgrammable, "handler", driverHandler);
TestUtils.setField(intProgrammable, "data", driverData);
TestUtils.setField(intProgrammable, "log", getLogger(""));
testInit();
}
use of org.onosproject.net.flow.FlowRuleService 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.FlowRuleService in project fabric-tna by stratum.
the class FabricPipelinerTest method setup.
@Before
public void setup() {
// Common setup between TNA and bmv2
FabricCapabilities capabilities = createMock(FabricCapabilities.class);
expect(capabilities.cpuPort()).andReturn(Optional.of(PORT_CPU)).anyTimes();
expect(capabilities.isArchV1model()).andReturn(this.isArchV1model).anyTimes();
expect(capabilities.isArchTna()).andReturn(!this.isArchV1model).anyTimes();
replay(capabilities);
// Services mock
flowRuleService = createMock(FlowRuleService.class);
groupService = createMock(GroupService.class);
pipeliner = new FabricPipeliner(capabilities);
pipeliner.flowRuleService = flowRuleService;
pipeliner.groupService = groupService;
pipeliner.appId = APP_ID;
pipeliner.deviceId = DEVICE_ID;
}
use of org.onosproject.net.flow.FlowRuleService in project fabric-tna by stratum.
the class FabricUpfProgrammable method setupBehaviour.
@Override
protected boolean setupBehaviour(String opName) {
/* Always setup internally the behavior to refresh
the internal references: client, controller, etc*/
if (!super.setupBehaviour(opName)) {
return false;
}
// Already initialized.
if (appId != null) {
return true;
}
if (!computeHardwareResourceSizes()) {
// error message will be printed by computeHardwareResourceSizes()
return false;
}
flowRuleService = handler().get(FlowRuleService.class);
meterService = handler().get(MeterService.class);
packetService = handler().get(PacketService.class);
slicingService = handler().get(SlicingService.class);
upfTranslator = new FabricUpfTranslator();
final CoreService coreService = handler().get(CoreService.class);
appId = coreService.getAppId(Constants.APP_NAME_UPF);
if (appId == null) {
log.warn("Application ID is null. Cannot initialize behaviour.");
return false;
}
var capabilities = new FabricCapabilities(pipeconf);
if (!capabilities.supportUpf()) {
log.warn("Pipeconf {} on {} does not support UPF capabilities, " + "cannot perform {}", pipeconf.id(), deviceId, opName);
return false;
}
return true;
}
Aggregations