blob: 76c6fd2d5cbb38d452c3f4b7e7140bf337806eb4 [file] [log] [blame]
alshabib3b1eadc2016-02-01 17:57:00 -08001/*
2 * Copyright 2015-2016 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 */
16package org.onosproject.cordmcast;
17
Jonathan Hartc3f84eb2016-02-19 12:44:36 -080018import com.fasterxml.jackson.databind.ObjectMapper;
19import com.fasterxml.jackson.databind.node.ArrayNode;
Jonathan Hart28271642016-02-10 16:13:54 -080020import com.fasterxml.jackson.databind.node.ObjectNode;
Jonathan Hartc3f84eb2016-02-19 12:44:36 -080021import com.google.common.collect.Lists;
alshabib3b1eadc2016-02-01 17:57:00 -080022import com.google.common.collect.Maps;
Jonathan Hart28271642016-02-10 16:13:54 -080023import com.sun.jersey.api.client.Client;
Jonathan Hart0212f642016-02-20 11:32:43 -080024import com.sun.jersey.api.client.ClientHandlerException;
Jonathan Hart28271642016-02-10 16:13:54 -080025import com.sun.jersey.api.client.WebResource;
26import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
alshabib3b1eadc2016-02-01 17:57:00 -080027import org.apache.felix.scr.annotations.Activate;
28import org.apache.felix.scr.annotations.Component;
29import org.apache.felix.scr.annotations.Deactivate;
Jonathan Hart28271642016-02-10 16:13:54 -080030import org.apache.felix.scr.annotations.Modified;
31import org.apache.felix.scr.annotations.Property;
alshabib3b1eadc2016-02-01 17:57:00 -080032import org.apache.felix.scr.annotations.Reference;
33import org.apache.felix.scr.annotations.ReferenceCardinality;
34import org.onlab.packet.Ethernet;
alshabib3b1eadc2016-02-01 17:57:00 -080035import org.onlab.packet.IpAddress;
36import org.onlab.packet.VlanId;
Jonathan Hart28271642016-02-10 16:13:54 -080037import org.onosproject.cfg.ComponentConfigService;
38import org.onosproject.codec.CodecService;
Jonathan Hartc3f84eb2016-02-19 12:44:36 -080039import org.onosproject.codec.JsonCodec;
alshabib3b1eadc2016-02-01 17:57:00 -080040import org.onosproject.core.ApplicationId;
41import org.onosproject.core.CoreService;
42import org.onosproject.net.ConnectPoint;
43import org.onosproject.net.flow.DefaultTrafficSelector;
44import org.onosproject.net.flow.DefaultTrafficTreatment;
45import org.onosproject.net.flow.TrafficSelector;
46import org.onosproject.net.flowobjective.DefaultForwardingObjective;
47import org.onosproject.net.flowobjective.DefaultNextObjective;
48import org.onosproject.net.flowobjective.FlowObjectiveService;
49import org.onosproject.net.flowobjective.ForwardingObjective;
50import org.onosproject.net.flowobjective.NextObjective;
51import org.onosproject.net.flowobjective.Objective;
52import org.onosproject.net.flowobjective.ObjectiveContext;
53import org.onosproject.net.flowobjective.ObjectiveError;
alshabib3b1eadc2016-02-01 17:57:00 -080054import org.onosproject.net.mcast.McastEvent;
55import org.onosproject.net.mcast.McastListener;
Jonathan Hart28271642016-02-10 16:13:54 -080056import org.onosproject.net.mcast.McastRoute;
alshabib3b1eadc2016-02-01 17:57:00 -080057import org.onosproject.net.mcast.McastRouteInfo;
58import org.onosproject.net.mcast.MulticastRouteService;
Jonathan Hart28271642016-02-10 16:13:54 -080059import org.onosproject.rest.AbstractWebResource;
60import org.osgi.service.component.ComponentContext;
alshabib3b1eadc2016-02-01 17:57:00 -080061import org.slf4j.Logger;
62
Jonathan Hartc3f84eb2016-02-19 12:44:36 -080063import javax.ws.rs.core.MediaType;
64import java.io.IOException;
Jonathan Hart28271642016-02-10 16:13:54 -080065import java.util.Dictionary;
Jonathan Hartc3f84eb2016-02-19 12:44:36 -080066import java.util.List;
alshabib3b1eadc2016-02-01 17:57:00 -080067import java.util.Map;
alshabibfc1cb032016-02-17 15:37:56 -080068import java.util.Properties;
Jonathan Hartc3f84eb2016-02-19 12:44:36 -080069import java.util.Set;
Jonathan Hart28271642016-02-10 16:13:54 -080070import java.util.concurrent.atomic.AtomicBoolean;
alshabib3b1eadc2016-02-01 17:57:00 -080071import java.util.concurrent.atomic.AtomicInteger;
72
Jonathan Hartc3f84eb2016-02-19 12:44:36 -080073import static com.google.common.base.Preconditions.checkNotNull;
alshabibfc1cb032016-02-17 15:37:56 -080074import static com.google.common.base.Strings.isNullOrEmpty;
Jonathan Hart28271642016-02-10 16:13:54 -080075import static com.google.common.net.MediaType.JSON_UTF_8;
alshabibfc1cb032016-02-17 15:37:56 -080076import static org.onlab.util.Tools.get;
alshabib3b1eadc2016-02-01 17:57:00 -080077import static org.slf4j.LoggerFactory.getLogger;
78
79/**
Jonathan Hartc3f84eb2016-02-19 12:44:36 -080080 * CORD multicast provisioning application. Operates by listening to
Jonathan Hart28271642016-02-10 16:13:54 -080081 * events on the multicast rib and provisioning groups to program multicast
alshabib3b1eadc2016-02-01 17:57:00 -080082 * flows on the dataplane.
83 */
84@Component(immediate = true)
85public class CordMcast {
86
Jonathan Hart0212f642016-02-20 11:32:43 -080087 private static final int DEFAULT_REST_TIMEOUT_MS = 2000;
alshabib3b1eadc2016-02-01 17:57:00 -080088 private static final int DEFAULT_PRIORITY = 1000;
89 private static final short DEFAULT_MCAST_VLAN = 4000;
alshabibfc1cb032016-02-17 15:37:56 -080090 private static final String DEFAULT_SYNC_HOST = "10.90.0.8:8181";
91 private static final String DEFAULT_USER = "karaf";
92 private static final String DEFAULT_PASSWORD = "karaf";
93
alshabib3b1eadc2016-02-01 17:57:00 -080094 private final Logger log = getLogger(getClass());
95
96 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
97 protected MulticastRouteService mcastService;
98
99 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
alshabib3b1eadc2016-02-01 17:57:00 -0800100 protected FlowObjectiveService flowObjectiveService;
101
102 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
103 protected CoreService coreService;
104
Jonathan Hart28271642016-02-10 16:13:54 -0800105 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
106 protected CodecService codecService;
107
108 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
109 protected ComponentConfigService componentConfigService;
110
alshabib3b1eadc2016-02-01 17:57:00 -0800111 protected McastListener listener = new InternalMulticastListener();
112
alshabib3b1eadc2016-02-01 17:57:00 -0800113 //TODO: move this to a ec map
114 private Map<IpAddress, Integer> groups = Maps.newConcurrentMap();
115
116 //TODO: move this to distributed atomic long
117 private AtomicInteger channels = new AtomicInteger(0);
118
119 private ApplicationId appId;
120
alshabibfc1cb032016-02-17 15:37:56 -0800121 @Property(name = "mcastVlan", intValue = DEFAULT_MCAST_VLAN,
122 label = "VLAN for multicast traffic")
123 private int mcastVlan = DEFAULT_MCAST_VLAN;
alshabib3b1eadc2016-02-01 17:57:00 -0800124
alshabibfc1cb032016-02-17 15:37:56 -0800125 @Property(name = "vlanEnabled", boolValue = false,
126 label = "Use vlan for multicast traffic")
127 private boolean vlanEnabled = false;
128
129 @Property(name = "priority", intValue = DEFAULT_PRIORITY,
130 label = "Priority for multicast rules")
alshabib3b1eadc2016-02-01 17:57:00 -0800131 private int priority = DEFAULT_PRIORITY;
132
alshabibfc1cb032016-02-17 15:37:56 -0800133 @Property(name = "syncHost", value = DEFAULT_SYNC_HOST,
Jonathan Hart28271642016-02-10 16:13:54 -0800134 label = "host:port to synchronize routes to")
alshabibfc1cb032016-02-17 15:37:56 -0800135 private String syncHost = DEFAULT_SYNC_HOST;
Jonathan Hart28271642016-02-10 16:13:54 -0800136
137 @Property(name = "username", value = DEFAULT_USER,
138 label = "Username for REST password authentication")
139 private String user = DEFAULT_USER;
140
141 @Property(name = "password", value = DEFAULT_PASSWORD,
142 label = "Password for REST authentication")
143 private String password = DEFAULT_PASSWORD;
144
145 private String fabricOnosUrl;
146
alshabib3b1eadc2016-02-01 17:57:00 -0800147 @Activate
Jonathan Hart435ffc42016-02-19 10:32:05 -0800148 public void activate(ComponentContext context) {
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800149 componentConfigService.registerProperties(getClass());
Jonathan Hart435ffc42016-02-19 10:32:05 -0800150 modified(context);
151
alshabib3b1eadc2016-02-01 17:57:00 -0800152 appId = coreService.registerApplication("org.onosproject.cordmcast");
Jonathan Hart28271642016-02-10 16:13:54 -0800153
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800154 clearRemoteRoutes();
155
156 mcastService.addListener(listener);
157
158 for (McastRoute route : mcastService.getRoutes()) {
159 Set<ConnectPoint> sinks = mcastService.fetchSinks(route);
160 if (!sinks.isEmpty()) {
161 sinks.forEach(s -> provisionGroup(route, s));
162 }
163 }
164
alshabib3b1eadc2016-02-01 17:57:00 -0800165 log.info("Started");
166 }
167
168 @Deactivate
169 public void deactivate() {
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800170 componentConfigService.unregisterProperties(getClass(), false);
alshabib3b1eadc2016-02-01 17:57:00 -0800171 mcastService.removeListener(listener);
172 log.info("Stopped");
173 }
174
Jonathan Hart28271642016-02-10 16:13:54 -0800175 @Modified
176 public void modified(ComponentContext context) {
alshabibfc1cb032016-02-17 15:37:56 -0800177 Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
178
alshabibfc1cb032016-02-17 15:37:56 -0800179 try {
180 String s = get(properties, "username");
181 user = isNullOrEmpty(s) ? DEFAULT_USER : s.trim();
182
183 s = get(properties, "password");
184 password = isNullOrEmpty(s) ? DEFAULT_PASSWORD : s.trim();
185
186 s = get(properties, "mcastVlan");
187 mcastVlan = isNullOrEmpty(s) ? DEFAULT_MCAST_VLAN : Short.parseShort(s.trim());
188
189 s = get(properties, "vlanEnabled");
190 vlanEnabled = isNullOrEmpty(s) || Boolean.parseBoolean(s.trim());
191
192 s = get(properties, "priority");
193 priority = isNullOrEmpty(s) ? DEFAULT_PRIORITY : Integer.parseInt(s.trim());
194
Jonathan Hart0212f642016-02-20 11:32:43 -0800195 s = get(properties, "syncHost");
alshabibfc1cb032016-02-17 15:37:56 -0800196 syncHost = isNullOrEmpty(s) ? DEFAULT_SYNC_HOST : s.trim();
197 } catch (Exception e) {
198 user = DEFAULT_USER;
199 password = DEFAULT_PASSWORD;
200 syncHost = DEFAULT_SYNC_HOST;
201 mcastVlan = DEFAULT_MCAST_VLAN;
202 vlanEnabled = false;
203 priority = DEFAULT_PRIORITY;
204 }
Jonathan Hart0212f642016-02-20 11:32:43 -0800205 fabricOnosUrl = createRemoteUrl(syncHost);
206 }
207
208 private static String createRemoteUrl(String remoteHost) {
209 return "http://" + remoteHost + "/onos/v1/mcast";
Jonathan Hart28271642016-02-10 16:13:54 -0800210 }
211
alshabib3b1eadc2016-02-01 17:57:00 -0800212 private class InternalMulticastListener implements McastListener {
213 @Override
214 public void event(McastEvent event) {
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800215 McastRouteInfo info = event.subject();
alshabib3b1eadc2016-02-01 17:57:00 -0800216 switch (event.type()) {
217 case ROUTE_ADDED:
218 break;
219 case ROUTE_REMOVED:
220 break;
221 case SOURCE_ADDED:
222 break;
223 case SINK_ADDED:
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800224 if (!info.sink().isPresent()) {
225 log.warn("No sink given after sink added event: {}", info);
226 return;
227 }
228 provisionGroup(info.route(), info.sink().get());
alshabib3b1eadc2016-02-01 17:57:00 -0800229 break;
230 case SINK_REMOVED:
alshabibfc1cb032016-02-17 15:37:56 -0800231 unprovisionGroup(event.subject());
alshabib3b1eadc2016-02-01 17:57:00 -0800232 break;
233 default:
234 log.warn("Unknown mcast event {}", event.type());
235 }
236 }
237 }
238
alshabibfc1cb032016-02-17 15:37:56 -0800239 private void unprovisionGroup(McastRouteInfo info) {
Jonathan Hart718c0452016-02-18 15:56:22 -0800240 if (info.sinks().isEmpty()) {
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800241 removeRemoteRoute(info.route());
Jonathan Hart718c0452016-02-18 15:56:22 -0800242 }
243
alshabibfc1cb032016-02-17 15:37:56 -0800244 if (!info.sink().isPresent()) {
245 log.warn("No sink given after sink removed event: {}", info);
246 return;
247 }
248 ConnectPoint loc = info.sink().get();
249
250 NextObjective next = DefaultNextObjective.builder()
251 .fromApp(appId)
252 .addTreatment(DefaultTrafficTreatment.builder().setOutput(loc.port()).build())
253 .withType(NextObjective.Type.BROADCAST)
254 .withId(groups.get(info.route().group()))
255 .removeFromExisting(new ObjectiveContext() {
256 @Override
257 public void onSuccess(Objective objective) {
258 //TODO: change to debug
259 log.info("Next Objective {} installed", objective.id());
260 }
261
262 @Override
263 public void onError(Objective objective, ObjectiveError error) {
264 //TODO: change to debug
265 log.info("Next Objective {} failed, because {}",
266 objective.id(),
267 error);
268 }
269 });
270
271 flowObjectiveService.next(loc.deviceId(), next);
alshabibfc1cb032016-02-17 15:37:56 -0800272 }
273
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800274 private void provisionGroup(McastRoute route, ConnectPoint sink) {
275 checkNotNull(route, "Route cannot be null");
276 checkNotNull(sink, "Sink cannot be null");
alshabib3b1eadc2016-02-01 17:57:00 -0800277
Jonathan Hart28271642016-02-10 16:13:54 -0800278 final AtomicBoolean sync = new AtomicBoolean(false);
alshabib3b1eadc2016-02-01 17:57:00 -0800279
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800280 Integer nextId = groups.computeIfAbsent(route.group(), (g) -> {
Jonathan Hart28271642016-02-10 16:13:54 -0800281 Integer id = allocateId();
alshabib3b1eadc2016-02-01 17:57:00 -0800282
alshabibfc1cb032016-02-17 15:37:56 -0800283 NextObjective next = DefaultNextObjective.builder()
284 .fromApp(appId)
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800285 .addTreatment(DefaultTrafficTreatment.builder().setOutput(sink.port()).build())
alshabibfc1cb032016-02-17 15:37:56 -0800286 .withType(NextObjective.Type.BROADCAST)
287 .withId(id)
288 .add(new ObjectiveContext() {
289 @Override
290 public void onSuccess(Objective objective) {
291 //TODO: change to debug
292 log.info("Next Objective {} installed", objective.id());
293 }
294
295 @Override
296 public void onError(Objective objective, ObjectiveError error) {
297 //TODO: change to debug
298 log.info("Next Objective {} failed, because {}",
299 objective.id(),
300 error);
301 }
302 });
303
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800304 flowObjectiveService.next(sink.deviceId(), next);
alshabibfc1cb032016-02-17 15:37:56 -0800305
306 TrafficSelector.Builder mcast = DefaultTrafficSelector.builder()
alshabib3b1eadc2016-02-01 17:57:00 -0800307 .matchEthType(Ethernet.TYPE_IPV4)
alshabibfc1cb032016-02-17 15:37:56 -0800308 .matchIPDst(g.toIpPrefix());
309
alshabibfc1cb032016-02-17 15:37:56 -0800310 if (vlanEnabled) {
311 mcast.matchVlanId(VlanId.vlanId((short) mcastVlan));
312 }
alshabib3b1eadc2016-02-01 17:57:00 -0800313
alshabib3b1eadc2016-02-01 17:57:00 -0800314 ForwardingObjective fwd = DefaultForwardingObjective.builder()
315 .fromApp(appId)
316 .nextStep(id)
317 .makePermanent()
318 .withFlag(ForwardingObjective.Flag.VERSATILE)
319 .withPriority(priority)
alshabibfc1cb032016-02-17 15:37:56 -0800320 .withSelector(mcast.build())
alshabib3b1eadc2016-02-01 17:57:00 -0800321 .add(new ObjectiveContext() {
322 @Override
323 public void onSuccess(Objective objective) {
324 //TODO: change to debug
325 log.info("Forwarding objective installed {}", objective);
326 }
327
328 @Override
329 public void onError(Objective objective, ObjectiveError error) {
330 //TODO: change to debug
331 log.info("Forwarding objective failed {}", objective);
332 }
333 });
334
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800335 flowObjectiveService.forward(sink.deviceId(), fwd);
alshabib3b1eadc2016-02-01 17:57:00 -0800336
Jonathan Hart28271642016-02-10 16:13:54 -0800337 sync.set(true);
338
alshabib3b1eadc2016-02-01 17:57:00 -0800339 return id;
340 });
341
alshabibfc1cb032016-02-17 15:37:56 -0800342 if (!sync.get()) {
343 NextObjective next = DefaultNextObjective.builder()
344 .fromApp(appId)
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800345 .addTreatment(DefaultTrafficTreatment.builder().setOutput(sink.port()).build())
alshabibfc1cb032016-02-17 15:37:56 -0800346 .withType(NextObjective.Type.BROADCAST)
347 .withId(nextId)
348 .addToExisting(new ObjectiveContext() {
349 @Override
350 public void onSuccess(Objective objective) {
351 //TODO: change to debug
352 log.info("Next Objective {} installed", objective.id());
353 }
alshabib3b1eadc2016-02-01 17:57:00 -0800354
alshabibfc1cb032016-02-17 15:37:56 -0800355 @Override
356 public void onError(Objective objective, ObjectiveError error) {
357 //TODO: change to debug
358 log.info("Next Objective {} failed, because {}",
359 objective.id(),
360 error);
361 }
362 });
alshabib3b1eadc2016-02-01 17:57:00 -0800363
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800364 flowObjectiveService.next(sink.deviceId(), next);
alshabibfc1cb032016-02-17 15:37:56 -0800365 }
Jonathan Hart28271642016-02-10 16:13:54 -0800366
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800367 addRemoteRoute(route);
alshabib3b1eadc2016-02-01 17:57:00 -0800368 }
369
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800370 private void addRemoteRoute(McastRoute route) {
371 checkNotNull(route);
Jonathan Hart28271642016-02-10 16:13:54 -0800372 if (syncHost == null) {
373 log.warn("No host configured for synchronization; route will be dropped");
374 return;
375 }
376
Jonathan Hart0212f642016-02-20 11:32:43 -0800377 log.debug("Sending route {} to other ONOS {}", route, fabricOnosUrl);
Jonathan Hart28271642016-02-10 16:13:54 -0800378
379 WebResource.Builder builder = getClientBuilder(fabricOnosUrl);
380
381 ObjectNode json = codecService.getCodec(McastRoute.class)
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800382 .encode(route, new AbstractWebResource());
Jonathan Hart0212f642016-02-20 11:32:43 -0800383
384 try {
385 builder.post(json.toString());
386 } catch (ClientHandlerException e) {
387 log.warn("Unable to send route to remote controller: {}", e.getMessage());
388 }
alshabib3b1eadc2016-02-01 17:57:00 -0800389 }
Jonathan Hart28271642016-02-10 16:13:54 -0800390
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800391 private void removeRemoteRoute(McastRoute route) {
Jonathan Hart718c0452016-02-18 15:56:22 -0800392 if (syncHost == null) {
393 log.warn("No host configured for synchronization; route will be dropped");
394 return;
395 }
396
Jonathan Hart0212f642016-02-20 11:32:43 -0800397 log.debug("Removing route {} from other ONOS {}", route, fabricOnosUrl);
Jonathan Hart718c0452016-02-18 15:56:22 -0800398
399 WebResource.Builder builder = getClientBuilder(fabricOnosUrl);
400
401 ObjectNode json = codecService.getCodec(McastRoute.class)
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800402 .encode(route, new AbstractWebResource());
Jonathan Hart0212f642016-02-20 11:32:43 -0800403 try {
404 builder.delete(json.toString());
405 } catch (ClientHandlerException e) {
406 log.warn("Unable to delete route from remote controller: {}", e.getMessage());
407 }
Jonathan Hart718c0452016-02-18 15:56:22 -0800408 }
409
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800410 private void clearRemoteRoutes() {
411 if (syncHost == null) {
412 log.warn("No host configured for synchronization");
413 return;
414 }
415
Jonathan Hart0212f642016-02-20 11:32:43 -0800416 log.debug("Clearing remote multicast routes from {}", fabricOnosUrl);
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800417
418 WebResource.Builder builder = getClientBuilder(fabricOnosUrl);
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800419 List<McastRoute> mcastRoutes = Lists.newArrayList();
Jonathan Hart0212f642016-02-20 11:32:43 -0800420
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800421 try {
Jonathan Hart0212f642016-02-20 11:32:43 -0800422 String response = builder
423 .accept(MediaType.APPLICATION_JSON_TYPE)
424 .get(String.class);
425
426 JsonCodec<McastRoute> routeCodec = codecService.getCodec(McastRoute.class);
427 ObjectMapper mapper = new ObjectMapper();
428
429
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800430 ObjectNode node = (ObjectNode) mapper.readTree(response);
431 ArrayNode list = (ArrayNode) node.path("routes");
432
433 list.forEach(n -> mcastRoutes.add(
434 routeCodec.decode((ObjectNode) n, new AbstractWebResource())));
Jonathan Hart0212f642016-02-20 11:32:43 -0800435
436 } catch (ClientHandlerException e) {
437 log.warn("Unable to clear routes from remote controller: {}", e.getMessage());
Jonathan Hartc3f84eb2016-02-19 12:44:36 -0800438 } catch (IOException e) {
439 log.warn("Error clearing remote routes", e);
440 }
441
442 mcastRoutes.forEach(this::removeRemoteRoute);
443 }
444
Jonathan Hart28271642016-02-10 16:13:54 -0800445 private Integer allocateId() {
446 return channels.getAndIncrement();
447 }
448
449 private WebResource.Builder getClientBuilder(String uri) {
450 Client client = Client.create();
Jonathan Hart0212f642016-02-20 11:32:43 -0800451 client.setConnectTimeout(DEFAULT_REST_TIMEOUT_MS);
452 client.setReadTimeout(DEFAULT_REST_TIMEOUT_MS);
Jonathan Hart28271642016-02-10 16:13:54 -0800453 client.addFilter(new HTTPBasicAuthFilter(user, password));
454 WebResource resource = client.resource(uri);
455 return resource.accept(JSON_UTF_8.toString())
456 .type(JSON_UTF_8.toString());
457 }
458
alshabib3b1eadc2016-02-01 17:57:00 -0800459}