aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/bgp/bgpio/src/main/java/org/onosproject')
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPLSNlri.java4
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNodeLSNlri.java4
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java28
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPPrefixLSNlri.java4
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java47
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java48
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java252
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSIdentifier.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSIdentifier.java)4
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSNlriVer4.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSNlriVer4.java)4
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixIPv4LSNlriVer4.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPPrefixIPv4LSNlriVer4.java)6
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixLSIdentifier.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPPrefixLSIdentifier.java)4
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/NodeDescriptors.java)4
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/package-info.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/package-info.java)2
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java24
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpPathAttributes.java13
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java285
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java7
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java9
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java21
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java5
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java128
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java128
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java51
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java131
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java11
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java10
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java219
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java204
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java13
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java12
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java32
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java130
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java150
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java21
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java133
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java132
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIGPFlags.java)70
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java134
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java33
39 files changed, 2336 insertions, 181 deletions
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/BGPOpenMsg.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java
index a8c242b4..bf5d05f4 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java
@@ -72,13 +72,6 @@ public interface BGPOpenMsg extends BGPMessage {
BGPOpenMsg build() throws BGPParseException;
/**
- * Returns hold time of Open Message.
- *
- * @return hold time of Open Message
- */
- short getHoldTime();
-
- /**
* Sets hold time in Open Message and return its builder.
*
* @param holdtime hold timer value in open message
@@ -87,13 +80,6 @@ public interface BGPOpenMsg extends BGPMessage {
Builder setHoldTime(short holdtime);
/**
- * Returns as number of Open Message.
- *
- * @return as number of Open Message
- */
- short getAsNumber();
-
- /**
* Sets AS number in Open Message and return its builder.
*
* @param asNumber as number in open message
@@ -102,13 +88,6 @@ public interface BGPOpenMsg extends BGPMessage {
Builder setAsNumber(short asNumber);
/**
- * Returns BGP Identifier of Open Message.
- *
- * @return BGP Identifier of Open Message
- */
- int getBgpId();
-
- /**
* Sets BGP Identifier in Open Message and return its builder.
*
* @param bgpId BGP Identifier in open message
@@ -117,13 +96,6 @@ public interface BGPOpenMsg extends BGPMessage {
Builder setBgpId(int bgpId);
/**
- * Returns capabilities of Open Message.
- *
- * @return capabilities of Open Message
- */
- LinkedList<BGPValueType> getCapabilityTlv();
-
- /**
* Sets capabilities in Open Message and return its builder.
*
* @param capabilityTlv capabilities in open message
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<BGPValueType> getPrefixdescriptor();
-} \ No newline at end of file
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java
new file mode 100644
index 00000000..dab7a3d2
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+import java.util.List;
+
+import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors;
+
+/**
+ * Abstraction of an entity providing BGP-LS Link NLRI.
+ */
+public interface BgpLinkLsNlri extends BGPLSNlri {
+ /**
+ * Returns local node descriptors.
+ *
+ * @return local node descriptors
+ */
+ NodeDescriptors localNodeDescriptors();
+
+ /**
+ * Returns remote node descriptors.
+ *
+ * @return remote node descriptors
+ */
+ NodeDescriptors remoteNodeDescriptors();
+
+ /**
+ * Returns link descriptors.
+ *
+ * @return link descriptors
+ */
+ List<BGPValueType> linkDescriptors();
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java
new file mode 100644
index 00000000..969936c8
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+import java.util.List;
+
+import org.onlab.packet.IpPrefix;
+import org.onosproject.bgpio.protocol.ver4.BgpPathAttributes;
+
+/**
+ * Abstraction of an entity providing BGP Update Message.
+ */
+public interface BgpUpdateMsg extends BGPMessage {
+ /**
+ * Returns path attributes in BGP Update Message.
+ *
+ * @return path attributes in BGP Update Message
+ */
+ BgpPathAttributes bgpPathAttributes();
+
+ /**
+ * Returns withdrawn Routes.
+ *
+ * @return withdrawn Routes
+ */
+ List<IpPrefix> withdrawnRoutes();
+
+ /**
+ * Returns NLRI list of prefix.
+ *
+ * @return NLRI list of prefix
+ */
+ List<IpPrefix> nlri();
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java
new file mode 100755
index 00000000..ffea74db
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java
@@ -0,0 +1,252 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.protocol.linkstate;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.types.BGPErrorType;
+import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.types.IPv4AddressTlv;
+import org.onosproject.bgpio.types.IPv6AddressTlv;
+import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv;
+import org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId;
+import org.onosproject.bgpio.util.UnSupportedAttribute;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+
+/**
+ * Implementation of local node descriptors, remote node descriptors and link descriptors.
+ */
+public class BGPLinkLSIdentifier {
+ private static final Logger log = LoggerFactory.getLogger(BGPLinkLSIdentifier.class);
+ public static final short IPV4_INTERFACE_ADDRESS_TYPE = 259;
+ public static final short IPV4_NEIGHBOR_ADDRESS_TYPE = 260;
+ public static final short IPV6_INTERFACE_ADDRESS_TYPE = 261;
+ public static final short IPV6_NEIGHBOR_ADDRESS_TYPE = 262;
+ public static final int TYPE_AND_LEN = 4;
+
+ private NodeDescriptors localNodeDescriptors;
+ private NodeDescriptors remoteNodeDescriptors;
+ private List<BGPValueType> linkDescriptor;
+
+ /**
+ * Initialize fields.
+ */
+ public BGPLinkLSIdentifier() {
+ this.localNodeDescriptors = null;
+ this.remoteNodeDescriptors = null;
+ this.linkDescriptor = null;
+ }
+
+ /**
+ * Constructors to initialize parameters.
+ *
+ * @param localNodeDescriptors local node descriptors
+ * @param remoteNodeDescriptors remote node descriptors
+ * @param linkDescriptor link descriptors
+ */
+ public BGPLinkLSIdentifier(NodeDescriptors localNodeDescriptors, NodeDescriptors remoteNodeDescriptors,
+ LinkedList<BGPValueType> linkDescriptor) {
+ this.localNodeDescriptors = Preconditions.checkNotNull(localNodeDescriptors);
+ this.remoteNodeDescriptors = Preconditions.checkNotNull(remoteNodeDescriptors);
+ this.linkDescriptor = Preconditions.checkNotNull(linkDescriptor);
+ }
+
+ /**
+ * Reads channel buffer and parses link identifier.
+ *
+ * @param cb ChannelBuffer
+ * @param protocolId in linkstate nlri
+ * @return object of BGPLinkLSIdentifier
+ * @throws BGPParseException while parsing link identifier
+ */
+ public static BGPLinkLSIdentifier parseLinkIdendifier(ChannelBuffer cb, byte protocolId) throws BGPParseException {
+ //Parse local node descriptor
+ NodeDescriptors localNodeDescriptors = new NodeDescriptors();
+ localNodeDescriptors = parseNodeDescriptors(cb, NodeDescriptors.LOCAL_NODE_DES_TYPE, protocolId);
+
+ //Parse remote node descriptor
+ NodeDescriptors remoteNodeDescriptors = new NodeDescriptors();
+ remoteNodeDescriptors = parseNodeDescriptors(cb, NodeDescriptors.REMOTE_NODE_DES_TYPE, protocolId);
+
+ //Parse link descriptor
+ LinkedList<BGPValueType> linkDescriptor = new LinkedList<>();
+ linkDescriptor = parseLinkDescriptors(cb);
+ return new BGPLinkLSIdentifier(localNodeDescriptors, remoteNodeDescriptors, linkDescriptor);
+ }
+
+ /**
+ * Parses Local/Remote node descriptors.
+ *
+ * @param cb ChannelBuffer
+ * @param desType descriptor type
+ * @param protocolId protocol identifier
+ * @return object of NodeDescriptors
+ * @throws BGPParseException while parsing Local/Remote node descriptors
+ */
+ public static NodeDescriptors parseNodeDescriptors(ChannelBuffer cb, short desType, byte protocolId)
+ throws BGPParseException {
+ ChannelBuffer tempBuf = cb;
+ short type = cb.readShort();
+ short length = cb.readShort();
+ if (cb.readableBytes() < length) {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
+ }
+ NodeDescriptors nodeIdentifier = new NodeDescriptors();
+ ChannelBuffer tempCb = cb.readBytes(length);
+
+ if (type == desType) {
+ nodeIdentifier = NodeDescriptors.read(tempCb, length, desType, protocolId);
+ } else {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null);
+ }
+ return nodeIdentifier;
+ }
+
+ /**
+ * Parses link descriptors.
+ *
+ * @param cb ChannelBuffer
+ * @return list of link descriptors
+ * @throws BGPParseException while parsing link descriptors
+ */
+ public static LinkedList<BGPValueType> parseLinkDescriptors(ChannelBuffer cb) throws BGPParseException {
+ LinkedList<BGPValueType> linkDescriptor = new LinkedList<>();
+ BGPValueType tlv = null;
+ int count = 0;
+
+ while (cb.readableBytes() > 0) {
+ ChannelBuffer tempBuf = cb;
+ short type = cb.readShort();
+ short length = cb.readShort();
+ if (cb.readableBytes() < length) {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
+ }
+ ChannelBuffer tempCb = cb.readBytes(length);
+ switch (type) {
+ case LinkLocalRemoteIdentifiersTlv.TYPE:
+ tlv = LinkLocalRemoteIdentifiersTlv.read(tempCb);
+ break;
+ case IPV4_INTERFACE_ADDRESS_TYPE:
+ tlv = IPv4AddressTlv.read(tempCb, IPV4_INTERFACE_ADDRESS_TYPE);
+ break;
+ case IPV4_NEIGHBOR_ADDRESS_TYPE:
+ tlv = IPv4AddressTlv.read(tempCb, IPV4_NEIGHBOR_ADDRESS_TYPE);
+ break;
+ case IPV6_INTERFACE_ADDRESS_TYPE:
+ tlv = IPv6AddressTlv.read(tempCb, IPV6_INTERFACE_ADDRESS_TYPE);
+ break;
+ case IPV6_NEIGHBOR_ADDRESS_TYPE:
+ tlv = IPv6AddressTlv.read(tempCb, IPV6_NEIGHBOR_ADDRESS_TYPE);
+ break;
+ case BgpAttrNodeMultiTopologyId.ATTRNODE_MULTITOPOLOGY:
+ tlv = BgpAttrNodeMultiTopologyId.read(tempCb);
+ count = count++;
+ //MultiTopologyId TLV cannot repeat more than once
+ if (count > 1) {
+ //length + 4 implies data contains type, length and value
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR, tempBuf.readBytes(length
+ + TYPE_AND_LEN));
+ }
+ break;
+ default:
+ UnSupportedAttribute.skipBytes(tempCb, length);
+ }
+ linkDescriptor.add(tlv);
+ }
+ return linkDescriptor;
+ }
+
+ /**
+ * Returns local node descriptors.
+ *
+ * @return local node descriptors
+ */
+ public NodeDescriptors localNodeDescriptors() {
+ return this.localNodeDescriptors;
+ }
+
+ /**
+ * Returns remote node descriptors.
+ *
+ * @return remote node descriptors
+ */
+ public NodeDescriptors remoteNodeDescriptors() {
+ return this.remoteNodeDescriptors;
+ }
+
+ /**
+ * Returns link descriptors.
+ *
+ * @return link descriptors
+ */
+ public List<BGPValueType> linkDescriptors() {
+ return this.linkDescriptor;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(linkDescriptor, localNodeDescriptors, remoteNodeDescriptors);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof BGPLinkLSIdentifier) {
+ int countObjSubTlv = 0;
+ int countOtherSubTlv = 0;
+ boolean isCommonSubTlv = true;
+ BGPLinkLSIdentifier other = (BGPLinkLSIdentifier) obj;
+ Iterator<BGPValueType> objListIterator = other.linkDescriptor.iterator();
+ countOtherSubTlv = other.linkDescriptor.size();
+ countObjSubTlv = linkDescriptor.size();
+ if (countObjSubTlv != countOtherSubTlv) {
+ return false;
+ } else {
+ while (objListIterator.hasNext() && isCommonSubTlv) {
+ BGPValueType subTlv = objListIterator.next();
+ isCommonSubTlv = Objects.equals(linkDescriptor.contains(subTlv),
+ other.linkDescriptor.contains(subTlv));
+ }
+ return isCommonSubTlv && Objects.equals(this.localNodeDescriptors, other.localNodeDescriptors)
+ && Objects.equals(this.remoteNodeDescriptors, other.remoteNodeDescriptors);
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("localNodeDescriptors", localNodeDescriptors)
+ .add("remoteNodeDescriptors", remoteNodeDescriptors)
+ .add("linkDescriptor", linkDescriptor)
+ .toString();
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSIdentifier.java
index cd2422a7..603bf6ec 100644
--- 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/linkstate/BGPNodeLSIdentifier.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.bgpio.protocol.link_state;
+package org.onosproject.bgpio.protocol.linkstate;
import java.util.Objects;
@@ -110,4 +110,4 @@ public class BGPNodeLSIdentifier {
.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/linkstate/BGPNodeLSNlriVer4.java
index 04780d82..54837ee8 100644
--- 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/linkstate/BGPNodeLSNlriVer4.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.bgpio.protocol.link_state;
+package org.onosproject.bgpio.protocol.linkstate;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
@@ -209,4 +209,4 @@ public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri {
.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/linkstate/BGPPrefixIPv4LSNlriVer4.java
index 0f18c757..6d6f48b1 100644
--- 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/linkstate/BGPPrefixIPv4LSNlriVer4.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.bgpio.protocol.link_state;
+package org.onosproject.bgpio.protocol.linkstate;
import java.util.LinkedList;
@@ -21,7 +21,7 @@ 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.protocol.linkstate.BGPNodeLSNlriVer4.PROTOCOLTYPE;
import org.onosproject.bgpio.types.BGPValueType;
import org.onosproject.bgpio.types.RouteDistinguisher;
import org.onosproject.bgpio.util.Constants;
@@ -202,4 +202,4 @@ public class BGPPrefixIPv4LSNlriVer4 implements BGPPrefixLSNlri {
.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/linkstate/BGPPrefixLSIdentifier.java
index 4fef47ff..23f41794 100644
--- 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/linkstate/BGPPrefixLSIdentifier.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.bgpio.protocol.link_state;
+package org.onosproject.bgpio.protocol.linkstate;
import java.util.Iterator;
import java.util.LinkedList;
@@ -225,4 +225,4 @@ public class BGPPrefixLSIdentifier {
.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/linkstate/NodeDescriptors.java
index a03b2bae..74637c7e 100644
--- 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/linkstate/NodeDescriptors.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.bgpio.protocol.link_state;
+package org.onosproject.bgpio.protocol.linkstate;
import java.util.Iterator;
import java.util.LinkedList;
@@ -222,4 +222,4 @@ public class NodeDescriptors {
.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/linkstate/package-info.java
index d2a2ccf3..87ba60f0 100755
--- 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/linkstate/package-info.java
@@ -17,4 +17,4 @@
/**
* BGP Protocol specific link state details.
*/
-package org.onosproject.bgpio.protocol.link_state; \ No newline at end of file
+package org.onosproject.bgpio.protocol.linkstate;
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java
index b50342d6..fccbf5f7 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java
@@ -311,8 +311,8 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
if (this.isLargeAsCapabilityTlvSet) {
BGPValueType tlv;
- int iValue = this.getAsNumber();
- tlv = new FourOctetAsNumCapabilityTlv(iValue);
+ int value = this.asNumber;
+ tlv = new FourOctetAsNumCapabilityTlv(value);
this.capabilityTlv.add(tlv);
}
@@ -333,26 +333,6 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
}
@Override
- public short getHoldTime() {
- return this.holdTime;
- }
-
- @Override
- public short getAsNumber() {
- return this.asNumber;
- }
-
- @Override
- public int getBgpId() {
- return this.bgpId;
- }
-
- @Override
- public LinkedList<BGPValueType> getCapabilityTlv() {
- return this.capabilityTlv;
- }
-
- @Override
public Builder setHoldTime(short holdTime) {
this.holdTime = holdTime;
this.isHoldTimeSet = true;
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpPathAttributes.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpPathAttributes.java
index 08fea4c6..20a7ba03 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpPathAttributes.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpPathAttributes.java
@@ -28,6 +28,8 @@ import org.onosproject.bgpio.types.LocalPref;
import org.onosproject.bgpio.types.Med;
import org.onosproject.bgpio.types.NextHop;
import org.onosproject.bgpio.types.Origin;
+import org.onosproject.bgpio.types.MpReachNlri;
+import org.onosproject.bgpio.types.MpUnReachNlri;
import org.onosproject.bgpio.util.UnSupportedAttribute;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
@@ -127,11 +129,14 @@ public class BgpPathAttributes {
case LocalPref.LOCAL_PREF_TYPE:
pathAttribute = LocalPref.read(cb);
break;
- case MPREACHNLRI_TYPE:
- //TODO: To be merged later
+ case MpReachNlri.MPREACHNLRI_TYPE:
+ pathAttribute = MpReachNlri.read(cb);
+ isMpReach = ((MpReachNlri) pathAttribute).isMpReachNlriSet();
break;
- case MPUNREACHNLRI_TYPE:
- //TODO: To be merged later
+ case MpUnReachNlri.MPUNREACHNLRI_TYPE:
+ pathAttribute = MpUnReachNlri.read(cb);
+ isMpUnReach = ((MpUnReachNlri) pathAttribute)
+ .isMpUnReachNlriSet();
break;
case LINK_STATE_ATTRIBUTE_TYPE:
//TODO: To be merged later
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java
new file mode 100644
index 00000000..9f4cf9b9
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java
@@ -0,0 +1,285 @@
+/*
+ * 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.ver4;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.IpPrefix;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.protocol.BGPMessageReader;
+import org.onosproject.bgpio.protocol.BGPType;
+import org.onosproject.bgpio.protocol.BgpUpdateMsg;
+import org.onosproject.bgpio.types.BGPErrorType;
+import org.onosproject.bgpio.types.BGPHeader;
+import org.onosproject.bgpio.util.Validation;
+import org.onosproject.bgpio.protocol.BGPVersion;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * BGP Update Message: UPDATE messages are used to transfer routing information
+ * between BGP peers. The information in the UPDATE message is used by core to
+ * construct a graph
+ */
+public class BgpUpdateMsgVer4 implements BgpUpdateMsg {
+
+ /* 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
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | |
+ + +
+ | |
+ + +
+ | Marker |
+ + +
+ | |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Length | Type |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Withdrawn Routes Length (2 octets) |
+ +-----------------------------------------------------+
+ | Withdrawn Routes (variable) |
+ +-----------------------------------------------------+
+ | Total Path Attribute Length (2 octets) |
+ +-----------------------------------------------------+
+ | Path Attributes (variable) |
+ +-----------------------------------------------------+
+ | Network Layer Reachability Information (variable) |
+ +-----------------------------------------------------+
+ REFERENCE : RFC 4271
+ */
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpUpdateMsgVer4.class);
+
+ public static final byte PACKET_VERSION = 4;
+ //Withdrawn Routes Length(2) + Total Path Attribute Length(2)
+ public static final int PACKET_MINIMUM_LENGTH = 4;
+ public static final int BYTE_IN_BITS = 8;
+ public static final int MIN_LEN_AFTER_WITHDRW_ROUTES = 2;
+ public static final int MINIMUM_COMMON_HEADER_LENGTH = 19;
+ public static final BGPType MSG_TYPE = BGPType.UPDATE;
+ public static final BgpUpdateMsgVer4.Reader READER = new Reader();
+
+ private List<IpPrefix> withdrawnRoutes;
+ private BgpPathAttributes bgpPathAttributes;
+ private BGPHeader bgpHeader;
+ private List<IpPrefix> nlri;
+
+ /**
+ * Constructor to initialize parameters for BGP Update message.
+ *
+ * @param bgpHeader in Update message
+ * @param withdrawnRoutes withdrawn routes
+ * @param bgpPathAttributes BGP Path attributes
+ * @param nlri Network Layer Reachability Information
+ */
+ public BgpUpdateMsgVer4(BGPHeader bgpHeader, List<IpPrefix> withdrawnRoutes,
+ BgpPathAttributes bgpPathAttributes, List<IpPrefix> nlri) {
+ this.bgpHeader = bgpHeader;
+ this.withdrawnRoutes = withdrawnRoutes;
+ this.bgpPathAttributes = bgpPathAttributes;
+ this.nlri = nlri;
+ }
+
+ /**
+ * Reader reads BGP Update Message from the channel buffer.
+ */
+ static class Reader implements BGPMessageReader<BgpUpdateMsg> {
+
+ @Override
+ public BgpUpdateMsg readFrom(ChannelBuffer cb, BGPHeader bgpHeader)
+ throws BGPParseException {
+
+ if (cb.readableBytes() != (bgpHeader.getLength() - MINIMUM_COMMON_HEADER_LENGTH)) {
+ Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.BAD_MESSAGE_LENGTH, bgpHeader.getLength());
+ }
+
+ LinkedList<IpPrefix> withDrwRoutes = new LinkedList<>();
+ LinkedList<IpPrefix> nlri = new LinkedList<>();
+ BgpPathAttributes bgpPathAttributes = new BgpPathAttributes();
+ // Reading Withdrawn Routes Length
+ Short withDrwLen = cb.readShort();
+
+ if (cb.readableBytes() < withDrwLen) {
+ Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.MALFORMED_ATTRIBUTE_LIST,
+ cb.readableBytes());
+ }
+ ChannelBuffer tempCb = cb.readBytes(withDrwLen);
+ if (withDrwLen != 0) {
+ // Parsing WithdrawnRoutes
+ withDrwRoutes = parseWithdrawnRoutes(tempCb);
+ }
+ if (cb.readableBytes() < MIN_LEN_AFTER_WITHDRW_ROUTES) {
+ log.debug("Bgp Path Attribute len field not present");
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null);
+ }
+
+ // Reading Total Path Attribute Length
+ short totPathAttrLen = cb.readShort();
+ int len = withDrwLen + totPathAttrLen + PACKET_MINIMUM_LENGTH;
+ if (len > bgpHeader.getLength()) {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null);
+ }
+ if (totPathAttrLen != 0) {
+ // Parsing BGPPathAttributes
+ if (cb.readableBytes() < totPathAttrLen) {
+ Validation
+ .validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.MALFORMED_ATTRIBUTE_LIST,
+ cb.readableBytes());
+ }
+ tempCb = cb.readBytes(totPathAttrLen);
+ bgpPathAttributes = BgpPathAttributes.read(tempCb);
+ }
+ if (cb.readableBytes() > 0) {
+ // Parsing NLRI
+ nlri = parseNlri(cb);
+ }
+ return new BgpUpdateMsgVer4(bgpHeader, withDrwRoutes,
+ bgpPathAttributes, nlri);
+ }
+ }
+
+ /**
+ * Parses NLRI from channel buffer.
+ *
+ * @param cb channelBuffer
+ * @return list of IP Prefix
+ * @throws BGPParseException while parsing NLRI
+ */
+ public static LinkedList<IpPrefix> parseNlri(ChannelBuffer cb)
+ throws BGPParseException {
+ LinkedList<IpPrefix> nlri = new LinkedList<>();
+ while (cb.readableBytes() > 0) {
+ int length = cb.readByte();
+ IpPrefix ipPrefix;
+ if (length == 0) {
+ byte[] prefix = new byte[] {0};
+ ipPrefix = Validation.bytesToPrefix(prefix, length);
+ nlri.add(ipPrefix);
+ } else {
+ int len = length / BYTE_IN_BITS;
+ int reminder = length % BYTE_IN_BITS;
+ if (reminder > 0) {
+ len = len + 1;
+ }
+ if (cb.readableBytes() < len) {
+ Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.MALFORMED_ATTRIBUTE_LIST,
+ cb.readableBytes());
+ }
+ byte[] prefix = new byte[len];
+ cb.readBytes(prefix, 0, len);
+ ipPrefix = Validation.bytesToPrefix(prefix, length);
+ nlri.add(ipPrefix);
+ }
+ }
+ return nlri;
+ }
+
+ /**
+ * Parsing withdrawn routes from channel buffer.
+ *
+ * @param cb channelBuffer
+ * @return list of IP prefix
+ * @throws BGPParseException while parsing withdrawn routes
+ */
+ public static LinkedList<IpPrefix> parseWithdrawnRoutes(ChannelBuffer cb)
+ throws BGPParseException {
+ LinkedList<IpPrefix> withDrwRoutes = new LinkedList<>();
+ while (cb.readableBytes() > 0) {
+ int length = cb.readByte();
+ IpPrefix ipPrefix;
+ if (length == 0) {
+ byte[] prefix = new byte[] {0};
+ ipPrefix = Validation.bytesToPrefix(prefix, length);
+ withDrwRoutes.add(ipPrefix);
+ } else {
+ int len = length / BYTE_IN_BITS;
+ int reminder = length % BYTE_IN_BITS;
+ if (reminder > 0) {
+ len = len + 1;
+ }
+ if (cb.readableBytes() < len) {
+ Validation
+ .validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.MALFORMED_ATTRIBUTE_LIST,
+ cb.readableBytes());
+ }
+ byte[] prefix = new byte[len];
+ cb.readBytes(prefix, 0, len);
+ ipPrefix = Validation.bytesToPrefix(prefix, length);
+ withDrwRoutes.add(ipPrefix);
+ }
+ }
+ return withDrwRoutes;
+ }
+
+ @Override
+ public BGPVersion getVersion() {
+ return BGPVersion.BGP_4;
+ }
+
+ @Override
+ public BGPType getType() {
+ return BGPType.UPDATE;
+ }
+
+ @Override
+ public void writeTo(ChannelBuffer channelBuffer) throws BGPParseException {
+ //Not to be implemented as of now
+ }
+
+ @Override
+ public BgpPathAttributes bgpPathAttributes() {
+ return this.bgpPathAttributes;
+ }
+
+ @Override
+ public List<IpPrefix> withdrawnRoutes() {
+ return withdrawnRoutes;
+ }
+
+ @Override
+ public List<IpPrefix> nlri() {
+ return nlri;
+ }
+
+ @Override
+ public BGPHeader getHeader() {
+ return this.bgpHeader;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("bgpHeader", bgpHeader)
+ .add("withDrawnRoutes", withdrawnRoutes)
+ .add("nlri", nlri)
+ .add("bgpPathAttributes", bgpPathAttributes)
+ .toString();
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java
index 90e94e88..e9df3999 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java
@@ -21,6 +21,7 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,8 +35,6 @@ public class As4Path implements BGPValueType {
private static final Logger log = LoggerFactory.getLogger(AsPath.class);
public static final byte AS4PATH_TYPE = 17;
public static final byte ASNUM_SIZE = 4;
- public static final int TYPE_AND_LEN_AS_SHORT = 4;
- public static final int TYPE_AND_LEN_AS_BYTE = 3;
private List<Integer> as4pathSet;
private List<Integer> as4pathSeq;
@@ -77,8 +76,8 @@ public class As4Path implements BGPValueType {
validation.getLength());
}
//if fourth bit is set length is read as short otherwise as byte , len includes type, length and value
- int len = validation.isShort() ? validation.getLength() + TYPE_AND_LEN_AS_SHORT : validation
- .getLength() + TYPE_AND_LEN_AS_BYTE;
+ int len = validation.isShort() ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : validation
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
index 100e14d7..e3eb2c51 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
@@ -22,6 +22,7 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -53,7 +54,7 @@ public class AsPath implements BGPValueType {
*
* @return AS type
*/
- public byte getType() {
+ public byte type() {
return (byte) value;
}
}
@@ -63,8 +64,6 @@ public class AsPath implements BGPValueType {
public static final byte ASPATH_SET_TYPE = 1;
public static final byte ASPATH_SEQ_TYPE = 2;
public static final byte ASNUM_SIZE = 2;
- public static final int TYPE_AND_LEN_AS_SHORT = 4;
- public static final int TYPE_AND_LEN_AS_BYTE = 3;
private boolean isAsPath = false;
private List<Short> aspathSet;
@@ -108,8 +107,8 @@ public class AsPath implements BGPValueType {
validation.getLength());
}
//if fourth bit is set, length is read as short otherwise as byte , len includes type, length and value
- int len = validation.isShort() ? validation.getLength() + TYPE_AND_LEN_AS_SHORT : validation
- .getLength() + TYPE_AND_LEN_AS_BYTE;
+ int len = validation.isShort() ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : validation
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java
index f643ae00..dfcfc9dc 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java
@@ -28,8 +28,8 @@ public final class BGPErrorType {
public static final byte OPEN_MESSAGE_ERROR = 2;
public static final byte UPDATE_MESSAGE_ERROR = 3;
public static final byte HOLD_TIMER_EXPIRED = 4;
- public static final byte FINITE_STATE_MACHINE_ERROR = 4;
- public static final byte CEASE = 5;
+ public static final byte FINITE_STATE_MACHINE_ERROR = 5;
+ public static final byte CEASE = 6;
//Message Header Error subcodes
public static final byte CONNECTION_NOT_SYNCHRONIZED = 1;
@@ -42,6 +42,7 @@ public final class BGPErrorType {
public static final byte BAD_BGP_IDENTIFIER = 3;
public static final byte UNSUPPORTED_OPTIONAL_PARAMETER = 4;
public static final byte UNACCEPTABLE_HOLD_TIME = 5;
+ public static final byte UNSUPPORTED_CAPABILITY = 7;
//UPDATE Message Error subcodes
public static final byte MALFORMED_ATTRIBUTE_LIST = 1;
@@ -54,4 +55,20 @@ public final class BGPErrorType {
public static final byte OPTIONAL_ATTRIBUTE_ERROR = 9;
public static final byte INVALID_NETWORK_FIELD = 10;
public static final byte MALFORMED_ASPATH = 11;
+
+ //FSM Error subcodes
+ public static final byte UNSPECIFIED_ERROR = 0;
+ public static final byte RECEIVE_UNEXPECTED_MESSAGE_IN_OPENSENT_STATE = 1;
+ public static final byte RECEIVE_UNEXPECTED_MESSAGE_IN_OPENCONFIRM_STATE = 2;
+ public static final byte RECEIVE_UNEXPECTED_MESSAGE_IN_ESTABLISHED_STATE = 3;
+
+ //Cease Error subcodes
+ public static final byte MAXIMUM_NUMBER_OF_PREFIXES_REACHED = 1;
+ public static final byte ADMINISTRATIVE_SHUTDOWN = 2;
+ public static final byte PEER_DECONFIGURED = 3;
+ public static final byte ADMINISTRATIVE_RESET = 4;
+ public static final byte CONNECTION_REJECTED = 5;
+ public static final byte OTHER_CONFIGURATION_CHANGE = 6;
+ public static final byte CONNECTION_COLLISION_RESOLUTION = 7;
+ public static final byte OUT_OF_RESOURCES = 8;
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java
index 85fb748b..59afbed6 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.bgpio.types;
+import java.util.Arrays;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
@@ -86,7 +87,7 @@ public class IPReachabilityInformationTlv implements BGPValueType {
@Override
public int hashCode() {
- return Objects.hash(ipPrefix, prefixLen);
+ return Objects.hash(Arrays.hashCode(ipPrefix), prefixLen);
}
@Override
@@ -97,7 +98,7 @@ public class IPReachabilityInformationTlv implements BGPValueType {
if (obj instanceof IPReachabilityInformationTlv) {
IPReachabilityInformationTlv other = (IPReachabilityInformationTlv) obj;
- return Objects.equals(prefixLen, other.prefixLen) && Objects.equals(ipPrefix, other.ipPrefix);
+ return Objects.equals(prefixLen, other.prefixLen) && Arrays.equals(ipPrefix, other.ipPrefix);
}
return false;
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java
new file mode 100644
index 00000000..d5f03268
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java
@@ -0,0 +1,128 @@
+/*
+ * 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;
+
+import java.net.InetAddress;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+
+/**
+ * Provides Implementation of IPv4AddressTlv.
+ */
+public class IPv4AddressTlv implements BGPValueType {
+ private static final Logger log = LoggerFactory.getLogger(IPv4AddressTlv.class);
+ private static final int LENGTH = 4;
+
+ private Ip4Address address;
+ private short type;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param address Ipv4 address of interface/neighbor
+ * @param type address type
+ */
+ public IPv4AddressTlv(Ip4Address address, short type) {
+ this.address = Preconditions.checkNotNull(address);
+ this.type = type;
+ }
+
+ /**
+ * Returns Ipv4 address of interface/neighbor.
+ *
+ * @return Ipv4 address of interface/neighbor
+ */
+ public Ip4Address getValue() {
+ return address;
+ }
+
+ @Override
+ public short getType() {
+ return this.type;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(address);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof IPv4AddressTlv) {
+ IPv4AddressTlv other = (IPv4AddressTlv) obj;
+ return Objects.equals(this.address, other.address) && Objects.equals(this.type, other.type);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ int iLenStartIndex = cb.writerIndex();
+ cb.writeShort(type);
+ cb.writeShort(LENGTH);
+ cb.writeInt(address.toInt());
+ return cb.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of IPv4AddressTlv.
+ *
+ * @param cb channelBuffer
+ * @param type address type
+ * @return object of IPv4AddressTlv
+ * @throws BGPParseException while parsing IPv4AddressTlv
+ */
+ public static IPv4AddressTlv read(ChannelBuffer cb, short type) throws BGPParseException {
+ //TODO: use Validation.toInetAddress once Validation is merged
+ InetAddress ipAddress = (InetAddress) cb.readBytes(LENGTH);
+ if (ipAddress.isMulticastAddress()) {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
+ }
+ Ip4Address address = Ip4Address.valueOf(ipAddress);
+ return IPv4AddressTlv.of(address, type);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param address Ipv4 interface/neighbor Address
+ * @param type says Ipv4 address of interface/neighbor tlv type
+ * @return object of this class
+ */
+ public static IPv4AddressTlv of(final Ip4Address address , final short type) {
+ return new IPv4AddressTlv(address, type);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("type", type)
+ .add("LENGTH", LENGTH)
+ .add("address", address)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java
new file mode 100644
index 00000000..65b7c16d
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java
@@ -0,0 +1,128 @@
+/*
+ * 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;
+
+import java.net.InetAddress;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip6Address;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+
+/**
+ * Provides Implementation of IPv6AddressTlv.
+ */
+public class IPv6AddressTlv implements BGPValueType {
+ private static final Logger log = LoggerFactory.getLogger(IPv6AddressTlv.class);
+ private static final int LENGTH = 16;
+
+ private final Ip6Address address;
+ private short type;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param address Ipv6 address of interface/neighbor
+ * @param type address type
+ */
+ public IPv6AddressTlv(Ip6Address address, short type) {
+ this.address = Preconditions.checkNotNull(address);
+ this.type = type;
+ }
+
+ /**
+ * Returns Ipv6 address of interface/neighbor.
+ *
+ * @return Ipv6 address of interface/neighbor
+ */
+ public Ip6Address getValue() {
+ return address;
+ }
+
+ @Override
+ public short getType() {
+ return type;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(address);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof IPv6AddressTlv) {
+ IPv6AddressTlv other = (IPv6AddressTlv) obj;
+ return Objects.equals(this.address, other.address) && Objects.equals(this.type, other.type);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ int iLenStartIndex = cb.writerIndex();
+ cb.writeShort(type);
+ cb.writeShort(LENGTH);
+ cb.writeBytes(address.toOctets());
+ return cb.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of IPv6AddressTlv.
+ *
+ * @param cb channelBuffer
+ * @param type address type
+ * @return object of IPv6AddressTlv
+ * @throws BGPParseException while parsing IPv6AddressTlv
+ */
+ public static IPv6AddressTlv read(ChannelBuffer cb, short type) throws BGPParseException {
+ //TODO: use Validation.toInetAddress once Validation is merged
+ InetAddress ipAddress = (InetAddress) cb.readBytes(LENGTH);
+ if (ipAddress.isMulticastAddress()) {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
+ }
+ Ip6Address address = Ip6Address.valueOf(ipAddress);
+ return IPv6AddressTlv.of(address, type);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param address Ipv6 interface/neighbor address
+ * @param type says Ipv6 address of interface/neighbor tlv type
+ * @return object of this class
+ */
+ public static IPv6AddressTlv of(final Ip6Address address , final short type) {
+ return new IPv6AddressTlv(address, type);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("type", type)
+ .add("LENGTH", LENGTH)
+ .add("address", address)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java
index 5c742d0f..35fd2493 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java
@@ -15,6 +15,9 @@
*/
package org.onosproject.bgpio.types;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
@@ -28,12 +31,12 @@ import com.google.common.base.MoreObjects;
* Provides implementation of IsIsPseudonode Tlv.
*/
public class IsIsPseudonode implements IGPRouterID, BGPValueType {
- protected static final Logger log = LoggerFactory.getLogger(IsIsPseudonode.class);
+ private static final Logger log = LoggerFactory.getLogger(IsIsPseudonode.class);
public static final short TYPE = 515;
public static final short LENGTH = 7;
- private final byte[] isoNodeID;
+ private final List<Byte> isoNodeID;
private byte psnIdentifier;
/**
@@ -42,7 +45,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
* @param isoNodeID ISO system-ID
* @param psnIdentifier PSN identifier
*/
- public IsIsPseudonode(byte[] isoNodeID, byte psnIdentifier) {
+ public IsIsPseudonode(List<Byte> isoNodeID, byte psnIdentifier) {
this.isoNodeID = isoNodeID;
this.psnIdentifier = psnIdentifier;
}
@@ -54,7 +57,8 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
* @param psnIdentifier PSN identifier
* @return object of IsIsPseudonode
*/
- public static IsIsPseudonode of(final byte[] isoNodeID, final byte psnIdentifier) {
+ public static IsIsPseudonode of(final List<Byte> isoNodeID,
+ final byte psnIdentifier) {
return new IsIsPseudonode(isoNodeID, psnIdentifier);
}
@@ -63,7 +67,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
*
* @return ISO NodeID
*/
- public byte[] getISONodeID() {
+ public List<Byte> getISONodeID() {
return isoNodeID;
}
@@ -78,7 +82,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
@Override
public int hashCode() {
- return Objects.hash(isoNodeID, psnIdentifier);
+ return Objects.hash(isoNodeID) & Objects.hash(psnIdentifier);
}
@Override
@@ -87,8 +91,27 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
return true;
}
if (obj instanceof IsIsPseudonode) {
+ int countObjSubTlv = 0;
+ int countOtherSubTlv = 0;
+ boolean isCommonSubTlv = true;
IsIsPseudonode other = (IsIsPseudonode) obj;
- return Objects.equals(isoNodeID, other.isoNodeID) && Objects.equals(psnIdentifier, other.psnIdentifier);
+ Iterator<Byte> objListIterator = other.isoNodeID.iterator();
+ countOtherSubTlv = other.isoNodeID.size();
+ countObjSubTlv = isoNodeID.size();
+ if (countObjSubTlv != countOtherSubTlv) {
+ return false;
+ } else {
+ while (objListIterator.hasNext() && isCommonSubTlv) {
+ Byte subTlv = objListIterator.next();
+ if (isoNodeID.contains(subTlv) && other.isoNodeID.contains(subTlv)) {
+ isCommonSubTlv = Objects.equals(isoNodeID.get(isoNodeID.indexOf(subTlv)),
+ other.isoNodeID.get(other.isoNodeID.indexOf(subTlv)));
+ } else {
+ isCommonSubTlv = false;
+ }
+ }
+ return isCommonSubTlv && Objects.equals(psnIdentifier, other.psnIdentifier);
+ }
}
return false;
}
@@ -98,7 +121,11 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
- c.writeBytes(isoNodeID);
+ Iterator<Byte> objListIterator = isoNodeID.iterator();
+ while (objListIterator.hasNext()) {
+ byte value = objListIterator.next();
+ c.writeByte(value);
+ }
c.writeByte(psnIdentifier);
return c.writerIndex() - iLenStartIndex;
}
@@ -110,8 +137,12 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
* @return object of IsIsPseudonode
*/
public static IsIsPseudonode read(ChannelBuffer cb) {
- byte[] isoNodeID = new byte[LENGTH - 1];
- cb.readBytes(isoNodeID, 0, LENGTH - 1);
+ List<Byte> isoNodeID = new ArrayList<Byte>();
+ byte value;
+ for (int i = 0; i < LENGTH; i++) {
+ value = cb.readByte();
+ isoNodeID.add(value);
+ }
byte psnIdentifier = cb.readByte();
return IsIsPseudonode.of(isoNodeID, psnIdentifier);
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java
new file mode 100644
index 00000000..988925f5
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java
@@ -0,0 +1,131 @@
+/*
+ * 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;
+
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides Implementation of Link Local/Remote IdentifiersTlv.
+ */
+public class LinkLocalRemoteIdentifiersTlv implements BGPValueType {
+ private static final Logger log = LoggerFactory.getLogger(LinkLocalRemoteIdentifiersTlv.class);
+ public static final short TYPE = 258;
+ private static final int LENGTH = 8;
+
+ private final int linkLocalIdentifer;
+ private final int linkRemoteIdentifer;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param linkLocalIdentifer link local Identifer
+ * @param linkRemoteIdentifer link remote Identifer
+ */
+ public LinkLocalRemoteIdentifiersTlv(int linkLocalIdentifer, int linkRemoteIdentifer) {
+ this.linkLocalIdentifer = linkLocalIdentifer;
+ this.linkRemoteIdentifer = linkRemoteIdentifer;
+ }
+
+ /**
+ * Returns link remote Identifer.
+ *
+ * @return link remote Identifer
+ */
+ public int getLinkRemoteIdentifier() {
+ return linkRemoteIdentifer;
+ }
+
+ /**
+ * Returns link local Identifer.
+ *
+ * @return link local Identifer
+ */
+ public int getLinkLocalIdentifier() {
+ return linkLocalIdentifer;
+ }
+
+ @Override
+ public short getType() {
+ return TYPE;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(linkLocalIdentifer, linkRemoteIdentifer);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof LinkLocalRemoteIdentifiersTlv) {
+ LinkLocalRemoteIdentifiersTlv other = (LinkLocalRemoteIdentifiersTlv) obj;
+ return Objects.equals(this.linkLocalIdentifer, other.linkLocalIdentifer)
+ && Objects.equals(this.linkRemoteIdentifer, other.linkRemoteIdentifer);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ int iLenStartIndex = cb.writerIndex();
+ cb.writeShort(TYPE);
+ cb.writeShort(LENGTH);
+ cb.writeInt(linkLocalIdentifer);
+ cb.writeInt(linkRemoteIdentifer);
+ return cb.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of LinkLocalRemoteIdentifiersTlv.
+ *
+ * @param cb channelBuffer
+ * @return object of LinkLocalRemoteIdentifiersTlv
+ */
+ public static LinkLocalRemoteIdentifiersTlv read(ChannelBuffer cb) {
+ int linkLocalIdentifer = cb.readInt();
+ int linkRemoteIdentifer = cb.readInt();
+ return LinkLocalRemoteIdentifiersTlv.of(linkLocalIdentifer, linkRemoteIdentifer);
+ }
+
+ /**
+ * Returns object of this class with specified link local identifer and link remote identifer.
+ *
+ * @param linkLocalIdentifer link local identifier
+ * @param linkRemoteIdentifer link remote identifier
+ * @return object of LinkLocalRemoteIdentifiersTlv
+ */
+ public static LinkLocalRemoteIdentifiersTlv of(final int linkLocalIdentifer, final int linkRemoteIdentifer) {
+ return new LinkLocalRemoteIdentifiersTlv(linkLocalIdentifer, linkRemoteIdentifer);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("TYPE", TYPE)
+ .add("LENGTH", LENGTH)
+ .add("linkLocalIdentifer", linkLocalIdentifer)
+ .add("linkRemoteIdentifer", linkRemoteIdentifer)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java
index 048d81ee..0f78ab77 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java
@@ -19,9 +19,8 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
@@ -29,11 +28,7 @@ import com.google.common.base.MoreObjects;
* Provides implementation of LocalPref BGP Path Attribute.
*/
public class LocalPref implements BGPValueType {
-
- private static final Logger log = LoggerFactory.getLogger(LocalPref.class);
public static final byte LOCAL_PREF_TYPE = 5;
- public static final int TYPE_AND_LEN_AS_SHORT = 4;
- public static final int TYPE_AND_LEN_AS_BYTE = 3;
public static final byte LOCAL_PREF_MAX_LEN = 4;
private int localPref;
@@ -72,8 +67,8 @@ public class LocalPref implements BGPValueType {
parseFlags.getLength());
}
- int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags.getLength()
- + TYPE_AND_LEN_AS_BYTE;
+ int len = parseFlags.isShort() ? parseFlags.getLength() +
+ Constants.TYPE_AND_LEN_AS_SHORT : parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (parseFlags.getFirstBit()) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java
index 49e1fc5a..23402c26 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java
@@ -19,9 +19,8 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
@@ -29,10 +28,7 @@ import com.google.common.base.MoreObjects;
* Provides Implementation of Med BGP Path Attribute.
*/
public class Med implements BGPValueType {
- private static final Logger log = LoggerFactory.getLogger(Med.class);
public static final byte MED_TYPE = 4;
- public static final int TYPE_AND_LEN_AS_SHORT = 4;
- public static final int TYPE_AND_LEN_AS_BYTE = 3;
public static final byte MED_MAX_LEN = 4;
private int med;
@@ -71,8 +67,8 @@ public class Med implements BGPValueType {
Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
parseFlags.getLength());
}
- int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags
- .getLength() + TYPE_AND_LEN_AS_BYTE;
+ int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java
new file mode 100644
index 00000000..fe99d28d
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java
@@ -0,0 +1,219 @@
+/*
+ * 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;
+
+import java.net.InetAddress;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.protocol.BGPLSNlri;
+import org.onosproject.bgpio.protocol.linkstate.BGPPrefixIPv4LSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
+import org.onosproject.bgpio.util.Constants;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/*
+ * Provides Implementation of MpReach Nlri BGP Path Attribute.
+ */
+public class MpReachNlri implements BGPValueType {
+
+ private static final Logger log = LoggerFactory.getLogger(MpReachNlri.class);
+ public static final byte MPREACHNLRI_TYPE = 14;
+ public static final byte LINK_NLRITYPE = 2;
+
+ private boolean isMpReachNlri = false;
+ private final List<BGPLSNlri> mpReachNlri;
+ private final int length;
+ private final short afi;
+ private final byte safi;
+ private final Ip4Address ipNextHop;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param mpReachNlri MpReach Nlri attribute
+ * @param afi address family identifier
+ * @param safi subsequent address family identifier
+ * @param ipNextHop nexthop IpAddress
+ * @param length of MpReachNlri
+ */
+ public MpReachNlri(List<BGPLSNlri> mpReachNlri, short afi, byte safi, Ip4Address ipNextHop, int length) {
+ this.mpReachNlri = mpReachNlri;
+ this.isMpReachNlri = true;
+ this.ipNextHop = ipNextHop;
+ this.afi = afi;
+ this.safi = safi;
+ this.length = length;
+ }
+
+ /**
+ * Returns whether MpReachNlri is present.
+ *
+ * @return whether MpReachNlri is present
+ */
+ public boolean isMpReachNlriSet() {
+ return this.isMpReachNlri;
+ }
+
+ /**
+ * Returns list of MpReach Nlri.
+ *
+ * @return list of MpReach Nlri
+ */
+ public List<BGPLSNlri> mpReachNlri() {
+ return this.mpReachNlri;
+ }
+
+ /**
+ * Returns length of MpReachNlri.
+ *
+ * @return length of MpReachNlri
+ */
+ public int mpReachNlriLen() {
+ return this.length;
+ }
+
+ /**
+ * Reads from ChannelBuffer and parses MpReachNlri.
+ *
+ * @param cb channelBuffer
+ * @return object of MpReachNlri
+ * @throws BGPParseException while parsing MpReachNlri
+ */
+ public static MpReachNlri read(ChannelBuffer cb) throws BGPParseException {
+ ChannelBuffer tempBuf = cb.copy();
+ Validation parseFlags = Validation.parseAttributeHeader(cb);
+ int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT :
+ parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
+ ChannelBuffer data = tempBuf.readBytes(len);
+
+ if (cb.readableBytes() < parseFlags.getLength()) {
+ Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ parseFlags.getLength());
+ }
+ if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ }
+
+ BGPLSNlri bgpLSNlri = null;
+ List<BGPLSNlri> mpReachNlri = new LinkedList<>();
+ ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength());
+ short afi = 0;
+ byte safi = 0;
+ Ip4Address ipNextHop = null;
+ while (tempCb.readableBytes() > 0) {
+ afi = tempCb.readShort();
+ safi = tempCb.readByte();
+
+ //Supporting for AFI 16388 / SAFI 71 and VPN AFI 16388 / SAFI 128
+ if ((afi == Constants.AFI_VALUE) && (safi == Constants.SAFI_VALUE) || (afi == Constants.AFI_VALUE)
+ && (safi == Constants.VPN_SAFI_VALUE)) {
+ byte nextHopLen = tempCb.readByte();
+ InetAddress ipAddress = Validation.toInetAddress(nextHopLen, cb);
+ if (ipAddress.isMulticastAddress()) {
+ throw new BGPParseException("Multicast not supported");
+ }
+ ipNextHop = Ip4Address.valueOf(ipAddress);
+ byte reserved = tempCb.readByte();
+
+ while (tempCb.readableBytes() > 0) {
+ short nlriType = tempCb.readShort();
+ short totNlriLen = tempCb.readShort();
+ if (tempCb.readableBytes() < totNlriLen) {
+ Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
+ }
+ tempBuf = tempCb.readBytes(totNlriLen);
+ switch (nlriType) {
+ case BGPNodeLSNlriVer4.NODE_NLRITYPE:
+ bgpLSNlri = BGPNodeLSNlriVer4.read(tempBuf, afi, safi);
+ break;
+ case BgpLinkLsNlriVer4.LINK_NLRITYPE:
+ bgpLSNlri = BgpLinkLsNlriVer4.read(tempBuf, afi, safi);
+ break;
+ case BGPPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE:
+ bgpLSNlri = BGPPrefixIPv4LSNlriVer4.read(tempBuf, afi, safi);
+ break;
+ default:
+ log.debug("nlriType not supported" + nlriType);
+ }
+ mpReachNlri.add(bgpLSNlri);
+ }
+ } else {
+ throw new BGPParseException("Not Supporting afi " + afi + "safi " + safi);
+ }
+ }
+ return new MpReachNlri(mpReachNlri, afi, safi, ipNextHop, parseFlags.getLength());
+ }
+
+ @Override
+ public short getType() {
+ return MPREACHNLRI_TYPE;
+ }
+
+ /**
+ * Returns AFI.
+ *
+ * @return AFI
+ */
+ public short afi() {
+ return this.afi;
+ }
+
+ /**
+ * Returns Nexthop IpAddress.
+ *
+ * @return Nexthop IpAddress
+ */
+ public Ip4Address nexthop4() {
+ return this.ipNextHop;
+ }
+
+ /**
+ * Returns SAFI.
+ *
+ * @return SAFI
+ */
+ public byte safi() {
+ return this.safi;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ //Not to be Implemented as of now
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("mpReachNlri", mpReachNlri)
+ .add("afi", afi)
+ .add("safi", safi)
+ .add("ipNextHop", ipNextHop)
+ .add("length", length)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
new file mode 100644
index 00000000..8763ec59
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
@@ -0,0 +1,204 @@
+/*
+ * 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;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.protocol.BGPLSNlri;
+import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BGPPrefixIPv4LSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
+import org.onosproject.bgpio.util.Constants;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides Implementation of MpUnReach Nlri BGP Path Attribute.
+ */
+public class MpUnReachNlri implements BGPValueType {
+
+ private static final Logger log = LoggerFactory.getLogger(MpUnReachNlri.class);
+ public static final byte MPUNREACHNLRI_TYPE = 15;
+ public static final byte LINK_NLRITYPE = 2;
+
+ private boolean isMpUnReachNlri = false;
+ private final short afi;
+ private final byte safi;
+ private final List<BGPLSNlri> mpUnReachNlri;
+ private final int length;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param mpUnReachNlri MpUnReach Nlri attribute
+ * @param afi address family identifier
+ * @param safi subsequent address family identifier
+ * @param length of MpUnReachNlri
+ */
+ public MpUnReachNlri(List<BGPLSNlri> mpUnReachNlri, short afi, byte safi,
+ int length) {
+ this.mpUnReachNlri = mpUnReachNlri;
+ this.isMpUnReachNlri = true;
+ this.afi = afi;
+ this.safi = safi;
+ this.length = length;
+ }
+
+ /**
+ * Reads from ChannelBuffer and parses MpUnReachNlri.
+ *
+ * @param cb ChannelBuffer
+ * @return object of MpUnReachNlri
+ * @throws BGPParseException while parsing MpUnReachNlri
+ */
+ public static MpUnReachNlri read(ChannelBuffer cb) throws BGPParseException {
+ ChannelBuffer tempBuf = cb.copy();
+ Validation parseFlags = Validation.parseAttributeHeader(cb);
+ int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT
+ : parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
+ ChannelBuffer data = tempBuf.readBytes(len);
+
+ if (!parseFlags.getFirstBit() && parseFlags.getSecondBit()
+ && parseFlags.getThirdBit()) {
+ throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ }
+
+ if (cb.readableBytes() < parseFlags.getLength()) {
+ Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.ATTRIBUTE_LENGTH_ERROR, parseFlags.getLength());
+ }
+
+ LinkedList<BGPLSNlri> mpUnReachNlri = new LinkedList<>();
+ BGPLSNlri bgpLSNlri = null;
+ short afi = 0;
+ byte safi = 0;
+ ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength());
+ while (tempCb.readableBytes() > 0) {
+ afi = tempCb.readShort();
+ safi = tempCb.readByte();
+
+ //Supporting only for AFI 16388 / SAFI 71
+ if ((afi == Constants.AFI_VALUE) && (safi == Constants.SAFI_VALUE)
+ || (afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) {
+ while (tempCb.readableBytes() > 0) {
+ short nlriType = tempCb.readShort();
+ short totNlriLen = tempCb.readShort();
+ if (tempCb.readableBytes() < totNlriLen) {
+ Validation.validateLen(
+ BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
+ }
+ tempBuf = tempCb.readBytes(totNlriLen);
+ switch (nlriType) {
+ case BGPNodeLSNlriVer4.NODE_NLRITYPE:
+ bgpLSNlri = BGPNodeLSNlriVer4.read(tempBuf, afi, safi);
+ break;
+ case BgpLinkLsNlriVer4.LINK_NLRITYPE:
+ bgpLSNlri = BgpLinkLsNlriVer4.read(tempBuf, afi, safi);
+ break;
+ case BGPPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE:
+ bgpLSNlri = BGPPrefixIPv4LSNlriVer4.read(tempBuf, afi,
+ safi);
+ break;
+ default:
+ log.debug("nlriType not supported" + nlriType);
+ }
+ mpUnReachNlri.add(bgpLSNlri);
+ }
+ } else {
+ //TODO: check with the values got from capability
+ throw new BGPParseException("Not Supporting afi " + afi
+ + "safi " + safi);
+ }
+ }
+ return new MpUnReachNlri(mpUnReachNlri, afi, safi,
+ parseFlags.getLength());
+ }
+
+ @Override
+ public short getType() {
+ return MPUNREACHNLRI_TYPE;
+ }
+
+ /**
+ * Returns SAFI.
+ *
+ * @return SAFI
+ */
+ public byte safi() {
+ return this.safi;
+ }
+
+ /**
+ * Returns AFI.
+ *
+ * @return AFI
+ */
+ public short afi() {
+ return this.afi;
+ }
+
+ /**
+ * Returns list of MpUnReach Nlri.
+ *
+ * @return list of MpUnReach Nlri
+ */
+ public List<BGPLSNlri> mpUnReachNlri() {
+ return this.mpUnReachNlri;
+ }
+
+ /**
+ * Returns whether MpReachNlri is present.
+ *
+ * @return whether MpReachNlri is present
+ */
+ public boolean isMpUnReachNlriSet() {
+ return this.isMpUnReachNlri;
+ }
+
+ /**
+ * Returns length of MpUnReach.
+ *
+ * @return length of MpUnReach
+ */
+ public int mpUnReachNlriLen() {
+ return this.length;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ //Not to be Implemented as of now
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("mpReachNlri", mpUnReachNlri)
+ .add("afi", afi)
+ .add("safi", safi)
+ .add("length", length)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java
index 353ec3d5..1d083b72 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java
@@ -21,9 +21,8 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
@@ -32,10 +31,7 @@ import com.google.common.base.Preconditions;
* Implementation of NextHop BGP Path Attribute.
*/
public class NextHop implements BGPValueType {
- private static final Logger log = LoggerFactory.getLogger(NextHop.class);
public static final byte NEXTHOP_TYPE = 3;
- public static final int TYPE_AND_LEN_AS_SHORT = 4;
- public static final int TYPE_AND_LEN_AS_BYTE = 3;
private boolean isNextHop = false;
private Ip4Address nextHop;
@@ -75,15 +71,14 @@ public class NextHop implements BGPValueType {
Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
parseFlags.getLength());
}
- int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags
- .getLength() + TYPE_AND_LEN_AS_BYTE;
+ int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
}
- //TODO: use Validation.toInetAddress once Validation is merged
- InetAddress ipAddress = (InetAddress) cb.readBytes(parseFlags.getLength());
+ InetAddress ipAddress = Validation.toInetAddress(parseFlags.getLength(), cb);
if (ipAddress.isMulticastAddress()) {
throw new BGPParseException("Multicast address is not supported");
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java
index 3b2070de..2052e965 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java
@@ -19,9 +19,8 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
@@ -29,7 +28,6 @@ import com.google.common.base.MoreObjects;
* Provides Implementation of mandatory BGP Origin path attribute.
*/
public class Origin implements BGPValueType {
- private static final Logger log = LoggerFactory.getLogger(Origin.class);
/**
* Enum to provide ORIGIN types.
@@ -58,8 +56,6 @@ public class Origin implements BGPValueType {
public static final byte ORIGIN_TYPE = 1;
public static final byte ORIGIN_VALUE_LEN = 1;
- public static final int TYPE_AND_LEN_AS_SHORT = 4;
- public static final int TYPE_AND_LEN_AS_BYTE = 3;
private boolean isOrigin = false;
private byte origin;
@@ -109,8 +105,8 @@ public class Origin implements BGPValueType {
ChannelBuffer tempCb = cb.copy();
Validation parseFlags = Validation.parseAttributeHeader(cb);
- int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags
- .getLength() + TYPE_AND_LEN_AS_BYTE;
+ int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if ((parseFlags.getLength() > ORIGIN_VALUE_LEN) || (cb.readableBytes() < parseFlags.getLength())) {
Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
@@ -122,7 +118,7 @@ public class Origin implements BGPValueType {
byte originValue;
originValue = cb.readByte();
- if ((originValue != ORIGINTYPE.INCOMPLETE.value) || (originValue != ORIGINTYPE.IGP.value) ||
+ if ((originValue != ORIGINTYPE.INCOMPLETE.value) && (originValue != ORIGINTYPE.IGP.value) &&
(originValue != ORIGINTYPE.EGP.value)) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.INVALID_ORIGIN_ATTRIBUTE, data);
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java
index 194d6dac..4b704fb0 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.onosproject.bgpio.types.attr;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
@@ -39,18 +40,28 @@ public class BgpAttrNodeMultiTopologyId implements BGPValueType {
public static final int ATTRNODE_MULTITOPOLOGY = 263;
/* Opaque Node Attribute */
- private short[] multiTopologyId;
+ private List<Short> multiTopologyId = new ArrayList<Short>();
/**
* Constructor to initialize the Node attribute multi-topology ID.
*
* @param multiTopologyId multi-topology ID
*/
- BgpAttrNodeMultiTopologyId(short[] multiTopologyId) {
+ public BgpAttrNodeMultiTopologyId(List<Short> multiTopologyId) {
this.multiTopologyId = multiTopologyId;
}
/**
+ * Returns object of this class with specified values.
+ *
+ * @param multiTopologyId Prefix Metric
+ * @return object of BgpAttrNodeMultiTopologyId
+ */
+ public static BgpAttrNodeMultiTopologyId of(ArrayList<Short> multiTopologyId) {
+ return new BgpAttrNodeMultiTopologyId(multiTopologyId);
+ }
+
+ /**
* Reads the Multi-topology ID of Node attribute.
*
* @param cb ChannelBuffer
@@ -59,21 +70,20 @@ public class BgpAttrNodeMultiTopologyId implements BGPValueType {
*/
public static BgpAttrNodeMultiTopologyId read(ChannelBuffer cb)
throws BGPParseException {
-
- log.debug("BgpAttrNodeMultiTopologyId");
+ ArrayList<Short> multiTopologyId = new ArrayList<Short>();
+ short tempMultiTopologyId;
short lsAttrLength = cb.readShort();
int len = lsAttrLength / 2; // Length is 2*n and n is the number of MT-IDs
if (cb.readableBytes() < lsAttrLength) {
Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
- cb.readableBytes());
+ lsAttrLength);
}
- short[] multiTopologyId;
- multiTopologyId = new short[len];
for (int i = 0; i < len; i++) {
- multiTopologyId[i] = cb.readShort();
+ tempMultiTopologyId = cb.readShort();
+ multiTopologyId.add(new Short(tempMultiTopologyId));
}
return new BgpAttrNodeMultiTopologyId(multiTopologyId);
@@ -84,7 +94,7 @@ public class BgpAttrNodeMultiTopologyId implements BGPValueType {
*
* @return multitopology ID
*/
- short[] getAttrMultiTopologyId() {
+ public List<Short> attrMultiTopologyId() {
return multiTopologyId;
}
@@ -113,7 +123,7 @@ public class BgpAttrNodeMultiTopologyId implements BGPValueType {
@Override
public int write(ChannelBuffer cb) {
- // TODO Auto-generated method stub
+ // TODO This will be implemented in the next version
return 0;
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java
new file mode 100644
index 00000000..086e8b06
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java
@@ -0,0 +1,130 @@
+/*
+ * 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 attribute Is Is Administrative area.
+ */
+public final class BgpLinkAttrIsIsAdminstGrp implements BGPValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpLinkAttrIsIsAdminstGrp.class);
+
+ public static final int ATTRLINK_PROTECTIONTYPE = 1088;
+ public static final int ISIS_ADMIN_DATA_LEN = 4;
+
+ /* ISIS administrative group */
+ private final long isisAdminGrp;
+
+ /**
+ * Constructor to initialize the values.
+ *
+ * @param isisAdminGrp ISIS protocol admin group
+ */
+ public BgpLinkAttrIsIsAdminstGrp(long isisAdminGrp) {
+ this.isisAdminGrp = isisAdminGrp;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param isisAdminGrp ISIS admin group
+ * @return object of BgpLinkAttrIsIsAdminstGrp
+ */
+ public static BgpLinkAttrIsIsAdminstGrp of(final long isisAdminGrp) {
+ return new BgpLinkAttrIsIsAdminstGrp(isisAdminGrp);
+ }
+
+ /**
+ * Reads the BGP link attributes of ISIS administrative group area.
+ *
+ * @param cb Channel buffer
+ * @return object of type BgpLinkAttrIsIsAdminstGrp
+ * @throws BGPParseException while parsing BgpLinkAttrIsIsAdminstGrp
+ */
+ public static BgpLinkAttrIsIsAdminstGrp read(ChannelBuffer cb)
+ throws BGPParseException {
+ long isisAdminGrp;
+ short lsAttrLength = cb.readShort();
+
+ if ((lsAttrLength != ISIS_ADMIN_DATA_LEN)
+ || (cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ isisAdminGrp = cb.readUnsignedInt();
+
+ return BgpLinkAttrIsIsAdminstGrp.of(isisAdminGrp);
+ }
+
+ /**
+ * Link attributes of ISIS administrative group area.
+ *
+ * @return long value of the administrative group area
+ */
+ public long linkAttrIsIsAdminGrp() {
+ return isisAdminGrp;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRLINK_PROTECTIONTYPE;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(isisAdminGrp);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrIsIsAdminstGrp) {
+ BgpLinkAttrIsIsAdminstGrp other = (BgpLinkAttrIsIsAdminstGrp) obj;
+ return Objects.equals(isisAdminGrp, other.isisAdminGrp);
+ }
+ 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("isisAdminGrp", isisAdminGrp).toString();
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java
new file mode 100644
index 00000000..a1f0198b
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java
@@ -0,0 +1,150 @@
+/*
+ * 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 attribute Max Link bandwidth.
+ */
+public final class BgpLinkAttrMaxLinkBandwidth implements BGPValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpLinkAttrMaxLinkBandwidth.class);
+
+ public static final int MAX_BANDWIDTH_LEN = 4;
+ public static final int NO_OF_BITS = 8;
+
+ public short type;
+
+ /* ISIS administrative group */
+ private final float maxBandwidth;
+
+ /**
+ * Constructor to initialize the values.
+ *
+ * @param maxBandwidth Maximum link bandwidth.
+ * @param type TLV type
+ */
+ private BgpLinkAttrMaxLinkBandwidth(float maxBandwidth, short type) {
+ this.maxBandwidth = maxBandwidth;
+ this.type = type;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param maxBandwidth Maximum link bandwidth.
+ * @param type TLV type
+ * @return object of BgpLinkAttrMaxLinkBandwidth
+ */
+ public static BgpLinkAttrMaxLinkBandwidth of(final float maxBandwidth,
+ final short type) {
+ return new BgpLinkAttrMaxLinkBandwidth(maxBandwidth, type);
+ }
+
+ /**
+ * Reads the BGP link attributes of Maximum link bandwidth.
+ *
+ * @param cb Channel buffer
+ * @param type type of this tlv
+ * @return object of type BgpLinkAttrMaxLinkBandwidth
+ * @throws BGPParseException while parsing BgpLinkAttrMaxLinkBandwidth
+ */
+ public static BgpLinkAttrMaxLinkBandwidth read(ChannelBuffer cb, short type)
+ throws BGPParseException {
+ float maxBandwidth;
+ short lsAttrLength = cb.readShort();
+
+ if ((lsAttrLength != MAX_BANDWIDTH_LEN)
+ || (cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ maxBandwidth = ieeeToFloatRead(cb.readInt()) * NO_OF_BITS;
+
+ return BgpLinkAttrMaxLinkBandwidth.of(maxBandwidth, type);
+ }
+
+ /**
+ * Returns Maximum link bandwidth.
+ *
+ * @return Maximum link bandwidth
+ */
+ float linkAttrMaxLinkBandwidth() {
+ return maxBandwidth;
+ }
+
+ /**
+ * Parse the IEEE floating point notation and returns it in normal float.
+ *
+ * @param iVal IEEE floating point number
+ * @return normal float
+ */
+ static float ieeeToFloatRead(int iVal) {
+ iVal = (((iVal & 0xFF) << 24) | ((iVal & 0xFF00) << 8)
+ | ((iVal & 0xFF0000) >> 8) | ((iVal >> 24) & 0xFF));
+
+ return Float.intBitsToFloat(iVal);
+ }
+
+ @Override
+ public short getType() {
+ return this.type;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(maxBandwidth);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrMaxLinkBandwidth) {
+ BgpLinkAttrMaxLinkBandwidth other = (BgpLinkAttrMaxLinkBandwidth) obj;
+ return Objects.equals(maxBandwidth, other.maxBandwidth);
+ }
+ 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("maxBandwidth", maxBandwidth).toString();
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java
index 50591ecf..e44ba7e1 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java
@@ -16,7 +16,6 @@
package org.onosproject.bgpio.types.attr;
import java.util.Arrays;
-import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
@@ -46,11 +45,21 @@ public class BgpLinkAttrName implements BGPValueType {
*
* @param linkName link name
*/
- BgpLinkAttrName(byte[] linkName) {
+ public BgpLinkAttrName(byte[] linkName) {
this.linkName = Arrays.copyOf(linkName, linkName.length);
}
/**
+ * Returns object of this class with specified values.
+ *
+ * @param linkName Prefix Metric
+ * @return object of BgpLinkAttrName
+ */
+ public static BgpLinkAttrName of(byte[] linkName) {
+ return new BgpLinkAttrName(linkName);
+ }
+
+ /**
* Reads the BGP link attributes Name.
*
* @param cb Channel buffer
@@ -70,7 +79,7 @@ public class BgpLinkAttrName implements BGPValueType {
linkName = new byte[lsAttrLength];
cb.readBytes(linkName);
- return new BgpLinkAttrName(linkName);
+ return BgpLinkAttrName.of(linkName);
}
/**
@@ -78,7 +87,7 @@ public class BgpLinkAttrName implements BGPValueType {
*
* @return link name
*/
- byte[] getAttrLinkName() {
+ public byte[] attrLinkName() {
return linkName;
}
@@ -89,7 +98,7 @@ public class BgpLinkAttrName implements BGPValueType {
@Override
public int hashCode() {
- return Objects.hash(linkName);
+ return Arrays.hashCode(linkName);
}
@Override
@@ -100,7 +109,7 @@ public class BgpLinkAttrName implements BGPValueType {
if (obj instanceof BgpLinkAttrName) {
BgpLinkAttrName other = (BgpLinkAttrName) obj;
- return Objects.equals(linkName, other.linkName);
+ return Arrays.equals(linkName, other.linkName);
}
return false;
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java
new file mode 100755
index 00000000..258598be
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java
@@ -0,0 +1,133 @@
+/*
+ * 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 link opaque attribute.
+ */
+public final class BgpLinkAttrOpaqLnkAttrib implements BGPValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpLinkAttrOpaqLnkAttrib.class);
+
+ public static final int ATTRNODE_OPAQUELNKATTRIB = 1097;
+
+ /* Opaque Node Attribute */
+ private final byte[] opaqueLinkAttribute;
+
+ /**
+ * Constructor to initialize the data.
+ *
+ * @param opaqueLinkAttribute opaque link attribute
+ */
+ private BgpLinkAttrOpaqLnkAttrib(byte[] opaqueLinkAttribute) {
+ this.opaqueLinkAttribute = Arrays.copyOf(opaqueLinkAttribute,
+ opaqueLinkAttribute.length);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param opaqueLinkAttribute opaque link attribute
+ * @return object of BgpLinkAttrOpaqLnkAttrib
+ */
+ public static BgpLinkAttrOpaqLnkAttrib of(final byte[] opaqueLinkAttribute) {
+ return new BgpLinkAttrOpaqLnkAttrib(opaqueLinkAttribute);
+ }
+
+ /**
+ * Reads the BGP link attributes Opaque link attribute.
+ *
+ * @param cb Channel buffer
+ * @return object of type BgpLinkAttrOpaqLnkAttrib
+ * @throws BGPParseException while parsing BgpLinkAttrOpaqLnkAttrib
+ */
+ public static BgpLinkAttrOpaqLnkAttrib read(ChannelBuffer cb)
+ throws BGPParseException {
+
+ byte[] opaqueLinkAttribute;
+
+ short lsAttrLength = cb.readShort();
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
+ BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ opaqueLinkAttribute = new byte[lsAttrLength];
+ cb.readBytes(opaqueLinkAttribute);
+
+ return BgpLinkAttrOpaqLnkAttrib.of(opaqueLinkAttribute);
+ }
+
+ /**
+ * Returns the Opaque link attribute.
+ *
+ * @return byte array of opaque link attribute.
+ */
+ public byte[] attrOpaqueLnk() {
+ return opaqueLinkAttribute;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRNODE_OPAQUELNKATTRIB;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(opaqueLinkAttribute);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrOpaqLnkAttrib) {
+ BgpLinkAttrOpaqLnkAttrib other = (BgpLinkAttrOpaqLnkAttrib) obj;
+ return Arrays
+ .equals(opaqueLinkAttribute, other.opaqueLinkAttribute);
+ }
+ 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("opaqueLinkAttribute", opaqueLinkAttribute).toString();
+ }
+}
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/BgpPrefixAttrIGPFlags.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java
index 035d706c..a215e6f1 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIGPFlags.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java
@@ -30,24 +30,24 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP prefix IGP Flag attribute.
*/
-public class BgpPrefixAttrIGPFlags implements BGPValueType {
+public final class BgpPrefixAttrIgpFlags implements BGPValueType {
protected static final Logger log = LoggerFactory
- .getLogger(BgpPrefixAttrIGPFlags.class);
+ .getLogger(BgpPrefixAttrIgpFlags.class);
public static final int ATTR_PREFIX_FLAGBIT = 1152;
public static final int ATTR_PREFIX_FLAG_LEN = 1;
- public static final int FIRST_BIT = 0x80;
- public static final int SECOND_BIT = 0x40;
- public static final int THIRD_BIT = 0x20;
- public static final int FOURTH_BIT = 0x01;
+ public static final byte FIRST_BIT = (byte) 0x80;
+ public static final byte SECOND_BIT = 0x40;
+ public static final byte THIRD_BIT = 0x20;
+ public static final byte FOURTH_BIT = 0x01;
/* Prefix IGP flag bit TLV */
- private boolean bisisUpDownBit = false;
- private boolean bOspfNoUnicastBit = false;
- private boolean bOspfLclAddrBit = false;
- private boolean bOspfNSSABit = false;
+ private final boolean bisisUpDownBit;
+ private final boolean bOspfNoUnicastBit;
+ private final boolean bOspfLclAddrBit;
+ private final boolean bOspfNSSABit;
/**
* Constructor to initialize the value.
@@ -57,7 +57,8 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType {
* @param bOspfLclAddrBit OSPF local address Bit
* @param bOspfNSSABit OSPF propagate NSSA Bit
*/
- BgpPrefixAttrIGPFlags(boolean bisisUpDownBit, boolean bOspfNoUnicastBit,
+ BgpPrefixAttrIgpFlags(boolean bisisUpDownBit,
+ boolean bOspfNoUnicastBit,
boolean bOspfLclAddrBit, boolean bOspfNSSABit) {
this.bisisUpDownBit = bisisUpDownBit;
this.bOspfNoUnicastBit = bOspfNoUnicastBit;
@@ -66,13 +67,30 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType {
}
/**
+ * Returns object of this class with specified values.
+ *
+ * @param bisisUpDownBit IS-IS Up/Down Bit
+ * @param bOspfNoUnicastBit OSPF no unicast Bit
+ * @param bOspfLclAddrBit OSPF local address Bit
+ * @param bOspfNSSABit OSPF propagate NSSA Bit
+ * @return object of BgpPrefixAttrIGPFlags
+ */
+ public static BgpPrefixAttrIgpFlags of(final boolean bisisUpDownBit,
+ final boolean bOspfNoUnicastBit,
+ final boolean bOspfLclAddrBit,
+ final boolean bOspfNSSABit) {
+ return new BgpPrefixAttrIgpFlags(bisisUpDownBit, bOspfNoUnicastBit,
+ bOspfLclAddrBit, bOspfNSSABit);
+ }
+
+ /**
* Reads the IGP Flags.
*
* @param cb ChannelBuffer
* @return object of BgpPrefixAttrIGPFlags
* @throws BGPParseException while parsing BgpPrefixAttrIGPFlags
*/
- public static BgpPrefixAttrIGPFlags read(ChannelBuffer cb)
+ public static BgpPrefixAttrIgpFlags read(ChannelBuffer cb)
throws BGPParseException {
boolean bisisUpDownBit = false;
boolean bOspfNoUnicastBit = false;
@@ -90,13 +108,13 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType {
byte nodeFlagBits = cb.readByte();
- bisisUpDownBit = ((nodeFlagBits & (byte) FIRST_BIT) == FIRST_BIT);
- bOspfNoUnicastBit = ((nodeFlagBits & (byte) SECOND_BIT) == SECOND_BIT);
- bOspfLclAddrBit = ((nodeFlagBits & (byte) THIRD_BIT) == THIRD_BIT);
- bOspfNSSABit = ((nodeFlagBits & (byte) FOURTH_BIT) == FOURTH_BIT);
+ bisisUpDownBit = ((nodeFlagBits & FIRST_BIT) == FIRST_BIT);
+ bOspfNoUnicastBit = ((nodeFlagBits & SECOND_BIT) == SECOND_BIT);
+ bOspfLclAddrBit = ((nodeFlagBits & THIRD_BIT) == THIRD_BIT);
+ bOspfNSSABit = ((nodeFlagBits & FOURTH_BIT) == FOURTH_BIT);
- return new BgpPrefixAttrIGPFlags(bisisUpDownBit, bOspfNoUnicastBit,
- bOspfLclAddrBit, bOspfNSSABit);
+ return BgpPrefixAttrIgpFlags.of(bisisUpDownBit, bOspfNoUnicastBit,
+ bOspfLclAddrBit, bOspfNSSABit);
}
/**
@@ -104,7 +122,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType {
*
* @return IS-IS Up/Down Bit set or not
*/
- boolean getisisUpDownBit() {
+ public boolean isisUpDownBit() {
return bisisUpDownBit;
}
@@ -113,7 +131,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType {
*
* @return OSPF no unicast Bit set or not
*/
- boolean getOspfNoUnicastBit() {
+ public boolean ospfNoUnicastBit() {
return bOspfNoUnicastBit;
}
@@ -122,7 +140,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType {
*
* @return OSPF local address Bit set or not
*/
- boolean getOspfLclAddrBit() {
+ public boolean ospfLclAddrBit() {
return bOspfLclAddrBit;
}
@@ -131,7 +149,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType {
*
* @return OSPF propagate NSSA Bit set or not
*/
- boolean getOspfNSSABit() {
+ public boolean ospfNSSABit() {
return bOspfNSSABit;
}
@@ -158,13 +176,13 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType {
return true;
}
- if (obj instanceof BgpPrefixAttrIGPFlags) {
- BgpPrefixAttrIGPFlags other = (BgpPrefixAttrIGPFlags) obj;
+ if (obj instanceof BgpPrefixAttrIgpFlags) {
+ BgpPrefixAttrIgpFlags other = (BgpPrefixAttrIgpFlags) obj;
return Objects.equals(bisisUpDownBit, other.bisisUpDownBit)
&& Objects.equals(bOspfNoUnicastBit,
other.bOspfNoUnicastBit)
- && Objects.equals(bOspfLclAddrBit, other.bOspfLclAddrBit)
- && Objects.equals(bOspfNSSABit, other.bOspfNSSABit);
+ && Objects.equals(bOspfLclAddrBit, other.bOspfLclAddrBit)
+ && Objects.equals(bOspfNSSABit, other.bOspfNSSABit);
}
return false;
}
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/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java
index 0cf02386..426eb274 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java
@@ -15,7 +15,8 @@
*/
package org.onosproject.bgpio.types.attr;
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
@@ -36,18 +37,28 @@ public class BgpPrefixAttrRouteTag implements BGPValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpPrefixAttrRouteTag.class);
- public static final int ATTR_PREFIX_ROUTETAG = 1153;
+ public static final short ATTR_PREFIX_ROUTETAG = 1153;
/* Prefix Route Tag */
- private int[] pfxRouteTag;
+ private List<Integer> pfxRouteTag = new ArrayList<Integer>();
/**
* Constructor to initialize the values.
*
* @param pfxRouteTag prefix route tag
*/
- BgpPrefixAttrRouteTag(int[] pfxRouteTag) {
- this.pfxRouteTag = Arrays.copyOf(pfxRouteTag, pfxRouteTag.length);
+ public BgpPrefixAttrRouteTag(List<Integer> pfxRouteTag) {
+ this.pfxRouteTag = pfxRouteTag;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param pfxRouteTag Prefix Metric
+ * @return object of BgpPrefixAttrRouteTag
+ */
+ public static BgpPrefixAttrRouteTag of(ArrayList<Integer> pfxRouteTag) {
+ return new BgpPrefixAttrRouteTag(pfxRouteTag);
}
/**
@@ -59,7 +70,8 @@ public class BgpPrefixAttrRouteTag implements BGPValueType {
*/
public static BgpPrefixAttrRouteTag read(ChannelBuffer cb)
throws BGPParseException {
- int[] pfxRouteTag;
+ int tmp;
+ ArrayList<Integer> pfxRouteTag = new ArrayList<Integer>();
short lsAttrLength = cb.readShort();
int len = lsAttrLength / Integer.SIZE;
@@ -70,13 +82,12 @@ public class BgpPrefixAttrRouteTag implements BGPValueType {
lsAttrLength);
}
- pfxRouteTag = new int[lsAttrLength];
-
for (int i = 0; i < len; i++) {
- pfxRouteTag[i] = cb.readInt();
+ tmp = cb.readInt();
+ pfxRouteTag.add(new Integer(tmp));
}
- return new BgpPrefixAttrRouteTag(pfxRouteTag);
+ return BgpPrefixAttrRouteTag.of(pfxRouteTag);
}
/**
@@ -84,7 +95,7 @@ public class BgpPrefixAttrRouteTag implements BGPValueType {
*
* @return route tag
*/
- int[] getPfxRouteTag() {
+ public List<Integer> getPfxRouteTag() {
return pfxRouteTag;
}