Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 19 | import java.io.IOException; |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 20 | import java.net.InetAddress; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 21 | import java.net.InetSocketAddress; |
| 22 | import java.net.SocketAddress; |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 23 | import java.net.UnknownHostException; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 24 | import java.nio.channels.ClosedChannelException; |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 25 | import java.util.Collections; |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 26 | import java.util.LinkedList; |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 27 | import java.util.List; |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 28 | import java.util.ListIterator; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 29 | import java.util.concurrent.RejectedExecutionException; |
| 30 | |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 31 | import org.jboss.netty.buffer.ChannelBuffer; |
| 32 | import org.jboss.netty.buffer.ChannelBuffers; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 33 | import org.jboss.netty.channel.Channel; |
| 34 | import org.jboss.netty.channel.ChannelHandlerContext; |
| 35 | import org.jboss.netty.channel.ChannelStateEvent; |
| 36 | import org.jboss.netty.channel.ExceptionEvent; |
| 37 | import org.jboss.netty.channel.MessageEvent; |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 38 | import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 39 | import org.jboss.netty.handler.timeout.ReadTimeoutException; |
| 40 | import org.jboss.netty.handler.timeout.ReadTimeoutHandler; |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 41 | import org.onlab.packet.Ip4Address; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 42 | import org.onlab.packet.IpAddress; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 43 | import org.onosproject.bgp.controller.BgpCfg; |
| 44 | import org.onosproject.bgp.controller.BgpController; |
| 45 | import org.onosproject.bgp.controller.BgpId; |
| 46 | import org.onosproject.bgp.controller.BgpPeer; |
| 47 | import org.onosproject.bgp.controller.BgpPeerCfg; |
| 48 | import org.onosproject.bgp.controller.impl.BgpControllerImpl.BgpPeerManagerImpl; |
| 49 | import org.onosproject.bgpio.exceptions.BgpParseException; |
| 50 | import org.onosproject.bgpio.protocol.BgpFactory; |
| 51 | import org.onosproject.bgpio.protocol.BgpMessage; |
| 52 | import org.onosproject.bgpio.protocol.BgpOpenMsg; |
| 53 | import org.onosproject.bgpio.protocol.BgpType; |
| 54 | import org.onosproject.bgpio.protocol.BgpVersion; |
| 55 | import org.onosproject.bgpio.types.BgpErrorType; |
| 56 | import org.onosproject.bgpio.types.BgpValueType; |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 57 | import org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv; |
| 58 | import org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 59 | import org.slf4j.Logger; |
| 60 | import org.slf4j.LoggerFactory; |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Channel handler deals with the bgp peer connection and dispatches messages from peer to the appropriate locations. |
| 64 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 65 | class BgpChannelHandler extends IdleStateAwareChannelHandler { |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 66 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 67 | private static final Logger log = LoggerFactory.getLogger(BgpChannelHandler.class); |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 68 | static final int BGP_MIN_HOLDTIME = 3; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 69 | static final int BGP_MAX_KEEPALIVE_INTERVAL = 3; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 70 | private BgpPeer bgpPeer; |
| 71 | private BgpId thisbgpId; |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 72 | private Channel channel; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 73 | private BgpKeepAliveTimer keepAliveTimer = null; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 74 | private short peerHoldTime = 0; |
| 75 | private short negotiatedHoldTime = 0; |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 76 | private long peerAsNum; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 77 | private int peerIdentifier; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 78 | private BgpPacketStatsImpl bgpPacketStats; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 79 | static final int MAX_WRONG_COUNT_PACKET = 5; |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 80 | static final byte MULTI_PROTOCOL_EXTN_CAPA_TYPE = 1; |
| 81 | static final byte FOUR_OCTET_AS_NUM_CAPA_TYPE = 65; |
| 82 | static final int AS_TRANS = 23456; |
| 83 | static final int MAX_AS2_NUM = 65535; |
| 84 | static final short AFI = 16388; |
| 85 | static final byte RES = 0; |
| 86 | static final byte SAFI = 71; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 87 | |
| 88 | // State needs to be volatile because the HandshakeTimeoutHandler |
| 89 | // needs to check if the handshake is complete |
| 90 | private volatile ChannelState state; |
| 91 | |
| 92 | // When a bgp peer with a ip addresss is found (i.e we already have a |
| 93 | // connected peer with the same ip), the new peer is immediately |
| 94 | // disconnected. At that point netty callsback channelDisconnected() which |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 95 | // proceeds to cleaup peer state - we need to ensure that it does not |
| 96 | // cleanup |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 97 | // peer state for the older (still connected) peer |
| 98 | private volatile Boolean duplicateBGPIdFound; |
| 99 | // Indicates the bgp version used by this bgp peer |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 100 | protected BgpVersion bgpVersion; |
| 101 | private BgpController bgpController; |
| 102 | protected BgpFactory factory4; |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 103 | private boolean isIbgpSession; |
| 104 | private BgpSessionInfoImpl sessionInfo; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 105 | private BgpPeerManagerImpl peerManager; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 106 | private InetSocketAddress inetAddress; |
| 107 | private IpAddress ipAddress; |
| 108 | private SocketAddress address; |
| 109 | private String peerAddr; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 110 | private BgpCfg bgpconfig; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 111 | |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 112 | /** |
| 113 | * Create a new unconnected BGPChannelHandler. |
| 114 | * |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 115 | * @param bgpController bgp controller |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 116 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 117 | BgpChannelHandler(BgpController bgpController) { |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 118 | this.bgpController = bgpController; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 119 | this.peerManager = (BgpPeerManagerImpl) bgpController.peerManager(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 120 | this.state = ChannelState.IDLE; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 121 | this.factory4 = Controller.getBgpMessageFactory4(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 122 | this.duplicateBGPIdFound = Boolean.FALSE; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 123 | this.bgpPacketStats = new BgpPacketStatsImpl(); |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 124 | this.bgpconfig = bgpController.getConfig(); |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 125 | } |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 126 | |
| 127 | // To disconnect peer session. |
| 128 | public void disconnectPeer() { |
| 129 | bgpPeer.disconnectPeer(); |
| 130 | } |
| 131 | |
| 132 | // ************************* |
| 133 | // Channel State Machine |
| 134 | // ************************* |
| 135 | |
| 136 | /** |
| 137 | * The state machine for handling the peer/channel state. All state transitions should happen from within the state |
| 138 | * machine (and not from other parts of the code) |
| 139 | */ |
| 140 | enum ChannelState { |
| 141 | /** |
| 142 | * Initial state before channel is connected. |
| 143 | */ |
| 144 | IDLE(false) { |
| 145 | |
| 146 | }, |
| 147 | |
| 148 | OPENSENT(false) { |
| 149 | @Override |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 150 | void processBgpMessage(BgpChannelHandler h, BgpMessage m) throws IOException, BgpParseException { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 151 | log.debug("message received in OPENSENT state"); |
| 152 | // check for OPEN message |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 153 | if (m.getType() != BgpType.OPEN) { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 154 | // When the message type is not keep alive message increment the wrong packet statistics |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 155 | h.processUnknownMsg(BgpErrorType.FINITE_STATE_MACHINE_ERROR, |
| 156 | BgpErrorType.RECEIVE_UNEXPECTED_MESSAGE_IN_OPENSENT_STATE, |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 157 | m.getType().getType()); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 158 | log.debug("Message is not OPEN message"); |
| 159 | } else { |
| 160 | log.debug("Sending keep alive message in OPENSENT state"); |
| 161 | h.bgpPacketStats.addInPacket(); |
| 162 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 163 | BgpOpenMsg pOpenmsg = (BgpOpenMsg) m; |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 164 | h.peerIdentifier = pOpenmsg.getBgpId(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 165 | |
| 166 | // validate capabilities and open msg |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 167 | if (h.openMsgValidation(h, pOpenmsg)) { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 168 | if (h.connectionCollisionDetection(BgpPeerCfg.State.OPENCONFIRM, |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 169 | h.peerIdentifier, h.peerAddr)) { |
| 170 | h.channel.close(); |
| 171 | return; |
| 172 | } |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 173 | log.debug("Sending handshake OPEN message"); |
| 174 | |
| 175 | /* |
| 176 | * RFC 4271, section 4.2: Upon receipt of an OPEN message, a BGP speaker MUST calculate the |
| 177 | * value of the Hold Timer by using the smaller of its configured Hold Time and the Hold Time |
| 178 | * received in the OPEN message |
| 179 | */ |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 180 | h.peerHoldTime = pOpenmsg.getHoldTime(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 181 | if (h.peerHoldTime < h.bgpconfig.getHoldTime()) { |
| 182 | h.channel.getPipeline().replace("holdTime", |
| 183 | "holdTime", |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 184 | new ReadTimeoutHandler(BgpPipelineFactory.TIMER, |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 185 | h.peerHoldTime)); |
| 186 | } |
| 187 | |
| 188 | log.info("Hold Time : " + h.peerHoldTime); |
| 189 | |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 190 | // update AS number |
| 191 | h.peerAsNum = pOpenmsg.getAsNumber(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | // Send keepalive message to peer. |
| 195 | h.sendKeepAliveMessage(); |
| 196 | h.bgpPacketStats.addOutPacket(); |
| 197 | h.setState(OPENCONFIRM); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 198 | h.bgpconfig.setPeerConnState(h.peerAddr, BgpPeerCfg.State.OPENCONFIRM); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | }, |
| 202 | |
| 203 | OPENWAIT(false) { |
| 204 | @Override |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 205 | void processBgpMessage(BgpChannelHandler h, BgpMessage m) throws IOException, BgpParseException { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 206 | log.debug("Message received in OPEN WAIT State"); |
| 207 | |
| 208 | // check for open message |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 209 | if (m.getType() != BgpType.OPEN) { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 210 | // When the message type is not open message increment the wrong packet statistics |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 211 | h.processUnknownMsg(BgpErrorType.FINITE_STATE_MACHINE_ERROR, BgpErrorType.UNSPECIFIED_ERROR, |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 212 | m.getType().getType()); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 213 | log.debug("Message is not OPEN message"); |
| 214 | } else { |
| 215 | h.bgpPacketStats.addInPacket(); |
| 216 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 217 | BgpOpenMsg pOpenmsg = (BgpOpenMsg) m; |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 218 | h.peerIdentifier = pOpenmsg.getBgpId(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 219 | |
| 220 | // Validate open message |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 221 | if (h.openMsgValidation(h, pOpenmsg)) { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 222 | if (h.connectionCollisionDetection(BgpPeerCfg.State.OPENSENT, |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 223 | h.peerIdentifier, h.peerAddr)) { |
| 224 | h.channel.close(); |
| 225 | return; |
| 226 | } |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 227 | log.debug("Sending handshake OPEN message"); |
| 228 | |
| 229 | /* |
| 230 | * RFC 4271, section 4.2: Upon receipt of an OPEN message, a BGP speaker MUST calculate the |
| 231 | * value of the Hold Timer by using the smaller of its configured Hold Time and the Hold Time |
| 232 | * received in the OPEN message |
| 233 | */ |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 234 | h.peerHoldTime = pOpenmsg.getHoldTime(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 235 | if (h.peerHoldTime < h.bgpconfig.getHoldTime()) { |
| 236 | h.channel.getPipeline().replace("holdTime", |
| 237 | "holdTime", |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 238 | new ReadTimeoutHandler(BgpPipelineFactory.TIMER, |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 239 | h.peerHoldTime)); |
| 240 | } |
| 241 | |
| 242 | log.debug("Hold Time : " + h.peerHoldTime); |
| 243 | |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 244 | // update AS number |
| 245 | h.peerAsNum = pOpenmsg.getAsNumber(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 246 | |
| 247 | h.sendHandshakeOpenMessage(); |
| 248 | h.bgpPacketStats.addOutPacket(); |
| 249 | h.setState(OPENCONFIRM); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 250 | h.bgpconfig.setPeerConnState(h.peerAddr, BgpPeerCfg.State.OPENCONFIRM); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | } |
| 254 | }, |
| 255 | |
| 256 | OPENCONFIRM(false) { |
| 257 | @Override |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 258 | void processBgpMessage(BgpChannelHandler h, BgpMessage m) throws IOException, BgpParseException { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 259 | log.debug("Message received in OPENCONFIRM state"); |
| 260 | // check for keep alive message |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 261 | if (m.getType() != BgpType.KEEP_ALIVE) { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 262 | // When the message type is not keep alive message handle the wrong packet |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 263 | h.processUnknownMsg(BgpErrorType.FINITE_STATE_MACHINE_ERROR, |
| 264 | BgpErrorType.RECEIVE_UNEXPECTED_MESSAGE_IN_OPENCONFIRM_STATE, |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 265 | m.getType().getType()); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 266 | log.debug("Message is not KEEPALIVE message"); |
| 267 | } else { |
| 268 | |
| 269 | // Set the peer connected status |
| 270 | h.bgpPacketStats.addInPacket(); |
| 271 | log.debug("Sending keep alive message in OPENCONFIRM state"); |
| 272 | |
| 273 | final InetSocketAddress inetAddress = (InetSocketAddress) h.address; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 274 | h.thisbgpId = BgpId.bgpId(IpAddress.valueOf(inetAddress.getAddress())); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 275 | |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 276 | // set session parameters |
| 277 | h.negotiatedHoldTime = (h.peerHoldTime < h.bgpconfig.getHoldTime()) ? h.peerHoldTime |
| 278 | : h.bgpconfig.getHoldTime(); |
| 279 | h.sessionInfo = new BgpSessionInfoImpl(h.thisbgpId, h.bgpVersion, h.peerAsNum, h.peerHoldTime, |
| 280 | h.peerIdentifier, h.negotiatedHoldTime, h.isIbgpSession); |
| 281 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 282 | h.bgpPeer = h.peerManager.getBgpPeerInstance(h.bgpController, h.sessionInfo, h.bgpPacketStats); |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 283 | // set the status of bgp as connected |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 284 | h.bgpPeer.setConnected(true); |
| 285 | h.bgpPeer.setChannel(h.channel); |
| 286 | |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 287 | /* |
| 288 | * RFC 4271, When an OPEN message is received, sends a KEEPALIVE message, If the negotiated hold |
| 289 | * time value is zero, then the HoldTimer and KeepaliveTimer are not started. A reasonable maximum |
| 290 | * time between KEEPALIVE messages would be one third of the Hold Time interval. |
| 291 | */ |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 292 | |
| 293 | if (h.negotiatedHoldTime != 0) { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 294 | h.keepAliveTimer = new BgpKeepAliveTimer(h, |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 295 | (h.negotiatedHoldTime / BGP_MAX_KEEPALIVE_INTERVAL)); |
Shashikanth VH | dae8040 | 2015-11-20 14:20:33 +0530 | [diff] [blame] | 296 | } else { |
| 297 | h.sendKeepAliveMessage(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | h.bgpPacketStats.addOutPacket(); |
| 301 | |
| 302 | // set the state handshake completion. |
| 303 | h.setHandshakeComplete(true); |
| 304 | |
| 305 | if (!h.peerManager.addConnectedPeer(h.thisbgpId, h.bgpPeer)) { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 306 | disconnectDuplicate(h); |
| 307 | } else { |
| 308 | h.setState(ESTABLISHED); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 309 | h.bgpconfig.setPeerConnState(h.peerAddr, BgpPeerCfg.State.ESTABLISHED); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | } |
| 313 | }, |
| 314 | |
| 315 | ESTABLISHED(true) { |
| 316 | @Override |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 317 | void processBgpMessage(BgpChannelHandler h, BgpMessage m) throws IOException, BgpParseException { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 318 | log.debug("Message received in established state " + m.getType()); |
| 319 | // dispatch the message |
| 320 | h.dispatchMessage(m); |
| 321 | } |
| 322 | }; |
| 323 | |
| 324 | private boolean handshakeComplete; |
| 325 | |
| 326 | ChannelState(boolean handshakeComplete) { |
| 327 | this.handshakeComplete = handshakeComplete; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * Is this a state in which the handshake has completed? |
| 332 | * |
| 333 | * @return true if the handshake is complete |
| 334 | */ |
| 335 | public boolean isHandshakeComplete() { |
| 336 | return this.handshakeComplete; |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Disconnect duplicate peer connection. |
| 341 | * |
| 342 | * @param h channel handler |
| 343 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 344 | protected void disconnectDuplicate(BgpChannelHandler h) { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 345 | log.error("Duplicated BGP IP or incompleted cleanup - " + "" + "disconnecting channel {}", |
| 346 | h.getPeerInfoString()); |
| 347 | h.duplicateBGPIdFound = Boolean.TRUE; |
| 348 | h.channel.disconnect(); |
| 349 | } |
| 350 | |
| 351 | // set handshake completion status |
| 352 | public void setHandshakeComplete(boolean handshakeComplete) { |
| 353 | this.handshakeComplete = handshakeComplete; |
| 354 | } |
| 355 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 356 | void processBgpMessage(BgpChannelHandler bgpChannelHandler, BgpMessage pm) |
| 357 | throws IOException, BgpParseException { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 358 | // TODO Auto-generated method stub |
| 359 | log.debug("BGP message stub"); |
| 360 | } |
| 361 | |
| 362 | } |
| 363 | |
Shashikanth VH | 3dd13cf | 2015-12-14 11:53:46 +0530 | [diff] [blame] | 364 | //Stop keepalive timer |
| 365 | private void stopKeepAliveTimer() { |
| 366 | if ((keepAliveTimer != null) && (keepAliveTimer.getKeepAliveTimer() != null)) { |
| 367 | keepAliveTimer.getKeepAliveTimer().cancel(); |
| 368 | } |
| 369 | } |
| 370 | |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 371 | // ************************* |
| 372 | // Channel handler methods |
| 373 | // ************************* |
| 374 | |
| 375 | @Override |
| 376 | public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { |
| 377 | |
| 378 | channel = e.getChannel(); |
| 379 | log.info("BGP connected from {}", channel.getRemoteAddress()); |
| 380 | |
| 381 | address = channel.getRemoteAddress(); |
| 382 | if (!(address instanceof InetSocketAddress)) { |
| 383 | throw new IOException("Invalid peer connection."); |
| 384 | } |
| 385 | |
Shashikanth VH | 97e571e | 2016-01-05 12:15:14 +0530 | [diff] [blame] | 386 | // Connection should establish only if local ip and Autonomous system number is configured. |
| 387 | if (bgpconfig.getState() != BgpCfg.State.IP_AS_CONFIGURED) { |
| 388 | sendNotification(BgpErrorType.CEASE, BgpErrorType.CONNECTION_REJECTED, null); |
| 389 | channel.close(); |
| 390 | log.info("BGP local AS and router ID not configured"); |
| 391 | return; |
| 392 | } |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 393 | |
| 394 | inetAddress = (InetSocketAddress) address; |
Shashikanth VH | dae8040 | 2015-11-20 14:20:33 +0530 | [diff] [blame] | 395 | peerAddr = IpAddress.valueOf(inetAddress.getAddress()).toString(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 396 | |
Shashikanth VH | 97e571e | 2016-01-05 12:15:14 +0530 | [diff] [blame] | 397 | // if peer is not configured disconnect session |
| 398 | if (!bgpconfig.isPeerConfigured(peerAddr)) { |
| 399 | log.debug("Peer is not configured {}", peerAddr); |
| 400 | sendNotification(BgpErrorType.CEASE, BgpErrorType.CONNECTION_REJECTED, null); |
| 401 | channel.close(); |
| 402 | return; |
| 403 | } |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 404 | |
| 405 | // if connection is already established close channel |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 406 | if (peerManager.isPeerConnected(BgpId.bgpId(IpAddress.valueOf(peerAddr)))) { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 407 | log.debug("Duplicate connection received, peer {}", peerAddr); |
| 408 | channel.close(); |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | if (null != channel.getPipeline().get("PassiveHandler")) { |
| 413 | log.info("BGP handle connection request from peer"); |
| 414 | // Wait for open message from bgp peer |
| 415 | setState(ChannelState.OPENWAIT); |
| 416 | } else if (null != channel.getPipeline().get("ActiveHandler")) { |
| 417 | log.info("BGP handle connection response from peer"); |
| 418 | |
| 419 | sendHandshakeOpenMessage(); |
| 420 | bgpPacketStats.addOutPacket(); |
| 421 | setState(ChannelState.OPENSENT); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 422 | bgpconfig.setPeerConnState(peerAddr, BgpPeerCfg.State.OPENSENT); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
| 426 | @Override |
| 427 | public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { |
| 428 | |
| 429 | channel = e.getChannel(); |
| 430 | log.info("BGP disconnected callback for bgp:{}. Cleaning up ...", getPeerInfoString()); |
| 431 | |
| 432 | address = channel.getRemoteAddress(); |
| 433 | if (!(address instanceof InetSocketAddress)) { |
| 434 | throw new IOException("Invalid peer connection."); |
| 435 | } |
| 436 | |
| 437 | inetAddress = (InetSocketAddress) address; |
Shashikanth VH | dae8040 | 2015-11-20 14:20:33 +0530 | [diff] [blame] | 438 | peerAddr = IpAddress.valueOf(inetAddress.getAddress()).toString(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 439 | |
| 440 | if (thisbgpId != null) { |
| 441 | if (!duplicateBGPIdFound) { |
| 442 | // if the disconnected peer (on this ChannelHandler) |
| 443 | // was not one with a duplicate, it is safe to remove all |
| 444 | // state for it at the controller. Notice that if the disconnected |
| 445 | // peer was a duplicate-ip, calling the method below would clear |
| 446 | // all state for the original peer (with the same ip), |
| 447 | // which we obviously don't want. |
| 448 | log.debug("{}:removal called", getPeerInfoString()); |
| 449 | if (bgpPeer != null) { |
Shashikanth VH | 3fe3798 | 2015-11-30 11:50:07 +0530 | [diff] [blame] | 450 | BgpPeerImpl peer = (BgpPeerImpl) bgpPeer; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 451 | peerManager.removeConnectedPeer(thisbgpId); |
Shashikanth VH | 3fe3798 | 2015-11-30 11:50:07 +0530 | [diff] [blame] | 452 | peer.updateLocalRIBOnPeerDisconnect(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 453 | } |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 454 | |
| 455 | // Retry connection if connection is lost to bgp speaker/peer |
| 456 | if ((channel != null) && (null != channel.getPipeline().get("ActiveHandler"))) { |
| 457 | BgpConnectPeerImpl connectPeer; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 458 | BgpPeerCfg.State peerCfgState; |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 459 | |
| 460 | peerCfgState = bgpconfig.getPeerConnState(peerAddr); |
| 461 | // on session disconnect using configuration, do not retry |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 462 | if (!peerCfgState.equals(BgpPeerCfg.State.IDLE)) { |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 463 | log.debug("Connection reset by peer, retry, STATE:{}", peerCfgState); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 464 | BgpPeerConfig peerConfig = (BgpPeerConfig) bgpconfig.displayPeers(peerAddr); |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 465 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 466 | bgpconfig.setPeerConnState(peerAddr, BgpPeerCfg.State.IDLE); |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 467 | connectPeer = new BgpConnectPeerImpl(bgpController, peerAddr, Controller.getBgpPortNum()); |
| 468 | peerConfig.setConnectPeer(connectPeer); |
| 469 | } |
| 470 | } else { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 471 | bgpconfig.setPeerConnState(peerAddr, BgpPeerCfg.State.IDLE); |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 472 | } |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 473 | } else { |
| 474 | // A duplicate was disconnected on this ChannelHandler, |
| 475 | // this is the same peer reconnecting, but the original state was |
| 476 | // not cleaned up - XXX check liveness of original ChannelHandler |
| 477 | log.debug("{}:duplicate found", getPeerInfoString()); |
| 478 | duplicateBGPIdFound = Boolean.FALSE; |
| 479 | } |
| 480 | |
Shashikanth VH | 3dd13cf | 2015-12-14 11:53:46 +0530 | [diff] [blame] | 481 | stopKeepAliveTimer(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 482 | } else { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 483 | bgpconfig.setPeerConnState(peerAddr, BgpPeerCfg.State.IDLE); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 484 | log.warn("No bgp ip in channelHandler registered for " + "disconnected peer {}", getPeerInfoString()); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | @Override |
| 489 | public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { |
| 490 | |
| 491 | log.info("[exceptionCaught]: " + e.toString()); |
| 492 | |
| 493 | if (e.getCause() instanceof ReadTimeoutException) { |
Shashikanth VH | a33f9a0 | 2015-12-05 12:22:23 +0530 | [diff] [blame] | 494 | // device timeout |
| 495 | log.error("Disconnecting device {} due to read timeout", getPeerInfoString()); |
| 496 | sendNotification(BgpErrorType.HOLD_TIMER_EXPIRED, (byte) 0, null); |
| 497 | state = ChannelState.IDLE; |
Shashikanth VH | 3dd13cf | 2015-12-14 11:53:46 +0530 | [diff] [blame] | 498 | stopKeepAliveTimer(); |
Shashikanth VH | a33f9a0 | 2015-12-05 12:22:23 +0530 | [diff] [blame] | 499 | ctx.getChannel().close(); |
| 500 | return; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 501 | } else if (e.getCause() instanceof ClosedChannelException) { |
| 502 | log.debug("Channel for bgp {} already closed", getPeerInfoString()); |
| 503 | } else if (e.getCause() instanceof IOException) { |
| 504 | log.error("Disconnecting peer {} due to IO Error: {}", getPeerInfoString(), e.getCause().getMessage()); |
| 505 | if (log.isDebugEnabled()) { |
| 506 | // still print stack trace if debug is enabled |
| 507 | log.debug("StackTrace for previous Exception: ", e.getCause()); |
| 508 | } |
Shashikanth VH | 3dd13cf | 2015-12-14 11:53:46 +0530 | [diff] [blame] | 509 | stopKeepAliveTimer(); |
Shashikanth VH | a33f9a0 | 2015-12-05 12:22:23 +0530 | [diff] [blame] | 510 | ctx.getChannel().close(); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 511 | } else if (e.getCause() instanceof BgpParseException) { |
Shashikanth VH | dae8040 | 2015-11-20 14:20:33 +0530 | [diff] [blame] | 512 | byte[] data = new byte[] {}; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 513 | BgpParseException errMsg = (BgpParseException) e.getCause(); |
Shashikanth VH | dae8040 | 2015-11-20 14:20:33 +0530 | [diff] [blame] | 514 | byte errorCode = errMsg.getErrorCode(); |
| 515 | byte errorSubCode = errMsg.getErrorSubCode(); |
| 516 | ChannelBuffer tempCb = errMsg.getData(); |
| 517 | if (tempCb != null) { |
| 518 | int dataLength = tempCb.capacity(); |
| 519 | data = new byte[dataLength]; |
| 520 | tempCb.readBytes(data, 0, dataLength); |
| 521 | } |
| 522 | sendNotification(errorCode, errorSubCode, data); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 523 | } else if (e.getCause() instanceof RejectedExecutionException) { |
| 524 | log.warn("Could not process message: queue full"); |
| 525 | } else { |
Shashikanth VH | 3dd13cf | 2015-12-14 11:53:46 +0530 | [diff] [blame] | 526 | stopKeepAliveTimer(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 527 | log.error("Error while processing message from peer " + getPeerInfoString() + "state " + this.state); |
Shashikanth VH | a33f9a0 | 2015-12-05 12:22:23 +0530 | [diff] [blame] | 528 | ctx.getChannel().close(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
| 532 | @Override |
| 533 | public String toString() { |
| 534 | return getPeerInfoString(); |
| 535 | } |
| 536 | |
| 537 | @Override |
| 538 | public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { |
| 539 | if (e.getMessage() instanceof List) { |
| 540 | @SuppressWarnings("Unchecked") |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 541 | List<BgpMessage> msglist = (List<BgpMessage>) e.getMessage(); |
| 542 | for (BgpMessage pm : msglist) { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 543 | // Do the actual packet processing |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 544 | state.processBgpMessage(this, pm); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 545 | } |
| 546 | } else { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 547 | state.processBgpMessage(this, (BgpMessage) e.getMessage()); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 551 | /** |
| 552 | * Check for connection collision. |
| 553 | * |
| 554 | * @param state connection state |
| 555 | * @param peerIdentifier BGP peer identifier |
| 556 | * @param peerAddr BGP peer address |
| 557 | * @return true if bgp spreakers initiated connection |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 558 | * @throws BgpParseException on error while procession collision detection |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 559 | * @throws IOException on error while procession collision detection |
| 560 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 561 | public boolean connectionCollisionDetection(BgpPeerCfg.State state, int peerIdentifier, String peerAddr) |
| 562 | throws IOException, BgpParseException { |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 563 | /* |
| 564 | * RFC 4271, Section 6.8, Based on the value of the BGP identifier, a convention is established for detecting |
| 565 | * which BGP connection is to be preserved when a collision occurs. The convention is to compare the BGP |
| 566 | * Identifiers of the peers involved in the collision and to retain only the connection initiated by the BGP |
| 567 | * speaker with the higher-valued BGP Identifier.. |
| 568 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 569 | BgpPeerCfg.State currentState = bgpconfig.getPeerConnState(peerAddr); |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 570 | if (currentState.equals(state)) { |
| 571 | if (((Ip4Address.valueOf(bgpconfig.getRouterId())).compareTo(Ip4Address.valueOf(peerIdentifier))) > 0) { |
| 572 | // send notification |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 573 | sendNotification(BgpErrorType.CEASE, BgpErrorType.CONNECTION_COLLISION_RESOLUTION, null); |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 574 | log.debug("Connection collision detected, local id: {}, peer id: {}, peer state:{}, in state:{}", |
| 575 | (Ip4Address.valueOf(bgpconfig.getRouterId())), (Ip4Address.valueOf(peerIdentifier)), |
| 576 | currentState, state); |
| 577 | return true; |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | return false; |
| 582 | } |
| 583 | |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 584 | // ************************* |
| 585 | // Channel utility methods |
| 586 | // ************************* |
| 587 | /** |
| 588 | * Set handshake status. |
| 589 | * |
| 590 | * @param handshakeComplete handshake complete status |
| 591 | */ |
| 592 | public void setHandshakeComplete(boolean handshakeComplete) { |
| 593 | this.state.setHandshakeComplete(handshakeComplete); |
| 594 | } |
| 595 | |
| 596 | /** |
| 597 | * Is this a state in which the handshake has completed? |
| 598 | * |
| 599 | * @return true if the handshake is complete |
| 600 | */ |
| 601 | public boolean isHandshakeComplete() { |
| 602 | return state.isHandshakeComplete(); |
| 603 | } |
| 604 | |
| 605 | /** |
| 606 | * To handle the BGP message. |
| 607 | * |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 608 | * @param m bgp message |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 609 | * @throws BgpParseException throw exception |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 610 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 611 | private void dispatchMessage(BgpMessage m) throws BgpParseException { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 612 | bgpPacketStats.addInPacket(); |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 613 | bgpController.processBGPPacket(thisbgpId, m); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | /** |
| 617 | * Return a string describing this peer based on the already available information (ip address and/or remote |
| 618 | * socket). |
| 619 | * |
| 620 | * @return display string |
| 621 | */ |
| 622 | private String getPeerInfoString() { |
| 623 | if (bgpPeer != null) { |
| 624 | return bgpPeer.toString(); |
| 625 | } |
| 626 | String channelString; |
| 627 | if (channel == null || channel.getRemoteAddress() == null) { |
| 628 | channelString = "?"; |
| 629 | } else { |
| 630 | channelString = channel.getRemoteAddress().toString(); |
| 631 | } |
| 632 | String bgpIpString; |
| 633 | // TODO: implement functionality to get bgp id string |
| 634 | bgpIpString = "?"; |
| 635 | return String.format("[%s BGP-IP[%s]]", channelString, bgpIpString); |
| 636 | } |
| 637 | |
| 638 | /** |
| 639 | * Update the channels state. Only called from the state machine. TODO: enforce restricted state transitions |
| 640 | * |
| 641 | * @param state |
| 642 | */ |
| 643 | private void setState(ChannelState state) { |
| 644 | this.state = state; |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * get packet statistics. |
| 649 | * |
| 650 | * @return packet statistics |
| 651 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 652 | public BgpPacketStatsImpl getBgpPacketStats() { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 653 | return bgpPacketStats; |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * Send handshake open message to the peer. |
| 658 | * |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 659 | * @throws IOException, BgpParseException |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 660 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 661 | private void sendHandshakeOpenMessage() throws IOException, BgpParseException { |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 662 | int bgpId; |
| 663 | |
Shashikanth VH | 97e571e | 2016-01-05 12:15:14 +0530 | [diff] [blame] | 664 | bgpId = Ip4Address.valueOf(bgpconfig.getRouterId()).toInt(); |
| 665 | BgpMessage msg = factory4.openMessageBuilder().setAsNumber((short) bgpconfig.getAsNumber()) |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 666 | .setHoldTime(bgpconfig.getHoldTime()).setBgpId(bgpId).setLsCapabilityTlv(bgpconfig.getLsCapability()) |
| 667 | .setLargeAsCapabilityTlv(bgpconfig.getLargeASCapability()).build(); |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 668 | log.debug("Sending open message to {}", channel.getRemoteAddress()); |
| 669 | channel.write(Collections.singletonList(msg)); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 670 | |
| 671 | } |
| 672 | |
| 673 | /** |
Shashikanth VH | dae8040 | 2015-11-20 14:20:33 +0530 | [diff] [blame] | 674 | * Send notification message to peer. |
| 675 | * |
| 676 | * @param errorCode error code send in notification |
| 677 | * @param errorSubCode sub error code send in notification |
| 678 | * @param data data to send in notification |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 679 | * @throws IOException, BgpParseException while building message |
Shashikanth VH | dae8040 | 2015-11-20 14:20:33 +0530 | [diff] [blame] | 680 | */ |
| 681 | private void sendNotification(byte errorCode, byte errorSubCode, byte[] data) |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 682 | throws IOException, BgpParseException { |
| 683 | BgpMessage msg = factory4.notificationMessageBuilder().setErrorCode(errorCode) |
Shashikanth VH | 447c6b0 | 2015-11-25 21:25:35 +0530 | [diff] [blame] | 684 | .setErrorSubCode(errorSubCode).setData(data).build(); |
Shashikanth VH | dae8040 | 2015-11-20 14:20:33 +0530 | [diff] [blame] | 685 | log.debug("Sending notification message to {}", channel.getRemoteAddress()); |
| 686 | channel.write(Collections.singletonList(msg)); |
| 687 | } |
| 688 | |
| 689 | /** |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 690 | * Send keep alive message. |
| 691 | * |
| 692 | * @throws IOException when channel is disconnected |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 693 | * @throws BgpParseException while building keep alive message |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 694 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 695 | synchronized void sendKeepAliveMessage() throws IOException, BgpParseException { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 696 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 697 | BgpMessage msg = factory4.keepaliveMessageBuilder().build(); |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 698 | log.debug("Sending keepalive message to {}", channel.getRemoteAddress()); |
| 699 | channel.write(Collections.singletonList(msg)); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | /** |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 703 | * Process unknown BGP message received. |
| 704 | * |
Shashikanth VH | dae8040 | 2015-11-20 14:20:33 +0530 | [diff] [blame] | 705 | * @param errorCode error code |
| 706 | * @param errorSubCode error sub code |
| 707 | * @param data message type |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 708 | * @throws BgpParseException while processing error messsage |
Shashikanth VH | dae8040 | 2015-11-20 14:20:33 +0530 | [diff] [blame] | 709 | * @throws IOException while processing error message |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 710 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 711 | public void processUnknownMsg(byte errorCode, byte errorSubCode, byte data) throws BgpParseException, IOException { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 712 | log.debug("UNKNOWN message received"); |
Shashikanth VH | dae8040 | 2015-11-20 14:20:33 +0530 | [diff] [blame] | 713 | byte[] byteArray = new byte[1]; |
| 714 | byteArray[0] = data; |
| 715 | sendNotification(errorCode, errorSubCode, byteArray); |
| 716 | channel.close(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | /** |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 720 | * BGP open message validation. |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 721 | * |
| 722 | * @param h channel handler |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 723 | * @param openMsg open message |
| 724 | * @return true if valid message, otherwise false |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 725 | * @throws BgpParseException throw exception |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 726 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 727 | public boolean openMsgValidation(BgpChannelHandler h, BgpOpenMsg openMsg) throws BgpParseException { |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 728 | boolean result; |
| 729 | |
| 730 | // Validate BGP ID |
| 731 | result = bgpIdValidation(openMsg); |
| 732 | if (!result) { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 733 | throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_BGP_IDENTIFIER, null); |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 734 | } |
| 735 | |
Shashikanth VH | 97e571e | 2016-01-05 12:15:14 +0530 | [diff] [blame] | 736 | // Validate AS number |
| 737 | result = asNumberValidation(h, openMsg); |
| 738 | if (!result) { |
| 739 | throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_PEER_AS, null); |
| 740 | } |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 741 | |
| 742 | // Validate hold timer |
| 743 | if ((openMsg.getHoldTime() != 0) && (openMsg.getHoldTime() < BGP_MIN_HOLDTIME)) { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 744 | throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.UNACCEPTABLE_HOLD_TIME, null); |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | // Validate capabilities |
| 748 | result = capabilityValidation(h, openMsg); |
| 749 | return result; |
| 750 | } |
| 751 | |
| 752 | /** |
| 753 | * Capability Validation. |
| 754 | * |
| 755 | * @param h channel handler |
| 756 | * @param openmsg open message |
| 757 | * @return success or failure |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 758 | * @throws BgpParseException |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 759 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 760 | private boolean capabilityValidation(BgpChannelHandler h, BgpOpenMsg openmsg) throws BgpParseException { |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 761 | log.debug("capabilityValidation"); |
| 762 | |
| 763 | boolean isMultiProtocolcapabilityExists = false; |
| 764 | boolean isFourOctetCapabilityExits = false; |
| 765 | int capAsNum = 0; |
| 766 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 767 | List<BgpValueType> capabilityTlv = openmsg.getCapabilityTlv(); |
| 768 | ListIterator<BgpValueType> listIterator = capabilityTlv.listIterator(); |
| 769 | List<BgpValueType> unSupportedCapabilityTlv = new LinkedList<>(); |
| 770 | ListIterator<BgpValueType> unSupportedCaplistIterator = unSupportedCapabilityTlv.listIterator(); |
| 771 | BgpValueType tempTlv; |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 772 | boolean isLargeAsCapabilityCfg = h.bgpconfig.getLargeASCapability(); |
| 773 | boolean isLsCapabilityCfg = h.bgpconfig.getLsCapability(); |
| 774 | |
| 775 | while (listIterator.hasNext()) { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 776 | BgpValueType tlv = listIterator.next(); |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 777 | if (tlv.getType() == MULTI_PROTOCOL_EXTN_CAPA_TYPE) { |
| 778 | isMultiProtocolcapabilityExists = true; |
| 779 | } |
| 780 | if (tlv.getType() == FOUR_OCTET_AS_NUM_CAPA_TYPE) { |
| 781 | isFourOctetCapabilityExits = true; |
| 782 | capAsNum = ((FourOctetAsNumCapabilityTlv) tlv).getInt(); |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | if (isFourOctetCapabilityExits) { |
| 787 | if (capAsNum > MAX_AS2_NUM) { |
| 788 | if (openmsg.getAsNumber() != AS_TRANS) { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 789 | throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_PEER_AS, null); |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 790 | } |
| 791 | } else { |
| 792 | if (capAsNum != openmsg.getAsNumber()) { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 793 | throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_PEER_AS, null); |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | if ((isLsCapabilityCfg)) { |
| 799 | if (!isMultiProtocolcapabilityExists) { |
| 800 | tempTlv = new MultiProtocolExtnCapabilityTlv(AFI, RES, SAFI); |
| 801 | unSupportedCapabilityTlv.add(tempTlv); |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | if ((isLargeAsCapabilityCfg)) { |
| 806 | if (!isFourOctetCapabilityExits) { |
| 807 | tempTlv = new FourOctetAsNumCapabilityTlv(h.bgpconfig.getAsNumber()); |
| 808 | unSupportedCapabilityTlv.add(tempTlv); |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | if (unSupportedCaplistIterator.hasNext()) { |
| 813 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 814 | while (unSupportedCaplistIterator.hasNext()) { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 815 | BgpValueType tlv = unSupportedCaplistIterator.next(); |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 816 | tlv.write(buffer); |
| 817 | } |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 818 | throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.UNSUPPORTED_CAPABILITY, buffer); |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 819 | } else { |
| 820 | return true; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | /** |
| 825 | * AS Number Validation. |
| 826 | * |
| 827 | * @param h channel Handler |
| 828 | * @param openMsg open message |
| 829 | * @return true or false |
| 830 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 831 | private boolean asNumberValidation(BgpChannelHandler h, BgpOpenMsg openMsg) { |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 832 | log.debug("AS Num validation"); |
| 833 | |
| 834 | int capAsNum = 0; |
| 835 | boolean isFourOctetCapabilityExits = false; |
| 836 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 837 | BgpPeerCfg peerCfg = h.bgpconfig.displayPeers(peerAddr); |
| 838 | List<BgpValueType> capabilityTlv = openMsg.getCapabilityTlv(); |
| 839 | ListIterator<BgpValueType> listIterator = capabilityTlv.listIterator(); |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 840 | |
| 841 | while (listIterator.hasNext()) { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 842 | BgpValueType tlv = listIterator.next(); |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 843 | if (tlv.getType() == FOUR_OCTET_AS_NUM_CAPA_TYPE) { |
| 844 | isFourOctetCapabilityExits = true; |
| 845 | capAsNum = ((FourOctetAsNumCapabilityTlv) tlv).getInt(); |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | if (peerCfg.getAsNumber() > MAX_AS2_NUM) { |
| 850 | if (openMsg.getAsNumber() != AS_TRANS) { |
| 851 | return false; |
| 852 | } |
| 853 | |
| 854 | if (!isFourOctetCapabilityExits) { |
| 855 | return false; |
| 856 | } |
| 857 | |
| 858 | if (peerCfg.getAsNumber() != capAsNum) { |
| 859 | return false; |
| 860 | } |
| 861 | |
| 862 | isIbgpSession = peerCfg.getIsIBgp(); |
| 863 | if (isIbgpSession) { |
| 864 | // IBGP - AS number should be same for Peer and local if it is IBGP |
| 865 | if (h.bgpconfig.getAsNumber() != capAsNum) { |
| 866 | return false; |
| 867 | } |
| 868 | } |
| 869 | } else { |
| 870 | |
| 871 | if (openMsg.getAsNumber() != peerCfg.getAsNumber()) { |
| 872 | return false; |
| 873 | } |
| 874 | |
| 875 | if (isFourOctetCapabilityExits) { |
| 876 | if (capAsNum != peerCfg.getAsNumber()) { |
| 877 | return false; |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | isIbgpSession = peerCfg.getIsIBgp(); |
| 882 | if (isIbgpSession) { |
| 883 | // IBGP - AS number should be same for Peer and local if it is IBGP |
| 884 | if (openMsg.getAsNumber() != h.bgpconfig.getAsNumber()) { |
| 885 | return false; |
| 886 | } |
| 887 | } |
| 888 | } |
| 889 | return true; |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * Validates BGP ID. |
| 894 | * |
| 895 | * @param openMsg open message |
| 896 | * @return true or false |
| 897 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 898 | private boolean bgpIdValidation(BgpOpenMsg openMsg) { |
Vidyashree Rama | ee29325 | 2015-11-18 17:00:11 +0530 | [diff] [blame] | 899 | String openMsgBgpId = Ip4Address.valueOf(openMsg.getBgpId()).toString(); |
| 900 | |
| 901 | InetAddress ipAddress; |
| 902 | try { |
| 903 | ipAddress = InetAddress.getByName(openMsgBgpId); |
| 904 | if (ipAddress.isMulticastAddress()) { |
| 905 | return false; |
| 906 | } |
| 907 | } catch (UnknownHostException e) { |
| 908 | log.debug("InetAddress convertion failed"); |
| 909 | } |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 910 | return true; |
| 911 | } |
| 912 | } |