aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate')
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java252
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSIdentifier.java113
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSNlriVer4.java212
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixIPv4LSNlriVer4.java205
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixLSIdentifier.java228
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java225
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/package-info.java20
7 files changed, 1255 insertions, 0 deletions
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java
new file mode 100755
index 00000000..ffea74db
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java
@@ -0,0 +1,252 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.protocol.linkstate;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.types.BGPErrorType;
+import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.types.IPv4AddressTlv;
+import org.onosproject.bgpio.types.IPv6AddressTlv;
+import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv;
+import org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId;
+import org.onosproject.bgpio.util.UnSupportedAttribute;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+
+/**
+ * Implementation of local node descriptors, remote node descriptors and link descriptors.
+ */
+public class BGPLinkLSIdentifier {
+ private static final Logger log = LoggerFactory.getLogger(BGPLinkLSIdentifier.class);
+ public static final short IPV4_INTERFACE_ADDRESS_TYPE = 259;
+ public static final short IPV4_NEIGHBOR_ADDRESS_TYPE = 260;
+ public static final short IPV6_INTERFACE_ADDRESS_TYPE = 261;
+ public static final short IPV6_NEIGHBOR_ADDRESS_TYPE = 262;
+ public static final int TYPE_AND_LEN = 4;
+
+ private NodeDescriptors localNodeDescriptors;
+ private NodeDescriptors remoteNodeDescriptors;
+ private List<BGPValueType> linkDescriptor;
+
+ /**
+ * Initialize fields.
+ */
+ public BGPLinkLSIdentifier() {
+ this.localNodeDescriptors = null;
+ this.remoteNodeDescriptors = null;
+ this.linkDescriptor = null;
+ }
+
+ /**
+ * Constructors to initialize parameters.
+ *
+ * @param localNodeDescriptors local node descriptors
+ * @param remoteNodeDescriptors remote node descriptors
+ * @param linkDescriptor link descriptors
+ */
+ public BGPLinkLSIdentifier(NodeDescriptors localNodeDescriptors, NodeDescriptors remoteNodeDescriptors,
+ LinkedList<BGPValueType> linkDescriptor) {
+ this.localNodeDescriptors = Preconditions.checkNotNull(localNodeDescriptors);
+ this.remoteNodeDescriptors = Preconditions.checkNotNull(remoteNodeDescriptors);
+ this.linkDescriptor = Preconditions.checkNotNull(linkDescriptor);
+ }
+
+ /**
+ * Reads channel buffer and parses link identifier.
+ *
+ * @param cb ChannelBuffer
+ * @param protocolId in linkstate nlri
+ * @return object of BGPLinkLSIdentifier
+ * @throws BGPParseException while parsing link identifier
+ */
+ public static BGPLinkLSIdentifier parseLinkIdendifier(ChannelBuffer cb, byte protocolId) throws BGPParseException {
+ //Parse local node descriptor
+ NodeDescriptors localNodeDescriptors = new NodeDescriptors();
+ localNodeDescriptors = parseNodeDescriptors(cb, NodeDescriptors.LOCAL_NODE_DES_TYPE, protocolId);
+
+ //Parse remote node descriptor
+ NodeDescriptors remoteNodeDescriptors = new NodeDescriptors();
+ remoteNodeDescriptors = parseNodeDescriptors(cb, NodeDescriptors.REMOTE_NODE_DES_TYPE, protocolId);
+
+ //Parse link descriptor
+ LinkedList<BGPValueType> linkDescriptor = new LinkedList<>();
+ linkDescriptor = parseLinkDescriptors(cb);
+ return new BGPLinkLSIdentifier(localNodeDescriptors, remoteNodeDescriptors, linkDescriptor);
+ }
+
+ /**
+ * Parses Local/Remote node descriptors.
+ *
+ * @param cb ChannelBuffer
+ * @param desType descriptor type
+ * @param protocolId protocol identifier
+ * @return object of NodeDescriptors
+ * @throws BGPParseException while parsing Local/Remote node descriptors
+ */
+ public static NodeDescriptors parseNodeDescriptors(ChannelBuffer cb, short desType, byte protocolId)
+ throws BGPParseException {
+ ChannelBuffer tempBuf = cb;
+ short type = cb.readShort();
+ short length = cb.readShort();
+ if (cb.readableBytes() < length) {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
+ }
+ NodeDescriptors nodeIdentifier = new NodeDescriptors();
+ ChannelBuffer tempCb = cb.readBytes(length);
+
+ if (type == desType) {
+ nodeIdentifier = NodeDescriptors.read(tempCb, length, desType, protocolId);
+ } else {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null);
+ }
+ return nodeIdentifier;
+ }
+
+ /**
+ * Parses link descriptors.
+ *
+ * @param cb ChannelBuffer
+ * @return list of link descriptors
+ * @throws BGPParseException while parsing link descriptors
+ */
+ public static LinkedList<BGPValueType> parseLinkDescriptors(ChannelBuffer cb) throws BGPParseException {
+ LinkedList<BGPValueType> linkDescriptor = new LinkedList<>();
+ BGPValueType tlv = null;
+ int count = 0;
+
+ while (cb.readableBytes() > 0) {
+ ChannelBuffer tempBuf = cb;
+ short type = cb.readShort();
+ short length = cb.readShort();
+ if (cb.readableBytes() < length) {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
+ }
+ ChannelBuffer tempCb = cb.readBytes(length);
+ switch (type) {
+ case LinkLocalRemoteIdentifiersTlv.TYPE:
+ tlv = LinkLocalRemoteIdentifiersTlv.read(tempCb);
+ break;
+ case IPV4_INTERFACE_ADDRESS_TYPE:
+ tlv = IPv4AddressTlv.read(tempCb, IPV4_INTERFACE_ADDRESS_TYPE);
+ break;
+ case IPV4_NEIGHBOR_ADDRESS_TYPE:
+ tlv = IPv4AddressTlv.read(tempCb, IPV4_NEIGHBOR_ADDRESS_TYPE);
+ break;
+ case IPV6_INTERFACE_ADDRESS_TYPE:
+ tlv = IPv6AddressTlv.read(tempCb, IPV6_INTERFACE_ADDRESS_TYPE);
+ break;
+ case IPV6_NEIGHBOR_ADDRESS_TYPE:
+ tlv = IPv6AddressTlv.read(tempCb, IPV6_NEIGHBOR_ADDRESS_TYPE);
+ break;
+ case BgpAttrNodeMultiTopologyId.ATTRNODE_MULTITOPOLOGY:
+ tlv = BgpAttrNodeMultiTopologyId.read(tempCb);
+ count = count++;
+ //MultiTopologyId TLV cannot repeat more than once
+ if (count > 1) {
+ //length + 4 implies data contains type, length and value
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR, tempBuf.readBytes(length
+ + TYPE_AND_LEN));
+ }
+ break;
+ default:
+ UnSupportedAttribute.skipBytes(tempCb, length);
+ }
+ linkDescriptor.add(tlv);
+ }
+ return linkDescriptor;
+ }
+
+ /**
+ * Returns local node descriptors.
+ *
+ * @return local node descriptors
+ */
+ public NodeDescriptors localNodeDescriptors() {
+ return this.localNodeDescriptors;
+ }
+
+ /**
+ * Returns remote node descriptors.
+ *
+ * @return remote node descriptors
+ */
+ public NodeDescriptors remoteNodeDescriptors() {
+ return this.remoteNodeDescriptors;
+ }
+
+ /**
+ * Returns link descriptors.
+ *
+ * @return link descriptors
+ */
+ public List<BGPValueType> linkDescriptors() {
+ return this.linkDescriptor;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(linkDescriptor, localNodeDescriptors, remoteNodeDescriptors);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof BGPLinkLSIdentifier) {
+ int countObjSubTlv = 0;
+ int countOtherSubTlv = 0;
+ boolean isCommonSubTlv = true;
+ BGPLinkLSIdentifier other = (BGPLinkLSIdentifier) obj;
+ Iterator<BGPValueType> objListIterator = other.linkDescriptor.iterator();
+ countOtherSubTlv = other.linkDescriptor.size();
+ countObjSubTlv = linkDescriptor.size();
+ if (countObjSubTlv != countOtherSubTlv) {
+ return false;
+ } else {
+ while (objListIterator.hasNext() && isCommonSubTlv) {
+ BGPValueType subTlv = objListIterator.next();
+ isCommonSubTlv = Objects.equals(linkDescriptor.contains(subTlv),
+ other.linkDescriptor.contains(subTlv));
+ }
+ return isCommonSubTlv && Objects.equals(this.localNodeDescriptors, other.localNodeDescriptors)
+ && Objects.equals(this.remoteNodeDescriptors, other.remoteNodeDescriptors);
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("localNodeDescriptors", localNodeDescriptors)
+ .add("remoteNodeDescriptors", remoteNodeDescriptors)
+ .add("linkDescriptor", linkDescriptor)
+ .toString();
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSIdentifier.java
new file mode 100644
index 00000000..603bf6ec
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSIdentifier.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.protocol.linkstate;
+
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.types.BGPErrorType;
+import org.onosproject.bgpio.util.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implementation of Node Identifier which includes local node descriptor/remote node descriptors.
+ */
+public class BGPNodeLSIdentifier {
+
+ protected static final Logger log = LoggerFactory.getLogger(BGPNodeLSIdentifier.class);
+ private NodeDescriptors nodeDescriptors;
+
+ /**
+ * Resets fields.
+ */
+ public BGPNodeLSIdentifier() {
+ this.nodeDescriptors = null;
+ }
+
+ /**
+ * Constructor to initialize fields.
+ *
+ * @param nodeDescriptors local/remote node descriptor
+ */
+ public BGPNodeLSIdentifier(NodeDescriptors nodeDescriptors) {
+ this.nodeDescriptors = nodeDescriptors;
+ }
+
+ /**
+ * Parse local node descriptors.
+ *
+ * @param cb ChannelBuffer
+ * @param protocolId protocol identifier
+ * @return object of this BGPNodeLSIdentifier
+ * @throws BGPParseException while parsing local node descriptors
+ */
+ public static BGPNodeLSIdentifier parseLocalNodeDescriptors(ChannelBuffer cb, byte protocolId)
+ throws BGPParseException {
+ ChannelBuffer tempBuf = cb;
+ short type = cb.readShort();
+ short length = cb.readShort();
+ if (cb.readableBytes() < length) {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ tempBuf.readBytes(cb.readableBytes() + Constants.TYPE_AND_LEN));
+ }
+ NodeDescriptors nodeDescriptors = new NodeDescriptors();
+ ChannelBuffer tempCb = cb.readBytes(length);
+
+ if (type == NodeDescriptors.LOCAL_NODE_DES_TYPE) {
+ nodeDescriptors = NodeDescriptors.read(tempCb, length, type, protocolId);
+ } else {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null);
+ }
+ return new BGPNodeLSIdentifier(nodeDescriptors);
+ }
+
+ /**
+ * Returns node descriptors.
+ *
+ * @return node descriptors
+ */
+ public NodeDescriptors getNodedescriptors() {
+ return this.nodeDescriptors;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof BGPNodeLSIdentifier) {
+ BGPNodeLSIdentifier other = (BGPNodeLSIdentifier) obj;
+ return Objects.equals(nodeDescriptors, other.nodeDescriptors);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(nodeDescriptors);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("NodeDescriptors", nodeDescriptors)
+ .toString();
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSNlriVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSNlriVer4.java
new file mode 100644
index 00000000..54837ee8
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSNlriVer4.java
@@ -0,0 +1,212 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.protocol.linkstate;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.protocol.BGPNodeLSNlri;
+import org.onosproject.bgpio.protocol.NlriType;
+import org.onosproject.bgpio.types.BGPErrorType;
+import org.onosproject.bgpio.types.RouteDistinguisher;
+import org.onosproject.bgpio.util.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implementation of Node LS NLRI.
+ */
+public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri {
+
+ /*
+ *REFERENCE : draft-ietf-idr-ls-distribution-11
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+
+ | Protocol-ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Identifier |
+ | (64 bits) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ // Local Node Descriptors (variable) //
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Figure : The Node NLRI format
+ */
+
+ protected static final Logger log = LoggerFactory.getLogger(BGPNodeLSNlriVer4.class);
+
+ public static final int NODE_NLRITYPE = 1;
+ public static final int IDENTIFIER_LENGTH = 16;
+ private long identifier;
+ private byte protocolId;
+ private BGPNodeLSIdentifier localNodeDescriptors;
+ private RouteDistinguisher routeDistinguisher;
+ private boolean isVpn;
+
+ /**
+ * Enum to provide PROTOCOLTYPE.
+ */
+ public enum PROTOCOLTYPE {
+ ISIS_LevelOne(1), ISIS_LevelTwo(2), OSPFv2(3), Direct(4), Static_Configuration(5), OSPFv3(6);
+ int value;
+
+ /**
+ * Assign val with the value as the protocol type.
+ *
+ * @param val protocol type
+ */
+ PROTOCOLTYPE(int val) {
+ value = val;
+ }
+
+ /**
+ * Returns value of protocol type.
+ *
+ * @return protocol type
+ */
+ public byte getType() {
+ return (byte) value;
+ }
+ }
+
+ /**
+ * Reset fields.
+ */
+ public BGPNodeLSNlriVer4() {
+ this.identifier = 0;
+ this.protocolId = 0;
+ this.localNodeDescriptors = null;
+ this.routeDistinguisher = null;
+ this.isVpn = false;
+ }
+
+ /**
+ * Constructors to initialize its parameters.
+ *
+ * @param identifier of LinkState Nlri
+ * @param protocolId of LinkState Nlri
+ * @param localNodeDescriptors local node descriptors
+ * @param isVpn true if VPN info is present
+ * @param routeDistinguisher unique for each VPN
+ */
+ BGPNodeLSNlriVer4(long identifier, byte protocolId, BGPNodeLSIdentifier localNodeDescriptors, boolean isVpn,
+ RouteDistinguisher routeDistinguisher) {
+ this.identifier = identifier;
+ this.protocolId = protocolId;
+ this.localNodeDescriptors = localNodeDescriptors;
+ this.routeDistinguisher = routeDistinguisher;
+ this.isVpn = isVpn;
+ }
+
+ /**
+ * Reads from channelBuffer and parses Node LS Nlri.
+ *
+ * @param cb ChannelBuffer
+ * @param afi Address Family Identifier
+ * @param safi Subsequent Address Family Identifier
+ * @return object of this class
+ * @throws BGPParseException while parsing node descriptors
+ */
+ public static BGPNodeLSNlriVer4 read(ChannelBuffer cb, short afi, byte safi) throws BGPParseException {
+ boolean isVpn = false;
+ RouteDistinguisher routeDistinguisher = null;
+ if ((afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) {
+ routeDistinguisher = new RouteDistinguisher();
+ routeDistinguisher = RouteDistinguisher.read(cb);
+ isVpn = true;
+ } else {
+ isVpn = false;
+ }
+ byte protocolId = cb.readByte();
+ long identifier = cb.readLong();
+
+ // Parse Local Node Descriptors
+ BGPNodeLSIdentifier localNodeDescriptors = new BGPNodeLSIdentifier();
+ localNodeDescriptors = BGPNodeLSIdentifier.parseLocalNodeDescriptors(cb, protocolId);
+ return new BGPNodeLSNlriVer4(identifier, protocolId, localNodeDescriptors, isVpn, routeDistinguisher);
+ }
+
+ @Override
+ public NlriType getNlriType() {
+ return NlriType.NODE;
+ }
+
+ @Override
+ public BGPNodeLSIdentifier getLocalNodeDescriptors() {
+ return this.localNodeDescriptors;
+ }
+
+ /**
+ * Returns whether VPN is present or not.
+ *
+ * @return whether VPN is present or not
+ */
+ public boolean isVpnPresent() {
+ return this.isVpn;
+ }
+
+ @Override
+ public RouteDistinguisher getRouteDistinguisher() {
+ return this.routeDistinguisher;
+ }
+
+ @Override
+ public long getIdentifier() {
+ return this.identifier;
+ }
+
+ /**
+ * Set the node LS identifier.
+ *
+ * @param localNodeDescriptors node LS identifier to set
+ */
+ public void setNodeLSIdentifier(BGPNodeLSIdentifier localNodeDescriptors) {
+ this.localNodeDescriptors = localNodeDescriptors;
+ }
+
+ @Override
+ public PROTOCOLTYPE getProtocolId() throws BGPParseException {
+ switch (protocolId) {
+ case Constants.ISIS_LEVELONE:
+ return PROTOCOLTYPE.ISIS_LevelOne;
+ case Constants.ISIS_LEVELTWO:
+ return PROTOCOLTYPE.ISIS_LevelTwo;
+ case Constants.OSPFV2:
+ return PROTOCOLTYPE.OSPFv2;
+ case Constants.DIRECT:
+ return PROTOCOLTYPE.Direct;
+ case Constants.STATIC_CONFIGURATION:
+ return PROTOCOLTYPE.Static_Configuration;
+ case Constants.OSPFV3:
+ return PROTOCOLTYPE.OSPFv3;
+ default:
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("protocolId", protocolId)
+ .add("identifier", identifier)
+ .add("RouteDistinguisher ", routeDistinguisher)
+ .add("localNodeDescriptors", localNodeDescriptors)
+ .toString();
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixIPv4LSNlriVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixIPv4LSNlriVer4.java
new file mode 100644
index 00000000..6d6f48b1
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixIPv4LSNlriVer4.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.protocol.linkstate;
+
+import java.util.LinkedList;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.protocol.BGPPrefixLSNlri;
+import org.onosproject.bgpio.protocol.NlriType;
+import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4.PROTOCOLTYPE;
+import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.types.RouteDistinguisher;
+import org.onosproject.bgpio.util.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implementation of Prefix IPV4 LS NLRI.
+ */
+public class BGPPrefixIPv4LSNlriVer4 implements BGPPrefixLSNlri {
+
+ /*
+ * REFERENCE : draft-ietf-idr-ls-distribution-11
+ * 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+
+ | Protocol-ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Identifier |
+ | (64 bits) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ // Local Node Descriptor (variable) //
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ // Prefix Descriptors (variable) //
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Figure : The IPv4/IPv6 Topology Prefix NLRI format
+ */
+
+ protected static final Logger log = LoggerFactory.getLogger(BGPPrefixIPv4LSNlriVer4.class);
+
+ public static final int PREFIX_IPV4_NLRITYPE = 3;
+ public static final int IDENTIFIER_LENGTH = 16;
+ private long identifier;
+ private byte protocolId;
+ private RouteDistinguisher routeDistinguisher;
+ private boolean isVpn;
+ private BGPPrefixLSIdentifier bgpPrefixLSIdentifier;
+
+ /**
+ * Resets parameters.
+ */
+ public BGPPrefixIPv4LSNlriVer4() {
+ this.identifier = 0;
+ this.protocolId = 0;
+ this.bgpPrefixLSIdentifier = null;
+ this.routeDistinguisher = null;
+ this.isVpn = false;
+ }
+
+ /**
+ * Constructor to initialize parameters for BGP PrefixLSNlri.
+ *
+ * @param identifier field in BGP PrefixLSNlri
+ * @param protocolId protocol Id
+ * @param bgpPrefixLSIdentifier prefix LS Identifier
+ * @param routeDistinguisher RouteDistinguisher
+ * @param isVpn vpn availability in message
+ */
+ public BGPPrefixIPv4LSNlriVer4(long identifier, byte protocolId, BGPPrefixLSIdentifier bgpPrefixLSIdentifier,
+ RouteDistinguisher routeDistinguisher, boolean isVpn) {
+ this.identifier = identifier;
+ this.protocolId = protocolId;
+ this.bgpPrefixLSIdentifier = bgpPrefixLSIdentifier;
+ this.routeDistinguisher = routeDistinguisher;
+ this.isVpn = isVpn;
+ }
+
+ /**
+ * Reads from channelBuffer and parses Prefix LS Nlri.
+ *
+ * @param cb ChannelBuffer
+ * @param afi Address family identifier
+ * @param safi Subsequent address family identifier
+ * @return object of BGPPrefixIPv4LSNlriVer4
+ * @throws BGPParseException while parsing Prefix LS Nlri
+ */
+ public static BGPPrefixIPv4LSNlriVer4 read(ChannelBuffer cb, short afi, byte safi) throws BGPParseException {
+
+ boolean isVpn = false;
+ RouteDistinguisher routeDistinguisher = null;
+ if ((afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) {
+ routeDistinguisher = new RouteDistinguisher();
+ routeDistinguisher = RouteDistinguisher.read(cb);
+ isVpn = true;
+ } else {
+ isVpn = false;
+ }
+ byte protocolId = cb.readByte();
+ long identifier = cb.readLong();
+
+ BGPPrefixLSIdentifier bgpPrefixLSIdentifier = new BGPPrefixLSIdentifier();
+ bgpPrefixLSIdentifier = BGPPrefixLSIdentifier.parsePrefixIdendifier(cb, protocolId);
+ return new BGPPrefixIPv4LSNlriVer4(identifier, protocolId, bgpPrefixLSIdentifier, routeDistinguisher, isVpn);
+ }
+
+ @Override
+ public NlriType getNlriType() {
+ return NlriType.PREFIX_IPV4;
+ }
+
+ @Override
+ public NodeDescriptors getLocalNodeDescriptors() {
+ return this.bgpPrefixLSIdentifier.getLocalNodeDescriptors();
+ }
+
+ @Override
+ public long getIdentifier() {
+ return this.identifier;
+ }
+
+ /**
+ * Set the prefix LS identifier.
+ *
+ * @param bgpPrefixLSIdentifier prefix identifier to set
+ */
+ public void setPrefixLSIdentifier(BGPPrefixLSIdentifier bgpPrefixLSIdentifier) {
+ this.bgpPrefixLSIdentifier = bgpPrefixLSIdentifier;
+ }
+
+ @Override
+ public PROTOCOLTYPE getProtocolId() throws BGPParseException {
+ switch (protocolId) {
+ case Constants.ISIS_LEVELONE:
+ return PROTOCOLTYPE.ISIS_LevelOne;
+ case Constants.ISIS_LEVELTWO:
+ return PROTOCOLTYPE.ISIS_LevelTwo;
+ case Constants.OSPFV2:
+ return PROTOCOLTYPE.OSPFv2;
+ case Constants.DIRECT:
+ return PROTOCOLTYPE.Direct;
+ case Constants.STATIC_CONFIGURATION:
+ return PROTOCOLTYPE.Static_Configuration;
+ case Constants.OSPFV3:
+ return PROTOCOLTYPE.OSPFv3;
+ default:
+ throw new BGPParseException("protocol id not valid");
+ }
+ }
+
+ /**
+ * Returns whether VPN is present or not.
+ *
+ * @return whether VPN is present or not
+ */
+ public boolean isVpnPresent() {
+ return this.isVpn;
+ }
+
+ /**
+ * Returns Prefix Identifier.
+ *
+ * @return Prefix Identifier
+ */
+ public BGPPrefixLSIdentifier getPrefixIdentifier() {
+ return this.bgpPrefixLSIdentifier;
+ }
+
+ @Override
+ public RouteDistinguisher getRouteDistinguisher() {
+ return this.routeDistinguisher;
+ }
+
+ @Override
+ public LinkedList<BGPValueType> getPrefixdescriptor() {
+ return this.bgpPrefixLSIdentifier.getPrefixdescriptor();
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("protocolId", protocolId)
+ .add("identifier", identifier)
+ .add("RouteDistinguisher ", routeDistinguisher)
+ .add("bgpPrefixLSIdentifier", bgpPrefixLSIdentifier)
+ .toString();
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixLSIdentifier.java
new file mode 100644
index 00000000..23f41794
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixLSIdentifier.java
@@ -0,0 +1,228 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.bgpio.protocol.linkstate;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.types.BGPErrorType;
+import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.types.IPReachabilityInformationTlv;
+import org.onosproject.bgpio.types.OSPFRouteTypeTlv;
+import org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId;
+import org.onosproject.bgpio.util.UnSupportedAttribute;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides Implementation of Local node descriptors and prefix descriptors.
+ */
+public class BGPPrefixLSIdentifier {
+
+ protected static final Logger log = LoggerFactory.getLogger(BGPPrefixLSIdentifier.class);
+ public static final int TYPE_AND_LEN = 4;
+ private NodeDescriptors localNodeDescriptors;
+ private LinkedList<BGPValueType> prefixDescriptor;
+
+ /**
+ * Resets parameters.
+ */
+ public BGPPrefixLSIdentifier() {
+ this.localNodeDescriptors = null;
+ this.prefixDescriptor = null;
+ }
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param localNodeDescriptors Local node descriptors
+ * @param prefixDescriptor Prefix Descriptors
+ */
+ public BGPPrefixLSIdentifier(NodeDescriptors localNodeDescriptors, LinkedList<BGPValueType> prefixDescriptor) {
+ this.localNodeDescriptors = localNodeDescriptors;
+ this.prefixDescriptor = prefixDescriptor;
+ }
+
+ /**
+ * Reads the channel buffer and parses Prefix Identifier.
+ *
+ * @param cb ChannelBuffer
+ * @param protocolId protocol ID
+ * @return object of this class
+ * @throws BGPParseException while parsing Prefix Identifier
+ */
+ public static BGPPrefixLSIdentifier parsePrefixIdendifier(ChannelBuffer cb, byte protocolId)
+ throws BGPParseException {
+ //Parse Local Node descriptor
+ NodeDescriptors localNodeDescriptors = new NodeDescriptors();
+ localNodeDescriptors = parseLocalNodeDescriptors(cb, protocolId);
+
+ //Parse Prefix descriptor
+ LinkedList<BGPValueType> prefixDescriptor = new LinkedList<>();
+ prefixDescriptor = parsePrefixDescriptors(cb);
+ return new BGPPrefixLSIdentifier(localNodeDescriptors, prefixDescriptor);
+ }
+
+ /**
+ * Parse local node descriptors.
+ *
+ * @param cb ChannelBuffer
+ * @param protocolId protocol identifier
+ * @return LocalNodeDescriptors
+ * @throws BGPParseException while parsing local node descriptors
+ */
+ public static NodeDescriptors parseLocalNodeDescriptors(ChannelBuffer cb, byte protocolId)
+ throws BGPParseException {
+ ChannelBuffer tempBuf = cb;
+ short type = cb.readShort();
+ short length = cb.readShort();
+ if (cb.readableBytes() < length) {
+ //length + 4 implies data contains type, length and value
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
+ }
+ NodeDescriptors localNodeDescriptors = new NodeDescriptors();
+ ChannelBuffer tempCb = cb.readBytes(length);
+
+ if (type == NodeDescriptors.LOCAL_NODE_DES_TYPE) {
+ localNodeDescriptors = NodeDescriptors.read(tempCb, length, type, protocolId);
+ } else {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null);
+ }
+ return localNodeDescriptors;
+ }
+
+ /**
+ * Parse list of prefix descriptors.
+ *
+ * @param cb ChannelBuffer
+ * @return list of prefix descriptors
+ * @throws BGPParseException while parsing list of prefix descriptors
+ */
+ public static LinkedList<BGPValueType> parsePrefixDescriptors(ChannelBuffer cb) throws BGPParseException {
+ LinkedList<BGPValueType> prefixDescriptor = new LinkedList<>();
+ BGPValueType tlv = null;
+ boolean isIpReachInfo = false;
+ ChannelBuffer tempCb;
+ int count = 0;
+
+ while (cb.readableBytes() > 0) {
+ ChannelBuffer tempBuf = cb;
+ short type = cb.readShort();
+ short length = cb.readShort();
+ if (cb.readableBytes() < length) {
+ //length + 4 implies data contains type, length and value
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
+ }
+ tempCb = cb.readBytes(length);
+ switch (type) {
+ case OSPFRouteTypeTlv.TYPE:
+ tlv = OSPFRouteTypeTlv.read(tempCb);
+ break;
+ case IPReachabilityInformationTlv.TYPE:
+ tlv = IPReachabilityInformationTlv.read(tempCb, length);
+ isIpReachInfo = true;
+ break;
+ case BgpAttrNodeMultiTopologyId.ATTRNODE_MULTITOPOLOGY:
+ tlv = BgpAttrNodeMultiTopologyId.read(tempCb);
+ count = count + 1;
+ if (count > 1) {
+ //length + 4 implies data contains type, length and value
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR, tempBuf.readBytes(length + TYPE_AND_LEN));
+ }
+ break;
+ default:
+ UnSupportedAttribute.skipBytes(tempCb, length);
+ }
+ prefixDescriptor.add(tlv);
+ }
+
+ if (!isIpReachInfo) {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ null);
+ }
+ return prefixDescriptor;
+ }
+
+ /**
+ * Returns local node descriptors.
+ *
+ * @return local node descriptors
+ */
+ public NodeDescriptors getLocalNodeDescriptors() {
+ return this.localNodeDescriptors;
+ }
+
+ /**
+ * Returns Prefix descriptors.
+ *
+ * @return Prefix descriptors
+ */
+ public LinkedList<BGPValueType> getPrefixdescriptor() {
+ return this.prefixDescriptor;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(prefixDescriptor.hashCode(), localNodeDescriptors);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BGPPrefixLSIdentifier) {
+ int countObjSubTlv = 0;
+ int countOtherSubTlv = 0;
+ boolean isCommonSubTlv = true;
+ BGPPrefixLSIdentifier other = (BGPPrefixLSIdentifier) obj;
+
+ Iterator<BGPValueType> objListIterator = other.prefixDescriptor.iterator();
+ countOtherSubTlv = other.prefixDescriptor.size();
+ countObjSubTlv = prefixDescriptor.size();
+ if (countObjSubTlv != countOtherSubTlv) {
+ return false;
+ } else {
+ while (objListIterator.hasNext() && isCommonSubTlv) {
+ BGPValueType subTlv = objListIterator.next();
+ isCommonSubTlv = Objects.equals(prefixDescriptor.contains(subTlv),
+ other.prefixDescriptor.contains(subTlv));
+ }
+ return isCommonSubTlv && Objects.equals(this.localNodeDescriptors, other.localNodeDescriptors);
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("localNodeDescriptors", localNodeDescriptors)
+ .add("prefixDescriptor", prefixDescriptor)
+ .toString();
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java
new file mode 100644
index 00000000..74637c7e
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java
@@ -0,0 +1,225 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.bgpio.protocol.linkstate;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.types.AreaIDTlv;
+import org.onosproject.bgpio.types.AutonomousSystemTlv;
+import org.onosproject.bgpio.types.BGPErrorType;
+import org.onosproject.bgpio.types.BGPLSIdentifierTlv;
+import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.types.IsIsNonPseudonode;
+import org.onosproject.bgpio.types.IsIsPseudonode;
+import org.onosproject.bgpio.types.OSPFNonPseudonode;
+import org.onosproject.bgpio.types.OSPFPseudonode;
+import org.onosproject.bgpio.util.UnSupportedAttribute;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides Local and Remote NodeDescriptors which contains Node Descriptor Sub-TLVs.
+ */
+public class NodeDescriptors {
+
+ /*
+ *Reference :draft-ietf-idr-ls-distribution-11
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Type | Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | |
+ // Node Descriptor Sub-TLVs (variable) //
+ | |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Figure : Local or Remote Node Descriptors TLV format
+ */
+
+ protected static final Logger log = LoggerFactory.getLogger(NodeDescriptors.class);
+
+ public static final short LOCAL_NODE_DES_TYPE = 256;
+ public static final short REMOTE_NODE_DES_TYPE = 257;
+ public static final short IGP_ROUTERID_TYPE = 515;
+ public static final short IS_IS_LEVEL_1_PROTOCOL_ID = 1;
+ public static final short IS_IS_LEVEL_2_PROTOCOL_ID = 2;
+ public static final short OSPF_V2_PROTOCOL_ID = 3;
+ public static final short OSPF_V3_PROTOCOL_ID = 6;
+ public static final int TYPE_AND_LEN = 4;
+ public static final int ISISNONPSEUDONODE_LEN = 6;
+ public static final int ISISPSEUDONODE_LEN = 7;
+ public static final int OSPFNONPSEUDONODE_LEN = 4;
+ public static final int OSPFPSEUDONODE_LEN = 8;
+ private LinkedList<BGPValueType> subTlvs;
+ private short deslength;
+ private short desType;
+
+ /**
+ * Resets parameters.
+ */
+ public NodeDescriptors() {
+ this.subTlvs = null;
+ this.deslength = 0;
+ this.desType = 0;
+ }
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param subTlvs list of subTlvs
+ * @param deslength Descriptors length
+ * @param desType local node descriptor or remote node descriptor type
+ */
+ public NodeDescriptors(LinkedList<BGPValueType> subTlvs, short deslength, short desType) {
+ this.subTlvs = subTlvs;
+ this.deslength = deslength;
+ this.desType = desType;
+ }
+
+ /**
+ * Returns list of subTlvs.
+ *
+ * @return subTlvs list of subTlvs
+ */
+ public LinkedList<BGPValueType> getSubTlvs() {
+ return subTlvs;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(subTlvs.hashCode());
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof NodeDescriptors) {
+ int countObjSubTlv = 0;
+ int countOtherSubTlv = 0;
+ boolean isCommonSubTlv = true;
+ NodeDescriptors other = (NodeDescriptors) obj;
+ Iterator<BGPValueType> objListIterator = other.subTlvs.iterator();
+ countOtherSubTlv = other.subTlvs.size();
+ countObjSubTlv = subTlvs.size();
+ if (countObjSubTlv != countOtherSubTlv) {
+ return false;
+ } else {
+ while (objListIterator.hasNext() && isCommonSubTlv) {
+ BGPValueType subTlv = objListIterator.next();
+ isCommonSubTlv = Objects.equals(subTlvs.contains(subTlv), other.subTlvs.contains(subTlv));
+ }
+ return isCommonSubTlv;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Reads node descriptors Sub-TLVs.
+ *
+ * @param cb ChannelBuffer
+ * @param desLength node descriptor length
+ * @param desType local node descriptor or remote node descriptor type
+ * @param protocolId protocol ID
+ * @return object of NodeDescriptors
+ * @throws BGPParseException while parsing node descriptors
+ */
+ public static NodeDescriptors read(ChannelBuffer cb, short desLength, short desType, byte protocolId)
+ throws BGPParseException {
+ LinkedList<BGPValueType> subTlvs;
+ subTlvs = new LinkedList<>();
+ BGPValueType tlv = null;
+
+ while (cb.readableBytes() > 0) {
+ ChannelBuffer tempBuf = cb;
+ short type = cb.readShort();
+ short length = cb.readShort();
+ if (cb.readableBytes() < length) {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
+ }
+ ChannelBuffer tempCb = cb.readBytes(length);
+ switch (type) {
+ case AutonomousSystemTlv.TYPE:
+ tlv = AutonomousSystemTlv.read(tempCb);
+ break;
+ case BGPLSIdentifierTlv.TYPE:
+ tlv = BGPLSIdentifierTlv.read(tempCb);
+ break;
+ case AreaIDTlv.TYPE:
+ tlv = AreaIDTlv.read(tempCb);
+ break;
+ case IGP_ROUTERID_TYPE:
+ if (protocolId == IS_IS_LEVEL_1_PROTOCOL_ID || protocolId == IS_IS_LEVEL_2_PROTOCOL_ID) {
+ if (length == ISISNONPSEUDONODE_LEN) {
+ tlv = IsIsNonPseudonode.read(tempCb);
+ } else if (length == ISISPSEUDONODE_LEN) {
+ tlv = IsIsPseudonode.read(tempCb);
+ }
+ } else if (protocolId == OSPF_V2_PROTOCOL_ID || protocolId == OSPF_V3_PROTOCOL_ID) {
+ if (length == OSPFNONPSEUDONODE_LEN) {
+ tlv = OSPFNonPseudonode.read(tempCb);
+ } else if (length == OSPFPSEUDONODE_LEN) {
+ tlv = OSPFPseudonode.read(tempCb);
+ }
+ }
+ break;
+ default:
+ UnSupportedAttribute.skipBytes(tempCb, length);
+ }
+ subTlvs.add(tlv);
+ }
+ return new NodeDescriptors(subTlvs, desLength, desType);
+ }
+
+ /**
+ * Returns node descriptors length.
+ *
+ * @return node descriptors length
+ */
+ public short getLength() {
+ return this.deslength;
+ }
+
+ /**
+ * Returns node descriptors type.
+ *
+ * @return node descriptors type
+ */
+ public short getType() {
+ return this.desType;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("desType", desType)
+ .add("deslength", deslength)
+ .add("subTlvs", subTlvs)
+ .toString();
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/package-info.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/package-info.java
new file mode 100755
index 00000000..87ba60f0
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * BGP Protocol specific link state details.
+ */
+package org.onosproject.bgpio.protocol.linkstate;