Initial import of CFM and SOAM api

Change-Id: Icf5cc2d5fb34b75460e80e8cced0d70265bcd33b
diff --git a/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/ComponentTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/ComponentTest.java
new file mode 100644
index 0000000..cd71911
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceAssociationTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceAssociationTest.java
new file mode 100644
index 0000000..68716dd
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceDomainTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MaintenanceDomainTest.java
new file mode 100644
index 0000000..74e076c
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbCreateTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbCreateTest.java
new file mode 100644
index 0000000..e415a84
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbEntryTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepLbEntryTest.java
new file mode 100644
index 0000000..47ef5b3
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/MepTest.java
new file mode 100644
index 0000000..eee1f97
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/RemoteMepEntryTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/RemoteMepEntryTest.java
new file mode 100644
index 0000000..9ec1029
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdShortTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MaIdShortTest.java
new file mode 100644
index 0000000..970e6a0
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MdIdTest.java
new file mode 100644
index 0000000..18af6b6
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MepIdTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/cfm/identifier/MepIdTest.java
new file mode 100644
index 0000000..ed11e39
--- /dev/null
+++ b/incubator/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"));
+        }
+    }
+
+}