ONOS-2739 - OSPF Basic Packet Structures , which includes encoding and decoding
Change-Id: I4bf4b7eb26a0e2b5006b41b24d67c7f21450b11b
diff --git a/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/exceptions/OspfErrorType.java b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/exceptions/OspfErrorType.java
new file mode 100644
index 0000000..1aacb07
--- /dev/null
+++ b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/exceptions/OspfErrorType.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.ospf.exceptions;
+
+/**
+ * Defines all error codes and error sub codes.
+ */
+public final class OspfErrorType {
+
+ //Represents an invalid OSPF message header
+ public static final byte MESSAGE_HEADER_ERROR = 1;
+ //Represents an invalid OSPF message body
+ public static final byte OSPF_MESSAGE_ERROR = 2;
+ //Message Header error sub codes
+ //Represents an invalid OSPF message length
+ public static final byte BAD_MESSAGE_LENGTH = 2;
+ //Represents an invalid OSPF message
+ public static final byte BAD_MESSAGE = 4;
+
+ /**
+ * Creates an instance of OSPF error type.
+ */
+ private OspfErrorType() {
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/exceptions/OspfParseException.java b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/exceptions/OspfParseException.java
new file mode 100644
index 0000000..24e8703
--- /dev/null
+++ b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/exceptions/OspfParseException.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.ospf.exceptions;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Representation of a custom exception for OSPF.
+ */
+public class OspfParseException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+ private byte errorCode;
+ private byte errorSubCode;
+
+ /**
+ * Creates a new OSPF exception.
+ */
+ public OspfParseException() {
+ super();
+ }
+
+ /**
+ * Creates a new OSPF exception based on the given arguments.
+ *
+ * @param message the detail of exception in string
+ * @param cause underlying cause of the error
+ */
+ public OspfParseException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates a new OSPF exception for the given message.
+ *
+ * @param message the detail of exception in string
+ */
+ public OspfParseException(final String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new OSPF exception from throwable instance.
+ *
+ * @param cause underlying cause of the error
+ */
+ public OspfParseException(final Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Creates a new OSPF exception from error code and error sub code.
+ *
+ * @param errorCode error code of OSPF message
+ * @param errorSubCode error sub code of OSPF message
+ */
+ public OspfParseException(final byte errorCode, final byte errorSubCode) {
+ super();
+ this.errorCode = errorCode;
+ this.errorSubCode = errorSubCode;
+ }
+
+ /**
+ * Returns error code for this exception.
+ *
+ * @return error code for this exception
+ */
+ public byte errorCode() {
+ return this.errorCode;
+ }
+
+ /**
+ * Returns error sub code for this exception.
+ *
+ * @return error sub code for this exception
+ */
+ public byte errorSubCode() {
+ return this.errorSubCode;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("errorCode", errorCode)
+ .add("errorSubCode", errorSubCode)
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/exceptions/package-info.java b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/exceptions/package-info.java
new file mode 100644
index 0000000..d74c2be
--- /dev/null
+++ b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/exceptions/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Implementation of the OSPF exception types.
+ */
+package org.onosproject.ospf.exceptions;
\ No newline at end of file