Initial import of CFM and SOAM api
Change-Id: Icf5cc2d5fb34b75460e80e8cced0d70265bcd33b
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMdManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMdManager.java
new file mode 100644
index 0000000..5a125f5
--- /dev/null
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMdManager.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.l2monitoring.cfm.impl;
+
+import java.util.Collection;
+import java.util.Optional;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.event.AbstractListenerManager;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain;
+import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation;
+import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.MdEvent;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.MdListener;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.MdStore;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.MdStoreDelegate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Manager of Cfm Md Service - persists Maintenance Domain in distributed store.
+ */
+@Component(immediate = true)
+@Service
+public class CfmMdManager extends AbstractListenerManager<MdEvent, MdListener>
+ implements CfmMdService {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ private static final String APP_ID = "org.onosproject.app.cfm";
+
+ protected ApplicationId appId;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected MdStore store;
+
+ protected final MdStoreDelegate delegate = new InternalStoreDelegate();
+
+ @Activate
+ public void activate() {
+ appId = coreService.registerApplication(APP_ID);
+
+ eventDispatcher.addSink(MdEvent.class, listenerRegistry);
+ store.setDelegate(delegate);
+
+ log.info("CFM Service Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ eventDispatcher.removeSink(MdEvent.class);
+ store.unsetDelegate(delegate);
+ log.info("CFM Service Stopped");
+ }
+
+ @Override
+ public Collection<MaintenanceDomain> getAllMaintenanceDomain() {
+ log.debug("Retrieving all MDs from distributed store");
+ return store.getAllMaintenanceDomain();
+ }
+
+ @Override
+ public Optional<MaintenanceDomain> getMaintenanceDomain(MdId mdName) {
+ log.debug("Retrieving MD {} from distributed store", mdName);
+ return store.getMaintenanceDomain(mdName);
+ }
+
+ @Override
+ public boolean deleteMaintenanceDomain(MdId mdName) throws CfmConfigException {
+ log.info("Deleting MD {} from distributed store", mdName);
+ return store.deleteMaintenanceDomain(mdName);
+ }
+
+ @Override
+ public Collection<MaintenanceAssociation> getAllMaintenanceAssociation(MdId mdName) {
+ log.debug("Retrieving all MA of MD {} from distributed store", mdName);
+ return store.getMaintenanceDomain(mdName)
+ .orElseThrow(() -> new IllegalArgumentException("Unknown MD " + mdName))
+ .maintenanceAssociationList();
+ }
+
+ @Override
+ public Optional<MaintenanceAssociation> getMaintenanceAssociation(
+ MdId mdName, MaIdShort maName) {
+ log.debug("Retrieving MA {} of MD {} from distributed store", maName, mdName);
+ return store.getMaintenanceDomain(mdName)
+ .orElseThrow(() -> new IllegalArgumentException("Unknown MD " + mdName))
+ .maintenanceAssociationList()
+ .stream().filter(ma -> ma.maId().equals(maName))
+ .findFirst();
+ }
+
+ @Override
+ public boolean deleteMaintenanceAssociation(MdId mdName, MaIdShort maName) throws CfmConfigException {
+ log.info("Deleting MA {} of MD {} from distributed store", maName, mdName);
+ MaintenanceDomain.MdBuilder builder = DefaultMaintenanceDomain
+ .builder(store.getMaintenanceDomain(mdName)
+ .orElseThrow(() -> new IllegalArgumentException("Unknown MD: " + mdName)));
+
+ //Check the MA is present
+ if (!builder.checkMaExists(maName)) {
+ return false;
+ }
+
+ builder = builder.deleteFromMaList(maName);
+
+ store.createUpdateMaintenanceDomain(builder.build());
+ return true;
+ }
+
+ @Override
+ public boolean createMaintenanceDomain(MaintenanceDomain newMd) throws CfmConfigException {
+ log.info("Creating/Updating MD {} in distributed store", newMd.mdId());
+ return store.createUpdateMaintenanceDomain(newMd);
+ }
+
+ @Override
+ public boolean createMaintenanceAssociation(MdId mdName, MaintenanceAssociation newMa)
+ throws CfmConfigException {
+ log.info("Updating MD {} in distributed store by adding new MA {}", mdName, newMa.maId());
+ MaintenanceDomain.MdBuilder builder = DefaultMaintenanceDomain
+ .builder(store.getMaintenanceDomain(mdName)
+ .orElseThrow(() -> new IllegalArgumentException("Unknown MD: " + mdName)));
+
+ boolean replaced = false;
+ //Check the MA is present
+ if (builder.checkMaExists(newMa.maId())) {
+ builder = builder.deleteFromMaList(newMa.maId());
+ replaced = true;
+ }
+
+ builder.addToMaList(newMa);
+ store.createUpdateMaintenanceDomain(builder.build());
+ return replaced;
+ }
+
+ private class InternalStoreDelegate implements MdStoreDelegate {
+ @Override
+ public void notify(MdEvent event) {
+ log.debug("New MD event: {}", event.subject());
+ eventDispatcher.post(event);
+ }
+ }
+
+}
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMepManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMepManager.java
new file mode 100644
index 0000000..5723466
--- /dev/null
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMepManager.java
@@ -0,0 +1,292 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.l2monitoring.cfm.impl;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onosproject.core.CoreService;
+import org.onosproject.core.IdGenerator;
+import org.onosproject.event.AbstractListenerManager;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep;
+import org.onosproject.incubator.net.l2monitoring.cfm.MepEntry;
+import org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate;
+import org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepEvent;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepListener;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.device.DeviceEvent;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceService;
+import org.slf4j.Logger;
+
+/**
+ * Provides implementation of the CFM North and South Bound Interfaces.
+ */
+@Component(immediate = true)
+@Service
+public class CfmMepManager
+ extends AbstractListenerManager<CfmMepEvent, CfmMepListener>
+ implements CfmMepService {
+
+ private final Logger log = getLogger(getClass());
+
+ private final DeviceListener deviceListener = new InternalDeviceListener();
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceService deviceService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected MastershipService mastershipService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CfmMdService cfmMdService;
+
+ private static final int DEFAULT_POLL_FREQUENCY = 30;
+ private int fallbackMepPollFrequency = DEFAULT_POLL_FREQUENCY;
+
+ private IdGenerator idGenerator;
+
+ //FIXME Get rid of this hack - we will use this in memory to emulate
+ // a store for the short term.
+ //Note: This is not distributed and will not work in a clustered system
+ //TODO Create a MepStore for this
+ private Collection<Mep> mepCollection;
+
+
+ @Activate
+ public void activate() {
+ //FIXME Get rid of this local list
+ mepCollection = new ArrayList<>();
+
+ eventDispatcher.addSink(CfmMepEvent.class, listenerRegistry);
+ deviceService.addListener(deviceListener);
+ idGenerator = coreService.getIdGenerator("mep-ids");
+ log.info("CFM MEP Manager Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ deviceService.removeListener(deviceListener);
+ eventDispatcher.removeSink(CfmMepEvent.class);
+ log.info("CFM MEP Manager Stopped");
+ mepCollection.clear();
+ }
+
+ @Override
+ public Collection<MepEntry> getAllMeps(MdId mdName, MaIdShort maName)
+ throws CfmConfigException {
+ //Will throw IllegalArgumentException if ma does not exist
+ cfmMdService.getMaintenanceAssociation(mdName, maName);
+
+ Collection<MepEntry> mepEntryCollection = new ArrayList<>();
+
+ for (Mep mep:mepCollection) {
+ if (mep.mdId().equals(mdName) && mep.maId().equals(maName)) {
+ DeviceId mepDeviceId = mep.deviceId();
+ if (deviceService.getDevice(mepDeviceId) == null) {
+ log.warn("Device not found/available " + mepDeviceId +
+ " for MEP: " + mdName + "/" + maName + "/" + mep.mepId());
+ continue;
+ } else if (!deviceService.getDevice(mepDeviceId)
+ .is(CfmMepProgrammable.class)) {
+ throw new CfmConfigException("Device " + mepDeviceId +
+ " does not support CfmMepProgrammable behaviour.");
+ }
+
+ log.debug("Retrieving MEP results for Mep {} in MD {}, MA {} "
+ + "on Device {}", mep.mepId(), mdName, maName, mepDeviceId);
+ mepEntryCollection.add(deviceService
+ .getDevice(mepDeviceId)
+ .as(CfmMepProgrammable.class)
+ .getMep(mdName, maName, mep.mepId()));
+ }
+ }
+
+ return mepEntryCollection;
+ }
+
+ @Override
+ public MepEntry getMep(MdId mdName, MaIdShort maName, MepId mepId) throws CfmConfigException {
+ //Will throw IllegalArgumentException if ma does not exist
+ cfmMdService.getMaintenanceAssociation(mdName, maName);
+
+ for (Mep mep : mepCollection) {
+ if (mep.mdId().equals(mdName) && mep.maId().equals(maName)
+ && mep.mepId().equals(mepId)) {
+
+ DeviceId mepDeviceId = mep.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.");
+ }
+
+ log.debug("Retrieving MEP reults for Mep {} in MD {}, MA {} on Device {}",
+ mep.mepId(), mdName, maName, mepDeviceId);
+
+ return deviceService.getDevice(mepDeviceId)
+ .as(CfmMepProgrammable.class).getMep(mdName, maName, mepId);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public boolean deleteMep(MdId mdName, MaIdShort maName, MepId mepId) throws CfmConfigException {
+ //Will throw IllegalArgumentException if ma does not exist
+ cfmMdService.getMaintenanceAssociation(mdName, maName);
+
+ for (Mep mep : mepCollection) {
+ if (mep.mdId().equals(mdName) && mep.maId().equals(maName)
+ && mep.mepId().equals(mepId)) {
+ Device mepDevice = deviceService.getDevice(mep.deviceId());
+ if (mepDevice == null || !mepDevice.is(CfmMepProgrammable.class)) {
+ throw new CfmConfigException("Unexpeced fault on device drier for "
+ + mep.deviceId());
+ }
+ boolean deleted = false;
+ try {
+ deleted = mepDevice.as(CfmMepProgrammable.class)
+ .deleteMep(mdName, maName, mepId);
+ } catch (CfmConfigException e) {
+ log.warn("MEP could not be deleted on device - perhaps it "
+ + "does not exist. Continuing");
+ mepCollection.remove(mep);
+ return false;
+ }
+ if (deleted) {
+ mepCollection.remove(mep);
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean createMep(MdId mdName, MaIdShort maName, Mep newMep) throws CfmConfigException {
+ log.debug("Creating MEP " + newMep.mepId() + " on MD {}, MA {} on Device {}",
+ mdName, maName, newMep.deviceId().toString());
+ for (Mep mep : mepCollection) {
+ if (mep.mdId().equals(mdName) && mep.maId().equals(maName)
+ && mep.mepId().equals(newMep.mepId())) {
+ 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) {
+ return mepCollection.add(newMep);
+ } else {
+ return deviceResult;
+ }
+ }
+
+ @Override
+ public void transmitLoopback(MdId mdName, MaIdShort maName,
+ MepId mepId, MepLbCreate lbCreate) throws CfmConfigException {
+ for (Mep mep : mepCollection) {
+ if (mep.mdId().equals(mdName) && mep.maId().equals(maName)
+ && mep.mepId().equals(mepId)) {
+ log.debug("Transmitting Loopback on MEP {}/{}/{} on Device {}",
+ mdName, maName, mepId, mep.deviceId());
+ deviceService.getDevice(mep.deviceId())
+ .as(CfmMepProgrammable.class)
+ .transmitLoopback(mdName, maName, mepId, lbCreate);
+ return;
+ }
+ }
+ throw new CfmConfigException("Mep " + mdName + "/" + maName + "/"
+ + mepId + " not found when calling Transmit Loopback");
+ }
+
+ @Override
+ public void abortLoopback(MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException {
+ for (Mep mep : mepCollection) {
+ if (mep.mdId().equals(mdName) && mep.maId().equals(maName)
+ && mep.mepId().equals(mepId)) {
+ log.debug("Aborting Loopback on MEP {}/{}/{} on Device {}",
+ mdName, maName, mepId, mep.deviceId());
+ deviceService.getDevice(mep.deviceId())
+ .as(CfmMepProgrammable.class)
+ .abortLoopback(mdName, maName, mepId);
+ return;
+ }
+ }
+ throw new CfmConfigException("Mep " + mdName + "/" + maName + "/"
+ + mepId + " not found when calling Transmit Loopback");
+ }
+
+ @Override
+ public void transmitLinktrace(MdId mdName, MaIdShort maName, MepId mepId,
+ MepLtCreate ltCreate) {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ private class InternalDeviceListener implements DeviceListener {
+ @Override
+ public void event(DeviceEvent event) {
+ switch (event.type()) {
+ case DEVICE_REMOVED:
+ case DEVICE_AVAILABILITY_CHANGED:
+ DeviceId deviceId = event.subject().id();
+ if (!deviceService.isAvailable(deviceId)) {
+ log.warn("Device {} has been removed or changed", deviceId);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+}
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/DistributedMdStore.java b/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/DistributedMdStore.java
new file mode 100644
index 0000000..964a56a
--- /dev/null
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/DistributedMdStore.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.l2monitoring.cfm.impl;
+
+import com.google.common.net.InternetDomainName;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onlab.packet.MacAddress;
+import org.onlab.util.Identifier;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultComponent;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain;
+import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation;
+import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaId2Octet;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdIccY1731;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdPrimaryVid;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdRfc2685VpnId;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdDomainName;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdMacUint;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdNone;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.MdEvent;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.MdStore;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.MdStoreDelegate;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.AbstractStore;
+import org.onosproject.store.service.ConsistentMap;
+import org.onosproject.store.service.MapEvent;
+import org.onosproject.store.service.MapEventListener;
+import org.onosproject.store.service.Serializer;
+import org.onosproject.store.service.StorageService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Maintenance Domain Store implementation backed by consistent map.
+ */
+@Component(immediate = true)
+@Service
+public class DistributedMdStore extends AbstractStore<MdEvent, MdStoreDelegate>
+ implements MdStore {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected StorageService storageService;
+
+ private ConsistentMap<MdId, MaintenanceDomain> maintenanceDomainConsistentMap;
+ private Map<MdId, MaintenanceDomain> maintenanceDomainMap;
+
+ private final InternalMdListener listener = new InternalMdListener();
+
+ @Activate
+ public void activate() {
+ maintenanceDomainConsistentMap = storageService
+ .<MdId, MaintenanceDomain>consistentMapBuilder()
+ .withName("onos-cfm-ma-map")
+ .withSerializer(Serializer.using(new KryoNamespace.Builder()
+ .register(KryoNamespaces.API)
+ .register(DefaultMaintenanceDomain.class)
+ .register(MdIdCharStr.class)
+ .register(MdIdDomainName.class)
+ .register(MdIdMacUint.class)
+ .register(MdIdNone.class)
+ .register(MaintenanceDomain.MdLevel.class)
+ .register(DefaultMaintenanceAssociation.class)
+ .register(MaIdCharStr.class)
+ .register(MaIdShort.class)
+ .register(MaId2Octet.class)
+ .register(MaIdIccY1731.class)
+ .register(MaIdPrimaryVid.class)
+ .register(MaIdRfc2685VpnId.class)
+ .register(MaintenanceAssociation.CcmInterval.class)
+ .register(DefaultComponent.class)
+ .register(MepId.class)
+ .register(Identifier.class)
+ .register(InternetDomainName.class)
+ .register(MacAddress.class)
+ .register(ImmutablePair.class)
+ .register(org.onosproject.incubator.net.l2monitoring
+ .cfm.Component.MhfCreationType.class)
+ .register(org.onosproject.incubator.net.l2monitoring
+ .cfm.Component.IdPermissionType.class)
+ .register(org.onosproject.incubator.net.l2monitoring
+ .cfm.Component.TagType.class)
+ .build("md")))
+ .build();
+
+ maintenanceDomainMap = maintenanceDomainConsistentMap.asJavaMap();
+ }
+
+ @Override
+ public Collection<MaintenanceDomain> getAllMaintenanceDomain() {
+ return maintenanceDomainMap.values();
+ }
+
+ @Override
+ public Optional<MaintenanceDomain> getMaintenanceDomain(MdId mdName) {
+ return Optional.ofNullable(
+ maintenanceDomainMap.get(mdName));
+ }
+
+ @Override
+ public boolean deleteMaintenanceDomain(MdId mdName) {
+ return maintenanceDomainMap.remove(mdName) == null ? false : true;
+ }
+
+ @Override
+ public boolean createUpdateMaintenanceDomain(MaintenanceDomain md) {
+ return maintenanceDomainMap.put(md.mdId(), md) == null ? false : true;
+ }
+
+ private class InternalMdListener implements MapEventListener<MdId, MaintenanceDomain> {
+ @Override
+ public void event(MapEvent<MdId, MaintenanceDomain> mapEvent) {
+ final MdEvent.Type type;
+ switch (mapEvent.type()) {
+ case INSERT:
+ type = MdEvent.Type.MD_ADDED;
+ break;
+ case UPDATE:
+ type = MdEvent.Type.MD_UPDATED;
+ break;
+ case REMOVE:
+ default:
+ type = MdEvent.Type.MD_REMOVED;
+ break;
+ }
+ notifyDelegate(new MdEvent(type, mapEvent.key()));
+ }
+ }
+}
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/package-info.java b/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/package-info.java
new file mode 100644
index 0000000..3542f07
--- /dev/null
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * An implementation of Layer 2 CFM (Connectivity Fault Management).
+ */
+package org.onosproject.incubator.net.l2monitoring.cfm.impl;
\ No newline at end of file