diff options
Diffstat (limited to 'framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate')
10 files changed, 0 insertions, 1859 deletions
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpLinkLSIdentifier.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpLinkLSIdentifier.java deleted file mode 100644 index a4360fdf..00000000 --- a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpLinkLSIdentifier.java +++ /dev/null @@ -1,297 +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.linkstate; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -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.Constants; -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 implements Comparable<Object> { - 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; - - private NodeDescriptors localNodeDescriptors; - private NodeDescriptors remoteNodeDescriptors; - private List<BgpValueType> linkDescriptor; - - /** - * Initialize fields. - */ - public BgpLinkLSIdentifier() { - this.localNodeDescriptors = null; - this.remoteNodeDescriptors = null; - this.linkDescriptor = null; - } - - /** - * Constructors to initialize parameters. - * - * @param localNodeDescriptors local node descriptors - * @param remoteNodeDescriptors remote node descriptors - * @param linkDescriptor link descriptors - */ - public BgpLinkLSIdentifier(NodeDescriptors localNodeDescriptors, NodeDescriptors remoteNodeDescriptors, - LinkedList<BgpValueType> linkDescriptor) { - this.localNodeDescriptors = Preconditions.checkNotNull(localNodeDescriptors); - this.remoteNodeDescriptors = Preconditions.checkNotNull(remoteNodeDescriptors); - this.linkDescriptor = Preconditions.checkNotNull(linkDescriptor); - } - - /** - * Reads channel buffer and parses link identifier. - * - * @param cb ChannelBuffer - * @param protocolId in linkstate nlri - * @return object of BGPLinkLSIdentifier - * @throws BgpParseException while parsing link identifier - */ - public static BgpLinkLSIdentifier parseLinkIdendifier(ChannelBuffer cb, byte protocolId) throws BgpParseException { - //Parse local node descriptor - NodeDescriptors localNodeDescriptors = new NodeDescriptors(); - localNodeDescriptors = parseNodeDescriptors(cb, NodeDescriptors.LOCAL_NODE_DES_TYPE, protocolId); - - //Parse remote node descriptor - NodeDescriptors remoteNodeDescriptors = new NodeDescriptors(); - remoteNodeDescriptors = parseNodeDescriptors(cb, NodeDescriptors.REMOTE_NODE_DES_TYPE, protocolId); - - //Parse link descriptor - LinkedList<BgpValueType> linkDescriptor = new LinkedList<>(); - linkDescriptor = parseLinkDescriptors(cb); - return new BgpLinkLSIdentifier(localNodeDescriptors, remoteNodeDescriptors, linkDescriptor); - } - - /** - * Parses Local/Remote node descriptors. - * - * @param cb ChannelBuffer - * @param desType descriptor type - * @param protocolId protocol identifier - * @return object of NodeDescriptors - * @throws BgpParseException while parsing Local/Remote node descriptors - */ - public static NodeDescriptors parseNodeDescriptors(ChannelBuffer cb, short desType, byte protocolId) - throws BgpParseException { - log.debug("parse Node descriptors"); - ChannelBuffer tempBuf = cb.copy(); - 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_AS_SHORT)); - } - NodeDescriptors nodeIdentifier = new NodeDescriptors(); - ChannelBuffer tempCb = cb.readBytes(length); - - if (type == desType) { - nodeIdentifier = NodeDescriptors.read(tempCb, length, desType, protocolId); - } else { - throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.MALFORMED_ATTRIBUTE_LIST, null); - } - return nodeIdentifier; - } - - /** - * Parses link descriptors. - * - * @param cb ChannelBuffer - * @return list of link descriptors - * @throws BgpParseException while parsing link descriptors - */ - public static LinkedList<BgpValueType> parseLinkDescriptors(ChannelBuffer cb) throws BgpParseException { - LinkedList<BgpValueType> linkDescriptor = new LinkedList<>(); - BgpValueType tlv = null; - int count = 0; - - while (cb.readableBytes() > 0) { - ChannelBuffer tempBuf = cb.copy(); - 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_AS_SHORT)); - } - 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 - + Constants.TYPE_AND_LEN_AS_SHORT)); - } - break; - default: - UnSupportedAttribute.skipBytes(tempCb, length); - } - linkDescriptor.add(tlv); - } - return linkDescriptor; - } - - /** - * Returns local node descriptors. - * - * @return local node descriptors - */ - public NodeDescriptors localNodeDescriptors() { - return this.localNodeDescriptors; - } - - /** - * Returns remote node descriptors. - * - * @return remote node descriptors - */ - public NodeDescriptors remoteNodeDescriptors() { - return this.remoteNodeDescriptors; - } - - /** - * Returns link descriptors. - * - * @return link descriptors - */ - public List<BgpValueType> linkDescriptors() { - return this.linkDescriptor; - } - - @Override - public int hashCode() { - return Objects.hash(linkDescriptor, localNodeDescriptors, remoteNodeDescriptors); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof BgpLinkLSIdentifier) { - int countObjSubTlv = 0; - int countOtherSubTlv = 0; - boolean isCommonSubTlv = true; - BgpLinkLSIdentifier other = (BgpLinkLSIdentifier) obj; - Iterator<BgpValueType> objListIterator = other.linkDescriptor.iterator(); - countOtherSubTlv = other.linkDescriptor.size(); - countObjSubTlv = linkDescriptor.size(); - if (countObjSubTlv != countOtherSubTlv) { - return false; - } else { - while (objListIterator.hasNext() && isCommonSubTlv) { - BgpValueType subTlv = objListIterator.next(); - if (linkDescriptor.contains(subTlv) && other.linkDescriptor.contains(subTlv)) { - isCommonSubTlv = Objects.equals(linkDescriptor.get(linkDescriptor.indexOf(subTlv)), - other.linkDescriptor.get(other.linkDescriptor.indexOf(subTlv))); - } else { - isCommonSubTlv = false; - } - } - 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(); - } - - @Override - public int compareTo(Object o) { - if (this.equals(o)) { - return 0; - } - int result = this.localNodeDescriptors.compareTo(((BgpLinkLSIdentifier) o).localNodeDescriptors); - if (result != 0) { - return result; - } else if (this.remoteNodeDescriptors.compareTo(((BgpLinkLSIdentifier) o).remoteNodeDescriptors) != 0) { - return this.remoteNodeDescriptors.compareTo(((BgpLinkLSIdentifier) o).remoteNodeDescriptors); - } else { - int countOtherSubTlv = ((BgpLinkLSIdentifier) o).linkDescriptor.size(); - int countObjSubTlv = linkDescriptor.size(); - if (countOtherSubTlv != countObjSubTlv) { - if (countOtherSubTlv > countObjSubTlv) { - return 1; - } else { - return -1; - } - } - ListIterator<BgpValueType> listIterator = linkDescriptor.listIterator(); - ListIterator<BgpValueType> listIteratorOther = ((BgpLinkLSIdentifier) o).linkDescriptor.listIterator(); - while (listIterator.hasNext()) { - BgpValueType tlv = listIterator.next(); - if (linkDescriptor.contains(tlv) && ((BgpLinkLSIdentifier) o).linkDescriptor.contains(tlv)) { - int res = linkDescriptor.get(linkDescriptor.indexOf(tlv)).compareTo( - ((BgpLinkLSIdentifier) o).linkDescriptor.get(((BgpLinkLSIdentifier) o).linkDescriptor - .indexOf(tlv))); - if (res != 0) { - return res; - } - } else { - return 1; - } - } - } - return 0; - } -} diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpLinkLsNlriVer4.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpLinkLsNlriVer4.java deleted file mode 100755 index 01d369e4..00000000 --- a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpLinkLsNlriVer4.java +++ /dev/null @@ -1,210 +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.linkstate;
-
-import java.util.List;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BgpParseException;
-import org.onosproject.bgpio.protocol.BgpLinkLsNlri;
-import org.onosproject.bgpio.protocol.NlriType;
-import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType;
-import org.onosproject.bgpio.types.BgpErrorType;
-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 Link LS NLRI.
- */
-public class BgpLinkLsNlriVer4 implements BgpLinkLsNlri {
-
- /*
- * 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) //
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- // Remote Node Descriptors (variable) //
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- // Link Descriptors (variable) //
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
- Figure : The Link NLRI format
- */
- private static final Logger log = LoggerFactory.getLogger(BgpLinkLsNlriVer4.class);
- public static final int LINK_NLRITYPE = 2;
-
- private BgpLinkLSIdentifier linkLSIdentifier;
- private byte protocolId;
- private long identifier;
- private RouteDistinguisher routeDistinguisher;
- private boolean isVpn;
-
- /**
- * Initialize fields.
- */
- public BgpLinkLsNlriVer4() {
- this.protocolId = 0;
- this.identifier = 0;
- this.linkLSIdentifier = null;
- this.routeDistinguisher = null;
- this.isVpn = false;
- }
-
- /**
- * Constructor to initialize parameters for BGP LinkLSNlri.
- *
- * @param protocolId protocol Id
- * @param identifier field in BGP LinkLSNlri
- * @param linkLSIdentifier link LS identifier
- * @param routeDistinguisher route distinguisher from message
- * @param isVpn vpn info availability in message
- */
- public BgpLinkLsNlriVer4(byte protocolId, long identifier, BgpLinkLSIdentifier linkLSIdentifier,
- RouteDistinguisher routeDistinguisher, boolean isVpn) {
- this.protocolId = protocolId;
- this.identifier = identifier;
- this.linkLSIdentifier = linkLSIdentifier;
- this.routeDistinguisher = routeDistinguisher;
- this.isVpn = isVpn;
- }
-
- /**
- * Reads from channelBuffer and parses Link 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 Link LS NLRI
- */
- public static BgpLinkLsNlriVer4 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();
-
- BgpLinkLSIdentifier linkLSIdentifier = new BgpLinkLSIdentifier();
- linkLSIdentifier = BgpLinkLSIdentifier.parseLinkIdendifier(cb, protocolId);
- return new BgpLinkLsNlriVer4(protocolId, identifier, linkLSIdentifier, routeDistinguisher, isVpn);
- }
-
- @Override
- public NlriType getNlriType() {
- return NlriType.LINK;
- }
-
- @Override
- public long getIdentifier() {
- return this.identifier;
- }
-
- /**
- * Set the link LS identifier.
- *
- * @param linkLSIdentifier link LS identifier to set
- */
- public void setLinkLSIdentifier(BgpLinkLSIdentifier linkLSIdentifier) {
- this.linkLSIdentifier = linkLSIdentifier;
- }
-
- @Override
- public ProtocolType getProtocolId() throws BgpParseException {
- switch (protocolId) {
- case Constants.ISIS_LEVELONE:
- return ProtocolType.ISIS_LEVEL_ONE;
- case Constants.ISIS_LEVELTWO:
- return ProtocolType.ISIS_LEVEL_TWO;
- case Constants.OSPFV2:
- return ProtocolType.OSPF_V2;
- case Constants.DIRECT:
- return ProtocolType.DIRECT;
- case Constants.STATIC_CONFIGURATION:
- return ProtocolType.STATIC_CONFIGURATION;
- case Constants.OSPFV3:
- return ProtocolType.OSPF_V3;
- default:
- throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
- }
- }
-
- @Override
- public NodeDescriptors localNodeDescriptors() {
- return this.linkLSIdentifier.localNodeDescriptors();
- }
-
- @Override
- public NodeDescriptors remoteNodeDescriptors() {
- return this.linkLSIdentifier.remoteNodeDescriptors();
- }
-
- /**
- * 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;
- }
-
- /**
- * Returns link identifier.
- *
- * @return link identifier
- */
- public BgpLinkLSIdentifier getLinkIdentifier() {
- return this.linkLSIdentifier;
- }
-
- @Override
- public List<BgpValueType> linkDescriptors() {
- return this.linkLSIdentifier.linkDescriptors();
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(getClass())
- .omitNullValues()
- .add("protocolId", protocolId)
- .add("identifier", identifier)
- .add("RouteDistinguisher ", routeDistinguisher)
- .add("linkLSIdentifier", linkLSIdentifier)
- .toString();
- }
-}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpNodeLSIdentifier.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpNodeLSIdentifier.java deleted file mode 100644 index 6c2c96d9..00000000 --- a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpNodeLSIdentifier.java +++ /dev/null @@ -1,122 +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.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 implements Comparable<Object> { - - private 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 { - log.debug("parse Local node descriptor"); - ChannelBuffer tempBuf = cb.copy(); - 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(); - } - - @Override - public int compareTo(Object o) { - if (this.equals(o)) { - return 0; - } - return this.nodeDescriptors.compareTo(((BgpNodeLSIdentifier) o).nodeDescriptors); - } -} diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpNodeLSNlriVer4.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpNodeLSNlriVer4.java deleted file mode 100644 index b27096cf..00000000 --- a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/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.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_LEVEL_ONE(1), ISIS_LEVEL_TWO(2), OSPF_V2(3), DIRECT(4), STATIC_CONFIGURATION(5), OSPF_V3(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 - */ - public 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_LEVEL_ONE; - case Constants.ISIS_LEVELTWO: - return ProtocolType.ISIS_LEVEL_TWO; - case Constants.OSPFV2: - return ProtocolType.OSPF_V2; - case Constants.DIRECT: - return ProtocolType.DIRECT; - case Constants.STATIC_CONFIGURATION: - return ProtocolType.STATIC_CONFIGURATION; - case Constants.OSPFV3: - return ProtocolType.OSPF_V3; - 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/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpPrefixIPv4LSNlriVer4.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpPrefixIPv4LSNlriVer4.java deleted file mode 100644 index 49cb74bd..00000000 --- a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/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.linkstate; - -import java.util.List; - -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_LEVEL_ONE; - case Constants.ISIS_LEVELTWO: - return ProtocolType.ISIS_LEVEL_TWO; - case Constants.OSPFV2: - return ProtocolType.OSPF_V2; - case Constants.DIRECT: - return ProtocolType.DIRECT; - case Constants.STATIC_CONFIGURATION: - return ProtocolType.STATIC_CONFIGURATION; - case Constants.OSPFV3: - return ProtocolType.OSPF_V3; - 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 List<BgpValueType> getPrefixdescriptor() { - return this.bgpPrefixLSIdentifier.getPrefixdescriptor(); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .omitNullValues() - .add("protocolId", protocolId) - .add("identifier", identifier) - .add("RouteDistinguisher ", routeDistinguisher) - .add("bgpPrefixLSIdentifier", bgpPrefixLSIdentifier) - .toString(); - } -} diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpPrefixLSIdentifier.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpPrefixLSIdentifier.java deleted file mode 100644 index 22e68917..00000000 --- a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpPrefixLSIdentifier.java +++ /dev/null @@ -1,272 +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.linkstate; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -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 implements Comparable<Object> { - - protected static final Logger log = LoggerFactory.getLogger(BgpPrefixLSIdentifier.class); - public static final int TYPE_AND_LEN = 4; - private NodeDescriptors localNodeDescriptors; - private List<BgpValueType> prefixDescriptor; - - /** - * Resets parameters. - */ - public BgpPrefixLSIdentifier() { - this.localNodeDescriptors = null; - this.prefixDescriptor = null; - } - - /** - * Constructor to initialize parameters. - * - * @param localNodeDescriptors Local node descriptors - * @param prefixDescriptor Prefix Descriptors - */ - public BgpPrefixLSIdentifier(NodeDescriptors localNodeDescriptors, List<BgpValueType> prefixDescriptor) { - this.localNodeDescriptors = localNodeDescriptors; - this.prefixDescriptor = prefixDescriptor; - } - - /** - * Reads the channel buffer and parses Prefix Identifier. - * - * @param cb ChannelBuffer - * @param protocolId protocol ID - * @return object of this class - * @throws BgpParseException while parsing Prefix Identifier - */ - public static BgpPrefixLSIdentifier parsePrefixIdendifier(ChannelBuffer cb, byte protocolId) - throws BgpParseException { - //Parse Local Node descriptor - NodeDescriptors localNodeDescriptors = new NodeDescriptors(); - localNodeDescriptors = parseLocalNodeDescriptors(cb, protocolId); - - //Parse Prefix descriptor - List<BgpValueType> prefixDescriptor = new LinkedList<>(); - prefixDescriptor = parsePrefixDescriptors(cb); - return new BgpPrefixLSIdentifier(localNodeDescriptors, prefixDescriptor); - } - - /** - * Parse local node descriptors. - * - * @param cb ChannelBuffer - * @param protocolId protocol identifier - * @return LocalNodeDescriptors - * @throws BgpParseException while parsing local node descriptors - */ - public static NodeDescriptors parseLocalNodeDescriptors(ChannelBuffer cb, byte protocolId) - throws BgpParseException { - ChannelBuffer tempBuf = cb.copy(); - 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 List<BgpValueType> parsePrefixDescriptors(ChannelBuffer cb) throws BgpParseException { - LinkedList<BgpValueType> prefixDescriptor = new LinkedList<>(); - BgpValueType tlv = null; - boolean isIpReachInfo = false; - ChannelBuffer tempCb; - int count = 0; - - while (cb.readableBytes() > 0) { - ChannelBuffer tempBuf = cb.copy(); - 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 List<BgpValueType> getPrefixdescriptor() { - return this.prefixDescriptor; - } - - @Override - public int hashCode() { - return Objects.hash(prefixDescriptor.hashCode(), localNodeDescriptors); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj instanceof BgpPrefixLSIdentifier) { - int countObjSubTlv = 0; - int countOtherSubTlv = 0; - boolean isCommonSubTlv = true; - BgpPrefixLSIdentifier other = (BgpPrefixLSIdentifier) obj; - - Iterator<BgpValueType> objListIterator = other.prefixDescriptor.iterator(); - countOtherSubTlv = other.prefixDescriptor.size(); - countObjSubTlv = prefixDescriptor.size(); - if (countObjSubTlv != countOtherSubTlv) { - return false; - } else { - while (objListIterator.hasNext() && isCommonSubTlv) { - BgpValueType subTlv = objListIterator.next(); - if (prefixDescriptor.contains(subTlv) && other.prefixDescriptor.contains(subTlv)) { - isCommonSubTlv = Objects.equals(prefixDescriptor.get(prefixDescriptor.indexOf(subTlv)), - other.prefixDescriptor.get(other.prefixDescriptor.indexOf(subTlv))); - } else { - isCommonSubTlv = false; - } - } - 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(); - } - - @Override - public int compareTo(Object o) { - if (this.equals(o)) { - return 0; - } - int result = this.localNodeDescriptors.compareTo(((BgpPrefixLSIdentifier) o).localNodeDescriptors); - if (result != 0) { - return result; - } else { - int countOtherSubTlv = ((BgpPrefixLSIdentifier) o).prefixDescriptor.size(); - int countObjSubTlv = prefixDescriptor.size(); - if (countOtherSubTlv != countObjSubTlv) { - if (countOtherSubTlv > countObjSubTlv) { - return 1; - } else { - return -1; - } - } - - ListIterator<BgpValueType> listIterator = prefixDescriptor.listIterator(); - ListIterator<BgpValueType> listIteratorOther = ((BgpPrefixLSIdentifier) o).prefixDescriptor.listIterator(); - while (listIterator.hasNext()) { - BgpValueType tlv = listIterator.next(); - if (prefixDescriptor.contains(tlv) && ((BgpPrefixLSIdentifier) o).prefixDescriptor.contains(tlv)) { - int res = prefixDescriptor.get(prefixDescriptor.indexOf(tlv)).compareTo( - ((BgpPrefixLSIdentifier) o).prefixDescriptor - .get(((BgpPrefixLSIdentifier) o).prefixDescriptor.indexOf(tlv))); - if (res != 0) { - return res; - } - } else { - return 1; - } - } - } - return 0; - } -} diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java deleted file mode 100644 index f91ac260..00000000 --- a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java +++ /dev/null @@ -1,264 +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.linkstate; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -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 - */ - - private 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 List<BgpValueType> subTlvs; - private short deslength; - private short desType; - - /** - * Resets parameters. - */ - public NodeDescriptors() { - this.subTlvs = null; - this.deslength = 0; - this.desType = 0; - } - - /** - * Constructor to initialize parameters. - * - * @param subTlvs list of subTlvs - * @param deslength Descriptors length - * @param desType local node descriptor or remote node descriptor type - */ - public NodeDescriptors(List<BgpValueType> subTlvs, short deslength, short desType) { - this.subTlvs = subTlvs; - this.deslength = deslength; - this.desType = desType; - } - - /** - * Returns list of subTlvs. - * - * @return subTlvs list of subTlvs - */ - public List<BgpValueType> getSubTlvs() { - return subTlvs; - } - - @Override - public int hashCode() { - return Objects.hash(subTlvs.hashCode()); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj instanceof NodeDescriptors) { - int countObjSubTlv = 0; - int countOtherSubTlv = 0; - boolean isCommonSubTlv = true; - NodeDescriptors other = (NodeDescriptors) obj; - Iterator<BgpValueType> objListIterator = other.subTlvs.iterator(); - countOtherSubTlv = other.subTlvs.size(); - countObjSubTlv = subTlvs.size(); - if (countObjSubTlv != countOtherSubTlv) { - return false; - } else { - while (objListIterator.hasNext() && isCommonSubTlv) { - BgpValueType subTlv = objListIterator.next(); - if (subTlvs.contains(subTlv) && other.subTlvs.contains(subTlv)) { - isCommonSubTlv = Objects.equals(subTlvs.get(subTlvs.indexOf(subTlv)), - other.subTlvs.get(other.subTlvs.indexOf(subTlv))); - } else { - isCommonSubTlv = false; - } - } - 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 { - log.debug("Read NodeDescriptor"); - List<BgpValueType> subTlvs = new LinkedList<>(); - BgpValueType tlv = null; - - while (cb.readableBytes() > 0) { - ChannelBuffer tempBuf = cb.copy(); - 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(); - } - - public int compareTo(Object o) { - if (this.equals(o)) { - return 0; - } - ListIterator<BgpValueType> listIterator = subTlvs.listIterator(); - ListIterator<BgpValueType> listIteratorOther = ((NodeDescriptors) o).subTlvs.listIterator(); - int countOtherSubTlv = ((NodeDescriptors) o).subTlvs.size(); - int countObjSubTlv = subTlvs.size(); - if (countOtherSubTlv != countObjSubTlv) { - if (countOtherSubTlv > countObjSubTlv) { - return 1; - } else { - return -1; - } - } else { - while (listIterator.hasNext()) { - BgpValueType tlv = listIterator.next(); - log.debug("NodeDescriptor compare subtlv's"); - if (subTlvs.contains(tlv) && ((NodeDescriptors) o).subTlvs.contains(tlv)) { - int result = subTlvs.get(subTlvs.indexOf(tlv)).compareTo( - ((NodeDescriptors) o).subTlvs.get(((NodeDescriptors) o).subTlvs.indexOf(tlv))); - if (result != 0) { - return result; - } - } else { - return 1; - } - } - } - return 0; - } -} diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetails.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetails.java deleted file mode 100755 index 9578ccfe..00000000 --- a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetails.java +++ /dev/null @@ -1,135 +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.linkstate; - -import java.util.Iterator; -import java.util.List; -import java.util.Objects; - -import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType; -import org.onosproject.bgpio.types.BgpValueType; - -import com.google.common.base.MoreObjects; - -/** - * This Class stores path Attributes, protocol ID and Identifier of LinkState NLRI. - */ -public class PathAttrNlriDetails { - private List<BgpValueType> pathAttributes; - private ProtocolType protocolID; - private long identifier; - - /** - * Sets path attribute with specified path attribute. - * - * @param pathAttributes in update message - */ - public void setPathAttribute(List<BgpValueType> pathAttributes) { - this.pathAttributes = pathAttributes; - } - - /** - * Returns path attributes. - * - * @return path attributes - */ - public List<BgpValueType> pathAttributes() { - return this.pathAttributes; - } - - /** - * Sets protocolID with specified protocolID. - * - * @param protocolID in linkstate nlri - */ - public void setProtocolID(ProtocolType protocolID) { - this.protocolID = protocolID; - } - - /** - * Returns protocolID. - * - * @return protocolID - */ - public ProtocolType protocolID() { - return this.protocolID; - } - - /** - * Sets identifier with specified identifier. - * - * @param identifier in linkstate nlri - */ - public void setIdentifier(long identifier) { - this.identifier = identifier; - } - - /** - * Returns Identifier. - * - * @return Identifier - */ - public long identifier() { - return this.identifier; - } - - @Override - public int hashCode() { - return Objects.hash(pathAttributes, protocolID, identifier); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj instanceof PathAttrNlriDetails) { - int countObjSubTlv = 0; - int countOtherSubTlv = 0; - boolean isCommonSubTlv = true; - PathAttrNlriDetails other = (PathAttrNlriDetails) obj; - Iterator<BgpValueType> objListIterator = other.pathAttributes.iterator(); - countOtherSubTlv = other.pathAttributes.size(); - countObjSubTlv = pathAttributes.size(); - if (countObjSubTlv != countOtherSubTlv) { - return false; - } else { - while (objListIterator.hasNext() && isCommonSubTlv) { - BgpValueType subTlv = objListIterator.next(); - if (pathAttributes.contains(subTlv) && other.pathAttributes.contains(subTlv)) { - isCommonSubTlv = Objects.equals(pathAttributes.get(pathAttributes.indexOf(subTlv)), - other.pathAttributes.get(other.pathAttributes.indexOf(subTlv))); - } else { - isCommonSubTlv = false; - } - } - return isCommonSubTlv && Objects.equals(identifier, other.identifier) - && Objects.equals(protocolID, other.protocolID); - } - } - return false; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("identifier", identifier) - .add("protocolID", protocolID) - .add("pathAttributes", pathAttributes) - .toString(); - } -} diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetailsLocalRib.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetailsLocalRib.java deleted file mode 100755 index 4172ae46..00000000 --- a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetailsLocalRib.java +++ /dev/null @@ -1,122 +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.linkstate; - -import java.util.Objects; - -import org.onlab.packet.IpAddress; -import com.google.common.base.MoreObjects; - -/** - * This Class stores path Attributes, protocol ID and Identifier of LinkState nlri. - */ -public class PathAttrNlriDetailsLocalRib { - - private IpAddress localRibIpAddress; - private long localRibAsNum; - private int localRibIdentifier; - private boolean isLocalRibIbgpSession; - private PathAttrNlriDetails localRibNlridetails; - - /** - * Constructor to initialize parameter. - * - * @param localRibIpAddress peer ip address - * @param localRibIdentifier peer identifier - * @param localRibAsNum peer As number - * @param isLocalRibIbgpSession flag to indicate is Ibgp session - * @param localRibNlridetails Nlri details - * - */ - public PathAttrNlriDetailsLocalRib(IpAddress localRibIpAddress, int localRibIdentifier, long localRibAsNum, - boolean isLocalRibIbgpSession, PathAttrNlriDetails localRibNlridetails) { - this.localRibIpAddress = localRibIpAddress; - this.localRibAsNum = localRibAsNum; - this.localRibIdentifier = localRibIdentifier; - this.isLocalRibIbgpSession = isLocalRibIbgpSession; - this.localRibNlridetails = localRibNlridetails; - } - - /** - * Gets the Ipaddress updated in local rib. - * - * @return localRibIpAddress ip address - */ - public IpAddress localRibIpAddress() { - return localRibIpAddress; - } - - /** - * Gets the autonomous system number updated in local rib. - * - * @return localRibAsNum autonomous system number - */ - public long localRibAsNum() { - return localRibAsNum; - } - - /** - * Gets the indetifier updated in local rib. - * - * @return localRibIdentifier identifier - */ - public int localRibIdentifier() { - return localRibIdentifier; - } - - /** - * Gets the bgp session type updated in local rib. - * - * @return isLocalRibIbgpSession session type - */ - public boolean isLocalRibIbgpSession() { - return isLocalRibIbgpSession; - } - - /** - * Returns local RIB Nlri details. - * - * @return localRibNlridetails Nlri details in local rib - */ - public PathAttrNlriDetails localRibNlridetails() { - return this.localRibNlridetails; - } - - @Override - public int hashCode() { - return Objects.hash(localRibIpAddress, localRibIdentifier, localRibAsNum, isLocalRibIbgpSession, - localRibNlridetails.hashCode()); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof PathAttrNlriDetailsLocalRib) { - PathAttrNlriDetailsLocalRib other = (PathAttrNlriDetailsLocalRib) obj; - return Objects.equals(localRibIpAddress, other.localRibIpAddress) - && Objects.equals(localRibIdentifier, other.localRibIdentifier) - && Objects.equals(localRibAsNum, other.localRibAsNum) - && Objects.equals(isLocalRibIbgpSession, other.isLocalRibIbgpSession) - && Objects.equals(localRibNlridetails, other.localRibNlridetails); - } - return false; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()).add("peerIdentifier", localRibIdentifier) - .add("localRibpathAttributes", localRibNlridetails.pathAttributes()).toString(); - } -} diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/package-info.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/package-info.java deleted file mode 100755 index 87ba60f0..00000000 --- a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/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.linkstate; |