Initial import of CFM and SOAM api

Change-Id: Icf5cc2d5fb34b75460e80e8cced0d70265bcd33b
diff --git a/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatCurrentTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatCurrentTest.java
new file mode 100644
index 0000000..d65c307
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatHistoryTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossAvailabilityStatHistoryTest.java
new file mode 100644
index 0000000..1b68b6e
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementCreateTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementCreateTest.java
new file mode 100644
index 0000000..c7d1264
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementEntryTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementEntryTest.java
new file mode 100644
index 0000000..30b637a
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatCurrentTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatCurrentTest.java
new file mode 100644
index 0000000..76e8246
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatHistoryTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementStatHistoryTest.java
new file mode 100644
index 0000000..46de87c
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementThresholdOptionTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/loss/LossMeasurementThresholdOptionTest.java
new file mode 100644
index 0000000..0882268
--- /dev/null
+++ b/incubator/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());
+    }
+}