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.
17 package org.onosproject.bgpio.types.attr;
19 import java.util.Objects;
21 import org.jboss.netty.buffer.ChannelBuffer;
22 import org.onosproject.bgpio.exceptions.BGPParseException;
23 import org.onosproject.bgpio.types.BGPErrorType;
24 import org.onosproject.bgpio.types.BGPValueType;
25 import org.onosproject.bgpio.util.Validation;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import com.google.common.base.MoreObjects;
32 * BGP Multi-Topology ID of the LS attribute.
34 public class BgpAttrNodeMultiTopologyId implements BGPValueType {
36 private static final Logger log = LoggerFactory
37 .getLogger(BgpAttrNodeMultiTopologyId.class);
39 public static final int ATTRNODE_MULTITOPOLOGY = 263;
41 /* Opaque Node Attribute */
42 private short[] multiTopologyId;
45 * Constructor to initialize the Node attribute multi-topology ID.
47 * @param multiTopologyId multi-topology ID
49 BgpAttrNodeMultiTopologyId(short[] multiTopologyId) {
50 this.multiTopologyId = multiTopologyId;
54 * Reads the Multi-topology ID of Node attribute.
56 * @param cb ChannelBuffer
57 * @return Constructor of BgpAttrNodeMultiTopologyId
58 * @throws BGPParseException while parsing BgpAttrNodeMultiTopologyId
60 public static BgpAttrNodeMultiTopologyId read(ChannelBuffer cb)
61 throws BGPParseException {
63 log.debug("BgpAttrNodeMultiTopologyId");
64 short lsAttrLength = cb.readShort();
65 int len = lsAttrLength / 2; // Length is 2*n and n is the number of MT-IDs
67 if (cb.readableBytes() < lsAttrLength) {
68 Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
69 BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
73 short[] multiTopologyId;
74 multiTopologyId = new short[len];
75 for (int i = 0; i < len; i++) {
76 multiTopologyId[i] = cb.readShort();
79 return new BgpAttrNodeMultiTopologyId(multiTopologyId);
83 * to get the multi-topology ID.
85 * @return multitopology ID
87 short[] getAttrMultiTopologyId() {
88 return multiTopologyId;
92 public short getType() {
93 return ATTRNODE_MULTITOPOLOGY;
97 public int hashCode() {
98 return Objects.hash(multiTopologyId);
102 public boolean equals(Object obj) {
107 if (obj instanceof BgpAttrNodeMultiTopologyId) {
108 BgpAttrNodeMultiTopologyId other = (BgpAttrNodeMultiTopologyId) obj;
109 return Objects.equals(multiTopologyId, other.multiTopologyId);
115 public int write(ChannelBuffer cb) {
116 // TODO Auto-generated method stub
121 public String toString() {
122 return MoreObjects.toStringHelper(getClass())
124 .add("multiTopologyId", multiTopologyId)