Search in sources :

Example 96 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class SimpleDeviceStore method createOrUpdateDevice.

@Override
public DeviceEvent createOrUpdateDevice(ProviderId providerId, DeviceId deviceId, DeviceDescription deviceDescription) {
    Map<ProviderId, DeviceDescriptions> providerDescs = getOrCreateDeviceDescriptions(deviceId);
    synchronized (providerDescs) {
        // locking per device
        DeviceDescriptions descs = getOrCreateProviderDeviceDescriptions(providerDescs, providerId, deviceDescription);
        Device oldDevice = devices.get(deviceId);
        // update description
        descs.putDeviceDesc(deviceDescription);
        Device newDevice = composeDevice(deviceId, providerDescs);
        DeviceEvent event = null;
        if (oldDevice == null) {
            // ADD
            event = createDevice(providerId, newDevice);
        } else {
            // UPDATE or ignore (no change or stale)
            event = updateDevice(providerId, oldDevice, newDevice);
        }
        notifyDelegateIfNotNull(event);
        return event;
    }
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device)

Example 97 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class SimpleDeviceStore method removeDevice.

@Override
public DeviceEvent removeDevice(DeviceId deviceId) {
    Map<ProviderId, DeviceDescriptions> descs = getOrCreateDeviceDescriptions(deviceId);
    synchronized (descs) {
        Device device = devices.remove(deviceId);
        // should DEVICE_REMOVED carry removed ports?
        Map<PortNumber, Port> ports = devicePorts.get(deviceId);
        if (ports != null) {
            ports.clear();
        }
        availableDevices.remove(deviceId);
        descs.clear();
        return device == null ? null : new DeviceEvent(DEVICE_REMOVED, device, null);
    }
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) PortNumber(org.onosproject.net.PortNumber)

Example 98 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class DefaultTopologyTest method setUp.

@Before
public void setUp() {
    long now = System.currentTimeMillis();
    Set<Device> devices = of(device("1"), device("2"), device("3"), device("4"), device("5"));
    Set<Link> links = of(link("1", 1, "2", 1), link("2", 1, "1", 1), link("3", 2, "2", 2), link("2", 2, "3", 2), link("1", 3, "4", 3), link("4", 3, "1", 3), link("3", 4, "4", 4), link("4", 4, "3", 4));
    GraphDescription graphDescription = new DefaultGraphDescription(now, System.currentTimeMillis(), devices, links);
    dt = new DefaultTopology(PID, graphDescription);
    assertEquals("incorrect supplier", PID, dt.providerId());
    assertEquals("incorrect time", now, dt.time());
    assertEquals("incorrect device count", 5, dt.deviceCount());
    assertEquals("incorrect link count", 8, dt.linkCount());
    assertEquals("incorrect cluster count", 2, dt.clusterCount());
    assertEquals("incorrect broadcast set size", 6, dt.broadcastSetSize(C0));
    assertEquals("incorrect root node", V1, dt.getCluster(C0).root());
    assertEquals("incorrect root node", V5, dt.getCluster(C1).root());
}
Also used : DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) DefaultGraphDescription(org.onosproject.net.topology.DefaultGraphDescription) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) GraphDescription(org.onosproject.net.topology.GraphDescription) DefaultGraphDescription(org.onosproject.net.topology.DefaultGraphDescription) Before(org.junit.Before)

Example 99 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class CzechLightDiscovery method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    NetconfSession session = getNetconfSession();
    if (session == null) {
        log.error("Cannot request NETCONF session for {}", data().deviceId());
        return null;
    }
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
    final var noDevice = new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.OTHER, null, null, null, null, null, annotations.build());
    try {
        Boolean isLineDegree = false, isAddDrop = false, isCoherentAddDrop = false, isInlineAmp = false;
        var data = doGetXPath(getNetconfSession(), YANGLIB_XML_PREFIX, YANGLIB_XMLNS, YANGLIB_XPATH_FILTER);
        if (!data.containsKey(YANGLIB_KEY_REVISION)) {
            log.error("Not talking to a supported CzechLight device, is that a teapot?");
            return noDevice;
        }
        final var revision = data.getString(YANGLIB_KEY_REVISION);
        if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_ROADM_DEVICE)) {
            if (!revision.equals(MOD_ROADM_DEVICE_DATE)) {
                log.error("Revision mismatch for YANG module {}: got {}", MOD_ROADM_DEVICE, revision);
                return noDevice;
            }
            final var features = data.getStringArray(YANGLIB_PATH_QUERY_FEATURES);
            isLineDegree = Arrays.stream(features).anyMatch(s -> s.equals(MOD_ROADM_FEATURE_LINE_DEGREE));
            isAddDrop = Arrays.stream(features).anyMatch(s -> s.equals(MOD_ROADM_FEATURE_FLEX_ADD_DROP));
            if (!isLineDegree && !isAddDrop) {
                log.error("Device type not recognized, but {} YANG model is present. Reported YANG features: {}", MOD_ROADM_DEVICE, String.join(", ", features));
                return noDevice;
            }
        } else if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_COHERENT_A_D)) {
            if (!revision.equals(MOD_COHERENT_A_D_DATE)) {
                log.error("Revision mismatch for YANG module {}: got {}", MOD_COHERENT_A_D, revision);
                return noDevice;
            }
            isCoherentAddDrop = true;
        } else if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_INLINE_AMP)) {
            if (!revision.equals(MOD_INLINE_AMP_DATE)) {
                log.error("Revision mismatch for YANG module {}: got {}", MOD_INLINE_AMP, revision);
                return noDevice;
            }
            isInlineAmp = true;
        }
        if (isLineDegree) {
            log.info("Talking to a Line/Degree ROADM node");
            annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.LINE_DEGREE.toString());
        } else if (isAddDrop) {
            log.info("Talking to an Add/Drop ROADM node");
            annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.ADD_DROP_FLEX.toString());
        } else if (isCoherentAddDrop) {
            log.info("Talking to a Coherent Add/Drop ROADM node");
            annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.COHERENT_ADD_DROP.toString());
        } else if (isInlineAmp) {
            log.info("Talking to an inline ampifier, not a ROADM, but we will fake it as a ROADM for now");
            annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.INLINE_AMP.toString());
        } else {
            log.error("Device type not recognized");
            return noDevice;
        }
    } catch (NetconfException e) {
        log.error("Cannot request ietf-yang-library data", e);
        return noDevice;
    }
    // FIXME: initialize these
    String vendor = "CzechLight";
    String hwVersion = "n/a";
    String swVersion = "n/a";
    String serialNumber = "n/a";
    ChassisId chassisId = null;
    return new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.ROADM, vendor, hwVersion, swVersion, serialNumber, chassisId, annotations.build());
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) OmsPortHelper.omsPortDescription(org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription) Arrays(java.util.Arrays) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) AnnotationKeys(org.onosproject.net.AnnotationKeys) NetconfSession(org.onosproject.netconf.NetconfSession) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Frequency(org.onlab.util.Frequency) Lists(com.google.common.collect.Lists) NetconfController(org.onosproject.netconf.NetconfController) PortDescription(org.onosproject.net.device.PortDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) Logger(org.slf4j.Logger) Device(org.onosproject.net.Device) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) XmlConfigParser(org.onosproject.drivers.utilities.XmlConfigParser) OdtnDeviceDescriptionDiscovery(org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery) DatastoreId(org.onosproject.netconf.DatastoreId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) List(java.util.List) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ChannelSpacing(org.onosproject.net.ChannelSpacing) DeviceId(org.onosproject.net.DeviceId) ChassisId(org.onlab.packet.ChassisId) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) NetconfException(org.onosproject.netconf.NetconfException) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 100 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class LinkDiscoveryCiscoImpl method getLinks.

