Initial import of CFM and SOAM api
Change-Id: Icf5cc2d5fb34b75460e80e8cced0d70265bcd33b
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"));
+ }
+ }
+
+}