Search in sources :

Example 11 with PiPipeconf

use of org.onosproject.net.pi.model.PiPipeconf in project onos by opennetworkinglab.

the class GeneralDeviceProvider method getPipeconfId.

private PiPipeconfId getPipeconfId(DeviceId deviceId, PiPipelineProgrammable pipelineProg) {
    // Places to look for a pipeconf ID (in priority order)):
    // 1) netcfg
    // 2) device driver (default one)
    final PiPipeconfId pipeconfId = getPipeconfFromCfg(deviceId);
    if (pipeconfId != null && !pipeconfId.id().isEmpty()) {
        return pipeconfId;
    }
    if (pipelineProg != null && pipelineProg.getDefaultPipeconf().isPresent()) {
        final PiPipeconf defaultPipeconf = pipelineProg.getDefaultPipeconf().get();
        log.info("Using default pipeconf {} for {}", defaultPipeconf.id(), deviceId);
        return defaultPipeconf.id();
    }
    return null;
}
Also used : PiPipeconf(org.onosproject.net.pi.model.PiPipeconf) PiPipeconfId(org.onosproject.net.pi.model.PiPipeconfId)

Example 12 with PiPipeconf

use of org.onosproject.net.pi.model.PiPipeconf in project onos by opennetworkinglab.

the class PortStatisticsDiscoveryImpl method discoverPortStatistics.

@Override
public Collection<PortStatistics> discoverPortStatistics() {
    DeviceService deviceService = this.handler().get(DeviceService.class);
    DeviceId deviceId = this.data().deviceId();
    // Get a client for this device.
    P4RuntimeController controller = handler().get(P4RuntimeController.class);
    P4RuntimeClient client = controller.get(deviceId);
    if (client == null) {
        log.warn("Unable to find client for {}, aborting operation", deviceId);
        return Collections.emptyList();
    }
    // Get the pipeconf of this device.
    PiPipeconfService piPipeconfService = handler().get(PiPipeconfService.class);
    if (!piPipeconfService.ofDevice(deviceId).isPresent() || !piPipeconfService.getPipeconf(piPipeconfService.ofDevice(deviceId).get()).isPresent()) {
        log.warn("Unable to get the pipeconf of {}, aborting operation", deviceId);
        return Collections.emptyList();
    }
    PiPipeconf pipeconf = piPipeconfService.getPipeconf(piPipeconfService.ofDevice(deviceId).get()).get();
    // Prepare PortStatistics objects to return, one per port of this device.
    Map<Long, DefaultPortStatistics.Builder> portStatBuilders = Maps.newHashMap();
    deviceService.getPorts(deviceId).forEach(p -> portStatBuilders.put(p.number().toLong(), DefaultPortStatistics.builder().setPort(p.number()).setDeviceId(deviceId)));
    // Generate the counter cell IDs.
    Set<PiCounterCellId> counterCellIds = Sets.newHashSet();
    portStatBuilders.keySet().forEach(p -> {
        // Counter cell/index = port number.
        counterCellIds.add(PiCounterCellId.ofIndirect(INGRESS_COUNTER_ID, p));
        counterCellIds.add(PiCounterCellId.ofIndirect(EGRESS_COUNTER_ID, p));
    });
    Set<PiCounterCellHandle> counterCellHandles = counterCellIds.stream().map(id -> PiCounterCellHandle.of(deviceId, id)).collect(Collectors.toSet());
    // Query the device.
    Collection<PiCounterCell> counterEntryResponse = client.read(DEFAULT_P4_DEVICE_ID, pipeconf).handles(counterCellHandles).submitSync().all(PiCounterCell.class);
    // Process response.
    counterEntryResponse.forEach(counterCell -> {
        if (counterCell.cellId().counterType() != INDIRECT) {
            log.warn("Invalid counter data type {}, skipping", counterCell.cellId().counterType());
            return;
        }
        if (!portStatBuilders.containsKey(counterCell.cellId().index())) {
            log.warn("Unrecognized counter index {}, skipping", counterCell);
            return;
        }
        DefaultPortStatistics.Builder statsBuilder = portStatBuilders.get(counterCell.cellId().index());
        if (counterCell.cellId().counterId().equals(INGRESS_COUNTER_ID)) {
            statsBuilder.setPacketsReceived(counterCell.data().packets());
            statsBuilder.setBytesReceived(counterCell.data().bytes());
        } else if (counterCell.cellId().counterId().equals(EGRESS_COUNTER_ID)) {
            statsBuilder.setPacketsSent(counterCell.data().packets());
            statsBuilder.setBytesSent(counterCell.data().bytes());
        } else {
            log.warn("Unrecognized counter ID {}, skipping", counterCell);
        }
    });
    return portStatBuilders.values().stream().map(DefaultPortStatistics.Builder::build).collect(Collectors.toList());
}
Also used : PiCounterCellId(org.onosproject.net.pi.runtime.PiCounterCellId) PiPipeconfService(org.onosproject.net.pi.service.PiPipeconfService) Logger(org.slf4j.Logger) INDIRECT(org.onosproject.net.pi.model.PiCounterType.INDIRECT) P4RuntimeClient(org.onosproject.p4runtime.api.P4RuntimeClient) PortStatistics(org.onosproject.net.device.PortStatistics) PiCounterId(org.onosproject.net.pi.model.PiCounterId) PiPipeconf(org.onosproject.net.pi.model.PiPipeconf) Collection(java.util.Collection) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) PiCounterCell(org.onosproject.net.pi.runtime.PiCounterCell) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) PiCounterCellHandle(org.onosproject.net.pi.runtime.PiCounterCellHandle) P4RuntimeController(org.onosproject.p4runtime.api.P4RuntimeController) Map(java.util.Map) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) PortStatisticsDiscovery(org.onosproject.net.device.PortStatisticsDiscovery) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PiCounterCellId(org.onosproject.net.pi.runtime.PiCounterCellId) PiCounterCellHandle(org.onosproject.net.pi.runtime.PiCounterCellHandle) DeviceId(org.onosproject.net.DeviceId) PiPipeconf(org.onosproject.net.pi.model.PiPipeconf) DeviceService(org.onosproject.net.device.DeviceService) PiPipeconfService(org.onosproject.net.pi.service.PiPipeconfService) P4RuntimeClient(org.onosproject.p4runtime.api.P4RuntimeClient) P4RuntimeController(org.onosproject.p4runtime.api.P4RuntimeController) PiCounterCell(org.onosproject.net.pi.runtime.PiCounterCell)

