ONOS-4082: Packet structures- TLV packet structures
Change-Id: Id67867d215e9e6215854bc35fc435a1b0da9bf3b
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/IsisConstantParameters.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/IsisConstantParameters.java
new file mode 100755
index 0000000..d3def43
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/IsisConstantParameters.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.isis.io.isispacket;
+
+/**
+ * Represents ISIS constant parameters.
+ */
+public final class IsisConstantParameters {
+
+ public static final int IRPDISCRIMINATOR = 131;
+ public static final int PROOCOLID = 1;
+ public static final int VERSION = 1;
+ public static final int RESERVED = 0;
+ public static final int MAXAREAADDRESS = 3;
+ public static final int IDLENGTH = 6;
+ public static final int PROTOCOLSUPPORTED = 6;
+ public static final int PACKETMINIMUMLENGTH = 27;
+ public static final int PDULENGTHPOSITION = 17;
+ public static final int PDUHEADERFORREADFROM = 8;
+
+ /**
+ * Creates an instance of this class.
+ */
+ private IsisConstantParameters() {
+
+ }
+}
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/package-info.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/package-info.java
new file mode 100755
index 0000000..4b60bd0
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Implementation of the ISIS protocol.
+ */
+package org.onosproject.isis.io.isispacket;
\ No newline at end of file
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
new file mode 100755
index 0000000..df76628
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/AreaAddressTlv.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.isis.io.isispacket.tlv;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.primitives.Bytes;
+import io.netty.buffer.ByteBuf;
+import org.onosproject.isis.io.util.IsisUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents the area address TLV.
+ */
+public class AreaAddressTlv extends TlvHeader implements IsisTlv {
+
+ private List<String> areaAddress = new ArrayList();
+
+ /**
+ * Sets TLV type and TLV length of area address TLV.
+ *
+ * @param tlvHeader tlvHeader.
+ */
+ public AreaAddressTlv(TlvHeader tlvHeader) {
+
+ this.setTlvType(tlvHeader.tlvType());
+ this.setTlvLength(tlvHeader.tlvLength());
+
+ }
+
+ /**
+ * Gets the area address of area address TLV.
+ *
+ * @return area address
+ */
+ public List<String> areaAddress() {
+ return this.areaAddress;
+ }
+
+ @Override
+ public void readFrom(ByteBuf byteBuf) {
+ while (byteBuf.readableBytes() > 0) {
+ int addressLength = byteBuf.readByte();
+ byte[] addressBytes = new byte[IsisUtil.THREE_BYTES];
+ byteBuf.readBytes(addressBytes, 0, IsisUtil.THREE_BYTES);
+ String areaAddress = IsisUtil.areaAddres(addressBytes);
+ this.areaAddress.add(areaAddress);
+ }
+ }
+
+ @Override
+ public byte[] asBytes() {
+ byte[] bytes = null;
+
+ byte[] tlvHeader = tlvHeaderAsByteArray();
+ byte[] tlvBody = tlvBodyAsBytes();
+ bytes = Bytes.concat(tlvHeader, tlvBody);
+
+ return bytes;
+ }
+
+ /**
+ * Gets TLV body of area address TLV.
+ *
+ * @return byteArray TLV body of area address TLV
+ */
+ public byte[] tlvBodyAsBytes() {
+
+ List<Byte> bytes = new ArrayList();
+ for (String areaAddress : this.areaAddress) {
+ bytes.add((byte) (areaAddress.length() / 2));
+ bytes.addAll(IsisUtil.areaAddresToBytes(areaAddress));
+ }
+ byte[] byteArray = new byte[bytes.size()];
+ int i = 0;
+ for (byte byt : bytes) {
+ byteArray[i++] = byt;
+ }
+ return byteArray;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .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
new file mode 100755
index 0000000..906acff
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpInterfaceAddressTlv.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.isis.io.isispacket.tlv;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.primitives.Bytes;
+import io.netty.buffer.ByteBuf;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.isis.io.util.IsisUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents IP interface address TLV.
+ */
+public class IpInterfaceAddressTlv extends TlvHeader implements IsisTlv {
+ private List<Ip4Address> interfaceAddress = new ArrayList();
+
+ /**
+ * Sets TLV type and TLV length of IP interface address TLV.
+ *
+ * @param tlvHeader tlvHeader.
+ */
+ public IpInterfaceAddressTlv(TlvHeader tlvHeader) {
+
+ this.setTlvType(tlvHeader.tlvType());
+ this.setTlvLength(tlvHeader.tlvLength());
+
+ }
+
+ /**
+ * Gets interface address of interface address TLV.
+ *
+ * @return interfaceAddress interface address
+ */
+ public List<Ip4Address> interfaceAddress() {
+ return interfaceAddress;
+ }
+
+ @Override
+ public void readFrom(ByteBuf byteBuf) {
+ while (byteBuf.readableBytes() >= 4) {
+ byte[] addressbytes = new byte[IsisUtil.FOUR_BYTES];
+ byteBuf.readBytes(addressbytes, 0, IsisUtil.FOUR_BYTES);
+ this.interfaceAddress.add(Ip4Address.valueOf(addressbytes));
+ }
+
+ }
+
+ @Override
+ public byte[] asBytes() {
+ byte[] bytes = null;
+
+ byte[] tlvHeader = tlvHeaderAsByteArray();
+ byte[] tlvBody = tlvBodyAsBytes();
+ bytes = Bytes.concat(tlvHeader, tlvBody);
+
+ return bytes;
+ }
+
+ /**
+ * Gets TLV body of interface address TLV.
+ *
+ * @return byteArray TLV body of interface address TLV.
+ */
+ public byte[] tlvBodyAsBytes() {
+
+ List<Byte> bytes = new ArrayList();
+ for (Ip4Address ip4Address : this.interfaceAddress) {
+ bytes.addAll(Bytes.asList(ip4Address.toOctets()));
+ }
+ byte[] byteArray = new byte[bytes.size()];
+ int i = 0;
+ for (byte byt : bytes) {
+ byteArray[i++] = byt;
+ }
+ return byteArray;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .toString();
+ }
+}
\ No newline at end of file
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
new file mode 100755
index 0000000..b8da9d9
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsisNeighborTlv.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.isis.io.isispacket.tlv;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.primitives.Bytes;
+import io.netty.buffer.ByteBuf;
+import org.onlab.packet.MacAddress;
+import org.onosproject.isis.io.util.IsisUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents ISIS neighbor TLV.
+ */
+public class IsisNeighborTlv extends TlvHeader implements IsisTlv {
+
+ private List<MacAddress> neighbor = new ArrayList();
+
+ /**
+ * Sets TLV type and TLV length of ISIS neighbor TLV.
+ *
+ * @param tlvHeader tlvHeader.
+ */
+ public IsisNeighborTlv(TlvHeader tlvHeader) {
+
+ this.setTlvType(tlvHeader.tlvType());
+ this.setTlvLength(tlvHeader.tlvLength());
+
+ }
+
+ /**
+ * Gets the MAC address of the neighbor TLV.
+ *
+ * @return neighbor MAC address of the neighbor TLV
+ */
+ public List<MacAddress> neighbor() {
+ return this.neighbor;
+ }
+
+ @Override
+ public void readFrom(ByteBuf byteBuf) {
+ while (byteBuf.readableBytes() >= 6) {
+ byte[] addressbytes = new byte[IsisUtil.SIX_BYTES];
+ byteBuf.readBytes(addressbytes, 0, IsisUtil.SIX_BYTES);
+ this.neighbor.add(MacAddress.valueOf(addressbytes));
+ }
+
+ }
+
+ @Override
+ public byte[] asBytes() {
+ byte[] bytes = null;
+
+ byte[] tlvHeader = tlvHeaderAsByteArray();
+ byte[] tlvBody = tlvBodyAsBytes();
+ bytes = Bytes.concat(tlvHeader, tlvBody);
+
+ return bytes;
+
+ }
+
+ /**
+ * Gets TLV body of neighbor TLV.
+ *
+ * @return byteArray TLV body of neighbor TLV
+ */
+ public byte[] tlvBodyAsBytes() {
+
+ List<Byte> bytes = new ArrayList();
+ for (MacAddress macAddress : this.neighbor) {
+ bytes.addAll(Bytes.asList(macAddress.toBytes()));
+ }
+ byte[] byteArray = new byte[bytes.size()];
+ int i = 0;
+ for (byte byt : bytes) {
+ byteArray[i++] = byt;
+ }
+ return byteArray;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsisTlv.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsisTlv.java
new file mode 100755
index 0000000..45c96ed
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsisTlv.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.isis.io.isispacket.tlv;
+
+/**
+ * Represents ISIS TLV.
+ */
+public interface IsisTlv {
+}
\ No newline at end of file
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
new file mode 100755
index 0000000..6135315
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/PaddingTlv.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.isis.io.isispacket.tlv;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.primitives.Bytes;
+import io.netty.buffer.ByteBuf;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents padding TLV.
+ */
+public class PaddingTlv extends TlvHeader implements IsisTlv {
+ private List<Byte> paddings = new ArrayList();
+
+ /**
+ * Sets TLV type and TLV length of padding TLV.
+ *
+ * @param tlvHeader tlvHeader.
+ */
+ public PaddingTlv(TlvHeader tlvHeader) {
+ this.setTlvType(tlvHeader.tlvType());
+ this.setTlvLength(tlvHeader.tlvLength());
+ }
+
+ @Override
+ public void readFrom(ByteBuf byteBuf) {
+ while (byteBuf.readableBytes() > 0) {
+ this.paddings.add(byteBuf.readByte());
+ }
+ }
+
+ @Override
+ public byte[] asBytes() {
+ byte[] bytes = null;
+
+ byte[] tlvHeader = tlvHeaderAsByteArray();
+ byte[] tlvBody = tlvBodyAsBytes();
+ bytes = Bytes.concat(tlvHeader, tlvBody);
+
+ return bytes;
+ }
+
+ /**
+ * Gets TLV body padding TLV.
+ *
+ * @return areaArea TLV body padding TLV\\
+ */
+ public byte[] tlvBodyAsBytes() {
+ byte[] areaArea = new byte[this.tlvLength()];
+ return areaArea;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .toString();
+ }
+}
\ No newline at end of file
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
new file mode 100755
index 0000000..dad08bd
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/ProtocolSupportedTlv.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.isis.io.isispacket.tlv;
+
+import com.google.common.primitives.Bytes;
+import io.netty.buffer.ByteBuf;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents Protocol supported TLV.
+ */
+public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv {
+
+ private List<Byte> protocolSupported = new ArrayList();
+
+ /**
+ * Sets TLV type and TLV length of protocol supported TLV.
+ *
+ * @param tlvHeader tlvHeader.
+ */
+ public ProtocolSupportedTlv(TlvHeader tlvHeader) {
+
+ this.setTlvType(tlvHeader.tlvType());
+ this.setTlvLength(tlvHeader.tlvLength());
+
+ }
+
+ /**
+ * Gets the Protocol Supported by the TLV.
+ *
+ * @return Protocol Supported
+ */
+ public List<Byte> protocolSupported() {
+
+ return this.protocolSupported;
+
+ }
+
+ @Override
+ public void readFrom(ByteBuf byteBuf) {
+
+ while (byteBuf.readableBytes() > 0) {
+ this.protocolSupported.add(byteBuf.readByte());
+ }
+ }
+
+ @Override
+ public byte[] asBytes() {
+ byte[] bytes = null;
+
+ byte[] tlvHeader = tlvHeaderAsByteArray();
+ byte[] tlvBody = tlvBodyAsBytes();
+ bytes = Bytes.concat(tlvHeader, tlvBody);
+
+ return bytes;
+ }
+
+ /**
+ * Gets TLV body of protocol supported TLV.
+ *
+ * @return byteArray TLV body of protocol supported TLV
+ */
+ public byte[] tlvBodyAsBytes() {
+
+ List<Byte> bytes = new ArrayList();
+ for (byte byt : this.protocolSupported) {
+ bytes.add(byt);
+ }
+ byte[] byteArray = new byte[bytes.size()];
+ int i = 0;
+ for (byte byt : bytes) {
+ byteArray[i++] = byt;
+ }
+ return byteArray;
+ }
+}
\ No newline at end of file
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
new file mode 100755
index 0000000..4b28c35
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvFinder.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.isis.io.isispacket.tlv;
+
+import io.netty.buffer.ByteBuf;
+import org.onosproject.isis.io.util.IsisUtil;
+
+/**
+ * Represents TLV finder.
+ */
+public class TlvFinder extends TlvHeader {
+
+ /**
+ * Sets the value for TLV header and the body of the TLV.
+ *
+ * @param tlvHeader tlvHeader
+ * @param byteBuf byteBuf
+ * @return isisTlv ISIS TLV
+ */
+ public static IsisTlv findTlv(TlvHeader tlvHeader, ByteBuf byteBuf) {
+
+ IsisTlv isisTlv = null;
+
+ switch (tlvHeader.tlvType()) {
+ case IsisUtil.AREAADDRESS:
+ AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
+ areaAddressTlv.readFrom(byteBuf);
+ isisTlv = areaAddressTlv;
+ break;
+ case IsisUtil.IPINTERFACEADDRESS:
+ IpInterfaceAddressTlv ipTlv = new IpInterfaceAddressTlv(tlvHeader);
+ ipTlv.readFrom(byteBuf);
+ isisTlv = ipTlv;
+ break;
+ case IsisUtil.PROTOCOLSUPPORTED:
+ ProtocolSupportedTlv psTlv = new ProtocolSupportedTlv(tlvHeader);
+ psTlv.readFrom(byteBuf);
+ isisTlv = psTlv;
+ break;
+ case IsisUtil.ISNEIGHBORS:
+ IsisNeighborTlv isisNeighborTlv = new IsisNeighborTlv(tlvHeader);
+ isisNeighborTlv.readFrom(byteBuf);
+ isisTlv = isisNeighborTlv;
+ break;
+ case IsisUtil.PADDING:
+ PaddingTlv paddingTlv = new PaddingTlv(tlvHeader);
+ paddingTlv.readFrom(byteBuf);
+ isisTlv = paddingTlv;
+ break;
+ default:
+ break;
+ }
+
+ return isisTlv;
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvHeader.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvHeader.java
new file mode 100755
index 0000000..1c2cda4
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvHeader.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.isis.io.isispacket.tlv;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.primitives.Bytes;
+import io.netty.buffer.ByteBuf;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents TLV header.
+ */
+public class TlvHeader implements IsisTlv {
+ private int tlvType;
+ private int tlvLength;
+
+ /**
+ * Gets the TLV length of the TLV.
+ *
+ * @return tlvLength TLV length
+ */
+ public int tlvLength() {
+ return tlvLength;
+ }
+
+ /**
+ * Sets the TLV length for the mTLV.
+ *
+ * @param tlvLength TLV length
+ */
+ public void setTlvLength(int tlvLength) {
+ this.tlvLength = tlvLength;
+ }
+
+ /**
+ * Gets the TLV type of the TLV.
+ *
+ * @return tlvType TLV type
+ */
+ public int tlvType() {
+ return tlvType;
+ }
+
+ /**
+ * Sets TLV type for the TLV.
+ *
+ * @param tlvType TLV type
+ */
+ public void setTlvType(int tlvType) {
+ this.tlvType = tlvType;
+ }
+
+ /**
+ * Sets the TLV values of TLV from b yte buffer.
+ *
+ * @param byteBuf byteBuf.
+ */
+ public void readFrom(ByteBuf byteBuf) {
+ //implemented in sub classes
+ }
+
+
+ /**
+ * Gets the TLV of the TLV as bytes.
+ *
+ * @return null
+ */
+ public byte[] asBytes() {
+ //implemented the subclasses
+ return null;
+ }
+
+ /**
+ * Gets the TLV header of the TLV.
+ *
+ * @return headerLst TLV of the TLV
+ */
+ public byte[] tlvHeaderAsByteArray() {
+ List<Byte> headerLst = new ArrayList();
+ headerLst.add((byte) this.tlvType);
+ headerLst.add((byte) this.tlvLength);
+ return Bytes.toArray(headerLst);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("tlvType", tlvType)
+ .add("tlvLength", tlvLength)
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvType.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvType.java
new file mode 100755
index 0000000..b340126
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvType.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.isis.io.isispacket.tlv;
+
+/**
+ * Represents various values for TLV types.
+ */
+public enum TlvType {
+ AREAADDRESS(1),
+ ISREACHABILITY(2),
+ ISNEIGHBORS(6),
+ PADDING(8),
+ LSPENTRY(9),
+ AUTHENTICATION(10),
+ CHECKSUM(12),
+ EXTENDEDISREACHABILITY(22),
+ ISALIAS(24),
+ IPINTERNALREACHABILITY(128),
+ PROTOCOLSUPPORTED(129),
+ IPEXTERNALREACHABILITY(130),
+ IDRPINFORMATION(131),
+ IPINTERFACEADDRESS(132);
+
+ private int value;
+
+ /**
+ * Sets the TLV type value.
+ * @param value value.
+ */
+ TlvType(int value) {
+ this.value = value;
+ }
+
+ /**
+ * Gets value.
+ * @return value
+ */
+ public int value() {
+ return value;
+ }
+}
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvsToBytes.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvsToBytes.java
new file mode 100755
index 0000000..829517e
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvsToBytes.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.isis.io.isispacket.tlv;
+
+import com.google.common.primitives.Bytes;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents conversion of TLV's to bytes.
+ */
+public final class TlvsToBytes {
+ /**
+ * Sets the ISIS TLV and returns in the form of bytes.
+ *
+ * @param isisTlv isisTlv
+ * @return tlvBytes TLV bytes
+ */
+ public static List<Byte> tlvToBytes(IsisTlv isisTlv) {
+
+ List<Byte> tlvBytes = new ArrayList();
+ if (isisTlv instanceof AreaAddressTlv) {
+ AreaAddressTlv areaAddressTlv = (AreaAddressTlv) isisTlv;
+ tlvBytes.addAll(Bytes.asList(areaAddressTlv.asBytes()));
+ } else if (isisTlv instanceof IpInterfaceAddressTlv) {
+ IpInterfaceAddressTlv ipInterfaceAddressTlv = (IpInterfaceAddressTlv) isisTlv;
+ tlvBytes.addAll(Bytes.asList(ipInterfaceAddressTlv.asBytes()));
+ } else if (isisTlv instanceof ProtocolSupportedTlv) {
+ ProtocolSupportedTlv protocolSupportedTlv = (ProtocolSupportedTlv) isisTlv;
+ tlvBytes.addAll(Bytes.asList(protocolSupportedTlv.asBytes()));
+ } else if (isisTlv instanceof PaddingTlv) {
+ PaddingTlv paddingTlv = (PaddingTlv) isisTlv;
+ tlvBytes.addAll(Bytes.asList(paddingTlv.asBytes()));
+ } else if (isisTlv instanceof IsisNeighborTlv) {
+ IsisNeighborTlv isisNeighborTlv = (IsisNeighborTlv) isisTlv;
+ tlvBytes.addAll(Bytes.asList(isisNeighborTlv.asBytes()));
+ } else {
+ System.out.println("UNKNOWN TLV TYPE ::TlvsToBytes ");
+ }
+
+ return tlvBytes;
+ }
+ /**
+ * Creates an instance.
+ */
+ private TlvsToBytes() {
+ //private constructor
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/package-info.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/package-info.java
new file mode 100755
index 0000000..11b325a
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Implementation of the ISIS protocol.
+ */
+package org.onosproject.isis.io.isispacket.tlv;
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/package-info.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/package-info.java
new file mode 100755
index 0000000..bfa972a
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Implementation of the ISIS protocol.
+ */
+package org.onosproject.isis.io;
\ No newline at end of file
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
new file mode 100755
index 0000000..46b5c53
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisUtil.java
@@ -0,0 +1,317 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.isis.io.util;
+
+
+import com.google.common.base.MoreObjects;
+import com.google.common.primitives.Bytes;
+import org.onosproject.isis.io.isispacket.tlv.PaddingTlv;
+import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
+
+import javax.xml.bind.DatatypeConverter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+/**
+ * Represents ISIS utils.
+ */
+public final class IsisUtil {
+ public static final int AREAADDRESS = 1;
+ public static final int ISREACHABILITY = 2;
+ public static final int ISNEIGHBORS = 6;
+ public static final int PADDING = 8;
+ public static final int LSPENTRY = 9;
+ public static final int AUTHENTICATION = 10;
+ public static final int CHECKSUM = 12;
+ public static final int EXTENDEDISREACHABILITY = 22;
+ public static final int ISALIAS = 24;
+ public static final int IPINTERNALREACHABILITY = 128;
+ public static final int PROTOCOLSUPPORTED = 129;
+ public static final int IPEXTERNALREACHABILITY = 130;
+ public static final int IDRPINFORMATION = 131;
+ public static final int IPINTERFACEADDRESS = 132;
+ public static final int L1HELLOPDU = 1;
+ public static final int L2HELLOPDU = 2;
+ public static final int P2PHELLOPDU = 3;
+ public static final int L1LSPDU = 18;
+ public static final int L2LSPDU = 20;
+ public static final int L1CSNP = 24;
+ public static final int L2CSNP = 25;
+ public static final int L1PSNP = 26;
+ public static final int L2PSNP = 27;
+ public static final int L1L2_LS_PDUHEADERLENGTH = 27;
+ public static final int P2PPDUHEADERLENGTH = 20;
+ public static final int PSNPPDUHEADERLENGTH = 17;
+ public static final char ETHER_FRAME_LEN = 1514;
+ public static final int ID_SIX_BYTES = 6;
+ 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 SIX_BYTES = 6;
+ public static final int FOUR_BYTES = 4;
+ public static final int PADDING_FIXED_LENGTH = 255;
+
+ /**
+ * Creates an instance of this class.
+ */
+ private IsisUtil() {
+
+ }
+
+ /**
+ * Parse byte array to string system ID.
+ *
+ * @param bytes system ID
+ * @return systemId system ID.
+ */
+ public static String systemId(byte[] bytes) {
+ 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 (systemId.length() == 4 || systemId.length() == 9) {
+ systemId = systemId + ".";
+ }
+ }
+ return systemId;
+ }
+
+ /**
+ * Parse byte array to LAN ID.
+ *
+ * @param bytes LAN ID
+ * @return systemId system ID.
+ */
+ public static String systemIdPlus(byte[] bytes) {
+ 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 (systemId.length() == 4 || systemId.length() == 9
+ || systemId.length() == 14) {
+ systemId = systemId + ".";
+ }
+ }
+ return systemId;
+ }
+
+ /**
+ * Parse byte array to area address.
+ *
+ * @param bytes area address
+ * @return areaAddress area address
+ */
+ public static String areaAddres(byte[] bytes) {
+ int count = 0;
+ String areaAddress = "";
+ for (Byte byt : bytes) {
+ String hexa = Integer.toHexString(Byte.toUnsignedInt(byt));
+ if (hexa.length() % 2 != 0) {
+ hexa = "0" + hexa;
+ }
+ if (count == 0) {
+ hexa = hexa + ".";
+ }
+ areaAddress = areaAddress + hexa;
+ count++;
+ }
+ return areaAddress;
+ }
+
+ /**
+ * Parse area address to bytes.
+ *
+ * @param address area address
+ * @return areaAddress area address
+ */
+ public static List<Byte> areaAddresToBytes(String address) {
+ List<Byte> idLst = new ArrayList();
+ StringTokenizer tokenizer = new StringTokenizer(address, ".");
+ int count = 0;
+ while (tokenizer.hasMoreElements()) {
+ String str = tokenizer.nextToken();
+ if (str.length() % 2 != 0) {
+ str = "0" + str;
+ }
+ if (count > 0) {
+
+ for (int i = 0; i < str.length(); i = i + 2) {
+ idLst.add((byte) Integer.parseInt(str.substring(i, i + 2), 16));
+ }
+ } else {
+ idLst.add((byte) Integer.parseInt(str, 16));
+ }
+ count++;
+ }
+ return idLst;
+ }
+
+ /**
+ * Gets PDU header length.
+ *
+ * @param pduType PDU type
+ * @return headerLength header length
+ */
+ public static int getPduHeaderLength(int pduType) {
+ int headerLength = 0;
+ switch (pduType) {
+ case L1HELLOPDU:
+ case L2HELLOPDU:
+ case L1LSPDU:
+ case L2LSPDU:
+ headerLength = L1L2_LS_PDUHEADERLENGTH;
+ break;
+ case P2PHELLOPDU:
+ headerLength = P2PPDUHEADERLENGTH;
+ break;
+ case L1PSNP:
+ case L2PSNP:
+ headerLength = PSNPPDUHEADERLENGTH;
+ break;
+ default:
+ break;
+ }
+ return headerLength;
+ }
+
+ /**
+ * Parse source and LAN ID.
+ *
+ * @param id source and LAN ID
+ * @return sourceAndLanIdToBytes source and LAN ID
+ */
+ public static List<Byte> sourceAndLanIdToBytes(String id) {
+ List<Byte> idLst = new ArrayList();
+
+ StringTokenizer tokenizer = new StringTokenizer(id, ".");
+ while (tokenizer.hasMoreElements()) {
+ int i = 0;
+ String str = tokenizer.nextToken();
+ idLst.add((byte) Integer.parseInt(str.substring(0, i + 2), 16));
+ if (str.length() > 2) {
+ idLst.add((byte) Integer.parseInt(str.substring(i + 2, str.length()), 16));
+ }
+
+ }
+ return idLst;
+ }
+
+ /**
+ * Parse padding for PDU based on current length.
+ *
+ * @param currentLength current length
+ * @return byteArray padding array
+ */
+ public static byte[] paddingForPdu(int currentLength) {
+ List<Byte> bytes = new ArrayList<>();
+ while (ETHER_FRAME_LEN > currentLength) {
+ int length = ETHER_FRAME_LEN - currentLength;
+ TlvHeader tlvHeader = new TlvHeader();
+ tlvHeader.setTlvType(PADDING);
+ if (length >= PADDING_FIXED_LENGTH) {
+ tlvHeader.setTlvLength(PADDING_FIXED_LENGTH);
+ } else {
+ tlvHeader.setTlvLength(ETHER_FRAME_LEN - currentLength);
+ }
+ PaddingTlv tlv = new PaddingTlv(tlvHeader);
+ bytes.addAll(Bytes.asList(tlv.asBytes()));
+ currentLength = currentLength + tlv.tlvLength();
+ }
+ byte[] byteArray = new byte[bytes.size()];
+ int i = 0;
+ for (byte byt : bytes) {
+ byteArray[i++] = byt;
+ }
+ return byteArray;
+
+ }
+
+ /**
+ * Converts an integer to two bytes.
+ *
+ * @param numberToConvert number to convert
+ * @return numInBytes given number as bytes
+ */
+ public static byte[] convertToTwoBytes(int numberToConvert) {
+
+ byte[] numInBytes = new byte[2];
+ String s1 = Integer.toHexString(numberToConvert);
+ if (s1.length() % 2 != 0) {
+ s1 = "0" + s1;
+ }
+ byte[] hexas = DatatypeConverter.parseHexBinary(s1);
+ if (hexas.length == 1) {
+ numInBytes[0] = 0;
+ numInBytes[1] = hexas[0];
+ } else {
+ numInBytes[0] = hexas[0];
+ numInBytes[1] = hexas[1];
+ }
+ return numInBytes;
+ }
+
+ /**
+ * Converts a number to four bytes.
+ *
+ * @param numberToConvert number to convert
+ * @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) {
+ s1 = "0" + s1;
+ }
+ byte[] hexas = DatatypeConverter.parseHexBinary(s1);
+ if (hexas.length == 1) {
+ numInBytes[0] = 0;
+ numInBytes[1] = 0;
+ numInBytes[2] = 0;
+ numInBytes[3] = hexas[0];
+ } else if (hexas.length == 2) {
+ numInBytes[0] = 0;
+ numInBytes[1] = 0;
+ numInBytes[2] = hexas[0];
+ numInBytes[3] = hexas[1];
+ } else if (hexas.length == 3) {
+ numInBytes[0] = 0;
+ numInBytes[1] = hexas[0];
+ numInBytes[2] = hexas[1];
+ numInBytes[3] = hexas[2];
+ } else {
+ numInBytes[0] = hexas[0];
+ numInBytes[1] = hexas[1];
+ numInBytes[2] = hexas[2];
+ numInBytes[3] = hexas[3];
+ }
+ return numInBytes;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/package-info.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/package-info.java
new file mode 100755
index 0000000..feaea77
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Implementation of the ISIS protocol.
+ */
+package org.onosproject.isis.io.util;
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/package-info.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/package-info.java
new file mode 100755
index 0000000..fbbe013
--- /dev/null
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Implementation of the ISIS protocol.
+ */
+package org.onosproject.isis;
\ No newline at end of file