blob: 578f4feaf8c7ec77f2147f3e7ca5730a20193dfa [file] [log] [blame]
Priyanka B3b695542015-10-14 17:16:27 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Priyanka B3b695542015-10-14 17:16:27 +05303 *
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
17package org.onosproject.bgpio.types;
18
Mohammad Shahid30fedc52017-08-09 11:49:40 +053019import com.google.common.base.MoreObjects;
Priyanka B3b695542015-10-14 17:16:27 +053020import org.jboss.netty.buffer.ChannelBuffer;
21import org.onlab.packet.Ip4Address;
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053022import org.onosproject.bgpio.exceptions.BgpParseException;
Mohammad Shahid30fedc52017-08-09 11:49:40 +053023import org.onosproject.bgpio.protocol.BgpEvpnNlri;
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053024import org.onosproject.bgpio.protocol.BgpLSNlri;
Mohammad Shahid30fedc52017-08-09 11:49:40 +053025import org.onosproject.bgpio.protocol.evpn.BgpEvpnNlriImpl;
26import org.onosproject.bgpio.protocol.evpn.BgpEvpnRouteType2Nlri;
Shashikanth VH26fd38a2016-04-26 18:11:37 +053027import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecNlri;
Priyanka Be07ea4d2015-11-21 21:28:10 +053028import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
Mohammad Shahid30fedc52017-08-09 11:49:40 +053029import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
30import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4;
Priyanka B3b695542015-10-14 17:16:27 +053031import org.onosproject.bgpio.util.Constants;
32import org.onosproject.bgpio.util.Validation;
33import org.slf4j.Logger;
34import org.slf4j.LoggerFactory;
35
Mohammad Shahid30fedc52017-08-09 11:49:40 +053036import java.net.InetAddress;
37import java.util.LinkedList;
38import java.util.List;
39import java.util.ListIterator;
Priyanka B3b695542015-10-14 17:16:27 +053040
41/*
42 * Provides Implementation of MpReach Nlri BGP Path Attribute.
43 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053044public class MpReachNlri implements BgpValueType {
Priyanka B3b695542015-10-14 17:16:27 +053045
46 private static final Logger log = LoggerFactory.getLogger(MpReachNlri.class);
Priyanka B3b695542015-10-14 17:16:27 +053047 public static final byte MPREACHNLRI_TYPE = 14;
48 public static final byte LINK_NLRITYPE = 2;
Shashikanth VH510a8d82016-02-12 12:32:43 +053049 public static final byte FLAGS = (byte) 0x90;
Priyanka B3b695542015-10-14 17:16:27 +053050 private boolean isMpReachNlri = false;
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053051 private final List<BgpLSNlri> mpReachNlri;
Priyanka B3b695542015-10-14 17:16:27 +053052 private final int length;
53 private final short afi;
54 private final byte safi;
55 private final Ip4Address ipNextHop;
Shashikanth VH26fd38a2016-04-26 18:11:37 +053056 private BgpFlowSpecNlri bgpFlowSpecNlri;
Mohammad Shahid30fedc52017-08-09 11:49:40 +053057 private List<BgpEvpnNlri> evpnNlri;
Priyanka B3b695542015-10-14 17:16:27 +053058
59 /**
60 * Constructor to initialize parameters.
61 *
62 * @param mpReachNlri MpReach Nlri attribute
63 * @param afi address family identifier
64 * @param safi subsequent address family identifier
65 * @param ipNextHop nexthop IpAddress
66 * @param length of MpReachNlri
67 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053068 public MpReachNlri(List<BgpLSNlri> mpReachNlri, short afi, byte safi, Ip4Address ipNextHop, int length) {
Priyanka B3b695542015-10-14 17:16:27 +053069 this.mpReachNlri = mpReachNlri;
70 this.isMpReachNlri = true;
71 this.ipNextHop = ipNextHop;
72 this.afi = afi;
73 this.safi = safi;
74 this.length = length;
75 }
76
Mohammad Shahid30fedc52017-08-09 11:49:40 +053077 /**
78 * Constructor to initialize parameters.
79 *
80 * @param bgpFlowSpecNlri bgpFlowSpecNlri
81 * @param afi afi
82 * @param safi safi
83 */
Shashikanth VH26fd38a2016-04-26 18:11:37 +053084 public MpReachNlri(BgpFlowSpecNlri bgpFlowSpecNlri, short afi, byte safi) {
Shashikanth VH510a8d82016-02-12 12:32:43 +053085 this.mpReachNlri = null;
86 this.isMpReachNlri = true;
87 this.length = 0;
88 this.ipNextHop = null;
Shashikanth VH26fd38a2016-04-26 18:11:37 +053089 this.bgpFlowSpecNlri = bgpFlowSpecNlri;
Shashikanth VH510a8d82016-02-12 12:32:43 +053090 this.afi = afi;
91 this.safi = safi;
92 }
93
Priyanka B3b695542015-10-14 17:16:27 +053094 /**
Mohammad Shahid30fedc52017-08-09 11:49:40 +053095 * Constructor to initialize parameters.
96 *
97 * @param evpnNlri evpnNlri
98 * @param afi afi
99 * @param safi safi
100 * @param ipNextHop IP Nexthop
101 */
102 public MpReachNlri(List<BgpEvpnNlri> evpnNlri, short afi, byte safi, Ip4Address ipNextHop) {
103 this.mpReachNlri = null;
104 this.length = 42;
105 this.ipNextHop = ipNextHop;
106 this.isMpReachNlri = true;
107 this.evpnNlri = evpnNlri;
108 this.afi = afi;
109 this.safi = safi;
110 }
111
112 /**
Priyanka B3b695542015-10-14 17:16:27 +0530113 * Returns whether MpReachNlri is present.
114 *
115 * @return whether MpReachNlri is present
116 */
117 public boolean isMpReachNlriSet() {
118 return this.isMpReachNlri;
119 }
120
121 /**
122 * Returns list of MpReach Nlri.
123 *
124 * @return list of MpReach Nlri
125 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530126 public List<BgpLSNlri> mpReachNlri() {
Priyanka B3b695542015-10-14 17:16:27 +0530127 return this.mpReachNlri;
128 }
129
130 /**
131 * Returns length of MpReachNlri.
132 *
133 * @return length of MpReachNlri
134 */
135 public int mpReachNlriLen() {
136 return this.length;
137 }
138
139 /**
Shashikanth VH510a8d82016-02-12 12:32:43 +0530140 * Returns BGP flow specification info.
141 *
142 * @return BGP flow specification info
143 */
Shashikanth VH26fd38a2016-04-26 18:11:37 +0530144 public BgpFlowSpecNlri bgpFlowSpecNlri() {
145 return this.bgpFlowSpecNlri;
Shashikanth VH510a8d82016-02-12 12:32:43 +0530146 }
147
148 /**
Mohammad Shahid30fedc52017-08-09 11:49:40 +0530149 * Returns BGP Evpn info.
150 *
151 * @return BGP Evpn info
152 */
153 public List<BgpEvpnNlri> bgpEvpnNlri() {
154 return this.evpnNlri;
155 }
156
157 /**
158 * Returns afi.
159 *
160 * @return afi
161 */
162 public short getAfi() {
163 return this.afi;
164 }
165
166 /**
167 * Returns safi.
168 *
169 * @return safi
170 */
171 public byte getSafi() {
172 return this.safi();
173 }
174
175 /**
176 * Returns mpReachNlri details type.
177 *
178 * @return type
179 */
180 public BgpNlriType getNlriDetailsType() {
181 if ((this.afi == Constants.AFI_VALUE)
182 && (this.safi == Constants.SAFI_VALUE)
183 || (this.afi == Constants.AFI_VALUE)
184 && (this.safi == Constants.VPN_SAFI_VALUE)) {
185 return BgpNlriType.LINK_STATE;
186 }
187
188 if ((afi == Constants.AFI_FLOWSPEC_VALUE)
189 && ((safi == Constants.SAFI_FLOWSPEC_VALUE)
190 || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) {
191 return BgpNlriType.FLOW_SPEC;
192 }
193
194 if ((afi == Constants.AFI_EVPN_VALUE)
195 && (safi == Constants.SAFI_EVPN_VALUE)) {
196 return BgpNlriType.EVPN;
197 }
198
199 return null;
200 }
201
202 /**
Priyanka B3b695542015-10-14 17:16:27 +0530203 * Reads from ChannelBuffer and parses MpReachNlri.
204 *
205 * @param cb channelBuffer
206 * @return object of MpReachNlri
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530207 * @throws BgpParseException while parsing MpReachNlri
Priyanka B3b695542015-10-14 17:16:27 +0530208 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530209 public static MpReachNlri read(ChannelBuffer cb) throws BgpParseException {
Priyanka B3b695542015-10-14 17:16:27 +0530210 ChannelBuffer tempBuf = cb.copy();
211 Validation parseFlags = Validation.parseAttributeHeader(cb);
212 int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT :
213 parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
214 ChannelBuffer data = tempBuf.readBytes(len);
215
216 if (cb.readableBytes() < parseFlags.getLength()) {
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530217 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
Priyanka B3b695542015-10-14 17:16:27 +0530218 parseFlags.getLength());
219 }
220 if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530221 throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
Priyanka B3b695542015-10-14 17:16:27 +0530222 }
223
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530224 BgpLSNlri bgpLSNlri = null;
225 List<BgpLSNlri> mpReachNlri = new LinkedList<>();
Priyanka B3b695542015-10-14 17:16:27 +0530226 ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength());
227 short afi = 0;
228 byte safi = 0;
229 Ip4Address ipNextHop = null;
230 while (tempCb.readableBytes() > 0) {
231 afi = tempCb.readShort();
232 safi = tempCb.readByte();
233
234 //Supporting for AFI 16388 / SAFI 71 and VPN AFI 16388 / SAFI 128
235 if ((afi == Constants.AFI_VALUE) && (safi == Constants.SAFI_VALUE) || (afi == Constants.AFI_VALUE)
236 && (safi == Constants.VPN_SAFI_VALUE)) {
237 byte nextHopLen = tempCb.readByte();
Vidyashree Rama7ba6b4c2015-11-30 17:20:22 +0530238 InetAddress ipAddress = Validation.toInetAddress(nextHopLen, tempCb);
Priyanka B3b695542015-10-14 17:16:27 +0530239 if (ipAddress.isMulticastAddress()) {
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530240 throw new BgpParseException("Multicast not supported");
Priyanka B3b695542015-10-14 17:16:27 +0530241 }
242 ipNextHop = Ip4Address.valueOf(ipAddress);
243 byte reserved = tempCb.readByte();
244
245 while (tempCb.readableBytes() > 0) {
246 short nlriType = tempCb.readShort();
247 short totNlriLen = tempCb.readShort();
248 if (tempCb.readableBytes() < totNlriLen) {
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530249 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
250 BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
Priyanka B3b695542015-10-14 17:16:27 +0530251 }
252 tempBuf = tempCb.readBytes(totNlriLen);
253 switch (nlriType) {
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530254 case BgpNodeLSNlriVer4.NODE_NLRITYPE:
255 bgpLSNlri = BgpNodeLSNlriVer4.read(tempBuf, afi, safi);
Priyanka B3b695542015-10-14 17:16:27 +0530256 break;
Priyanka Be07ea4d2015-11-21 21:28:10 +0530257 case BgpLinkLsNlriVer4.LINK_NLRITYPE:
258 bgpLSNlri = BgpLinkLsNlriVer4.read(tempBuf, afi, safi);
Priyanka B3b695542015-10-14 17:16:27 +0530259 break;
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530260 case BgpPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE:
261 bgpLSNlri = BgpPrefixIPv4LSNlriVer4.read(tempBuf, afi, safi);
Priyanka B3b695542015-10-14 17:16:27 +0530262 break;
263 default:
264 log.debug("nlriType not supported" + nlriType);
265 }
266 mpReachNlri.add(bgpLSNlri);
267 }
Shashikanth VH510a8d82016-02-12 12:32:43 +0530268 } else if ((afi == Constants.AFI_FLOWSPEC_VALUE)
269 && ((safi == Constants.SAFI_FLOWSPEC_VALUE)
270 || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) {
271 List<BgpValueType> flowSpecComponents = new LinkedList<>();
Shashikanth VHe3a73bc2016-02-22 20:11:31 +0530272 RouteDistinguisher routeDistinguisher = null;
Shashikanth VH58260662016-02-13 01:12:02 +0530273 if (tempCb.readableBytes() > 0) {
274 BgpValueType flowSpecComponent = null;
Shashikanth VH510a8d82016-02-12 12:32:43 +0530275
Shashikanth VH58260662016-02-13 01:12:02 +0530276 byte nextHopLen = tempCb.readByte();
277 if (nextHopLen > 0) {
278 InetAddress ipAddress = Validation.toInetAddress(nextHopLen, tempCb);
279 if (ipAddress.isMulticastAddress()) {
280 throw new BgpParseException("Multicast not supported");
281 }
282 ipNextHop = Ip4Address.valueOf(ipAddress);
Shashikanth VH510a8d82016-02-12 12:32:43 +0530283 }
Shashikanth VH58260662016-02-13 01:12:02 +0530284
285 byte reserved = tempCb.readByte();
Shashikanth VHe3a73bc2016-02-22 20:11:31 +0530286
287 if (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE) {
288 routeDistinguisher = new RouteDistinguisher();
289 routeDistinguisher = RouteDistinguisher.read(tempCb);
290 }
Shashikanth VH26fd38a2016-04-26 18:11:37 +0530291 while (tempCb.readableBytes() > 0) {
subhasis77755e43a82017-02-12 07:46:09 +0530292 short totNlriLen = tempCb.getUnsignedByte(tempCb.readerIndex());
Shashikanth VH26fd38a2016-04-26 18:11:37 +0530293 if (totNlriLen >= BgpFlowSpecNlri.FLOW_SPEC_LEN) {
294 if (tempCb.readableBytes() < 2) {
295 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
296 BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
297 }
298 totNlriLen = tempCb.readShort();
299 } else {
300 totNlriLen = tempCb.readByte();
Shashikanth VH58260662016-02-13 01:12:02 +0530301 }
Shashikanth VH26fd38a2016-04-26 18:11:37 +0530302 if (tempCb.readableBytes() < totNlriLen) {
303 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
304 BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
305 }
306 tempBuf = tempCb.readBytes(totNlriLen);
307 while (tempBuf.readableBytes() > 0) {
308 short type = tempBuf.readByte();
309 switch (type) {
310 case Constants.BGP_FLOWSPEC_DST_PREFIX:
311 flowSpecComponent = BgpFsDestinationPrefix.read(tempBuf);
312 break;
313 case Constants.BGP_FLOWSPEC_SRC_PREFIX:
314 flowSpecComponent = BgpFsSourcePrefix.read(tempBuf);
315 break;
316 case Constants.BGP_FLOWSPEC_IP_PROTO:
317 flowSpecComponent = BgpFsIpProtocol.read(tempBuf);
318 break;
319 case Constants.BGP_FLOWSPEC_PORT:
320 flowSpecComponent = BgpFsPortNum.read(tempBuf);
321 break;
322 case Constants.BGP_FLOWSPEC_DST_PORT:
323 flowSpecComponent = BgpFsDestinationPortNum.read(tempBuf);
324 break;
325 case Constants.BGP_FLOWSPEC_SRC_PORT:
326 flowSpecComponent = BgpFsSourcePortNum.read(tempBuf);
327 break;
328 case Constants.BGP_FLOWSPEC_ICMP_TP:
329 flowSpecComponent = BgpFsIcmpType.read(tempBuf);
330 break;
331 case Constants.BGP_FLOWSPEC_ICMP_CD:
332 flowSpecComponent = BgpFsIcmpCode.read(tempBuf);
333 break;
334 case Constants.BGP_FLOWSPEC_TCP_FLAGS:
335 flowSpecComponent = BgpFsTcpFlags.read(tempBuf);
336 break;
337 case Constants.BGP_FLOWSPEC_PCK_LEN:
338 flowSpecComponent = BgpFsPacketLength.read(tempBuf);
339 break;
340 case Constants.BGP_FLOWSPEC_DSCP:
341 flowSpecComponent = BgpFsDscpValue.read(tempBuf);
342 break;
343 case Constants.BGP_FLOWSPEC_FRAGMENT:
344 flowSpecComponent = BgpFsFragment.read(tempBuf);
345 break;
346 default:
347 log.debug("flow spec type not supported" + type);
348 break;
349 }
350 flowSpecComponents.add(flowSpecComponent);
351 }
Shashikanth VH58260662016-02-13 01:12:02 +0530352 }
Shashikanth VH510a8d82016-02-12 12:32:43 +0530353 }
Shashikanth VH26fd38a2016-04-26 18:11:37 +0530354 BgpFlowSpecNlri flowSpecDetails = new BgpFlowSpecNlri(flowSpecComponents);
Shashikanth VHe3a73bc2016-02-22 20:11:31 +0530355 flowSpecDetails.setRouteDistinguiher(routeDistinguisher);
356 return new MpReachNlri(flowSpecDetails, afi, safi);
Mohammad Shahid30fedc52017-08-09 11:49:40 +0530357 } else if ((afi == Constants.AFI_EVPN_VALUE)
358 && (safi == Constants.SAFI_EVPN_VALUE)) {
359
360 List<BgpEvpnNlri> eVpnComponents = null;
361
362 byte nextHopLen = tempCb.readByte();
363 InetAddress ipAddress = Validation.toInetAddress(nextHopLen,
364 tempCb);
365 if (ipAddress.isMulticastAddress()) {
366 throw new BgpParseException("Multicast not supported");
367 }
368 ipNextHop = Ip4Address.valueOf(ipAddress);
369 byte reserved = tempCb.readByte();
370 while (tempCb.readableBytes() > 0) {
371 BgpEvpnNlri eVpnComponent = BgpEvpnNlriImpl.read(tempCb);
372 eVpnComponents = new LinkedList<>();
373 eVpnComponents.add(eVpnComponent);
374 log.info("=====evpn Component is {} ======", eVpnComponent);
375 }
376
377 return new MpReachNlri(eVpnComponents, afi, safi, ipNextHop);
378
379
Priyanka B3b695542015-10-14 17:16:27 +0530380 } else {
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530381 throw new BgpParseException("Not Supporting afi " + afi + "safi " + safi);
Priyanka B3b695542015-10-14 17:16:27 +0530382 }
383 }
384 return new MpReachNlri(mpReachNlri, afi, safi, ipNextHop, parseFlags.getLength());
385 }
386
387 @Override
388 public short getType() {
389 return MPREACHNLRI_TYPE;
390 }
391
392 /**
393 * Returns AFI.
394 *
395 * @return AFI
396 */
397 public short afi() {
398 return this.afi;
399 }
400
401 /**
402 * Returns Nexthop IpAddress.
403 *
404 * @return Nexthop IpAddress
405 */
406 public Ip4Address nexthop4() {
407 return this.ipNextHop;
408 }
409
410 /**
411 * Returns SAFI.
412 *
413 * @return SAFI
414 */
415 public byte safi() {
416 return this.safi;
417 }
418
419 @Override
420 public int write(ChannelBuffer cb) {
Shashikanth VH510a8d82016-02-12 12:32:43 +0530421 int iLenStartIndex = cb.writerIndex();
Shashikanth VH26fd38a2016-04-26 18:11:37 +0530422
Shashikanth VH510a8d82016-02-12 12:32:43 +0530423 if ((afi == Constants.AFI_FLOWSPEC_VALUE) && ((safi == Constants.SAFI_FLOWSPEC_VALUE)
424 || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) {
Shashikanth VH26fd38a2016-04-26 18:11:37 +0530425 List<BgpValueType> flowSpec = bgpFlowSpecNlri.flowSpecComponents();
426 ListIterator<BgpValueType> listIterator = flowSpec.listIterator();
427 boolean isAllFlowTypesIdentical = true;
Shashikanth VH510a8d82016-02-12 12:32:43 +0530428
429 cb.writeByte(FLAGS);
430 cb.writeByte(MPREACHNLRI_TYPE);
431
432 int mpReachDataIndx = cb.writerIndex();
433 cb.writeShort(0);
434
435 cb.writeShort(afi);
436 cb.writeByte(safi);
437 //next hop address
438 cb.writeByte(0);
439 //sub network points of attachment
440 cb.writeByte(0);
441
Shashikanth VH26fd38a2016-04-26 18:11:37 +0530442 if (bgpFlowSpecNlri.routeDistinguisher() != null) {
443 cb.writeLong(bgpFlowSpecNlri.routeDistinguisher().getRouteDistinguisher());
Shashikanth VH510a8d82016-02-12 12:32:43 +0530444 }
445
Shashikanth VH26fd38a2016-04-26 18:11:37 +0530446 BgpValueType tlv1 = null;
447 if (listIterator.hasNext()) {
448 tlv1 = listIterator.next();
449 }
Ray Milkeyfd4f8d32018-01-17 15:24:52 -0800450 while (tlv1 != null && listIterator.hasNext()) {
Shashikanth VH510a8d82016-02-12 12:32:43 +0530451 BgpValueType tlv = listIterator.next();
Shashikanth VH26fd38a2016-04-26 18:11:37 +0530452 if (tlv.getType() != tlv1.getType()) {
453 isAllFlowTypesIdentical = false;
Shashikanth VH510a8d82016-02-12 12:32:43 +0530454 break;
455 }
456 }
457
Shashikanth VH26fd38a2016-04-26 18:11:37 +0530458 if (isAllFlowTypesIdentical) {
459 BgpFlowSpecNlri.updateBufferIdenticalFlowTypes(cb, bgpFlowSpecNlri());
Shashikanth VH510a8d82016-02-12 12:32:43 +0530460 } else {
Shashikanth VH26fd38a2016-04-26 18:11:37 +0530461 BgpFlowSpecNlri.updateBufferNonIdenticalFlowTypes(cb, bgpFlowSpecNlri());
Shashikanth VH510a8d82016-02-12 12:32:43 +0530462 }
Shashikanth VH510a8d82016-02-12 12:32:43 +0530463 int fsNlriLen = cb.writerIndex() - mpReachDataIndx;
464 cb.setShort(mpReachDataIndx, (short) (fsNlriLen - 2));
465
Mohammad Shahid30fedc52017-08-09 11:49:40 +0530466 } else if ((afi == Constants.AFI_EVPN_VALUE)
467 && (safi == Constants.SAFI_EVPN_VALUE)) {
468
469 cb.writeByte(FLAGS);
470 cb.writeByte(MPREACHNLRI_TYPE);
471
472 int mpReachDataIndex = cb.writerIndex();
473 cb.writeShort(0);
474 cb.writeShort(afi);
475 cb.writeByte(safi);
476 // ip address length
477 cb.writeByte(0x04);
478 cb.writeInt(ipNextHop.toInt());
479 //sub network points of attachment
480 cb.writeByte(0);
481
482 for (BgpEvpnNlri element : evpnNlri) {
483 short routeType = element.getType();
484 switch (routeType) {
485 case Constants.BGP_EVPN_MAC_IP_ADVERTISEMENT:
486 cb.writeByte(element.getType());
487 int iSpecStartIndex = cb.writerIndex();
488 cb.writeByte(0);
489 BgpEvpnRouteType2Nlri macIpAdvNlri = (BgpEvpnRouteType2Nlri) element
490 .getNlri();
491 macIpAdvNlri.write(cb);
492 cb.setByte(iSpecStartIndex, (byte) (cb.writerIndex()
493 - iSpecStartIndex - 1));
494 //ChannelBuffer temcb = cb.copy();
495 break;
496 case Constants.BGP_EVPN_ETHERNET_AUTO_DISCOVERY:
497 break;
498 case Constants.BGP_EVPN_INCLUSIVE_MULTICASE_ETHERNET:
499 break;
500 case Constants.BGP_EVPN_ETHERNET_SEGMENT:
501 break;
502 default:
503 break;
504 }
505 }
506 int evpnNlriLen = cb.writerIndex() - mpReachDataIndex;
507 cb.setShort(mpReachDataIndex, (short) (evpnNlriLen - 2));
Shashikanth VH510a8d82016-02-12 12:32:43 +0530508 }
509
510 return cb.writerIndex() - iLenStartIndex;
Priyanka B3b695542015-10-14 17:16:27 +0530511 }
512
513 @Override
514 public String toString() {
Shashikanth VH510a8d82016-02-12 12:32:43 +0530515 return MoreObjects.toStringHelper(getClass()).omitNullValues()
Priyanka B3b695542015-10-14 17:16:27 +0530516 .add("mpReachNlri", mpReachNlri)
Shashikanth VH26fd38a2016-04-26 18:11:37 +0530517 .add("bgpFlowSpecNlri", bgpFlowSpecNlri)
Priyanka B3b695542015-10-14 17:16:27 +0530518 .add("afi", afi)
519 .add("safi", safi)
520 .add("ipNextHop", ipNextHop)
521 .add("length", length)
522 .toString();
523 }
Priyanka B02040732015-11-29 11:30:29 +0530524
525 @Override
526 public int compareTo(Object o) {
527 // TODO Auto-generated method stub
528 return 0;
529 }
Priyanka B3b695542015-10-14 17:16:27 +0530530}