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.Objects;
20 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.onosproject.bgpio.exceptions.BgpParseException;
22 import org.onosproject.bgpio.types.BgpErrorType;
23 import org.onosproject.bgpio.types.BgpValueType;
24 import org.onosproject.bgpio.util.Validation;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import com.google.common.base.MoreObjects;
31 * Implements BGP link state Default TE metric link attribute.
33 public class BgpLinkAttrTeDefaultMetric implements BgpValueType {
35 protected static final Logger log = LoggerFactory
36 .getLogger(BgpLinkAttrTeDefaultMetric.class);
38 public static final int ATTRLINK_TEDEFAULTMETRIC = 1092;
39 public static final int TE_DATA_LEN = 4;
41 /* TE Default Metric */
42 private int linkTeMetric;
45 * Constructor to initialize the value.
47 * @param linkTeMetric TE default metric
50 public BgpLinkAttrTeDefaultMetric(int linkTeMetric) {
51 this.linkTeMetric = linkTeMetric;
55 * Returns object of this class with specified values.
57 * @param linkTeMetric TE default metric
58 * @return object of BgpLinkAttrTeDefaultMetric
60 public static BgpLinkAttrTeDefaultMetric of(final int linkTeMetric) {
61 return new BgpLinkAttrTeDefaultMetric(linkTeMetric);
65 * Reads the BGP link attributes of TE default metric.
67 * @param cb Channel buffer
68 * @return object of type BgpLinkAttrTeDefaultMetric
69 * @throws BgpParseException while parsing BgpLinkAttrTeDefaultMetric
71 public static BgpLinkAttrTeDefaultMetric read(ChannelBuffer cb)
72 throws BgpParseException {
75 short lsAttrLength = cb.readShort();
77 if ((lsAttrLength != TE_DATA_LEN)
78 || (cb.readableBytes() < lsAttrLength)) {
79 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
80 BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
84 linkTeMetric = cb.readInt();
86 return new BgpLinkAttrTeDefaultMetric(linkTeMetric);
90 * Returns the TE default metrics.
92 * @return link default metric
94 public int attrLinkDefTeMetric() {
99 public short getType() {
100 return ATTRLINK_TEDEFAULTMETRIC;
104 public int hashCode() {
105 return Objects.hash(linkTeMetric);
109 public boolean equals(Object obj) {
114 if (obj instanceof BgpLinkAttrTeDefaultMetric) {
115 BgpLinkAttrTeDefaultMetric other = (BgpLinkAttrTeDefaultMetric) obj;
116 return Objects.equals(linkTeMetric, other.linkTeMetric);
122 public int write(ChannelBuffer cb) {
123 // TODO This will be implemented in the next version
128 public String toString() {
129 return MoreObjects.toStringHelper(getClass())
130 .add("linkTEMetric", linkTeMetric).toString();
134 public int compareTo(Object o) {
135 // TODO Auto-generated method stub