Example 13 with PiPipeconf

use of org.onosproject.net.pi.model.PiPipeconf in project fabric-tna by stratum.

the class FabricInterpreterTest method setup.

@Before
public void setup() {
    DriverData data = createNiceMock(DriverData.class);
    expect(data.deviceId()).andReturn(DEVICE_ID).anyTimes();
    replay(data);
    PiPipeconf piPipeconf = createNiceMock(PiPipeconf.class);
    PiPipeconfService piPipeconfService = createNiceMock(PiPipeconfService.class);
    expect(piPipeconfService.getPipeconf(DEVICE_ID)).andReturn(Optional.of(piPipeconf));
    replay(piPipeconfService);
    SlicingService slicingService = createNiceMock(SlicingService.class);
    expect(slicingService.getSystemTrafficClass()).andReturn(TrafficClassDescription.BEST_EFFORT);
    replay(slicingService);
    DriverHandler handler = createNiceMock(DriverHandler.class);
    deviceService = createNiceMock(DeviceService.class);
    expect(handler.get(DeviceService.class)).andReturn(deviceService).anyTimes();
    expect(handler.data()).andReturn(data).anyTimes();
    expect(handler.get(PiPipeconfService.class)).andReturn(piPipeconfService).anyTimes();
    expect(handler.get(SlicingService.class)).andReturn(slicingService).once();
    replay(handler);
    interpreter = new FabricInterpreter();
    interpreter.setHandler(handler);
}
Also used : DriverData(org.onosproject.net.driver.DriverData) PiPipeconf(org.onosproject.net.pi.model.PiPipeconf) DriverHandler(org.onosproject.net.driver.DriverHandler) DeviceService(org.onosproject.net.device.DeviceService) PiPipeconfService(org.onosproject.net.pi.service.PiPipeconfService) SlicingService(org.stratumproject.fabric.tna.slicing.api.SlicingService) Before(org.junit.Before)

Aggregations

PiPipeconf (org.onosproject.net.pi.model.PiPipeconf)13 Sets (com.google.common.collect.Sets)4 Set (java.util.Set)4 PiPipeconfService (org.onosproject.net.pi.service.PiPipeconfService)4 Logger (org.slf4j.Logger)4 Maps (com.google.common.collect.Maps)3 Collection (java.util.Collection)3 Map (java.util.Map)3 DeviceService (org.onosproject.net.device.DeviceService)3 PortStatisticsDiscovery (org.onosproject.net.device.PortStatisticsDiscovery)3 String.format (java.lang.String.format)2 Collections (java.util.Collections)2 Collectors (java.util.stream.Collectors)2 Device (org.onosproject.net.Device)2 DeviceId (org.onosproject.net.DeviceId)2 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)2 PortStatistics (org.onosproject.net.device.PortStatistics)2 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)2 PiUtils.getInterpreterOrNull (org.onosproject.net.pi.impl.PiUtils.getInterpreterOrNull)2 PiPipeconfId (org.onosproject.net.pi.model.PiPipeconfId)2