Search in sources :

Example 1 with DefaultDevice

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

the class SoamManagerTest method testCreateDmNoBehavior.

@Test
public void testCreateDmNoBehavior() throws CfmConfigException, SoamConfigException {
    final DeviceId deviceId3 = DeviceId.deviceId("netconf:3.2.3.4:830");
    final MepId mepId3 = MepId.valueOf((short) 3);
    Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = new HashMap<>();
    behaviours.put(DeviceDescriptionDiscovery.class, TestDeviceDiscoveryBehavior.class);
    Driver testDriver3 = new DefaultDriver(TEST_DRIVER_3, new ArrayList<Driver>(), TEST_MFR, TEST_HW_VERSION, TEST_SW_3, behaviours, new HashMap<>());
    Device device3 = new DefaultDevice(ProviderId.NONE, deviceId3, Device.Type.SWITCH, TEST_MFR, TEST_HW_VERSION, TEST_SW_3, TEST_SN, new ChassisId(2), DefaultAnnotations.builder().set(AnnotationKeys.DRIVER, TEST_DRIVER_3).build());
    expect(deviceService.getDevice(deviceId3)).andReturn(device3).anyTimes();
    replay(deviceService);
    MepEntry mep3 = DefaultMepEntry.builder(mepId3, deviceId3, PortNumber.P0, Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).buildEntry();
    expect(mepService.getMep(MDNAME1, MANAME1, mepId3)).andReturn(mep3).anyTimes();
    replay(mepService);
    expect(driverService.getDriver(deviceId3)).andReturn(testDriver3).anyTimes();
    replay(driverService);
    DelayMeasurementCreate dmCreate1 = DefaultDelayMeasurementCreate.builder(DelayMeasurementCreate.DmType.DM1DMTX, DelayMeasurementCreate.Version.Y17312011, MepId.valueOf((short) 11), Mep.Priority.PRIO3).binsPerFdInterval((short) 4).binsPerFdrInterval((short) 5).binsPerIfdvInterval((short) 6).build();
    try {
        soamManager.createDm(MDNAME1, MANAME1, mepId3, dmCreate1);
        fail("Expecting exception since device does not support behavior");
    } catch (CfmConfigException e) {
        assertEquals("Device netconf:3.2.3.4:830 from MEP :md-1/" + "ma-1-1/3 does not implement SoamDmProgrammable", e.getMessage());
    }
}
Also used : ChassisId(org.onlab.packet.ChassisId) Behaviour(org.onosproject.net.driver.Behaviour) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) DefaultDevice(org.onosproject.net.DefaultDevice) Driver(org.onosproject.net.driver.Driver) DefaultDriver(org.onosproject.net.driver.DefaultDriver) MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) DefaultMepEntry(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepEntry) DefaultDriver(org.onosproject.net.driver.DefaultDriver) DelayMeasurementCreate(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate) DefaultDelayMeasurementCreate(org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementCreate) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Test(org.junit.Test)

Example 2 with DefaultDevice

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

the class IntentsDiagnosisCommand method getDeviceString.

private String getDeviceString(Device dev) {
    StringBuilder buf = new StringBuilder();
    if (dev != null) {
        buf.append(String.format("Device: %s, ", dev.id()));
        buf.append(String.format("%s, ", dev.type()));
        buf.append(String.format("%s, ", dev.manufacturer()));
        buf.append(String.format("%s, ", dev.hwVersion()));
        buf.append(String.format("%s, ", dev.swVersion()));
        if (dev instanceof DefaultDevice) {
            DefaultDevice dfltDev = (DefaultDevice) dev;
            if (dfltDev.driver() != null) {
                buf.append(String.format("%s, ", dfltDev.driver().name()));
            }
            String channelId = dfltDev.annotations().value("channelId");
            if (channelId != null) {
                buf.append(String.format("%s, ", channelId));
            }
        }
    }
    return buf.toString();
}
Also used : DefaultDevice(org.onosproject.net.DefaultDevice)

Example 3 with DefaultDevice

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

the class ECDeviceStore method composeDevice.

/**
 * Returns a Device, merging descriptions from multiple Providers.
 *
 * @param deviceId      device identifier
 * @return Device instance
 */
