summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr')
-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
9 files changed, 781 insertions, 54 deletions
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;
}