blob: 129bdb91f38737b94601c5e7b28cd43d1fbb5134 [file] [log] [blame]
Shashikanth VH73b12772016-04-18 14:28:45 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16package org.onosproject.bgpio.types;
17
18import com.google.common.base.MoreObjects;
19
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.onosproject.bgpio.exceptions.BgpParseException;
22import org.onosproject.bgpio.types.attr.WideCommunity;
23
24import java.util.List;
25import java.util.Objects;
26
27/**
28 * Provides implementation of BGP wide community parameter.
29 */
30public class WideCommunityParameter implements BgpValueType {
31
32 public static final byte TYPE = 3;
33 private List<BgpValueType> parameterTlv;
34
35 /**
36 * Creates an instance of wide community parameter.
37 *
38 * @param parameterTlv wide community parameter
39 */
40 public WideCommunityParameter(List<BgpValueType> parameterTlv) {
41 this.parameterTlv = parameterTlv;
42 }
43
44 /**
45 * Returns object of this class with specified values.
46 *
47 * @param parameterTlv wide community parameter
48 * @return object of WideCommunityParameter
49 */
50 public static WideCommunityParameter of(List<BgpValueType> parameterTlv) {
51 return new WideCommunityParameter(parameterTlv);
52 }
53
54 /**
55 * Returns wide community parameter.
56 *
57 * @return wide community parameter
58 */
59 public List<BgpValueType> parameterTlv() {
60 return parameterTlv;
61 }
62
63 /**
64 * Sets wide community parameter.
65 *
66 * @param parameterTlv wide community parameter
67 */
68 public void setParameterTlv(List<BgpValueType> parameterTlv) {
69 this.parameterTlv = parameterTlv;
70 }
71
72 @Override
73 public int hashCode() {
74 return Objects.hash(parameterTlv);
75 }
76
77 @Override
78 public boolean equals(Object obj) {
79 if (this == obj) {
80 return true;
81 }
82
83 if (obj == null) {
84 return false;
85 }
86
87 if (obj instanceof WideCommunityParameter) {
88 WideCommunityParameter other = (WideCommunityParameter) obj;
89 return Objects.equals(parameterTlv, other.parameterTlv);
90 }
91 return false;
92 }
93
94 @Override
95 public int write(ChannelBuffer c) {
96 int iLenStartIndex = c.writerIndex();
97 WideCommunity.encodeWideCommunityTlv(c, parameterTlv());
98 return c.writerIndex() - iLenStartIndex;
99 }
100
101 /**
102 * Reads the channel buffer and returns object of WideCommunityParameter.
103 *
104 * @param c ChannelBuffer
105 * @return object of WideCommunityParameter
106 * @throws BgpParseException on read error
107 */
108 public static WideCommunityParameter read(ChannelBuffer c) throws BgpParseException {
109 return new WideCommunityParameter(WideCommunity.decodeWideCommunityTlv(c));
110 }
111
112 @Override
113 public short getType() {
114 return TYPE;
115 }
116
117 @Override
118 public String toString() {
119 return MoreObjects.toStringHelper(getClass())
120 .omitNullValues()
121 .add("Type", TYPE)
122 .add("parameterTlv", parameterTlv)
123 .toString();
124 }
125
126 @Override
127 public int compareTo(Object o) {
128 // TODO Auto-generated method stub
129 return 0;
130 }
131}