Search in sources :

Example 1 with Behaviour

use of org.onosproject.net.driver.Behaviour 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 Behaviour

use of org.onosproject.net.driver.Behaviour in project onos by opennetworkinglab.

the class DriverCodecTest method codecTest.

@Test
public void codecTest() {
    Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = ImmutableMap.of(TestBehaviour.class, TestBehaviourImpl.class, TestBehaviourTwo.class, TestBehaviourTwoImpl.class);
    Map<String, String> properties = ImmutableMap.of("key1", "value1", "key2", "value2");
    DefaultDriver parent = new DefaultDriver("parent", new ArrayList<>(), "Acme", "HW1.2.3", "SW1.2.3", behaviours, properties);
    DefaultDriver child = new DefaultDriver("child", ImmutableList.of(parent), "Acme", "HW1.2.3.1", "SW1.2.3.1", behaviours, properties);
    MockCodecContext context = new MockCodecContext();
    ObjectNode driverJson = context.codec(Driver.class).encode(child, context);
    assertThat(driverJson, matchesDriver(child));
}
Also used : TestBehaviour(org.onosproject.net.driver.TestBehaviour) Behaviour(org.onosproject.net.driver.Behaviour) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultDriver(org.onosproject.net.driver.DefaultDriver) DefaultDriver(org.onosproject.net.driver.DefaultDriver) DriverJsonMatcher.matchesDriver(org.onosproject.codec.impl.DriverJsonMatcher.matchesDriver) Driver(org.onosproject.net.driver.Driver) Test(org.junit.Test)

Example 3 with Behaviour

use of org.onosproject.net.driver.Behaviour in project onos by opennetworkinglab.

the class PiPipeconfManager method buildMergedDriver.

private Driver buildMergedDriver(PiPipeconfId pipeconfId, String baseDriverName, String newDriverName) {
    final Driver baseDriver = getDriver(baseDriverName);
    if (baseDriver == null) {
        log.error("Base driver {} not found, cannot build a merged one", baseDriverName);
        return null;
    }
    final PiPipeconf pipeconf = pipeconfs.get(pipeconfId);
    if (pipeconf == null) {
        log.error("Pipeconf {} is not registered, cannot build a merged driver", pipeconfId);
        return null;
    }
    // extract the behaviours from the pipipeconf.
    final Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = new HashMap<>();
    pipeconf.behaviours().forEach(b -> behaviours.put(b, pipeconf.implementation(b).get()));
    // general, we should give higher priority to pipeconf behaviours.
    if (baseDriver.hasBehaviour(PortStatisticsDiscovery.class) && behaviours.remove(PortStatisticsDiscovery.class) != null) {
        log.warn("Ignoring {} behaviour from pipeconf {}, but using " + "the one provided by {} driver...", PortStatisticsDiscovery.class.getSimpleName(), pipeconfId, baseDriver.name());
    }
    final Driver piPipeconfDriver = new DefaultDriver(newDriverName, baseDriver.parents(), baseDriver.manufacturer(), baseDriver.hwVersion(), baseDriver.swVersion(), behaviours, new HashMap<>());
    // merge it with the base driver that was assigned to the device
    return piPipeconfDriver.merge(baseDriver);
}
Also used : PortStatisticsDiscovery(org.onosproject.net.device.PortStatisticsDiscovery) Behaviour(org.onosproject.net.driver.Behaviour) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PiPipeconf(org.onosproject.net.pi.model.PiPipeconf) DefaultDriver(org.onosproject.net.driver.DefaultDriver) DefaultDriver(org.onosproject.net.driver.DefaultDriver) Driver(org.onosproject.net.driver.Driver)

Example 4 with Behaviour

use of org.onosproject.net.driver.Behaviour in project onos by opennetworkinglab.

the class SoamManagerTest method setup.

