alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.cordmcast; |
| 17 | |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 19 | import com.google.common.collect.Maps; |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 20 | import com.sun.jersey.api.client.Client; |
| 21 | import com.sun.jersey.api.client.WebResource; |
| 22 | import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 23 | import org.apache.felix.scr.annotations.Activate; |
| 24 | import org.apache.felix.scr.annotations.Component; |
| 25 | import org.apache.felix.scr.annotations.Deactivate; |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 26 | import org.apache.felix.scr.annotations.Modified; |
| 27 | import org.apache.felix.scr.annotations.Property; |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 28 | import org.apache.felix.scr.annotations.Reference; |
| 29 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 30 | import org.onlab.packet.Ethernet; |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 31 | import org.onlab.packet.IpAddress; |
| 32 | import org.onlab.packet.VlanId; |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 33 | import org.onosproject.cfg.ComponentConfigService; |
| 34 | import org.onosproject.codec.CodecService; |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 35 | import org.onosproject.core.ApplicationId; |
| 36 | import org.onosproject.core.CoreService; |
| 37 | import org.onosproject.net.ConnectPoint; |
| 38 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 39 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 40 | import org.onosproject.net.flow.TrafficSelector; |
| 41 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 42 | import org.onosproject.net.flowobjective.DefaultNextObjective; |
| 43 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 44 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 45 | import org.onosproject.net.flowobjective.NextObjective; |
| 46 | import org.onosproject.net.flowobjective.Objective; |
| 47 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 48 | import org.onosproject.net.flowobjective.ObjectiveError; |
| 49 | import org.onosproject.net.group.GroupService; |
| 50 | import org.onosproject.net.mcast.McastEvent; |
| 51 | import org.onosproject.net.mcast.McastListener; |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 52 | import org.onosproject.net.mcast.McastRoute; |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 53 | import org.onosproject.net.mcast.McastRouteInfo; |
| 54 | import org.onosproject.net.mcast.MulticastRouteService; |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 55 | import org.onosproject.rest.AbstractWebResource; |
| 56 | import org.osgi.service.component.ComponentContext; |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 57 | import org.slf4j.Logger; |
| 58 | |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 59 | import java.util.Dictionary; |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 60 | import java.util.Map; |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 61 | import java.util.Properties; |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 62 | import java.util.concurrent.atomic.AtomicBoolean; |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 63 | import java.util.concurrent.atomic.AtomicInteger; |
| 64 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 65 | import static com.google.common.base.Strings.isNullOrEmpty; |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 66 | import static com.google.common.net.MediaType.JSON_UTF_8; |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 67 | import static org.onlab.util.Tools.get; |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 68 | import static org.slf4j.LoggerFactory.getLogger; |
| 69 | |
| 70 | /** |
| 71 | * CORD multicast provisoning application. Operates by listening to |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 72 | * events on the multicast rib and provisioning groups to program multicast |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 73 | * flows on the dataplane. |
| 74 | */ |
| 75 | @Component(immediate = true) |
| 76 | public class CordMcast { |
| 77 | |
| 78 | private static final int DEFAULT_PRIORITY = 1000; |
| 79 | private static final short DEFAULT_MCAST_VLAN = 4000; |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 80 | private static final String DEFAULT_SYNC_HOST = "10.90.0.8:8181"; |
| 81 | private static final String DEFAULT_USER = "karaf"; |
| 82 | private static final String DEFAULT_PASSWORD = "karaf"; |
| 83 | |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 84 | private final Logger log = getLogger(getClass()); |
| 85 | |
| 86 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 87 | protected MulticastRouteService mcastService; |
| 88 | |
| 89 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 90 | protected GroupService groupService; |
| 91 | |
| 92 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 93 | protected FlowObjectiveService flowObjectiveService; |
| 94 | |
| 95 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 96 | protected CoreService coreService; |
| 97 | |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 98 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 99 | protected CodecService codecService; |
| 100 | |
| 101 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 102 | protected ComponentConfigService componentConfigService; |
| 103 | |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 104 | protected McastListener listener = new InternalMulticastListener(); |
| 105 | |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 106 | //TODO: move this to a ec map |
| 107 | private Map<IpAddress, Integer> groups = Maps.newConcurrentMap(); |
| 108 | |
| 109 | //TODO: move this to distributed atomic long |
| 110 | private AtomicInteger channels = new AtomicInteger(0); |
| 111 | |
| 112 | private ApplicationId appId; |
| 113 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 114 | @Property(name = "mcastVlan", intValue = DEFAULT_MCAST_VLAN, |
| 115 | label = "VLAN for multicast traffic") |
| 116 | private int mcastVlan = DEFAULT_MCAST_VLAN; |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 117 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 118 | @Property(name = "vlanEnabled", boolValue = false, |
| 119 | label = "Use vlan for multicast traffic") |
| 120 | private boolean vlanEnabled = false; |
| 121 | |
| 122 | @Property(name = "priority", intValue = DEFAULT_PRIORITY, |
| 123 | label = "Priority for multicast rules") |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 124 | private int priority = DEFAULT_PRIORITY; |
| 125 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 126 | @Property(name = "syncHost", value = DEFAULT_SYNC_HOST, |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 127 | label = "host:port to synchronize routes to") |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 128 | private String syncHost = DEFAULT_SYNC_HOST; |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 129 | |
| 130 | @Property(name = "username", value = DEFAULT_USER, |
| 131 | label = "Username for REST password authentication") |
| 132 | private String user = DEFAULT_USER; |
| 133 | |
| 134 | @Property(name = "password", value = DEFAULT_PASSWORD, |
| 135 | label = "Password for REST authentication") |
| 136 | private String password = DEFAULT_PASSWORD; |
| 137 | |
| 138 | private String fabricOnosUrl; |
| 139 | |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 140 | @Activate |
Jonathan Hart | 81d7310 | 2016-02-19 10:32:05 -0800 | [diff] [blame] | 141 | public void activate(ComponentContext context) { |
| 142 | modified(context); |
| 143 | |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 144 | appId = coreService.registerApplication("org.onosproject.cordmcast"); |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 145 | componentConfigService.registerProperties(getClass()); |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 146 | mcastService.addListener(listener); |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 147 | |
| 148 | fabricOnosUrl = "http://" + syncHost + "/onos/v1/mcast"; |
| 149 | |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 150 | //TODO: obtain all existing mcast routes |
| 151 | log.info("Started"); |
| 152 | } |
| 153 | |
| 154 | @Deactivate |
| 155 | public void deactivate() { |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 156 | componentConfigService.unregisterProperties(getClass(), true); |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 157 | mcastService.removeListener(listener); |
| 158 | log.info("Stopped"); |
| 159 | } |
| 160 | |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 161 | @Modified |
| 162 | public void modified(ComponentContext context) { |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 163 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 164 | |
| 165 | |
| 166 | try { |
| 167 | String s = get(properties, "username"); |
| 168 | user = isNullOrEmpty(s) ? DEFAULT_USER : s.trim(); |
| 169 | |
| 170 | s = get(properties, "password"); |
| 171 | password = isNullOrEmpty(s) ? DEFAULT_PASSWORD : s.trim(); |
| 172 | |
| 173 | s = get(properties, "mcastVlan"); |
| 174 | mcastVlan = isNullOrEmpty(s) ? DEFAULT_MCAST_VLAN : Short.parseShort(s.trim()); |
| 175 | |
| 176 | s = get(properties, "vlanEnabled"); |
| 177 | vlanEnabled = isNullOrEmpty(s) || Boolean.parseBoolean(s.trim()); |
| 178 | |
| 179 | s = get(properties, "priority"); |
| 180 | priority = isNullOrEmpty(s) ? DEFAULT_PRIORITY : Integer.parseInt(s.trim()); |
| 181 | |
| 182 | s = get(properties, syncHost); |
| 183 | syncHost = isNullOrEmpty(s) ? DEFAULT_SYNC_HOST : s.trim(); |
| 184 | } catch (Exception e) { |
| 185 | user = DEFAULT_USER; |
| 186 | password = DEFAULT_PASSWORD; |
| 187 | syncHost = DEFAULT_SYNC_HOST; |
| 188 | mcastVlan = DEFAULT_MCAST_VLAN; |
| 189 | vlanEnabled = false; |
| 190 | priority = DEFAULT_PRIORITY; |
| 191 | } |
| 192 | |
| 193 | |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 194 | } |
| 195 | |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 196 | private class InternalMulticastListener implements McastListener { |
| 197 | @Override |
| 198 | public void event(McastEvent event) { |
| 199 | switch (event.type()) { |
| 200 | case ROUTE_ADDED: |
| 201 | break; |
| 202 | case ROUTE_REMOVED: |
| 203 | break; |
| 204 | case SOURCE_ADDED: |
| 205 | break; |
| 206 | case SINK_ADDED: |
| 207 | provisionGroup(event.subject()); |
| 208 | break; |
| 209 | case SINK_REMOVED: |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 210 | unprovisionGroup(event.subject()); |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 211 | break; |
| 212 | default: |
| 213 | log.warn("Unknown mcast event {}", event.type()); |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 218 | private void unprovisionGroup(McastRouteInfo info) { |
Jonathan Hart | dd7e3d5 | 2016-02-18 15:56:22 -0800 | [diff] [blame] | 219 | if (info.sinks().isEmpty()) { |
| 220 | removeSyncedRoute(info); |
| 221 | } |
| 222 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 223 | if (!info.sink().isPresent()) { |
| 224 | log.warn("No sink given after sink removed event: {}", info); |
| 225 | return; |
| 226 | } |
| 227 | ConnectPoint loc = info.sink().get(); |
| 228 | |
| 229 | NextObjective next = DefaultNextObjective.builder() |
| 230 | .fromApp(appId) |
| 231 | .addTreatment(DefaultTrafficTreatment.builder().setOutput(loc.port()).build()) |
| 232 | .withType(NextObjective.Type.BROADCAST) |
| 233 | .withId(groups.get(info.route().group())) |
| 234 | .removeFromExisting(new ObjectiveContext() { |
| 235 | @Override |
| 236 | public void onSuccess(Objective objective) { |
| 237 | //TODO: change to debug |
| 238 | log.info("Next Objective {} installed", objective.id()); |
| 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public void onError(Objective objective, ObjectiveError error) { |
| 243 | //TODO: change to debug |
| 244 | log.info("Next Objective {} failed, because {}", |
| 245 | objective.id(), |
| 246 | error); |
| 247 | } |
| 248 | }); |
| 249 | |
| 250 | flowObjectiveService.next(loc.deviceId(), next); |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 251 | } |
| 252 | |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 253 | private void provisionGroup(McastRouteInfo info) { |
| 254 | if (!info.sink().isPresent()) { |
| 255 | log.warn("No sink given after sink added event: {}", info); |
| 256 | return; |
| 257 | } |
| 258 | ConnectPoint loc = info.sink().get(); |
| 259 | |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 260 | final AtomicBoolean sync = new AtomicBoolean(false); |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 261 | |
| 262 | Integer nextId = groups.computeIfAbsent(info.route().group(), (g) -> { |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 263 | Integer id = allocateId(); |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 264 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 265 | NextObjective next = DefaultNextObjective.builder() |
| 266 | .fromApp(appId) |
| 267 | .addTreatment(DefaultTrafficTreatment.builder().setOutput(loc.port()).build()) |
| 268 | .withType(NextObjective.Type.BROADCAST) |
| 269 | .withId(id) |
| 270 | .add(new ObjectiveContext() { |
| 271 | @Override |
| 272 | public void onSuccess(Objective objective) { |
| 273 | //TODO: change to debug |
| 274 | log.info("Next Objective {} installed", objective.id()); |
| 275 | } |
| 276 | |
| 277 | @Override |
| 278 | public void onError(Objective objective, ObjectiveError error) { |
| 279 | //TODO: change to debug |
| 280 | log.info("Next Objective {} failed, because {}", |
| 281 | objective.id(), |
| 282 | error); |
| 283 | } |
| 284 | }); |
| 285 | |
| 286 | flowObjectiveService.next(loc.deviceId(), next); |
| 287 | |
| 288 | TrafficSelector.Builder mcast = DefaultTrafficSelector.builder() |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 289 | .matchEthType(Ethernet.TYPE_IPV4) |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 290 | .matchIPDst(g.toIpPrefix()); |
| 291 | |
| 292 | |
| 293 | if (vlanEnabled) { |
| 294 | mcast.matchVlanId(VlanId.vlanId((short) mcastVlan)); |
| 295 | } |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 296 | |
| 297 | |
| 298 | ForwardingObjective fwd = DefaultForwardingObjective.builder() |
| 299 | .fromApp(appId) |
| 300 | .nextStep(id) |
| 301 | .makePermanent() |
| 302 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 303 | .withPriority(priority) |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 304 | .withSelector(mcast.build()) |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 305 | .add(new ObjectiveContext() { |
| 306 | @Override |
| 307 | public void onSuccess(Objective objective) { |
| 308 | //TODO: change to debug |
| 309 | log.info("Forwarding objective installed {}", objective); |
| 310 | } |
| 311 | |
| 312 | @Override |
| 313 | public void onError(Objective objective, ObjectiveError error) { |
| 314 | //TODO: change to debug |
| 315 | log.info("Forwarding objective failed {}", objective); |
| 316 | } |
| 317 | }); |
| 318 | |
| 319 | flowObjectiveService.forward(loc.deviceId(), fwd); |
| 320 | |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 321 | sync.set(true); |
| 322 | |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 323 | return id; |
| 324 | }); |
| 325 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 326 | if (!sync.get()) { |
| 327 | NextObjective next = DefaultNextObjective.builder() |
| 328 | .fromApp(appId) |
| 329 | .addTreatment(DefaultTrafficTreatment.builder().setOutput(loc.port()).build()) |
| 330 | .withType(NextObjective.Type.BROADCAST) |
| 331 | .withId(nextId) |
| 332 | .addToExisting(new ObjectiveContext() { |
| 333 | @Override |
| 334 | public void onSuccess(Objective objective) { |
| 335 | //TODO: change to debug |
| 336 | log.info("Next Objective {} installed", objective.id()); |
| 337 | } |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 338 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 339 | @Override |
| 340 | public void onError(Objective objective, ObjectiveError error) { |
| 341 | //TODO: change to debug |
| 342 | log.info("Next Objective {} failed, because {}", |
| 343 | objective.id(), |
| 344 | error); |
| 345 | } |
| 346 | }); |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 347 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 348 | flowObjectiveService.next(loc.deviceId(), next); |
| 349 | } |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 350 | |
| 351 | if (sync.get()) { |
| 352 | syncRoute(info); |
| 353 | } |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 354 | } |
| 355 | |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 356 | private void syncRoute(McastRouteInfo info) { |
| 357 | if (syncHost == null) { |
| 358 | log.warn("No host configured for synchronization; route will be dropped"); |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | log.debug("Sending route to other ONOS: {}", info.route()); |
| 363 | |
| 364 | WebResource.Builder builder = getClientBuilder(fabricOnosUrl); |
| 365 | |
| 366 | ObjectNode json = codecService.getCodec(McastRoute.class) |
| 367 | .encode(info.route(), new AbstractWebResource()); |
| 368 | builder.post(json.toString()); |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 369 | } |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 370 | |
Jonathan Hart | dd7e3d5 | 2016-02-18 15:56:22 -0800 | [diff] [blame] | 371 | private void removeSyncedRoute(McastRouteInfo info) { |
| 372 | if (syncHost == null) { |
| 373 | log.warn("No host configured for synchronization; route will be dropped"); |
| 374 | return; |
| 375 | } |
| 376 | |
| 377 | log.debug("Removing route from other ONOS: {}", info.route()); |
| 378 | |
| 379 | WebResource.Builder builder = getClientBuilder(fabricOnosUrl); |
| 380 | |
| 381 | ObjectNode json = codecService.getCodec(McastRoute.class) |
| 382 | .encode(info.route(), new AbstractWebResource()); |
| 383 | builder.delete(json.toString()); |
| 384 | } |
| 385 | |
Jonathan Hart | fcdcb4f | 2016-02-10 16:13:54 -0800 | [diff] [blame] | 386 | private Integer allocateId() { |
| 387 | return channels.getAndIncrement(); |
| 388 | } |
| 389 | |
| 390 | private WebResource.Builder getClientBuilder(String uri) { |
| 391 | Client client = Client.create(); |
| 392 | client.addFilter(new HTTPBasicAuthFilter(user, password)); |
| 393 | WebResource resource = client.resource(uri); |
| 394 | return resource.accept(JSON_UTF_8.toString()) |
| 395 | .type(JSON_UTF_8.toString()); |
| 396 | } |
| 397 | |
alshabib | 7115cd2 | 2016-02-01 17:57:00 -0800 | [diff] [blame] | 398 | } |