diff options
Diffstat (limited to 'framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr')
3 files changed, 58 insertions, 28 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/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/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; } |