Search in sources :

Example 36 with DeviceDescription

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

the class SimpleDeviceStoreTest method putDevice.

private void putDevice(DeviceId deviceId, String swVersion, SparseAnnotations... annotations) {
    DeviceDescription description = new DefaultDeviceDescription(deviceId.uri(), SWITCH, MFR, HW, swVersion, SN, CID, annotations);
    deviceStore.createOrUpdateDevice(PID, deviceId, description);
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 37 with DeviceDescription

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

the class SimpleDeviceStoreTest method testCreateOrUpdateDevice.

@Test
public final void testCreateOrUpdateDevice() {
    DeviceDescription description = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID);
    DeviceEvent event = deviceStore.createOrUpdateDevice(PID, DID1, description);
    assertEquals(DEVICE_ADDED, event.type());
    assertDevice(DID1, SW1, event.subject());
    DeviceDescription description2 = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW2, SN, CID);
    DeviceEvent event2 = deviceStore.createOrUpdateDevice(PID, DID1, description2);
    assertEquals(DEVICE_UPDATED, event2.type());
    assertDevice(DID1, SW2, event2.subject());
    assertNull("No change expected", deviceStore.createOrUpdateDevice(PID, DID1, description2));
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Test(org.junit.Test)

Example 38 with DeviceDescription

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

the class SimpleDeviceStoreTest method testCreateOrUpdateDeviceAncillary.

@Test
public final void testCreateOrUpdateDeviceAncillary() {
    DeviceDescription description = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID, A2);
    DeviceEvent event = deviceStore.createOrUpdateDevice(PIDA, DID1, description);
    assertEquals(DEVICE_ADDED, event.type());
    assertDevice(DID1, SW1, event.subject());
    assertEquals(PIDA, event.subject().providerId());
    assertAnnotationsEquals(event.subject().annotations(), A2);
    assertFalse("Ancillary will not bring device up", deviceStore.isAvailable(DID1));
    DeviceDescription description2 = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW2, SN, CID, A1);
    DeviceEvent event2 = deviceStore.createOrUpdateDevice(PID, DID1, description2);
    assertEquals(DEVICE_UPDATED, event2.type());
    assertDevice(DID1, SW2, event2.subject());
    assertEquals(PID, event2.subject().providerId());
    assertAnnotationsEquals(event2.subject().annotations(), A1, A2);
    assertTrue(deviceStore.isAvailable(DID1));
    assertNull("No change expected", deviceStore.createOrUpdateDevice(PID, DID1, description2));
    // For now, Ancillary is ignored once primary appears
    assertNull("No change expected", deviceStore.createOrUpdateDevice(PIDA, DID1, description));
    // But, Ancillary annotations will be in effect
    DeviceDescription description3 = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID, A2_2);
    DeviceEvent event3 = deviceStore.createOrUpdateDevice(PIDA, DID1, description3);
    assertEquals(DEVICE_UPDATED, event3.type());
    // basic information will be the one from Primary
    assertDevice(DID1, SW2, event3.subject());
    assertEquals(PID, event3.subject().providerId());
    // but annotation from Ancillary will be merged
    assertAnnotationsEquals(event3.subject().annotations(), A1, A2, A2_2);
    assertTrue(deviceStore.isAvailable(DID1));
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Test(org.junit.Test)

Example 39 with DeviceDescription

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

the class SimpleDeviceStoreTest method testEvents.

// If Delegates should be called only on remote events,
// then Simple* should never call them, thus not test required.
// TODO add test for Port events when we have them
@Ignore("Ignore until Delegate spec. is clear.")
@Test
public final void testEvents() throws InterruptedException {
    final CountDownLatch addLatch = new CountDownLatch(1);
    DeviceStoreDelegate checkAdd = event -> {
        assertEquals(DEVICE_ADDED, event.type());
        assertDevice(DID1, SW1, event.subject());
        addLatch.countDown();
    };
    final CountDownLatch updateLatch = new CountDownLatch(1);
    DeviceStoreDelegate checkUpdate = event -> {
        assertEquals(DEVICE_UPDATED, event.type());
        assertDevice(DID1, SW2, event.subject());
        updateLatch.countDown();
    };
    final CountDownLatch removeLatch = new CountDownLatch(1);
    DeviceStoreDelegate checkRemove = event -> {
        assertEquals(DEVICE_REMOVED, event.type());
        assertDevice(DID1, SW2, event.subject());
        removeLatch.countDown();
    };
    DeviceDescription description = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID);
    deviceStore.setDelegate(checkAdd);
    deviceStore.createOrUpdateDevice(PID, DID1, description);
    assertTrue("Add event fired", addLatch.await(1, TimeUnit.SECONDS));
    DeviceDescription description2 = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW2, SN, CID);
    deviceStore.unsetDelegate(checkAdd);
    deviceStore.setDelegate(checkUpdate);
    deviceStore.createOrUpdateDevice(PID, DID1, description2);
    assertTrue("Update event fired", updateLatch.await(1, TimeUnit.SECONDS));
    deviceStore.unsetDelegate(checkUpdate);
    deviceStore.setDelegate(checkRemove);
    deviceStore.removeDevice(DID1);
    assertTrue("Remove event fired", removeLatch.await(1, TimeUnit.SECONDS));
}
Also used : Arrays(java.util.Arrays) Iterables(com.google.common.collect.Iterables) BeforeClass(org.junit.BeforeClass) PortNumber(org.onosproject.net.PortNumber) HashMap(java.util.HashMap) DeviceStore(org.onosproject.net.device.DeviceStore) NetTestTools.assertAnnotationsEquals(org.onosproject.net.NetTestTools.assertAnnotationsEquals) Port(org.onosproject.net.Port) Map(java.util.Map) After(org.junit.After) SWITCH(org.onosproject.net.Device.Type.SWITCH) PortDescription(org.onosproject.net.device.PortDescription) DeviceId.deviceId(org.onosproject.net.DeviceId.deviceId) DeviceStoreDelegate(org.onosproject.net.device.DeviceStoreDelegate) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Before(org.junit.Before) DeviceDescription(org.onosproject.net.device.DeviceDescription) AfterClass(org.junit.AfterClass) Device(org.onosproject.net.Device) Set(java.util.Set) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) Type(org.onosproject.net.device.DeviceEvent.Type) Sets(com.google.common.collect.Sets) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) Ignore(org.junit.Ignore) SparseAnnotations(org.onosproject.net.SparseAnnotations) DeviceEvent(org.onosproject.net.device.DeviceEvent) Assert(org.junit.Assert) DeviceId(org.onosproject.net.DeviceId) ChassisId(org.onlab.packet.ChassisId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) DeviceStoreDelegate(org.onosproject.net.device.DeviceStoreDelegate) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) CountDownLatch(java.util.concurrent.CountDownLatch) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 40 with DeviceDescription

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

the class SimpleDeviceStore method composeDevice.

/**
 * Returns a Device, merging description given from multiple Providers.
 *
 * @param deviceId      device identifier
 * @param providerDescs Collection of Descriptions from multiple providers
 * @return Device instance
 */
private Device composeDevice(DeviceId deviceId, Map<ProviderId, DeviceDescriptions> providerDescs) {
    checkArgument(!providerDescs.isEmpty(), "No Device descriptions supplied");
    ProviderId primary = pickPrimaryPid(providerDescs);
    DeviceDescriptions desc = providerDescs.get(primary);
    final DeviceDescription base = desc.getDeviceDesc();
    Type type = base.type();
    String manufacturer = base.manufacturer();
    String hwVersion = base.hwVersion();
    String swVersion = base.swVersion();
    String serialNumber = base.serialNumber();
    ChassisId chassisId = base.chassisId();
    DefaultAnnotations annotations = DefaultAnnotations.builder().build();
    annotations = merge(annotations, base.annotations());
    for (Entry<ProviderId, DeviceDescriptions> e : providerDescs.entrySet()) {
        if (e.getKey().equals(primary)) {
            continue;
        }
        // TODO: should keep track of Description timestamp
        // and only merge conflicting keys when timestamp is newer
        // Currently assuming there will never be a key conflict between
        // providers
        // annotation merging. not so efficient, should revisit later
        annotations = merge(annotations, e.getValue().getDeviceDesc().annotations());
    }
    return new DefaultDevice(primary, deviceId, type, manufacturer, hwVersion, swVersion, serialNumber, chassisId, annotations);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Type(org.onosproject.net.Device.Type) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultDevice(org.onosproject.net.DefaultDevice)

Aggregations

DeviceDescription (org.onosproject.net.device.DeviceDescription)44 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)32 ChassisId (org.onlab.packet.ChassisId)14 DeviceId (org.onosproject.net.DeviceId)14 Test (org.junit.Test)11 ProviderId (org.onosproject.net.provider.ProviderId)10 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)9 DeviceEvent (org.onosproject.net.device.DeviceEvent)8 SparseAnnotations (org.onosproject.net.SparseAnnotations)6 DeviceDescriptionDiscovery (org.onosproject.net.device.DeviceDescriptionDiscovery)6 Device (org.onosproject.net.Device)5 PortDescription (org.onosproject.net.device.PortDescription)5 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)4 BiFunction (java.util.function.BiFunction)4 Function (java.util.function.Function)4 NodeId (org.onosproject.cluster.NodeId)4 NetconfException (org.onosproject.netconf.NetconfException)4 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3