Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 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.bgpio.types; |
| 18 | |
Mohammad Shahid | 30fedc5 | 2017-08-09 11:49:40 +0530 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 20 | import org.jboss.netty.buffer.ChannelBuffer; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 21 | import org.onosproject.bgpio.exceptions.BgpParseException; |
Mohammad Shahid | 30fedc5 | 2017-08-09 11:49:40 +0530 | [diff] [blame] | 22 | import org.onosproject.bgpio.protocol.BgpEvpnNlri; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 23 | import org.onosproject.bgpio.protocol.BgpLSNlri; |
Mohammad Shahid | 30fedc5 | 2017-08-09 11:49:40 +0530 | [diff] [blame] | 24 | import org.onosproject.bgpio.protocol.evpn.BgpEvpnNlriImpl; |
| 25 | import org.onosproject.bgpio.protocol.evpn.BgpEvpnRouteType2Nlri; |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 26 | import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecNlri; |
Mohammad Shahid | 30fedc5 | 2017-08-09 11:49:40 +0530 | [diff] [blame] | 27 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 28 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; |
| 29 | import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4; |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 30 | import org.onosproject.bgpio.util.Constants; |
| 31 | import org.onosproject.bgpio.util.Validation; |
| 32 | import org.slf4j.Logger; |
| 33 | import org.slf4j.LoggerFactory; |
| 34 | |
Mohammad Shahid | 30fedc5 | 2017-08-09 11:49:40 +0530 | [diff] [blame] | 35 | import java.util.LinkedList; |
| 36 | import java.util.List; |
| 37 | import java.util.ListIterator; |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Provides Implementation of MpUnReach Nlri BGP Path Attribute. |
| 41 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 42 | public class MpUnReachNlri implements BgpValueType { |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 43 | |
Priyanka B | e07ea4d | 2015-11-21 21:28:10 +0530 | [diff] [blame] | 44 | private static final Logger log = LoggerFactory.getLogger(MpUnReachNlri.class); |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 45 | public static final byte MPUNREACHNLRI_TYPE = 15; |
| 46 | public static final byte LINK_NLRITYPE = 2; |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 47 | public static final byte FLAGS = (byte) 0x90; |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 48 | private boolean isMpUnReachNlri = false; |
| 49 | private final short afi; |
| 50 | private final byte safi; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 51 | private final List<BgpLSNlri> mpUnReachNlri; |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 52 | private final int length; |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 53 | private BgpFlowSpecNlri bgpFlowSpecNlri; |
Mohammad Shahid | 30fedc5 | 2017-08-09 11:49:40 +0530 | [diff] [blame] | 54 | private List<BgpEvpnNlri> evpnNlri; |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Constructor to initialize parameters. |
| 58 | * |
| 59 | * @param mpUnReachNlri MpUnReach Nlri attribute |
| 60 | * @param afi address family identifier |
| 61 | * @param safi subsequent address family identifier |
| 62 | * @param length of MpUnReachNlri |
| 63 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 64 | public MpUnReachNlri(List<BgpLSNlri> mpUnReachNlri, short afi, byte safi, |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 65 | int length) { |
| 66 | this.mpUnReachNlri = mpUnReachNlri; |
| 67 | this.isMpUnReachNlri = true; |
| 68 | this.afi = afi; |
| 69 | this.safi = safi; |
| 70 | this.length = length; |
| 71 | } |
| 72 | |
Mohammad Shahid | 30fedc5 | 2017-08-09 11:49:40 +0530 | [diff] [blame] | 73 | /** |
| 74 | * Constructor to initialize parameters. |
| 75 | * |
| 76 | * @param bgpFlowSpecNlri bgpFlowSpecNlri |
| 77 | * @param afi afi |
| 78 | * @param safi safi |
| 79 | */ |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 80 | public MpUnReachNlri(BgpFlowSpecNlri bgpFlowSpecNlri, short afi, byte safi) { |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 81 | this.mpUnReachNlri = null; |
| 82 | this.isMpUnReachNlri = true; |
| 83 | this.length = 0; |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 84 | this.bgpFlowSpecNlri = bgpFlowSpecNlri; |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 85 | this.afi = afi; |
| 86 | this.safi = safi; |
| 87 | } |
| 88 | |
| 89 | /** |
Mohammad Shahid | 30fedc5 | 2017-08-09 11:49:40 +0530 | [diff] [blame] | 90 | * Constructor to initialize parameters. |
| 91 | * |
| 92 | * @param evpnNlri evpnNlri |
| 93 | * @param afi afi |
| 94 | * @param safi safi |
| 95 | */ |
| 96 | public MpUnReachNlri(List<BgpEvpnNlri> evpnNlri, short afi, byte safi) { |
| 97 | this.mpUnReachNlri = null; |
| 98 | this.isMpUnReachNlri = true; |
| 99 | this.length = 0; |
| 100 | this.evpnNlri = evpnNlri; |
| 101 | this.afi = afi; |
| 102 | this.safi = safi; |
| 103 | } |
| 104 | |
| 105 | /** |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 106 | * Returns BGP flow specification info. |
| 107 | * |
| 108 | * @return BGP flow specification info |
| 109 | */ |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 110 | public BgpFlowSpecNlri bgpFlowSpecNlri() { |
| 111 | return this.bgpFlowSpecNlri; |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 112 | } |
| 113 | |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 114 | /** |
Mohammad Shahid | 30fedc5 | 2017-08-09 11:49:40 +0530 | [diff] [blame] | 115 | * Returns BGP Evpn info. |
| 116 | * |
| 117 | * @return BGP Evpn info |
| 118 | */ |
| 119 | public List<BgpEvpnNlri> bgpEvpnNlri() { |
| 120 | return this.evpnNlri; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Returns afi. |
| 125 | * |
| 126 | * @return afi |
| 127 | */ |
| 128 | public short getAfi() { |
| 129 | return this.afi; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Returns safi. |
| 134 | * |
| 135 | * @return safi |
| 136 | */ |
| 137 | public byte getSafi() { |
| 138 | return this.safi(); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Returns mpUnReachNlri details type. |
| 143 | * |
| 144 | * @return type |
| 145 | */ |
| 146 | public BgpNlriType getNlriDetailsType() { |
| 147 | if ((this.afi == Constants.AFI_VALUE) |
| 148 | && (this.safi == Constants.SAFI_VALUE) |
| 149 | || (this.afi == Constants.AFI_VALUE) |
| 150 | && (this.safi == Constants.VPN_SAFI_VALUE)) { |
| 151 | return BgpNlriType.LINK_STATE; |
| 152 | } |
| 153 | |
| 154 | if ((afi == Constants.AFI_FLOWSPEC_VALUE) |
| 155 | && ((safi == Constants.SAFI_FLOWSPEC_VALUE) |
| 156 | || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { |
| 157 | return BgpNlriType.FLOW_SPEC; |
| 158 | } |
| 159 | |
| 160 | if ((afi == Constants.AFI_EVPN_VALUE) |
| 161 | && (safi == Constants.SAFI_EVPN_VALUE)) { |
| 162 | return BgpNlriType.EVPN; |
| 163 | } |
| 164 | |
| 165 | return null; |
| 166 | } |
| 167 | |
| 168 | /** |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 169 | * Reads from ChannelBuffer and parses MpUnReachNlri. |
| 170 | * |
| 171 | * @param cb ChannelBuffer |
| 172 | * @return object of MpUnReachNlri |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 173 | * @throws BgpParseException while parsing MpUnReachNlri |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 174 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 175 | public static MpUnReachNlri read(ChannelBuffer cb) throws BgpParseException { |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 176 | ChannelBuffer tempBuf = cb.copy(); |
| 177 | Validation parseFlags = Validation.parseAttributeHeader(cb); |
| 178 | int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT |
| 179 | : parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE; |
| 180 | ChannelBuffer data = tempBuf.readBytes(len); |
| 181 | |
| 182 | if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() |
| 183 | && parseFlags.getThirdBit()) { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 184 | throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, |
| 185 | BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data); |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | if (cb.readableBytes() < parseFlags.getLength()) { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 189 | Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, |
| 190 | BgpErrorType.ATTRIBUTE_LENGTH_ERROR, parseFlags.getLength()); |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 191 | } |
| 192 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 193 | LinkedList<BgpLSNlri> mpUnReachNlri = new LinkedList<>(); |
| 194 | BgpLSNlri bgpLSNlri = null; |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 195 | short afi = 0; |
| 196 | byte safi = 0; |
| 197 | ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength()); |
| 198 | while (tempCb.readableBytes() > 0) { |
| 199 | afi = tempCb.readShort(); |
| 200 | safi = tempCb.readByte(); |
| 201 | |
| 202 | //Supporting only for AFI 16388 / SAFI 71 |
| 203 | if ((afi == Constants.AFI_VALUE) && (safi == Constants.SAFI_VALUE) |
| 204 | || (afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) { |
| 205 | while (tempCb.readableBytes() > 0) { |
| 206 | short nlriType = tempCb.readShort(); |
| 207 | short totNlriLen = tempCb.readShort(); |
| 208 | if (tempCb.readableBytes() < totNlriLen) { |
| 209 | Validation.validateLen( |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 210 | BgpErrorType.UPDATE_MESSAGE_ERROR, |
| 211 | BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 212 | } |
| 213 | tempBuf = tempCb.readBytes(totNlriLen); |
| 214 | switch (nlriType) { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 215 | case BgpNodeLSNlriVer4.NODE_NLRITYPE: |
| 216 | bgpLSNlri = BgpNodeLSNlriVer4.read(tempBuf, afi, safi); |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 217 | break; |
Priyanka B | e07ea4d | 2015-11-21 21:28:10 +0530 | [diff] [blame] | 218 | case BgpLinkLsNlriVer4.LINK_NLRITYPE: |
| 219 | bgpLSNlri = BgpLinkLsNlriVer4.read(tempBuf, afi, safi); |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 220 | break; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 221 | case BgpPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE: |
| 222 | bgpLSNlri = BgpPrefixIPv4LSNlriVer4.read(tempBuf, afi, |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 223 | safi); |
| 224 | break; |
| 225 | default: |
| 226 | log.debug("nlriType not supported" + nlriType); |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 227 | break; |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 228 | } |
| 229 | mpUnReachNlri.add(bgpLSNlri); |
| 230 | } |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 231 | } else if ((afi == Constants.AFI_FLOWSPEC_VALUE) |
| 232 | && ((safi == Constants.SAFI_FLOWSPEC_VALUE) |
| 233 | || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { |
| 234 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 235 | RouteDistinguisher routeDistinguisher = null; |
Shashikanth VH | 5826066 | 2016-02-13 01:12:02 +0530 | [diff] [blame] | 236 | if (tempCb.readableBytes() > 0) { |
| 237 | BgpValueType flowSpecComponent = null; |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 238 | |
| 239 | if (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE) { |
| 240 | routeDistinguisher = new RouteDistinguisher(); |
| 241 | routeDistinguisher = RouteDistinguisher.read(tempCb); |
| 242 | } |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 243 | while (tempCb.readableBytes() > 0) { |
subhasis777 | 55e43a8 | 2017-02-12 07:46:09 +0530 | [diff] [blame] | 244 | short totNlriLen = tempCb.getUnsignedByte(tempCb.readerIndex()); |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 245 | if (totNlriLen >= BgpFlowSpecNlri.FLOW_SPEC_LEN) { |
| 246 | if (tempCb.readableBytes() < 2) { |
| 247 | Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, |
| 248 | BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); |
| 249 | } |
| 250 | totNlriLen = tempCb.readShort(); |
| 251 | } else { |
| 252 | totNlriLen = tempCb.readByte(); |
Shashikanth VH | 5826066 | 2016-02-13 01:12:02 +0530 | [diff] [blame] | 253 | } |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 254 | if (tempCb.readableBytes() < totNlriLen) { |
| 255 | Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, |
| 256 | BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); |
| 257 | } |
| 258 | tempBuf = tempCb.readBytes(totNlriLen); |
| 259 | while (tempBuf.readableBytes() > 0) { |
| 260 | short type = tempBuf.readByte(); |
| 261 | switch (type) { |
| 262 | case Constants.BGP_FLOWSPEC_DST_PREFIX: |
| 263 | flowSpecComponent = BgpFsDestinationPrefix.read(tempBuf); |
| 264 | break; |
| 265 | case Constants.BGP_FLOWSPEC_SRC_PREFIX: |
| 266 | flowSpecComponent = BgpFsSourcePrefix.read(tempBuf); |
| 267 | break; |
| 268 | case Constants.BGP_FLOWSPEC_IP_PROTO: |
| 269 | flowSpecComponent = BgpFsIpProtocol.read(tempBuf); |
| 270 | break; |
| 271 | case Constants.BGP_FLOWSPEC_PORT: |
| 272 | flowSpecComponent = BgpFsPortNum.read(tempBuf); |
| 273 | break; |
| 274 | case Constants.BGP_FLOWSPEC_DST_PORT: |
| 275 | flowSpecComponent = BgpFsDestinationPortNum.read(tempBuf); |
| 276 | break; |
| 277 | case Constants.BGP_FLOWSPEC_SRC_PORT: |
| 278 | flowSpecComponent = BgpFsSourcePortNum.read(tempBuf); |
| 279 | break; |
| 280 | case Constants.BGP_FLOWSPEC_ICMP_TP: |
| 281 | flowSpecComponent = BgpFsIcmpType.read(tempBuf); |
| 282 | break; |
| 283 | case Constants.BGP_FLOWSPEC_ICMP_CD: |
| 284 | flowSpecComponent = BgpFsIcmpCode.read(tempBuf); |
| 285 | break; |
| 286 | case Constants.BGP_FLOWSPEC_TCP_FLAGS: |
| 287 | flowSpecComponent = BgpFsTcpFlags.read(tempBuf); |
| 288 | break; |
| 289 | case Constants.BGP_FLOWSPEC_PCK_LEN: |
| 290 | flowSpecComponent = BgpFsPacketLength.read(tempBuf); |
| 291 | break; |
| 292 | case Constants.BGP_FLOWSPEC_DSCP: |
| 293 | flowSpecComponent = BgpFsDscpValue.read(tempBuf); |
| 294 | break; |
| 295 | case Constants.BGP_FLOWSPEC_FRAGMENT: |
| 296 | flowSpecComponent = BgpFsFragment.read(tempBuf); |
| 297 | break; |
| 298 | default: |
| 299 | log.debug("flow spec type not supported" + type); |
| 300 | break; |
| 301 | } |
| 302 | flowSpecComponents.add(flowSpecComponent); |
| 303 | } |
Shashikanth VH | 5826066 | 2016-02-13 01:12:02 +0530 | [diff] [blame] | 304 | } |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 305 | } |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 306 | BgpFlowSpecNlri flowSpecDetails = new BgpFlowSpecNlri(flowSpecComponents); |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 307 | flowSpecDetails.setRouteDistinguiher(routeDistinguisher); |
| 308 | return new MpUnReachNlri(flowSpecDetails, afi, safi); |
Mohammad Shahid | 30fedc5 | 2017-08-09 11:49:40 +0530 | [diff] [blame] | 309 | } else if ((afi == Constants.AFI_EVPN_VALUE) |
| 310 | && (safi == Constants.SAFI_EVPN_VALUE)) { |
| 311 | List<BgpEvpnNlri> eVpnComponents = null; |
| 312 | while (tempCb.readableBytes() > 0) { |
| 313 | BgpEvpnNlri eVpnComponent = BgpEvpnNlriImpl.read(tempCb); |
| 314 | eVpnComponents = new LinkedList<>(); |
| 315 | eVpnComponents.add(eVpnComponent); |
| 316 | log.info("=====evpn Component is {} ======", eVpnComponent); |
| 317 | } |
| 318 | |
| 319 | return new MpUnReachNlri(eVpnComponents, afi, safi); |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 320 | } else { |
| 321 | //TODO: check with the values got from capability |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 322 | throw new BgpParseException("Not Supporting afi " + afi + "safi " + safi); |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | return new MpUnReachNlri(mpUnReachNlri, afi, safi, |
| 326 | parseFlags.getLength()); |
| 327 | } |
| 328 | |
| 329 | @Override |
| 330 | public short getType() { |
| 331 | return MPUNREACHNLRI_TYPE; |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Returns SAFI. |
| 336 | * |
| 337 | * @return SAFI |
| 338 | */ |
| 339 | public byte safi() { |
| 340 | return this.safi; |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * Returns AFI. |
| 345 | * |
| 346 | * @return AFI |
| 347 | */ |
| 348 | public short afi() { |
| 349 | return this.afi; |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Returns list of MpUnReach Nlri. |
| 354 | * |
| 355 | * @return list of MpUnReach Nlri |
| 356 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 357 | public List<BgpLSNlri> mpUnReachNlri() { |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 358 | return this.mpUnReachNlri; |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * Returns whether MpReachNlri is present. |
| 363 | * |
| 364 | * @return whether MpReachNlri is present |
| 365 | */ |
| 366 | public boolean isMpUnReachNlriSet() { |
| 367 | return this.isMpUnReachNlri; |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * Returns length of MpUnReach. |
| 372 | * |
| 373 | * @return length of MpUnReach |
| 374 | */ |
| 375 | public int mpUnReachNlriLen() { |
| 376 | return this.length; |
| 377 | } |
| 378 | |
| 379 | @Override |
| 380 | public int write(ChannelBuffer cb) { |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 381 | int iLenStartIndex = cb.writerIndex(); |
| 382 | if ((afi == Constants.AFI_FLOWSPEC_VALUE) && ((safi == Constants.SAFI_FLOWSPEC_VALUE) || |
| 383 | (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 384 | List<BgpValueType> flowSpec = bgpFlowSpecNlri.flowSpecComponents(); |
| 385 | ListIterator<BgpValueType> listIterator = flowSpec.listIterator(); |
| 386 | boolean isAllFlowTypesIdentical = true; |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 387 | |
| 388 | cb.writeByte(FLAGS); |
| 389 | cb.writeByte(MPUNREACHNLRI_TYPE); |
| 390 | |
| 391 | int mpUnReachIndx = cb.writerIndex(); |
| 392 | cb.writeShort(0); |
| 393 | |
| 394 | cb.writeShort(afi); |
| 395 | cb.writeByte(safi); |
| 396 | |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 397 | if (bgpFlowSpecNlri.routeDistinguisher() != null) { |
| 398 | cb.writeLong(bgpFlowSpecNlri.routeDistinguisher().getRouteDistinguisher()); |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 399 | } |
| 400 | |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 401 | BgpValueType tlv1 = null; |
| 402 | if (listIterator.hasNext()) { |
| 403 | tlv1 = listIterator.next(); |
| 404 | } |
Ray Milkey | ae4e5ed | 2018-01-17 15:24:52 -0800 | [diff] [blame^] | 405 | while (tlv1 != null && listIterator.hasNext()) { |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 406 | BgpValueType tlv = listIterator.next(); |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 407 | if (tlv.getType() != tlv1.getType()) { |
| 408 | isAllFlowTypesIdentical = false; |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 409 | break; |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 413 | if (isAllFlowTypesIdentical) { |
| 414 | BgpFlowSpecNlri.updateBufferIdenticalFlowTypes(cb, bgpFlowSpecNlri()); |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 415 | } else { |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 416 | BgpFlowSpecNlri.updateBufferNonIdenticalFlowTypes(cb, bgpFlowSpecNlri()); |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 417 | } |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 418 | int fsNlriLen = cb.writerIndex() - mpUnReachIndx; |
| 419 | cb.setShort(mpUnReachIndx, (short) (fsNlriLen - 2)); |
Mohammad Shahid | 30fedc5 | 2017-08-09 11:49:40 +0530 | [diff] [blame] | 420 | } else if ((afi == Constants.AFI_EVPN_VALUE) |
| 421 | && (safi == Constants.SAFI_EVPN_VALUE)) { |
| 422 | |
| 423 | cb.writeByte(FLAGS); |
| 424 | cb.writeByte(MPUNREACHNLRI_TYPE); |
| 425 | |
| 426 | int mpUnReachDataIndex = cb.writerIndex(); |
| 427 | cb.writeShort(0); |
| 428 | cb.writeShort(afi); |
| 429 | cb.writeByte(safi); |
| 430 | |
| 431 | for (BgpEvpnNlri element : evpnNlri) { |
| 432 | short routeType = element.getType(); |
| 433 | switch (routeType) { |
| 434 | case Constants.BGP_EVPN_MAC_IP_ADVERTISEMENT: |
| 435 | cb.writeByte(element.getType()); |
| 436 | int iSpecStartIndex = cb.writerIndex(); |
| 437 | cb.writeByte(0); |
| 438 | BgpEvpnRouteType2Nlri macIpAdvNlri = |
| 439 | (BgpEvpnRouteType2Nlri) element |
| 440 | .getNlri(); |
| 441 | |
| 442 | macIpAdvNlri.write(cb); |
| 443 | cb.setByte(iSpecStartIndex, (short) (cb.writerIndex() |
| 444 | - iSpecStartIndex - 1)); |
| 445 | break; |
| 446 | case Constants.BGP_EVPN_ETHERNET_AUTO_DISCOVERY: |
| 447 | break; |
| 448 | case Constants.BGP_EVPN_INCLUSIVE_MULTICASE_ETHERNET: |
| 449 | break; |
| 450 | case Constants.BGP_EVPN_ETHERNET_SEGMENT: |
| 451 | break; |
| 452 | default: |
| 453 | break; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | int evpnNlriLen = cb.writerIndex() - mpUnReachDataIndex; |
| 458 | cb.setShort(mpUnReachDataIndex, (short) (evpnNlriLen - 2)); |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | return cb.writerIndex() - iLenStartIndex; |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | @Override |
Priyanka B | 0204073 | 2015-11-29 11:30:29 +0530 | [diff] [blame] | 465 | public int compareTo(Object o) { |
| 466 | // TODO Auto-generated method stub |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | @Override |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 471 | public String toString() { |
Shashikanth VH | 510a8d8 | 2016-02-12 12:32:43 +0530 | [diff] [blame] | 472 | return MoreObjects.toStringHelper(getClass()).omitNullValues() |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 473 | .add("mpReachNlri", mpUnReachNlri) |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 474 | .add("bgpFlowSpecNlri", bgpFlowSpecNlri) |
Priyanka B | 3b69554 | 2015-10-14 17:16:27 +0530 | [diff] [blame] | 475 | .add("afi", afi) |
| 476 | .add("safi", safi) |
| 477 | .add("length", length) |
| 478 | .toString(); |
| 479 | } |
| 480 | } |