blob: 819ffb6dac1592b7e37813ab4671e5c622f6b5b6 [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 exclude target.
29 */
30public class WideCommunityExcludeTarget implements BgpValueType {
31
32 public static final byte TYPE = 2;
33 private List<BgpValueType> excludeTargetTlv;
34
35 /**
36 * Wide community targets.
37 *
38 * @param excludeTargetTlv wide community exclude target
39 */
40 public WideCommunityExcludeTarget(List<BgpValueType> excludeTargetTlv) {
41 this.excludeTargetTlv = excludeTargetTlv;
42 }
43
44 /**
45 * Returns object of this class with specified values.
46 *
47 * @param excludeTargetTlv exclude target
48 * @return object of WideCommunityExcludeTarget
49 */
50 public static BgpValueType of(List<BgpValueType> excludeTargetTlv) {
51 return new WideCommunityExcludeTarget(excludeTargetTlv);
52 }
53
54 /**
55 * Returns wide community targets.
56 *
57 * @return wide community targets
58 */
59 public List<BgpValueType> excludeTargetTlv() {
60 return excludeTargetTlv;
61 }
62
63 /**
64 * Sets wide community target.
65 *
66 * @param excludeTargetTlv wide community exclude targets
67 */
68 public void setExcludeTargetTlv(List<BgpValueType> excludeTargetTlv) {
69 this.excludeTargetTlv = excludeTargetTlv;
70 }
71
72
73 @Override
74 public int hashCode() {
75 return Objects.hash(excludeTargetTlv);
76 }
77
78 @Override
79 public boolean equals(Object obj) {
80 if (this == obj) {
81 return true;
82 }
83
84 if (obj == null) {
85 return false;
86 }
87
88 if (obj instanceof WideCommunityExcludeTarget) {
89 WideCommunityExcludeTarget other = (WideCommunityExcludeTarget) obj;
90 return Objects.equals(excludeTargetTlv, other.excludeTargetTlv);
91 }
92 return false;
93 }
94
95 @Override
96 public int write(ChannelBuffer c) {
97 int iLenStartIndex = c.writerIndex();
98 WideCommunity.encodeWideCommunityTlv(c, excludeTargetTlv());
99 return c.writerIndex() - iLenStartIndex;
100 }
101
102 /**
103 * Reads the channel buffer and returns object of WideCommunityExcludeTarget.
104 *
105 * @param c ChannelBuffer
106 * @return object of WideCommunityExcludeTarget
107 * @throws BgpParseException on read error
108 */
109 public static WideCommunityExcludeTarget read(ChannelBuffer c) throws BgpParseException {
110 return new WideCommunityExcludeTarget(WideCommunity.decodeWideCommunityTlv(c));
111 }
112
113 @Override
114 public short getType() {
115 return TYPE;
116 }
117
118 @Override
119 public String toString() {
120 return MoreObjects.toStringHelper(getClass())
121 .omitNullValues()
122 .add("Type", TYPE)
123 .add("targetTlv", excludeTargetTlv)
124 .toString();
125 }
126
127 @Override
128 public int compareTo(Object o) {
129 // TODO Auto-generated method stub
130 return 0;
131 }
132}