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"));
+ }
+ }
+
+}
diff --git a/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/MilliPctTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/MilliPctTest.java
new file mode 100644
index 0000000..e51a761
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/StartTimeTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/StartTimeTest.java
new file mode 100644
index 0000000..4d7c6c0
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementCreateTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementCreateTest.java
new file mode 100644
index 0000000..d24effc
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementEntryTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementEntryTest.java
new file mode 100644
index 0000000..ad2439a
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementStatCurrentAndHistoryTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementStatCurrentAndHistoryTest.java
new file mode 100644
index 0000000..0bde63a
--- /dev/null
+++ b/incubator/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/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementThresholdOptionTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/delay/DelayMeasurementThresholdOptionTest.java
new file mode 100644
index 0000000..f838143
--- /dev/null
+++ b/incubator/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/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());
+ }
+}