Search in sources :

Example 81 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class DevicesWebResource method getDevicePorts.

/**
 * Gets ports of infrastructure device.
 * Returns details of the specified infrastructure device.
 *
 * @onos.rsModel DeviceGetPorts
 * @param id device identifier
 * @return 200 OK with a collection of ports of the given device
 */
@GET
@Path("{id}/ports")
@Produces(MediaType.APPLICATION_JSON)
public Response getDevicePorts(@PathParam("id") String id) {
    DeviceService service = get(DeviceService.class);
    Device device = nullIsNotFound(service.getDevice(deviceId(id)), DEVICE_NOT_FOUND);
    List<Port> ports = checkNotNull(service.getPorts(deviceId(id)), "Ports could not be retrieved");
    ObjectNode result = codec(Device.class).encode(device, this);
    result.set("ports", codec(Port.class).encode(ports, this));
    return ok(result).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 82 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class FabricInterpreter method mapOutboundPacket.

@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) throws PiInterpreterException {
    DeviceId deviceId = packet.sendThrough();
    TrafficTreatment treatment = packet.treatment();
    // fabric.p4 supports only OUTPUT instructions.
    List<Instructions.OutputInstruction> outInstructions = treatment.allInstructions().stream().filter(i -> i.type().equals(OUTPUT)).map(i -> (Instructions.OutputInstruction) i).collect(toList());
    if (treatment.allInstructions().size() != outInstructions.size()) {
        // There are other instructions that are not of type OUTPUT.
        throw new PiInterpreterException("Treatment not supported: " + treatment);
    }
    ImmutableList.Builder<PiPacketOperation> builder = ImmutableList.builder();
    for (Instructions.OutputInstruction outInst : outInstructions) {
        if (outInst.port().equals(TABLE)) {
            // Logical port. Forward using the switch tables like a regular packet.
            builder.add(createPiPacketOperation(packet.data(), -1, true));
        } else if (outInst.port().equals(FLOOD)) {
            // Logical port. Create a packet operation for each switch port.
            final DeviceService deviceService = handler().get(DeviceService.class);
            for (Port port : deviceService.getPorts(packet.sendThrough())) {
                builder.add(createPiPacketOperation(packet.data(), port.number().toLong(), false));
            }
        } else if (outInst.port().isLogical()) {
            throw new PiInterpreterException(format("Output on logical port '%s' not supported", outInst.port()));
        } else {
            // Send as-is to given port bypassing all switch tables.
            builder.add(createPiPacketOperation(packet.data(), outInst.port().toLong(), false));
        }
    }
    return builder.build();
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) PACKET_OUT(org.onosproject.net.pi.model.PiPacketOperationType.PACKET_OUT) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) ImmutableList(com.google.common.collect.ImmutableList) DeserializationException(org.onlab.packet.DeserializationException) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ImmutableByteSequence.copyFrom(org.onlab.util.ImmutableByteSequence.copyFrom) Port(org.onosproject.net.Port) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FLOOD(org.onosproject.net.PortNumber.FLOOD) Instructions(org.onosproject.net.flow.instructions.Instructions) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Collection(java.util.Collection) Set(java.util.Set) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) FabricConstants(org.onosproject.pipelines.fabric.FabricConstants) String.format(java.lang.String.format) CONTROLLER(org.onosproject.net.PortNumber.CONTROLLER) PiAction(org.onosproject.net.pi.runtime.PiAction) TABLE(org.onosproject.net.PortNumber.TABLE) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) DriverHandler(org.onosproject.net.driver.DriverHandler) InboundPacket(org.onosproject.net.packet.InboundPacket) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) DeviceId(org.onosproject.net.DeviceId) ImmutableList(com.google.common.collect.ImmutableList) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) Instructions(org.onosproject.net.flow.instructions.Instructions) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation)

Example 83 with DeviceService

