Search in sources :

Example 91 with DeviceService

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

the class PolatisLinkDiscovery method checkPeer.

private boolean checkPeer(ConnectPoint nearEndCP, ConnectPoint peerCP, DriverHandler handler, boolean direct) {
    // check peerCP exists and is available (either via device service or direct from device)
    DeviceId peerDeviceID = peerCP.deviceId();
    boolean result = false;
    DeviceService deviceService = checkNotNull(handler.get(DeviceService.class));
    if (deviceService.isAvailable(peerDeviceID)) {
        log.trace("Peer device {} exists", peerDeviceID.toString());
        Device device = deviceService.getDevice(peerDeviceID);
        int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
        int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
        List<Port> ports = deviceService.getPorts(peerDeviceID);
        PortNumber farEndPortNum = peerCP.port();
        Port port = deviceService.getPort(peerCP);
        if (port != null) {
            if (port.isEnabled()) {
                log.trace("Peer port {} exists", port.number().toLong());
                // check far end peer-port entry (use device service or retrieve direct from switch)
                Port peerPort = deviceService.getPort(peerDeviceID, farEndPortNum);
                String farEndPortPeerportData = peerPort.annotations().value(KEY_PORTPEER);
                if (direct) {
                    log.trace("Checking device {} DIRECT", handler.data().deviceId());
                    // A bit of a cludge it seems but temporarily open a new NETCONF session to far-end device
                    NetconfController controller = checkNotNull(handler.get(NetconfController.class));
                    NetconfSession farEndDeviceSession = controller.getDevicesMap().get(peerDeviceID).getSession();
                    String reply = netconfGet(farEndDeviceSession, getPortFilter(farEndPortNum));
                    PortDescription peerPortDescDirect = parsePorts(reply, numInputPorts, numOutputPorts).get(0);
                    log.trace("peerPortDesc from device: " + peerPortDescDirect.toString());
                    String farEndPortPeerportDataDirect = peerPortDescDirect.annotations().value(KEY_PORTPEER);
                    farEndPortPeerportData = farEndPortPeerportDataDirect;
                }
                if (!farEndPortPeerportData.equals("")) {
                    if (farEndPortPeerportData.charAt(0) == '{') {
                        log.trace("Far-end peer-port value:" + farEndPortPeerportData);
                        ObjectMapper mapper = new ObjectMapper();
                        ConnectPoint checkNearEndCP = null;
                        try {
                            checkNearEndCP = parsePeerportDataForCP(mapper.readTree(farEndPortPeerportData));
                        } catch (JsonProcessingException jpe) {
                            log.trace("Error processing peer-port JSON: {}", jpe.toString());
                        }
                        if (nearEndCP.equals(checkNearEndCP)) {
                            log.trace("Reciprocal peer port entries match: nearEnd={}, farEnd={}", nearEndCP, checkNearEndCP);
                            result = true;
                        } else {
                            log.trace("Peer-port entry for far-end port ({}) does not match near-end " + "port number ({})", checkNearEndCP, nearEndCP);
                        }
                    }
                } else {
                    log.trace("Null peer-port entry for far-end port ({})", peerCP);
                }
            } else {
                log.trace("Peer port {} is DISABLED", port);
            }
        } else {
            log.trace("Peer port {} does not exist", port);
        }
    } else {
        log.trace("Far end device does not exist or is not available");
    }
    return result;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) PortDescription(org.onosproject.net.device.PortDescription) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfController(org.onosproject.netconf.NetconfController) PortNumber(org.onosproject.net.PortNumber) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 92 with DeviceService

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

the class ZtePortStatisticsDiscovery method discoverPortStatistics.

@Override
public Collection<PortStatistics> discoverPortStatistics() {
    DeviceId deviceId = handler().data().deviceId();
    LOG.debug("Discovering ZTE PortStatistics for device {}", deviceId);
    NetconfController controller = handler().get(NetconfController.class);
    if (null == controller) {
        LOG.error("Cannot find NetconfController");
        return null;
    }
    NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
    if (null == session) {
        LOG.error("No session available for device {}", deviceId);
        return null;
    }
    DeviceService deviceService = this.handler().get(DeviceService.class);
    List<Port> ports = deviceService.getPorts(deviceId);
    Collection<PortStatistics> portStatistics = Lists.newArrayList();
    ports.stream().filter(Port::isEnabled).filter(this::isClientPort).forEach(port -> portStatistics.add(discoverSpecifiedPortStatistics(session, deviceId, port)));
    return portStatistics;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) NetconfController(org.onosproject.netconf.NetconfController) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics)

