ONOS-4083, ONOS-4084, ONOS-4096, ONOS-4097:ISIS PDU Data Structures
Change-Id: I22d30e8f7ba7d414e75254fdec6d0865bf471ff9
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/AttachedToOtherAreas.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/AttachedToOtherAreas.java
new file mode 100644
index 0000000..3dfa308
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/AttachedToOtherAreas.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2016-present 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.isis.io.isispacket.pdu;
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Representation of attached to other areas.
+ */
+public enum AttachedToOtherAreas {
+ DEFAULTMETRIC(1),
+ DELAYMETRIC(2),
+ EXPENSEMETRIC(4),
+ ERRORMETRIC(8),
+ NONE(0);
+ // Reverse lookup table
+ private static final Map<Integer, AttachedToOtherAreas> LOOKUP = new HashMap<>();
+
+ // Populate the lookup table on loading time
+ static {
+ for (AttachedToOtherAreas attachedToOtherAreas :
+ EnumSet.allOf(AttachedToOtherAreas.class)) {
+ LOOKUP.put(attachedToOtherAreas.value(), attachedToOtherAreas);
+ }
+ }
+
+ private int value;
+
+ /**
+ * Returns the attached to other areas value.
+ *
+ * @param value attached to other areas value
+ */
+ AttachedToOtherAreas(int value) {
+ this.value = value;
+ }
+
+ /**
+ * Returns the value for attached to other areas from pdu type value.
+ *
+ * @param pduTypeValue to get attached areas value
+ * @return attachedToOtherAreas value of the enum
+ */
+ public static AttachedToOtherAreas get(int pduTypeValue) {
+ return LOOKUP.get(pduTypeValue);
+ }
+
+ /**
+ * Returns the value representing PDU type.
+ *
+ * @return value represents PDU type
+ */
+ public int value() {
+ return value;
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/Csnp.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/Csnp.java
new file mode 100644
index 0000000..80dc5b1
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/Csnp.java
@@ -0,0 +1,272 @@
+/*
+ * Copyright 2016-present 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.isis.io.isispacket.pdu;
+
+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.isis.io.isispacket.IsisHeader;
+import org.onosproject.isis.io.isispacket.tlv.IsisTlv;
+import org.onosproject.isis.io.isispacket.tlv.TlvFinder;
+import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
+import org.onosproject.isis.io.isispacket.tlv.TlvType;
+import org.onosproject.isis.io.isispacket.tlv.TlvsToBytes;
+import org.onosproject.isis.io.util.IsisUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Representation of complete sequence number PDU.
+ */
+public class Csnp extends IsisHeader {
+
+ /*
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Intra-domain Routing Protocol Discriminator |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Length Indicator |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Version/Protocol ID Extension |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | ID Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | R | R | R | PDU Type |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Version |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Reserved |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Maximum area address |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | PDU Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Source ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Start LSP ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | End LSP ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Variable Lengths Fields |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ CSNP Message Format
+ REFERENCE : ISO/IEC 10589
+ */
+ private int pduLength;
+ private String sourceId;
+ private String startLspId;
+ private String endLspId;
+ private List<IsisTlv> variableLengths = new ArrayList<>();
+
+ /**
+ * Creates the instance for this class.
+ *
+ * @param isisHeader ISIS header
+ */
+ public Csnp(IsisHeader isisHeader) {
+ populateHeader(isisHeader);
+ }
+
+ /**
+ * Returns the list of all tlvs.
+ *
+ * @return variableLengths list of tlvs
+ */
+ public List<IsisTlv> getAllTlv() {
+ return variableLengths;
+ }
+
+ /**
+ * Returns the source ID of csnp.
+ *
+ * @return sourceId source ID
+ */
+ public String sourceId() {
+ return sourceId;
+ }
+
+ /**
+ * Sets the source ID for csnp.
+ *
+ * @param sourceId source ID
+ */
+ public void setSourceId(String sourceId) {
+ this.sourceId = sourceId;
+ }
+
+ /**
+ * Returns the initial link state packet ID of csnp.
+ *
+ * @return startLspId start link state packet ID
+ */
+ public String startLspId() {
+ return startLspId;
+ }
+
+ /**
+ * Sets the initial link state packet ID for csnp.
+ *
+ * @param startLspId start link state packet ID
+ */
+ public void setStartLspId(String startLspId) {
+ this.startLspId = startLspId;
+ }
+
+ /**
+ * Returns the end link state packet ID of csnp.
+ *
+ * @return endLspId end link state packet ID of csnp.
+ */
+ public String endLspId() {
+ return endLspId;
+ }
+
+ /**
+ * Sets the end link state packet ID for csnp.
+ *
+ * @param endLspId end link state packet ID of csnp.
+ */
+ public void setEndLspId(String endLspId) {
+ this.endLspId = endLspId;
+ }
+
+ /**
+ * Returns the packet data unit length of link state packet.
+ * Entire length of this PDU, in octets
+ *
+ * @return pduLength packet date unit length
+ */
+ public int pduLength() {
+ return pduLength;
+ }
+
+ /**
+ * Sets the packet data unit length for link state packet.
+ * Entire Length of this PDU, in octets
+ *
+ * @param pduLength packet data length
+ */
+ public void setPduLength(int pduLength) {
+ this.pduLength = pduLength;
+ }
+
+ @Override
+ public void readFrom(ChannelBuffer channelBuffer) {
+ this.setPduLength(channelBuffer.readUnsignedShort());
+ //source id + 1 value
+ byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
+ channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
+ this.setSourceId(IsisUtil.systemIdPlus(tempByteArray));
+ //start lsp id + 2 value
+ tempByteArray = new byte[IsisUtil.ID_PLUS_TWO_BYTE];
+ channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_TWO_BYTE);
+ this.setStartLspId(IsisUtil.systemIdPlus(tempByteArray));
+ //end lsp id + 2 value
+ tempByteArray = new byte[IsisUtil.ID_PLUS_TWO_BYTE];
+ channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_TWO_BYTE);
+ this.setEndLspId(IsisUtil.systemIdPlus(tempByteArray));
+ //tlv here
+ while (channelBuffer.readableBytes() > 0) {
+ TlvHeader tlvHeader = new TlvHeader();
+ tlvHeader.setTlvType(channelBuffer.readUnsignedByte());
+ tlvHeader.setTlvLength(channelBuffer.readUnsignedByte());
+ TlvType tlvValue = TlvType.get(tlvHeader.tlvType());
+ if (tlvValue != null) {
+ IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength()));
+ this.variableLengths.add(tlv);
+ } else {
+ channelBuffer.readBytes(tlvHeader.tlvLength());
+ }
+ }
+ }
+
+ @Override
+ public byte[] asBytes() {
+ byte[] csnpMessage = null;
+ byte[] isisPduHeader = isisPduHeader();
+ byte[] csnpBody = completeSequenceNumberPduBody();
+ csnpMessage = Bytes.concat(isisPduHeader, csnpBody);
+ return csnpMessage;
+ }
+
+ /**
+ * Builds ISIS PDU header for complete sequence numbers PDU.
+ *
+ * @return isisPduHeader ISIS PDU header
+ */
+ public byte[] isisPduHeader() {
+ List<Byte> headerList = new ArrayList<>();
+ headerList.add(this.irpDiscriminator());
+ headerList.add((byte) IsisUtil.getPduHeaderLength(this.pduType()));
+ headerList.add(this.version());
+ headerList.add(this.idLength());
+ headerList.add((byte) this.pduType());
+ headerList.add(this.version2());
+ headerList.add(this.reserved());
+ headerList.add(this.maximumAreaAddresses());
+ return Bytes.toArray(headerList);
+ }
+
+ /**
+ * Builds complete sequence numbers PDU body.
+ *
+ * @return bodyList complete sequence numbers PDU body
+ */
+ public byte[] completeSequenceNumberPduBody() {
+ List<Byte> bodyList = new ArrayList<>();
+ bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength())));
+ bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.sourceId()));
+ bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.startLspId()));
+ bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.endLspId()));
+ for (IsisTlv isisTlv : variableLengths) {
+ bodyList.addAll(TlvsToBytes.tlvToBytes(isisTlv));
+ }
+ return Bytes.toArray(bodyList);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("pduLength", pduLength)
+ .add("sourceId", sourceId)
+ .add("startLspId", startLspId)
+ .add("endLspId", endLspId)
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ Csnp that = (Csnp) o;
+ return Objects.equal(pduLength, that.pduLength) &&
+ Objects.equal(sourceId, that.sourceId) &&
+ Objects.equal(startLspId, that.startLspId) &&
+ Objects.equal(endLspId, that.endLspId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(pduLength, sourceId, startLspId, endLspId);
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/HelloPdu.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/HelloPdu.java
new file mode 100644
index 0000000..6ce37c8
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/HelloPdu.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright 2016-present 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.isis.io.isispacket.pdu;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import org.onlab.packet.Ip4Address;
+import org.onlab.packet.MacAddress;
+import org.onosproject.isis.controller.IsisInterfaceState;
+import org.onosproject.isis.io.isispacket.IsisHeader;
+import org.onosproject.isis.io.isispacket.tlv.AdjacencyStateTlv;
+import org.onosproject.isis.io.isispacket.tlv.AreaAddressTlv;
+import org.onosproject.isis.io.isispacket.tlv.IpInterfaceAddressTlv;
+import org.onosproject.isis.io.isispacket.tlv.IsisNeighborTlv;
+import org.onosproject.isis.io.isispacket.tlv.IsisTlv;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Representation of ISIS hello PDU.
+ */
+public abstract class HelloPdu extends IsisHeader {
+
+ protected List<IsisTlv> variableLengths = new ArrayList<>();
+ private byte circuitType;
+ private String sourceId;
+ private int holdingTime;
+ private int pduLength;
+
+ public void addTlv(IsisTlv isisTlv) {
+ variableLengths.add(isisTlv);
+ }
+
+ /**
+ * Returns the variable lengths.
+ *
+ * @return variable lengths
+ */
+ public List<IsisTlv> tlvs() {
+ return variableLengths;
+ }
+
+ /**
+ * Returns the list of area addresses.
+ *
+ * @return areaAddresses area addresses
+ */
+ public List<String> areaAddress() {
+ List<String> areaAddresses = null;
+ for (IsisTlv tlv : tlvs()) {
+ if (tlv instanceof AreaAddressTlv) {
+ areaAddresses = ((AreaAddressTlv) tlv).areaAddress();
+ }
+ }
+ return areaAddresses;
+ }
+
+ /**
+ * Returns the list of interface IP addresses.
+ *
+ * @return interfaceIpAddresses list of interface IP addresses
+ */
+ public List<Ip4Address> interfaceIpAddresses() {
+ List<Ip4Address> interfaceIpAddresses = null;
+ for (IsisTlv tlv : tlvs()) {
+ if (tlv instanceof IpInterfaceAddressTlv) {
+ interfaceIpAddresses = ((IpInterfaceAddressTlv) tlv).interfaceAddress();
+ }
+ }
+ return interfaceIpAddresses;
+ }
+
+ /**
+ * Returns the list of neighbor list.
+ *
+ * @return macAddresses list of neighbor MAC address
+ */
+ public List<MacAddress> neighborList() {
+ List<MacAddress> macAddresses = null;
+ for (IsisTlv tlv : tlvs()) {
+ if (tlv instanceof IsisNeighborTlv) {
+ macAddresses = ((IsisNeighborTlv) tlv).neighbor();
+ }
+ }
+ return macAddresses;
+ }
+
+ /**
+ * Returns the adjacency state.
+ *
+ * @return interfaceState adjacency state
+ */
+ public IsisInterfaceState adjacencyState() {
+ IsisInterfaceState interfaceState = null;
+ for (IsisTlv tlv : tlvs()) {
+ if (tlv instanceof AdjacencyStateTlv) {
+ interfaceState = IsisInterfaceState.get(((AdjacencyStateTlv) tlv).adjacencyType());
+ break;
+ }
+ }
+ return interfaceState;
+ }
+
+ /**
+ * Returns the source ID.
+ *
+ * @return sourceId source ID
+ */
+ public String sourceId() {
+ return sourceId;
+ }
+
+ /**
+ * Sets source ID.
+ *
+ * @param sourceId source ID
+ */
+ public void setSourceId(String sourceId) {
+ this.sourceId = sourceId;
+ }
+
+ /**
+ * Returns the PDU length.
+ *
+ * @return pduLength PDU length
+ */
+ public int pduLength() {
+ return pduLength;
+ }
+
+ /**
+ * Sets the PDU length.
+ *
+ * @param pduLength PDU lenght
+ */
+ public void setPduLength(int pduLength) {
+ this.pduLength = pduLength;
+ }
+
+ /**
+ * Returns the holding time.
+ *
+ * @return holdingTime holding time
+ */
+ public int holdingTime() {
+ return holdingTime;
+ }
+
+ /**
+ * Sets the holding time.
+ *
+ * @param holdingTime holding time
+ */
+ public void setHoldingTime(int holdingTime) {
+ this.holdingTime = holdingTime;
+ }
+
+ /**
+ * Returns the circuit type.
+ *
+ * @return circuitType circuit type
+ */
+ public byte circuitType() {
+ return circuitType;
+ }
+
+ /**
+ * Sets the circuit type.
+ *
+ * @param circuitType circuit type
+ */
+ public void setCircuitType(byte circuitType) {
+ this.circuitType = circuitType;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("circuitType", circuitType)
+ .add("sourceId", sourceId)
+ .add("holdingTime", holdingTime)
+ .add("pduLength", pduLength)
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ HelloPdu that = (HelloPdu) o;
+ return Objects.equal(circuitType, that.circuitType) &&
+ Objects.equal(sourceId, that.sourceId) &&
+ Objects.equal(holdingTime, that.holdingTime) &&
+ Objects.equal(pduLength, that.pduLength);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(circuitType, sourceId, holdingTime, pduLength);
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/L1L2HelloPdu.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/L1L2HelloPdu.java
new file mode 100644
index 0000000..9737e1a
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/L1L2HelloPdu.java
@@ -0,0 +1,228 @@
+/*
+ * Copyright 2016-present 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.isis.io.isispacket.pdu;
+
+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.isis.io.isispacket.IsisHeader;
+import org.onosproject.isis.io.isispacket.tlv.IsisTlv;
+import org.onosproject.isis.io.isispacket.tlv.TlvFinder;
+import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
+import org.onosproject.isis.io.isispacket.tlv.TlvType;
+import org.onosproject.isis.io.isispacket.tlv.TlvsToBytes;
+import org.onosproject.isis.io.util.IsisUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Representation of L1L2 hello PDU.
+ */
+public class L1L2HelloPdu extends HelloPdu {
+
+ /*
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Intra-domain Routing Protocol Discriminator |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Length Indicator |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Version/Protocol ID Extension |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | ID Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | R | R | R | PDU Type |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Version |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Reserved |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Maximum area address |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Circuit Type |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Source ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Holding Time |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | PDU Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | PDU Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | R | Priority |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LAN ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Variable Lengths Fields |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Hello Message Format
+ REFERENCE : ISO/IEC 10589
+ */
+
+ private byte priority;
+ private String lanId;
+
+ /**
+ * Parametrized constructor.
+ *
+ * @param isisHeader ISIs header
+ */
+ public L1L2HelloPdu(IsisHeader isisHeader) {
+ populateHeader(isisHeader);
+ }
+
+ /**
+ * Returns the LAN ID.
+ *
+ * @return LAN ID
+ */
+
+ public String lanId() {
+ return lanId;
+ }
+
+ /**
+ * Sets the LAN ID.
+ *
+ * @param lanId LAN ID
+ */
+ public void setLanId(String lanId) {
+ this.lanId = lanId;
+ }
+
+ /**
+ * Returns the priority.
+ *
+ * @return priority
+ */
+ public byte priority() {
+ return priority;
+ }
+
+ /**
+ * Sets priority.
+ *
+ * @param priority priority
+ */
+ public void setPriority(byte priority) {
+ this.priority = priority;
+ }
+
+ @Override
+ public void readFrom(ChannelBuffer channelBuffer) {
+ this.setCircuitType(channelBuffer.readByte());
+ //sorce id
+ byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES];
+ channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES);
+ this.setSourceId(IsisUtil.systemId(tempByteArray));
+ this.setHoldingTime(channelBuffer.readUnsignedShort());
+ this.setPduLength(channelBuffer.readUnsignedShort());
+ this.setPriority(channelBuffer.readByte());
+ //landid id + 1 value
+ tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
+ channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
+ this.setLanId(IsisUtil.systemIdPlus(tempByteArray));
+ //tlv here
+ while (channelBuffer.readableBytes() > 0) {
+ TlvHeader tlvHeader = new TlvHeader();
+ tlvHeader.setTlvType(channelBuffer.readUnsignedByte());
+ tlvHeader.setTlvLength(channelBuffer.readUnsignedByte());
+ TlvType tlvType = TlvType.get(tlvHeader.tlvType());
+ if (tlvType != null) {
+ IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength()));
+ this.variableLengths.add(tlv);
+ } else {
+ channelBuffer.readBytes(tlvHeader.tlvLength());
+ }
+ }
+ }
+
+ @Override
+ public byte[] asBytes() {
+ byte[] helloMessage = null;
+ byte[] helloHeader = l1l2IsisPduHeader();
+ byte[] helloBody = l1l2HelloPduBody();
+ helloMessage = Bytes.concat(helloHeader, helloBody);
+ return helloMessage;
+ }
+
+ /**
+ * Parse the ISIS L1L2 PDU header.
+ *
+ * @return ISIS L1L2 PDU header
+ */
+ public byte[] l1l2IsisPduHeader() {
+ List<Byte> headerLst = new ArrayList<>();
+ headerLst.add(this.irpDiscriminator());
+ headerLst.add((byte) IsisUtil.getPduHeaderLength(this.pduType()));
+ headerLst.add(this.version());
+ headerLst.add(this.idLength());
+ headerLst.add((byte) this.pduType());
+ headerLst.add(this.version2());
+ headerLst.add(this.reserved());
+ headerLst.add(this.maximumAreaAddresses());
+ return Bytes.toArray(headerLst);
+ }
+
+ /**
+ * Parse the ISIS L1L2 PDU body.
+ *
+ * @return ISIS L1L2 PDU body
+ */
+ public byte[] l1l2HelloPduBody() {
+ List<Byte> bodyLst = new ArrayList<>();
+
+ bodyLst.add(this.circuitType());
+ bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.sourceId()));
+ bodyLst.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.holdingTime())));
+ bodyLst.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength())));
+ bodyLst.add(this.priority);
+ bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.lanId()));
+ for (IsisTlv isisTlv : variableLengths) {
+ bodyLst.addAll(TlvsToBytes.tlvToBytes(isisTlv));
+ }
+ return Bytes.toArray(bodyLst);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("priority", priority)
+ .add("lanId", lanId)
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ L1L2HelloPdu that = (L1L2HelloPdu) o;
+ return Objects.equal(priority, that.priority) &&
+ Objects.equal(lanId, that.lanId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(priority, lanId);
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/LsPdu.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/LsPdu.java
new file mode 100644
index 0000000..11de4f4
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/LsPdu.java
@@ -0,0 +1,486 @@
+/*
+ * Copyright 2016-present 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.isis.io.isispacket.pdu;
+
+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.isis.io.isispacket.IsisHeader;
+import org.onosproject.isis.io.isispacket.tlv.IsisTlv;
+import org.onosproject.isis.io.isispacket.tlv.TlvFinder;
+import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
+import org.onosproject.isis.io.isispacket.tlv.TlvType;
+import org.onosproject.isis.io.isispacket.tlv.TlvsToBytes;
+import org.onosproject.isis.io.util.IsisUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Representation of an ISIS Link State packet.
+ * Each Link State packet carries a collection of TLVs
+ * Several TLVs may be included in a single packet.
+ */
+public class LsPdu extends IsisHeader {
+
+ /*
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Intra-domain Routing Protocol Discriminator |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Length Indicator |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Version/Protocol ID Extension |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | ID Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | R | R | R | PDU Type |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Version |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Reserved |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Maximum area address |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | PDU Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Remaining Lifetime |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | LSP ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | PDU Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Sequence Number |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Checksum |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | P | ATT | LSPDBOL | IS Type |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Variable Lengths Fields |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ LS PDU Format
+ REFERENCE : ISO/IEC 10589
+ */
+ private int pduLength;
+ private int remainingLifeTime;
+ private String lspId;
+ private int sequenceNumber;
+ private int checkSum;
+ private boolean partitionRepair;
+ private AttachedToOtherAreas attachedToOtherAreas;
+ private boolean lspDbol;
+ private byte typeBlock;
+ private byte intermediateSystemType;
+ private List<IsisTlv> variableLengths = new ArrayList<>();
+
+ /**
+ * Creates an instance of Link State packet.
+ * Parameterized constructor which populate
+ *
+ * @param isisHeader isis header details
+ */
+ public LsPdu(IsisHeader isisHeader) {
+ populateHeader(isisHeader);
+ }
+
+ /**
+ * Adds the isis tlv to the list for the link state PDU.
+ *
+ * @param isisTlv isis tlv
+ */
+ public void addTlv(IsisTlv isisTlv) {
+ variableLengths.add(isisTlv);
+ }
+
+ /**
+ * Returns the remaining time of the link state pdu.
+ * Number of seconds before LSP considered expired
+ *
+ * @return remainingTime remaining time
+ */
+ public int remainingLifeTime() {
+ return remainingLifeTime;
+ }
+
+ /**
+ * Sets the remaining time for the link state pdu.
+ *
+ * @param remainingLifeTime remaining time
+ */
+ public void setRemainingLifeTime(int remainingLifeTime) {
+ this.remainingLifeTime = remainingLifeTime;
+ }
+
+ /**
+ * Returns the link state database overload.
+ *
+ * @return lspdbol link state database overload
+ */
+ public boolean lspDbol() {
+ return lspDbol;
+ }
+
+ /**
+ * Sets the link state database overload for this pdu.
+ *
+ * @param lspDbol link state database overload
+ */
+ public void setLspDbol(boolean lspDbol) {
+ this.lspDbol = lspDbol;
+ }
+
+ /**
+ * Returns the type block.
+ *
+ * @return type block
+ */
+ public byte typeBlock() {
+ return typeBlock;
+ }
+
+ /**
+ * Sets the type block.
+ *
+ * @param typeBlock type block
+ */
+ public void setTypeBlock(byte typeBlock) {
+ this.typeBlock = typeBlock;
+ }
+
+ /**
+ * Returns the sequence number of LSP.
+ *
+ * @return sequenceNumber sequence number
+ */
+ public int sequenceNumber() {
+ return sequenceNumber;
+ }
+
+ /**
+ * Sets the sequence nubmer for LSP.
+ *
+ * @param sequenceNumber sequence number
+ */
+ public void setSequenceNumber(int sequenceNumber) {
+ this.sequenceNumber = sequenceNumber;
+ }
+
+ /**
+ * Returns the checksum of LSP from Source ID to end.
+ *
+ * @return checkSum check sum
+ */
+ public int checkSum() {
+ return checkSum;
+ }
+
+ /**
+ * Sets the checksum for LSP from Source ID to end.
+ *
+ * @param checkSum check sum
+ */
+ public void setCheckSum(int checkSum) {
+ this.checkSum = checkSum;
+ }
+
+ /**
+ * Returns the partition repair value of the intermediate system.
+ *
+ * @return partitionRepair partition repair
+ */
+ public boolean partitionRepair() {
+ return partitionRepair;
+ }
+
+ /**
+ * Sets partition repair value for the intermediate system.
+ *
+ * @param partitionRepair partition repair
+ */
+ public void setPartitionRepair(boolean partitionRepair) {
+ this.partitionRepair = partitionRepair;
+ }
+
+ /**
+ * Returns the value of intermediate system attached field.
+ * return values based on type Default Metric, Delay Metric, Expense Metric, Error Metric
+ *
+ * @return attachedToOtherAreas attached to other areas
+ */
+ public AttachedToOtherAreas attachedToOtherAreas() {
+ return attachedToOtherAreas;
+ }
+
+ /**
+ * Sets the value for intermediate system attached field.
+ * it will pass values based on type Default Metric, Delay Metric, Expense Metric, Error Metric
+ *
+ * @param attachedToOtherAreas attached to other areas
+ */
+ public void setAttachedToOtherAreas(AttachedToOtherAreas attachedToOtherAreas) {
+ this.attachedToOtherAreas = attachedToOtherAreas;
+ }
+
+ /**
+ * Returns the intermediate system type.
+ * type will be level 1 or level 2
+ *
+ * @return intermediateSystemType intermediate system type
+ */
+ public byte intermediateSystemType() {
+ return intermediateSystemType;
+ }
+
+ /**
+ * Sets the value for intermediate system.
+ * type will be level 1 or level 2
+ *
+ * @param intermediateSystemType intermediate system type
+ */
+ public void setIntermediateSystemType(byte intermediateSystemType) {
+ this.intermediateSystemType = intermediateSystemType;
+ }
+
+ /**
+ * Returns the link state ID of link state packet.
+ * System ID of the source of link state PDU
+ *
+ * @return lspId link state packet ID
+ */
+ public String lspId() {
+ return lspId;
+ }
+
+ /**
+ * Sets the link state ID for link state packet.
+ * System ID of the source of link state PDU
+ *
+ * @param lspId link state packet ID
+ */
+ public void setLspId(String lspId) {
+ this.lspId = lspId;
+ }
+
+ /**
+ * Returns the packet data unit length of link state packet.
+ * Entire length of this PDU, in octets
+ *
+ * @return pduLength packte date unit length
+ */
+ public int pduLength() {
+ return pduLength;
+ }
+
+ /**
+ * Sets the packet data unit length for link state packet.
+ * Entire Length of this PDU, in octets
+ *
+ * @param pduLength packte data length
+ */
+ public void setPduLength(int pduLength) {
+ this.pduLength = pduLength;
+ }
+
+ @Override
+ public void readFrom(ChannelBuffer channelBuffer) {
+
+ this.setPduLength(channelBuffer.readUnsignedShort());
+ this.setRemainingLifeTime(channelBuffer.readUnsignedShort());
+ //lsp id + 2 value
+ byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_TWO_BYTE];
+ channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_TWO_BYTE);
+ this.setLspId(IsisUtil.systemIdPlus(tempByteArray));
+ //sequence number 4
+ this.setSequenceNumber(channelBuffer.readInt());
+ this.setCheckSum(channelBuffer.readUnsignedShort());
+ int typeTemp = channelBuffer.readUnsignedByte();
+ byte isTypeByte = (byte) typeTemp;
+ String tempValue = String.format("%8s", Integer.toBinaryString(isTypeByte & 0xFF)).replace(' ', '0');
+ int pBit = Integer.parseInt(new Character(tempValue.charAt(0)).toString());
+ if (pBit == 1) {
+ this.setPartitionRepair(true);
+ } else {
+ this.setPartitionRepair(false);
+ }
+ int attValue = Integer.parseInt(tempValue.substring(1, 5), 2);
+ switch (AttachedToOtherAreas.get(attValue)) {
+ case DEFAULTMETRIC:
+ this.setAttachedToOtherAreas(AttachedToOtherAreas.DEFAULTMETRIC);
+ break;
+ case DELAYMETRIC:
+ this.setAttachedToOtherAreas(AttachedToOtherAreas.DELAYMETRIC);
+ break;
+ case EXPENSEMETRIC:
+ this.setAttachedToOtherAreas(AttachedToOtherAreas.EXPENSEMETRIC);
+ break;
+ case ERRORMETRIC:
+ this.setAttachedToOtherAreas(AttachedToOtherAreas.ERRORMETRIC);
+ break;
+ case NONE:
+ this.setAttachedToOtherAreas(AttachedToOtherAreas.NONE);
+ break;
+ default:
+ break;
+ }
+ int lspdbol = Integer.parseInt(new Character(tempValue.charAt(5)).toString());
+ if (lspdbol == 1) {
+ this.setLspDbol(true);
+ } else {
+ this.setLspDbol(false);
+ }
+ int isType = Integer.parseInt(tempValue.substring(6, 8), 2);
+ byte isTypeByteValue = (byte) isType;
+ this.setIntermediateSystemType(isTypeByteValue);
+ //tlv here
+ while (channelBuffer.readableBytes() > 0) {
+ TlvHeader tlvHeader = new TlvHeader();
+ tlvHeader.setTlvType(channelBuffer.readUnsignedByte());
+ tlvHeader.setTlvLength(channelBuffer.readUnsignedByte());
+ TlvType tlvValue = TlvType.get(tlvHeader.tlvType());
+ if (tlvValue != null) {
+ IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength()));
+ this.variableLengths.add(tlv);
+ } else {
+ channelBuffer.readBytes(tlvHeader.tlvLength());
+ }
+ }
+ }
+
+ @Override
+ public byte[] asBytes() {
+ byte[] lspMessage = null;
+ byte[] helloHeader = l1l2IsisPduHeader();
+ byte[] lspBody = l1l2LsPduBody();
+ lspMessage = Bytes.concat(helloHeader, lspBody);
+ return lspMessage;
+ }
+
+ /**
+ * Builds ISIS PDU header from ISIS message.
+ *
+ * @return headerList ISIS PDU header
+ */
+ public byte[] l1l2IsisPduHeader() {
+ List<Byte> headerList = new ArrayList<>();
+ headerList.add(this.irpDiscriminator());
+ headerList.add((byte) IsisUtil.getPduHeaderLength(this.pduType()));
+ headerList.add(this.version());
+ headerList.add(this.idLength());
+ headerList.add((byte) this.pduType());
+ headerList.add(this.version2());
+ headerList.add(this.reserved());
+ headerList.add(this.maximumAreaAddresses());
+ return Bytes.toArray(headerList);
+ }
+
+ /**
+ * Builds link state PDU body from ISIS message.
+ *
+ * @return bodyList link state PDU body
+ */
+ public byte[] l1l2LsPduBody() {
+ List<Byte> bodyList = new ArrayList<>();
+ bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength())));
+ bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.remainingLifeTime())));
+ bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.lspId()));
+ bodyList.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.sequenceNumber())));
+ bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.checkSum())));
+ String temString = "";
+ if (this.partitionRepair()) {
+ temString = "1" + temString;
+ } else {
+ temString = "0" + temString;
+ }
+ switch (this.attachedToOtherAreas()) {
+ case ERRORMETRIC:
+ temString = temString + "1000";
+ break;
+ case EXPENSEMETRIC:
+ temString = temString + "0100";
+ break;
+ case DELAYMETRIC:
+ temString = temString + "0010";
+ break;
+ case DEFAULTMETRIC:
+ temString = temString + "0001";
+ break;
+ case NONE:
+ temString = temString + "0000";
+ break;
+ default:
+ break;
+ }
+ if (this.lspDbol()) {
+ temString = temString + "1";
+ } else {
+ temString = temString + "0";
+ }
+ String isType = Integer.toBinaryString(this.intermediateSystemType());
+ if (isType.length() % 2 != 0) {
+ isType = "0" + isType;
+ }
+ temString = temString + isType;
+ bodyList.add((byte) Integer.parseInt(temString, 2));
+ for (IsisTlv isisTlv : variableLengths) {
+ bodyList.addAll(TlvsToBytes.tlvToBytes(isisTlv));
+ }
+ return Bytes.toArray(bodyList);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("pduLength", pduLength)
+ .add("remainingLifeTime", remainingLifeTime)
+ .add("lspId", lspId)
+ .add("sequenceNumber", sequenceNumber)
+ .add("checkSum", checkSum)
+ .add("partitionRepair", partitionRepair)
+ .add("lspDbol", lspDbol)
+ .add("typeBlock", typeBlock)
+ .add("intermediateSystemType", intermediateSystemType)
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ LsPdu that = (LsPdu) o;
+ return Objects.equal(pduLength, that.pduLength) &&
+ Objects.equal(remainingLifeTime, that.remainingLifeTime) &&
+ Objects.equal(lspId, that.lspId) &&
+ Objects.equal(sequenceNumber, that.sequenceNumber) &&
+ Objects.equal(checkSum, that.checkSum) &&
+ Objects.equal(partitionRepair, that.partitionRepair) &&
+ Objects.equal(lspDbol, that.lspDbol) &&
+ Objects.equal(typeBlock, that.typeBlock) &&
+ Objects.equal(intermediateSystemType, that.intermediateSystemType);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(pduLength, remainingLifeTime, lspId, sequenceNumber,
+ checkSum, partitionRepair, lspDbol, typeBlock, intermediateSystemType);
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/P2PHelloPdu.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/P2PHelloPdu.java
new file mode 100644
index 0000000..e236610
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/P2PHelloPdu.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright 2016-present 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.isis.io.isispacket.pdu;
+
+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.isis.io.isispacket.IsisHeader;
+import org.onosproject.isis.io.isispacket.tlv.IsisTlv;
+import org.onosproject.isis.io.isispacket.tlv.TlvFinder;
+import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
+import org.onosproject.isis.io.isispacket.tlv.TlvType;
+import org.onosproject.isis.io.isispacket.tlv.TlvsToBytes;
+import org.onosproject.isis.io.util.IsisUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Representation of P2P hello.
+ */
+public class P2PHelloPdu extends HelloPdu {
+ /*
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Intra-domain Routing Protocol Discriminator |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Length Indicator |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Version/Protocol ID Extension |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | ID Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | R | R | R | PDU Type |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Version |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Reserved |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Maximum area address |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Circuit Type |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Source ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Holding Time |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | PDU Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Local Circuit Id |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Variable Lengths Fields |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ P2P Hello Message Format
+ REFERENCE : ISO/IEC 10589
+ */
+ private byte localCircuitId;
+
+ /**
+ * Sets the ISIS header.
+ *
+ * @param isisHeader isisHeader
+ */
+ public P2PHelloPdu(IsisHeader isisHeader) {
+ populateHeader(isisHeader);
+ }
+
+ /**
+ * Returns the local circuit ID.
+ *
+ * @return Local circuit ID
+ */
+ public byte localCircuitId() {
+ return localCircuitId;
+ }
+
+ /**
+ * Sets the local circuit ID.
+ *
+ * @param localCircuitId Local circuit ID
+ */
+ public void setLocalCircuitId(byte localCircuitId) {
+ this.localCircuitId = localCircuitId;
+ }
+
+ /**
+ * Sets the variable lengths.
+ *
+ * @param variableLengths variable lengths.
+ */
+ public void setVariableLengths(List<IsisTlv> variableLengths) {
+ this.variableLengths = variableLengths;
+ }
+
+
+ @Override
+ public void readFrom(ChannelBuffer channelBuffer) {
+ this.setCircuitType(channelBuffer.readByte());
+ //source id
+ byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES];
+ channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES);
+ this.setSourceId(IsisUtil.systemId(tempByteArray));
+ this.setHoldingTime(channelBuffer.readUnsignedShort());
+ this.setPduLength(channelBuffer.readUnsignedShort());
+ this.setLocalCircuitId((byte) channelBuffer.readUnsignedByte());
+ while (channelBuffer.readableBytes() > 0) {
+ TlvHeader tlvHeader = new TlvHeader();
+ tlvHeader.setTlvType(channelBuffer.readUnsignedByte());
+ tlvHeader.setTlvLength(channelBuffer.readUnsignedByte());
+ TlvType tlvType = TlvType.get(tlvHeader.tlvType());
+ if (tlvType != null) {
+ IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength()));
+ this.variableLengths.add(tlv);
+ } else {
+ channelBuffer.readBytes(tlvHeader.tlvLength());
+ }
+ }
+ }
+
+ @Override
+ public byte[] asBytes() {
+ byte[] helloMessage = null;
+ byte[] helloHeader = p2PHeader();
+ byte[] helloBody = p2P2HelloPduBody();
+ helloMessage = Bytes.concat(helloHeader, helloBody);
+ return helloMessage;
+ }
+
+ /**
+ * Builds the point to point header.
+ *
+ * @return headerList point to point header
+ */
+ public byte[] p2PHeader() {
+ List<Byte> headerList = new ArrayList<>();
+ headerList.add(this.irpDiscriminator());
+ headerList.add((byte) IsisUtil.getPduHeaderLength(this.pduType()));
+ headerList.add(this.version());
+ headerList.add(this.idLength());
+ headerList.add((byte) this.pduType());
+ headerList.add(this.version2());
+ headerList.add(this.reserved());
+ headerList.add(this.maximumAreaAddresses());
+ return Bytes.toArray(headerList);
+ }
+
+ /**
+ * Builds the point to point hello PDU body.
+ *
+ * @return bodyList point to point hello PDU body
+ */
+ public byte[] p2P2HelloPduBody() {
+ List<Byte> bodyList = new ArrayList<>();
+ bodyList.add(this.circuitType());
+ bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.sourceId()));
+ bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.holdingTime())));
+ bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength())));
+ bodyList.add((byte) this.localCircuitId());
+ for (IsisTlv isisTlv : variableLengths) {
+ bodyList.addAll(TlvsToBytes.tlvToBytes(isisTlv));
+ }
+ return Bytes.toArray(bodyList);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("localCircuitId", localCircuitId)
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ P2PHelloPdu that = (P2PHelloPdu) o;
+ return Objects.equal(localCircuitId, that.localCircuitId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(localCircuitId);
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/Psnp.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/Psnp.java
new file mode 100644
index 0000000..6ed6a4c
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/Psnp.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright 2016-present 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.isis.io.isispacket.pdu;
+
+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.isis.io.isispacket.IsisHeader;
+import org.onosproject.isis.io.isispacket.tlv.IsisTlv;
+import org.onosproject.isis.io.isispacket.tlv.TlvFinder;
+import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
+import org.onosproject.isis.io.isispacket.tlv.TlvType;
+import org.onosproject.isis.io.isispacket.tlv.TlvsToBytes;
+import org.onosproject.isis.io.util.IsisUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Representation of partial sequence number PDU.
+ */
+public class Psnp extends IsisHeader {
+ /*
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Intradomain Routing Protocol Discriminator |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Length Indicator |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Version/Protocol ID Extension |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | ID Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | R | R | R | PDU Type |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Version |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Reserved |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Maximum area address |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | PDU Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Source ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Start LSP ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | End LSP ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Variable Lengths Fields |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Hello Message Format
+ REFERENCE : ISO/IEC 10589
+ */
+ private int pduLength;
+ private String sourceId;
+ private List<IsisTlv> variableLengths = new ArrayList<>();
+
+ /**
+ * Creates the instance for this class.
+ *
+ * @param isisHeader ISIS header
+ */
+ public Psnp(IsisHeader isisHeader) {
+ populateHeader(isisHeader);
+ }
+
+ public void addTlv(IsisTlv isisTlv) {
+ variableLengths.add(isisTlv);
+ }
+
+ /**
+ * Returns the source ID of csnp.
+ *
+ * @return sourceId source ID
+ */
+ public String sourceId() {
+ return sourceId;
+ }
+
+ /**
+ * Sets the source ID for csnp.
+ *
+ * @param sourceId source ID
+ */
+ public void setSourceId(String sourceId) {
+ this.sourceId = sourceId;
+ }
+
+ /**
+ * Returns the packet data unit length of link state packet.
+ * Entire length of this PDU, in octets
+ *
+ * @return pduLength packte date unit length
+ */
+ public int pduLength() {
+ return pduLength;
+ }
+
+ /**
+ * Sets the packet data unit length for link state packet.
+ * Entire Length of this PDU, in octets
+ *
+ * @param pduLength packte data length
+ */
+ public void setPduLength(int pduLength) {
+ this.pduLength = pduLength;
+ }
+
+ @Override
+ public void readFrom(ChannelBuffer channelBuffer) {
+ this.setPduLength(channelBuffer.readUnsignedShort());
+ //source id + 2 value
+ byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
+ channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
+ this.setSourceId(IsisUtil.systemIdPlus(tempByteArray));
+ //tlv here
+ while (channelBuffer.readableBytes() > 0) {
+ TlvHeader tlvHeader = new TlvHeader();
+ tlvHeader.setTlvType(channelBuffer.readUnsignedByte());
+ tlvHeader.setTlvLength(channelBuffer.readUnsignedByte());
+ TlvType tlvValue = TlvType.get(tlvHeader.tlvType());
+ if (tlvValue != null) {
+ IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength()));
+ this.variableLengths.add(tlv);
+ } else {
+ channelBuffer.readBytes(tlvHeader.tlvLength());
+ }
+ }
+ }
+
+
+ @Override
+ public byte[] asBytes() {
+ byte[] psnpMessage = null;
+ byte[] isisPduHeader = isisPduHeader();
+ byte[] psnpBody = partialSequenceNumberPduBody();
+ psnpMessage = Bytes.concat(isisPduHeader, psnpBody);
+ return psnpMessage;
+ }
+
+ /**
+ * Builds the ISIS PDU header.
+ *
+ * @return headerList ISIS PDU header
+ */
+ public byte[] isisPduHeader() {
+ List<Byte> headerList = new ArrayList<>();
+ headerList.add(this.irpDiscriminator());
+ headerList.add((byte) IsisUtil.getPduHeaderLength(this.pduType()));
+ headerList.add(this.version());
+ headerList.add(this.idLength());
+ headerList.add((byte) this.pduType());
+ headerList.add(this.version2());
+ headerList.add(this.reserved());
+ headerList.add(this.maximumAreaAddresses());
+ return Bytes.toArray(headerList);
+ }
+
+ /**
+ * Builds the partial sequence number PDU body.
+ *
+ * @return bodyList partial sequence number PDU body
+ */
+ public byte[] partialSequenceNumberPduBody() {
+ List<Byte> bodyList = new ArrayList<>();
+ bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength())));
+ bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.sourceId()));
+ for (IsisTlv isisTlv : variableLengths) {
+ bodyList.addAll(TlvsToBytes.tlvToBytes(isisTlv));
+ }
+ return Bytes.toArray(bodyList);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("pduLength", pduLength)
+ .add("sourceId", sourceId)
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ Psnp that = (Psnp) o;
+ return Objects.equal(pduLength, that.pduLength);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(sourceId, pduLength);
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/package-info.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/package-info.java
new file mode 100644
index 0000000..8493298
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present 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 isis protocol.
+ */
+package org.onosproject.isis.io.isispacket.pdu;
\ No newline at end of file