@Override
    public boolean createMep(MdId mdName, MaIdShort maName, Mep newMep) throws CfmConfigException {
        MepKeyId key = new MepKeyId(mdName, maName, newMep.mepId());
        log.debug("Creating MEP " + newMep.mepId() + " on MD {}, MA {} on Device {}",
                mdName, maName, newMep.deviceId().toString());
        if (mepStore.getMep(key).isPresent()) {
            return false;
        }

        //Will throw IllegalArgumentException if ma does not exist
        cfmMdService.getMaintenanceAssociation(mdName, maName);

        DeviceId mepDeviceId = newMep.deviceId();
        if (deviceService.getDevice(mepDeviceId) == null) {
            throw new CfmConfigException("Device not found " + mepDeviceId);
        } else if (!deviceService.getDevice(mepDeviceId).is(CfmMepProgrammable.class)) {
            throw new CfmConfigException("Device " + mepDeviceId + " does not support CfmMepProgrammable behaviour.");
        }

        boolean deviceResult =
                deviceService.getDevice(mepDeviceId).as(CfmMepProgrammable.class).createMep(mdName, maName, newMep);
        log.debug("MEP created on {}", mepDeviceId);
        if (deviceResult) {
            boolean alreadyExisted = mepStore.createUpdateMep(key, newMep);

            //Add to other Remote Mep List on other devices
            for (Mep mep:mepStore.getMepsByMdMa(mdName, maName)) {
                List<DeviceId> alreadyHandledDevices = new ArrayList<>();
                if (mep.deviceId().equals(mepDeviceId) ||
                        alreadyHandledDevices.contains(mep.deviceId())) {
                    continue;
                }
                boolean created = deviceService.getDevice(mep.deviceId())
                        .as(CfmMepProgrammable.class)
                        .createMaRemoteMepOnDevice(mdName, maName, newMep.mepId());
                alreadyHandledDevices.add(mep.deviceId());
                log.info("Created RMep entry on {} on device {}",
                        mdName.mdName() + "/" + maName.maName(), mep.deviceId());
            }

            return !alreadyExisted;
        } else {
            return deviceResult;
        }
    }
@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());
        }
    }