Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 16 | package org.onosproject.routing.bgp; |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | d24fafb | 2015-02-09 17:55:32 -0800 | [diff] [blame] | 18 | import org.apache.felix.scr.annotations.Activate; |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Component; |
Jonathan Hart | d24fafb | 2015-02-09 17:55:32 -0800 | [diff] [blame] | 20 | import org.apache.felix.scr.annotations.Deactivate; |
| 21 | import org.apache.felix.scr.annotations.Modified; |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 22 | import org.apache.felix.scr.annotations.Service; |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 23 | import org.jboss.netty.bootstrap.ServerBootstrap; |
| 24 | import org.jboss.netty.channel.Channel; |
| 25 | import org.jboss.netty.channel.ChannelException; |
| 26 | import org.jboss.netty.channel.ChannelFactory; |
| 27 | import org.jboss.netty.channel.ChannelPipeline; |
| 28 | import org.jboss.netty.channel.ChannelPipelineFactory; |
| 29 | import org.jboss.netty.channel.Channels; |
Pavlin Radoslavov | 7e19094 | 2014-11-13 18:50:59 -0800 | [diff] [blame] | 30 | import org.jboss.netty.channel.group.ChannelGroup; |
| 31 | import org.jboss.netty.channel.group.DefaultChannelGroup; |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 32 | import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; |
Pavlin Radoslavov | 6b57073 | 2014-11-06 13:16:45 -0800 | [diff] [blame] | 33 | import org.onlab.packet.Ip4Address; |
| 34 | import org.onlab.packet.Ip4Prefix; |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 35 | import org.onlab.packet.Ip6Prefix; |
Thomas Vachuska | 9ea3e6f | 2015-01-23 16:34:22 -0800 | [diff] [blame] | 36 | import org.onlab.packet.IpPrefix; |
Jonathan Hart | 2da1e60 | 2015-02-18 19:09:24 -0800 | [diff] [blame] | 37 | import org.onosproject.routing.BgpService; |
| 38 | import org.onosproject.routing.RouteListener; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 39 | import org.osgi.service.component.ComponentContext; |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 40 | import org.slf4j.Logger; |
| 41 | import org.slf4j.LoggerFactory; |
| 42 | |
Thomas Vachuska | 9ea3e6f | 2015-01-23 16:34:22 -0800 | [diff] [blame] | 43 | import java.net.InetAddress; |
| 44 | import java.net.InetSocketAddress; |
| 45 | import java.net.SocketAddress; |
| 46 | import java.util.Collection; |
Jonathan Hart | d24fafb | 2015-02-09 17:55:32 -0800 | [diff] [blame] | 47 | import java.util.Dictionary; |
Thomas Vachuska | 9ea3e6f | 2015-01-23 16:34:22 -0800 | [diff] [blame] | 48 | import java.util.concurrent.ConcurrentHashMap; |
| 49 | import java.util.concurrent.ConcurrentMap; |
| 50 | |
| 51 | import static com.google.common.base.Preconditions.checkNotNull; |
| 52 | import static java.util.concurrent.Executors.newCachedThreadPool; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 53 | import static org.onlab.util.Tools.groupedThreads; |
Thomas Vachuska | 9ea3e6f | 2015-01-23 16:34:22 -0800 | [diff] [blame] | 54 | |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 55 | /** |
| 56 | * BGP Session Manager class. |
| 57 | */ |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 58 | @Component(immediate = true) |
| 59 | @Service |
| 60 | public class BgpSessionManager implements BgpInfoService, BgpService { |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 61 | private static final Logger log = |
Thomas Vachuska | 9ea3e6f | 2015-01-23 16:34:22 -0800 | [diff] [blame] | 62 | LoggerFactory.getLogger(BgpSessionManager.class); |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 63 | |
Pavlin Radoslavov | 7e19094 | 2014-11-13 18:50:59 -0800 | [diff] [blame] | 64 | boolean isShutdown = true; |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 65 | private Channel serverChannel; // Listener for incoming BGP connections |
Pavlin Radoslavov | 7e19094 | 2014-11-13 18:50:59 -0800 | [diff] [blame] | 66 | private ServerBootstrap serverBootstrap; |
| 67 | private ChannelGroup allChannels = new DefaultChannelGroup(); |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 68 | private ConcurrentMap<SocketAddress, BgpSession> bgpSessions = |
Thomas Vachuska | 9ea3e6f | 2015-01-23 16:34:22 -0800 | [diff] [blame] | 69 | new ConcurrentHashMap<>(); |
Pavlin Radoslavov | 6b57073 | 2014-11-06 13:16:45 -0800 | [diff] [blame] | 70 | private Ip4Address myBgpId; // Same BGP ID for all peers |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 71 | |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 72 | private BgpRouteSelector bgpRouteSelector = new BgpRouteSelector(this); |
| 73 | private ConcurrentMap<Ip4Prefix, BgpRouteEntry> bgpRoutes4 = |
Thomas Vachuska | 9ea3e6f | 2015-01-23 16:34:22 -0800 | [diff] [blame] | 74 | new ConcurrentHashMap<>(); |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 75 | private ConcurrentMap<Ip6Prefix, BgpRouteEntry> bgpRoutes6 = |
Thomas Vachuska | 9ea3e6f | 2015-01-23 16:34:22 -0800 | [diff] [blame] | 76 | new ConcurrentHashMap<>(); |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 77 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 78 | private RouteListener routeListener; |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 79 | |
Jonathan Hart | d24fafb | 2015-02-09 17:55:32 -0800 | [diff] [blame] | 80 | private static final int DEFAULT_BGP_PORT = 2000; |
| 81 | private int bgpPort; |
| 82 | |
| 83 | @Activate |
| 84 | protected void activate(ComponentContext context) { |
| 85 | readComponentConfiguration(context); |
| 86 | log.info("BgpSessionManager started"); |
| 87 | } |
| 88 | |
| 89 | @Deactivate |
| 90 | protected void deactivate() { |
| 91 | log.info("BgpSessionManager stopped"); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Extracts properties from the component configuration context. |
| 96 | * |
| 97 | * @param context the component context |
| 98 | */ |
| 99 | private void readComponentConfiguration(ComponentContext context) { |
| 100 | Dictionary<?, ?> properties = context.getProperties(); |
| 101 | try { |
| 102 | String strPort = (String) properties.get("bgpPort"); |
| 103 | if (strPort != null) { |
| 104 | bgpPort = Integer.parseInt(strPort); |
| 105 | } else { |
| 106 | bgpPort = DEFAULT_BGP_PORT; |
| 107 | } |
Pavlin Radoslavov | b9e50df | 2015-02-20 20:01:26 -0800 | [diff] [blame] | 108 | } catch (NumberFormatException | ClassCastException e) { |
Jonathan Hart | d24fafb | 2015-02-09 17:55:32 -0800 | [diff] [blame] | 109 | bgpPort = DEFAULT_BGP_PORT; |
| 110 | } |
| 111 | log.debug("BGP port is set to {}", bgpPort); |
| 112 | } |
| 113 | |
| 114 | @Modified |
| 115 | public void modified(ComponentContext context) { |
| 116 | // Blank @Modified method to catch modifications to the context. |
| 117 | // If no @Modified method exists, it seems @Activate is called again |
| 118 | // when the context is modified. |
| 119 | } |
| 120 | |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 121 | /** |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 122 | * Checks whether the BGP Session Manager is shutdown. |
| 123 | * |
| 124 | * @return true if the BGP Session Manager is shutdown, otherwise false |
| 125 | */ |
| 126 | boolean isShutdown() { |
| 127 | return this.isShutdown; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Gets the route listener. |
| 132 | * |
| 133 | * @return the route listener to use |
| 134 | */ |
| 135 | RouteListener getRouteListener() { |
| 136 | return routeListener; |
| 137 | } |
| 138 | |
| 139 | /** |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 140 | * Gets the BGP sessions. |
| 141 | * |
| 142 | * @return the BGP sessions |
| 143 | */ |
| 144 | public Collection<BgpSession> getBgpSessions() { |
| 145 | return bgpSessions.values(); |
| 146 | } |
| 147 | |
| 148 | /** |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 149 | * Gets the selected IPv4 BGP routes among all BGP sessions. |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 150 | * |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 151 | * @return the selected IPv4 BGP routes among all BGP sessions |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 152 | */ |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 153 | public Collection<BgpRouteEntry> getBgpRoutes4() { |
| 154 | return bgpRoutes4.values(); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Gets the selected IPv6 BGP routes among all BGP sessions. |
| 159 | * |
| 160 | * @return the selected IPv6 BGP routes among all BGP sessions |
| 161 | */ |
| 162 | public Collection<BgpRouteEntry> getBgpRoutes6() { |
| 163 | return bgpRoutes6.values(); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Finds a BGP route for a prefix. The prefix can be either IPv4 or IPv6. |
| 168 | * |
| 169 | * @param prefix the prefix to use |
| 170 | * @return the BGP route if found, otherwise null |
| 171 | */ |
| 172 | BgpRouteEntry findBgpRoute(IpPrefix prefix) { |
Pavlin Radoslavov | 87dd930 | 2015-03-10 13:53:24 -0700 | [diff] [blame] | 173 | if (prefix.isIp4()) { |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 174 | return bgpRoutes4.get(prefix.getIp4Prefix()); // IPv4 |
| 175 | } |
| 176 | return bgpRoutes6.get(prefix.getIp6Prefix()); // IPv6 |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Adds a BGP route. The route can be either IPv4 or IPv6. |
| 181 | * |
| 182 | * @param bgpRouteEntry the BGP route entry to use |
| 183 | */ |
| 184 | void addBgpRoute(BgpRouteEntry bgpRouteEntry) { |
Pavlin Radoslavov | 87dd930 | 2015-03-10 13:53:24 -0700 | [diff] [blame] | 185 | if (bgpRouteEntry.isIp4()) { |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 186 | bgpRoutes4.put(bgpRouteEntry.prefix().getIp4Prefix(), // IPv4 |
| 187 | bgpRouteEntry); |
| 188 | } else { |
| 189 | bgpRoutes6.put(bgpRouteEntry.prefix().getIp6Prefix(), // IPv6 |
| 190 | bgpRouteEntry); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Removes a BGP route for a prefix. The prefix can be either IPv4 or IPv6. |
| 196 | * |
| 197 | * @param prefix the prefix to use |
| 198 | * @return true if the route was found and removed, otherwise false |
| 199 | */ |
| 200 | boolean removeBgpRoute(IpPrefix prefix) { |
Pavlin Radoslavov | 87dd930 | 2015-03-10 13:53:24 -0700 | [diff] [blame] | 201 | if (prefix.isIp4()) { |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 202 | return (bgpRoutes4.remove(prefix.getIp4Prefix()) != null); // IPv4 |
| 203 | } |
| 204 | return (bgpRoutes6.remove(prefix.getIp6Prefix()) != null); // IPv6 |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | /** |
Pavlin Radoslavov | 7e19094 | 2014-11-13 18:50:59 -0800 | [diff] [blame] | 208 | * Adds the channel for a BGP session. |
| 209 | * |
| 210 | * @param channel the channel to add |
| 211 | */ |
| 212 | void addSessionChannel(Channel channel) { |
| 213 | allChannels.add(channel); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Removes the channel for a BGP session. |
| 218 | * |
| 219 | * @param channel the channel to remove |
| 220 | */ |
| 221 | void removeSessionChannel(Channel channel) { |
| 222 | allChannels.remove(channel); |
| 223 | } |
| 224 | |
| 225 | /** |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 226 | * Processes the connection from a BGP peer. |
| 227 | * |
| 228 | * @param bgpSession the BGP session for the peer |
| 229 | * @return true if the connection can be established, otherwise false |
| 230 | */ |
| 231 | boolean peerConnected(BgpSession bgpSession) { |
| 232 | |
| 233 | // Test whether there is already a session from the same remote |
Pavlin Radoslavov | 8a36ce3 | 2015-01-28 12:26:57 -0800 | [diff] [blame] | 234 | if (bgpSessions.get(bgpSession.remoteInfo().address()) != null) { |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 235 | return false; // Duplicate BGP session |
| 236 | } |
Pavlin Radoslavov | 8a36ce3 | 2015-01-28 12:26:57 -0800 | [diff] [blame] | 237 | bgpSessions.put(bgpSession.remoteInfo().address(), bgpSession); |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 238 | |
| 239 | // |
| 240 | // If the first connection, set my BGP ID to the local address |
| 241 | // of the socket. |
| 242 | // |
Pavlin Radoslavov | 8a36ce3 | 2015-01-28 12:26:57 -0800 | [diff] [blame] | 243 | if (bgpSession.localInfo().address() instanceof InetSocketAddress) { |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 244 | InetAddress inetAddr = |
Pavlin Radoslavov | 8a36ce3 | 2015-01-28 12:26:57 -0800 | [diff] [blame] | 245 | ((InetSocketAddress) bgpSession.localInfo().address()).getAddress(); |
Pavlin Radoslavov | 6b57073 | 2014-11-06 13:16:45 -0800 | [diff] [blame] | 246 | Ip4Address ip4Address = Ip4Address.valueOf(inetAddr.getAddress()); |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 247 | updateMyBgpId(ip4Address); |
| 248 | } |
| 249 | return true; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Processes the disconnection from a BGP peer. |
| 254 | * |
| 255 | * @param bgpSession the BGP session for the peer |
| 256 | */ |
| 257 | void peerDisconnected(BgpSession bgpSession) { |
Pavlin Radoslavov | 8a36ce3 | 2015-01-28 12:26:57 -0800 | [diff] [blame] | 258 | bgpSessions.remove(bgpSession.remoteInfo().address()); |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Conditionally updates the local BGP ID if it wasn't set already. |
| 263 | * <p/> |
| 264 | * NOTE: A BGP instance should use same BGP ID across all BGP sessions. |
| 265 | * |
| 266 | * @param ip4Address the IPv4 address to use as BGP ID |
| 267 | */ |
Pavlin Radoslavov | 6b57073 | 2014-11-06 13:16:45 -0800 | [diff] [blame] | 268 | private synchronized void updateMyBgpId(Ip4Address ip4Address) { |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 269 | if (myBgpId == null) { |
| 270 | myBgpId = ip4Address; |
| 271 | log.debug("BGP: My BGP ID is {}", myBgpId); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Gets the local BGP Identifier as an IPv4 address. |
| 277 | * |
| 278 | * @return the local BGP Identifier as an IPv4 address |
| 279 | */ |
Pavlin Radoslavov | 6b57073 | 2014-11-06 13:16:45 -0800 | [diff] [blame] | 280 | Ip4Address getMyBgpId() { |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 281 | return myBgpId; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Gets the BGP Route Selector. |
| 286 | * |
| 287 | * @return the BGP Route Selector |
| 288 | */ |
| 289 | BgpRouteSelector getBgpRouteSelector() { |
| 290 | return bgpRouteSelector; |
| 291 | } |
| 292 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 293 | @Override |
Jonathan Hart | d24fafb | 2015-02-09 17:55:32 -0800 | [diff] [blame] | 294 | public void start(RouteListener routeListener) { |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 295 | log.debug("BGP Session Manager start."); |
Pavlin Radoslavov | 7e19094 | 2014-11-13 18:50:59 -0800 | [diff] [blame] | 296 | isShutdown = false; |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 297 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 298 | this.routeListener = checkNotNull(routeListener); |
| 299 | |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 300 | ChannelFactory channelFactory = new NioServerSocketChannelFactory( |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 301 | newCachedThreadPool(groupedThreads("onos/bgp", "sm-boss-%d")), |
| 302 | newCachedThreadPool(groupedThreads("onos/bgp", "sm-worker-%d"))); |
Sho SHIMIZU | 7462641 | 2015-09-11 11:46:27 -0700 | [diff] [blame^] | 303 | ChannelPipelineFactory pipelineFactory = () -> { |
| 304 | // Allocate a new session per connection |
| 305 | BgpSession bgpSessionHandler = |
| 306 | new BgpSession(BgpSessionManager.this); |
| 307 | BgpFrameDecoder bgpFrameDecoder = |
| 308 | new BgpFrameDecoder(bgpSessionHandler); |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 309 | |
Sho SHIMIZU | 7462641 | 2015-09-11 11:46:27 -0700 | [diff] [blame^] | 310 | // Setup the processing pipeline |
| 311 | ChannelPipeline pipeline = Channels.pipeline(); |
| 312 | pipeline.addLast("BgpFrameDecoder", bgpFrameDecoder); |
| 313 | pipeline.addLast("BgpSession", bgpSessionHandler); |
| 314 | return pipeline; |
Thomas Vachuska | 9ea3e6f | 2015-01-23 16:34:22 -0800 | [diff] [blame] | 315 | }; |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 316 | InetSocketAddress listenAddress = |
Jonathan Hart | d24fafb | 2015-02-09 17:55:32 -0800 | [diff] [blame] | 317 | new InetSocketAddress(bgpPort); |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 318 | |
Pavlin Radoslavov | 7e19094 | 2014-11-13 18:50:59 -0800 | [diff] [blame] | 319 | serverBootstrap = new ServerBootstrap(channelFactory); |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 320 | // serverBootstrap.setOptions("reuseAddr", true); |
| 321 | serverBootstrap.setOption("child.keepAlive", true); |
| 322 | serverBootstrap.setOption("child.tcpNoDelay", true); |
| 323 | serverBootstrap.setPipelineFactory(pipelineFactory); |
| 324 | try { |
| 325 | serverChannel = serverBootstrap.bind(listenAddress); |
Pavlin Radoslavov | 7e19094 | 2014-11-13 18:50:59 -0800 | [diff] [blame] | 326 | allChannels.add(serverChannel); |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 327 | } catch (ChannelException e) { |
| 328 | log.debug("Exception binding to BGP port {}: ", |
| 329 | listenAddress.getPort(), e); |
| 330 | } |
| 331 | } |
| 332 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 333 | @Override |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 334 | public void stop() { |
Pavlin Radoslavov | 7e19094 | 2014-11-13 18:50:59 -0800 | [diff] [blame] | 335 | isShutdown = true; |
| 336 | allChannels.close().awaitUninterruptibly(); |
| 337 | serverBootstrap.releaseExternalResources(); |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 338 | } |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 339 | } |