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.Arrays;
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 opaque attribute.
33 public final class BgpLinkAttrOpaqLnkAttrib implements BgpValueType {
35 protected static final Logger log = LoggerFactory
36 .getLogger(BgpLinkAttrOpaqLnkAttrib.class);
38 public static final int ATTRNODE_OPAQUELNKATTRIB = 1097;
40 /* Opaque Node Attribute */
41 private final byte[] opaqueLinkAttribute;
44 * Constructor to initialize the data.
46 * @param opaqueLinkAttribute opaque link attribute
48 private BgpLinkAttrOpaqLnkAttrib(byte[] opaqueLinkAttribute) {
49 this.opaqueLinkAttribute = Arrays.copyOf(opaqueLinkAttribute,
50 opaqueLinkAttribute.length);
54 * Returns object of this class with specified values.
56 * @param opaqueLinkAttribute opaque link attribute
57 * @return object of BgpLinkAttrOpaqLnkAttrib
59 public static BgpLinkAttrOpaqLnkAttrib of(final byte[] opaqueLinkAttribute) {
60 return new BgpLinkAttrOpaqLnkAttrib(opaqueLinkAttribute);
64 * Reads the BGP link attributes Opaque link attribute.
66 * @param cb Channel buffer
67 * @return object of type BgpLinkAttrOpaqLnkAttrib
68 * @throws BgpParseException while parsing BgpLinkAttrOpaqLnkAttrib
70 public static BgpLinkAttrOpaqLnkAttrib read(ChannelBuffer cb)
71 throws BgpParseException {
73 byte[] opaqueLinkAttribute;
75 short lsAttrLength = cb.readShort();
77 if (cb.readableBytes() < lsAttrLength) {
78 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
79 BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
83 opaqueLinkAttribute = new byte[lsAttrLength];
84 cb.readBytes(opaqueLinkAttribute);
86 return BgpLinkAttrOpaqLnkAttrib.of(opaqueLinkAttribute);
90 * Returns the Opaque link attribute.
92 * @return byte array of opaque link attribute.
94 public byte[] attrOpaqueLnk() {
95 return opaqueLinkAttribute;
99 public short getType() {
100 return ATTRNODE_OPAQUELNKATTRIB;
104 public int hashCode() {
105 return Arrays.hashCode(opaqueLinkAttribute);
109 public boolean equals(Object obj) {
114 if (obj instanceof BgpLinkAttrOpaqLnkAttrib) {
115 BgpLinkAttrOpaqLnkAttrib other = (BgpLinkAttrOpaqLnkAttrib) obj;
117 .equals(opaqueLinkAttribute, other.opaqueLinkAttribute);
123 public int write(ChannelBuffer cb) {
124 // TODO This will be implemented in the next version
129 public String toString() {
130 return MoreObjects.toStringHelper(getClass()).omitNullValues()
131 .add("opaqueLinkAttribute", opaqueLinkAttribute).toString();
135 public int compareTo(Object o) {
136 // TODO Auto-generated method stub