ONOS-4083, ONOS-4084, ONOS-4096, ONOS-4097:ISIS PDU Data Structures
Change-Id: I22d30e8f7ba7d414e75254fdec6d0865bf471ff9
diff --git a/protocols/isis/api/src/main/java/org/onosproject/isis/controller/IsisLsdb.java b/protocols/isis/api/src/main/java/org/onosproject/isis/controller/IsisLsdb.java
index 7ceb9f1..06e34fd 100644
--- a/protocols/isis/api/src/main/java/org/onosproject/isis/controller/IsisLsdb.java
+++ b/protocols/isis/api/src/main/java/org/onosproject/isis/controller/IsisLsdb.java
@@ -16,6 +16,7 @@
package org.onosproject.isis.controller;
import java.util.List;
+import java.util.Map;
/**
* Representation of an ISIS link state database.
@@ -93,4 +94,18 @@
* @param lsp LSP instance
*/
void deleteLsp(IsisMessage lsp);
-}
+
+ /**
+ * Gets the neighbor database information.
+ *
+ * @return neighbor database information
+ */
+ Map<String, LspWrapper> getL1Db();
+
+ /**
+ * Gets the neighbor database information.
+ *
+ * @return neighbor database information
+ */
+ Map<String, LspWrapper> getL2Db();
+}
\ No newline at end of file
diff --git a/protocols/isis/api/src/main/java/org/onosproject/isis/controller/IsisNeighbor.java b/protocols/isis/api/src/main/java/org/onosproject/isis/controller/IsisNeighbor.java
index f6a462b..22b0cca 100644
--- a/protocols/isis/api/src/main/java/org/onosproject/isis/controller/IsisNeighbor.java
+++ b/protocols/isis/api/src/main/java/org/onosproject/isis/controller/IsisNeighbor.java
@@ -84,4 +84,18 @@
* @param localExtendedCircuitId neighbor extended circuit ID
*/
void setLocalExtendedCircuitId(int localExtendedCircuitId);
+
+ /**
+ * Returns Holding time of neighbor.
+ *
+ * @return Holding time of neighbor
+ */
+ int holdingTime();
+
+ /**
+ * Sets Holding time of neighbor.
+ *
+ * @param holdingTime Holding time of neighbor
+ */
+ void setHoldingTime(int holdingTime);
}
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/exceptions/IsisErrorType.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/exceptions/IsisErrorType.java
new file mode 100644
index 0000000..5fbf691
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/exceptions/IsisErrorType.java
@@ -0,0 +1,38 @@
+/*
+ * 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.exceptions;
+
+/**
+ * Defines all error codes and error sub codes.
+ */
+public final class IsisErrorType {
+
+ //Represents an invalid ISIS message header
+ public static final byte MESSAGE_HEADER_ERROR = 1;
+ //Represents an invalid ISIS message body
+ public static final byte ISIS_MESSAGE_ERROR = 2;
+ //Message Header error sub codes
+ //Represents an invalid ISIS message length
+ public static final byte BAD_MESSAGE_LENGTH = 3;
+ //Represents an invalid ISIS message
+ public static final byte BAD_MESSAGE = 4;
+
+ /**
+ * Creates an instance of ISIS error type.
+ */
+ private IsisErrorType() {
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/exceptions/IsisParseException.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/exceptions/IsisParseException.java
new file mode 100644
index 0000000..57ad8d3
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/exceptions/IsisParseException.java
@@ -0,0 +1,102 @@
+/*
+ * 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.exceptions;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Representation of a custom exception for ISIS.
+ */
+public class IsisParseException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+ private byte errorCode;
+ private byte errorSubCode;
+
+ /**
+ * Creates a new ISIS exception.
+ */
+ public IsisParseException() {
+ super();
+ }
+
+ /**
+ * Creates a new ISIS exception based on the given arguments.
+ *
+ * @param message the detail of exception in string
+ * @param cause underlying cause of the error
+ */
+ public IsisParseException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates a new ISIS exception for the given message.
+ *
+ * @param message the detail of exception in string
+ */
+ public IsisParseException(final String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new ISIS exception from throwable instance.
+ *
+ * @param cause underlying cause of the error
+ */
+ public IsisParseException(final Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Creates a new ISIS exception from error code and error sub code.
+ *
+ * @param errorCode error code of ISIS message
+ * @param errorSubCode error sub code of ISIS message
+ */
+ public IsisParseException(final byte errorCode, final byte errorSubCode) {
+ super();
+ this.errorCode = errorCode;
+ this.errorSubCode = errorSubCode;
+ }
+
+ /**
+ * Returns error code for this exception.
+ *
+ * @return error code for this exception
+ */
+ public byte errorCode() {
+ return this.errorCode;
+ }
+
+ /**
+ * Returns error sub code for this exception.
+ *
+ * @return error sub code for this exception
+ */
+ public byte errorSubCode() {
+ return this.errorSubCode;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("errorCode", errorCode)
+ .add("errorSubCode", errorSubCode)
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/exceptions/package-info.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/exceptions/package-info.java
new file mode 100644
index 0000000..00c0d22
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/exceptions/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 exceptions.
+ */
+package org.onosproject.isis.exceptions;
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/IsisHeader.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/IsisHeader.java
new file mode 100644
index 0000000..5152423
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/IsisHeader.java
@@ -0,0 +1,271 @@
+/*
+ * 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;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.MacAddress;
+import org.onosproject.isis.controller.IsisMessage;
+import org.onosproject.isis.controller.IsisPduType;
+
+/**
+ * Representation of ISIS message header.
+ */
+public class IsisHeader implements IsisMessage {
+
+ private MacAddress sourceMac;
+ private int interfaceIndex;
+ private MacAddress interfaceMac;
+ private int isisPduType;
+ private byte irpDiscriminator;
+ private byte pduHeaderLength;
+ private byte version2;
+ private byte idLength;
+ private byte version;
+ private byte reserved;
+ private byte maximumAreaAddresses;
+
+ /**
+ * Returns the interface index on which the message received.
+ *
+ * @return interface index on which the message received
+ */
+ public int interfaceIndex() {
+ return interfaceIndex;
+ }
+
+ /**
+ * Sets the interface index on which the message received.
+ *
+ * @param interfaceIndex interface index on which the message received
+ */
+ public void setInterfaceIndex(int interfaceIndex) {
+ this.interfaceIndex = interfaceIndex;
+ }
+
+ /**
+ * Returns the interface mac address on which the message received.
+ *
+ * @return interface mac address on which the message received
+ */
+ public MacAddress interfaceMac() {
+ return interfaceMac;
+ }
+
+ /**
+ * Returns the mac address of the message sender.
+ *
+ * @return mac address of the message sender
+ */
+ public MacAddress sourceMac() {
+ return sourceMac;
+ }
+
+ /**
+ * Sets the mac address of the message sender.
+ *
+ * @param sourceMac mac address of the message sender
+ */
+ public void setSourceMac(MacAddress sourceMac) {
+ this.sourceMac = sourceMac;
+ }
+
+ /**
+ * Sets the interface mac address on which the message received.
+ *
+ * @param interfaceMac mac address on which the message received
+ */
+ public void setInterfaceMac(MacAddress interfaceMac) {
+ this.interfaceMac = interfaceMac;
+ }
+
+ /**
+ * Returns the version of TLV header.
+ *
+ * @return version version of TLV header
+ */
+ public byte version2() {
+ return version2;
+ }
+
+ /**
+ * Sets the version of TLV header.
+ *
+ * @param version2 version of TLV header
+ */
+ public void setVersion2(byte version2) {
+ this.version2 = version2;
+ }
+
+ /**
+ * Returns maximum area address.
+ *
+ * @return maximum area address
+ */
+ public byte maximumAreaAddresses() {
+ return maximumAreaAddresses;
+ }
+
+ /**
+ * Sets maximum area address.
+ *
+ * @param maximumAreaAddresses maximum area address
+ */
+ public void setMaximumAreaAddresses(byte maximumAreaAddresses) {
+ this.maximumAreaAddresses = maximumAreaAddresses;
+ }
+
+ /**
+ * Returns reserved field value on which data received.
+ *
+ * @return reserved
+ */
+ public byte reserved() {
+ return reserved;
+ }
+
+ /**
+ * Sets reserved.
+ *
+ * @param reserved reserved
+ */
+ public void setReserved(byte reserved) {
+ this.reserved = reserved;
+ }
+
+ /**
+ * Returns version.
+ *
+ * @return version
+ */
+ public byte version() {
+ return version;
+ }
+
+ /**
+ * Returns ID length.
+ *
+ * @return ID length
+ */
+ public byte idLength() {
+ return idLength;
+ }
+
+ /**
+ * Sets ID length.
+ *
+ * @param idLength ID length
+ */
+ public void setIdLength(byte idLength) {
+ this.idLength = idLength;
+ }
+
+ /**
+ * Returns the PDU type.
+ *
+ * @return PDU type
+ */
+ public int pduType() {
+
+ return this.isisPduType;
+ }
+
+ /**
+ * Sets PDU type.
+ *
+ * @param isisPduType PDU type
+ */
+ public void setIsisPduType(int isisPduType) {
+ this.isisPduType = isisPduType;
+ }
+
+ /**
+ * Sets protocol ID.
+ *
+ * @param version protocol ID
+ */
+ public void setVersion(byte version) {
+ this.version = version;
+ }
+
+ /**
+ * Returns length indicator.
+ *
+ * @return length indicator
+ */
+ public byte pduHeaderLength() {
+ return pduHeaderLength;
+ }
+
+ /**
+ * Sets length indicator.
+ *
+ * @param pduHeaderLength length indicator
+ */
+ public void setPduHeaderLength(byte pduHeaderLength) {
+ this.pduHeaderLength = pduHeaderLength;
+ }
+
+ /**
+ * Returns IRP discriminator.
+ *
+ * @return IRP discriminator
+ */
+ public byte irpDiscriminator() {
+ return irpDiscriminator;
+ }
+
+ /**
+ * Sets IRP discriminator.
+ *
+ * @param irpDiscriminator IRP discriminator
+ */
+ public void setIrpDiscriminator(byte irpDiscriminator) {
+
+ this.irpDiscriminator = irpDiscriminator;
+ }
+
+ @Override
+ public IsisPduType isisPduType() {
+
+ return IsisPduType.get(this.isisPduType);
+ }
+
+ @Override
+ public void readFrom(ChannelBuffer channelBuffer) {
+ //implemented in the sub classes
+ }
+
+ @Override
+ public byte[] asBytes() {
+ return null;
+ }
+
+ /**
+ * Populates ISIS header.
+ *
+ * @param isisHeader ISIS header
+ */
+ public void populateHeader(IsisHeader isisHeader) {
+ this.setIrpDiscriminator(isisHeader.irpDiscriminator());
+ this.setPduHeaderLength(isisHeader.pduHeaderLength());
+ this.setVersion(isisHeader.version());
+ this.setIdLength(isisHeader.idLength());
+ this.setIsisPduType(isisHeader.pduType());
+ this.setVersion2(isisHeader.version2());
+ this.setReserved(isisHeader.reserved());
+ this.setMaximumAreaAddresses(isisHeader.maximumAreaAddresses());
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/IsisMessageReader.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/IsisMessageReader.java
new file mode 100644
index 0000000..fe149c6
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/IsisMessageReader.java
@@ -0,0 +1,122 @@
+/*
+ * 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;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.isis.controller.IsisMessage;
+import org.onosproject.isis.exceptions.IsisErrorType;
+import org.onosproject.isis.exceptions.IsisParseException;
+import org.onosproject.isis.io.isispacket.pdu.Csnp;
+import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu;
+import org.onosproject.isis.io.isispacket.pdu.LsPdu;
+import org.onosproject.isis.io.isispacket.pdu.P2PHelloPdu;
+import org.onosproject.isis.io.isispacket.pdu.Psnp;
+import org.onosproject.isis.io.util.IsisConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Represents ISIS message reader.
+ */
+public class IsisMessageReader {
+
+ protected static final Logger log = LoggerFactory.getLogger(IsisMessageReader.class);
+
+ /**
+ * Reads from ISIS packet from buffer.
+ *
+ * @param channelBuffer buffer
+ * @return ISIS message
+ * @throws Exception exception
+ */
+ public IsisMessage readFromBuffer(ChannelBuffer channelBuffer) throws Exception {
+
+ int dataLength = channelBuffer.readableBytes();
+ log.debug("IsisMessageReader::readFromBuffer Data length {}", dataLength);
+ if (channelBuffer.readableBytes() < IsisConstants.PDU_LENGTH) {
+ log.debug("Packet should have minimum length...");
+ throw new IsisParseException(IsisErrorType.MESSAGE_HEADER_ERROR, IsisErrorType.BAD_MESSAGE_LENGTH);
+ }
+ IsisHeader isisHeader = getIsisHeader(channelBuffer);
+ int totalLength = 0;
+ IsisMessage isisMessage = null;
+ switch (isisHeader.isisPduType()) {
+ case L1HELLOPDU:
+ case L2HELLOPDU:
+ isisMessage = new L1L2HelloPdu(isisHeader);
+ totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION);
+ break;
+ case P2PHELLOPDU:
+ isisMessage = new P2PHelloPdu(isisHeader);
+ totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION);
+ break;
+ case L1LSPDU:
+ case L2LSPDU:
+ isisMessage = new LsPdu(isisHeader);
+ totalLength = channelBuffer.getShort(8);
+ break;
+ case L1CSNP:
+ case L2CSNP:
+ isisMessage = new Csnp(isisHeader);
+ totalLength = channelBuffer.getShort(8);
+ break;
+ case L1PSNP:
+ case L2PSNP:
+ isisMessage = new Psnp(isisHeader);
+ totalLength = channelBuffer.getShort(8);
+ break;
+ default:
+ log.debug("Message Reader[Decoder] - Unknown PDU type..!!!");
+ break;
+ }
+
+ if (isisMessage != null) {
+ try {
+ int bodyLength = totalLength - IsisConstants.COMMONHEADERLENGTH;
+ isisMessage.readFrom(channelBuffer.readBytes(bodyLength));
+
+ } catch (Exception e) {
+ throw new IsisParseException(IsisErrorType.ISIS_MESSAGE_ERROR,
+ IsisErrorType.BAD_MESSAGE);
+ }
+
+ }
+
+ return isisMessage;
+ }
+
+ /**
+ * Gets ISIS header.
+ *
+ * @param channelBuffer ISIS header
+ * @return ISIS header
+ * @throws Exception
+ */
+ private IsisHeader getIsisHeader(ChannelBuffer channelBuffer) throws Exception {
+
+ IsisHeader isisHeader = new IsisHeader();
+ isisHeader.setIrpDiscriminator(channelBuffer.readByte());
+ isisHeader.setPduHeaderLength(channelBuffer.readByte());
+ isisHeader.setVersion(channelBuffer.readByte());
+ isisHeader.setIdLength(channelBuffer.readByte());
+ isisHeader.setIsisPduType(channelBuffer.readByte());
+ isisHeader.setVersion2(channelBuffer.readByte());
+ isisHeader.setReserved(channelBuffer.readByte());
+ isisHeader.setMaximumAreaAddresses(channelBuffer.readByte());
+
+ return isisHeader;
+ }
+}
\ No newline at end of file
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
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/AdjacencyStateTlv.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/AdjacencyStateTlv.java
index d13841c..5ee07fe 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/AdjacencyStateTlv.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/AdjacencyStateTlv.java
@@ -36,7 +36,7 @@
/**
* Creates an instance of adjacency state TLV..
*
- * @param tlvHeader tlvHeader
+ * @param tlvHeader TLV header
*/
public AdjacencyStateTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
@@ -118,8 +118,8 @@
@Override
public void readFrom(ChannelBuffer channelBuffer) {
this.setAdjacencyType(channelBuffer.readByte());
+ this.setLocalCircuitId(channelBuffer.readInt());
if (channelBuffer.readableBytes() > 0) {
- this.setLocalCircuitId(channelBuffer.readInt());
byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES);
this.setNeighborSystemId(IsisUtil.systemId(tempByteArray));
@@ -146,8 +146,10 @@
List<Byte> bytes = new ArrayList<>();
bytes.add(this.adjacencyType);
bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.localCircuitId)));
+ if (this.neighborSystemId != null) {
bytes.addAll(IsisUtil.sourceAndLanIdToBytes(this.neighborSystemId));
bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.neighborLocalCircuitId)));
+ }
return Bytes.toArray(bytes);
}
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/AreaAddressTlv.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/AreaAddressTlv.java
index bc24910..0f3d54d 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/AreaAddressTlv.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/AreaAddressTlv.java
@@ -33,7 +33,7 @@
/**
* Creates an instance of area address TLV.
*
- * @param tlvHeader tlvHeader
+ * @param tlvHeader TLV header
*/
public AreaAddressTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/HostNameTlv.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/HostNameTlv.java
index 82e8099..bc0fe8f 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/HostNameTlv.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/HostNameTlv.java
@@ -28,7 +28,7 @@
/**
* Creates an instance of host name TLV.
*
- * @param tlvHeader tlvHeader.
+ * @param tlvHeader TLV header
*/
public HostNameTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IdrpInformationTlv.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IdrpInformationTlv.java
index b16a54d..eeb31f3 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IdrpInformationTlv.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IdrpInformationTlv.java
@@ -29,7 +29,7 @@
/**
* Creates an instance of IDRP information TLV.
*
- * @param tlvHeader tlvHeader
+ * @param tlvHeader TLV header
*/
public IdrpInformationTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpExtendedReachabilityTlv.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpExtendedReachabilityTlv.java
index 7acb9c8..14962d8 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpExtendedReachabilityTlv.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpExtendedReachabilityTlv.java
@@ -21,6 +21,7 @@
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvFinder;
import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvToBytes;
+import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvType;
import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringSubTlv;
import org.onosproject.isis.io.util.IsisUtil;
@@ -32,15 +33,18 @@
*/
public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv {
- private String sysIdAndPseudoNumber;
- private int defaultMetric;
+ private boolean down;
+ private boolean subTlvPresence;
+ private int prefixLength;
+ private int metric;
private byte subTlvLength;
+ private String prefix;
private List<TrafficEngineeringSubTlv> trafEnginSubTlv = new ArrayList<>();
/**
* Creates an instance of IP external reachability TLV.
*
- * @param tlvHeader tlvHeader
+ * @param tlvHeader TLV header
*/
public IpExtendedReachabilityTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
@@ -48,21 +52,75 @@
}
/**
- * Returns the system ID and pseudo number of IP external reachability TLV.
+ * Returns the prefix of IP external reachability TLV.
*
- * @return sysIdAndPseudoNumber system ID and pseudo number
+ * @return prefix
*/
- public String sysIdAndPseudoNumber() {
- return sysIdAndPseudoNumber;
+ public String prefix() {
+ return prefix;
}
/**
- * Sets the system ID and pseudo number for IP external reachability TLV.
+ * Sets the prefix of IP external reachability TLV.
*
- * @param sysIdAndPseudoNumber system ID and pseudo number
+ * @param prefix prefix
*/
- public void setSysIdAndPseudoNumber(String sysIdAndPseudoNumber) {
- this.sysIdAndPseudoNumber = sysIdAndPseudoNumber;
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ /**
+ * Returns if down true else false of IP external reachability TLV.
+ *
+ * @return if down true else false
+ */
+ public boolean isDown() {
+ return down;
+ }
+
+ /**
+ * Sets if down true else false of IP external reachability TLV.
+ *
+ * @param upOrDown if down true else false
+ */
+ public void setDown(boolean upOrDown) {
+ this.down = upOrDown;
+ }
+
+ /**
+ * Returns true if sub TLV present else false of IP external reachability TLV.
+ *
+ * @return true if present else false
+ */
+ public boolean isSubTlvPresence() {
+ return subTlvPresence;
+ }
+
+ /**
+ * Sets true if sub TLV present else false of IP external reachability TLV.
+ *
+ * @param subTlvPresence true if present else false
+ */
+ public void setSubTlvPresence(boolean subTlvPresence) {
+ this.subTlvPresence = subTlvPresence;
+ }
+
+ /**
+ * Sets the prefix length of IP external reachability TLV.
+ *
+ * @return prefix length
+ */
+ public int prefixLength() {
+ return prefixLength;
+ }
+
+ /**
+ * Returns the prefix length of IP external reachability TLV.
+ *
+ * @param prefixLength the prefix length of IP external reachability TLV
+ */
+ public void setPrefixLength(int prefixLength) {
+ this.prefixLength = prefixLength;
}
/**
@@ -93,39 +151,70 @@
}
/**
- * Returns default metric of IP external reachability TLV.
+ * Returns metric of IP external reachability TLV.
*
- * @return default metric
+ * @return metric
*/
- public int defaultMetric() {
- return defaultMetric;
+ public int metric() {
+ return metric;
}
/**
* Sets default metric for IP external reachability TLV.
*
- * @param defaultMetric default metric
+ * @param metric default metric
*/
- public void setDefaultMetric(int defaultMetric) {
- this.defaultMetric = defaultMetric;
+ public void setMetric(int metric) {
+ this.metric = metric;
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
- byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
- channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
- this.setSysIdAndPseudoNumber(IsisUtil.systemIdPlus(tempByteArray));
- this.setDefaultMetric(channelBuffer.readUnsignedMedium());
- this.setSubTlvLength((byte) channelBuffer.readByte());
- while (channelBuffer.readableBytes() > 0) {
- TlvHeader tlvHeader = new TlvHeader();
- tlvHeader.setTlvType(channelBuffer.readByte());
- tlvHeader.setTlvLength(channelBuffer.readByte());
- this.addSubTlv(SubTlvFinder.findSubTlv(tlvHeader,
- channelBuffer.readBytes(tlvHeader.tlvLength())));
+ this.setMetric(channelBuffer.readInt());
+ int controlInfo = channelBuffer.readByte();
+ byte[] tempByteArray = null;
+
+ String string = IsisUtil.toEightBitBinary(Integer.toBinaryString(controlInfo));
+ if (string.charAt(0) == '0') {
+ this.setDown(false);
+ }
+ if (string.charAt(1) == '1') {
+ this.setSubTlvPresence(true);
+ }
+ this.setPrefixLength(Integer.parseInt(string.substring(2, string.length()), 2));
+ if (this.prefixLength >= 0 && this.prefixLength <= 8) {
+ channelBuffer.readByte();
+ } else if (this.prefixLength >= 8 && this.prefixLength <= 16) {
+ tempByteArray = new byte[IsisUtil.TWO_BYTES];
+ channelBuffer.readBytes(tempByteArray, 0, IsisUtil.TWO_BYTES);
+ this.setPrefix(IsisUtil.prefixConversion(tempByteArray));
+ } else if (this.prefixLength >= 17 && this.prefixLength <= 24) {
+ tempByteArray = new byte[IsisUtil.THREE_BYTES];
+ channelBuffer.readBytes(tempByteArray, 0, IsisUtil.THREE_BYTES);
+ this.setPrefix(IsisUtil.prefixConversion(tempByteArray));
+ } else if (this.prefixLength >= 24 && this.prefixLength <= 32) {
+ tempByteArray = new byte[IsisUtil.FOUR_BYTES];
+ channelBuffer.readBytes(tempByteArray, 0, IsisUtil.FOUR_BYTES);
+ this.setPrefix(IsisUtil.prefixConversion(tempByteArray));
+ }
+ if (this.isSubTlvPresence()) {
+ this.setSubTlvLength(channelBuffer.readByte());
+ while (channelBuffer.readableBytes() > 0) {
+ TlvHeader tlvHeader = new TlvHeader();
+ tlvHeader.setTlvType(channelBuffer.readByte());
+ tlvHeader.setTlvLength(channelBuffer.readByte());
+ SubTlvType tlvValue = SubTlvType.get(tlvHeader.tlvType());
+ if (tlvValue != null) {
+ this.addSubTlv(SubTlvFinder.findSubTlv(tlvHeader,
+ channelBuffer.readBytes(tlvHeader.tlvLength())));
+ } else {
+ channelBuffer.readBytes(tlvHeader.tlvLength());
+ }
+ }
}
}
+
@Override
public byte[] asBytes() {
byte[] bytes = null;
@@ -145,11 +234,26 @@
*/
private byte[] tlvBodyAsBytes() {
List<Byte> bodyLst = new ArrayList<>();
- bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.sysIdAndPseudoNumber()));
- bodyLst.addAll(Bytes.asList(IsisUtil.convertToThreeBytes(this.defaultMetric())));
- bodyLst.add(this.subTlvLength());
- for (TrafficEngineeringSubTlv trafficEngineeringSubTlv : this.trafEnginSubTlv) {
- bodyLst.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv));
+ bodyLst.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.metric())));
+ String controlInfo = "";
+ if (this.isDown()) {
+ controlInfo = controlInfo + "1";
+ } else {
+ controlInfo = controlInfo + "0";
+ }
+ if (this.isSubTlvPresence()) {
+ controlInfo = controlInfo + "1";
+ } else {
+ controlInfo = controlInfo + "0";
+ }
+ String prefixlength = IsisUtil.toEightBitBinary(Integer.toBinaryString(this.prefixLength()));
+ controlInfo = controlInfo + prefixlength.substring(2, prefixlength.length());
+ bodyLst.add(Byte.parseByte(controlInfo, 2));
+ if (this.isSubTlvPresence()) {
+ bodyLst.add(this.subTlvLength());
+ for (TrafficEngineeringSubTlv trafficEngineeringSubTlv : this.trafEnginSubTlv) {
+ bodyLst.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv));
+ }
}
return Bytes.toArray(bodyLst);
}
@@ -158,9 +262,12 @@
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
- .add("sysIdAndPseudoNumber", sysIdAndPseudoNumber)
- .add("defaultMetric", defaultMetric)
+ .add("down", down)
+ .add("subTlvPresence", subTlvPresence)
+ .add("prefixLength", prefixLength)
+ .add("metric", metric)
.add("subTlvLength", subTlvLength)
+ .add("prefix", prefix)
.add("trafEnginSubTlv", trafEnginSubTlv)
.toString();
}
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpExternalReachabilityTlv.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpExternalReachabilityTlv.java
deleted file mode 100644
index e050017..0000000
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpExternalReachabilityTlv.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * 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.tlv;
-
-import com.google.common.base.MoreObjects;
-import com.google.common.primitives.Bytes;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvFinder;
-import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvToBytes;
-import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringSubTlv;
-import org.onosproject.isis.io.util.IsisUtil;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Representation of IP external reachability TLV.
- */
-public class IpExternalReachabilityTlv extends TlvHeader implements IsisTlv {
-
- private String sysIdAndPseudoNumber;
- private int defaultMetric;
- private byte subTlvLength;
- private List<TrafficEngineeringSubTlv> trafEnginSubTlv = new ArrayList<>();
-
- /**
- * Sets TLV type and TLV length for IP external reachability TLV.
- *
- * @param tlvHeader tlvHeader
- */
- public IpExternalReachabilityTlv(TlvHeader tlvHeader) {
- this.setTlvType(tlvHeader.tlvType());
- this.setTlvLength(tlvHeader.tlvLength());
- }
-
- /**
- * Gets the system ID and pseudo number of IP external reachability TLV.
- *
- * @return sysIdAndPseudoNumber system ID and pseudo number
- */
- public String sysIdAndPseudoNumber() {
- return sysIdAndPseudoNumber;
- }
-
- /**
- * Gets the system ID and pseudo number for IP external reachability TLV.
- *
- * @param sysIdAndPseudoNumber system ID and pseudo number
- */
- public void setSysIdAndPseudoNumber(String sysIdAndPseudoNumber) {
- this.sysIdAndPseudoNumber = sysIdAndPseudoNumber;
- }
-
- /**
- * Adds the traffic engineering sub TLV to IP external reachability TLV.
- *
- * @param trafEnginSubTlv traffic engineering sub TLV
- */
- public void addSubTlv(TrafficEngineeringSubTlv trafEnginSubTlv) {
- this.trafEnginSubTlv.add(trafEnginSubTlv);
- }
-
- /**
- * Gets the sub TLV length of IP external reachability TLV.
- *
- * @return sub TLV length
- */
- public byte subTlvLength() {
- return subTlvLength;
- }
-
- /**
- * Sets the sub TLV length for IP external reachability TLV.
- *
- * @param subTlvLength sub TLV length
- */
- public void setSubTlvLength(byte subTlvLength) {
- this.subTlvLength = subTlvLength;
- }
-
- /**
- * Gets default metric of IP external reachability TLV.
- *
- * @return default metric
- */
- public int defaultMetric() {
- return defaultMetric;
- }
-
- /**
- * Sets default metric for IP external reachability TLV.
- *
- * @param defaultMetric default metric
- */
- public void setDefaultMetric(int defaultMetric) {
- this.defaultMetric = defaultMetric;
- }
-
- @Override
- public void readFrom(ChannelBuffer channelBuffer) {
- byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
- channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
- this.setSysIdAndPseudoNumber(IsisUtil.systemIdPlus(tempByteArray));
- this.setDefaultMetric(channelBuffer.readUnsignedMedium());
- this.setSubTlvLength((byte) channelBuffer.readByte());
- while (channelBuffer.readableBytes() > 0) {
- TlvHeader tlvHeader = new TlvHeader();
- tlvHeader.setTlvType(channelBuffer.readByte());
- tlvHeader.setTlvLength(channelBuffer.readByte());
- this.addSubTlv(SubTlvFinder.findSubTlv(tlvHeader,
- channelBuffer.readBytes(tlvHeader.tlvLength())));
- }
- }
-
- @Override
- public byte[] asBytes() {
- byte[] bytes = null;
- byte[] tlvHeader = tlvHeaderAsByteArray();
- byte[] tlvBody = tlvBodyAsBytes();
- //systemID + pseudo number+length of subtlv=11l
- tlvBody[10] = (byte) (tlvBody.length - 11);
- tlvHeader[1] = (byte) tlvBody.length;
- bytes = Bytes.concat(tlvHeader, tlvBody);
- return bytes;
- }
-
- /**
- * Gets TLV body of IP external reachability TLV.
- *
- * @return byteArray TLV body of IP external reachability TLV.
- */
- public byte[] tlvBodyAsBytes() {
- List<Byte> bodyLst = new ArrayList<>();
- bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.sysIdAndPseudoNumber()));
- bodyLst.addAll(Bytes.asList(IsisUtil.convertToThreeBytes(this.defaultMetric())));
- bodyLst.add(this.subTlvLength());
- for (TrafficEngineeringSubTlv trafficEngineeringSubTlv : this.trafEnginSubTlv) {
- bodyLst.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv));
- }
- return Bytes.toArray(bodyLst);
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(getClass())
- .omitNullValues()
- .add("sysIdAndPseudoNumber", sysIdAndPseudoNumber)
- .add("defaultMetric", defaultMetric)
- .add("subTlvLength", subTlvLength)
- .toString();
- }
-}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpInterfaceAddressTlv.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpInterfaceAddressTlv.java
index f372a6b..fcc7be6 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpInterfaceAddressTlv.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpInterfaceAddressTlv.java
@@ -34,7 +34,7 @@
/**
* Creates an instance of IP interface address TLV.
*
- * @param tlvHeader tlvHeader.
+ * @param tlvHeader TLV header
*/
public IpInterfaceAddressTlv(TlvHeader tlvHeader) {
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpInternalReachabilityTlv.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpInternalReachabilityTlv.java
index fd92e1c..049674f 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpInternalReachabilityTlv.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpInternalReachabilityTlv.java
@@ -31,7 +31,7 @@
/**
* Creates an instance of IP internal reachability TLV.
*
- * @param tlvHeader tlvHeader.
+ * @param tlvHeader TLV header
*/
public IpInternalReachabilityTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsReachabilityTlv.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsReachabilityTlv.java
index f5e6d43..4dd9df4 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsReachabilityTlv.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsReachabilityTlv.java
@@ -33,7 +33,7 @@
/**
* Creates an instance of IS reachability TLV.
*
- * @param tlvHeader tlvHeader.
+ * @param tlvHeader TLV header
*/
public IsReachabilityTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsisNeighborTlv.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsisNeighborTlv.java
index 573568d..2d7f9e0 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsisNeighborTlv.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsisNeighborTlv.java
@@ -34,7 +34,7 @@
/**
* Creates an instance of ISIS neighbor TLV.
*
- * @param tlvHeader tlvHeader
+ * @param tlvHeader TLV header
*/
public IsisNeighborTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/LspEntriesTlv.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/LspEntriesTlv.java
index 5cccfa6..e43d4b4 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/LspEntriesTlv.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/LspEntriesTlv.java
@@ -31,7 +31,7 @@
/**
* Creates an instance of LSP entries TLV.
*
- * @param tlvHeader tlvHeader.
+ * @param tlvHeader TLV header
*/
public LspEntriesTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/LspEntry.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/LspEntry.java
index 184d411..d0713ac 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/LspEntry.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/LspEntry.java
@@ -46,7 +46,7 @@
/**
* Sets LSP sequenceNumber for LSP entry.
*
- * @param lspSequenceNumber lspSequenceNumber.
+ * @param lspSequenceNumber lspSequenceNumber
*/
public void setLspSequenceNumber(int lspSequenceNumber) {
this.lspSequenceNumber = lspSequenceNumber;
@@ -113,11 +113,11 @@
*/
public void readFrom(ChannelBuffer channelBuffer) {
this.setRemainingTime(channelBuffer.readUnsignedShort());
- byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
- channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
+ byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_TWO_BYTE];
+ channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_TWO_BYTE);
this.setLspId(IsisUtil.systemIdPlus(tempByteArray));
this.setLspSequenceNumber(channelBuffer.readInt());
- this.setLspChecksum(channelBuffer.readUnsignedByte());
+ this.setLspChecksum(channelBuffer.readUnsignedShort());
}
/**
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/MetricOfInternalReachability.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/MetricOfInternalReachability.java
index d133656..179b3e6 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/MetricOfInternalReachability.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/MetricOfInternalReachability.java
@@ -226,7 +226,7 @@
/**
* Returns error metric of metric of internal reachability.
*
- * @return errorMetric error metic
+ * @return errorMetric error metric
*/
public byte errorMetric() {
return errorMetric;
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/MetricsOfReachability.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/MetricsOfReachability.java
index 5274424..9157532 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/MetricsOfReachability.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/MetricsOfReachability.java
@@ -217,7 +217,7 @@
/**
* Sets delay metric for metric of reachability.
*
- * @param delayMetric delay metric.
+ * @param delayMetric delay metric
*/
public void setDelayMetric(byte delayMetric) {
this.delayMetric = delayMetric;
@@ -235,7 +235,7 @@
/**
* Sets Expense metric for metric of reachability.
*
- * @param expenseMetric Expense metric.
+ * @param expenseMetric Expense metric
*/
public void setExpenseMetric(byte expenseMetric) {
this.expenseMetric = expenseMetric;
@@ -253,7 +253,7 @@
/**
* Sets Error metric for metric of reachability.
*
- * @param errorMetric Error metric.
+ * @param errorMetric Error metric
*/
public void setErrorMetric(byte errorMetric) {
this.errorMetric = errorMetric;
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/PaddingTlv.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/PaddingTlv.java
index 7aff5c2..2ff97c3 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/PaddingTlv.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/PaddingTlv.java
@@ -31,7 +31,7 @@
/**
* Creates an instance of padding TLV.
*
- * @param tlvHeader tlvHeader.
+ * @param tlvHeader TLV header
*/
public PaddingTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/ProtocolSupportedTlv.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/ProtocolSupportedTlv.java
index 1c41d12..e261e92 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/ProtocolSupportedTlv.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/ProtocolSupportedTlv.java
@@ -32,7 +32,7 @@
/**
* Creates an instance of protocol supported TLV.
*
- * @param tlvHeader tlvHeader.
+ * @param tlvHeader TLV header
*/
public ProtocolSupportedTlv(TlvHeader tlvHeader) {
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvFinder.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvFinder.java
index e1fcbdf..d6bb909 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvFinder.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvFinder.java
@@ -44,6 +44,11 @@
case EXTENDEDISREACHABILITY:
//TODO
break;
+ case HOSTNAME:
+ HostNameTlv hostNameTlv = new HostNameTlv(tlvHeader);
+ hostNameTlv.readFrom(channelBuffer);
+ isisTlv = hostNameTlv;
+ break;
case IDRPINFORMATION:
IdrpInformationTlv idrpInformationTlv = new IdrpInformationTlv(tlvHeader);
idrpInformationTlv.readFrom(channelBuffer);
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/AdministrativeGroup.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/AdministrativeGroup.java
index 8e6dfa7..27675e7 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/AdministrativeGroup.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/AdministrativeGroup.java
@@ -40,7 +40,7 @@
}
/**
- * Gets administrative group value.
+ * Returns administrative group value.
*
* @return administrative group value
*/
@@ -58,7 +58,7 @@
}
/**
- * Gets administrative group value.
+ * Returns administrative group value.
*
* @return administrativeGroup value
*/
@@ -93,7 +93,7 @@
}
/**
- * Gets administrative group body as byte array.
+ * Returns administrative group body as byte array.
*
* @return byte array of sub tlv administrative group
*/
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/MaximumBandwidth.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/MaximumBandwidth.java
index e5cba2b..e138cb0 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/MaximumBandwidth.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/MaximumBandwidth.java
@@ -31,7 +31,7 @@
/**
* Creates an instance of maximum bandwidth.
*
- * @param header tlv header instance
+ * @param header TLV header instance
*/
public MaximumBandwidth(TlvHeader header) {
this.setTlvType(header.tlvType());
@@ -48,7 +48,7 @@
}
/**
- * Gets value of maximum bandwidth.
+ * Returns value of maximum bandwidth.
*
* @return maximumBandwidth value of maximum bandwidth
*/
@@ -69,7 +69,7 @@
}
/**
- * Gets byte array of maximum bandwidth sub tlv.
+ * Returns byte array of maximum bandwidth sub tlv.
*
* @return byte array of maximum bandwidth sub tlv
*/
@@ -83,7 +83,7 @@
}
/**
- * Gets maximum bandwidth sub tlv byte array.
+ * Returns maximum bandwidth sub tlv byte array.
*
* @return byte array of maximum bandwidth sub tlv
*/
@@ -92,7 +92,7 @@
linkSubTypeBody = IsisUtil.convertToFourBytes(Float.floatToIntBits(this.maximumBandwidth));
return linkSubTypeBody;
}
-
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("maximumBandwidth", maximumBandwidth)
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/MaximumReservableBandwidth.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/MaximumReservableBandwidth.java
index 22d96db..bfe72d4 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/MaximumReservableBandwidth.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/MaximumReservableBandwidth.java
@@ -31,7 +31,7 @@
/**
* Creates an instance of maximum reservable bandwidth.
*
- * @param header tlv header
+ * @param header TLV header
*/
public MaximumReservableBandwidth(TlvHeader header) {
this.setTlvType(header.tlvType());
@@ -48,7 +48,7 @@
}
/**
- * Gets value of maximum reversible bandwidth.
+ * Returns value of maximum reversible bandwidth.
*
* @return maximumBandwidth maximum reversible bandwidth
*/
@@ -84,7 +84,7 @@
}
/**
- * Gets maximum reservable bandwidth sub tlv body as byte array.
+ * Returns maximum reservable bandwidth sub tlv body as byte array.
*
* @return byte of maximum reservable bandwidth sub tlv body
*/
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/SubTlvType.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/SubTlvType.java
index b02da25..12c1127 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/SubTlvType.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/SubTlvType.java
@@ -51,7 +51,7 @@
}
/**
- * Gets the enum instance from type value - reverse lookup purpose.
+ * Returns the enum instance from type value - reverse lookup purpose.
*
* @param subTlvTypeValue TLV type value
* @return ISIS sub TLV type instance
@@ -61,7 +61,7 @@
}
/**
- * Gets value.
+ * Returns value.
*
* @return value
*/
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/TrafficEngineeringMetric.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/TrafficEngineeringMetric.java
index cad36e4..b5fe8a8 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/TrafficEngineeringMetric.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/TrafficEngineeringMetric.java
@@ -47,7 +47,7 @@
}
/**
- * Gets TE metric value.
+ * Returns TE metric value.
*
* @return value of traffic engineering metric
*/
@@ -67,7 +67,7 @@
}
/**
- * Gets instance as byte array.
+ * Returns instance as byte array.
*
* @return instance as byte array
*/
@@ -82,7 +82,7 @@
}
/**
- * Gets trafficEngineeringMetric as byte array .
+ * Returns trafficEngineeringMetric as byte array .
*
* @return byte array of trafficEngineeringMetric
*/
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/UnreservedBandwidth.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/UnreservedBandwidth.java
index 7ba34f0..94db6bb 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/UnreservedBandwidth.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/UnreservedBandwidth.java
@@ -50,7 +50,7 @@
}
/**
- * Gets list of un reserved bandwidth .
+ * Returns list of un reserved bandwidth .
*
* @return List of un reserved bandwidth
*/
@@ -71,7 +71,7 @@
}
/**
- * Gets instance as byte array.
+ * Returns instance as byte array.
*
* @return instance as byte array
*/
@@ -86,7 +86,7 @@
}
/**
- * Gets unreserved bandwidth as byte array.
+ * Returns unreserved bandwidth as byte array.
*
* @return unreserved bandwidth as byte array
*/
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/ChecksumCalculator.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/ChecksumCalculator.java
index d6b91f9..31f75b4 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/ChecksumCalculator.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/ChecksumCalculator.java
@@ -32,6 +32,7 @@
* @return true if valid else false
*/
public boolean validateLspCheckSum(byte[] lspPacket, int lspChecksumPos1, int lspChecksumPos2) {
+
byte[] checksum = calculateLspChecksum(lspPacket, lspChecksumPos1, lspChecksumPos2);
if (lspPacket[lspChecksumPos1] == checksum[0] && lspPacket[lspChecksumPos2] == checksum[1]) {
return true;
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisConfig.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisConfig.java
new file mode 100644
index 0000000..9b37cbd
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisConfig.java
@@ -0,0 +1,44 @@
+/*
+ * 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.util;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+/**
+ * Representation of ISIS config.
+ */
+public enum IsisConfig {
+ INSTANCE;
+ private JsonNode jsonNodes = null;
+
+ /**
+ * Returns the config value.
+ *
+ * @return jsonNodes json node
+ */
+ public JsonNode config() {
+ return jsonNodes;
+ }
+
+ /**
+ * Sets the config value for jsonNode.
+ *
+ * @param jsonNodes json node
+ */
+ public void setConfig(JsonNode jsonNodes) {
+ this.jsonNodes = jsonNodes;
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisConstants.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisConstants.java
index 53ef74b..fe84218 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisConstants.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisConstants.java
@@ -17,7 +17,7 @@
package org.onosproject.isis.io.util;
/**
- * Representation of ISIS constants.
+ * Representation of ISIS Constants.
*/
public final class IsisConstants {
public static final char PDU_LENGTH = 1497; // mtu (1500) - (3) LLC
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisUtil.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisUtil.java
index 318eb1b..44ad9e0 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisUtil.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisUtil.java
@@ -17,7 +17,20 @@
import com.google.common.primitives.Bytes;
import org.onlab.packet.Ip4Address;
+import org.onlab.packet.MacAddress;
+import org.onosproject.isis.controller.IsisInterface;
+import org.onosproject.isis.controller.IsisInterfaceState;
+import org.onosproject.isis.controller.IsisNeighbor;
+import org.onosproject.isis.controller.IsisPduType;
+import org.onosproject.isis.io.isispacket.IsisHeader;
+import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu;
+import org.onosproject.isis.io.isispacket.pdu.P2PHelloPdu;
+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.PaddingTlv;
+import org.onosproject.isis.io.isispacket.tlv.ProtocolSupportedTlv;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import org.onosproject.isis.io.isispacket.tlv.TlvType;
import org.slf4j.Logger;
@@ -26,6 +39,7 @@
import javax.xml.bind.DatatypeConverter;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import java.util.StringTokenizer;
/**
@@ -37,6 +51,7 @@
public static final int ID_PLUS_ONE_BYTE = 7;
public static final int ID_PLUS_TWO_BYTE = 8;
public static final int THREE_BYTES = 3;
+ public static final int TWO_BYTES = 2;
public static final int SIX_BYTES = 6;
public static final int EIGHT_BYTES = 8;
public static final int FOUR_BYTES = 4;
@@ -103,17 +118,23 @@
* @return systemIdPlus system ID
*/
public static String systemIdPlus(byte[] bytes) {
+ int count = 1;
String systemId = "";
for (Byte byt : bytes) {
String hexa = Integer.toHexString(Byte.toUnsignedInt(byt));
if (hexa.length() % 2 != 0) {
hexa = "0" + hexa;
}
- systemId = systemId + hexa;
+ if (count == 7 && bytes.length == 8) {
+ systemId = systemId + hexa + "-";
+ } else {
+ systemId = systemId + hexa;
+ }
if (systemId.length() == 4 || systemId.length() == 9
|| systemId.length() == 14) {
systemId = systemId + ".";
}
+ count++;
}
return systemId;
}
@@ -154,6 +175,38 @@
}
/**
+ * Returns PDU headaer length.
+ *
+ * @param pduType PDU type
+ * @return headerLength header length
+ */
+ public static int getPduHeaderLength(int pduType) {
+ int headerLength = 0;
+ switch (IsisPduType.get(pduType)) {
+ case L1HELLOPDU:
+ case L2HELLOPDU:
+ case L1LSPDU:
+ case L2LSPDU:
+ headerLength = IsisConstants.HELLOHEADERLENGTH;
+ break;
+ case P2PHELLOPDU:
+ headerLength = IsisConstants.P2PHELLOHEADERLENGTH;
+ break;
+ case L1PSNP:
+ case L2PSNP:
+ headerLength = IsisConstants.PSNPDUHEADERLENGTH;
+ break;
+ case L1CSNP:
+ case L2CSNP:
+ headerLength = IsisConstants.CSNPDUHEADERLENGTH;
+ break;
+ default:
+ break;
+ }
+ return headerLength;
+ }
+
+ /**
* Adds the PDU length in packet.
*
* @param isisPacket ISIS packet
@@ -186,7 +239,7 @@
*/
public static byte[] addChecksum(byte[] isisPacket, int checksumBytePos1, int checksumBytePos2) {
//Set the checksum for the packet
- //Convert the lenth to two bytes as the length field is 2 bytes
+ //Convert the length to two bytes as the length field is 2 bytes
byte[] checksumInTwoBytes = new ChecksumCalculator().calculateLspChecksum(
isisPacket, checksumBytePos1, checksumBytePos2);
//isis header 3rd and 4th position represents length
@@ -296,7 +349,6 @@
* @return numInBytes given number as bytes
*/
public static byte[] convertToFourBytes(int numberToConvert) {
-
byte[] numInBytes = new byte[4];
String s1 = Integer.toHexString(numberToConvert);
if (s1.length() % 2 != 0) {
@@ -328,6 +380,168 @@
}
/**
+ * Returns the P2P hello PDU.
+ *
+ * @param isisInterface ISIS interface instance
+ * @param paddingEnabled padding enabled or not
+ * @return hello PDU
+ */
+ public static byte[] getP2pHelloPdu(IsisInterface isisInterface, boolean paddingEnabled) {
+ IsisHeader isisHeader = new IsisHeader();
+ isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR);
+ isisHeader.setPduHeaderLength((byte) IsisConstants.P2PHELLOHEADERLENGTH);
+ isisHeader.setVersion((byte) IsisConstants.ISISVERSION);
+ isisHeader.setIdLength((byte) IsisConstants.IDLENGTH);
+ isisHeader.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
+ isisHeader.setVersion2((byte) IsisConstants.ISISVERSION);
+ //isisHeader.setReserved((byte) IsisConstants.RESERVED);
+ isisHeader.setReserved((byte) IsisConstants.PDULENGTHPOSITION);
+ isisHeader.setMaximumAreaAddresses((byte) IsisConstants.MAXAREAADDRESS);
+ P2PHelloPdu p2pHelloPdu = new P2PHelloPdu(isisHeader);
+ p2pHelloPdu.setCircuitType((byte) isisInterface.reservedPacketCircuitType());
+ p2pHelloPdu.setSourceId(isisInterface.systemId());
+ p2pHelloPdu.setHoldingTime(isisInterface.holdingTime());
+ p2pHelloPdu.setPduLength(IsisConstants.PDU_LENGTH);
+ p2pHelloPdu.setLocalCircuitId((byte) IsisConstants.LOCALCIRCUITIDFORP2P);
+
+ TlvHeader tlvHeader = new TlvHeader();
+ tlvHeader.setTlvType(TlvType.AREAADDRESS.value());
+ tlvHeader.setTlvLength(0);
+ AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
+ areaAddressTlv.addAddress(isisInterface.areaAddress());
+ p2pHelloPdu.addTlv(areaAddressTlv);
+
+ tlvHeader.setTlvType(TlvType.PROTOCOLSUPPORTED.value());
+ tlvHeader.setTlvLength(0);
+ ProtocolSupportedTlv protocolSupportedTlv = new ProtocolSupportedTlv(tlvHeader);
+ protocolSupportedTlv.addProtocolSupported((byte) IsisConstants.PROTOCOLSUPPORTED);
+ p2pHelloPdu.addTlv(protocolSupportedTlv);
+
+ tlvHeader.setTlvType(TlvType.ADJACENCYSTATE.value());
+ tlvHeader.setTlvLength(0);
+ AdjacencyStateTlv adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader);
+ adjacencyStateTlv.setAdjacencyType((byte) IsisInterfaceState.DOWN.value());
+ adjacencyStateTlv.setLocalCircuitId(Integer.parseInt(isisInterface.circuitId()));
+ Set<MacAddress> neighbors = isisInterface.neighbors();
+ if (neighbors.size() > 0) {
+ IsisNeighbor neighbor = isisInterface.lookup(neighbors.iterator().next());
+ adjacencyStateTlv.setAdjacencyType((byte) neighbor.interfaceState().value());
+ adjacencyStateTlv.setNeighborSystemId(neighbor.neighborSystemId());
+ adjacencyStateTlv.setNeighborLocalCircuitId(neighbor.localExtendedCircuitId());
+ }
+ p2pHelloPdu.addTlv(adjacencyStateTlv);
+
+ tlvHeader.setTlvType(TlvType.IPINTERFACEADDRESS.value());
+ tlvHeader.setTlvLength(0);
+ IpInterfaceAddressTlv ipInterfaceAddressTlv = new IpInterfaceAddressTlv(tlvHeader);
+ ipInterfaceAddressTlv.addInterfaceAddres(isisInterface.interfaceIpAddress());
+ p2pHelloPdu.addTlv(ipInterfaceAddressTlv);
+
+ byte[] beforePadding = p2pHelloPdu.asBytes();
+ byte[] helloMessage;
+ if (paddingEnabled) {
+ byte[] paddingTlvs = getPaddingTlvs(beforePadding.length);
+ helloMessage = Bytes.concat(beforePadding, paddingTlvs);
+ } else {
+ helloMessage = beforePadding;
+ }
+ return helloMessage;
+ }
+
+ /**
+ * Returns the L1 hello PDU.
+ *
+ * @param isisInterface ISIS interface instance
+ * @param paddingEnabled padding enabled or not
+ * @return helloMessage hello PDU
+ */
+ public static byte[] getL1HelloPdu(IsisInterface isisInterface, boolean paddingEnabled) {
+ return getL1OrL2HelloPdu(isisInterface, IsisPduType.L1HELLOPDU, paddingEnabled);
+ }
+
+ /**
+ * Returns the L2 hello PDU.
+ *
+ * @param isisInterface ISIS interface instance
+ * @param paddingEnabled padding enabled or not
+ * @return helloMessage hello PDU
+ */
+ public static byte[] getL2HelloPdu(IsisInterface isisInterface, boolean paddingEnabled) {
+ return getL1OrL2HelloPdu(isisInterface, IsisPduType.L2HELLOPDU, paddingEnabled);
+ }
+
+ /**
+ * Returns the hello PDU.
+ *
+ * @param isisInterface ISIS interface instance
+ * @param paddingEnabled padding enabled or not
+ * @return helloMessage hello PDU
+ */
+ private static byte[] getL1OrL2HelloPdu(IsisInterface isisInterface, IsisPduType isisPduType,
+ boolean paddingEnabled) {
+ String lanId = "";
+ IsisHeader isisHeader = new IsisHeader();
+ isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR);
+ isisHeader.setPduHeaderLength((byte) IsisConstants.HELLOHEADERLENGTH);
+ isisHeader.setVersion((byte) IsisConstants.ISISVERSION);
+ isisHeader.setIdLength((byte) IsisConstants.IDLENGTH);
+ if (isisPduType == IsisPduType.L1HELLOPDU) {
+ isisHeader.setIsisPduType(IsisPduType.L1HELLOPDU.value());
+ lanId = isisInterface.l1LanId();
+ } else if (isisPduType == IsisPduType.L2HELLOPDU) {
+ isisHeader.setIsisPduType(IsisPduType.L2HELLOPDU.value());
+ lanId = isisInterface.l2LanId();
+ }
+ isisHeader.setVersion2((byte) IsisConstants.ISISVERSION);
+ isisHeader.setReserved((byte) IsisConstants.PDULENGTHPOSITION);
+ isisHeader.setMaximumAreaAddresses((byte) IsisConstants.MAXAREAADDRESS);
+ L1L2HelloPdu l1L2HelloPdu = new L1L2HelloPdu(isisHeader);
+ l1L2HelloPdu.setCircuitType((byte) isisInterface.reservedPacketCircuitType());
+ l1L2HelloPdu.setSourceId(isisInterface.systemId());
+ l1L2HelloPdu.setHoldingTime(isisInterface.holdingTime());
+ l1L2HelloPdu.setPduLength(IsisConstants.PDU_LENGTH);
+ l1L2HelloPdu.setPriority((byte) isisInterface.priority());
+ l1L2HelloPdu.setLanId(lanId);
+ TlvHeader tlvHeader = new TlvHeader();
+ tlvHeader.setTlvType(TlvType.AREAADDRESS.value());
+ tlvHeader.setTlvLength(0);
+ AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
+ areaAddressTlv.addAddress(isisInterface.areaAddress());
+ l1L2HelloPdu.addTlv(areaAddressTlv);
+ Set<MacAddress> neighbors = isisInterface.neighbors();
+ if (neighbors.size() > 0) {
+ tlvHeader.setTlvType(TlvType.ISNEIGHBORS.value());
+ tlvHeader.setTlvLength(0);
+ IsisNeighborTlv isisNeighborTlv = new IsisNeighborTlv(tlvHeader);
+ for (MacAddress neighbor : neighbors) {
+ isisNeighborTlv.addNeighbor(neighbor);
+ }
+ l1L2HelloPdu.addTlv(isisNeighborTlv);
+ }
+ tlvHeader.setTlvType(TlvType.PROTOCOLSUPPORTED.value());
+ tlvHeader.setTlvLength(0);
+ ProtocolSupportedTlv protocolSupportedTlv = new ProtocolSupportedTlv(tlvHeader);
+ protocolSupportedTlv.addProtocolSupported((byte) IsisConstants.PROTOCOLSUPPORTED);
+ l1L2HelloPdu.addTlv(protocolSupportedTlv);
+
+ tlvHeader.setTlvType(TlvType.IPINTERFACEADDRESS.value());
+ tlvHeader.setTlvLength(0);
+ IpInterfaceAddressTlv ipInterfaceAddressTlv = new IpInterfaceAddressTlv(tlvHeader);
+ ipInterfaceAddressTlv.addInterfaceAddres(isisInterface.interfaceIpAddress());
+ l1L2HelloPdu.addTlv(ipInterfaceAddressTlv);
+
+ byte[] beforePadding = l1L2HelloPdu.asBytes();
+ byte[] helloMessage;
+ if (paddingEnabled) {
+ byte[] paddingTlvs = getPaddingTlvs(beforePadding.length);
+ helloMessage = Bytes.concat(beforePadding, paddingTlvs);
+ } else {
+ helloMessage = beforePadding;
+ }
+ return helloMessage;
+ }
+
+ /**
* Converts a byte to integer variable.
*
* @param bytesToConvert bytes to convert
@@ -461,4 +675,22 @@
}
return numInBytes;
}
-}
+
+ /**
+ * Converts the bytes of prefix to string type value.
+ *
+ * @param bytes array of prefix
+ * @return string value of prefix
+ */
+ public static String prefixConversion(byte[] bytes) {
+ String prefix = "";
+ for (int i = 0; i < bytes.length; i++) {
+ if (i < (bytes.length - 1)) {
+ prefix = prefix + bytes[i] + ".";
+ } else {
+ prefix = prefix + bytes[i];
+ }
+ }
+ return prefix;
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/LspGenerator.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/LspGenerator.java
new file mode 100644
index 0000000..1dfb1a4
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/LspGenerator.java
@@ -0,0 +1,159 @@
+/*
+ * 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.util;
+
+import org.onlab.packet.Ip4Address;
+import org.onlab.packet.MacAddress;
+import org.onosproject.isis.controller.IsisInterface;
+import org.onosproject.isis.controller.IsisNeighbor;
+import org.onosproject.isis.controller.IsisNetworkType;
+import org.onosproject.isis.controller.IsisPduType;
+import org.onosproject.isis.io.isispacket.IsisHeader;
+import org.onosproject.isis.io.isispacket.pdu.AttachedToOtherAreas;
+import org.onosproject.isis.io.isispacket.pdu.LsPdu;
+import org.onosproject.isis.io.isispacket.tlv.AreaAddressTlv;
+import org.onosproject.isis.io.isispacket.tlv.HostNameTlv;
+import org.onosproject.isis.io.isispacket.tlv.IpInterfaceAddressTlv;
+import org.onosproject.isis.io.isispacket.tlv.IpInternalReachabilityTlv;
+import org.onosproject.isis.io.isispacket.tlv.IsReachabilityTlv;
+import org.onosproject.isis.io.isispacket.tlv.MetricOfInternalReachability;
+import org.onosproject.isis.io.isispacket.tlv.MetricsOfReachability;
+import org.onosproject.isis.io.isispacket.tlv.ProtocolSupportedTlv;
+import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
+import org.onosproject.isis.io.isispacket.tlv.TlvType;
+
+import java.util.List;
+
+/**
+ * Representation of link state PDU generator.
+ */
+public class LspGenerator {
+
+ public LsPdu getLsp(IsisInterface isisInterface, String lspId, IsisPduType isisPduType,
+ List<Ip4Address> allConfiguredInterfaceIps) {
+ IsisHeader header = getHeader(isisPduType);
+ LsPdu lsp = new LsPdu(header);
+
+ lsp.setPduLength(0);
+ lsp.setRemainingLifeTime(IsisConstants.LSPMAXAGE);
+ lsp.setLspId(lspId);
+ lsp.setSequenceNumber(isisInterface.isisLsdb().lsSequenceNumber(isisPduType));
+ lsp.setCheckSum(0);
+ if (isisPduType == IsisPduType.L1LSPDU) {
+ lsp.setTypeBlock((byte) 1);
+ lsp.setIntermediateSystemType((byte) 1);
+ } else if (isisPduType == IsisPduType.L2LSPDU) {
+ lsp.setTypeBlock((byte) 3);
+ lsp.setIntermediateSystemType((byte) 3);
+ }
+ lsp.setAttachedToOtherAreas(AttachedToOtherAreas.NONE);
+ lsp.setPartitionRepair(false);
+ lsp.setLspDbol(false);
+
+ TlvHeader tlvHeader = new TlvHeader();
+ tlvHeader.setTlvType(TlvType.AREAADDRESS.value());
+ tlvHeader.setTlvLength(0);
+ AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
+ areaAddressTlv.addAddress(isisInterface.areaAddress());
+ lsp.addTlv(areaAddressTlv);
+
+ tlvHeader.setTlvType(TlvType.PROTOCOLSUPPORTED.value());
+ tlvHeader.setTlvLength(0);
+ ProtocolSupportedTlv protocolSupportedTlv = new ProtocolSupportedTlv(tlvHeader);
+ protocolSupportedTlv.addProtocolSupported((byte) IsisConstants.PROTOCOLSUPPORTED);
+ lsp.addTlv(protocolSupportedTlv);
+
+ tlvHeader.setTlvType(TlvType.IPINTERFACEADDRESS.value());
+ tlvHeader.setTlvLength(0);
+ IpInterfaceAddressTlv ipInterfaceAddressTlv = new IpInterfaceAddressTlv(tlvHeader);
+ for (Ip4Address ipaddress : allConfiguredInterfaceIps) {
+ ipInterfaceAddressTlv.addInterfaceAddres(ipaddress);
+ }
+ lsp.addTlv(ipInterfaceAddressTlv);
+
+ tlvHeader.setTlvType(TlvType.HOSTNAME.value());
+ tlvHeader.setTlvLength(0);
+ HostNameTlv hostNameTlv = new HostNameTlv(tlvHeader);
+ hostNameTlv.setHostName(isisInterface.intermediateSystemName());
+ lsp.addTlv(hostNameTlv);
+
+ tlvHeader.setTlvType(TlvType.ISREACHABILITY.value());
+ tlvHeader.setTlvLength(0);
+ IsReachabilityTlv isReachabilityTlv = new IsReachabilityTlv(tlvHeader);
+ isReachabilityTlv.setReserved(0);
+ MetricsOfReachability metricsOfReachability = new MetricsOfReachability();
+ metricsOfReachability.setDefaultMetric((byte) 10);
+ metricsOfReachability.setDefaultIsInternal(true);
+ metricsOfReachability.setDelayMetric((byte) 10);
+ metricsOfReachability.setDelayIsInternal(true);
+ metricsOfReachability.setDelayMetricSupported(true);
+ metricsOfReachability.setExpenseMetric((byte) 10);
+ metricsOfReachability.setExpenseIsInternal(true);
+ metricsOfReachability.setExpenseMetricSupported(true);
+ metricsOfReachability.setErrorMetric((byte) 10);
+ metricsOfReachability.setErrorIsInternal(true);
+ metricsOfReachability.setErrorMetricSupported(true);
+ if (isisInterface.networkType() == IsisNetworkType.BROADCAST) {
+ if (isisPduType == IsisPduType.L1LSPDU) {
+ metricsOfReachability.setNeighborId(isisInterface.l1LanId());
+ } else if (isisPduType == IsisPduType.L2LSPDU) {
+ metricsOfReachability.setNeighborId(isisInterface.l2LanId());
+ }
+ } else if (isisInterface.networkType() == IsisNetworkType.P2P) {
+ MacAddress neighborMac = isisInterface.neighbors().iterator().next();
+ IsisNeighbor neighbor = isisInterface.lookup(neighborMac);
+ metricsOfReachability.setNeighborId(neighbor.neighborSystemId());
+ }
+
+ isReachabilityTlv.addMeticsOfReachability(metricsOfReachability);
+ lsp.addTlv(isReachabilityTlv);
+
+ tlvHeader.setTlvType(TlvType.IPINTERNALREACHABILITY.value());
+ tlvHeader.setTlvLength(0);
+ IpInternalReachabilityTlv ipInterReacTlv = new IpInternalReachabilityTlv(tlvHeader);
+ MetricOfInternalReachability metricOfIntRea = new MetricOfInternalReachability();
+ metricOfIntRea.setDefaultMetric((byte) 10);
+ metricOfIntRea.setDefaultIsInternal(true);
+ metricOfIntRea.setDefaultDistributionDown(true);
+ metricOfIntRea.setDelayMetric((byte) 0);
+ metricOfIntRea.setDelayMetricSupported(false);
+ metricOfIntRea.setDelayIsInternal(true);
+ metricOfIntRea.setExpenseMetric((byte) 0);
+ metricOfIntRea.setExpenseMetricSupported(false);
+ metricOfIntRea.setExpenseIsInternal(true);
+ metricOfIntRea.setErrorMetric((byte) 0);
+ metricOfIntRea.setErrorMetricSupported(false);
+ metricOfIntRea.setExpenseIsInternal(true);
+ metricOfIntRea.setIpAddress(isisInterface.interfaceIpAddress());
+ metricOfIntRea.setSubnetAddres(Ip4Address.valueOf(isisInterface.networkMask()));
+ ipInterReacTlv.addInternalReachabilityMetric(metricOfIntRea);
+ lsp.addTlv(ipInterReacTlv);
+ return lsp;
+ }
+
+ public IsisHeader getHeader(IsisPduType pduType) {
+ IsisHeader isisHeader = new IsisHeader();
+ isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR);
+ isisHeader.setPduHeaderLength((byte) IsisUtil.getPduHeaderLength(pduType.value()));
+ isisHeader.setVersion((byte) IsisConstants.ISISVERSION);
+ isisHeader.setIdLength((byte) IsisConstants.IDLENGTH);
+ isisHeader.setIsisPduType(pduType.value());
+ isisHeader.setVersion2((byte) IsisConstants.ISISVERSION);
+ isisHeader.setReserved((byte) IsisConstants.RESERVED);
+ isisHeader.setMaximumAreaAddresses((byte) IsisConstants.MAXAREAADDRESS);
+ return isisHeader;
+ }
+}
\ No newline at end of file