aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol')
-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
16 files changed, 661 insertions, 72 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();
+ }
+}