Committed by
Thomas Vachuska
ONOS-2709
Fix bug of installing flowrules. Change-Id: I84fc3e3c4894b3f84173a5364e4506d4fc6ba3fc
Showing
1 changed file
with
219 additions
and
89 deletions
... | @@ -19,7 +19,10 @@ import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | ... | @@ -19,7 +19,10 @@ import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
19 | import static org.onlab.util.Tools.groupedThreads; | 19 | import static org.onlab.util.Tools.groupedThreads; |
20 | import static org.slf4j.LoggerFactory.getLogger; | 20 | import static org.slf4j.LoggerFactory.getLogger; |
21 | 21 | ||
22 | +import java.util.ArrayList; | ||
23 | +import java.util.Collection; | ||
22 | import java.util.HashSet; | 24 | import java.util.HashSet; |
25 | +import java.util.Iterator; | ||
23 | import java.util.List; | 26 | import java.util.List; |
24 | import java.util.Set; | 27 | import java.util.Set; |
25 | import java.util.concurrent.ScheduledExecutorService; | 28 | import java.util.concurrent.ScheduledExecutorService; |
... | @@ -42,6 +45,7 @@ import org.onosproject.net.HostId; | ... | @@ -42,6 +45,7 @@ import org.onosproject.net.HostId; |
42 | import org.onosproject.net.Port; | 45 | import org.onosproject.net.Port; |
43 | import org.onosproject.net.PortNumber; | 46 | import org.onosproject.net.PortNumber; |
44 | import org.onosproject.net.behaviour.BridgeConfig; | 47 | import org.onosproject.net.behaviour.BridgeConfig; |
48 | +import org.onosproject.net.behaviour.BridgeDescription; | ||
45 | import org.onosproject.net.behaviour.BridgeName; | 49 | import org.onosproject.net.behaviour.BridgeName; |
46 | import org.onosproject.net.behaviour.DefaultTunnelDescription; | 50 | import org.onosproject.net.behaviour.DefaultTunnelDescription; |
47 | import org.onosproject.net.behaviour.IpTunnelEndPoint; | 51 | import org.onosproject.net.behaviour.IpTunnelEndPoint; |
... | @@ -119,6 +123,11 @@ public class VTNManager implements VTNService { | ... | @@ -119,6 +123,11 @@ public class VTNManager implements VTNService { |
119 | private static final String PORT_HEAD = "vxlan"; | 123 | private static final String PORT_HEAD = "vxlan"; |
120 | private static final String DEFAULT_BRIDGE_NAME = "br-int"; | 124 | private static final String DEFAULT_BRIDGE_NAME = "br-int"; |
121 | private static final String CONTROLLER_IP_KEY = "ipaddress"; | 125 | private static final String CONTROLLER_IP_KEY = "ipaddress"; |
126 | + private static final int DEFAULT_MAC_PRIORITY = 0x0000; | ||
127 | + private static final int MAC_PRIORITY = 0xffff; | ||
128 | + private static final int DEFAULT_PORT_PRIORITY = 0x0000; | ||
129 | + private static final int PORT_PRIORITY = 0xffff; | ||
130 | + private static final String SWITCH_CHANNEL_ID = "channelId"; | ||
122 | 131 | ||
123 | @Activate | 132 | @Activate |
124 | public void activate() { | 133 | public void activate() { |
... | @@ -152,19 +161,20 @@ public class VTNManager implements VTNService { | ... | @@ -152,19 +161,20 @@ public class VTNManager implements VTNService { |
152 | bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME)); | 161 | bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME)); |
153 | String ipAddress = device.annotations().value(CONTROLLER_IP_KEY); | 162 | String ipAddress = device.annotations().value(CONTROLLER_IP_KEY); |
154 | IpAddress ip = IpAddress.valueOf(ipAddress); | 163 | IpAddress ip = IpAddress.valueOf(ipAddress); |
155 | - Sets.newHashSet(devices) | 164 | + Sets.newHashSet(devices).stream() |
156 | - .stream() | 165 | + .filter(d -> Device.Type.CONTROLLER == d.type()) |
157 | - .filter(d -> d.type() == Device.Type.CONTROLLER) | 166 | + .filter(d -> !device.id().equals(d.id())).forEach(d -> { |
158 | - .filter(d -> !device.id().equals(d.id())) | 167 | + if (!device.id().equals(d.id()) |
159 | - .forEach(d -> { | 168 | + && Device.Type.CONTROLLER == d.type()) { |
160 | - String ipAddress1 = d.annotations() | 169 | + String ipAddress1 = d.annotations() |
161 | - .value(CONTROLLER_IP_KEY); | 170 | + .value(CONTROLLER_IP_KEY); |
162 | - IpAddress ip1 = IpAddress.valueOf(ipAddress1); | 171 | + IpAddress ip1 = IpAddress.valueOf(ipAddress1); |
163 | - applyTunnelConfig(ip, ip1, handler); | 172 | + applyTunnelConfig(ip, ip1, handler); |
164 | - DriverHandler handler1 = driverService | 173 | + DriverHandler handler1 = driverService |
165 | - .createHandler(d.id()); | 174 | + .createHandler(d.id()); |
166 | - applyTunnelConfig(ip1, ip, handler1); | 175 | + applyTunnelConfig(ip1, ip, handler1); |
167 | - }); | 176 | + } |
177 | + }); | ||
168 | } | 178 | } |
169 | 179 | ||
170 | @Override | 180 | @Override |
... | @@ -172,18 +182,15 @@ public class VTNManager implements VTNService { | ... | @@ -172,18 +182,15 @@ public class VTNManager implements VTNService { |
172 | Iterable<Device> devices = deviceService.getAvailableDevices(); | 182 | Iterable<Device> devices = deviceService.getAvailableDevices(); |
173 | String ipAddress = device.annotations().value(CONTROLLER_IP_KEY); | 183 | String ipAddress = device.annotations().value(CONTROLLER_IP_KEY); |
174 | IpAddress dst = IpAddress.valueOf(ipAddress); | 184 | IpAddress dst = IpAddress.valueOf(ipAddress); |
175 | - Sets.newHashSet(devices) | 185 | + Sets.newHashSet(devices).stream() |
176 | - .stream() | ||
177 | .filter(d -> d.type() == Device.Type.CONTROLLER) | 186 | .filter(d -> d.type() == Device.Type.CONTROLLER) |
178 | - .filter(d -> !device.id().equals(d.id())) | 187 | + .filter(d -> !device.id().equals(d.id())).forEach(d -> { |
179 | - .forEach(d -> { | 188 | + String ipAddress1 = d.annotations() |
180 | - String ipAddress1 = d.annotations() | 189 | + .value(CONTROLLER_IP_KEY); |
181 | - .value(CONTROLLER_IP_KEY); | 190 | + DriverHandler handler = driverService.createHandler(d.id()); |
182 | - DriverHandler handler = driverService | 191 | + IpAddress src = IpAddress.valueOf(ipAddress1); |
183 | - .createHandler(d.id()); | 192 | + removeTunnelConfig(src, dst, handler); |
184 | - IpAddress src = IpAddress.valueOf(ipAddress1); | 193 | + }); |
185 | - removeTunnelConfig(src, dst, handler); | ||
186 | - }); | ||
187 | } | 194 | } |
188 | 195 | ||
189 | private void applyTunnelConfig(IpAddress src, IpAddress dst, | 196 | private void applyTunnelConfig(IpAddress src, IpAddress dst, |
... | @@ -216,6 +223,32 @@ public class VTNManager implements VTNService { | ... | @@ -216,6 +223,32 @@ public class VTNManager implements VTNService { |
216 | public void onOvsDetected(Device device) { | 223 | public void onOvsDetected(Device device) { |
217 | programMacDefaultRules(device.id(), appId, Objective.Operation.ADD); | 224 | programMacDefaultRules(device.id(), appId, Objective.Operation.ADD); |
218 | programPortDefaultRules(device.id(), appId, Objective.Operation.ADD); | 225 | programPortDefaultRules(device.id(), appId, Objective.Operation.ADD); |
226 | + Set<Host> hosts = hostService.getConnectedHosts(device.id()); | ||
227 | + hosts.forEach(h -> { | ||
228 | + String ifaceId = h.annotations().value(IFACEID); | ||
229 | + String currentControllerIp = getControllerIpOfSwitch(device.id()); | ||
230 | + VirtualPortId portId = VirtualPortId.portId(ifaceId); | ||
231 | + VirtualPort port = virtualPortService.getPort(portId); | ||
232 | + TenantNetwork network = tenantNetworkService | ||
233 | + .getNetwork(port.networkId()); | ||
234 | + String vxlanName = "vxlan-" + currentControllerIp; | ||
235 | + | ||
236 | + DriverHandler handler = driverService.createHandler(device.id()); | ||
237 | + BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); | ||
238 | + Collection<BridgeDescription> bridgeDescriptions = bridgeConfig | ||
239 | + .getBridges(); | ||
240 | + Iterator<BridgeDescription> it = bridgeDescriptions.iterator(); | ||
241 | + if (it.hasNext()) { | ||
242 | + BridgeDescription sw = it.next(); | ||
243 | + Set<PortNumber> ports = bridgeConfig.getPortNumbers(); | ||
244 | + ports.stream().filter(p -> p.name().equalsIgnoreCase(vxlanName)) | ||
245 | + .forEach(p -> { | ||
246 | + programTunnelOut(sw.deviceId(), network.segmentationId(), p, | ||
247 | + h.mac(), appId, Objective.Operation.ADD); | ||
248 | + }); | ||
249 | + } | ||
250 | + | ||
251 | + }); | ||
219 | } | 252 | } |
220 | 253 | ||
221 | @Override | 254 | @Override |
... | @@ -227,58 +260,137 @@ public class VTNManager implements VTNService { | ... | @@ -227,58 +260,137 @@ public class VTNManager implements VTNService { |
227 | @Override | 260 | @Override |
228 | public void onHostDetected(Host host) { | 261 | public void onHostDetected(Host host) { |
229 | String ifaceId = host.annotations().value(IFACEID); | 262 | String ifaceId = host.annotations().value(IFACEID); |
263 | + DeviceId deviceId = host.location().deviceId(); | ||
264 | + String currentControllerIp = getControllerIpOfSwitch(deviceId); | ||
265 | + Iterable<Device> devices = deviceService.getAvailableDevices(); | ||
230 | VirtualPortId portId = VirtualPortId.portId(ifaceId); | 266 | VirtualPortId portId = VirtualPortId.portId(ifaceId); |
231 | VirtualPort port = virtualPortService.getPort(portId); | 267 | VirtualPort port = virtualPortService.getPort(portId); |
232 | - TenantNetwork network = tenantNetworkService.getNetwork(port | 268 | + TenantNetwork network = tenantNetworkService |
233 | - .networkId()); | 269 | + .getNetwork(port.networkId()); |
270 | + String tunnelName = "vxlan-" + currentControllerIp; | ||
234 | binding.put(host.id(), network.segmentationId()); | 271 | binding.put(host.id(), network.segmentationId()); |
235 | - DeviceId deviceId = host.location().deviceId(); | ||
236 | List<Port> allPorts = deviceService.getPorts(deviceId); | 272 | List<Port> allPorts = deviceService.getPorts(deviceId); |
237 | PortNumber inPort = host.location().port(); | 273 | PortNumber inPort = host.location().port(); |
238 | Set<Port> localPorts = new HashSet<>(); | 274 | Set<Port> localPorts = new HashSet<>(); |
239 | - allPorts.forEach(p -> { | 275 | + Set<Port> tunnelPorts = new HashSet<>(); |
240 | - if (!p.number().name().startsWith(PORT_HEAD)) { | 276 | + List<Port> outports = new ArrayList<>(); |
277 | + Sets.newHashSet(allPorts.iterator()).stream() | ||
278 | + .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { | ||
279 | + if (!p.annotations().value("portName").startsWith(PORT_HEAD)) { | ||
241 | localPorts.add(p); | 280 | localPorts.add(p); |
281 | + } else { | ||
282 | + tunnelPorts.add(p); | ||
242 | } | 283 | } |
284 | + outports.add(p); | ||
243 | }); | 285 | }); |
286 | + | ||
244 | programLocalBcastRules(deviceId, network.segmentationId(), inPort, | 287 | programLocalBcastRules(deviceId, network.segmentationId(), inPort, |
245 | - allPorts, appId, Objective.Operation.ADD); | 288 | + outports, appId, Objective.Operation.ADD); |
246 | programLocalOut(deviceId, network.segmentationId(), inPort, host.mac(), | 289 | programLocalOut(deviceId, network.segmentationId(), inPort, host.mac(), |
247 | appId, Objective.Operation.ADD); | 290 | appId, Objective.Operation.ADD); |
248 | - programTunnelFloodOut(deviceId, network.segmentationId(), inPort, | 291 | + tunnelPorts |
249 | - localPorts, appId, Objective.Operation.ADD); | 292 | + .forEach(tp -> programTunnelFloodOut(deviceId, |
250 | - programTunnelOut(deviceId, network.segmentationId(), inPort, | 293 | + network.segmentationId(), |
251 | - host.mac(), appId, Objective.Operation.ADD); | 294 | + tp.number(), localPorts, |
295 | + appId, | ||
296 | + Objective.Operation.ADD)); | ||
297 | + Sets.newHashSet(devices).stream() | ||
298 | + .filter(d -> d.type() == Device.Type.CONTROLLER).forEach(d -> { | ||
299 | + DriverHandler handler = driverService.createHandler(d.id()); | ||
300 | + BridgeConfig bridgeConfig = handler | ||
301 | + .behaviour(BridgeConfig.class); | ||
302 | + Collection<BridgeDescription> bridgeDescriptions = bridgeConfig | ||
303 | + .getBridges(); | ||
304 | + | ||
305 | + Iterator<BridgeDescription> it = bridgeDescriptions | ||
306 | + .iterator(); | ||
307 | + if (it.hasNext()) { | ||
308 | + BridgeDescription sw = it.next(); | ||
309 | + Set<PortNumber> ports = bridgeConfig.getPortNumbers(); | ||
310 | + ports.stream() | ||
311 | + .filter(p -> p.name() | ||
312 | + .equalsIgnoreCase(tunnelName)) | ||
313 | + .forEach(p -> { | ||
314 | + programTunnelOut(sw.deviceId(), | ||
315 | + network.segmentationId(), p, | ||
316 | + host.mac(), appId, | ||
317 | + Objective.Operation.ADD); | ||
318 | + }); | ||
319 | + } | ||
320 | + }); | ||
252 | programLocalIn(deviceId, network.segmentationId(), inPort, host.mac(), | 321 | programLocalIn(deviceId, network.segmentationId(), inPort, host.mac(), |
253 | appId, Objective.Operation.ADD); | 322 | appId, Objective.Operation.ADD); |
254 | - programTunnelIn(deviceId, network.segmentationId(), inPort, host.mac(), | 323 | + tunnelPorts |
255 | - appId, Objective.Operation.ADD); | 324 | + .forEach(tp -> programTunnelIn(deviceId, |
325 | + network.segmentationId(), | ||
326 | + tp.number(), inPort, host.mac(), | ||
327 | + appId, Objective.Operation.ADD)); | ||
328 | + | ||
256 | } | 329 | } |
257 | 330 | ||
258 | @Override | 331 | @Override |
259 | public void onHostVanished(Host host) { | 332 | public void onHostVanished(Host host) { |
260 | SegmentationId segId = binding.remove(host.id()); | 333 | SegmentationId segId = binding.remove(host.id()); |
261 | DeviceId deviceId = host.location().deviceId(); | 334 | DeviceId deviceId = host.location().deviceId(); |
335 | + String currentControllerIp = getControllerIpOfSwitch(deviceId); | ||
336 | + Iterable<Device> devices = deviceService.getAvailableDevices(); | ||
262 | List<Port> allPorts = deviceService.getPorts(deviceId); | 337 | List<Port> allPorts = deviceService.getPorts(deviceId); |
263 | PortNumber inPort = host.location().port(); | 338 | PortNumber inPort = host.location().port(); |
339 | + String vxlanName = "vxlan-" + currentControllerIp; | ||
264 | Set<Port> localPorts = new HashSet<>(); | 340 | Set<Port> localPorts = new HashSet<>(); |
265 | - allPorts.forEach(p -> { | 341 | + Set<Port> tunnelPorts = new HashSet<>(); |
266 | - if (!p.number().name().startsWith(PORT_HEAD)) { | 342 | + List<Port> outports = new ArrayList<>(); |
343 | + Sets.newHashSet(allPorts.iterator()).stream() | ||
344 | + .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { | ||
345 | + if (!p.annotations().value("portName").startsWith(PORT_HEAD)) { | ||
267 | localPorts.add(p); | 346 | localPorts.add(p); |
347 | + } else { | ||
348 | + tunnelPorts.add(p); | ||
268 | } | 349 | } |
350 | + outports.add(p); | ||
269 | }); | 351 | }); |
270 | - programLocalBcastRules(deviceId, segId, inPort, allPorts, appId, | 352 | + |
271 | - Objective.Operation.REMOVE); | 353 | + programLocalBcastRules(deviceId, segId, inPort, |
272 | - programLocalOut(deviceId, segId, inPort, host.mac(), appId, | 354 | + outports, appId, Objective.Operation.REMOVE); |
273 | - Objective.Operation.REMOVE); | 355 | + programLocalOut(deviceId, segId, inPort, host.mac(), |
274 | - programTunnelFloodOut(deviceId, segId, inPort, localPorts, appId, | 356 | + appId, Objective.Operation.REMOVE); |
275 | - Objective.Operation.REMOVE); | 357 | + tunnelPorts |
276 | - programTunnelOut(deviceId, segId, inPort, host.mac(), appId, | 358 | + .forEach(tp -> programTunnelFloodOut(deviceId, |
277 | - Objective.Operation.REMOVE); | 359 | + segId, |
278 | - programLocalIn(deviceId, segId, inPort, host.mac(), appId, | 360 | + tp.number(), localPorts, |
279 | - Objective.Operation.REMOVE); | 361 | + appId, |
280 | - programTunnelIn(deviceId, segId, inPort, host.mac(), appId, | 362 | + Objective.Operation.REMOVE)); |
281 | - Objective.Operation.REMOVE); | 363 | + Sets.newHashSet(devices).stream() |
364 | + .filter(d -> d.type() == Device.Type.CONTROLLER).forEach(d -> { | ||
365 | + DriverHandler handler = driverService.createHandler(d.id()); | ||
366 | + BridgeConfig bridgeConfig = handler | ||
367 | + .behaviour(BridgeConfig.class); | ||
368 | + Collection<BridgeDescription> bridgeDescriptions = bridgeConfig | ||
369 | + .getBridges(); | ||
370 | + | ||
371 | + Iterator<BridgeDescription> it = bridgeDescriptions | ||
372 | + .iterator(); | ||
373 | + if (it.hasNext()) { | ||
374 | + BridgeDescription sw = it.next(); | ||
375 | + Set<PortNumber> ports = bridgeConfig.getPortNumbers(); | ||
376 | + ports.stream() | ||
377 | + .filter(p -> p.name() | ||
378 | + .equalsIgnoreCase(vxlanName)) | ||
379 | + .forEach(p -> { | ||
380 | + programTunnelOut(sw.deviceId(), | ||
381 | + segId, p, | ||
382 | + host.mac(), appId, | ||
383 | + Objective.Operation.REMOVE); | ||
384 | + }); | ||
385 | + } | ||
386 | + }); | ||
387 | + programLocalIn(deviceId, segId, inPort, host.mac(), | ||
388 | + appId, Objective.Operation.REMOVE); | ||
389 | + tunnelPorts | ||
390 | + .forEach(tp -> programTunnelIn(deviceId, | ||
391 | + segId, | ||
392 | + tp.number(), inPort, host.mac(), | ||
393 | + appId, Objective.Operation.REMOVE)); | ||
282 | } | 394 | } |
283 | 395 | ||
284 | private class InnerDeviceListener implements DeviceListener { | 396 | private class InnerDeviceListener implements DeviceListener { |
... | @@ -309,7 +421,7 @@ public class VTNManager implements VTNService { | ... | @@ -309,7 +421,7 @@ public class VTNManager implements VTNService { |
309 | onOvsVanished(device); | 421 | onOvsVanished(device); |
310 | }); | 422 | }); |
311 | } else { | 423 | } else { |
312 | - log.info("do nothing for this device type"); | 424 | + log.info("Do nothing for this device type"); |
313 | } | 425 | } |
314 | } | 426 | } |
315 | 427 | ||
... | @@ -328,8 +440,11 @@ public class VTNManager implements VTNService { | ... | @@ -328,8 +440,11 @@ public class VTNManager implements VTNService { |
328 | backgroundService.execute(() -> { | 440 | backgroundService.execute(() -> { |
329 | onHostVanished(host); | 441 | onHostVanished(host); |
330 | }); | 442 | }); |
331 | - } else { | 443 | + } else if (HostEvent.Type.HOST_UPDATED == event.type()) { |
332 | - log.info("unknow host"); | 444 | + backgroundService.execute(() -> { |
445 | + onHostVanished(host); | ||
446 | + onHostDetected(host); | ||
447 | + }); | ||
333 | } | 448 | } |
334 | } | 449 | } |
335 | 450 | ||
... | @@ -338,16 +453,18 @@ public class VTNManager implements VTNService { | ... | @@ -338,16 +453,18 @@ public class VTNManager implements VTNService { |
338 | // Used to forward the flows to the local VM. | 453 | // Used to forward the flows to the local VM. |
339 | private void programLocalOut(DeviceId dpid, SegmentationId segmentationId, | 454 | private void programLocalOut(DeviceId dpid, SegmentationId segmentationId, |
340 | PortNumber outPort, MacAddress sourceMac, | 455 | PortNumber outPort, MacAddress sourceMac, |
341 | - ApplicationId appid, Objective.Operation type) { | 456 | + ApplicationId appid, |
457 | + Objective.Operation type) { | ||
342 | TrafficSelector selector = DefaultTrafficSelector.builder() | 458 | TrafficSelector selector = DefaultTrafficSelector.builder() |
343 | .matchEthDst(sourceMac).build(); | 459 | .matchEthDst(sourceMac).build(); |
344 | - TrafficTreatment treatment = DefaultTrafficTreatment | 460 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
345 | - .builder() | 461 | + .add(Instructions |
346 | - .add(Instructions.modTunnelId(Long.parseLong(segmentationId | 462 | + .modTunnelId(Long.parseLong(segmentationId.toString()))) |
347 | - .toString()))).setOutput(outPort).build(); | 463 | + .setOutput(outPort).build(); |
348 | ForwardingObjective.Builder objective = DefaultForwardingObjective | 464 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
349 | .builder().withTreatment(treatment).withSelector(selector) | 465 | .builder().withTreatment(treatment).withSelector(selector) |
350 | - .fromApp(appId).withFlag(Flag.SPECIFIC); | 466 | + .fromApp(appId).withFlag(Flag.SPECIFIC) |
467 | + .withPriority(MAC_PRIORITY); | ||
351 | if (type.equals(Objective.Operation.ADD)) { | 468 | if (type.equals(Objective.Operation.ADD)) { |
352 | flowObjectiveService.forward(dpid, objective.add()); | 469 | flowObjectiveService.forward(dpid, objective.add()); |
353 | } else { | 470 | } else { |
... | @@ -356,24 +473,28 @@ public class VTNManager implements VTNService { | ... | @@ -356,24 +473,28 @@ public class VTNManager implements VTNService { |
356 | 473 | ||
357 | } | 474 | } |
358 | 475 | ||
359 | - // Used to forward the flows to the remote VM via VXLAN tunnel. | 476 | + // Used to forward the flows into the VXLAN tunnel. |
360 | private void programTunnelOut(DeviceId dpid, SegmentationId segmentationId, | 477 | private void programTunnelOut(DeviceId dpid, SegmentationId segmentationId, |
361 | - PortNumber outPort, MacAddress sourceMac, | 478 | + PortNumber tunnelOutPort, MacAddress dstMac, |
362 | - ApplicationId appid, Objective.Operation type) { | 479 | + ApplicationId appid, |
480 | + Objective.Operation type) { | ||
363 | TrafficSelector selector = DefaultTrafficSelector.builder() | 481 | TrafficSelector selector = DefaultTrafficSelector.builder() |
364 | - .matchEthDst(sourceMac).build(); | 482 | + .matchEthDst(dstMac).add(Criteria.matchTunnelId(Long |
365 | - TrafficTreatment treatment = DefaultTrafficTreatment | 483 | + .parseLong(segmentationId.toString()))) |
366 | - .builder() | 484 | + .build(); |
367 | - .add(Instructions.modTunnelId(Long.parseLong(segmentationId | 485 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
368 | - .toString()))).setOutput(outPort).build(); | 486 | + |
487 | + .setOutput(tunnelOutPort).build(); | ||
369 | ForwardingObjective.Builder objective = DefaultForwardingObjective | 488 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
370 | .builder().withTreatment(treatment).withSelector(selector) | 489 | .builder().withTreatment(treatment).withSelector(selector) |
371 | - .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC); | 490 | + .fromApp(appId).withFlag(Flag.SPECIFIC) |
491 | + .withPriority(MAC_PRIORITY); | ||
372 | if (type.equals(Objective.Operation.ADD)) { | 492 | if (type.equals(Objective.Operation.ADD)) { |
373 | flowObjectiveService.forward(dpid, objective.add()); | 493 | flowObjectiveService.forward(dpid, objective.add()); |
374 | } else { | 494 | } else { |
375 | flowObjectiveService.forward(dpid, objective.remove()); | 495 | flowObjectiveService.forward(dpid, objective.remove()); |
376 | } | 496 | } |
497 | + | ||
377 | } | 498 | } |
378 | 499 | ||
379 | // Used to forward multicast flows to remote VMs of the same tenant via | 500 | // Used to forward multicast flows to remote VMs of the same tenant via |
... | @@ -384,8 +505,7 @@ public class VTNManager implements VTNService { | ... | @@ -384,8 +505,7 @@ public class VTNManager implements VTNService { |
384 | Iterable<Port> localports, | 505 | Iterable<Port> localports, |
385 | ApplicationId appid, | 506 | ApplicationId appid, |
386 | Objective.Operation type) { | 507 | Objective.Operation type) { |
387 | - TrafficSelector selector = DefaultTrafficSelector | 508 | + TrafficSelector selector = DefaultTrafficSelector.builder() |
388 | - .builder() | ||
389 | .matchInPort(ofPortOut) | 509 | .matchInPort(ofPortOut) |
390 | 510 | ||
391 | .add(Criteria.matchTunnelId(Long.parseLong(segmentationId | 511 | .add(Criteria.matchTunnelId(Long.parseLong(segmentationId |
... | @@ -399,7 +519,7 @@ public class VTNManager implements VTNService { | ... | @@ -399,7 +519,7 @@ public class VTNManager implements VTNService { |
399 | ForwardingObjective.Builder objective = DefaultForwardingObjective | 519 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
400 | .builder().withTreatment(treatment.build()) | 520 | .builder().withTreatment(treatment.build()) |
401 | .withSelector(selector).fromApp(appId).makePermanent() | 521 | .withSelector(selector).fromApp(appId).makePermanent() |
402 | - .withFlag(Flag.SPECIFIC); | 522 | + .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); |
403 | if (type.equals(Objective.Operation.ADD)) { | 523 | if (type.equals(Objective.Operation.ADD)) { |
404 | flowObjectiveService.forward(dpid, objective.add()); | 524 | flowObjectiveService.forward(dpid, objective.add()); |
405 | } else { | 525 | } else { |
... | @@ -415,7 +535,8 @@ public class VTNManager implements VTNService { | ... | @@ -415,7 +535,8 @@ public class VTNManager implements VTNService { |
415 | .build(); | 535 | .build(); |
416 | ForwardingObjective.Builder objective = DefaultForwardingObjective | 536 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
417 | .builder().withTreatment(treatment).withSelector(selector) | 537 | .builder().withTreatment(treatment).withSelector(selector) |
418 | - .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC); | 538 | + .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) |
539 | + .withPriority(DEFAULT_MAC_PRIORITY); | ||
419 | if (type.equals(Objective.Operation.ADD)) { | 540 | if (type.equals(Objective.Operation.ADD)) { |
420 | flowObjectiveService.forward(dpid, objective.add()); | 541 | flowObjectiveService.forward(dpid, objective.add()); |
421 | } else { | 542 | } else { |
... | @@ -429,12 +550,11 @@ public class VTNManager implements VTNService { | ... | @@ -429,12 +550,11 @@ public class VTNManager implements VTNService { |
429 | PortNumber inPort, List<Port> allports, | 550 | PortNumber inPort, List<Port> allports, |
430 | ApplicationId appid, | 551 | ApplicationId appid, |
431 | Objective.Operation type) { | 552 | Objective.Operation type) { |
432 | - TrafficSelector selector = DefaultTrafficSelector | 553 | + TrafficSelector selector = DefaultTrafficSelector.builder() |
433 | - .builder() | 554 | + .matchInPort(inPort).matchEthDst(MacAddress.BROADCAST) |
434 | - .matchInPort(inPort) | 555 | + .add(Criteria.matchTunnelId(Long |
435 | - .matchEthDst(MacAddress.BROADCAST) | 556 | + .parseLong(segmentationId.toString()))) |
436 | - .add(Criteria.matchTunnelId(Long.parseLong(segmentationId | 557 | + .build(); |
437 | - .toString()))).build(); | ||
438 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | 558 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
439 | 559 | ||
440 | for (Port outport : allports) { | 560 | for (Port outport : allports) { |
... | @@ -445,7 +565,7 @@ public class VTNManager implements VTNService { | ... | @@ -445,7 +565,7 @@ public class VTNManager implements VTNService { |
445 | ForwardingObjective.Builder objective = DefaultForwardingObjective | 565 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
446 | .builder().withTreatment(treatment.build()) | 566 | .builder().withTreatment(treatment.build()) |
447 | .withSelector(selector).fromApp(appId).makePermanent() | 567 | .withSelector(selector).fromApp(appId).makePermanent() |
448 | - .withFlag(Flag.SPECIFIC); | 568 | + .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); |
449 | if (type.equals(Objective.Operation.ADD)) { | 569 | if (type.equals(Objective.Operation.ADD)) { |
450 | flowObjectiveService.forward(dpid, objective.add()); | 570 | flowObjectiveService.forward(dpid, objective.add()); |
451 | } else { | 571 | } else { |
... | @@ -465,7 +585,7 @@ public class VTNManager implements VTNService { | ... | @@ -465,7 +585,7 @@ public class VTNManager implements VTNService { |
465 | ForwardingObjective.Builder objective = DefaultForwardingObjective | 585 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
466 | .builder().withTreatment(treatment.build()) | 586 | .builder().withTreatment(treatment.build()) |
467 | .withSelector(selector).fromApp(appId).makePermanent() | 587 | .withSelector(selector).fromApp(appId).makePermanent() |
468 | - .withFlag(Flag.SPECIFIC); | 588 | + .withFlag(Flag.SPECIFIC).withPriority(PORT_PRIORITY); |
469 | if (type.equals(Objective.Operation.ADD)) { | 589 | if (type.equals(Objective.Operation.ADD)) { |
470 | flowObjectiveService.forward(dpid, objective.add()); | 590 | flowObjectiveService.forward(dpid, objective.add()); |
471 | } else { | 591 | } else { |
... | @@ -475,18 +595,19 @@ public class VTNManager implements VTNService { | ... | @@ -475,18 +595,19 @@ public class VTNManager implements VTNService { |
475 | 595 | ||
476 | // Used to forward the flows from the egress tunnel to the VM. | 596 | // Used to forward the flows from the egress tunnel to the VM. |
477 | private void programTunnelIn(DeviceId dpid, SegmentationId segmentationId, | 597 | private void programTunnelIn(DeviceId dpid, SegmentationId segmentationId, |
478 | - PortNumber inPort, MacAddress sourceMac, | 598 | + PortNumber tunnelInPort, PortNumber outPort, |
479 | - ApplicationId appid, Objective.Operation type) { | 599 | + MacAddress sourceMac, ApplicationId appid, |
480 | - TrafficSelector selector = DefaultTrafficSelector | 600 | + Objective.Operation type) { |
481 | - .builder() | 601 | + TrafficSelector selector = DefaultTrafficSelector.builder() |
482 | - .matchInPort(inPort) | 602 | + .matchInPort(tunnelInPort).add(Criteria.matchTunnelId(Long |
483 | - .add(Criteria.matchTunnelId(Long.parseLong(segmentationId | 603 | + .parseLong(segmentationId.toString()))) |
484 | - .toString()))).build(); | 604 | + .build(); |
485 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | 605 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); |
486 | 606 | ||
487 | ForwardingObjective.Builder objective = DefaultForwardingObjective | 607 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
488 | .builder().withTreatment(treatment).withSelector(selector) | 608 | .builder().withTreatment(treatment).withSelector(selector) |
489 | - .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC); | 609 | + .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) |
610 | + .withPriority(PORT_PRIORITY); | ||
490 | if (type.equals(Objective.Operation.ADD)) { | 611 | if (type.equals(Objective.Operation.ADD)) { |
491 | flowObjectiveService.forward(dpid, objective.add()); | 612 | flowObjectiveService.forward(dpid, objective.add()); |
492 | } else { | 613 | } else { |
... | @@ -501,11 +622,20 @@ public class VTNManager implements VTNService { | ... | @@ -501,11 +622,20 @@ public class VTNManager implements VTNService { |
501 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | 622 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); |
502 | ForwardingObjective.Builder objective = DefaultForwardingObjective | 623 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
503 | .builder().withTreatment(treatment).withSelector(selector) | 624 | .builder().withTreatment(treatment).withSelector(selector) |
504 | - .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC); | 625 | + .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) |
626 | + .withPriority(DEFAULT_PORT_PRIORITY); | ||
505 | if (type.equals(Objective.Operation.ADD)) { | 627 | if (type.equals(Objective.Operation.ADD)) { |
506 | flowObjectiveService.forward(dpid, objective.add()); | 628 | flowObjectiveService.forward(dpid, objective.add()); |
507 | } else { | 629 | } else { |
508 | flowObjectiveService.forward(dpid, objective.remove()); | 630 | flowObjectiveService.forward(dpid, objective.remove()); |
509 | } | 631 | } |
510 | } | 632 | } |
633 | + | ||
634 | + // Used to get channelId from the device annotations. | ||
635 | + private String getControllerIpOfSwitch(DeviceId deviceId) { | ||
636 | + Device device = deviceService.getDevice(deviceId); | ||
637 | + String url = device.annotations().value(SWITCH_CHANNEL_ID); | ||
638 | + return url.substring(0, url.lastIndexOf(":")); | ||
639 | + } | ||
640 | + | ||
511 | } | 641 | } | ... | ... |
-
Please register or login to post a comment