Example 93 with DeviceService

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

the class LinkDiscovery method processLldp.

private boolean processLldp(PacketContext packetContext, Ethernet eth) {
    ONOSLLDP onoslldp = ONOSLLDP.parseLLDP(eth);
    if (onoslldp != null) {
        Type lt = eth.getEtherType() == Ethernet.TYPE_LLDP ? Type.DIRECT : Type.INDIRECT;
        DeviceService deviceService = context.deviceService();
        MacAddress srcChassisId = onoslldp.getChassisIdByMac();
        String srcPortName = onoslldp.getPortNameString();
        String srcPortDesc = onoslldp.getPortDescString();
        log.debug("srcChassisId:{}, srcPortName:{}, srcPortDesc:{}", srcChassisId, srcPortName, srcPortDesc);
        if (srcChassisId == null && srcPortDesc == null) {
            log.warn("there are no valid port id");
            return false;
        }
        Optional<Device> srcDevice = findSourceDeviceByChassisId(deviceService, srcChassisId);
        if (!srcDevice.isPresent()) {
            log.debug("source device not found. srcChassisId value: {}", srcChassisId);
            return false;
        }
        Optional<Port> sourcePort = findSourcePortByName(srcPortName == null ? srcPortDesc : srcPortName, deviceService, srcDevice.get());
        if (!sourcePort.isPresent()) {
            log.debug("source port not found. sourcePort value: {}", sourcePort);
            return false;
        }
        PortNumber srcPort = sourcePort.get().number();
        PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
        DeviceId srcDeviceId = srcDevice.get().id();
        DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();
        if (!sourcePort.get().isEnabled()) {
            log.debug("Ports are disabled. Cannot create a link between {}/{} and {}/{}", srcDeviceId, sourcePort.get(), dstDeviceId, dstPort);
            return false;
        }
        ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort);
        ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
        DefaultAnnotations annotations = DefaultAnnotations.builder().set(AnnotationKeys.PROTOCOL, SCHEME_NAME.toUpperCase()).set(AnnotationKeys.LAYER, ETHERNET).build();
        LinkDescription ld = new DefaultLinkDescription(src, dst, lt, true, annotations);
        try {
            context.providerService().linkDetected(ld);
            context.setTtl(LinkKey.linkKey(src, dst), onoslldp.getTtlBySeconds());
        } catch (IllegalStateException e) {
            log.debug("There is a exception during link creation: {}", e);
            return true;
        }
        return true;
    }
    return false;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) Device(org.onosproject.net.Device) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) ONOSLLDP(org.onlab.packet.ONOSLLDP) DeviceService(org.onosproject.net.device.DeviceService) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) Type(org.onosproject.net.Link.Type) PortNumber(org.onosproject.net.PortNumber) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Example 94 with DeviceService

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

the class BasicInterpreterImpl method mapOutboundPacket.

