2 * Copyright 2015 Open Networking Laboratory
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onosproject.bgpio.types.attr;
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Objects;
22 import org.jboss.netty.buffer.ChannelBuffer;
23 import org.onosproject.bgpio.exceptions.BgpParseException;
24 import org.onosproject.bgpio.types.BgpErrorType;
25 import org.onosproject.bgpio.types.BgpValueType;
26 import org.onosproject.bgpio.util.Validation;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 import com.google.common.base.MoreObjects;
33 * Implements BGP prefix route tag attribute.
35 public class BgpPrefixAttrRouteTag implements BgpValueType {
37 protected static final Logger log = LoggerFactory
38 .getLogger(BgpPrefixAttrRouteTag.class);
40 public static final short ATTR_PREFIX_ROUTETAG = 1153;
42 /* Prefix Route Tag */
43 private List<Integer> pfxRouteTag = new ArrayList<Integer>();
46 * Constructor to initialize the values.
48 * @param pfxRouteTag prefix route tag
50 public BgpPrefixAttrRouteTag(List<Integer> pfxRouteTag) {
51 this.pfxRouteTag = pfxRouteTag;
55 * Returns object of this class with specified values.
57 * @param pfxRouteTag Prefix Metric
58 * @return object of BgpPrefixAttrRouteTag
60 public static BgpPrefixAttrRouteTag of(ArrayList<Integer> pfxRouteTag) {
61 return new BgpPrefixAttrRouteTag(pfxRouteTag);
65 * Reads the Route Tag.
67 * @param cb ChannelBuffer
68 * @return object of BgpPrefixAttrRouteTag
69 * @throws BgpParseException while parsing BgpPrefixAttrRouteTag
71 public static BgpPrefixAttrRouteTag read(ChannelBuffer cb)
72 throws BgpParseException {
74 ArrayList<Integer> pfxRouteTag = new ArrayList<Integer>();
76 short lsAttrLength = cb.readShort();
77 int len = lsAttrLength / Integer.SIZE;
79 if (cb.readableBytes() < lsAttrLength) {
80 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
81 BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
85 for (int i = 0; i < len; i++) {
87 pfxRouteTag.add(new Integer(tmp));
90 return BgpPrefixAttrRouteTag.of(pfxRouteTag);
94 * Returns the prefix route tag.
98 public List<Integer> getPfxRouteTag() {
103 public short getType() {
104 return ATTR_PREFIX_ROUTETAG;
108 public int hashCode() {
109 return Objects.hash(pfxRouteTag);
113 public boolean equals(Object obj) {
118 if (obj instanceof BgpPrefixAttrRouteTag) {
119 BgpPrefixAttrRouteTag other = (BgpPrefixAttrRouteTag) obj;
120 return Objects.equals(pfxRouteTag, other.pfxRouteTag);
126 public int write(ChannelBuffer cb) {
127 // TODO This will be implemented in the next version
132 public String toString() {
133 return MoreObjects.toStringHelper(getClass()).omitNullValues()
134 .add("pfxRouteTag", pfxRouteTag).toString();
138 public int compareTo(Object o) {
139 // TODO Auto-generated method stub