Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [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 | package org.onosproject.vtn.impl; |
| 17 | |
| 18 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
| 19 | import static org.onlab.util.Tools.groupedThreads; |
| 20 | import static org.slf4j.LoggerFactory.getLogger; |
| 21 | |
| 22 | import java.util.ArrayList; |
| 23 | import java.util.Collection; |
lishuai | ce88390 | 2015-09-14 15:46:23 +0800 | [diff] [blame] | 24 | import java.util.Collections; |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 25 | import java.util.Iterator; |
| 26 | import java.util.List; |
| 27 | import java.util.Set; |
| 28 | import java.util.concurrent.ScheduledExecutorService; |
lishuai | ce88390 | 2015-09-14 15:46:23 +0800 | [diff] [blame] | 29 | import java.util.stream.Collectors; |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 30 | |
| 31 | import org.apache.felix.scr.annotations.Activate; |
| 32 | import org.apache.felix.scr.annotations.Component; |
| 33 | import org.apache.felix.scr.annotations.Deactivate; |
| 34 | import org.apache.felix.scr.annotations.Reference; |
| 35 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 36 | import org.apache.felix.scr.annotations.Service; |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 37 | import org.onlab.osgi.DefaultServiceDirectory; |
| 38 | import org.onlab.osgi.ServiceDirectory; |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 39 | import org.onlab.packet.IpAddress; |
| 40 | import org.onlab.packet.MacAddress; |
| 41 | import org.onlab.util.KryoNamespace; |
| 42 | import org.onosproject.core.ApplicationId; |
| 43 | import org.onosproject.core.CoreService; |
| 44 | import org.onosproject.net.Device; |
| 45 | import org.onosproject.net.DeviceId; |
| 46 | import org.onosproject.net.Host; |
| 47 | import org.onosproject.net.HostId; |
| 48 | import org.onosproject.net.Port; |
| 49 | import org.onosproject.net.PortNumber; |
| 50 | import org.onosproject.net.behaviour.BridgeConfig; |
| 51 | import org.onosproject.net.behaviour.BridgeDescription; |
| 52 | import org.onosproject.net.behaviour.BridgeName; |
| 53 | import org.onosproject.net.behaviour.DefaultTunnelDescription; |
| 54 | import org.onosproject.net.behaviour.IpTunnelEndPoint; |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 55 | import org.onosproject.net.behaviour.Pipeliner; |
| 56 | import org.onosproject.net.behaviour.PipelinerContext; |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 57 | import org.onosproject.net.behaviour.TunnelConfig; |
| 58 | import org.onosproject.net.behaviour.TunnelDescription; |
| 59 | import org.onosproject.net.behaviour.TunnelEndPoint; |
| 60 | import org.onosproject.net.device.DeviceEvent; |
| 61 | import org.onosproject.net.device.DeviceListener; |
| 62 | import org.onosproject.net.device.DeviceService; |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 63 | import org.onosproject.net.driver.DefaultDriverData; |
| 64 | import org.onosproject.net.driver.Driver; |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 65 | import org.onosproject.net.driver.DriverHandler; |
| 66 | import org.onosproject.net.driver.DriverService; |
| 67 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 68 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 69 | import org.onosproject.net.flow.FlowRuleService; |
| 70 | import org.onosproject.net.flow.TrafficSelector; |
| 71 | import org.onosproject.net.flow.TrafficTreatment; |
| 72 | import org.onosproject.net.flow.criteria.Criteria; |
| 73 | import org.onosproject.net.flow.instructions.Instructions; |
| 74 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 75 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 76 | import org.onosproject.net.flowobjective.FlowObjectiveStore; |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 77 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 78 | import org.onosproject.net.flowobjective.ForwardingObjective.Flag; |
| 79 | import org.onosproject.net.flowobjective.Objective; |
| 80 | import org.onosproject.net.host.HostEvent; |
| 81 | import org.onosproject.net.host.HostListener; |
| 82 | import org.onosproject.net.host.HostService; |
| 83 | import org.onosproject.store.serializers.KryoNamespaces; |
| 84 | import org.onosproject.store.service.EventuallyConsistentMap; |
| 85 | import org.onosproject.store.service.StorageService; |
| 86 | import org.onosproject.store.service.WallClockTimestamp; |
| 87 | import org.onosproject.vtn.VTNService; |
| 88 | import org.onosproject.vtnrsc.SegmentationId; |
| 89 | import org.onosproject.vtnrsc.TenantNetwork; |
| 90 | import org.onosproject.vtnrsc.VirtualPort; |
| 91 | import org.onosproject.vtnrsc.VirtualPortId; |
| 92 | import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; |
| 93 | import org.onosproject.vtnrsc.virtualport.VirtualPortService; |
| 94 | import org.slf4j.Logger; |
| 95 | |
| 96 | import com.google.common.collect.Sets; |
| 97 | |
| 98 | /** |
| 99 | * Provides implementation of VTNService. |
| 100 | */ |
| 101 | @Component(immediate = true) |
| 102 | @Service |
| 103 | public class VTNManager implements VTNService { |
| 104 | private final Logger log = getLogger(getClass()); |
| 105 | |
| 106 | private static final String APP_ID = "org.onosproject.app.vtn"; |
| 107 | private ScheduledExecutorService backgroundService; |
| 108 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 109 | protected DeviceService deviceService; |
| 110 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 111 | protected HostService hostService; |
| 112 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 113 | protected FlowRuleService flowRuleService; |
| 114 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 115 | protected CoreService coreService; |
| 116 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 117 | protected StorageService storageService; |
| 118 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 119 | protected TenantNetworkService tenantNetworkService; |
| 120 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 121 | protected VirtualPortService virtualPortService; |
| 122 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 123 | protected DriverService driverService; |
| 124 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 125 | protected FlowObjectiveService flowObjectiveService; |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 126 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 127 | protected FlowObjectiveStore flowObjectiveStore; |
| 128 | protected ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 129 | private EventuallyConsistentMap<HostId, SegmentationId> binding; |
| 130 | private ApplicationId appId; |
| 131 | private HostListener hostListener = new InnerHostListener(); |
| 132 | private DeviceListener deviceListener = new InnerDeviceListener(); |
| 133 | private static final String IFACEID = "ifaceid"; |
| 134 | private static final String PORT_HEAD = "vxlan"; |
| 135 | private static final String DEFAULT_BRIDGE_NAME = "br-int"; |
| 136 | private static final String CONTROLLER_IP_KEY = "ipaddress"; |
| 137 | private static final int DEFAULT_MAC_PRIORITY = 0x0000; |
| 138 | private static final int MAC_PRIORITY = 0xffff; |
| 139 | private static final int DEFAULT_PORT_PRIORITY = 0x0000; |
| 140 | private static final int PORT_PRIORITY = 0xffff; |
| 141 | private static final String SWITCH_CHANNEL_ID = "channelId"; |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 142 | private static final String DRIVER_NAME = "onosfw"; |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 143 | |
| 144 | @Activate |
| 145 | public void activate() { |
| 146 | KryoNamespace.Builder serializer = KryoNamespace.newBuilder() |
| 147 | .register(KryoNamespaces.API); |
| 148 | appId = coreService.registerApplication(APP_ID); |
| 149 | deviceService.addListener(deviceListener); |
| 150 | hostService.addListener(hostListener); |
| 151 | backgroundService = newSingleThreadScheduledExecutor(groupedThreads("onos-apps/vtn", |
| 152 | "manager-background")); |
| 153 | binding = storageService |
| 154 | .<HostId, SegmentationId>eventuallyConsistentMapBuilder() |
| 155 | .withName("all_tunnel").withSerializer(serializer) |
| 156 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 157 | .build(); |
| 158 | log.info("Started"); |
| 159 | } |
| 160 | |
| 161 | @Deactivate |
| 162 | public void deactivate() { |
| 163 | backgroundService.shutdown(); |
| 164 | binding.destroy(); |
| 165 | log.info("Stopped"); |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void onServerDetected(Device device) { |
| 170 | Iterable<Device> devices = deviceService.getAvailableDevices(); |
| 171 | DriverHandler handler = driverService.createHandler(device.id()); |
| 172 | BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); |
| 173 | bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME)); |
| 174 | String ipAddress = device.annotations().value(CONTROLLER_IP_KEY); |
| 175 | IpAddress ip = IpAddress.valueOf(ipAddress); |
| 176 | Sets.newHashSet(devices).stream() |
| 177 | .filter(d -> Device.Type.CONTROLLER == d.type()) |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 178 | .filter(d -> !device.id().equals(d.id())).forEach(d -> { |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 179 | String ipAddress1 = d.annotations() |
| 180 | .value(CONTROLLER_IP_KEY); |
| 181 | IpAddress ip1 = IpAddress.valueOf(ipAddress1); |
| 182 | applyTunnelConfig(ip, ip1, handler); |
| 183 | DriverHandler handler1 = driverService |
| 184 | .createHandler(d.id()); |
| 185 | applyTunnelConfig(ip1, ip, handler1); |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 186 | |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 187 | }); |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public void onServerVanished(Device device) { |
| 192 | Iterable<Device> devices = deviceService.getAvailableDevices(); |
| 193 | String ipAddress = device.annotations().value(CONTROLLER_IP_KEY); |
| 194 | IpAddress dst = IpAddress.valueOf(ipAddress); |
| 195 | Sets.newHashSet(devices).stream() |
| 196 | .filter(d -> d.type() == Device.Type.CONTROLLER) |
| 197 | .filter(d -> !device.id().equals(d.id())).forEach(d -> { |
| 198 | String ipAddress1 = d.annotations() |
| 199 | .value(CONTROLLER_IP_KEY); |
| 200 | DriverHandler handler = driverService.createHandler(d.id()); |
| 201 | IpAddress src = IpAddress.valueOf(ipAddress1); |
| 202 | removeTunnelConfig(src, dst, handler); |
| 203 | }); |
| 204 | } |
| 205 | |
| 206 | private void applyTunnelConfig(IpAddress src, IpAddress dst, |
| 207 | DriverHandler handler) { |
| 208 | TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(src); |
| 209 | TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dst); |
| 210 | TunnelDescription tunnel = new DefaultTunnelDescription( |
| 211 | tunnelAsSrc, |
| 212 | tunnelAsDst, |
| 213 | TunnelDescription.Type.VXLAN, |
| 214 | null); |
| 215 | TunnelConfig config = handler.behaviour(TunnelConfig.class); |
| 216 | config.createTunnel(tunnel); |
| 217 | } |
| 218 | |
| 219 | private void removeTunnelConfig(IpAddress src, IpAddress dst, |
| 220 | DriverHandler handler) { |
| 221 | TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(src); |
| 222 | TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dst); |
| 223 | TunnelDescription tunnel = new DefaultTunnelDescription( |
| 224 | tunnelAsSrc, |
| 225 | tunnelAsDst, |
| 226 | TunnelDescription.Type.VXLAN, |
| 227 | null); |
| 228 | TunnelConfig config = handler.behaviour(TunnelConfig.class); |
| 229 | config.removeTunnel(tunnel); |
| 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public void onOvsDetected(Device device) { |
| 234 | programMacDefaultRules(device.id(), appId, Objective.Operation.ADD); |
| 235 | programPortDefaultRules(device.id(), appId, Objective.Operation.ADD); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | @Override |
| 239 | public void onOvsVanished(Device device) { |
| 240 | programMacDefaultRules(device.id(), appId, Objective.Operation.REMOVE); |
| 241 | programPortDefaultRules(device.id(), appId, Objective.Operation.REMOVE); |
| 242 | } |
| 243 | |
| 244 | @Override |
| 245 | public void onHostDetected(Host host) { |
| 246 | String ifaceId = host.annotations().value(IFACEID); |
| 247 | DeviceId deviceId = host.location().deviceId(); |
| 248 | String currentControllerIp = getControllerIpOfSwitch(deviceId); |
| 249 | Iterable<Device> devices = deviceService.getAvailableDevices(); |
| 250 | VirtualPortId portId = VirtualPortId.portId(ifaceId); |
| 251 | VirtualPort port = virtualPortService.getPort(portId); |
| 252 | TenantNetwork network = tenantNetworkService |
| 253 | .getNetwork(port.networkId()); |
| 254 | String tunnelName = "vxlan-" + currentControllerIp; |
| 255 | binding.put(host.id(), network.segmentationId()); |
| 256 | List<Port> allPorts = deviceService.getPorts(deviceId); |
| 257 | PortNumber inPort = host.location().port(); |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 258 | List<PortNumber> localVmPorts = getLocalPorts(deviceId, ifaceId); |
| 259 | List<PortNumber> localTunnelPorts = new ArrayList<>(); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 260 | Sets.newHashSet(allPorts.iterator()).stream() |
| 261 | .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 262 | if (p.annotations().value("portName").startsWith(PORT_HEAD)) { |
| 263 | localTunnelPorts.add(p.number()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 264 | } |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 265 | }); |
| 266 | |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 267 | localVmPorts.forEach(lp -> programLocalBcastRules(deviceId, network.segmentationId(), lp, localVmPorts, |
| 268 | localTunnelPorts, appId, Objective.Operation.ADD)); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 269 | programLocalOut(deviceId, network.segmentationId(), inPort, host.mac(), |
| 270 | appId, Objective.Operation.ADD); |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 271 | localTunnelPorts |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 272 | .forEach(tp -> programTunnelFloodOut(deviceId, |
| 273 | network.segmentationId(), |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 274 | tp, localVmPorts, |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 275 | appId, |
| 276 | Objective.Operation.ADD)); |
| 277 | Sets.newHashSet(devices).stream() |
| 278 | .filter(d -> d.type() == Device.Type.CONTROLLER).forEach(d -> { |
| 279 | DriverHandler handler = driverService.createHandler(d.id()); |
| 280 | BridgeConfig bridgeConfig = handler |
| 281 | .behaviour(BridgeConfig.class); |
| 282 | Collection<BridgeDescription> bridgeDescriptions = bridgeConfig |
| 283 | .getBridges(); |
| 284 | |
| 285 | Iterator<BridgeDescription> it = bridgeDescriptions |
| 286 | .iterator(); |
| 287 | if (it.hasNext()) { |
| 288 | BridgeDescription sw = it.next(); |
| 289 | Set<PortNumber> ports = bridgeConfig.getPortNumbers(); |
| 290 | ports.stream() |
| 291 | .filter(p -> p.name() |
| 292 | .equalsIgnoreCase(tunnelName)) |
Sho SHIMIZU | feafdca | 2015-09-11 15:02:21 -0700 | [diff] [blame] | 293 | .forEach(p -> programTunnelOut(sw.deviceId(), |
| 294 | network.segmentationId(), p, |
| 295 | host.mac(), appId, |
| 296 | Objective.Operation.ADD)); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 297 | } |
| 298 | }); |
| 299 | programLocalIn(deviceId, network.segmentationId(), inPort, host.mac(), |
| 300 | appId, Objective.Operation.ADD); |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 301 | localTunnelPorts |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 302 | .forEach(tp -> programTunnelIn(deviceId, |
| 303 | network.segmentationId(), |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 304 | tp, inPort, host.mac(), |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 305 | appId, Objective.Operation.ADD)); |
| 306 | |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public void onHostVanished(Host host) { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 311 | String ifaceId = host.annotations().value(IFACEID); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 312 | SegmentationId segId = binding.remove(host.id()); |
| 313 | DeviceId deviceId = host.location().deviceId(); |
| 314 | String currentControllerIp = getControllerIpOfSwitch(deviceId); |
| 315 | Iterable<Device> devices = deviceService.getAvailableDevices(); |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 316 | |
| 317 | String tunnelName = "vxlan-" + currentControllerIp; |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 318 | List<Port> allPorts = deviceService.getPorts(deviceId); |
| 319 | PortNumber inPort = host.location().port(); |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 320 | |
| 321 | List<PortNumber> localTunnelPorts = new ArrayList<>(); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 322 | Sets.newHashSet(allPorts.iterator()).stream() |
| 323 | .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 324 | if (p.annotations().value("portName").startsWith(PORT_HEAD)) { |
| 325 | localTunnelPorts.add(p.number()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 326 | } |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 327 | }); |
| 328 | |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 329 | List<PortNumber> localVmPorts = getLocalPorts(deviceId, ifaceId); |
| 330 | localVmPorts.add(inPort); |
| 331 | localVmPorts.forEach(lp -> programLocalBcastRules(deviceId, segId, lp, localVmPorts, |
| 332 | localTunnelPorts, appId, Objective.Operation.REMOVE)); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 333 | programLocalOut(deviceId, segId, inPort, host.mac(), |
| 334 | appId, Objective.Operation.REMOVE); |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 335 | localTunnelPorts |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 336 | .forEach(tp -> programTunnelFloodOut(deviceId, |
| 337 | segId, |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 338 | tp, localVmPorts, |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 339 | appId, |
| 340 | Objective.Operation.REMOVE)); |
| 341 | Sets.newHashSet(devices).stream() |
| 342 | .filter(d -> d.type() == Device.Type.CONTROLLER).forEach(d -> { |
| 343 | DriverHandler handler = driverService.createHandler(d.id()); |
| 344 | BridgeConfig bridgeConfig = handler |
| 345 | .behaviour(BridgeConfig.class); |
| 346 | Collection<BridgeDescription> bridgeDescriptions = bridgeConfig |
| 347 | .getBridges(); |
| 348 | |
| 349 | Iterator<BridgeDescription> it = bridgeDescriptions |
| 350 | .iterator(); |
| 351 | if (it.hasNext()) { |
| 352 | BridgeDescription sw = it.next(); |
| 353 | Set<PortNumber> ports = bridgeConfig.getPortNumbers(); |
| 354 | ports.stream() |
| 355 | .filter(p -> p.name() |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 356 | .equalsIgnoreCase(tunnelName)) |
Sho SHIMIZU | feafdca | 2015-09-11 15:02:21 -0700 | [diff] [blame] | 357 | .forEach(p -> programTunnelOut(sw.deviceId(), |
| 358 | segId, p, |
| 359 | host.mac(), appId, |
| 360 | Objective.Operation.REMOVE)); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 361 | } |
| 362 | }); |
| 363 | programLocalIn(deviceId, segId, inPort, host.mac(), |
| 364 | appId, Objective.Operation.REMOVE); |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 365 | localTunnelPorts |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 366 | .forEach(tp -> programTunnelIn(deviceId, |
| 367 | segId, |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 368 | tp, inPort, host.mac(), |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 369 | appId, Objective.Operation.REMOVE)); |
| 370 | } |
| 371 | |
| 372 | private class InnerDeviceListener implements DeviceListener { |
| 373 | |
| 374 | @Override |
| 375 | public void event(DeviceEvent event) { |
| 376 | Device device = event.subject(); |
| 377 | if (Device.Type.CONTROLLER == device.type() |
| 378 | && DeviceEvent.Type.DEVICE_ADDED == event.type()) { |
Sho SHIMIZU | feafdca | 2015-09-11 15:02:21 -0700 | [diff] [blame] | 379 | backgroundService.execute(() -> onServerDetected(device)); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 380 | } else if (Device.Type.CONTROLLER == device.type() |
| 381 | && DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED == event |
| 382 | .type()) { |
Sho SHIMIZU | feafdca | 2015-09-11 15:02:21 -0700 | [diff] [blame] | 383 | backgroundService.execute(() -> onServerVanished(device)); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 384 | } else if (Device.Type.SWITCH == device.type() |
| 385 | && DeviceEvent.Type.DEVICE_ADDED == event.type()) { |
Sho SHIMIZU | feafdca | 2015-09-11 15:02:21 -0700 | [diff] [blame] | 386 | backgroundService.execute(() -> onOvsDetected(device)); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 387 | } else if (Device.Type.SWITCH == device.type() |
| 388 | && DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED == event |
| 389 | .type()) { |
Sho SHIMIZU | feafdca | 2015-09-11 15:02:21 -0700 | [diff] [blame] | 390 | backgroundService.execute(() -> onOvsVanished(device)); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 391 | } else { |
| 392 | log.info("Do nothing for this device type"); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | } |
| 397 | |
| 398 | private class InnerHostListener implements HostListener { |
| 399 | |
| 400 | @Override |
| 401 | public void event(HostEvent event) { |
| 402 | Host host = event.subject(); |
| 403 | if (HostEvent.Type.HOST_ADDED == event.type()) { |
Sho SHIMIZU | feafdca | 2015-09-11 15:02:21 -0700 | [diff] [blame] | 404 | backgroundService.execute(() -> onHostDetected(host)); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 405 | } else if (HostEvent.Type.HOST_REMOVED == event.type()) { |
Sho SHIMIZU | feafdca | 2015-09-11 15:02:21 -0700 | [diff] [blame] | 406 | backgroundService.execute(() -> onHostVanished(host)); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 407 | } else if (HostEvent.Type.HOST_UPDATED == event.type()) { |
| 408 | backgroundService.execute(() -> { |
| 409 | onHostVanished(host); |
| 410 | onHostDetected(host); |
| 411 | }); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | } |
| 416 | |
| 417 | // Used to forward the flows to the local VM. |
| 418 | private void programLocalOut(DeviceId dpid, SegmentationId segmentationId, |
| 419 | PortNumber outPort, MacAddress sourceMac, |
| 420 | ApplicationId appid, |
| 421 | Objective.Operation type) { |
| 422 | TrafficSelector selector = DefaultTrafficSelector.builder() |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 423 | .matchTunnelId(Long.parseLong(segmentationId.toString())) |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 424 | .matchEthDst(sourceMac).build(); |
| 425 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 426 | .setOutput(outPort).build(); |
| 427 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
| 428 | .builder().withTreatment(treatment).withSelector(selector) |
| 429 | .fromApp(appId).withFlag(Flag.SPECIFIC) |
| 430 | .withPriority(MAC_PRIORITY); |
| 431 | if (type.equals(Objective.Operation.ADD)) { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 432 | flowServiceForward(dpid, objective.add()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 433 | } else { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 434 | flowServiceForward(dpid, objective.remove()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | } |
| 438 | |
| 439 | // Used to forward the flows into the VXLAN tunnel. |
| 440 | private void programTunnelOut(DeviceId dpid, SegmentationId segmentationId, |
| 441 | PortNumber tunnelOutPort, MacAddress dstMac, |
| 442 | ApplicationId appid, |
| 443 | Objective.Operation type) { |
| 444 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 445 | .matchEthDst(dstMac).add(Criteria.matchTunnelId(Long |
| 446 | .parseLong(segmentationId.toString()))) |
| 447 | .build(); |
| 448 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 449 | |
| 450 | .setOutput(tunnelOutPort).build(); |
| 451 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
| 452 | .builder().withTreatment(treatment).withSelector(selector) |
| 453 | .fromApp(appId).withFlag(Flag.SPECIFIC) |
| 454 | .withPriority(MAC_PRIORITY); |
| 455 | if (type.equals(Objective.Operation.ADD)) { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 456 | flowServiceForward(dpid, objective.add()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 457 | } else { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 458 | flowServiceForward(dpid, objective.remove()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | } |
| 462 | |
| 463 | // Used to forward multicast flows to remote VMs of the same tenant via |
| 464 | // VXLAN tunnel. |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 465 | private void programTunnelFloodOut(DeviceId deviceId, |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 466 | SegmentationId segmentationId, |
| 467 | PortNumber ofPortOut, |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 468 | List<PortNumber> localVmPorts, |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 469 | ApplicationId appid, |
| 470 | Objective.Operation type) { |
| 471 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 472 | .matchInPort(ofPortOut) |
| 473 | |
| 474 | .add(Criteria.matchTunnelId(Long.parseLong(segmentationId |
| 475 | .toString()))).matchEthDst(MacAddress.BROADCAST) |
| 476 | .build(); |
| 477 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 478 | |
| 479 | for (PortNumber outPort : localVmPorts) { |
| 480 | treatment.setOutput(outPort); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
| 484 | .builder().withTreatment(treatment.build()) |
| 485 | .withSelector(selector).fromApp(appId).makePermanent() |
| 486 | .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); |
| 487 | if (type.equals(Objective.Operation.ADD)) { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 488 | flowServiceForward(deviceId, objective.add()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 489 | } else { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 490 | flowServiceForward(deviceId, objective.remove()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
| 494 | // Applies default flows to mac table. |
| 495 | private void programMacDefaultRules(DeviceId dpid, ApplicationId appid, |
| 496 | Objective.Operation type) { |
| 497 | TrafficSelector selector = DefaultTrafficSelector.builder().build(); |
| 498 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().drop() |
| 499 | .build(); |
| 500 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
| 501 | .builder().withTreatment(treatment).withSelector(selector) |
| 502 | .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) |
| 503 | .withPriority(DEFAULT_MAC_PRIORITY); |
| 504 | if (type.equals(Objective.Operation.ADD)) { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 505 | flowServiceForward(dpid, objective.add()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 506 | } else { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 507 | flowServiceForward(dpid, objective.remove()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | |
| 511 | // Used to forward the flows to the local VMs with the same tenant. |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 512 | private void programLocalBcastRules(DeviceId deviceId, |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 513 | SegmentationId segmentationId, |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 514 | PortNumber inPort, |
| 515 | List<PortNumber> localVmPorts, |
| 516 | List<PortNumber> localTunnelPorts, |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 517 | ApplicationId appid, |
| 518 | Objective.Operation type) { |
| 519 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 520 | .matchInPort(inPort).matchEthDst(MacAddress.BROADCAST) |
| 521 | .add(Criteria.matchTunnelId(Long |
| 522 | .parseLong(segmentationId.toString()))) |
| 523 | .build(); |
| 524 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 525 | for (PortNumber outPort : localVmPorts) { |
| 526 | if (inPort != outPort) { |
| 527 | treatment.setOutput(outPort); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 528 | } |
| 529 | } |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 530 | for (PortNumber outport : localTunnelPorts) { |
| 531 | treatment.setOutput(outport); |
| 532 | } |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 533 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
| 534 | .builder().withTreatment(treatment.build()) |
| 535 | .withSelector(selector).fromApp(appId).makePermanent() |
| 536 | .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); |
| 537 | if (type.equals(Objective.Operation.ADD)) { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 538 | flowServiceForward(deviceId, objective.add()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 539 | } else { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 540 | flowServiceForward(deviceId, objective.remove()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
| 544 | // Used to apply local entry flow. |
| 545 | private void programLocalIn(DeviceId dpid, SegmentationId segmentationId, |
| 546 | PortNumber inPort, MacAddress srcMac, |
| 547 | ApplicationId appid, Objective.Operation type) { |
| 548 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 549 | .matchInPort(inPort).matchEthSrc(srcMac).build(); |
| 550 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 551 | treatment.add(Instructions.modTunnelId(Long.parseLong(segmentationId |
| 552 | .toString()))); |
| 553 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
| 554 | .builder().withTreatment(treatment.build()) |
| 555 | .withSelector(selector).fromApp(appId).makePermanent() |
| 556 | .withFlag(Flag.SPECIFIC).withPriority(PORT_PRIORITY); |
| 557 | if (type.equals(Objective.Operation.ADD)) { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 558 | flowServiceForward(dpid, objective.add()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 559 | } else { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 560 | flowServiceForward(dpid, objective.remove()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
| 564 | // Used to forward the flows from the egress tunnel to the VM. |
| 565 | private void programTunnelIn(DeviceId dpid, SegmentationId segmentationId, |
| 566 | PortNumber tunnelInPort, PortNumber outPort, |
| 567 | MacAddress sourceMac, ApplicationId appid, |
| 568 | Objective.Operation type) { |
| 569 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 570 | .matchInPort(tunnelInPort).add(Criteria.matchTunnelId(Long |
| 571 | .parseLong(segmentationId.toString()))) |
| 572 | .build(); |
| 573 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); |
| 574 | |
| 575 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
| 576 | .builder().withTreatment(treatment).withSelector(selector) |
| 577 | .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) |
| 578 | .withPriority(PORT_PRIORITY); |
| 579 | if (type.equals(Objective.Operation.ADD)) { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 580 | flowServiceForward(dpid, objective.add()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 581 | } else { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 582 | flowServiceForward(dpid, objective.remove()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | |
| 586 | // Applies the default flows to port table. |
| 587 | private void programPortDefaultRules(DeviceId dpid, ApplicationId appid, |
| 588 | Objective.Operation type) { |
| 589 | TrafficSelector selector = DefaultTrafficSelector.builder().build(); |
| 590 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); |
| 591 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
| 592 | .builder().withTreatment(treatment).withSelector(selector) |
| 593 | .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) |
| 594 | .withPriority(DEFAULT_PORT_PRIORITY); |
| 595 | if (type.equals(Objective.Operation.ADD)) { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 596 | flowServiceForward(dpid, objective.add()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 597 | } else { |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 598 | flowServiceForward(dpid, objective.remove()); |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
| 602 | // Used to get channelId from the device annotations. |
| 603 | private String getControllerIpOfSwitch(DeviceId deviceId) { |
| 604 | Device device = deviceService.getDevice(deviceId); |
| 605 | String url = device.annotations().value(SWITCH_CHANNEL_ID); |
| 606 | return url.substring(0, url.lastIndexOf(":")); |
| 607 | } |
| 608 | |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 609 | private Iterable<String> getIfaceIds(String ifaceId) { |
| 610 | VirtualPortId portId = VirtualPortId.portId(ifaceId); |
| 611 | VirtualPort port = virtualPortService.getPort(portId); |
lishuai | ce88390 | 2015-09-14 15:46:23 +0800 | [diff] [blame] | 612 | if (port == null) { |
| 613 | return Collections.emptyList(); |
| 614 | } |
| 615 | |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 616 | TenantNetwork network = tenantNetworkService |
| 617 | .getNetwork(port.networkId()); |
lishuai | ce88390 | 2015-09-14 15:46:23 +0800 | [diff] [blame] | 618 | if (network == null) { |
| 619 | return Collections.emptyList(); |
| 620 | } |
| 621 | |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 622 | Collection<VirtualPort> ports = virtualPortService |
| 623 | .getPorts(network.id()); |
lishuai | ce88390 | 2015-09-14 15:46:23 +0800 | [diff] [blame] | 624 | return ports.stream().map(p -> p.portId().portId()) |
| 625 | .collect(Collectors.toSet()); |
CNlucius | a66c397 | 2015-09-06 20:31:29 +0800 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | private List<PortNumber> getLocalPorts(DeviceId deviceId, String ifaceId) { |
| 629 | DriverHandler handler = driverService |
| 630 | .createHandler(getController(deviceId)); |
| 631 | BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); |
| 632 | Iterable<String> ifaceIds = getIfaceIds(ifaceId); |
| 633 | return bridgeConfig.getLocalPorts(ifaceIds); |
| 634 | } |
| 635 | |
| 636 | private DeviceId getController(DeviceId deviceId) { |
| 637 | Iterable<Device> devices = deviceService.getAvailableDevices(); |
| 638 | for (Device device : devices) { |
| 639 | if (device.type() == Device.Type.CONTROLLER && device.id() |
| 640 | .toString().contains(getControllerIpOfSwitch(deviceId))) { |
| 641 | return device.id(); |
| 642 | } |
| 643 | } |
| 644 | log.info("Can not find controller for device : {}", deviceId); |
| 645 | return null; |
| 646 | } |
| 647 | |
| 648 | //Used to apply flowRule |
| 649 | private void flowServiceForward(DeviceId deviceId, ForwardingObjective forwardingObjective) { |
| 650 | Driver driver = driverService.getDriver(DRIVER_NAME); |
| 651 | Pipeliner pipeLiner = driver.createBehaviour(new DefaultDriverData(driver, deviceId), Pipeliner.class); |
| 652 | if (pipeLiner != null) { |
| 653 | final PipelinerContext context = new InnerPipelineContext(); |
| 654 | pipeLiner.init(deviceId, context); |
| 655 | pipeLiner.forward(forwardingObjective); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | // Processing context for initializing pipeline driver behaviours. |
| 660 | private class InnerPipelineContext implements PipelinerContext { |
| 661 | @Override |
| 662 | public ServiceDirectory directory() { |
| 663 | return serviceDirectory; |
| 664 | } |
| 665 | |
| 666 | @Override |
| 667 | public FlowObjectiveStore store() { |
| 668 | return flowObjectiveStore; |
| 669 | } |
| 670 | } |
| 671 | |
Sho SHIMIZU | 7d2e48e | 2015-09-01 17:37:00 -0700 | [diff] [blame] | 672 | } |