@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) throws PiInterpreterException {
    TrafficTreatment treatment = packet.treatment();
    // basic.p4 supports only OUTPUT instructions.
    List<OutputInstruction> outInstructions = treatment.allInstructions().stream().filter(i -> i.type().equals(OUTPUT)).map(i -> (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 (OutputInstruction outInst : outInstructions) {
        if (outInst.port().isLogical() && !outInst.port().equals(FLOOD)) {
            throw new PiInterpreterException(format("Output on logical port '%s' not supported", outInst.port()));
        } else if (outInst.port().equals(FLOOD)) {
            // Since basic.p4 does not support flooding, we 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()));
            }
        } else {
            builder.add(createPiPacketOperation(packet.data(), outInst.port().toLong()));
        }
    }
    return builder.build();
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) PiTableId(org.onosproject.net.pi.model.PiTableId) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) ImmutableByteSequence.copyFrom(org.onlab.util.ImmutableByteSequence.copyFrom) INGRESS_WCMP_CONTROL_WCMP_TABLE(org.onosproject.pipelines.basic.BasicConstants.INGRESS_WCMP_CONTROL_WCMP_TABLE) Port(org.onosproject.net.Port) Map(java.util.Map) HDR_STANDARD_METADATA_INGRESS_PORT(org.onosproject.pipelines.basic.BasicConstants.HDR_STANDARD_METADATA_INGRESS_PORT) INGRESS_PORT(org.onosproject.pipelines.basic.BasicConstants.INGRESS_PORT) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) EGRESS_PORT(org.onosproject.pipelines.basic.BasicConstants.EGRESS_PORT) String.format(java.lang.String.format) HDR_HDR_ETHERNET_DST_ADDR(org.onosproject.pipelines.basic.BasicConstants.HDR_HDR_ETHERNET_DST_ADDR) List(java.util.List) InboundPacket(org.onosproject.net.packet.InboundPacket) PORT(org.onosproject.pipelines.basic.BasicConstants.PORT) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) PACKET_OUT(org.onosproject.net.pi.model.PiPacketOperationType.PACKET_OUT) HDR_HDR_ETHERNET_ETHER_TYPE(org.onosproject.pipelines.basic.BasicConstants.HDR_HDR_ETHERNET_ETHER_TYPE) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) INGRESS_TABLE0_CONTROL_DROP(org.onosproject.pipelines.basic.BasicConstants.INGRESS_TABLE0_CONTROL_DROP) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) HDR_HDR_ETHERNET_SRC_ADDR(org.onosproject.pipelines.basic.BasicConstants.HDR_HDR_ETHERNET_SRC_ADDR) ImmutableList(com.google.common.collect.ImmutableList) DeserializationException(org.onlab.packet.DeserializationException) OutboundPacket(org.onosproject.net.packet.OutboundPacket) 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) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Instruction(org.onosproject.net.flow.instructions.Instruction) NO_ACTION(org.onosproject.pipelines.basic.BasicConstants.NO_ACTION) INGRESS_TABLE0_CONTROL_SEND_TO_CPU(org.onosproject.pipelines.basic.BasicConstants.INGRESS_TABLE0_CONTROL_SEND_TO_CPU) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) INGRESS_TABLE0_CONTROL_SET_EGRESS_PORT(org.onosproject.pipelines.basic.BasicConstants.INGRESS_TABLE0_CONTROL_SET_EGRESS_PORT) CONTROLLER(org.onosproject.net.PortNumber.CONTROLLER) HDR_HDR_IPV4_DST_ADDR(org.onosproject.pipelines.basic.BasicConstants.HDR_HDR_IPV4_DST_ADDR) INGRESS_WCMP_CONTROL_SET_EGRESS_PORT(org.onosproject.pipelines.basic.BasicConstants.INGRESS_WCMP_CONTROL_SET_EGRESS_PORT) PiAction(org.onosproject.net.pi.runtime.PiAction) INGRESS_TABLE0_CONTROL_TABLE0(org.onosproject.pipelines.basic.BasicConstants.INGRESS_TABLE0_CONTROL_TABLE0) Collectors.toList(java.util.stream.Collectors.toList) HDR_HDR_IPV4_SRC_ADDR(org.onosproject.pipelines.basic.BasicConstants.HDR_HDR_IPV4_SRC_ADDR) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) PiActionId(org.onosproject.net.pi.model.PiActionId) ImmutableList(com.google.common.collect.ImmutableList) Port(org.onosproject.net.Port) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) DeviceService(org.onosproject.net.device.DeviceService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 95 with DeviceService

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

the class PolatisDeviceDescription method discoverPortDetails.

/**
 * Discovers port details, for polatis device.
 *
 * @return port list
 */
@Override
public List<PortDescription> discoverPortDetails() {
    log.debug("Discovering ports on Polatis switch...");
    DeviceService deviceService = handler().get(DeviceService.class);
    DeviceId deviceID = handler().data().deviceId();
    Device device = deviceService.getDevice(deviceID);
    int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
    int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
    String reply = netconfGet(handler(), getPortsFilter());
    List<PortDescription> descriptions = parsePorts(reply, numInputPorts, numOutputPorts);
    return ImmutableList.copyOf(descriptions);
}
Also used : DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) PortDescription(org.onosproject.net.device.PortDescription)

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