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 * BGP Multi-Topology ID of the LS attribute.
35 public class BgpAttrNodeMultiTopologyId implements BGPValueType {
37 private static final Logger log = LoggerFactory
38 .getLogger(BgpAttrNodeMultiTopologyId.class);
40 public static final int ATTRNODE_MULTITOPOLOGY = 263;
42 /* Opaque Node Attribute */
43 private List<Short> multiTopologyId = new ArrayList<Short>();
46 * Constructor to initialize the Node attribute multi-topology ID.
48 * @param multiTopologyId multi-topology ID
50 public BgpAttrNodeMultiTopologyId(List<Short> multiTopologyId) {
51 this.multiTopologyId = multiTopologyId;
55 * Returns object of this class with specified values.
57 * @param multiTopologyId Prefix Metric
58 * @return object of BgpAttrNodeMultiTopologyId
60 public static BgpAttrNodeMultiTopologyId of(ArrayList<Short> multiTopologyId) {
61 return new BgpAttrNodeMultiTopologyId(multiTopologyId);
65 * Reads the Multi-topology ID of Node attribute.
67 * @param cb ChannelBuffer
68 * @return Constructor of BgpAttrNodeMultiTopologyId
69 * @throws BGPParseException while parsing BgpAttrNodeMultiTopologyId
71 public static BgpAttrNodeMultiTopologyId read(ChannelBuffer cb)
72 throws BGPParseException {
73 ArrayList<Short> multiTopologyId = new ArrayList<Short>();
74 short tempMultiTopologyId;
75 short lsAttrLength = cb.readShort();
76 int len = lsAttrLength / 2; // Length is 2*n and n is the number of MT-IDs
78 if (cb.readableBytes() < lsAttrLength) {
79 Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
80 BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
84 for (int i = 0; i < len; i++) {
85 tempMultiTopologyId = cb.readShort();
86 multiTopologyId.add(new Short(tempMultiTopologyId));
89 return new BgpAttrNodeMultiTopologyId(multiTopologyId);
93 * to get the multi-topology ID.
95 * @return multitopology ID
97 public List<Short> attrMultiTopologyId() {
98 return multiTopologyId;
102 public short getType() {
103 return ATTRNODE_MULTITOPOLOGY;
107 public int hashCode() {
108 return Objects.hash(multiTopologyId);
112 public boolean equals(Object obj) {
117 if (obj instanceof BgpAttrNodeMultiTopologyId) {
118 BgpAttrNodeMultiTopologyId other = (BgpAttrNodeMultiTopologyId) obj;
119 return Objects.equals(multiTopologyId, other.multiTopologyId);
125 public int write(ChannelBuffer cb) {
126 // TODO This will be implemented in the next version
131 public String toString() {
132 return MoreObjects.toStringHelper(getClass())
134 .add("multiTopologyId", multiTopologyId)