From baac58c7c50e6f89eb0520e3f5b0e83a69839bd3 Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Wed, 11 Nov 2015 14:39:51 -0800 Subject: Updating onos src to commit id ec0425c18cbe49d368c600160f033acf9fe344ca Change-Id: Iec2815bf7771080f25272842b852bd9d33f908ff Signed-off-by: Ashlee Young --- .../org/onosproject/bgpio/protocol/BGPLSNlri.java | 4 +- .../onosproject/bgpio/protocol/BGPNodeLSNlri.java | 4 +- .../bgpio/protocol/BGPPrefixLSNlri.java | 4 +- .../protocol/link_state/BGPLinkLSIdentifier.java | 252 --------------------- .../protocol/link_state/BGPNodeLSIdentifier.java | 113 --------- .../protocol/link_state/BGPNodeLSNlriVer4.java | 212 ----------------- .../link_state/BGPPrefixIPv4LSNlriVer4.java | 205 ----------------- .../protocol/link_state/BGPPrefixLSIdentifier.java | 228 ------------------- .../bgpio/protocol/link_state/NodeDescriptors.java | 225 ------------------ .../bgpio/protocol/link_state/package-info.java | 20 -- .../protocol/linkstate/BGPLinkLSIdentifier.java | 252 +++++++++++++++++++++ .../protocol/linkstate/BGPNodeLSIdentifier.java | 113 +++++++++ .../protocol/linkstate/BGPNodeLSNlriVer4.java | 212 +++++++++++++++++ .../linkstate/BGPPrefixIPv4LSNlriVer4.java | 205 +++++++++++++++++ .../protocol/linkstate/BGPPrefixLSIdentifier.java | 228 +++++++++++++++++++ .../bgpio/protocol/linkstate/NodeDescriptors.java | 225 ++++++++++++++++++ .../bgpio/protocol/linkstate/package-info.java | 20 ++ .../types/attr/BgpLinkAttrTeDefaultMetric.java | 132 +++++++++++ .../bgpio/types/attr/BgpPrefixAttrOpaqueData.java | 134 +++++++++++ .../bgp/BgpLinkAttrTeDefaultMetricTest.java | 42 ++++ 20 files changed, 1569 insertions(+), 1261 deletions(-) delete mode 100755 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPLinkLSIdentifier.java delete mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSIdentifier.java delete mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSNlriVer4.java delete mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPPrefixIPv4LSNlriVer4.java delete mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPPrefixLSIdentifier.java delete mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/NodeDescriptors.java delete mode 100755 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/package-info.java create mode 100755 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java create mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSIdentifier.java create mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSNlriVer4.java create mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixIPv4LSNlriVer4.java create mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixLSIdentifier.java create mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java create mode 100755 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/package-info.java create mode 100755 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java create mode 100755 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrTeDefaultMetricTest.java (limited to 'framework/src/onos/bgp') diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPLSNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPLSNlri.java index 572e2aeb..189edb88 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPLSNlri.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPLSNlri.java @@ -16,7 +16,7 @@ package org.onosproject.bgpio.protocol; import org.onosproject.bgpio.exceptions.BGPParseException; -import org.onosproject.bgpio.protocol.link_state.BGPNodeLSNlriVer4.PROTOCOLTYPE; +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4.PROTOCOLTYPE; import org.onosproject.bgpio.types.RouteDistinguisher; /** @@ -51,4 +51,4 @@ public interface BGPLSNlri { * @return Route distinguisher in Nlri */ RouteDistinguisher getRouteDistinguisher(); -} \ No newline at end of file +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNodeLSNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNodeLSNlri.java index fd5b8056..b6e4a3a0 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNodeLSNlri.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNodeLSNlri.java @@ -15,7 +15,7 @@ */ package org.onosproject.bgpio.protocol; -import org.onosproject.bgpio.protocol.link_state.BGPNodeLSIdentifier; +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSIdentifier; /** * Abstraction of an entity providing BGP-LS Node NLRI. @@ -27,4 +27,4 @@ public interface BGPNodeLSNlri extends BGPLSNlri { * @return local node descriptors */ BGPNodeLSIdentifier getLocalNodeDescriptors(); -} \ No newline at end of file +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPPrefixLSNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPPrefixLSNlri.java index 7e849f48..2c331a2e 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPPrefixLSNlri.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPPrefixLSNlri.java @@ -18,7 +18,7 @@ package org.onosproject.bgpio.protocol; import java.util.LinkedList; import org.onosproject.bgpio.types.BGPValueType; -import org.onosproject.bgpio.protocol.link_state.NodeDescriptors; +import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors; /** * Abstraction of an entity providing BGP-LS Prefix NLRI. @@ -37,4 +37,4 @@ public interface BGPPrefixLSNlri extends BGPLSNlri { * @return list of Prefix descriptor */ LinkedList getPrefixdescriptor(); -} \ No newline at end of file +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPLinkLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPLinkLSIdentifier.java deleted file mode 100755 index 3229cc11..00000000 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPLinkLSIdentifier.java +++ /dev/null @@ -1,252 +0,0 @@ -/* - * 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.link_state; - -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 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 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 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 parseLinkDescriptors(ChannelBuffer cb) throws BGPParseException { - LinkedList 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 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 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(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSIdentifier.java deleted file mode 100644 index cd2422a7..00000000 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSIdentifier.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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.link_state; - -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(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSNlriVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSNlriVer4.java deleted file mode 100644 index 04780d82..00000000 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSNlriVer4.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * 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.link_state; - -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(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPPrefixIPv4LSNlriVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPPrefixIPv4LSNlriVer4.java deleted file mode 100644 index 0f18c757..00000000 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPPrefixIPv4LSNlriVer4.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * 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.link_state; - -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.link_state.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 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(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPPrefixLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPPrefixLSIdentifier.java deleted file mode 100644 index 4fef47ff..00000000 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPPrefixLSIdentifier.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * 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.link_state; - -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 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 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 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 parsePrefixDescriptors(ChannelBuffer cb) throws BGPParseException { - LinkedList 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 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 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(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/NodeDescriptors.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/NodeDescriptors.java deleted file mode 100644 index a03b2bae..00000000 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/NodeDescriptors.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * 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.link_state; - -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 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 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 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 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 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(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/package-info.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/package-info.java deleted file mode 100755 index d2a2ccf3..00000000 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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.link_state; \ No newline at end of file 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 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 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 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 parseLinkDescriptors(ChannelBuffer cb) throws BGPParseException { + LinkedList 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 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 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 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 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 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 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 parsePrefixDescriptors(ChannelBuffer cb) throws BGPParseException { + LinkedList 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 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 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 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 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 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 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 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; diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java new file mode 100755 index 00000000..7febe3c3 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java @@ -0,0 +1,132 @@ +/* + * 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.types.attr; + +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.util.Validation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/** + * Implements BGP link state Default TE metric link attribute. + */ +public class BgpLinkAttrTeDefaultMetric implements BGPValueType { + + protected static final Logger log = LoggerFactory + .getLogger(BgpLinkAttrTeDefaultMetric.class); + + public static final int ATTRLINK_TEDEFAULTMETRIC = 1092; + public static final int TE_DATA_LEN = 4; + + /* TE Default Metric */ + private int linkTeMetric; + + /** + * Constructor to initialize the value. + * + * @param linkTeMetric TE default metric + * + */ + public BgpLinkAttrTeDefaultMetric(int linkTeMetric) { + this.linkTeMetric = linkTeMetric; + } + + /** + * Returns object of this class with specified values. + * + * @param linkTeMetric TE default metric + * @return object of BgpLinkAttrTeDefaultMetric + */ + public static BgpLinkAttrTeDefaultMetric of(final int linkTeMetric) { + return new BgpLinkAttrTeDefaultMetric(linkTeMetric); + } + + /** + * Reads the BGP link attributes of TE default metric. + * + * @param cb Channel buffer + * @return object of type BgpLinkAttrTeDefaultMetric + * @throws BGPParseException while parsing BgpLinkAttrTeDefaultMetric + */ + public static BgpLinkAttrTeDefaultMetric read(ChannelBuffer cb) + throws BGPParseException { + int linkTeMetric; + + short lsAttrLength = cb.readShort(); + + if ((lsAttrLength != TE_DATA_LEN) + || (cb.readableBytes() < lsAttrLength)) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, + lsAttrLength); + } + + linkTeMetric = cb.readInt(); + + return new BgpLinkAttrTeDefaultMetric(linkTeMetric); + } + + /** + * Returns the TE default metrics. + * + * @return link default metric + */ + public int attrLinkDefTeMetric() { + return linkTeMetric; + } + + @Override + public short getType() { + return ATTRLINK_TEDEFAULTMETRIC; + } + + @Override + public int hashCode() { + return Objects.hash(linkTeMetric); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj instanceof BgpLinkAttrTeDefaultMetric) { + BgpLinkAttrTeDefaultMetric other = (BgpLinkAttrTeDefaultMetric) obj; + return Objects.equals(linkTeMetric, other.linkTeMetric); + } + return false; + } + + @Override + public int write(ChannelBuffer cb) { + // TODO This will be implemented in the next version + return 0; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("linkTEMetric", linkTeMetric).toString(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java new file mode 100755 index 00000000..c7008ca1 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java @@ -0,0 +1,134 @@ +/* + * 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.types.attr; + +import java.util.Arrays; + +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.util.Validation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/** + * Implements BGP prefix opaque data attribute. + */ +public final class BgpPrefixAttrOpaqueData implements BGPValueType { + + protected static final Logger log = LoggerFactory + .getLogger(BgpPrefixAttrOpaqueData.class); + + public static final int ATTR_PREFIX_OPAQUEDATA = 1157; + + /* Opaque Node Attribute */ + private final byte[] opaquePrefixAttribute; + + /** + * Constructor to initialize the values. + * + * @param opaquePrefixAttribute opaque prefix data + */ + public BgpPrefixAttrOpaqueData(byte[] opaquePrefixAttribute) { + this.opaquePrefixAttribute = Arrays + .copyOf(opaquePrefixAttribute, opaquePrefixAttribute.length); + } + + /** + * Returns object of this class with specified values. + * + * @param opaquePrefixAttribute opaque prefix data + * @return object of BgpPrefixAttrOpaqueData + */ + public static BgpPrefixAttrOpaqueData of(final byte[] opaquePrefixAttribute) { + return new BgpPrefixAttrOpaqueData(opaquePrefixAttribute); + } + + /** + * Reads the Opaque Prefix Attribute. + * + * @param cb ChannelBuffer + * @return object of BgpPrefixAttrOpaqueData + * @throws BGPParseException while parsing BgpPrefixAttrOpaqueData + */ + public static BgpPrefixAttrOpaqueData read(ChannelBuffer cb) + throws BGPParseException { + byte[] opaquePrefixAttribute; + + short lsAttrLength = cb.readShort(); + opaquePrefixAttribute = new byte[lsAttrLength]; + + if (cb.readableBytes() < lsAttrLength) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, + lsAttrLength); + } + + cb.readBytes(opaquePrefixAttribute); + + return BgpPrefixAttrOpaqueData.of(opaquePrefixAttribute); + } + + /** + * Returns the Opaque prefix attribute name. + * + * @return opaque prefix name + */ + public byte[] getOpaquePrefixAttribute() { + return opaquePrefixAttribute; + } + + @Override + public short getType() { + return ATTR_PREFIX_OPAQUEDATA; + } + + @Override + public int hashCode() { + return Arrays.hashCode(opaquePrefixAttribute); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj instanceof BgpPrefixAttrOpaqueData) { + BgpPrefixAttrOpaqueData other = (BgpPrefixAttrOpaqueData) obj; + return Arrays.equals(opaquePrefixAttribute, + other.opaquePrefixAttribute); + } + return false; + } + + @Override + public int write(ChannelBuffer cb) { + // TODO This will be implemented in the next version + return 0; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()).omitNullValues() + .add("opaquePrefixAttribute", getOpaquePrefixAttribute()) + .toString(); + } + +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrTeDefaultMetricTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrTeDefaultMetricTest.java new file mode 100644 index 00000000..b6453c45 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrTeDefaultMetricTest.java @@ -0,0 +1,42 @@ +/* + * 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.bgp; + +import org.junit.Test; +import org.onosproject.bgpio.types.attr.BgpLinkAttrTeDefaultMetric; + +import com.google.common.testing.EqualsTester; + +/** + * Test for BGP link TE default metric attribute. + */ +public class BgpLinkAttrTeDefaultMetricTest { + private final int val = 0x010203; + private final int val1 = 0x01020304; + + private final BgpLinkAttrTeDefaultMetric data = BgpLinkAttrTeDefaultMetric + .of(val); + private final BgpLinkAttrTeDefaultMetric sameAsData = BgpLinkAttrTeDefaultMetric + .of(val); + private final BgpLinkAttrTeDefaultMetric diffData = BgpLinkAttrTeDefaultMetric + .of(val1); + + @Test + public void basics() { + new EqualsTester().addEqualityGroup(data, sameAsData) + .addEqualityGroup(diffData).testEquals(); + } +} \ No newline at end of file -- cgit 1.2.3-korg