ONOS-2739 - OSPF Basic Packet Structures , which includes encoding and decoding
Change-Id: I3f09176ad4ccc330b8989f13b12f74dc86f53ae4
diff --git a/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/subtypes/OspfExternalDestination.java b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/subtypes/OspfExternalDestination.java
new file mode 100644
index 0000000..fd4882f
--- /dev/null
+++ b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/subtypes/OspfExternalDestination.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2014-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.protocol.lsa.subtypes;
+
+import com.google.common.base.MoreObjects;
+import org.onlab.packet.Ip4Address;
+
+/**
+ * Defines the OSPF external destination.
+ */
+public class OspfExternalDestination {
+
+ private boolean isType1orType2Metric;
+ private int metric;
+ private Ip4Address forwardingAddress;
+ private int externalRouterTag;
+
+ /**
+ * Gets whether type1 or type 2 metric.
+ *
+ * @return true if Type1 or false if Type2 metric
+ */
+ public boolean isType1orType2Metric() {
+ return isType1orType2Metric;
+ }
+
+ /**
+ * Sets whether type1 or Type2 metric.
+ *
+ * @param isType1orType2Metric is type 1 or type 2 metric
+ */
+ public void setType1orType2Metric(boolean isType1orType2Metric) {
+ this.isType1orType2Metric = isType1orType2Metric;
+ }
+
+ /**
+ * Gets the metric value.
+ *
+ * @return metric value
+ */
+ public int metric() {
+ return metric;
+ }
+
+ /**
+ * Sets the metric value.
+ *
+ * @param metric metric value
+ */
+ public void setMetric(int metric) {
+ this.metric = metric;
+ }
+
+ /**
+ * Gets forwarding address.
+ *
+ * @return forwarding address
+ */
+ public Ip4Address forwardingAddress() {
+ return forwardingAddress;
+ }
+
+ /**
+ * Sets forwarding address.
+ *
+ * @param forwardingAddress forwarding address
+ */
+ public void setForwardingAddress(Ip4Address forwardingAddress) {
+ this.forwardingAddress = forwardingAddress;
+ }
+
+ /**
+ * Gets external router tag.
+ *
+ * @return external router tag
+ */
+ public int externalRouterTag() {
+ return externalRouterTag;
+ }
+
+ /**
+ * Sets external router tag.
+ *
+ * @param externalRouterTag external router tag
+ */
+ public void setExternalRouterTag(int externalRouterTag) {
+ this.externalRouterTag = externalRouterTag;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("isType1orType2Metric", isType1orType2Metric)
+ .add("metric", metric)
+ .add("forwardingAddress", forwardingAddress)
+ .add("externalRouterTag", externalRouterTag)
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/subtypes/OspfLsaLink.java b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/subtypes/OspfLsaLink.java
new file mode 100644
index 0000000..5db5648
--- /dev/null
+++ b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/subtypes/OspfLsaLink.java
@@ -0,0 +1,132 @@
+/*
+ * 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.protocol.lsa.subtypes;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Representation of an OSPF LSA link.
+ */
+public class OspfLsaLink {
+
+ public String linkId;
+ public String linkData;
+ public int linkType;
+ public int metric;
+ public int tos;
+
+ /**
+ * Gets link id.
+ *
+ * @return link id
+ */
+ public String linkId() {
+ return linkId;
+ }
+
+ /**
+ * Sets link id.
+ *
+ * @param linkId link id
+ */
+ public void setLinkId(String linkId) {
+ this.linkId = linkId;
+ }
+
+ /**
+ * Gets link data.
+ *
+ * @return link data
+ */
+ public String linkData() {
+ return linkData;
+ }
+
+ /**
+ * Sets link data.
+ *
+ * @param linkData link data
+ */
+ public void setLinkData(String linkData) {
+ this.linkData = linkData;
+ }
+
+ /**
+ * Gets link type.
+ *
+ * @return link type
+ */
+ public int linkType() {
+ return linkType;
+ }
+
+ /**
+ * Sets link type.
+ *
+ * @param linkType link type
+ */
+ public void setLinkType(int linkType) {
+ this.linkType = linkType;
+ }
+
+ /**
+ * Gets metric value.
+ *
+ * @return metric.
+ */
+ public int metric() {
+ return metric;
+ }
+
+ /**
+ * Sets metric value.
+ *
+ * @param metric metric
+ */
+ public void setMetric(int metric) {
+ this.metric = metric;
+ }
+
+ /**
+ * Gets tos.
+ *
+ * @return tos
+ */
+ public int tos() {
+ return tos;
+ }
+
+ /**
+ * Sets tos.
+ *
+ * @param tos tos
+ */
+ public void setTos(int tos) {
+ this.tos = tos;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("linkID", linkId)
+ .add("linkData", linkData)
+ .add("linkType", linkType)
+ .add("metric", metric)
+ .add("tos", tos)
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/AsbrSummaryLsa.java b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/AsbrSummaryLsa.java
new file mode 100644
index 0000000..d5c9047
--- /dev/null
+++ b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/AsbrSummaryLsa.java
@@ -0,0 +1,196 @@
+/*
+ * 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.protocol.lsa.types;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import com.google.common.primitives.Bytes;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.ospf.controller.OspfLsaType;
+import org.onosproject.ospf.exceptions.OspfErrorType;
+import org.onosproject.ospf.exceptions.OspfParseException;
+import org.onosproject.ospf.protocol.lsa.LsaHeader;
+import org.onosproject.ospf.protocol.util.OspfUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Representation of an ASBR Summary LSA and methods to access them.
+ */
+public class AsbrSummaryLsa extends LsaHeader {
+
+ /*
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS age | Options | 3 or 4 |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Link State ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Advertising Router |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS sequence number |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS checksum | length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Network Mask |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | 0 | metric |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | TOS | TOS metric |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | ... |
+
+ Summary LSA format
+ REFERENCE : RFC 2328
+ */
+ private Ip4Address networkMask;
+ private int metric;
+
+ /**
+ * Creates an instance of ASBR Summary LSA.
+ *
+ * @param lsaHeader lsa header instance.
+ */
+ public AsbrSummaryLsa(LsaHeader lsaHeader) {
+ populateHeader(lsaHeader);
+ }
+
+ /**
+ * Gets network mask.
+ *
+ * @return networkMask network mask
+ */
+ public Ip4Address networkMask() {
+ return networkMask;
+ }
+
+ /**
+ * Sets network mask.
+ *
+ * @param networkMask network mask
+ */
+ public void setNetworkMask(Ip4Address networkMask) {
+ this.networkMask = networkMask;
+ }
+
+ /**
+ * Gets metric value.
+ *
+ * @return metric value
+ */
+ public int metric() {
+ return metric;
+ }
+
+ /**
+ * Sets metric value.
+ *
+ * @param metric metric value
+ */
+ public void setMetric(int metric) {
+ this.metric = metric;
+ }
+
+ /**
+ * Reads from channel buffer and populate instance.
+ *
+ * @param channelBuffer channelBuffer instance.
+ * @throws OspfParseException might throws exception while parsing buffer
+ */
+ public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
+ try {
+ byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
+ channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
+ this.setNetworkMask(Ip4Address.valueOf(tempByteArray));
+ int unusedByte = channelBuffer.readByte();
+ this.setMetric(channelBuffer.readUnsignedMedium());
+ } catch (Exception e) {
+ log.debug("Error::AsbrSummaryLsa:: {}", e.getMessage());
+ throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
+ }
+ }
+
+ /**
+ * Gets LSA bytes as array.
+ *
+ * @return LSA message as bytes
+ * @throws OspfParseException might throws exception while parsing packet
+ */
+ public byte[] asBytes() throws OspfParseException {
+ byte[] lsaMessage = null;
+
+ byte[] lsaHeader = getLsaHeaderAsByteArray();
+ byte[] lsaBody = getLsaBodyAsByteArray();
+ lsaMessage = Bytes.concat(lsaHeader, lsaBody);
+
+ return lsaMessage;
+ }
+
+ /**
+ * Get LSA body as byte array.
+ *
+ * @return byte array contains lsa body
+ * @throws OspfParseException might throws exception while parsing packet
+ */
+ public byte[] getLsaBodyAsByteArray() throws OspfParseException {
+ List<Byte> bodyLst = new ArrayList<>();
+
+ try {
+ bodyLst.addAll(Bytes.asList(this.networkMask().toOctets()));
+ bodyLst.addAll(Bytes.asList(OspfUtil.convertToFourBytes(this.metric())));
+ } catch (Exception e) {
+ log.debug("Error::getLsrBodyAsByteArray {}", e.getMessage());
+ throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
+ }
+
+ return Bytes.toArray(bodyLst);
+ }
+
+ @Override
+ public OspfLsaType getOspfLsaType() {
+ return OspfLsaType.ASBR_SUMMARY;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ AsbrSummaryLsa that = (AsbrSummaryLsa) o;
+ return Objects.equal(networkMask, that.networkMask) &&
+ Objects.equal(metric, that.metric);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(networkMask, metric);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("networkMask", networkMask)
+ .add("metric", metric)
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/ExternalLsa.java b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/ExternalLsa.java
new file mode 100644
index 0000000..c6d1642
--- /dev/null
+++ b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/ExternalLsa.java
@@ -0,0 +1,234 @@
+/*
+ * 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.protocol.lsa.types;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import com.google.common.primitives.Bytes;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.ospf.controller.OspfLsaType;
+import org.onosproject.ospf.exceptions.OspfErrorType;
+import org.onosproject.ospf.exceptions.OspfParseException;
+import org.onosproject.ospf.protocol.lsa.LsaHeader;
+import org.onosproject.ospf.protocol.lsa.subtypes.OspfExternalDestination;
+import org.onosproject.ospf.protocol.util.OspfUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Representation of an External LSA and the fields and methods to access them.
+ */
+public class ExternalLsa extends LsaHeader {
+
+ /*
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS age | Options | 5 |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Link State ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Advertising Router |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS sequence number |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS checksum | length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Network Mask |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ |E| 0 | metric |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Forwarding address |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | External Route Tag |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ |E| TOS | TOS metric |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Forwarding address |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | External Route Tag |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | ... |
+
+ External LSA format
+ REFERENCE : RFC 2328
+ */
+ private static final Logger log =
+ LoggerFactory.getLogger(ExternalLsa.class);
+ private Ip4Address networkMask;
+ private List<OspfExternalDestination> externalDestinations = new ArrayList<>();
+
+ /**
+ * Creates an instance of External LSA.
+ *
+ * @param lsaHeader lsa header instance.
+ */
+ public ExternalLsa(LsaHeader lsaHeader) {
+ populateHeader(lsaHeader);
+ }
+
+
+ /**
+ * Gets the network mask.
+ *
+ * @return networkMask
+ */
+ public Ip4Address networkMask() {
+ return networkMask;
+ }
+
+ /**
+ * Sets network mask.
+ *
+ * @param networkMask network mask
+ */
+ public void setNetworkMask(Ip4Address networkMask) {
+ this.networkMask = networkMask;
+ }
+
+ /**
+ * Adds the external destination details to the list.
+ *
+ * @param externalDestination external destination details
+ */
+ public void addExternalDestination(OspfExternalDestination externalDestination) {
+ if (!externalDestinations.contains(externalDestination)) {
+ externalDestinations.add(externalDestination);
+ }
+ }
+
+ /**
+ * Reads from channel buffer and populate instance.
+ *
+ * @param channelBuffer channelBuffer instance
+ * @throws OspfParseException might throws exception while parsing buffer
+ */
+ public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
+
+ try {
+ byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
+ channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
+ this.setNetworkMask(Ip4Address.valueOf(tempByteArray));
+
+ while (channelBuffer.readableBytes() >= OspfUtil.EXTERNAL_DESTINATION_LENGTH) {
+ OspfExternalDestination externalDestination = new OspfExternalDestination();
+
+ //E Bit - use to find type1 or type2
+ int eIsSet = channelBuffer.readByte();
+ if (eIsSet != 0) {
+ externalDestination.setType1orType2Metric(true);
+ } else {
+ externalDestination.setType1orType2Metric(false);
+ }
+ externalDestination.setMetric(channelBuffer.readUnsignedMedium());
+ tempByteArray = new byte[OspfUtil.FOUR_BYTES];
+ channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
+ externalDestination.setForwardingAddress(Ip4Address.valueOf(tempByteArray));
+ externalDestination.setExternalRouterTag(channelBuffer.readInt());
+
+ this.addExternalDestination(externalDestination);
+ }
+ } catch (Exception e) {
+ log.debug("Error::ExternalLSA:: {}", e.getMessage());
+ throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
+ }
+ }
+
+ /**
+ * Gets LSA as bytes.
+ *
+ * @return LSA as bytes.
+ * @throws OspfParseException might throws exception while parsing packet
+ */
+ public byte[] asBytes() throws OspfParseException {
+ byte[] lsaMessage = null;
+
+ byte[] lsaHeader = getLsaHeaderAsByteArray();
+ byte[] lsaBody = getLsaBodyAsByteArray();
+ lsaMessage = Bytes.concat(lsaHeader, lsaBody);
+
+ return lsaMessage;
+ }
+
+ /**
+ * Gets LSA body as byte array.
+ *
+ * @return byte array contains LSA body
+ * @throws OspfParseException might throws exception while parsing buffer
+ */
+ public byte[] getLsaBodyAsByteArray() throws OspfParseException {
+ List<Byte> bodyLst = new ArrayList<>();
+
+ try {
+ bodyLst.addAll(Bytes.asList(this.networkMask().toOctets()));
+
+ //add each OSPFExternalDestination details
+ for (OspfExternalDestination externalDest : externalDestinations) {
+ if (externalDest.isType1orType2Metric()) {
+ //add 1 followed by 7 zeros equals to decimal 128
+ bodyLst.add((byte) 128);
+ } else {
+ bodyLst.add((byte) 0);
+ }
+
+ bodyLst.addAll(Bytes.asList(OspfUtil.convertToThreeBytes(externalDest.metric())));
+ bodyLst.addAll(Bytes.asList(externalDest.forwardingAddress().toOctets()));
+ bodyLst.addAll(Bytes.asList(OspfUtil.convertToFourBytes(externalDest.externalRouterTag())));
+ }
+ } catch (Exception e) {
+ log.debug("Error::getLsrBodyAsByteArray {}", e.getMessage());
+ return Bytes.toArray(bodyLst);
+ }
+
+ return Bytes.toArray(bodyLst);
+ }
+
+ @Override
+ public OspfLsaType getOspfLsaType() {
+ return OspfLsaType.EXTERNAL_LSA;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (other == null || getClass() != other.getClass()) {
+ return false;
+ }
+ ExternalLsa that = (ExternalLsa) other;
+ return Objects.equal(networkMask, that.networkMask) &&
+ Objects.equal(externalDestinations, that.externalDestinations);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(networkMask, externalDestinations);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("networkMask", networkMask)
+ .add("externalDestinations", externalDestinations)
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/NetworkLsa.java b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/NetworkLsa.java
new file mode 100644
index 0000000..07465b2
--- /dev/null
+++ b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/NetworkLsa.java
@@ -0,0 +1,195 @@
+/*
+ * 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.protocol.lsa.types;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import com.google.common.primitives.Bytes;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.ospf.exceptions.OspfErrorType;
+import org.onosproject.ospf.exceptions.OspfParseException;
+import org.onosproject.ospf.protocol.lsa.LsaHeader;
+import org.onosproject.ospf.protocol.util.OspfUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Representation of a Network LSA and fields and methods to access them.
+ */
+public class NetworkLsa extends LsaHeader {
+
+ /*
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS age | Options | 2 |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Link State ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Advertising Router |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS sequence number |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS checksum | length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Network Mask |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Attached Router |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | ... |
+ */
+ private static final Logger log =
+ LoggerFactory.getLogger(NetworkLsa.class);
+ private Ip4Address networkMask;
+ private List<Ip4Address> attachedRouters = new ArrayList<>();
+
+ /**
+ * Creates an instance of Network LSA.
+ */
+ public NetworkLsa() {
+ }
+
+ /**
+ * Creates an instance of Network LSA.
+ *
+ * @param lsaHeader lsa header instance.
+ */
+ public NetworkLsa(LsaHeader lsaHeader) {
+ populateHeader(lsaHeader);
+ }
+
+ /**
+ * Gets network mask.
+ *
+ * @return network mask
+ */
+ public Ip4Address networkMask() {
+ return networkMask;
+ }
+
+ /**
+ * Sets network mask.
+ *
+ * @param networkMask network mask
+ */
+ public void setNetworkMask(Ip4Address networkMask) {
+ this.networkMask = networkMask;
+ }
+
+ /**
+ * Adds attached router to list.
+ *
+ * @param attachedRouter attached router ip address.
+ */
+ public void addAttachedRouter(Ip4Address attachedRouter) {
+ attachedRouters.add(attachedRouter);
+ }
+
+ /**
+ * Reads from channel buffer and populate instance.
+ *
+ * @param channelBuffer channel buffer instance
+ * @throws OspfParseException might throws exception while parsing buffer
+ */
+ public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
+
+ try {
+ byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
+ channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
+ this.setNetworkMask(Ip4Address.valueOf(tempByteArray));
+ //add all the attached routers
+ while (channelBuffer.readableBytes() > 0) {
+ tempByteArray = new byte[OspfUtil.FOUR_BYTES];
+ channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
+ this.addAttachedRouter(Ip4Address.valueOf(tempByteArray));
+ }
+ } catch (Exception e) {
+ log.debug("Error::NetworkLSA::readFrom:: {}", e.getMessage());
+ throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
+ }
+ }
+
+ /**
+ * Gets LSA as bytes.
+ *
+ * @return LSA as byte array
+ * @throws OspfParseException might throws exception while parsing packet
+ */
+ public byte[] asBytes() throws OspfParseException {
+ byte[] lsaMessage = null;
+
+ byte[] lsaHeader = getLsaHeaderAsByteArray();
+ byte[] lsaBody = getLSABodyAsByteArray();
+ lsaMessage = Bytes.concat(lsaHeader, lsaBody);
+
+ return lsaMessage;
+ }
+
+ /**
+ * Gets LSA body as byte array.
+ *
+ * @return LSA body as byte array
+ * @throws OspfParseException might throws exception while parsing packet
+ */
+ public byte[] getLSABodyAsByteArray() throws OspfParseException {
+ List<Byte> bodyLst = new ArrayList<>();
+
+ try {
+ bodyLst.addAll(Bytes.asList(this.networkMask().toOctets()));
+ //add each attachedRouters details
+ for (Ip4Address attachedRouter : attachedRouters) {
+ //attached router
+ bodyLst.addAll(Bytes.asList(attachedRouter.toOctets()));
+ }
+ } catch (Exception e) {
+ log.debug("Error::NetworkLSA::getLsrBodyAsByteArray {}", e.getMessage());
+ throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
+ }
+
+ return Bytes.toArray(bodyLst);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ NetworkLsa that = (NetworkLsa) o;
+ return Objects.equal(networkMask, that.networkMask) &&
+ Objects.equal(attachedRouters, that.attachedRouters);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(networkMask, attachedRouters);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("networkMask", networkMask)
+ .add("attachedRouters", attachedRouters)
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/OpaqueLsa11.java b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/OpaqueLsa11.java
new file mode 100644
index 0000000..d86d8b2
--- /dev/null
+++ b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/OpaqueLsa11.java
@@ -0,0 +1,124 @@
+/*
+ * 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.protocol.lsa.types;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import com.google.common.primitives.Bytes;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.ospf.controller.OspfLsaType;
+import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
+
+/**
+ * Representation of an Opaque LSA of type AS (11).
+ */
+public class OpaqueLsa11 extends OpaqueLsaHeader {
+ /*
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS age | Options | 9, 10 or 11 |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Opaque Type | Opaque ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Advertising Router |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS Sequence Number |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS checksum | Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | |
+ + +
+ | Opaque Information |
+ + +
+ | ... |
+ */
+ private byte[] opaqueInfo = null;
+
+ /**
+ * Creates an instance of Opaque type 11 LSA.
+ *
+ * @param lsaHeader LSA header instance
+ */
+ public OpaqueLsa11(OpaqueLsaHeader lsaHeader) {
+ populateHeader(lsaHeader);
+ }
+
+ /**
+ * Reads from channel buffer and populate this.
+ *
+ * @param channelBuffer channelBuffer instance.
+ */
+ public void readFrom(ChannelBuffer channelBuffer) {
+ int length = channelBuffer.readableBytes();
+ opaqueInfo = new byte[length];
+ channelBuffer.readBytes(opaqueInfo, 0, length);
+ }
+
+ /**
+ * Returns instance as bytes.
+ *
+ * @return instance as bytes
+ */
+ public byte[] asBytes() {
+ byte[] lsaMessage = null;
+
+ byte[] lsaHeader = getOpaqueLsaHeaderAsByteArray();
+ byte[] lsaBody = getLsaBodyAsByteArray();
+ lsaMessage = Bytes.concat(lsaHeader, lsaBody);
+
+ return lsaMessage;
+ }
+
+ /**
+ * Get the LSA body as byte array.
+ *
+ * @return LSA body as byte array
+ */
+ public byte[] getLsaBodyAsByteArray() {
+ return opaqueInfo;
+ }
+
+ @Override
+ public OspfLsaType getOspfLsaType() {
+ return OspfLsaType.AS_OPAQUE_LSA;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ OpaqueLsa11 that = (OpaqueLsa11) o;
+ return Objects.equal(opaqueInfo, that.opaqueInfo);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(opaqueInfo);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("opaqueInfo", opaqueInfo)
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/OpaqueLsa9.java b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/OpaqueLsa9.java
new file mode 100644
index 0000000..0780be0
--- /dev/null
+++ b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/OpaqueLsa9.java
@@ -0,0 +1,126 @@
+/*
+ * 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.protocol.lsa.types;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import com.google.common.primitives.Bytes;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.ospf.controller.OspfLsaType;
+import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
+
+/**
+ * Representation of an Opaque LSA of type link local (9).
+ */
+public class OpaqueLsa9 extends OpaqueLsaHeader {
+
+ /*
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS age | Options | 9, 10 or 11 |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Opaque Type | Opaque ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Advertising Router |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS Sequence Number |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS checksum | Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | |
+ + +
+ | Opaque Information |
+ + +
+ | ... |
+ */
+ private byte[] opaqueInfo = null;
+
+ /**
+ * Creates an instance of Opaque type 9 LSA.
+ *
+ * @param lsaHeader LSA header instance
+ */
+ public OpaqueLsa9(OpaqueLsaHeader lsaHeader) {
+ populateHeader(lsaHeader);
+ }
+
+ /**
+ * Reads from channel buffer and populate instance.
+ *
+ * @param channelBuffer channelBuffer instance
+ */
+ public void readFrom(ChannelBuffer channelBuffer) {
+ int length = channelBuffer.readableBytes();
+ opaqueInfo = new byte[length];
+ channelBuffer.readBytes(opaqueInfo, 0, length);
+ }
+
+ /**
+ * Returns instance as bytes.
+ *
+ * @return instance as bytes
+ */
+ public byte[] asBytes() {
+ byte[] lsaMessage = null;
+
+ byte[] lsaHeader = getOpaqueLsaHeaderAsByteArray();
+ byte[] lsaBody = getLsaBodyAsByteArray();
+ lsaMessage = Bytes.concat(lsaHeader, lsaBody);
+
+ return lsaMessage;
+ }
+
+ /**
+ * Gets the LSA body.
+ *
+ * @return the LSA body
+ */
+ public byte[] getLsaBodyAsByteArray() {
+ return opaqueInfo;
+
+ }
+
+ @Override
+ public OspfLsaType getOspfLsaType() {
+ return OspfLsaType.LINK_LOCAL_OPAQUE_LSA;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ OpaqueLsa9 that = (OpaqueLsa9) o;
+ return Objects.equal(opaqueInfo, that.opaqueInfo);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(opaqueInfo);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("opaqueInfo", opaqueInfo)
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/SummaryLsa.java b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/SummaryLsa.java
new file mode 100644
index 0000000..df16dd9
--- /dev/null
+++ b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/SummaryLsa.java
@@ -0,0 +1,195 @@
+/*
+ * 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.protocol.lsa.types;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import com.google.common.primitives.Bytes;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.ospf.controller.OspfLsaType;
+import org.onosproject.ospf.exceptions.OspfErrorType;
+import org.onosproject.ospf.exceptions.OspfParseException;
+import org.onosproject.ospf.protocol.lsa.LsaHeader;
+import org.onosproject.ospf.protocol.util.OspfUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Representation of a Summary LSA, fields and methods to access them.
+ */
+public class SummaryLsa extends LsaHeader {
+ /*
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS age | Options | 3 or 4 |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Link State ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Advertising Router |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS sequence number |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LS checksum | length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Network Mask |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | 0 | metric |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | TOS | TOS metric |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | ... |
+
+ */
+ private static final Logger log = LoggerFactory.getLogger(SummaryLsa.class);
+ private Ip4Address networkMask;
+ private int metric;
+
+ /**
+ * Creates an instance of Summary LSA.
+ *
+ * @param lsaHeader LSA header instance
+ */
+ public SummaryLsa(LsaHeader lsaHeader) {
+ populateHeader(lsaHeader);
+ }
+
+ /**
+ * Gets network mask.
+ *
+ * @return network mask
+ */
+ public Ip4Address networkMask() {
+ return networkMask;
+ }
+
+ /**
+ * Sets network mask.
+ *
+ * @param networkMask network mask
+ */
+ public void setNetworkMask(Ip4Address networkMask) {
+ this.networkMask = networkMask;
+ }
+
+ /**
+ * Gets metric value.
+ *
+ * @return metric
+ */
+ public int metric() {
+ return metric;
+ }
+
+ /**
+ * Sets metric value.
+ *
+ * @param metric metric value
+ */
+ public void setMetric(int metric) {
+ this.metric = metric;
+ }
+
+ /**
+ * Reads from channel buffer and populate instance.
+ *
+ * @param channelBuffer channelBuffer instance
+ * @throws OspfParseException might throws exception while parsing buffer
+ */
+ public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
+
+ try {
+ byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
+ channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
+ this.setNetworkMask(Ip4Address.valueOf(tempByteArray));
+ int unsedByte = channelBuffer.readByte();
+ this.setMetric(channelBuffer.readUnsignedMedium());
+ } catch (Exception e) {
+ log.debug("Error::SummaryLsa:: {}", e.getMessage());
+ throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
+ }
+ }
+
+ /**
+ * Returns instance as bytes.
+ *
+ * @return instance as bytes
+ */
+ public byte[] asBytes() {
+ byte[] lsaMessage = null;
+ byte[] lsaHeader = getLsaHeaderAsByteArray();
+ byte[] lsaBody = getLsaBodyAsByteArray();
+ lsaMessage = Bytes.concat(lsaHeader, lsaBody);
+
+ return lsaMessage;
+ }
+
+ /**
+ * Get the LSA body.
+ *
+ * @return LSA body
+ */
+ public byte[] getLsaBodyAsByteArray() {
+ List<Byte> bodyLst = new ArrayList<>();
+
+ try {
+ bodyLst.addAll(Bytes.asList(this.networkMask().toOctets()));
+ bodyLst.add((byte) 0);
+ bodyLst.addAll(Bytes.asList(OspfUtil.convertToThreeBytes(this.metric())));
+ } catch (Exception e) {
+ log.debug("Error::getLsrBodyAsByteArray {}", e.getMessage());
+ return Bytes.toArray(bodyLst);
+ }
+
+ return Bytes.toArray(bodyLst);
+ }
+
+ @Override
+ public OspfLsaType getOspfLsaType() {
+ return OspfLsaType.SUMMARY;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("networkMask", networkMask)
+ .add("metric", metric)
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ SummaryLsa that = (SummaryLsa) o;
+ return Objects.equal(networkMask, that.networkMask) &&
+ Objects.equal(metric, that.metric);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(networkMask, metric);
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/TopLevelTlv.java b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/TopLevelTlv.java
new file mode 100644
index 0000000..2cf9fdd
--- /dev/null
+++ b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/types/TopLevelTlv.java
@@ -0,0 +1,22 @@
+/*
+ * 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.protocol.lsa.types;
+
+/**
+ * Marker interface represents a top level TLV in an Opaque LSA.
+ */
+public interface TopLevelTlv {
+}