Committed by
Gerrit Code Review
[ONOS-4241]Codec for wide community and flow spec
Change-Id: I2dfd6b88c4ae14a02d258a2cdc9ee35b9ff08292
Showing
13 changed files
with
316 additions
and
549 deletions
... | @@ -19,9 +19,10 @@ import org.jboss.netty.channel.Channel; | ... | @@ -19,9 +19,10 @@ import org.jboss.netty.channel.Channel; |
19 | import org.onosproject.bgpio.exceptions.BgpParseException; | 19 | import org.onosproject.bgpio.exceptions.BgpParseException; |
20 | import org.onosproject.bgpio.protocol.BgpFactory; | 20 | import org.onosproject.bgpio.protocol.BgpFactory; |
21 | import org.onosproject.bgpio.protocol.BgpMessage; | 21 | import org.onosproject.bgpio.protocol.BgpMessage; |
22 | -import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails; | 22 | +import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecNlri; |
23 | -import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix; | 23 | +import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecRouteKey; |
24 | import org.onosproject.bgpio.types.BgpValueType; | 24 | import org.onosproject.bgpio.types.BgpValueType; |
25 | +import org.onosproject.bgpio.types.attr.WideCommunity; | ||
25 | 26 | ||
26 | /** | 27 | /** |
27 | * Represents the peer side of an BGP peer. | 28 | * Represents the peer side of an BGP peer. |
... | @@ -124,14 +125,6 @@ public interface BgpPeer { | ... | @@ -124,14 +125,6 @@ public interface BgpPeer { |
124 | void buildAdjRibIn(List<BgpValueType> pathAttr) throws BgpParseException; | 125 | void buildAdjRibIn(List<BgpValueType> pathAttr) throws BgpParseException; |
125 | 126 | ||
126 | /** | 127 | /** |
127 | - * Update flow specification RIB for each peer. | ||
128 | - * | ||
129 | - * @param pathAttr list of Bgp path attributes | ||
130 | - * @throws BgpParseException while building flow spec RIB | ||
131 | - */ | ||
132 | - void buildFlowSpecRib(List<BgpValueType> pathAttr) throws BgpParseException; | ||
133 | - | ||
134 | - /** | ||
135 | * Return the BGP session info. | 128 | * Return the BGP session info. |
136 | * | 129 | * |
137 | * @return sessionInfo bgp session info | 130 | * @return sessionInfo bgp session info |
... | @@ -142,9 +135,10 @@ public interface BgpPeer { | ... | @@ -142,9 +135,10 @@ public interface BgpPeer { |
142 | * Updates flow specification rule. | 135 | * Updates flow specification rule. |
143 | * | 136 | * |
144 | * @param operType operation type add or delete or update | 137 | * @param operType operation type add or delete or update |
145 | - * @param prefix prefix for the flow rule | 138 | + * @param routeKey flow route key for the flow rule |
146 | * @param flowSpec BGP flow specification components | 139 | * @param flowSpec BGP flow specification components |
140 | + * @param wideCommunity for route policy | ||
147 | */ | 141 | */ |
148 | - void updateFlowSpec(FlowSpecOperation operType, BgpFlowSpecPrefix prefix, | 142 | + void updateFlowSpec(FlowSpecOperation operType, BgpFlowSpecRouteKey routeKey, |
149 | - BgpFlowSpecDetails flowSpec); | 143 | + BgpFlowSpecNlri flowSpec, WideCommunity wideCommunity); |
150 | } | 144 | } | ... | ... |
... | @@ -17,25 +17,44 @@ package org.onosproject.bgpio.protocol.flowspec; | ... | @@ -17,25 +17,44 @@ package org.onosproject.bgpio.protocol.flowspec; |
17 | 17 | ||
18 | import java.util.Iterator; | 18 | import java.util.Iterator; |
19 | import java.util.List; | 19 | import java.util.List; |
20 | +import java.util.ListIterator; | ||
20 | import java.util.Objects; | 21 | import java.util.Objects; |
22 | + | ||
23 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
24 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
25 | +import org.onosproject.bgpio.types.BgpFsDestinationPortNum; | ||
26 | +import org.onosproject.bgpio.types.BgpFsDestinationPrefix; | ||
27 | +import org.onosproject.bgpio.types.BgpFsDscpValue; | ||
28 | +import org.onosproject.bgpio.types.BgpFsFragment; | ||
29 | +import org.onosproject.bgpio.types.BgpFsIcmpCode; | ||
30 | +import org.onosproject.bgpio.types.BgpFsIcmpType; | ||
31 | +import org.onosproject.bgpio.types.BgpFsIpProtocol; | ||
32 | +import org.onosproject.bgpio.types.BgpFsPacketLength; | ||
33 | +import org.onosproject.bgpio.types.BgpFsPortNum; | ||
34 | +import org.onosproject.bgpio.types.BgpFsSourcePortNum; | ||
35 | +import org.onosproject.bgpio.types.BgpFsSourcePrefix; | ||
36 | +import org.onosproject.bgpio.types.BgpFsTcpFlags; | ||
21 | import org.onosproject.bgpio.types.BgpValueType; | 37 | import org.onosproject.bgpio.types.BgpValueType; |
22 | import org.onosproject.bgpio.types.RouteDistinguisher; | 38 | import org.onosproject.bgpio.types.RouteDistinguisher; |
39 | +import org.onosproject.bgpio.util.Constants; | ||
40 | + | ||
23 | import com.google.common.base.MoreObjects; | 41 | import com.google.common.base.MoreObjects; |
24 | 42 | ||
25 | /** | 43 | /** |
26 | * This Class stores flow specification components and action. | 44 | * This Class stores flow specification components and action. |
27 | */ | 45 | */ |
28 | -public class BgpFlowSpecDetails { | 46 | +public class BgpFlowSpecNlri { |
29 | private List<BgpValueType> flowSpecComponents; | 47 | private List<BgpValueType> flowSpecComponents; |
30 | private List<BgpValueType> fsActionTlv; | 48 | private List<BgpValueType> fsActionTlv; |
31 | private RouteDistinguisher routeDistinguisher; | 49 | private RouteDistinguisher routeDistinguisher; |
50 | + public static final short FLOW_SPEC_LEN = 240; | ||
32 | 51 | ||
33 | /** | 52 | /** |
34 | * Flow specification details object constructor with the parameter. | 53 | * Flow specification details object constructor with the parameter. |
35 | * | 54 | * |
36 | * @param flowSpecComponents flow specification components | 55 | * @param flowSpecComponents flow specification components |
37 | */ | 56 | */ |
38 | - public BgpFlowSpecDetails(List<BgpValueType> flowSpecComponents) { | 57 | + public BgpFlowSpecNlri(List<BgpValueType> flowSpecComponents) { |
39 | this.flowSpecComponents = flowSpecComponents; | 58 | this.flowSpecComponents = flowSpecComponents; |
40 | } | 59 | } |
41 | 60 | ||
... | @@ -43,7 +62,7 @@ public class BgpFlowSpecDetails { | ... | @@ -43,7 +62,7 @@ public class BgpFlowSpecDetails { |
43 | * Flow specification details object constructor. | 62 | * Flow specification details object constructor. |
44 | * | 63 | * |
45 | */ | 64 | */ |
46 | - public BgpFlowSpecDetails() { | 65 | + public BgpFlowSpecNlri() { |
47 | 66 | ||
48 | } | 67 | } |
49 | 68 | ||
... | @@ -112,11 +131,11 @@ public class BgpFlowSpecDetails { | ... | @@ -112,11 +131,11 @@ public class BgpFlowSpecDetails { |
112 | return true; | 131 | return true; |
113 | } | 132 | } |
114 | 133 | ||
115 | - if (obj instanceof BgpFlowSpecDetails) { | 134 | + if (obj instanceof BgpFlowSpecNlri) { |
116 | int countObjSubTlv = 0; | 135 | int countObjSubTlv = 0; |
117 | int countOtherSubTlv = 0; | 136 | int countOtherSubTlv = 0; |
118 | boolean isCommonSubTlv = true; | 137 | boolean isCommonSubTlv = true; |
119 | - BgpFlowSpecDetails other = (BgpFlowSpecDetails) obj; | 138 | + BgpFlowSpecNlri other = (BgpFlowSpecNlri) obj; |
120 | Iterator<BgpValueType> objListIterator = other.flowSpecComponents.iterator(); | 139 | Iterator<BgpValueType> objListIterator = other.flowSpecComponents.iterator(); |
121 | countOtherSubTlv = other.flowSpecComponents.size(); | 140 | countOtherSubTlv = other.flowSpecComponents.size(); |
122 | countObjSubTlv = flowSpecComponents.size(); | 141 | countObjSubTlv = flowSpecComponents.size(); |
... | @@ -138,6 +157,133 @@ public class BgpFlowSpecDetails { | ... | @@ -138,6 +157,133 @@ public class BgpFlowSpecDetails { |
138 | return false; | 157 | return false; |
139 | } | 158 | } |
140 | 159 | ||
160 | + /** | ||
161 | + * Write flow type to channel buffer. | ||
162 | + * | ||
163 | + * @param tlv flow type | ||
164 | + * @param cb channel buffer | ||
165 | + */ | ||
166 | + public static void writeFlowType(BgpValueType tlv, ChannelBuffer cb) { | ||
167 | + | ||
168 | + switch (tlv.getType()) { | ||
169 | + case Constants.BGP_FLOWSPEC_DST_PREFIX: | ||
170 | + BgpFsDestinationPrefix fsDstPrefix = (BgpFsDestinationPrefix) tlv; | ||
171 | + fsDstPrefix.write(cb); | ||
172 | + break; | ||
173 | + case Constants.BGP_FLOWSPEC_SRC_PREFIX: | ||
174 | + BgpFsSourcePrefix fsSrcPrefix = (BgpFsSourcePrefix) tlv; | ||
175 | + fsSrcPrefix.write(cb); | ||
176 | + break; | ||
177 | + case Constants.BGP_FLOWSPEC_IP_PROTO: | ||
178 | + BgpFsIpProtocol fsIpProtocol = (BgpFsIpProtocol) tlv; | ||
179 | + fsIpProtocol.write(cb); | ||
180 | + break; | ||
181 | + case Constants.BGP_FLOWSPEC_PORT: | ||
182 | + BgpFsPortNum fsPortNum = (BgpFsPortNum) tlv; | ||
183 | + fsPortNum.write(cb); | ||
184 | + break; | ||
185 | + case Constants.BGP_FLOWSPEC_DST_PORT: | ||
186 | + BgpFsDestinationPortNum fsDstPortNum = (BgpFsDestinationPortNum) tlv; | ||
187 | + fsDstPortNum.write(cb); | ||
188 | + break; | ||
189 | + case Constants.BGP_FLOWSPEC_SRC_PORT: | ||
190 | + BgpFsSourcePortNum fsSrcPortNum = (BgpFsSourcePortNum) tlv; | ||
191 | + fsSrcPortNum.write(cb); | ||
192 | + break; | ||
193 | + case Constants.BGP_FLOWSPEC_ICMP_TP: | ||
194 | + BgpFsIcmpType fsIcmpType = (BgpFsIcmpType) tlv; | ||
195 | + fsIcmpType.write(cb); | ||
196 | + break; | ||
197 | + case Constants.BGP_FLOWSPEC_ICMP_CD: | ||
198 | + BgpFsIcmpCode fsIcmpCode = (BgpFsIcmpCode) tlv; | ||
199 | + fsIcmpCode.write(cb); | ||
200 | + break; | ||
201 | + case Constants.BGP_FLOWSPEC_TCP_FLAGS: | ||
202 | + BgpFsTcpFlags fsTcpFlags = (BgpFsTcpFlags) tlv; | ||
203 | + fsTcpFlags.write(cb); | ||
204 | + break; | ||
205 | + case Constants.BGP_FLOWSPEC_PCK_LEN: | ||
206 | + BgpFsPacketLength fsPacketLen = (BgpFsPacketLength) tlv; | ||
207 | + fsPacketLen.write(cb); | ||
208 | + break; | ||
209 | + case Constants.BGP_FLOWSPEC_DSCP: | ||
210 | + BgpFsDscpValue fsDscpVal = (BgpFsDscpValue) tlv; | ||
211 | + fsDscpVal.write(cb); | ||
212 | + break; | ||
213 | + case Constants.BGP_FLOWSPEC_FRAGMENT: | ||
214 | + BgpFsFragment fsFragment = (BgpFsFragment) tlv; | ||
215 | + fsFragment.write(cb); | ||
216 | + break; | ||
217 | + default: | ||
218 | + break; | ||
219 | + } | ||
220 | + return; | ||
221 | + } | ||
222 | + | ||
223 | + /** | ||
224 | + * Update buffer with identical flow types. | ||
225 | + * | ||
226 | + * @param cb channel buffer | ||
227 | + */ | ||
228 | + public static void updateBufferIdenticalFlowTypes(ChannelBuffer cb, BgpFlowSpecNlri bgpFlowSpecNlri) { | ||
229 | + | ||
230 | + List<BgpValueType> flowSpec = bgpFlowSpecNlri.flowSpecComponents(); | ||
231 | + ListIterator<BgpValueType> listIterator = flowSpec.listIterator(); | ||
232 | + | ||
233 | + while (listIterator.hasNext()) { | ||
234 | + ChannelBuffer flowSpecTmpBuff = ChannelBuffers.dynamicBuffer(); | ||
235 | + int tmpBuffStartIndx = flowSpecTmpBuff.writerIndex(); | ||
236 | + | ||
237 | + BgpValueType tlv = listIterator.next(); | ||
238 | + writeFlowType(tlv, flowSpecTmpBuff); | ||
239 | + | ||
240 | + /* RFC 5575: section 4, If the NLRI length value is smaller than 240 (0xf0 hex), the length | ||
241 | + field can be encoded as a single octet. Otherwise, it is encoded as | ||
242 | + an extended-length 2-octet values */ | ||
243 | + int len = flowSpecTmpBuff.writerIndex() - tmpBuffStartIndx; | ||
244 | + if (len >= FLOW_SPEC_LEN) { | ||
245 | + cb.writeShort(len); | ||
246 | + } else { | ||
247 | + cb.writeByte(len); | ||
248 | + } | ||
249 | + //Copy from bynamic buffer to channel buffer | ||
250 | + cb.writeBytes(flowSpecTmpBuff); | ||
251 | + } | ||
252 | + return; | ||
253 | + } | ||
254 | + | ||
255 | + /** | ||
256 | + * Update buffer with non-identical flow types. | ||
257 | + * | ||
258 | + * @param cb channel buffer | ||
259 | + */ | ||
260 | + public static void updateBufferNonIdenticalFlowTypes(ChannelBuffer cb, BgpFlowSpecNlri bgpFlowSpecNlri) { | ||
261 | + ChannelBuffer flowSpecTmpBuff = ChannelBuffers.dynamicBuffer(); | ||
262 | + List<BgpValueType> flowSpec = bgpFlowSpecNlri.flowSpecComponents(); | ||
263 | + ListIterator<BgpValueType> listIterator = flowSpec.listIterator(); | ||
264 | + int tmpBuffStartIndx = flowSpecTmpBuff.writerIndex(); | ||
265 | + | ||
266 | + flowSpec = bgpFlowSpecNlri.flowSpecComponents(); | ||
267 | + listIterator = flowSpec.listIterator(); | ||
268 | + | ||
269 | + while (listIterator.hasNext()) { | ||
270 | + BgpValueType tlv = listIterator.next(); | ||
271 | + writeFlowType(tlv, flowSpecTmpBuff); | ||
272 | + } | ||
273 | + | ||
274 | + /* RFC 5575: section 4, If the NLRI length value is smaller than 240 (0xf0 hex), the length | ||
275 | + field can be encoded as a single octet. Otherwise, it is encoded as | ||
276 | + an extended-length 2-octet values */ | ||
277 | + int len = flowSpecTmpBuff.writerIndex() - tmpBuffStartIndx; | ||
278 | + if (len >= FLOW_SPEC_LEN) { | ||
279 | + cb.writeShort(len); | ||
280 | + } else { | ||
281 | + cb.writeByte(len); | ||
282 | + } | ||
283 | + //Copy from bynamic buffer to channel buffer | ||
284 | + cb.writeBytes(flowSpecTmpBuff); | ||
285 | + } | ||
286 | + | ||
141 | @Override | 287 | @Override |
142 | public String toString() { | 288 | public String toString() { |
143 | return MoreObjects.toStringHelper(getClass()) | 289 | return MoreObjects.toStringHelper(getClass()) | ... | ... |
... | @@ -17,45 +17,41 @@ | ... | @@ -17,45 +17,41 @@ |
17 | package org.onosproject.bgpio.protocol.flowspec; | 17 | package org.onosproject.bgpio.protocol.flowspec; |
18 | 18 | ||
19 | import java.util.Objects; | 19 | import java.util.Objects; |
20 | -import org.onlab.packet.IpPrefix; | ||
21 | import org.slf4j.Logger; | 20 | import org.slf4j.Logger; |
22 | import org.slf4j.LoggerFactory; | 21 | import org.slf4j.LoggerFactory; |
23 | -import java.nio.ByteBuffer; | ||
24 | 22 | ||
25 | import com.google.common.base.MoreObjects; | 23 | import com.google.common.base.MoreObjects; |
26 | 24 | ||
27 | /** | 25 | /** |
28 | - * Provides BGP flow specification rule index. | 26 | + * Provides BGP flow specification route index. |
29 | */ | 27 | */ |
30 | -public class BgpFlowSpecPrefix implements Comparable<Object> { | 28 | +public class BgpFlowSpecRouteKey implements Comparable<Object> { |
31 | 29 | ||
32 | - private static final Logger log = LoggerFactory.getLogger(BgpFlowSpecPrefix.class); | 30 | + private static final Logger log = LoggerFactory.getLogger(BgpFlowSpecRouteKey.class); |
33 | 31 | ||
34 | - private final IpPrefix destinationPrefix; | 32 | + private final String routeKey; |
35 | - private final IpPrefix sourcePrefix; | ||
36 | 33 | ||
37 | /** | 34 | /** |
38 | * Constructor to initialize parameters. | 35 | * Constructor to initialize parameters. |
39 | * | 36 | * |
40 | - * @param destinationPrefix destination prefix | 37 | + * @param routeKey route key |
41 | - * @param sourcePrefix source prefix | ||
42 | */ | 38 | */ |
43 | - public BgpFlowSpecPrefix(IpPrefix destinationPrefix, IpPrefix sourcePrefix) { | 39 | + public BgpFlowSpecRouteKey(String routeKey) { |
44 | - if (destinationPrefix == null) { | 40 | + this.routeKey = routeKey; |
45 | - destinationPrefix = IpPrefix.valueOf(0, 0); | ||
46 | } | 41 | } |
47 | 42 | ||
48 | - if (sourcePrefix == null) { | 43 | + /** |
49 | - sourcePrefix = IpPrefix.valueOf(0, 0); | 44 | + * Returns route key. |
50 | - } | 45 | + * |
51 | - | 46 | + * @return route key |
52 | - this.destinationPrefix = destinationPrefix; | 47 | + */ |
53 | - this.sourcePrefix = sourcePrefix; | 48 | + public String routeKey() { |
49 | + return this.routeKey; | ||
54 | } | 50 | } |
55 | 51 | ||
56 | @Override | 52 | @Override |
57 | public int hashCode() { | 53 | public int hashCode() { |
58 | - return Objects.hash(destinationPrefix, sourcePrefix); | 54 | + return Objects.hashCode(routeKey); |
59 | } | 55 | } |
60 | 56 | ||
61 | @Override | 57 | @Override |
... | @@ -63,93 +59,33 @@ public class BgpFlowSpecPrefix implements Comparable<Object> { | ... | @@ -63,93 +59,33 @@ public class BgpFlowSpecPrefix implements Comparable<Object> { |
63 | if (this == obj) { | 59 | if (this == obj) { |
64 | return true; | 60 | return true; |
65 | } | 61 | } |
66 | - | 62 | + if (obj instanceof BgpFlowSpecRouteKey) { |
67 | - if (obj instanceof BgpFlowSpecPrefix) { | 63 | + BgpFlowSpecRouteKey other = (BgpFlowSpecRouteKey) obj; |
68 | - BgpFlowSpecPrefix other = (BgpFlowSpecPrefix) obj; | 64 | + return this.routeKey.equals(other.routeKey); |
69 | - | ||
70 | - if ((this.destinationPrefix != null) && (this.sourcePrefix != null) | ||
71 | - && (this.destinationPrefix.equals(other.destinationPrefix))) { | ||
72 | - return this.sourcePrefix.equals(other.sourcePrefix); | ||
73 | - } else if (this.destinationPrefix != null) { | ||
74 | - return this.destinationPrefix.equals(other.destinationPrefix); | ||
75 | - } else if (this.sourcePrefix != null) { | ||
76 | - return this.sourcePrefix.equals(other.sourcePrefix); | ||
77 | - } | ||
78 | - return false; | ||
79 | } | 65 | } |
80 | return false; | 66 | return false; |
81 | } | 67 | } |
82 | 68 | ||
83 | - /** | ||
84 | - * Returns destination prefix. | ||
85 | - * | ||
86 | - * @return destination prefix | ||
87 | - */ | ||
88 | - public IpPrefix destinationPrefix() { | ||
89 | - return this.destinationPrefix; | ||
90 | - } | ||
91 | - | ||
92 | - /** | ||
93 | - * Returns source prefix. | ||
94 | - * | ||
95 | - * @return source prefix | ||
96 | - */ | ||
97 | - public IpPrefix sourcePrefix() { | ||
98 | - return this.sourcePrefix; | ||
99 | - } | ||
100 | - | ||
101 | @Override | 69 | @Override |
102 | - public String toString() { | ||
103 | - return MoreObjects.toStringHelper(getClass()).omitNullValues() | ||
104 | - .add("destinationPrefix", destinationPrefix) | ||
105 | - .add("sourcePrefix", destinationPrefix) | ||
106 | - .toString(); | ||
107 | - } | ||
108 | - | ||
109 | - /** | ||
110 | - * Compares this and o object. | ||
111 | - * | ||
112 | - * @param o object to be compared with this object | ||
113 | - * @return which object is greater | ||
114 | - */ | ||
115 | public int compareTo(Object o) { | 70 | public int compareTo(Object o) { |
116 | if (this.equals(o)) { | 71 | if (this.equals(o)) { |
117 | return 0; | 72 | return 0; |
118 | } | 73 | } |
119 | 74 | ||
120 | - if (o instanceof BgpFlowSpecPrefix) { | 75 | + if (o instanceof BgpFlowSpecRouteKey) { |
121 | - BgpFlowSpecPrefix that = (BgpFlowSpecPrefix) o; | 76 | + BgpFlowSpecRouteKey other = (BgpFlowSpecRouteKey) o; |
122 | - if (this.destinationPrefix() != null) { | 77 | + if (this.routeKey.compareTo(other.routeKey) != 0) { |
123 | - if (this.destinationPrefix().prefixLength() == that.destinationPrefix().prefixLength()) { | 78 | + return this.routeKey.compareTo(other.routeKey); |
124 | - ByteBuffer value1 = ByteBuffer.wrap(this.destinationPrefix().address().toOctets()); | ||
125 | - ByteBuffer value2 = ByteBuffer.wrap(that.destinationPrefix().address().toOctets()); | ||
126 | - int cmpVal = value1.compareTo(value2); | ||
127 | - if (cmpVal != 0) { | ||
128 | - return cmpVal; | ||
129 | - } | ||
130 | - } else { | ||
131 | - if (this.destinationPrefix().prefixLength() > that.destinationPrefix().prefixLength()) { | ||
132 | - return 1; | ||
133 | - } else if (this.destinationPrefix().prefixLength() < that.destinationPrefix().prefixLength()) { | ||
134 | - return -1; | ||
135 | - } | ||
136 | - } | ||
137 | - } | ||
138 | - if (this.sourcePrefix() != null) { | ||
139 | - if (this.sourcePrefix().prefixLength() == that.sourcePrefix().prefixLength()) { | ||
140 | - ByteBuffer value1 = ByteBuffer.wrap(this.sourcePrefix().address().toOctets()); | ||
141 | - ByteBuffer value2 = ByteBuffer.wrap(that.sourcePrefix().address().toOctets()); | ||
142 | - return value1.compareTo(value2); | ||
143 | - } | ||
144 | - | ||
145 | - if (this.sourcePrefix().prefixLength() > that.sourcePrefix().prefixLength()) { | ||
146 | - return 1; | ||
147 | - } else if (this.sourcePrefix().prefixLength() < that.sourcePrefix().prefixLength()) { | ||
148 | - return -1; | ||
149 | - } | ||
150 | } | 79 | } |
151 | return 0; | 80 | return 0; |
152 | } | 81 | } |
153 | return 1; | 82 | return 1; |
154 | } | 83 | } |
84 | + | ||
85 | + @Override | ||
86 | + public String toString() { | ||
87 | + return MoreObjects.toStringHelper(getClass()).omitNullValues() | ||
88 | + .add("routeKey", routeKey) | ||
89 | + .toString(); | ||
90 | + } | ||
155 | } | 91 | } | ... | ... |
... | @@ -22,11 +22,10 @@ import java.util.List; | ... | @@ -22,11 +22,10 @@ import java.util.List; |
22 | import java.util.ListIterator; | 22 | import java.util.ListIterator; |
23 | 23 | ||
24 | import org.jboss.netty.buffer.ChannelBuffer; | 24 | import org.jboss.netty.buffer.ChannelBuffer; |
25 | -import org.jboss.netty.buffer.ChannelBuffers; | ||
26 | import org.onlab.packet.Ip4Address; | 25 | import org.onlab.packet.Ip4Address; |
27 | import org.onosproject.bgpio.exceptions.BgpParseException; | 26 | import org.onosproject.bgpio.exceptions.BgpParseException; |
28 | import org.onosproject.bgpio.protocol.BgpLSNlri; | 27 | import org.onosproject.bgpio.protocol.BgpLSNlri; |
29 | -import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails; | 28 | +import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecNlri; |
30 | import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4; | 29 | import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4; |
31 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; | 30 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; |
32 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; | 31 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; |
... | @@ -46,14 +45,13 @@ public class MpReachNlri implements BgpValueType { | ... | @@ -46,14 +45,13 @@ public class MpReachNlri implements BgpValueType { |
46 | public static final byte MPREACHNLRI_TYPE = 14; | 45 | public static final byte MPREACHNLRI_TYPE = 14; |
47 | public static final byte LINK_NLRITYPE = 2; | 46 | public static final byte LINK_NLRITYPE = 2; |
48 | public static final byte FLAGS = (byte) 0x90; | 47 | public static final byte FLAGS = (byte) 0x90; |
49 | - public static final short FLOW_SPEC_LEN = 240; | ||
50 | private boolean isMpReachNlri = false; | 48 | private boolean isMpReachNlri = false; |
51 | private final List<BgpLSNlri> mpReachNlri; | 49 | private final List<BgpLSNlri> mpReachNlri; |
52 | private final int length; | 50 | private final int length; |
53 | private final short afi; | 51 | private final short afi; |
54 | private final byte safi; | 52 | private final byte safi; |
55 | private final Ip4Address ipNextHop; | 53 | private final Ip4Address ipNextHop; |
56 | - private BgpFlowSpecDetails bgpFlowSpecInfo; | 54 | + private BgpFlowSpecNlri bgpFlowSpecNlri; |
57 | 55 | ||
58 | /** | 56 | /** |
59 | * Constructor to initialize parameters. | 57 | * Constructor to initialize parameters. |
... | @@ -73,12 +71,12 @@ public class MpReachNlri implements BgpValueType { | ... | @@ -73,12 +71,12 @@ public class MpReachNlri implements BgpValueType { |
73 | this.length = length; | 71 | this.length = length; |
74 | } | 72 | } |
75 | 73 | ||
76 | - public MpReachNlri(BgpFlowSpecDetails bgpFlowSpecInfo, short afi, byte safi) { | 74 | + public MpReachNlri(BgpFlowSpecNlri bgpFlowSpecNlri, short afi, byte safi) { |
77 | this.mpReachNlri = null; | 75 | this.mpReachNlri = null; |
78 | this.isMpReachNlri = true; | 76 | this.isMpReachNlri = true; |
79 | this.length = 0; | 77 | this.length = 0; |
80 | this.ipNextHop = null; | 78 | this.ipNextHop = null; |
81 | - this.bgpFlowSpecInfo = bgpFlowSpecInfo; | 79 | + this.bgpFlowSpecNlri = bgpFlowSpecNlri; |
82 | this.afi = afi; | 80 | this.afi = afi; |
83 | this.safi = safi; | 81 | this.safi = safi; |
84 | } | 82 | } |
... | @@ -115,8 +113,8 @@ public class MpReachNlri implements BgpValueType { | ... | @@ -115,8 +113,8 @@ public class MpReachNlri implements BgpValueType { |
115 | * | 113 | * |
116 | * @return BGP flow specification info | 114 | * @return BGP flow specification info |
117 | */ | 115 | */ |
118 | - public BgpFlowSpecDetails bgpFlowSpecInfo() { | 116 | + public BgpFlowSpecNlri bgpFlowSpecNlri() { |
119 | - return this.bgpFlowSpecInfo; | 117 | + return this.bgpFlowSpecNlri; |
120 | } | 118 | } |
121 | 119 | ||
122 | /** | 120 | /** |
... | @@ -208,8 +206,13 @@ public class MpReachNlri implements BgpValueType { | ... | @@ -208,8 +206,13 @@ public class MpReachNlri implements BgpValueType { |
208 | routeDistinguisher = new RouteDistinguisher(); | 206 | routeDistinguisher = new RouteDistinguisher(); |
209 | routeDistinguisher = RouteDistinguisher.read(tempCb); | 207 | routeDistinguisher = RouteDistinguisher.read(tempCb); |
210 | } | 208 | } |
209 | + while (tempCb.readableBytes() > 0) { | ||
211 | short totNlriLen = tempCb.getByte(tempCb.readerIndex()); | 210 | short totNlriLen = tempCb.getByte(tempCb.readerIndex()); |
212 | - if (totNlriLen >= FLOW_SPEC_LEN) { | 211 | + if (totNlriLen >= BgpFlowSpecNlri.FLOW_SPEC_LEN) { |
212 | + if (tempCb.readableBytes() < 2) { | ||
213 | + Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, | ||
214 | + BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); | ||
215 | + } | ||
213 | totNlriLen = tempCb.readShort(); | 216 | totNlriLen = tempCb.readShort(); |
214 | } else { | 217 | } else { |
215 | totNlriLen = tempCb.readByte(); | 218 | totNlriLen = tempCb.readByte(); |
... | @@ -265,7 +268,8 @@ public class MpReachNlri implements BgpValueType { | ... | @@ -265,7 +268,8 @@ public class MpReachNlri implements BgpValueType { |
265 | flowSpecComponents.add(flowSpecComponent); | 268 | flowSpecComponents.add(flowSpecComponent); |
266 | } | 269 | } |
267 | } | 270 | } |
268 | - BgpFlowSpecDetails flowSpecDetails = new BgpFlowSpecDetails(flowSpecComponents); | 271 | + } |
272 | + BgpFlowSpecNlri flowSpecDetails = new BgpFlowSpecNlri(flowSpecComponents); | ||
269 | flowSpecDetails.setRouteDistinguiher(routeDistinguisher); | 273 | flowSpecDetails.setRouteDistinguiher(routeDistinguisher); |
270 | return new MpReachNlri(flowSpecDetails, afi, safi); | 274 | return new MpReachNlri(flowSpecDetails, afi, safi); |
271 | } else { | 275 | } else { |
... | @@ -310,8 +314,12 @@ public class MpReachNlri implements BgpValueType { | ... | @@ -310,8 +314,12 @@ public class MpReachNlri implements BgpValueType { |
310 | @Override | 314 | @Override |
311 | public int write(ChannelBuffer cb) { | 315 | public int write(ChannelBuffer cb) { |
312 | int iLenStartIndex = cb.writerIndex(); | 316 | int iLenStartIndex = cb.writerIndex(); |
317 | + | ||
313 | if ((afi == Constants.AFI_FLOWSPEC_VALUE) && ((safi == Constants.SAFI_FLOWSPEC_VALUE) | 318 | if ((afi == Constants.AFI_FLOWSPEC_VALUE) && ((safi == Constants.SAFI_FLOWSPEC_VALUE) |
314 | || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { | 319 | || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { |
320 | + List<BgpValueType> flowSpec = bgpFlowSpecNlri.flowSpecComponents(); | ||
321 | + ListIterator<BgpValueType> listIterator = flowSpec.listIterator(); | ||
322 | + boolean isAllFlowTypesIdentical = true; | ||
315 | 323 | ||
316 | cb.writeByte(FLAGS); | 324 | cb.writeByte(FLAGS); |
317 | cb.writeByte(MPREACHNLRI_TYPE); | 325 | cb.writeByte(MPREACHNLRI_TYPE); |
... | @@ -326,84 +334,27 @@ public class MpReachNlri implements BgpValueType { | ... | @@ -326,84 +334,27 @@ public class MpReachNlri implements BgpValueType { |
326 | //sub network points of attachment | 334 | //sub network points of attachment |
327 | cb.writeByte(0); | 335 | cb.writeByte(0); |
328 | 336 | ||
329 | - if (bgpFlowSpecInfo.routeDistinguisher() != null) { | 337 | + if (bgpFlowSpecNlri.routeDistinguisher() != null) { |
330 | - cb.writeLong(bgpFlowSpecInfo.routeDistinguisher().getRouteDistinguisher()); | 338 | + cb.writeLong(bgpFlowSpecNlri.routeDistinguisher().getRouteDistinguisher()); |
331 | } | 339 | } |
332 | 340 | ||
333 | - ChannelBuffer flowSpecTmpBuff = ChannelBuffers.dynamicBuffer(); | 341 | + BgpValueType tlv1 = null; |
334 | - int tmpBuffStartIndx = flowSpecTmpBuff.writerIndex(); | 342 | + if (listIterator.hasNext()) { |
335 | - | 343 | + tlv1 = listIterator.next(); |
336 | - List<BgpValueType> flowSpec = bgpFlowSpecInfo.flowSpecComponents(); | 344 | + } |
337 | - ListIterator<BgpValueType> listIterator = flowSpec.listIterator(); | ||
338 | - | ||
339 | while (listIterator.hasNext()) { | 345 | while (listIterator.hasNext()) { |
340 | BgpValueType tlv = listIterator.next(); | 346 | BgpValueType tlv = listIterator.next(); |
341 | - switch (tlv.getType()) { | 347 | + if (tlv.getType() != tlv1.getType()) { |
342 | - case Constants.BGP_FLOWSPEC_DST_PREFIX: | 348 | + isAllFlowTypesIdentical = false; |
343 | - BgpFsDestinationPrefix fsDstPrefix = (BgpFsDestinationPrefix) tlv; | ||
344 | - fsDstPrefix.write(flowSpecTmpBuff); | ||
345 | - break; | ||
346 | - case Constants.BGP_FLOWSPEC_SRC_PREFIX: | ||
347 | - BgpFsSourcePrefix fsSrcPrefix = (BgpFsSourcePrefix) tlv; | ||
348 | - fsSrcPrefix.write(flowSpecTmpBuff); | ||
349 | - break; | ||
350 | - case Constants.BGP_FLOWSPEC_IP_PROTO: | ||
351 | - BgpFsIpProtocol fsIpProtocol = (BgpFsIpProtocol) tlv; | ||
352 | - fsIpProtocol.write(flowSpecTmpBuff); | ||
353 | - break; | ||
354 | - case Constants.BGP_FLOWSPEC_PORT: | ||
355 | - BgpFsPortNum fsPortNum = (BgpFsPortNum) tlv; | ||
356 | - fsPortNum.write(flowSpecTmpBuff); | ||
357 | - break; | ||
358 | - case Constants.BGP_FLOWSPEC_DST_PORT: | ||
359 | - BgpFsDestinationPortNum fsDstPortNum = (BgpFsDestinationPortNum) tlv; | ||
360 | - fsDstPortNum.write(flowSpecTmpBuff); | ||
361 | - break; | ||
362 | - case Constants.BGP_FLOWSPEC_SRC_PORT: | ||
363 | - BgpFsSourcePortNum fsSrcPortNum = (BgpFsSourcePortNum) tlv; | ||
364 | - fsSrcPortNum.write(flowSpecTmpBuff); | ||
365 | - break; | ||
366 | - case Constants.BGP_FLOWSPEC_ICMP_TP: | ||
367 | - BgpFsIcmpType fsIcmpType = (BgpFsIcmpType) tlv; | ||
368 | - fsIcmpType.write(flowSpecTmpBuff); | ||
369 | - break; | ||
370 | - case Constants.BGP_FLOWSPEC_ICMP_CD: | ||
371 | - BgpFsIcmpCode fsIcmpCode = (BgpFsIcmpCode) tlv; | ||
372 | - fsIcmpCode.write(flowSpecTmpBuff); | ||
373 | - break; | ||
374 | - case Constants.BGP_FLOWSPEC_TCP_FLAGS: | ||
375 | - BgpFsTcpFlags fsTcpFlags = (BgpFsTcpFlags) tlv; | ||
376 | - fsTcpFlags.write(flowSpecTmpBuff); | ||
377 | - break; | ||
378 | - case Constants.BGP_FLOWSPEC_PCK_LEN: | ||
379 | - BgpFsPacketLength fsPacketLen = (BgpFsPacketLength) tlv; | ||
380 | - fsPacketLen.write(flowSpecTmpBuff); | ||
381 | - break; | ||
382 | - case Constants.BGP_FLOWSPEC_DSCP: | ||
383 | - BgpFsDscpValue fsDscpVal = (BgpFsDscpValue) tlv; | ||
384 | - fsDscpVal.write(flowSpecTmpBuff); | ||
385 | - break; | ||
386 | - case Constants.BGP_FLOWSPEC_FRAGMENT: | ||
387 | - BgpFsFragment fsFragment = (BgpFsFragment) tlv; | ||
388 | - fsFragment.write(flowSpecTmpBuff); | ||
389 | - break; | ||
390 | - default: | ||
391 | break; | 349 | break; |
392 | } | 350 | } |
393 | } | 351 | } |
394 | 352 | ||
395 | - /* RFC 5575: section 4, If the NLRI length value is smaller than 240 (0xf0 hex), the length | 353 | + if (isAllFlowTypesIdentical) { |
396 | - field can be encoded as a single octet. Otherwise, it is encoded as | 354 | + BgpFlowSpecNlri.updateBufferIdenticalFlowTypes(cb, bgpFlowSpecNlri()); |
397 | - an extended-length 2-octet values */ | ||
398 | - int len = flowSpecTmpBuff.writerIndex() - tmpBuffStartIndx; | ||
399 | - if (len >= FLOW_SPEC_LEN) { | ||
400 | - cb.writeShort(len); | ||
401 | } else { | 355 | } else { |
402 | - cb.writeByte(len); | 356 | + BgpFlowSpecNlri.updateBufferNonIdenticalFlowTypes(cb, bgpFlowSpecNlri()); |
403 | } | 357 | } |
404 | - //Copy from bynamic buffer to channel buffer | ||
405 | - cb.writeBytes(flowSpecTmpBuff); | ||
406 | - | ||
407 | int fsNlriLen = cb.writerIndex() - mpReachDataIndx; | 358 | int fsNlriLen = cb.writerIndex() - mpReachDataIndx; |
408 | cb.setShort(mpReachDataIndx, (short) (fsNlriLen - 2)); | 359 | cb.setShort(mpReachDataIndx, (short) (fsNlriLen - 2)); |
409 | 360 | ||
... | @@ -416,7 +367,7 @@ public class MpReachNlri implements BgpValueType { | ... | @@ -416,7 +367,7 @@ public class MpReachNlri implements BgpValueType { |
416 | public String toString() { | 367 | public String toString() { |
417 | return MoreObjects.toStringHelper(getClass()).omitNullValues() | 368 | return MoreObjects.toStringHelper(getClass()).omitNullValues() |
418 | .add("mpReachNlri", mpReachNlri) | 369 | .add("mpReachNlri", mpReachNlri) |
419 | - .add("bgpFlowSpecInfo", bgpFlowSpecInfo) | 370 | + .add("bgpFlowSpecNlri", bgpFlowSpecNlri) |
420 | .add("afi", afi) | 371 | .add("afi", afi) |
421 | .add("safi", safi) | 372 | .add("safi", safi) |
422 | .add("ipNextHop", ipNextHop) | 373 | .add("ipNextHop", ipNextHop) | ... | ... |
... | @@ -21,10 +21,9 @@ import java.util.List; | ... | @@ -21,10 +21,9 @@ import java.util.List; |
21 | import java.util.ListIterator; | 21 | import java.util.ListIterator; |
22 | 22 | ||
23 | import org.jboss.netty.buffer.ChannelBuffer; | 23 | import org.jboss.netty.buffer.ChannelBuffer; |
24 | -import org.jboss.netty.buffer.ChannelBuffers; | ||
25 | import org.onosproject.bgpio.exceptions.BgpParseException; | 24 | import org.onosproject.bgpio.exceptions.BgpParseException; |
26 | import org.onosproject.bgpio.protocol.BgpLSNlri; | 25 | import org.onosproject.bgpio.protocol.BgpLSNlri; |
27 | -import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails; | 26 | +import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecNlri; |
28 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; | 27 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; |
29 | import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4; | 28 | import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4; |
30 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; | 29 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; |
... | @@ -44,13 +43,12 @@ public class MpUnReachNlri implements BgpValueType { | ... | @@ -44,13 +43,12 @@ public class MpUnReachNlri implements BgpValueType { |
44 | public static final byte MPUNREACHNLRI_TYPE = 15; | 43 | public static final byte MPUNREACHNLRI_TYPE = 15; |
45 | public static final byte LINK_NLRITYPE = 2; | 44 | public static final byte LINK_NLRITYPE = 2; |
46 | public static final byte FLAGS = (byte) 0x90; | 45 | public static final byte FLAGS = (byte) 0x90; |
47 | - public static final short FLOW_SPEC_LEN = 240; | ||
48 | private boolean isMpUnReachNlri = false; | 46 | private boolean isMpUnReachNlri = false; |
49 | private final short afi; | 47 | private final short afi; |
50 | private final byte safi; | 48 | private final byte safi; |
51 | private final List<BgpLSNlri> mpUnReachNlri; | 49 | private final List<BgpLSNlri> mpUnReachNlri; |
52 | private final int length; | 50 | private final int length; |
53 | - private BgpFlowSpecDetails bgpFlowSpecInfo; | 51 | + private BgpFlowSpecNlri bgpFlowSpecNlri; |
54 | 52 | ||
55 | /** | 53 | /** |
56 | * Constructor to initialize parameters. | 54 | * Constructor to initialize parameters. |
... | @@ -69,11 +67,11 @@ public class MpUnReachNlri implements BgpValueType { | ... | @@ -69,11 +67,11 @@ public class MpUnReachNlri implements BgpValueType { |
69 | this.length = length; | 67 | this.length = length; |
70 | } | 68 | } |
71 | 69 | ||
72 | - public MpUnReachNlri(BgpFlowSpecDetails bgpFlowSpecInfo, short afi, byte safi) { | 70 | + public MpUnReachNlri(BgpFlowSpecNlri bgpFlowSpecNlri, short afi, byte safi) { |
73 | this.mpUnReachNlri = null; | 71 | this.mpUnReachNlri = null; |
74 | this.isMpUnReachNlri = true; | 72 | this.isMpUnReachNlri = true; |
75 | this.length = 0; | 73 | this.length = 0; |
76 | - this.bgpFlowSpecInfo = bgpFlowSpecInfo; | 74 | + this.bgpFlowSpecNlri = bgpFlowSpecNlri; |
77 | this.afi = afi; | 75 | this.afi = afi; |
78 | this.safi = safi; | 76 | this.safi = safi; |
79 | } | 77 | } |
... | @@ -83,8 +81,8 @@ public class MpUnReachNlri implements BgpValueType { | ... | @@ -83,8 +81,8 @@ public class MpUnReachNlri implements BgpValueType { |
83 | * | 81 | * |
84 | * @return BGP flow specification info | 82 | * @return BGP flow specification info |
85 | */ | 83 | */ |
86 | - public BgpFlowSpecDetails bgpFlowSpecInfo() { | 84 | + public BgpFlowSpecNlri bgpFlowSpecNlri() { |
87 | - return this.bgpFlowSpecInfo; | 85 | + return this.bgpFlowSpecNlri; |
88 | } | 86 | } |
89 | 87 | ||
90 | /** | 88 | /** |
... | @@ -162,8 +160,13 @@ public class MpUnReachNlri implements BgpValueType { | ... | @@ -162,8 +160,13 @@ public class MpUnReachNlri implements BgpValueType { |
162 | routeDistinguisher = new RouteDistinguisher(); | 160 | routeDistinguisher = new RouteDistinguisher(); |
163 | routeDistinguisher = RouteDistinguisher.read(tempCb); | 161 | routeDistinguisher = RouteDistinguisher.read(tempCb); |
164 | } | 162 | } |
163 | + while (tempCb.readableBytes() > 0) { | ||
165 | short totNlriLen = tempCb.getByte(tempCb.readerIndex()); | 164 | short totNlriLen = tempCb.getByte(tempCb.readerIndex()); |
166 | - if (totNlriLen >= FLOW_SPEC_LEN) { | 165 | + if (totNlriLen >= BgpFlowSpecNlri.FLOW_SPEC_LEN) { |
166 | + if (tempCb.readableBytes() < 2) { | ||
167 | + Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, | ||
168 | + BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); | ||
169 | + } | ||
167 | totNlriLen = tempCb.readShort(); | 170 | totNlriLen = tempCb.readShort(); |
168 | } else { | 171 | } else { |
169 | totNlriLen = tempCb.readByte(); | 172 | totNlriLen = tempCb.readByte(); |
... | @@ -198,7 +201,7 @@ public class MpUnReachNlri implements BgpValueType { | ... | @@ -198,7 +201,7 @@ public class MpUnReachNlri implements BgpValueType { |
198 | flowSpecComponent = BgpFsIcmpType.read(tempBuf); | 201 | flowSpecComponent = BgpFsIcmpType.read(tempBuf); |
199 | break; | 202 | break; |
200 | case Constants.BGP_FLOWSPEC_ICMP_CD: | 203 | case Constants.BGP_FLOWSPEC_ICMP_CD: |
201 | - flowSpecComponent = BgpFsIcmpType.read(tempBuf); | 204 | + flowSpecComponent = BgpFsIcmpCode.read(tempBuf); |
202 | break; | 205 | break; |
203 | case Constants.BGP_FLOWSPEC_TCP_FLAGS: | 206 | case Constants.BGP_FLOWSPEC_TCP_FLAGS: |
204 | flowSpecComponent = BgpFsTcpFlags.read(tempBuf); | 207 | flowSpecComponent = BgpFsTcpFlags.read(tempBuf); |
... | @@ -219,7 +222,8 @@ public class MpUnReachNlri implements BgpValueType { | ... | @@ -219,7 +222,8 @@ public class MpUnReachNlri implements BgpValueType { |
219 | flowSpecComponents.add(flowSpecComponent); | 222 | flowSpecComponents.add(flowSpecComponent); |
220 | } | 223 | } |
221 | } | 224 | } |
222 | - BgpFlowSpecDetails flowSpecDetails = new BgpFlowSpecDetails(flowSpecComponents); | 225 | + } |
226 | + BgpFlowSpecNlri flowSpecDetails = new BgpFlowSpecNlri(flowSpecComponents); | ||
223 | flowSpecDetails.setRouteDistinguiher(routeDistinguisher); | 227 | flowSpecDetails.setRouteDistinguiher(routeDistinguisher); |
224 | return new MpUnReachNlri(flowSpecDetails, afi, safi); | 228 | return new MpUnReachNlri(flowSpecDetails, afi, safi); |
225 | } else { | 229 | } else { |
... | @@ -286,6 +290,9 @@ public class MpUnReachNlri implements BgpValueType { | ... | @@ -286,6 +290,9 @@ public class MpUnReachNlri implements BgpValueType { |
286 | int iLenStartIndex = cb.writerIndex(); | 290 | int iLenStartIndex = cb.writerIndex(); |
287 | if ((afi == Constants.AFI_FLOWSPEC_VALUE) && ((safi == Constants.SAFI_FLOWSPEC_VALUE) || | 291 | if ((afi == Constants.AFI_FLOWSPEC_VALUE) && ((safi == Constants.SAFI_FLOWSPEC_VALUE) || |
288 | (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { | 292 | (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { |
293 | + List<BgpValueType> flowSpec = bgpFlowSpecNlri.flowSpecComponents(); | ||
294 | + ListIterator<BgpValueType> listIterator = flowSpec.listIterator(); | ||
295 | + boolean isAllFlowTypesIdentical = true; | ||
289 | 296 | ||
290 | cb.writeByte(FLAGS); | 297 | cb.writeByte(FLAGS); |
291 | cb.writeByte(MPUNREACHNLRI_TYPE); | 298 | cb.writeByte(MPUNREACHNLRI_TYPE); |
... | @@ -296,79 +303,27 @@ public class MpUnReachNlri implements BgpValueType { | ... | @@ -296,79 +303,27 @@ public class MpUnReachNlri implements BgpValueType { |
296 | cb.writeShort(afi); | 303 | cb.writeShort(afi); |
297 | cb.writeByte(safi); | 304 | cb.writeByte(safi); |
298 | 305 | ||
299 | - if (bgpFlowSpecInfo.routeDistinguisher() != null) { | 306 | + if (bgpFlowSpecNlri.routeDistinguisher() != null) { |
300 | - cb.writeLong(bgpFlowSpecInfo.routeDistinguisher().getRouteDistinguisher()); | 307 | + cb.writeLong(bgpFlowSpecNlri.routeDistinguisher().getRouteDistinguisher()); |
301 | } | 308 | } |
302 | 309 | ||
303 | - ChannelBuffer flowSpecTmpBuff = ChannelBuffers.dynamicBuffer(); | 310 | + BgpValueType tlv1 = null; |
304 | - int tmpBuffStartIndx = flowSpecTmpBuff.writerIndex(); | 311 | + if (listIterator.hasNext()) { |
305 | - | 312 | + tlv1 = listIterator.next(); |
306 | - List<BgpValueType> flowSpec = bgpFlowSpecInfo.flowSpecComponents(); | 313 | + } |
307 | - ListIterator<BgpValueType> listIterator = flowSpec.listIterator(); | ||
308 | while (listIterator.hasNext()) { | 314 | while (listIterator.hasNext()) { |
309 | BgpValueType tlv = listIterator.next(); | 315 | BgpValueType tlv = listIterator.next(); |
310 | - switch (tlv.getType()) { | 316 | + if (tlv.getType() != tlv1.getType()) { |
311 | - case Constants.BGP_FLOWSPEC_DST_PREFIX: | 317 | + isAllFlowTypesIdentical = false; |
312 | - BgpFsDestinationPrefix fsDstPrefix = (BgpFsDestinationPrefix) tlv; | ||
313 | - fsDstPrefix.write(flowSpecTmpBuff); | ||
314 | break; | 318 | break; |
315 | - case Constants.BGP_FLOWSPEC_SRC_PREFIX: | ||
316 | - BgpFsSourcePrefix fsSrcPrefix = (BgpFsSourcePrefix) tlv; | ||
317 | - fsSrcPrefix.write(flowSpecTmpBuff); | ||
318 | - break; | ||
319 | - case Constants.BGP_FLOWSPEC_IP_PROTO: | ||
320 | - BgpFsIpProtocol fsIpProtocol = (BgpFsIpProtocol) tlv; | ||
321 | - fsIpProtocol.write(flowSpecTmpBuff); | ||
322 | - break; | ||
323 | - case Constants.BGP_FLOWSPEC_PORT: | ||
324 | - BgpFsPortNum fsPortNum = (BgpFsPortNum) tlv; | ||
325 | - fsPortNum.write(flowSpecTmpBuff); | ||
326 | - break; | ||
327 | - case Constants.BGP_FLOWSPEC_DST_PORT: | ||
328 | - BgpFsDestinationPortNum fsDstPortNum = (BgpFsDestinationPortNum) tlv; | ||
329 | - fsDstPortNum.write(flowSpecTmpBuff); | ||
330 | - break; | ||
331 | - case Constants.BGP_FLOWSPEC_SRC_PORT: | ||
332 | - BgpFsSourcePortNum fsSrcPortNum = (BgpFsSourcePortNum) tlv; | ||
333 | - fsSrcPortNum.write(flowSpecTmpBuff); | ||
334 | - break; | ||
335 | - case Constants.BGP_FLOWSPEC_ICMP_TP: | ||
336 | - BgpFsIcmpType fsIcmpType = (BgpFsIcmpType) tlv; | ||
337 | - fsIcmpType.write(flowSpecTmpBuff); | ||
338 | - break; | ||
339 | - case Constants.BGP_FLOWSPEC_ICMP_CD: | ||
340 | - BgpFsIcmpCode fsIcmpCode = (BgpFsIcmpCode) tlv; | ||
341 | - fsIcmpCode.write(flowSpecTmpBuff); | ||
342 | - break; | ||
343 | - case Constants.BGP_FLOWSPEC_TCP_FLAGS: | ||
344 | - BgpFsTcpFlags fsTcpFlags = (BgpFsTcpFlags) tlv; | ||
345 | - fsTcpFlags.write(flowSpecTmpBuff); | ||
346 | - break; | ||
347 | - case Constants.BGP_FLOWSPEC_PCK_LEN: | ||
348 | - BgpFsPacketLength fsPacketLen = (BgpFsPacketLength) tlv; | ||
349 | - fsPacketLen.write(flowSpecTmpBuff); | ||
350 | - break; | ||
351 | - case Constants.BGP_FLOWSPEC_DSCP: | ||
352 | - BgpFsDscpValue fsDscpVal = (BgpFsDscpValue) tlv; | ||
353 | - fsDscpVal.write(flowSpecTmpBuff); | ||
354 | - break; | ||
355 | - case Constants.BGP_FLOWSPEC_FRAGMENT: | ||
356 | - BgpFsFragment fsFragment = (BgpFsFragment) tlv; | ||
357 | - fsFragment.write(flowSpecTmpBuff); | ||
358 | - break; | ||
359 | - default: | ||
360 | } | 319 | } |
361 | } | 320 | } |
362 | 321 | ||
363 | - int len = flowSpecTmpBuff.writerIndex() - tmpBuffStartIndx; | 322 | + if (isAllFlowTypesIdentical) { |
364 | - if (len >= FLOW_SPEC_LEN) { | 323 | + BgpFlowSpecNlri.updateBufferIdenticalFlowTypes(cb, bgpFlowSpecNlri()); |
365 | - cb.writeShort(len); | ||
366 | } else { | 324 | } else { |
367 | - cb.writeByte(len); | 325 | + BgpFlowSpecNlri.updateBufferNonIdenticalFlowTypes(cb, bgpFlowSpecNlri()); |
368 | } | 326 | } |
369 | - //Copy from bynamic buffer to channel buffer | ||
370 | - cb.writeBytes(flowSpecTmpBuff); | ||
371 | - | ||
372 | int fsNlriLen = cb.writerIndex() - mpUnReachIndx; | 327 | int fsNlriLen = cb.writerIndex() - mpUnReachIndx; |
373 | cb.setShort(mpUnReachIndx, (short) (fsNlriLen - 2)); | 328 | cb.setShort(mpUnReachIndx, (short) (fsNlriLen - 2)); |
374 | } | 329 | } |
... | @@ -386,7 +341,7 @@ public class MpUnReachNlri implements BgpValueType { | ... | @@ -386,7 +341,7 @@ public class MpUnReachNlri implements BgpValueType { |
386 | public String toString() { | 341 | public String toString() { |
387 | return MoreObjects.toStringHelper(getClass()).omitNullValues() | 342 | return MoreObjects.toStringHelper(getClass()).omitNullValues() |
388 | .add("mpReachNlri", mpUnReachNlri) | 343 | .add("mpReachNlri", mpUnReachNlri) |
389 | - .add("bgpFlowSpecInfo", bgpFlowSpecInfo) | 344 | + .add("bgpFlowSpecNlri", bgpFlowSpecNlri) |
390 | .add("afi", afi) | 345 | .add("afi", afi) |
391 | .add("safi", safi) | 346 | .add("safi", safi) |
392 | .add("length", length) | 347 | .add("length", length) | ... | ... |
... | @@ -64,6 +64,22 @@ public class RpdCapabilityTlv implements BgpValueType { | ... | @@ -64,6 +64,22 @@ public class RpdCapabilityTlv implements BgpValueType { |
64 | return sendReceive; | 64 | return sendReceive; |
65 | } | 65 | } |
66 | 66 | ||
67 | + /** | ||
68 | + * Returns address family identifier value. | ||
69 | + * @return afi address family identifier value | ||
70 | + */ | ||
71 | + public short getAfi() { | ||
72 | + return afi; | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * Returns subsequent address family identifier value. | ||
77 | + * @return safi subsequent address family identifier value | ||
78 | + */ | ||
79 | + public byte getSafi() { | ||
80 | + return sAfi; | ||
81 | + } | ||
82 | + | ||
67 | @Override | 83 | @Override |
68 | public short getType() { | 84 | public short getType() { |
69 | return TYPE; | 85 | return TYPE; | ... | ... |
... | @@ -28,23 +28,23 @@ import org.onosproject.bgpio.types.BgpValueType; | ... | @@ -28,23 +28,23 @@ import org.onosproject.bgpio.types.BgpValueType; |
28 | import com.google.common.testing.EqualsTester; | 28 | import com.google.common.testing.EqualsTester; |
29 | 29 | ||
30 | /** | 30 | /** |
31 | - * Test for BgpFlowSpecDetails flow specification. | 31 | + * Test for BgpFlowSpecNlri flow specification. |
32 | */ | 32 | */ |
33 | -public class BgpFlowSpecDetailsTest { | 33 | +public class BgpFlowSpecNlriTest { |
34 | 34 | ||
35 | List<BgpValueType> flowSpecComponents1 = new LinkedList<>(); | 35 | List<BgpValueType> flowSpecComponents1 = new LinkedList<>(); |
36 | private List<BgpFsOperatorValue> operatorValue1 = new ArrayList<>(); | 36 | private List<BgpFsOperatorValue> operatorValue1 = new ArrayList<>(); |
37 | - BgpFlowSpecDetails flowSpecDetails1 = new BgpFlowSpecDetails(flowSpecComponents1); | 37 | + BgpFlowSpecNlri flowSpecDetails1 = new BgpFlowSpecNlri(flowSpecComponents1); |
38 | BgpFsPortNum portNum1 = new BgpFsPortNum(operatorValue1); | 38 | BgpFsPortNum portNum1 = new BgpFsPortNum(operatorValue1); |
39 | 39 | ||
40 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); | 40 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); |
41 | private List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); | 41 | private List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); |
42 | - BgpFlowSpecDetails flowSpecDetails = new BgpFlowSpecDetails(flowSpecComponents); | 42 | + BgpFlowSpecNlri flowSpecDetails = new BgpFlowSpecNlri(flowSpecComponents); |
43 | BgpFsPortNum portNum = new BgpFsPortNum(operatorValue); | 43 | BgpFsPortNum portNum = new BgpFsPortNum(operatorValue); |
44 | 44 | ||
45 | List<BgpValueType> flowSpecComponents2 = new LinkedList<>(); | 45 | List<BgpValueType> flowSpecComponents2 = new LinkedList<>(); |
46 | private List<BgpFsOperatorValue> operatorValue2 = new ArrayList<>(); | 46 | private List<BgpFsOperatorValue> operatorValue2 = new ArrayList<>(); |
47 | - BgpFlowSpecDetails flowSpecDetails2 = new BgpFlowSpecDetails(flowSpecComponents2); | 47 | + BgpFlowSpecNlri flowSpecDetails2 = new BgpFlowSpecNlri(flowSpecComponents2); |
48 | BgpFsPortNum portNum2 = new BgpFsPortNum(operatorValue2); | 48 | BgpFsPortNum portNum2 = new BgpFsPortNum(operatorValue2); |
49 | 49 | ||
50 | @Test | 50 | @Test | ... | ... |
protocols/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/flowspec/BgpFlowSpecPrefixTest.java
... | @@ -16,23 +16,18 @@ | ... | @@ -16,23 +16,18 @@ |
16 | package org.onosproject.bgpio.protocol.flowspec; | 16 | package org.onosproject.bgpio.protocol.flowspec; |
17 | 17 | ||
18 | import org.junit.Test; | 18 | import org.junit.Test; |
19 | - | ||
20 | -import org.onlab.packet.IpPrefix; | ||
21 | - | ||
22 | import com.google.common.testing.EqualsTester; | 19 | import com.google.common.testing.EqualsTester; |
23 | 20 | ||
24 | /** | 21 | /** |
25 | * Test for BgpFsDestinationPrefix flow specification component. | 22 | * Test for BgpFsDestinationPrefix flow specification component. |
26 | */ | 23 | */ |
27 | public class BgpFlowSpecPrefixTest { | 24 | public class BgpFlowSpecPrefixTest { |
28 | - private IpPrefix destinationPrefix1 = IpPrefix.valueOf("21.21.21.21/16"); | 25 | + private String routeKey1 = "flowRoute1"; |
29 | - private IpPrefix sourcePrefix1 = IpPrefix.valueOf("11.11.11.11/16"); | 26 | + private String routeKey2 = "flowRoute2"; |
30 | - private IpPrefix destinationPrefix2 = IpPrefix.valueOf("42.42.42.42/16"); | ||
31 | - private IpPrefix sourcePrefix2 = IpPrefix.valueOf("32.32.32.32/16"); | ||
32 | 27 | ||
33 | - private final BgpFlowSpecPrefix tlv1 = new BgpFlowSpecPrefix(destinationPrefix1, sourcePrefix1); | 28 | + private final BgpFlowSpecRouteKey tlv1 = new BgpFlowSpecRouteKey(routeKey1); |
34 | - private final BgpFlowSpecPrefix sameAsTlv1 = new BgpFlowSpecPrefix(destinationPrefix1, sourcePrefix1); | 29 | + private final BgpFlowSpecRouteKey sameAsTlv1 = new BgpFlowSpecRouteKey(routeKey1); |
35 | - private final BgpFlowSpecPrefix tlv2 = new BgpFlowSpecPrefix(destinationPrefix2, sourcePrefix2); | 30 | + private final BgpFlowSpecRouteKey tlv2 = new BgpFlowSpecRouteKey(routeKey2); |
36 | 31 | ||
37 | @Test | 32 | @Test |
38 | public void testEquality() { | 33 | public void testEquality() { | ... | ... |
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.protocol.flowspec; | ||
17 | + | ||
18 | +import org.junit.Test; | ||
19 | + | ||
20 | +import com.google.common.testing.EqualsTester; | ||
21 | + | ||
22 | +/** | ||
23 | + * Test for BgpFlowSpecRouteKeyTest flow specification component. | ||
24 | + */ | ||
25 | +public class BgpFlowSpecRouteKeyTest { | ||
26 | + private static String routeKey1 = "flowRoute1"; | ||
27 | + private static String routeKey2 = "flowRoute2"; | ||
28 | + | ||
29 | + private final BgpFlowSpecRouteKey tlv1 = new BgpFlowSpecRouteKey(routeKey1); | ||
30 | + private final BgpFlowSpecRouteKey sameAsTlv1 = new BgpFlowSpecRouteKey(routeKey1); | ||
31 | + private final BgpFlowSpecRouteKey tlv2 = new BgpFlowSpecRouteKey(routeKey2); | ||
32 | + | ||
33 | + @Test | ||
34 | + public void testEquality() { | ||
35 | + new EqualsTester() | ||
36 | + .addEqualityGroup(tlv1, sameAsTlv1) | ||
37 | + .addEqualityGroup(tlv2) | ||
38 | + .testEquals(); | ||
39 | + } | ||
40 | +} |
... | @@ -133,29 +133,23 @@ public class BgpControllerImpl implements BgpController { | ... | @@ -133,29 +133,23 @@ public class BgpControllerImpl implements BgpController { |
133 | } | 133 | } |
134 | Iterator<BgpValueType> listIterator = pathAttr.iterator(); | 134 | Iterator<BgpValueType> listIterator = pathAttr.iterator(); |
135 | boolean isLinkstate = false; | 135 | boolean isLinkstate = false; |
136 | - boolean isFlowSpec = false; | 136 | + |
137 | while (listIterator.hasNext()) { | 137 | while (listIterator.hasNext()) { |
138 | BgpValueType attr = listIterator.next(); | 138 | BgpValueType attr = listIterator.next(); |
139 | if (attr instanceof MpReachNlri) { | 139 | if (attr instanceof MpReachNlri) { |
140 | MpReachNlri mpReach = (MpReachNlri) attr; | 140 | MpReachNlri mpReach = (MpReachNlri) attr; |
141 | - if (mpReach.bgpFlowSpecInfo() == null) { | 141 | + if (mpReach.bgpFlowSpecNlri() == null) { |
142 | isLinkstate = true; | 142 | isLinkstate = true; |
143 | - } else { | ||
144 | - isFlowSpec = true; | ||
145 | } | 143 | } |
146 | } else if (attr instanceof MpUnReachNlri) { | 144 | } else if (attr instanceof MpUnReachNlri) { |
147 | MpUnReachNlri mpUnReach = (MpUnReachNlri) attr; | 145 | MpUnReachNlri mpUnReach = (MpUnReachNlri) attr; |
148 | - if (mpUnReach.bgpFlowSpecInfo() == null) { | 146 | + if (mpUnReach.bgpFlowSpecNlri() == null) { |
149 | isLinkstate = true; | 147 | isLinkstate = true; |
150 | - } else { | ||
151 | - isFlowSpec = true; | ||
152 | } | 148 | } |
153 | } | 149 | } |
154 | } | 150 | } |
155 | if (isLinkstate) { | 151 | if (isLinkstate) { |
156 | peer.buildAdjRibIn(pathAttr); | 152 | peer.buildAdjRibIn(pathAttr); |
157 | - } else if (isFlowSpec) { | ||
158 | - peer.buildFlowSpecRib(pathAttr); | ||
159 | } | 153 | } |
160 | break; | 154 | break; |
161 | default: | 155 | default: | ... | ... |
protocols/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpFlowSpecRib.java
deleted
100755 → 0
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 | - | ||
17 | -package org.onosproject.bgp.controller.impl; | ||
18 | - | ||
19 | -import java.util.Map; | ||
20 | -import java.util.TreeMap; | ||
21 | - | ||
22 | -import org.onosproject.bgpio.types.RouteDistinguisher; | ||
23 | -import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails; | ||
24 | -import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix; | ||
25 | - | ||
26 | -import com.google.common.base.MoreObjects; | ||
27 | - | ||
28 | -/** | ||
29 | - * Implementation of BGP flow specification RIB. | ||
30 | - */ | ||
31 | -public class BgpFlowSpecRib { | ||
32 | - private Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> flowSpecTree = new TreeMap<>(); | ||
33 | - private Map<RouteDistinguisher, Map<BgpFlowSpecPrefix, BgpFlowSpecDetails>> vpnFlowSpecTree = new TreeMap<>(); | ||
34 | - | ||
35 | - /** | ||
36 | - * Returns the BGP flow spec info. | ||
37 | - * | ||
38 | - * @return BGP flow spec tree | ||
39 | - */ | ||
40 | - public Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> flowSpecTree() { | ||
41 | - return flowSpecTree; | ||
42 | - } | ||
43 | - | ||
44 | - /** | ||
45 | - * Gets VPN flowspec tree. | ||
46 | - * | ||
47 | - * @return vpn flow spec tree | ||
48 | - */ | ||
49 | - public Map<RouteDistinguisher, Map<BgpFlowSpecPrefix, BgpFlowSpecDetails>> vpnFlowSpecTree() { | ||
50 | - return vpnFlowSpecTree; | ||
51 | - } | ||
52 | - | ||
53 | - | ||
54 | - /** | ||
55 | - * Update BGP flow spec details. | ||
56 | - * | ||
57 | - * @param prefix prefix Info | ||
58 | - * @param flowSpec BGP flow specifications details | ||
59 | - */ | ||
60 | - public void add(BgpFlowSpecPrefix prefix, BgpFlowSpecDetails flowSpec) { | ||
61 | - if (flowSpecTree.containsKey(prefix)) { | ||
62 | - flowSpecTree.replace(prefix, flowSpec); | ||
63 | - } else { | ||
64 | - flowSpecTree.put(prefix, flowSpec); | ||
65 | - } | ||
66 | - } | ||
67 | - | ||
68 | - /** | ||
69 | - * Removes flow spec. | ||
70 | - * | ||
71 | - * @param flowSpec BGP flow specification | ||
72 | - */ | ||
73 | - public void delete(BgpFlowSpecPrefix flowSpec) { | ||
74 | - if (flowSpecTree.containsKey(flowSpec)) { | ||
75 | - flowSpecTree.remove(flowSpec); | ||
76 | - } | ||
77 | - } | ||
78 | - | ||
79 | - /** | ||
80 | - * Update BGP flow spec details with routedistinguisher. | ||
81 | - * | ||
82 | - * @param routeDistinguisher route distinguisher | ||
83 | - * @param prefix prefix Info | ||
84 | - * @param flowSpec BGP flow specifications details | ||
85 | - */ | ||
86 | - public void add(RouteDistinguisher routeDistinguisher, BgpFlowSpecPrefix prefix, BgpFlowSpecDetails flowSpec) { | ||
87 | - Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> fsTree; | ||
88 | - if (!vpnFlowSpecTree.containsKey(routeDistinguisher)) { | ||
89 | - | ||
90 | - fsTree = new TreeMap<>(); | ||
91 | - | ||
92 | - vpnFlowSpecTree.put(routeDistinguisher, fsTree); | ||
93 | - } else { | ||
94 | - fsTree = vpnFlowSpecTree().get(routeDistinguisher); | ||
95 | - } | ||
96 | - if (fsTree.containsKey(prefix)) { | ||
97 | - fsTree.replace(prefix, flowSpec); | ||
98 | - } else { | ||
99 | - fsTree.put(prefix, flowSpec); | ||
100 | - } | ||
101 | - } | ||
102 | - | ||
103 | - /** | ||
104 | - * Removes flow spec. | ||
105 | - * | ||
106 | - * @param routeDistinguisher route distinguisher | ||
107 | - * @param flowSpecPrefix BGP flow specification prefix | ||
108 | - */ | ||
109 | - public void delete(RouteDistinguisher routeDistinguisher, BgpFlowSpecPrefix flowSpecPrefix) { | ||
110 | - if (vpnFlowSpecTree.containsKey(routeDistinguisher)) { | ||
111 | - Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> fsTree = vpnFlowSpecTree().get(routeDistinguisher); | ||
112 | - fsTree.remove(flowSpecPrefix); | ||
113 | - if (fsTree.size() == 0) { | ||
114 | - vpnFlowSpecTree.remove(routeDistinguisher); | ||
115 | - } | ||
116 | - } | ||
117 | - } | ||
118 | - | ||
119 | - @Override | ||
120 | - public String toString() { | ||
121 | - return MoreObjects.toStringHelper(getClass()) | ||
122 | - .omitNullValues() | ||
123 | - .add("flowSpecTree", flowSpecTree) | ||
124 | - .add("vpnFlowSpecTree", vpnFlowSpecTree) | ||
125 | - .toString(); | ||
126 | - } | ||
127 | -} |
This diff is collapsed. Click to expand it.
protocols/bgp/ctl/src/test/java/org/onosproject/controller/impl/BgpFlowSpecRibTest.java
deleted
100644 → 0
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.controller.impl; | ||
17 | - | ||
18 | -import org.junit.Test; | ||
19 | -import org.onlab.packet.IpAddress; | ||
20 | -import org.onlab.packet.IpPrefix; | ||
21 | -import org.onosproject.bgp.controller.impl.BgpFlowSpecRib; | ||
22 | -import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails; | ||
23 | -import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix; | ||
24 | -import org.onosproject.bgpio.types.BgpFsOperatorValue; | ||
25 | -import org.onosproject.bgpio.types.BgpFsPortNum; | ||
26 | -import org.onosproject.bgpio.types.BgpValueType; | ||
27 | -import org.onosproject.bgpio.types.RouteDistinguisher; | ||
28 | - | ||
29 | -import java.util.ArrayList; | ||
30 | -import java.util.LinkedList; | ||
31 | -import java.util.List; | ||
32 | - | ||
33 | -import static org.hamcrest.MatcherAssert.assertThat; | ||
34 | -import static org.hamcrest.core.Is.is; | ||
35 | - | ||
36 | -/** | ||
37 | - * Test cases for BGP Selection Algorithm. | ||
38 | - */ | ||
39 | -public class BgpFlowSpecRibTest { | ||
40 | - | ||
41 | - /** | ||
42 | - * Add flow specification to rib. | ||
43 | - */ | ||
44 | - @Test | ||
45 | - public void bgpFlowSpecRibTests1() { | ||
46 | - List<BgpValueType> flowSpecComponents = new LinkedList<>(); | ||
47 | - List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); | ||
48 | - BgpFlowSpecRib rib = new BgpFlowSpecRib(); | ||
49 | - | ||
50 | - IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32); | ||
51 | - IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32); | ||
52 | - | ||
53 | - BgpFlowSpecPrefix prefix = new BgpFlowSpecPrefix(destinationPrefix, sourcePrefix); | ||
54 | - | ||
55 | - byte[] port = new byte[] {(byte) 0x1 }; | ||
56 | - operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port)); | ||
57 | - | ||
58 | - BgpFsPortNum portNum = new BgpFsPortNum(operatorValue); | ||
59 | - flowSpecComponents.add(portNum); | ||
60 | - | ||
61 | - BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents); | ||
62 | - | ||
63 | - rib.add(prefix, flowSpec); | ||
64 | - | ||
65 | - boolean isPresent = rib.flowSpecTree().containsKey(prefix); | ||
66 | - assertThat(isPresent, is(true)); | ||
67 | - } | ||
68 | - | ||
69 | - /** | ||
70 | - * Add and delete flow specification to rib. | ||
71 | - */ | ||
72 | - @Test | ||
73 | - public void bgpFlowSpecRibTest2() { | ||
74 | - List<BgpValueType> flowSpecComponents = new LinkedList<>(); | ||
75 | - List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); | ||
76 | - BgpFlowSpecRib rib = new BgpFlowSpecRib(); | ||
77 | - | ||
78 | - IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32); | ||
79 | - IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32); | ||
80 | - | ||
81 | - BgpFlowSpecPrefix prefix = new BgpFlowSpecPrefix(destinationPrefix, sourcePrefix); | ||
82 | - byte[] port = new byte[] {(byte) 0x1 }; | ||
83 | - operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port)); | ||
84 | - | ||
85 | - BgpFsPortNum portNum = new BgpFsPortNum(operatorValue); | ||
86 | - flowSpecComponents.add(portNum); | ||
87 | - | ||
88 | - BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents); | ||
89 | - | ||
90 | - rib.add(prefix, flowSpec); | ||
91 | - | ||
92 | - boolean isPresent = rib.flowSpecTree().containsKey(prefix); | ||
93 | - assertThat(isPresent, is(true)); | ||
94 | - | ||
95 | - rib.delete(prefix); | ||
96 | - isPresent = rib.flowSpecTree().containsKey(prefix); | ||
97 | - assertThat(isPresent, is(false)); | ||
98 | - | ||
99 | - } | ||
100 | - | ||
101 | - /** | ||
102 | - * Add and delete flow specification with a specific VPN to rib. | ||
103 | - */ | ||
104 | - @Test | ||
105 | - public void bgpFlowSpecRibTest3() { | ||
106 | - List<BgpValueType> flowSpecComponents = new LinkedList<>(); | ||
107 | - List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); | ||
108 | - RouteDistinguisher routeDistinguisher = new RouteDistinguisher(1); | ||
109 | - BgpFlowSpecRib rib = new BgpFlowSpecRib(); | ||
110 | - | ||
111 | - IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32); | ||
112 | - IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32); | ||
113 | - | ||
114 | - BgpFlowSpecPrefix prefix = new BgpFlowSpecPrefix(destinationPrefix, sourcePrefix); | ||
115 | - | ||
116 | - byte[] port = new byte[] {(byte) 0x1 }; | ||
117 | - operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port)); | ||
118 | - | ||
119 | - BgpFsPortNum portNum = new BgpFsPortNum(operatorValue); | ||
120 | - flowSpecComponents.add(portNum); | ||
121 | - | ||
122 | - BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents); | ||
123 | - | ||
124 | - rib.add(routeDistinguisher, prefix, flowSpec); | ||
125 | - | ||
126 | - boolean isPresent = rib.vpnFlowSpecTree().containsKey(routeDistinguisher); | ||
127 | - assertThat(isPresent, is(true)); | ||
128 | - | ||
129 | - rib.delete(routeDistinguisher, prefix); | ||
130 | - isPresent = rib.vpnFlowSpecTree().containsKey(routeDistinguisher); | ||
131 | - assertThat(isPresent, is(false)); | ||
132 | - } | ||
133 | -} |
-
Please register or login to post a comment