@Before
public void setup() throws CfmConfigException, SoamConfigException {
    soamManager = new SoamManager();
    TestUtils.setField(soamManager, "coreService", new TestCoreService());
    TestUtils.setField(soamManager, "cfmMepService", mepService);
    TestUtils.setField(soamManager, "deviceService", deviceService);
    injectEventDispatcher(soamManager, new TestEventDispatcher());
    soamService = soamManager;
    soamManager.activate();
    DelayMeasurementEntry dmEntry1 = DefaultDelayMeasurementEntry.builder(DMID101, DelayMeasurementCreate.DmType.DM1DMTX, DelayMeasurementCreate.Version.Y17312011, MepId.valueOf((short) 11), Mep.Priority.PRIO5).build();
    DelayMeasurementEntry dmEntry2 = DefaultDelayMeasurementEntry.builder(DMID102, DelayMeasurementCreate.DmType.DM1DMTX, DelayMeasurementCreate.Version.Y17312011, MepId.valueOf((short) 11), Mep.Priority.PRIO6).build();
    mep1 = DefaultMepEntry.builder(MEPID1, DEVICE_ID1, PortNumber.P0, Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).addToDelayMeasurementList(dmEntry1).addToDelayMeasurementList(dmEntry2).buildEntry();
    device1 = new DefaultDevice(ProviderId.NONE, DEVICE_ID1, Device.Type.SWITCH, TEST_MFR, TEST_HW_VERSION, TEST_SW_VERSION, TEST_SN, new ChassisId(1), DefaultAnnotations.builder().set(AnnotationKeys.DRIVER, TEST_DRIVER).build());
    AbstractProjectableModel.setDriverService(null, driverService);
    Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = new HashMap<>();
    behaviours.put(DeviceDescriptionDiscovery.class, TestDeviceDiscoveryBehavior.class);
    behaviours.put(CfmMepProgrammable.class, TestCfmMepProgrammable.class);
    behaviours.put(SoamDmProgrammable.class, TestSoamDmProgrammable.class);
    testDriver = new DefaultDriver(TEST_DRIVER, new ArrayList<Driver>(), TEST_MFR, TEST_HW_VERSION, TEST_SW_VERSION, behaviours, new HashMap<>());
}
Also used : TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) ChassisId(org.onlab.packet.ChassisId) Behaviour(org.onosproject.net.driver.Behaviour) HashMap(java.util.HashMap) DelayMeasurementEntry(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry) DefaultDelayMeasurementEntry(org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementEntry) DefaultDevice(org.onosproject.net.DefaultDevice) DefaultDriver(org.onosproject.net.driver.DefaultDriver) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Example 5 with Behaviour

use of org.onosproject.net.driver.Behaviour in project onos by opennetworkinglab.

the class CfmMepManagerTest method testCreateMepBehaviorNotSupported.

@Test
public void testCreateMepBehaviorNotSupported() throws CfmConfigException {
    final DeviceId deviceId3 = DeviceId.deviceId("netconf:3.2.3.4:830");
    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(mdService.getMaintenanceAssociation(MDNAME1, MANAME1)).andReturn(Optional.ofNullable(ma1)).anyTimes();
    replay(mdService);
    expect(deviceService.getDevice(deviceId3)).andReturn(device3).anyTimes();
    replay(deviceService);
    expect(driverService.getDriver(deviceId3)).andReturn(testDriver3).anyTimes();
    replay(driverService);
    MepId mepId3 = MepId.valueOf((short) 3);
    Mep mep3 = DefaultMep.builder(mepId3, deviceId3, PortNumber.portNumber(1), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
    try {
        mepManager.createMep(MDNAME1, MANAME1, mep3);
        fail("Expecting CfmConfigException because driver does not support behavior");
    } catch (CfmConfigException e) {
        assertEquals("Device netconf:3.2.3.4:830 does not support " + "CfmMepProgrammable behaviour.", 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) DefaultDriver(org.onosproject.net.driver.DefaultDriver) DefaultMep(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Test(org.junit.Test)

Aggregations

Behaviour (org.onosproject.net.driver.Behaviour)7 DefaultDriver (org.onosproject.net.driver.DefaultDriver)6 HashMap (java.util.HashMap)5 Driver (org.onosproject.net.driver.Driver)5 Test (org.junit.Test)4 ChassisId (org.onlab.packet.ChassisId)4 DefaultDevice (org.onosproject.net.DefaultDevice)4 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)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 Device (org.onosproject.net.Device)2 DeviceId (org.onosproject.net.DeviceId)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 DriverJsonMatcher.matchesDriver (org.onosproject.codec.impl.DriverJsonMatcher.matchesDriver)1 DefaultMep (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep)1 DefaultMepEntry (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepEntry)1 Mep (org.onosproject.incubator.net.l2monitoring.cfm.Mep)1