Committed by
Gerrit Code Review
[ONOS-3856] BGP flow specification update message encode.
Change-Id: I4286ea636df154f64c5b27f1f55a26fdc257e4f3
Showing
4 changed files
with
118 additions
and
41 deletions
... | @@ -21,7 +21,6 @@ import java.util.List; | ... | @@ -21,7 +21,6 @@ import java.util.List; |
21 | import org.jboss.netty.buffer.ChannelBuffer; | 21 | import org.jboss.netty.buffer.ChannelBuffer; |
22 | import org.onlab.packet.IpPrefix; | 22 | import org.onlab.packet.IpPrefix; |
23 | import org.onosproject.bgpio.protocol.ver4.BgpPathAttributes; | 23 | import org.onosproject.bgpio.protocol.ver4.BgpPathAttributes; |
24 | -import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails; | ||
25 | import org.onosproject.bgpio.types.BgpValueType; | 24 | import org.onosproject.bgpio.types.BgpValueType; |
26 | import org.onosproject.bgpio.types.BgpHeader; | 25 | import org.onosproject.bgpio.types.BgpHeader; |
27 | 26 | ||
... | @@ -51,10 +50,6 @@ public interface BgpUpdateMsg extends BgpMessage { | ... | @@ -51,10 +50,6 @@ public interface BgpUpdateMsg extends BgpMessage { |
51 | 50 | ||
52 | Builder setBgpPathAttributes(List<BgpValueType> attributes); | 51 | Builder setBgpPathAttributes(List<BgpValueType> attributes); |
53 | 52 | ||
54 | - Builder setNlriIdentifier(short afi, byte safi); | ||
55 | - | ||
56 | - Builder setBgpFlowSpecComponents(BgpFlowSpecDetails flowSpecComponents); | ||
57 | - | ||
58 | @Override | 53 | @Override |
59 | Builder setHeader(BgpHeader bgpMsgHeader); | 54 | Builder setHeader(BgpHeader bgpMsgHeader); |
60 | } | 55 | } | ... | ... |
... | @@ -27,8 +27,8 @@ import com.google.common.base.MoreObjects; | ... | @@ -27,8 +27,8 @@ import com.google.common.base.MoreObjects; |
27 | */ | 27 | */ |
28 | public class BgpFlowSpecDetails { | 28 | public class BgpFlowSpecDetails { |
29 | private List<BgpValueType> flowSpecComponents; | 29 | private List<BgpValueType> flowSpecComponents; |
30 | - BgpValueType fsActionTlv; | 30 | + private BgpValueType fsActionTlv; |
31 | - RouteDistinguisher routeDistinguisher; | 31 | + private RouteDistinguisher routeDistinguisher; |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * Flow specification details object constructor with the parameter. | 34 | * Flow specification details object constructor with the parameter. | ... | ... |
... | @@ -17,12 +17,14 @@ package org.onosproject.bgpio.protocol.ver4; | ... | @@ -17,12 +17,14 @@ package org.onosproject.bgpio.protocol.ver4; |
17 | 17 | ||
18 | import java.util.LinkedList; | 18 | import java.util.LinkedList; |
19 | import java.util.List; | 19 | import java.util.List; |
20 | +import java.util.ListIterator; | ||
20 | 21 | ||
21 | import org.jboss.netty.buffer.ChannelBuffer; | 22 | import org.jboss.netty.buffer.ChannelBuffer; |
22 | import org.onosproject.bgpio.exceptions.BgpParseException; | 23 | import org.onosproject.bgpio.exceptions.BgpParseException; |
23 | import org.onosproject.bgpio.types.As4Path; | 24 | import org.onosproject.bgpio.types.As4Path; |
24 | import org.onosproject.bgpio.types.AsPath; | 25 | import org.onosproject.bgpio.types.AsPath; |
25 | import org.onosproject.bgpio.types.BgpErrorType; | 26 | import org.onosproject.bgpio.types.BgpErrorType; |
27 | +import org.onosproject.bgpio.types.BgpExtendedCommunity; | ||
26 | import org.onosproject.bgpio.types.BgpValueType; | 28 | import org.onosproject.bgpio.types.BgpValueType; |
27 | import org.onosproject.bgpio.types.LinkStateAttributes; | 29 | import org.onosproject.bgpio.types.LinkStateAttributes; |
28 | import org.onosproject.bgpio.types.LocalPref; | 30 | import org.onosproject.bgpio.types.LocalPref; |
... | @@ -33,6 +35,7 @@ import org.onosproject.bgpio.types.MpReachNlri; | ... | @@ -33,6 +35,7 @@ import org.onosproject.bgpio.types.MpReachNlri; |
33 | import org.onosproject.bgpio.types.MpUnReachNlri; | 35 | import org.onosproject.bgpio.types.MpUnReachNlri; |
34 | import org.onosproject.bgpio.util.UnSupportedAttribute; | 36 | import org.onosproject.bgpio.util.UnSupportedAttribute; |
35 | import org.onosproject.bgpio.util.Validation; | 37 | import org.onosproject.bgpio.util.Validation; |
38 | +import org.onosproject.bgpio.util.Constants; | ||
36 | import org.slf4j.Logger; | 39 | import org.slf4j.Logger; |
37 | import org.slf4j.LoggerFactory; | 40 | import org.slf4j.LoggerFactory; |
38 | 41 | ||
... | @@ -58,6 +61,7 @@ public class BgpPathAttributes { | ... | @@ -58,6 +61,7 @@ public class BgpPathAttributes { |
58 | public static final int LINK_STATE_ATTRIBUTE_TYPE = 29; | 61 | public static final int LINK_STATE_ATTRIBUTE_TYPE = 29; |
59 | public static final int MPREACHNLRI_TYPE = 14; | 62 | public static final int MPREACHNLRI_TYPE = 14; |
60 | public static final int MPUNREACHNLRI_TYPE = 15; | 63 | public static final int MPUNREACHNLRI_TYPE = 15; |
64 | + public static final int EXTENDED_COMMUNITY_TYPE = 16; | ||
61 | 65 | ||
62 | private final List<BgpValueType> pathAttribute; | 66 | private final List<BgpValueType> pathAttribute; |
63 | 67 | ||
... | @@ -142,6 +146,9 @@ public class BgpPathAttributes { | ... | @@ -142,6 +146,9 @@ public class BgpPathAttributes { |
142 | case LINK_STATE_ATTRIBUTE_TYPE: | 146 | case LINK_STATE_ATTRIBUTE_TYPE: |
143 | pathAttribute = LinkStateAttributes.read(cb); | 147 | pathAttribute = LinkStateAttributes.read(cb); |
144 | break; | 148 | break; |
149 | + case EXTENDED_COMMUNITY_TYPE: | ||
150 | + pathAttribute = BgpExtendedCommunity.read(cb); | ||
151 | + break; | ||
145 | default: | 152 | default: |
146 | //skip bytes for unsupported attribute types | 153 | //skip bytes for unsupported attribute types |
147 | UnSupportedAttribute.read(cb); | 154 | UnSupportedAttribute.read(cb); |
... | @@ -155,6 +162,81 @@ public class BgpPathAttributes { | ... | @@ -155,6 +162,81 @@ public class BgpPathAttributes { |
155 | } | 162 | } |
156 | 163 | ||
157 | /** | 164 | /** |
165 | + * Write path attributes to channelBuffer. | ||
166 | + * | ||
167 | + * @param cb channelBuffer | ||
168 | + * @return object of BgpPathAttributes | ||
169 | + * @throws BgpParseException while parsing BGP path attributes | ||
170 | + */ | ||
171 | + public int write(ChannelBuffer cb) | ||
172 | + throws BgpParseException { | ||
173 | + | ||
174 | + if (pathAttribute == null) { | ||
175 | + return 0; | ||
176 | + } | ||
177 | + int iLenStartIndex = cb.writerIndex(); | ||
178 | + | ||
179 | + ListIterator<BgpValueType> iterator = pathAttribute.listIterator(); | ||
180 | + | ||
181 | + int pathAttributeIndx = cb.writerIndex(); | ||
182 | + cb.writeShort(0); | ||
183 | + | ||
184 | + while (iterator.hasNext()) { | ||
185 | + | ||
186 | + BgpValueType attr = iterator.next(); | ||
187 | + | ||
188 | + switch (attr.getType()) { | ||
189 | + case Origin.ORIGIN_TYPE: | ||
190 | + Origin origin = (Origin) attr; | ||
191 | + origin.write(cb); | ||
192 | + break; | ||
193 | + case AsPath.ASPATH_TYPE: | ||
194 | + AsPath asPath = (AsPath) attr; | ||
195 | + asPath.write(cb); | ||
196 | + break; | ||
197 | + case As4Path.AS4PATH_TYPE: | ||
198 | + As4Path as4Path = (As4Path) attr; | ||
199 | + as4Path.write(cb); | ||
200 | + break; | ||
201 | + case NextHop.NEXTHOP_TYPE: | ||
202 | + NextHop nextHop = (NextHop) attr; | ||
203 | + nextHop.write(cb); | ||
204 | + break; | ||
205 | + case Med.MED_TYPE: | ||
206 | + Med med = (Med) attr; | ||
207 | + med.write(cb); | ||
208 | + break; | ||
209 | + case LocalPref.LOCAL_PREF_TYPE: | ||
210 | + LocalPref localPref = (LocalPref) attr; | ||
211 | + localPref.write(cb); | ||
212 | + break; | ||
213 | + case Constants.BGP_EXTENDED_COMMUNITY: | ||
214 | + BgpExtendedCommunity extendedCommunity = (BgpExtendedCommunity) attr; | ||
215 | + extendedCommunity.write(cb); | ||
216 | + break; | ||
217 | + case MpReachNlri.MPREACHNLRI_TYPE: | ||
218 | + MpReachNlri mpReach = (MpReachNlri) attr; | ||
219 | + mpReach.write(cb); | ||
220 | + break; | ||
221 | + case MpUnReachNlri.MPUNREACHNLRI_TYPE: | ||
222 | + MpUnReachNlri mpUnReach = (MpUnReachNlri) attr; | ||
223 | + mpUnReach.write(cb); | ||
224 | + break; | ||
225 | + case LINK_STATE_ATTRIBUTE_TYPE: | ||
226 | + LinkStateAttributes linkState = (LinkStateAttributes) attr; | ||
227 | + linkState.write(cb); | ||
228 | + break; | ||
229 | + default: | ||
230 | + return cb.writerIndex() - iLenStartIndex; | ||
231 | + } | ||
232 | + } | ||
233 | + | ||
234 | + int pathAttrLen = cb.writerIndex() - pathAttributeIndx; | ||
235 | + cb.setShort(pathAttributeIndx, (short) (pathAttrLen - 2)); | ||
236 | + return cb.writerIndex() - iLenStartIndex; | ||
237 | + } | ||
238 | + | ||
239 | + /** | ||
158 | * Checks mandatory attributes are presents, if not present throws exception. | 240 | * Checks mandatory attributes are presents, if not present throws exception. |
159 | * | 241 | * |
160 | * @param isOrigin say whether origin attribute is present | 242 | * @param isOrigin say whether origin attribute is present | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.bgpio.protocol.ver4; | 16 | package org.onosproject.bgpio.protocol.ver4; |
17 | 17 | ||
18 | +import java.util.Iterator; | ||
18 | import java.util.LinkedList; | 19 | import java.util.LinkedList; |
19 | import java.util.List; | 20 | import java.util.List; |
20 | 21 | ||
... | @@ -26,9 +27,10 @@ import org.onosproject.bgpio.protocol.BgpMessageWriter; | ... | @@ -26,9 +27,10 @@ import org.onosproject.bgpio.protocol.BgpMessageWriter; |
26 | import org.onosproject.bgpio.protocol.BgpType; | 27 | import org.onosproject.bgpio.protocol.BgpType; |
27 | import org.onosproject.bgpio.protocol.BgpUpdateMsg; | 28 | import org.onosproject.bgpio.protocol.BgpUpdateMsg; |
28 | import org.onosproject.bgpio.protocol.BgpVersion; | 29 | import org.onosproject.bgpio.protocol.BgpVersion; |
29 | -import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails; | ||
30 | import org.onosproject.bgpio.types.BgpErrorType; | 30 | import org.onosproject.bgpio.types.BgpErrorType; |
31 | import org.onosproject.bgpio.types.BgpHeader; | 31 | import org.onosproject.bgpio.types.BgpHeader; |
32 | +import org.onosproject.bgpio.types.MpReachNlri; | ||
33 | +import org.onosproject.bgpio.types.MpUnReachNlri; | ||
32 | import org.onosproject.bgpio.util.Constants; | 34 | import org.onosproject.bgpio.util.Constants; |
33 | import org.onosproject.bgpio.util.Validation; | 35 | import org.onosproject.bgpio.util.Validation; |
34 | 36 | ||
... | @@ -94,9 +96,6 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg { | ... | @@ -94,9 +96,6 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg { |
94 | private BgpPathAttributes bgpPathAttributes; | 96 | private BgpPathAttributes bgpPathAttributes; |
95 | private BgpHeader bgpHeader; | 97 | private BgpHeader bgpHeader; |
96 | private List<IpPrefix> nlri; | 98 | private List<IpPrefix> nlri; |
97 | - private BgpFlowSpecDetails bgpFlowSpecComponents; | ||
98 | - private short afi; | ||
99 | - private byte safi; | ||
100 | 99 | ||
101 | /** | 100 | /** |
102 | * Constructor to initialize parameters for BGP Update message. | 101 | * Constructor to initialize parameters for BGP Update message. |
... | @@ -114,15 +113,6 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg { | ... | @@ -114,15 +113,6 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg { |
114 | this.nlri = nlri; | 113 | this.nlri = nlri; |
115 | } | 114 | } |
116 | 115 | ||
117 | - public BgpUpdateMsgVer4(BgpHeader bgpHeader, short afi, byte safi, BgpPathAttributes bgpPathAttributes, | ||
118 | - BgpFlowSpecDetails bgpFlowSpecComponents) { | ||
119 | - this.bgpHeader = bgpHeader; | ||
120 | - this.bgpFlowSpecComponents = bgpFlowSpecComponents; | ||
121 | - this.bgpPathAttributes = bgpPathAttributes; | ||
122 | - this.afi = afi; | ||
123 | - this.safi = safi; | ||
124 | - } | ||
125 | - | ||
126 | /** | 116 | /** |
127 | * Reader reads BGP Update Message from the channel buffer. | 117 | * Reader reads BGP Update Message from the channel buffer. |
128 | */ | 118 | */ |
... | @@ -191,16 +181,15 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg { | ... | @@ -191,16 +181,15 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg { |
191 | */ | 181 | */ |
192 | static class Builder implements BgpUpdateMsg.Builder { | 182 | static class Builder implements BgpUpdateMsg.Builder { |
193 | BgpHeader bgpMsgHeader = null; | 183 | BgpHeader bgpMsgHeader = null; |
194 | - BgpFlowSpecDetails bgpFlowSpecComponents; | ||
195 | BgpPathAttributes bgpPathAttributes; | 184 | BgpPathAttributes bgpPathAttributes; |
196 | - private short afi; | 185 | + List<IpPrefix> withdrawnRoutes; |
197 | - private byte safi; | 186 | + List<IpPrefix> nlri; |
198 | 187 | ||
199 | @Override | 188 | @Override |
200 | - public BgpUpdateMsg build() /* throws BgpParseException */ { | 189 | + public BgpUpdateMsg build() { |
201 | BgpHeader bgpMsgHeader = DEFAULT_UPDATE_HEADER; | 190 | BgpHeader bgpMsgHeader = DEFAULT_UPDATE_HEADER; |
202 | 191 | ||
203 | - return new BgpUpdateMsgVer4(bgpMsgHeader, afi, safi, bgpPathAttributes, bgpFlowSpecComponents); | 192 | + return new BgpUpdateMsgVer4(bgpMsgHeader, withdrawnRoutes, bgpPathAttributes, nlri); |
204 | } | 193 | } |
205 | 194 | ||
206 | @Override | 195 | @Override |
... | @@ -210,23 +199,11 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg { | ... | @@ -210,23 +199,11 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg { |
210 | } | 199 | } |
211 | 200 | ||
212 | @Override | 201 | @Override |
213 | - public Builder setBgpFlowSpecComponents(BgpFlowSpecDetails bgpFlowSpecComponents) { | ||
214 | - this.bgpFlowSpecComponents = bgpFlowSpecComponents; | ||
215 | - return this; | ||
216 | - } | ||
217 | - | ||
218 | - @Override | ||
219 | public Builder setBgpPathAttributes(List<BgpValueType> attributes) { | 202 | public Builder setBgpPathAttributes(List<BgpValueType> attributes) { |
220 | this.bgpPathAttributes = new BgpPathAttributes(attributes); | 203 | this.bgpPathAttributes = new BgpPathAttributes(attributes); |
221 | return this; | 204 | return this; |
222 | } | 205 | } |
223 | 206 | ||
224 | - @Override | ||
225 | - public Builder setNlriIdentifier(short afi, byte safi) { | ||
226 | - this.afi = afi; | ||
227 | - this.safi = safi; | ||
228 | - return this; | ||
229 | - } | ||
230 | } | 207 | } |
231 | 208 | ||
232 | public static final Writer WRITER = new Writer(); | 209 | public static final Writer WRITER = new Writer(); |
... | @@ -240,6 +217,8 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg { | ... | @@ -240,6 +217,8 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg { |
240 | public void write(ChannelBuffer cb, BgpUpdateMsgVer4 message) throws BgpParseException { | 217 | public void write(ChannelBuffer cb, BgpUpdateMsgVer4 message) throws BgpParseException { |
241 | 218 | ||
242 | int startIndex = cb.writerIndex(); | 219 | int startIndex = cb.writerIndex(); |
220 | + short afi = 0; | ||
221 | + byte safi = 0; | ||
243 | 222 | ||
244 | // write common header and get msg length index | 223 | // write common header and get msg length index |
245 | int msgLenIndex = message.bgpHeader.write(cb); | 224 | int msgLenIndex = message.bgpHeader.write(cb); |
... | @@ -247,13 +226,34 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg { | ... | @@ -247,13 +226,34 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg { |
247 | if (msgLenIndex <= 0) { | 226 | if (msgLenIndex <= 0) { |
248 | throw new BgpParseException("Unable to write message header."); | 227 | throw new BgpParseException("Unable to write message header."); |
249 | } | 228 | } |
229 | + List<BgpValueType> pathAttr = message.bgpPathAttributes.pathAttributes(); | ||
230 | + if (pathAttr != null) { | ||
231 | + Iterator<BgpValueType> listIterator = pathAttr.iterator(); | ||
232 | + | ||
233 | + while (listIterator.hasNext()) { | ||
234 | + BgpValueType attr = listIterator.next(); | ||
235 | + if (attr instanceof MpReachNlri) { | ||
236 | + MpReachNlri mpReach = (MpReachNlri) attr; | ||
237 | + afi = mpReach.afi(); | ||
238 | + safi = mpReach.safi(); | ||
239 | + } else if (attr instanceof MpUnReachNlri) { | ||
240 | + MpUnReachNlri mpUnReach = (MpUnReachNlri) attr; | ||
241 | + afi = mpUnReach.afi(); | ||
242 | + safi = mpUnReach.safi(); | ||
243 | + } | ||
244 | + | ||
245 | + if ((afi == Constants.AFI_FLOWSPEC_VALUE) && ((safi == Constants.SAFI_FLOWSPEC_VALUE) | ||
246 | + || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { | ||
247 | + //unfeasible route length | ||
248 | + cb.writeShort(0); | ||
249 | + } | ||
250 | + } | ||
250 | 251 | ||
251 | - if ((message.afi == Constants.AFI_FLOWSPEC_VALUE) && (message.safi == Constants.SAFI_FLOWSPEC_VALUE)) { | ||
252 | - //unfeasible route length | ||
253 | - cb.writeShort(0); | ||
254 | } | 252 | } |
255 | 253 | ||
256 | - // TODO: write path attributes | 254 | + if (message.bgpPathAttributes != null) { |
255 | + message.bgpPathAttributes.write(cb); | ||
256 | + } | ||
257 | 257 | ||
258 | // write UPDATE Object Length | 258 | // write UPDATE Object Length |
259 | int length = cb.writerIndex() - startIndex; | 259 | int length = cb.writerIndex() - startIndex; | ... | ... |
-
Please register or login to post a comment