private Device composeDevice(DeviceId deviceId) {
    ProviderId primaryProviderId = getPrimaryProviderId(deviceId);
    DeviceDescription primaryDeviceDescription = deviceDescriptions.get(new DeviceKey(primaryProviderId, deviceId));
    Type type = primaryDeviceDescription.type();
    String manufacturer = primaryDeviceDescription.manufacturer();
    String hwVersion = primaryDeviceDescription.hwVersion();
    String swVersion = primaryDeviceDescription.swVersion();
    String serialNumber = primaryDeviceDescription.serialNumber();
    ChassisId chassisId = primaryDeviceDescription.chassisId();
    DefaultAnnotations annotations = mergeAnnotations(deviceId);
    return new DefaultDevice(primaryProviderId, deviceId, type, manufacturer, hwVersion, swVersion, serialNumber, chassisId, annotations);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceDescription(org.onosproject.net.device.DeviceDescription) Type(org.onosproject.net.Device.Type) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultDevice(org.onosproject.net.DefaultDevice)

Example 4 with DefaultDevice

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

the class LinkDiscoveryCiscoImpl method findRemoteDeviceByChassisId.

private Device findRemoteDeviceByChassisId(DeviceService deviceService, String remoteChassisIdString) {
    String forMacTmp = remoteChassisIdString.replace(".", "").replaceAll("(.{2})", "$1:").trim().substring(0, 17);
    MacAddress mac = MacAddress.valueOf(forMacTmp);
    ChassisId remoteChassisId = new ChassisId(mac.toLong());
    Optional<Device> remoteDeviceOptional;
    Supplier<Stream<Device>> deviceStream = () -> StreamSupport.stream(deviceService.getAvailableDevices().spliterator(), false);
    remoteDeviceOptional = deviceStream.get().filter(device -> device.chassisId() != null && MacAddress.valueOf(device.chassisId().value()).equals(mac)).findAny();
    if (remoteDeviceOptional.isPresent()) {
        return remoteDeviceOptional.get();
    } else {
        remoteDeviceOptional = deviceStream.get().filter(device -> Tools.stream(deviceService.getPorts(device.id())).anyMatch(port -> port.annotations().keys().contains(AnnotationKeys.PORT_MAC) && MacAddress.valueOf(port.annotations().value(AnnotationKeys.PORT_MAC)).equals(mac))).findAny();
        if (remoteDeviceOptional.isPresent()) {
            return remoteDeviceOptional.get();
        } else {
            log.debug("remote device not found. remoteChassisId value: {}", remoteChassisId);
            return new DefaultDevice(ProviderId.NONE, DeviceId.deviceId(LLDP + mac.toString()), Device.Type.SWITCH, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, remoteChassisId, DefaultAnnotations.EMPTY);
        }
    }
}
Also used : Tools(org.onlab.util.Tools) Supplier(com.google.common.base.Supplier) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) DefaultDevice(org.onosproject.net.DefaultDevice) AnnotationKeys(org.onosproject.net.AnnotationKeys) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) MediaType(javax.ws.rs.core.MediaType) Lists(com.google.common.collect.Lists) ByteArrayInputStream(java.io.ByteArrayInputStream) Port(org.onosproject.net.Port) JsonNode(com.fasterxml.jackson.databind.JsonNode) StreamSupport(java.util.stream.StreamSupport) LinkDescription(org.onosproject.net.link.LinkDescription) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DefaultPort(org.onosproject.net.DefaultPort) Device(org.onosproject.net.Device) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) ProviderId(org.onosproject.net.provider.ProviderId) IOException(java.io.IOException) RestSBController(org.onosproject.protocol.rest.RestSBController) Sets(com.google.common.collect.Sets) LinkDiscovery(org.onosproject.net.behaviour.LinkDiscovery) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) List(java.util.List) DriverHandler(org.onosproject.net.driver.DriverHandler) Stream(java.util.stream.Stream) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) ChassisId(org.onlab.packet.ChassisId) InputStream(java.io.InputStream) ChassisId(org.onlab.packet.ChassisId) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) DefaultDevice(org.onosproject.net.DefaultDevice) ByteArrayInputStream(java.io.ByteArrayInputStream) Stream(java.util.stream.Stream) InputStream(java.io.InputStream) MacAddress(org.onlab.packet.MacAddress)

Example 5 with DefaultDevice

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

the class HostLocationProviderTest method removeHostByDevicePortDown.

@Test
public void removeHostByDevicePortDown() {
    provider.modified(CTX_FOR_REMOVE);
    testProcessor.process(new TestArpPacketContext(DEV1));
    testProcessor.process(new TestArpPacketContext(DEV4));
    Device device = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), SWITCH, "m", "h", "s", "n", new ChassisId(0L));
    deviceService.listener.event(new DeviceEvent(PORT_UPDATED, device, new DefaultPort(device, portNumber(INPORT), false)));
    assertEquals("incorrect remove count", 1, providerService.locationRemoveCount);
    device = new DefaultDevice(ProviderId.NONE, deviceId(DEV4), SWITCH, "m", "h", "s", "n", new ChassisId(0L));
    deviceService.listener.event(new DeviceEvent(PORT_UPDATED, device, new DefaultPort(device, portNumber(INPORT), false)));
    assertEquals("incorrect remove count", 2, providerService.locationRemoveCount);
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) ChassisId(org.onlab.packet.ChassisId) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) DefaultDevice(org.onosproject.net.DefaultDevice) DefaultPort(org.onosproject.net.DefaultPort) Test(org.junit.Test)

Aggregations

DefaultDevice (org.onosproject.net.DefaultDevice)22 Device (org.onosproject.net.Device)14 Test (org.junit.Test)13 ChassisId (org.onlab.packet.ChassisId)13 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)10 Annotations (org.onosproject.net.Annotations)5 DefaultPort (org.onosproject.net.DefaultPort)5 DeviceId (org.onosproject.net.DeviceId)5 ProviderId (org.onosproject.net.provider.ProviderId)5 HashMap (java.util.HashMap)4 Type (org.onosproject.net.Device.Type)4 Before (org.junit.Before)3 Port (org.onosproject.net.Port)3 Behaviour (org.onosproject.net.driver.Behaviour)3 DefaultDriver (org.onosproject.net.driver.DefaultDriver)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 TestEventDispatcher (org.onosproject.common.event.impl.TestEventDispatcher)2 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)2 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)2