Committed by
Gerrit Code Review
[ONOS-4241]Codec for wide community and flow spec
Change-Id: I2dfd6b88c4ae14a02d258a2cdc9ee35b9ff08292
Showing
13 changed files
with
456 additions
and
815 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); | 41 | + } |
46 | - } | ||
47 | - | ||
48 | - if (sourcePrefix == null) { | ||
49 | - sourcePrefix = IpPrefix.valueOf(0, 0); | ||
50 | - } | ||
51 | 42 | ||
52 | - this.destinationPrefix = destinationPrefix; | 43 | + /** |
53 | - this.sourcePrefix = sourcePrefix; | 44 | + * Returns route key. |
45 | + * | ||
46 | + * @return route key | ||
47 | + */ | ||
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,64 +206,70 @@ public class MpReachNlri implements BgpValueType { | ... | @@ -208,64 +206,70 @@ 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 | } |
211 | - short totNlriLen = tempCb.getByte(tempCb.readerIndex()); | 209 | + while (tempCb.readableBytes() > 0) { |
212 | - if (totNlriLen >= FLOW_SPEC_LEN) { | 210 | + short totNlriLen = tempCb.getByte(tempCb.readerIndex()); |
213 | - totNlriLen = tempCb.readShort(); | 211 | + if (totNlriLen >= BgpFlowSpecNlri.FLOW_SPEC_LEN) { |
214 | - } else { | 212 | + if (tempCb.readableBytes() < 2) { |
215 | - totNlriLen = tempCb.readByte(); | 213 | + Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, |
216 | - } | 214 | + BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); |
217 | - if (tempCb.readableBytes() < totNlriLen) { | 215 | + } |
218 | - Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, | 216 | + totNlriLen = tempCb.readShort(); |
219 | - BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); | 217 | + } else { |
220 | - } | 218 | + totNlriLen = tempCb.readByte(); |
221 | - tempBuf = tempCb.readBytes(totNlriLen); | 219 | + } |
222 | - while (tempBuf.readableBytes() > 0) { | 220 | + if (tempCb.readableBytes() < totNlriLen) { |
223 | - short type = tempBuf.readByte(); | 221 | + Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, |
224 | - switch (type) { | 222 | + BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); |
225 | - case Constants.BGP_FLOWSPEC_DST_PREFIX: | 223 | + } |
226 | - flowSpecComponent = BgpFsDestinationPrefix.read(tempBuf); | 224 | + tempBuf = tempCb.readBytes(totNlriLen); |
227 | - break; | 225 | + while (tempBuf.readableBytes() > 0) { |
228 | - case Constants.BGP_FLOWSPEC_SRC_PREFIX: | 226 | + short type = tempBuf.readByte(); |
229 | - flowSpecComponent = BgpFsSourcePrefix.read(tempBuf); | 227 | + switch (type) { |
230 | - break; | 228 | + case Constants.BGP_FLOWSPEC_DST_PREFIX: |
231 | - case Constants.BGP_FLOWSPEC_IP_PROTO: | 229 | + flowSpecComponent = BgpFsDestinationPrefix.read(tempBuf); |
232 | - flowSpecComponent = BgpFsIpProtocol.read(tempBuf); | 230 | + break; |
233 | - break; | 231 | + case Constants.BGP_FLOWSPEC_SRC_PREFIX: |
234 | - case Constants.BGP_FLOWSPEC_PORT: | 232 | + flowSpecComponent = BgpFsSourcePrefix.read(tempBuf); |
235 | - flowSpecComponent = BgpFsPortNum.read(tempBuf); | 233 | + break; |
236 | - break; | 234 | + case Constants.BGP_FLOWSPEC_IP_PROTO: |
237 | - case Constants.BGP_FLOWSPEC_DST_PORT: | 235 | + flowSpecComponent = BgpFsIpProtocol.read(tempBuf); |
238 | - flowSpecComponent = BgpFsDestinationPortNum.read(tempBuf); | 236 | + break; |
239 | - break; | 237 | + case Constants.BGP_FLOWSPEC_PORT: |
240 | - case Constants.BGP_FLOWSPEC_SRC_PORT: | 238 | + flowSpecComponent = BgpFsPortNum.read(tempBuf); |
241 | - flowSpecComponent = BgpFsSourcePortNum.read(tempBuf); | 239 | + break; |
242 | - break; | 240 | + case Constants.BGP_FLOWSPEC_DST_PORT: |
243 | - case Constants.BGP_FLOWSPEC_ICMP_TP: | 241 | + flowSpecComponent = BgpFsDestinationPortNum.read(tempBuf); |
244 | - flowSpecComponent = BgpFsIcmpType.read(tempBuf); | 242 | + break; |
245 | - break; | 243 | + case Constants.BGP_FLOWSPEC_SRC_PORT: |
246 | - case Constants.BGP_FLOWSPEC_ICMP_CD: | 244 | + flowSpecComponent = BgpFsSourcePortNum.read(tempBuf); |
247 | - flowSpecComponent = BgpFsIcmpCode.read(tempBuf); | 245 | + break; |
248 | - break; | 246 | + case Constants.BGP_FLOWSPEC_ICMP_TP: |
249 | - case Constants.BGP_FLOWSPEC_TCP_FLAGS: | 247 | + flowSpecComponent = BgpFsIcmpType.read(tempBuf); |
250 | - flowSpecComponent = BgpFsTcpFlags.read(tempBuf); | 248 | + break; |
251 | - break; | 249 | + case Constants.BGP_FLOWSPEC_ICMP_CD: |
252 | - case Constants.BGP_FLOWSPEC_PCK_LEN: | 250 | + flowSpecComponent = BgpFsIcmpCode.read(tempBuf); |
253 | - flowSpecComponent = BgpFsPacketLength.read(tempBuf); | 251 | + break; |
254 | - break; | 252 | + case Constants.BGP_FLOWSPEC_TCP_FLAGS: |
255 | - case Constants.BGP_FLOWSPEC_DSCP: | 253 | + flowSpecComponent = BgpFsTcpFlags.read(tempBuf); |
256 | - flowSpecComponent = BgpFsDscpValue.read(tempBuf); | 254 | + break; |
257 | - break; | 255 | + case Constants.BGP_FLOWSPEC_PCK_LEN: |
258 | - case Constants.BGP_FLOWSPEC_FRAGMENT: | 256 | + flowSpecComponent = BgpFsPacketLength.read(tempBuf); |
259 | - flowSpecComponent = BgpFsFragment.read(tempBuf); | 257 | + break; |
260 | - break; | 258 | + case Constants.BGP_FLOWSPEC_DSCP: |
261 | - default: | 259 | + flowSpecComponent = BgpFsDscpValue.read(tempBuf); |
262 | - log.debug("flow spec type not supported" + type); | 260 | + break; |
263 | - break; | 261 | + case Constants.BGP_FLOWSPEC_FRAGMENT: |
262 | + flowSpecComponent = BgpFsFragment.read(tempBuf); | ||
263 | + break; | ||
264 | + default: | ||
265 | + log.debug("flow spec type not supported" + type); | ||
266 | + break; | ||
267 | + } | ||
268 | + flowSpecComponents.add(flowSpecComponent); | ||
264 | } | 269 | } |
265 | - flowSpecComponents.add(flowSpecComponent); | ||
266 | } | 270 | } |
267 | } | 271 | } |
268 | - BgpFlowSpecDetails flowSpecDetails = new BgpFlowSpecDetails(flowSpecComponents); | 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,64 +160,70 @@ public class MpUnReachNlri implements BgpValueType { | ... | @@ -162,64 +160,70 @@ 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 | } |
165 | - short totNlriLen = tempCb.getByte(tempCb.readerIndex()); | 163 | + while (tempCb.readableBytes() > 0) { |
166 | - if (totNlriLen >= FLOW_SPEC_LEN) { | 164 | + short totNlriLen = tempCb.getByte(tempCb.readerIndex()); |
167 | - totNlriLen = tempCb.readShort(); | 165 | + if (totNlriLen >= BgpFlowSpecNlri.FLOW_SPEC_LEN) { |
168 | - } else { | 166 | + if (tempCb.readableBytes() < 2) { |
169 | - totNlriLen = tempCb.readByte(); | 167 | + Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, |
170 | - } | 168 | + BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); |
171 | - if (tempCb.readableBytes() < totNlriLen) { | 169 | + } |
172 | - Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, | 170 | + totNlriLen = tempCb.readShort(); |
173 | - BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); | 171 | + } else { |
174 | - } | 172 | + totNlriLen = tempCb.readByte(); |
175 | - tempBuf = tempCb.readBytes(totNlriLen); | 173 | + } |
176 | - while (tempBuf.readableBytes() > 0) { | 174 | + if (tempCb.readableBytes() < totNlriLen) { |
177 | - short type = tempBuf.readByte(); | 175 | + Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, |
178 | - switch (type) { | 176 | + BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); |
179 | - case Constants.BGP_FLOWSPEC_DST_PREFIX: | 177 | + } |
180 | - flowSpecComponent = BgpFsDestinationPrefix.read(tempBuf); | 178 | + tempBuf = tempCb.readBytes(totNlriLen); |
181 | - break; | 179 | + while (tempBuf.readableBytes() > 0) { |
182 | - case Constants.BGP_FLOWSPEC_SRC_PREFIX: | 180 | + short type = tempBuf.readByte(); |
183 | - flowSpecComponent = BgpFsSourcePrefix.read(tempBuf); | 181 | + switch (type) { |
184 | - break; | 182 | + case Constants.BGP_FLOWSPEC_DST_PREFIX: |
185 | - case Constants.BGP_FLOWSPEC_IP_PROTO: | 183 | + flowSpecComponent = BgpFsDestinationPrefix.read(tempBuf); |
186 | - flowSpecComponent = BgpFsIpProtocol.read(tempBuf); | 184 | + break; |
187 | - break; | 185 | + case Constants.BGP_FLOWSPEC_SRC_PREFIX: |
188 | - case Constants.BGP_FLOWSPEC_PORT: | 186 | + flowSpecComponent = BgpFsSourcePrefix.read(tempBuf); |
189 | - flowSpecComponent = BgpFsPortNum.read(tempBuf); | 187 | + break; |
190 | - break; | 188 | + case Constants.BGP_FLOWSPEC_IP_PROTO: |
191 | - case Constants.BGP_FLOWSPEC_DST_PORT: | 189 | + flowSpecComponent = BgpFsIpProtocol.read(tempBuf); |
192 | - flowSpecComponent = BgpFsDestinationPortNum.read(tempBuf); | 190 | + break; |
193 | - break; | 191 | + case Constants.BGP_FLOWSPEC_PORT: |
194 | - case Constants.BGP_FLOWSPEC_SRC_PORT: | 192 | + flowSpecComponent = BgpFsPortNum.read(tempBuf); |
195 | - flowSpecComponent = BgpFsSourcePortNum.read(tempBuf); | 193 | + break; |
196 | - break; | 194 | + case Constants.BGP_FLOWSPEC_DST_PORT: |
197 | - case Constants.BGP_FLOWSPEC_ICMP_TP: | 195 | + flowSpecComponent = BgpFsDestinationPortNum.read(tempBuf); |
198 | - flowSpecComponent = BgpFsIcmpType.read(tempBuf); | 196 | + break; |
199 | - break; | 197 | + case Constants.BGP_FLOWSPEC_SRC_PORT: |
200 | - case Constants.BGP_FLOWSPEC_ICMP_CD: | 198 | + flowSpecComponent = BgpFsSourcePortNum.read(tempBuf); |
201 | - flowSpecComponent = BgpFsIcmpType.read(tempBuf); | 199 | + break; |
202 | - break; | 200 | + case Constants.BGP_FLOWSPEC_ICMP_TP: |
203 | - case Constants.BGP_FLOWSPEC_TCP_FLAGS: | 201 | + flowSpecComponent = BgpFsIcmpType.read(tempBuf); |
204 | - flowSpecComponent = BgpFsTcpFlags.read(tempBuf); | 202 | + break; |
205 | - break; | 203 | + case Constants.BGP_FLOWSPEC_ICMP_CD: |
206 | - case Constants.BGP_FLOWSPEC_PCK_LEN: | 204 | + flowSpecComponent = BgpFsIcmpCode.read(tempBuf); |
207 | - flowSpecComponent = BgpFsPacketLength.read(tempBuf); | 205 | + break; |
208 | - break; | 206 | + case Constants.BGP_FLOWSPEC_TCP_FLAGS: |
209 | - case Constants.BGP_FLOWSPEC_DSCP: | 207 | + flowSpecComponent = BgpFsTcpFlags.read(tempBuf); |
210 | - flowSpecComponent = BgpFsDscpValue.read(tempBuf); | 208 | + break; |
211 | - break; | 209 | + case Constants.BGP_FLOWSPEC_PCK_LEN: |
212 | - case Constants.BGP_FLOWSPEC_FRAGMENT: | 210 | + flowSpecComponent = BgpFsPacketLength.read(tempBuf); |
213 | - flowSpecComponent = BgpFsFragment.read(tempBuf); | 211 | + break; |
214 | - break; | 212 | + case Constants.BGP_FLOWSPEC_DSCP: |
215 | - default: | 213 | + flowSpecComponent = BgpFsDscpValue.read(tempBuf); |
216 | - log.debug("flow spec type not supported" + type); | 214 | + break; |
217 | - break; | 215 | + case Constants.BGP_FLOWSPEC_FRAGMENT: |
216 | + flowSpecComponent = BgpFsFragment.read(tempBuf); | ||
217 | + break; | ||
218 | + default: | ||
219 | + log.debug("flow spec type not supported" + type); | ||
220 | + break; | ||
221 | + } | ||
222 | + flowSpecComponents.add(flowSpecComponent); | ||
218 | } | 223 | } |
219 | - flowSpecComponents.add(flowSpecComponent); | ||
220 | } | 224 | } |
221 | } | 225 | } |
222 | - BgpFlowSpecDetails flowSpecDetails = new BgpFlowSpecDetails(flowSpecComponents); | 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; | ||
315 | - case Constants.BGP_FLOWSPEC_SRC_PREFIX: | ||
316 | - BgpFsSourcePrefix fsSrcPrefix = (BgpFsSourcePrefix) tlv; | ||
317 | - fsSrcPrefix.write(flowSpecTmpBuff); | ||
318 | break; | 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 | -} |
... | @@ -19,14 +19,8 @@ package org.onosproject.bgp.controller.impl; | ... | @@ -19,14 +19,8 @@ package org.onosproject.bgp.controller.impl; |
19 | import com.google.common.base.MoreObjects; | 19 | import com.google.common.base.MoreObjects; |
20 | import com.google.common.base.Preconditions; | 20 | import com.google.common.base.Preconditions; |
21 | 21 | ||
22 | -import java.util.ArrayList; | ||
23 | -import java.util.LinkedList; | ||
24 | -import java.util.Map; | ||
25 | -import java.util.Set; | ||
26 | - | ||
27 | import org.jboss.netty.channel.Channel; | 22 | import org.jboss.netty.channel.Channel; |
28 | import org.onlab.packet.IpAddress; | 23 | import org.onlab.packet.IpAddress; |
29 | -import org.onlab.packet.IpPrefix; | ||
30 | import org.onosproject.bgp.controller.BgpController; | 24 | import org.onosproject.bgp.controller.BgpController; |
31 | import org.onosproject.bgp.controller.BgpLocalRib; | 25 | import org.onosproject.bgp.controller.BgpLocalRib; |
32 | import org.onosproject.bgp.controller.BgpPeer; | 26 | import org.onosproject.bgp.controller.BgpPeer; |
... | @@ -36,8 +30,8 @@ import org.onosproject.bgpio.protocol.BgpFactories; | ... | @@ -36,8 +30,8 @@ import org.onosproject.bgpio.protocol.BgpFactories; |
36 | import org.onosproject.bgpio.protocol.BgpFactory; | 30 | import org.onosproject.bgpio.protocol.BgpFactory; |
37 | import org.onosproject.bgpio.protocol.BgpLSNlri; | 31 | import org.onosproject.bgpio.protocol.BgpLSNlri; |
38 | import org.onosproject.bgpio.protocol.BgpMessage; | 32 | import org.onosproject.bgpio.protocol.BgpMessage; |
39 | -import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails; | 33 | +import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecNlri; |
40 | -import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix; | 34 | +import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecRouteKey; |
41 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; | 35 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; |
42 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; | 36 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; |
43 | import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4; | 37 | import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4; |
... | @@ -45,8 +39,6 @@ import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails; | ... | @@ -45,8 +39,6 @@ import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails; |
45 | import org.onosproject.bgpio.types.AsPath; | 39 | import org.onosproject.bgpio.types.AsPath; |
46 | import org.onosproject.bgpio.types.As4Path; | 40 | import org.onosproject.bgpio.types.As4Path; |
47 | import org.onosproject.bgpio.types.BgpExtendedCommunity; | 41 | import org.onosproject.bgpio.types.BgpExtendedCommunity; |
48 | -import org.onosproject.bgpio.types.BgpFsDestinationPrefix; | ||
49 | -import org.onosproject.bgpio.types.BgpFsSourcePrefix; | ||
50 | import org.onosproject.bgpio.types.BgpValueType; | 42 | import org.onosproject.bgpio.types.BgpValueType; |
51 | import org.onosproject.bgpio.types.LocalPref; | 43 | import org.onosproject.bgpio.types.LocalPref; |
52 | import org.onosproject.bgpio.types.Med; | 44 | import org.onosproject.bgpio.types.Med; |
... | @@ -54,14 +46,17 @@ import org.onosproject.bgpio.types.MpReachNlri; | ... | @@ -54,14 +46,17 @@ import org.onosproject.bgpio.types.MpReachNlri; |
54 | import org.onosproject.bgpio.types.MpUnReachNlri; | 46 | import org.onosproject.bgpio.types.MpUnReachNlri; |
55 | import org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv; | 47 | import org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv; |
56 | import org.onosproject.bgpio.types.Origin; | 48 | import org.onosproject.bgpio.types.Origin; |
57 | -import org.onosproject.bgpio.types.RouteDistinguisher; | 49 | +import org.onosproject.bgpio.types.attr.WideCommunity; |
50 | +import org.onosproject.bgpio.types.RpdCapabilityTlv; | ||
58 | import org.onosproject.bgpio.util.Constants; | 51 | import org.onosproject.bgpio.util.Constants; |
59 | import org.slf4j.Logger; | 52 | import org.slf4j.Logger; |
60 | import org.slf4j.LoggerFactory; | 53 | import org.slf4j.LoggerFactory; |
61 | 54 | ||
62 | import java.net.InetSocketAddress; | 55 | import java.net.InetSocketAddress; |
63 | import java.net.SocketAddress; | 56 | import java.net.SocketAddress; |
57 | +import java.util.ArrayList; | ||
64 | import java.util.Collections; | 58 | import java.util.Collections; |
59 | +import java.util.LinkedList; | ||
65 | import java.util.List; | 60 | import java.util.List; |
66 | import java.util.ListIterator; | 61 | import java.util.ListIterator; |
67 | import java.util.concurrent.RejectedExecutionException; | 62 | import java.util.concurrent.RejectedExecutionException; |
... | @@ -86,26 +81,6 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -86,26 +81,6 @@ public class BgpPeerImpl implements BgpPeer { |
86 | private BgpLocalRib bgplocalRibVpn; | 81 | private BgpLocalRib bgplocalRibVpn; |
87 | private AdjRibIn adjRib; | 82 | private AdjRibIn adjRib; |
88 | private VpnAdjRibIn vpnAdjRib; | 83 | private VpnAdjRibIn vpnAdjRib; |
89 | - private BgpFlowSpecRib flowSpecRibOut; | ||
90 | - private BgpFlowSpecRib flowSpecRibIn; | ||
91 | - | ||
92 | - /** | ||
93 | - * Returns the flowSpec RIB out. | ||
94 | - * | ||
95 | - * @return flow Specification RIB out | ||
96 | - */ | ||
97 | - public BgpFlowSpecRib flowSpecRibOut() { | ||
98 | - return flowSpecRibOut; | ||
99 | - } | ||
100 | - | ||
101 | - /** | ||
102 | - * Returns the flowSpec RIB-in. | ||
103 | - * | ||
104 | - * @return flow Specification RIB-in | ||
105 | - */ | ||
106 | - public BgpFlowSpecRib flowSpecRibIn() { | ||
107 | - return flowSpecRibIn; | ||
108 | - } | ||
109 | 84 | ||
110 | /** | 85 | /** |
111 | * Return the adjacency RIB-IN. | 86 | * Return the adjacency RIB-IN. |
... | @@ -145,8 +120,6 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -145,8 +120,6 @@ public class BgpPeerImpl implements BgpPeer { |
145 | this.bgplocalRibVpn = bgpController.bgpLocalRibVpn(); | 120 | this.bgplocalRibVpn = bgpController.bgpLocalRibVpn(); |
146 | this.adjRib = new AdjRibIn(); | 121 | this.adjRib = new AdjRibIn(); |
147 | this.vpnAdjRib = new VpnAdjRibIn(); | 122 | this.vpnAdjRib = new VpnAdjRibIn(); |
148 | - this.flowSpecRibOut = new BgpFlowSpecRib(); | ||
149 | - this.flowSpecRibIn = new BgpFlowSpecRib(); | ||
150 | } | 123 | } |
151 | 124 | ||
152 | /** | 125 | /** |
... | @@ -171,6 +144,11 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -171,6 +144,11 @@ public class BgpPeerImpl implements BgpPeer { |
171 | if ((temp.getAfi() == afi) && (temp.getSafi() == sAfi)) { | 144 | if ((temp.getAfi() == afi) && (temp.getSafi() == sAfi)) { |
172 | return true; | 145 | return true; |
173 | } | 146 | } |
147 | + } else if (tlv.getType() == RpdCapabilityTlv.TYPE) { | ||
148 | + RpdCapabilityTlv temp = (RpdCapabilityTlv) tlv; | ||
149 | + if ((temp.getAfi() == afi) && (temp.getSafi() == sAfi)) { | ||
150 | + return true; | ||
151 | + } | ||
174 | } | 152 | } |
175 | } | 153 | } |
176 | } | 154 | } |
... | @@ -182,12 +160,14 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -182,12 +160,14 @@ public class BgpPeerImpl implements BgpPeer { |
182 | * | 160 | * |
183 | * @param operType operation type | 161 | * @param operType operation type |
184 | * @param flowSpec flow specification details | 162 | * @param flowSpec flow specification details |
163 | + * @param wideCommunity for route policy | ||
185 | */ | 164 | */ |
186 | - public final void sendFlowSpecUpdateMessageToPeer(FlowSpecOperation operType, BgpFlowSpecDetails flowSpec) { | 165 | + public final void sendFlowSpecUpdateMessageToPeer(FlowSpecOperation operType, BgpFlowSpecRouteKey routeKey, |
166 | + BgpFlowSpecNlri flowSpec, WideCommunity wideCommunity) { | ||
187 | 167 | ||
188 | List<BgpValueType> attributesList = new LinkedList<>(); | 168 | List<BgpValueType> attributesList = new LinkedList<>(); |
189 | byte sessionType = sessionInfo.isIbgpSession() ? (byte) 0 : (byte) 1; | 169 | byte sessionType = sessionInfo.isIbgpSession() ? (byte) 0 : (byte) 1; |
190 | - byte sAfi = Constants.SAFI_FLOWSPEC_VALUE; | 170 | + byte sAfi = Constants.VPN_SAFI_FLOWSPEC_VALUE; |
191 | 171 | ||
192 | boolean isFsCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE, | 172 | boolean isFsCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE, |
193 | Constants.AFI_FLOWSPEC_VALUE, | 173 | Constants.AFI_FLOWSPEC_VALUE, |
... | @@ -196,16 +176,26 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -196,16 +176,26 @@ public class BgpPeerImpl implements BgpPeer { |
196 | boolean isVpnFsCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE, | 176 | boolean isVpnFsCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE, |
197 | Constants.AFI_FLOWSPEC_VALUE, | 177 | Constants.AFI_FLOWSPEC_VALUE, |
198 | Constants.VPN_SAFI_FLOWSPEC_VALUE); | 178 | Constants.VPN_SAFI_FLOWSPEC_VALUE); |
199 | - if ((!isFsCapabilitySet) && (!isVpnFsCapabilitySet)) { | 179 | + |
180 | + boolean isRpdCapabilitySet = isCapabilitySupported(RpdCapabilityTlv.TYPE, | ||
181 | + Constants.AFI_FLOWSPEC_RPD_VALUE, | ||
182 | + Constants.SAFI_FLOWSPEC_RPD_VALUE); | ||
183 | + | ||
184 | + boolean isVpnRpdCapabilitySet = isCapabilitySupported(RpdCapabilityTlv.TYPE, | ||
185 | + Constants.AFI_FLOWSPEC_RPD_VALUE, | ||
186 | + Constants.VPN_SAFI_FLOWSPEC_RDP_VALUE); | ||
187 | + | ||
188 | + if ((!isFsCapabilitySet) && (!isVpnFsCapabilitySet) && (!isRpdCapabilitySet) && (!isVpnRpdCapabilitySet)) { | ||
200 | log.debug("Peer do not support BGP flow spec capability", channel.getRemoteAddress()); | 189 | log.debug("Peer do not support BGP flow spec capability", channel.getRemoteAddress()); |
201 | return; | 190 | return; |
202 | } | 191 | } |
203 | 192 | ||
204 | - if (isVpnFsCapabilitySet) { | 193 | + if ((wideCommunity != null) && (isVpnRpdCapabilitySet)) { |
194 | + sAfi = Constants.VPN_SAFI_FLOWSPEC_RDP_VALUE; | ||
195 | + } else if (isVpnFsCapabilitySet) { | ||
205 | sAfi = Constants.VPN_SAFI_FLOWSPEC_VALUE; | 196 | sAfi = Constants.VPN_SAFI_FLOWSPEC_VALUE; |
206 | } | 197 | } |
207 | - | 198 | + attributesList.add(new Origin((byte) 0)); |
208 | - attributesList.add(new Origin(sessionType)); | ||
209 | 199 | ||
210 | if (sessionType != 0) { | 200 | if (sessionType != 0) { |
211 | // EBGP | 201 | // EBGP |
... | @@ -232,6 +222,7 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -232,6 +222,7 @@ public class BgpPeerImpl implements BgpPeer { |
232 | } | 222 | } |
233 | 223 | ||
234 | attributesList.add(new BgpExtendedCommunity(flowSpec.fsActionTlv())); | 224 | attributesList.add(new BgpExtendedCommunity(flowSpec.fsActionTlv())); |
225 | + attributesList.add(wideCommunity); | ||
235 | 226 | ||
236 | if (operType == FlowSpecOperation.ADD) { | 227 | if (operType == FlowSpecOperation.ADD) { |
237 | attributesList.add(new MpReachNlri(flowSpec, Constants.AFI_FLOWSPEC_VALUE, sAfi)); | 228 | attributesList.add(new MpReachNlri(flowSpec, Constants.AFI_FLOWSPEC_VALUE, sAfi)); |
... | @@ -247,38 +238,14 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -247,38 +238,14 @@ public class BgpPeerImpl implements BgpPeer { |
247 | } | 238 | } |
248 | 239 | ||
249 | @Override | 240 | @Override |
250 | - public void updateFlowSpec(FlowSpecOperation operType, BgpFlowSpecPrefix prefix, BgpFlowSpecDetails flowSpec) { | 241 | + public void updateFlowSpec(FlowSpecOperation operType, BgpFlowSpecRouteKey routeKey, |
242 | + BgpFlowSpecNlri flowSpec, WideCommunity wideCommunity) { | ||
251 | Preconditions.checkNotNull(operType, "flow specification operation type cannot be null"); | 243 | Preconditions.checkNotNull(operType, "flow specification operation type cannot be null"); |
252 | - Preconditions.checkNotNull(prefix, "flow specification prefix cannot be null"); | 244 | + Preconditions.checkNotNull(routeKey, "flow specification prefix cannot be null"); |
253 | Preconditions.checkNotNull(flowSpec, "flow specification details cannot be null"); | 245 | Preconditions.checkNotNull(flowSpec, "flow specification details cannot be null"); |
254 | Preconditions.checkNotNull(flowSpec.fsActionTlv(), "flow specification action cannot be null"); | 246 | Preconditions.checkNotNull(flowSpec.fsActionTlv(), "flow specification action cannot be null"); |
255 | 247 | ||
256 | - if (operType == FlowSpecOperation.ADD) { | 248 | + sendFlowSpecUpdateMessageToPeer(operType, routeKey, flowSpec, wideCommunity); |
257 | - if (flowSpec.routeDistinguisher() == null) { | ||
258 | - if (flowSpecRibOut.flowSpecTree().containsKey(prefix)) { | ||
259 | - sendFlowSpecUpdateMessageToPeer(FlowSpecOperation.DELETE, | ||
260 | - flowSpecRibOut.flowSpecTree().get(prefix)); | ||
261 | - } | ||
262 | - flowSpecRibOut.add(prefix, flowSpec); | ||
263 | - } else { | ||
264 | - if (flowSpecRibOut.vpnFlowSpecTree().containsKey(flowSpec.routeDistinguisher())) { | ||
265 | - Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> fsTree; | ||
266 | - fsTree = flowSpecRibOut.vpnFlowSpecTree().get(flowSpec.routeDistinguisher()); | ||
267 | - if (fsTree.containsKey(prefix)) { | ||
268 | - sendFlowSpecUpdateMessageToPeer(FlowSpecOperation.DELETE, | ||
269 | - fsTree.get(prefix)); | ||
270 | - } | ||
271 | - } | ||
272 | - flowSpecRibOut.add(flowSpec.routeDistinguisher(), prefix, flowSpec); | ||
273 | - } | ||
274 | - } else if (operType == FlowSpecOperation.DELETE) { | ||
275 | - if (flowSpec.routeDistinguisher() == null) { | ||
276 | - flowSpecRibOut.delete(prefix); | ||
277 | - } else { | ||
278 | - flowSpecRibOut.delete(flowSpec.routeDistinguisher(), prefix); | ||
279 | - } | ||
280 | - } | ||
281 | - sendFlowSpecUpdateMessageToPeer(operType, flowSpec); | ||
282 | } | 249 | } |
283 | 250 | ||
284 | @Override | 251 | @Override |
... | @@ -297,65 +264,6 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -297,65 +264,6 @@ public class BgpPeerImpl implements BgpPeer { |
297 | } | 264 | } |
298 | } | 265 | } |
299 | 266 | ||
300 | - @Override | ||
301 | - public void buildFlowSpecRib(List<BgpValueType> pathAttr) throws BgpParseException { | ||
302 | - ListIterator<BgpValueType> iterator = pathAttr.listIterator(); | ||
303 | - BgpFlowSpecDetails bgpFlowSpecDetails = new BgpFlowSpecDetails(); | ||
304 | - FlowSpecOperation operType = FlowSpecOperation.UPDATE; | ||
305 | - | ||
306 | - while (iterator.hasNext()) { | ||
307 | - BgpValueType attr = iterator.next(); | ||
308 | - if (attr instanceof MpReachNlri) { | ||
309 | - MpReachNlri mpReach = (MpReachNlri) attr; | ||
310 | - bgpFlowSpecDetails.setFlowSpecComponents(mpReach.bgpFlowSpecInfo().flowSpecComponents()); | ||
311 | - bgpFlowSpecDetails.setRouteDistinguiher(mpReach.bgpFlowSpecInfo().routeDistinguisher()); | ||
312 | - operType = FlowSpecOperation.ADD; | ||
313 | - } | ||
314 | - | ||
315 | - if (attr instanceof BgpExtendedCommunity) { | ||
316 | - BgpExtendedCommunity extCommunity = (BgpExtendedCommunity) attr; | ||
317 | - bgpFlowSpecDetails.setFsActionTlv(extCommunity.fsActionTlv()); | ||
318 | - } | ||
319 | - | ||
320 | - if (attr instanceof MpUnReachNlri) { | ||
321 | - MpUnReachNlri mpUnReach = (MpUnReachNlri) attr; | ||
322 | - bgpFlowSpecDetails.setFlowSpecComponents(mpUnReach.bgpFlowSpecInfo().flowSpecComponents()); | ||
323 | - bgpFlowSpecDetails.setRouteDistinguiher(mpUnReach.bgpFlowSpecInfo().routeDistinguisher()); | ||
324 | - operType = FlowSpecOperation.DELETE; | ||
325 | - } | ||
326 | - } | ||
327 | - | ||
328 | - iterator = bgpFlowSpecDetails.flowSpecComponents().listIterator(); | ||
329 | - IpPrefix destIpPrefix = null; | ||
330 | - IpPrefix srcIpPrefix = null; | ||
331 | - while (iterator.hasNext()) { | ||
332 | - BgpValueType fsAttr = iterator.next(); | ||
333 | - if (fsAttr instanceof BgpFsDestinationPrefix) { | ||
334 | - BgpFsDestinationPrefix destinationPrefix = (BgpFsDestinationPrefix) fsAttr; | ||
335 | - destIpPrefix = destinationPrefix.ipPrefix(); | ||
336 | - } | ||
337 | - | ||
338 | - if (fsAttr instanceof BgpFsSourcePrefix) { | ||
339 | - BgpFsSourcePrefix sourcePrefix = (BgpFsSourcePrefix) fsAttr; | ||
340 | - srcIpPrefix = sourcePrefix.ipPrefix(); | ||
341 | - } | ||
342 | - } | ||
343 | - BgpFlowSpecPrefix prefix = new BgpFlowSpecPrefix(destIpPrefix, srcIpPrefix); | ||
344 | - if (operType == FlowSpecOperation.ADD) { | ||
345 | - if (bgpFlowSpecDetails.routeDistinguisher() == null) { | ||
346 | - flowSpecRibIn.add(prefix, bgpFlowSpecDetails); | ||
347 | - } else { | ||
348 | - flowSpecRibIn.add(bgpFlowSpecDetails.routeDistinguisher(), prefix, bgpFlowSpecDetails); | ||
349 | - } | ||
350 | - } else if (operType == FlowSpecOperation.DELETE) { | ||
351 | - if (bgpFlowSpecDetails.routeDistinguisher() == null) { | ||
352 | - flowSpecRibIn.delete(prefix); | ||
353 | - } else { | ||
354 | - flowSpecRibIn.delete(bgpFlowSpecDetails.routeDistinguisher(), prefix); | ||
355 | - } | ||
356 | - } | ||
357 | - } | ||
358 | - | ||
359 | /** | 267 | /** |
360 | * Updates NLRI identifier node in a tree separately based on afi and safi. | 268 | * Updates NLRI identifier node in a tree separately based on afi and safi. |
361 | * | 269 | * |
... | @@ -490,46 +398,12 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -490,46 +398,12 @@ public class BgpPeerImpl implements BgpPeer { |
490 | localRibVpn.localRibUpdate(vpnAdjacencyRib()); | 398 | localRibVpn.localRibUpdate(vpnAdjacencyRib()); |
491 | } | 399 | } |
492 | 400 | ||
493 | - /** | ||
494 | - * Update peer flow specification RIB on peer disconnect. | ||
495 | - */ | ||
496 | - public void updateFlowSpecOnPeerDisconnect() { | ||
497 | - | ||
498 | - boolean isCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE, | ||
499 | - Constants.AFI_FLOWSPEC_VALUE, | ||
500 | - Constants.SAFI_FLOWSPEC_VALUE); | ||
501 | - if (isCapabilitySet) { | ||
502 | - Set<BgpFlowSpecPrefix> flowSpecKeys = flowSpecRibOut.flowSpecTree().keySet(); | ||
503 | - for (BgpFlowSpecPrefix key : flowSpecKeys) { | ||
504 | - BgpFlowSpecDetails flowSpecDetails = flowSpecRibOut.flowSpecTree().get(key); | ||
505 | - sendFlowSpecUpdateMessageToPeer(FlowSpecOperation.DELETE, flowSpecDetails); | ||
506 | - } | ||
507 | - } | ||
508 | - | ||
509 | - boolean isVpnCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE, | ||
510 | - Constants.AFI_FLOWSPEC_VALUE, | ||
511 | - Constants.VPN_SAFI_FLOWSPEC_VALUE); | ||
512 | - if (isVpnCapabilitySet) { | ||
513 | - Set<RouteDistinguisher> flowSpecKeys = flowSpecRibOut.vpnFlowSpecTree().keySet(); | ||
514 | - for (RouteDistinguisher key : flowSpecKeys) { | ||
515 | - Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> fsTree = flowSpecRibOut.vpnFlowSpecTree().get(key); | ||
516 | - | ||
517 | - Set<BgpFlowSpecPrefix> fsKeys = fsTree.keySet(); | ||
518 | - for (BgpFlowSpecPrefix fsKey : fsKeys) { | ||
519 | - BgpFlowSpecDetails flowSpecDetails = flowSpecRibOut.flowSpecTree().get(fsKey); | ||
520 | - sendFlowSpecUpdateMessageToPeer(FlowSpecOperation.DELETE, flowSpecDetails); | ||
521 | - } | ||
522 | - } | ||
523 | - } | ||
524 | - } | ||
525 | - | ||
526 | // ************************ | 401 | // ************************ |
527 | // Channel related | 402 | // Channel related |
528 | // ************************ | 403 | // ************************ |
529 | 404 | ||
530 | @Override | 405 | @Override |
531 | public final void disconnectPeer() { | 406 | public final void disconnectPeer() { |
532 | - this.updateFlowSpecOnPeerDisconnect(); | ||
533 | this.channel.close(); | 407 | this.channel.close(); |
534 | } | 408 | } |
535 | 409 | ... | ... |
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