@Override
public Set<LinkDescription> getLinks() {
    String response = retrieveResponse(SHOW_LLDP_NEIGHBOR_DETAIL_CMD);
    DeviceId localDeviceId = this.handler().data().deviceId();
    DeviceService deviceService = this.handler().get(DeviceService.class);
    Set<LinkDescription> linkDescriptions = Sets.newHashSet();
    List<Port> ports = deviceService.getPorts(localDeviceId);
    if (ports.size() == 0 || Objects.isNull(response)) {
        return linkDescriptions;
    }
    try {
        ObjectMapper om = new ObjectMapper();
        JsonNode json = om.readTree(response);
        if (json == null) {
            return linkDescriptions;
        }
        JsonNode res = json.at("/" + JSON_RESULT);
        if (res.isMissingNode()) {
            return linkDescriptions;
        }
        JsonNode lldpNeighborsRow = res.at("/" + TABLE_NBOR_DETAIL);
        if (lldpNeighborsRow.isMissingNode()) {
            return linkDescriptions;
        }
        JsonNode lldpNeighbors = lldpNeighborsRow.at("/" + ROW_NBOR_DETAIL);
        if (lldpNeighbors.isMissingNode()) {
            return linkDescriptions;
        }
        Iterator<JsonNode> iterator = lldpNeighbors.elements();
        while (iterator.hasNext()) {
            JsonNode neighbors = iterator.next();
            String remoteChassisId = neighbors.get(CHASSIS_ID).asText();
            String remotePortName = neighbors.get(PORT_ID).asText();
            String remotePortDesc = neighbors.get(PORT_DESC).asText();
            String lldpLocalPort = neighbors.get(LOCAL_PORT_ID).asText().replaceAll("(Eth.{0,5})(.\\d{0,5}/\\d{0,5})", "Ethernet$2");
            Port localPort = findLocalPortByName(ports, lldpLocalPort);
            if (localPort == null) {
                log.warn("local port not found. LldpLocalPort value: {}", lldpLocalPort);
                continue;
            }
            Device remoteDevice = findRemoteDeviceByChassisId(deviceService, remoteChassisId);
            Port remotePort = findDestinationPortByName(remotePortName, remotePortDesc, deviceService, remoteDevice);
            if (!localPort.isEnabled() || !remotePort.isEnabled()) {
                log.debug("Ports are disabled. Cannot create a link between {}/{} and {}/{}", localDeviceId, localPort, remoteDevice.id(), remotePort);
                continue;
            }
            linkDescriptions.addAll(buildLinkPair(localDeviceId, localPort, remoteDevice.id(), remotePort));
        }
    } catch (IOException e) {
        log.error("Failed to get links ", e);
    }
    log.debug("Returning linkDescriptions: {}", linkDescriptions);
    return linkDescriptions;
}
Also used : DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Device (org.onosproject.net.Device)316 DeviceService (org.onosproject.net.device.DeviceService)102 DeviceId (org.onosproject.net.DeviceId)85 Port (org.onosproject.net.Port)51 DefaultDevice (org.onosproject.net.DefaultDevice)50 ConnectPoint (org.onosproject.net.ConnectPoint)47 Test (org.junit.Test)43 List (java.util.List)37 PortNumber (org.onosproject.net.PortNumber)35 DeviceEvent (org.onosproject.net.device.DeviceEvent)33 TrafficSelector (org.onosproject.net.flow.TrafficSelector)30 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)29 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)29 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)26 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)26 ArrayList (java.util.ArrayList)25 DefaultPort (org.onosproject.net.DefaultPort)25 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)25 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)24 Set (java.util.Set)24