use of org.onosproject.net.device.DeviceService 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();
    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();
    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();
    }
    Map<Long, DefaultPortStatistics.Builder> portStatBuilders = Maps.newHashMap();
    deviceService.getPorts(deviceId).forEach(p -> portStatBuilders.put(p.number().toLong(), DefaultPortStatistics.builder().setPort(p.number()).setDeviceId(deviceId).setDurationSec(getDuration(p.number()))));
    Set<PiCounterCellId> counterCellIds = Sets.newHashSet();
    portStatBuilders.keySet().forEach(p -> {
        // Counter cell/index = port number.
        counterCellIds.add(PiCounterCellId.ofIndirect(ingressCounterId(), p));
        counterCellIds.add(PiCounterCellId.ofIndirect(egressCounterId(), 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);
    counterEntryResponse.forEach(counterCell -> {
        if (counterCell.cellId().counterType() != INDIRECT) {
            log.warn("Invalid counter data type {}, skipping", counterCell.cellId().counterType());
            return;
        }
        PiCounterCellId indCellId = counterCell.cellId();
        if (!portStatBuilders.containsKey(indCellId.index())) {
            log.warn("Unrecognized counter index {}, skipping", counterCell);
            return;
        }
        DefaultPortStatistics.Builder statsBuilder = portStatBuilders.get(indCellId.index());
        if (counterCell.cellId().counterId().equals(ingressCounterId())) {
            statsBuilder.setPacketsReceived(counterCell.data().packets());
            statsBuilder.setBytesReceived(counterCell.data().bytes());
        } else if (counterCell.cellId().counterId().equals(egressCounterId())) {
            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 : INGRESS_PORT_COUNTERS_INGRESS_INGRESS_PORT_COUNTER(org.onosproject.pipelines.basic.BasicConstants.INGRESS_PORT_COUNTERS_INGRESS_INGRESS_PORT_COUNTER) PiPipeconfService(org.onosproject.net.pi.service.PiPipeconfService) PortStatistics(org.onosproject.net.device.PortStatistics) PiCounterId(org.onosproject.net.pi.model.PiCounterId) PiPipeconf(org.onosproject.net.pi.model.PiPipeconf) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) PiCounterCellHandle(org.onosproject.net.pi.runtime.PiCounterCellHandle) Pair(org.apache.commons.lang3.tuple.Pair) P4RuntimeController(org.onosproject.p4runtime.api.P4RuntimeController) Map(java.util.Map) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatisticsDiscovery(org.onosproject.net.device.PortStatisticsDiscovery) PiCounterCellId(org.onosproject.net.pi.runtime.PiCounterCellId) Logger(org.slf4j.Logger) INDIRECT(org.onosproject.net.pi.model.PiCounterType.INDIRECT) P4RuntimeClient(org.onosproject.p4runtime.api.P4RuntimeClient) Collection(java.util.Collection) Set(java.util.Set) PiCounterCell(org.onosproject.net.pi.runtime.PiCounterCell) EGRESS_PORT_COUNTERS_EGRESS_EGRESS_PORT_COUNTER(org.onosproject.pipelines.basic.BasicConstants.EGRESS_PORT_COUNTERS_EGRESS_EGRESS_PORT_COUNTER) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) 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 84 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class TrafficMonitorBase method createTrafficLinks.

protected void createTrafficLinks(Highlights highlights, TrafficLinkMap linkMap, Set<Intent> intents, LinkHighlight.Flavor flavor, boolean showTraffic) {
    for (Intent intent : intents) {
        List<Intent> installables = services.intent().getInstallableIntents(intent.key());
        Iterable<Link> links = null;
        if (installables != null) {
            for (Intent installable : installables) {
                if (installable instanceof PathIntent) {
                    links = ((PathIntent) installable).path().links();
                } else if (installable instanceof FlowRuleIntent) {
                    Collection<Link> l = new ArrayList<>();
                    l.addAll(linkResources(installable));
                    // Add cross connect links
                    if (intent instanceof OpticalConnectivityIntent) {
                        OpticalConnectivityIntent ocIntent = (OpticalConnectivityIntent) intent;
                        LinkService linkService = services.link();
                        DeviceService deviceService = services.device();
                        l.addAll(linkService.getDeviceIngressLinks(ocIntent.getSrc().deviceId()).stream().filter(i -> deviceService.getDevice(i.src().deviceId()).type() == Device.Type.SWITCH).collect(Collectors.toList()));
                        l.addAll(linkService.getDeviceEgressLinks(ocIntent.getDst().deviceId()).stream().filter(e -> deviceService.getDevice(e.dst().deviceId()).type() == Device.Type.SWITCH).collect(Collectors.toList()));
                    }
                    links = l;
                } else if (installable instanceof FlowObjectiveIntent) {
                    links = linkResources(installable);
                } else if (installable instanceof LinkCollectionIntent) {
                    links = ((LinkCollectionIntent) installable).links();
                } else if (installable instanceof OpticalPathIntent) {
                    links = ((OpticalPathIntent) installable).path().links();
                }
                if (links == null) {
                    links = Lists.newArrayList();
                }
                links = addEdgeLinksIfNeeded(intent, Lists.newArrayList(links));
                boolean isOptical = intent instanceof OpticalConnectivityIntent;
                processLinks(linkMap, links, flavor, isOptical, showTraffic);
                updateHighlights(highlights, links);
            }
        }
    }
}
Also used : Mode(org.onosproject.ui.impl.TrafficMonitorBase.Mode) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) ElementId(org.onosproject.net.ElementId) Highlights(org.onosproject.ui.topo.Highlights) Timer(java.util.Timer) Link(org.onosproject.net.Link) DefaultEdgeLink(org.onosproject.net.DefaultEdgeLink) PACKETS(org.onosproject.net.statistic.PortStatisticsService.MetricType.PACKETS) ServicesBundle(org.onosproject.ui.impl.topo.util.ServicesBundle) TimerTask(java.util.TimerTask) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Device(org.onosproject.net.Device) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) TrafficLink(org.onosproject.ui.impl.topo.util.TrafficLink) OpticalPathIntent(org.onosproject.net.intent.OpticalPathIntent) LinkHighlight(org.onosproject.ui.topo.LinkHighlight) Collection(java.util.Collection) Set(java.util.Set) BYTES(org.onosproject.net.statistic.PortStatisticsService.MetricType.BYTES) IntentSelection(org.onosproject.ui.impl.topo.util.IntentSelection) Collectors(java.util.stream.Collectors) List(java.util.List) LinkService(org.onosproject.net.link.LinkService) DeviceId(org.onosproject.net.DeviceId) TopoologyTrafficMessageHandlerAbstract(org.onosproject.ui.impl.topo.TopoologyTrafficMessageHandlerAbstract) AbstractTopoMonitor(org.onosproject.ui.topo.AbstractTopoMonitor) DeviceHighlight(org.onosproject.ui.topo.DeviceHighlight) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Host(org.onosproject.net.Host) TrafficLinkMap(org.onosproject.ui.impl.topo.util.TrafficLinkMap) UiExtensionService(org.onosproject.ui.UiExtensionService) MetricType(org.onosproject.net.statistic.PortStatisticsService.MetricType) Load(org.onosproject.net.statistic.Load) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) UiTopoHighlighterFactory(org.onosproject.ui.UiTopoHighlighterFactory) HostHighlight(org.onosproject.ui.topo.HostHighlight) NodeHighlight(org.onosproject.ui.topo.NodeHighlight) Intent(org.onosproject.net.intent.Intent) UiTopoHighlighter(org.onosproject.ui.UiTopoHighlighter) HostId(org.onosproject.net.HostId) PathIntent(org.onosproject.net.intent.PathIntent) Logger(org.slf4j.Logger) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) DefaultEdgeLink.createEdgeLinks(org.onosproject.net.DefaultEdgeLink.createEdgeLinks) TopoIntentFilter(org.onosproject.ui.impl.topo.util.TopoIntentFilter) NodeSelection(org.onosproject.ui.topo.NodeSelection) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) Collections(java.util.Collections) TopoUtils(org.onosproject.ui.topo.TopoUtils) OpticalPathIntent(org.onosproject.net.intent.OpticalPathIntent) PathIntent(org.onosproject.net.intent.PathIntent) OpticalPathIntent(org.onosproject.net.intent.OpticalPathIntent) DeviceService(org.onosproject.net.device.DeviceService) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) OpticalPathIntent(org.onosproject.net.intent.OpticalPathIntent) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Collection(java.util.Collection) LinkService(org.onosproject.net.link.LinkService) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) Link(org.onosproject.net.Link) DefaultEdgeLink(org.onosproject.net.DefaultEdgeLink) TrafficLink(org.onosproject.ui.impl.topo.util.TrafficLink) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 85 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class StatisticsWebResource method getPortStatistics.

/**
 * Gets port statistics of all devices.
 * @onos.rsModel StatisticsPorts
 * @return 200 OK with JSON encoded array of port statistics
 */
@GET
@Path("ports")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortStatistics() {
    final DeviceService service = get(DeviceService.class);
    final Iterable<Device> devices = service.getDevices();
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    for (final Device device : devices) {
        final ObjectNode deviceStatsNode = mapper().createObjectNode();
        deviceStatsNode.put("device", device.id().toString());
        final ArrayNode statisticsNode = deviceStatsNode.putArray("ports");
        final Iterable<PortStatistics> portStatsEntries = service.getPortStatistics(device.id());
        if (portStatsEntries != null) {
            for (final PortStatistics entry : portStatsEntries) {
                statisticsNode.add(codec(PortStatistics.class).encode(entry, this));
            }
        }
        rootArrayNode.add(deviceStatsNode);
    }
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortStatistics(org.onosproject.net.device.PortStatistics) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

DeviceService (org.onosproject.net.device.DeviceService)187 Device (org.onosproject.net.Device)75 DeviceId (org.onosproject.net.DeviceId)73 Port (org.onosproject.net.Port)59 ConnectPoint (org.onosproject.net.ConnectPoint)42 PortNumber (org.onosproject.net.PortNumber)40 List (java.util.List)30 Collectors (java.util.stream.Collectors)24 Set (java.util.Set)23 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)19 Logger (org.slf4j.Logger)19 ArrayList (java.util.ArrayList)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Optional (java.util.Optional)17 Test (org.junit.Test)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Collections (java.util.Collections)15 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)15 DriverHandler (org.onosproject.net.driver.DriverHandler)15 Collection (java.util.Collection)14