Committed by
Gerrit Code Review
[ONOS-4240, ONOS-4241] Support wide community optional path attribute
Change-Id: I59f9c4b69e8c26702ab955d58655497a394b9ec9
Showing
7 changed files
with
986 additions
and
0 deletions
protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/WideCommunityAttrHeader.java
0 → 100644
1 | +/* | ||
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 | + */ | ||
16 | +package org.onosproject.bgpio.types; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | + | ||
20 | +import org.onosproject.bgpio.exceptions.BgpParseException; | ||
21 | +import org.onosproject.bgpio.util.Validation; | ||
22 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
23 | + | ||
24 | +import java.util.Objects; | ||
25 | + | ||
26 | +/** | ||
27 | + * Provides implementation of BGP wide community attribute header. | ||
28 | + */ | ||
29 | +public class WideCommunityAttrHeader implements BgpValueType { | ||
30 | + | ||
31 | + /* 0 1 2 3 | ||
32 | + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
33 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
34 | + | Type | Flags | Hop Count | | ||
35 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
36 | + | Length | | ||
37 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/ | ||
38 | + | ||
39 | + /*FLAG | ||
40 | + +------+-------+----------------------------------------------------+ | ||
41 | + | Bit | Value | Meaning | | ||
42 | + +------+-------+----------------------------------------------------+ | ||
43 | + | 0 | 0 | Local community value. | | ||
44 | + | | 1 | Registered community value. | | ||
45 | + | 1 | 0 | Do not decrement Hop Count field across | | ||
46 | + | | | confederation boundaries. | | ||
47 | + | | 1 | Decrement Hop Count field across confederation | | ||
48 | + | | | boundaries. | | ||
49 | + | 2..7 | - | MUST be zero when sent and ignored upon receipt. | | ||
50 | + +------+-------+----------------------------------------------------+*/ | ||
51 | + | ||
52 | + public static final short TYPE = 1; | ||
53 | + public static final short HEADER_LENGTH = 6; | ||
54 | + private byte flag; | ||
55 | + private byte hopCount; | ||
56 | + private short length; | ||
57 | + | ||
58 | + /** | ||
59 | + * Wide community attribute header. | ||
60 | + * | ||
61 | + * @param flag to apply to all wide community container types | ||
62 | + * @param hopCount represents the forwarding radius, in units of AS hops, for the given Wide BGP Community | ||
63 | + * @param length field represents the total length of a given container | ||
64 | + */ | ||
65 | + public WideCommunityAttrHeader(byte flag, byte hopCount, short length) { | ||
66 | + this.flag = flag; | ||
67 | + this.hopCount = hopCount; | ||
68 | + this.length = length; | ||
69 | + } | ||
70 | + | ||
71 | + /** | ||
72 | + * Returns object of this class with specified values. | ||
73 | + * | ||
74 | + * @param flag flag to apply to all wide community container types | ||
75 | + * @param hopCount represents the forwarding radius, in units of AS hops, for the given Wide BGP Community | ||
76 | + * @param length field represents the total length of a given container | ||
77 | + * @return wide community attribute header | ||
78 | + */ | ||
79 | + public static WideCommunityAttrHeader of(byte flag, byte hopCount, short length) { | ||
80 | + return new WideCommunityAttrHeader(flag, hopCount, length); | ||
81 | + } | ||
82 | + | ||
83 | + /** | ||
84 | + * Returns wide community flag. | ||
85 | + * | ||
86 | + * @return wide community flag | ||
87 | + */ | ||
88 | + public byte flag() { | ||
89 | + return flag; | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * Sets wide community flag. | ||
94 | + * | ||
95 | + * @param flag to apply to all wide community container types | ||
96 | + */ | ||
97 | + public void setFlag(byte flag) { | ||
98 | + this.flag = flag; | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * Returns hop count for wide community attribute. | ||
103 | + * | ||
104 | + * @return hop count from wide community | ||
105 | + */ | ||
106 | + public byte hopCount() { | ||
107 | + return hopCount; | ||
108 | + } | ||
109 | + | ||
110 | + /** | ||
111 | + * Sets wide community hop count. | ||
112 | + * | ||
113 | + * @param hopCount represents the forwarding radius, in units of AS hops, for the given Wide BGP Community | ||
114 | + */ | ||
115 | + public void setHopCount(byte hopCount) { | ||
116 | + this.hopCount = hopCount; | ||
117 | + } | ||
118 | + | ||
119 | + /** | ||
120 | + * Returns length of wide community attribute. | ||
121 | + * | ||
122 | + * @return length of wide community attribute | ||
123 | + */ | ||
124 | + public short length() { | ||
125 | + return length; | ||
126 | + } | ||
127 | + | ||
128 | + /** | ||
129 | + * Sets wide community length. | ||
130 | + * | ||
131 | + * @param length total length of a given container | ||
132 | + */ | ||
133 | + public void setLength(short length) { | ||
134 | + this.length = length; | ||
135 | + } | ||
136 | + | ||
137 | + @Override | ||
138 | + public int hashCode() { | ||
139 | + return Objects.hash(flag, hopCount, length); | ||
140 | + } | ||
141 | + | ||
142 | + @Override | ||
143 | + public boolean equals(Object obj) { | ||
144 | + if (this == obj) { | ||
145 | + return true; | ||
146 | + } | ||
147 | + | ||
148 | + if (obj == null) { | ||
149 | + return false; | ||
150 | + } | ||
151 | + | ||
152 | + if (obj instanceof WideCommunityAttrHeader) { | ||
153 | + WideCommunityAttrHeader other = (WideCommunityAttrHeader) obj; | ||
154 | + return Objects.equals(flag, other.flag) && Objects.equals(hopCount, other.hopCount) | ||
155 | + && Objects.equals(length, other.length); | ||
156 | + } | ||
157 | + return false; | ||
158 | + } | ||
159 | + | ||
160 | + @Override | ||
161 | + public int write(ChannelBuffer c) { | ||
162 | + int iLenStartIndex = c.writerIndex(); | ||
163 | + c.writeShort(TYPE); | ||
164 | + c.writeByte(flag); | ||
165 | + c.writeByte(hopCount); | ||
166 | + c.writeShort(length); | ||
167 | + return c.writerIndex() - iLenStartIndex; | ||
168 | + } | ||
169 | + | ||
170 | + /** | ||
171 | + * Reads the channel buffer and returns object of WideCommunityAttrHeader. | ||
172 | + * | ||
173 | + * @param c ChannelBuffer | ||
174 | + * @return object of WideCommunityAttrHeader | ||
175 | + */ | ||
176 | + public static WideCommunityAttrHeader read(ChannelBuffer c) throws BgpParseException { | ||
177 | + | ||
178 | + if (c.readableBytes() < HEADER_LENGTH) { | ||
179 | + Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, | ||
180 | + BgpErrorType.ATTRIBUTE_LENGTH_ERROR, c.readableBytes()); | ||
181 | + } | ||
182 | + | ||
183 | + short type = c.readShort(); | ||
184 | + byte flag = c.readByte(); | ||
185 | + byte hopCount = c.readByte(); | ||
186 | + short length = c.readShort(); | ||
187 | + return WideCommunityAttrHeader.of(flag, hopCount, length); | ||
188 | + } | ||
189 | + | ||
190 | + @Override | ||
191 | + public short getType() { | ||
192 | + return TYPE; | ||
193 | + } | ||
194 | + | ||
195 | + @Override | ||
196 | + public String toString() { | ||
197 | + return MoreObjects.toStringHelper(getClass()) | ||
198 | + .add("Type", TYPE) | ||
199 | + .add("flag", flag) | ||
200 | + .add("hopCount", hopCount) | ||
201 | + .add("length", length) | ||
202 | + .toString(); | ||
203 | + } | ||
204 | + | ||
205 | + @Override | ||
206 | + public int compareTo(Object o) { | ||
207 | + // TODO Auto-generated method stub | ||
208 | + return 0; | ||
209 | + } | ||
210 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/WideCommunityExcludeTarget.java
0 → 100644
1 | +/* | ||
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 | + */ | ||
16 | +package org.onosproject.bgpio.types; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | + | ||
20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
21 | +import org.onosproject.bgpio.exceptions.BgpParseException; | ||
22 | +import org.onosproject.bgpio.types.attr.WideCommunity; | ||
23 | + | ||
24 | +import java.util.List; | ||
25 | +import java.util.Objects; | ||
26 | + | ||
27 | +/** | ||
28 | + * Provides implementation of BGP wide community exclude target. | ||
29 | + */ | ||
30 | +public 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 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
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 | + */ | ||
16 | +package org.onosproject.bgpio.types; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | + | ||
20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
21 | +import org.onosproject.bgpio.exceptions.BgpParseException; | ||
22 | +import org.onosproject.bgpio.util.Validation; | ||
23 | + | ||
24 | +import java.util.ArrayList; | ||
25 | +import java.util.Iterator; | ||
26 | +import java.util.List; | ||
27 | +import java.util.Objects; | ||
28 | + | ||
29 | +/** | ||
30 | + * Provides implementation of BGP wide community integer subtlv. | ||
31 | + */ | ||
32 | +public class WideCommunityInteger implements BgpValueType { | ||
33 | + public static final short TYPE = 4; | ||
34 | + private List<Integer> integer; | ||
35 | + | ||
36 | + /** | ||
37 | + * Creates an instance of wide community integer subtlv. | ||
38 | + * | ||
39 | + * @param integer integer | ||
40 | + */ | ||
41 | + public WideCommunityInteger(List<Integer> integer) { | ||
42 | + this.integer = integer; | ||
43 | + } | ||
44 | + | ||
45 | + /** | ||
46 | + * Returns object of this class with specified values. | ||
47 | + * | ||
48 | + * @param integer wide community subtlv integer | ||
49 | + * @return object of WideCommunityInteger | ||
50 | + */ | ||
51 | + public static WideCommunityInteger of(List<Integer> integer) { | ||
52 | + return new WideCommunityInteger(integer); | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * Returns wide community subtlv integer. | ||
57 | + * | ||
58 | + * @return wide community subtlv integer | ||
59 | + */ | ||
60 | + public List<Integer> integer() { | ||
61 | + return integer; | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * Sets wide community subtlv integer. | ||
66 | + * | ||
67 | + * @param integer wide community subtlv integer | ||
68 | + */ | ||
69 | + public void setInteger(List<Integer> integer) { | ||
70 | + this.integer = integer; | ||
71 | + } | ||
72 | + | ||
73 | + @Override | ||
74 | + public int hashCode() { | ||
75 | + return Objects.hash(integer); | ||
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 WideCommunityInteger) { | ||
89 | + WideCommunityInteger other = (WideCommunityInteger) obj; | ||
90 | + return Objects.equals(integer, other.integer); | ||
91 | + } | ||
92 | + return false; | ||
93 | + } | ||
94 | + | ||
95 | + @Override | ||
96 | + public int write(ChannelBuffer c) { | ||
97 | + int iLenStartIndex = c.writerIndex(); | ||
98 | + | ||
99 | + Iterator<Integer> listIterator = integer.iterator(); | ||
100 | + c.writeByte(TYPE); | ||
101 | + | ||
102 | + int iLengthIndex = c.writerIndex(); | ||
103 | + c.writeShort(0); | ||
104 | + | ||
105 | + while (listIterator.hasNext()) { | ||
106 | + Integer integer = listIterator.next(); | ||
107 | + if (integer instanceof Integer) { | ||
108 | + c.writeInt(integer); | ||
109 | + } | ||
110 | + } | ||
111 | + | ||
112 | + int length = c.writerIndex() - iLengthIndex; | ||
113 | + c.setShort(iLengthIndex, (short) (length - 2)); | ||
114 | + | ||
115 | + return c.writerIndex() - iLenStartIndex; | ||
116 | + } | ||
117 | + | ||
118 | + /** | ||
119 | + * Reads the channel buffer and returns object of WideCommunityInteger. | ||
120 | + * | ||
121 | + * @param c ChannelBuffer | ||
122 | + * @return object of WideCommunityInteger | ||
123 | + * @throws BgpParseException on read error | ||
124 | + */ | ||
125 | + public static WideCommunityInteger read(ChannelBuffer c) throws BgpParseException { | ||
126 | + | ||
127 | + List<Integer> integer = new ArrayList<>(); | ||
128 | + short length; | ||
129 | + | ||
130 | + if (c.readableBytes() < 2) { | ||
131 | + Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, | ||
132 | + c.readableBytes()); | ||
133 | + } | ||
134 | + | ||
135 | + length = c.readShort(); | ||
136 | + if (length == 0) { | ||
137 | + return new WideCommunityInteger(integer); | ||
138 | + } | ||
139 | + | ||
140 | + if (c.readableBytes() < length) { | ||
141 | + Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, | ||
142 | + c.readableBytes()); | ||
143 | + } | ||
144 | + | ||
145 | + while (c.readableBytes() > 0) { | ||
146 | + if (c.readableBytes() < 4) { | ||
147 | + Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, | ||
148 | + c.readableBytes()); | ||
149 | + } | ||
150 | + integer.add(c.readInt()); | ||
151 | + } | ||
152 | + | ||
153 | + return new WideCommunityInteger(integer); | ||
154 | + } | ||
155 | + | ||
156 | + @Override | ||
157 | + public String toString() { | ||
158 | + return MoreObjects.toStringHelper(getClass()) | ||
159 | + .omitNullValues() | ||
160 | + .add("integer", integer) | ||
161 | + .toString(); | ||
162 | + } | ||
163 | + | ||
164 | + @Override | ||
165 | + public int compareTo(Object o) { | ||
166 | + // TODO Auto-generated method stub | ||
167 | + return 0; | ||
168 | + } | ||
169 | + | ||
170 | + @Override | ||
171 | + public short getType() { | ||
172 | + // TODO Auto-generated method stub | ||
173 | + return 0; | ||
174 | + } | ||
175 | +} |
protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/WideCommunityIpV4Neighbour.java
0 → 100644
1 | +/* | ||
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 | + */ | ||
16 | +package org.onosproject.bgpio.types; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | + | ||
20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
21 | +import org.onlab.packet.IpAddress; | ||
22 | +import org.onosproject.bgpio.exceptions.BgpParseException; | ||
23 | +import org.onosproject.bgpio.util.Validation; | ||
24 | +import java.util.ArrayList; | ||
25 | +import java.util.Iterator; | ||
26 | +import java.util.List; | ||
27 | +import java.util.Objects; | ||
28 | + | ||
29 | +/** | ||
30 | + * Provides implementation of BGP wide community IPV4 neighbour subtlv. | ||
31 | + */ | ||
32 | +public class WideCommunityIpV4Neighbour implements BgpValueType { | ||
33 | + public static final byte TYPE = 8; | ||
34 | + private List<IpV4Neighbour> ipv4Neighbour; | ||
35 | + public static final byte IPV4_NEIGHBOUR_SIZE = 8; | ||
36 | + | ||
37 | + /** | ||
38 | + * Creates an instance of wide community ipv4 neighbour subtlv. | ||
39 | + * | ||
40 | + */ | ||
41 | + public WideCommunityIpV4Neighbour() { | ||
42 | + this.ipv4Neighbour = new ArrayList<>(); | ||
43 | + } | ||
44 | + | ||
45 | + /** | ||
46 | + * Adds local and remote speakers. | ||
47 | + * | ||
48 | + * @param localSpeaker local speaker | ||
49 | + * @param remoteSpeaker remote speaker | ||
50 | + */ | ||
51 | + public void add(IpAddress localSpeaker, IpAddress remoteSpeaker) { | ||
52 | + ipv4Neighbour.add(new IpV4Neighbour(localSpeaker, remoteSpeaker)); | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * Deletes local and remote speakers. | ||
57 | + * | ||
58 | + * @param localSpeaker local speaker | ||
59 | + * @param remoteSpeaker remote speaker | ||
60 | + */ | ||
61 | + public void remove(IpAddress localSpeaker, IpAddress remoteSpeaker) { | ||
62 | + ipv4Neighbour.remove(new IpV4Neighbour(localSpeaker, remoteSpeaker)); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public int hashCode() { | ||
67 | + return Objects.hash(ipv4Neighbour); | ||
68 | + } | ||
69 | + | ||
70 | + @Override | ||
71 | + public boolean equals(Object obj) { | ||
72 | + if (this == obj) { | ||
73 | + return true; | ||
74 | + } | ||
75 | + | ||
76 | + if (obj == null) { | ||
77 | + return false; | ||
78 | + } | ||
79 | + | ||
80 | + if (obj instanceof WideCommunityIpV4Neighbour) { | ||
81 | + WideCommunityIpV4Neighbour other = (WideCommunityIpV4Neighbour) obj; | ||
82 | + return Objects.equals(ipv4Neighbour, other.ipv4Neighbour); | ||
83 | + } | ||
84 | + return false; | ||
85 | + } | ||
86 | + | ||
87 | + @Override | ||
88 | + public int write(ChannelBuffer c) { | ||
89 | + int iLenStartIndex = c.writerIndex(); | ||
90 | + | ||
91 | + Iterator<IpV4Neighbour> listIterator = ipv4Neighbour.iterator(); | ||
92 | + c.writeByte(TYPE); | ||
93 | + | ||
94 | + int iLengthIndex = c.writerIndex(); | ||
95 | + c.writeShort(0); | ||
96 | + | ||
97 | + while (listIterator.hasNext()) { | ||
98 | + IpV4Neighbour speaker = listIterator.next(); | ||
99 | + if (speaker instanceof IpV4Neighbour) { | ||
100 | + c.writeInt(Integer.valueOf(speaker.localSpeaker.toString())); | ||
101 | + c.writeInt(Integer.valueOf(speaker.remoteSpeaker.toString())); | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + int length = c.writerIndex() - iLengthIndex; | ||
106 | + c.setShort(iLengthIndex, (short) (length - 2)); | ||
107 | + | ||
108 | + return c.writerIndex() - iLenStartIndex; | ||
109 | + } | ||
110 | + | ||
111 | + /** | ||
112 | + * Reads the channel buffer and returns object of WideCommunityIpV4Neighbour. | ||
113 | + * | ||
114 | + * @param c ChannelBuffer | ||
115 | + * @return object of WideCommunityIpV4Neighbour | ||
116 | + * @throws BgpParseException on read error | ||
117 | + */ | ||
118 | + public static WideCommunityIpV4Neighbour read(ChannelBuffer c) throws BgpParseException { | ||
119 | + WideCommunityIpV4Neighbour wideCommNeighbour = new WideCommunityIpV4Neighbour(); | ||
120 | + short length; | ||
121 | + | ||
122 | + if (c.readableBytes() == 0) { | ||
123 | + Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, | ||
124 | + c.readableBytes()); | ||
125 | + } | ||
126 | + | ||
127 | + length = c.readShort(); | ||
128 | + if (c.readableBytes() == 0) { | ||
129 | + return wideCommNeighbour; | ||
130 | + } | ||
131 | + | ||
132 | + if (c.readableBytes() < length) { | ||
133 | + Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, | ||
134 | + c.readableBytes()); | ||
135 | + } | ||
136 | + | ||
137 | + while (c.readableBytes() > 0) { | ||
138 | + if (c.readableBytes() < IPV4_NEIGHBOUR_SIZE) { | ||
139 | + Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, | ||
140 | + c.readableBytes()); | ||
141 | + } | ||
142 | + | ||
143 | + IpAddress localSpeaker = IpAddress.valueOf(c.readInt()); | ||
144 | + IpAddress remoteSpeaker = IpAddress.valueOf(c.readInt()); | ||
145 | + | ||
146 | + wideCommNeighbour.add(localSpeaker, remoteSpeaker); | ||
147 | + | ||
148 | + } | ||
149 | + | ||
150 | + return wideCommNeighbour; | ||
151 | + } | ||
152 | + | ||
153 | + @Override | ||
154 | + public String toString() { | ||
155 | + return MoreObjects.toStringHelper(getClass()) | ||
156 | + .add("ipv4Neighbour", ipv4Neighbour) | ||
157 | + .toString(); | ||
158 | + } | ||
159 | + | ||
160 | + @Override | ||
161 | + public int compareTo(Object o) { | ||
162 | + // TODO Auto-generated method stub | ||
163 | + return 0; | ||
164 | + } | ||
165 | + | ||
166 | + @Override | ||
167 | + public short getType() { | ||
168 | + // TODO Auto-generated method stub | ||
169 | + return 0; | ||
170 | + } | ||
171 | + | ||
172 | + /* | ||
173 | + * IpV4Neighbour class contain remote and local speaker. | ||
174 | + */ | ||
175 | + private class IpV4Neighbour { | ||
176 | + private IpAddress localSpeaker; | ||
177 | + private IpAddress remoteSpeaker; | ||
178 | + | ||
179 | + /** | ||
180 | + * Creates an instance of ipv4 neighbour. | ||
181 | + * | ||
182 | + * @param localSpeaker ip address of local speaker | ||
183 | + * @param remoteSpeaker ip address of remote speaker | ||
184 | + */ | ||
185 | + public IpV4Neighbour(IpAddress localSpeaker, IpAddress remoteSpeaker) { | ||
186 | + this.localSpeaker = localSpeaker; | ||
187 | + this.remoteSpeaker = remoteSpeaker; | ||
188 | + } | ||
189 | + | ||
190 | + /** | ||
191 | + * Returns IPV4 neighbour local speaker. | ||
192 | + * | ||
193 | + * @return IPV4 neighbour local speaker | ||
194 | + */ | ||
195 | + public IpAddress localSpeaker() { | ||
196 | + return localSpeaker; | ||
197 | + } | ||
198 | + | ||
199 | + /** | ||
200 | + * Returns IPV4 neighbour remote speaker. | ||
201 | + * | ||
202 | + * @return IPV4 neighbour remote speaker | ||
203 | + */ | ||
204 | + public IpAddress remoteSpeaker() { | ||
205 | + return remoteSpeaker; | ||
206 | + } | ||
207 | + } | ||
208 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/WideCommunityParameter.java
0 → 100644
1 | +/* | ||
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 | + */ | ||
16 | +package org.onosproject.bgpio.types; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | + | ||
20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
21 | +import org.onosproject.bgpio.exceptions.BgpParseException; | ||
22 | +import org.onosproject.bgpio.types.attr.WideCommunity; | ||
23 | + | ||
24 | +import java.util.List; | ||
25 | +import java.util.Objects; | ||
26 | + | ||
27 | +/** | ||
28 | + * Provides implementation of BGP wide community parameter. | ||
29 | + */ | ||
30 | +public 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 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
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 | + */ | ||
16 | +package org.onosproject.bgpio.types; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | + | ||
20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
21 | +import org.onosproject.bgpio.exceptions.BgpParseException; | ||
22 | +import org.onosproject.bgpio.types.attr.WideCommunity; | ||
23 | + | ||
24 | +import java.util.List; | ||
25 | +import java.util.Objects; | ||
26 | + | ||
27 | +/** | ||
28 | + * Provides implementation of BGP wide community target. | ||
29 | + */ | ||
30 | +public class WideCommunityTarget implements BgpValueType { | ||
31 | + | ||
32 | + public static final byte TYPE = 1; | ||
33 | + private List<BgpValueType> targetTlv; | ||
34 | + | ||
35 | + /** | ||
36 | + * Creates an instance of Wide community targets. | ||
37 | + * | ||
38 | + * @param targetTlv wide community targets to match | ||
39 | + */ | ||
40 | + public WideCommunityTarget(List<BgpValueType> targetTlv) { | ||
41 | + this.targetTlv = targetTlv; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * Returns object of this class with specified values. | ||
46 | + * | ||
47 | + * @param targetTlv wide community target | ||
48 | + * @return object of WideCommunityTarget | ||
49 | + */ | ||
50 | + public static WideCommunityTarget of(List<BgpValueType> targetTlv) { | ||
51 | + return new WideCommunityTarget(targetTlv); | ||
52 | + } | ||
53 | + | ||
54 | + /** | ||
55 | + * Returns wide community targets. | ||
56 | + * | ||
57 | + * @return wide community targets | ||
58 | + */ | ||
59 | + public List<BgpValueType> targetTlv() { | ||
60 | + return targetTlv; | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * Sets wide community target. | ||
65 | + * | ||
66 | + * @param targetTlv wide community targets to match | ||
67 | + */ | ||
68 | + public void setTargetTlv(List<BgpValueType> targetTlv) { | ||
69 | + this.targetTlv = targetTlv; | ||
70 | + } | ||
71 | + | ||
72 | + @Override | ||
73 | + public int hashCode() { | ||
74 | + return Objects.hash(targetTlv); | ||
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 WideCommunityTarget) { | ||
88 | + WideCommunityTarget other = (WideCommunityTarget) obj; | ||
89 | + return Objects.equals(targetTlv, other.targetTlv); | ||
90 | + } | ||
91 | + return false; | ||
92 | + } | ||
93 | + | ||
94 | + @Override | ||
95 | + public int write(ChannelBuffer c) { | ||
96 | + int iLenStartIndex = c.writerIndex(); | ||
97 | + WideCommunity.encodeWideCommunityTlv(c, targetTlv()); | ||
98 | + return c.writerIndex() - iLenStartIndex; | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * Reads the channel buffer and returns object of WideCommunityTarget. | ||
103 | + * | ||
104 | + * @param c ChannelBuffer | ||
105 | + * @return object of WideCommunityTarget | ||
106 | + * @throws BgpParseException on read error | ||
107 | + */ | ||
108 | + public static WideCommunityTarget read(ChannelBuffer c) throws BgpParseException { | ||
109 | + return new WideCommunityTarget(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 | + .add("Type", TYPE) | ||
121 | + .add("targetTlv", targetTlv) | ||
122 | + .toString(); | ||
123 | + } | ||
124 | + | ||
125 | + @Override | ||
126 | + public int compareTo(Object o) { | ||
127 | + // TODO Auto-generated method stub | ||
128 | + return 0; | ||
129 | + } | ||
130 | +} |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment