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 static com.google.common.base.Preconditions.checkNotNull;
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.Objects;
24 import org.jboss.netty.buffer.ChannelBuffer;
25 import org.onosproject.bgpio.exceptions.BgpParseException;
26 import org.onosproject.bgpio.types.BgpErrorType;
27 import org.onosproject.bgpio.types.BgpValueType;
28 import org.onosproject.bgpio.util.Validation;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 import com.google.common.base.MoreObjects;
35 * Implements BGP prefix route Extended tag attribute.
37 public class BgpPrefixAttrExtRouteTag implements BgpValueType {
39 protected static final Logger log = LoggerFactory
40 .getLogger(BgpPrefixAttrExtRouteTag.class);
42 public static final int ATTR_PREFIX_EXTROUTETAG = 1154;
43 public static final int ATTR_PREFIX_EXT_LEN = 8;
45 /* Prefix Route Tag */
46 private List<Long> pfxExtRouteTag = new ArrayList<Long>();
49 * Constructor to initialize the values.
51 * @param pfxExtRouteTag Extended route tag
53 public BgpPrefixAttrExtRouteTag(List<Long> pfxExtRouteTag) {
54 this.pfxExtRouteTag = checkNotNull(pfxExtRouteTag);
58 * Returns object of this class with specified values.
60 * @param pfxExtRouteTag Prefix Metric
61 * @return object of BgpPrefixAttrMetric
63 public static BgpPrefixAttrExtRouteTag of(ArrayList<Long> pfxExtRouteTag) {
64 return new BgpPrefixAttrExtRouteTag(pfxExtRouteTag);
68 * Reads the Extended Tag.
70 * @param cb ChannelBuffer
71 * @return object of BgpPrefixAttrExtRouteTag
72 * @throws BgpParseException while parsing BgpPrefixAttrExtRouteTag
74 public static BgpPrefixAttrExtRouteTag read(ChannelBuffer cb)
75 throws BgpParseException {
76 ArrayList<Long> pfxExtRouteTag = new ArrayList<Long>();
79 short lsAttrLength = cb.readShort();
80 int len = lsAttrLength / ATTR_PREFIX_EXT_LEN;
82 if (cb.readableBytes() < lsAttrLength) {
83 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
84 BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
88 for (int i = 0; i < len; i++) {
90 pfxExtRouteTag.add(new Long(temp));
93 return new BgpPrefixAttrExtRouteTag(pfxExtRouteTag);
97 * Returns Extended route tag.
101 public List<Long> pfxExtRouteTag() {
102 return pfxExtRouteTag;
106 public short getType() {
107 return ATTR_PREFIX_EXTROUTETAG;
111 public int hashCode() {
112 return Objects.hash(pfxExtRouteTag);
116 public boolean equals(Object obj) {
121 if (obj instanceof BgpPrefixAttrExtRouteTag) {
122 BgpPrefixAttrExtRouteTag other = (BgpPrefixAttrExtRouteTag) obj;
123 return Objects.equals(pfxExtRouteTag, other.pfxExtRouteTag);
129 public int write(ChannelBuffer cb) {
130 // TODO This will be implemented in the next version
135 public String toString() {
136 return MoreObjects.toStringHelper(getClass()).omitNullValues()
137 .add("pfxExtRouteTag", pfxExtRouteTag).toString();
141 public int compareTo(Object o) {
142 // TODO Auto-generated method stub