Refactor of CFM code part2 - API
Change-Id: Id1407e140b561fbe7ab79e0726f50e9276f3e20b
diff --git a/apps/cfm/BUCK b/apps/cfm/BUCK
index 6f1cef6..687badd 100644
--- a/apps/cfm/BUCK
+++ b/apps/cfm/BUCK
@@ -1,6 +1,6 @@
BUNDLES = [
-# '//apps/cfm/api:onos-apps-cfm-api',
-# '//apps/cfm/app:onos-apps-cfm-app',
+ '//apps/cfm/api:onos-apps-cfm-api',
+ '//apps/cfm/app:onos-apps-cfm-app',
'//apps/cfm/nbi:onos-apps-cfm-nbi',
]
diff --git a/apps/cfm/api/BUCK b/apps/cfm/api/BUCK
new file mode 100644
index 0000000..ab6251e
--- /dev/null
+++ b/apps/cfm/api/BUCK
@@ -0,0 +1,14 @@
+COMPILE_DEPS = [
+ '//lib:CORE_DEPS',
+]
+
+TEST_DEPS = [
+ '//lib:TEST_ADAPTERS',
+]
+
+osgi_jar_with_tests (
+ deps = COMPILE_DEPS,
+ test_deps = TEST_DEPS,
+ visibility = ['PUBLIC'],
+)
+
diff --git a/apps/cfm/api/README.md b/apps/cfm/api/README.md
new file mode 100644
index 0000000..6123509
--- /dev/null
+++ b/apps/cfm/api/README.md
@@ -0,0 +1,168 @@
+# Layer 2 Monitoring with CFM and SOAM in ONOS
+
+Connectivity Fault Management (CFM) was first introduced in IEEE 802.1ag, which
+has been superseded by IEEE 802.1Q-2011 and subsequently by IEEE 802.1Q-2014 -
+the IEEE Standard for Local and metropolitan area networks - Bridges and Bridged
+Networks.
+
+It defines protocols and practices for OAM (Operations, Administration, and
+Maintenance) for paths through 802.1 bridges and local area networks (LANs).
+It is an amendment to IEEE 802.1Q-2005 and was approved in 2007.
+
+IEEE 802.1ag is largely identical with ITU-T Recommendation Y.1731, which
+additionally addresses performance monitoring.
+
+In addition the Metro Ethernet Forum (MEF) has defined SOAM (Service Operations
+Administration and Management) in MEF-17 on top of these standards to build a
+framework for monitoring in conjunction with MEF services. This and other MEF
+standards are available in their technical documentation section.
+
+## Modelling
+Working these combined standards into a unified model is a complex task an
+inevitably requires some compromises. For instance while 802.1Q talks about
+Maintenance Domains and Maintenance Associations the MEF 17 standard uses the
+name Maintenance Entity (ME) and Maintenance Entity Group (MEG). MEF 38 and 39
+defines a model that encompasses all of the concepts as a set of YANG modules,
+that separate out the Monitoring aspects of MEF 17 from MEF Carrier Ethernet
+Services. In this way a loose coupling exists between the CFM and MEF Services
+linked together only through VLAN ids.
+
+MEF 38 defines a root object mef-cfm which represents 802.1Q and Y.1731 CFM
+entities, which is augmented by mef-soam-fm which adds on additional attributes
+and operations from SOAM related to fault management.
+
+MEF 39 augments mef-cfm further with the performance management aspects of SOAM
+as mef-soam-pm including monitoring of delay, jitter and loss measurements.
+
+These YANG models act as a unified definition of these standards that it makes
+practical sense to reuse in ONOS.
+
+## Implementation in ONOS
+Direct translation of the MEF 38 and MEF 39 YANG models into ONOS does not provide
+a completely clean way to define the models in ONOS, because of the complication
+brought by the augments. Instead the models have been defined independently in
+ONOS as a new structure under reusing common ONOS classes such as DeviceId,
+PortNumber, NetworkResource, Identifier, MacAddress etc.
+
+* onos/incubator/src/main/java/org/onosproject/api/net/l2monitoring/cfm
+* onos/incubator/src/main/java/org/onosproject/api/net/l2monitoring/soam
+
+## Java Model
+These immutable objects are defined as Java POJOs with little dependencies on
+outside elements, and built the familiar builder pattern.
+
+As with 802.1Q the model’s top level starts with the Maintenance Domain - an
+abstract reference object defining the span of the domain of activity for
+maintenance in the network. Maintenance Domains are defined at 8 different levels
+to indicate the scope of their span.
+
+Beneath the Maintenance Domain is the Maintenance Association, another abstract
+object specific to a VLAN that contains common parameters for a group of MEPs
+(Maintenance Association Endpoints). It is these MEPs that are created on devices
+in the network and can be thought of as monitoring points. Devices must support
+the CfmMepProgrammable behaviour to support the creation of MEPs.
+
+The MEP is the key item then that allows specific actions to be taken on devices
+such as
+
+* Continuity Check Messaging (CCM)
+* Loopback testing
+* Linktrace testing
+
+In addition these MEPs allow the creation of
+* Delay Measurement entities (which run tests for Delay and Jitter on a continuous basis)
+* Loss Measurement entities (which run tests for Loss Measurement on a continuous basis)
+
+The following shows the structure of Java classes defined in ONOS to represent
+these entities.
+
+`Maintenance-Domain*`<br/>
+ `|-MdId` (MdIdCharStr or MdIdDomainName or MdIdMacUint or MdIdNone)<br/>
+ `|-Maintenance-Association*`<br/>
+ `|-MaIdShort` (MaIdCharStr or MaIdPrimaryVid or Ma2Octet
+ or MaIdRfc2685VpnId or MaIdIccY1731)<br/>
+ `|-Component*`<br/>
+ `|-Mep*` (Maintenance-Association-EndPoint) and MepEntry*<br/>
+ | `|-MepId`<br/>
+ | `|-MepLbEntry`<br/>
+ | `|-MepLtEntry`<br/>
+ | | `|-MepLtTransactionEntry*`<br/>
+ | | `|-MepLtReply*`<br/>
+ | | `|-SenderIdTlv`<br/>
+ | `|-DelayMeasurement*` (SOAM)<br/>
+ | | `|-DmId`<br/>
+ | | `|-DelayMeasurement-Stat-Current`<br/>
+ | | |`-DelayMeasurement-Stat-History*`<br/>
+ | |`-LossMeasurement*` (SOAM)<br/>
+ | | `|-LmId`<br/>
+ | | `|-LossMeasurement-Stat-Current`<br/>
+ | | `|-LossMeasurement-Stat-History*`<br/>
+ | `|-RemoteMepEntry*`<br/>
+ | `|-MepId`<br/>
+ `|-RemoteMepId`<br/>
+
+
+The classes and interfaces can be broken down into 4 main categories:
+* Those used as identifiers
+* Those for configuring the object
+* Those representing both the status attributes of the object and its
+configuration (usually ending in Entry)
+* Those used in commands called on objects - for Loopback, Linktrace, Delay and
+Loss Measurement these are not configured - they are called as a method with
+parameters
+
+
+# Java Services
+A set of services are defined for managing the object model
+* CFM MD Service
+* CFM MEP Service
+* SOAM Service
+
+## CFM MD Service
+This is an interface that manages only the configuration of Maintenance Domain
+and Maintenance Association. It acts as a standalone service in ONOS that manages
+only these 2 levels of the model. The Maintenance Domain contains a list of
+Maintenance Associations does not contain Meps - these are left to the CfmMepService.
+
+These objects are persisted in ONOS in a distributed data store by this service.
+
+There are CLI commands for creating, deleting and modifying these objects.
+* cfm-md-list-all - Lists all CFM Maintenance Domains.
+* cfm-md-list - Lists a single CFM Maintenance Domain.
+* cfm-md-add - Add a CFM Maintenance Domain.
+* cfm-md-delete - Delete a CFM Maintenance Domain and its children.
+* cfm-ma-add - Add a CFM Maintenance Association to a Maintenance Domain.
+* cfm-ma-delete - Delete a CFM Maintenance Association and its children.
+
+## CFM MEP Service
+This is an interface that manages the MEP and objects and commands below it. A
+MEP managed under this service has a reference to the Maintenance Domain and
+Maintenance Association above it.
+
+MEPs are identified by a combination of MdId, MaID and MepId.
+
+The service has the following actions associated with it
+* Create MEP
+* Delete MEP
+* Get all MEPs (for a particular MD and MA)
+* Get individual MEP
+* Transmit Loopback
+* Abort Loopback
+* Transmit Linktrace
+* Create Test Signal
+* Abort Test Signal
+
+At the moment the MEP object is only maintained in memory and not persisted in
+the ONOS data store. The objects Loopback, Linktrace, Test Signal, Loss
+Measurement and Delay Measurement are not maintained in ONOS at all as they are
+not really configuration objects. They are called on the fly and are passed down
+as a collection of method parameters to the device implementing the MEP. This
+device will operate on them and their results can be obtained by querying the
+responsible MEP on the device. For instance the results of LinkTrace, Loopback
+and Test Signal will appear in the MepLbEntry, MepLbEntry and MepTsEntry under
+the MepEntry when the “Get Individual Mep” method is called.
+
+See in
+* apps/cfm/src/test/resources/examples
+
+for some JSON examples that can be used to activate this functionality.
\ No newline at end of file
diff --git a/apps/cfm/api/pom.xml b/apps/cfm/api/pom.xml
new file mode 100644
index 0000000..06c0a95
--- /dev/null
+++ b/apps/cfm/api/pom.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2018-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>onos-apps-cfm</artifactId>
+ <groupId>org.onosproject</groupId>
+ <version>1.13.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>onos-apps-cfm-api</artifactId>
+
+ <packaging>bundle</packaging>
+ <description>API for CFM applications</description>
+ <version>1.13.0-SNAPSHOT</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onlab-misc</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ <scope>test</scope>
+ <classifier>tests</classifier>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onlab-junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
+
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/Component.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/Component.java
new file mode 100644
index 0000000..9c3e726
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/Component.java
@@ -0,0 +1,177 @@
+/*
+ * 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;
+
+import com.google.common.annotations.Beta;
+import org.onlab.packet.EthType;
+import org.onlab.packet.VlanId;
+
+import java.util.Collection;
+
+/**
+ * Components which can be managed in a manner equivalent to an 802.1Q bridge.
+ *
+ * Direct child of the {@link org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation}.
+ */
+public interface Component {
+
+ int componentId();
+
+ /**
+ * The VID(s) monitored by this MA, or 0, if the MA is not attached to any VID.
+ *
+ * The first VID returned is the MA's Primary VID
+ * @return A collection of VIDs
+ */
+ Collection<VlanId> vidList();
+
+ /**
+ * Defines how the MA can create MHFs (MIP Half Function) for this VID at this MA.
+ * @return An enumerated value
+ */
+ MhfCreationType mhfCreationType();
+
+ /**
+ * indicates what, if anything, is to be included in the Sender ID TLV.
+ * The Sender ID TLV is transmitted by MPs configured in this MA.
+ * @return An enumerated value
+ */
+ IdPermissionType idPermission();
+
+ /**
+ * Indicates the tag type for this component.
+ * @return The type of Tag active on this VLAN
+ */
+ @Beta
+ TagType tagType();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.Component}.
+ */
+ interface ComponentBuilder {
+
+ ComponentBuilder addToVidList(VlanId vid);
+
+ ComponentBuilder mhfCreationType(MhfCreationType mhfCreationType);
+
+ ComponentBuilder idPermission(IdPermissionType idPermission);
+
+ ComponentBuilder tagType(TagType tagType);
+
+ Component build();
+ }
+
+ /**
+ * An enumerated type defining how MHFs (MIP Half Function) can be created.
+ */
+ public enum MhfCreationType {
+ /**
+ * No MHFs can be created for this VID(s).
+ */
+ NONE,
+
+ /**
+ * MHFs can be created for this VID(s) on any Bridge Port through which the.
+ * VID(s) can pass where:
+ * - There are no lower active MD levels; or
+ * - There is a MEP at the next lower active MD-level on the port
+ */
+ DEFAULT,
+
+ /**
+ * MHFs can be created for this VID(s) only on Bridge Ports through which.
+ * this VID(s) can pass, and only if there is a MEP at the next
+ * lower active MD-level on the port.
+ */
+ EXPLICIT,
+
+ /**
+ * In the Maintenance Association managed object only, the control of MHF.
+ * creation is deferred to the corresponding variable in the
+ * enclosing Maintenance Domain
+ */
+ DEFER
+ }
+
+ /**
+ * An enumerated value indicating what, if anything, is to be included in.
+ * the Sender ID TLV transmitted by maintenance-points configured in the
+ * default Maintenance Domain
+ * reference
+ * [802.1q] 21.5.3, 12.14.3.1.3:e";
+ */
+ public enum IdPermissionType {
+ /**
+ * The Sender ID TLV is not to be sent.
+ */
+ NONE,
+
+ /**
+ * The Chassis ID Length, Chassis ID Subtype, and Chassis ID fields of the.
+ * Sender ID TLV are to be sent, but not the Management Address
+ * Length or Management Address fields.
+ */
+ CHASSIS,
+
+ /**
+ * The Management Address Length and Management Address of the Sender ID.
+ * TLV are to be sent, but the Chassis ID Length is to be
+ * transmitted with a 0 value, and the Chassis ID Subtype and
+ * Chassis ID fields not sent
+ */
+ MANAGE,
+
+ /**
+ * The Chassis ID Length, Chassis ID Subtype, Chassis ID, Management.
+ * Address Length, and Management Address fields are all to be sent
+ */
+ CHASSIS_MANAGE,
+
+ /**
+ * The contents of the Sender ID TLV are determined by the Maintenance.
+ * Domain managed object
+ */
+ DEFER
+ }
+
+ /**
+ * A choice of VLan tag type.
+ */
+ public enum TagType {
+ VLAN_NONE(EthType.EtherType.IPV4),
+ VLAN_CTAG(EthType.EtherType.VLAN),
+ VLAN_STAG(EthType.EtherType.QINQ);
+
+ private EthType.EtherType type = EthType.EtherType.IPV4;
+
+ TagType(EthType.EtherType type) {
+ this.type = type;
+ }
+
+ public EthType.EtherType getType() {
+ return type;
+ }
+
+ public static TagType fromEtherType(EthType.EtherType type) {
+ for (TagType tt:values()) {
+ if (tt.type.equals(type)) {
+ return tt;
+ }
+ }
+ throw new IllegalArgumentException("Unsupported EtherType: " + type);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultComponent.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultComponent.java
new file mode 100644
index 0000000..e8f43ae
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultComponent.java
@@ -0,0 +1,166 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import com.google.common.collect.Lists;
+import org.onlab.packet.VlanId;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.cfm.Component}.
+ */
+public final class DefaultComponent implements Component {
+
+ private final int componentId;
+ private final Collection<VlanId> vidList;
+ private final MhfCreationType mhfCreationType;
+ private final IdPermissionType idPermission;
+ private final TagType tagType;
+
+ private DefaultComponent(DefaultComponentBuilder builder) {
+ this.componentId = builder.componentId;
+ this.vidList = builder.vidList;
+ this.mhfCreationType = builder.mhfCreationType;
+ this.idPermission = builder.idPermission;
+ this.tagType = builder.tagType;
+ }
+
+ @Override
+ public int componentId() {
+ return componentId;
+ }
+
+ @Override
+ public Collection<VlanId> vidList() {
+ if (vidList != null) {
+ return Lists.newArrayList(vidList);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public MhfCreationType mhfCreationType() {
+ return mhfCreationType;
+ }
+
+ @Override
+ public IdPermissionType idPermission() {
+ return idPermission;
+ }
+
+ @Override
+ public TagType tagType() {
+ return tagType;
+ }
+
+
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + componentId;
+ result = prime * result
+ + ((idPermission == null) ? 0 : idPermission.hashCode());
+ result = prime * result
+ + ((mhfCreationType == null) ? 0 : mhfCreationType.hashCode());
+ result = prime * result + ((tagType == null) ? 0 : tagType.hashCode());
+ result = prime * result + ((vidList == null) ? 0 : vidList.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ DefaultComponent other = (DefaultComponent) obj;
+ if (componentId != other.componentId) {
+ return false;
+ }
+ if (idPermission != other.idPermission) {
+ return false;
+ }
+ if (mhfCreationType != other.mhfCreationType) {
+ return false;
+ }
+ if (tagType != other.tagType) {
+ return false;
+ }
+ if (vidList == null) {
+ if (other.vidList != null) {
+ return false;
+ }
+ } else if (!vidList.equals(other.vidList)) {
+ return false;
+ }
+ return true;
+ }
+
+ public static ComponentBuilder builder(int componentId) {
+ return new DefaultComponentBuilder(componentId);
+ }
+
+ private static final class DefaultComponentBuilder implements ComponentBuilder {
+ private final int componentId;
+ private Collection<VlanId> vidList;
+ private MhfCreationType mhfCreationType;
+ private IdPermissionType idPermission;
+ private TagType tagType;
+
+ private DefaultComponentBuilder(int componentId) {
+ this.componentId = componentId;
+ vidList = new ArrayList<>();
+ }
+
+ @Override
+ public ComponentBuilder addToVidList(VlanId vid) {
+ this.vidList.add(vid);
+ return this;
+ }
+
+ @Override
+ public ComponentBuilder mhfCreationType(MhfCreationType mhfCreationType) {
+ this.mhfCreationType = mhfCreationType;
+ return this;
+ }
+
+ @Override
+ public ComponentBuilder idPermission(IdPermissionType idPermission) {
+ this.idPermission = idPermission;
+ return this;
+ }
+
+ @Override
+ public ComponentBuilder tagType(TagType tagType) {
+ this.tagType = tagType;
+ return this;
+ }
+
+ public Component build() {
+ return new DefaultComponent(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMaintenanceAssociation.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMaintenanceAssociation.java
new file mode 100644
index 0000000..38c3d6f
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMaintenanceAssociation.java
@@ -0,0 +1,248 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.Lists;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation}.
+ */
+public final class DefaultMaintenanceAssociation implements MaintenanceAssociation {
+
+ private MaIdShort maId;
+ private final CcmInterval ccmInterval;
+ private final Collection<Component> componentList;
+ private final Collection<MepId> remoteMepIdList;
+ private final short maNumericId;
+
+ private DefaultMaintenanceAssociation(DefaultMaBuilder builder)
+ throws CfmConfigException {
+ this.maId = builder.maId;
+ this.ccmInterval = builder.ccmInterval;
+ this.componentList = builder.componentList;
+ this.remoteMepIdList = builder.remoteMepIdList;
+ this.maNumericId = builder.maNumericId;
+ }
+
+ private DefaultMaintenanceAssociation(MaintenanceAssociation ma,
+ AttributeName attrName, Object attrValue) {
+ this.maId = ma.maId();
+ this.ccmInterval = ma.ccmInterval();
+
+ if (attrName == AttributeName.COMPONENTLIST) {
+ this.componentList = (Collection<Component>) attrValue;
+ } else {
+ this.componentList = ma.componentList();
+ }
+
+ if (attrName == AttributeName.REMOTEMEPIDLIST) {
+ this.remoteMepIdList = (Collection<MepId>) attrValue;
+ } else {
+ this.remoteMepIdList = ma.remoteMepIdList();
+ }
+
+ this.maNumericId = ma.maNumericId();
+ }
+
+ @Override
+ public MaIdShort maId() {
+ return maId;
+ }
+
+ @Override
+ public CcmInterval ccmInterval() {
+ return ccmInterval;
+ }
+
+ @Override
+ public Collection<Component> componentList() {
+ if (componentList != null) {
+ return Lists.newArrayList(componentList);
+ }
+ return Lists.newArrayList();
+ }
+
+ @Override
+ public MaintenanceAssociation withComponentList(Collection<Component> componentList) {
+ return new DefaultMaintenanceAssociation(this, AttributeName.COMPONENTLIST, componentList);
+ }
+
+ @Override
+ public Collection<MepId> remoteMepIdList() {
+ if (remoteMepIdList != null) {
+ return Lists.newArrayList(remoteMepIdList);
+ }
+ return Lists.newArrayList();
+ }
+
+ @Override
+ public MaintenanceAssociation withRemoteMepIdList(Collection<MepId> remoteMepIdList) {
+ return new DefaultMaintenanceAssociation(this, AttributeName.REMOTEMEPIDLIST, remoteMepIdList);
+ }
+
+ @Override
+ public short maNumericId() {
+ return maNumericId;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((ccmInterval == null) ? 0 : ccmInterval.hashCode());
+ result = prime * result
+ + ((componentList == null) ? 0 : componentList.hashCode());
+ result = prime * result + ((maId == null) ? 0 : maId.hashCode());
+ result = prime * result
+ + ((remoteMepIdList == null) ? 0 : remoteMepIdList.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ DefaultMaintenanceAssociation other = (DefaultMaintenanceAssociation) obj;
+ if (ccmInterval != other.ccmInterval) {
+ return false;
+ }
+ if (componentList == null) {
+ if (other.componentList != null) {
+ return false;
+ }
+ } else if (!componentList.equals(other.componentList)) {
+ return false;
+ }
+ if (!maId.equals(other.maId)) {
+ return false;
+ }
+ if (remoteMepIdList == null) {
+ if (other.remoteMepIdList != null) {
+ return false;
+ }
+ } else if (!remoteMepIdList.equals(other.remoteMepIdList)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).add("maId", maId).toString();
+ }
+
+ public static MaBuilder builder(MaIdShort maId, int mdNameAndTypeLen)
+ throws CfmConfigException {
+ return new DefaultMaBuilder(maId, mdNameAndTypeLen);
+ }
+
+ public static MaBuilder builder(MaintenanceAssociation ma)
+ throws CfmConfigException {
+ return new DefaultMaBuilder(ma);
+ }
+
+ private static final class DefaultMaBuilder implements MaintenanceAssociation.MaBuilder {
+
+ private final MaIdShort maId;
+ private CcmInterval ccmInterval;
+ private Collection<Component> componentList;
+ private Collection<MepId> remoteMepIdList;
+ private short maNumericId;
+
+ public DefaultMaBuilder(MaIdShort maId, int mdNameAndTypeLen)
+ throws CfmConfigException {
+ if (maId.getNameLength() + mdNameAndTypeLen > 48) {
+ throw new CfmConfigException("Combined length of MD name and "
+ + "MA name exceeds 48. Cannot create");
+ }
+ this.maId = maId;
+ this.componentList = new ArrayList<>();
+ this.remoteMepIdList = new ArrayList<>();
+ }
+
+ public DefaultMaBuilder(MaintenanceAssociation ma)
+ throws CfmConfigException {
+
+ this.maId = ma.maId();
+ this.maNumericId = ma.maNumericId();
+ this.componentList = new ArrayList<>();
+ ma.componentList().forEach(comp -> this.componentList.add(comp));
+ this.remoteMepIdList = new ArrayList<>();
+ ma.remoteMepIdList().forEach((rmep -> this.remoteMepIdList.add(rmep)));
+ }
+
+ @Override
+ public MaBuilder addToComponentList(Component component) {
+ this.componentList.add(component);
+ return this;
+ }
+
+ @Override
+ public MaBuilder addToRemoteMepIdList(MepId remoteMep) {
+ this.remoteMepIdList.add(remoteMep);
+ return this;
+ }
+
+ @Override
+ public MaBuilder removeFromRemoteMepIdList(MepId remoteMep) {
+ this.remoteMepIdList.remove(remoteMep);
+ return this;
+ }
+
+ @Override
+ public MaBuilder ccmInterval(CcmInterval ccmInterval) {
+ this.ccmInterval = ccmInterval;
+ return this;
+ }
+
+ @Override
+ public MaBuilder maNumericId(short maNumericId) {
+ if (maNumericId <= 0) {
+ throw new IllegalArgumentException(
+ "numericId must be > 0. Rejecting " + maNumericId);
+ }
+ this.maNumericId = maNumericId;
+ return this;
+ }
+
+ @Override
+ public MaintenanceAssociation build() throws CfmConfigException {
+ return new DefaultMaintenanceAssociation(this);
+ }
+ }
+
+ private enum AttributeName {
+ REMOTEMEPIDLIST,
+ COMPONENTLIST
+ }
+
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMaintenanceDomain.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMaintenanceDomain.java
new file mode 100644
index 0000000..c6e16b0
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMaintenanceDomain.java
@@ -0,0 +1,189 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+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 com.google.common.base.MoreObjects;
+import com.google.common.collect.Lists;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain}.
+ */
+public final class DefaultMaintenanceDomain implements MaintenanceDomain {
+
+ private final MdId mdId;
+ private final MdLevel mdLevel;
+ private final Collection<MaintenanceAssociation> maintenanceAssociationList;
+ private final short mdNumericId;
+
+ private DefaultMaintenanceDomain(DefaultMdBuilder builder) throws CfmConfigException {
+ this.mdId = builder.mdId;
+ this.mdLevel = builder.mdLevel;
+ this.maintenanceAssociationList = builder.maList;
+ this.mdNumericId = builder.mdNumericId;
+ }
+
+ private DefaultMaintenanceDomain(DefaultMaintenanceDomain md, Collection<MaintenanceAssociation> maList) {
+ this.mdId = md.mdId;
+ this.mdLevel = md.mdLevel;
+ this.maintenanceAssociationList = maList;
+ this.mdNumericId = md.mdNumericId;
+ }
+
+ @Override
+ public MdId mdId() {
+ return mdId;
+ }
+
+ @Override
+ public MdLevel mdLevel() {
+ return mdLevel;
+ }
+
+ @Override
+ public Collection<MaintenanceAssociation> maintenanceAssociationList() {
+ if (maintenanceAssociationList != null) {
+ return Lists.newArrayList(maintenanceAssociationList);
+ }
+ return Lists.newArrayList();
+ }
+
+ @Override
+ public MaintenanceDomain withMaintenanceAssociationList(
+ Collection<MaintenanceAssociation> maintenanceAssociationList) {
+ return new DefaultMaintenanceDomain(this, maintenanceAssociationList);
+ }
+
+ @Override
+ public short mdNumericId() {
+ return mdNumericId;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((mdId == null) ? 0 : mdId.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ DefaultMaintenanceDomain other = (DefaultMaintenanceDomain) obj;
+ if (mdId == null) {
+ if (other.mdId != null) {
+ return false;
+ }
+ } else if (!mdId.equals(other.mdId)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("mdId", mdId.toString())
+ .add("level", mdLevel).toString();
+ }
+
+ public static MdBuilder builder(MdId mdId)
+ throws CfmConfigException {
+ return new DefaultMdBuilder(mdId);
+ }
+
+ //A method for creating a builder from an existing MD
+ public static MdBuilder builder(MaintenanceDomain md)
+ throws CfmConfigException {
+ return new DefaultMdBuilder(md);
+ }
+
+
+ private static final class DefaultMdBuilder implements MaintenanceDomain.MdBuilder {
+ private final MdId mdId;
+ private MdLevel mdLevel = MdLevel.LEVEL0;
+ private Collection<MaintenanceAssociation> maList;
+ private short mdNumericId;
+
+ private DefaultMdBuilder(MdId mdId)
+ throws CfmConfigException, NumberFormatException {
+ this.mdId = mdId;
+ this.maList = new ArrayList<>();
+ }
+
+ private DefaultMdBuilder(MaintenanceDomain md)
+ throws CfmConfigException, NumberFormatException {
+ this.mdId = md.mdId();
+ this.mdNumericId = md.mdNumericId();
+ this.mdLevel = md.mdLevel();
+ this.maList = new ArrayList<>();
+ md.maintenanceAssociationList().forEach(ma -> this.maList.add(ma));
+ }
+
+ @Override
+ public MdBuilder mdLevel(MdLevel mdLevel) {
+ this.mdLevel = mdLevel;
+ return this;
+ }
+
+ @Override
+ public MdBuilder addToMaList(MaintenanceAssociation ma) {
+ this.maList.add(ma);
+ return this;
+ }
+
+ @Override
+ public MdBuilder deleteFromMaList(MaIdShort maName) {
+ this.maList.removeIf(ma -> ma.maId().equals(maName));
+ return this;
+ }
+
+ @Override
+ public boolean checkMaExists(MaIdShort maName) {
+ return this.maList.stream().anyMatch(ma -> ma.maId().equals(maName));
+ }
+
+ @Override
+ public MdBuilder mdNumericId(short mdNumericId) {
+ if (mdNumericId <= 0) {
+ throw new IllegalArgumentException(
+ "numericId must be > 0. Rejecting " + mdNumericId);
+ }
+ this.mdNumericId = mdNumericId;
+ return this;
+ }
+
+ @Override
+ public MaintenanceDomain build() throws CfmConfigException {
+ return new DefaultMaintenanceDomain(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMep.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMep.java
new file mode 100644
index 0000000..72c9769
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMep.java
@@ -0,0 +1,457 @@
+/*
+ * 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;
+
+import java.time.Duration;
+
+import org.onlab.packet.VlanId;
+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.net.DeviceId;
+import org.onosproject.net.PortNumber;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.cfm.Mep}.
+ */
+public class DefaultMep implements Mep {
+
+ protected final MepId mepId;
+ protected final DeviceId deviceId;
+ protected final PortNumber port;
+ protected final MepDirection direction;
+ protected final MdId mdId;
+ protected final MaIdShort maId;
+ protected final VlanId primaryVid;
+ protected final boolean administrativeState;
+ protected final boolean cciEnabled;
+ protected final Priority ccmLtmPriority;
+ protected final FngAddress fngAddress;
+ protected final LowestFaultDefect lowestFaultPriorityDefect;
+ protected final Duration defectPresentTime;
+ protected final Duration defectAbsentTime;
+
+ protected DefaultMep(DefaultMepBuilder mepBuilder) {
+ this.mepId = mepBuilder.mepId;
+ this.deviceId = mepBuilder.deviceId;
+ this.port = mepBuilder.port;
+ this.direction = mepBuilder.direction;
+ this.mdId = mepBuilder.mdId;
+ this.maId = mepBuilder.maId;
+ this.primaryVid = mepBuilder.primaryVid;
+ this.administrativeState = mepBuilder.administrativeState;
+ this.cciEnabled = mepBuilder.cciEnabled;
+ this.ccmLtmPriority = mepBuilder.ccmLtmPriority;
+ this.fngAddress = mepBuilder.fngAddress;
+ this.lowestFaultPriorityDefect = mepBuilder.lowestFaultPriorityDefect;
+ this.defectPresentTime = mepBuilder.defectPresentTime;
+ this.defectAbsentTime = mepBuilder.defectAbsentTime;
+ }
+
+ protected DefaultMep(DefaultMep mep, AttributeName attrName, Object attrValue) {
+ this.mepId = mep.mepId;
+ this.deviceId = mep.deviceId;
+ this.port = mep.port;
+ this.direction = mep.direction;
+ this.mdId = mep.mdId;
+ this.maId = mep.maId;
+ if (attrName == AttributeName.PRIMARY_VID) {
+ this.primaryVid = (VlanId) attrValue;
+ } else {
+ this.primaryVid = mep.primaryVid;
+ }
+ if (attrName == AttributeName.ADMINISTRATIVE_STATE) {
+ this.administrativeState = (boolean) attrValue;
+ } else {
+ this.administrativeState = mep.administrativeState;
+ }
+
+ if (attrName == AttributeName.CCI_ENABLED) {
+ this.cciEnabled = (boolean) attrValue;
+ } else {
+ this.cciEnabled = mep.cciEnabled;
+ }
+
+ if (attrName == AttributeName.CCM_LTM_PRIORITY) {
+ this.ccmLtmPriority = (Priority) attrValue;
+ } else {
+ this.ccmLtmPriority = mep.ccmLtmPriority;
+ }
+
+ if (attrName == AttributeName.FNG_ADDRESS) {
+ this.fngAddress = (FngAddress) attrValue;
+ } else {
+ this.fngAddress = mep.fngAddress;
+ }
+
+ if (attrName == AttributeName.LOWEST_FAULT_PRIORITY_DEFECT) {
+ this.lowestFaultPriorityDefect = (LowestFaultDefect) attrValue;
+ } else {
+ this.lowestFaultPriorityDefect = mep.lowestFaultPriorityDefect;
+ }
+
+ if (attrName == AttributeName.DEFECT_PRESENT_TIME) {
+ this.defectPresentTime = (Duration) attrValue;
+ } else {
+ this.defectPresentTime = mep.defectPresentTime;
+ }
+
+ if (attrName == AttributeName.DEFECT_ABSENT_TIME) {
+ this.defectAbsentTime = (Duration) attrValue;
+ } else {
+ this.defectAbsentTime = mep.defectAbsentTime;
+ }
+ }
+
+ @Override
+ public MepId mepId() {
+ return mepId;
+ }
+
+ @Override
+ public DeviceId deviceId() {
+ return deviceId;
+ }
+
+ @Override
+ public PortNumber port() {
+ return port;
+ }
+
+ @Override
+ public MepDirection direction() {
+ return direction;
+ }
+
+ @Override
+ public MdId mdId() {
+ return mdId;
+ }
+
+ @Override
+ public MaIdShort maId() {
+ return maId;
+ }
+
+ @Override
+ public VlanId primaryVid() {
+ return primaryVid;
+ }
+
+ @Override
+ public Mep withPrimaryVid(VlanId primaryVid) {
+ return new DefaultMep(this, AttributeName.PRIMARY_VID, primaryVid);
+ }
+
+ @Override
+ public boolean administrativeState() {
+ return administrativeState;
+ }
+
+ @Override
+ public Mep withAdministrativeState(boolean adminState) {
+ return new DefaultMep(this, AttributeName.ADMINISTRATIVE_STATE, adminState);
+ }
+
+ @Override
+ public Boolean cciEnabled() {
+ return cciEnabled;
+ }
+
+ @Override
+ public Mep withCciEnabled(boolean cciEnabled) {
+ return new DefaultMep(this, AttributeName.CCI_ENABLED, cciEnabled);
+ }
+
+ @Override
+ public Priority ccmLtmPriority() {
+ return ccmLtmPriority;
+ }
+
+ @Override
+ public Mep withCcmLtmPriority(Priority priority) {
+ return new DefaultMep(this, AttributeName.CCM_LTM_PRIORITY, priority);
+ }
+
+ @Override
+ public Mep withFngAddress(FngAddress fngAddress) {
+ return new DefaultMep(this, AttributeName.FNG_ADDRESS, fngAddress);
+ }
+
+ @Override
+ public FngAddress fngAddress() {
+ return fngAddress;
+ }
+
+ @Override
+ public LowestFaultDefect lowestFaultPriorityDefect() {
+ return lowestFaultPriorityDefect;
+ }
+
+ @Override
+ public Mep withLowestFaultPriorityDefect(LowestFaultDefect lowestFdType) {
+ return new DefaultMep(this, AttributeName.LOWEST_FAULT_PRIORITY_DEFECT, lowestFdType);
+ }
+
+ @Override
+ public Duration defectPresentTime() {
+ return defectPresentTime;
+ }
+
+ @Override
+ public Mep withDefectPresentTime(Duration duration) {
+ return new DefaultMep(this, AttributeName.DEFECT_PRESENT_TIME, duration);
+ }
+
+ @Override
+ public Duration defectAbsentTime() {
+ return defectAbsentTime;
+ }
+
+ @Override
+ public Mep withDefectAbsentTime(Duration duration) {
+ return new DefaultMep(this, AttributeName.DEFECT_ABSENT_TIME, duration);
+ }
+
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ DefaultMep that = (DefaultMep) o;
+
+ if (administrativeState != that.administrativeState) {
+ return false;
+ }
+ if (cciEnabled != that.cciEnabled) {
+ return false;
+ }
+ if (!mepId.equals(that.mepId)) {
+ return false;
+ }
+ if (!deviceId.equals(that.deviceId)) {
+ return false;
+ }
+ if (!port.equals(that.port)) {
+ return false;
+ }
+ if (direction != that.direction) {
+ return false;
+ }
+ if (!mdId.equals(that.mdId)) {
+ return false;
+ }
+ if (!maId.equals(that.maId)) {
+ return false;
+ }
+ if (primaryVid != null ? !primaryVid.equals(that.primaryVid) : that.primaryVid != null) {
+ return false;
+ }
+ if (ccmLtmPriority != that.ccmLtmPriority) {
+ return false;
+ }
+ if (fngAddress != null ? !fngAddress.equals(that.fngAddress) : that.fngAddress != null) {
+ return false;
+ }
+ if (lowestFaultPriorityDefect != that.lowestFaultPriorityDefect) {
+ return false;
+ }
+ if (defectPresentTime != null ?
+ !defectPresentTime.equals(that.defectPresentTime) : that.defectPresentTime != null) {
+ return false;
+ }
+ return defectAbsentTime != null ?
+ defectAbsentTime.equals(that.defectAbsentTime) : that.defectAbsentTime == null;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = mepId.hashCode();
+ result = 31 * result + deviceId.hashCode();
+ result = 31 * result + port.hashCode();
+ result = 31 * result + (direction != null ? direction.hashCode() : 0);
+ result = 31 * result + mdId.hashCode();
+ result = 31 * result + maId.hashCode();
+ result = 31 * result + (primaryVid != null ? primaryVid.hashCode() : 0);
+ result = 31 * result + (administrativeState ? 1 : 0);
+ result = 31 * result + (cciEnabled ? 1 : 0);
+ result = 31 * result + (ccmLtmPriority != null ? ccmLtmPriority.hashCode() : 0);
+ result = 31 * result + (fngAddress != null ? fngAddress.hashCode() : 0);
+ result = 31 * result + (lowestFaultPriorityDefect != null ? lowestFaultPriorityDefect.hashCode() : 0);
+ result = 31 * result + (defectPresentTime != null ? defectPresentTime.hashCode() : 0);
+ result = 31 * result + (defectAbsentTime != null ? defectAbsentTime.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "DefaultMep{" +
+ "mepId=" + mepId +
+ ", deviceId=" + deviceId +
+ ", port=" + port +
+ ", direction=" + direction +
+ ", mdId=" + mdId +
+ ", maId=" + maId +
+ ", primaryVid=" + primaryVid +
+ ", administrativeState=" + administrativeState +
+ ", cciEnabled=" + cciEnabled +
+ ", ccmLtmPriority=" + ccmLtmPriority +
+ ", fngAddress=" + fngAddress +
+ ", lowestFaultPriorityDefect=" + lowestFaultPriorityDefect +
+ ", defectPresentTime=" + defectPresentTime +
+ ", defectAbsentTime=" + defectAbsentTime +
+ '}';
+ }
+
+ public static MepBuilder builder(
+ MepId mepId,
+ DeviceId deviceId,
+ PortNumber port,
+ MepDirection direction,
+ MdId mdId,
+ MaIdShort maId)
+ throws CfmConfigException {
+ return new DefaultMepBuilder(mepId, deviceId, port, direction, mdId, maId);
+ }
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.Mep}.
+ */
+ protected static class DefaultMepBuilder implements Mep.MepBuilder {
+ protected final MepId mepId;
+ protected final DeviceId deviceId;
+ protected final PortNumber port;
+ protected final MepDirection direction;
+ protected final MdId mdId;
+ protected final MaIdShort maId;
+ protected VlanId primaryVid;
+ protected boolean administrativeState;
+ protected boolean cciEnabled;
+ protected Priority ccmLtmPriority;
+ protected FngAddress fngAddress;
+ protected LowestFaultDefect lowestFaultPriorityDefect;
+ protected Duration defectPresentTime;
+ protected Duration defectAbsentTime;
+
+ protected DefaultMepBuilder(MepId mepId, DeviceId deviceId, PortNumber port,
+ MepDirection direction, MdId mdId, MaIdShort maId)
+ throws CfmConfigException {
+ if (port.isLogical()) {
+ throw new CfmConfigException("Port must be physical. Rejecting; " + port.toString());
+ } else if (mepId == null) {
+ throw new CfmConfigException("MepId is null");
+ } else if (mdId == null) {
+ throw new CfmConfigException("MdId is null");
+ } else if (maId == null) {
+ throw new CfmConfigException("MaId is null");
+ }
+ this.mepId = mepId;
+ this.deviceId = deviceId;
+ this.port = port;
+ this.direction = direction;
+ this.mdId = mdId;
+ this.maId = maId;
+ }
+
+ public DefaultMepBuilder(Mep mep) {
+ this.mepId = mep.mepId();
+ this.deviceId = mep.deviceId();
+ this.port = mep.port();
+ this.direction = mep.direction();
+ this.mdId = mep.mdId();
+ this.maId = mep.maId();
+ this.primaryVid = mep.primaryVid();
+ this.administrativeState = mep.administrativeState();
+ this.cciEnabled = mep.cciEnabled();
+ this.ccmLtmPriority = mep.ccmLtmPriority();
+ this.fngAddress = mep.fngAddress();
+ this.lowestFaultPriorityDefect = mep.lowestFaultPriorityDefect();
+ this.defectPresentTime = mep.defectPresentTime();
+ this.defectAbsentTime = mep.defectAbsentTime();
+ }
+
+ @Override
+ public MepBuilder primaryVid(VlanId primaryVid) {
+ this.primaryVid = primaryVid;
+ return this;
+ }
+
+ @Override
+ public MepBuilder administrativeState(boolean administrativeState) {
+ this.administrativeState = administrativeState;
+ return this;
+ }
+
+ @Override
+ public MepBuilder cciEnabled(boolean cciEnabled) {
+ this.cciEnabled = cciEnabled;
+ return this;
+ }
+
+ @Override
+ public MepBuilder ccmLtmPriority(Priority ccmLtmPriority) {
+ this.ccmLtmPriority = ccmLtmPriority;
+ return this;
+ }
+
+ @Override
+ public MepBuilder fngAddress(FngAddress fngAddress) {
+ this.fngAddress = fngAddress;
+ return this;
+ }
+
+ @Override
+ public MepBuilder lowestFaultPriorityDefect(
+ LowestFaultDefect lowestFaultPriorityDefect) {
+ this.lowestFaultPriorityDefect = lowestFaultPriorityDefect;
+ return this;
+ }
+
+ @Override
+ public MepBuilder defectPresentTime(Duration defectPresentTime) {
+ this.defectPresentTime = defectPresentTime;
+ return this;
+ }
+
+ @Override
+ public MepBuilder defectAbsentTime(Duration defectAbsentTime) {
+ this.defectAbsentTime = defectAbsentTime;
+ return this;
+ }
+
+ @Override
+ public Mep build() throws CfmConfigException {
+ return new DefaultMep(this);
+ }
+ }
+
+ private enum AttributeName {
+ PRIMARY_VID,
+ ADMINISTRATIVE_STATE,
+ CCI_ENABLED,
+ CCM_LTM_PRIORITY,
+ FNG_ADDRESS,
+ LOWEST_FAULT_PRIORITY_DEFECT,
+ DEFECT_PRESENT_TIME,
+ DEFECT_ABSENT_TIME;
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMepEntry.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMepEntry.java
new file mode 100644
index 0000000..1fa255e
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMepEntry.java
@@ -0,0 +1,392 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.onlab.packet.MacAddress;
+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.soam.delay.DelayMeasurementEntry;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.Lists;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.cfm.MepEntry}.
+ */
+public final class DefaultMepEntry extends DefaultMep implements MepEntry {
+
+ private final MacAddress macAddress;
+ private final FngState fngState;
+ private final FaultDefectType highestPriorityDefect;
+ private final boolean activeRdiCcmDefect;
+ private final boolean activeMacStatusDefect;
+ private final boolean activeRemoteCcmDefect;
+ private final boolean activeErrorCcmDefect;
+ private final boolean activeXconCcmDefect;
+ private final byte[] lastErrorCcm;
+ private final byte[] lastXconCcm;
+ private final int ccmSequenceErrorCount;
+ private final int totalCcmsTransmitted;
+ private final MepLbEntry loopbackAttributes;
+ private final MepLtEntry linktraceAttributes;
+ private final Collection<RemoteMepEntry> activeRemoteMepList;
+ private final Collection<DelayMeasurementEntry> delayMeasurementList;
+ private final Collection<LossMeasurementEntry> lossMeasurementList;
+
+ private DefaultMepEntry(DefaultMepEntryBuilder mepEntryBuilder) throws CfmConfigException {
+ super((DefaultMepBuilder) DefaultMep.builder(
+ mepEntryBuilder.mepId,
+ mepEntryBuilder.deviceId,
+ mepEntryBuilder.port,
+ mepEntryBuilder.direction,
+ mepEntryBuilder.mdId,
+ mepEntryBuilder.maId)
+ .administrativeState(mepEntryBuilder.administrativeState)
+ .cciEnabled(mepEntryBuilder.cciEnabled)
+ .ccmLtmPriority(mepEntryBuilder.ccmLtmPriority));
+
+ this.macAddress = mepEntryBuilder.macAddress;
+ this.fngState = mepEntryBuilder.fngState;
+ this.highestPriorityDefect = mepEntryBuilder.highestPriorityDefect;
+ this.activeRdiCcmDefect = mepEntryBuilder.activeRdiCcmDefect;
+ this.activeMacStatusDefect = mepEntryBuilder.activeMacStatusDefect;
+ this.activeRemoteCcmDefect = mepEntryBuilder.activeRemoteCcmDefect;
+ this.activeErrorCcmDefect = mepEntryBuilder.activeErrorCcmDefect;
+ this.activeXconCcmDefect = mepEntryBuilder.activeXconCcmDefect;
+ this.lastErrorCcm = mepEntryBuilder.lastErrorCcm;
+ this.lastXconCcm = mepEntryBuilder.lastXconCcm;
+ this.ccmSequenceErrorCount = mepEntryBuilder.ccmSequenceErrorCount;
+ this.totalCcmsTransmitted = mepEntryBuilder.totalCcmsTransmitted;
+ this.loopbackAttributes = mepEntryBuilder.loopbackAttributes;
+ this.linktraceAttributes = mepEntryBuilder.linktraceAttributes;
+ this.activeRemoteMepList = mepEntryBuilder.activeRemoteMepList;
+ this.delayMeasurementList = mepEntryBuilder.delayMeasurementList;
+ this.lossMeasurementList = mepEntryBuilder.lossMeasurementList;
+ }
+
+ @Override
+ public MacAddress macAddress() {
+ return macAddress;
+ }
+
+ @Override
+ public FngState fngState() {
+ return fngState;
+ }
+
+ @Override
+ public FaultDefectType getHighestPriorityDefect() {
+ return highestPriorityDefect;
+ }
+
+ @Override
+ public boolean activeRdiCcmDefect() {
+ return activeRdiCcmDefect;
+ }
+
+ @Override
+ public boolean activeMacStatusDefect() {
+ return activeMacStatusDefect;
+ }
+
+ @Override
+ public boolean activeRemoteCcmDefect() {
+ return activeRemoteCcmDefect;
+ }
+
+ @Override
+ public boolean activeErrorCcmDefect() {
+ return activeErrorCcmDefect;
+ }
+
+ @Override
+ public boolean activeXconCcmDefect() {
+ return activeXconCcmDefect;
+ }
+
+ @Override
+ public byte[] lastErrorCcm() {
+ return lastErrorCcm;
+ }
+
+ @Override
+ public byte[] lastXconCcm() {
+ return lastXconCcm;
+ }
+
+ @Override
+ public int ccmSequenceErrorCount() {
+ return ccmSequenceErrorCount;
+ }
+
+ @Override
+ public int totalCcmsTransmitted() {
+ return totalCcmsTransmitted;
+ }
+
+ @Override
+ public MepLbEntry loopbackAttributes() {
+ return loopbackAttributes;
+ }
+
+ @Override
+ public MepLtEntry linktraceAttributes() {
+ return linktraceAttributes;
+ }
+
+ @Override
+ public List<RemoteMepEntry> activeRemoteMepList() {
+ if (activeRemoteMepList == null) {
+ return null;
+ } else {
+ return Lists.newArrayList(activeRemoteMepList);
+ }
+ }
+
+ @Override
+ public Collection<DelayMeasurementEntry> delayMeasurementList() {
+ return delayMeasurementList;
+ }
+
+ @Override
+ public Collection<LossMeasurementEntry> lossMeasurementList() {
+ return lossMeasurementList;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + mepId.value();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ DefaultMepEntry other = (DefaultMepEntry) obj;
+ if (mepId != other.mepId) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).add("id", mepId).toString();
+ }
+
+ public static MepEntryBuilder builder(
+ MepId mepId,
+ DeviceId deviceId,
+ PortNumber port,
+ MepDirection direction,
+ MdId mdName,
+ MaIdShort maName)
+ throws CfmConfigException {
+ return new DefaultMepEntryBuilder(mepId, deviceId, port, direction, mdName, maName);
+ }
+
+ public static MepEntryBuilder builder(Mep mep) throws CfmConfigException {
+ return new DefaultMepEntryBuilder(mep);
+ }
+
+ private static final class DefaultMepEntryBuilder
+ extends DefaultMep.DefaultMepBuilder implements MepEntry.MepEntryBuilder {
+ private MacAddress macAddress;
+ private FngState fngState;
+ private FaultDefectType highestPriorityDefect;
+ private boolean activeRdiCcmDefect;
+ private boolean activeMacStatusDefect;
+ private boolean activeRemoteCcmDefect;
+ private boolean activeErrorCcmDefect;
+ private boolean activeXconCcmDefect;
+ private byte[] lastErrorCcm;
+ private byte[] lastXconCcm;
+ private int ccmSequenceErrorCount;
+ private int totalCcmsTransmitted;
+ private MepLbEntry loopbackAttributes;
+ private MepLtEntry linktraceAttributes;
+ private Collection<RemoteMepEntry> activeRemoteMepList;
+ private Collection<DelayMeasurementEntry> delayMeasurementList;
+ private Collection<LossMeasurementEntry> lossMeasurementList;
+
+ private DefaultMepEntryBuilder(MepId mepId, DeviceId deviceId, PortNumber port, MepDirection direction,
+ MdId mdName, MaIdShort maName)
+ throws CfmConfigException {
+ super(mepId, deviceId, port, direction, mdName, maName);
+
+ activeRemoteMepList = new ArrayList<>();
+ delayMeasurementList = new ArrayList<>();
+ lossMeasurementList = new ArrayList<>();
+ }
+
+ private DefaultMepEntryBuilder(MepEntry mepEntry) throws CfmConfigException {
+ super(mepEntry.mepId(), mepEntry.deviceId(),
+ mepEntry.port(), mepEntry.direction(), mepEntry.mdId(), mepEntry.maId());
+ this.macAddress = mepEntry.macAddress();
+ this.fngState = mepEntry.fngState();
+ this.highestPriorityDefect = mepEntry.getHighestPriorityDefect();
+ this.activeRdiCcmDefect = mepEntry.activeRdiCcmDefect();
+ this.activeMacStatusDefect = mepEntry.activeMacStatusDefect();
+ this.activeRemoteCcmDefect = mepEntry.activeRemoteCcmDefect();
+ this.activeErrorCcmDefect = mepEntry.activeErrorCcmDefect();
+ this.activeXconCcmDefect = mepEntry.activeXconCcmDefect();
+ this.lastErrorCcm = mepEntry.lastErrorCcm();
+ this.lastXconCcm = mepEntry.lastXconCcm();
+ this.ccmSequenceErrorCount = mepEntry.ccmSequenceErrorCount();
+ this.totalCcmsTransmitted = mepEntry.totalCcmsTransmitted();
+ this.loopbackAttributes = mepEntry.loopbackAttributes();
+ this.linktraceAttributes = mepEntry.linktraceAttributes();
+ this.activeRemoteMepList = Lists.newArrayList(mepEntry.activeRemoteMepList());
+ this.delayMeasurementList = Lists.newArrayList(mepEntry.delayMeasurementList());
+ this.lossMeasurementList = Lists.newArrayList(mepEntry.lossMeasurementList());
+ }
+
+ private DefaultMepEntryBuilder(Mep mep) throws CfmConfigException {
+ super(mep.mepId(), mep.deviceId(),
+ mep.port(), mep.direction(),
+ mep.mdId(), mep.maId());
+ }
+
+ @Override
+ public MepEntryBuilder macAddress(MacAddress macAddress) {
+ this.macAddress = macAddress;
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder fngState(FngState fngState) {
+ this.fngState = fngState;
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder highestPriorityDefect(FaultDefectType highestPriorityDefect) {
+ this.highestPriorityDefect = highestPriorityDefect;
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder activeRdiCcmDefect(boolean activeRdiCcmDefect) {
+ this.activeRdiCcmDefect = activeRdiCcmDefect;
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder activeMacStatusDefect(boolean activeMacStatusDefect) {
+ this.activeMacStatusDefect = activeMacStatusDefect;
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder activeRemoteCcmDefect(boolean activeRemoteCcmDefect) {
+ this.activeRemoteCcmDefect = activeRemoteCcmDefect;
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder activeErrorCcmDefect(boolean activeErrorCcmDefect) {
+ this.activeErrorCcmDefect = activeErrorCcmDefect;
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder activeXconCcmDefect(boolean activeXconCcmDefect) {
+ this.activeXconCcmDefect = activeXconCcmDefect;
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder lastErrorCcm(byte[] lastErrorCcm) {
+ this.lastErrorCcm = lastErrorCcm;
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder lastXconCcm(byte[] lastXconCcm) {
+ this.lastXconCcm = lastXconCcm;
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder ccmSequenceErrorCount(int ccmSequenceErrorCount) {
+ this.ccmSequenceErrorCount = ccmSequenceErrorCount;
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder totalCcmsTransmitted(int totalCcmsTransmitted) {
+ this.totalCcmsTransmitted = totalCcmsTransmitted;
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder loopbackAttributes(MepLbEntry loopbackAttributes) {
+ this.loopbackAttributes = loopbackAttributes;
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder linktraceAttributes(MepLtEntry linktraceAttributes) {
+ this.linktraceAttributes = linktraceAttributes;
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder addToActiveRemoteMepList(
+ RemoteMepEntry activeRemoteMep) {
+ this.activeRemoteMepList.add(activeRemoteMep);
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder addToDelayMeasurementList(
+ DelayMeasurementEntry delayMeasurement) {
+ this.delayMeasurementList.add(delayMeasurement);
+ return this;
+ }
+
+ @Override
+ public MepEntryBuilder addToLossMeasurementList(
+ LossMeasurementEntry lossMeasurement) {
+ this.lossMeasurementList.add(lossMeasurement);
+ return this;
+ }
+
+ @Override
+ public MepEntry buildEntry() throws CfmConfigException {
+ return new DefaultMepEntry(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMepLbCreate.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMepLbCreate.java
new file mode 100644
index 0000000..b6eb62a
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMepLbCreate.java
@@ -0,0 +1,146 @@
+/*
+ * 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;
+
+import java.util.Base64;
+
+import org.onlab.packet.MacAddress;
+import org.onlab.util.HexString;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate}.
+ */
+public final class DefaultMepLbCreate implements MepLbCreate {
+
+ private final MacAddress remoteMepAddress;
+ private final MepId remoteMepId;
+ private final Integer numberMessages;
+ private final String dataTlvHex;
+ private final Priority vlanPriority;
+ private final Boolean vlanDropEligible;
+
+ private DefaultMepLbCreate(DefaultMepLbCreateBuilder builder) {
+ this.remoteMepAddress = builder.remoteMepAddress;
+ this.remoteMepId = builder.remoteMepId;
+ this.numberMessages = builder.numberMessages;
+ this.dataTlvHex = builder.dataTlvHex;
+ this.vlanPriority = builder.vlanPriority;
+ this.vlanDropEligible = builder.vlanDropEligible;
+ }
+
+ @Override
+ public MacAddress remoteMepAddress() {
+ return remoteMepAddress;
+ }
+
+ @Override
+ public MepId remoteMepId() {
+ return remoteMepId;
+ }
+
+ @Override
+ public Integer numberMessages() {
+ return numberMessages;
+ }
+
+ @Override
+ public String dataTlvHex() {
+ return dataTlvHex;
+ }
+
+ @Override
+ public Priority vlanPriority() {
+ return vlanPriority;
+ }
+
+ @Override
+ public Boolean vlanDropEligible() {
+ return vlanDropEligible;
+ }
+
+ public static final MepLbCreateBuilder builder(MacAddress remoteMepAddress) {
+ return new DefaultMepLbCreateBuilder(remoteMepAddress);
+ }
+
+ public static final MepLbCreateBuilder builder(MepId remoteMepId) {
+ return new DefaultMepLbCreateBuilder(remoteMepId);
+ }
+
+ private static final class DefaultMepLbCreateBuilder implements MepLbCreateBuilder {
+ private final MacAddress remoteMepAddress;
+ private final MepId remoteMepId;
+ private Integer numberMessages;
+ private String dataTlvHex;
+ private Priority vlanPriority;
+ private Boolean vlanDropEligible;
+
+ private DefaultMepLbCreateBuilder(MacAddress remoteMepAddress) {
+ this.remoteMepAddress = remoteMepAddress;
+ this.remoteMepId = null;
+ }
+
+ private DefaultMepLbCreateBuilder(MepId remoteMepId) {
+ this.remoteMepAddress = null;
+ this.remoteMepId = remoteMepId;
+ }
+
+ @Override
+ public MepLbCreateBuilder numberMessages(int numberMessages) {
+ this.numberMessages = numberMessages;
+ return this;
+ }
+
+ @Override
+ public MepLbCreateBuilder dataTlv(byte[] dataTlv) {
+ this.dataTlvHex = HexString.toHexString(dataTlv);
+ return this;
+ }
+
+ @Override
+ public MepLbCreateBuilder dataTlvHex(String dataTlvHex) {
+ this.dataTlvHex = HexString.toHexString(
+ HexString.fromHexString(dataTlvHex));
+ return this;
+ }
+
+ @Override
+ public MepLbCreateBuilder dataTlvB64(String dataTlvB64) {
+ this.dataTlvHex = HexString.toHexString(
+ Base64.getDecoder().decode(dataTlvB64));
+ return this;
+ }
+
+ @Override
+ public MepLbCreateBuilder vlanPriority(Priority vlanPriority) {
+ this.vlanPriority = vlanPriority;
+ return this;
+ }
+
+ @Override
+ public MepLbCreateBuilder vlanDropEligible(boolean vlanDropEligible) {
+ this.vlanDropEligible = vlanDropEligible;
+ return this;
+ }
+
+ @Override
+ public MepLbCreate build() {
+ return new DefaultMepLbCreate(this);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMepLbEntry.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMepLbEntry.java
new file mode 100644
index 0000000..0ebe47b
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMepLbEntry.java
@@ -0,0 +1,127 @@
+/*
+ * 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;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.cfm.MepLbEntry}.
+ */
+public final class DefaultMepLbEntry implements MepLbEntry {
+ private final long nextLbmIdentifier;
+ private final long countLbrTransmitted;
+ private final long countLbrReceived;
+ private final long countLbrValidInOrder;
+ private final long countLbrValidOutOfOrder;
+ private final long countLbrMacMisMatch;
+
+ private DefaultMepLbEntry(DefaultMepLbEntryBuilder builder) {
+ this.nextLbmIdentifier = builder.nextLbmIdentifier;
+ this.countLbrTransmitted = builder.countLbrTransmitted;
+ this.countLbrReceived = builder.countLbrReceived;
+ this.countLbrValidInOrder = builder.countLbrValidInOrder;
+ this.countLbrValidOutOfOrder = builder.countLbrValidOutOfOrder;
+ this.countLbrMacMisMatch = builder.countLbrMacMisMatch;
+ }
+
+ @Override
+ public long nextLbmIdentifier() {
+ return nextLbmIdentifier;
+ }
+
+ @Override
+ public long countLbrTransmitted() {
+ return countLbrTransmitted;
+ }
+
+ @Override
+ public long countLbrReceived() {
+ return countLbrReceived;
+ }
+
+ @Override
+ public long countLbrValidInOrder() {
+ return countLbrValidInOrder;
+ }
+
+ @Override
+ public long countLbrValidOutOfOrder() {
+ return countLbrValidOutOfOrder;
+ }
+
+ @Override
+ public long countLbrMacMisMatch() {
+ return countLbrMacMisMatch;
+ }
+
+ public static final MepLbEntryBuilder builder() {
+ return new DefaultMepLbEntryBuilder();
+ }
+
+ private static final class DefaultMepLbEntryBuilder implements MepLbEntryBuilder {
+ private long nextLbmIdentifier;
+ private long countLbrTransmitted;
+ private long countLbrReceived;
+ private long countLbrValidInOrder;
+ private long countLbrValidOutOfOrder;
+ private long countLbrMacMisMatch;
+
+ private DefaultMepLbEntryBuilder() {
+ //Hidden
+ }
+
+ @Override
+ public MepLbEntryBuilder nextLbmIdentifier(long nextLbmIdentifier) {
+ this.nextLbmIdentifier = nextLbmIdentifier;
+ return this;
+ }
+
+ @Override
+ public MepLbEntryBuilder countLbrTransmitted(long countLbrTransmitted) {
+ this.countLbrTransmitted = countLbrTransmitted;
+ return this;
+ }
+
+ @Override
+ public MepLbEntryBuilder countLbrReceived(long countLbrReceived) {
+ this.countLbrReceived = countLbrReceived;
+ return this;
+ }
+
+ @Override
+ public MepLbEntryBuilder countLbrValidInOrder(
+ long countLbrValidInOrder) {
+ this.countLbrValidInOrder = countLbrValidInOrder;
+ return this;
+ }
+
+ @Override
+ public MepLbEntryBuilder countLbrValidOutOfOrder(
+ long countLbrValidOutOfOrder) {
+ this.countLbrValidOutOfOrder = countLbrValidOutOfOrder;
+ return this;
+ }
+
+ @Override
+ public MepLbEntryBuilder countLbrMacMisMatch(long countLbrMacMisMatch) {
+ this.countLbrMacMisMatch = countLbrMacMisMatch;
+ return this;
+ }
+
+ @Override
+ public MepLbEntry build() {
+ return new DefaultMepLbEntry(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMepLtCreate.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMepLtCreate.java
new file mode 100644
index 0000000..790278a
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultMepLtCreate.java
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import org.onlab.packet.MacAddress;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+
+import java.util.BitSet;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate}.
+ */
+public final class DefaultMepLtCreate implements MepLtCreate {
+ private final MacAddress remoteMepAddress;
+ private final MepId remoteMepId;
+ private BitSet transmitLtmFlags;
+ private Short defaultTtl;
+
+ private DefaultMepLtCreate(DefaultMepLtCreateBuilder builder) {
+ this.remoteMepAddress = builder.remoteMepAddress;
+ this.remoteMepId = builder.remoteMepId;
+ this.defaultTtl = builder.defaultTtl;
+ this.transmitLtmFlags = builder.transmitLtmFlags;
+ }
+
+ @Override
+ public MacAddress remoteMepAddress() {
+ return remoteMepAddress;
+ }
+
+ @Override
+ public MepId remoteMepId() {
+ return remoteMepId;
+ }
+
+ @Override
+ public BitSet transmitLtmFlags() {
+ return transmitLtmFlags;
+ }
+
+ @Override
+ public Short defaultTtl() {
+ return defaultTtl;
+ }
+
+ public static final MepLtCreate.MepLtCreateBuilder builder(MacAddress remoteMepAddress) {
+ return new DefaultMepLtCreate.DefaultMepLtCreateBuilder(remoteMepAddress);
+ }
+
+ public static final MepLtCreate.MepLtCreateBuilder builder(MepId remoteMepId) {
+ return new DefaultMepLtCreate.DefaultMepLtCreateBuilder(remoteMepId);
+ }
+
+ private static final class DefaultMepLtCreateBuilder implements MepLtCreate.MepLtCreateBuilder {
+ private final MacAddress remoteMepAddress;
+ private final MepId remoteMepId;
+ private BitSet transmitLtmFlags;
+ private Short defaultTtl;
+
+ private DefaultMepLtCreateBuilder(MacAddress remoteMepAddress) {
+ this.remoteMepId = null;
+ this.remoteMepAddress = remoteMepAddress;
+ }
+
+ private DefaultMepLtCreateBuilder(MepId remoteMepId) {
+ this.remoteMepId = remoteMepId;
+ this.remoteMepAddress = null;
+ }
+
+ @Override
+ public MepLtCreateBuilder transmitLtmFlags(BitSet transmitLtmFlags) {
+ this.transmitLtmFlags = transmitLtmFlags;
+ return this;
+ }
+
+ @Override
+ public MepLtCreateBuilder defaultTtl(Short defaultTtl) {
+ this.defaultTtl = defaultTtl;
+ return this;
+ }
+
+ @Override
+ public MepLtCreate build() {
+ return new DefaultMepLtCreate(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultRemoteMepEntry.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultRemoteMepEntry.java
new file mode 100644
index 0000000..377ddde
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/DefaultRemoteMepEntry.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;
+
+import java.time.Duration;
+
+import org.onlab.packet.MacAddress;
+import org.onosproject.incubator.net.l2monitoring.cfm.SenderIdTlv.SenderIdTlvType;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry}.
+ */
+public class DefaultRemoteMepEntry implements RemoteMepEntry {
+
+ private final MepId remoteMepId;
+ private final RemoteMepState state;
+ private final Duration failedOrOkTime;
+ private final MacAddress macAddress;
+ private final boolean rdi;
+ private final PortStatusTlvType portStatusTlvType;
+ private final InterfaceStatusTlvType interfaceStatusTlvType;
+ private final SenderIdTlvType senderIdTlvType;
+
+ protected DefaultRemoteMepEntry(DefaultRemoteMepEntryBuilder rmepBuilder) {
+ this.remoteMepId = rmepBuilder.remoteMepId;
+ this.state = rmepBuilder.state;
+ this.failedOrOkTime = rmepBuilder.failedOrOkTime;
+ this.macAddress = rmepBuilder.macAddress;
+ this.rdi = rmepBuilder.rdi;
+ this.portStatusTlvType = rmepBuilder.portStatusTlvType;
+ this.interfaceStatusTlvType = rmepBuilder.interfaceStatusTlvType;
+ this.senderIdTlvType = rmepBuilder.senderIdTlvType;
+ }
+
+ @Override
+ public MepId remoteMepId() {
+ return this.remoteMepId;
+ }
+
+ @Override
+ public RemoteMepState state() {
+ return this.state;
+ }
+
+ @Override
+ public Duration failedOrOkTime() {
+ return failedOrOkTime;
+ }
+
+ @Override
+ public MacAddress macAddress() {
+ return macAddress;
+ }
+
+ @Override
+ public boolean rdi() {
+ return rdi;
+ }
+
+ @Override
+ public PortStatusTlvType portStatusTlvType() {
+ return portStatusTlvType;
+ }
+
+ @Override
+ public InterfaceStatusTlvType interfaceStatusTlvType() {
+ return interfaceStatusTlvType;
+ }
+
+ @Override
+ public SenderIdTlvType senderIdTlvType() {
+ return senderIdTlvType;
+ }
+
+ public static RemoteMepEntryBuilder builder(
+ MepId remoteMepId, RemoteMepState state) throws CfmConfigException {
+ return new DefaultRemoteMepEntryBuilder(remoteMepId, state);
+ }
+
+ private static class DefaultRemoteMepEntryBuilder implements RemoteMepEntryBuilder {
+ private final MepId remoteMepId;
+ private final RemoteMepState state;
+ private Duration failedOrOkTime;
+ private MacAddress macAddress;
+ private boolean rdi;
+ private PortStatusTlvType portStatusTlvType;
+ private InterfaceStatusTlvType interfaceStatusTlvType;
+ private SenderIdTlvType senderIdTlvType;
+
+ protected DefaultRemoteMepEntryBuilder(MepId remoteMepId,
+ RemoteMepState state) throws CfmConfigException {
+ if (remoteMepId == null) {
+ throw new CfmConfigException("remoteMepId is null");
+ } else if (state == null) {
+ throw new CfmConfigException("state is null");
+ }
+ this.remoteMepId = remoteMepId;
+ this.state = state;
+ }
+
+ @Override
+ public RemoteMepEntryBuilder failedOrOkTime(Duration failedOrOkTime) {
+ this.failedOrOkTime = failedOrOkTime;
+ return this;
+ }
+
+ @Override
+ public RemoteMepEntryBuilder macAddress(MacAddress macAddress) {
+ this.macAddress = macAddress;
+ return this;
+ }
+
+ @Override
+ public RemoteMepEntryBuilder rdi(boolean rdi) {
+ this.rdi = rdi;
+ return this;
+ }
+
+ @Override
+ public RemoteMepEntryBuilder portStatusTlvType(PortStatusTlvType portStatusTlvType) {
+ this.portStatusTlvType = portStatusTlvType;
+ return this;
+ }
+
+ @Override
+ public RemoteMepEntryBuilder interfaceStatusTlvType(
+ InterfaceStatusTlvType interfaceStatusTlvType) {
+ this.interfaceStatusTlvType = interfaceStatusTlvType;
+ return this;
+ }
+
+ @Override
+ public RemoteMepEntryBuilder senderIdTlvType(
+ SenderIdTlvType senderIdTlvType) {
+ this.senderIdTlvType = senderIdTlvType;
+ return this;
+ }
+
+ @Override
+ public RemoteMepEntry build() {
+ return new DefaultRemoteMepEntry(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceAssociation.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceAssociation.java
new file mode 100644
index 0000000..37c1a84
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceAssociation.java
@@ -0,0 +1,124 @@
+/*
+ * 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;
+
+import java.time.Duration;
+import java.util.Collection;
+
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+import org.onosproject.net.NetworkResource;
+
+/**
+ * A model of the Maintenance Association.
+ *
+ * See IEEE 802.1Q Section 12.14 CFM entities
+ * Direct child of {@link org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain}
+ */
+public interface MaintenanceAssociation extends NetworkResource {
+ /**
+ * Get the ID of the Maintenance Association.
+ * @return The id object
+ */
+ MaIdShort maId();
+
+ /**
+ * Get the CCM interval for the Maintenance Association.
+ * @return An enumerated value
+ */
+ CcmInterval ccmInterval();
+
+ /**
+ * A list of components each of which can be managed in a manner essentially equivalent to an 802.1Q bridge.
+ * @return A collection of Components
+ */
+ Collection<Component> componentList();
+
+ /**
+ * Create a new component collection.
+ * @param componentList A collection of component objects
+ * @return A new Maintenance Association
+ */
+ MaintenanceAssociation withComponentList(Collection<Component> componentList);
+
+ /**
+ * Get the list of the Remote Mep Ids.
+ * @return A list of Remote Mep Ids
+ */
+ Collection<MepId> remoteMepIdList();
+
+ /**
+ * Create a new Maintenance Association from the current with the specified RemoteMepId list.
+ * @param remoteMepIdList A list of RemoteMepIds
+ * @return A new Maintenance Association
+ */
+ MaintenanceAssociation withRemoteMepIdList(Collection<MepId> remoteMepIdList);
+
+ /**
+ * Numeric identifier.
+ * Some systems require to have a placeholder for a numeric identifier in
+ * addition to the MaId
+ * @return A short numeric id that's been assigned to the MA
+ */
+ short maNumericId();
+
+ /**
+ * Enumerated values from IEEE 802.1Q Table 21-16—CCM Interval field encoding.
+ */
+ enum CcmInterval {
+ INVALID(0),
+ INTERVAL_3MS(3),
+ INTERVAL_10MS(10),
+ INTERVAL_100MS(100),
+ INTERVAL_1S(1000),
+ INTERVAL_10S(10000),
+ INTERVAL_1MIN(60000),
+ INTERVAL_10MIN(600000);
+
+ private final int millis;
+
+ CcmInterval(int millis) {
+ this.millis = millis;
+ }
+
+ public int millis() {
+ return millis;
+ }
+
+ public Duration duration() {
+ return Duration.ofMillis(millis);
+ }
+ }
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation}.
+ */
+ interface MaBuilder {
+
+ MaBuilder ccmInterval(CcmInterval ccmInterval);
+
+ MaBuilder addToRemoteMepIdList(MepId remoteMep);
+
+ MaBuilder removeFromRemoteMepIdList(MepId remoteMep);
+
+ MaBuilder addToComponentList(Component component);
+
+ MaBuilder maNumericId(short maNumericId);
+
+ MaintenanceAssociation build() throws CfmConfigException;
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceDomain.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceDomain.java
new file mode 100644
index 0000000..f98b76b
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceDomain.java
@@ -0,0 +1,125 @@
+/*
+ * 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;
+
+import java.util.Collection;
+
+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.net.NetworkResource;
+
+/**
+ * A model of the Maintenance Domain.
+ *
+ * See IEEE 802.1Q Section 12.14.5.1.3 CFM entities.<br>
+ * This is the root of the L2 Monitoring hierarchy<br>
+ * |-Maintenance-Domain*<br>
+ * |-{@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId}
+ * (MdIdCharStr or MdIdDomainName or MdIdMacUint or MdIdNone)<br>
+ * |-{@link org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation Maintenance-Association}*<br>
+ * |-{@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort}
+ * ({@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr}
+ * or {@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdPrimaryVid}
+ * or {@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaId2Octet}
+ * or {@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdRfc2685VpnId}
+ * or {@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdIccY1731})<br>
+ * |-{@link org.onosproject.incubator.net.l2monitoring.cfm.Component}*<br>
+ * |-{@link org.onosproject.incubator.net.l2monitoring.cfm.Mep}* (Maintenance-Association-EndPoint)
+ * and {@link org.onosproject.incubator.net.l2monitoring.cfm.MepEntry}*<br>
+ * | |-{@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId}<br>
+ * | |-{@link org.onosproject.incubator.net.l2monitoring.cfm.MepLbEntry}<br>
+ * | |-{@link org.onosproject.incubator.net.l2monitoring.cfm.MepLtEntry}<br>
+ * | | |-{@link org.onosproject.incubator.net.l2monitoring.cfm.MepLtTransactionEntry}*<br>
+ * | | |-{@link org.onosproject.incubator.net.l2monitoring.cfm.MepLtReply}*<br>
+ * | | |-{@link org.onosproject.incubator.net.l2monitoring.cfm.SenderIdTlv}<br>
+ * | |-{@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate} (SOAM)*
+ * and {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry}<br>
+ * | | |-{@link org.onosproject.incubator.net.l2monitoring.soam.SoamId DmId}<br>
+ * | | |-{@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatCurrent}<br>
+ * | | |-{@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatHistory}*<br>
+ * | |-{@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate} (SOAM)*
+ * and {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry}<br>
+ * | | |-{@link org.onosproject.incubator.net.l2monitoring.soam.SoamId LmId}<br>
+ * | | |-{@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatCurrent}<br>
+ * | | |-{@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatHistory}*<br>
+ * | |-{@link org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry}*<br>
+ * | | |-{@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId RemoteMepId}<br>
+ * |-{@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId RemoteMepId}*<br>
+ *<br>
+ * *above indicates 0-many can be created
+ * -Create suffix means the Object is part of a request
+ * -Entry suffix means the Object is part of a reply
+ */
+public interface MaintenanceDomain extends NetworkResource {
+ /**
+ * Retrieve the id of the Maintenance Domain.
+ * @return The id object
+ */
+ MdId mdId();
+
+ /**
+ * Retrieve the level of the MD.
+ * @return An enumerated value for the level
+ */
+ MdLevel mdLevel();
+
+ /**
+ * Retrieve the MA list of the MD.
+ * @return The collection of Maintenance Associations
+ */
+ Collection<MaintenanceAssociation> maintenanceAssociationList();
+
+ /**
+ * Replace the MA list of the MD.
+ * @param maintenanceAssociationList A list of MAs to replace the existing one
+ * @return A new version of the MD with the given MA list
+ */
+ MaintenanceDomain withMaintenanceAssociationList(
+ Collection<MaintenanceAssociation> maintenanceAssociationList);
+
+ /**
+ * Numeric identifier.
+ * Some systems require to have a placeholder for a numeric identifier in
+ * addition to the MdId
+ * @return A short numeric id that's been assigned to the MD
+ */
+ short mdNumericId();
+
+ /**
+ * An enumerated set of values to represent MD Level.
+ */
+ public enum MdLevel {
+ LEVEL0, LEVEL1, LEVEL2, LEVEL3, LEVEL4, LEVEL5, LEVEL6, LEVEL7
+ }
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain}.
+ */
+ interface MdBuilder {
+ MdBuilder mdLevel(MdLevel mdLevel);
+
+ MdBuilder mdNumericId(short mdNumericId);
+
+ MdBuilder addToMaList(MaintenanceAssociation ma);
+
+ MdBuilder deleteFromMaList(MaIdShort maName);
+
+ boolean checkMaExists(MaIdShort maName);
+
+ MaintenanceDomain build() throws CfmConfigException;
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/Mep.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/Mep.java
new file mode 100644
index 0000000..ff06932
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/Mep.java
@@ -0,0 +1,369 @@
+/*
+ * 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;
+
+import java.time.Duration;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.VlanId;
+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.net.DeviceId;
+import org.onosproject.net.NetworkResource;
+import org.onosproject.net.PortNumber;
+
+/**
+ * A model of the Maintenance Association Endpoint.
+ *
+ * See IEE 802.1Q Section 12.14.7.1.3 for reference
+ */
+public interface Mep extends NetworkResource {
+
+ /**
+ * Get the ID of the MEP.
+ *
+ * @return The MEPID is an integer in the range 1–8191
+ */
+ MepId mepId();
+
+ /**
+ * Get the Device ID which the MEP is realized on.
+ *
+ * @return The DeviceID to which this Mep is associated
+ */
+ DeviceId deviceId();
+
+ /**
+ * Get the port to which the MEP is attached.
+ *
+ * @return An port to which the MEP is attached
+ */
+ PortNumber port();
+
+ /**
+ * Get the MEP direction.
+ *
+ * @return A value indicating the direction in which the MEP faces on the interface
+ */
+ MepDirection direction();
+
+ /**
+ * Get the Maintenance Domain reference.
+ *
+ * @return The name of the containing Maintenance Domain
+ */
+ MdId mdId();
+
+ /**
+ * Get the Maintenance Association reference.
+ *
+ * @return The name of the containing Maintenance Association
+ */
+ MaIdShort maId();
+
+ /**
+ * Get the Primary VID of the MEP.
+ * The value 0 indicates that either the Primary VID is that
+ * of the MEP's MA or that the MEP's MA is associated with no VID.
+ *
+ * @return An integer in the range 0-4094
+ */
+ VlanId primaryVid();
+
+ /**
+ * Set the Primary VID of the MEP.
+ *
+ * @param primaryVid An integer between 0 and 4094
+ * @return A new MEP with this value set
+ */
+ Mep withPrimaryVid(VlanId primaryVid);
+
+ /**
+ * Get the administrative state of the MEP.
+ *
+ * @return The administrative state of the MEP
+ */
+ boolean administrativeState();
+
+ /**
+ * Set the administrative state of the MEP.
+ *
+ * @param adminState The administrative state of the MEP
+ * @return A new MEP with this value set
+ */
+ Mep withAdministrativeState(boolean adminState);
+
+ /**
+ * Get whether the MEP is or is not to generate CCMs.
+ *
+ * CCMs are Continuity Check Messages
+ *
+ * @return boolean value indicating whether the MEP is or is not to generate CCMs
+ */
+ Boolean cciEnabled();
+
+ /**
+ * Enable or disable the generation of CCMs by the MEP.
+ *
+ * @param cciEnabled boolean value dictating whether CCMs are sent or not
+ * @return A new MEP with this value set
+ */
+ Mep withCciEnabled(boolean cciEnabled);
+
+ /**
+ * Get the priority parameter for CCMs and LTMs transmitted by the MEP.
+ *
+ * @return The priority parameter for CCMs and LTMs transmitted by the MEP
+ */
+ Priority ccmLtmPriority();
+
+ /**
+ * Set the priority parameter for CCMs and LTMs transmitted by the MEP.
+ *
+ * @param priority An integer value between 0 and 7 inclusive
+ * @return A new MEP with this value set
+ */
+ Mep withCcmLtmPriority(Priority priority);
+
+ /**
+ * Get the network address to which Fault Alarms are to be transmitted.
+ *
+ * @return The IP address to which Fault Alarms are to be transmitted
+ */
+ FngAddress fngAddress();
+
+ /**
+ * Set the network address to which Fault Alarms are to be transmitted.
+ *
+ * If “not specified,” the address used is that from the Maintenance Association managed object
+ *
+ * @param address Address type or indicator that address is not specified or alarms are not to be transmitted
+ * @return A new MEP with this value set
+ */
+ Mep withFngAddress(FngAddress address);
+
+ /**
+ * Get the lowest priority defect that is allowed to generate a Fault Alarm.
+ * @return The lowest priority defect that is allowed to generate a Fault Alarm
+ */
+ LowestFaultDefect lowestFaultPriorityDefect();
+
+ /**
+ * Set the lowest priority defect that is allowed to generate a Fault Alarm.
+ * @param lowestFdType The lowest priority defect that is allowed to generate a Fault Alarm
+ * @return A new MEP with this value set
+ */
+ Mep withLowestFaultPriorityDefect(LowestFaultDefect lowestFdType);
+
+ /**
+ * Get the time that the Fault must be present before it is issued.
+ * @return The time that the Fault must be present before it is issued
+ */
+ Duration defectPresentTime();
+
+ /**
+ * Set the time that the Fault must be present before it is issued.
+ *
+ * The default is 2500ms (2.5 seconds) if not specified
+ * @param duration The time that the Fault must be present before it is issued
+ * @return A new MEP with this value set
+ */
+ Mep withDefectPresentTime(Duration duration);
+
+ /**
+ * Get the time that the Fault must be absent before it is reset.
+ * @return The time that the Fault must be absent before it is reset
+ */
+ Duration defectAbsentTime();
+
+ /**
+ * Set the time that the Fault must be absent before it is reset.
+ *
+ * The default is 10000ms (10 seconds) if not specified
+ * @param duration The time that the Fault must be absent before it is reset
+ * @return A new MEP with this value set
+ */
+ Mep withDefectAbsentTime(Duration duration);
+
+ /**
+ * Enumerated options for MEP Directions.
+ */
+ public enum MepDirection {
+ UP_MEP,
+ DOWN_MEP
+ }
+
+ /**
+ * Supported FNG Address Types.
+ * See {@link org.onosproject.incubator.net.l2monitoring.cfm.Mep.FngAddress}
+ */
+ public enum FngAddressType {
+ IPV4,
+ IPV6,
+ NOT_SPECIFIED,
+ NOT_TRANSMITTED;
+ }
+
+ /**
+ * Supported Fault Defect Types.
+ */
+ public enum FaultDefectType {
+ DEF_NONE,
+ DEF_RDI_CCM,
+ DEF_MAC_STATUS,
+ DEF_REMOTE_CCM,
+ DEF_ERROR_CCM,
+ DEF_XCON_CCM
+ }
+
+ /**
+ * Options for setting the lowest fault defect.
+ * Each comprises a set of {@link org.onosproject.incubator.net.l2monitoring.cfm.Mep.FaultDefectType}
+ */
+ public enum LowestFaultDefect {
+ ALL_DEFECTS(FaultDefectType.DEF_RDI_CCM,
+ FaultDefectType.DEF_MAC_STATUS,
+ FaultDefectType.DEF_REMOTE_CCM,
+ FaultDefectType.DEF_ERROR_CCM,
+ FaultDefectType.DEF_XCON_CCM),
+ MAC_FD_PLUS(FaultDefectType.DEF_MAC_STATUS,
+ FaultDefectType.DEF_REMOTE_CCM,
+ FaultDefectType.DEF_ERROR_CCM,
+ FaultDefectType.DEF_XCON_CCM),
+ REMOTE_FD_PLUS(FaultDefectType.DEF_REMOTE_CCM,
+ FaultDefectType.DEF_ERROR_CCM,
+ FaultDefectType.DEF_XCON_CCM),
+ ERROR_FD_PLUS(FaultDefectType.DEF_ERROR_CCM,
+ FaultDefectType.DEF_XCON_CCM),
+ XCON_FD_ONLY(FaultDefectType.DEF_XCON_CCM);
+
+ private Set<FaultDefectType> defectTypes = new HashSet<>();
+
+ private LowestFaultDefect(FaultDefectType... defectTypes) {
+ for (FaultDefectType defectType:defectTypes) {
+ this.defectTypes.add(defectType);
+ }
+ }
+
+ public Set<FaultDefectType> getDefectTypes() {
+ return defectTypes;
+ }
+ }
+
+ /**
+ * An enumerated set of values to represent Priority.
+ */
+ public enum Priority {
+ PRIO0, PRIO1, PRIO2, PRIO3, PRIO4, PRIO5, PRIO6, PRIO7
+ }
+
+ /**
+ * A simple class to join an FngAddressType and an IpAddress.
+ */
+ public final class FngAddress {
+ private final FngAddressType addressType;
+ private final IpAddress ipAddress;
+
+ private FngAddress(FngAddressType addressType, IpAddress ipAddress) {
+ this.addressType = addressType;
+ this.ipAddress = ipAddress;
+ }
+
+ public FngAddressType addressType() {
+ return addressType;
+ }
+
+ public IpAddress ipAddress() {
+ return ipAddress;
+ }
+
+ public static FngAddress ipV4Address(IpAddress ipAddress) {
+ return new FngAddress(FngAddressType.IPV4, ipAddress);
+ }
+
+ public static FngAddress ipV6Address(IpAddress ipAddress) {
+ return new FngAddress(FngAddressType.IPV6, ipAddress);
+ }
+
+ public static FngAddress notSpecified() {
+ return new FngAddress(FngAddressType.NOT_SPECIFIED, null);
+ }
+
+ public static FngAddress notTransmitted(IpAddress ipAddress) {
+ return new FngAddress(FngAddressType.NOT_TRANSMITTED, ipAddress);
+ }
+
+ @Override
+ public String toString() {
+ return "FngAddress{" +
+ "addressType=" + addressType +
+ ", ipAddress=" + ipAddress +
+ '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ FngAddress that = (FngAddress) o;
+
+ if (addressType != that.addressType) {
+ return false;
+ }
+ return ipAddress != null ? ipAddress.equals(that.ipAddress) : that.ipAddress == null;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = addressType.hashCode();
+ result = 31 * result + (ipAddress != null ? ipAddress.hashCode() : 0);
+ return result;
+ }
+ }
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.Mep}.
+ */
+ interface MepBuilder {
+
+ MepBuilder primaryVid(VlanId primaryVid);
+
+ MepBuilder administrativeState(boolean administrativeState);
+
+ MepBuilder cciEnabled(boolean cciEnabled);
+
+ MepBuilder ccmLtmPriority(Priority ccmLtmPriority);
+
+ MepBuilder fngAddress(FngAddress fngAddress);
+
+ MepBuilder lowestFaultPriorityDefect(LowestFaultDefect lowestFaultPriorityDefect);
+
+ MepBuilder defectPresentTime(Duration defectPresentTime);
+
+ MepBuilder defectAbsentTime(Duration defectAbsentTime);
+
+ Mep build() throws CfmConfigException;
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepEntry.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepEntry.java
new file mode 100644
index 0000000..5259ec6
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepEntry.java
@@ -0,0 +1,187 @@
+/*
+ * 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;
+
+import java.util.Collection;
+
+import org.onlab.packet.MacAddress;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry;
+
+/**
+ * An extension of the Mep interface to represent the state attributes.
+ *
+ */
+public interface MepEntry extends Mep {
+ /**
+ * Get the MAC address of the MEP.
+ *
+ * @return The MAC address of the MEP
+ */
+ MacAddress macAddress();
+
+ /**
+ * Get the state of the MEPs Fault Notification Generator.
+ *
+ * @return The state of the MEPs Fault Notification Generator
+ */
+ FngState fngState();
+
+ /**
+ * Get the highest-priority defect that has been present since last FNG reset.
+ * @return The highest-priority defect
+ */
+ FaultDefectType getHighestPriorityDefect();
+
+ /**
+ * Get flag indicating that some other MEP in this MEP’s MA is transmitting the RDI bit.
+ * @return true or false
+ */
+ boolean activeRdiCcmDefect();
+
+ /**
+ * Get flag indicating that a Port Status or Interface Status TLV is indicating an error condition.
+ * @return true or false
+ */
+ boolean activeMacStatusDefect();
+
+ /**
+ * Get flag indicating that CCMs are not being received from at least one of the configured remote MEPs.
+ * @return true or false
+ */
+ boolean activeRemoteCcmDefect();
+
+ /**
+ * Get flag indicating that erroneous CCMs are being received from some MEP in this MEP’s MA.
+ * @return true or false
+ */
+ boolean activeErrorCcmDefect();
+
+ /**
+ * Get flag indicating indicating that CCMs are being received from a MEP that could be in some other MA.
+ * @return true or false
+ */
+ boolean activeXconCcmDefect();
+
+ /**
+ * The last-received CCM that triggered a DEF_ERROR_CCM fault.
+ *
+ * @return An array of bytes (length 1-1522) containing the CCM
+ */
+ byte[] lastErrorCcm();
+
+ /**
+ * The last-received CCM that triggered a DEF_XCON_CCM fault.
+ *
+ * @return An array of bytes (length 1-1522) containing the CCM
+ */
+ byte[] lastXconCcm();
+
+ /**
+ * Get the total number of out-of-sequence CCMs received.
+ * @return The total number of out-of-sequence CCMs received
+ */
+ int ccmSequenceErrorCount();
+
+ /**
+ * Get the total number of CCMs transmitted.
+ * @return The total number of CCMs transmitted
+ */
+ int totalCcmsTransmitted();
+
+ /**
+ * Get the collection of attributes related to loopback.
+ * @return An object with loopback attributes
+ */
+ MepLbEntry loopbackAttributes();
+
+ /**
+ * Get the collection of attributes related to linktrace.
+ * @return An object with linktrace attributes
+ */
+ MepLtEntry linktraceAttributes();
+
+ /**
+ * Get the list of active Remote MEPs.
+ * @return A list of remote MEPs including their states
+ */
+ Collection<RemoteMepEntry> activeRemoteMepList();
+
+ /**
+ * Get the list of Delay Measurements for this MEP.
+ * @return A list of the Delay Measurements including their states
+ */
+ Collection<DelayMeasurementEntry> delayMeasurementList();
+
+ /**
+ * Get the list of Loss Measurements for this MEP.
+ * @return A list of the Loss Measurements including their states
+ */
+ Collection<LossMeasurementEntry> lossMeasurementList();
+
+ /**
+ * States of Fault Notification Generator.
+ */
+ public enum FngState {
+ FNG_RESET,
+ FNG_DEFECT,
+ FNG_REPORT_DEFECT,
+ FNG_DEFECT_REPORTED,
+ FNG_DEFECT_CLEARING
+ }
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.MepEntry}.
+ */
+ interface MepEntryBuilder extends MepBuilder {
+ MepEntryBuilder macAddress(MacAddress macAddress);
+
+ MepEntryBuilder fngState(FngState fngState);
+
+ MepEntryBuilder highestPriorityDefect(FaultDefectType highestPriorityDefect);
+
+ MepEntryBuilder activeRdiCcmDefect(boolean activeRdiCcmDefect);
+
+ MepEntryBuilder activeMacStatusDefect(boolean activeMacStatusDefect);
+
+ MepEntryBuilder activeRemoteCcmDefect(boolean activeRemoteCcmDefect);
+
+ MepEntryBuilder activeErrorCcmDefect(boolean activeErrorCcmDefect);
+
+ MepEntryBuilder activeXconCcmDefect(boolean activeXconCcmDefect);
+
+ MepEntryBuilder lastErrorCcm(byte[] lastErrorCcm);
+
+ MepEntryBuilder lastXconCcm(byte[] lastXconCcm);
+
+ MepEntryBuilder ccmSequenceErrorCount(int ccmSequenceErrorCount);
+
+ MepEntryBuilder totalCcmsTransmitted(int totalCcmsTransmitted);
+
+ MepEntryBuilder loopbackAttributes(MepLbEntry loopbackAttributes);
+
+ MepEntryBuilder linktraceAttributes(MepLtEntry linktraceAttributes);
+
+ MepEntryBuilder addToActiveRemoteMepList(RemoteMepEntry activeRemoteMep);
+
+ MepEntryBuilder addToDelayMeasurementList(DelayMeasurementEntry delayMeasurement);
+
+ MepEntryBuilder addToLossMeasurementList(LossMeasurementEntry lossMeasurement);
+
+ MepEntry buildEntry() throws CfmConfigException;
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbCreate.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbCreate.java
new file mode 100644
index 0000000..cdb02ca
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbCreate.java
@@ -0,0 +1,98 @@
+/*
+ * 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;
+
+import org.onlab.packet.MacAddress;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+
+/**
+ * Grouping of parameters used to create a loopback test on a MEP.
+ */
+public interface MepLbCreate {
+ /**
+ * The remote Mep will be identified by either a MacAddress or a MEPId.
+ * @return The MAC address of the remoteMep
+ */
+ MacAddress remoteMepAddress();
+
+ /**
+ * The remote Mep will be identified by either a MacAddress or a MEPId.
+ * @return The id of the remoteMep
+ */
+ MepId remoteMepId();
+
+ /**
+ * The number of LBM transmissions in a session.
+ * [802.1q] 12.14.7.3.2:c, [MEF30] R39
+ * @return The number of messages to send
+ */
+ Integer numberMessages();
+
+ /**
+ * An arbitrary amount of data to be included in a Data TLV.
+ * [802.1q] 12.14.7.3.d, IEEE8021-CFM-MIB.dot1agCfmMepTransmitLbmDataTlv
+ * @return The data that will be sent encoded as hexadecimal (lower case, colon separated bytes)
+ */
+ String dataTlvHex();
+
+ /**
+ * The priority parameter to be used in the transmitted LBMs.
+ * [802.1q] 12.14.7.3.2:e
+ * @return The priority to be used
+ */
+ Priority vlanPriority();
+
+ /**
+ * The drop eligible parameter to be used in the transmitted LBMs.
+ * @return True or False
+ */
+ Boolean vlanDropEligible();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate}.
+ */
+ interface MepLbCreateBuilder {
+ MepLbCreateBuilder numberMessages(int numberMessages);
+
+ /**
+ * Define the dataTlv straight from a byte array.
+ * @param dataTlv String of hex pairs separated by : e.g. AA:BB:CC
+ * @return The builder
+ */
+ MepLbCreateBuilder dataTlv(byte[] dataTlv);
+
+ /**
+ * Define the dataTlv byte array from a Hex string.
+ * @param dataTlv String of hex pairs separated by : e.g. AA:BB:CC
+ * @return The builder
+ */
+ MepLbCreateBuilder dataTlvHex(String dataTlv);
+
+ /**
+ * Define the dataTlv byte array from a Base64 string.
+ * @param dataTlv A string in base64 encoding
+ * @return The builder
+ */
+ MepLbCreateBuilder dataTlvB64(String dataTlv);
+
+ MepLbCreateBuilder vlanPriority(Priority vlanPriority);
+
+ MepLbCreateBuilder vlanDropEligible(boolean vlanDropEligible);
+
+ MepLbCreate build();
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbEntry.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbEntry.java
new file mode 100644
index 0000000..fe72023
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbEntry.java
@@ -0,0 +1,78 @@
+/*
+ * 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;
+
+/**
+ * An extension of the MepEntry for Loopback state attributes.
+ *
+ */
+public interface MepLbEntry {
+ /**
+ * Get the next Loopback Transaction Identifier to be sent in an LBM.
+ * LBM = LoopBack Message
+ * @return The next Loopback Transaction Identifier to be sent in an LBM
+ */
+ long nextLbmIdentifier();
+
+ /**
+ * Get the total number of LBRs transmitted by this Mep.
+ * @return The total number of LBRs transmitted
+ */
+ long countLbrTransmitted();
+
+ /**
+ * Get the total number of LBRs received by this Mep.
+ * @return The total number of LBRs received
+ */
+ long countLbrReceived();
+
+ /**
+ * Get the total number of valid, in-order LBRs received.
+ * @return The total number of valid, in-order LBRs received
+ */
+ long countLbrValidInOrder();
+
+ /**
+ * Get the total number of valid, out-of-order LBRs received.
+ * @return The total number of valid, out-of-order LBRs received
+ */
+ long countLbrValidOutOfOrder();
+
+ /**
+ * Get the total number of LBRs received whose mac_service_data_unit did not match LBM.
+ * @return the total number of LBRs received whose mac_service_data_unit did not match LBM
+ */
+ long countLbrMacMisMatch();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.MepLbEntry}.
+ */
+ interface MepLbEntryBuilder {
+ MepLbEntryBuilder nextLbmIdentifier(long nextLbmIdentifier);
+
+ MepLbEntryBuilder countLbrTransmitted(long countLbrTransmitted);
+
+ MepLbEntryBuilder countLbrReceived(long countLbrRecieved);
+
+ MepLbEntryBuilder countLbrValidInOrder(long countLbrValidInOrder);
+
+ MepLbEntryBuilder countLbrValidOutOfOrder(long countLbrValidOutOfOrder);
+
+ MepLbEntryBuilder countLbrMacMisMatch(long countLbrMacMisMatch);
+
+ MepLbEntry build();
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLtCreate.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLtCreate.java
new file mode 100644
index 0000000..adf472b
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLtCreate.java
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import org.onlab.packet.MacAddress;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+
+import java.util.BitSet;
+
+/**
+ * Object representing Linktrace create parameters.
+ */
+public interface MepLtCreate {
+ /**
+ * The remote Mep will be identified by either a MacAddress or a MEPId.
+ * @return The MAC address of the remoteMep
+ */
+ MacAddress remoteMepAddress();
+
+ /**
+ * The remote Mep will be identified by either a MacAddress or a MEPId.
+ * @return The id of the remoteMep
+ */
+ MepId remoteMepId();
+
+ /**
+ * The Flags field for LTMs transmitted by the MEP.
+ * [802.1q] 12.14.7.4.2:b
+ * Bit 0 is use-fdb-only
+ * @return A bit set of flags
+ */
+ BitSet transmitLtmFlags();
+
+ /**
+ * An initial value for the LTM TTL field. 64 if not specified.
+ * [802.1q] 12.14.7.4.2:d
+ * @return The default number of hops
+ */
+ Short defaultTtl();
+
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate}.
+ */
+ interface MepLtCreateBuilder {
+ MepLtCreateBuilder transmitLtmFlags(BitSet transmitLtmFlags);
+
+ MepLtCreateBuilder defaultTtl(Short defaultTtl);
+
+ public MepLtCreate build();
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLtEntry.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLtEntry.java
new file mode 100644
index 0000000..310b58a
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLtEntry.java
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import java.util.Collection;
+
+/**
+ * An extension of the MepEntry for LinkTrace state attributes.
+ *
+ */
+public interface MepLtEntry {
+ /**
+ * Get the next LTM Transaction Identifier to be sent in an LTM.
+ * LTM = Link Trace Message
+ * @return The next LTM Transaction Identifier to be sent in an LTM
+ */
+ int nextLtmIdentifier();
+
+ /**
+ * Get the total number of unexpected LTRs received.
+ * @return The total number of unexpected LTRs received
+ */
+ int countLtrUnexpected();
+
+ /**
+ * Get the total number of LBRs transmitted.
+ * LBR = LoopBack Response
+ * @return The total number of LBRs transmitted
+ */
+ int countLbrTransmitted();
+
+ /**
+ * Get the linktrace database of results.
+ * @return A collection of Linktrace transaction details
+ */
+ Collection<MepLtTransactionEntry> linktraceDatabase();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.MepLtEntry}.
+ */
+ interface MepLtEntryBuilder {
+ MepLtEntryBuilder nextLtmIdentifier(int nextLtmIdentifier);
+
+ MepLtEntryBuilder countLtrUnexpected(int countLtrUnexpected);
+
+ MepLtEntryBuilder countLbrTransmitted(int countLbrTransmitted);
+
+ MepLtEntryBuilder addToLinktraceDatabase(MepLtTransactionEntry linktrace);
+
+ MepLtEntryBuilder build();
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLtReply.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLtReply.java
new file mode 100644
index 0000000..4fa0004
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLtReply.java
@@ -0,0 +1,104 @@
+/*
+ * 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;
+
+/**
+ * The list of LTRs associated with a specific Linktrace transaction.
+ */
+public interface MepLtReply {
+ /**
+ * An index to distinguish among multiple LTRs with the same LTR transaction-id field value.
+ * reply-order are assigned sequentially from 1, in the order that the Linktrace Initiator received the LTR
+ * @return The index
+ */
+ int replyOrder();
+
+ /**
+ * The integer Reply TTL field value returned in the LTR.
+ * @return the Reply TTL field value
+ */
+ int replyTtl();
+
+ /**
+ * A Boolean value stating whether an LTM was forwarded by the responding MP.
+ * @return true when the LTM was forwarded
+ */
+ boolean forwarded();
+
+ /**
+ * A Boolean value stating whether the forwarded LTM reached a MEP for its MA.
+ * @return true when the forwarded LTM reached a MEP
+ */
+ boolean terminalMep();
+
+ /**
+ * An octet string holding the Last Egress Identifier field returned in the LTR Egress Identifier TLV of the LTR.
+ * @return the Last Egress Identifier
+ */
+ byte[] lastEgressIdentifier();
+
+ /**
+ * An octet string holding the Next Egress Identifier field returned in the LTR Egress Identifier TLV of the LTR.
+ * @return the Next Egress Identifier
+ */
+ byte[] nextEgressIdentifier();
+
+ /**
+ * An enumerated value indicating the value returned in the Relay Action field.
+ * @return the Relay Action
+ */
+ LtrReply ltrRelay();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.MepLtReply}.
+ */
+ public interface MepLtReplyBuilder {
+ MepLtReplyBuilder replyOrder(int replyOrder);
+
+ MepLtReplyBuilder replyTtl(int replyTtl);
+
+ MepLtReplyBuilder forwarded(boolean forwarded);
+
+ MepLtReplyBuilder terminalMep(boolean terminalMep);
+
+ MepLtReplyBuilder lastEgressIdentifier(byte[] lastEgressIdentifier);
+
+ MepLtReplyBuilder nextEgressIdentifier(byte[] nextEgressIdentifier);
+
+ MepLtReplyBuilder ltrRelay(LtrReply ltrRelay);
+
+ MepLtReplyBuilder build();
+ }
+
+ /**
+ * An enumerated value indicating the value returned in the Relay Action field.
+ * reference [802.1q] 12.14.7.5.3:g, Table 21-27 IEEE8021-CFM-MIB.Dot1agCfmRelayActionFieldValue
+ */
+ public enum LtrReply {
+ /**
+ * Indicates the LTM reached an MP whose MAC address matches the target MAC address.
+ */
+ RELAY_HIT,
+ /**
+ * Indicates the Egress Port was determined by consulting the Filtering Database.
+ */
+ RELAY_FILTERING_DATABASE,
+ /**
+ * Indicates the Egress Port was determined by consulting the MIP CCM Database.
+ */
+ RELAY_MIP_CCM_DATABASE;
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLtTransactionEntry.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLtTransactionEntry.java
new file mode 100644
index 0000000..82ddfe1
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLtTransactionEntry.java
@@ -0,0 +1,87 @@
+/*
+ * 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;
+
+import java.util.BitSet;
+import java.util.Collection;
+
+import org.onlab.packet.MacAddress;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+
+/**
+ * The LTM entry for a previously transmitted LTM.
+ * An LTM entry consists of a list of LTR entries, each
+ * corresponding to a Linktrace Reply (LTR) PDU received in response to that LTM.
+ *
+ * See IEEE 802.1Q 12.14.7.5.3
+ */
+public interface MepLtTransactionEntry {
+ /**
+ * The LTM Transaction Identifier to which the LTR entries will be attached.
+ * @return The id
+ */
+ int transactionId();
+
+ /**
+ * The remote Mep will be identified by either a MacAddress or a MEPId.
+ * @return The MAC address of the remoteMep
+ */
+ MacAddress macAddress();
+
+ /**
+ * The remote Mep will be identified by either a MacAddress or a MEPId.
+ * @return The id of the remoteMep
+ */
+ MepId mepId();
+
+ /**
+ * The Flags field for LTMs transmitted by the MEP.
+ * [802.1q] 12.14.7.4.2:b
+ * Bit 0 is use-fdb-only
+ * @return A bit set of flags
+ */
+ BitSet transmitLtmUseFdbOnly();
+
+ /**
+ * An initial value for the LTM TTL field. 64 if not specified.
+ * [802.1q] 12.14.7.4.2:d
+ * @return The default number of hops
+ */
+ int defaultTtl();
+
+ /**
+ * The list of LTRs associated with a specific Linktrace transaction.
+ * @return A collection of Replies
+ */
+ Collection<MepLtReply> ltrReplies();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.MepLtTransactionEntry}.
+ */
+ interface MepLtEntryBuilder {
+ MepLtEntryBuilder macAddress(MacAddress macAddress);
+
+ MepLtEntryBuilder mepId(MepId mepId);
+
+ MepLtEntryBuilder transmitLtmUseFdbOnly(boolean transmitLtmUseFdbOnly);
+
+ MepLtEntryBuilder defaultTtl(int defaultTtl);
+
+ MepLtEntryBuilder addToLtrReplies(MepLtReply ltrReply);
+
+ MepLtEntryBuilder build();
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepTsCreate.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepTsCreate.java
new file mode 100644
index 0000000..fce75aa
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/MepTsCreate.java
@@ -0,0 +1,90 @@
+/*
+ * 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;
+
+import org.onlab.packet.MacAddress;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+
+import java.util.Optional;
+
+/**
+ * Grouping of parameters used to create a Test Signal test on a MEP.
+ */
+public interface MepTsCreate {
+ /**
+ * The remote Mep will be identified by either a MacAddress or a MEPId.
+ * @return The MAC address of the remoteMep
+ */
+ MacAddress remoteMepAddress();
+
+ /**
+ * The remote Mep will be identified by either a MacAddress or a MEPId.
+ * @return The id of the remoteMep
+ */
+ MepId remoteMepId();
+
+ /**
+ * Indicates the MEP is acting in the role of a receiver.
+ * True by default
+ * @return true if MEP is acting as a receiver
+ */
+ Optional<Boolean> isReceiver();
+
+ /**
+ * Indicates the MEP is acting in the role of a generator.
+ * False by default
+ * @return true if MEP is acting as a generator
+ */
+ Optional<Boolean> isGenerator();
+
+ /**
+ * This attribute specifies the type of ETH-Test to perform whether it is service interrupting or not.
+ * An 'in-service' value indicates that the ETH-Test is in service and normal
+ * client service traffic is not interrupted. A 'out-of-service' value
+ * indicates that the ETH-Test is out of service and normal client service
+ * traffic is disrupted.
+ * The test-type parameter is only relevant for the generator side
+ * @return test type enumeration
+ */
+ Optional<TestType> testType();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.MepTsCreate}.
+ */
+ interface MepTsCreateBuilder {
+ MepTsCreateBuilder isReceiver(Optional<Boolean> isReceiver);
+
+ MepTsCreateBuilder isGenerator(Optional<Boolean> isGenerator);
+
+ MepTsCreateBuilder testType(Optional<TestType> testType);
+
+ MepTsCreateBuilder build();
+ }
+
+ /**
+ * Types of Test Signal test.
+ */
+ public enum TestType {
+ /**
+ * Indicates the ETH-Test is in-service and normal client service traffic is not interrupted.
+ */
+ INSERVICE,
+ /**
+ * Indicates the ETH-Test is out-of-service and normal client service traffic is disrupted.
+ */
+ OUTOFSERVICE
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/RemoteMepEntry.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/RemoteMepEntry.java
new file mode 100644
index 0000000..91d45d8
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/RemoteMepEntry.java
@@ -0,0 +1,126 @@
+/*
+ * 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;
+
+import java.time.Duration;
+
+import org.onlab.packet.MacAddress;
+import org.onosproject.incubator.net.l2monitoring.cfm.SenderIdTlv.SenderIdTlvType;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+
+/**
+ * Defined in IEEE 802.1Q Section 12.14.7.6.3 Read MEP Database - Outputs.
+ *
+ */
+public interface RemoteMepEntry {
+
+ MepId remoteMepId();
+
+ /**
+ * Get the operational state of a Remote MEP state machine for a remote MEP.
+ * @return An enumerated value
+ */
+ RemoteMepState state();
+
+ /**
+ * Get the time since Remote MEP last entered either RMEP_FAILED or RMEP_OK state.
+ * @return Duration
+ */
+ Duration failedOrOkTime();
+
+ /**
+ * Get the MAC address of the remote MEP or 0 if no CCM has been received.
+ * @return A MAC address
+ */
+ MacAddress macAddress();
+
+ /**
+ * A Boolean value indicating the state of the RDI bit in the last received CCM.
+ *
+ * @return (TRUE for RDI = 1), or FALSE, if none has been received
+ */
+ boolean rdi();
+
+ /**
+ * Get the Port Status TLV from the last CCM received from the remote MEP.
+ * @return An enumerated value
+ */
+ PortStatusTlvType portStatusTlvType();
+
+ /**
+ * Get the Interface Status TLV from the last CCM received from the remote MEP.
+ * @return An enumerated value
+ */
+ InterfaceStatusTlvType interfaceStatusTlvType();
+
+ /**
+ * Get the Sender ID TLV type from the last CCM received from the remote MEP or default.
+ * @return An enumerated value
+ */
+ SenderIdTlvType senderIdTlvType();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry}.
+ */
+ public interface RemoteMepEntryBuilder {
+ RemoteMepEntryBuilder failedOrOkTime(Duration failedOrOkTime);
+
+ RemoteMepEntryBuilder macAddress(MacAddress macAddress);
+
+ RemoteMepEntryBuilder rdi(boolean rdi);
+
+ RemoteMepEntryBuilder portStatusTlvType(PortStatusTlvType portStatusTlvType);
+
+ RemoteMepEntryBuilder interfaceStatusTlvType(InterfaceStatusTlvType interfaceStatusTlvType);
+
+ RemoteMepEntryBuilder senderIdTlvType(SenderIdTlvType senderIdTlvType);
+
+ RemoteMepEntry build();
+ }
+
+ /**
+ * Remote MEP States.
+ */
+ public enum RemoteMepState {
+ RMEP_IDLE,
+ RMEP_START,
+ RMEP_FAILED,
+ RMEP_OK
+ }
+
+ /**
+ * Port Status TLV types.
+ */
+ public enum PortStatusTlvType {
+ PS_NO_STATUS_TLV,
+ PS_BLOCKED,
+ PS_UP;
+ }
+
+ /**
+ * Interface Status TLV types.
+ */
+ public enum InterfaceStatusTlvType {
+ IS_NO_STATUS_TLV,
+ IS_UP,
+ IS_DOWN,
+ IS_TESTING,
+ IS_UNKNOWN,
+ IS_DORMANT,
+ IS_NOTPRESENT,
+ IS_LOWERLAYERDOWN;
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/SenderIdTlv.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/SenderIdTlv.java
new file mode 100644
index 0000000..12cd23b
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/SenderIdTlv.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+/**
+ * Object for representing Sender ID TLV.
+ */
+public interface SenderIdTlv {
+
+ /**
+ * Type of Sender ID TLV.
+ */
+ public enum SenderIdTlvType {
+ SI_NO_SENDER_ID_TLV,
+ SI_CHASSIS_COMPONENT,
+ SI_INTERFACE_ALIAS,
+ SI_PORT_COMPONENT,
+ SI_MAC_ADDRESS,
+ SI_NETWORK_ADDRESS,
+ SI_INTERFACE_NAME,
+ SI_LOCALLY_ASSIGNED;
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaId2Octet.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaId2Octet.java
new file mode 100644
index 0000000..d18fb6f
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaId2Octet.java
@@ -0,0 +1,52 @@
+/*
+ * 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.identifier;
+
+/**
+ * The 2 octet format of MA Short Name.
+ * This is similar to primaryVid except range is 0 to 65535
+ */
+public final class MaId2Octet extends MaIdPrimaryVid {
+ protected static int uintUpperLimit = 65535;
+
+ protected MaId2Octet(int id2octet) {
+ super(id2octet);
+ }
+
+ public static MaIdShort asMaId(int id) {
+ if (id <= lowerLimit || id > uintUpperLimit) {
+ throw new IllegalArgumentException("MA Id must be between " +
+ lowerLimit + " and " + uintUpperLimit + ". Rejecting: " + id);
+ }
+ return new MaId2Octet(id);
+ }
+
+ public static MaIdShort asMaId(String maName) {
+ int id = 0;
+ try {
+ id = Integer.parseInt(maName);
+ return asMaId(id);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("MA Name must be numeric. Rejecting: " +
+ maName + " " + e.getMessage());
+ }
+ }
+
+ @Override
+ public MaIdType nameType() {
+ return MaIdType.TWOOCTET;
+ }
+}
\ No newline at end of file
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdCharStr.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdCharStr.java
new file mode 100644
index 0000000..5fee714
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdCharStr.java
@@ -0,0 +1,52 @@
+/*
+ * 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.identifier;
+
+import org.onlab.util.Identifier;
+
+/**
+ * A representation of a string identifier as an MA identifier.
+ */
+public final class MaIdCharStr extends Identifier<String> implements MaIdShort {
+ private static final String MANAME_PATTERN = "[a-zA-Z0-9\\-:]{1,48}";
+
+ protected MaIdCharStr(String mdName) {
+ super(mdName);
+ }
+
+ @Override
+ public String maName() {
+ return identifier;
+ }
+
+ @Override
+ public int getNameLength() {
+ return identifier.length();
+ }
+
+ @Override
+ public MaIdType nameType() {
+ return MaIdType.CHARACTERSTRING;
+ }
+
+ public static MaIdShort asMaId(String maName) {
+ if (maName == null || !maName.matches(MANAME_PATTERN)) {
+ throw new IllegalArgumentException("MA Name must follow pattern "
+ + MANAME_PATTERN + " Rejecting: " + maName);
+ }
+ return new MaIdCharStr(maName);
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdIccY1731.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdIccY1731.java
new file mode 100644
index 0000000..27b3d03
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdIccY1731.java
@@ -0,0 +1,80 @@
+/*
+ * 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.identifier;
+
+import org.onlab.util.Identifier;
+
+/**
+ * ICC-based MEG ID Format, thirteen octet field.
+ *
+ * It consists of two subfields: the ITU Carrier Code (ICC) followed by a unique
+ * MEG ID code (UMC). The ITU Carrier Code consists of 1-6
+ * left-justified characters, alphabetic, or leading alphabetic
+ * with trailing numeric. The UMC code immediately follows the ICC
+ * and shall consist of 7-12 characters, with trailing NULLs,
+ * completing the 13-character MEG ID Value.
+ * reference
+ * [Y.1731] Annex A;
+ */
+public final class MaIdIccY1731 extends Identifier<String> implements MaIdShort {
+ private static final String ICC_PATTERN = "[a-z|A-Z|0-9]{1,6}";
+ private static final String UMC_PATTERN = "[a-z|A-Z|0-9]{7,12}";
+ private int iccLength = 0;
+
+ protected MaIdIccY1731(String icc, String umc) {
+ super(icc + umc);
+ iccLength = icc.length();
+ }
+
+ @Override
+ public String toString() {
+ return identifier.substring(0, iccLength) + ":" + identifier.substring(iccLength);
+ }
+
+ @Override
+ public String maName() {
+ return identifier;
+ }
+
+ @Override
+ public int getNameLength() {
+ return identifier.length();
+ }
+
+ @Override
+ public MaIdType nameType() {
+ return MaIdType.ICCY1731;
+ }
+
+ public static MaIdShort asMaId(String icc, String umc) {
+ if (icc == null || !icc.matches(ICC_PATTERN)) {
+ throw new IllegalArgumentException("ICC part must follow pattern "
+ + ICC_PATTERN + " Rejecting: " + icc);
+ } else if (umc == null || !umc.matches(UMC_PATTERN)) {
+ throw new IllegalArgumentException("UMC part must follow pattern "
+ + UMC_PATTERN + " Rejecting: " + umc);
+ }
+ return new MaIdIccY1731(icc, umc);
+ }
+
+ public static MaIdShort asMaId(String iccAndUmc) {
+ String[] nameParts = iccAndUmc.split(":");
+ if (nameParts.length != 2) {
+ throw new IllegalArgumentException("Expecting format like ICC:UMC");
+ }
+ return asMaId(nameParts[0], nameParts[1]);
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdPrimaryVid.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdPrimaryVid.java
new file mode 100644
index 0000000..f82efc4
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdPrimaryVid.java
@@ -0,0 +1,69 @@
+/*
+ * 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.identifier;
+
+import org.onlab.util.Identifier;
+
+/**
+ * A representation of a Vid identifier as an int as an MA identifier.
+ */
+public class MaIdPrimaryVid extends Identifier<Integer> implements MaIdShort {
+ private static final int PRIMARY_VID_BYTES = 2;
+ protected static int lowerLimit = 0;
+ protected static int upperLimit = 4095;
+
+ protected MaIdPrimaryVid(int primaryVid) {
+ super(primaryVid);
+ }
+
+ @Override
+ public String maName() {
+ return identifier.toString();
+ }
+
+ /**
+ * Vid length of 12 bits will be rounded up to 2 bytes (16 bits).
+ * @return 2 bytes
+ */
+ @Override
+ public int getNameLength() {
+ return PRIMARY_VID_BYTES;
+ }
+
+ @Override
+ public MaIdType nameType() {
+ return MaIdType.PRIMARYVID;
+ }
+
+ public static MaIdShort asMaId(String maName) {
+ int id = 0;
+ try {
+ id = Integer.parseInt(maName);
+ return asMaId(id);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("MA Name must be numeric. Rejecting: " +
+ maName + " " + e.getMessage());
+ }
+ }
+
+ public static MaIdShort asMaId(int id) {
+ if (id <= lowerLimit || id > upperLimit) {
+ throw new IllegalArgumentException("MA Id must be between " +
+ lowerLimit + " and " + upperLimit + ". Rejecting: " + id);
+ }
+ return new MaIdPrimaryVid(id);
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdRfc2685VpnId.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdRfc2685VpnId.java
new file mode 100644
index 0000000..d4e623c
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdRfc2685VpnId.java
@@ -0,0 +1,58 @@
+/*
+ * 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.identifier;
+
+import org.onlab.util.Identifier;
+
+/**
+ * A representation of a Rfc2685VpnId identifier in Hexadecimal as an MA identifier.
+ */
+public final class MaIdRfc2685VpnId extends Identifier<String> implements MaIdShort {
+ private static final String VPNID_HEX_PATTERN = "([a-f|A-F|0-9]{2}:){6}[a-f|A-F|0-9]{2}";
+
+ protected MaIdRfc2685VpnId(String maNameHex) {
+ super(maNameHex);
+ }
+
+ @Override
+ public String maName() {
+ return identifier;
+ }
+
+ /**
+ * Identifier will be in the format aa:bb:cc:dd:ee:ff:11.
+ * Each pair of hex chars (and one colon) is one byte
+ * To get the length in bytes add 1 (extra colon) and divide by 3
+ * @return name length in bytes
+ */
+ @Override
+ public int getNameLength() {
+ return (identifier.length() + 1) / 3;
+ }
+
+ @Override
+ public MaIdType nameType() {
+ return MaIdType.RFC2685VPNID;
+ }
+
+ public static MaIdShort asMaIdHex(String hexString) {
+ if (hexString == null || !hexString.matches(VPNID_HEX_PATTERN)) {
+ throw new IllegalArgumentException("MA Name must follow pattern " +
+ VPNID_HEX_PATTERN + " Rejecting: " + hexString);
+ }
+ return new MaIdRfc2685VpnId(hexString.toLowerCase());
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdShort.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdShort.java
new file mode 100644
index 0000000..6e1d6fb
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdShort.java
@@ -0,0 +1,73 @@
+/*
+ * 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.identifier;
+
+/**
+ * Representation of a Maintenance Association ID.
+ *
+ * The MA Id consists of a name and a name type.
+ * In certain applications the MA name and type together with the MD Name and
+ * name type are embedded in to a TLV and passed between systems, and so it is
+ * important that all combinations of the name and name type can be represented here.
+ *
+ * IEEE 802.1Q Table 21-20—Short MA Name Format.
+ */
+public interface MaIdShort {
+
+ /**
+ * Get the MA name as a string.
+ * @return A string representation of the name
+ */
+ String maName();
+
+ /**
+ * Get the length of the MD name.
+ * @return The length of the name in bytes
+ */
+ int getNameLength();
+
+ /**
+ * The type of the name.
+ * @return An enumerated value
+ */
+ MaIdType nameType();
+
+ /**
+ * Supported types of MD identifier.
+ */
+ enum MaIdType {
+ /**
+ * Implemented as {@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr}.
+ */
+ CHARACTERSTRING,
+ /**
+ * Implemented as {@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaId2Octet}.
+ */
+ TWOOCTET,
+ /**
+ * Implemented as {@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdIccY1731}.
+ */
+ ICCY1731,
+ /**
+ * Implemented as {@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdPrimaryVid}.
+ */
+ PRIMARYVID,
+ /**
+ * Implemented as {@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdRfc2685VpnId}.
+ */
+ RFC2685VPNID
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdId.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdId.java
new file mode 100644
index 0000000..4d82f51
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdId.java
@@ -0,0 +1,75 @@
+/*
+ * 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.identifier;
+
+/**
+ * Representation of a Maintenance Domain ID.
+ *
+ * The MD Id consists of a name and a name type.
+ * In certain applications the MD name and type are embedded in to a TLV and
+ * passed between systems, and so it is important that all combinations of the
+ * name and name type can be represented here.
+ *
+ * For example the name "test1.domain.tld" could be a valid with either a
+ * CharacterString name type and a DomainName name type. Both could be present
+ * on the same system concurrently and must be distinguished by the name type
+ *
+ * IEEE 802.1Q Table 21-19—Maintenance Domain Name Format.
+ */
+public interface MdId {
+ public static final int MD_NAME_MAX_LEN = 45;
+ public static final int MD_NAME_MIN_LEN = 1;
+
+ /**
+ * Get the MD name as a string.
+ * @return A string representation of the name
+ */
+ String mdName();
+
+ /**
+ * Get the length of the MD name.
+ * @return The length of the name in bytes
+ */
+ int getNameLength();
+
+ /**
+ * The type of the name.
+ * @return An enumerated value
+ */
+ MdNameType nameType();
+
+ /**
+ * Supported types of MA identifier.
+ */
+ enum MdNameType {
+ /**
+ * Implemented as {@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr}.
+ */
+ CHARACTERSTRING,
+ /**
+ * Implemented as {@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdDomainName}.
+ */
+ DOMAINNAME,
+ /**
+ * Implemented as {@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdMacUint}.
+ */
+ MACANDUINT,
+ /**
+ * Implemented as {@link org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdNone}.
+ */
+ NONE
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdCharStr.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdCharStr.java
new file mode 100644
index 0000000..5fea05a
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdCharStr.java
@@ -0,0 +1,53 @@
+/*
+ * 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.identifier;
+
+import org.onlab.util.Identifier;
+
+/**
+ * A representation of a string identifier as an MD identifier.
+ */
+public final class MdIdCharStr extends Identifier<String> implements MdId {
+ private static final String MDNAME_PATTERN =
+ "[a-zA-Z0-9\\-:\\.]{" + MD_NAME_MIN_LEN + "," + MD_NAME_MAX_LEN + "}";
+
+ protected MdIdCharStr(String mdName) {
+ super(mdName);
+ }
+
+ @Override
+ public String mdName() {
+ return identifier;
+ }
+
+ @Override
+ public int getNameLength() {
+ return identifier.length();
+ }
+
+ @Override
+ public MdNameType nameType() {
+ return MdNameType.CHARACTERSTRING;
+ }
+
+ public static MdId asMdId(String mdName) {
+ if (mdName == null || !mdName.matches(MDNAME_PATTERN)) {
+ throw new IllegalArgumentException("MD Name must follow pattern "
+ + MDNAME_PATTERN + " Rejecting: " + mdName);
+ }
+ return new MdIdCharStr(mdName);
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdDomainName.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdDomainName.java
new file mode 100644
index 0000000..c015fd1
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdDomainName.java
@@ -0,0 +1,64 @@
+/*
+ * 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.identifier;
+
+import org.onlab.util.Identifier;
+
+import com.google.common.net.InternetDomainName;
+
+/**
+ * A representation of a domain name as an MD identifier.
+ */
+public class MdIdDomainName extends Identifier<InternetDomainName> implements MdId {
+
+ protected MdIdDomainName(InternetDomainName mdDomainName) {
+ super(mdDomainName);
+ }
+
+ @Override
+ public String mdName() {
+ return identifier.toString();
+ }
+
+ @Override
+ public int getNameLength() {
+ return identifier.toString().length();
+ }
+
+ public static MdId asMdId(String mdName) {
+ if (mdName == null || !InternetDomainName.isValid(mdName)) {
+ throw new IllegalArgumentException("MD Name must follow internet domain name pattern "
+ + " Rejecting: " + mdName);
+ }
+ return asMdId(InternetDomainName.from(mdName));
+ }
+
+ @Override
+ public MdNameType nameType() {
+ return MdNameType.DOMAINNAME;
+ }
+
+
+ public static MdId asMdId(InternetDomainName mdName) {
+ if (mdName == null || mdName.toString().length() < MD_NAME_MIN_LEN ||
+ mdName.toString().length() > MD_NAME_MAX_LEN) {
+ throw new IllegalArgumentException("MD Domain Name must be between " +
+ MD_NAME_MIN_LEN + " and " + MD_NAME_MAX_LEN + " chars long"
+ + " Rejecting: " + mdName);
+ }
+ return new MdIdDomainName(mdName);
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdMacUint.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdMacUint.java
new file mode 100644
index 0000000..b790f0e
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdMacUint.java
@@ -0,0 +1,73 @@
+/*
+ * 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.identifier;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.onlab.packet.MacAddress;
+import org.onlab.util.Identifier;
+
+/**
+ * A representation of a Mac Address and Unsigned Integer as an MD identifier.
+ */
+public class MdIdMacUint extends Identifier<Pair<MacAddress, Integer>> implements MdId {
+ private static final String MACUINT_PATTERN = "([a-fA-F0-9]{2}[\\-:]){6}[0-9]{1,5}";
+ private static final int MAC_UINT_LENGTH_BYTES = 8;
+ private static final int UINT_MIN = 0;
+ private static final int UINT_MAX = 65535;
+
+ protected MdIdMacUint(Pair<MacAddress, Integer> macAndUint) {
+ super(macAndUint);
+ }
+
+ @Override
+ public String mdName() {
+ return identifier.getLeft().toString() + ":" + identifier.getRight();
+ }
+
+ @Override
+ public String toString() {
+ return mdName();
+ }
+
+ @Override
+ public int getNameLength() {
+ return MAC_UINT_LENGTH_BYTES;
+ }
+
+ public static MdId asMdId(String mdName) {
+ if (mdName == null || !mdName.matches(MACUINT_PATTERN)) {
+ throw new IllegalArgumentException("MD Name must follow pattern "
+ + MACUINT_PATTERN + " Rejecting: " + mdName);
+ }
+ MacAddress macAddress = MacAddress.valueOf(mdName.substring(0, 17));
+ int uInt = Integer.parseInt(mdName.substring(18));
+
+ return asMdId(macAddress, uInt);
+ }
+
+ @Override
+ public MdNameType nameType() {
+ return MdNameType.MACANDUINT;
+ }
+
+ public static MdId asMdId(MacAddress macAddress, int uInt) {
+ if (uInt < UINT_MIN || uInt > UINT_MAX) {
+ throw new IllegalArgumentException("uInt must be between " +
+ UINT_MIN + " and " + UINT_MAX + ". Rejecting: " + uInt);
+ }
+ return new MdIdMacUint(Pair.of(macAddress, uInt));
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdNone.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdNone.java
new file mode 100644
index 0000000..0e9eaa8
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdNone.java
@@ -0,0 +1,59 @@
+/*
+ * 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.identifier;
+
+/**
+ * A representation of NONE as an MA identifier.
+ */
+public class MdIdNone implements MdId {
+
+ @Override
+ public String mdName() {
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return "";
+ }
+
+ @Override
+ public int getNameLength() {
+ return 0;
+ }
+
+ @Override
+ public MdNameType nameType() {
+ return MdNameType.NONE;
+ }
+
+ public static MdId asMdId() {
+ return new MdIdNone();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof MdIdNone) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MepId.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MepId.java
new file mode 100644
index 0000000..dde3da3
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MepId.java
@@ -0,0 +1,46 @@
+/*
+ * 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.identifier;
+
+import org.onlab.util.Identifier;
+
+/**
+ * Representation of a Mep Id.
+ */
+public final class MepId extends Identifier<Short> {
+
+ private MepId(short id) {
+ super(id);
+ }
+
+ public static MepId valueOf(short id) {
+ if (id < 1 || id > 8191) {
+ throw new IllegalArgumentException(
+ "Invalid value for Mep Id - must be between 1-8191 inclusive. "
+ + "Rejecting " + id);
+ }
+ return new MepId(id);
+ }
+
+ public short value() {
+ return this.identifier;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(identifier);
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MepKeyId.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MepKeyId.java
new file mode 100644
index 0000000..afb337b
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MepKeyId.java
@@ -0,0 +1,87 @@
+/*
+ * 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.identifier;
+
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep;
+
+/**
+ * Immutable class to represent a unique identifier of a Mep.
+ */
+public class MepKeyId {
+ private MdId mdId;
+ private MaIdShort maId;
+ private MepId mepId;
+
+ public MepKeyId(MdId mdId, MaIdShort maId, MepId mepId) {
+ this.mdId = mdId;
+ this.maId = maId;
+ this.mepId = mepId;
+ if (mdId == null || maId == null || mepId == null) {
+ throw new IllegalArgumentException("Arguments to MepKeyId constructor cannot be null");
+ }
+ }
+
+ public MepKeyId(Mep mep) {
+ this.mdId = mep.mdId();
+ this.maId = mep.maId();
+ this.mepId = mep.mepId();
+ }
+
+ public MdId mdId() {
+ return mdId;
+ }
+
+ public MaIdShort maId() {
+ return maId;
+ }
+
+ public MepId mepId() {
+ return mepId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ MepKeyId mepKeyId = (MepKeyId) o;
+
+ if (mdId != null ? !mdId.equals(mepKeyId.mdId) : mepKeyId.mdId != null) {
+ return false;
+ }
+ if (maId != null ? !maId.equals(mepKeyId.maId) : mepKeyId.maId != null) {
+ return false;
+ }
+ return mepId != null ? mepId.equals(mepKeyId.mepId) : mepKeyId.mepId == null;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = mdId != null ? mdId.hashCode() : 0;
+ result = 31 * result + (maId != null ? maId.hashCode() : 0);
+ result = 31 * result + (mepId != null ? mepId.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return mdId.mdName() + "/" + maId.maName() + "/" + mepId();
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/package-info.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/package-info.java
new file mode 100644
index 0000000..7d5a4eb
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Identifiers related to Connectivity Fault Management functionality from IEEE 802.1Q Chapter 18.
+ */
+package org.onosproject.incubator.net.l2monitoring.cfm.identifier;
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/package-info.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/package-info.java
new file mode 100644
index 0000000..41bf1b9
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+/**
+ * Object model for Connectivity Fault Management functionality from IEEE 802.1Q Chapter 18.
+ *
+ * See {@link org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain} for the hierarchy.
+ */
+package org.onosproject.incubator.net.l2monitoring.cfm;
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmConfigException.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmConfigException.java
new file mode 100644
index 0000000..6d0d057
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmConfigException.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016-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.service;
+
+/**
+ * Exception for configuration related to Connectivity Fault Management.
+ */
+public class CfmConfigException extends Throwable {
+
+ private static final long serialVersionUID = 1L;
+
+ public CfmConfigException(String message) {
+ super(message);
+ }
+
+ public CfmConfigException(Throwable t) {
+ super(t);
+ }
+
+ public CfmConfigException(String message, Throwable t) {
+ super(message, t);
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMdService.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMdService.java
new file mode 100644
index 0000000..b495eb9
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMdService.java
@@ -0,0 +1,98 @@
+/*
+ * 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.service;
+
+import java.util.Collection;
+import java.util.Optional;
+
+import org.onosproject.event.ListenerService;
+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;
+
+/**
+ * For the management of Maintenance Domains and Maintenance Associations.
+ */
+public interface CfmMdService extends ListenerService<MdEvent, MdListener> {
+
+ /**
+ * Get a list of all of the Maintenance Domains on the system.
+ * @return A collection Maintenance domains from the Distributed MD Store.
+ */
+ Collection<MaintenanceDomain> getAllMaintenanceDomain();
+
+ /**
+ * Get a specific Maintenance Domain by its identifier.
+ * @param mdName An identifier for the Maintenance Domain
+ * @return A Maintenance Domain from the Distributed MD Store. Empty if not found.
+ */
+ Optional<MaintenanceDomain> getMaintenanceDomain(MdId mdName);
+
+ /**
+ * Delete a specific Maintenance Domain by its identifier.
+ * @param mdName An identifier for the Maintenance Domain to be deleted
+ * @return True if the MD was found and deleted
+ * @exception CfmConfigException If there were any Meps dependent on the MD or its MAs
+ */
+ boolean deleteMaintenanceDomain(MdId mdName) throws CfmConfigException;
+
+ /**
+ * Create or replace a Maintenance Domain.
+ * @param md The Maintenance Domain to create or replace
+ * @return true if an MD of this name already existed
+ * @throws CfmConfigException If it is a replacement and there were any
+ * Meps dependent on the MD or its MAs
+ */
+ boolean createMaintenanceDomain(MaintenanceDomain md) throws CfmConfigException;
+
+ /**
+ * Get all of the Maintenance Associations for a Maintenance Domain.
+ * @param mdName The identifier of the Maintenance Domain
+ * @return A collection of Maintenance Associations
+ */
+ Collection<MaintenanceAssociation> getAllMaintenanceAssociation(MdId mdName);
+
+ /**
+ * Get a specific Maintenance Association of a specific Maintenance Domain.
+ * @param mdName The identifier of the Maintenance Domain
+ * @param maName The identifier of the Maintenance Association
+ * @return A Maintenance Association from the Distributed MD Store. Empty if not found.
+ * @throws IllegalArgumentException if MD is not found
+ */
+ Optional<MaintenanceAssociation> getMaintenanceAssociation(MdId mdName, MaIdShort maName);
+
+ /**
+ * Delete a specific Maintenance Association of a specific Maintenance Domain.
+ * @param mdName The identifier of the Maintenance Domain
+ * @param maName The identifier of the Maintenance Association
+ * @return true if deleted
+ * @throws CfmConfigException If there were any Meps dependent on the MD or its MAs
+ * @throws IllegalArgumentException if MD is not found
+ */
+ boolean deleteMaintenanceAssociation(MdId mdName, MaIdShort maName) throws CfmConfigException;
+
+ /**
+ * Create or replace a Maintenance Domain of a specific Maintenance Domain.
+ * @param mdName The identifier of the Maintenance Domain
+ * @param ma A Maintenance Association
+ * @return true if an MA of this name already existed in the MD
+ * @throws CfmConfigException If it is a replacement and there were any
+ * Meps dependent on the MD or its MAs
+ * @throws IllegalArgumentException if MD is not found
+ */
+ boolean createMaintenanceAssociation(MdId mdName, MaintenanceAssociation ma) throws CfmConfigException;
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepEvent.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepEvent.java
new file mode 100644
index 0000000..cb96b52
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepEvent.java
@@ -0,0 +1,60 @@
+/*
+ * 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.service;
+
+import org.onosproject.event.AbstractEvent;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId;
+
+/**
+ * Event related to the maintenance of CFM MEPs.
+ */
+public class CfmMepEvent extends AbstractEvent<CfmMepEvent.Type, MepKeyId> {
+
+ /**
+ * Type of Mep events.
+ */
+ public enum Type {
+ /**
+ * Signifies that a new Mep has been detected.
+ */
+ MEP_ADDED,
+
+ /**
+ * Signifies that a Mep has been removed.
+ */
+ MEP_REMOVED,
+
+ /**
+ * Signifies that a Mep has been updated.
+ */
+ MEP_UPDATED,
+
+ /**
+ * Signifies that the MEP has raised a fault alarm.
+ */
+ MEP_FAULT_ALARM
+ }
+
+ /**
+ * Creates an event of a given type and for the specified Mep and the current time.
+ *
+ * @param type Mep event type
+ * @param mepKeyId event Mep subject
+ */
+ public CfmMepEvent(Type type, MepKeyId mepKeyId) {
+ super(type, mepKeyId);
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepListener.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepListener.java
new file mode 100644
index 0000000..655823f
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.service;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Entity capable of receiving {@link org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepEvent} events.
+ */
+public interface CfmMepListener extends EventListener<CfmMepEvent> {
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepProgrammable.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepProgrammable.java
new file mode 100644
index 0000000..1b902cb
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepProgrammable.java
@@ -0,0 +1,109 @@
+/*
+ * 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.service;
+
+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.identifier.MepId;
+import org.onosproject.net.driver.HandlerBehaviour;
+
+import java.util.Optional;
+
+/**
+ * Behaviour that allows Layer 2 Monitoring as defined in IEEE 802.1Q be implemented by devices.
+ *
+ * Has all of the same methods as
+ * {@link CfmMepServiceBase} so reuse that
+ */
+public interface CfmMepProgrammable extends HandlerBehaviour, CfmMepServiceBase {
+
+
+ /**
+ * Allows an MD and children MAs to be created on a device.
+ * A convenience method that allows an MD to be created on a device
+ * This is a preparation mechanism. If this was not called the MD would be created
+ * at the time of provisioning a MEP anyway
+ * @param mdId The ID of the MD to create - the details will be got from the CfmMdService
+ * @return true when created. false if it already existed
+ * @throws CfmConfigException If the MD already exists
+ */
+ boolean createMdOnDevice(MdId mdId) throws CfmConfigException;
+
+ /**
+ * Allows an MA to be created on an existing MD on a device.
+ * A convenience method that allows an MA to be created
+ * This is a preparation mechanism. If this was not called the MA would be created
+ * at the time of provisioning a MEP anyway. Also MAs can be created when they
+ * are contained in an MD using the createMdOnDevice method
+ * @param mdId The identifier of the MD to create the MA in
+ * @param maId The identifier of the MA to create - the details will be retrieved from the CfmMdService
+ * @return true when created. false if it already existed
+ * @throws CfmConfigException If the MD already exists
+ */
+ boolean createMaOnDevice(MdId mdId, MaIdShort maId) throws CfmConfigException;
+
+ /**
+ * Allows a MD and its MAs to be deleted from a device.
+ * A convenience method that allows an MD that has been provisioned on a
+ * device to be removed.
+ * All Meps must be removed first unless they are Meps unknown to ONOS.
+ * This is a cleanup mechanism. Deleting Meps in the normal way does not celan
+ * up MDs and MAs
+ * @param mdId The identifier of the MD
+ * @param oldMd The MaintenanceDomain that is being deleted
+ * @return true when deleted. false if it did not exist
+ * @throws CfmConfigException If the MD has any MAs that have MEPs then this will fail
+ */
+ boolean deleteMdOnDevice(MdId mdId, Optional<MaintenanceDomain> oldMd) throws CfmConfigException;
+
+ /**
+ * Allows an MA to be deleted from an MD on a device.
+ * A convenience method that allows an MA that has been provisioned on a
+ * device to be removed.
+ * All Meps must be removed first unless they are Meps unknown to ONOS.
+ * This is a cleanup mechanism. Deleting Meps in the normal way does not celan
+ * up MDs and MAs
+ * @param mdId The identifier of the MD
+ * @param maId The identifier of the MA
+ * @param oldMd The MaintenanceDomain from which the MA is being deleted
+ * @return true when deleted. false if it did not exist
+ * @throws CfmConfigException If the MA has any MEPs then this will fail
+ */
+ boolean deleteMaOnDevice(MdId mdId, MaIdShort maId,
+ Optional<MaintenanceDomain> oldMd) throws CfmConfigException;
+
+ /**
+ * Creates a Remote Mep entry on an MA.
+ * @param mdId The identifier of the MD
+ * @param maId The identifier of the MA
+ * @param remoteMep The remote Mep Id to remove from the MA
+ * @return true when deleted. false if it did not exist
+ * @throws CfmConfigException If the MA does not exist this will fail
+ */
+ boolean createMaRemoteMepOnDevice(MdId mdId, MaIdShort maId, MepId remoteMep) throws CfmConfigException;
+
+ /**
+ * Deletes a Remote Mep entry on an MA.
+ * @param mdId The identifier of the MD
+ * @param maId The identifier of the MA
+ * @param remoteMep The remote Mep Id to remove from the MA
+ * @return true when deleted. false if it did not exist
+ * @throws CfmConfigException If the MA does not exist this will fail
+ */
+ boolean deleteMaRemoteMepOnDevice(MdId mdId, MaIdShort maId, MepId remoteMep) throws CfmConfigException;
+
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepService.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepService.java
new file mode 100644
index 0000000..c774c65
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepService.java
@@ -0,0 +1,55 @@
+/*
+ * 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.service;
+
+import java.util.Collection;
+
+import org.onosproject.event.ListenerService;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep;
+import org.onosproject.incubator.net.l2monitoring.cfm.MepEntry;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
+import org.onosproject.net.DeviceId;
+
+/**
+ * For the management of Maintenance Association Endpoints.
+ *
+ * These are dependent on the Maintenance Domain service which maintains the
+ * Maintenance Domain and Maintenance Associations
+ */
+public interface CfmMepService
+ extends ListenerService<CfmMepEvent, CfmMepListener>, CfmMepServiceBase {
+ /**
+ * Retrieve all {@link org.onosproject.incubator.net.l2monitoring.cfm.MepEntry}(s) belonging to an MA.
+ * @param mdName A Maintenance Domain
+ * @param maName A Maintetance Association in the MD
+ * @return A collection of MEP Entries
+ * @throws CfmConfigException If there a problem with the MD or MA
+ */
+ Collection<MepEntry> getAllMeps(MdId mdName, MaIdShort maName)
+ throws CfmConfigException;
+
+ /**
+ * Retrieve all {@link org.onosproject.incubator.net.l2monitoring.cfm.Mep}(s) belonging to an MA.
+ * Note: This just returns the configuration part of the Mep, not the MepEntry
+ * which contains config and state
+ * @param deviceId A device id
+ * @return A collection of MEP Entries
+ * @throws CfmConfigException If there a problem with the MD or MA
+ */
+ Collection<Mep> getAllMepsByDevice(DeviceId deviceId)
+ throws CfmConfigException;
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepServiceBase.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepServiceBase.java
new file mode 100644
index 0000000..71e5611
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/CfmMepServiceBase.java
@@ -0,0 +1,95 @@
+/*
+ * 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.service;
+
+import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain;
+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 java.util.Optional;
+
+public interface CfmMepServiceBase {
+ /**
+ * Retrieve a named {@link org.onosproject.incubator.net.l2monitoring.cfm.MepEntry} belonging to an MA.
+ * @param mdName A Maintenance Domain
+ * @param maName A Maintetance Association in the MD
+ * @param mepId A Mep Id
+ * @return A MEP Entry or null if none found
+ * @throws CfmConfigException If there a problem with the MD, MA or MEP
+ */
+ MepEntry getMep(MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException;
+
+ /**
+ * Delete a named {@link org.onosproject.incubator.net.l2monitoring.cfm.Mep} belonging to an MA.
+ * @param mdName A Maintenance Domain
+ * @param maName A Maintetance Association in the MD
+ * @param mepId A Mep Id
+ * @param oldMd The MaintenanceDomain from which the MEP is being deleted
+ * @return true if the MEP was deleted successfully. false if it was not found
+ * @throws CfmConfigException If there a problem with the MD or MA
+ */
+ boolean deleteMep(MdId mdName, MaIdShort maName, MepId mepId, Optional<MaintenanceDomain> oldMd)
+ throws CfmConfigException;
+
+ /**
+ * Create a named {@link org.onosproject.incubator.net.l2monitoring.cfm.Mep} on an MA.
+ * @param mdName A Maintenance Domain
+ * @param maName A Maintetance Association in the MD
+ * @param mep A Mep object
+ * @return True if it was created successfully. False if the object already exists.
+ * @throws CfmConfigException If there a problem with the MD, MA or MEP
+ */
+ boolean createMep(MdId mdName, MaIdShort maName, Mep mep)
+ throws CfmConfigException;
+
+ /**
+ * Create a {@link org.onosproject.incubator.net.l2monitoring.cfm.MepLbEntry Loopback} session on the named Mep.
+ * @param mdName A Maintenance Domain
+ * @param maName A Maintetance Association in the MD
+ * @param mepId A Mep Id
+ * @param lbCreate The Loopback session details
+ * @throws CfmConfigException If there a problem with the MD, MA or MEP
+ */
+ void transmitLoopback(MdId mdName, MaIdShort maName, MepId mepId,
+ MepLbCreate lbCreate) throws CfmConfigException;
+
+ /**
+ * Abort a {@link org.onosproject.incubator.net.l2monitoring.cfm.MepLbEntry Loopback} session on the named Mep.
+ * @param mdName A Maintenance Domain
+ * @param maName A Maintetance Association in the MD
+ * @param mepId A Mep Id
+ * @throws CfmConfigException If there a problem with the MD, MA or MEP
+ */
+ void abortLoopback(MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException;
+
+ /**
+ * Create a {@link org.onosproject.incubator.net.l2monitoring.cfm.MepLtEntry Linktrace} session on the named Mep.
+ * @param mdName A Maintenance Domain
+ * @param maName A Maintetance Association in the MD
+ * @param mepId A Mep Id
+ * @param ltCreate The Linktrace session details
+ * @throws CfmConfigException If there a problem with the MD, MA or MEP
+ */
+ void transmitLinktrace(MdId mdName, MaIdShort maName, MepId mepId,
+ MepLtCreate ltCreate) throws CfmConfigException;
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MdEvent.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MdEvent.java
new file mode 100644
index 0000000..49023d4
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MdEvent.java
@@ -0,0 +1,92 @@
+/*
+ * 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.service;
+
+import com.google.common.base.MoreObjects;
+import org.onlab.util.Tools;
+import org.onosproject.event.AbstractEvent;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain;
+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 java.util.Optional;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Event related to the maintenance of CFM MDs.
+ */
+public class MdEvent extends AbstractEvent<MdEvent.Type, MdId> {
+
+ private MaIdShort maId;
+ private MaintenanceDomain oldMd;
+ /**
+ * MD Event types supported.
+ */
+ public enum Type {
+ MD_ADDED,
+ MD_REMOVED,
+ MD_UPDATED,
+ MA_ADDED,
+ MA_REMOVED
+ }
+
+ public MdEvent(Type type, MdId mdId) {
+ super(type, mdId);
+ }
+
+ /**
+ * Constructor that allows the MD to be held in the event.
+ * This is useful if the MD had been deleted - it will be the only way of
+ * retrieving some of its attributes
+ * @param type The type of the event
+ * @param mdId The ID of the MD
+ * @param md The whole MD
+ * @throws CfmConfigException if there's a problem copying MD
+ */
+ public MdEvent(Type type, MdId mdId, MaintenanceDomain md) throws CfmConfigException {
+ super(type, mdId);
+ this.oldMd = DefaultMaintenanceDomain.builder(md).build();
+ }
+
+ public MdEvent(Type type, MdId mdId, MaintenanceDomain md, MaIdShort maId)
+ throws CfmConfigException {
+ super(type, mdId);
+ this.maId = maId;
+ this.oldMd = DefaultMaintenanceDomain.builder(md).build();
+ }
+
+ public Optional<MaIdShort> maId() {
+ return maId == null ? Optional.empty() : Optional.of(maId);
+ }
+
+ public Optional<MaintenanceDomain> md() {
+ return oldMd == null ? Optional.empty() : Optional.of(oldMd);
+ }
+
+ @Override
+ public String toString() {
+ MoreObjects.ToStringHelper helper = toStringHelper(this)
+ .add("time", Tools.defaultOffsetDataTime(time()))
+ .add("type", type())
+ .add("subject", subject());
+ if (maId != null) {
+ helper = helper.add("subject2", maId);
+ }
+ return helper.toString();
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MdListener.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MdListener.java
new file mode 100644
index 0000000..ca840d8
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MdListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.service;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Listener interface for MD Store.
+ */
+public interface MdListener extends EventListener<MdEvent> {
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MdStore.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MdStore.java
new file mode 100644
index 0000000..26a3933
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MdStore.java
@@ -0,0 +1,58 @@
+/*
+ * 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.service;
+
+import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
+import org.onosproject.store.Store;
+
+import java.util.Collection;
+import java.util.Optional;
+
+/**
+ * {@link org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain Maintenance Domain's} storage interface.
+ * Note: because the MaintenanceDomain is immutable if anything needs to be
+ * changed in it, then it must be replaced in the store. This includes adding
+ * and deleting Maintenance Associations from an MD.
+ */
+public interface MdStore extends Store<MdEvent, MdStoreDelegate> {
+ /**
+ * Get a list of all of the Maintenance Domains on the system.
+ * @return A collection Maintenance domains from the MD Store.
+ */
+ Collection<MaintenanceDomain> getAllMaintenanceDomain();
+
+ /**
+ * Get a specific Maintenance Domain by its identifier.
+ * @param mdName An identifier for the Maintenance Domain
+ * @return A Maintenance Domain from the MD Store. Empty if not found.
+ */
+ Optional<MaintenanceDomain> getMaintenanceDomain(MdId mdName);
+
+ /**
+ * Delete a specific Maintenance Domain by its identifier.
+ * @param mdName An identifier for the Maintenance Domain to be deleted
+ * @return True if the MD was found and deleted
+ */
+ boolean deleteMaintenanceDomain(MdId mdName);
+
+ /**
+ * Create or replace a Maintenance Domain.
+ * @param md The Maintenance Domain to create or replace
+ * @return true if an MD of this name already existed
+ */
+ boolean createUpdateMaintenanceDomain(MaintenanceDomain md);
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MdStoreDelegate.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MdStoreDelegate.java
new file mode 100644
index 0000000..91a6260
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MdStoreDelegate.java
@@ -0,0 +1,24 @@
+/*
+ * 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.service;
+
+import org.onosproject.store.StoreDelegate;
+
+/**
+ * Delegate for MD Store.
+ */
+public interface MdStoreDelegate extends StoreDelegate<MdEvent> {
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MepStore.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MepStore.java
new file mode 100644
index 0000000..ed4bb35
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MepStore.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2018-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.service;
+
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep;
+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.MepKeyId;
+import org.onosproject.net.DeviceId;
+import org.onosproject.store.Store;
+
+import java.util.Collection;
+import java.util.Optional;
+
+/**
+ * {@link org.onosproject.incubator.net.l2monitoring.cfm.Mep Maintenance Association Endpoint's} storage interface.
+ * Note: because the Mep is immutable if anything needs to be
+ * changed in it, then it must be replaced in the store.
+ */
+public interface MepStore extends Store<CfmMepEvent, MepStoreDelegate> {
+ /**
+ * Get a list of all of the Meps on the system.
+ * @return A collection Meps from the Mep Store.
+ */
+ Collection<Mep> getAllMeps();
+
+ /**
+ * Get all Meps by MD.
+ * @param mdName An identifier for the Maintenance Domain
+ * @return MEPs from the MEP Store. Empty if not found.
+ */
+ Collection<Mep> getMepsByMd(MdId mdName);
+
+ /**
+ * Get all Meps by MD, MA.
+ * @param mdName An identifier for the Maintenance Domain
+ * @param maName An identifier for the Maintenance Association
+ * @return MEPs from the MEP Store. Empty if not found.
+ */
+ Collection<Mep> getMepsByMdMa(MdId mdName, MaIdShort maName);
+
+ /**
+ * Get all Meps by DeviceId.
+ * @param deviceId An identifier for the Device
+ * @return MEPs from the MEP Store. Empty if not found.
+ */
+ Collection<Mep> getMepsByDeviceId(DeviceId deviceId);
+
+ /**
+ * Get a specific Mep by its Mep key id.
+ * @param mepKeyId An unique identifier for the MEP
+ * @return A MEP from the MEP Store. Empty if not found.
+ */
+ Optional<Mep> getMep(MepKeyId mepKeyId);
+
+ /**
+ * Delete a specific Mep by its identifier.
+ * @param mepKeyId An unique identifier for the MEP
+ * @return True if the Mep was found and deleted
+ */
+ boolean deleteMep(MepKeyId mepKeyId);
+
+ /**
+ * Create or replace a Mep.
+ * @param mepKeyId An unique identifier for the MEP
+ * @param mep The new MEP
+ * @return true if an Mep of this name already existed
+ */
+ boolean createUpdateMep(MepKeyId mepKeyId, Mep mep);
+
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MepStoreDelegate.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MepStoreDelegate.java
new file mode 100644
index 0000000..6d5dfd3
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/MepStoreDelegate.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2018-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.service;
+
+import org.onosproject.store.StoreDelegate;
+
+/**
+ * Delegate for MEP Store.
+ */
+public interface MepStoreDelegate extends StoreDelegate<CfmMepEvent> {
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/package-info.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/package-info.java
new file mode 100644
index 0000000..79ca829
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/service/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Interfaces related to the Service for Connectivity Fault Management.
+ */
+package org.onosproject.incubator.net.l2monitoring.cfm.service;
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/DefaultMeasurementCreateBase.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/DefaultMeasurementCreateBase.java
new file mode 100644
index 0000000..62b9e3a
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/DefaultMeasurementCreateBase.java
@@ -0,0 +1,287 @@
+/*
+ * 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.soam;
+
+import java.time.Duration;
+import java.time.Instant;
+
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.soam.StartTime.StartTimeOption;
+import org.onosproject.incubator.net.l2monitoring.soam.StopTime.StopTimeOption;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DataPattern;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.TestTlvPattern;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.Version;
+
+/**
+ * Abstract implementation of {@link org.onosproject.incubator.net.l2monitoring.soam.MeasurementCreateBase}.
+ */
+public abstract class DefaultMeasurementCreateBase
+ implements MeasurementCreateBase {
+ protected final Version version;
+
+ protected final MepId remoteMepId;
+ protected final Duration messagePeriod;
+ protected final Priority priority;
+ protected final Short frameSize;
+ protected final DataPattern dataPattern;
+ protected final boolean testTlvIncluded;
+ protected final TestTlvPattern testTlvPattern;
+ protected final Duration measurementInterval;
+ protected final Short numberIntervalsStored;
+ protected final boolean alignMeasurementIntervals;
+ protected final Duration alignMeasurementOffset;
+ protected final SessionType sessionType;
+ protected final StartTime startTime;
+ protected final StopTime stopTime;
+
+ protected DefaultMeasurementCreateBase(DefaultMeasCreateBaseBuilder builder) {
+ this.version = builder.version;
+
+ this.remoteMepId = builder.remoteMepId;
+ this.messagePeriod = builder.messagePeriod;
+ this.priority = builder.priority;
+ this.frameSize = builder.frameSize;
+ this.dataPattern = builder.dataPattern;
+ this.testTlvIncluded = builder.testTlvIncluded;
+ this.testTlvPattern = builder.testTlvPattern;
+ this.measurementInterval = builder.measurementInterval;
+ this.numberIntervalsStored = builder.numberIntervalsStored;
+ this.alignMeasurementIntervals = builder.alignMeasurementIntervals;
+ this.alignMeasurementOffset = builder.alignMeasurementOffset;
+ this.sessionType = builder.sessionType;
+ this.startTime = builder.startTime;
+ this.stopTime = builder.stopTime;
+ }
+
+ @Override
+ public Version version() {
+ return version;
+ }
+
+ @Override
+ public MepId remoteMepId() {
+ return remoteMepId;
+ }
+
+ @Override
+ public Duration messagePeriod() {
+ return messagePeriod;
+ }
+
+ @Override
+ public Priority priority() {
+ return priority;
+ }
+
+ @Override
+ public Short frameSize() {
+ return frameSize;
+ }
+
+ @Override
+ public DataPattern dataPattern() {
+ return dataPattern;
+ }
+
+ @Override
+ public boolean testTlvIncluded() {
+ return testTlvIncluded;
+ }
+
+ @Override
+ public TestTlvPattern testTlvPattern() {
+ return testTlvPattern;
+ }
+
+ @Override
+ public Duration measurementInterval() {
+ return measurementInterval;
+ }
+
+ @Override
+ public Short numberIntervalsStored() {
+ return numberIntervalsStored;
+ }
+
+ @Override
+ public boolean alignMeasurementIntervals() {
+ return alignMeasurementIntervals;
+ }
+
+ @Override
+ public Duration alignMeasurementOffset() {
+ return alignMeasurementOffset;
+ }
+
+ @Override
+ public SessionType sessionType() {
+ return sessionType;
+ }
+
+ @Override
+ public StartTime startTime() {
+ return startTime;
+ }
+
+ @Override
+ public StopTime stopTime() {
+ return stopTime;
+ }
+
+ /**
+ * Abstract Builder class for building.
+ * {@link org.onosproject.incubator.net.l2monitoring.soam.MeasurementCreateBase}.
+ */
+ protected abstract static class DefaultMeasCreateBaseBuilder implements MeasCreateBaseBuilder {
+ protected final Version version;
+ protected final MepId remoteMepId;
+ protected final Priority priority;
+
+ protected Duration messagePeriod;
+ protected Short frameSize;
+ protected DataPattern dataPattern;
+ protected boolean testTlvIncluded;
+ protected TestTlvPattern testTlvPattern;
+ protected Duration measurementInterval;
+ protected Short numberIntervalsStored;
+ protected boolean alignMeasurementIntervals;
+ protected Duration alignMeasurementOffset;
+ protected SessionType sessionType;
+ protected StartTime startTime;
+ protected StopTime stopTime;
+
+ protected DefaultMeasCreateBaseBuilder(Version version,
+ MepId remoteMepId, Priority priority)
+ throws SoamConfigException {
+ super();
+ if (remoteMepId == null) {
+ throw new SoamConfigException("RemoteMepId is null");
+ }
+ this.remoteMepId = remoteMepId;
+ this.version = version;
+ this.priority = priority;
+ }
+
+ @Override
+ public MeasCreateBaseBuilder messagePeriod(Duration messagePeriod) throws SoamConfigException {
+ if (messagePeriod.toMillis() < 3 || messagePeriod.toMillis() > 3600000) {
+ throw new SoamConfigException("Message Period must be between 3-3600000ms. Rejecting: "
+ + messagePeriod);
+ }
+ this.messagePeriod = messagePeriod;
+ return this;
+ }
+
+ @Override
+ public MeasCreateBaseBuilder frameSize(Short frameSize) throws SoamConfigException {
+ if (frameSize < 64 || frameSize > 9600) {
+ throw new SoamConfigException("Frame Size must be between 64-9600 bytes."
+ + " Rejecting: " + frameSize);
+ }
+ this.frameSize = frameSize;
+ return this;
+ }
+
+ @Override
+ public MeasCreateBaseBuilder dataPattern(DataPattern dataPattern) {
+ this.dataPattern = dataPattern;
+ return this;
+ }
+
+ @Override
+ public MeasCreateBaseBuilder testTlvIncluded(boolean testTlvIncluded) {
+ this.testTlvIncluded = testTlvIncluded;
+ return this;
+ }
+
+ @Override
+ public MeasCreateBaseBuilder testTlvPattern(TestTlvPattern testTlvPattern) {
+ this.testTlvPattern = testTlvPattern;
+ return this;
+ }
+
+ @Override
+ public MeasCreateBaseBuilder measurementInterval(Duration measurementInterval) throws SoamConfigException {
+ if (measurementInterval.toMinutes() < 1 || measurementInterval.toMinutes() > 525600) {
+ throw new SoamConfigException(
+ "Measurement Interval must be between 1..525600 minutes. Rejecting: " + measurementInterval);
+ }
+ this.measurementInterval = measurementInterval;
+ return this;
+ }
+
+ @Override
+ public MeasCreateBaseBuilder numberIntervalsStored(Short numberIntervalsStored)
+ throws SoamConfigException {
+ if (numberIntervalsStored < 2 || numberIntervalsStored > 1000) {
+ throw new SoamConfigException(
+ "Number Intervals Stored must be between 2-1000. "
+ + "Rejecting: " + numberIntervalsStored);
+ }
+ this.numberIntervalsStored = numberIntervalsStored;
+ return this;
+ }
+
+ @Override
+ public MeasCreateBaseBuilder alignMeasurementIntervals(boolean alignMeasurementIntervals) {
+ this.alignMeasurementIntervals = alignMeasurementIntervals;
+ return this;
+ }
+
+ @Override
+ public MeasCreateBaseBuilder alignMeasurementOffset(
+ Duration alignMeasurementOffset) throws SoamConfigException {
+ if (alignMeasurementOffset.toMinutes() < 0 || alignMeasurementOffset.toMinutes() > 525600) {
+ throw new SoamConfigException(
+ "Align Measurement Offset must be between 0..525600 minutes. Rejecting: " +
+ alignMeasurementOffset);
+ }
+ this.alignMeasurementOffset = alignMeasurementOffset;
+ return this;
+ }
+
+ @Override
+ public MeasCreateBaseBuilder sessionType(SessionType sessionType) {
+ this.sessionType = sessionType;
+ return this;
+ }
+
+ @Override
+ public MeasCreateBaseBuilder startTime(StartTime startTime) throws SoamConfigException {
+ if (startTime.option() == StartTimeOption.ABSOLUTE &&
+ startTime.absoluteTime().isBefore(Instant.now())) {
+ throw new SoamConfigException(
+ "Start Time must be not be in the past. Rejecting: " + startTime);
+ }
+ this.startTime = startTime;
+ return this;
+ }
+
+ @Override
+ public MeasCreateBaseBuilder stopTime(StopTime stopTime) throws SoamConfigException {
+ if (stopTime.option() == StopTimeOption.ABSOLUTE &&
+ stopTime.absoluteTime().isBefore(Instant.now())) {
+ throw new SoamConfigException(
+ "Stop Time must be not be in the past. Rejecting: " + stopTime);
+ }
+ this.stopTime = stopTime;
+ return this;
+ }
+
+
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/MeasurementCreateBase.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/MeasurementCreateBase.java
new file mode 100644
index 0000000..89428b0
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/MeasurementCreateBase.java
@@ -0,0 +1,208 @@
+/*
+ * 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.soam;
+
+import java.time.Duration;
+
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DataPattern;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.TestTlvPattern;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.Version;
+
+/**
+ * A base interface with attributes that are common to both Delay and Loss Measurements.
+ */
+public interface MeasurementCreateBase {
+ /**
+ * The version of the PDUs used to perform Loss or Delay Measurement.
+ * The exact PDUs to use are specified by this object in combination with measurement-type
+ * @return The version of the PDUs
+ */
+ Version version();
+
+ /**
+ * The remote MEP to perform the tests against.
+ * @return An ID of a MEP
+ */
+ MepId remoteMepId();
+
+ /**
+ * The interval between Loss or Delay Measurement OAM message transmission.
+ * For Loss Measurement monitoring applications the default value is 1 sec.
+ * This object is not applicable if measurement-type is set to 'ccm' and is ignored for that Loss Measurement Type
+ * @return A java Duration
+ */
+ Duration messagePeriod();
+
+ /**
+ * The priority of frames with Performance Monitoring OAM message information.
+ * @return A priority enumerated value 0-7
+ */
+ Priority priority();
+
+ /**
+ * The Loss Measurement frame size between 64 bytes and the maximum transmission unit of the EVC.
+ * The range of frame sizes from 64 through 2000 octets need to be supported,
+ * and the range of frame sizes from 2001 through 9600 octets is suggested be supported.
+ * The adjustment to the frame size of the standard frame size is accomplished
+ * by the addition of a Data or Test TLV. A Data or Test TLV is only added to
+ * the frame if the frame size is greater than 64 bytes
+ * @return frame size in bytes
+ */
+ Short frameSize();
+
+ /**
+ * The LM data pattern included in a Data TLV.
+ * when the size of the LM frame is determined by the frame-size object and test-tlv-included is 'false'.
+ * If the frame size object does not define the LM frame size or
+ * test-tlv-included is 'true' the value of this object is ignored
+ * @return The data pattern - ones or zeroes
+ */
+ DataPattern dataPattern();
+
+ /**
+ * Whether a Test TLV or Data TLV is included when the size of the LM frame is determined by the frame-size object.
+ * If the frame-size object does not define the LM frame size the value of
+ * this object is ignored.
+ * @return true indicates that the Test TLV is to be included, false indicates it is not
+ */
+ boolean testTlvIncluded();
+
+ /**
+ * The type of test pattern to be sent in the LM frame Test TLV.
+ * when the size of LM PDU is determined by the frame-size object and
+ * test-tlv-included is 'true'.
+ * If the frame size object does not define the LM frame size or
+ * test-tlv-included is 'false' the value of this object is ignored
+ * @return A TLV pattern enum
+ */
+ TestTlvPattern testTlvPattern();
+
+ /**
+ * The Measurement Interval for FLR statistics.
+ * A Measurement Interval of 15 minutes needs to be supported, other
+ * intervals may be supported.
+ * @return A java Duration
+ */
+ Duration measurementInterval();
+
+ /**
+ * The number of completed measurement intervals to store in the history statistic table.
+ * At least 32 completed measurement intervals are to be stored.
+ * 96 measurement intervals are recommended to be stored
+ * @return The number to be stored.
+ */
+ Short numberIntervalsStored();
+
+ /**
+ * Whether the measurement intervals for the Loss Measurement session are aligned with a zero offset to real time.
+ * The value 'true' indicates that each Measurement Interval starts at a time
+ * which is aligned to NE time source hour if the interval is a factor of an
+ * hour, i.e. 60min/15min = 4. For instance, a measurement time interval of
+ * 15 minutes would stop/start the measurement interval at 0, 15, 30, and 45
+ * minutes of an hour. A measurement interval of 7 minutes would not align to
+ * the hour since 7 minutes is NOT a factor of an hour, i.e. 60min/7min = 8.6,
+ * and the behavior is the same as if the object is set to 'false'.
+ * The value 'false' indicates that each Measurement Interval starts at a time
+ * which is indicated by repetition-period.
+ * One side effect of the usage of this parameter is that if the value is true
+ * and the repetition-period is not a factor of an hour then the start of the
+ * next Measurement Interval will be delayed until the next factor of an hour.
+ * @return See above for the meaning of true and false
+ */
+ boolean alignMeasurementIntervals();
+
+ /**
+ * The offset in minutes from the time of day value.
+ * if align-measurement-intervals is 'true' and the repetition time is a factor
+ * of 60 minutes. If not, the value of this object is ignored.
+ * If the Measurement Interval is 15 minutes and align-measurement-intervals
+ * is true and if this object was set to 5 minutes, the Measurement Intervals
+ * would start at 5, 20, 35, 50 minutes past each hour
+ * @return A java Duration
+ */
+ Duration alignMeasurementOffset();
+
+ /**
+ * Defines the session start time.
+ * @return An object with the start time type and optionally an instant
+ */
+ StartTime startTime();
+
+ /**
+ * Defines the session stop time.
+ * @return An object with the stop time type and optionally an instant
+ */
+ StopTime stopTime();
+
+ /**
+ * Indicates whether the current session is defined to be 'proactive' or 'on-demand.
+ * @return An enumerated value
+ */
+ SessionType sessionType();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.MeasurementCreateBase}.
+ */
+ public interface MeasCreateBaseBuilder {
+ MeasCreateBaseBuilder messagePeriod(
+ Duration messagePeriod) throws SoamConfigException;
+
+ MeasCreateBaseBuilder frameSize(Short frameSize) throws SoamConfigException;
+
+ MeasCreateBaseBuilder dataPattern(DataPattern dataPattern);
+
+ MeasCreateBaseBuilder testTlvIncluded(boolean testTlvIncluded);
+
+ MeasCreateBaseBuilder testTlvPattern(TestTlvPattern testTlvPattern);
+
+ MeasCreateBaseBuilder measurementInterval(
+ Duration measurementInterval) throws SoamConfigException;
+
+ MeasCreateBaseBuilder numberIntervalsStored(
+ Short numberIntervalsStored) throws SoamConfigException;
+
+ MeasCreateBaseBuilder alignMeasurementIntervals(
+ boolean alignMeasurementIntervals);
+
+ MeasCreateBaseBuilder alignMeasurementOffset(
+ Duration alignMeasurementOffset) throws SoamConfigException;
+
+ MeasCreateBaseBuilder startTime(StartTime startTime) throws SoamConfigException;
+
+ MeasCreateBaseBuilder stopTime(StopTime stopTime) throws SoamConfigException;
+
+ MeasCreateBaseBuilder sessionType(SessionType sessionType);
+
+ }
+
+ /**
+ * Supported session types.
+ * reference [MEF SOAM IA] R3
+ */
+ public enum SessionType {
+ /**
+ * The current session is 'proactive'.
+ */
+ PROACTIVE,
+ /**
+ * The current session is 'on-demand'.
+ */
+ ONDEMAND;
+ }
+
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/MilliPct.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/MilliPct.java
new file mode 100644
index 0000000..0c6dd88
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/MilliPct.java
@@ -0,0 +1,80 @@
+/*
+ * 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.soam;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+
+/**
+ * A representation of a ratio in milli-percent.
+ */
+public final class MilliPct extends Number {
+
+ private static final long serialVersionUID = 1476288484705687568L;
+ private static NumberFormat pf = DecimalFormat.getPercentInstance();
+
+ private int value;
+
+ private MilliPct(int value) {
+ this.value = value;
+ pf.setMaximumFractionDigits(3);
+ }
+
+ public static MilliPct ofMilliPct(int value) {
+ return new MilliPct(value);
+ }
+
+ public static MilliPct ofPercent(float value) {
+ return new MilliPct(Float.valueOf(value * 1000f).intValue());
+ }
+
+ public static MilliPct ofRatio(float value) {
+ return new MilliPct(Float.valueOf(value * 100000f).intValue());
+ }
+
+ @Override
+ public int intValue() {
+ return value;
+ }
+
+ @Override
+ public long longValue() {
+ return value;
+ }
+
+ @Override
+ public float floatValue() {
+ return value;
+ }
+
+ @Override
+ public double doubleValue() {
+ return value;
+ }
+
+ public float percentValue() {
+ return value / 1000f;
+ }
+
+ public float ratioValue() {
+ return value / 100000f;
+ }
+
+ @Override
+ public String toString() {
+ return pf.format(ratioValue());
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamConfigException.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamConfigException.java
new file mode 100644
index 0000000..6ca9994
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamConfigException.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016-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.soam;
+
+/**
+ * Exception for configuration related to Service OAM.
+ */
+public class SoamConfigException extends Throwable {
+
+ private static final long serialVersionUID = 1L;
+
+ public SoamConfigException(String message) {
+ super(message);
+ }
+
+ public SoamConfigException(Throwable t) {
+ super(t);
+ }
+
+ public SoamConfigException(String message, Throwable t) {
+ super(message, t);
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamDmProgrammable.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamDmProgrammable.java
new file mode 100644
index 0000000..77582e9
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamDmProgrammable.java
@@ -0,0 +1,27 @@
+/*
+ * 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.soam;
+
+import org.onosproject.net.driver.HandlerBehaviour;
+
+/**
+ * Behaviour that allows Layer 2 SOAM PM in the form of Delay Measurement to be implemented by devices.
+ *
+ * Has all of the same methods as {@link org.onosproject.incubator.net.l2monitoring.soam.SoamService},
+ * so we don't repeat them here
+ */
+public interface SoamDmProgrammable extends HandlerBehaviour, SoamService {
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamId.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamId.java
new file mode 100644
index 0000000..a4434d9
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamId.java
@@ -0,0 +1,55 @@
+/*
+ * 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.soam;
+
+import org.onlab.util.Identifier;
+
+/**
+ * Identifier for SOAM objects.
+ */
+public class SoamId extends Identifier<Integer> {
+ protected SoamId(int id) {
+ super(id);
+ }
+
+ /**
+ * Creates a dm ID from a int value.
+ *
+ * @param id int value
+ * @return dm ID
+ */
+ public static SoamId valueOf(int id) {
+ if (id < 0) {
+ throw new IllegalArgumentException("SOAM Value must be unsigned."
+ + "Rejecting: " + id);
+ }
+ return new SoamId(id);
+ }
+
+ /**
+ * Gets the dm ID value.
+ *
+ * @return dm ID value as int
+ */
+ public int value() {
+ return this.identifier;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(identifier);
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamService.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamService.java
new file mode 100644
index 0000000..fc777cb
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamService.java
@@ -0,0 +1,334 @@
+/*
+ * 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.soam;
+
+import java.util.Collection;
+import java.util.Optional;
+
+import org.onosproject.incubator.net.l2monitoring.cfm.MepTsCreate;
+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.soam.delay.DelayMeasurementCreate;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatCurrent;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatHistory;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatCurrent;
+
+/**
+ * Methods callable on MEPs to implement SOAM functionality.
+ * Most of the methods have been derived from the MEF 38 and MEF 39 standards
+ *
+ */
+public interface SoamService {
+ /**
+ * Get all of the Delay Measurements on a particular MEP.
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @return A collection of Delay Measurements and their children
+ * @throws CfmConfigException If there's a problem with Cfm attributes
+ * @throws SoamConfigException If there's a problem with Soam attributes
+ */
+ Collection<DelayMeasurementEntry> getAllDms(MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException, SoamConfigException;
+
+ /**
+ * Get a named Delay Measurements on a particular MEP.
+ * While devices are not required to have named delay measurement objects
+ * so do. The getAllDms() method may have produced a list of DM Ids that can
+ * be used here to retrieve one DM at a time
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @param dmId The id of the Delay Measurement
+ * @return A collection of Delay Measurements and their children
+ * @throws CfmConfigException If there's a problem with Cfm attributes
+ * @throws SoamConfigException If there's a problem with Soam attributes
+ */
+ DelayMeasurementEntry getDm(MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId)
+ throws CfmConfigException, SoamConfigException;
+
+ /**
+ * Get only the current stats of a named Delay Measurements on a particular MEP.
+ * It may be useful to retrieve the current stats on their own to retrieve
+ * values between Delay Measurement intervals
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @param dmId The id of the Delay Measurement
+ * @throws CfmConfigException If there's a problem with Cfm attributes
+ * @throws SoamConfigException If there's a problem with Soam attributes
+ * @return A collection of Delay Measurements and their children
+ */
+ DelayMeasurementStatCurrent getDmCurrentStat(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId)
+ throws CfmConfigException, SoamConfigException;
+
+ /**
+ * Get only the history stats of a named Delay Measurements on a particular MEP.
+ * It may be useful to retrieve the history stats on their own to retrieve
+ * values before they have been overwritten
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @param dmId The id of the Delay Measurement
+ * @throws CfmConfigException If there's a problem with Cfm attributes
+ * @throws SoamConfigException If there's a problem with Soam attributes
+ * @return A collection of Delay Measurements and their children
+ */
+ Collection<DelayMeasurementStatHistory> getDmHistoricalStats(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId)
+ throws CfmConfigException, SoamConfigException;
+
+ /**
+ * Create a Delay Measurement on a particular MEP.
+ * MEF 39 defines a delay measurement as an ephemeral object and does not
+ * require the supporting device to persist it. It runs as an action until
+ * stopped with the corresponding abort action below.
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @param dm The parameters of the Delay Measurement
+ * @return The id of the newly created DM if available
+ * @throws CfmConfigException If there's a problem with Cfm attributes
+ * @throws SoamConfigException If there's a problem with Soam attributes
+ */
+ Optional<SoamId> createDm(MdId mdName, MaIdShort maName, MepId mepId,
+ DelayMeasurementCreate dm) throws CfmConfigException, SoamConfigException;
+
+ /**
+ * Stop all Delay Measurements on a particular MEP.
+ * This stops the Delay Measurement activity started through the
+ * createDm action above. It is up to the individual device how to implement
+ * it. It does not necessarily mean delete the DM.
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @throws CfmConfigException When the command cannot be completed
+ */
+ void abortDm(MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException;
+
+ /**
+ * Stop a particular named Delay Measurement on a particular MEP.
+ * This stops the Delay Measurement activity started through the
+ * createDm action above. It is up to the individual device how to implement
+ * it. It does not necessarily mean delete the DM.
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @param dmId The id of the DM
+ * @throws CfmConfigException When the command cannot be completed
+ */
+ void abortDm(MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId)
+ throws CfmConfigException;
+
+ /**
+ * Clear the history stats on all Delay Measurements on a particular MEP.
+ * This removes any historical stats stored on a device for one MEP
+ * It does NOT require that the Delay Measurement test is aborted.
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @throws CfmConfigException When the command cannot be completed
+ */
+ void clearDelayHistoryStats(MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException;
+
+ /**
+ * Clear the history stats on a named Delay Measurement on a particular MEP.
+ * This removes any historical stats stored on a device for one DM on one MEP
+ * It does NOT require that the Delay Measurement test is aborted.
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @param dmId The id of the DM
+ * @throws CfmConfigException When the command cannot be completed
+ */
+ void clearDelayHistoryStats(MdId mdName, MaIdShort maName, MepId mepId,
+ SoamId dmId) throws CfmConfigException;
+
+ /**
+ * Get all of the Loss Measurements on a particular MEP.
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @return A collection of Loss Measurements and their children
+ * @throws CfmConfigException When the command cannot be completed
+ * @throws SoamConfigException When the command cannot be completed
+ */
+ Collection<LossMeasurementEntry> getAllLms(MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException, SoamConfigException;
+
+ /**
+ * Get a named Loss Measurements on a particular MEP.
+ * While devices are not required to have named Loss measurement objects
+ * some do. The getAllLms() method may have produced a list of LM Ids that
+ * can be used here to retrieve one LM at a time
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @param lmId The id of the Loss Measurement
+ * @return A collection of Loss Measurements and their children
+ * @throws CfmConfigException When the command cannot be completed
+ * @throws SoamConfigException When the command cannot be completed
+ */
+ LossMeasurementEntry getLm(MdId mdName, MaIdShort maName, MepId mepId,
+ SoamId lmId) throws CfmConfigException, SoamConfigException;
+
+ /**
+ * Get only the current stats of a named Loss Measurements on a particular MEP.
+ * It may be useful to retrieve the current stats on their own to retrieve
+ * values between Loss Measurement intervals
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @param lmId The id of the Loss Measurement
+ * @return A collection of Loss Measurements and their children
+ */
+ LossMeasurementStatCurrent getLmCurrentStat(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId);
+
+ /**
+ * Get only the history stats of a named Loss Measurements on a particular MEP.
+ * It may be useful to retrieve the history stats on their own to retrieve
+ * values before they have been overwritten
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @param lmId The id of the Loss Measurement
+ * @return A collection of Loss Measurements and their children
+ */
+ Collection<LossMeasurementStatCurrent> getLmHistoricalStats(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId);
+
+ /**
+ * Create a Loss Measurement on a particular MEP.
+ * MEF 39 defines a Loss measurement as an ephemeral object and does not
+ * require the supporting device to persist it. It runs as an action until
+ * stopped with the corresponding abort action below.
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @param lm The parameters of the Loss Measurement
+ * @return The id of the newly created LM if available
+ * @throws CfmConfigException When the command cannot be completed
+ * @throws SoamConfigException When the command cannot be completed
+ */
+ Optional<SoamId> createLm(MdId mdName, MaIdShort maName, MepId mepId,
+ LossMeasurementCreate lm) throws CfmConfigException, SoamConfigException;
+
+ /**
+ * Stop all Loss Measurements on a particular MEP.
+ * This stops the Loss Measurement activity started through the
+ * createLm action above. It is up to the individual device how to implement
+ * it. It does not necessarily mean delete the LM.
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @throws CfmConfigException When the command cannot be completed
+ */
+ void abortLm(MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException;
+
+ /**
+ * Stop a particular named Loss Measurement on a particular MEP.
+ * This stops the Loss Measurement activity started through the
+ * createLm action above. It is up to the individual device how to implement
+ * it. It does not necessarily mean delete the LM.
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @param lmId The id of the LM
+ * @throws CfmConfigException When the command cannot be completed
+ */
+ void abortLm(MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId)
+ throws CfmConfigException;
+
+ /**
+ * Clear the history stats on all Loss Measurements on a particular MEP.
+ * This removes any historical stats stored on a device for one MEP
+ * It does NOT require that the Loss Measurement test is aborted.
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @throws CfmConfigException When the command cannot be completed
+ */
+ void clearLossHistoryStats(MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException;
+
+ /**
+ * Clear the history stats on a named Loss Measurement on a particular MEP.
+ * This removes any historical stats stored on a device for one LM on one MEP
+ * It does NOT require that the Loss Measurement test is aborted.
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @param lmId The id of the LM
+ * @throws CfmConfigException When the command cannot be completed
+ */
+ void clearLossHistoryStats(MdId mdName, MaIdShort maName, MepId mepId,
+ SoamId lmId) throws CfmConfigException;
+
+ /**
+ * Create a Test Signal operation on a particular MEP.
+ * MEF39 defines the Test Signal as an ephemeral operation that is not
+ * required to be persisted by a device. Only one Test Signal is active
+ * on a MEP at a time
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @param tsCreate The parameters the Test Signal is created with
+ * @throws CfmConfigException When the command cannot be completed
+ */
+ void createTestSignal(MdId mdName, MaIdShort maName, MepId mepId,
+ MepTsCreate tsCreate) throws CfmConfigException;
+
+ /**
+ * Abort a Test Signal operation on a particular MEP.
+ * Abort a Test Signal operation on a Mep
+ *
+ * @param mdName The Maintenance Domain of the MEP
+ * @param maName The Maintenance Association of the MEP
+ * @param mepId The id of the MEP itself
+ * @throws CfmConfigException When the command cannot be completed
+ */
+ void abortTestSignal(MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException;
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamTime.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamTime.java
new file mode 100644
index 0000000..d8e5924
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/SoamTime.java
@@ -0,0 +1,52 @@
+/*
+ * 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.soam;
+
+import java.time.Duration;
+import java.time.Instant;
+
+/**
+ * A base class with common attributes of StartTime and StopTime.
+ */
+public abstract class SoamTime {
+ protected final TimeOption option;
+ protected final Duration relativeTime;
+ protected final Instant absoluteTime;
+
+ public TimeOption option() {
+ return option;
+ }
+
+ public Duration relativeTime() {
+ return relativeTime;
+ }
+
+ public Instant absoluteTime() {
+ return absoluteTime;
+ }
+
+ protected SoamTime(TimeOption option, Duration relativeStart, Instant absoluteStart) {
+ this.option = option;
+ this.relativeTime = relativeStart;
+ this.absoluteTime = absoluteStart;
+ }
+
+ /**
+ * Abstract interface for TimeOptions on SoamTime concrete classes.
+ */
+ public interface TimeOption {
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/StartTime.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/StartTime.java
new file mode 100644
index 0000000..02fa765
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/StartTime.java
@@ -0,0 +1,64 @@
+/*
+ * 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.soam;
+
+import java.time.Duration;
+import java.time.Instant;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * A utility class for specifying a Start Time for Delay and Loss Measurements.
+ */
+public final class StartTime extends SoamTime {
+
+ protected StartTime(TimeOption option, Duration relativeStart, Instant absoluteStart) {
+ super(option, relativeStart, absoluteStart);
+ }
+
+ public static final StartTime immediate() {
+ return new StartTime(StartTimeOption.IMMEDIATE, null, null);
+ }
+
+ public static final StartTime relative(Duration relativeStart) {
+ return new StartTime(StartTimeOption.RELATIVE, relativeStart, null);
+ }
+
+ public static final StartTime absolute(Instant absoluteStart) {
+ return new StartTime(StartTimeOption.ABSOLUTE, null, absoluteStart);
+ }
+
+ @Override
+ public String toString() {
+ if (option == StartTimeOption.IMMEDIATE) {
+ return "immediate";
+ } else if (option == StartTimeOption.ABSOLUTE) {
+ return MoreObjects.toStringHelper(getClass()).add("absolute", absoluteTime).toString();
+ } else if (option == StartTimeOption.RELATIVE) {
+ return MoreObjects.toStringHelper(getClass()).add("relative", relativeTime).toString();
+ }
+ return "unknown";
+ }
+
+ /**
+ * Options for Start Time.
+ */
+ public enum StartTimeOption implements TimeOption {
+ IMMEDIATE,
+ RELATIVE,
+ ABSOLUTE;
+ }
+}
\ No newline at end of file
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/StopTime.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/StopTime.java
new file mode 100644
index 0000000..b581036
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/StopTime.java
@@ -0,0 +1,64 @@
+/*
+ * 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.soam;
+
+import java.time.Duration;
+import java.time.Instant;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * A utility class for specifying a Stop Time for Delay and Loss Measurements.
+ */
+public final class StopTime extends SoamTime {
+
+ private StopTime(TimeOption option, Duration relativeStart, Instant absoluteStart) {
+ super(option, relativeStart, absoluteStart);
+ }
+
+ public static final StopTime none() {
+ return new StopTime(StopTimeOption.NONE, null, null);
+ }
+
+ public static final StopTime relative(Duration relativeStop) {
+ return new StopTime(StopTimeOption.RELATIVE, relativeStop, null);
+ }
+
+ public static final StopTime absolute(Instant absoluteStop) {
+ return new StopTime(StopTimeOption.ABSOLUTE, null, absoluteStop);
+ }
+
+ @Override
+ public String toString() {
+ if (option == StopTimeOption.NONE) {
+ return "none";
+ } else if (option == StopTimeOption.ABSOLUTE) {
+ return MoreObjects.toStringHelper(getClass()).add("absolute", absoluteTime).toString();
+ } else if (option == StopTimeOption.RELATIVE) {
+ return MoreObjects.toStringHelper(getClass()).add("relative", relativeTime).toString();
+ }
+ return "unknown";
+ }
+
+ /**
+ * Options for Stop Time.
+ */
+ public enum StopTimeOption implements TimeOption {
+ NONE,
+ RELATIVE,
+ ABSOLUTE;
+ }
+}
\ No newline at end of file
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementCreate.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementCreate.java
new file mode 100644
index 0000000..f74ff04
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementCreate.java
@@ -0,0 +1,182 @@
+/*
+ * 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.soam.delay;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.soam.DefaultMeasurementCreateBase;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate}.
+ */
+public class DefaultDelayMeasurementCreate extends DefaultMeasurementCreateBase
+ implements DelayMeasurementCreate {
+
+ protected final DmType dmCfgType;
+ protected final Collection<MeasurementOption> measurementsEnabled;
+ protected final Short binsPerFdInterval;
+ protected final Short binsPerIfdvInterval;
+ protected final Short ifdvSelectionOffset;
+ protected final Short binsPerFdrInterval;
+ protected final Collection<DelayMeasurementThreshold> thresholds;
+
+ protected DefaultDelayMeasurementCreate(DefaultDmCreateBuilder builder) {
+ super(builder);
+ this.dmCfgType = builder.dmCfgType;
+ this.measurementsEnabled = builder.measurementsEnabled;
+ this.binsPerFdInterval = builder.binsPerFdInterval;
+ this.binsPerIfdvInterval = builder.binsPerIfdvInterval;
+ this.ifdvSelectionOffset = builder.ifdvSelectionOffset;
+ this.binsPerFdrInterval = builder.binsPerFdrInterval;
+ this.thresholds = builder.thresholds;
+ }
+
+ @Override
+ public DmType dmCfgType() {
+ return dmCfgType;
+ }
+
+ @Override
+ public Collection<MeasurementOption> measurementsEnabled() {
+ return measurementsEnabled;
+ }
+
+ @Override
+ public Short binsPerFdInterval() {
+ return binsPerFdInterval;
+ }
+
+ @Override
+ public Short binsPerIfdvInterval() {
+ return binsPerIfdvInterval;
+ }
+
+ @Override
+ public Short ifdvSelectionOffset() {
+ return ifdvSelectionOffset;
+ }
+
+ @Override
+ public Short binsPerFdrInterval() {
+ return binsPerFdrInterval;
+ }
+
+ @Override
+ public Collection<DelayMeasurementThreshold> thresholds() {
+ return thresholds;
+ }
+
+ public static DmCreateBuilder builder(DmType dmCfgType,
+ Version version, MepId remoteMepId, Priority priority)
+ throws SoamConfigException {
+ return new DefaultDmCreateBuilder(dmCfgType, version, remoteMepId, priority);
+ }
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate}.
+ */
+ protected static class DefaultDmCreateBuilder extends DefaultMeasCreateBaseBuilder
+ implements DmCreateBuilder {
+ protected final DmType dmCfgType;
+
+ protected Collection<MeasurementOption> measurementsEnabled;
+ protected Short binsPerFdInterval;
+ protected Short binsPerIfdvInterval;
+ protected Short ifdvSelectionOffset;
+ protected Short binsPerFdrInterval;
+ protected Collection<DelayMeasurementThreshold> thresholds;
+
+ protected DefaultDmCreateBuilder(DmType dmCfgType, Version version,
+ MepId remoteMepId, Priority priority)
+ throws SoamConfigException {
+ super(version, remoteMepId, priority);
+ this.dmCfgType = dmCfgType;
+ measurementsEnabled = new ArrayList<>();
+ thresholds = new ArrayList<>();
+ }
+
+ @Override
+ public DmCreateBuilder addToMeasurementsEnabled(
+ MeasurementOption measurementEnabled) {
+ this.measurementsEnabled.add(measurementEnabled);
+ return this;
+ }
+
+ @Override
+ public DmCreateBuilder binsPerFdInterval(Short binsPerFdInterval)
+ throws SoamConfigException {
+ if (binsPerFdInterval < 2 || binsPerFdInterval > 100) {
+ throw new SoamConfigException(
+ "Bins Per Fd Interval must be between 2..100. Rejecting: " +
+ binsPerFdInterval);
+ }
+ this.binsPerFdInterval = binsPerFdInterval;
+ return this;
+ }
+
+ @Override
+ public DmCreateBuilder binsPerIfdvInterval(Short binsPerIfdvInterval)
+ throws SoamConfigException {
+ if (binsPerIfdvInterval < 2 || binsPerIfdvInterval > 100) {
+ throw new SoamConfigException(
+ "Bins Per Ifdv Interval must be between 2..100. Rejecting: " +
+ binsPerIfdvInterval);
+ }
+ this.binsPerIfdvInterval = binsPerIfdvInterval;
+ return this;
+ }
+
+ @Override
+ public DmCreateBuilder ifdvSelectionOffset(Short ifdvSelectionOffset)
+ throws SoamConfigException {
+ if (ifdvSelectionOffset < 2 || ifdvSelectionOffset > 100) {
+ throw new SoamConfigException(
+ "IFDV Selection Offset must be between 2..100. Rejecting: " +
+ ifdvSelectionOffset);
+ }
+ this.ifdvSelectionOffset = ifdvSelectionOffset;
+ return this;
+ }
+
+ @Override
+ public DmCreateBuilder binsPerFdrInterval(Short binsPerFdrInterval)
+ throws SoamConfigException {
+ if (binsPerFdrInterval < 2 || binsPerFdrInterval > 100) {
+ throw new SoamConfigException(
+ "Bins Per Fd Interval must be between 2..100. Rejecting: " +
+ binsPerFdrInterval);
+ }
+ this.binsPerFdrInterval = binsPerFdrInterval;
+ return this;
+ }
+
+ @Override
+ public DmCreateBuilder addToThresholds(
+ DelayMeasurementThreshold threshold) {
+ this.thresholds.add(threshold);
+ return this;
+ }
+
+ @Override
+ public DelayMeasurementCreate build() {
+ return new DefaultDelayMeasurementCreate(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementEntry.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementEntry.java
new file mode 100644
index 0000000..c53c63b
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementEntry.java
@@ -0,0 +1,211 @@
+/*
+ * 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.soam.delay;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+
+import com.google.common.collect.Lists;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry}.
+ */
+public final class DefaultDelayMeasurementEntry
+ extends DefaultDelayMeasurementCreate implements DelayMeasurementEntry {
+
+ private final SoamId dmId;
+ private final SessionStatus sessionStatus;
+ private final Duration frameDelayTwoWay;
+ private final Duration frameDelayForward;
+ private final Duration frameDelayBackward;
+ private final Duration interFrameDelayVariationTwoWay;
+ private final Duration interFrameDelayVariationForward;
+ private final Duration interFrameDelayVariationBackward;
+ private final DelayMeasurementStatCurrent currentResult;
+ private final Collection<DelayMeasurementStatHistory> historicalResults;
+
+ private DefaultDelayMeasurementEntry(DefaultDmEntryBuilder builder) {
+ super(builder);
+ this.dmId = builder.dmId;
+ this.currentResult = builder.currentResult;
+ this.historicalResults = builder.historicalResults;
+
+ this.sessionStatus = builder.sessionStatus;
+ this.frameDelayTwoWay = builder.frameDelayTwoWay;
+ this.frameDelayForward = builder.frameDelayForward;
+ this.frameDelayBackward = builder.frameDelayBackward;
+ this.interFrameDelayVariationTwoWay = builder.interFrameDelayVariationTwoWay;
+ this.interFrameDelayVariationForward = builder.interFrameDelayVariationForward;
+ this.interFrameDelayVariationBackward = builder.interFrameDelayVariationBackward;
+ }
+
+ @Override
+ public SoamId dmId() {
+ return dmId;
+ }
+
+ @Override
+ public SessionStatus sessionStatus() {
+ return sessionStatus;
+ }
+
+ @Override
+ public Duration frameDelayTwoWay() {
+ return frameDelayTwoWay;
+ }
+
+ @Override
+ public Duration frameDelayForward() {
+ return frameDelayForward;
+ }
+
+ @Override
+ public Duration frameDelayBackward() {
+ return frameDelayBackward;
+ }
+
+ @Override
+ public Duration interFrameDelayVariationTwoWay() {
+ return interFrameDelayVariationTwoWay;
+ }
+
+ @Override
+ public Duration interFrameDelayVariationForward() {
+ return interFrameDelayVariationForward;
+ }
+
+ @Override
+ public Duration interFrameDelayVariationBackward() {
+ return interFrameDelayVariationBackward;
+ }
+
+ @Override
+ public DelayMeasurementStatCurrent currentResult() {
+ return currentResult;
+ }
+
+ @Override
+ public Collection<DelayMeasurementStatHistory> historicalResults() {
+ if (historicalResults != null) {
+ return Lists.newArrayList(historicalResults);
+ }
+ return null;
+ }
+
+ public static DmEntryBuilder builder(SoamId dmId, DmType dmCfgType,
+ Version version, MepId remoteMepId, Priority priority)
+ throws SoamConfigException {
+ return new DefaultDmEntryBuilder(dmId, dmCfgType, version,
+ remoteMepId, priority);
+ }
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry}.
+ */
+ private static final class DefaultDmEntryBuilder extends DefaultDmCreateBuilder
+ implements DmEntryBuilder {
+ private final SoamId dmId;
+ private SessionStatus sessionStatus;
+ private Duration frameDelayTwoWay;
+ private Duration frameDelayForward;
+ private Duration frameDelayBackward;
+ private Duration interFrameDelayVariationTwoWay;
+ private Duration interFrameDelayVariationForward;
+ private Duration interFrameDelayVariationBackward;
+ private DelayMeasurementStatCurrent currentResult;
+ private Collection<DelayMeasurementStatHistory> historicalResults;
+
+ private DefaultDmEntryBuilder(SoamId dmId, DmType dmCfgType,
+ Version version, MepId remoteMepId, Priority priority)
+ throws SoamConfigException {
+ super(dmCfgType, version, remoteMepId, priority);
+ if (dmId == null) {
+ throw new SoamConfigException("DmId is null");
+ }
+ this.dmId = dmId;
+ historicalResults = new ArrayList<>();
+ }
+
+ @Override
+ public DmEntryBuilder sessionStatus(SessionStatus sessionStatus) {
+ this.sessionStatus = sessionStatus;
+ return this;
+ }
+
+ @Override
+ public DmEntryBuilder frameDelayTwoWay(Duration frameDelayTwoWay) {
+ this.frameDelayTwoWay = frameDelayTwoWay;
+ return this;
+ }
+
+ @Override
+ public DmEntryBuilder frameDelayForward(Duration frameDelayForward) {
+ this.frameDelayForward = frameDelayForward;
+ return this;
+ }
+
+ @Override
+ public DmEntryBuilder frameDelayBackward(Duration frameDelayBackward) {
+ this.frameDelayBackward = frameDelayBackward;
+ return this;
+ }
+
+ @Override
+ public DmEntryBuilder interFrameDelayVariationTwoWay(
+ Duration interFrameDelayVariationTwoWay) {
+ this.interFrameDelayVariationTwoWay = interFrameDelayVariationTwoWay;
+ return this;
+ }
+
+ @Override
+ public DmEntryBuilder interFrameDelayVariationForward(
+ Duration interFrameDelayVariationForward) {
+ this.interFrameDelayVariationForward = interFrameDelayVariationForward;
+ return this;
+ }
+
+ @Override
+ public DmEntryBuilder interFrameDelayVariationBackward(
+ Duration interFrameDelayVariationBackward) {
+ this.interFrameDelayVariationBackward = interFrameDelayVariationBackward;
+ return this;
+ }
+
+ @Override
+ public DmEntryBuilder currentResult(DelayMeasurementStatCurrent currentResult) {
+ this.currentResult = currentResult;
+ return this;
+ }
+
+ @Override
+ public DmEntryBuilder addToHistoricalResults(
+ DelayMeasurementStatHistory historicalResult) {
+ this.historicalResults.add(historicalResult);
+ return this;
+ }
+
+ @Override
+ public DelayMeasurementEntry build() {
+ return new DefaultDelayMeasurementEntry(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementStat.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementStat.java
new file mode 100644
index 0000000..01f0bc4
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementStat.java
@@ -0,0 +1,589 @@
+/*
+ * 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.soam.delay;
+
+import java.time.Duration;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+/**
+ * Abstract default implementation of DelayMeasurementStat.
+ * {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStat}.
+ */
+public abstract class DefaultDelayMeasurementStat implements DelayMeasurementStat {
+
+ private final Duration elapsedTime;
+ private final boolean suspectStatus;
+ private final Duration frameDelayTwoWayMin;
+ private final Duration frameDelayTwoWayMax;
+ private final Duration frameDelayTwoWayAvg;
+ private final Duration frameDelayForwardMin;
+ private final Duration frameDelayForwardMax;
+ private final Duration frameDelayForwardAvg;
+ private final Duration frameDelayBackwardMin;
+ private final Duration frameDelayBackwardMax;
+ private final Duration frameDelayBackwardAvg;
+ private final Duration interFrameDelayVariationTwoWayMin;
+ private final Duration interFrameDelayVariationTwoWayMax;
+ private final Duration interFrameDelayVariationTwoWayAvg;
+ private final Duration interFrameDelayVariationForwardMin;
+ private final Duration interFrameDelayVariationForwardMax;
+ private final Duration interFrameDelayVariationForwardAvg;
+ private final Duration interFrameDelayVariationBackwardMin;
+ private final Duration interFrameDelayVariationBackwardMax;
+ private final Duration interFrameDelayVariationBackwardAvg;
+ private final Duration frameDelayRangeTwoWayMax;
+ private final Duration frameDelayRangeTwoWayAvg;
+ private final Duration frameDelayRangeForwardMax;
+ private final Duration frameDelayRangeForwardAvg;
+ private final Duration frameDelayRangeBackwardMax;
+ private final Duration frameDelayRangeBackwardAvg;
+ private final Integer soamPdusSent;
+ private final Integer soamPdusReceived;
+ private final Map<Duration, Integer> frameDelayTwoWayBins;
+ private final Map<Duration, Integer> frameDelayForwardBins;
+ private final Map<Duration, Integer> frameDelayBackwardBins;
+ private final Map<Duration, Integer> interFrameDelayVariationTwoWayBins;
+ private final Map<Duration, Integer> interFrameDelayVariationForwardBins;
+ private final Map<Duration, Integer> interFrameDelayVariationBackwardBins;
+ private final Map<Duration, Integer> frameDelayRangeTwoWayBins;
+ private final Map<Duration, Integer> frameDelayRangeForwardBins;
+ private final Map<Duration, Integer> frameDelayRangeBackwardBins;
+
+ protected DefaultDelayMeasurementStat(DefaultDmStatBuilder builder) {
+ this.elapsedTime = builder.elapsedTime;
+ this.suspectStatus = builder.suspectStatus;
+ this.frameDelayTwoWayMin = builder.frameDelayTwoWayMin;
+ this.frameDelayTwoWayMax = builder.frameDelayTwoWayMax;
+ this.frameDelayTwoWayAvg = builder.frameDelayTwoWayAvg;
+ this.frameDelayForwardMin = builder.frameDelayForwardMin;
+ this.frameDelayForwardMax = builder.frameDelayForwardMax;
+ this.frameDelayForwardAvg = builder.frameDelayForwardAvg;
+ this.frameDelayBackwardMin = builder.frameDelayBackwardMin;
+ this.frameDelayBackwardMax = builder.frameDelayBackwardMax;
+ this.frameDelayBackwardAvg = builder.frameDelayBackwardAvg;
+ this.interFrameDelayVariationTwoWayMin = builder.interFrameDelayVariationTwoWayMin;
+ this.interFrameDelayVariationTwoWayMax = builder.interFrameDelayVariationTwoWayMax;
+ this.interFrameDelayVariationTwoWayAvg = builder.interFrameDelayVariationTwoWayAvg;
+ this.interFrameDelayVariationForwardMin = builder.interFrameDelayVariationForwardMin;
+ this.interFrameDelayVariationForwardMax = builder.interFrameDelayVariationForwardMax;
+ this.interFrameDelayVariationForwardAvg = builder.interFrameDelayVariationForwardAvg;
+ this.interFrameDelayVariationBackwardMin = builder.interFrameDelayVariationBackwardMin;
+ this.interFrameDelayVariationBackwardMax = builder.interFrameDelayVariationBackwardMax;
+ this.interFrameDelayVariationBackwardAvg = builder.interFrameDelayVariationBackwardAvg;
+ this.frameDelayRangeTwoWayMax = builder.frameDelayRangeTwoWayMax;
+ this.frameDelayRangeTwoWayAvg = builder.frameDelayRangeTwoWayAvg;
+ this.frameDelayRangeForwardMax = builder.frameDelayRangeForwardMax;
+ this.frameDelayRangeForwardAvg = builder.frameDelayRangeForwardAvg;
+ this.frameDelayRangeBackwardMax = builder.frameDelayRangeBackwardMax;
+ this.frameDelayRangeBackwardAvg = builder.frameDelayRangeBackwardAvg;
+ this.soamPdusSent = builder.soamPdusSent;
+ this.soamPdusReceived = builder.soamPdusReceived;
+ this.frameDelayTwoWayBins = builder.frameDelayTwoWayBins;
+ this.frameDelayForwardBins = builder.frameDelayForwardBins;
+ this.frameDelayBackwardBins = builder.frameDelayBackwardBins;
+ this.interFrameDelayVariationTwoWayBins = builder.interFrameDelayVariationTwoWayBins;
+ this.interFrameDelayVariationForwardBins = builder.interFrameDelayVariationForwardBins;
+ this.interFrameDelayVariationBackwardBins = builder.interFrameDelayVariationBackwardBins;
+ this.frameDelayRangeTwoWayBins = builder.frameDelayRangeTwoWayBins;
+ this.frameDelayRangeForwardBins = builder.frameDelayRangeForwardBins;
+ this.frameDelayRangeBackwardBins = builder.frameDelayRangeBackwardBins;
+ }
+
+ @Override
+ public Duration elapsedTime() {
+ return elapsedTime;
+ }
+
+ @Override
+ public boolean suspectStatus() {
+ return suspectStatus;
+ }
+
+ @Override
+ public Duration frameDelayTwoWayMin() {
+ return frameDelayTwoWayMin;
+ }
+
+ @Override
+ public Duration frameDelayTwoWayMax() {
+ return frameDelayTwoWayMax;
+ }
+
+ @Override
+ public Duration frameDelayTwoWayAvg() {
+ return frameDelayTwoWayAvg;
+ }
+
+ @Override
+ public Duration frameDelayForwardMin() {
+ return frameDelayForwardMin;
+ }
+
+ @Override
+ public Duration frameDelayForwardMax() {
+ return frameDelayForwardMax;
+ }
+
+ @Override
+ public Duration frameDelayForwardAvg() {
+ return frameDelayForwardAvg;
+ }
+
+ @Override
+ public Duration frameDelayBackwardMin() {
+ return frameDelayBackwardMin;
+ }
+
+ @Override
+ public Duration frameDelayBackwardMax() {
+ return frameDelayBackwardMax;
+ }
+
+ @Override
+ public Duration frameDelayBackwardAvg() {
+ return frameDelayBackwardAvg;
+ }
+
+ @Override
+ public Duration interFrameDelayVariationTwoWayMin() {
+ return interFrameDelayVariationTwoWayMin;
+ }
+
+ @Override
+ public Duration interFrameDelayVariationTwoWayMax() {
+ return interFrameDelayVariationTwoWayMax;
+ }
+
+ @Override
+ public Duration interFrameDelayVariationTwoWayAvg() {
+ return interFrameDelayVariationTwoWayAvg;
+ }
+
+ @Override
+ public Duration interFrameDelayVariationForwardMin() {
+ return interFrameDelayVariationForwardMin;
+ }
+
+ @Override
+ public Duration interFrameDelayVariationForwardMax() {
+ return interFrameDelayVariationForwardMax;
+ }
+
+ @Override
+ public Duration interFrameDelayVariationForwardAvg() {
+ return interFrameDelayVariationForwardAvg;
+ }
+
+ @Override
+ public Duration interFrameDelayVariationBackwardMin() {
+ return interFrameDelayVariationBackwardMin;
+ }
+
+ @Override
+ public Duration interFrameDelayVariationBackwardMax() {
+ return interFrameDelayVariationBackwardMax;
+ }
+
+ @Override
+ public Duration interFrameDelayVariationBackwardAvg() {
+ return interFrameDelayVariationBackwardAvg;
+ }
+
+ @Override
+ public Duration frameDelayRangeTwoWayMax() {
+ return frameDelayRangeTwoWayMax;
+ }
+
+ @Override
+ public Duration frameDelayRangeTwoWayAvg() {
+ return frameDelayRangeTwoWayAvg;
+ }
+
+ @Override
+ public Duration frameDelayRangeForwardMax() {
+ return frameDelayRangeForwardMax;
+ }
+
+ @Override
+ public Duration frameDelayRangeForwardAvg() {
+ return frameDelayRangeForwardAvg;
+ }
+
+ @Override
+ public Duration frameDelayRangeBackwardMax() {
+ return frameDelayRangeBackwardMax;
+ }
+
+ @Override
+ public Duration frameDelayRangeBackwardAvg() {
+ return frameDelayRangeBackwardAvg;
+ }
+
+ @Override
+ public Integer soamPdusSent() {
+ return soamPdusSent;
+ }
+
+ @Override
+ public Integer soamPdusReceived() {
+ return soamPdusReceived;
+ }
+
+ @Override
+ public Map<Duration, Integer> frameDelayTwoWayBins() {
+ if (frameDelayTwoWayBins != null) {
+ return Maps.newHashMap(frameDelayTwoWayBins);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Map<Duration, Integer> frameDelayForwardBins() {
+ if (frameDelayForwardBins != null) {
+ return Maps.newHashMap(frameDelayForwardBins);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Map<Duration, Integer> frameDelayBackwardBins() {
+ if (frameDelayBackwardBins != null) {
+ return Maps.newHashMap(frameDelayBackwardBins);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Map<Duration, Integer> interFrameDelayVariationTwoWayBins() {
+ if (interFrameDelayVariationTwoWayBins != null) {
+ return Maps.newHashMap(interFrameDelayVariationTwoWayBins);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Map<Duration, Integer> interFrameDelayVariationForwardBins() {
+ if (interFrameDelayVariationForwardBins != null) {
+ return Maps.newHashMap(interFrameDelayVariationForwardBins);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Map<Duration, Integer> interFrameDelayVariationBackwardBins() {
+ if (interFrameDelayVariationBackwardBins != null) {
+ return Maps.newHashMap(interFrameDelayVariationBackwardBins);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Map<Duration, Integer> frameDelayRangeTwoWayBins() {
+ if (frameDelayRangeTwoWayBins != null) {
+ return Maps.newHashMap(frameDelayRangeTwoWayBins);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Map<Duration, Integer> frameDelayRangeForwardBins() {
+ if (frameDelayRangeForwardBins != null) {
+ return Maps.newHashMap(frameDelayRangeForwardBins);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Map<Duration, Integer> frameDelayRangeBackwardBins() {
+ if (frameDelayRangeBackwardBins != null) {
+ return Maps.newHashMap(frameDelayRangeBackwardBins);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Abstract builder for {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStat}.
+ */
+ protected abstract static class DefaultDmStatBuilder implements DmStatBuilder {
+
+ private final Duration elapsedTime;
+ private final boolean suspectStatus;
+ private Duration frameDelayTwoWayMin;
+ private Duration frameDelayTwoWayMax;
+ private Duration frameDelayTwoWayAvg;
+ private Duration frameDelayForwardMin;
+ private Duration frameDelayForwardMax;
+ private Duration frameDelayForwardAvg;
+ private Duration frameDelayBackwardMin;
+ private Duration frameDelayBackwardMax;
+ private Duration frameDelayBackwardAvg;
+ private Duration interFrameDelayVariationTwoWayMin;
+ private Duration interFrameDelayVariationTwoWayMax;
+ private Duration interFrameDelayVariationTwoWayAvg;
+ private Duration interFrameDelayVariationForwardMin;
+ private Duration interFrameDelayVariationForwardMax;
+ private Duration interFrameDelayVariationForwardAvg;
+ private Duration interFrameDelayVariationBackwardMin;
+ private Duration interFrameDelayVariationBackwardMax;
+ private Duration interFrameDelayVariationBackwardAvg;
+ private Duration frameDelayRangeTwoWayMax;
+ private Duration frameDelayRangeTwoWayAvg;
+ private Duration frameDelayRangeForwardMax;
+ private Duration frameDelayRangeForwardAvg;
+ private Duration frameDelayRangeBackwardMax;
+ private Duration frameDelayRangeBackwardAvg;
+ private Integer soamPdusSent;
+ private Integer soamPdusReceived;
+ private Map<Duration, Integer> frameDelayTwoWayBins;
+ private Map<Duration, Integer> frameDelayForwardBins;
+ private Map<Duration, Integer> frameDelayBackwardBins;
+ private Map<Duration, Integer> interFrameDelayVariationTwoWayBins;
+ private Map<Duration, Integer> interFrameDelayVariationForwardBins;
+ private Map<Duration, Integer> interFrameDelayVariationBackwardBins;
+ private Map<Duration, Integer> frameDelayRangeTwoWayBins;
+ private Map<Duration, Integer> frameDelayRangeForwardBins;
+ private Map<Duration, Integer> frameDelayRangeBackwardBins;
+
+ protected DefaultDmStatBuilder(Duration elapsedTime, boolean suspectStatus) {
+ this.elapsedTime = elapsedTime;
+ this.suspectStatus = suspectStatus;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayTwoWayMin(Duration frameDelayTwoWayMin) {
+ this.frameDelayTwoWayMin = frameDelayTwoWayMin;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayTwoWayMax(Duration frameDelayTwoWayMax) {
+ this.frameDelayTwoWayMax = frameDelayTwoWayMax;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayTwoWayAvg(Duration frameDelayTwoWayAvg) {
+ this.frameDelayTwoWayAvg = frameDelayTwoWayAvg;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayForwardMin(Duration frameDelayForwardMin) {
+ this.frameDelayForwardMin = frameDelayForwardMin;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayForwardMax(Duration frameDelayForwardMax) {
+ this.frameDelayForwardMax = frameDelayForwardMax;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayForwardAvg(Duration frameDelayForwardAvg) {
+ this.frameDelayForwardAvg = frameDelayForwardAvg;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayBackwardMin(Duration frameDelayBackwardMin) {
+ this.frameDelayBackwardMin = frameDelayBackwardMin;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayBackwardMax(Duration frameDelayBackwardMax) {
+ this.frameDelayBackwardMax = frameDelayBackwardMax;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayBackwardAvg(Duration frameDelayBackwardAvg) {
+ this.frameDelayBackwardAvg = frameDelayBackwardAvg;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder interFrameDelayVariationTwoWayMin(Duration interFrameDelayVariationTwoWayMin) {
+ this.interFrameDelayVariationTwoWayMin = interFrameDelayVariationTwoWayMin;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder interFrameDelayVariationTwoWayMax(Duration interFrameDelayVariationTwoWayMax) {
+ this.interFrameDelayVariationTwoWayMax = interFrameDelayVariationTwoWayMax;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder interFrameDelayVariationTwoWayAvg(Duration interFrameDelayVariationTwoWayAvg) {
+ this.interFrameDelayVariationTwoWayAvg = interFrameDelayVariationTwoWayAvg;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder interFrameDelayVariationForwardMin(Duration interFrameDelayVariationForwardMin) {
+ this.interFrameDelayVariationForwardMin = interFrameDelayVariationForwardMin;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder interFrameDelayVariationForwardMax(Duration interFrameDelayVariationForwardMax) {
+ this.interFrameDelayVariationForwardMax = interFrameDelayVariationForwardMax;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder interFrameDelayVariationForwardAvg(Duration interFrameDelayVariationForwardAvg) {
+ this.interFrameDelayVariationForwardAvg = interFrameDelayVariationForwardAvg;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder interFrameDelayVariationBackwardMin(Duration interFrameDelayVariationBackwardMin) {
+ this.interFrameDelayVariationBackwardMin = interFrameDelayVariationBackwardMin;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder interFrameDelayVariationBackwardMax(Duration interFrameDelayVariationBackwardMax) {
+ this.interFrameDelayVariationBackwardMax = interFrameDelayVariationBackwardMax;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder interFrameDelayVariationBackwardAvg(Duration interFrameDelayVariationBackwardAvg) {
+ this.interFrameDelayVariationBackwardAvg = interFrameDelayVariationBackwardAvg;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayRangeTwoWayMax(Duration frameDelayRangeTwoWayMax) {
+ this.frameDelayRangeTwoWayMax = frameDelayRangeTwoWayMax;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayRangeTwoWayAvg(Duration frameDelayRangeTwoWayAvg) {
+ this.frameDelayRangeTwoWayAvg = frameDelayRangeTwoWayAvg;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayRangeForwardMax(Duration frameDelayRangeForwardMax) {
+ this.frameDelayRangeForwardMax = frameDelayRangeForwardMax;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayRangeForwardAvg(Duration frameDelayRangeForwardAvg) {
+ this.frameDelayRangeForwardAvg = frameDelayRangeForwardAvg;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayRangeBackwardMax(Duration frameDelayRangeBackwardMax) {
+ this.frameDelayRangeBackwardMax = frameDelayRangeBackwardMax;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayRangeBackwardAvg(Duration frameDelayRangeBackwardAvg) {
+ this.frameDelayRangeBackwardAvg = frameDelayRangeBackwardAvg;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder soamPdusSent(Integer soamPdusSent) {
+ this.soamPdusSent = soamPdusSent;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder soamPdusReceived(Integer soamPdusReceived) {
+ this.soamPdusReceived = soamPdusReceived;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayTwoWayBins(Map<Duration, Integer> frameDelayTwoWayBins) {
+ this.frameDelayTwoWayBins = frameDelayTwoWayBins;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayForwardBins(Map<Duration, Integer> frameDelayForwardBins) {
+ this.frameDelayForwardBins = frameDelayForwardBins;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayBackwardBins(Map<Duration, Integer> frameDelayBackwardBins) {
+ this.frameDelayBackwardBins = frameDelayBackwardBins;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder interFrameDelayVariationTwoWayBins(
+ Map<Duration, Integer> interFrameDelayVariationTwoWayBins) {
+ this.interFrameDelayVariationTwoWayBins = interFrameDelayVariationTwoWayBins;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder interFrameDelayVariationForwardBins(
+ Map<Duration, Integer> interFrameDelayVariationForwardBins) {
+ this.interFrameDelayVariationForwardBins = interFrameDelayVariationForwardBins;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder interFrameDelayVariationBackwardBins(
+ Map<Duration, Integer> interFrameDelayVariationBackwardBins) {
+ this.interFrameDelayVariationBackwardBins = interFrameDelayVariationBackwardBins;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayRangeTwoWayBins(Map<Duration, Integer> frameDelayRangeTwoWayBins) {
+ this.frameDelayRangeTwoWayBins = frameDelayRangeTwoWayBins;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayRangeForwardBins(Map<Duration, Integer> frameDelayRangeForwardBins) {
+ this.frameDelayRangeForwardBins = frameDelayRangeForwardBins;
+ return this;
+ }
+
+ @Override
+ public DmStatBuilder frameDelayRangeBackwardBins(Map<Duration, Integer> frameDelayRangeBackwardBins) {
+ this.frameDelayRangeBackwardBins = frameDelayRangeBackwardBins;
+ return this;
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementStatCurrent.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementStatCurrent.java
new file mode 100644
index 0000000..7263134
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementStatCurrent.java
@@ -0,0 +1,68 @@
+/*
+ * 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.soam.delay;
+
+import java.time.Duration;
+import java.time.Instant;
+
+/**
+ * The default implementation of DelayMeasurementStatCurrent.
+ * {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatCurrent}.
+ */
+public final class DefaultDelayMeasurementStatCurrent
+ extends DefaultDelayMeasurementStat
+ implements DelayMeasurementStatCurrent {
+
+ private final Instant startTime;
+
+ protected DefaultDelayMeasurementStatCurrent(DefaultDmStatCurrentBuilder builder) {
+ super(builder);
+ this.startTime = builder.startTime;
+ }
+
+ @Override
+ public Instant startTime() {
+ return startTime;
+ }
+
+ public static DmStatCurrentBuilder builder(Duration elapsedTime, boolean suspectStatus) {
+ return new DefaultDmStatCurrentBuilder(elapsedTime, suspectStatus);
+ }
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatCurrent}.
+ */
+ private static final class DefaultDmStatCurrentBuilder extends DefaultDmStatBuilder
+ implements DmStatCurrentBuilder {
+
+ private Instant startTime;
+
+ private DefaultDmStatCurrentBuilder(Duration elapsedTime, boolean suspectStatus) {
+ super(elapsedTime, suspectStatus);
+ }
+
+ @Override
+ public DmStatCurrentBuilder startTime(Instant startTime) {
+ this.startTime = startTime;
+ return this;
+ }
+
+ @Override
+ public DelayMeasurementStat build() {
+ return new DefaultDelayMeasurementStatCurrent(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementStatHistory.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementStatHistory.java
new file mode 100644
index 0000000..4db3683
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementStatHistory.java
@@ -0,0 +1,80 @@
+/*
+ * 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.soam.delay;
+
+import java.time.Duration;
+import java.time.Instant;
+
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+
+/**
+ * The default implementation of DelayMeasurementStatHistory.
+ * {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatHistory}.
+ */
+public class DefaultDelayMeasurementStatHistory extends DefaultDelayMeasurementStat
+ implements DelayMeasurementStatHistory {
+
+ private final SoamId historyStatsId;
+ private final Instant endTime;
+
+ protected DefaultDelayMeasurementStatHistory(DefaultDmStatHistoryBuilder builder) {
+ super(builder);
+ this.historyStatsId = builder.historyStatsId;
+ this.endTime = builder.endTime;
+ }
+
+ @Override
+ public SoamId historyStatsId() {
+ return historyStatsId;
+ }
+
+ @Override
+ public Instant endTime() {
+ return endTime;
+ }
+
+ public static DmStatHistoryBuilder builder(SoamId historyStatsId,
+ Duration elapsedTime, boolean suspectStatus) {
+ return new DefaultDmStatHistoryBuilder(
+ historyStatsId, elapsedTime, suspectStatus);
+ }
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatHistory}.
+ */
+ private static final class DefaultDmStatHistoryBuilder
+ extends DefaultDmStatBuilder implements DmStatHistoryBuilder {
+ private final SoamId historyStatsId;
+ private Instant endTime;
+
+ private DefaultDmStatHistoryBuilder(SoamId historyStatsId,
+ Duration elapsedTime, boolean suspectStatus) {
+ super(elapsedTime, suspectStatus);
+ this.historyStatsId = historyStatsId;
+ }
+
+ @Override
+ public DmStatHistoryBuilder endTime(Instant endTime) {
+ this.endTime = endTime;
+ return this;
+ }
+
+ @Override
+ public DelayMeasurementStat build() {
+ return new DefaultDelayMeasurementStatHistory(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementThreshold.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementThreshold.java
new file mode 100644
index 0000000..90a8c25
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DefaultDelayMeasurementThreshold.java
@@ -0,0 +1,458 @@
+/*
+ * 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.soam.delay;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+
+/**
+ * The default implementation of DelayMeasurementThreshold.
+ * {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementThreshold}.
+ */
+public final class DefaultDelayMeasurementThreshold
+ implements DelayMeasurementThreshold {
+
+ private final SoamId threshId;
+ private final Collection<ThresholdOption> thresholdsEnabled;
+ private final Duration measuredFrameDelayTwoWay;
+ private final Duration maxFrameDelayTwoWay;
+ private final Duration averageFrameDelayTwoWay;
+ private final Duration measuredInterFrameDelayVariationTwoWay;
+ private final Duration maxInterFrameDelayVariationTwoWay;
+ private final Duration averageInterFrameDelayVariationTwoWay;
+ private final Duration maxFrameDelayRangeTwoWay;
+ private final Duration averageFrameDelayRangeTwoWay;
+ private final Duration measuredFrameDelayForward;
+ private final Duration maxFrameDelayForward;
+ private final Duration averageFrameDelayForward;
+ private final Duration measuredInterFrameDelayVariationForward;
+ private final Duration maxInterFrameDelayVariationForward;
+ private final Duration averageInterFrameDelayVariationForward;
+ private final Duration maxFrameDelayRangeForward;
+ private final Duration averageFrameDelayRangeForward;
+ private final Duration measuredFrameDelayBackward;
+ private final Duration maxFrameDelayBackward;
+ private final Duration averageFrameDelayBackward;
+ private final Duration measuredInterFrameDelayVariationBackward;
+ private final Duration maxInterFrameDelayVariationBackward;
+ private final Duration averageInterFrameDelayVariationBackward;
+ private final Duration maxFrameDelayRangeBackward;
+ private final Duration averageFrameDelayRangeBackward;
+
+ private DefaultDelayMeasurementThreshold(DefaultDmThresholdBuilder builder) {
+ this.threshId = builder.threshId;
+ this.thresholdsEnabled = builder.thresholdsEnabled;
+ this.measuredFrameDelayTwoWay = builder.measuredFrameDelayTwoWay;
+ this.maxFrameDelayTwoWay = builder.maxFrameDelayTwoWay;
+ this.averageFrameDelayTwoWay = builder.averageFrameDelayTwoWay;
+ this.measuredInterFrameDelayVariationTwoWay =
+ builder.measuredInterFrameDelayVariationTwoWay;
+ this.maxInterFrameDelayVariationTwoWay =
+ builder.maxInterFrameDelayVariationTwoWay;
+ this.averageInterFrameDelayVariationTwoWay =
+ builder.averageInterFrameDelayVariationTwoWay;
+ this.maxFrameDelayRangeTwoWay = builder.maxFrameDelayRangeTwoWay;
+ this.averageFrameDelayRangeTwoWay = builder.averageFrameDelayRangeTwoWay;
+ this.measuredFrameDelayForward = builder.measuredFrameDelayForward;
+ this.maxFrameDelayForward = builder.maxFrameDelayForward;
+ this.averageFrameDelayForward = builder.averageFrameDelayForward;
+ this.measuredInterFrameDelayVariationForward =
+ builder.measuredInterFrameDelayVariationForward;
+ this.maxInterFrameDelayVariationForward =
+ builder.maxInterFrameDelayVariationForward;
+ this.averageInterFrameDelayVariationForward =
+ builder.averageInterFrameDelayVariationForward;
+ this.maxFrameDelayRangeForward = builder.maxFrameDelayRangeForward;
+ this.averageFrameDelayRangeForward = builder.averageFrameDelayRangeForward;
+ this.measuredFrameDelayBackward = builder.measuredFrameDelayBackward;
+ this.maxFrameDelayBackward = builder.maxFrameDelayBackward;
+ this.averageFrameDelayBackward = builder.averageFrameDelayBackward;
+ this.measuredInterFrameDelayVariationBackward =
+ builder.measuredInterFrameDelayVariationBackward;
+ this.maxInterFrameDelayVariationBackward =
+ builder.maxInterFrameDelayVariationBackward;
+ this.averageInterFrameDelayVariationBackward =
+ builder.averageInterFrameDelayVariationBackward;
+ this.maxFrameDelayRangeBackward =
+ builder.maxFrameDelayRangeBackward;
+ this.averageFrameDelayRangeBackward =
+ builder.averageFrameDelayRangeBackward;
+ }
+
+ @Override
+ public SoamId threshId() {
+ return threshId;
+ }
+
+ @Override
+ public Collection<ThresholdOption> thresholdsEnabled() {
+ return thresholdsEnabled;
+ }
+
+ @Override
+ public Duration measuredFrameDelayTwoWay() {
+ return measuredFrameDelayTwoWay;
+ }
+
+ @Override
+ public Duration maxFrameDelayTwoWay() {
+ return maxFrameDelayTwoWay;
+ }
+
+ @Override
+ public Duration averageFrameDelayTwoWay() {
+ return averageFrameDelayTwoWay;
+ }
+
+ @Override
+ public Duration measuredInterFrameDelayVariationTwoWay() {
+ return measuredInterFrameDelayVariationTwoWay;
+ }
+
+ @Override
+ public Duration maxInterFrameDelayVariationTwoWay() {
+ return maxInterFrameDelayVariationTwoWay;
+ }
+
+ @Override
+ public Duration averageInterFrameDelayVariationTwoWay() {
+ return averageInterFrameDelayVariationTwoWay;
+ }
+
+ @Override
+ public Duration maxFrameDelayRangeTwoWay() {
+ return maxFrameDelayRangeTwoWay;
+ }
+
+ @Override
+ public Duration averageFrameDelayRangeTwoWay() {
+ return averageFrameDelayRangeTwoWay;
+ }
+
+ @Override
+ public Duration measuredFrameDelayForward() {
+ return measuredFrameDelayForward;
+ }
+
+ @Override
+ public Duration maxFrameDelayForward() {
+ return maxFrameDelayForward;
+ }
+
+ @Override
+ public Duration averageFrameDelayForward() {
+ return averageFrameDelayForward;
+ }
+
+ @Override
+ public Duration measuredInterFrameDelayVariationForward() {
+ return measuredInterFrameDelayVariationForward;
+ }
+
+ @Override
+ public Duration maxInterFrameDelayVariationForward() {
+ return maxInterFrameDelayVariationForward;
+ }
+
+ @Override
+ public Duration averageInterFrameDelayVariationForward() {
+ return averageInterFrameDelayVariationForward;
+ }
+
+ @Override
+ public Duration maxFrameDelayRangeForward() {
+ return maxFrameDelayRangeForward;
+ }
+
+ @Override
+ public Duration averageFrameDelayRangeForward() {
+ return averageFrameDelayRangeForward;
+ }
+
+ @Override
+ public Duration measuredFrameDelayBackward() {
+ return measuredFrameDelayBackward;
+ }
+
+ @Override
+ public Duration maxFrameDelayBackward() {
+ return maxFrameDelayBackward;
+ }
+
+ @Override
+ public Duration averageFrameDelayBackward() {
+ return averageFrameDelayBackward;
+ }
+
+ @Override
+ public Duration measuredInterFrameDelayVariationBackward() {
+ return measuredInterFrameDelayVariationBackward;
+ }
+
+ @Override
+ public Duration maxInterFrameDelayVariationBackward() {
+ return maxInterFrameDelayVariationBackward;
+ }
+
+ @Override
+ public Duration averageInterFrameDelayVariationBackward() {
+ return averageInterFrameDelayVariationBackward;
+ }
+
+ @Override
+ public Duration maxFrameDelayRangeBackward() {
+ return maxFrameDelayRangeBackward;
+ }
+
+ @Override
+ public Duration averageFrameDelayRangeBackward() {
+ return averageFrameDelayRangeBackward;
+ }
+
+ public static DmThresholdBuilder builder(SoamId threshId) {
+ return new DefaultDmThresholdBuilder(threshId);
+ }
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementThreshold}.
+ */
+ private static final class DefaultDmThresholdBuilder implements DmThresholdBuilder {
+ private final SoamId threshId;
+ private Collection<ThresholdOption> thresholdsEnabled;
+ private Duration measuredFrameDelayTwoWay;
+ private Duration maxFrameDelayTwoWay;
+ private Duration averageFrameDelayTwoWay;
+ private Duration measuredInterFrameDelayVariationTwoWay;
+ private Duration maxInterFrameDelayVariationTwoWay;
+ private Duration averageInterFrameDelayVariationTwoWay;
+ private Duration maxFrameDelayRangeTwoWay;
+ private Duration averageFrameDelayRangeTwoWay;
+ private Duration measuredFrameDelayForward;
+ private Duration maxFrameDelayForward;
+ private Duration averageFrameDelayForward;
+ private Duration measuredInterFrameDelayVariationForward;
+ private Duration maxInterFrameDelayVariationForward;
+ private Duration averageInterFrameDelayVariationForward;
+ private Duration maxFrameDelayRangeForward;
+ private Duration averageFrameDelayRangeForward;
+ private Duration measuredFrameDelayBackward;
+ private Duration maxFrameDelayBackward;
+ private Duration averageFrameDelayBackward;
+ private Duration measuredInterFrameDelayVariationBackward;
+ private Duration maxInterFrameDelayVariationBackward;
+ private Duration averageInterFrameDelayVariationBackward;
+ private Duration maxFrameDelayRangeBackward;
+ private Duration averageFrameDelayRangeBackward;
+
+ protected DefaultDmThresholdBuilder(SoamId threshId) {
+ this.threshId = threshId;
+ this.thresholdsEnabled = new ArrayList<>();
+ }
+
+ @Override
+ public DmThresholdBuilder addToThresholdsEnabled(
+ ThresholdOption thresholdEnabled) {
+ this.thresholdsEnabled.add(thresholdEnabled);
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder measuredFrameDelayTwoWay(
+ Duration measuredFrameDelayTwoWay) {
+ this.measuredFrameDelayTwoWay = measuredFrameDelayTwoWay;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder maxFrameDelayTwoWay(
+ Duration maxFrameDelayTwoWay) {
+ this.maxFrameDelayTwoWay = maxFrameDelayTwoWay;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder averageFrameDelayTwoWay(
+ Duration averageFrameDelayTwoWay) {
+ this.averageFrameDelayTwoWay = averageFrameDelayTwoWay;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder measuredInterFrameDelayVariationTwoWay(
+ Duration measuredInterFrameDelayVariationTwoWay) {
+ this.measuredInterFrameDelayVariationTwoWay =
+ measuredInterFrameDelayVariationTwoWay;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder maxInterFrameDelayVariationTwoWay(
+ Duration maxInterFrameDelayVariationTwoWay) {
+ this.maxInterFrameDelayVariationTwoWay =
+ maxInterFrameDelayVariationTwoWay;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder averageInterFrameDelayVariationTwoWay(
+ Duration averageInterFrameDelayVariationTwoWay) {
+ this.averageInterFrameDelayVariationTwoWay =
+ averageInterFrameDelayVariationTwoWay;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder maxFrameDelayRangeTwoWay(
+ Duration maxFrameDelayRangeTwoWay) {
+ this.maxFrameDelayRangeTwoWay = maxFrameDelayRangeTwoWay;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder averageFrameDelayRangeTwoWay(
+ Duration averageFrameDelayRangeTwoWay) {
+ this.averageFrameDelayRangeTwoWay = averageFrameDelayRangeTwoWay;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder measuredFrameDelayForward(
+ Duration measuredFrameDelayForward) {
+ this.measuredFrameDelayForward = measuredFrameDelayForward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder maxFrameDelayForward(
+ Duration maxFrameDelayForward) {
+ this.maxFrameDelayForward = maxFrameDelayForward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder averageFrameDelayForward(
+ Duration averageFrameDelayForward) {
+ this.averageFrameDelayForward = averageFrameDelayForward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder measuredInterFrameDelayVariationForward(
+ Duration measuredInterFrameDelayVariationForward) {
+ this.measuredInterFrameDelayVariationForward =
+ measuredInterFrameDelayVariationForward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder maxInterFrameDelayVariationForward(
+ Duration maxInterFrameDelayVariationForward) {
+ this.maxInterFrameDelayVariationForward =
+ maxInterFrameDelayVariationForward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder averageInterFrameDelayVariationForward(
+ Duration averageInterFrameDelayVariationForward) {
+ this.averageInterFrameDelayVariationForward =
+ averageInterFrameDelayVariationForward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder maxFrameDelayRangeForward(
+ Duration maxFrameDelayRangeForward) {
+ this.maxFrameDelayRangeForward = maxFrameDelayRangeForward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder averageFrameDelayRangeForward(
+ Duration averageFrameDelayRangeForward) {
+ this.averageFrameDelayRangeForward = averageFrameDelayRangeForward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder measuredFrameDelayBackward(
+ Duration measuredFrameDelayBackward) {
+ this.measuredFrameDelayBackward = measuredFrameDelayBackward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder maxFrameDelayBackward(
+ Duration maxFrameDelayBackward) {
+ this.maxFrameDelayBackward = maxFrameDelayBackward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder averageFrameDelayBackward(
+ Duration averageFrameDelayBackward) {
+ this.averageFrameDelayBackward = averageFrameDelayBackward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder measuredInterFrameDelayVariationBackward(
+ Duration measuredInterFrameDelayVariationBackward) {
+ this.measuredInterFrameDelayVariationBackward =
+ measuredInterFrameDelayVariationBackward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder maxInterFrameDelayVariationBackward(
+ Duration maxInterFrameDelayVariationBackward) {
+ this.maxInterFrameDelayVariationBackward =
+ maxInterFrameDelayVariationBackward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder averageInterFrameDelayVariationBackward(
+ Duration averageInterFrameDelayVariationBackward) {
+ this.averageInterFrameDelayVariationBackward =
+ averageInterFrameDelayVariationBackward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder maxFrameDelayRangeBackward(
+ Duration maxFrameDelayRangeBackward) {
+ this.maxFrameDelayRangeBackward = maxFrameDelayRangeBackward;
+ return this;
+ }
+
+ @Override
+ public DmThresholdBuilder averageFrameDelayRangeBackward(
+ Duration averageFrameDelayRangeBackward) {
+ this.averageFrameDelayRangeBackward = averageFrameDelayRangeBackward;
+ return this;
+ }
+
+ @Override
+ public DelayMeasurementThreshold build() {
+ return new DefaultDelayMeasurementThreshold(this);
+ }
+ }
+
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementCreate.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementCreate.java
new file mode 100644
index 0000000..4934146
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementCreate.java
@@ -0,0 +1,226 @@
+/*
+ * 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.soam.delay;
+
+import java.util.Collection;
+
+import org.onosproject.incubator.net.l2monitoring.soam.MeasurementCreateBase;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
+
+/**
+ * A model of Delay Measurement from ITU Y.1731 Chapter 8.2, MEF 17, MEF 36.1 and MEF 39.
+ *
+ * In this model delay measurements entries are returned as a collection in the
+ * MepEntry. In this way Delay Measurements are created by calling on the
+ * Create Delay Measurement function, passing this DelayMeasurementCreate object
+ * and any other arguments needed.
+ * The Delay Measurement Entry is a result and not configured or
+ * persisted in ONOS, but instead is is passed on to some analytics system
+ */
+public interface DelayMeasurementCreate extends MeasurementCreateBase {
+ /**
+ * The type of Delay Measurement is to be performed.
+ * The exact PDUs to use are specified by this object in combination with version
+ * @return enumerated type
+ */
+ DmType dmCfgType();
+
+ /**
+ * A vector of bits that indicates the type of SOAM DM counters that are enabled.
+ * A present bit enables the specific SOAM DM counter.
+ * A not present bit disables the SOAM DM counter.
+ * If a particular SOAM DM counter is not supported the BIT value is not present.
+ * Not all SOAM DM counters are supported for all SOAM DM types.
+ * @return A collection of options
+ */
+ Collection<MeasurementOption> measurementsEnabled();
+
+ /**
+ * The number of measurement bins per Measurement Interval for Frame Delay measurements.
+ * At least 3 bins are to be supported; at least 10 bins are recommended to be supported
+ * @return the number of bins
+ */
+ Short binsPerFdInterval();
+
+ /**
+ * The number of measurement bins per Measurement Interval for Inter-Frame Delay Variation measurements.
+ * The minimum number of measurement bins to be supported is 2. The desired
+ * number of measurements bins to be supported is 10
+ * @return the number of bins
+ */
+ Short binsPerIfdvInterval();
+
+ /**
+ * The selection offset for Inter-Frame Delay Variation measurements.
+ * If this value is set to n, then the IFDV is calculated by taking the
+ * difference in frame delay between frame F and frame (F+n).
+ * reference: MEF-SOAM-PM-MIB.mefSoamDmCfgInterFrameDelayVariationSelectionOffset
+ * @return The selection offset
+ */
+ Short ifdvSelectionOffset();
+
+ /**
+ * The number of measurement bins per Measurement Interval for Frame Delay Range measurements.
+ * @return the number of bins
+ */
+ Short binsPerFdrInterval();
+
+ /**
+ * The Delay Measurement threshold configuration values for DM Performance Monitoring.
+ * The main purpose of the threshold configuration list is to configure
+ * threshold alarm notifications indicating that a specific performance metric
+ * is not being met
+ * @return a collection of Thresholds
+ */
+ Collection<DelayMeasurementThreshold> thresholds();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate}.
+ */
+ public interface DmCreateBuilder extends MeasCreateBaseBuilder {
+
+ DmCreateBuilder addToMeasurementsEnabled(
+ MeasurementOption measurementEnabled);
+
+ DmCreateBuilder binsPerFdInterval(Short binsPerFdInterval)
+ throws SoamConfigException;
+
+ DmCreateBuilder binsPerIfdvInterval(Short binsPerIfdvInterval)
+ throws SoamConfigException;
+
+ DmCreateBuilder ifdvSelectionOffset(Short ifdvSelectionOffset)
+ throws SoamConfigException;
+
+ DmCreateBuilder binsPerFdrInterval(Short binsPerFdrInterval)
+ throws SoamConfigException;
+
+ DmCreateBuilder addToThresholds(DelayMeasurementThreshold threshold);
+
+ DelayMeasurementCreate build();
+ }
+
+ /**
+ * Enumerated options for Delay Measurement Types.
+ */
+ public enum DmType {
+ /**
+ * DMM SOAM PDU generated, DMR responses received (one-way or two-way measurements).
+ */
+ DMDMM,
+ /**
+ * 1DM SOAM PDU generated (one-way measurements are made by the receiver).
+ */
+ DM1DMTX,
+ /**
+ * 1DM SOAM PDU received and tracked (one-way measurements).
+ */
+ DM1DMRX
+ }
+
+ /**
+ * Supported Versions of Y.1731.
+ */
+ public enum Version {
+ Y17312008("Y.1731-2008"),
+ Y17312011("Y.1731-2011");
+
+ private String literal;
+ private Version(String literal) {
+ this.literal = literal;
+ }
+
+ public String literal() {
+ return literal;
+ }
+ }
+
+ /**
+ * Selection of Measurement types.
+ */
+ public enum MeasurementOption {
+ SOAM_PDUS_SENT,
+ SOAM_PDUS_RECEIVED,
+ FRAME_DELAY_TWO_WAY_BINS,
+ FRAME_DELAY_TWO_WAY_MIN,
+ FRAME_DELAY_TWO_WAY_MAX,
+ FRAME_DELAY_TWO_WAY_AVERAGE,
+ FRAME_DELAY_FORWARD_BINS,
+ FRAME_DELAY_FORWARD_MIN,
+ FRAME_DELAY_FORWARD_MAX,
+ FRAME_DELAY_FORWARD_AVERAGE,
+ FRAME_DELAY_BACKWARD_BINS,
+ FRAME_DELAY_BACKWARD_MIN,
+ FRAME_DELAY_BACKWARD_MAX,
+ FRAME_DELAY_BACKWARD_AVERAGE,
+ INTER_FRAME_DELAY_VARIATION_FORWARD_BINS,
+ INTER_FRAME_DELAY_VARIATION_FORWARD_MIN,
+ INTER_FRAME_DELAY_VARIATION_FORWARD_MAX,
+ INTER_FRAME_DELAY_VARIATION_FORWARD_AVERAGE,
+ INTER_FRAME_DELAY_VARIATION_BACKWARD_BINS,
+ INTER_FRAME_DELAY_VARIATION_BACKWARD_MIN,
+ INTER_FRAME_DELAY_VARIATION_BACKWARD_MAX,
+ INTER_FRAME_DELAY_VARIATION_BACKWARD_AVERAGE,
+ INTER_FRAME_DELAY_VARIATION_TWO_WAY_BINS,
+ INTER_FRAME_DELAY_VARIATION_TWO_WAY_MIN,
+ INTER_FRAME_DELAY_VARIATION_TWO_WAY_MAX,
+ INTER_FRAME_DELAY_VARIATION_TWO_WAY_AVERAGE,
+ FRAME_DELAY_RANGE_FORWARD_BINS,
+ FRAME_DELAY_RANGE_FORWARD_MAX,
+ FRAME_DELAY_RANGE_FORWARD_AVERAGE,
+ FRAME_DELAY_RANGE_BACKWARD_BINS,
+ FRAME_DELAY_RANGE_BACKWARD_MAX,
+ FRAME_DELAY_RANGE_BACKWARD_AVERAGE,
+ FRAME_DELAY_RANGE_TWO_WAY_BINS,
+ FRAME_DELAY_RANGE_TWO_WAY_MAX,
+ FRAME_DELAY_RANGE_TWO_WAY_AVERAGE,
+ MEASURED_STATS_FRAME_DELAY_TWO_WAY,
+ MEASURED_STATS_FRAME_DELAY_FORWARD,
+ MEASURED_STATS_FRAME_DELAY_BACKWARD,
+ MEASURED_STATS_INTER_FRAME_DELAY_VARIATION_TWO_WAY,
+ MEASURED_STATS_INTER_FRAME_DELAY_VARIATION_FORWARD,
+ MEASURED_STATS_INTER_FRAME_DELAY_VARIATION_BACKWARD;
+ }
+
+ /**
+ * Selection of Data Patterns.
+ */
+ public enum DataPattern {
+ ZEROES,
+ ONES;
+ }
+
+ /**
+ * Selection of Test TLV Patterns.
+ */
+ public enum TestTlvPattern {
+ /**
+ * This test pattern is a Null signal without CRC-32.
+ */
+ NULL_SIGNAL_WITHOUT_CRC_32,
+ /**
+ * This test pattern is a Null signal with CRC-32.
+ */
+ NULL_SIGNAL_WITH_CRC_32,
+ /**
+ * This test pattern is a PRBS 2^31-1 without CRC-32.
+ */
+ PRBS_2311_WITHOUT_CRC_32,
+ /**
+ * This test pattern is a PRBS 2^31-1 with CRC-32.
+ */
+ PRBS_2311_WITH_CRC_32;
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementEntry.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementEntry.java
new file mode 100644
index 0000000..3571922
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementEntry.java
@@ -0,0 +1,141 @@
+/*
+ * 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.soam.delay;
+
+import java.time.Duration;
+import java.util.Collection;
+
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+
+/**
+ * Delay Measurement from ITU Y.1731 Chapter 8.2, MEF 17, MEF 36.1 and MEF 39.
+ *
+ * This represents the result returned and includes the parameters used to
+ * configure the DM when it was created
+ */
+public interface DelayMeasurementEntry extends DelayMeasurementCreate {
+ /**
+ * This uniquely identifies a scheduled measurement.
+ * It is automatically generated by the server on creation of a new measurement
+ * @return the id
+ */
+ SoamId dmId();
+
+ /**
+ * The current status of the DM session.
+ * A value of 'active' indicates the current DM session is active,
+ * i.e. the current time lies between the start time and the stop time, and
+ * enabled is true. A value of 'not-active' indicates the current DM session
+ * is not active, i.e. it has not started yet, has stopped upon reaching the
+ * stop time, or is disabled
+ * @return the status
+ */
+ SessionStatus sessionStatus();
+
+ /**
+ * The two-way frame delay calculated by this MEP from the last received SOAM PDU.
+ * This object is undefined is measurement-type is dm1-transmitted or dm1-received
+ * @return The delay as a java duration
+ */
+ Duration frameDelayTwoWay();
+
+ /**
+ * The frame delay in the forward direction calculated by this MEP from the last received SOAM PDU.
+ * The value of this object may not be accurate in the absence of sufficiently
+ * precise clock synchronization.
+ * This object is undefined is measurement-type is dm1-transmitted
+ * @return The delay as a java duration
+ */
+ Duration frameDelayForward();
+
+ /**
+ * The frame delay in the backward direction calculated by this MEP from the last received SOAM PDU.
+ * The value of this object may not be accurate in the absence of sufficiently
+ * precise clock synchronization.
+ * This object is undefined is measurement-type is dm1-transmitted or dm1-received
+ * @return The delay as a java duration
+ */
+ Duration frameDelayBackward();
+
+ /**
+ * The last two-way inter-frame delay interval calculated by this MEP.
+ * The value of this object is undefined when measurement-type is dm1-transmitted or dm1-received
+ * @return The delay as a java duration
+ */
+ Duration interFrameDelayVariationTwoWay();
+
+ /**
+ * The last one-way inter-frame delay interval in the forward direction calculated by this MEP.
+ * The value of this object is undefined when measurement-type is dm1-transmitted
+ * @return The delay as a java duration
+ */
+ Duration interFrameDelayVariationForward();
+
+ /**
+ * The last one-way inter-frame delay interval in the backward direction calculated by this MEP.
+ * The value of this object is undefined when measurement-type is
+ * dm1-transmitted or dm1-received
+ * @return The delay as a java duration
+ */
+ Duration interFrameDelayVariationBackward();
+
+ /**
+ * The results for the current Measurement Interval in a SOAM Delay Measurement session.
+ * gathered during the interval indicated by measurement-interval.
+ * @return The current set of results
+ */
+ DelayMeasurementStatCurrent currentResult();
+
+ /**
+ * The results for history Measurement Intervals in a SOAM Delay Measurement session.
+ * @return A collection of history results
+ */
+ Collection<DelayMeasurementStatHistory> historicalResults();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry}.
+ */
+ public interface DmEntryBuilder extends DmCreateBuilder {
+ DmEntryBuilder sessionStatus(SessionStatus sessionStatus);
+
+ DmEntryBuilder frameDelayTwoWay(Duration frameDelayTwoWay);
+
+ DmEntryBuilder frameDelayForward(Duration frameDelayForward);
+
+ DmEntryBuilder frameDelayBackward(Duration frameDelayBackward);
+
+ DmEntryBuilder interFrameDelayVariationTwoWay(Duration interFrameDelayVariationTwoWay);
+
+ DmEntryBuilder interFrameDelayVariationForward(Duration interFrameDelayVariationForward);
+
+ DmEntryBuilder interFrameDelayVariationBackward(Duration interFrameDelayVariationBackward);
+
+ DmEntryBuilder currentResult(DelayMeasurementStatCurrent currentResult);
+
+ DmEntryBuilder addToHistoricalResults(
+ DelayMeasurementStatHistory historicalResult);
+
+ DelayMeasurementEntry build();
+ }
+
+ /**
+ * Session Status options.
+ */
+ public enum SessionStatus {
+ ACTIVE,
+ NOT_ACTIVE;
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementStat.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementStat.java
new file mode 100644
index 0000000..c218c06
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementStat.java
@@ -0,0 +1,356 @@
+/*
+ * 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.soam.delay;
+
+import java.time.Duration;
+import java.util.Map;
+
+/**
+ * Abstract object as a base for DelayMeasurementStatCurrent and DelayMeasurementStatHistory interfaces.
+ */
+public interface DelayMeasurementStat {
+ /**
+ * The time that the current Measurement Interval has been running.
+ * @return A java duration
+ */
+ Duration elapsedTime();
+
+ /**
+ * The suspect flag for the current measurement interval in which the notification was generated.
+ * reference MEF-SOAM-PM-MIB.mefSoamPmNotificationObjSuspect";
+ * @return true if the measurement might include an error
+ */
+ boolean suspectStatus();
+
+ /**
+ * The minimum two-way frame delay calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration frameDelayTwoWayMin();
+
+ /**
+ * The maximum two-way frame delay calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration frameDelayTwoWayMax();
+
+ /**
+ * The average two-way frame delay calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration frameDelayTwoWayAvg();
+
+ /**
+ * The minimum foward frame delay calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration frameDelayForwardMin();
+
+ /**
+ * The maximum forward frame delay calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration frameDelayForwardMax();
+
+ /**
+ * The average forward frame delay calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration frameDelayForwardAvg();
+
+ /**
+ * The minimum backward frame delay calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration frameDelayBackwardMin();
+
+ /**
+ * The maximum backward frame delay calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration frameDelayBackwardMax();
+
+ /**
+ * The average backward frame delay calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration frameDelayBackwardAvg();
+
+ /**
+ * The minimum two-way inter-frame delay interval calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration interFrameDelayVariationTwoWayMin();
+
+ /**
+ * The maximum two-way inter-frame delay interval calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration interFrameDelayVariationTwoWayMax();
+
+ /**
+ * The average two-way inter-frame delay interval calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration interFrameDelayVariationTwoWayAvg();
+
+ /**
+ * The minimum one-way inter-frame delay interval in the forward direction.
+ * calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration interFrameDelayVariationForwardMin();
+
+ /**
+ * The maximum one-way inter-frame delay interval in the forward direction.
+ * calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration interFrameDelayVariationForwardMax();
+
+ /**
+ * The average one-way inter-frame delay interval in the forward direction.
+ * calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration interFrameDelayVariationForwardAvg();
+
+ /**
+ * The minimum one-way inter-frame delay interval in the backward direction.
+ * calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration interFrameDelayVariationBackwardMin();
+
+ /**
+ * The maximum one-way inter-frame delay interval in the backward direction.
+ * calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration interFrameDelayVariationBackwardMax();
+
+ /**
+ * The average one-way inter-frame delay interval in the backward direction.
+ * calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration interFrameDelayVariationBackwardAvg();
+
+ /**
+ * The maximum two-way Frame Delay Range calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration frameDelayRangeTwoWayMax();
+
+ /**
+ * The average two-way Frame Delay Range calculated by this MEP for this Measurement Interval.
+ * @return A java duration
+ */
+ Duration frameDelayRangeTwoWayAvg();
+
+ /**
+ * The maximum one-way Frame Delay Range in the forward direction.
+ * calculated by this MEP for this Measurement Interval
+ * @return A java duration
+ */
+ Duration frameDelayRangeForwardMax();
+
+ /**
+ * The average one-way Frame Delay Range in the forward direction.
+ * calculated by this MEP for this Measurement Interval
+ * @return A java duration
+ */
+ Duration frameDelayRangeForwardAvg();
+
+ /**
+ * The maximum one-way Frame Delay Range in the backward direction.
+ * calculated by this MEP for this Measurement Interval
+ * @return A java duration
+ */
+ Duration frameDelayRangeBackwardMax();
+
+ /**
+ * The average one-way Frame Delay Range in the backward direction.
+ * calculated by this MEP for this Measurement Interval
+ * @return A java duration
+ */
+ Duration frameDelayRangeBackwardAvg();
+
+ /**
+ * The count of the number of SOAM PDUs sent during this Measurement Interval.
+ * @return the count as an integer
+ */
+ Integer soamPdusSent();
+
+ /**
+ * The count of the number of SOAM PDUs received during this Measurement Interval.
+ * @return the count as an integer
+ */
+ Integer soamPdusReceived();
+
+ /**
+ * Bins calculated for two-way Frame Delay measurements.
+ * calculated by this MEP for this Measurement interval.
+ *
+ * The reply contains a set of counts of packets per bin
+ * The bin is defined by the durations given as the lower limit and the next
+ * size being the upper limit. For the largest duration, the count is of packets
+ * of that size up to infinity
+ *
+ * For example, if there are 4 elements in the result
+ * PT0.000S 4 - This means there are 4 packets in the 0-20ms bin
+ * PT0.020S 6 - This means there are 6 packets in the 20-30ms bin
+ * PT0.030S 8 - This means there are 8 packets in the 30-50ms bin
+ * PT0.050S 10 - This means there are 10 packets in the 50ms-infinity bin
+ *
+ * @return A map of counts per time periods
+ */
+ Map<Duration, Integer> frameDelayTwoWayBins();
+
+ /**
+ * Bins calculated for one-way Frame Delay measurements in the Forward direction.
+ * calculated by this MEP for this Measurement interval.
+ * @return A map of counts per time periods
+ */
+ Map<Duration, Integer> frameDelayForwardBins();
+
+ /**
+ * Bins calculated for one-way Frame Delay measurements in the Backward direction.
+ * calculated by this MEP for this Measurement interval.
+ * @return A map of counts per time periods
+ */
+ Map<Duration, Integer> frameDelayBackwardBins();
+
+ /**
+ * Bins calculated for two-way Inter Frame Delay Variation measurements.
+ * calculated by this MEP for this Measurement interval.
+ * @return A map of counts per time periods
+ */
+ Map<Duration, Integer> interFrameDelayVariationTwoWayBins();
+
+ /**
+ * Bins calculated for one-way Inter Frame Delay Variation measurements in the Forward direction.
+ * calculated by this MEP for this Measurement interval.
+ * @return A map of counts per time periods
+ */
+ Map<Duration, Integer> interFrameDelayVariationForwardBins();
+
+ /**
+ * Bins calculated for one-way Inter Frame Delay Variation measurements in the Backward direction.
+ * calculated by this MEP for this Measurement interval.
+ * @return A map of counts per time periods
+ */
+ Map<Duration, Integer> interFrameDelayVariationBackwardBins();
+
+ /**
+ * Bins calculated for two-way Frame Delay Range measurements.
+ * calculated by this MEP for this Measurement interval.
+ * @return A map of counts per time periods
+ */
+ Map<Duration, Integer> frameDelayRangeTwoWayBins();
+
+ /**
+ * Bins calculated for one-way Frame Delay Range measurements in the Forward direction.
+ * calculated by this MEP for this Measurement interval.
+ * @return A map of counts per time periods
+ */
+ Map<Duration, Integer> frameDelayRangeForwardBins();
+
+ /**
+ * Bins calculated for one-way Frame Delay Range measurements in the Backward direction.
+ * calculated by this MEP for this Measurement interval.
+ * @return A map of counts per time periods
+ */
+ Map<Duration, Integer> frameDelayRangeBackwardBins();
+
+ /**
+ * Abstract Builder interface for DelayMeasurementStat.
+ * {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStat}.
+ */
+ interface DmStatBuilder {
+ DmStatBuilder frameDelayTwoWayMin(Duration frameDelayTwoWayMin);
+
+ DmStatBuilder frameDelayTwoWayMax(Duration frameDelayTwoWayMax);
+
+ DmStatBuilder frameDelayTwoWayAvg(Duration frameDelayTwoWayAvg);
+
+ DmStatBuilder frameDelayForwardMin(Duration frameDelayForwardMin);
+
+ DmStatBuilder frameDelayForwardMax(Duration frameDelayForwardMax);
+
+ DmStatBuilder frameDelayForwardAvg(Duration frameDelayForwardAvg);
+
+ DmStatBuilder frameDelayBackwardMin(Duration frameDelayBackwardMin);
+
+ DmStatBuilder frameDelayBackwardMax(Duration frameDelayBackwardMax);
+
+ DmStatBuilder frameDelayBackwardAvg(Duration frameDelayBackwardAvg);
+
+ DmStatBuilder interFrameDelayVariationTwoWayMin(Duration interFrameDelayVariationTwoWayMin);
+
+ DmStatBuilder interFrameDelayVariationTwoWayMax(Duration interFrameDelayVariationTwoWayMax);
+
+ DmStatBuilder interFrameDelayVariationTwoWayAvg(Duration interFrameDelayVariationTwoWayAvg);
+
+ DmStatBuilder interFrameDelayVariationForwardMin(Duration interFrameDelayVariationForwardMin);
+
+ DmStatBuilder interFrameDelayVariationForwardMax(Duration interFrameDelayVariationForwardMax);
+
+ DmStatBuilder interFrameDelayVariationForwardAvg(Duration interFrameDelayVariationForwardAvg);
+
+ DmStatBuilder interFrameDelayVariationBackwardMin(Duration interFrameDelayVariationBackwardMin);
+
+ DmStatBuilder interFrameDelayVariationBackwardMax(Duration interFrameDelayVariationBackwardMax);
+
+ DmStatBuilder interFrameDelayVariationBackwardAvg(Duration interFrameDelayVariationBackwardAvg);
+
+ DmStatBuilder frameDelayRangeTwoWayMax(Duration frameDelayRangeTwoWayMax);
+
+ DmStatBuilder frameDelayRangeTwoWayAvg(Duration frameDelayRangeTwoWayAvg);
+
+ DmStatBuilder frameDelayRangeForwardMax(Duration frameDelayRangeForwardMax);
+
+ DmStatBuilder frameDelayRangeForwardAvg(Duration frameDelayRangeForwardAvg);
+
+ DmStatBuilder frameDelayRangeBackwardMax(Duration frameDelayRangeBackwardMax);
+
+ DmStatBuilder frameDelayRangeBackwardAvg(Duration frameDelayRangeBackwardAvg);
+
+ DmStatBuilder soamPdusSent(Integer soamPdusSent);
+
+ DmStatBuilder soamPdusReceived(Integer soamPdusReceived);
+
+ DmStatBuilder frameDelayTwoWayBins(Map<Duration, Integer> frameDelayTwoWayBins);
+
+ DmStatBuilder frameDelayForwardBins(Map<Duration, Integer> frameDelayForwardBins);
+
+ DmStatBuilder frameDelayBackwardBins(Map<Duration, Integer> frameDelayBackwardBins);
+
+ DmStatBuilder interFrameDelayVariationTwoWayBins(Map<Duration, Integer> interFrameDelayVariationTwoWayBins);
+
+ DmStatBuilder interFrameDelayVariationForwardBins(Map<Duration, Integer> interFrameDelayVariationForwardBins);
+
+ DmStatBuilder interFrameDelayVariationBackwardBins(Map<Duration, Integer> interFrameDelayVariationBackwardBins);
+
+ DmStatBuilder frameDelayRangeTwoWayBins(Map<Duration, Integer> frameDelayRangeTwoWayBins);
+
+ DmStatBuilder frameDelayRangeForwardBins(Map<Duration, Integer> frameDelayRangeForwardBins);
+
+ DmStatBuilder frameDelayRangeBackwardBins(Map<Duration, Integer> frameDelayRangeBackwardBins);
+
+ DelayMeasurementStat build();
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementStatCurrent.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementStatCurrent.java
new file mode 100644
index 0000000..f9bb25f
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementStatCurrent.java
@@ -0,0 +1,36 @@
+/*
+ * 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.soam.delay;
+
+import java.time.Instant;
+
+/**
+ * Object for representing Delay Measurement Current Stats.
+ */
+public interface DelayMeasurementStatCurrent extends DelayMeasurementStat {
+ /**
+ * The time that the current Measurement Interval started.
+ * @return The start time as a java Instant
+ */
+ Instant startTime();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatCurrent}.
+ */
+ public interface DmStatCurrentBuilder extends DmStatBuilder {
+ DmStatCurrentBuilder startTime(Instant startTime);
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementStatHistory.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementStatHistory.java
new file mode 100644
index 0000000..c55c66a
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementStatHistory.java
@@ -0,0 +1,44 @@
+/*
+ * 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.soam.delay;
+
+import java.time.Instant;
+
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+
+/**
+ * Object for representing Delay Measurement History Stats.
+ */
+public interface DelayMeasurementStatHistory extends DelayMeasurementStat {
+ /**
+ * The identifier of the historic measurement.
+ * @return The id
+ */
+ SoamId historyStatsId();
+
+ /**
+ * The time that the historic Measurement Interval ended.
+ * @return A java Instant
+ */
+ Instant endTime();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatHistory}.
+ */
+ public interface DmStatHistoryBuilder extends DmStatBuilder {
+ DmStatHistoryBuilder endTime(Instant endTime);
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementThreshold.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementThreshold.java
new file mode 100644
index 0000000..78ae5d4
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementThreshold.java
@@ -0,0 +1,298 @@
+/*
+ * 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.soam.delay;
+
+import java.time.Duration;
+import java.util.Collection;
+
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+
+/**
+ * Object to represent a Delay Measurement Threshold.
+ */
+public interface DelayMeasurementThreshold {
+ /**
+ * The identifier or the scheduled measurement.
+ * @return The id
+ */
+ SoamId threshId();
+
+ /**
+ * A vector of bits that indicates the type of SOAM LM thresholds notifications that are enabled.
+ * A present bit enables the specific SOAM LM threshold notification and
+ * when the specific counter is enabled and the threshold is crossed a
+ * notification is generated.
+ * A not present bit disables the specific SOAM LM threshold notification. If
+ * a particular SOAM LM threshold is not supported the BIT value is not present.
+ * @return A collection of bit options
+ */
+ Collection<ThresholdOption> thresholdsEnabled();
+
+ /**
+ * The measurement two-way delay threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration measuredFrameDelayTwoWay();
+
+ /**
+ * The maximum two-way delay threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration maxFrameDelayTwoWay();
+
+ /**
+ * The average two-way delay threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration averageFrameDelayTwoWay();
+
+ /**
+ * The measurement two-way IFDV threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration measuredInterFrameDelayVariationTwoWay();
+
+ /**
+ * The maximum two-way IFDV threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration maxInterFrameDelayVariationTwoWay();
+
+ /**
+ * The average two-way IFDV threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration averageInterFrameDelayVariationTwoWay();
+
+ /**
+ * The maximum two-way Frame Delay Range threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration maxFrameDelayRangeTwoWay();
+
+ /**
+ * The average two-way Frame Delay Range threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration averageFrameDelayRangeTwoWay();
+
+ /**
+ * The measurement forward delay threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration measuredFrameDelayForward();
+
+ /**
+ * The maximum forward delay threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration maxFrameDelayForward();
+
+ /**
+ * The average forward delay threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration averageFrameDelayForward();
+
+ /**
+ * The measurement IFDV threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration measuredInterFrameDelayVariationForward();
+
+ /**
+ * The maximum IFDV threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration maxInterFrameDelayVariationForward();
+
+ /**
+ * The average IFDV threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration averageInterFrameDelayVariationForward();
+
+ /**
+ * The maximum Frame Delay Range threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration maxFrameDelayRangeForward();
+
+ /**
+ * The average Frame Delay Range threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration averageFrameDelayRangeForward();
+
+ /**
+ * The measurement backward delay threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration measuredFrameDelayBackward();
+
+ /**
+ * The maximum backward delay threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration maxFrameDelayBackward();
+
+ /**
+ * The average backward delay threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration averageFrameDelayBackward();
+
+ /**
+ * The measurement backward IFDV threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration measuredInterFrameDelayVariationBackward();
+
+ /**
+ * The maximum backward IFDV threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration maxInterFrameDelayVariationBackward();
+
+ /**
+ * The average backward IFDV threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration averageInterFrameDelayVariationBackward();
+
+ /**
+ * The maximum backward Frame Delay Range threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration maxFrameDelayRangeBackward();
+
+ /**
+ * The average backward Frame Delay Range threshold used to determine if a threshold notification is generated.
+ * @return A java duration
+ */
+ Duration averageFrameDelayRangeBackward();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementThreshold}.
+ */
+ public interface DmThresholdBuilder {
+ DmThresholdBuilder addToThresholdsEnabled(
+ ThresholdOption thresholdEnabled);
+
+ DmThresholdBuilder measuredFrameDelayTwoWay(
+ Duration measuredFrameDelayTwoWay);
+
+ DmThresholdBuilder maxFrameDelayTwoWay(Duration maxFrameDelayTwoWay);
+
+ DmThresholdBuilder averageFrameDelayTwoWay(Duration averageFrameDelayTwoWay);
+
+ DmThresholdBuilder measuredInterFrameDelayVariationTwoWay(
+ Duration measuredInterFrameDelayVariationTwoWay);
+
+ DmThresholdBuilder maxInterFrameDelayVariationTwoWay(
+ Duration maxInterFrameDelayVariationTwoWay);
+
+ DmThresholdBuilder averageInterFrameDelayVariationTwoWay(
+ Duration averageInterFrameDelayVariationTwoWay);
+
+ DmThresholdBuilder maxFrameDelayRangeTwoWay(
+ Duration maxFrameDelayRangeTwoWay);
+
+ DmThresholdBuilder averageFrameDelayRangeTwoWay(
+ Duration averageFrameDelayRangeTwoWay);
+
+ DmThresholdBuilder measuredFrameDelayForward(
+ Duration averageFrameDelayRangeTwoWay);
+
+ DmThresholdBuilder maxFrameDelayForward(
+ Duration maxFrameDelayForward);
+
+ DmThresholdBuilder averageFrameDelayForward(
+ Duration averageFrameDelayForward);
+
+ DmThresholdBuilder measuredInterFrameDelayVariationForward(
+ Duration measuredInterFrameDelayVariationForward);
+
+ DmThresholdBuilder maxInterFrameDelayVariationForward(
+ Duration maxInterFrameDelayVariationForward);
+
+ DmThresholdBuilder averageInterFrameDelayVariationForward(
+ Duration averageInterFrameDelayVariationForward);
+
+ DmThresholdBuilder maxFrameDelayRangeForward(
+ Duration maxFrameDelayRangeForward);
+
+ DmThresholdBuilder averageFrameDelayRangeForward(
+ Duration averageFrameDelayRangeForward);
+
+ DmThresholdBuilder measuredFrameDelayBackward(
+ Duration measuredFrameDelayBackward);
+
+ DmThresholdBuilder maxFrameDelayBackward(
+ Duration maxFrameDelayBackward);
+
+ DmThresholdBuilder averageFrameDelayBackward(
+ Duration averageFrameDelayBackward);
+
+ DmThresholdBuilder measuredInterFrameDelayVariationBackward(
+ Duration measuredInterFrameDelayVariationBackward);
+
+ DmThresholdBuilder maxInterFrameDelayVariationBackward(
+ Duration maxInterFrameDelayVariationBackward);
+
+ DmThresholdBuilder averageInterFrameDelayVariationBackward(
+ Duration averageInterFrameDelayVariationBackward);
+
+ DmThresholdBuilder maxFrameDelayRangeBackward(
+ Duration maxFrameDelayRangeBackward);
+
+ DmThresholdBuilder averageFrameDelayRangeBackward(
+ Duration averageFrameDelayRangeBackward);
+
+ public DelayMeasurementThreshold build();
+
+ }
+
+ /**
+ * Selection of Threshold choices.
+ */
+ public enum ThresholdOption {
+ MEASURED_FRAME_DELAY_TWO_WAY,
+ MAX_FRAME_DELAY_TWO_WAY,
+ AVERAGE_FRAME_DELAY_TWO_WAY,
+ MEASURED_INTER_FRAME_DELAY_VARIATION_TWO_WAY,
+ MAX_INTER_FRAME_DELAY_VARIATION_TWO_WAY,
+ AVERAGE_INTER_FRAME_DELAY_VARIATION_TWO_WAY,
+ MAX_FRAME_DELAY_RANGE_TWO_WAY,
+ AVERAGE_FRAME_DELAY_RANGE_TWO_WAY,
+ MEASURED_FRAME_DELAY_FORWARD,
+ MAX_FRAME_DELAY_FORWARD,
+ AVERAGE_FRAME_DELAY_FORWARD,
+ MEASURED_INTER_FRAME_DELAY_VARIATION_FORWARD,
+ MAX_INTER_FRAME_DELAY_VARIATION_FORWARD,
+ AVERAGE_INTER_FRAME_DELAY_VARIATION_FORWARD,
+ MAX_FRAME_DELAY_RANGE_FORWARD,
+ AVERAGE_FRAME_DELAY_RANGE_FORWARD,
+ MEASURED_FRAME_DELAY_BACKWARD,
+ MAX_FRAME_DELAY_BACKWARD,
+ AVERAGE_FRAME_DELAY_BACKWARD,
+ MEASURED_INTER_FRAME_DELAY_VARIATION_BACKWARD,
+ MAX_INTER_FRAME_DELAY_VARIATION_BACKWARD,
+ AVERAGE_INTER_FRAME_DELAY_VARIATION_BACKWARD,
+ MAX_FRAME_DELAY_RANGE_BACKWARD,
+ AVERAGE_FRAME_DELAY_RANGE_BACKWARD;
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/package-info.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/package-info.java
new file mode 100644
index 0000000..310eb12
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/delay/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+/**
+ * Implementation of Service Operation and Maintenance related to Frame delay measurement.
+ *
+ * From ITU Y.1731 (ETH-DM) and MEF 17 Frame Delay Performance and Frame Delay Variation Performance
+ * MEF 36.1 Service OAM SNMP MIB for Performance Monitoring, MEF 39 Service OAM Performance Monitoring YANG Module
+ */
+package org.onosproject.incubator.net.l2monitoring.soam.delay;
\ No newline at end of file
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLaStat.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLaStat.java
new file mode 100644
index 0000000..0616a55
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLaStat.java
@@ -0,0 +1,262 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Duration;
+
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossAvailabilityStat}.
+ */
+public abstract class DefaultLaStat implements LossAvailabilityStat {
+ private final Duration elapsedTime;
+ private final boolean suspectStatus;
+ private final Long forwardHighLoss;
+ private final Long backwardHighLoss;
+ private final Long forwardConsecutiveHighLoss;
+ private final Long backwardConsecutiveHighLoss;
+ private final Long forwardAvailable;
+ private final Long backwardAvailable;
+ private final Long forwardUnavailable;
+ private final Long backwardUnavailable;
+ private final MilliPct forwardMinFrameLossRatio;
+ private final MilliPct forwardMaxFrameLossRatio;
+ private final MilliPct forwardAverageFrameLossRatio;
+ private final MilliPct backwardMinFrameLossRatio;
+ private final MilliPct backwardMaxFrameLossRatio;
+ private final MilliPct backwardAverageFrameLossRatio;
+
+ protected DefaultLaStat(DefaultLaStatBuilder builder) {
+ this.elapsedTime = builder.elapsedTime;
+ this.suspectStatus = builder.suspectStatus;
+ this.forwardHighLoss = builder.forwardHighLoss;
+ this.backwardHighLoss = builder.backwardHighLoss;
+ this.forwardConsecutiveHighLoss = builder.forwardConsecutiveHighLoss;
+ this.backwardConsecutiveHighLoss = builder.backwardConsecutiveHighLoss;
+ this.forwardAvailable = builder.forwardAvailable;
+ this.backwardAvailable = builder.backwardAvailable;
+ this.forwardUnavailable = builder.forwardUnavailable;
+ this.backwardUnavailable = builder.backwardUnavailable;
+ this.forwardMinFrameLossRatio = builder.forwardMinFrameLossRatio;
+ this.forwardMaxFrameLossRatio = builder.forwardMaxFrameLossRatio;
+ this.forwardAverageFrameLossRatio = builder.forwardAverageFrameLossRatio;
+ this.backwardMinFrameLossRatio = builder.backwardMinFrameLossRatio;
+ this.backwardMaxFrameLossRatio = builder.backwardMaxFrameLossRatio;
+ this.backwardAverageFrameLossRatio = builder.backwardAverageFrameLossRatio;
+ }
+
+ @Override
+ public Duration elapsedTime() {
+ return elapsedTime;
+ }
+
+ @Override
+ public boolean suspectStatus() {
+ return suspectStatus;
+ }
+
+ @Override
+ public Long forwardHighLoss() {
+ return forwardHighLoss;
+ }
+
+ @Override
+ public Long backwardHighLoss() {
+ return backwardHighLoss;
+ }
+
+ @Override
+ public Long forwardConsecutiveHighLoss() {
+ return forwardConsecutiveHighLoss;
+ }
+
+ @Override
+ public Long backwardConsecutiveHighLoss() {
+ return backwardConsecutiveHighLoss;
+ }
+
+ @Override
+ public Long forwardAvailable() {
+ return forwardAvailable;
+ }
+
+ @Override
+ public Long backwardAvailable() {
+ return backwardAvailable;
+ }
+
+ @Override
+ public Long forwardUnavailable() {
+ return forwardUnavailable;
+ }
+
+ @Override
+ public Long backwardUnavailable() {
+ return backwardUnavailable;
+ }
+
+ @Override
+ public MilliPct forwardMinFrameLossRatio() {
+ return forwardMinFrameLossRatio;
+ }
+
+ @Override
+ public MilliPct forwardMaxFrameLossRatio() {
+ return forwardMaxFrameLossRatio;
+ }
+
+ @Override
+ public MilliPct forwardAverageFrameLossRatio() {
+ return forwardAverageFrameLossRatio;
+ }
+
+ @Override
+ public MilliPct backwardMinFrameLossRatio() {
+ return backwardMinFrameLossRatio;
+ }
+
+ @Override
+ public MilliPct backwardMaxFrameLossRatio() {
+ return backwardMaxFrameLossRatio;
+ }
+
+ @Override
+ public MilliPct backwardAverageFrameLossRatio() {
+ return backwardAverageFrameLossRatio;
+ }
+
+ /**
+ * Abstract base class for builders of.
+ * {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossAvailabilityStat}.
+ */
+ protected abstract static class DefaultLaStatBuilder implements LaStatBuilder {
+ private final Duration elapsedTime;
+ private final boolean suspectStatus;
+ private Long forwardHighLoss;
+ private Long backwardHighLoss;
+ private Long forwardConsecutiveHighLoss;
+ private Long backwardConsecutiveHighLoss;
+ private Long forwardAvailable;
+ private Long backwardAvailable;
+ private Long forwardUnavailable;
+ private Long backwardUnavailable;
+ private MilliPct forwardMinFrameLossRatio;
+ private MilliPct forwardMaxFrameLossRatio;
+ private MilliPct forwardAverageFrameLossRatio;
+ private MilliPct backwardMinFrameLossRatio;
+ private MilliPct backwardMaxFrameLossRatio;
+ private MilliPct backwardAverageFrameLossRatio;
+
+ protected DefaultLaStatBuilder(Duration elapsedTime, boolean suspectStatus) {
+ this.elapsedTime = elapsedTime;
+ this.suspectStatus = suspectStatus;
+ }
+
+ @Override
+ public LaStatBuilder forwardHighLoss(Long forwardHighLoss) {
+ this.forwardHighLoss = forwardHighLoss;
+ return this;
+ }
+
+ @Override
+ public LaStatBuilder backwardHighLoss(Long backwardHighLoss) {
+ this.backwardHighLoss = backwardHighLoss;
+ return this;
+ }
+
+ @Override
+ public LaStatBuilder forwardConsecutiveHighLoss(
+ Long forwardConsecutiveHighLoss) {
+ this.forwardConsecutiveHighLoss = forwardConsecutiveHighLoss;
+ return this;
+ }
+
+ @Override
+ public LaStatBuilder backwardConsecutiveHighLoss(
+ Long backwardConsecutiveHighLoss) {
+ this.backwardConsecutiveHighLoss = backwardConsecutiveHighLoss;
+ return this;
+ }
+
+ @Override
+ public LaStatBuilder forwardAvailable(Long forwardAvailable) {
+ this.forwardAvailable = forwardAvailable;
+ return this;
+ }
+
+ @Override
+ public LaStatBuilder backwardAvailable(Long backwardAvailable) {
+ this.backwardAvailable = backwardAvailable;
+ return this;
+ }
+
+ @Override
+ public LaStatBuilder forwardUnavailable(Long forwardUnavailable) {
+ this.forwardUnavailable = forwardUnavailable;
+ return this;
+ }
+
+ @Override
+ public LaStatBuilder backwardUnavailable(Long backwardUnavailable) {
+ this.backwardUnavailable = backwardUnavailable;
+ return this;
+ }
+
+ @Override
+ public LaStatBuilder forwardMinFrameLossRatio(
+ MilliPct forwardMinFrameLossRatio) {
+ this.forwardMinFrameLossRatio = forwardMinFrameLossRatio;
+ return this;
+ }
+
+ @Override
+ public LaStatBuilder forwardMaxFrameLossRatio(
+ MilliPct forwardMaxFrameLossRatio) {
+ this.forwardMaxFrameLossRatio = forwardMaxFrameLossRatio;
+ return this;
+ }
+
+ @Override
+ public LaStatBuilder forwardAverageFrameLossRatio(
+ MilliPct forwardAverageFrameLossRatio) {
+ this.forwardAverageFrameLossRatio = forwardAverageFrameLossRatio;
+ return this;
+ }
+
+ @Override
+ public LaStatBuilder backwardMinFrameLossRatio(
+ MilliPct backwardMinFrameLossRatio) {
+ this.backwardMinFrameLossRatio = backwardMinFrameLossRatio;
+ return this;
+ }
+
+ @Override
+ public LaStatBuilder backwardMaxFrameLossRatio(
+ MilliPct backwardMaxFrameLossRatio) {
+ this.backwardMaxFrameLossRatio = backwardMaxFrameLossRatio;
+ return this;
+ }
+
+ @Override
+ public LaStatBuilder backwardAverageFrameLossRatio(
+ MilliPct backwardAverageFrameLossRatio) {
+ this.backwardAverageFrameLossRatio = backwardAverageFrameLossRatio;
+ return this;
+ }
+ }
+
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLaStatCurrent.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLaStatCurrent.java
new file mode 100644
index 0000000..9564ef0
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLaStatCurrent.java
@@ -0,0 +1,60 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Duration;
+import java.time.Instant;
+
+/**
+ * The default implementation of LossAvailabilityStatCurrent.
+ * {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossAvailabilityStatCurrent}.
+ */
+public final class DefaultLaStatCurrent extends DefaultLaStat
+ implements LossAvailabilityStatCurrent {
+ private final Instant startTime;
+
+ private DefaultLaStatCurrent(DefaultLaStatCurrentBuilder builder) {
+ super(builder);
+ this.startTime = builder.startTime;
+ }
+
+ @Override
+ public Instant startTime() {
+ return startTime;
+ }
+
+ public static LaStatCurrentBuilder builder(Duration elapsedTime,
+ boolean suspectStatus, Instant startTime) {
+ return new DefaultLaStatCurrentBuilder(elapsedTime, suspectStatus,
+ startTime);
+ }
+
+ private static final class DefaultLaStatCurrentBuilder
+ extends DefaultLaStatBuilder implements LaStatCurrentBuilder {
+ private Instant startTime;
+
+ protected DefaultLaStatCurrentBuilder(Duration elapsedTime,
+ boolean suspectStatus, Instant startTime) {
+ super(elapsedTime, suspectStatus);
+ this.startTime = startTime;
+ }
+
+ @Override
+ public LossAvailabilityStatCurrent build() {
+ return new DefaultLaStatCurrent(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLaStatHistory.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLaStatHistory.java
new file mode 100644
index 0000000..6203bbd
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLaStatHistory.java
@@ -0,0 +1,71 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Duration;
+import java.time.Instant;
+
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+
+/**
+ * The default implementation of LossAvailabilityStatHistory.
+ * {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossAvailabilityStatHistory}.
+ */
+public final class DefaultLaStatHistory extends DefaultLaStat
+ implements LossAvailabilityStatHistory {
+ private final Instant endTime;
+ private final SoamId historyStatsId;
+
+ private DefaultLaStatHistory(DefaultLaStatHistoryBuilder builder) {
+ super(builder);
+ this.endTime = builder.endTime;
+ this.historyStatsId = builder.historyStatsId;
+ }
+
+ @Override
+ public Instant endTime() {
+ return endTime;
+ }
+
+ @Override
+ public SoamId historyStatsId() {
+ return historyStatsId;
+ }
+
+ public static LaStatHistoryBuilder builder(Duration elapsedTime,
+ boolean suspectStatus, SoamId historyStatsId, Instant endTime) {
+ return new DefaultLaStatHistoryBuilder(elapsedTime, suspectStatus,
+ historyStatsId, endTime);
+ }
+
+ private static final class DefaultLaStatHistoryBuilder
+ extends DefaultLaStatBuilder implements LaStatHistoryBuilder {
+ private Instant endTime;
+ private SoamId historyStatsId;
+
+ protected DefaultLaStatHistoryBuilder(Duration elapsedTime,
+ boolean suspectStatus, SoamId historyStatsId, Instant endTime) {
+ super(elapsedTime, suspectStatus);
+ this.historyStatsId = historyStatsId;
+ this.endTime = endTime;
+ }
+
+ @Override
+ public LossAvailabilityStatHistory build() {
+ return new DefaultLaStatHistory(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmCreate.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmCreate.java
new file mode 100644
index 0000000..c735994
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmCreate.java
@@ -0,0 +1,182 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.soam.DefaultMeasurementCreateBase;
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.Version;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate}.
+ */
+public class DefaultLmCreate extends DefaultMeasurementCreateBase
+ implements LossMeasurementCreate {
+
+ private final LmType lmCfgType;
+ private final Collection<CounterOption> countersEnabled;
+ private final Duration availabilityMeasurementInterval;
+ private final Integer availabilityNumberConsecutiveFlrMeasurements;
+ private final MilliPct availabilityFlrThreshold;
+ private final Short availabilityNumberConsecutiveIntervals;
+ private final Short availabilityNumberConsecutiveHighFlr;
+ private final Collection<LossMeasurementThreshold> lossMeasurementThresholds;
+
+ protected DefaultLmCreate(DefaultLmCreateBuilder builder) {
+ super(builder);
+ this.lmCfgType = builder.lmCfgType;
+ this.countersEnabled = builder.countersEnabled;
+ this.availabilityMeasurementInterval = builder.availabilityMeasurementInterval;
+ this.availabilityNumberConsecutiveFlrMeasurements = builder.availabilityNumberConsecutiveFlrMeasurements;
+ this.availabilityFlrThreshold = builder.availabilityFlrThreshold;
+ this.availabilityNumberConsecutiveIntervals = builder.availabilityNumberConsecutiveIntervals;
+ this.availabilityNumberConsecutiveHighFlr = builder.availabilityNumberConsecutiveHighFlr;
+ this.lossMeasurementThresholds = builder.lossMeasurementThresholds;
+ }
+
+ @Override
+ public LmType lmCfgType() {
+ return this.lmCfgType;
+ }
+
+ @Override
+ public Collection<CounterOption> countersEnabled() {
+ return this.countersEnabled;
+ }
+
+ @Override
+ public Duration availabilityMeasurementInterval() {
+ return this.availabilityMeasurementInterval;
+ }
+
+ @Override
+ public Integer availabilityNumberConsecutiveFlrMeasurements() {
+ return this.availabilityNumberConsecutiveFlrMeasurements;
+ }
+
+ @Override
+ public MilliPct availabilityFlrThreshold() {
+ return this.availabilityFlrThreshold;
+ }
+
+ @Override
+ public Short availabilityNumberConsecutiveIntervals() {
+ return this.availabilityNumberConsecutiveIntervals;
+ }
+
+ @Override
+ public Short availabilityNumberConsecutiveHighFlr() {
+ return this.availabilityNumberConsecutiveHighFlr;
+ }
+
+ @Override
+ public Collection<LossMeasurementThreshold> lossMeasurementThreshold() {
+ return this.lossMeasurementThresholds;
+ }
+
+ public static LmCreateBuilder builder(Version version, MepId remoteMepId,
+ Priority priority, LmType lmCfgType) throws SoamConfigException {
+ return new DefaultLmCreateBuilder(version, remoteMepId,
+ priority, lmCfgType);
+ }
+
+ /**
+ * Implementation of LmCreateBuilder.
+ * {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate.LmCreateBuilder}
+ */
+ protected static class DefaultLmCreateBuilder extends DefaultMeasCreateBaseBuilder
+ implements LmCreateBuilder {
+ private final LmType lmCfgType;
+ private Collection<CounterOption> countersEnabled;
+ private Duration availabilityMeasurementInterval;
+ private Integer availabilityNumberConsecutiveFlrMeasurements;
+ private MilliPct availabilityFlrThreshold;
+ private Short availabilityNumberConsecutiveIntervals;
+ private Short availabilityNumberConsecutiveHighFlr;
+ private Collection<LossMeasurementThreshold> lossMeasurementThresholds;
+
+ protected DefaultLmCreateBuilder(Version version, MepId remoteMepId,
+ Priority priority, LmType lmCfgType) throws SoamConfigException {
+ super(version, remoteMepId, priority);
+ this.lmCfgType = lmCfgType;
+ countersEnabled = new ArrayList<>();
+ lossMeasurementThresholds = new ArrayList<>();
+ }
+
+ @Override
+ public LmCreateBuilder addToCountersEnabled(
+ CounterOption counterOption) {
+ this.countersEnabled.add(counterOption);
+ return this;
+ }
+
+ @Override
+ public LmCreateBuilder availabilityMeasurementInterval(
+ Duration availabilityMeasurementInterval) {
+ this.availabilityMeasurementInterval = availabilityMeasurementInterval;
+ return this;
+ }
+
+ @Override
+ public LmCreateBuilder availabilityNumberConsecutiveFlrMeasurements(
+ Integer availabilityNumberConsecutiveFlrMeasurements) {
+ this.availabilityNumberConsecutiveFlrMeasurements =
+ availabilityNumberConsecutiveFlrMeasurements;
+ return this;
+ }
+
+ @Override
+ public LmCreateBuilder availabilityFlrThreshold(
+ MilliPct availabilityFlrThreshold) {
+ this.availabilityFlrThreshold = availabilityFlrThreshold;
+ return this;
+ }
+
+ @Override
+ public LmCreateBuilder availabilityNumberConsecutiveIntervals(
+ Short availabilityNumberConsecutiveIntervals)
+ throws SoamConfigException {
+ this.availabilityNumberConsecutiveIntervals = availabilityNumberConsecutiveIntervals;
+ return this;
+ }
+
+ @Override
+ public LmCreateBuilder availabilityNumberConsecutiveHighFlr(
+ Short availabilityNumberConsecutiveHighFlr)
+ throws SoamConfigException {
+ this.availabilityNumberConsecutiveHighFlr = availabilityNumberConsecutiveHighFlr;
+ return this;
+ }
+
+ @Override
+ public LmCreateBuilder addToLossMeasurementThreshold(
+ LossMeasurementThreshold lossMeasurementThreshold) {
+ this.lossMeasurementThresholds.add(lossMeasurementThreshold);
+ return this;
+ }
+
+ @Override
+ public LossMeasurementCreate build() {
+ return new DefaultLmCreate(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmEntry.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmEntry.java
new file mode 100644
index 0000000..3e45303
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmEntry.java
@@ -0,0 +1,220 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.Version;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry}.
+ */
+public final class DefaultLmEntry extends DefaultLmCreate
+ implements LossMeasurementEntry {
+ private final SoamId lmId;
+ private final MilliPct measuredForwardFlr;
+ private final MilliPct measuredBackwardFlr;
+ private final AvailabilityType measuredAvailabilityForwardStatus;
+ private final AvailabilityType measuredAvailabilityBackwardStatus;
+ private final Instant measuredForwardLastTransitionTime;
+ private final Instant measuredBackwardLastTransitionTime;
+ private final LossMeasurementStatCurrent measurementCurrent;
+ private final Collection<LossMeasurementStatHistory> measurementHistories;
+ private final LossAvailabilityStatCurrent availabilityCurrent;
+ private final Collection<LossAvailabilityStatHistory> availabilityHistories;
+
+ protected DefaultLmEntry(DefaultLmEntryBuilder builder) {
+ super(builder);
+ this.lmId = builder.lmId;
+ this.measuredForwardFlr = builder.measuredForwardFlr;
+ this.measuredBackwardFlr = builder.measuredBackwardFlr;
+ this.measuredAvailabilityForwardStatus = builder.measuredAvailabilityForwardStatus;
+ this.measuredAvailabilityBackwardStatus = builder.measuredAvailabilityBackwardStatus;
+ this.measuredForwardLastTransitionTime = builder.measuredForwardLastTransitionTime;
+ this.measuredBackwardLastTransitionTime = builder.measuredBackwardLastTransitionTime;
+ this.measurementCurrent = builder.measurementCurrent;
+ this.measurementHistories = builder.measurementHistories;
+ this.availabilityCurrent = builder.availabilityCurrent;
+ this.availabilityHistories = builder.availabilityHistories;
+ }
+
+ @Override
+ public SoamId lmId() {
+ return lmId;
+ }
+
+ @Override
+ public MilliPct measuredForwardFlr() {
+ return measuredForwardFlr;
+ }
+
+ @Override
+ public MilliPct measuredBackwardFlr() {
+ return measuredBackwardFlr;
+ }
+
+ @Override
+ public AvailabilityType measuredAvailabilityForwardStatus() {
+ return measuredAvailabilityForwardStatus;
+ }
+
+ @Override
+ public AvailabilityType measuredAvailabilityBackwardStatus() {
+ return measuredAvailabilityBackwardStatus;
+ }
+
+ @Override
+ public Instant measuredForwardLastTransitionTime() {
+ return measuredForwardLastTransitionTime;
+ }
+
+ @Override
+ public Instant measuredBackwardLastTransitionTime() {
+ return measuredBackwardLastTransitionTime;
+ }
+
+ @Override
+ public LossMeasurementStatCurrent measurementCurrent() {
+ return measurementCurrent;
+ }
+
+ @Override
+ public Collection<LossMeasurementStatHistory> measurementHistories() {
+ return measurementHistories;
+ }
+
+ @Override
+ public LossAvailabilityStatCurrent availabilityCurrent() {
+ return availabilityCurrent;
+ }
+
+ @Override
+ public Collection<LossAvailabilityStatHistory> availabilityHistories() {
+ return availabilityHistories;
+ }
+
+ public static LmEntryBuilder builder(Version version, MepId remoteMepId,
+ Priority priority, LmType lmCfgType, SoamId lmId)
+ throws SoamConfigException {
+ return new DefaultLmEntryBuilder(version, remoteMepId,
+ priority, lmCfgType, lmId);
+ }
+
+ private static final class DefaultLmEntryBuilder extends DefaultLmCreateBuilder
+ implements LmEntryBuilder {
+ private final SoamId lmId;
+ private MilliPct measuredForwardFlr;
+ private MilliPct measuredBackwardFlr;
+ private AvailabilityType measuredAvailabilityForwardStatus;
+ private AvailabilityType measuredAvailabilityBackwardStatus;
+ private Instant measuredForwardLastTransitionTime;
+ private Instant measuredBackwardLastTransitionTime;
+ private LossMeasurementStatCurrent measurementCurrent;
+ private Collection<LossMeasurementStatHistory> measurementHistories;
+ private LossAvailabilityStatCurrent availabilityCurrent;
+ private Collection<LossAvailabilityStatHistory> availabilityHistories;
+
+ protected DefaultLmEntryBuilder(Version version, MepId remoteMepId,
+ Priority priority, LmType lmCfgType, SoamId lmId)
+ throws SoamConfigException {
+ super(version, remoteMepId, priority, lmCfgType);
+ this.lmId = lmId;
+ measurementHistories = new ArrayList<>();
+ availabilityHistories = new ArrayList<>();
+ }
+
+ @Override
+ public LmEntryBuilder measuredForwardFlr(MilliPct measuredForwardFlr) {
+ this.measuredForwardFlr = measuredForwardFlr;
+ return this;
+ }
+
+ @Override
+ public LmEntryBuilder measuredBackwardFlr(
+ MilliPct measuredBackwardFlr) {
+ this.measuredBackwardFlr = measuredBackwardFlr;
+ return this;
+ }
+
+ @Override
+ public LmEntryBuilder measuredAvailabilityForwardStatus(
+ AvailabilityType measuredAvailabilityForwardStatus) {
+ this.measuredAvailabilityForwardStatus = measuredAvailabilityForwardStatus;
+ return this;
+ }
+
+ @Override
+ public LmEntryBuilder measuredAvailabilityBackwardStatus(
+ AvailabilityType measuredAvailabilityBackwardStatus) {
+ this.measuredAvailabilityBackwardStatus = measuredAvailabilityBackwardStatus;
+ return this;
+ }
+
+ @Override
+ public LmEntryBuilder measuredForwardLastTransitionTime(
+ Instant measuredForwardLastTransitionTime) {
+ this.measuredForwardLastTransitionTime = measuredForwardLastTransitionTime;
+ return this;
+ }
+
+ @Override
+ public LmEntryBuilder measuredBackwardLastTransitionTime(
+ Instant measuredBackwardLastTransitionTime) {
+ this.measuredBackwardLastTransitionTime = measuredBackwardLastTransitionTime;
+ return this;
+ }
+
+ @Override
+ public LmEntryBuilder measurementCurrent(
+ LossMeasurementStatCurrent measurementCurrent) {
+ this.measurementCurrent = measurementCurrent;
+ return this;
+ }
+
+ @Override
+ public LmEntryBuilder addToMeasurementHistories(
+ LossMeasurementStatHistory history) {
+ this.measurementHistories.add(history);
+ return this;
+ }
+
+ @Override
+ public LmEntryBuilder availabilityCurrent(
+ LossAvailabilityStatCurrent availabilityCurrent) {
+ this.availabilityCurrent = availabilityCurrent;
+ return this;
+ }
+
+ @Override
+ public LmEntryBuilder addToAvailabilityHistories(
+ LossAvailabilityStatHistory history) {
+ this.availabilityHistories.add(history);
+ return this;
+ }
+
+ @Override
+ public LossMeasurementEntry build() {
+ return new DefaultLmEntry(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmStat.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmStat.java
new file mode 100644
index 0000000..0410e47
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmStat.java
@@ -0,0 +1,235 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Duration;
+
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStat}.
+ */
+public abstract class DefaultLmStat implements LossMeasurementStat {
+ private final Duration elapsedTime;
+ private final boolean suspectStatus;
+ private final Long forwardTransmittedFrames;
+ private final Long forwardReceivedFrames;
+ private final MilliPct forwardMinFrameLossRatio;
+ private final MilliPct forwardMaxFrameLossRatio;
+ private final MilliPct forwardAverageFrameLossRatio;
+ private final Long backwardTransmittedFrames;
+ private final Long backwardReceivedFrames;
+ private final MilliPct backwardMinFrameLossRatio;
+ private final MilliPct backwardMaxFrameLossRatio;
+ private final MilliPct backwardAverageFrameLossRatio;
+ private final Long soamPdusSent;
+ private final Long soamPdusReceived;
+
+ protected DefaultLmStat(DefaultLmStatBuilder builder) {
+ this.elapsedTime = builder.elapsedTime;
+ this.suspectStatus = builder.suspectStatus;
+ this.forwardTransmittedFrames = builder.forwardTransmittedFrames;
+ this.forwardReceivedFrames = builder.forwardReceivedFrames;
+ this.forwardMinFrameLossRatio = builder.forwardMinFrameLossRatio;
+ this.forwardMaxFrameLossRatio = builder.forwardMaxFrameLossRatio;
+ this.forwardAverageFrameLossRatio = builder.forwardAverageFrameLossRatio;
+ this.backwardTransmittedFrames = builder.backwardTransmittedFrames;
+ this.backwardReceivedFrames = builder.backwardReceivedFrames;
+ this.backwardMinFrameLossRatio = builder.backwardMinFrameLossRatio;
+ this.backwardMaxFrameLossRatio = builder.backwardMaxFrameLossRatio;
+ this.backwardAverageFrameLossRatio = builder.backwardAverageFrameLossRatio;
+ this.soamPdusSent = builder.soamPdusSent;
+ this.soamPdusReceived = builder.soamPdusReceived;
+ }
+
+ @Override
+ public Duration elapsedTime() {
+ return this.elapsedTime;
+ }
+
+ @Override
+ public boolean suspectStatus() {
+ return this.suspectStatus;
+ }
+
+ @Override
+ public Long forwardTransmittedFrames() {
+ return this.forwardTransmittedFrames;
+ }
+
+ @Override
+ public Long forwardReceivedFrames() {
+ return this.forwardReceivedFrames;
+ }
+
+ @Override
+ public MilliPct forwardMinFrameLossRatio() {
+ return this.forwardMinFrameLossRatio;
+ }
+
+ @Override
+ public MilliPct forwardMaxFrameLossRatio() {
+ return this.forwardMaxFrameLossRatio;
+ }
+
+ @Override
+ public MilliPct forwardAverageFrameLossRatio() {
+ return this.forwardAverageFrameLossRatio;
+ }
+
+ @Override
+ public Long backwardTransmittedFrames() {
+ return this.backwardTransmittedFrames;
+ }
+
+ @Override
+ public Long backwardReceivedFrames() {
+ return this.backwardReceivedFrames;
+ }
+
+ @Override
+ public MilliPct backwardMinFrameLossRatio() {
+ return this.backwardMinFrameLossRatio;
+ }
+
+ @Override
+ public MilliPct backwardMaxFrameLossRatio() {
+ return this.backwardMaxFrameLossRatio;
+ }
+
+ @Override
+ public MilliPct backwardAverageFrameLossRatio() {
+ return this.backwardAverageFrameLossRatio;
+ }
+
+ @Override
+ public Long soamPdusSent() {
+ return this.soamPdusSent;
+ }
+
+ @Override
+ public Long soamPdusReceived() {
+ return this.soamPdusReceived;
+ }
+
+ /**
+ * Abstract implementation of LmStatBuilder.
+ * {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStat.LmStatBuilder}
+ */
+ protected abstract static class DefaultLmStatBuilder implements LmStatBuilder {
+ private final Duration elapsedTime;
+ private final boolean suspectStatus;
+ private Long forwardTransmittedFrames;
+ private Long forwardReceivedFrames;
+ private MilliPct forwardMinFrameLossRatio;
+ private MilliPct forwardMaxFrameLossRatio;
+ private MilliPct forwardAverageFrameLossRatio;
+ private Long backwardTransmittedFrames;
+ private Long backwardReceivedFrames;
+ private MilliPct backwardMinFrameLossRatio;
+ private MilliPct backwardMaxFrameLossRatio;
+ private MilliPct backwardAverageFrameLossRatio;
+ private Long soamPdusSent;
+ private Long soamPdusReceived;
+
+ protected DefaultLmStatBuilder(Duration elapsedTime, boolean suspectStatus) {
+ this.elapsedTime = elapsedTime;
+ this.suspectStatus = suspectStatus;
+ }
+
+ @Override
+ public LmStatBuilder forwardTransmittedFrames(
+ Long forwardTransmittedFrames) {
+ this.forwardTransmittedFrames = forwardTransmittedFrames;
+ return this;
+ }
+
+ @Override
+ public LmStatBuilder forwardReceivedFrames(Long forwardReceivedFrames) {
+ this.forwardReceivedFrames = forwardReceivedFrames;
+ return this;
+ }
+
+ @Override
+ public LmStatBuilder forwardMinFrameLossRatio(
+ MilliPct forwardMinFrameLossRatio) {
+ this.forwardMinFrameLossRatio = forwardMinFrameLossRatio;
+ return this;
+ }
+
+ @Override
+ public LmStatBuilder forwardMaxFrameLossRatio(
+ MilliPct forwardMaxFrameLossRatio) {
+ this.forwardMaxFrameLossRatio = forwardMaxFrameLossRatio;
+ return this;
+ }
+
+ @Override
+ public LmStatBuilder forwardAverageFrameLossRatio(
+ MilliPct forwardAverageFrameLossRatio) {
+ this.forwardAverageFrameLossRatio = forwardAverageFrameLossRatio;
+ return this;
+ }
+
+ @Override
+ public LmStatBuilder backwardTransmittedFrames(
+ Long backwardTransmittedFrames) {
+ this.backwardTransmittedFrames = backwardTransmittedFrames;
+ return this;
+ }
+
+ @Override
+ public LmStatBuilder backwardReceivedFrames(
+ Long backwardReceivedFrames) {
+ this.backwardReceivedFrames = backwardReceivedFrames;
+ return this;
+ }
+
+ @Override
+ public LmStatBuilder backwardMinFrameLossRatio(
+ MilliPct backwardMinFrameLossRatio) {
+ this.backwardMinFrameLossRatio = backwardMinFrameLossRatio;
+ return this;
+ }
+
+ @Override
+ public LmStatBuilder backwardMaxFrameLossRatio(
+ MilliPct backwardMaxFrameLossRatio) {
+ this.backwardMaxFrameLossRatio = backwardMaxFrameLossRatio;
+ return this;
+ }
+
+ @Override
+ public LmStatBuilder backwardAverageFrameLossRatio(
+ MilliPct backwardAverageFrameLossRatio) {
+ this.backwardAverageFrameLossRatio = backwardAverageFrameLossRatio;
+ return this;
+ }
+
+ @Override
+ public LmStatBuilder soamPdusSent(Long soamPdusSent) {
+ this.soamPdusSent = soamPdusSent;
+ return this;
+ }
+
+ @Override
+ public LmStatBuilder soamPdusReceived(Long soamPdusReceived) {
+ this.soamPdusReceived = soamPdusReceived;
+ return this;
+ }
+ }
+
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmStatCurrent.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmStatCurrent.java
new file mode 100644
index 0000000..1920845
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmStatCurrent.java
@@ -0,0 +1,60 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Duration;
+import java.time.Instant;
+
+/**
+ * The default implementation of LossMeasurementStatCurrent.
+ * {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatCurrent}
+ */
+public final class DefaultLmStatCurrent extends DefaultLmStat
+ implements LossMeasurementStatCurrent {
+ private final Instant startTime;
+
+ protected DefaultLmStatCurrent(DefaultLmStatCurrentBuilder builder) {
+ super(builder);
+ this.startTime = builder.startTime;
+ }
+
+ @Override
+ public Instant startTime() {
+ return startTime;
+ }
+
+ public static LmStatCurrentBuilder builder(Duration elapsedTime,
+ boolean suspectStatus, Instant startTime) {
+ return new DefaultLmStatCurrentBuilder(elapsedTime,
+ suspectStatus, startTime);
+ }
+
+ private static class DefaultLmStatCurrentBuilder extends DefaultLmStatBuilder
+ implements LmStatCurrentBuilder {
+ private final Instant startTime;
+
+ protected DefaultLmStatCurrentBuilder(Duration elapsedTime,
+ boolean suspectStatus, Instant startTime) {
+ super(elapsedTime, suspectStatus);
+ this.startTime = startTime;
+ }
+
+ @Override
+ public LossMeasurementStatCurrent build() {
+ return new DefaultLmStatCurrent(this);
+ }
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmStatHistory.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmStatHistory.java
new file mode 100644
index 0000000..1109e92
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmStatHistory.java
@@ -0,0 +1,74 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Duration;
+import java.time.Instant;
+
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+
+/**
+ * The default implementation of LossMeasurementStatHistory.
+ * {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatHistory}
+ */
+public final class DefaultLmStatHistory extends DefaultLmStat
+ implements LossMeasurementStatHistory {
+ private final SoamId historyStatsId;
+ private final Instant endTime;
+
+ protected DefaultLmStatHistory(DefaultLmStatHistoryBuilder builder) {
+ super(builder);
+ this.historyStatsId = builder.historyStatsId;
+ this.endTime = builder.endTime;
+ }
+
+ @Override
+ public SoamId historyStatsId() {
+ return historyStatsId;
+ }
+
+
+ @Override
+ public Instant endTime() {
+ return endTime;
+ }
+
+ public static LmStatHistoryBuilder builder(Duration elapsedTime,
+ boolean suspectStatus, SoamId historyStatsId, Instant endTime) {
+ return new DefaultLmStatHistoryBuilder(elapsedTime,
+ suspectStatus, historyStatsId, endTime);
+ }
+
+ private static class DefaultLmStatHistoryBuilder extends DefaultLmStatBuilder
+ implements LmStatHistoryBuilder {
+ private final SoamId historyStatsId;
+ private final Instant endTime;
+
+ protected DefaultLmStatHistoryBuilder(Duration elapsedTime,
+ boolean suspectStatus, SoamId historyStatsId, Instant endTime) {
+ super(elapsedTime, suspectStatus);
+ this.historyStatsId = historyStatsId;
+ this.endTime = endTime;
+ }
+
+ @Override
+ public LossMeasurementStatHistory build() {
+ return new DefaultLmStatHistory(this);
+ }
+ }
+
+
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmThreshold.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmThreshold.java
new file mode 100644
index 0000000..0487516
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/DefaultLmThreshold.java
@@ -0,0 +1,274 @@
+/*
+ * 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.soam.loss;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+
+/**
+ * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementThreshold}.
+ */
+public final class DefaultLmThreshold implements LossMeasurementThreshold {
+
+ private final SoamId thresholdId;
+ private final Collection<ThresholdOption> threshold;
+ private final MilliPct measuredFlrForward;
+ private final MilliPct maxFlrForward;
+ private final MilliPct averageFlrForward;
+ private final MilliPct measuredFlrBackward;
+ private final MilliPct maxFlrBackward;
+ private final MilliPct averageFlrBackward;
+ private final Long forwardHighLoss;
+ private final Long forwardConsecutiveHighLoss;
+ private final Long backwardHighLoss;
+ private final Long backwardConsecutiveHighLoss;
+ private final Long forwardUnavailableCount;
+ private final MilliPct forwardAvailableRatio;
+ private final Long backwardUnavailableCount;
+ private final MilliPct backwardAvailableRatio;
+
+ private DefaultLmThreshold(DefaultLmThresholdBuilder builder) {
+ this.thresholdId = builder.thresholdId;
+ this.threshold = builder.threshold;
+ this.measuredFlrForward = builder.measuredFlrForward;
+ this.maxFlrForward = builder.maxFlrForward;
+ this.averageFlrForward = builder.averageFlrForward;
+ this.measuredFlrBackward = builder.measuredFlrBackward;
+ this.maxFlrBackward = builder.maxFlrBackward;
+ this.averageFlrBackward = builder.averageFlrBackward;
+ this.forwardHighLoss = builder.forwardHighLoss;
+ this.forwardConsecutiveHighLoss = builder.forwardConsecutiveHighLoss;
+ this.backwardHighLoss = builder.backwardHighLoss;
+ this.backwardConsecutiveHighLoss = builder.backwardConsecutiveHighLoss;
+ this.forwardUnavailableCount = builder.forwardUnavailableCount;
+ this.forwardAvailableRatio = builder.forwardAvailableRatio;
+ this.backwardUnavailableCount = builder.backwardUnavailableCount;
+ this.backwardAvailableRatio = builder.backwardAvailableRatio;
+ }
+
+ @Override
+ public SoamId thresholdId() {
+ return thresholdId;
+ }
+
+ @Override
+ public Collection<ThresholdOption> thresholds() {
+ return threshold;
+ }
+
+ @Override
+ public MilliPct measuredFlrForward() {
+ return measuredFlrForward;
+ }
+
+ @Override
+ public MilliPct maxFlrForward() {
+ return maxFlrForward;
+ }
+
+ @Override
+ public MilliPct averageFlrForward() {
+ return averageFlrForward;
+ }
+
+ @Override
+ public MilliPct measuredFlrBackward() {
+ return measuredFlrBackward;
+ }
+
+ @Override
+ public MilliPct maxFlrBackward() {
+ return maxFlrBackward;
+ }
+
+ @Override
+ public MilliPct averageFlrBackward() {
+ return averageFlrBackward;
+ }
+
+ @Override
+ public Long forwardHighLoss() {
+ return forwardHighLoss;
+ }
+
+ @Override
+ public Long forwardConsecutiveHighLoss() {
+ return forwardConsecutiveHighLoss;
+ }
+
+ @Override
+ public Long backwardHighLoss() {
+ return backwardHighLoss;
+ }
+
+ @Override
+ public Long backwardConsecutiveHighLoss() {
+ return backwardConsecutiveHighLoss;
+ }
+
+ @Override
+ public Long forwardUnavailableCount() {
+ return forwardUnavailableCount;
+ }
+
+ @Override
+ public MilliPct forwardAvailableRatio() {
+ return forwardAvailableRatio;
+ }
+
+ @Override
+ public Long backwardUnavailableCount() {
+ return backwardUnavailableCount;
+ }
+
+ @Override
+ public MilliPct backwardAvailableRatio() {
+ return backwardAvailableRatio;
+ }
+
+ public static LmThresholdBuilder builder(SoamId thresholdId) {
+ return new DefaultLmThresholdBuilder(thresholdId);
+ }
+
+ private static final class DefaultLmThresholdBuilder implements LmThresholdBuilder {
+ private final SoamId thresholdId;
+ private Collection<ThresholdOption> threshold;
+ private MilliPct measuredFlrForward;
+ private MilliPct maxFlrForward;
+ private MilliPct averageFlrForward;
+ private MilliPct measuredFlrBackward;
+ private MilliPct maxFlrBackward;
+ private MilliPct averageFlrBackward;
+ private Long forwardHighLoss;
+ private Long forwardConsecutiveHighLoss;
+ private Long backwardHighLoss;
+ private Long backwardConsecutiveHighLoss;
+ private Long forwardUnavailableCount;
+ private MilliPct forwardAvailableRatio;
+ private Long backwardUnavailableCount;
+ private MilliPct backwardAvailableRatio;
+
+ protected DefaultLmThresholdBuilder(SoamId thresholdId) {
+ this.thresholdId = thresholdId;
+ threshold = new ArrayList<>();
+ }
+
+ @Override
+ public LmThresholdBuilder addToThreshold(ThresholdOption threshold) {
+ this.threshold.add(threshold);
+ return this;
+ }
+
+ @Override
+ public LmThresholdBuilder measuredFlrForward(MilliPct measuredFlrForward) {
+ this.measuredFlrForward = measuredFlrForward;
+ return this;
+ }
+
+ @Override
+ public LmThresholdBuilder maxFlrForward(MilliPct maxFlrForward) {
+ this.maxFlrForward = maxFlrForward;
+ return this;
+ }
+
+ @Override
+ public LmThresholdBuilder averageFlrForward(MilliPct averageFlrForward) {
+ this.averageFlrForward = averageFlrForward;
+ return this;
+ }
+
+ @Override
+ public LmThresholdBuilder measuredFlrBackward(
+ MilliPct measuredFlrBackward) {
+ this.measuredFlrBackward = measuredFlrBackward;
+ return this;
+ }
+
+ @Override
+ public LmThresholdBuilder maxFlrBackward(MilliPct maxFlrBackward) {
+ this.maxFlrBackward = maxFlrBackward;
+ return this;
+ }
+
+ @Override
+ public LmThresholdBuilder averageFlrBackward(MilliPct averageFlrBackward) {
+ this.averageFlrBackward = averageFlrBackward;
+ return this;
+ }
+
+ @Override
+ public LmThresholdBuilder forwardHighLoss(Long forwardHighLoss) {
+ this.forwardHighLoss = forwardHighLoss;
+ return this;
+ }
+
+ @Override
+ public LmThresholdBuilder forwardConsecutiveHighLoss(
+ Long forwardConsecutiveHighLoss) {
+ this.forwardConsecutiveHighLoss = forwardConsecutiveHighLoss;
+ return this;
+ }
+
+ @Override
+ public LmThresholdBuilder backwardHighLoss(Long backwardHighLoss) {
+ this.backwardHighLoss = backwardHighLoss;
+ return this;
+ }
+
+ @Override
+ public LmThresholdBuilder backwardConsecutiveHighLoss(
+ Long backwardConsecutiveHighLoss) {
+ this.backwardConsecutiveHighLoss = backwardConsecutiveHighLoss;
+ return this;
+ }
+
+ @Override
+ public LmThresholdBuilder forwardUnavailableCount(
+ Long forwardUnavailableCount) {
+ this.forwardUnavailableCount = forwardUnavailableCount;
+ return this;
+ }
+
+ @Override
+ public LmThresholdBuilder forwardAvailableRatio(
+ MilliPct forwardAvailableRatio) {
+ this.forwardAvailableRatio = forwardAvailableRatio;
+ return this;
+ }
+
+ @Override
+ public LmThresholdBuilder backwardUnavailableCount(
+ Long backwardUnavailableCount) {
+ this.backwardUnavailableCount = backwardUnavailableCount;
+ return this;
+ }
+
+ @Override
+ public LmThresholdBuilder backwardAvailableRatio(
+ MilliPct backwardAvailableRatio) {
+ this.backwardAvailableRatio = backwardAvailableRatio;
+ return this;
+ }
+
+ @Override
+ public LossMeasurementThreshold build() {
+ return new DefaultLmThreshold(this);
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStat.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStat.java
new file mode 100644
index 0000000..09b6e0e
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStat.java
@@ -0,0 +1,204 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Duration;
+
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+
+/**
+ * Abstract base interface to represent Loss Availability Stats.
+ */
+public interface LossAvailabilityStat {
+
+ Duration elapsedTime();
+
+ /**
+ * Indicates whether the Measurement Interval has been marked as suspect.
+ * The object is set to false at the start of a measurement interval.
+ * Conditions for a discontinuity include, but are not limited to the following:
+ * 1 - The local time-of-day clock is adjusted by at least 10 seconds
+ * 2 - The conducting of a performance measurement is halted before the
+ * current Measurement Interval is completed
+ * 3 - A local test, failure, or reconfiguration that disrupts service
+ * @return true when there is a discontinuity in the performance measurements during the Measurement Interval
+ */
+ boolean suspectStatus();
+
+ /**
+ * The number of high loss intervals (HLI) over time in the forward direction.
+ * The value starts at 0 and increments for every HLI that occurs.
+ * This parameter is equivalent to 'L Sub T' found in MEF 10.2.1
+ * @return the number of intervals
+ */
+ Long forwardHighLoss();
+
+ /**
+ * The number of high loss intervals (HLI) over time in the backward direction.
+ * The value starts at 0 and increments for every HLI that occurs.
+ * This parameter is equivalent to 'L Sub T' found in MEF 10.2.1
+ * @return the number of intervals
+ */
+ Long backwardHighLoss();
+
+ /**
+ * The number of consecutive high loss intervals (CHLI) over time in the forward direction.
+ * The value starts at 0 and increments for every HLI that occurs.
+ * This parameter is equivalent to 'B Sub T' found in MEF 10.2.1
+ * @return the number of intervals
+ */
+ Long forwardConsecutiveHighLoss();
+
+ /**
+ * The number of consecutive high loss intervals (CHLI) over time in the backward direction.
+ * The value starts at 0 and increments for every HLI that occurs.
+ * This parameter is equivalent to 'B Sub T' found in MEF 10.2.1
+ * @return the number of intervals
+ */
+ Long backwardConsecutiveHighLoss();
+
+ /**
+ * The number of availability indicators during a small time interval.
+ * evaluated as available (low frame loss) in the forward direction by this
+ * MEP during this measurement interval.
+ * @return The number of availability indicators
+ */
+ Long forwardAvailable();
+
+ /**
+ * The number of availability indicators during a small time interval.
+ * evaluated as available (low frame loss) in the backward direction by
+ * this MEP during this measurement interval.
+ * @return The number of availability indicators
+ */
+ Long backwardAvailable();
+
+ /**
+ * The number of availability indicators during a small time interval.
+ * evaluated as unavailable (high frame loss) in the forward direction by
+ * this MEP during this measurement interval
+ * @return The number of availability indicators
+ */
+ Long forwardUnavailable();
+
+ /**
+ * The number of availability indicators during a small time interval.
+ * evaluated as unavailable (high frame loss) in the backward direction by
+ * this MEP during this measurement interval
+ * @return The number of availability indicators
+ */
+ Long backwardUnavailable();
+
+ /**
+ * The minimum one-way availability flr in the forward direction,.
+ * from among the set of availability flr values calculated by the MEP in this Measurement Interval.
+ * There is one availability flr value for each 'delta_t' time period within
+ * the Measurement Interval, as specified in MEF 10.2.1.
+ * The flr value is a ratio that is expressed as a percent with a value of 0
+ * (ratio 0.00) through 100000 (ratio 1.00).
+ * @return The ratio as 1/1000th of a percent, where 1 indicates 0.001 percent
+ */
+ MilliPct forwardMinFrameLossRatio();
+
+ /**
+ * The maximum one-way availability flr in the forward direction,.
+ * from among the set of availability flr values calculated by the MEP in this Measurement Interval.
+ * There is one availability flr value for each 'delta_t' time period within
+ * the Measurement Interval, as specified in MEF 10.2.1.
+ * The flr value is a ratio that is expressed as a percent with a value of 0
+ * (ratio 0.00) through 100000 (ratio 1.00).
+ * @return The ratio as 1/1000th of a percent, where 1 indicates 0.001 percent
+ */
+ MilliPct forwardMaxFrameLossRatio();
+
+ /**
+ * The average one-way availability flr in the forward direction,.
+ * from among the set of availability flr values calculated by the MEP in this Measurement Interval.
+ * There is one availability flr value for each 'delta_t' time period within
+ * the Measurement Interval, as specified in MEF 10.2.1.
+ * The flr value is a ratio that is expressed as a percent with a value of 0
+ * (ratio 0.00) through 100000 (ratio 1.00).
+ * @return The ratio as 1/1000th of a percent, where 1 indicates 0.001 percent
+ */
+ MilliPct forwardAverageFrameLossRatio();
+
+ /**
+ * The minimum one-way availability flr in the backward direction,.
+ * from among the set of availability flr values calculated by the MEP in this Measurement Interval.
+ * There is one availability flr value for each 'delta_t' time period within
+ * the Measurement Interval, as specified in MEF 10.2.1.
+ * The flr value is a ratio that is expressed as a percent with a value of 0
+ * (ratio 0.00) through 100000 (ratio 1.00).
+ * @return The ratio as 1/1000th of a percent, where 1 indicates 0.001 percent
+ */
+ MilliPct backwardMinFrameLossRatio();
+
+ /**
+ * The maximum one-way availability flr in the backward direction,.
+ * from among the set of availability flr values calculated by the MEP in this Measurement Interval.
+ * There is one availability flr value for each 'delta_t' time period within
+ * the Measurement Interval, as specified in MEF 10.2.1.
+ * The flr value is a ratio that is expressed as a percent with a value of 0
+ * (ratio 0.00) through 100000 (ratio 1.00).
+ * @return The ratio as 1/1000th of a percent, where 1 indicates 0.001 percent
+ */
+ MilliPct backwardMaxFrameLossRatio();
+
+ /**
+ * The average one-way availability flr in the backward direction,.
+ * from among the set of availability flr values calculated by the MEP in this Measurement Interval.
+ * There is one availability flr value for each 'delta_t' time period within
+ * the Measurement Interval, as specified in MEF 10.2.1.
+ * The flr value is a ratio that is expressed as a percent with a value of 0
+ * (ratio 0.00) through 100000 (ratio 1.00).
+ * @return The ratio as 1/1000th of a percent, where 1 indicates 0.001 percent
+ */
+ MilliPct backwardAverageFrameLossRatio();
+
+ /**
+ * Abstract builder for classes derived from LossAvailabilityStat.
+ * {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossAvailabilityStat}.
+ */
+ public interface LaStatBuilder {
+ LaStatBuilder forwardHighLoss(Long forwardHighLoss);
+
+ LaStatBuilder backwardHighLoss(Long backwardHighLoss);
+
+ LaStatBuilder forwardConsecutiveHighLoss(Long forwardConsecutiveHighLoss);
+
+ LaStatBuilder backwardConsecutiveHighLoss(Long backwardConsecutiveHighLoss);
+
+ LaStatBuilder forwardAvailable(Long forwardAvailable);
+
+ LaStatBuilder backwardAvailable(Long backwardAvailable);
+
+ LaStatBuilder forwardUnavailable(Long forwardUnavailable);
+
+ LaStatBuilder backwardUnavailable(Long backwardUnavailable);
+
+ LaStatBuilder forwardMinFrameLossRatio(MilliPct forwardMinFrameLossRatio);
+
+ LaStatBuilder forwardMaxFrameLossRatio(MilliPct forwardMaxFrameLossRatio);
+
+ LaStatBuilder forwardAverageFrameLossRatio(MilliPct forwardAverageFrameLossRatio);
+
+ LaStatBuilder backwardMinFrameLossRatio(MilliPct backwardMinFrameLossRatio);
+
+ LaStatBuilder backwardMaxFrameLossRatio(MilliPct backwardMaxFrameLossRatio);
+
+ LaStatBuilder backwardAverageFrameLossRatio(MilliPct backwardAverageFrameLossRatio);
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatCurrent.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatCurrent.java
new file mode 100644
index 0000000..9c1465a
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatCurrent.java
@@ -0,0 +1,37 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Instant;
+
+/**
+ * Object for representing Loss Availability Stats Current.
+ * Extends {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossAvailabilityStat}
+ */
+public interface LossAvailabilityStatCurrent extends LossAvailabilityStat {
+ /**
+ * The time that the current Measurement Interval started.
+ * @return The start time as a java Instant
+ */
+ Instant startTime();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossAvailabilityStatCurrent}.
+ */
+ public interface LaStatCurrentBuilder extends LaStatBuilder {
+ LossAvailabilityStatCurrent build();
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatHistory.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatHistory.java
new file mode 100644
index 0000000..49beef5
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatHistory.java
@@ -0,0 +1,45 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Instant;
+
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+
+/**
+ * Object for representing Loss Availability Stats History.
+ * Extends {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossAvailabilityStat}
+ */
+public interface LossAvailabilityStatHistory extends LossAvailabilityStat {
+ /**
+ * The identifier of the historic measurement.
+ * @return The id
+ */
+ SoamId historyStatsId();
+
+ /**
+ * The time that the historic Measurement Interval ended.
+ * @return A java Instant
+ */
+ Instant endTime();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossAvailabilityStatHistory}.
+ */
+ public interface LaStatHistoryBuilder extends LaStatBuilder {
+ LossAvailabilityStatHistory build();
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementCreate.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementCreate.java
new file mode 100644
index 0000000..032a4bb
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementCreate.java
@@ -0,0 +1,207 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Duration;
+import java.util.Collection;
+
+import org.onosproject.incubator.net.l2monitoring.soam.MeasurementCreateBase;
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
+
+/**
+ * Object to support creation of Loss Measurement tests.
+ */
+public interface LossMeasurementCreate extends MeasurementCreateBase {
+ /**
+ * The type of Loss Measurement that will be performed.
+ * @return A loss Measurement type
+ */
+ LmType lmCfgType();
+
+ /**
+ * A vector of bits that indicates the type of SOAM LM counters found.
+ * in the current-stats and history-stats that are enabled.
+ * A present bit enables the specific SOAM LM counter. A not present bit disables the SOAM LM counter.
+ * If a particular SOAM LM counter is not supported the BIT value is not present.
+ * Not all SOAM LM counters are supported for all SOAM LM types.
+ * @return A collection of bit options
+ */
+ Collection<CounterOption> countersEnabled();
+
+ /**
+ * This object specifies the availability measurement interval.
+ * A measurement interval of 15 minutes is to be supported, other intervals can be supported
+ * @return A java Duration
+ */
+ Duration availabilityMeasurementInterval();
+
+ /**
+ * Specifies a configurable number of consecutive loss measurement PDUs.
+ * to be used in evaluating the availability/unavailability status of each
+ * availability indicator per MEF 10.2.1.
+ * Loss Measurement PDUs (LMMs, CCMs or SLMs) are sent regularly with a
+ * period defined by message-period. Therefore, this object, when multiplied
+ * by message-period, is equivalent to the Availability parameter of 'delta_t'
+ * as specified by MEF 10.2.1.
+ *
+ * If the measurement-type is lmm or ccm, this object defines the number of
+ * LMM or CCM PDUs transmitted during each 'delta_t' period. The Availability
+ * flr for a given 'delta_t' can be calculated based on the counters in the
+ * last LMM/R or CCM during this 'delta_t' and the last LMM/R or CCM in the
+ * previous 'delta_t'.
+ *
+ * If the measurement-type is slm, this object defines the number of SLM PDUs
+ * transmitted during each 'delta_t' period. The Availability flr for a
+ * given 'delta_t' is calculated based on the number of those SLM PDUs that are lost.
+ *
+ * If the measurement-type is lmm or ccm, the number range of 1 through 10
+ * must be supported. The number range of 10 through 1000000 may be supported,
+ * but is not mandatory.
+ *
+ * If the measurement-type is slm, the number range of 10 through 100 must be
+ * supported. The number range of 100 through 1000000 may be supported,
+ * but is not mandatory
+ * @return number of consecutive loss measurement PDUs
+ */
+ Integer availabilityNumberConsecutiveFlrMeasurements();
+
+ /**
+ * Specifies a configurable availability threshold to be used in evaluating
+ * the availability/unavailability status of an availability indicator per
+ * MEF 10.2.1. The availability threshold range of 0.00 (0) through 1.00 (100000)
+ * is supported. This parameter is equivalent to the Availability parameter
+ * of 'C' as specified by MEF 10.2.1.
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct availabilityFlrThreshold();
+
+ /**
+ * Specifies a configurable number of consecutive availability indicators to
+ * be used to determine a change in the availability status as indicated by
+ * MEF 10.2.1. This parameter is equivalent to the Availability parameter of
+ * 'n' as specified by MEF 10.2.1.
+ * The number range of 1 through 10 must be supported.
+ * The number range of 1 through 1000 may be supported, but is not mandatory
+ * @return number of consecutive availability indicators
+ */
+ Short availabilityNumberConsecutiveIntervals();
+
+ /**
+ * Specifies a configurable number of consecutive availability indicators.
+ * to be used for assessing CHLI. This parameter is equivalent to the
+ * Resilency parameter of 'p' as specified by MEF 10.2.1.
+ *
+ * Availability-consecutive-high-flr must be strictly less than
+ * availability-number-consecutive-intervals. If not, the count of high loss
+ * intervals over time, and the count of consecutive high loss levels, is disabled.
+ *
+ * The number range of 1 through 10 must be supported. The number range of 1
+ * through 1000 may be supported, but is not mandatory
+ * @return number of consecutive availability indicators
+ */
+ Short availabilityNumberConsecutiveHighFlr();
+
+ /**
+ * The list of Loss Measurement configuration threshold values for LM Performance Monitoring.
+ * The main purpose of the threshold configuration list is to configure
+ * threshold alarm notifications indicating that a specific performance metric
+ * is not being met
+ * @return A collection of Loss Measurement Thresholds
+ */
+ Collection<LossMeasurementThreshold> lossMeasurementThreshold();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate}.
+ */
+ public interface LmCreateBuilder extends MeasCreateBaseBuilder {
+
+ LmCreateBuilder addToCountersEnabled(CounterOption counterOption);
+
+ LmCreateBuilder availabilityMeasurementInterval(
+ Duration availabilityMeasurementInterval);
+
+ LmCreateBuilder availabilityNumberConsecutiveFlrMeasurements(
+ Integer availabilityNumberConsecutiveFlrMeasurements);
+
+ LmCreateBuilder availabilityFlrThreshold(MilliPct availabilityFlrThreshold);
+
+ LmCreateBuilder availabilityNumberConsecutiveIntervals(
+ Short availabilityNumberConsecutiveIntervals) throws SoamConfigException;
+
+ LmCreateBuilder availabilityNumberConsecutiveHighFlr(
+ Short availabilityNumberConsecutiveHighFlr) throws SoamConfigException;
+
+ LmCreateBuilder addToLossMeasurementThreshold(
+ LossMeasurementThreshold lossMeasurementThreshold);
+
+ LossMeasurementCreate build();
+ }
+
+ /**
+ * Enumerated set of Loss Measurement types.
+ */
+ public enum LmType {
+ /**
+ * LMM SOAM PDU generated and received LMR responses tracked.
+ */
+ LMLMM,
+ /**
+ * SLM SOAM PDU generated and received SLR responses tracked.
+ */
+ LMSLM,
+ /**
+ * CCM SOAM PDU generated and received CCM PDUs tracked.
+ */
+ LMCCM;
+ }
+
+ /**
+ * Options for Counters that may be enabled.
+ */
+ public enum CounterOption {
+ FORWARD_TRANSMITTED_FRAMES,
+ FORWARD_RECEIVED_FRAMES,
+ FORWARD_MIN_FLR,
+ FORWARD_MAX_FLR,
+ FORWARD_AVERAGE_FLR,
+ BACKWARD_TRANSMITTED_FRAMES,
+ BACKWARD_RECEIVED_FRAMES,
+ BACKWARD_MIN_FLR,
+ BACKWARD_MAX_FLR,
+ BACKWARD_AVERAGE_FLR,
+ SOAM_PDUS_SENT,
+ SOAM_PDUS_RECEIVED,
+ AVAILABILITY_FORWARD_HIGH_LOSS,
+ AVAILABILITY_FORWARD_CONSECUTIVE_HIGH_LOSS,
+ AVAILABILITY_FORWARD_AVAILABLE,
+ AVAILABILITY_FORWARD_UNAVAILABLE,
+ AVAILABILILITY_FORWARD_MIN_FLR,
+ AVAILABILITY_FORWARD_MAX_FLR,
+ AVAILABILITY_FORWARD_AVERAGE_FLR,
+ AVAILABILITY_BACKWARD_HIGH_LOSS,
+ AVAILABILITY_BACKWARD_CONSECUTIVE_HIGH_LOSS,
+ AVAILABILITY_BACKWARD_AVAILABLE,
+ AVAILABLE_BACKWARD_UNAVAILABLE,
+ AVAILABLE_BACKWARD_MIN_FLR,
+ AVAILABLE_BACKWARD_MAX_FLR,
+ AVAILABLE_BACKWARD_AVERAGE_FLR,
+ MEASURED_STATS_FORWARD_MEASURED_FLR,
+ MEASURED_STATS_BACKWARD_MEASURED_FLR,
+ MEASURED_STATS_AVAILABILITY_FORWARD_STATUS,
+ MEASURED_STATS_AVAILABILITY_BACKWARD_STATUS;
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementEntry.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementEntry.java
new file mode 100644
index 0000000..fb0cecb
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementEntry.java
@@ -0,0 +1,157 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Instant;
+import java.util.Collection;
+
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+
+/**
+ * A model of Loss Measurement from ITU Y.1731 Chapter 8.2, MEF 17, MEF 36.1 and MEF 39.
+ *
+ * In this model Loss Measurements entries are returned as a collection in the
+ * MepEntry. In this way Loss Measurements are created by calling on the
+ * Create Loss Measurement function, passing in any arguments needed to
+ * configure it. The Loss Measurement is a result and not configured or
+ * persisted in ONOS, but instead is is passed on to some analytics system.
+ */
+public interface LossMeasurementEntry extends LossMeasurementCreate {
+ /**
+ * Ian id that uniquely identifies a scheduled measurement.
+ * It is automatically generated by the server on creation of a new measurement
+ * @return An LM id
+ */
+ SoamId lmId();
+
+ /**
+ * Contains the Frame Loss Ratio in the forward direction calculated by this MEP.
+ * from the last received SOAM PDU.
+ * The FLR value is a ratio that is expressed as a percent with a value of
+ * 0 (ratio 0.00) through 100000 (ratio 1.00).
+ * @return Units are in milli-percent, where 1 indicates 0.001 per-cent
+ */
+ MilliPct measuredForwardFlr();
+
+ /**
+ * Contains the Frame Loss Ratio in the backward direction calculated by this MEP.
+ * from the last received SOAM PDU.
+ * The FLR value is a ratio that is expressed as a percent with a value of
+ * 0 (ratio 0.00) through 100000 (ratio 1.00).
+ * @return Units are in milli-percent, where 1 indicates 0.001 per-cent
+ */
+ MilliPct measuredBackwardFlr();
+
+ /**
+ * The availability status (the outcome of the last availability indicator) in the forward direction.
+ * based upon the last received SOAM PDU
+ * @return enumerated availability value
+ */
+ AvailabilityType measuredAvailabilityForwardStatus();
+
+ /**
+ * The availability status (the outcome of the last availability indicator) in the backward direction.
+ * based upon the last received SOAM PDU
+ * @return enumerated availability value
+ */
+ AvailabilityType measuredAvailabilityBackwardStatus();
+
+ /**
+ * The time of the last transition between available and unavailable in the forward direction.
+ * If there have been no transitions since the Loss Measurement Session was
+ * started, this is set to 0
+ * @return The transition time
+ */
+ Instant measuredForwardLastTransitionTime();
+
+ /**
+ * The time of the last transition between available and unavailable in the backward direction.
+ * If there have been no transitions since the Loss Measurement Session was
+ * started, this is set to 0
+ * @return The transition time
+ */
+ Instant measuredBackwardLastTransitionTime();
+
+ /**
+ * The results for the current Measurement Interval in a SOAM Loss Measurement session.
+ * gathered during the interval indicated by measurement-interval
+ * @return An object with current measurements
+ */
+ LossMeasurementStatCurrent measurementCurrent();
+
+ /**
+ * The results for history Measurement Intervals in a SOAM Loss Measurement session.
+ * @return An object with historic measurements
+ */
+ Collection<LossMeasurementStatHistory> measurementHistories();
+
+ /**
+ * The current results for a SOAM Loss Measurement session for availability statistics.
+ * gathered during the interval indicated by availability-measurement-interval
+ * @return An object with current availability
+ */
+ LossAvailabilityStatCurrent availabilityCurrent();
+
+ /**
+ * The results for availability history Measurement Intervals in a SOAM Loss Measurement session.
+ * @return An object with historic availability
+ */
+ Collection<LossAvailabilityStatHistory> availabilityHistories();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry}.
+ */
+ public interface LmEntryBuilder extends LmCreateBuilder {
+ LmEntryBuilder measuredForwardFlr(MilliPct measuredForwardFlr);
+
+ LmEntryBuilder measuredBackwardFlr(MilliPct measuredBackwardFlr);
+
+ LmEntryBuilder measuredAvailabilityForwardStatus(
+ AvailabilityType measuredAvailabilityForwardStatus);
+
+ LmEntryBuilder measuredAvailabilityBackwardStatus(
+ AvailabilityType measuredAvailabilityBackwardStatus);
+
+ LmEntryBuilder measuredForwardLastTransitionTime(
+ Instant measuredForwardLastTransitionTime);
+
+ LmEntryBuilder measuredBackwardLastTransitionTime(
+ Instant measuredBackwardLastTransitionTime);
+
+ LmEntryBuilder measurementCurrent(
+ LossMeasurementStatCurrent measurementCurrent);
+
+ LmEntryBuilder addToMeasurementHistories(
+ LossMeasurementStatHistory history);
+
+ LmEntryBuilder availabilityCurrent(
+ LossAvailabilityStatCurrent availabilityCurrent);
+
+ LmEntryBuilder addToAvailabilityHistories(LossAvailabilityStatHistory history);
+
+ LossMeasurementEntry build();
+ }
+
+ /**
+ * Options for Availability test types.
+ */
+ public enum AvailabilityType {
+ AVAILABLE,
+ UNAVAILABLE,
+ UNKNOWN;
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStat.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStat.java
new file mode 100644
index 0000000..f61aab5
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStat.java
@@ -0,0 +1,172 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Duration;
+
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+
+/**
+ * Abstract base interface for the creation of Loss Measurement Stat.
+ * This is the base for {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatHistory}
+ * and {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatCurrent}
+ */
+public interface LossMeasurementStat {
+ /**
+ * The time that the current Measurement Interval has been running.
+ * @return A java Duration
+ */
+ Duration elapsedTime();
+
+ /**
+ * The suspect flag for the current measurement interval in which the notification was generated.
+ * reference MEF-SOAM-PM-MIB.mefSoamPmNotificationObjSuspect";
+ * @return true if the measurement might include an error
+ */
+ boolean suspectStatus();
+
+ /**
+ * The number of frames transmitted in the forward direction by this MEP.
+ * For a PM Session of types lmm or ccm this includes Ethernet Service Frames
+ * and SOAM PDUs that are in a higher MEG level only.
+ * For a PM Session of type slm this includes the count of SOAM ETH-SLM frames only
+ * @return The number of frames
+ */
+ Long forwardTransmittedFrames();
+
+ /**
+ * The number of frames received in the forward direction by this MEP.
+ * For a PM Session of types lmm or ccm this includes Ethernet
+ * Service Frames and SOAM PDUs that are in a higher MEG level only.
+ * For a PM Session of type slm this includes the count of SOAM ETH-SLM frames only
+ * @return The number of frames received
+ */
+ Long forwardReceivedFrames();
+
+ /**
+ * The minimum one-way frame loss ratio in the forward direction calculated by this MEP for this Interval.
+ * The FLR value is a ratio that is expressed as a percent with a value of
+ * 0 (ratio 0.00) through 100000 (ratio 1.00).
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct forwardMinFrameLossRatio();
+
+ /**
+ * The maximum one-way frame loss ratio in the forward direction calculated by this MEP for this Interval.
+ * The FLR value is a ratio that is expressed as a percent with a value of
+ * 0 (ratio 0.00) through 100000 (ratio 1.00).
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct forwardMaxFrameLossRatio();
+
+ /**
+ * The average one-way frame loss ratio in the forward direction calculated by this MEP for this Interval.
+ * The FLR value is a ratio that is expressed as a percent with a value of
+ * 0 (ratio 0.00) through 100000 (ratio 1.00).
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct forwardAverageFrameLossRatio();
+
+ /**
+ * The number of frames transmitted in the backward direction by this MEP.
+ * For a PM Session of type lmm or ccm this includes Ethernet Service Frames
+ * and SOAM PDUs that are in a higher MEG level only.
+ * For a PM Session of type slm this includes the count of SOAM ETH-SLM frames only
+ * @return The number of frames
+ */
+ Long backwardTransmittedFrames();
+
+ /**
+ * The number of frames received in the backward direction by this MEP.
+ * For a PM Session of type lmm this includes Ethernet Service Frames and
+ * SOAM PDUs that are in a higher MEG level only.
+ * For a PM Session of type slm this includes the count of SOAM ETH-SLM frames only
+ * @return The number of frames
+ */
+ Long backwardReceivedFrames();
+
+ /**
+ * The minimum one-way frame loss ratio in the backward direction.
+ * calculated by this MEP for this Measurement Interval. The FLR value is a
+ * ratio that is expressed as a percent with a value of 0 (ratio 0.00)
+ * through 100000 (ratio 1.00).
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct backwardMinFrameLossRatio();
+
+ /**
+ * The maximum one-way frame loss ratio in the backward direction.
+ * calculated by this MEP for this Measurement Interval. The FLR value is a
+ * ratio that is expressed as a percent with a value of 0 (ratio 0.00)
+ * through 100000 (ratio 1.00).
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct backwardMaxFrameLossRatio();
+
+ /**
+ * The average one-way frame loss ratio in the backward direction.
+ * calculated by this MEP for this Measurement Interval. The FLR value is a
+ * ratio that is expressed as a percent with a value of 0 (ratio 0.00)
+ * through 100000 (ratio 1.00).
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct backwardAverageFrameLossRatio();
+
+ /**
+ * The count of the number of SOAM PDUs sent during this Measurement Interval.
+ * This object applies when type is lmm, slm or ccm. It indicates the number
+ * of LMM, CCM, or SLM SOAM frames transmitted
+ * @return the number of SOAM PDUs sent
+ */
+ Long soamPdusSent();
+
+ /**
+ * The count of the number of SOAM PDUs PDUs received in this Measurement Interval.
+ * This object applies when type is lmm, slm, or ccm. This object indicates
+ * the number of LMR, CCM, or SLR SOAM frames received
+ * @return the number of SOAM PDUs PDUs received
+ */
+ Long soamPdusReceived();
+
+ /**
+ * Base interface for builders of {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStat}.
+ */
+ interface LmStatBuilder {
+ LmStatBuilder forwardTransmittedFrames(Long forwardTransmittedFrames);
+
+ LmStatBuilder forwardReceivedFrames(Long forwardReceivedFrames);
+
+ LmStatBuilder forwardMinFrameLossRatio(MilliPct forwardMinFrameLossRatio);
+
+ LmStatBuilder forwardMaxFrameLossRatio(MilliPct forwardMaxFrameLossRatio);
+
+ LmStatBuilder forwardAverageFrameLossRatio(MilliPct forwardAverageFrameLossRatio);
+
+ LmStatBuilder backwardTransmittedFrames(Long backwardTransmittedFrames);
+
+ LmStatBuilder backwardReceivedFrames(Long backwardReceivedFrames);
+
+ LmStatBuilder backwardMinFrameLossRatio(MilliPct backwardMinFrameLossRatio);
+
+ LmStatBuilder backwardMaxFrameLossRatio(MilliPct backwardMaxFrameLossRatio);
+
+ LmStatBuilder backwardAverageFrameLossRatio(MilliPct backwardAverageFrameLossRatio);
+
+ LmStatBuilder soamPdusSent(Long soamPdusSent);
+
+ LmStatBuilder soamPdusReceived(Long soamPdusReceived);
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatCurrent.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatCurrent.java
new file mode 100644
index 0000000..c5b2423
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatCurrent.java
@@ -0,0 +1,37 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Instant;
+
+/**
+ * Object for representing Loss Availability Stats Current.
+ * Extends {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStat}
+ */
+public interface LossMeasurementStatCurrent extends LossMeasurementStat {
+ /**
+ * The time that the current Measurement Interval started.
+ * @return The start time as a java Instant
+ */
+ Instant startTime();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatCurrent}.
+ */
+ public interface LmStatCurrentBuilder extends LmStatBuilder {
+ LossMeasurementStatCurrent build();
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatHistory.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatHistory.java
new file mode 100644
index 0000000..90c7a5f
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatHistory.java
@@ -0,0 +1,45 @@
+/*
+ * 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.soam.loss;
+
+import java.time.Instant;
+
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+
+/**
+ * Object for representing Loss Measurement Stats History.
+ * Extends {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStat}
+ */
+public interface LossMeasurementStatHistory extends LossMeasurementStat {
+ /**
+ * The identifier of the historic measurement.
+ * @return The id
+ */
+ SoamId historyStatsId();
+
+ /**
+ * The time that the historic Measurement Interval ended.
+ * @return A java Instant
+ */
+ Instant endTime();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatHistory}.
+ */
+ public interface LmStatHistoryBuilder extends LmStatBuilder {
+ LossMeasurementStatHistory build();
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementThreshold.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementThreshold.java
new file mode 100644
index 0000000..1624204
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementThreshold.java
@@ -0,0 +1,209 @@
+/*
+ * 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.soam.loss;
+
+import java.util.Collection;
+
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+
+/**
+ * Object to support the setting of Loss Measurement Thresholds.
+ *
+ * The main purpose of the threshold configuration is to configure threshold
+ * alarm notifications indicating that a specific performance metric is not being met
+ */
+public interface LossMeasurementThreshold {
+ /**
+ * The index of the threshold number for the specific LM threshold entry.
+ * An index value of '1' needs to be supported. Other index values can also be supported
+ * @return The threshold Id
+ */
+ SoamId thresholdId();
+
+ /**
+ * A vector of bits that indicates the type of SOAM LM thresholds notifications that are enabled.
+ * A present but enables the specific SOAM LM threshold notification and
+ * when the specific counter is enabled and the threshold is crossed a
+ * notification is generated.
+ * A not present bit disables the specific SOAM LM threshold notification.
+ * If a particular SOAM LM threshold is not supported the BIT value is not present
+ * @return A collection of bit options
+ */
+ Collection<ThresholdOption> thresholds();
+
+ /**
+ * The measured forward frame loss ratio threshold value.
+ * that will be used to determine if a threshold notification is generated
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct measuredFlrForward();
+
+ /**
+ * The maximum forward frame loss ratio threshold value.
+ * that will be used to determine if a threshold notification is generated
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct maxFlrForward();
+
+ /**
+ * The average forward frame loss ratio threshold value.
+ * that will be used to determine if a threshold notification is generated
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct averageFlrForward();
+
+ /**
+ * The measured backward frame loss ratio threshold value.
+ * that will be used to determine if a threshold notification is generated
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct measuredFlrBackward();
+
+ /**
+ * The maximum backward frame loss ratio threshold value.
+ * that will be used to determine if a threshold notification is generated
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct maxFlrBackward();
+
+ /**
+ * The average backward frame loss ratio threshold value.
+ * that will be used to determine if a threshold notification is generated
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct averageFlrBackward();
+
+ /**
+ * The forward high loss threshold value.
+ * that will be used to determine if a threshold notification is generated.
+ * @return The threshold value
+ */
+ Long forwardHighLoss();
+
+ /**
+ * The consecutive forward high loss threshold value.
+ * that will be used to determine if a threshold notification is generated
+ * @return The threshold value
+ */
+ Long forwardConsecutiveHighLoss();
+
+ /**
+ * The backward high loss threshold value.
+ * that will be used to determine if a threshold notification is generated.
+ * @return The threshold value
+ */
+ Long backwardHighLoss();
+
+ /**
+ * The consecutive backward high loss threshold value.
+ * that will be used to determine if a threshold notification is generated
+ * @return The threshold value
+ */
+ Long backwardConsecutiveHighLoss();
+
+ /**
+ * The forward unavailability threshold value.
+ * that will be used to determine if a threshold notification is generated
+ * @return The threshold value
+ */
+ Long forwardUnavailableCount();
+
+ /**
+ * The forward availability/total time ratio threshold value.
+ * that will be used to determine if a threshold notification is generated
+ * if the ratio drops below the configured value.
+ * The ratio value is expressed as a percent with a value of 0 (ratio 0.00)
+ * through 100000 (ratio 1.00)
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct forwardAvailableRatio();
+
+ /**
+ * The backward unavailability threshold value.
+ * that will be used to determine if a threshold notification is generated
+ * @return The threshold value
+ */
+ Long backwardUnavailableCount();
+
+ /**
+ * The backward availability/total time ratio threshold value.
+ * that will be used to determine if a threshold notification is generated
+ * if the ratio drops below the configured value.
+ * The ratio value is expressed as a percent with a value of 0 (ratio 0.00)
+ * through 100000 (ratio 1.00)
+ * @return Units are in milli-percent, where 1 indicates 0.001 percent
+ */
+ MilliPct backwardAvailableRatio();
+
+ /**
+ * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementThreshold}.
+ */
+ public interface LmThresholdBuilder {
+
+ LmThresholdBuilder addToThreshold(ThresholdOption threshold);
+
+ LmThresholdBuilder measuredFlrForward(MilliPct measuredFlrForward);
+
+ LmThresholdBuilder maxFlrForward(MilliPct maxFlrForward);
+
+ LmThresholdBuilder averageFlrForward(MilliPct averageFlrForward);
+
+ LmThresholdBuilder measuredFlrBackward(MilliPct measuredFlrBackward);
+
+ LmThresholdBuilder maxFlrBackward(MilliPct maxFlrBackward);
+
+ LmThresholdBuilder averageFlrBackward(MilliPct averageFlrBackward);
+
+ LmThresholdBuilder forwardHighLoss(Long forwardHighLoss);
+
+ LmThresholdBuilder forwardConsecutiveHighLoss(Long forwardConsecutiveHighLoss);
+
+ LmThresholdBuilder backwardHighLoss(Long backwardHighLoss);
+
+ LmThresholdBuilder backwardConsecutiveHighLoss(Long backwardConsecutiveHighLoss);
+
+ LmThresholdBuilder forwardUnavailableCount(Long forwardUnavailableCount);
+
+ LmThresholdBuilder forwardAvailableRatio(MilliPct forwardAvailableRatio);
+
+ LmThresholdBuilder backwardUnavailableCount(Long backwardUnavailableCount);
+
+ LmThresholdBuilder backwardAvailableRatio(MilliPct backwardAvailableRatio);
+
+ LossMeasurementThreshold build();
+ }
+
+ /**
+ * Set of enumerated threshold options.
+ */
+ public enum ThresholdOption {
+ MEASURED_FLR_FORWARD,
+ MAX_FLR_FORWARD,
+ AVERAGE_FLR_FORWARD,
+ MEASURED_FLR_BACKWARD,
+ MAX_FLR_BACKWARD,
+ AVERAGE_FLR_BACKWARD,
+ FORWARD_HIGH_LOSS,
+ FORWARD_CONSECUTIVE_HIGH_LOSS,
+ BACKWARD_HIGH_LOSS,
+ BACKWARD_CONSECUTIVE_HIGH_LOSS,
+ FORWARD_UNAVAILABLE_COUNT,
+ FORWARD_AVAILABLE_RATIO,
+ BACKWARD_UNAVAILABLE_COUNT,
+ BACKWARD_AVAILABLE_RATIO;
+ }
+}
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/package-info.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/package-info.java
new file mode 100644
index 0000000..909113a
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/loss/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+/**
+ * Implementation of Service Operation and Maintenance related to Frame loss measurement.
+ *
+ * From ITU Y.1731 (ETH-DM) and MEF 17 Frame Delay Performance and Frame Delay Variation Performance
+ * MEF 36.1 Service OAM SNMP MIB for Performance Monitoring, MEF 39 Service OAM Performance Monitoring YANG Module
+ */
+package org.onosproject.incubator.net.l2monitoring.soam.loss;
\ No newline at end of file
diff --git a/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/package-info.java b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/package-info.java
new file mode 100644
index 0000000..a718c8b
--- /dev/null
+++ b/apps/cfm/api/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Implementation of MEF Service Operation and Maintenance.
+ */
+package org.onosproject.incubator.net.l2monitoring.soam;
\ No newline at end of file
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/ComponentTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/ComponentTest.java
new file mode 100644
index 0000000..cd71911
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/ComponentTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.VlanId;
+import org.onosproject.incubator.net.l2monitoring.cfm.Component.IdPermissionType;
+import org.onosproject.incubator.net.l2monitoring.cfm.Component.MhfCreationType;
+
+public class ComponentTest {
+ Component c1;
+
+ @Before
+ public void setUp() throws Exception {
+ c1 = DefaultComponent.builder(1)
+ .idPermission(IdPermissionType.MANAGE)
+ .mhfCreationType(MhfCreationType.EXPLICIT)
+ .addToVidList(VlanId.vlanId((short) 1))
+ .addToVidList(VlanId.vlanId((short) 2))
+ .addToVidList(VlanId.vlanId((short) 3))
+ .build();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testComponentId() {
+ assertEquals(1, c1.componentId());
+ }
+
+ @Test
+ public void testVidList() {
+ assertEquals(3, c1.vidList().size());
+ }
+
+ @Test
+ public void testMhfCreationType() {
+ assertEquals(MhfCreationType.EXPLICIT, c1.mhfCreationType());
+ }
+
+ @Test
+ public void testIdPermission() {
+ assertEquals(IdPermissionType.MANAGE, c1.idPermission());
+ }
+
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceAssociationTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceAssociationTest.java
new file mode 100644
index 0000000..68716dd
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceAssociationTest.java
@@ -0,0 +1,136 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation.CcmInterval;
+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.MaIdPrimaryVid;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdRfc2685VpnId;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+
+public class MaintenanceAssociationTest {
+
+ MaintenanceAssociation ma1;
+ MaintenanceAssociation ma2;
+ MaintenanceAssociation ma3;
+ MaintenanceAssociation ma4;
+ MaintenanceAssociation ma5;
+
+ @Before
+ public void setUp() throws Exception {
+ try {
+ ma1 = DefaultMaintenanceAssociation.builder(MaIdCharStr.asMaId("ma-1"), 10)
+ .ccmInterval(CcmInterval.INTERVAL_1MIN)
+ .maNumericId((short) 1)
+ .build();
+
+ ma2 = DefaultMaintenanceAssociation.builder(MaIdPrimaryVid.asMaId("1024"), 10)
+ .build();
+
+ ma3 = DefaultMaintenanceAssociation.builder(MaId2Octet.asMaId("33333"), 10)
+ .build();
+
+ ma4 = DefaultMaintenanceAssociation.builder(MaIdRfc2685VpnId
+ .asMaIdHex("0A:0B:0C:0D:0E:0F:00"), 10).build();
+
+ } catch (CfmConfigException e) {
+ throw new Exception(e);
+ }
+ }
+
+ @Test
+ public void testMaName() {
+ assertEquals("ma-1", ma1.maId().maName());
+
+ assertEquals("1024", ma2.maId().maName());
+
+ assertEquals("33333", ma3.maId().maName());
+
+ assertEquals("0A:0B:0C:0D:0E:0F:00".toLowerCase(), ma4.maId().maName());
+ }
+
+ @Test
+ public void testCcmInterval() {
+ assertEquals(CcmInterval.INTERVAL_1MIN, ma1.ccmInterval());
+ }
+
+ @Test
+ public void testComponentList() {
+ assertNotNull(ma1.componentList());
+ }
+
+ @Test
+ public void testWithComponentList() {
+ Collection<Component> componentList2 = new ArrayList<>();
+ MaintenanceAssociation ma2 = ma1.withComponentList(componentList2);
+ assertNotNull(ma2.componentList());
+ }
+
+ @Test
+ public void testRemoteMepIdList() {
+ assertNotNull(ma1.remoteMepIdList());
+ }
+
+ @Test
+ public void testWithRemoteMepIdList() throws CfmConfigException {
+ Collection<MepId> remoteMepIdList2 = new ArrayList<>();
+ remoteMepIdList2.add(MepId.valueOf((short) 450));
+ remoteMepIdList2.add(MepId.valueOf((short) 451));
+ remoteMepIdList2.add(MepId.valueOf((short) 452));
+ MaintenanceAssociation ma2 = ma1.withRemoteMepIdList(remoteMepIdList2);
+ assertEquals(3, ma2.remoteMepIdList().size());
+ }
+
+ @Test
+ public void testMaNumericId() {
+ assertEquals(1, ma1.maNumericId());
+ }
+
+ @Test
+ public void testCopyThroughBuilder() throws CfmConfigException {
+ MaintenanceAssociation maCopy =
+ DefaultMaintenanceAssociation.builder(ma3).build();
+ assertEquals(ma3, maCopy);
+ }
+
+ @Test
+ public void testEquals() {
+ //For char string
+ assertFalse(ma1.equals(null));
+ assertFalse(ma1.equals(new String("test")));
+
+ assertTrue(ma1.equals(ma1));
+ assertFalse(ma1.equals(ma2));
+ }
+
+ @Test
+ public void testHashCode() {
+ assertEquals(ma1.hashCode(), ma1.hashCode());
+ }
+
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceDomainTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceDomainTest.java
new file mode 100644
index 0000000..74e076c
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceDomainTest.java
@@ -0,0 +1,153 @@
+/*
+ * 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;
+
+import java.util.Collection;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain.MdLevel;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr;
+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.service.CfmConfigException;
+
+import static org.junit.Assert.*;
+
+public class MaintenanceDomainTest {
+
+ MaintenanceDomain md1;
+ MaintenanceDomain md2;
+ MaintenanceDomain md3;
+ MaintenanceDomain md4;
+
+ @Before
+ public void setUp() {
+
+ try {
+ MaintenanceAssociation ma1 =
+ DefaultMaintenanceAssociation
+ .builder(MaIdCharStr.asMaId("ma-1-1"), 4)
+ .build();
+
+ md1 = DefaultMaintenanceDomain.builder(MdIdCharStr.asMdId("md-1"))
+ .mdLevel(MdLevel.LEVEL3)
+ .addToMaList(ma1)
+ .mdNumericId((short) 1)
+ .build();
+
+ md2 = DefaultMaintenanceDomain.builder(MdIdDomainName.asMdId("test1.onosproject.org"))
+ .mdLevel(MdLevel.LEVEL4)
+ .build();
+
+ md3 = DefaultMaintenanceDomain.builder(MdIdMacUint.asMdId("00:11:22:33:44:55:8191"))
+ .mdLevel(MdLevel.LEVEL5)
+ .build();
+
+ md4 = DefaultMaintenanceDomain.builder(MdIdNone.asMdId())
+ .build();
+
+ } catch (CfmConfigException e) {
+ fail("Unexpected exception " + e.getMessage());
+ }
+ }
+
+ @Test
+ public void testMdNameType() {
+ assertEquals("md-1", md1.mdId().mdName());
+ assertEquals(MdIdCharStr.class, md1.mdId().getClass());
+ assertEquals(4, md1.mdId().getNameLength());
+
+ assertEquals("test1.onosproject.org", md2.mdId().mdName());
+ assertEquals(MdIdDomainName.class, md2.mdId().getClass());
+ assertEquals(21, md2.mdId().getNameLength());
+
+ assertEquals("00:11:22:33:44:55:8191", md3.mdId().mdName());
+ assertEquals(MdIdMacUint.class, md3.mdId().getClass());
+ assertEquals(8, md3.mdId().getNameLength());
+
+ assertEquals(null, md4.mdId().mdName());
+ assertEquals(MdIdNone.class, md4.mdId().getClass());
+ assertEquals(0, md4.mdId().getNameLength());
+ }
+
+ @Test
+ public void testMdLevel() {
+ assertEquals(MdLevel.LEVEL3, md1.mdLevel());
+ assertEquals(MdLevel.LEVEL4, md2.mdLevel());
+ assertEquals(MdLevel.LEVEL5, md3.mdLevel());
+ assertEquals(MdLevel.LEVEL0, md4.mdLevel());
+ }
+
+ @Test
+ public void testMaintenanceAssociationList() {
+ assertEquals(1, md1.maintenanceAssociationList().size());
+
+ assertEquals(0, md2.maintenanceAssociationList().size());
+ }
+
+ @Test
+ public void testWithMaintenanceAssociationList() throws CfmConfigException {
+ Collection<MaintenanceAssociation> maList = md1.maintenanceAssociationList();
+ maList.add(DefaultMaintenanceAssociation
+ .builder(MaIdCharStr.asMaId("ma-1-2"), 4)
+ .build());
+
+ md1 = md1.withMaintenanceAssociationList(maList);
+ assertEquals(2, md1.maintenanceAssociationList().size());
+ }
+
+ @Test
+ public void testMdNumericid() throws CfmConfigException {
+ assertEquals(1, md1.mdNumericId());
+ }
+
+ @Test
+ public void testEquals() throws CfmConfigException {
+ assertFalse(md1.equals(md2));
+
+ assertFalse(md1.equals(null));
+
+ assertFalse(md1.equals(new String("test")));
+ }
+
+ @Test
+ public void testHashCode() throws CfmConfigException {
+ assertFalse(md1.hashCode() == md2.hashCode());
+
+ assertTrue(md1.hashCode() == md1.hashCode());
+ }
+
+ @Test
+ public void testCopyToBuilder() throws CfmConfigException {
+ MaintenanceDomain mdCopy = DefaultMaintenanceDomain.builder(md1).build();
+
+ assertEquals(md1, mdCopy);
+ }
+
+ @Test
+ public void testToString() {
+ assertEquals("DefaultMaintenanceDomain{mdId=md-1, level=LEVEL3}",
+ md1.toString());
+ assertEquals("DefaultMaintenanceDomain{mdId=test1.onosproject.org, level=LEVEL4}",
+ md2.toString());
+ assertEquals("DefaultMaintenanceDomain{mdId=00:11:22:33:44:55:8191, level=LEVEL5}",
+ md3.toString());
+ assertEquals("DefaultMaintenanceDomain{mdId=, level=LEVEL0}", md4.toString());
+ }
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbCreateTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbCreateTest.java
new file mode 100644
index 0000000..e415a84
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbCreateTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.MacAddress;
+import org.onlab.util.HexString;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+
+public class MepLbCreateTest {
+
+ MepLbCreate lb1;
+ MepLbCreate lb2;
+
+ @Before
+ public void setUp() throws Exception {
+ lb1 = DefaultMepLbCreate
+ .builder(MacAddress.valueOf("aa:bb:cc:dd:ee:ff"))
+ .numberMessages(5)
+ .dataTlv(new byte[]{0x01, 0x02, 0x03, 0x04, 0x05, 0x06})
+ .vlanPriority(Priority.PRIO3)
+ .vlanDropEligible(true)
+ .build();
+ lb2 = DefaultMepLbCreate
+ .builder(MepId.valueOf((short) 12))
+ .build();
+
+ }
+
+ @Test
+ public void testRemoteMepAddress() {
+ assertEquals("aa:bb:cc:dd:ee:ff".toUpperCase(),
+ lb1.remoteMepAddress().toString());
+ assertNull(lb1.remoteMepId());
+ }
+
+ @Test
+ public void testRemoteMepId() {
+ assertEquals(12, lb2.remoteMepId().id().intValue());
+ assertNull(lb2.remoteMepAddress());
+ }
+
+ @Test
+ public void testNumberMessages() {
+ assertEquals(5, lb1.numberMessages().intValue());
+ }
+
+ @Test
+ public void testDataTlv() {
+ assertEquals(0x06, HexString.fromHexString(lb1.dataTlvHex())[5]);
+ }
+
+ @Test
+ public void testVlanPriority() {
+ assertEquals(3, lb1.vlanPriority().ordinal());
+ }
+
+ @Test
+ public void testVlanDropElegible() {
+ assertEquals(true, lb1.vlanDropEligible());
+ }
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbEntryTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbEntryTest.java
new file mode 100644
index 0000000..47ef5b3
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbEntryTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class MepLbEntryTest {
+
+ MepLbEntry lbResult;
+
+ @Before
+ public void setUp() throws Exception {
+ lbResult = DefaultMepLbEntry.builder()
+ .countLbrMacMisMatch(987654321L)
+ .countLbrReceived(987654322L)
+ .countLbrTransmitted(987654323L)
+ .countLbrValidInOrder(987654324L)
+ .countLbrValidOutOfOrder(987654325L)
+ .nextLbmIdentifier(987654326L)
+ .build();
+ }
+
+ @Test
+ public void testNextLbmIdentifier() {
+ assertEquals(987654326L, lbResult.nextLbmIdentifier());
+ }
+
+ @Test
+ public void testCountLbrTransmitted() {
+ assertEquals(987654323L, lbResult.countLbrTransmitted());
+ }
+
+ @Test
+ public void testCountLbrReceived() {
+ assertEquals(987654322L, lbResult.countLbrReceived());
+ }
+
+ @Test
+ public void testCountLbrValidInOrder() {
+ assertEquals(987654324L, lbResult.countLbrValidInOrder());
+ }
+
+ @Test
+ public void testCountLbrValidOutOfOrder() {
+ assertEquals(987654325L, lbResult.countLbrValidOutOfOrder());
+ }
+
+ @Test
+ public void testCountLbrMacMisMatch() {
+ assertEquals(987654321L, lbResult.countLbrMacMisMatch());
+ }
+
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepTest.java
new file mode 100644
index 0000000..eee1f97
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepTest.java
@@ -0,0 +1,275 @@
+/*
+ * 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;
+
+import java.time.Duration;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.VlanId;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep.DefaultMepBuilder;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.FngAddress;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.FngAddressType;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.LowestFaultDefect;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.MepDirection;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+
+import static org.junit.Assert.*;
+
+public class MepTest {
+ private Mep mep1;
+
+ @Before
+ public void setUp() throws Exception {
+ try {
+ mep1 = DefaultMep.builder(MepId.valueOf((short) 1),
+ DeviceId.deviceId("of:12345678"),
+ PortNumber.portNumber(0),
+ MepDirection.UP_MEP,
+ MdIdCharStr.asMdId("md-1"),
+ MaIdCharStr.asMaId("ma-1-1"))
+ .primaryVid(VlanId.vlanId((short) 1000))
+ .administrativeState(true)
+ .cciEnabled(true)
+ .ccmLtmPriority(Priority.PRIO6)
+ .fngAddress(FngAddress.ipV4Address(IpAddress.valueOf("10.2.3.1")))
+ .lowestFaultPriorityDefect(LowestFaultDefect.ERROR_FD_PLUS)
+ .defectPresentTime(Duration.ofSeconds(1))
+ .defectAbsentTime(Duration.ofSeconds(2))
+ .build();
+ } catch (CfmConfigException e) {
+ throw new Exception(e);
+ }
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testPortError() {
+ try {
+ DefaultMep.builder(MepId.valueOf((short) 1),
+ DeviceId.deviceId("of:12345678"),
+ PortNumber.FLOOD,
+ MepDirection.UP_MEP,
+ MdIdCharStr.asMdId("md-1"),
+ MaIdCharStr.asMaId("ma-1-1"))
+ .build();
+ fail("Port = FLOOD should throw exception");
+ } catch (CfmConfigException e) {
+ assertTrue(e.getMessage().contains("Port must be physical"));
+ }
+ }
+
+ @Test
+ public void testMdNameErrorNull() {
+ try {
+ DefaultMep.builder(MepId.valueOf((short) 1),
+ DeviceId.deviceId("of:12345678"),
+ PortNumber.portNumber(0),
+ MepDirection.UP_MEP,
+ null,
+ MaIdCharStr.asMaId("ma-1-1"))
+ .build();
+ fail("Null md Name should throw exception");
+ } catch (CfmConfigException e) {
+ assertTrue(e.getMessage().contains("MdId is null"));
+ }
+ }
+
+ @Test
+ public void testMaNameErrorNull() {
+ try {
+ DefaultMep.builder(MepId.valueOf((short) 1),
+ DeviceId.deviceId("of:12345678"),
+ PortNumber.portNumber(0),
+ MepDirection.UP_MEP,
+ MdIdCharStr.asMdId("md-1"),
+ null)
+ .build();
+ fail("Null ma Name should throw exception");
+ } catch (CfmConfigException e) {
+ assertTrue(e.getMessage().contains("MaId is null"));
+ }
+ }
+
+ @Test
+ public void testMepCopyConstructor() throws CfmConfigException {
+ Mep mep2 = (new DefaultMepBuilder(mep1)).build();
+ assertEquals(1, mep2.mepId().value());
+ assertEquals("md-1", mep2.mdId().mdName());
+ }
+
+ @Test
+ public void testMepId() {
+ assertEquals(1, mep1.mepId().value());
+ }
+
+ @Test
+ public void testDeviceId() {
+ assertEquals("of:12345678", mep1.deviceId().toString());
+ }
+
+ @Test
+ public void testPort() {
+ assertEquals(0, mep1.port().toLong());
+ }
+
+ @Test
+ public void testDirection() {
+ assertEquals(MepDirection.UP_MEP, mep1.direction());
+ }
+
+ @Test
+ public void testPrimaryVid() {
+ assertEquals(1000, mep1.primaryVid().id().intValue());
+ }
+
+ @Test
+ public void testAdministrativeState() {
+ assertTrue(mep1.administrativeState());
+ }
+
+ @Test
+ public void testWithAdministrativeState() {
+ Mep mep2 = mep1.withAdministrativeState(false);
+ assertFalse(mep2.administrativeState());
+ assertEquals(1, mep2.mepId().value());
+ }
+
+ @Test
+ public void testCciEnabled() {
+ assertTrue(mep1.cciEnabled());
+ }
+
+ @Test
+ public void testWithCciEnabled() {
+ Mep mep2 = mep1.withCciEnabled(false);
+ assertFalse(mep2.cciEnabled());
+ }
+
+ @Test
+ public void testCcmLtmPriority() {
+ assertEquals(6, mep1.ccmLtmPriority().ordinal());
+ }
+
+ @Test
+ public void testWithCcmLtmPriority() throws CfmConfigException {
+ Mep mep2 = mep1.withCcmLtmPriority(Priority.PRIO5);
+ assertEquals(5, mep2.ccmLtmPriority().ordinal());
+ assertEquals(1, mep2.mepId().value());
+ }
+
+ @Test
+ public void testWithFngAddress() {
+ Mep mep2 = mep1.withFngAddress(FngAddress.ipV4Address(IpAddress.valueOf("10.2.3.2")));
+ assertEquals(FngAddressType.IPV4, mep2.fngAddress().addressType());
+ assertEquals(IpAddress.valueOf("10.2.3.2"), mep2.fngAddress().ipAddress());
+ }
+
+ @Test
+ public void testFngAddress() {
+ assertEquals(FngAddressType.IPV4, mep1.fngAddress().addressType());
+ assertEquals(IpAddress.valueOf("10.2.3.1"), mep1.fngAddress().ipAddress());
+ }
+
+ @Test
+ public void testLowestFaultPriorityDefect() {
+ assertEquals(LowestFaultDefect.ERROR_FD_PLUS, mep1.lowestFaultPriorityDefect());
+ }
+
+ @Test
+ public void testWithLowestFaultPriorityDefect() {
+ Mep mep2 = mep1.withLowestFaultPriorityDefect(LowestFaultDefect.XCON_FD_ONLY);
+ assertEquals(LowestFaultDefect.XCON_FD_ONLY, mep2.lowestFaultPriorityDefect());
+ }
+
+ @Test
+ public void testDefectPresetTime() {
+ assertEquals(1000, mep1.defectPresentTime().toMillis());
+ }
+
+ @Test
+ public void testWithDefectPresentTime() {
+ Mep mep2 = mep1.withDefectPresentTime(Duration.ofMillis(1500L));
+ assertEquals(1500, mep2.defectPresentTime().toMillis());
+ }
+
+ @Test
+ public void testDefectAbsentTime() {
+ assertEquals(2000, mep1.defectAbsentTime().toMillis());
+ }
+
+ @Test
+ public void testWithDefectAbsentTime() {
+ Mep mep2 = mep1.withDefectAbsentTime(Duration.ofMillis(2500L));
+ assertEquals(2500, mep2.defectAbsentTime().toMillis());
+ }
+
+ @Test
+ public void testEqualsObject() throws CfmConfigException {
+ Mep mep2 = mep1.withPrimaryVid(VlanId.vlanId((short) 5));
+ assertNotEquals(mep1, mep2);
+ }
+
+ @Test
+ public void testMepToString() {
+ assertEquals(mep1.toString(), "DefaultMep{" +
+ "mepId=1, " +
+ "deviceId=of:12345678, " +
+ "port=0, " +
+ "direction=UP_MEP, " +
+ "mdId=md-1, " +
+ "maId=ma-1-1, " +
+ "primaryVid=1000, " +
+ "administrativeState=true, " +
+ "cciEnabled=true, " +
+ "ccmLtmPriority=PRIO6, " +
+ "fngAddress=FngAddress{addressType=IPV4, ipAddress=10.2.3.1}, " +
+ "lowestFaultPriorityDefect=ERROR_FD_PLUS, " +
+ "defectPresentTime=PT1S, " +
+ "defectAbsentTime=PT2S}");
+ }
+
+ @Test
+ public void testEquality() throws CfmConfigException {
+ assertFalse(mep1.equals(null));
+ assertTrue(mep1.equals(mep1));
+ assertFalse(mep1.equals(new String("test")));
+
+ Mep mep2 = new DefaultMepBuilder(mep1).build();
+ assertTrue(mep1.equals(mep2));
+ assertEquals(mep1.hashCode(), mep2.hashCode());
+
+ Mep mep3 = DefaultMep.builder(MepId.valueOf((short) 2),
+ DeviceId.deviceId("of:12345680"),
+ PortNumber.portNumber(0),
+ MepDirection.UP_MEP,
+ MdIdCharStr.asMdId("md-3"),
+ MaIdCharStr.asMaId("ma-3-3"))
+ .build();
+ assertFalse(mep1.equals(mep3));
+ }
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/RemoteMepEntryTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/RemoteMepEntryTest.java
new file mode 100644
index 0000000..9ec1029
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/RemoteMepEntryTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+
+import java.time.Duration;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.MacAddress;
+import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.InterfaceStatusTlvType;
+import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.PortStatusTlvType;
+import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.RemoteMepState;
+import org.onosproject.incubator.net.l2monitoring.cfm.SenderIdTlv.SenderIdTlvType;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+
+public class RemoteMepEntryTest {
+
+ RemoteMepEntry rmep1;
+
+ @Before
+ public void setUp() throws Exception, CfmConfigException {
+ rmep1 = DefaultRemoteMepEntry
+ .builder(MepId.valueOf((short) 1), RemoteMepState.RMEP_IDLE)
+ .failedOrOkTime(Duration.ofSeconds(5))
+ .macAddress(MacAddress.valueOf("AA:BB:CC:DD:EE:FF"))
+ .rdi(true)
+ .portStatusTlvType(PortStatusTlvType.PS_UP)
+ .interfaceStatusTlvType(InterfaceStatusTlvType.IS_UP)
+ .senderIdTlvType(SenderIdTlvType.SI_MAC_ADDRESS)
+ .build();
+ }
+
+ @Test
+ public void testRemoteMepId() {
+ assertEquals(1, rmep1.remoteMepId().value());
+ }
+
+ @Test
+ public void testState() {
+ assertEquals(RemoteMepState.RMEP_IDLE, rmep1.state());
+ }
+
+ @Test
+ public void testFailedOrOkTime() {
+ assertEquals(5, rmep1.failedOrOkTime().getSeconds());
+ }
+
+ @Test
+ public void testMacAddress() {
+ assertEquals("AA:BB:CC:DD:EE:FF", rmep1.macAddress().toString());
+ }
+
+ @Test
+ public void testRdi() {
+ assertEquals(true, rmep1.rdi());
+ }
+
+ @Test
+ public void testPortStatusTlvType() {
+ assertEquals(PortStatusTlvType.PS_UP, rmep1.portStatusTlvType());
+ }
+
+ @Test
+ public void testInterfaceStatusTlvType() {
+ assertEquals(InterfaceStatusTlvType.IS_UP, rmep1.interfaceStatusTlvType());
+ }
+
+ @Test
+ public void testSenderIdTlvType() {
+ assertEquals(SenderIdTlvType.SI_MAC_ADDRESS, rmep1.senderIdTlvType());
+ }
+
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdShortTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdShortTest.java
new file mode 100644
index 0000000..970e6a0
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdShortTest.java
@@ -0,0 +1,207 @@
+/*
+ * 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.identifier;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+
+public class MaIdShortTest {
+
+ MaIdShort maId1;
+ MaIdShort maId2;
+ MaIdShort maId3;
+ MaIdShort maId4;
+ MaIdShort maId5;
+
+ @Before
+ public void setUp() throws Exception, CfmConfigException {
+ maId1 = MaIdCharStr.asMaId("ma-1-1");
+ maId2 = MaIdPrimaryVid.asMaId((short) 1234);
+ maId3 = MaId2Octet.asMaId(33333);
+ maId4 = MaIdRfc2685VpnId.asMaIdHex("aa:BB:cc:DD:ee:ff:11");
+ maId5 = MaIdIccY1731.asMaId("ABC", "DEFGHIJK");
+ }
+
+ @Test
+ public void testMaName() {
+ assertEquals("ma-1-1", maId1.maName());
+ assertEquals("1234", maId2.maName());
+ assertEquals("33333", maId3.maName());
+ assertEquals("aa:BB:cc:DD:ee:ff:11".toLowerCase(), maId4.maName());
+ assertEquals("ABCDEFGHIJK", maId5.maName());
+ }
+
+ @Test
+ public void testGetNameLength() {
+ assertEquals(6, maId1.getNameLength());
+ assertEquals(2, maId2.getNameLength());
+ assertEquals(2, maId3.getNameLength());
+ assertEquals(7, maId4.getNameLength());
+ assertEquals(11, maId5.getNameLength());
+ }
+
+ @Test
+ public void testMaNameWrong() {
+ try {
+ MaIdCharStr.asMaId(null);
+ fail("Expected exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MA Name must follow pattern"));
+ }
+
+ try {
+ MaIdCharStr.asMaId("");
+ fail("Expected exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MA Name must follow pattern"));
+ }
+
+ try {
+ MaIdCharStr.asMaId("This is a name with spaces - not allowed");
+ fail("Expected exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MA Name must follow pattern"));
+ }
+
+ try {
+ MaIdCharStr.asMaId("This-name-is-too-long-at-forty-eight-characters-in-total");
+ fail("Expected exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MA Name must follow pattern"));
+ }
+
+
+ try {
+ MaIdPrimaryVid.asMaId("abcdef");
+ fail("Expected exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MA Name must be numeric"));
+ }
+
+ try {
+ MaIdPrimaryVid.asMaId("-20");
+ fail("Expected exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MA Id must be between 0 and 4095"));
+ }
+
+ try {
+ MaIdPrimaryVid.asMaId("5000");
+ fail("Expected exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MA Id must be between 0 and 4095"));
+ }
+
+
+ try {
+ MaId2Octet.asMaId("abcdef");
+ fail("Expected exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MA Name must be numeric"));
+ }
+
+ try {
+ MaId2Octet.asMaId("-20");
+ fail("Expected exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MA Id must be between 0 and 65535"));
+ }
+
+ try {
+ MaId2Octet.asMaId("70000");
+ fail("Expected exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MA Id must be between 0 and 65535"));
+ }
+
+
+ try {
+ MaIdRfc2685VpnId.asMaIdHex("aa:bb:cc:dd:ee:ff"); //Need 7
+ fail("Expected exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MA Name must follow pattern"));
+ }
+
+ try {
+ MaIdIccY1731.asMaId("ABCDEFG", "HIJKL"); //7 too long for ICC
+ fail("Expected exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("ICC part must follow pattern"));
+ }
+
+ try {
+ MaIdIccY1731.asMaId("A", "BCDEFGHIJKLMNO"); //14 too long for UMC
+ fail("Expected exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("UMC part must follow pattern"));
+ }
+
+ }
+
+ @Test
+ public void testEquals() {
+ //For char string
+ assertFalse(maId1.equals(null));
+ assertFalse(maId1.equals(new String("test")));
+
+ assertTrue(maId1.equals(maId1));
+ assertFalse(maId1.equals(maId2));
+
+ //For primary vid
+ assertFalse(maId2.equals(null));
+ assertFalse(maId2.equals(new String("test")));
+
+ assertTrue(maId2.equals(maId2));
+ assertFalse(maId2.equals(maId1));
+
+ //For 2 octet
+ assertFalse(maId3.equals(null));
+ assertFalse(maId3.equals(new String("test")));
+
+ assertTrue(maId3.equals(maId3));
+ assertFalse(maId3.equals(maId1));
+
+ //rfc2685vpn
+ assertFalse(maId4.equals(null));
+ assertFalse(maId4.equals(new String("test")));
+
+ assertTrue(maId4.equals(maId4));
+ assertFalse(maId4.equals(maId1));
+
+
+ //ICC-Y1731
+ assertFalse(maId5.equals(null));
+ assertFalse(maId5.equals(new String("test")));
+
+ assertTrue(maId5.equals(maId5));
+ assertFalse(maId5.equals(maId1));
+}
+
+ @Test
+ public void testHashCode() {
+ assertEquals(maId1.hashCode(), maId1.hashCode());
+ assertEquals(maId2.hashCode(), maId2.hashCode());
+ assertEquals(maId3.hashCode(), maId3.hashCode());
+ assertEquals(maId4.hashCode(), maId4.hashCode());
+ assertEquals(maId5.hashCode(), maId5.hashCode());
+ }
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdTest.java
new file mode 100644
index 0000000..18af6b6
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdTest.java
@@ -0,0 +1,170 @@
+/*
+ * 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.identifier;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.MacAddress;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+
+import com.google.common.net.InternetDomainName;
+
+public class MdIdTest {
+
+ MdId mdId1;
+ MdId mdId2;
+ MdId mdId3;
+ MdId mdId4;
+
+ @Before
+ public void setUp() throws Exception, CfmConfigException {
+ mdId1 = MdIdCharStr.asMdId("md-1");
+ mdId2 = MdIdDomainName.asMdId("md.domain.tld");
+ mdId3 = MdIdMacUint.asMdId(MacAddress.valueOf("AA:BB:cc:dd:ee:ff"), 54321);
+ mdId4 = MdIdNone.asMdId();
+ }
+
+ @Test
+ public void testMdNameWrong() {
+
+ try {
+ MdIdCharStr.asMdId("");
+ fail("Expected an exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MD Name must follow pattern"));
+ }
+
+ try {
+ MdIdCharStr.asMdId("name with spaces and other stuff");
+ fail("Expected an exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MD Name must follow pattern"));
+ }
+
+ try {
+ MdIdCharStr.asMdId("NameIsTooLongItShouldNotExceedFortyFiveCharacters");
+ fail("Expected an exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MD Name must follow pattern"));
+ }
+
+ try {
+ MdIdCharStr.asMdId(null);
+ fail("Expected an exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MD Name must follow pattern"));
+ }
+
+
+ try {
+ MdIdDomainName.asMdId((String) null);
+ fail("Expected an exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MD Name must follow internet domain"));
+ }
+
+ try {
+ MdIdDomainName.asMdId("name with spaces");
+ fail("Expected an exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MD Name must follow internet domain"));
+ }
+
+ try {
+ MdIdDomainName.asMdId(InternetDomainName
+ .from("a.really.long.domain.name.which.is.more.than.45.chars.long"));
+ fail("Expected an exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MD Domain Name must be between 1 and 45 chars long"));
+ }
+
+ try {
+ MdIdMacUint.asMdId("AA:BB:cc:dd:ee:ff:70000");
+ fail("Expected an exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("uInt must be between 0 and 65535"));
+ }
+
+ try {
+ MdIdMacUint.asMdId("something:12345");
+ fail("Expected an exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("MD Name must follow pattern"));
+ }
+}
+
+ @Test
+ public void testMdName() {
+ assertEquals("md-1", mdId1.mdName());
+ assertEquals("md.domain.tld", mdId2.mdName());
+ assertEquals("AA:BB:cc:dd:ee:ff:54321".toUpperCase(), mdId3.mdName());
+ assertNull(mdId4.mdName());
+ }
+
+ @Test
+ public void testGetNameLength() {
+ assertEquals(4, mdId1.getNameLength());
+ assertEquals(13, mdId2.getNameLength());
+ assertEquals(8, mdId3.getNameLength());
+ assertEquals(0, mdId4.getNameLength());
+ }
+
+ @Test
+ public void testEquals() {
+ //For char string
+ assertFalse(mdId1.equals(null));
+ assertFalse(mdId1.equals(new String("test")));
+
+ assertTrue(mdId1.equals(mdId1));
+ assertFalse(mdId1.equals(mdId2));
+
+ //For DomainName
+ assertFalse(mdId2.equals(null));
+ assertFalse(mdId2.equals(new String("test")));
+
+ assertTrue(mdId2.equals(mdId2));
+ assertFalse(mdId2.equals(mdId1));
+
+ //For MacUint
+ assertFalse(mdId3.equals(null));
+ assertFalse(mdId3.equals(new String("test")));
+
+ assertTrue(mdId3.equals(mdId3));
+ assertFalse(mdId3.equals(mdId1));
+
+ //For None
+ assertFalse(mdId4.equals(null));
+ assertFalse(mdId4.equals(new String("test")));
+
+ assertTrue(mdId4.equals(mdId4));
+ assertFalse(mdId4.equals(mdId1));
+
+ }
+
+ @Test
+ public void testHashCode() {
+ assertEquals(mdId1.hashCode(), mdId1.hashCode());
+ assertEquals(mdId2.hashCode(), mdId2.hashCode());
+ assertEquals(mdId3.hashCode(), mdId3.hashCode());
+ assertEquals(mdId4.hashCode(), mdId4.hashCode());
+ }
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MepIdTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MepIdTest.java
new file mode 100644
index 0000000..ed11e39
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MepIdTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.identifier;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+public class MepIdTest {
+ @Test
+ public void testLowRange() {
+ try {
+ MepId.valueOf((short) -1);
+ fail("Exception expected for MepId = -1");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("Invalid value for Mep Id"));
+ }
+
+ try {
+ MepId.valueOf((short) 0);
+ fail("Exception expected for MepId = 0");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("Invalid value for Mep Id"));
+ }
+ }
+
+ @Test
+ public void testHighRange() {
+ try {
+ MepId.valueOf((short) 8192);
+ fail("Exception expected for MepId = 8192");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("Invalid value for Mep Id"));
+ }
+
+ try {
+ MepId.valueOf((short) 33333); //Above the range of short
+ fail("Exception expected for MepId = 33333");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("Invalid value for Mep Id"));
+ }
+ }
+
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/MilliPctTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/MilliPctTest.java
new file mode 100644
index 0000000..e51a761
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/MilliPctTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.soam;
+
+import static org.junit.Assert.assertEquals;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+
+import org.junit.Test;
+
+public class MilliPctTest {
+
+ @Test
+ public void testIntValue() {
+ assertEquals(100, MilliPct.ofMilliPct(100).intValue());
+ assertEquals(-100, MilliPct.ofMilliPct(-100).intValue());
+ }
+
+ @Test
+ public void testLongValue() {
+ assertEquals(100, MilliPct.ofMilliPct(100).longValue());
+ assertEquals(-100, MilliPct.ofMilliPct(-100).longValue());
+ }
+
+ @Test
+ public void testFloatValue() {
+ assertEquals(100f, MilliPct.ofMilliPct(100).floatValue(), 0.0001f);
+ assertEquals(-100f, MilliPct.ofMilliPct(-100).floatValue(), 0.0001f);
+ }
+
+ @Test
+ public void testDoubleValue() {
+ assertEquals(100f, MilliPct.ofMilliPct(100).doubleValue(), 0.0001f);
+ assertEquals(-100f, MilliPct.ofMilliPct(-100).doubleValue(), 0.0001f);
+ }
+
+ @Test
+ public void testOfPercent() {
+ assertEquals(63563, MilliPct.ofPercent(63.563f).intValue());
+ assertEquals(-63563, MilliPct.ofPercent(-63.563f).intValue());
+ }
+
+ @Test
+ public void testOfRatio() {
+ assertEquals(43211, MilliPct.ofRatio(0.43211f).intValue());
+ assertEquals(-43211, MilliPct.ofRatio(-0.43211f).intValue());
+ }
+
+ @Test
+ public void testPercentValue() {
+ assertEquals(0.1f, MilliPct.ofMilliPct(100).percentValue(), 0.0001f);
+ assertEquals(-0.1f, MilliPct.ofMilliPct(-100).percentValue(), 0.0001f);
+ }
+
+ @Test
+ public void testRatioValue() {
+ assertEquals(0.002f, MilliPct.ofMilliPct(200).ratioValue(), 0.0001f);
+ assertEquals(-0.002f, MilliPct.ofMilliPct(-200).ratioValue(), 0.0001f);
+ }
+
+ @Test
+ public void testToString() {
+ NumberFormat pf = DecimalFormat.getPercentInstance(); //Varies by machine
+ pf.setMaximumFractionDigits(3);
+ assertEquals(pf.format(0.12345f), MilliPct.ofMilliPct(12345).toString());
+ assertEquals(pf.format(-0.12345f), MilliPct.ofMilliPct(-12345).toString());
+ }
+
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/StartTimeTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/StartTimeTest.java
new file mode 100644
index 0000000..4d7c6c0
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/StartTimeTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.soam;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.time.Duration;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.soam.StartTime.StartTimeOption;
+import org.onosproject.incubator.net.l2monitoring.soam.StopTime.StopTimeOption;
+
+public class StartTimeTest {
+
+ @Test
+ public void testStartImmediate() {
+ StartTime st = StartTime.immediate();
+ assertEquals(StartTimeOption.IMMEDIATE, st.option());
+ assertNull(st.relativeTime());
+ assertNull(st.absoluteTime());
+ }
+
+ @Test
+ public void testStartRelative() {
+ StartTime st = StartTime.relative(Duration.ofMinutes(20));
+ assertEquals(StartTimeOption.RELATIVE, st.option());
+ assertEquals(20 * 60, st.relativeTime().getSeconds());
+ assertNull(st.absoluteTime());
+ }
+
+ @Test
+ public void testStartAbsolute() {
+ StartTime st = StartTime.absolute(OffsetDateTime
+ .of(2017, 3, 20, 11, 43, 11, 0, ZoneOffset.ofHours(-7))
+ .toInstant());
+ assertEquals(StartTimeOption.ABSOLUTE, st.option());
+ assertNull(st.relativeTime());
+ assertEquals("2017-03-20T11:43:11-07:00", st
+ .absoluteTime()
+ .atOffset(ZoneOffset.ofHours(-7))
+ .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
+ }
+
+ @Test
+ public void testStopImmediate() {
+ StopTime st = StopTime.none();
+ assertEquals(StopTimeOption.NONE, st.option());
+ assertNull(st.relativeTime());
+ assertNull(st.absoluteTime());
+ }
+
+ @Test
+ public void testStopRelative() {
+ StopTime st = StopTime.relative(Duration.ofMinutes(20));
+ assertEquals(StopTimeOption.RELATIVE, st.option());
+ assertEquals(20 * 60, st.relativeTime().getSeconds());
+ assertNull(st.absoluteTime());
+ }
+
+ @Test
+ public void testStopAbsolute() {
+ StopTime st = StopTime.absolute(OffsetDateTime
+ .of(2017, 3, 20, 11, 43, 11, 0, ZoneOffset.ofHours(-7))
+ .toInstant());
+ assertEquals(StopTimeOption.ABSOLUTE, st.option());
+ assertNull(st.relativeTime());
+ assertEquals("2017-03-20T11:43:11-07:00", st
+ .absoluteTime()
+ .atOffset(ZoneOffset.ofHours(-7))
+ .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
+ }
+
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementCreateTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementCreateTest.java
new file mode 100644
index 0000000..d24effc
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementCreateTest.java
@@ -0,0 +1,304 @@
+/*
+ * 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.soam.delay;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.time.Duration;
+import java.time.OffsetDateTime;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.MeasurementCreateBase.SessionType;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+import org.onosproject.incubator.net.l2monitoring.soam.StartTime;
+import org.onosproject.incubator.net.l2monitoring.soam.StartTime.StartTimeOption;
+import org.onosproject.incubator.net.l2monitoring.soam.StopTime;
+import org.onosproject.incubator.net.l2monitoring.soam.StopTime.StopTimeOption;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementCreate.DefaultDmCreateBuilder;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DataPattern;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DmType;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.MeasurementOption;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.TestTlvPattern;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.Version;
+
+public class DelayMeasurementCreateTest {
+
+ DelayMeasurementCreate dm1;
+
+ @Before
+ public void setUp() throws Exception, CfmConfigException, SoamConfigException {
+
+ DelayMeasurementThreshold dmT1 = DefaultDelayMeasurementThreshold
+ .builder(SoamId.valueOf(1))
+ .averageFrameDelayBackward(Duration.ofMillis(123))
+ .averageInterFrameDelayVariationForward(Duration.ofMillis(321))
+ .build();
+
+ DelayMeasurementThreshold dmT2 = DefaultDelayMeasurementThreshold
+ .builder(SoamId.valueOf(2))
+ .averageFrameDelayBackward(Duration.ofMillis(456))
+ .averageInterFrameDelayVariationForward(Duration.ofMillis(654))
+ .build();
+
+ try {
+ DefaultDmCreateBuilder builder = (DefaultDmCreateBuilder)
+ DefaultDelayMeasurementCreate.builder(
+ DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 12), Priority.PRIO6)
+ .addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_FORWARD_MIN)
+ .addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_FORWARD_AVERAGE)
+ .addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_FORWARD_MAX)
+ .addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_FORWARD_BINS)
+ .binsPerFdInterval((short) 8)
+ .binsPerIfdvInterval((short) 9)
+ .ifdvSelectionOffset((short) 10)
+ .binsPerFdrInterval((short) 12)
+ .addToThresholds(dmT1)
+ .addToThresholds(dmT2)
+ .messagePeriod(Duration.ofMillis(100L))
+ .frameSize((short) 64)
+ .dataPattern(DataPattern.ONES)
+ .testTlvIncluded(true)
+ .testTlvPattern(TestTlvPattern.NULL_SIGNAL_WITHOUT_CRC_32)
+ .measurementInterval(Duration.ofMinutes(15))
+ .numberIntervalsStored((short) 32)
+ .alignMeasurementIntervals(true)
+ .alignMeasurementOffset(Duration.ofMinutes(4))
+ .sessionType(SessionType.ONDEMAND)
+ .startTime(StartTime.relative(Duration.ofMinutes(7)))
+ .stopTime(StopTime.relative(Duration.ofMinutes(8)));
+ dm1 = builder.build();
+ } catch (SoamConfigException e) {
+ throw new Exception(e);
+ }
+ }
+
+ @Test
+ public void testInvalidMessagePeriod() throws CfmConfigException {
+ try {
+ DefaultDelayMeasurementCreate.builder(
+ DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20),
+ Priority.PRIO6)
+ .messagePeriod(Duration.ofMinutes(61));
+ fail("Expected an exception to be thrown for invalid messagePeriod: " + 3660000);
+ } catch (SoamConfigException e) {
+ assertEquals(SoamConfigException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void testInvalidFrameSize() throws CfmConfigException {
+ try {
+ DefaultDelayMeasurementCreate.builder(
+ DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20),
+ Priority.PRIO6)
+ .frameSize((short) 11111);
+ fail("Expected an exception to be thrown for frame size: " + 11111);
+ } catch (SoamConfigException e) {
+ assertEquals(SoamConfigException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void testInvalidMeasurementInterval() throws CfmConfigException {
+ try {
+ DefaultDelayMeasurementCreate.builder(
+ DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20),
+ Priority.PRIO6)
+ .measurementInterval(Duration.ofMinutes(0));
+ fail("Expected an exception to be thrown for invalid measurementInterval: " + 0);
+ } catch (SoamConfigException e) {
+ assertEquals(SoamConfigException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void testInvalidNumberIntervalsStored() throws CfmConfigException {
+ try {
+ DefaultDelayMeasurementCreate.builder(
+ DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20),
+ Priority.PRIO6)
+ .numberIntervalsStored((short) 1001);
+ fail("Expected an exception to be thrown for number intervals stored: " + 1001);
+ } catch (SoamConfigException e) {
+ assertEquals(SoamConfigException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void testInvalidAlignMeasurementOffset() throws CfmConfigException {
+ try {
+ DefaultDelayMeasurementCreate.builder(
+ DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20),
+ Priority.PRIO6)
+ .alignMeasurementOffset(Duration.ofMinutes(525601));
+ fail("Expected an exception to be thrown for align Measurement Offset: " + 525601);
+ } catch (SoamConfigException e) {
+ assertEquals(SoamConfigException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void testInvalidStartTime() throws CfmConfigException {
+ OffsetDateTime oneMinuteAgo = OffsetDateTime.now().minusMinutes(1);
+ try {
+ DefaultDelayMeasurementCreate.builder(
+ DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20),
+ Priority.PRIO6)
+ .startTime(StartTime.absolute(oneMinuteAgo.toInstant()));
+ fail("Expected an exception to be thrown for align Start Time: " + oneMinuteAgo);
+ } catch (SoamConfigException e) {
+ assertEquals(SoamConfigException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void testInvalidStopTime() throws CfmConfigException {
+ OffsetDateTime oneMinuteAgo = OffsetDateTime.now().minusMinutes(1);
+ try {
+ DefaultDelayMeasurementCreate.builder(
+ DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20),
+ Priority.PRIO6)
+ .stopTime(StopTime.absolute(oneMinuteAgo.toInstant()));
+ fail("Expected an exception to be thrown for align Stop Time: " + oneMinuteAgo);
+ } catch (SoamConfigException e) {
+ assertEquals(SoamConfigException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void testDmCfgType() {
+ assertEquals(DmType.DMDMM, dm1.dmCfgType());
+ }
+
+ @Test
+ public void testVersion() {
+ assertEquals(Version.Y17312011, dm1.version());
+ }
+
+ @Test
+ public void testRemoteMepId() {
+ assertEquals(12, dm1.remoteMepId().value());
+ }
+
+ @Test
+ public void testMeasurementsEnabled() {
+ assertEquals(4, dm1.measurementsEnabled().size());
+ }
+
+ @Test
+ public void testMessagePeriod() {
+ assertEquals(100, dm1.messagePeriod().toMillis());
+ }
+
+ @Test
+ public void testPriority() {
+ assertEquals(Priority.PRIO6.name(), dm1.priority().name());
+ }
+
+ @Test
+ public void testFrameSize() {
+ assertEquals(64, dm1.frameSize().shortValue());
+ }
+
+ @Test
+ public void testDataPattern() {
+ assertEquals(DataPattern.ONES, dm1.dataPattern());
+ }
+
+ @Test
+ public void testTestTlvIncluded() {
+ assertTrue(dm1.testTlvIncluded());
+ }
+
+ @Test
+ public void testTestTlvPattern() {
+ assertEquals(TestTlvPattern.NULL_SIGNAL_WITHOUT_CRC_32, dm1.testTlvPattern());
+ }
+
+ @Test
+ public void testMeasurementInterval() {
+ assertEquals(15, dm1.measurementInterval().toMinutes());
+ }
+
+ @Test
+ public void testNumberIntervalsStored() {
+ assertEquals(32, dm1.numberIntervalsStored().shortValue());
+ }
+
+ @Test
+ public void testAlignMeasurementIntervals() {
+ assertTrue(dm1.alignMeasurementIntervals());
+ }
+
+ @Test
+ public void testAlignMeasurementOffset() {
+ assertEquals(4, dm1.alignMeasurementOffset().toMinutes());
+ }
+
+ @Test
+ public void testBinsPerFdInterval() {
+ assertEquals(8, dm1.binsPerFdInterval().shortValue());
+ }
+
+ @Test
+ public void testBinsPerIfdvInterval() {
+ assertEquals(9, dm1.binsPerIfdvInterval().shortValue());
+ }
+
+ @Test
+ public void testIfdvSelectionOffset() {
+ assertEquals(10, dm1.ifdvSelectionOffset().shortValue());
+ }
+
+ @Test
+ public void testBinsPerFdrInterval() {
+ assertEquals(12, dm1.binsPerFdrInterval().shortValue());
+ }
+
+ @Test
+ public void testSessionType() {
+ assertEquals(SessionType.ONDEMAND, dm1.sessionType());
+ }
+
+ @Test
+ public void testStartTime() {
+ assertEquals(StartTimeOption.RELATIVE, dm1.startTime().option());
+ assertEquals(7, dm1.startTime().relativeTime().toMinutes());
+ }
+
+ @Test
+ public void testStopTime() {
+ assertEquals(StopTimeOption.RELATIVE, dm1.stopTime().option());
+ assertEquals(8, dm1.stopTime().relativeTime().toMinutes());
+ }
+
+ @Test
+ public void testThresholds() {
+ DelayMeasurementThreshold[] thresholds =
+ dm1.thresholds().toArray(
+ new DelayMeasurementThreshold[dm1.thresholds().size()]);
+
+ assertEquals(1, thresholds[0].threshId().id().intValue());
+ assertEquals(123, thresholds[0].averageFrameDelayBackward().toMillis());
+ }
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementEntryTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementEntryTest.java
new file mode 100644
index 0000000..ad2439a
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementEntryTest.java
@@ -0,0 +1,125 @@
+/*
+ * 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.soam.delay;
+
+import static org.junit.Assert.*;
+
+import java.time.Duration;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DmType;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.Version;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry.SessionStatus;
+
+public class DelayMeasurementEntryTest {
+
+ DelayMeasurementEntry dmE1;
+
+ @Before
+ public void setUp() throws Exception, SoamConfigException, CfmConfigException {
+
+ DelayMeasurementStatCurrent dmE1c = (DelayMeasurementStatCurrent)
+ DefaultDelayMeasurementStatCurrent.builder(
+ Duration.ofMinutes(6), false)
+ .build();
+
+ DelayMeasurementStatHistory dmE1h1 = (DelayMeasurementStatHistory)
+ DefaultDelayMeasurementStatHistory.builder(
+ SoamId.valueOf(1), Duration.ofMinutes(15), false)
+ .build();
+
+ DelayMeasurementStatHistory dmE1h2 = (DelayMeasurementStatHistory)
+ DefaultDelayMeasurementStatHistory.builder(
+ SoamId.valueOf(2), Duration.ofMinutes(15), false)
+ .build();
+
+ dmE1 = DefaultDelayMeasurementEntry.builder(
+ SoamId.valueOf(1),
+ DmType.DMDMM,
+ Version.Y17312011,
+ MepId.valueOf((short) 10),
+ Priority.PRIO3)
+ .sessionStatus(SessionStatus.NOT_ACTIVE)
+ .frameDelayTwoWay(Duration.ofMillis(1))
+ .frameDelayForward(Duration.ofMillis(2))
+ .frameDelayBackward(Duration.ofMillis(3))
+ .interFrameDelayVariationTwoWay(Duration.ofMillis(4))
+ .interFrameDelayVariationForward(Duration.ofMillis(5))
+ .interFrameDelayVariationBackward(Duration.ofMillis(6))
+ .currentResult(dmE1c)
+ .addToHistoricalResults(dmE1h1)
+ .addToHistoricalResults(dmE1h2)
+ .build();
+ }
+
+ @Test
+ public void testDmId() {
+ assertEquals(1, dmE1.dmId().id().shortValue());
+ }
+
+ @Test
+ public void testSessionStatus() {
+ assertEquals(SessionStatus.NOT_ACTIVE.name(),
+ dmE1.sessionStatus().name());
+ }
+
+ @Test
+ public void testFrameDelayTwoWay() {
+ assertEquals(1, dmE1.frameDelayTwoWay().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayForward() {
+ assertEquals(2, dmE1.frameDelayForward().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayBackward() {
+ assertEquals(3, dmE1.frameDelayBackward().toMillis());
+ }
+
+ @Test
+ public void testInterFrameDelayVariationTwoWay() {
+ assertEquals(4, dmE1.interFrameDelayVariationTwoWay().toMillis());
+ }
+
+ @Test
+ public void testInterFrameDelayVariationForward() {
+ assertEquals(5, dmE1.interFrameDelayVariationForward().toMillis());
+ }
+
+ @Test
+ public void testInterFrameDelayVariationBackward() {
+ assertEquals(6, dmE1.interFrameDelayVariationBackward().toMillis());
+ }
+
+ @Test
+ public void testCurrentResult() {
+ assertEquals(360, dmE1.currentResult().elapsedTime().getSeconds());
+ }
+
+ @Test
+ public void testHistoricalResults() {
+ assertEquals(2, dmE1.historicalResults().size());
+ }
+
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementStatCurrentAndHistoryTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementStatCurrentAndHistoryTest.java
new file mode 100644
index 0000000..0bde63a
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementStatCurrentAndHistoryTest.java
@@ -0,0 +1,385 @@
+/*
+ * 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.soam.delay;
+
+import static junit.framework.TestCase.fail;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.time.Duration;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+
+public class DelayMeasurementStatCurrentAndHistoryTest {
+
+ private DelayMeasurementStatCurrent dmStCurr1;
+ private DelayMeasurementStatHistory dmStHist1;
+
+ @Before
+ public void setUp() throws Exception, SoamConfigException {
+ dmStCurr1 = (DelayMeasurementStatCurrent)
+ DefaultDelayMeasurementStatCurrent.builder(
+ Duration.ofMinutes(9), false)
+ .startTime(OffsetDateTime.of(2017, 3, 20, 23, 22, 7, 0,
+ ZoneOffset.ofHours(-7)).toInstant())
+ .frameDelayTwoWayMin(Duration.ofMillis(101))
+ .frameDelayTwoWayMax(Duration.ofMillis(102))
+ .frameDelayTwoWayAvg(Duration.ofMillis(103))
+ .frameDelayForwardMin(Duration.ofMillis(104))
+ .frameDelayForwardMax(Duration.ofMillis(105))
+ .frameDelayForwardAvg(Duration.ofMillis(106))
+ .frameDelayBackwardMin(Duration.ofMillis(107))
+ .frameDelayBackwardMax(Duration.ofMillis(108))
+ .frameDelayBackwardAvg(Duration.ofMillis(109))
+ .interFrameDelayVariationTwoWayMin(Duration.ofMillis(110))
+ .interFrameDelayVariationTwoWayMax(Duration.ofMillis(111))
+ .interFrameDelayVariationTwoWayAvg(Duration.ofMillis(112))
+ .interFrameDelayVariationForwardMin(Duration.ofMillis(113))
+ .interFrameDelayVariationForwardMax(Duration.ofMillis(114))
+ .interFrameDelayVariationForwardAvg(Duration.ofMillis(115))
+ .interFrameDelayVariationBackwardMin(Duration.ofMillis(116))
+ .interFrameDelayVariationBackwardMax(Duration.ofMillis(117))
+ .interFrameDelayVariationBackwardAvg(Duration.ofMillis(118))
+ .frameDelayRangeTwoWayMax(Duration.ofMillis(119))
+ .frameDelayRangeTwoWayAvg(Duration.ofMillis(120))
+ .frameDelayRangeForwardMax(Duration.ofMillis(121))
+ .frameDelayRangeForwardAvg(Duration.ofMillis(122))
+ .frameDelayRangeBackwardMax(Duration.ofMillis(123))
+ .frameDelayRangeBackwardAvg(Duration.ofMillis(124))
+ .soamPdusSent(125)
+ .soamPdusReceived(126)
+ .build();
+
+ dmStHist1 = (DelayMeasurementStatHistory)
+ DefaultDelayMeasurementStatHistory.builder(
+ SoamId.valueOf(11), Duration.ofMinutes(15), true)
+ .endTime(OffsetDateTime.of(2017, 3, 20, 23, 22, 8, 0,
+ ZoneOffset.ofHours(-7)).toInstant())
+ .frameDelayTwoWayMin(Duration.ofMillis(201))
+ .frameDelayTwoWayMax(Duration.ofMillis(202))
+ .frameDelayTwoWayAvg(Duration.ofMillis(203))
+ .frameDelayForwardMin(Duration.ofMillis(204))
+ .frameDelayForwardMax(Duration.ofMillis(205))
+ .frameDelayForwardAvg(Duration.ofMillis(206))
+ .frameDelayBackwardMin(Duration.ofMillis(207))
+ .frameDelayBackwardMax(Duration.ofMillis(208))
+ .frameDelayBackwardAvg(Duration.ofMillis(209))
+ .interFrameDelayVariationTwoWayMin(Duration.ofMillis(210))
+ .interFrameDelayVariationTwoWayMax(Duration.ofMillis(211))
+ .interFrameDelayVariationTwoWayAvg(Duration.ofMillis(212))
+ .interFrameDelayVariationForwardMin(Duration.ofMillis(213))
+ .interFrameDelayVariationForwardMax(Duration.ofMillis(214))
+ .interFrameDelayVariationForwardAvg(Duration.ofMillis(215))
+ .interFrameDelayVariationBackwardMin(Duration.ofMillis(216))
+ .interFrameDelayVariationBackwardMax(Duration.ofMillis(217))
+ .interFrameDelayVariationBackwardAvg(Duration.ofMillis(218))
+ .frameDelayRangeTwoWayMax(Duration.ofMillis(219))
+ .frameDelayRangeTwoWayAvg(Duration.ofMillis(220))
+ .frameDelayRangeForwardMax(Duration.ofMillis(221))
+ .frameDelayRangeForwardAvg(Duration.ofMillis(222))
+ .frameDelayRangeBackwardMax(Duration.ofMillis(223))
+ .frameDelayRangeBackwardAvg(Duration.ofMillis(224))
+ .soamPdusSent(225)
+ .soamPdusReceived(226)
+ .build();
+ }
+
+ @Test
+ public void testStartTime() {
+ assertEquals("2017-03-20T23:22:07-07:00",
+ dmStCurr1.startTime().atOffset(ZoneOffset.ofHours(-7))
+ .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
+ }
+
+ @Test
+ public void testEndTime() {
+ assertEquals("2017-03-20T23:22:08-07:00",
+ dmStHist1.endTime().atOffset(ZoneOffset.ofHours(-7))
+ .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
+ }
+
+ @Test
+ public void testHistoryStatsId() {
+ assertEquals(11, dmStHist1.historyStatsId().id().intValue());
+ }
+
+ @Test
+ public void testElapsedTime() {
+ assertEquals(9, dmStCurr1.elapsedTime().toMinutes());
+
+ assertEquals(15, dmStHist1.elapsedTime().toMinutes());
+ }
+
+ @Test
+ public void testSuspectStatus() {
+ assertFalse(dmStCurr1.suspectStatus());
+
+ assertTrue(dmStHist1.suspectStatus());
+ }
+
+ @Test
+ public void testFrameDelayTwoWayMin() {
+ assertEquals(101, dmStCurr1.frameDelayTwoWayMin().toMillis());
+
+ assertEquals(201, dmStHist1.frameDelayTwoWayMin().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayTwoWayMax() {
+ assertEquals(102, dmStCurr1.frameDelayTwoWayMax().toMillis());
+
+ assertEquals(202, dmStHist1.frameDelayTwoWayMax().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayTwoWayAvg() {
+ assertEquals(103, dmStCurr1.frameDelayTwoWayAvg().toMillis());
+
+ assertEquals(203, dmStHist1.frameDelayTwoWayAvg().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayForwardMin() {
+ assertEquals(104, dmStCurr1.frameDelayForwardMin().toMillis());
+
+ assertEquals(204, dmStHist1.frameDelayForwardMin().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayForwardMax() {
+ assertEquals(105, dmStCurr1.frameDelayForwardMax().toMillis());
+
+ assertEquals(205, dmStHist1.frameDelayForwardMax().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayForwardAvg() {
+ assertEquals(106, dmStCurr1.frameDelayForwardAvg().toMillis());
+
+ assertEquals(206, dmStHist1.frameDelayForwardAvg().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayBackwardMin() {
+ assertEquals(107, dmStCurr1.frameDelayBackwardMin().toMillis());
+
+ assertEquals(207, dmStHist1.frameDelayBackwardMin().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayBackwardMax() {
+ assertEquals(108, dmStCurr1.frameDelayBackwardMax().toMillis());
+
+ assertEquals(208, dmStHist1.frameDelayBackwardMax().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayBackwardAvg() {
+ assertEquals(109, dmStCurr1.frameDelayBackwardAvg().toMillis());
+
+ assertEquals(209, dmStHist1.frameDelayBackwardAvg().toMillis());
+ }
+
+ @Test
+ public void testInterFrameDelayVariationTwoWayMin() {
+ assertEquals(110, dmStCurr1.interFrameDelayVariationTwoWayMin().toMillis());
+
+ assertEquals(210, dmStHist1.interFrameDelayVariationTwoWayMin().toMillis());
+ }
+
+ @Test
+ public void testInterFrameDelayVariationTwoWayMax() {
+ assertEquals(111, dmStCurr1.interFrameDelayVariationTwoWayMax().toMillis());
+
+ assertEquals(211, dmStHist1.interFrameDelayVariationTwoWayMax().toMillis());
+ }
+
+ @Test
+ public void testInterFrameDelayVariationTwoWayAvg() {
+ assertEquals(112, dmStCurr1.interFrameDelayVariationTwoWayAvg().toMillis());
+
+ assertEquals(212, dmStHist1.interFrameDelayVariationTwoWayAvg().toMillis());
+ }
+
+ @Test
+ public void testInterFrameDelayVariationForwardMin() {
+ assertEquals(113, dmStCurr1.interFrameDelayVariationForwardMin().toMillis());
+
+ assertEquals(213, dmStHist1.interFrameDelayVariationForwardMin().toMillis());
+ }
+
+ @Test
+ public void testInterFrameDelayVariationForwardMax() {
+ assertEquals(114, dmStCurr1.interFrameDelayVariationForwardMax().toMillis());
+
+ assertEquals(214, dmStHist1.interFrameDelayVariationForwardMax().toMillis());
+ }
+
+ @Test
+ public void testInterFrameDelayVariationForwardAvg() {
+ assertEquals(115, dmStCurr1.interFrameDelayVariationForwardAvg().toMillis());
+
+ assertEquals(215, dmStHist1.interFrameDelayVariationForwardAvg().toMillis());
+ }
+
+ @Test
+ public void testInterFrameDelayVariationBackwardMin() {
+ assertEquals(116, dmStCurr1.interFrameDelayVariationBackwardMin().toMillis());
+
+ assertEquals(216, dmStHist1.interFrameDelayVariationBackwardMin().toMillis());
+ }
+
+ @Test
+ public void testInterFrameDelayVariationBackwardMax() {
+ assertEquals(117, dmStCurr1.interFrameDelayVariationBackwardMax().toMillis());
+
+ assertEquals(217, dmStHist1.interFrameDelayVariationBackwardMax().toMillis());
+ }
+
+ @Test
+ public void testInterFrameDelayVariationBackwardAvg() {
+ assertEquals(118, dmStCurr1.interFrameDelayVariationBackwardAvg().toMillis());
+
+ assertEquals(218, dmStHist1.interFrameDelayVariationBackwardAvg().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayRangeTwoWayMax() {
+ assertEquals(119, dmStCurr1.frameDelayRangeTwoWayMax().toMillis());
+
+ assertEquals(219, dmStHist1.frameDelayRangeTwoWayMax().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayRangeTwoWayAvg() {
+ assertEquals(120, dmStCurr1.frameDelayRangeTwoWayAvg().toMillis());
+
+ assertEquals(220, dmStHist1.frameDelayRangeTwoWayAvg().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayRangeForwardMax() {
+ assertEquals(121, dmStCurr1.frameDelayRangeForwardMax().toMillis());
+
+ assertEquals(221, dmStHist1.frameDelayRangeForwardMax().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayRangeForwardAvg() {
+ assertEquals(122, dmStCurr1.frameDelayRangeForwardAvg().toMillis());
+
+ assertEquals(222, dmStHist1.frameDelayRangeForwardAvg().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayRangeBackwardMax() {
+ assertEquals(123, dmStCurr1.frameDelayRangeBackwardMax().toMillis());
+
+ assertEquals(223, dmStHist1.frameDelayRangeBackwardMax().toMillis());
+ }
+
+ @Test
+ public void testFrameDelayRangeBackwardAvg() {
+ assertEquals(124, dmStCurr1.frameDelayRangeBackwardAvg().toMillis());
+
+ assertEquals(224, dmStHist1.frameDelayRangeBackwardAvg().toMillis());
+ }
+
+ @Test
+ public void testSoamPdusSent() {
+ assertEquals(125, dmStCurr1.soamPdusSent().intValue());
+
+ assertEquals(225, dmStHist1.soamPdusSent().intValue());
+ }
+
+ @Test
+ public void testSoamPdusReceived() {
+ assertEquals(126, dmStCurr1.soamPdusReceived().intValue());
+
+ assertEquals(226, dmStHist1.soamPdusReceived().intValue());
+ }
+
+ @Ignore
+ @Test
+ public void testFrameDelayTwoWayBins() {
+ //TODO Add in test
+ fail("Not yet implemented");
+ }
+
+ @Ignore
+ @Test
+ public void testFrameDelayForwardBins() {
+ //TODO Add in test
+ fail("Not yet implemented");
+ }
+
+ @Ignore
+ @Test
+ public void testFrameDelayBackwardBins() {
+ //TODO Add in test
+ fail("Not yet implemented");
+ }
+
+ @Ignore
+ @Test
+ public void testInterFrameDelayVariationTwoWayBins() {
+ //TODO Add in test
+ fail("Not yet implemented");
+ }
+
+ @Ignore
+ @Test
+ public void testInterFrameDelayVariationForwardBins() {
+ //TODO Add in test
+ fail("Not yet implemented");
+ }
+
+ @Ignore
+ @Test
+ public void testInterFrameDelayVariationBackwardBins() {
+ //TODO Add in test
+ fail("Not yet implemented");
+ }
+
+ @Ignore
+ @Test
+ public void testFrameDelayRangeTwoWayBins() {
+ //TODO Add in test
+ fail("Not yet implemented");
+ }
+
+ @Ignore
+ @Test
+ public void testFrameDelayRangeForwardBins() {
+ //TODO Add in test
+ fail("Not yet implemented");
+ }
+
+ @Ignore
+ @Test
+ public void testFrameDelayRangeBackwardBins() {
+ //TODO Add in test
+ fail("Not yet implemented");
+ }
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementThresholdOptionTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementThresholdOptionTest.java
new file mode 100644
index 0000000..f838143
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementThresholdOptionTest.java
@@ -0,0 +1,216 @@
+/*
+ * 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.soam.delay;
+
+import static org.junit.Assert.*;
+
+import java.time.Duration;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementThreshold.ThresholdOption;
+
+public class DelayMeasurementThresholdOptionTest {
+
+ DelayMeasurementThreshold dmT1;
+
+ @Before
+ public void setUp() throws Exception, SoamConfigException {
+ dmT1 = DefaultDelayMeasurementThreshold.builder(SoamId.valueOf(1))
+ .averageFrameDelayBackward(Duration.ofMillis(101))
+ .averageFrameDelayForward(Duration.ofMillis(102))
+ .averageFrameDelayTwoWay(Duration.ofMillis(103))
+ .averageFrameDelayRangeBackward(Duration.ofMillis(201))
+ .averageFrameDelayRangeForward(Duration.ofMillis(202))
+ .averageFrameDelayRangeTwoWay(Duration.ofMillis(203))
+ .averageInterFrameDelayVariationBackward(Duration.ofMillis(301))
+ .averageInterFrameDelayVariationForward(Duration.ofMillis(302))
+ .averageInterFrameDelayVariationTwoWay(Duration.ofMillis(303))
+ .maxFrameDelayBackward(Duration.ofMillis(401))
+ .maxFrameDelayForward(Duration.ofMillis(402))
+ .maxFrameDelayTwoWay(Duration.ofMillis(403))
+ .maxFrameDelayRangeBackward(Duration.ofMillis(501))
+ .maxFrameDelayRangeForward(Duration.ofMillis(502))
+ .maxFrameDelayRangeTwoWay(Duration.ofMillis(503))
+ .maxInterFrameDelayVariationBackward(Duration.ofMillis(601))
+ .maxInterFrameDelayVariationForward(Duration.ofMillis(602))
+ .maxInterFrameDelayVariationTwoWay(Duration.ofMillis(603))
+ .measuredFrameDelayBackward(Duration.ofMillis(701))
+ .measuredFrameDelayForward(Duration.ofMillis(702))
+ .measuredFrameDelayTwoWay(Duration.ofMillis(703))
+ .measuredInterFrameDelayVariationBackward(Duration.ofMillis(801))
+ .measuredInterFrameDelayVariationForward(Duration.ofMillis(802))
+ .measuredInterFrameDelayVariationTwoWay(Duration.ofMillis(803))
+ .addToThresholdsEnabled(ThresholdOption.MEASURED_FRAME_DELAY_TWO_WAY)
+ .addToThresholdsEnabled(ThresholdOption.MAX_FRAME_DELAY_TWO_WAY)
+ .addToThresholdsEnabled(ThresholdOption.AVERAGE_FRAME_DELAY_TWO_WAY)
+ .addToThresholdsEnabled(ThresholdOption.MEASURED_INTER_FRAME_DELAY_VARIATION_TWO_WAY)
+ .addToThresholdsEnabled(ThresholdOption.MAX_INTER_FRAME_DELAY_VARIATION_TWO_WAY)
+ .addToThresholdsEnabled(ThresholdOption.AVERAGE_INTER_FRAME_DELAY_VARIATION_TWO_WAY)
+ .addToThresholdsEnabled(ThresholdOption.MAX_FRAME_DELAY_RANGE_TWO_WAY)
+ .addToThresholdsEnabled(ThresholdOption.AVERAGE_FRAME_DELAY_RANGE_TWO_WAY)
+ .addToThresholdsEnabled(ThresholdOption.MEASURED_FRAME_DELAY_FORWARD)
+ .addToThresholdsEnabled(ThresholdOption.MAX_FRAME_DELAY_FORWARD)
+ .addToThresholdsEnabled(ThresholdOption.AVERAGE_FRAME_DELAY_FORWARD)
+ .addToThresholdsEnabled(ThresholdOption.MEASURED_INTER_FRAME_DELAY_VARIATION_FORWARD)
+ .addToThresholdsEnabled(ThresholdOption.MAX_INTER_FRAME_DELAY_VARIATION_FORWARD)
+ .addToThresholdsEnabled(ThresholdOption.AVERAGE_INTER_FRAME_DELAY_VARIATION_FORWARD)
+ .addToThresholdsEnabled(ThresholdOption.MAX_FRAME_DELAY_RANGE_FORWARD)
+ .addToThresholdsEnabled(ThresholdOption.AVERAGE_FRAME_DELAY_RANGE_FORWARD)
+ .addToThresholdsEnabled(ThresholdOption.MEASURED_FRAME_DELAY_BACKWARD)
+ .addToThresholdsEnabled(ThresholdOption.MAX_FRAME_DELAY_BACKWARD)
+ .addToThresholdsEnabled(ThresholdOption.AVERAGE_FRAME_DELAY_BACKWARD)
+ .addToThresholdsEnabled(ThresholdOption.MEASURED_INTER_FRAME_DELAY_VARIATION_BACKWARD)
+ .addToThresholdsEnabled(ThresholdOption.MAX_INTER_FRAME_DELAY_VARIATION_BACKWARD)
+ .addToThresholdsEnabled(ThresholdOption.AVERAGE_INTER_FRAME_DELAY_VARIATION_BACKWARD)
+ .addToThresholdsEnabled(ThresholdOption.MAX_FRAME_DELAY_RANGE_BACKWARD)
+ .addToThresholdsEnabled(ThresholdOption.AVERAGE_FRAME_DELAY_RANGE_BACKWARD)
+ .build();
+ }
+
+ @Test
+ public void testThreshId() {
+ assertEquals(1, dmT1.threshId().id().intValue());
+ }
+
+ @Test
+ public void testThresholdsEnabled() {
+ assertEquals(24, dmT1.thresholdsEnabled().size());
+ }
+
+ @Test
+ public void testMeasuredFrameDelayTwoWay() {
+ assertEquals(703, dmT1.measuredFrameDelayTwoWay().toMillis());
+ }
+
+ @Test
+ public void testMaxFrameDelayTwoWay() {
+ assertEquals(403, dmT1.maxFrameDelayTwoWay().toMillis());
+ }
+
+ @Test
+ public void testAverageFrameDelayTwoWay() {
+ assertEquals(103, dmT1.averageFrameDelayTwoWay().toMillis());
+ }
+
+ @Test
+ public void testMeasuredInterFrameDelayVariationTwoWay() {
+ assertEquals(803, dmT1.measuredInterFrameDelayVariationTwoWay().toMillis());
+ }
+
+ @Test
+ public void testMaxInterFrameDelayVariationTwoWay() {
+ assertEquals(603, dmT1.maxInterFrameDelayVariationTwoWay().toMillis());
+ }
+
+ @Test
+ public void testAverageInterFrameDelayVariationTwoWay() {
+ assertEquals(303, dmT1.averageInterFrameDelayVariationTwoWay().toMillis());
+ }
+
+ @Test
+ public void testMaxFrameDelayRangeTwoWay() {
+ assertEquals(503, dmT1.maxFrameDelayRangeTwoWay().toMillis());
+ }
+
+ @Test
+ public void testAverageFrameDelayRangeTwoWay() {
+ assertEquals(203, dmT1.averageFrameDelayRangeTwoWay().toMillis());
+ }
+
+ @Test
+ public void testMeasuredFrameDelayForward() {
+ assertEquals(702, dmT1.measuredFrameDelayForward().toMillis());
+ }
+
+ @Test
+ public void testMaxFrameDelayForward() {
+ assertEquals(402, dmT1.maxFrameDelayForward().toMillis());
+ }
+
+ @Test
+ public void testAverageFrameDelayForward() {
+ assertEquals(102, dmT1.averageFrameDelayForward().toMillis());
+ }
+
+ @Test
+ public void testMeasuredInterFrameDelayVariationForward() {
+ assertEquals(802, dmT1.measuredInterFrameDelayVariationForward().toMillis());
+ }
+
+ @Test
+ public void testMaxInterFrameDelayVariationForward() {
+ assertEquals(602, dmT1.maxInterFrameDelayVariationForward().toMillis());
+ }
+
+ @Test
+ public void testAverageInterFrameDelayVariationForward() {
+ assertEquals(302, dmT1.averageInterFrameDelayVariationForward().toMillis());
+ }
+
+ @Test
+ public void testMaxFrameDelayRangeForward() {
+ assertEquals(502, dmT1.maxFrameDelayRangeForward().toMillis());
+ }
+
+ @Test
+ public void testAverageFrameDelayRangeForward() {
+ assertEquals(202, dmT1.averageFrameDelayRangeForward().toMillis());
+ }
+
+ @Test
+ public void testMeasuredFrameDelayBackward() {
+ assertEquals(701, dmT1.measuredFrameDelayBackward().toMillis());
+ }
+
+ @Test
+ public void testMaxFrameDelayBackward() {
+ assertEquals(401, dmT1.maxFrameDelayBackward().toMillis());
+ }
+
+ @Test
+ public void testAverageFrameDelayBackward() {
+ assertEquals(101, dmT1.averageFrameDelayBackward().toMillis());
+ }
+
+ @Test
+ public void testMeasuredInterFrameDelayVariationBackward() {
+ assertEquals(801, dmT1.measuredInterFrameDelayVariationBackward().toMillis());
+ }
+
+ @Test
+ public void testMaxInterFrameDelayVariationBackward() {
+ assertEquals(601, dmT1.maxInterFrameDelayVariationBackward().toMillis());
+ }
+
+ @Test
+ public void testAverageInterFrameDelayVariationBackward() {
+ assertEquals(301, dmT1.averageInterFrameDelayVariationBackward().toMillis());
+ }
+
+ @Test
+ public void testMaxFrameDelayRangeBackward() {
+ assertEquals(501, dmT1.maxFrameDelayRangeBackward().toMillis());
+ }
+
+ @Test
+ public void testAverageFrameDelayRangeBackward() {
+ assertEquals(201, dmT1.averageFrameDelayRangeBackward().toMillis());
+ }
+
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatCurrentTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatCurrentTest.java
new file mode 100644
index 0000000..d65c307
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatCurrentTest.java
@@ -0,0 +1,141 @@
+/*
+ * 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.soam.loss;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.time.Duration;
+import java.time.Instant;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossAvailabilityStatCurrent.LaStatCurrentBuilder;
+
+public class LossAvailabilityStatCurrentTest {
+
+ LossAvailabilityStatCurrent lasc1;
+
+ @Before
+ public void setUp() {
+ LaStatCurrentBuilder builder = DefaultLaStatCurrent.builder(
+ Duration.ofMinutes(13), true, Instant.ofEpochSecond(123456789L));
+ builder = (LaStatCurrentBuilder) builder
+ .backwardAvailable(123456780L)
+ .backwardAverageFrameLossRatio(MilliPct.ofMilliPct(12345))
+ .backwardConsecutiveHighLoss(123456781L)
+ .backwardHighLoss(123456782L)
+ .backwardMaxFrameLossRatio(MilliPct.ofMilliPct(12346))
+ .backwardMinFrameLossRatio(MilliPct.ofMilliPct(12347))
+ .backwardUnavailable(123456783L)
+ .forwardAvailable(123456784L)
+ .forwardAverageFrameLossRatio(MilliPct.ofMilliPct(12348))
+ .forwardConsecutiveHighLoss(123456785L)
+ .forwardHighLoss(123456786L)
+ .forwardMaxFrameLossRatio(MilliPct.ofMilliPct(12349))
+ .forwardMinFrameLossRatio(MilliPct.ofMilliPct(12350))
+ .forwardUnavailable(123456787L);
+
+ lasc1 = builder.build();
+ }
+
+ @Test
+ public void testStartTime() {
+ assertEquals(123456789L, lasc1.startTime().getEpochSecond());
+ }
+
+ @Test
+ public void testElapsedTime() {
+ assertEquals(13, lasc1.elapsedTime().toMinutes());
+ }
+
+ @Test
+ public void testSuspectStatus() {
+ assertTrue(lasc1.suspectStatus());
+ }
+
+ @Test
+ public void testForwardHighLoss() {
+ assertEquals(123456786L, lasc1.forwardHighLoss().longValue());
+ }
+
+ @Test
+ public void testBackwardHighLoss() {
+ assertEquals(123456782L, lasc1.backwardHighLoss().longValue());
+ }
+
+ @Test
+ public void testForwardConsecutiveHighLoss() {
+ assertEquals(123456785L, lasc1.forwardConsecutiveHighLoss().longValue());
+ }
+
+ @Test
+ public void testBackwardConsecutiveHighLoss() {
+ assertEquals(123456781L, lasc1.backwardConsecutiveHighLoss().longValue());
+ }
+
+ @Test
+ public void testForwardAvailable() {
+ assertEquals(123456784L, lasc1.forwardAvailable().longValue());
+ }
+
+ @Test
+ public void testBackwardAvailable() {
+ assertEquals(123456780L, lasc1.backwardAvailable().longValue());
+ }
+
+ @Test
+ public void testForwardUnavailable() {
+ assertEquals(123456787L, lasc1.forwardUnavailable().longValue());
+ }
+
+ @Test
+ public void testBackwardUnavailable() {
+ assertEquals(123456783L, lasc1.backwardUnavailable().longValue());
+ }
+
+ @Test
+ public void testForwardMinFrameLossRatio() {
+ assertEquals(12350, lasc1.forwardMinFrameLossRatio().intValue());
+ }
+
+ @Test
+ public void testForwardMaxFrameLossRatio() {
+ assertEquals(12349, lasc1.forwardMaxFrameLossRatio().intValue());
+ }
+
+ @Test
+ public void testForwardAverageFrameLossRatio() {
+ assertEquals(12348, lasc1.forwardAverageFrameLossRatio().intValue());
+ }
+
+ @Test
+ public void testBackwardMinFrameLossRatio() {
+ assertEquals(12347, lasc1.backwardMinFrameLossRatio().intValue());
+ }
+
+ @Test
+ public void testBackwardMaxFrameLossRatio() {
+ assertEquals(12346, lasc1.backwardMaxFrameLossRatio().intValue());
+ }
+
+ @Test
+ public void testBackwardAverageFrameLossRatio() {
+ assertEquals(12345, lasc1.backwardAverageFrameLossRatio().intValue());
+ }
+
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatHistoryTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatHistoryTest.java
new file mode 100644
index 0000000..1b68b6e
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatHistoryTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.soam.loss;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.time.Duration;
+import java.time.Instant;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossAvailabilityStatHistory.LaStatHistoryBuilder;
+
+public class LossAvailabilityStatHistoryTest {
+ LossAvailabilityStatHistory lash1;
+
+ @Before
+ public void setUp() {
+ LaStatHistoryBuilder builder = DefaultLaStatHistory.builder(
+ Duration.ofMinutes(12), true, SoamId.valueOf(5),
+ Instant.ofEpochSecond(123456789L));
+
+ lash1 = builder.build();
+ }
+
+ @Test
+ public void testHistoryStatsId() {
+ assertEquals(5, lash1.historyStatsId().id().intValue());
+ }
+
+ @Test
+ public void testEndTime() {
+ assertEquals(123456789L, lash1.endTime().getEpochSecond());
+ }
+
+ @Test
+ public void testElapsedTime() {
+ assertEquals(12, lash1.elapsedTime().toMinutes());
+ }
+
+ @Test
+ public void testSuspectStatus() {
+ assertTrue(lash1.suspectStatus());
+ }
+
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementCreateTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementCreateTest.java
new file mode 100644
index 0000000..c7d1264
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementCreateTest.java
@@ -0,0 +1,194 @@
+/*
+ * 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.soam.loss;
+
+import static org.junit.Assert.*;
+
+import java.time.Duration;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.soam.MeasurementCreateBase.SessionType;
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+import org.onosproject.incubator.net.l2monitoring.soam.StartTime;
+import org.onosproject.incubator.net.l2monitoring.soam.StopTime;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DataPattern;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.TestTlvPattern;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.Version;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate.CounterOption;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate.LmCreateBuilder;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate.LmType;
+
+public class LossMeasurementCreateTest {
+
+ LossMeasurementCreate lmc1;
+
+ @Before
+ public void setUp() throws SoamConfigException {
+
+ LossMeasurementThreshold lmt1 = DefaultLmThreshold
+ .builder(SoamId.valueOf(4)).build();
+
+
+ LmCreateBuilder builder = (LmCreateBuilder) DefaultLmCreate
+ .builder(Version.Y17312008, MepId.valueOf((short) 10),
+ Priority.PRIO3, LmType.LMLMM)
+ .addToCountersEnabled(CounterOption.AVAILABILITY_FORWARD_AVERAGE_FLR)
+ .addToCountersEnabled(CounterOption.AVAILABILITY_FORWARD_CONSECUTIVE_HIGH_LOSS)
+ .availabilityFlrThreshold(MilliPct.ofRatio(0.201f))
+ .availabilityMeasurementInterval(Duration.ofSeconds(5))
+ .availabilityNumberConsecutiveFlrMeasurements(6)
+ .availabilityNumberConsecutiveHighFlr((short) 7)
+ .availabilityNumberConsecutiveIntervals((short) 8)
+ .addToLossMeasurementThreshold(lmt1)
+ .frameSize((short) 100)
+ .dataPattern(DataPattern.ZEROES)
+ .testTlvIncluded(true)
+ .testTlvPattern(TestTlvPattern.NULL_SIGNAL_WITHOUT_CRC_32)
+ .messagePeriod(Duration.ofMinutes(9))
+ .measurementInterval(Duration.ofMinutes(10))
+ .numberIntervalsStored((short) 11)
+ .alignMeasurementIntervals(true)
+ .alignMeasurementOffset(Duration.ofSeconds(12))
+ .startTime(StartTime.immediate())
+ .stopTime(StopTime.none())
+ .sessionType(SessionType.PROACTIVE);
+
+ lmc1 = builder.build();
+ }
+
+ @Test
+ public void testLmCfgType() {
+ assertEquals(LmType.LMLMM, lmc1.lmCfgType());
+ }
+
+ @Test
+ public void testCountersEnabled() {
+ assertEquals(2, lmc1.countersEnabled().size());
+ }
+
+ @Test
+ public void testAvailabilityMeasurementInterval() {
+ assertEquals(5, lmc1.availabilityMeasurementInterval().getSeconds());
+ }
+
+ @Test
+ public void testAvailabilityNumberConsecutiveFlrMeasurements() {
+ assertEquals(6, lmc1.availabilityNumberConsecutiveFlrMeasurements().intValue());
+ }
+
+ @Test
+ public void testAvailabilityFlrThreshold() {
+ assertEquals(0.201f, lmc1.availabilityFlrThreshold().ratioValue(), 0.0001f);
+ }
+
+ @Test
+ public void testAvailabilityNumberConsecutiveIntervals() {
+ assertEquals(8, lmc1.availabilityNumberConsecutiveIntervals().shortValue());
+ }
+
+ @Test
+ public void testAvailabilityNumberConsecutiveHighFlr() {
+ assertEquals(7, lmc1.availabilityNumberConsecutiveHighFlr().shortValue());
+ }
+
+ @Test
+ public void testLossMeasurementThreshold() {
+ assertEquals(1, lmc1.lossMeasurementThreshold().size());
+ }
+
+ @Test
+ public void testVersion() {
+ assertEquals(Version.Y17312008, lmc1.version());
+ }
+
+ @Test
+ public void testRemoteMepId() {
+ assertEquals(10, lmc1.remoteMepId().id().shortValue());
+ }
+
+ @Test
+ public void testMessagePeriod() {
+ assertEquals(9, lmc1.messagePeriod().toMinutes());
+ }
+
+ @Test
+ public void testPriority() {
+ assertEquals(Priority.PRIO3, lmc1.priority());
+ }
+
+ @Test
+ public void testFrameSize() {
+ assertEquals(100, lmc1.frameSize().shortValue());
+ }
+
+ @Test
+ public void testDataPattern() {
+ assertEquals(DataPattern.ZEROES, lmc1.dataPattern());
+ }
+
+ @Test
+ public void testTestTlvIncluded() {
+ assertEquals(true, lmc1.testTlvIncluded());
+ }
+
+ @Test
+ public void testTestTlvPattern() {
+ assertEquals(TestTlvPattern.NULL_SIGNAL_WITHOUT_CRC_32, lmc1.testTlvPattern());
+ }
+
+ @Test
+ public void testMeasurementInterval() {
+ assertEquals(10, lmc1.measurementInterval().toMinutes());
+ }
+
+ @Test
+ public void testNumberIntervalsStored() {
+ assertEquals(11, lmc1.numberIntervalsStored().shortValue());
+ }
+
+ @Test
+ public void testAlignMeasurementIntervals() {
+ assertEquals(true, lmc1.alignMeasurementIntervals());
+ }
+
+ @Test
+ public void testAlignMeasurementOffset() {
+ assertEquals(12, lmc1.alignMeasurementOffset().getSeconds());
+ }
+
+ @Test
+ public void testStartTime() {
+ assertEquals(StartTime.immediate().option(),
+ lmc1.startTime().option());
+ }
+
+ @Test
+ public void testStopTime() {
+ assertEquals(StopTime.none().option(),
+ lmc1.stopTime().option());
+ }
+
+ @Test
+ public void testSessionType() {
+ assertEquals(SessionType.PROACTIVE, lmc1.sessionType());
+ }
+
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementEntryTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementEntryTest.java
new file mode 100644
index 0000000..30b637a
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementEntryTest.java
@@ -0,0 +1,158 @@
+/*
+ * 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.soam.loss;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.util.ArrayList;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.Version;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate.CounterOption;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate.LmType;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry.AvailabilityType;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry.LmEntryBuilder;
+
+public class LossMeasurementEntryTest {
+
+ LossMeasurementEntry lme1;
+
+ @Before
+ public void setUp() throws SoamConfigException {
+ LmEntryBuilder builder = DefaultLmEntry.builder(
+ Version.Y17312008, MepId.valueOf((short) 10),
+ Priority.PRIO3, LmType.LMLMM, SoamId.valueOf(1))
+ .measuredAvailabilityBackwardStatus(AvailabilityType.UNAVAILABLE)
+ .measuredAvailabilityForwardStatus(AvailabilityType.UNKNOWN)
+ .measuredBackwardFlr(MilliPct.ofMilliPct(1600))
+ .measuredBackwardLastTransitionTime(Instant.ofEpochSecond(123456L))
+ .measuredForwardFlr(MilliPct.ofMilliPct(1601))
+ .measuredForwardLastTransitionTime(Instant.ofEpochSecond(123457L))
+
+ .availabilityCurrent(DefaultLaStatCurrent.builder(
+ Duration.ofMinutes(9), false, Instant.ofEpochSecond(9876543))
+ .build())
+ .measurementCurrent(DefaultLmStatCurrent.builder(
+ Duration.ofMinutes(10), true, Instant.ofEpochSecond(9876544))
+ .build())
+
+ .addToAvailabilityHistories(DefaultLaStatHistory.builder(
+ Duration.ofMinutes(11), true, SoamId.valueOf(10),
+ Instant.ofEpochSecond(9876545))
+ .build())
+ .addToAvailabilityHistories(DefaultLaStatHistory.builder(
+ Duration.ofMinutes(12), true, SoamId.valueOf(11),
+ Instant.ofEpochSecond(9876546))
+ .build())
+
+ .addToMeasurementHistories(DefaultLmStatHistory.builder(
+ Duration.ofMinutes(13), true, SoamId.valueOf(12),
+ Instant.ofEpochSecond(9876547))
+ .build())
+ .addToMeasurementHistories(DefaultLmStatHistory.builder(
+ Duration.ofMinutes(14), true, SoamId.valueOf(13),
+ Instant.ofEpochSecond(9876548))
+ .build());
+
+ builder = (LmEntryBuilder) builder
+ .addToCountersEnabled(CounterOption.AVAILABILITY_BACKWARD_CONSECUTIVE_HIGH_LOSS)
+ .addToCountersEnabled(CounterOption.AVAILABILITY_FORWARD_MAX_FLR)
+ .alignMeasurementIntervals(true)
+ .frameSize((short) 100);
+
+ lme1 = builder.build();
+ }
+
+ @Test
+ public void testLmId() {
+ assertEquals(1, lme1.lmId().id().intValue());
+ }
+
+ @Test
+ public void testMeasuredForwardFlr() {
+ assertEquals(1601, lme1.measuredForwardFlr().intValue());
+ }
+
+ @Test
+ public void testMeasuredBackwardFlr() {
+ assertEquals(1600, lme1.measuredBackwardFlr().intValue());
+ }
+
+ @Test
+ public void testMeasuredAvailabilityForwardStatus() {
+ assertEquals(AvailabilityType.UNKNOWN, lme1.measuredAvailabilityForwardStatus());
+ }
+
+ @Test
+ public void testMeasuredAvailabilityBackwardStatus() {
+ assertEquals(AvailabilityType.UNAVAILABLE, lme1.measuredAvailabilityBackwardStatus());
+ }
+
+ @Test
+ public void testMeasuredForwardLastTransitionTime() {
+ assertEquals(123457L, lme1.measuredForwardLastTransitionTime().getEpochSecond());
+ }
+
+ @Test
+ public void testMeasuredBackwardLastTransitionTime() {
+ assertEquals(123456L, lme1.measuredBackwardLastTransitionTime().getEpochSecond());
+ }
+
+ @Test
+ public void testMeasurementCurrent() {
+ assertEquals(10, lme1.measurementCurrent().elapsedTime().toMinutes());
+ }
+
+ @Test
+ public void testMeasurementHistories() {
+ assertEquals(2, lme1.measurementHistories().size());
+ ArrayList<LossMeasurementStatHistory> histories = new ArrayList<>();
+ lme1.measurementHistories().forEach(histories::add);
+ assertEquals(14, histories.get(1).elapsedTime().toMinutes());
+ }
+
+ @Test
+ public void testAvailabilityCurrent() {
+ assertEquals(9, lme1.availabilityCurrent().elapsedTime().toMinutes());
+ }
+
+ @Test
+ public void testAvailabilityHistories() {
+ assertEquals(2, lme1.measurementHistories().size());
+ ArrayList<LossAvailabilityStatHistory> histories = new ArrayList<>();
+ lme1.availabilityHistories().forEach(histories::add);
+ assertEquals(11, histories.get(0).elapsedTime().toMinutes());
+ }
+
+ @Test
+ public void testLmCfgType() {
+ assertEquals(LmType.LMLMM, lme1.lmCfgType());
+ }
+
+ @Test
+ public void testAlignMeasurementIntervals() {
+ assertTrue(lme1.alignMeasurementIntervals());
+ }
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatCurrentTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatCurrentTest.java
new file mode 100644
index 0000000..76e8246
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatCurrentTest.java
@@ -0,0 +1,129 @@
+/*
+ * 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.soam.loss;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.time.Duration;
+import java.time.Instant;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatCurrent.LmStatCurrentBuilder;
+
+public class LossMeasurementStatCurrentTest {
+ LossMeasurementStatCurrent lmsc1;
+
+ @Before
+ public void setUp() {
+ LmStatCurrentBuilder builder = DefaultLmStatCurrent
+ .builder(Duration.ofMinutes(14),
+ true, Instant.ofEpochSecond(12345678L));
+ builder = (LmStatCurrentBuilder) builder
+ .backwardAverageFrameLossRatio(MilliPct.ofMilliPct(301))
+ .backwardMaxFrameLossRatio(MilliPct.ofMilliPct(302))
+ .backwardMinFrameLossRatio(MilliPct.ofMilliPct(303))
+ .backwardReceivedFrames(123456780L)
+ .backwardTransmittedFrames(123456781L)
+ .forwardAverageFrameLossRatio(MilliPct.ofMilliPct(304))
+ .forwardMaxFrameLossRatio(MilliPct.ofMilliPct(305))
+ .forwardMinFrameLossRatio(MilliPct.ofMilliPct(306))
+ .forwardReceivedFrames(123456782L)
+ .forwardTransmittedFrames(123456783L)
+ .soamPdusReceived(123456784L)
+ .soamPdusSent(123456785L);
+
+ lmsc1 = builder.build();
+ }
+
+ @Test
+ public void testStartTime() {
+ assertEquals(12345678L, lmsc1.startTime().getEpochSecond());
+ }
+
+ @Test
+ public void testElapsedTime() {
+ assertEquals(14, lmsc1.elapsedTime().toMinutes());
+ }
+
+ @Test
+ public void testSuspectStatus() {
+ assertTrue(lmsc1.suspectStatus());
+ }
+
+ @Test
+ public void testForwardTransmittedFrames() {
+ assertEquals(123456783L, lmsc1.forwardTransmittedFrames().longValue());
+ }
+
+ @Test
+ public void testForwardReceivedFrames() {
+ assertEquals(123456782L, lmsc1.forwardReceivedFrames().longValue());
+ }
+
+ @Test
+ public void testForwardMinFrameLossRatio() {
+ assertEquals(306, lmsc1.forwardMinFrameLossRatio().intValue());
+ }
+
+ @Test
+ public void testForwardMaxFrameLossRatio() {
+ assertEquals(305, lmsc1.forwardMaxFrameLossRatio().intValue());
+ }
+
+ @Test
+ public void testForwardAverageFrameLossRatio() {
+ assertEquals(304, lmsc1.forwardAverageFrameLossRatio().intValue());
+ }
+
+ @Test
+ public void testBackwardTransmittedFrames() {
+ assertEquals(123456781L, lmsc1.backwardTransmittedFrames().longValue());
+ }
+
+ @Test
+ public void testBackwardReceivedFrames() {
+ assertEquals(123456780L, lmsc1.backwardReceivedFrames().longValue());
+ }
+
+ @Test
+ public void testBackwardMinFrameLossRatio() {
+ assertEquals(303, lmsc1.backwardMinFrameLossRatio().intValue());
+ }
+
+ @Test
+ public void testBackwardMaxFrameLossRatio() {
+ assertEquals(302, lmsc1.backwardMaxFrameLossRatio().intValue());
+ }
+
+ @Test
+ public void testBackwardAverageFrameLossRatio() {
+ assertEquals(301, lmsc1.backwardAverageFrameLossRatio().intValue());
+ }
+
+ @Test
+ public void testSoamPdusSent() {
+ assertEquals(123456785L, lmsc1.soamPdusSent().longValue());
+ }
+
+ @Test
+ public void testSoamPdusReceived() {
+ assertEquals(123456784L, lmsc1.soamPdusReceived().longValue());
+ }
+
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatHistoryTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatHistoryTest.java
new file mode 100644
index 0000000..46de87c
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatHistoryTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.soam.loss;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.time.Duration;
+import java.time.Instant;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatHistory.LmStatHistoryBuilder;
+
+public class LossMeasurementStatHistoryTest {
+ LossMeasurementStatHistory lmsh1;
+
+ @Before
+ public void setUp() {
+ LmStatHistoryBuilder builder = DefaultLmStatHistory.builder(
+ Duration.ofMinutes(11), true, SoamId.valueOf(6),
+ Instant.ofEpochSecond(123456789L));
+
+ lmsh1 = builder.build();
+ }
+
+ @Test
+ public void testHistoryStatsId() {
+ assertEquals(6, lmsh1.historyStatsId().id().intValue());
+ }
+
+ @Test
+ public void testEndTime() {
+ assertEquals(123456789L, lmsh1.endTime().getEpochSecond());
+ }
+
+ @Test
+ public void testElapsedTime() {
+ assertEquals(11, lmsh1.elapsedTime().toMinutes());
+ }
+
+ @Test
+ public void testSuspectStatus() {
+ assertTrue(lmsh1.suspectStatus());
+ }
+
+}
diff --git a/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementThresholdOptionTest.java b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementThresholdOptionTest.java
new file mode 100644
index 0000000..0882268
--- /dev/null
+++ b/apps/cfm/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementThresholdOptionTest.java
@@ -0,0 +1,138 @@
+/*
+ * 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.soam.loss;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementThreshold.ThresholdOption;
+
+public class LossMeasurementThresholdOptionTest {
+
+ LossMeasurementThreshold lmt1;
+
+ @Before
+ public void setUp() throws Exception {
+ lmt1 = DefaultLmThreshold
+ .builder(SoamId.valueOf(4))
+ .addToThreshold(ThresholdOption.BACKWARD_CONSECUTIVE_HIGH_LOSS)
+ .addToThreshold(ThresholdOption.MAX_FLR_BACKWARD)
+ .averageFlrBackward(MilliPct.ofMilliPct(301))
+ .averageFlrForward(MilliPct.ofMilliPct(302))
+ .backwardAvailableRatio(MilliPct.ofMilliPct(303))
+ .backwardConsecutiveHighLoss(123451L)
+ .backwardHighLoss(123452L)
+ .backwardUnavailableCount(123453L)
+ .forwardAvailableRatio(MilliPct.ofMilliPct(304))
+ .forwardConsecutiveHighLoss(123454L)
+ .forwardHighLoss(123455L)
+ .forwardUnavailableCount(123456L)
+ .maxFlrBackward(MilliPct.ofMilliPct(305))
+ .maxFlrForward(MilliPct.ofMilliPct(306))
+ .measuredFlrBackward(MilliPct.ofMilliPct(307))
+ .measuredFlrForward(MilliPct.ofMilliPct(308))
+ .build();
+ }
+
+ @Test
+ public void testThresholdId() {
+ assertEquals(4, lmt1.thresholdId().id().intValue());
+ }
+
+ @Test
+ public void testThreshold() {
+ assertEquals(2, lmt1.thresholds().size());
+ ArrayList<ThresholdOption> list = new ArrayList<>();
+ lmt1.thresholds().forEach(list::add);
+ assertEquals(ThresholdOption.BACKWARD_CONSECUTIVE_HIGH_LOSS, list.get(0));
+ assertEquals(ThresholdOption.MAX_FLR_BACKWARD, list.get(1));
+ }
+
+ @Test
+ public void testMeasuredFlrForward() {
+ assertEquals(308, lmt1.measuredFlrForward().intValue());
+ }
+
+ @Test
+ public void testMaxFlrForward() {
+ assertEquals(306, lmt1.maxFlrForward().intValue());
+ }
+
+ @Test
+ public void testAverageFlrForward() {
+ assertEquals(302, lmt1.averageFlrForward().intValue());
+ }
+
+ @Test
+ public void testMeasuredFlrBackward() {
+ assertEquals(307, lmt1.measuredFlrBackward().intValue());
+ }
+
+ @Test
+ public void testMaxFlrBackward() {
+ assertEquals(305, lmt1.maxFlrBackward().intValue());
+ }
+
+ @Test
+ public void testAverageFlrBackward() {
+ assertEquals(301, lmt1.averageFlrBackward().intValue());
+ }
+
+ @Test
+ public void testForwardHighLoss() {
+ assertEquals(123455L, lmt1.forwardHighLoss().longValue());
+ }
+
+ @Test
+ public void testForwardConsecutiveHighLoss() {
+ assertEquals(123454L, lmt1.forwardConsecutiveHighLoss().longValue());
+ }
+
+ @Test
+ public void testBackwardHighLoss() {
+ assertEquals(123452L, lmt1.backwardHighLoss().longValue());
+ }
+
+ @Test
+ public void testBackwardConsecutiveHighLoss() {
+ assertEquals(123451L, lmt1.backwardConsecutiveHighLoss().longValue());
+ }
+
+ @Test
+ public void testForwardUnavailableCount() {
+ assertEquals(123456L, lmt1.forwardUnavailableCount().longValue());
+ }
+
+ @Test
+ public void testForwardAvailableRatio() {
+ assertEquals(304, lmt1.forwardAvailableRatio().intValue());
+ }
+
+ @Test
+ public void testBackwardUnavailableCount() {
+ assertEquals(123453L, lmt1.backwardUnavailableCount().longValue());
+ }
+
+ @Test
+ public void testBackwardAvailableRatio() {
+ assertEquals(303, lmt1.backwardAvailableRatio().intValue());
+ }
+}
diff --git a/apps/cfm/app/BUCK b/apps/cfm/app/BUCK
new file mode 100644
index 0000000..93d3d70
--- /dev/null
+++ b/apps/cfm/app/BUCK
@@ -0,0 +1,17 @@
+COMPILE_DEPS = [
+ '//lib:CORE_DEPS',
+ '//lib:KRYO',
+ '//core/store/serializers:onos-core-serializers',
+ '//apps/cfm/api:onos-apps-cfm-api',
+]
+
+TEST_DEPS = [
+ '//lib:TEST_ADAPTERS',
+ '//utils/osgi:onlab-osgi-tests',
+]
+
+osgi_jar_with_tests (
+ deps = COMPILE_DEPS,
+ test_deps = TEST_DEPS,
+)
+
diff --git a/apps/cfm/app/pom.xml b/apps/cfm/app/pom.xml
new file mode 100644
index 0000000..235182e
--- /dev/null
+++ b/apps/cfm/app/pom.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ~ Copyright 2017 Open Networking Laboratory ~ ~ 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-apps-cfm</artifactId>
+ <version>1.13.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>onos-apps-cfm-app</artifactId>
+ <packaging>bundle</packaging>
+ <version>1.13.0-SNAPSHOT</version>
+
+ <description>ONOS OSGi bundle archetype</description>
+ <url>http://onosproject.org</url>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-apps-cfm-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-core-common</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-core-common</artifactId>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onlab-junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onlab-osgi</artifactId>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-incubator-store</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-core-serializers</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
+
diff --git a/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMdManager.java b/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMdManager.java
new file mode 100644
index 0000000..b18d2f6
--- /dev/null
+++ b/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMdManager.java
@@ -0,0 +1,168 @@
+/*
+ * 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);
+ eventDispatcher.post(event);
+ }
+ }
+}
diff --git a/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMepManager.java b/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMepManager.java
new file mode 100644
index 0000000..e58a570
--- /dev/null
+++ b/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMepManager.java
@@ -0,0 +1,583 @@
+/*
+ * 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.onlab.util.Tools.groupedThreads;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+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.event.Event;
+import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain;
+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.identifier.MepKeyId;
+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.incubator.net.l2monitoring.cfm.service.MdEvent;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.MdListener;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.MepStore;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.MepStoreDelegate;
+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 InternalDeviceListener deviceListener = null;
+ private InternalMdListener mdListener = null;
+
+ @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 InternalEventHandler eventHandler = new InternalEventHandler();
+ private static final Object THREAD_SCHED_LOCK = new Object();
+ private static int numOfEventsQueued = 0;
+ private static int numOfEventsExecuted = 0;
+ private static int numOfHandlerExecution = 0;
+ private static int numOfHandlerScheduled = 0;
+
+ private ScheduledExecutorService executorService = Executors
+ .newScheduledThreadPool(1,
+ groupedThreads("CfmMepManager", "event-%d", log));
+
+ @SuppressWarnings("unused")
+ private static ScheduledFuture<?> eventHandlerFuture = null;
+ @SuppressWarnings("rawtypes")
+ private ConcurrentLinkedQueue<Event> eventQueue = new ConcurrentLinkedQueue<>();
+
+
+ private IdGenerator idGenerator;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected MepStore mepStore;
+
+ protected final MepStoreDelegate delegate = new InternalStoreDelegate();
+
+ @Activate
+ public void activate() {
+ mepStore.setDelegate(delegate);
+
+ deviceListener = new InternalDeviceListener();
+ deviceService.addListener(deviceListener);
+ mdListener = new InternalMdListener();
+ cfmMdService.addListener(mdListener);
+ eventDispatcher.addSink(CfmMepEvent.class, listenerRegistry);
+ idGenerator = coreService.getIdGenerator("mep-ids");
+ log.info("CFM MEP Manager Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ deviceService.removeListener(deviceListener);
+ cfmMdService.removeListener(mdListener);
+ eventDispatcher.removeSink(CfmMepEvent.class);
+ log.info("CFM MEP Manager Stopped");
+ mepStore.unsetDelegate(delegate);
+ deviceListener = null;
+ mdListener = null;
+ }
+
+ @Override
+ public Collection<MepEntry> getAllMeps(MdId mdName, MaIdShort maName)
+ throws CfmConfigException {
+ //Will throw IllegalArgumentException if ma does not exist
+ cfmMdService.getMaintenanceAssociation(mdName, maName);
+
+ Collection<Mep> mepStoreCollection = mepStore.getAllMeps();
+ Collection<MepEntry> mepEntryCollection = new ArrayList<>();
+
+ for (Mep mep : mepStoreCollection) {
+ 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 Collection<Mep> getAllMepsByDevice(DeviceId deviceId) throws CfmConfigException {
+ return mepStore.getMepsByDeviceId(deviceId);
+ }
+
+ @Override
+ public MepEntry getMep(MdId mdName, MaIdShort maName, MepId mepId) throws CfmConfigException {
+ MepKeyId key = new MepKeyId(mdName, maName, mepId);
+
+ //Will throw IllegalArgumentException if ma does not exist
+ cfmMdService.getMaintenanceAssociation(mdName, maName);
+
+ Optional<Mep> mepOptional = mepStore.getMep(key);
+ if (mepOptional.isPresent()) {
+ Mep mep = mepOptional.get();
+ 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);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public boolean deleteMep(MdId mdName, MaIdShort maName, MepId mepId,
+ Optional<MaintenanceDomain> oldMd) throws CfmConfigException {
+ MepKeyId key = new MepKeyId(mdName, maName, mepId);
+
+ //Will throw IllegalArgumentException if ma does not exist
+ cfmMdService.getMaintenanceAssociation(mdName, maName);
+
+ //Get the device ID from the MEP
+ Optional<Mep> deletedMep = mepStore.getMep(key);
+ if (!deletedMep.isPresent()) {
+ log.warn("MEP {} not found when deleting Mep", key);
+ return false;
+ }
+
+ DeviceId mepDeviceId = deletedMep.get().deviceId();
+ boolean deleted = mepStore.deleteMep(key);
+
+ Device mepDevice = deviceService.getDevice(mepDeviceId);
+ if (mepDevice == null || !mepDevice.is(CfmMepProgrammable.class)) {
+ throw new CfmConfigException("Unexpeced fault on device driver for "
+ + mepDeviceId);
+ }
+ try {
+ deleted = mepDevice.as(CfmMepProgrammable.class)
+ .deleteMep(mdName, maName, mepId, oldMd);
+ } catch (CfmConfigException e) {
+ log.warn("MEP could not be deleted on device - perhaps it "
+ + "does not exist. Continuing");
+ }
+
+ //Iterate through all other devices and remove as a Remote Mep
+ int mepsOnMdCount = 0;
+ int mepsOnMaCount = 0;
+ for (Mep mep : mepStore.getAllMeps()) {
+ if (mep.deviceId().equals(mepDeviceId) && mdName.equals(mep.mdId())) {
+ mepsOnMdCount++;
+ if (maName.equals(mep.maId())) {
+ mepsOnMaCount++;
+ }
+ }
+ List<DeviceId> alreadyHandledDevices = new ArrayList<>();
+ if (mep.deviceId().equals(mepDeviceId) || !mep.mdId().equals(mdName) ||
+ !mep.maId().equals(maName) ||
+ alreadyHandledDevices.contains(mep.deviceId())) {
+ continue;
+ }
+ deviceService.getDevice(mep.deviceId())
+ .as(CfmMepProgrammable.class)
+ .deleteMaRemoteMepOnDevice(mdName, maName, mepId);
+ alreadyHandledDevices.add(mep.deviceId());
+ log.info("Deleted RMep entry on {} on device {}",
+ mdName.mdName() + "/" + maName.maName(), mep.deviceId());
+ }
+
+ //Also if this is the last MEP in this MA then delete this MA from device
+ //If this is the last MA in this MD on device, then delete the MD from the device
+ if (mepsOnMdCount == 0) {
+ boolean deletedMd = deviceService.getDevice(mepDeviceId)
+ .as(CfmMepProgrammable.class).deleteMdOnDevice(mdName, oldMd);
+ log.info("Deleted MD {} from Device {}", mdName.mdName(), mepDeviceId);
+ } else if (mepsOnMaCount == 0) {
+ boolean deletedMa = deviceService.getDevice(mepDeviceId)
+ .as(CfmMepProgrammable.class).deleteMaOnDevice(mdName, maName, oldMd);
+ log.info("Deleted MA {} from Device {}",
+ mdName.mdName() + "/" + maName.maName(), mepDeviceId);
+ }
+
+ return deleted;
+ }
+
+ @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;
+ }
+ }
+
+ @Override
+ public void transmitLoopback(MdId mdName, MaIdShort maName,
+ MepId mepId, MepLbCreate lbCreate) throws CfmConfigException {
+ MepKeyId key = new MepKeyId(mdName, maName, mepId);
+ Mep mep = mepStore.getMep(key)
+ .orElseThrow(() -> new CfmConfigException("Mep " + mdName + "/" + maName + "/"
+ + mepId + " not found when calling Transmit Loopback"));
+
+ log.debug("Transmitting Loopback on MEP {} on Device {}",
+ key, mep.deviceId());
+ deviceService.getDevice(mep.deviceId())
+ .as(CfmMepProgrammable.class)
+ .transmitLoopback(mdName, maName, mepId, lbCreate);
+ }
+
+ @Override
+ public void abortLoopback(MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException {
+
+ MepKeyId key = new MepKeyId(mdName, maName, mepId);
+ Mep mep = mepStore.getMep(key)
+ .orElseThrow(() -> new CfmConfigException("Mep " + mdName + "/" + maName + "/"
+ + mepId + " not found when calling Aborting Loopback"));
+
+ log.debug("Aborting Loopback on MEP {} on Device {}",
+ key, mep.deviceId());
+ deviceService.getDevice(mep.deviceId())
+ .as(CfmMepProgrammable.class)
+ .abortLoopback(mdName, maName, mepId);
+ }
+
+ @Override
+ public void transmitLinktrace(MdId mdName, MaIdShort maName, MepId mepId,
+ MepLtCreate ltCreate) {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ private class InternalMdListener implements MdListener {
+ @Override
+ public boolean isRelevant(MdEvent event) {
+ return event.type().equals(MdEvent.Type.MD_REMOVED) ||
+ event.type().equals(MdEvent.Type.MA_REMOVED);
+ }
+
+ @Override
+ public void event(MdEvent event) {
+ MdId mdName = event.subject();
+ switch (event.type()) {
+ case MA_REMOVED:
+ case MD_REMOVED:
+ log.trace("Event {} receieved from MD Service for {}", event.type(), mdName);
+ scheduleEventHandlerIfNotScheduled(event);
+ break;
+ default:
+ log.warn("Unhandled Event {} received from MD Service", event.type());
+ break;
+ }
+ }
+ }
+
+ private class InternalDeviceListener implements DeviceListener {
+ @Override
+ public boolean isRelevant(DeviceEvent event) {
+ return event.type().equals(DeviceEvent.Type.DEVICE_REMOVED);
+ }
+
+ @Override
+ public void event(DeviceEvent event) {
+ DeviceId deviceId = event.subject().id();
+ switch (event.type()) {
+ case DEVICE_ADDED:
+ case PORT_UPDATED:
+ case PORT_ADDED:
+ case DEVICE_UPDATED:
+ case DEVICE_REMOVED:
+ case DEVICE_AVAILABILITY_CHANGED:
+ log.trace("Event {} received from Device Service", event.type());
+ scheduleEventHandlerIfNotScheduled(event);
+ break;
+ default:
+ log.warn("Unhandled Event {} received from Device Service", event.type());
+ break;
+ }
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ private void scheduleEventHandlerIfNotScheduled(Event event) {
+ synchronized (THREAD_SCHED_LOCK) {
+ eventQueue.add(event);
+ numOfEventsQueued++;
+
+ if ((numOfHandlerScheduled - numOfHandlerExecution) == 0) {
+ //No pending scheduled event handling threads. So start a new one.
+ eventHandlerFuture = executorService
+ .schedule(eventHandler, 100, TimeUnit.MILLISECONDS);
+ numOfHandlerScheduled++;
+ }
+ log.trace("numOfEventsQueued {}, numOfEventHandlerScheduled {}",
+ numOfEventsQueued,
+ numOfHandlerScheduled);
+ }
+ }
+
+ private class InternalEventHandler implements Runnable {
+ @Override
+ public void run() {
+ try {
+ while (true) {
+ @SuppressWarnings("rawtypes")
+ Event event;
+ synchronized (THREAD_SCHED_LOCK) {
+ if (!eventQueue.isEmpty()) {
+ event = eventQueue.poll();
+ numOfEventsExecuted++;
+ } else {
+ numOfHandlerExecution++;
+ log.debug("numOfHandlerExecution {} numOfEventsExecuted {}",
+ numOfHandlerExecution, numOfEventsExecuted);
+ break;
+ }
+ }
+ if (event.type() == DeviceEvent.Type.DEVICE_REMOVED) {
+ DeviceId deviceId = ((Device) event.subject()).id();
+ log.info("Processing device removal event for unavailable device {}",
+ deviceId);
+ processDeviceRemoved((Device) event.subject());
+ } else if (event.type() == MdEvent.Type.MD_REMOVED) {
+ MdId mdName = (MdId) event.subject();
+ log.info("Processing MD removal event for MD {}",
+ mdName);
+ processMdRemoved(mdName, ((MdEvent) event).md().get());
+ } else if (event.type() == MdEvent.Type.MA_REMOVED) {
+ MdId mdName = (MdId) event.subject();
+ MaIdShort maName = ((MdEvent) event).maId().get();
+ log.info("Processing MA removal event for MA {}",
+ mdName.mdName() + "/" + maName.maName());
+ processMaRemoved(mdName, maName, ((MdEvent) event).md().get());
+ }
+ }
+ } catch (Exception e) {
+ log.error("CfmMepService event handler "
+ + "thread thrown an exception: {}", e);
+ }
+ }
+ }
+
+ /**
+ * This removes a MEP from the internal list of Meps, and updates remote meps list on other Meps.
+ * Note: This does not call the device's CfmMepProgrammable, because there
+ * would be no point as the device has already been removed from ONOS.
+ * The configuration for this MEP may still be present on the actual device, and
+ * any future config would have to be careful to wipe the Mep from the device
+ * before applying a Mep again
+ * @param removedDevice The device that has been removed
+ */
+ protected void processDeviceRemoved(Device removedDevice) {
+ log.warn("Remove Mep(s) associated with Device: " + removedDevice.id());
+ Collection<Mep> mepListForDevice = mepStore.getMepsByDeviceId(removedDevice.id());
+
+
+ for (Mep mep:mepStore.getAllMeps()) {
+ for (Mep mepForDevice:mepListForDevice) {
+ if (mep.mdId().equals(mepForDevice.mdId()) && mep.maId().equals(mepForDevice.maId())) {
+ Device mepDevice = deviceService.getDevice(mep.deviceId());
+ log.info("Removing Remote Mep {} from MA{} on device {}",
+ mepForDevice.mepId(),
+ mep.mdId().mdName() + "/" + mep.maId().maName(),
+ mepDevice.id());
+ try {
+ mepDevice.as(CfmMepProgrammable.class)
+ .deleteMaRemoteMepOnDevice(mep.mdId(), mep.maId(), mepForDevice.mepId());
+ } catch (CfmConfigException e) {
+ log.error("Error when removing Remote Mep {} from MA {}. Continuing.",
+ mep.mdId().mdName() + "/" + mep.maId().maName(),
+ mepForDevice.mepId());
+ }
+ }
+ }
+ }
+
+ for (Iterator<Mep> iter = mepListForDevice.iterator(); iter.hasNext();) {
+ mepStore.deleteMep(new MepKeyId(iter.next()));
+ }
+ }
+
+ protected void processMaRemoved(MdId mdId, MaIdShort maId, MaintenanceDomain oldMd) {
+ Set<DeviceId> deviceIdsRemoved = new HashSet<>();
+
+ for (Iterator<Mep> iter = mepStore.getMepsByMdMa(mdId, maId).iterator(); iter.hasNext();) {
+ Mep mepForMdMa = iter.next();
+ DeviceId mepDeviceId = mepForMdMa.deviceId();
+ try {
+ deviceService.getDevice(mepDeviceId).as(CfmMepProgrammable.class)
+ .deleteMep(mdId, maId, mepForMdMa.mepId(), Optional.of(oldMd));
+ deviceIdsRemoved.add(mepDeviceId);
+ } catch (CfmConfigException e) {
+ log.warn("Could not delete MEP {} from Device {}", mepForMdMa.mepId(), mepDeviceId, e);
+ }
+ iter.remove();
+
+ log.info("Removed MEP {} from Device {} because MA {} was deleted",
+ mepForMdMa.mepId(), mepDeviceId, mdId.mdName() + "/" + maId.maName());
+ }
+
+ deviceIdsRemoved.forEach(deviceId -> {
+ try {
+ deviceService.getDevice(deviceId).as(CfmMepProgrammable.class)
+ .deleteMaOnDevice(mdId, maId, Optional.of(oldMd));
+ } catch (CfmConfigException e) {
+ log.warn("Could not delete MA {} from Device {}",
+ mdId.mdName() + "/" + maId.maName(), deviceId, e);
+ }
+ });
+ }
+
+ protected void processMdRemoved(MdId mdId, MaintenanceDomain oldMd) {
+ Set<DeviceId> deviceIdsRemoved = new HashSet<>();
+ for (Iterator<Mep> iter = mepStore.getMepsByMd(mdId).iterator(); iter.hasNext();) {
+ Mep mep = iter.next();
+ DeviceId mepDeviceId = mep.deviceId();
+ try {
+ deviceService.getDevice(mepDeviceId).as(CfmMepProgrammable.class)
+ .deleteMep(mdId, mep.maId(), mep.mepId(), Optional.of(oldMd));
+ deviceIdsRemoved.add(mepDeviceId);
+ } catch (CfmConfigException e) {
+ log.warn("Could not delete MEP {} from Device {}", mep.mepId(), mepDeviceId, e);
+ }
+ iter.remove();
+ log.info("Removed MEP {} from Device {} because MD {} was deleted",
+ mep.mepId(), mepDeviceId, mdId.mdName());
+ }
+
+ deviceIdsRemoved.forEach(deviceId -> {
+ try {
+ deviceService.getDevice(deviceId).as(CfmMepProgrammable.class)
+ .deleteMdOnDevice(mdId, Optional.of(oldMd));
+ } catch (CfmConfigException e) {
+ log.warn("Could not delete MD {} from Device {}",
+ mdId.mdName(), deviceId, e);
+ }
+ });
+ }
+
+ private class InternalStoreDelegate implements MepStoreDelegate {
+ @Override
+ public void notify(CfmMepEvent event) {
+ log.debug("New Mep event: {}", event);
+ eventDispatcher.post(event);
+ }
+ }
+}
diff --git a/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/DistributedMdStore.java b/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/DistributedMdStore.java
new file mode 100644
index 0000000..82c550d
--- /dev/null
+++ b/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/DistributedMdStore.java
@@ -0,0 +1,218 @@
+/*
+ * 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.Deactivate;
+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.CfmConfigException;
+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;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * 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 MapEventListener<MdId, MaintenanceDomain> mapListener = null;
+
+ @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();
+ mapListener = new InternalMdListener();
+ maintenanceDomainConsistentMap.addListener(mapListener);
+
+ maintenanceDomainMap = maintenanceDomainConsistentMap.asJavaMap();
+ log.info("MDStore started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ maintenanceDomainConsistentMap.removeListener(mapListener);
+ log.info("Stopped");
+ }
+
+ @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;
+ MaIdShort maId = null;
+ switch (mapEvent.type()) {
+ case INSERT:
+ type = MdEvent.Type.MD_ADDED;
+ break;
+ case UPDATE:
+ // Examine the diff to see if it was a removal or addition of an MA caused it
+ if (mapEvent.oldValue().value().maintenanceAssociationList().size() >
+ mapEvent.newValue().value().maintenanceAssociationList().size()) {
+ Set<MaIdShort> newMaIds = mapEvent.newValue().value().maintenanceAssociationList()
+ .stream()
+ .map(MaintenanceAssociation::maId)
+ .collect(Collectors.toSet());
+ Optional<MaintenanceAssociation> removedMa =
+ mapEvent.oldValue().value().maintenanceAssociationList()
+ .stream()
+ .filter(maOld -> !newMaIds.contains(maOld.maId())).findFirst();
+ if (removedMa.isPresent()) {
+ maId = removedMa.get().maId();
+ }
+ type = MdEvent.Type.MA_REMOVED;
+ } else if (mapEvent.oldValue().value().maintenanceAssociationList().size() <
+ mapEvent.newValue().value().maintenanceAssociationList().size()) {
+ Set<MaIdShort> oldMaIds = mapEvent.oldValue().value().maintenanceAssociationList()
+ .stream()
+ .map(MaintenanceAssociation::maId)
+ .collect(Collectors.toSet());
+ Optional<MaintenanceAssociation> addedMa =
+ mapEvent.newValue().value().maintenanceAssociationList()
+ .stream()
+ .filter(maNew -> !oldMaIds.contains(maNew.maId())).findFirst();
+ if (addedMa.isPresent()) {
+ maId = addedMa.get().maId();
+ }
+ type = MdEvent.Type.MA_ADDED;
+ } else {
+ type = MdEvent.Type.MD_UPDATED;
+ }
+ break;
+ case REMOVE:
+ default:
+ type = MdEvent.Type.MD_REMOVED;
+ break;
+ }
+ if (mapEvent.oldValue() != null && mapEvent.oldValue().value() != null) {
+ MaintenanceDomain oldMd = mapEvent.oldValue().value();
+ try {
+ if (maId != null) {
+ notifyDelegate(new MdEvent(type, mapEvent.key(), oldMd, maId));
+ } else {
+ notifyDelegate(new MdEvent(type, mapEvent.key(), oldMd));
+ }
+ } catch (CfmConfigException e) {
+ log.warn("Unable to copy MD {}", oldMd);
+ notifyDelegate(new MdEvent(type, mapEvent.key()));
+ }
+ } else {
+ notifyDelegate(new MdEvent(type, mapEvent.key()));
+ }
+ }
+ }
+}
diff --git a/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/DistributedMepStore.java b/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/DistributedMepStore.java
new file mode 100644
index 0000000..c21166a
--- /dev/null
+++ b/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/DistributedMepStore.java
@@ -0,0 +1,193 @@
+/*
+ * 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 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.onlab.packet.IpAddress;
+import org.onlab.packet.VlanId;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep;
+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.identifier.MepKeyId;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepEvent;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.MepStore;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.MepStoreDelegate;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.NetworkResource;
+import org.onosproject.net.PortNumber;
+import org.onosproject.store.AbstractStore;
+import org.onosproject.store.serializers.KryoNamespaces;
+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.time.Duration;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * MEP Store implementation backed by consistent map.
+ */
+@Component(immediate = true)
+@Service
+public class DistributedMepStore extends AbstractStore<CfmMepEvent, MepStoreDelegate>
+ implements MepStore {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected StorageService storageService;
+
+ private ConsistentMap<MepKeyId, Mep> mepConsistentMap;
+ private Map<MepKeyId, Mep> mepMap;
+
+ private MapEventListener<MepKeyId, Mep> mapListener = null;
+
+ @Activate
+ public void activate() {
+ mepConsistentMap = storageService
+ .<MepKeyId, Mep>consistentMapBuilder()
+ .withName("onos-cfm-mep-map")
+ .withSerializer(Serializer.using(new KryoNamespace.Builder()
+ .register(KryoNamespaces.API)
+ .register(DefaultMep.class)
+ .register(MepId.class)
+ .register(MepKeyId.class)
+ .register(NetworkResource.class)
+ .register(DeviceId.class)
+ .register(PortNumber.class)
+ .register(Mep.MepDirection.class)
+ .register(VlanId.class)
+ .register(Mep.Priority.class)
+ .register(Mep.FngAddress.class)
+ .register(Mep.FngAddressType.class)
+ .register(IpAddress.class)
+ .register(Mep.LowestFaultDefect.class)
+ .register(Duration.class)
+ .register(MdIdCharStr.class)
+ .register(MdIdDomainName.class)
+ .register(MdIdMacUint.class)
+ .register(MdIdNone.class)
+ .register(MaIdCharStr.class)
+ .register(MaIdShort.class)
+ .register(MaId2Octet.class)
+ .register(MaIdIccY1731.class)
+ .register(MaIdPrimaryVid.class)
+ .register(MaIdRfc2685VpnId.class)
+ .build("mep")))
+ .build();
+ mapListener = new InternalMepListener();
+ mepConsistentMap.addListener(mapListener);
+
+ mepMap = mepConsistentMap.asJavaMap();
+ log.info("MepStore started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ mepConsistentMap.removeListener(mapListener);
+ log.info("MepStore stopped");
+ }
+
+ @Override
+ public Collection<Mep> getAllMeps() {
+ return mepMap.values();
+ }
+
+ @Override
+ public Collection<Mep> getMepsByMd(MdId mdName) {
+ return mepMap.values().stream()
+ .filter(mep -> mep.mdId().equals(mdName))
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Collection<Mep> getMepsByMdMa(MdId mdName, MaIdShort maName) {
+ return mepMap.values().stream()
+ .filter(mep -> mep.mdId().equals(mdName) && mep.maId().equals(maName))
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Collection<Mep> getMepsByDeviceId(DeviceId deviceId) {
+ return mepMap.values().stream()
+ .filter(mep -> mep.deviceId().equals(deviceId))
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Optional<Mep> getMep(MepKeyId mepKeyId) {
+ return mepMap.values().stream()
+ .filter(mep -> mep.mdId().equals(mepKeyId.mdId()) &&
+ mep.maId().equals(mepKeyId.maId()) &&
+ mep.mepId().equals(mepKeyId.mepId()))
+ .findFirst();
+ }
+
+ @Override
+ public boolean deleteMep(MepKeyId mepKeyId) {
+ return mepMap.remove(mepKeyId) == null ? false : true;
+ }
+
+ @Override
+ public boolean createUpdateMep(MepKeyId mepKeyId, Mep mep) {
+ return mepMap.put(mepKeyId, mep) == null ? false : true;
+ }
+
+ private class InternalMepListener implements MapEventListener<MepKeyId, Mep> {
+
+ @Override
+ public void event(MapEvent<MepKeyId, Mep> mapEvent) {
+ final CfmMepEvent.Type type;
+
+ switch (mapEvent.type()) {
+ case INSERT:
+ type = CfmMepEvent.Type.MEP_ADDED;
+ break;
+ case UPDATE:
+ type = CfmMepEvent.Type.MEP_UPDATED;
+ break;
+ default:
+ case REMOVE:
+ type = CfmMepEvent.Type.MEP_REMOVED;
+ }
+ notifyDelegate(new CfmMepEvent(type, mapEvent.key()));
+ }
+ }
+}
diff --git a/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/package-info.java b/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/package-info.java
new file mode 100644
index 0000000..3542f07
--- /dev/null
+++ b/apps/cfm/app/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
diff --git a/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/impl/SoamManager.java b/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/impl/SoamManager.java
new file mode 100644
index 0000000..ca8a373
--- /dev/null
+++ b/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/impl/SoamManager.java
@@ -0,0 +1,284 @@
+/*
+ * 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.soam.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.incubator.net.l2monitoring.cfm.MepEntry;
+import org.onosproject.incubator.net.l2monitoring.cfm.MepTsCreate;
+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.CfmMepService;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamDmProgrammable;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamService;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatCurrent;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatHistory;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatCurrent;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.device.DeviceService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ONOS application component.
+ */
+@Component(immediate = true)
+@Service
+public class SoamManager implements SoamService {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ private static final String APP_ID = "org.onosproject.app.soam";
+
+ private ApplicationId appId;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceService deviceService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CfmMepService cfmMepService;
+
+ @Activate
+ protected void activate() {
+ appId = coreService.registerApplication(APP_ID);
+
+ log.info("SOAM Service Started");
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ log.info("SOAM Service Stopped");
+ }
+
+ @Override
+ public Collection<DelayMeasurementEntry> getAllDms(
+ MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException, SoamConfigException {
+ MepEntry mep = cfmMepService.getMep(mdName, maName, mepId);
+ if (mep == null || mep.deviceId() == null) {
+ throw new CfmConfigException("MEP :"
+ + mdName + "/" + maName + "/" + mepId + " does not exist");
+ } else if (deviceService.getDevice(mep.deviceId()) == null) {
+ throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :"
+ + mdName + "/" + maName + "/" + mepId + " does not exist");
+ } else if (!deviceService.getDevice(mep.deviceId()).is(SoamDmProgrammable.class)) {
+ throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :"
+ + mdName + "/" + maName + "/" + mepId +
+ " does not implement SoamDmProgrammable");
+ }
+ log.debug("Retrieving DMs for MD {}, MA {}, MEP {} on Device {}",
+ mdName, maName, mepId, mep.deviceId());
+
+ return deviceService.getDevice(mep.deviceId())
+ .as(SoamDmProgrammable.class).getAllDms(mdName, maName, mepId);
+ };
+
+ @Override
+ public DelayMeasurementEntry getDm(MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId)
+ throws CfmConfigException, SoamConfigException {
+ MepEntry mep = cfmMepService.getMep(mdName, maName, mepId);
+ if (mep == null || mep.deviceId() == null) {
+ throw new CfmConfigException("MEP :"
+ + mdName + "/" + maName + "/" + mepId + " does not exist");
+ } else if (deviceService.getDevice(mep.deviceId()) == null) {
+ throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :"
+ + mdName + "/" + maName + "/" + mepId + " does not exist");
+ } else if (!deviceService.getDevice(mep.deviceId()).is(SoamDmProgrammable.class)) {
+ throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :"
+ + mdName + "/" + maName + "/" + mepId +
+ " does not implement SoamDmProgrammable");
+ }
+ log.debug("Retrieving DM for DM {} in MD {}, MA {}, MEP {} on Device {}",
+ dmId, mdName, maName, mepId, mep.deviceId());
+ return deviceService.getDevice(mep.deviceId())
+ .as(SoamDmProgrammable.class).getDm(mdName, maName, mepId, dmId);
+ }
+
+ @Override
+ public DelayMeasurementStatCurrent getDmCurrentStat(MdId mdName,
+ MaIdShort maName, MepId mepId, SoamId dmId)
+ throws CfmConfigException, SoamConfigException {
+ MepEntry mep = cfmMepService.getMep(mdName, maName, mepId);
+ if (mep == null || mep.deviceId() == null) {
+ throw new CfmConfigException("MEP :"
+ + mdName + "/" + maName + "/" + mepId + " does not exist");
+ } else if (deviceService.getDevice(mep.deviceId()) == null) {
+ throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :"
+ + mdName + "/" + maName + "/" + mepId + " does not exist");
+ } else if (!deviceService.getDevice(mep.deviceId()).is(SoamDmProgrammable.class)) {
+ throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :"
+ + mdName + "/" + maName + "/" + mepId +
+ " does not implement SoamDmProgrammable");
+ }
+ log.debug("Retrieving Current Stats for DM {} in MD {}, MA {}, MEP {} "
+ + "on Device {}", dmId, mdName, maName, mepId, mep.deviceId());
+ return deviceService.getDevice(mep.deviceId())
+ .as(SoamDmProgrammable.class).getDmCurrentStat(mdName, maName, mepId, dmId);
+ }
+
+ @Override
+ public Collection<DelayMeasurementStatHistory> getDmHistoricalStats(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId)
+ throws SoamConfigException, CfmConfigException {
+ MepEntry mep = cfmMepService.getMep(mdName, maName, mepId);
+ if (mep == null || mep.deviceId() == null) {
+ throw new CfmConfigException("MEP :"
+ + mdName + "/" + maName + "/" + mepId + " does not exist");
+ } else if (deviceService.getDevice(mep.deviceId()) == null) {
+ throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :"
+ + mdName + "/" + maName + "/" + mepId + " does not exist");
+ } else if (!deviceService.getDevice(mep.deviceId()).is(SoamDmProgrammable.class)) {
+ throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :"
+ + mdName + "/" + maName + "/" + mepId +
+ " does not implement SoamDmProgrammable");
+ }
+ log.debug("Retrieving History Stats for DM {} in MD {}, MA {}, MEP {} "
+ + "on Device {}", dmId, mdName, maName, mepId, mep.deviceId());
+ return deviceService.getDevice(mep.deviceId())
+ .as(SoamDmProgrammable.class).getDmHistoricalStats(mdName, maName, mepId, dmId);
+ }
+
+ @Override
+ public Optional<SoamId> createDm(MdId mdName, MaIdShort maName, MepId mepId,
+ DelayMeasurementCreate dmNew)
+ throws CfmConfigException, SoamConfigException {
+ DeviceId mepDeviceId = cfmMepService.getMep(mdName, maName, mepId).deviceId();
+ if (mepDeviceId == null) {
+ throw new CfmConfigException("Unable to create DM. MEP :"
+ + mdName + "/" + maName + "/" + mepId + " does not exist");
+ } else if (deviceService.getDevice(mepDeviceId) == null) {
+ throw new CfmConfigException("Device " + mepDeviceId + " from MEP :"
+ + mdName + "/" + maName + "/" + mepId + " does not exist");
+ } else if (!deviceService.getDevice(mepDeviceId).is(SoamDmProgrammable.class)) {
+ throw new CfmConfigException("Device " + mepDeviceId + " from MEP :"
+ + mdName + "/" + maName + "/" + mepId +
+ " does not implement SoamDmProgrammable");
+ }
+ log.debug("Creating new DM in MD {}, MA {}, MEP {} on Device {}",
+ mdName, maName, mepId, mepDeviceId);
+ return deviceService.getDevice(mepDeviceId)
+ .as(SoamDmProgrammable.class).createDm(mdName, maName, mepId, dmNew);
+ }
+
+ @Override
+ public void abortDm(MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public void abortDm(MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId)
+ throws CfmConfigException {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public void clearDelayHistoryStats(MdId mdName, MaIdShort maName,
+ MepId mepId) throws CfmConfigException {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public void clearDelayHistoryStats(MdId mdName, MaIdShort maName,
+ MepId mepId, SoamId dmId) throws CfmConfigException {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public Collection<LossMeasurementEntry> getAllLms(MdId mdName,
+ MaIdShort maName, MepId mepId) throws CfmConfigException {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public LossMeasurementEntry getLm(MdId mdName, MaIdShort maName,
+ MepId mepId, SoamId lmId) throws CfmConfigException {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public LossMeasurementStatCurrent getLmCurrentStat(MdId mdName,
+ MaIdShort maName, MepId mepId, SoamId lmId) {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public Collection<LossMeasurementStatCurrent> getLmHistoricalStats(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public Optional<SoamId> createLm(MdId mdName, MaIdShort maName, MepId mepId,
+ LossMeasurementCreate lm) throws CfmConfigException {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public void abortLm(MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public void abortLm(MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId)
+ throws CfmConfigException {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public void clearLossHistoryStats(MdId mdName, MaIdShort maName,
+ MepId mepId) throws CfmConfigException {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public void clearLossHistoryStats(MdId mdName, MaIdShort maName,
+ MepId mepId, SoamId lmId) throws CfmConfigException {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public void createTestSignal(MdId mdName, MaIdShort maName, MepId mepId,
+ MepTsCreate tsCreate) throws CfmConfigException {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public void abortTestSignal(MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+}
diff --git a/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/impl/package-info.java b/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/impl/package-info.java
new file mode 100644
index 0000000..fd932e0
--- /dev/null
+++ b/apps/cfm/app/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/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 Service Operations and Maintenance (SOAM).
+ */
+package org.onosproject.incubator.net.l2monitoring.soam.impl;
\ No newline at end of file
diff --git a/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMdManagerTest.java b/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMdManagerTest.java
new file mode 100644
index 0000000..fa79546
--- /dev/null
+++ b/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMdManagerTest.java
@@ -0,0 +1,396 @@
+/*
+ * 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.collect.Sets;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.junit.TestUtils;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cluster.ClusterServiceAdapter;
+import org.onosproject.cluster.ControllerNode;
+import org.onosproject.cluster.DefaultControllerNode;
+import org.onosproject.cluster.NodeId;
+import org.onosproject.common.event.impl.TestEventDispatcher;
+import org.onosproject.core.CoreServiceAdapter;
+import org.onosproject.core.DefaultApplicationId;
+import org.onosproject.core.IdGenerator;
+import org.onosproject.incubator.net.l2monitoring.cfm.Component;
+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.MaIdCharStr;
+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.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.CfmMepService;
+import org.onosproject.mastership.MastershipServiceAdapter;
+import org.onosproject.net.DeviceId;
+import org.onosproject.store.service.TestStorageService;
+
+import java.util.Collection;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static junit.framework.TestCase.assertFalse;
+import static org.easymock.EasyMock.createMock;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.onosproject.net.NetTestTools.injectEventDispatcher;
+
+/**
+ * CFM MD Manager test.
+ */
+public class CfmMdManagerTest {
+ private static final NodeId NID_LOCAL = new NodeId("local");
+ private static final IpAddress LOCALHOST = IpAddress.valueOf("127.0.0.1");
+ private static final MaIdShort MA_ID_1_1 = MaIdCharStr.asMaId("test-ma-1-1");
+ private static final MaIdShort MA_ID_1_2 = MaIdCharStr.asMaId("test-ma-1-2");
+ private static final MdId MD_ID_1 = MdIdCharStr.asMdId("test-md-1");
+
+ private final CfmMepService mepService = createMock(CfmMepService.class);
+
+ private DistributedMdStore mdStore;
+ private CfmMdService service;
+ private CfmMdManager manager;
+
+ @Before
+ public void setup() throws Exception, CfmConfigException {
+ mdStore = new DistributedMdStore();
+
+ MaintenanceAssociation maTest11 = DefaultMaintenanceAssociation
+ .builder(MA_ID_1_1, MD_ID_1.getNameLength())
+ .ccmInterval(MaintenanceAssociation.CcmInterval.INTERVAL_10MIN)
+ .maNumericId((short) 1)
+ .addToRemoteMepIdList(MepId.valueOf((short) 101))
+ .addToRemoteMepIdList(MepId.valueOf((short) 102))
+ .addToComponentList(
+ DefaultComponent.builder(1)
+ .tagType(Component.TagType.VLAN_CTAG)
+ .build())
+ .build();
+
+ MaintenanceAssociation maTest12 = DefaultMaintenanceAssociation
+ .builder(MA_ID_1_2, MD_ID_1.getNameLength())
+ .ccmInterval(MaintenanceAssociation.CcmInterval.INTERVAL_10MIN)
+ .maNumericId((short) 2)
+ .addToRemoteMepIdList(MepId.valueOf((short) 201))
+ .addToRemoteMepIdList(MepId.valueOf((short) 202))
+ .addToComponentList(
+ DefaultComponent.builder(2)
+ .tagType(Component.TagType.VLAN_CTAG)
+ .build())
+ .build();
+
+ MaintenanceDomain mdTest1 = DefaultMaintenanceDomain
+ .builder(MD_ID_1)
+ .mdLevel(MaintenanceDomain.MdLevel.LEVEL1)
+ .mdNumericId((short) 1)
+ .addToMaList(maTest11)
+ .addToMaList(maTest12)
+ .build();
+
+ TestUtils.setField(mdStore, "storageService", new TestStorageService());
+ TestUtils.setField(mdStore, "clusterService", new CfmMdManagerTest.TestClusterService());
+ TestUtils.setField(mdStore, "mastershipService", new CfmMdManagerTest.TestMastershipService());
+
+ mdStore.activate();
+ mdStore.createUpdateMaintenanceDomain(mdTest1);
+
+ manager = new CfmMdManager();
+ manager.store = mdStore;
+ service = manager;
+ TestUtils.setField(manager, "storageService", new TestStorageService());
+ TestUtils.setField(manager, "coreService", new TestCoreService());
+ TestUtils.setField(manager, "mepService", mepService);
+ injectEventDispatcher(manager, new TestEventDispatcher());
+
+ manager.appId = new CfmMdManagerTest.TestApplicationId(0, "CfmMdManagerTest");
+ manager.activate();
+ }
+
+ @After
+ public void tearDown() {
+
+ manager.deactivate();
+ injectEventDispatcher(manager, null);
+
+ }
+
+ @Test
+ public void testGetAllMaintenanceDomain() {
+ Collection<MaintenanceDomain> mdList = service.getAllMaintenanceDomain();
+ assertEquals(1, mdList.size());
+
+ MaintenanceDomain md = mdList.iterator().next();
+ assertEquals(1, md.mdNumericId());
+
+ assertEquals(2, md.maintenanceAssociationList().size());
+
+ md.maintenanceAssociationList().iterator().forEachRemaining(ma ->
+ assertTrue(ma.maId().maName().endsWith(String.valueOf(ma.maNumericId())))
+ );
+ }
+
+ @Test
+ public void testGetMaintenanceDomain() {
+ Optional<MaintenanceDomain> md =
+ service.getMaintenanceDomain(MdIdCharStr.asMdId("test-md-1"));
+ assertTrue(md.isPresent());
+
+ assertEquals(1, md.get().mdNumericId());
+
+ assertEquals(2, md.get().maintenanceAssociationList().size());
+
+
+
+ //Now try an invalid name
+ Optional<MaintenanceDomain> mdInvalid =
+ service.getMaintenanceDomain(MdIdCharStr.asMdId("test-md-3"));
+ assertFalse(mdInvalid.isPresent());
+ }
+
+ @Test
+ public void testDeleteMaintenanceDomain() {
+ try {
+ assertTrue(service.deleteMaintenanceDomain(
+ MdIdCharStr.asMdId("test-md-1")));
+ } catch (CfmConfigException e) {
+ fail("Should not have thrown exception: " + e.getMessage());
+ }
+
+ //Now try an invalid name
+ try {
+ assertFalse(service.deleteMaintenanceDomain(
+ MdIdCharStr.asMdId("test-md-3")));
+ } catch (CfmConfigException e) {
+ fail("Should not have thrown exception: " + e.getMessage());
+ }
+ }
+
+ @Test
+ public void testCreateMaintenanceDomain() throws CfmConfigException {
+
+ MaintenanceAssociation maTest21 = DefaultMaintenanceAssociation
+ .builder(MaIdCharStr.asMaId("test-ma-2-1"), 9)
+ .ccmInterval(MaintenanceAssociation.CcmInterval.INTERVAL_1S)
+ .maNumericId((short) 1)
+ .addToRemoteMepIdList(MepId.valueOf((short) 101))
+ .addToRemoteMepIdList(MepId.valueOf((short) 102))
+ .addToComponentList(
+ DefaultComponent.builder(1)
+ .tagType(Component.TagType.VLAN_STAG)
+ .build())
+ .build();
+
+ MaintenanceDomain mdTest2 = DefaultMaintenanceDomain
+ .builder(MdIdCharStr.asMdId("test-md-2"))
+ .mdLevel(MaintenanceDomain.MdLevel.LEVEL2)
+ .mdNumericId((short) 2)
+ .addToMaList(maTest21)
+ .build();
+
+
+ //We expect false here because there should have been no previous value
+ //with that ID in the store
+ assertFalse(service.createMaintenanceDomain(mdTest2));
+ }
+
+ @Test
+ public void testGetAllMaintenanceAssociation() {
+ Collection<MaintenanceAssociation> maListMd1 =
+ service.getAllMaintenanceAssociation(
+ MdIdCharStr.asMdId("test-md-1"));
+
+ assertEquals(2, maListMd1.size());
+
+ maListMd1.iterator().forEachRemaining(ma ->
+ assertTrue(ma.maId().maName().endsWith(String.valueOf(ma.maNumericId())))
+ );
+
+ //Now try with an invalid name
+ try {
+ service.getAllMaintenanceAssociation(
+ MdIdCharStr.asMdId("test-md-2"));
+ } catch (IllegalArgumentException e) {
+ assertEquals("Unknown MD test-md-2", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testGetMaintenanceAssociation() {
+ Optional<MaintenanceAssociation> ma =
+ service.getMaintenanceAssociation(
+ MdIdCharStr.asMdId("test-md-1"),
+ MaIdCharStr.asMaId("test-ma-1-2"));
+
+ assertTrue(ma.isPresent());
+
+ //Now try an invalid MD Name
+ try {
+ service.getMaintenanceAssociation(
+ MdIdCharStr.asMdId("test-md-2"),
+ MaIdCharStr.asMaId("test-ma-1-2"));
+ } catch (IllegalArgumentException e) {
+ assertEquals("Unknown MD test-md-2", e.getMessage());
+ }
+
+ //Now try an invalid MA Name with a valid MD Name
+ try {
+ Optional<MaintenanceAssociation> maInvalid =
+ service.getMaintenanceAssociation(
+ MdIdCharStr.asMdId("test-md-1"),
+ MaIdCharStr.asMaId("test-ma-1-3"));
+ assertFalse(maInvalid.isPresent());
+ } catch (IllegalArgumentException e) {
+ fail("Should not throw exception: " + e.getMessage());
+ }
+ }
+
+ @Test
+ public void testDeleteMaintenanceAssociation() throws CfmConfigException {
+ assertTrue(service.deleteMaintenanceAssociation(
+ MdIdCharStr.asMdId("test-md-1"),
+ MaIdCharStr.asMaId("test-ma-1-2")));
+
+ //Now check it has actually been removed
+ Collection<MaintenanceAssociation> maListUpdated =
+ service.getAllMaintenanceAssociation(
+ MdIdCharStr.asMdId("test-md-1"));
+ assertEquals(1, maListUpdated.size());
+ maListUpdated.stream().findFirst().ifPresent(ma ->
+ assertEquals("test-ma-1-1", ma.maId().maName())
+ );
+
+ //Now try with an invalid mdName
+ try {
+ service.deleteMaintenanceAssociation(
+ MdIdCharStr.asMdId("test-md-2"),
+ MaIdCharStr.asMaId("test-ma-1-2"));
+ } catch (IllegalArgumentException e) {
+ assertEquals("Unknown MD: test-md-2", e.getMessage());
+ }
+
+ //Now try with an invalid maName
+ try {
+ assertFalse(service.deleteMaintenanceAssociation(
+ MdIdCharStr.asMdId("test-md-1"),
+ MaIdCharStr.asMaId("test-ma-1-3")));
+ } catch (IllegalArgumentException e) {
+ fail("Should not throw exception: " + e.getMessage());
+ }
+ }
+
+ @Test
+ public void testCreateMaintenanceAssociation() throws CfmConfigException {
+ MaintenanceAssociation maTest41 = DefaultMaintenanceAssociation
+ .builder(MaIdCharStr.asMaId("test-ma-1-4"), 9)
+ .ccmInterval(MaintenanceAssociation.CcmInterval.INTERVAL_1S)
+ .maNumericId((short) 4)
+ .addToRemoteMepIdList(MepId.valueOf((short) 401))
+ .addToRemoteMepIdList(MepId.valueOf((short) 402))
+ .addToComponentList(
+ DefaultComponent.builder(4)
+ .tagType(Component.TagType.VLAN_STAG)
+ .build())
+ .build();
+
+ //Should return false, as this MA did not exist before
+ assertFalse(service.createMaintenanceAssociation(
+ MdIdCharStr.asMdId("test-md-1"), maTest41));
+ assertEquals(3, service.getAllMaintenanceAssociation(
+ MdIdCharStr.asMdId("test-md-1")).size());
+
+ //Now try with an invalid mdName
+ try {
+ service.createMaintenanceAssociation(
+ MdIdCharStr.asMdId("test-md-2"), maTest41);
+ } catch (IllegalArgumentException e) {
+ assertEquals("Unknown MD: test-md-2", e.getMessage());
+ }
+
+ //Now try replacing an MA with some new values or Remote MEP
+ MaintenanceAssociation maTest11 = DefaultMaintenanceAssociation
+ .builder(MaIdCharStr.asMaId("test-ma-1-1"), 9)
+ .ccmInterval(MaintenanceAssociation.CcmInterval.INTERVAL_10MIN)
+ .maNumericId((short) 1)
+ .addToRemoteMepIdList(MepId.valueOf((short) 111)) //Changed
+ .addToRemoteMepIdList(MepId.valueOf((short) 112)) //Changed
+ .addToComponentList(
+ DefaultComponent.builder(1)
+ .tagType(Component.TagType.VLAN_CTAG)
+ .build())
+ .build();
+
+ //Should return true, as this MA did exist before
+ assertTrue(service.createMaintenanceAssociation(
+ MdIdCharStr.asMdId("test-md-1"), maTest11));
+ assertEquals(3, service.getAllMaintenanceAssociation(
+ MdIdCharStr.asMdId("test-md-1")).size());
+ }
+
+ public class TestApplicationId extends DefaultApplicationId {
+ public TestApplicationId(int id, String name) {
+ super(id, name);
+ }
+ }
+
+ private final class TestClusterService extends ClusterServiceAdapter {
+
+ ControllerNode local = new DefaultControllerNode(NID_LOCAL, LOCALHOST);
+
+ @Override
+ public ControllerNode getLocalNode() {
+ return local;
+ }
+
+ @Override
+ public Set<ControllerNode> getNodes() {
+ return Sets.newHashSet();
+ }
+
+ }
+
+ private class TestMastershipService extends MastershipServiceAdapter {
+ @Override
+ public NodeId getMasterFor(DeviceId deviceId) {
+ return NID_LOCAL;
+ }
+ }
+
+ private class TestCoreService extends CoreServiceAdapter {
+
+ @Override
+ public IdGenerator getIdGenerator(String topic) {
+ return new IdGenerator() {
+ private AtomicLong counter = new AtomicLong(0);
+
+ @Override
+ public long getNewId() {
+ return counter.getAndIncrement();
+ }
+ };
+ }
+ }
+}
diff --git a/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMepManagerTest.java b/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMepManagerTest.java
new file mode 100644
index 0000000..5941f6f
--- /dev/null
+++ b/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/CfmMepManagerTest.java
@@ -0,0 +1,504 @@
+/*
+ * 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 org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.junit.TestUtils;
+import org.onlab.packet.ChassisId;
+import org.onosproject.common.event.impl.TestEventDispatcher;
+import org.onosproject.core.CoreServiceAdapter;
+import org.onosproject.core.IdGenerator;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLbCreate;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLtCreate;
+import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation;
+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.MaIdCharStr;
+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.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId;
+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.CfmMepProgrammable;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.MepStore;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamDmProgrammable;
+import org.onosproject.incubator.net.l2monitoring.soam.impl.TestSoamDmProgrammable;
+import org.onosproject.net.AbstractProjectableModel;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DefaultDevice;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DeviceDescriptionDiscovery;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.driver.Behaviour;
+import org.onosproject.net.driver.DefaultDriver;
+import org.onosproject.net.driver.Driver;
+import org.onosproject.net.driver.DriverService;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.store.service.AsyncDocumentTree;
+import org.onosproject.store.service.DocumentTreeBuilder;
+import org.onosproject.store.service.Serializer;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.TestAsyncDocumentTree;
+import org.onosproject.store.service.TestStorageService;
+import org.onosproject.store.service.TestTopic;
+import org.onosproject.store.service.Topic;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.onosproject.net.NetTestTools.injectEventDispatcher;
+
+/**
+ * CFM MEP Manager test.
+ */
+public class CfmMepManagerTest {
+ private static final String TEST_MFR = "testMfr";
+ private static final String TEST_HW_VERSION = "testHwVersion";
+ private static final String TEST_SW_VERSION = "testSwVersion";
+ private static final String TEST_SN = "testSn";
+ private static final String TEST_DRIVER = "testDriver";
+ public static final String TEST_DRIVER_3 = "testDriver3";
+ public static final String TEST_SW_3 = "testSw3";
+ private final CfmMdService mdService = createMock(CfmMdService.class);
+ private final DeviceService deviceService = createMock(DeviceService.class);
+ private final DriverService driverService = createMock(DriverService.class);
+
+ private CfmMepService mepService;
+ private CfmMepManager mepManager;
+ private MepStore mepStore;
+ private StorageService storageService;
+
+ protected static final MdId MDNAME1 = MdIdCharStr.asMdId("md-1");
+ protected static final MdId MDNAME2 = MdIdCharStr.asMdId("md-2");
+ protected static final MaIdShort MANAME1 = MaIdCharStr.asMaId("ma-1-1");
+ protected static final MaIdShort MANAME2 = MaIdCharStr.asMaId("ma-2-2");
+
+ private MaintenanceAssociation ma1;
+ private MaintenanceAssociation ma2;
+ protected static final MepId MEPID1 = MepId.valueOf((short) 10);
+ protected static final MepId MEPID11 = MepId.valueOf((short) 11);
+ protected static final MepId MEPID12 = MepId.valueOf((short) 12);
+ protected static final MepId MEPID2 = MepId.valueOf((short) 20);
+ protected static final MepId MEPID21 = MepId.valueOf((short) 21);
+ protected static final MepId MEPID22 = MepId.valueOf((short) 22);
+
+ protected static final DeviceId DEVICE_ID1 = DeviceId.deviceId("netconf:1.2.3.4:830");
+ protected static final DeviceId DEVICE_ID2 = DeviceId.deviceId("netconf:2.2.3.4:830");
+
+ private Mep mep1;
+ private Mep mep11;
+ private Mep mep12;
+ private Mep mep2;
+ private Mep mep21;
+ private Mep mep22;
+
+ private Device device1;
+ private Device device2;
+
+ private Driver testDriver;
+
+ @Before
+ public void setup() throws CfmConfigException {
+ mepManager = new CfmMepManager();
+ mepStore = new DistributedMepStore();
+ storageService = new MockStorageService();
+
+ ma1 = DefaultMaintenanceAssociation.builder(MANAME1, MDNAME1.getNameLength()).build();
+ ma2 = DefaultMaintenanceAssociation.builder(MANAME2, MDNAME2.getNameLength()).build();
+
+ TestUtils.setField(mepStore, "storageService", storageService);
+ ((DistributedMepStore) mepStore).activate();
+
+ TestUtils.setField(mepManager, "coreService", new TestCoreService());
+ TestUtils.setField(mepManager, "deviceService", deviceService);
+ TestUtils.setField(mepManager, "cfmMdService", mdService);
+ TestUtils.setField(mepManager, "mepStore", mepStore);
+ injectEventDispatcher(mepManager, new TestEventDispatcher());
+
+ mepService = mepManager;
+ mepManager.activate();
+
+ mep1 = DefaultMep.builder(MEPID1, DEVICE_ID1, PortNumber.P0,
+ Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
+ mepStore.createUpdateMep(new MepKeyId(MDNAME1, MANAME1, MEPID1), mep1);
+
+ mep11 = DefaultMep.builder(MEPID11, DEVICE_ID1, PortNumber.P0,
+ Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
+ mepStore.createUpdateMep(new MepKeyId(MDNAME1, MANAME1, MEPID11), mep11);
+
+ mep12 = DefaultMep.builder(MEPID12, DEVICE_ID1, PortNumber.P0,
+ Mep.MepDirection.UP_MEP, MDNAME2, MANAME2).build();
+ mepStore.createUpdateMep(new MepKeyId(MDNAME2, MANAME2, MEPID12), mep12);
+
+ mep2 = DefaultMep.builder(MEPID2, DEVICE_ID2, PortNumber.portNumber(2),
+ Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
+ mepStore.createUpdateMep(new MepKeyId(MDNAME1, MANAME1, MEPID2), mep2);
+
+ mep21 = DefaultMep.builder(MEPID21, DEVICE_ID2, PortNumber.portNumber(2),
+ Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
+ mepStore.createUpdateMep(new MepKeyId(MDNAME1, MANAME1, MEPID21), mep21);
+
+ mep22 = DefaultMep.builder(MEPID22, DEVICE_ID2, PortNumber.portNumber(2),
+ Mep.MepDirection.UP_MEP, MDNAME2, MANAME2).build();
+ mepStore.createUpdateMep(new MepKeyId(MDNAME2, MANAME2, MEPID22), mep22);
+
+ 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());
+
+ device2 = new DefaultDevice(
+ ProviderId.NONE, DEVICE_ID2, Device.Type.SWITCH,
+ TEST_MFR, TEST_HW_VERSION, TEST_SW_VERSION, TEST_SN,
+ new ChassisId(2),
+ 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<>());
+ }
+
+
+ @After
+ public void tearDown() {
+// mepManager.deactivate();
+ }
+
+ @Test
+ public void testGetAllMeps() throws CfmConfigException {
+
+ expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1))
+ .andReturn(Optional.ofNullable(ma1))
+ .anyTimes();
+ replay(mdService);
+
+ expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
+ expect(deviceService.getDevice(DEVICE_ID2)).andReturn(device2).anyTimes();
+ replay(deviceService);
+
+ expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).anyTimes();
+ replay(driverService);
+
+ Collection<MepEntry> mepEntries = mepManager.getAllMeps(MDNAME1, MANAME1);
+
+ assertEquals(4, mepEntries.size());
+ }
+
+ @Test
+ public void testGetMep() throws CfmConfigException {
+
+ expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1))
+ .andReturn(Optional.ofNullable(ma1))
+ .anyTimes();
+ replay(mdService);
+
+ expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
+ replay(deviceService);
+
+ expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).anyTimes();
+ replay(driverService);
+
+ MepEntry mepEntry = mepManager.getMep(MDNAME1, MANAME1, MEPID1);
+
+ assertEquals(MEPID1.value(), mepEntry.mepId().value());
+ }
+
+ @Test
+ public void testGetMepMissing() {
+
+ expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1))
+ .andReturn(Optional.ofNullable(ma1))
+ .anyTimes();
+ replay(mdService);
+
+ expect(deviceService.getDevice(DEVICE_ID1)).andReturn(null).anyTimes();
+ replay(deviceService);
+
+ expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).anyTimes();
+ replay(driverService);
+
+ try {
+ mepManager.getMep(MDNAME1, MANAME1, MEPID1);
+ fail("Expecting CfmConfigException because device does not exist");
+ } catch (CfmConfigException e) {
+ assertEquals("Device not found netconf:1.2.3.4:830", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testDeleteMep() throws CfmConfigException {
+ expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1))
+ .andReturn(Optional.ofNullable(ma1))
+ .anyTimes();
+ replay(mdService);
+
+ expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
+ expect(deviceService.getDevice(DEVICE_ID2)).andReturn(device2).anyTimes();
+ replay(deviceService);
+
+ expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).anyTimes();
+ replay(driverService);
+
+ assertTrue(mepManager.deleteMep(MDNAME1, MANAME1, MEPID1, Optional.empty()));
+ }
+
+ @Test
+ public void testCreateMep() throws CfmConfigException {
+ expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1))
+ .andReturn(Optional.ofNullable(ma1))
+ .anyTimes();
+ replay(mdService);
+
+ expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
+ expect(deviceService.getDevice(DEVICE_ID2)).andReturn(device2).anyTimes();
+ replay(deviceService);
+
+ expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).anyTimes();
+ replay(driverService);
+
+ MepId mepId3 = MepId.valueOf((short) 3);
+ Mep mep3 = DefaultMep.builder(mepId3, DEVICE_ID1, PortNumber.portNumber(1),
+ Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
+
+ //Expecting false - since it was not found
+ assertTrue(mepManager.createMep(MDNAME1, MANAME1, mep3));
+ }
+
+ @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(TEST_DRIVER_3)).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());
+ }
+ }
+
+ @Test
+ public void testTransmitLoopback() {
+ expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1))
+ .andReturn(Optional.ofNullable(ma1))
+ .anyTimes();
+ replay(mdService);
+
+ expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
+ replay(deviceService);
+
+ expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).anyTimes();
+ replay(driverService);
+
+ MepLbCreate lbCreate = DefaultMepLbCreate.builder(MepId.valueOf((short) 11)).build();
+ try {
+ mepService.transmitLoopback(MDNAME1, MANAME1, MEPID1, lbCreate);
+ } catch (CfmConfigException e) {
+ fail("Not expecting an exception");
+ }
+ }
+
+ @Test
+ public void testAbortLoopback() {
+ expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1))
+ .andReturn(Optional.ofNullable(ma1))
+ .anyTimes();
+ replay(mdService);
+
+ expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
+ replay(deviceService);
+
+ expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).anyTimes();
+ replay(driverService);
+
+ try {
+ mepService.abortLoopback(MDNAME1, MANAME1, MEPID1);
+ } catch (CfmConfigException e) {
+ fail("Not expecting an exception");
+ }
+ }
+
+ @Test
+ public void testTransmitLinktrace() throws CfmConfigException {
+ expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1))
+ .andReturn(Optional.ofNullable(ma1))
+ .anyTimes();
+ replay(mdService);
+
+ expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
+ replay(deviceService);
+
+ expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).anyTimes();
+ replay(driverService);
+
+ MepLtCreate ltCreate = DefaultMepLtCreate.builder(MepId.valueOf((short) 11)).build();
+ try {
+ mepService.transmitLinktrace(MDNAME1, MANAME1, MEPID1, ltCreate);
+ } catch (UnsupportedOperationException e) {
+ assertEquals("Not yet implemented", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testDeviceRemoved() throws CfmConfigException {
+ expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1))
+ .andReturn(Optional.ofNullable(ma1))
+ .anyTimes();
+ expect(mdService.getMaintenanceAssociation(MDNAME2, MANAME2))
+ .andReturn(Optional.ofNullable(ma2))
+ .anyTimes();
+ replay(mdService);
+
+ expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
+ expect(deviceService.getDevice(DEVICE_ID2)).andReturn(device2).anyTimes();
+ replay(deviceService);
+
+ expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).anyTimes();
+ replay(driverService);
+
+// This is arranged like
+// device1 device2
+// / \ / \
+// md-1 md-2 md-1 md-2
+// | | | |
+// ma-1-1 ma-2-2 ma-1-1 ma-2-2
+// / \ | / \ \
+// mep1 mep11 mep12 mep2 mep21 mep22
+ assertNotNull(mepService.getMep(MDNAME1, MANAME1, MEPID1));
+ assertNotNull(mepService.getMep(MDNAME1, MANAME1, MEPID11));
+ assertNotNull(mepService.getMep(MDNAME2, MANAME2, MEPID12));
+ assertNotNull(mepService.getMep(MDNAME1, MANAME1, MEPID2));
+ assertNotNull(mepService.getMep(MDNAME1, MANAME1, MEPID21));
+ assertNotNull(mepService.getMep(MDNAME2, MANAME2, MEPID22));
+
+ //By deleting Device2 we expect Mep2,21,22 to have been deleted but Mep1,11,12 to remain
+ ((CfmMepManager) mepService).processDeviceRemoved(device2);
+
+ assertNotNull(mepService.getMep(MDNAME1, MANAME1, MEPID1));
+ assertNotNull(mepService.getMep(MDNAME1, MANAME1, MEPID11));
+ assertNotNull(mepService.getMep(MDNAME2, MANAME2, MEPID12));
+ //The device 2 related ones are gone
+ assertNull(mepService.getMep(MDNAME1, MANAME1, MEPID2));
+ assertNull(mepService.getMep(MDNAME1, MANAME1, MEPID21));
+ assertNull(mepService.getMep(MDNAME2, MANAME2, MEPID22));
+
+ //Now delete device1
+ ((CfmMepManager) mepService).processDeviceRemoved(device1);
+ assertNull(mepService.getMep(MDNAME1, MANAME1, MEPID1));
+ assertNull(mepService.getMep(MDNAME1, MANAME1, MEPID11));
+ assertNull(mepService.getMep(MDNAME2, MANAME2, MEPID12));
+ }
+
+ private class TestCoreService extends CoreServiceAdapter {
+
+ @Override
+ public IdGenerator getIdGenerator(String topic) {
+ return new IdGenerator() {
+ private AtomicLong counter = new AtomicLong(0);
+
+ @Override
+ public long getNewId() {
+ return counter.getAndIncrement();
+ }
+ };
+ }
+ }
+
+ private static class MockStorageService extends TestStorageService {
+ @Override
+ public <V> DocumentTreeBuilder<V> documentTreeBuilder() {
+ return new DocumentTreeBuilder<V>() {
+ @Override
+ public AsyncDocumentTree<V> buildDocumentTree() {
+ return build();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public AsyncDocumentTree<V> build() {
+ return new TestAsyncDocumentTree<>(name());
+ }
+ };
+ }
+
+ @Override
+ public <T> Topic<T> getTopic(String name, Serializer serializer) {
+ return new TestTopic<>(name);
+ }
+ }
+}
diff --git a/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/TestCfmMepProgrammable.java b/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/TestCfmMepProgrammable.java
new file mode 100644
index 0000000..3f4be0e
--- /dev/null
+++ b/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/TestCfmMepProgrammable.java
@@ -0,0 +1,131 @@
+/*
+ * 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 org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepEntry;
+import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain;
+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.CfmMepProgrammable;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import static org.onosproject.incubator.net.l2monitoring.cfm.impl.CfmMepManagerTest.*;
+
+/**
+ * A dummy implementation of the CfmMepProgrammable for test purposes.
+ */
+public class TestCfmMepProgrammable extends AbstractHandlerBehaviour implements CfmMepProgrammable {
+
+ private List<Mep> deviceMepList;
+
+ public TestCfmMepProgrammable() throws CfmConfigException {
+ deviceMepList = new ArrayList<>();
+
+ deviceMepList.add(DefaultMep.builder(MEPID1, DEVICE_ID1, PortNumber.P0,
+ Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build());
+ deviceMepList.add(DefaultMep.builder(MEPID11, DEVICE_ID1, PortNumber.P0,
+ Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build());
+ deviceMepList.add(DefaultMep.builder(MEPID12, DEVICE_ID1, PortNumber.P0,
+ Mep.MepDirection.UP_MEP, MDNAME2, MANAME2).build());
+ deviceMepList.add(DefaultMep.builder(MEPID2, DEVICE_ID2, PortNumber.portNumber(2),
+ Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build());
+ deviceMepList.add(DefaultMep.builder(MEPID21, DEVICE_ID2, PortNumber.portNumber(2),
+ Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build());
+ deviceMepList.add(DefaultMep.builder(MEPID22, DEVICE_ID2, PortNumber.portNumber(2),
+ Mep.MepDirection.UP_MEP, MDNAME2, MANAME2).build());
+ }
+
+ @Override
+ public MepEntry getMep(MdId mdName, MaIdShort maName, MepId mepId) throws CfmConfigException {
+ for (Mep mep:deviceMepList) {
+ if (mep.mdId().equals(mdName) && mep.maId().equals(maName) && mep.mepId().equals(mepId)) {
+ return DefaultMepEntry.builder(mep).buildEntry();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public boolean deleteMep(MdId mdName, MaIdShort maName, MepId mepId,
+ Optional<MaintenanceDomain> oldMd) throws CfmConfigException {
+ return true;
+ }
+
+ @Override
+ public boolean createMep(MdId mdName, MaIdShort maName, Mep mep) throws CfmConfigException {
+ return true;
+ }
+
+ @Override
+ public boolean deleteMdOnDevice(MdId mdId, Optional<MaintenanceDomain> oldMd) throws CfmConfigException {
+ return false;
+ }
+
+ @Override
+ public boolean deleteMaOnDevice(MdId mdId, MaIdShort maId,
+ Optional<MaintenanceDomain> oldMd) throws CfmConfigException {
+ return false;
+ }
+
+ @Override
+ public boolean createMdOnDevice(MdId mdId) throws CfmConfigException {
+ return false;
+ }
+
+ @Override
+ public boolean createMaOnDevice(MdId mdId, MaIdShort maId) throws CfmConfigException {
+ return false;
+ }
+
+ @Override
+ public boolean createMaRemoteMepOnDevice(MdId mdId, MaIdShort maId, MepId remoteMep) throws CfmConfigException {
+ return false;
+ }
+
+ @Override
+ public boolean deleteMaRemoteMepOnDevice(MdId mdId, MaIdShort maId, MepId remoteMep) throws CfmConfigException {
+ return false;
+ }
+
+ @Override
+ public void transmitLoopback(MdId mdName, MaIdShort maName, MepId mepId, MepLbCreate lbCreate)
+ throws CfmConfigException {
+
+ }
+
+ @Override
+ public void abortLoopback(MdId mdName, MaIdShort maName, MepId mepId) throws CfmConfigException {
+
+ }
+
+ @Override
+ public void transmitLinktrace(MdId mdName, MaIdShort maName, MepId mepId, MepLtCreate ltCreate)
+ throws CfmConfigException {
+
+ }
+}
diff --git a/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/TestDeviceDiscoveryBehavior.java b/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/TestDeviceDiscoveryBehavior.java
new file mode 100644
index 0000000..01d3d01
--- /dev/null
+++ b/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/impl/TestDeviceDiscoveryBehavior.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.onosproject.net.device.DeviceDescription;
+import org.onosproject.net.device.DeviceDescriptionDiscovery;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+
+import java.util.List;
+
+public class TestDeviceDiscoveryBehavior extends AbstractHandlerBehaviour
+ implements DeviceDescriptionDiscovery {
+
+ @Override
+ public DeviceDescription discoverDeviceDetails() {
+ return null;
+ }
+
+ @Override
+ public List<PortDescription> discoverPortDetails() {
+ return null;
+ }
+}
diff --git a/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/impl/SoamManagerTest.java b/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/impl/SoamManagerTest.java
new file mode 100644
index 0000000..a3a6d52
--- /dev/null
+++ b/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/impl/SoamManagerTest.java
@@ -0,0 +1,476 @@
+/*
+ * 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.soam.impl;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.junit.TestUtils;
+import org.onlab.packet.ChassisId;
+import org.onosproject.common.event.impl.TestEventDispatcher;
+import org.onosproject.core.CoreServiceAdapter;
+import org.onosproject.core.IdGenerator;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepEntry;
+import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep;
+import org.onosproject.incubator.net.l2monitoring.cfm.MepEntry;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr;
+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.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.impl.TestCfmMepProgrammable;
+import org.onosproject.incubator.net.l2monitoring.cfm.impl.TestDeviceDiscoveryBehavior;
+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.CfmMepProgrammable;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamDmProgrammable;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamService;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementCreate;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementEntry;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatCurrent;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatHistory;
+import org.onosproject.net.AbstractProjectableModel;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DefaultDevice;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DeviceDescriptionDiscovery;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.driver.Behaviour;
+import org.onosproject.net.driver.DefaultDriver;
+import org.onosproject.net.driver.Driver;
+import org.onosproject.net.driver.DriverService;
+import org.onosproject.net.provider.ProviderId;
+
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertNotNull;
+import static junit.framework.TestCase.fail;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertTrue;
+import static org.onosproject.net.NetTestTools.injectEventDispatcher;
+
+/**
+ * Services OAM Manager test.
+ */
+public class SoamManagerTest {
+ private static final String TEST_MFR = "testMfr";
+ private static final String TEST_HW_VERSION = "testHwVersion";
+ private static final String TEST_SW_VERSION = "testSwVersion";
+ private static final String TEST_SN = "testSn";
+ private static final String TEST_DRIVER = "testDriver";
+ public static final String TEST_DRIVER_3 = "testDriver3";
+ public static final String TEST_SW_3 = "testSw3";
+
+
+ protected static final MdId MDNAME1 = MdIdCharStr.asMdId("md-1");
+ protected static final MaIdShort MANAME1 = MaIdCharStr.asMaId("ma-1-1");
+ protected static final MepId MEPID1 = MepId.valueOf((short) 10);
+ protected static final DeviceId DEVICE_ID1 = DeviceId.deviceId("netconf:1.2.3.4:830");
+ protected static final SoamId DMID101 = SoamId.valueOf(101);
+ protected static final SoamId DMID102 = SoamId.valueOf(102);
+ protected static final SoamId LMID101 = SoamId.valueOf(201);
+
+ private MaintenanceAssociation ma1;
+ private MepEntry mep1;
+
+ private SoamManager soamManager;
+ private SoamService soamService;
+
+ private final CfmMdService mdService = createMock(CfmMdService.class);
+ private CfmMepService mepService = createMock(CfmMepService.class);
+ private final DeviceService deviceService = createMock(DeviceService.class);
+ private final DriverService driverService = createMock(DriverService.class);
+ private Device device1;
+ private Driver testDriver;
+
+ @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<>());
+
+ }
+
+ @After
+ public void tearDown() {
+// soamManager.deactivate();
+ }
+
+ @Test
+ public void testGetAllDms() throws CfmConfigException, SoamConfigException {
+ expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
+ replay(deviceService);
+
+ expect(mepService.getMep(MDNAME1, MANAME1, MEPID1)).andReturn(mep1).anyTimes();
+ replay(mepService);
+
+ expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).anyTimes();
+ replay(driverService);
+
+ Collection<DelayMeasurementEntry> dmEntries =
+ soamManager.getAllDms(MDNAME1, MANAME1, MEPID1);
+ assertNotNull(dmEntries);
+ assertEquals(1, dmEntries.size());
+ }
+
+ @Test
+ public void testGetDm() throws CfmConfigException, SoamConfigException {
+ expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
+ replay(deviceService);
+
+ expect(mepService.getMep(MDNAME1, MANAME1, MEPID1)).andReturn(mep1).anyTimes();
+ replay(mepService);
+
+ expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).anyTimes();
+ replay(driverService);
+
+ DelayMeasurementEntry dmEntry =
+ soamManager.getDm(MDNAME1, MANAME1, MEPID1, DMID101);
+
+ assertNotNull(dmEntry);
+ assertEquals(DMID101, dmEntry.dmId());
+ }
+
+ @Test
+ public void testGetDmCurrentStat() throws CfmConfigException, SoamConfigException {
+ expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
+ replay(deviceService);
+
+ expect(mepService.getMep(MDNAME1, MANAME1, MEPID1)).andReturn(mep1).anyTimes();
+ replay(mepService);
+
+ expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).anyTimes();
+ replay(driverService);
+
+ DelayMeasurementStatCurrent dmCurrentStat =
+ soamManager.getDmCurrentStat(MDNAME1, MANAME1, MEPID1, DMID101);
+
+ assertNotNull(dmCurrentStat);
+ assertTrue(dmCurrentStat.startTime().isBefore(Instant.now()));
+ }
+
+ @Test
+ public void testGetDmHistoryStats() throws CfmConfigException, SoamConfigException {
+ expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
+ replay(deviceService);
+
+ expect(mepService.getMep(MDNAME1, MANAME1, MEPID1)).andReturn(mep1).anyTimes();
+ replay(mepService);
+
+ expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).anyTimes();
+ replay(driverService);
+
+ Collection<DelayMeasurementStatHistory> dmHistoricalStats =
+ soamManager.getDmHistoricalStats(MDNAME1, MANAME1, MEPID1, DMID101);
+
+ assertNotNull(dmHistoricalStats);
+ assertEquals(2, dmHistoricalStats.size());
+ }
+
+ @Test
+ public void testCreateDm() throws CfmConfigException, SoamConfigException {
+ expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
+ replay(deviceService);
+
+ expect(mepService.getMep(MDNAME1, MANAME1, MEPID1)).andReturn(mep1).anyTimes();
+ replay(mepService);
+
+ expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).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();
+
+ assertEquals(1000, soamManager.createDm(
+ MDNAME1, MANAME1, MEPID1, dmCreate1).get().value());
+ }
+
+ @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(TEST_DRIVER_3)).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());
+ }
+ }
+
+ @Test
+ public void testAbortAllDmOnMep() throws CfmConfigException {
+ //TODO: Implement underlying method
+ try {
+ soamManager.abortDm(MDNAME1, MANAME1, MEPID1);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ @Test
+ public void testAbortOneDm() throws CfmConfigException {
+ //TODO: Implement underlying method
+ try {
+ soamManager.abortDm(MDNAME1, MANAME1, MEPID1, DMID101);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ @Test
+ public void testClearAllDmHistoriesOnMep() throws CfmConfigException {
+ //TODO: Implement underlying method
+ try {
+ soamManager.clearDelayHistoryStats(MDNAME1, MANAME1, MEPID1);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ @Test
+ public void testClearOneDmHistories() throws CfmConfigException {
+ //TODO: Implement underlying method
+ try {
+ soamManager.clearDelayHistoryStats(MDNAME1, MANAME1, MEPID1, DMID101);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ @Test
+ public void testGetAllLmsOnMep() throws CfmConfigException {
+ //TODO: Implement underlying method
+ try {
+ soamManager.getAllLms(MDNAME1, MANAME1, MEPID1);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ @Test
+ public void testGetLm() throws CfmConfigException {
+ //TODO: Implement underlying method
+ try {
+ soamManager.getLm(MDNAME1, MANAME1, MEPID1, LMID101);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ @Test
+ public void testGetLmCurrentStat() {
+ //TODO: Implement underlying method
+ try {
+ soamManager.getLmCurrentStat(MDNAME1, MANAME1, MEPID1, LMID101);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ @Test
+ public void testGetLmhistoricalStats() {
+ //TODO: Implement underlying method
+ try {
+ soamManager.getLmHistoricalStats(MDNAME1, MANAME1, MEPID1, LMID101);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ @Test
+ public void testCreateLm() throws CfmConfigException {
+ //TODO: Implement underlying method
+ try {
+ soamManager.createLm(MDNAME1, MANAME1, MEPID1, null);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ @Test
+ public void testAbortAllLmOnMep() throws CfmConfigException {
+ //TODO: Implement underlying method
+ try {
+ soamManager.abortLm(MDNAME1, MANAME1, MEPID1);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ @Test
+ public void testAbortOneLm() throws CfmConfigException {
+ //TODO: Implement underlying method
+ try {
+ soamManager.abortLm(MDNAME1, MANAME1, MEPID1, LMID101);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ @Test
+ public void testClearAllLossHistoryStatsOnMep() throws CfmConfigException {
+ //TODO: Implement underlying method
+ try {
+ soamManager.clearLossHistoryStats(MDNAME1, MANAME1, MEPID1);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ @Test
+ public void testClearLossHistoryStatsOnLm() throws CfmConfigException {
+ //TODO: Implement underlying method
+ try {
+ soamManager.clearLossHistoryStats(MDNAME1, MANAME1, MEPID1, LMID101);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ @Test
+ public void testCreateTestSignal() throws CfmConfigException {
+ //TODO: Implement underlying method
+ try {
+ soamManager.createTestSignal(MDNAME1, MANAME1, MEPID1, null);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ @Test
+ public void testAbortTestSignal() throws CfmConfigException {
+ //TODO: Implement underlying method
+ try {
+ soamManager.abortTestSignal(MDNAME1, MANAME1, MEPID1);
+ fail("Expecting UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ protected class TestCoreService extends CoreServiceAdapter {
+
+ @Override
+ public IdGenerator getIdGenerator(String topic) {
+ return new IdGenerator() {
+ private AtomicLong counter = new AtomicLong(0);
+
+ @Override
+ public long getNewId() {
+ return counter.getAndIncrement();
+ }
+ };
+ }
+ }
+}
diff --git a/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/impl/TestSoamDmProgrammable.java b/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/impl/TestSoamDmProgrammable.java
new file mode 100644
index 0000000..9750550
--- /dev/null
+++ b/apps/cfm/app/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/impl/TestSoamDmProgrammable.java
@@ -0,0 +1,243 @@
+/*
+ * 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.soam.impl;
+
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep;
+import org.onosproject.incubator.net.l2monitoring.cfm.MepTsCreate;
+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.soam.SoamConfigException;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamDmProgrammable;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementEntry;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementStatCurrent;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementStatHistory;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatCurrent;
+import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatHistory;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry;
+import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatCurrent;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Optional;
+
+import static org.onosproject.incubator.net.l2monitoring.soam.impl.SoamManagerTest.*;
+
+/**
+ * A dummy implementation of the SoamDmProgrammable for test purposes.
+ */
+public class TestSoamDmProgrammable extends AbstractHandlerBehaviour implements SoamDmProgrammable {
+ private DelayMeasurementEntry dmEntry1;
+
+ public TestSoamDmProgrammable() throws SoamConfigException {
+ long nowMs = System.currentTimeMillis();
+ long lastSecond = nowMs - nowMs % 1000;
+ DelayMeasurementStatCurrent current =
+ (DelayMeasurementStatCurrent) DefaultDelayMeasurementStatCurrent
+ .builder(Duration.ofSeconds(37), false)
+ .startTime(Instant.ofEpochMilli(lastSecond))
+ .build();
+
+ long lastMinute = nowMs - nowMs % (60 * 1000);
+ DelayMeasurementStatHistory history1 =
+ (DelayMeasurementStatHistory) DefaultDelayMeasurementStatHistory
+ .builder(SoamId.valueOf(67), Duration.ofSeconds(60), false)
+ .endTime(Instant.ofEpochMilli(lastMinute))
+ .frameDelayForwardMin(Duration.ofMillis(107))
+ .frameDelayForwardMax(Duration.ofMillis(109))
+ .frameDelayForwardAvg(Duration.ofMillis(108))
+ .build();
+
+ long lastMinute2 = lastMinute - (60 * 1000);
+ DelayMeasurementStatHistory history2 =
+ (DelayMeasurementStatHistory) DefaultDelayMeasurementStatHistory
+ .builder(SoamId.valueOf(66), Duration.ofSeconds(60), false)
+ .endTime(Instant.ofEpochMilli(lastMinute2))
+ .frameDelayForwardMin(Duration.ofMillis(117))
+ .frameDelayForwardMax(Duration.ofMillis(119))
+ .frameDelayForwardAvg(Duration.ofMillis(118))
+ .build();
+
+ dmEntry1 = DefaultDelayMeasurementEntry
+ .builder(DMID101, DelayMeasurementCreate.DmType.DM1DMTX,
+ DelayMeasurementCreate.Version.Y17312011,
+ MepId.valueOf((short) 11), Mep.Priority.PRIO5)
+ .currentResult(current)
+ .addToHistoricalResults(history1)
+ .addToHistoricalResults(history2)
+ .build();
+ }
+
+ @Override
+ public Collection<DelayMeasurementEntry> getAllDms(
+ MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException, SoamConfigException {
+ Collection<DelayMeasurementEntry> dmEntries = new ArrayList<>();
+ if (mdName.equals(MDNAME1) && maName.equals(MANAME1) && mepId.equals(MEPID1)) {
+ dmEntries.add(dmEntry1);
+ return dmEntries;
+ }
+ return new ArrayList<>();
+ }
+
+ @Override
+ public DelayMeasurementEntry getDm(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId)
+ throws CfmConfigException, SoamConfigException {
+ if (mdName.equals(MDNAME1) && maName.equals(MANAME1) && mepId.equals(MEPID1)) {
+ return dmEntry1;
+ }
+ return null;
+ }
+
+ @Override
+ public DelayMeasurementStatCurrent getDmCurrentStat(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId)
+ throws CfmConfigException, SoamConfigException {
+ if (mdName.equals(MDNAME1) && maName.equals(MANAME1) && mepId.equals(MEPID1)) {
+ return dmEntry1.currentResult();
+ }
+ return null;
+ }
+
+ @Override
+ public Collection<DelayMeasurementStatHistory> getDmHistoricalStats(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId)
+ throws CfmConfigException, SoamConfigException {
+ if (mdName.equals(MDNAME1) && maName.equals(MANAME1) && mepId.equals(MEPID1)) {
+ return dmEntry1.historicalResults();
+ }
+ return null;
+ }
+
+ @Override
+ public Optional<SoamId> createDm(
+ MdId mdName, MaIdShort maName, MepId mepId, DelayMeasurementCreate dm)
+ throws CfmConfigException, SoamConfigException {
+ return Optional.ofNullable(SoamId.valueOf(1000));
+ }
+
+ @Override
+ public void abortDm(
+ MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException {
+
+ }
+
+ @Override
+ public void abortDm(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId)
+ throws CfmConfigException {
+
+ }
+
+ @Override
+ public void clearDelayHistoryStats(
+ MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException {
+
+ }
+
+ @Override
+ public void clearDelayHistoryStats(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId)
+ throws CfmConfigException {
+
+ }
+
+ @Override
+ public Collection<LossMeasurementEntry> getAllLms(
+ MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException, SoamConfigException {
+ return null;
+ }
+
+ @Override
+ public LossMeasurementEntry getLm(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId)
+ throws CfmConfigException, SoamConfigException {
+ return null;
+ }
+
+ @Override
+ public LossMeasurementStatCurrent getLmCurrentStat(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) {
+ return null;
+ }
+
+ @Override
+ public Collection<LossMeasurementStatCurrent> getLmHistoricalStats(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) {
+ return new ArrayList<LossMeasurementStatCurrent>();
+ }
+
+ @Override
+ public Optional<SoamId> createLm(
+ MdId mdName, MaIdShort maName, MepId mepId, LossMeasurementCreate lm)
+ throws CfmConfigException, SoamConfigException {
+ return Optional.empty();
+ }
+
+ @Override
+ public void abortLm(
+ MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException {
+
+ }
+
+ @Override
+ public void abortLm(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId)
+ throws CfmConfigException {
+
+ }
+
+ @Override
+ public void clearLossHistoryStats(
+ MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException {
+
+ }
+
+ @Override
+ public void clearLossHistoryStats(
+ MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId)
+ throws CfmConfigException {
+
+ }
+
+ @Override
+ public void createTestSignal(
+ MdId mdName, MaIdShort maName, MepId mepId, MepTsCreate tsCreate)
+ throws CfmConfigException {
+
+ }
+
+ @Override
+ public void abortTestSignal(
+ MdId mdName, MaIdShort maName, MepId mepId)
+ throws CfmConfigException {
+
+ }
+}
\ No newline at end of file
diff --git a/apps/cfm/nbi/BUCK b/apps/cfm/nbi/BUCK
index 9acd4a0..fd493f4 100644
--- a/apps/cfm/nbi/BUCK
+++ b/apps/cfm/nbi/BUCK
@@ -5,7 +5,7 @@
'//lib:JACKSON',
'//cli:onos-cli',
'//lib:org.apache.karaf.shell.console',
- '//incubator/api:onos-incubator-api'
+ '//apps/cfm/api:onos-apps-cfm-api',
]
TEST_DEPS = [
diff --git a/apps/cfm/nbi/pom.xml b/apps/cfm/nbi/pom.xml
index 9036ba1..fa99b78 100644
--- a/apps/cfm/nbi/pom.xml
+++ b/apps/cfm/nbi/pom.xml
@@ -13,11 +13,11 @@
<parent>
<groupId>org.onosproject</groupId>
- <artifactId>onos-apps</artifactId>
+ <artifactId>onos-apps-cfm</artifactId>
<version>1.13.0-SNAPSHOT</version>
</parent>
- <artifactId>onos-apps-cfm</artifactId>
+ <artifactId>onos-apps-cfm-nbi</artifactId>
<packaging>bundle</packaging>
<version>1.13.0-SNAPSHOT</version>
@@ -47,7 +47,8 @@
<dependency>
<groupId>org.onosproject</groupId>
- <artifactId>onos-incubator-api</artifactId>
+ <artifactId>onos-apps-cfm-api</artifactId>
+ <version>${project.version}</version>
</dependency>
<dependency>
@@ -90,7 +91,14 @@
<artifactId>jersey-test-framework-provider-jetty</artifactId>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.inject</groupId>
+ <artifactId>jersey-hk2</artifactId>
+ </dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-rest</artifactId>
diff --git a/apps/cfm/pom.xml b/apps/cfm/pom.xml
index 2e2437f..d31b0a1 100644
--- a/apps/cfm/pom.xml
+++ b/apps/cfm/pom.xml
@@ -18,26 +18,14 @@
</parent>
<artifactId>onos-apps-cfm</artifactId>
- <packaging>bundle</packaging>
+ <packaging>pom</packaging>
<version>1.13.0-SNAPSHOT</version>
- <description>ONOS OSGi bundle archetype</description>
- <url>http://onosproject.org</url>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <web.context>/onos/cfm</web.context>
- <api.description>Layer 2 Monitoring CFM REST API</api.description>
- <api.version>1.0.0</api.version>
- <api.package>org.onosproject.cfm</api.package>
- <api.title>Layer 2 Monitoring CFM REST API</api.title>
- <onos.app.name>org.onosproject.cfm</onos.app.name>
- <onos.app.title>Layer 2 Monitoring CFM App</onos.app.title>
- <onos.app.origin>Microsemi Inc</onos.app.origin>
- <onos.app.category>default</onos.app.category>
- <onos.app.url>http://onosproject.org</onos.app.url>
- <onos.app.readme>Layer 2 Monitoring Connectivity Fault Management App</onos.app.readme>
- </properties>
+ <modules>
+ <module>api</module>
+ <module>app</module>
+ <module>nbi</module>
+ </modules>
<dependencies>
<dependency>
@@ -47,27 +35,6 @@
<dependency>
<groupId>org.onosproject</groupId>
- <artifactId>onos-incubator-api</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.onosproject</groupId>
- <artifactId>onos-core-common</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.onosproject</groupId>
- <artifactId>onos-cli</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.karaf.shell</groupId>
- <artifactId>org.apache.karaf.shell.console</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.onosproject</groupId>
<artifactId>onlab-junit</artifactId>
<scope>test</scope>
</dependency>
@@ -79,26 +46,6 @@
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.glassfish.jersey.test-framework</groupId>
- <artifactId>jersey-test-framework-core</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.glassfish.jersey.test-framework.providers</groupId>
- <artifactId>jersey-test-framework-provider-jetty</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.onosproject</groupId>
- <artifactId>onos-rest</artifactId>
- <version>${project.version}</version>
- <classifier>tests</classifier>
- <scope>test</scope>
- </dependency>
-
</dependencies>
-
</project>
+