Committed by
Gerrit Code Review
ONOS-2724
Fix bug of apply flowrule and remove flowrule Change-Id: Ia7dec83206c3f5e24f912f111bd87dab6eab4610
Showing
9 changed files
with
337 additions
and
192 deletions
... | @@ -33,6 +33,8 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -33,6 +33,8 @@ import org.apache.felix.scr.annotations.Deactivate; |
33 | import org.apache.felix.scr.annotations.Reference; | 33 | import org.apache.felix.scr.annotations.Reference; |
34 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 34 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
35 | import org.apache.felix.scr.annotations.Service; | 35 | import org.apache.felix.scr.annotations.Service; |
36 | +import org.onlab.osgi.DefaultServiceDirectory; | ||
37 | +import org.onlab.osgi.ServiceDirectory; | ||
36 | import org.onlab.packet.IpAddress; | 38 | import org.onlab.packet.IpAddress; |
37 | import org.onlab.packet.MacAddress; | 39 | import org.onlab.packet.MacAddress; |
38 | import org.onlab.util.KryoNamespace; | 40 | import org.onlab.util.KryoNamespace; |
... | @@ -49,12 +51,16 @@ import org.onosproject.net.behaviour.BridgeDescription; | ... | @@ -49,12 +51,16 @@ import org.onosproject.net.behaviour.BridgeDescription; |
49 | import org.onosproject.net.behaviour.BridgeName; | 51 | import org.onosproject.net.behaviour.BridgeName; |
50 | import org.onosproject.net.behaviour.DefaultTunnelDescription; | 52 | import org.onosproject.net.behaviour.DefaultTunnelDescription; |
51 | import org.onosproject.net.behaviour.IpTunnelEndPoint; | 53 | import org.onosproject.net.behaviour.IpTunnelEndPoint; |
54 | +import org.onosproject.net.behaviour.Pipeliner; | ||
55 | +import org.onosproject.net.behaviour.PipelinerContext; | ||
52 | import org.onosproject.net.behaviour.TunnelConfig; | 56 | import org.onosproject.net.behaviour.TunnelConfig; |
53 | import org.onosproject.net.behaviour.TunnelDescription; | 57 | import org.onosproject.net.behaviour.TunnelDescription; |
54 | import org.onosproject.net.behaviour.TunnelEndPoint; | 58 | import org.onosproject.net.behaviour.TunnelEndPoint; |
55 | import org.onosproject.net.device.DeviceEvent; | 59 | import org.onosproject.net.device.DeviceEvent; |
56 | import org.onosproject.net.device.DeviceListener; | 60 | import org.onosproject.net.device.DeviceListener; |
57 | import org.onosproject.net.device.DeviceService; | 61 | import org.onosproject.net.device.DeviceService; |
62 | +import org.onosproject.net.driver.DefaultDriverData; | ||
63 | +import org.onosproject.net.driver.Driver; | ||
58 | import org.onosproject.net.driver.DriverHandler; | 64 | import org.onosproject.net.driver.DriverHandler; |
59 | import org.onosproject.net.driver.DriverService; | 65 | import org.onosproject.net.driver.DriverService; |
60 | import org.onosproject.net.flow.DefaultTrafficSelector; | 66 | import org.onosproject.net.flow.DefaultTrafficSelector; |
... | @@ -66,6 +72,7 @@ import org.onosproject.net.flow.criteria.Criteria; | ... | @@ -66,6 +72,7 @@ import org.onosproject.net.flow.criteria.Criteria; |
66 | import org.onosproject.net.flow.instructions.Instructions; | 72 | import org.onosproject.net.flow.instructions.Instructions; |
67 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; | 73 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
68 | import org.onosproject.net.flowobjective.FlowObjectiveService; | 74 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
75 | +import org.onosproject.net.flowobjective.FlowObjectiveStore; | ||
69 | import org.onosproject.net.flowobjective.ForwardingObjective; | 76 | import org.onosproject.net.flowobjective.ForwardingObjective; |
70 | import org.onosproject.net.flowobjective.ForwardingObjective.Flag; | 77 | import org.onosproject.net.flowobjective.ForwardingObjective.Flag; |
71 | import org.onosproject.net.flowobjective.Objective; | 78 | import org.onosproject.net.flowobjective.Objective; |
... | @@ -115,6 +122,9 @@ public class VTNManager implements VTNService { | ... | @@ -115,6 +122,9 @@ public class VTNManager implements VTNService { |
115 | protected DriverService driverService; | 122 | protected DriverService driverService; |
116 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 123 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
117 | protected FlowObjectiveService flowObjectiveService; | 124 | protected FlowObjectiveService flowObjectiveService; |
125 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
126 | + protected FlowObjectiveStore flowObjectiveStore; | ||
127 | + protected ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); | ||
118 | private EventuallyConsistentMap<HostId, SegmentationId> binding; | 128 | private EventuallyConsistentMap<HostId, SegmentationId> binding; |
119 | private ApplicationId appId; | 129 | private ApplicationId appId; |
120 | private HostListener hostListener = new InnerHostListener(); | 130 | private HostListener hostListener = new InnerHostListener(); |
... | @@ -128,6 +138,7 @@ public class VTNManager implements VTNService { | ... | @@ -128,6 +138,7 @@ public class VTNManager implements VTNService { |
128 | private static final int DEFAULT_PORT_PRIORITY = 0x0000; | 138 | private static final int DEFAULT_PORT_PRIORITY = 0x0000; |
129 | private static final int PORT_PRIORITY = 0xffff; | 139 | private static final int PORT_PRIORITY = 0xffff; |
130 | private static final String SWITCH_CHANNEL_ID = "channelId"; | 140 | private static final String SWITCH_CHANNEL_ID = "channelId"; |
141 | + private static final String DRIVER_NAME = "onosfw"; | ||
131 | 142 | ||
132 | @Activate | 143 | @Activate |
133 | public void activate() { | 144 | public void activate() { |
... | @@ -163,8 +174,7 @@ public class VTNManager implements VTNService { | ... | @@ -163,8 +174,7 @@ public class VTNManager implements VTNService { |
163 | IpAddress ip = IpAddress.valueOf(ipAddress); | 174 | IpAddress ip = IpAddress.valueOf(ipAddress); |
164 | Sets.newHashSet(devices).stream() | 175 | Sets.newHashSet(devices).stream() |
165 | .filter(d -> Device.Type.CONTROLLER == d.type()) | 176 | .filter(d -> Device.Type.CONTROLLER == d.type()) |
166 | - .filter(d -> !device.id().equals(d.id())) | 177 | + .filter(d -> !device.id().equals(d.id())).forEach(d -> { |
167 | - .forEach(d -> { | ||
168 | String ipAddress1 = d.annotations() | 178 | String ipAddress1 = d.annotations() |
169 | .value(CONTROLLER_IP_KEY); | 179 | .value(CONTROLLER_IP_KEY); |
170 | IpAddress ip1 = IpAddress.valueOf(ipAddress1); | 180 | IpAddress ip1 = IpAddress.valueOf(ipAddress1); |
... | @@ -172,6 +182,7 @@ public class VTNManager implements VTNService { | ... | @@ -172,6 +182,7 @@ public class VTNManager implements VTNService { |
172 | DriverHandler handler1 = driverService | 182 | DriverHandler handler1 = driverService |
173 | .createHandler(d.id()); | 183 | .createHandler(d.id()); |
174 | applyTunnelConfig(ip1, ip, handler1); | 184 | applyTunnelConfig(ip1, ip, handler1); |
185 | + | ||
175 | }); | 186 | }); |
176 | } | 187 | } |
177 | 188 | ||
... | @@ -221,30 +232,6 @@ public class VTNManager implements VTNService { | ... | @@ -221,30 +232,6 @@ public class VTNManager implements VTNService { |
221 | public void onOvsDetected(Device device) { | 232 | public void onOvsDetected(Device device) { |
222 | programMacDefaultRules(device.id(), appId, Objective.Operation.ADD); | 233 | programMacDefaultRules(device.id(), appId, Objective.Operation.ADD); |
223 | programPortDefaultRules(device.id(), appId, Objective.Operation.ADD); | 234 | programPortDefaultRules(device.id(), appId, Objective.Operation.ADD); |
224 | - Set<Host> hosts = hostService.getConnectedHosts(device.id()); | ||
225 | - hosts.forEach(h -> { | ||
226 | - String ifaceId = h.annotations().value(IFACEID); | ||
227 | - String currentControllerIp = getControllerIpOfSwitch(device.id()); | ||
228 | - VirtualPortId portId = VirtualPortId.portId(ifaceId); | ||
229 | - VirtualPort port = virtualPortService.getPort(portId); | ||
230 | - TenantNetwork network = tenantNetworkService | ||
231 | - .getNetwork(port.networkId()); | ||
232 | - String vxlanName = "vxlan-" + currentControllerIp; | ||
233 | - | ||
234 | - DriverHandler handler = driverService.createHandler(device.id()); | ||
235 | - BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); | ||
236 | - Collection<BridgeDescription> bridgeDescriptions = bridgeConfig | ||
237 | - .getBridges(); | ||
238 | - Iterator<BridgeDescription> it = bridgeDescriptions.iterator(); | ||
239 | - if (it.hasNext()) { | ||
240 | - BridgeDescription sw = it.next(); | ||
241 | - Set<PortNumber> ports = bridgeConfig.getPortNumbers(); | ||
242 | - ports.stream().filter(p -> p.name().equalsIgnoreCase(vxlanName)) | ||
243 | - .forEach(p -> programTunnelOut(sw.deviceId(), network.segmentationId(), p, | ||
244 | - h.mac(), appId, Objective.Operation.ADD)); | ||
245 | - } | ||
246 | - | ||
247 | - }); | ||
248 | } | 235 | } |
249 | 236 | ||
250 | @Override | 237 | @Override |
... | @@ -267,27 +254,23 @@ public class VTNManager implements VTNService { | ... | @@ -267,27 +254,23 @@ public class VTNManager implements VTNService { |
267 | binding.put(host.id(), network.segmentationId()); | 254 | binding.put(host.id(), network.segmentationId()); |
268 | List<Port> allPorts = deviceService.getPorts(deviceId); | 255 | List<Port> allPorts = deviceService.getPorts(deviceId); |
269 | PortNumber inPort = host.location().port(); | 256 | PortNumber inPort = host.location().port(); |
270 | - Set<Port> localPorts = new HashSet<>(); | 257 | + List<PortNumber> localVmPorts = getLocalPorts(deviceId, ifaceId); |
271 | - Set<Port> tunnelPorts = new HashSet<>(); | 258 | + List<PortNumber> localTunnelPorts = new ArrayList<>(); |
272 | - List<Port> outports = new ArrayList<>(); | ||
273 | Sets.newHashSet(allPorts.iterator()).stream() | 259 | Sets.newHashSet(allPorts.iterator()).stream() |
274 | .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { | 260 | .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { |
275 | - if (!p.annotations().value("portName").startsWith(PORT_HEAD)) { | 261 | + if (p.annotations().value("portName").startsWith(PORT_HEAD)) { |
276 | - localPorts.add(p); | 262 | + localTunnelPorts.add(p.number()); |
277 | - } else { | ||
278 | - tunnelPorts.add(p); | ||
279 | } | 263 | } |
280 | - outports.add(p); | ||
281 | }); | 264 | }); |
282 | 265 | ||
283 | - programLocalBcastRules(deviceId, network.segmentationId(), inPort, | 266 | + localVmPorts.forEach(lp -> programLocalBcastRules(deviceId, network.segmentationId(), lp, localVmPorts, |
284 | - outports, appId, Objective.Operation.ADD); | 267 | + localTunnelPorts, appId, Objective.Operation.ADD)); |
285 | programLocalOut(deviceId, network.segmentationId(), inPort, host.mac(), | 268 | programLocalOut(deviceId, network.segmentationId(), inPort, host.mac(), |
286 | appId, Objective.Operation.ADD); | 269 | appId, Objective.Operation.ADD); |
287 | - tunnelPorts | 270 | + localTunnelPorts |
288 | .forEach(tp -> programTunnelFloodOut(deviceId, | 271 | .forEach(tp -> programTunnelFloodOut(deviceId, |
289 | network.segmentationId(), | 272 | network.segmentationId(), |
290 | - tp.number(), localPorts, | 273 | + tp, localVmPorts, |
291 | appId, | 274 | appId, |
292 | Objective.Operation.ADD)); | 275 | Objective.Operation.ADD)); |
293 | Sets.newHashSet(devices).stream() | 276 | Sets.newHashSet(devices).stream() |
... | @@ -306,52 +289,54 @@ public class VTNManager implements VTNService { | ... | @@ -306,52 +289,54 @@ public class VTNManager implements VTNService { |
306 | ports.stream() | 289 | ports.stream() |
307 | .filter(p -> p.name() | 290 | .filter(p -> p.name() |
308 | .equalsIgnoreCase(tunnelName)) | 291 | .equalsIgnoreCase(tunnelName)) |
309 | - .forEach(p -> programTunnelOut(sw.deviceId(), | 292 | + .forEach(p -> { |
310 | - network.segmentationId(), p, | 293 | + programTunnelOut(sw.deviceId(), |
311 | - host.mac(), appId, | 294 | + network.segmentationId(), p, |
312 | - Objective.Operation.ADD)); | 295 | + host.mac(), appId, |
296 | + Objective.Operation.ADD); | ||
297 | + }); | ||
313 | } | 298 | } |
314 | }); | 299 | }); |
315 | programLocalIn(deviceId, network.segmentationId(), inPort, host.mac(), | 300 | programLocalIn(deviceId, network.segmentationId(), inPort, host.mac(), |
316 | appId, Objective.Operation.ADD); | 301 | appId, Objective.Operation.ADD); |
317 | - tunnelPorts | 302 | + localTunnelPorts |
318 | .forEach(tp -> programTunnelIn(deviceId, | 303 | .forEach(tp -> programTunnelIn(deviceId, |
319 | network.segmentationId(), | 304 | network.segmentationId(), |
320 | - tp.number(), inPort, host.mac(), | 305 | + tp, inPort, host.mac(), |
321 | appId, Objective.Operation.ADD)); | 306 | appId, Objective.Operation.ADD)); |
322 | 307 | ||
323 | } | 308 | } |
324 | 309 | ||
325 | @Override | 310 | @Override |
326 | public void onHostVanished(Host host) { | 311 | public void onHostVanished(Host host) { |
312 | + String ifaceId = host.annotations().value(IFACEID); | ||
327 | SegmentationId segId = binding.remove(host.id()); | 313 | SegmentationId segId = binding.remove(host.id()); |
328 | DeviceId deviceId = host.location().deviceId(); | 314 | DeviceId deviceId = host.location().deviceId(); |
329 | String currentControllerIp = getControllerIpOfSwitch(deviceId); | 315 | String currentControllerIp = getControllerIpOfSwitch(deviceId); |
330 | Iterable<Device> devices = deviceService.getAvailableDevices(); | 316 | Iterable<Device> devices = deviceService.getAvailableDevices(); |
317 | + | ||
318 | + String tunnelName = "vxlan-" + currentControllerIp; | ||
331 | List<Port> allPorts = deviceService.getPorts(deviceId); | 319 | List<Port> allPorts = deviceService.getPorts(deviceId); |
332 | PortNumber inPort = host.location().port(); | 320 | PortNumber inPort = host.location().port(); |
333 | - String vxlanName = "vxlan-" + currentControllerIp; | 321 | + |
334 | - Set<Port> localPorts = new HashSet<>(); | 322 | + List<PortNumber> localTunnelPorts = new ArrayList<>(); |
335 | - Set<Port> tunnelPorts = new HashSet<>(); | ||
336 | - List<Port> outports = new ArrayList<>(); | ||
337 | Sets.newHashSet(allPorts.iterator()).stream() | 323 | Sets.newHashSet(allPorts.iterator()).stream() |
338 | .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { | 324 | .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { |
339 | - if (!p.annotations().value("portName").startsWith(PORT_HEAD)) { | 325 | + if (p.annotations().value("portName").startsWith(PORT_HEAD)) { |
340 | - localPorts.add(p); | 326 | + localTunnelPorts.add(p.number()); |
341 | - } else { | ||
342 | - tunnelPorts.add(p); | ||
343 | } | 327 | } |
344 | - outports.add(p); | ||
345 | }); | 328 | }); |
346 | 329 | ||
347 | - programLocalBcastRules(deviceId, segId, inPort, | 330 | + List<PortNumber> localVmPorts = getLocalPorts(deviceId, ifaceId); |
348 | - outports, appId, Objective.Operation.REMOVE); | 331 | + localVmPorts.add(inPort); |
332 | + localVmPorts.forEach(lp -> programLocalBcastRules(deviceId, segId, lp, localVmPorts, | ||
333 | + localTunnelPorts, appId, Objective.Operation.REMOVE)); | ||
349 | programLocalOut(deviceId, segId, inPort, host.mac(), | 334 | programLocalOut(deviceId, segId, inPort, host.mac(), |
350 | appId, Objective.Operation.REMOVE); | 335 | appId, Objective.Operation.REMOVE); |
351 | - tunnelPorts | 336 | + localTunnelPorts |
352 | .forEach(tp -> programTunnelFloodOut(deviceId, | 337 | .forEach(tp -> programTunnelFloodOut(deviceId, |
353 | segId, | 338 | segId, |
354 | - tp.number(), localPorts, | 339 | + tp, localVmPorts, |
355 | appId, | 340 | appId, |
356 | Objective.Operation.REMOVE)); | 341 | Objective.Operation.REMOVE)); |
357 | Sets.newHashSet(devices).stream() | 342 | Sets.newHashSet(devices).stream() |
... | @@ -369,19 +354,21 @@ public class VTNManager implements VTNService { | ... | @@ -369,19 +354,21 @@ public class VTNManager implements VTNService { |
369 | Set<PortNumber> ports = bridgeConfig.getPortNumbers(); | 354 | Set<PortNumber> ports = bridgeConfig.getPortNumbers(); |
370 | ports.stream() | 355 | ports.stream() |
371 | .filter(p -> p.name() | 356 | .filter(p -> p.name() |
372 | - .equalsIgnoreCase(vxlanName)) | 357 | + .equalsIgnoreCase(tunnelName)) |
373 | - .forEach(p -> programTunnelOut(sw.deviceId(), | 358 | + .forEach(p -> { |
374 | - segId, p, | 359 | + programTunnelOut(sw.deviceId(), |
375 | - host.mac(), appId, | 360 | + segId, p, |
376 | - Objective.Operation.REMOVE)); | 361 | + host.mac(), appId, |
362 | + Objective.Operation.REMOVE); | ||
363 | + }); | ||
377 | } | 364 | } |
378 | }); | 365 | }); |
379 | programLocalIn(deviceId, segId, inPort, host.mac(), | 366 | programLocalIn(deviceId, segId, inPort, host.mac(), |
380 | appId, Objective.Operation.REMOVE); | 367 | appId, Objective.Operation.REMOVE); |
381 | - tunnelPorts | 368 | + localTunnelPorts |
382 | .forEach(tp -> programTunnelIn(deviceId, | 369 | .forEach(tp -> programTunnelIn(deviceId, |
383 | segId, | 370 | segId, |
384 | - tp.number(), inPort, host.mac(), | 371 | + tp, inPort, host.mac(), |
385 | appId, Objective.Operation.REMOVE)); | 372 | appId, Objective.Operation.REMOVE)); |
386 | } | 373 | } |
387 | 374 | ||
... | @@ -448,19 +435,18 @@ public class VTNManager implements VTNService { | ... | @@ -448,19 +435,18 @@ public class VTNManager implements VTNService { |
448 | ApplicationId appid, | 435 | ApplicationId appid, |
449 | Objective.Operation type) { | 436 | Objective.Operation type) { |
450 | TrafficSelector selector = DefaultTrafficSelector.builder() | 437 | TrafficSelector selector = DefaultTrafficSelector.builder() |
438 | + .matchTunnelId(Long.parseLong(segmentationId.toString())) | ||
451 | .matchEthDst(sourceMac).build(); | 439 | .matchEthDst(sourceMac).build(); |
452 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() | 440 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
453 | - .add(Instructions | ||
454 | - .modTunnelId(Long.parseLong(segmentationId.toString()))) | ||
455 | .setOutput(outPort).build(); | 441 | .setOutput(outPort).build(); |
456 | ForwardingObjective.Builder objective = DefaultForwardingObjective | 442 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
457 | .builder().withTreatment(treatment).withSelector(selector) | 443 | .builder().withTreatment(treatment).withSelector(selector) |
458 | .fromApp(appId).withFlag(Flag.SPECIFIC) | 444 | .fromApp(appId).withFlag(Flag.SPECIFIC) |
459 | .withPriority(MAC_PRIORITY); | 445 | .withPriority(MAC_PRIORITY); |
460 | if (type.equals(Objective.Operation.ADD)) { | 446 | if (type.equals(Objective.Operation.ADD)) { |
461 | - flowObjectiveService.forward(dpid, objective.add()); | 447 | + flowServiceForward(dpid, objective.add()); |
462 | } else { | 448 | } else { |
463 | - flowObjectiveService.forward(dpid, objective.remove()); | 449 | + flowServiceForward(dpid, objective.remove()); |
464 | } | 450 | } |
465 | 451 | ||
466 | } | 452 | } |
... | @@ -482,19 +468,19 @@ public class VTNManager implements VTNService { | ... | @@ -482,19 +468,19 @@ public class VTNManager implements VTNService { |
482 | .fromApp(appId).withFlag(Flag.SPECIFIC) | 468 | .fromApp(appId).withFlag(Flag.SPECIFIC) |
483 | .withPriority(MAC_PRIORITY); | 469 | .withPriority(MAC_PRIORITY); |
484 | if (type.equals(Objective.Operation.ADD)) { | 470 | if (type.equals(Objective.Operation.ADD)) { |
485 | - flowObjectiveService.forward(dpid, objective.add()); | 471 | + flowServiceForward(dpid, objective.add()); |
486 | } else { | 472 | } else { |
487 | - flowObjectiveService.forward(dpid, objective.remove()); | 473 | + flowServiceForward(dpid, objective.remove()); |
488 | } | 474 | } |
489 | 475 | ||
490 | } | 476 | } |
491 | 477 | ||
492 | // Used to forward multicast flows to remote VMs of the same tenant via | 478 | // Used to forward multicast flows to remote VMs of the same tenant via |
493 | // VXLAN tunnel. | 479 | // VXLAN tunnel. |
494 | - private void programTunnelFloodOut(DeviceId dpid, | 480 | + private void programTunnelFloodOut(DeviceId deviceId, |
495 | SegmentationId segmentationId, | 481 | SegmentationId segmentationId, |
496 | PortNumber ofPortOut, | 482 | PortNumber ofPortOut, |
497 | - Iterable<Port> localports, | 483 | + List<PortNumber> localVmPorts, |
498 | ApplicationId appid, | 484 | ApplicationId appid, |
499 | Objective.Operation type) { | 485 | Objective.Operation type) { |
500 | TrafficSelector selector = DefaultTrafficSelector.builder() | 486 | TrafficSelector selector = DefaultTrafficSelector.builder() |
... | @@ -504,8 +490,9 @@ public class VTNManager implements VTNService { | ... | @@ -504,8 +490,9 @@ public class VTNManager implements VTNService { |
504 | .toString()))).matchEthDst(MacAddress.BROADCAST) | 490 | .toString()))).matchEthDst(MacAddress.BROADCAST) |
505 | .build(); | 491 | .build(); |
506 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | 492 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
507 | - for (Port outport : localports) { | 493 | + |
508 | - treatment.setOutput(outport.number()); | 494 | + for (PortNumber outPort : localVmPorts) { |
495 | + treatment.setOutput(outPort); | ||
509 | } | 496 | } |
510 | 497 | ||
511 | ForwardingObjective.Builder objective = DefaultForwardingObjective | 498 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
... | @@ -513,9 +500,9 @@ public class VTNManager implements VTNService { | ... | @@ -513,9 +500,9 @@ public class VTNManager implements VTNService { |
513 | .withSelector(selector).fromApp(appId).makePermanent() | 500 | .withSelector(selector).fromApp(appId).makePermanent() |
514 | .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); | 501 | .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); |
515 | if (type.equals(Objective.Operation.ADD)) { | 502 | if (type.equals(Objective.Operation.ADD)) { |
516 | - flowObjectiveService.forward(dpid, objective.add()); | 503 | + flowServiceForward(deviceId, objective.add()); |
517 | } else { | 504 | } else { |
518 | - flowObjectiveService.forward(dpid, objective.remove()); | 505 | + flowServiceForward(deviceId, objective.remove()); |
519 | } | 506 | } |
520 | } | 507 | } |
521 | 508 | ||
... | @@ -530,16 +517,18 @@ public class VTNManager implements VTNService { | ... | @@ -530,16 +517,18 @@ public class VTNManager implements VTNService { |
530 | .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) | 517 | .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) |
531 | .withPriority(DEFAULT_MAC_PRIORITY); | 518 | .withPriority(DEFAULT_MAC_PRIORITY); |
532 | if (type.equals(Objective.Operation.ADD)) { | 519 | if (type.equals(Objective.Operation.ADD)) { |
533 | - flowObjectiveService.forward(dpid, objective.add()); | 520 | + flowServiceForward(dpid, objective.add()); |
534 | } else { | 521 | } else { |
535 | - flowObjectiveService.forward(dpid, objective.remove()); | 522 | + flowServiceForward(dpid, objective.remove()); |
536 | } | 523 | } |
537 | } | 524 | } |
538 | 525 | ||
539 | // Used to forward the flows to the local VMs with the same tenant. | 526 | // Used to forward the flows to the local VMs with the same tenant. |
540 | - private void programLocalBcastRules(DeviceId dpid, | 527 | + private void programLocalBcastRules(DeviceId deviceId, |
541 | SegmentationId segmentationId, | 528 | SegmentationId segmentationId, |
542 | - PortNumber inPort, List<Port> allports, | 529 | + PortNumber inPort, |
530 | + List<PortNumber> localVmPorts, | ||
531 | + List<PortNumber> localTunnelPorts, | ||
543 | ApplicationId appid, | 532 | ApplicationId appid, |
544 | Objective.Operation type) { | 533 | Objective.Operation type) { |
545 | TrafficSelector selector = DefaultTrafficSelector.builder() | 534 | TrafficSelector selector = DefaultTrafficSelector.builder() |
... | @@ -548,20 +537,22 @@ public class VTNManager implements VTNService { | ... | @@ -548,20 +537,22 @@ public class VTNManager implements VTNService { |
548 | .parseLong(segmentationId.toString()))) | 537 | .parseLong(segmentationId.toString()))) |
549 | .build(); | 538 | .build(); |
550 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | 539 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
551 | - | 540 | + for (PortNumber outPort : localVmPorts) { |
552 | - for (Port outport : allports) { | 541 | + if (inPort != outPort) { |
553 | - if (inPort != outport.number()) { | 542 | + treatment.setOutput(outPort); |
554 | - treatment.setOutput(outport.number()); | ||
555 | } | 543 | } |
556 | } | 544 | } |
545 | + for (PortNumber outport : localTunnelPorts) { | ||
546 | + treatment.setOutput(outport); | ||
547 | + } | ||
557 | ForwardingObjective.Builder objective = DefaultForwardingObjective | 548 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
558 | .builder().withTreatment(treatment.build()) | 549 | .builder().withTreatment(treatment.build()) |
559 | .withSelector(selector).fromApp(appId).makePermanent() | 550 | .withSelector(selector).fromApp(appId).makePermanent() |
560 | .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); | 551 | .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); |
561 | if (type.equals(Objective.Operation.ADD)) { | 552 | if (type.equals(Objective.Operation.ADD)) { |
562 | - flowObjectiveService.forward(dpid, objective.add()); | 553 | + flowServiceForward(deviceId, objective.add()); |
563 | } else { | 554 | } else { |
564 | - flowObjectiveService.forward(dpid, objective.remove()); | 555 | + flowServiceForward(deviceId, objective.remove()); |
565 | } | 556 | } |
566 | } | 557 | } |
567 | 558 | ||
... | @@ -579,9 +570,9 @@ public class VTNManager implements VTNService { | ... | @@ -579,9 +570,9 @@ public class VTNManager implements VTNService { |
579 | .withSelector(selector).fromApp(appId).makePermanent() | 570 | .withSelector(selector).fromApp(appId).makePermanent() |
580 | .withFlag(Flag.SPECIFIC).withPriority(PORT_PRIORITY); | 571 | .withFlag(Flag.SPECIFIC).withPriority(PORT_PRIORITY); |
581 | if (type.equals(Objective.Operation.ADD)) { | 572 | if (type.equals(Objective.Operation.ADD)) { |
582 | - flowObjectiveService.forward(dpid, objective.add()); | 573 | + flowServiceForward(dpid, objective.add()); |
583 | } else { | 574 | } else { |
584 | - flowObjectiveService.forward(dpid, objective.remove()); | 575 | + flowServiceForward(dpid, objective.remove()); |
585 | } | 576 | } |
586 | } | 577 | } |
587 | 578 | ||
... | @@ -601,9 +592,9 @@ public class VTNManager implements VTNService { | ... | @@ -601,9 +592,9 @@ public class VTNManager implements VTNService { |
601 | .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) | 592 | .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) |
602 | .withPriority(PORT_PRIORITY); | 593 | .withPriority(PORT_PRIORITY); |
603 | if (type.equals(Objective.Operation.ADD)) { | 594 | if (type.equals(Objective.Operation.ADD)) { |
604 | - flowObjectiveService.forward(dpid, objective.add()); | 595 | + flowServiceForward(dpid, objective.add()); |
605 | } else { | 596 | } else { |
606 | - flowObjectiveService.forward(dpid, objective.remove()); | 597 | + flowServiceForward(dpid, objective.remove()); |
607 | } | 598 | } |
608 | } | 599 | } |
609 | 600 | ||
... | @@ -617,9 +608,9 @@ public class VTNManager implements VTNService { | ... | @@ -617,9 +608,9 @@ public class VTNManager implements VTNService { |
617 | .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) | 608 | .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) |
618 | .withPriority(DEFAULT_PORT_PRIORITY); | 609 | .withPriority(DEFAULT_PORT_PRIORITY); |
619 | if (type.equals(Objective.Operation.ADD)) { | 610 | if (type.equals(Objective.Operation.ADD)) { |
620 | - flowObjectiveService.forward(dpid, objective.add()); | 611 | + flowServiceForward(dpid, objective.add()); |
621 | } else { | 612 | } else { |
622 | - flowObjectiveService.forward(dpid, objective.remove()); | 613 | + flowServiceForward(dpid, objective.remove()); |
623 | } | 614 | } |
624 | } | 615 | } |
625 | 616 | ||
... | @@ -630,4 +621,61 @@ public class VTNManager implements VTNService { | ... | @@ -630,4 +621,61 @@ public class VTNManager implements VTNService { |
630 | return url.substring(0, url.lastIndexOf(":")); | 621 | return url.substring(0, url.lastIndexOf(":")); |
631 | } | 622 | } |
632 | 623 | ||
624 | + private Iterable<String> getIfaceIds(String ifaceId) { | ||
625 | + VirtualPortId portId = VirtualPortId.portId(ifaceId); | ||
626 | + VirtualPort port = virtualPortService.getPort(portId); | ||
627 | + TenantNetwork network = tenantNetworkService | ||
628 | + .getNetwork(port.networkId()); | ||
629 | + Collection<String> ifaceIds = new HashSet<String>(); | ||
630 | + Collection<VirtualPort> ports = virtualPortService | ||
631 | + .getPorts(network.id()); | ||
632 | + Sets.newHashSet(ports).stream() | ||
633 | + .forEach(p -> ifaceIds.add(p.portId().portId())); | ||
634 | + return ifaceIds; | ||
635 | + } | ||
636 | + | ||
637 | + private List<PortNumber> getLocalPorts(DeviceId deviceId, String ifaceId) { | ||
638 | + DriverHandler handler = driverService | ||
639 | + .createHandler(getController(deviceId)); | ||
640 | + BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); | ||
641 | + Iterable<String> ifaceIds = getIfaceIds(ifaceId); | ||
642 | + return bridgeConfig.getLocalPorts(ifaceIds); | ||
643 | + } | ||
644 | + | ||
645 | + private DeviceId getController(DeviceId deviceId) { | ||
646 | + Iterable<Device> devices = deviceService.getAvailableDevices(); | ||
647 | + for (Device device : devices) { | ||
648 | + if (device.type() == Device.Type.CONTROLLER && device.id() | ||
649 | + .toString().contains(getControllerIpOfSwitch(deviceId))) { | ||
650 | + return device.id(); | ||
651 | + } | ||
652 | + } | ||
653 | + log.info("Can not find controller for device : {}", deviceId); | ||
654 | + return null; | ||
655 | + } | ||
656 | + | ||
657 | + //Used to apply flowRule | ||
658 | + private void flowServiceForward(DeviceId deviceId, ForwardingObjective forwardingObjective) { | ||
659 | + Driver driver = driverService.getDriver(DRIVER_NAME); | ||
660 | + Pipeliner pipeLiner = driver.createBehaviour(new DefaultDriverData(driver, deviceId), Pipeliner.class); | ||
661 | + if (pipeLiner != null) { | ||
662 | + final PipelinerContext context = new InnerPipelineContext(); | ||
663 | + pipeLiner.init(deviceId, context); | ||
664 | + pipeLiner.forward(forwardingObjective); | ||
665 | + } | ||
666 | + } | ||
667 | + | ||
668 | + // Processing context for initializing pipeline driver behaviours. | ||
669 | + private class InnerPipelineContext implements PipelinerContext { | ||
670 | + @Override | ||
671 | + public ServiceDirectory directory() { | ||
672 | + return serviceDirectory; | ||
673 | + } | ||
674 | + | ||
675 | + @Override | ||
676 | + public FlowObjectiveStore store() { | ||
677 | + return flowObjectiveStore; | ||
678 | + } | ||
679 | + } | ||
680 | + | ||
633 | } | 681 | } | ... | ... |
1 | -/* | 1 | +/* |
2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2015 Open Networking Laboratory |
3 | - * | 3 | + * |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | - * you may not use this file except in compliance with 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 | 6 | + * You may obtain a copy of the License at |
7 | - * | 7 | + * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
9 | - * | 9 | + * |
10 | - * Unless required by applicable law or agreed to in writing, software | 10 | + * Unless required by applicable law or agreed to in writing, software |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | - * See the License for the specific language governing permissions and | 13 | + * See the License for the specific language governing permissions and |
14 | - * limitations under the License. | 14 | + * limitations under the License. |
15 | - */ | 15 | + */ |
16 | -package org.onosproject.net.behaviour; | 16 | +package org.onosproject.net.behaviour; |
17 | - | 17 | + |
18 | -import java.util.Collection; | 18 | +import java.util.Collection; |
19 | -import java.util.Set; | 19 | +import java.util.List; |
20 | - | 20 | +import java.util.Set; |
21 | -import org.onosproject.net.PortNumber; | 21 | + |
22 | -import org.onosproject.net.device.PortDescription; | 22 | +import org.onosproject.net.PortNumber; |
23 | -import org.onosproject.net.driver.HandlerBehaviour; | 23 | +import org.onosproject.net.device.PortDescription; |
24 | - | 24 | +import org.onosproject.net.driver.HandlerBehaviour; |
25 | -/** | 25 | + |
26 | - * Behaviour for handling various drivers for bridge configurations. | 26 | +/** |
27 | - */ | 27 | + * Behaviour for handling various drivers for bridge configurations. |
28 | -public interface BridgeConfig extends HandlerBehaviour { | 28 | + */ |
29 | - | 29 | +public interface BridgeConfig extends HandlerBehaviour { |
30 | - /** | 30 | + |
31 | - * Add a bridge. | 31 | + /** |
32 | - * | 32 | + * Add a bridge. |
33 | - * @param bridgeName bridge name | 33 | + * |
34 | - */ | 34 | + * @param bridgeName bridge name |
35 | - void addBridge(BridgeName bridgeName); | 35 | + */ |
36 | - | 36 | + void addBridge(BridgeName bridgeName); |
37 | - /** | 37 | + |
38 | - * Remove a bridge. | 38 | + /** |
39 | - * | 39 | + * Remove a bridge. |
40 | - * @param bridgeName bridge name | 40 | + * |
41 | - */ | 41 | + * @param bridgeName bridge name |
42 | - void deleteBridge(BridgeName bridgeName); | 42 | + */ |
43 | - | 43 | + void deleteBridge(BridgeName bridgeName); |
44 | - /** | 44 | + |
45 | - * Remove a bridge. | 45 | + /** |
46 | - * | 46 | + * Remove a bridge. |
47 | - * @return bridge collection | 47 | + * |
48 | - */ | 48 | + * @return bridge collection |
49 | - Collection<BridgeDescription> getBridges(); | 49 | + */ |
50 | - | 50 | + Collection<BridgeDescription> getBridges(); |
51 | - /** | 51 | + |
52 | - * Add a logical/virtual port. | 52 | + /** |
53 | - * | 53 | + * Add a logical/virtual port. |
54 | - * @param port port number | 54 | + * |
55 | - */ | 55 | + * @param port port number |
56 | - void addPort(PortDescription port); | 56 | + */ |
57 | - | 57 | + void addPort(PortDescription port); |
58 | - /** | 58 | + |
59 | - * Delete a logical/virtual port. | 59 | + /** |
60 | - * | 60 | + * Delete a logical/virtual port. |
61 | - * @param port port number | 61 | + * |
62 | - */ | 62 | + * @param port port number |
63 | - void deletePort(PortDescription port); | 63 | + */ |
64 | - | 64 | + void deletePort(PortDescription port); |
65 | - /** | 65 | + |
66 | - * Delete a logical/virtual port. | 66 | + /** |
67 | - * | 67 | + * Delete a logical/virtual port. |
68 | - * @return collection of port | 68 | + * |
69 | - */ | 69 | + * @return collection of port |
70 | - Collection<PortDescription> getPorts(); | 70 | + */ |
71 | - | 71 | + Collection<PortDescription> getPorts(); |
72 | - /** | 72 | + |
73 | - * Get a collection of port. | 73 | + /** |
74 | - * | 74 | + * Get a collection of port. |
75 | - * @return portNumbers set of PortNumber | 75 | + * |
76 | - */ | 76 | + * @return portNumbers set of PortNumber |
77 | - Set<PortNumber> getPortNumbers(); | 77 | + */ |
78 | -} | 78 | + Set<PortNumber> getPortNumbers(); |
79 | + | ||
80 | + /** | ||
81 | + * Get logical/virtual ports by ifaceIds. | ||
82 | + * | ||
83 | + * @param ifaceIds the ifaceid that needed | ||
84 | + * @return list of PortNumber | ||
85 | + */ | ||
86 | + List<PortNumber> getLocalPorts(Iterable<String> ifaceIds); | ||
87 | +} | ... | ... |
... | @@ -153,8 +153,8 @@ public class DefaultDriver implements Driver { | ... | @@ -153,8 +153,8 @@ public class DefaultDriver implements Driver { |
153 | // Creates an instance of behaviour primed with the specified driver data. | 153 | // Creates an instance of behaviour primed with the specified driver data. |
154 | private <T extends Behaviour> T createBehaviour(DriverData data, DriverHandler handler, | 154 | private <T extends Behaviour> T createBehaviour(DriverData data, DriverHandler handler, |
155 | Class<T> behaviourClass) { | 155 | Class<T> behaviourClass) { |
156 | - checkArgument(handler != null || !HandlerBehaviour.class.isAssignableFrom(behaviourClass), | 156 | + //checkArgument(handler != null || !HandlerBehaviour.class.isAssignableFrom(behaviourClass), |
157 | - "{} is applicable only to handler context", behaviourClass.getName()); | 157 | + // "{} is applicable only to handler context", behaviourClass.getName()); |
158 | 158 | ||
159 | // Locate the implementation of the requested behaviour. | 159 | // Locate the implementation of the requested behaviour. |
160 | Class<? extends Behaviour> implementation = behaviours.get(behaviourClass); | 160 | Class<? extends Behaviour> implementation = behaviours.get(behaviourClass); | ... | ... |
... | @@ -15,7 +15,9 @@ | ... | @@ -15,7 +15,9 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.driver.ovsdb; | 16 | package org.onosproject.driver.ovsdb; |
17 | 17 | ||
18 | +import java.util.ArrayList; | ||
18 | import java.util.Collection; | 19 | import java.util.Collection; |
20 | +import java.util.List; | ||
19 | import java.util.Set; | 21 | import java.util.Set; |
20 | import java.util.stream.Collectors; | 22 | import java.util.stream.Collectors; |
21 | 23 | ||
... | @@ -146,4 +148,18 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour | ... | @@ -146,4 +148,18 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour |
146 | ) | 148 | ) |
147 | .collect(Collectors.toSet()); | 149 | .collect(Collectors.toSet()); |
148 | } | 150 | } |
151 | + | ||
152 | + @Override | ||
153 | + public List<PortNumber> getLocalPorts(Iterable<String> ifaceIds) { | ||
154 | + List<PortNumber> ports = new ArrayList<>(); | ||
155 | + DriverHandler handler = handler(); | ||
156 | + OvsdbClientService clientService = getOvsdbClientService(handler); | ||
157 | + Set<OvsdbPort> ovsdbSet = clientService.getLocalPorts(ifaceIds); | ||
158 | + ovsdbSet.forEach(o -> { | ||
159 | + PortNumber port = PortNumber.portNumber(o.portNumber().value(), | ||
160 | + o.portName().value()); | ||
161 | + ports.add(port); | ||
162 | + }); | ||
163 | + return ports; | ||
164 | + } | ||
149 | } | 165 | } | ... | ... |
... | @@ -26,7 +26,6 @@ import org.onosproject.net.DeviceId; | ... | @@ -26,7 +26,6 @@ import org.onosproject.net.DeviceId; |
26 | import org.onosproject.net.behaviour.Pipeliner; | 26 | import org.onosproject.net.behaviour.Pipeliner; |
27 | import org.onosproject.net.behaviour.PipelinerContext; | 27 | import org.onosproject.net.behaviour.PipelinerContext; |
28 | import org.onosproject.net.device.DeviceService; | 28 | import org.onosproject.net.device.DeviceService; |
29 | -import org.onosproject.net.driver.AbstractHandlerBehaviour; | ||
30 | import org.onosproject.net.flow.DefaultFlowRule; | 29 | import org.onosproject.net.flow.DefaultFlowRule; |
31 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 30 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
32 | import org.onosproject.net.flow.FlowRule; | 31 | import org.onosproject.net.flow.FlowRule; |
... | @@ -48,9 +47,10 @@ import org.slf4j.Logger; | ... | @@ -48,9 +47,10 @@ import org.slf4j.Logger; |
48 | /** | 47 | /** |
49 | * Driver for standard OpenVSwitch. | 48 | * Driver for standard OpenVSwitch. |
50 | */ | 49 | */ |
51 | -public class OpenVSwitchPipeline extends AbstractHandlerBehaviour | 50 | +public class OpenVSwitchPipeline extends DefaultSingleTablePipeline |
52 | implements Pipeliner { | 51 | implements Pipeliner { |
53 | 52 | ||
53 | + private static final String VTN_APP_ID = "org.onosproject.app.vtn"; | ||
54 | private final Logger log = getLogger(getClass()); | 54 | private final Logger log = getLogger(getClass()); |
55 | private CoreService coreService; | 55 | private CoreService coreService; |
56 | private ServiceDirectory serviceDirectory; | 56 | private ServiceDirectory serviceDirectory; |
... | @@ -58,14 +58,13 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour | ... | @@ -58,14 +58,13 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour |
58 | protected DeviceId deviceId; | 58 | protected DeviceId deviceId; |
59 | protected FlowRuleService flowRuleService; | 59 | protected FlowRuleService flowRuleService; |
60 | protected DeviceService deviceService; | 60 | protected DeviceService deviceService; |
61 | - private static final int MAC_TABLE_PRIORITY = 0xffff; | ||
62 | - private static final int PORT_TABLE_PRIORITY = 0xffff; | ||
63 | private static final int TIME_OUT = 0; | 61 | private static final int TIME_OUT = 0; |
64 | private static final int MAC_TABLE = 40; | 62 | private static final int MAC_TABLE = 40; |
65 | private static final int PORT_TABLE = 0; | 63 | private static final int PORT_TABLE = 0; |
66 | 64 | ||
67 | @Override | 65 | @Override |
68 | public void init(DeviceId deviceId, PipelinerContext context) { | 66 | public void init(DeviceId deviceId, PipelinerContext context) { |
67 | + super.init(deviceId, context); | ||
69 | this.serviceDirectory = context.directory(); | 68 | this.serviceDirectory = context.directory(); |
70 | this.deviceId = deviceId; | 69 | this.deviceId = deviceId; |
71 | 70 | ||
... | @@ -79,11 +78,15 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour | ... | @@ -79,11 +78,15 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour |
79 | 78 | ||
80 | @Override | 79 | @Override |
81 | public void filter(FilteringObjective filteringObjective) { | 80 | public void filter(FilteringObjective filteringObjective) { |
82 | - // TODO Auto-generated method stub | 81 | + super.filter(filteringObjective); |
83 | } | 82 | } |
84 | 83 | ||
85 | @Override | 84 | @Override |
86 | public void forward(ForwardingObjective fwd) { | 85 | public void forward(ForwardingObjective fwd) { |
86 | + if (!VTN_APP_ID.equals(fwd.appId().name())) { | ||
87 | + super.forward(fwd); | ||
88 | + return; | ||
89 | + } | ||
87 | Collection<FlowRule> rules; | 90 | Collection<FlowRule> rules; |
88 | FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations | 91 | FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations |
89 | .builder(); | 92 | .builder(); |
... | @@ -119,8 +122,7 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour | ... | @@ -119,8 +122,7 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour |
119 | 122 | ||
120 | @Override | 123 | @Override |
121 | public void next(NextObjective nextObjective) { | 124 | public void next(NextObjective nextObjective) { |
122 | - // TODO Auto-generated method stub | 125 | + super.next(nextObjective); |
123 | - | ||
124 | } | 126 | } |
125 | 127 | ||
126 | private Collection<FlowRule> processForward(ForwardingObjective fwd) { | 128 | private Collection<FlowRule> processForward(ForwardingObjective fwd) { |
... | @@ -148,18 +150,16 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour | ... | @@ -148,18 +150,16 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour |
148 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() | 150 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
149 | .fromApp(fwd.appId()).withPriority(fwd.priority()) | 151 | .fromApp(fwd.appId()).withPriority(fwd.priority()) |
150 | .forDevice(deviceId).withSelector(selector) | 152 | .forDevice(deviceId).withSelector(selector) |
151 | - .makeTemporary(TIME_OUT); | 153 | + .withTreatment(tb).makeTemporary(TIME_OUT); |
152 | - | 154 | + ruleBuilder.withPriority(fwd.priority()); |
153 | if (fwd.permanent()) { | 155 | if (fwd.permanent()) { |
154 | ruleBuilder.makePermanent(); | 156 | ruleBuilder.makePermanent(); |
155 | } | 157 | } |
156 | if (selector.getCriterion(Type.ETH_DST) != null | 158 | if (selector.getCriterion(Type.ETH_DST) != null |
157 | || tb.allInstructions().contains(Instructions.createDrop())) { | 159 | || tb.allInstructions().contains(Instructions.createDrop())) { |
158 | - ruleBuilder.withPriority(MAC_TABLE_PRIORITY); | ||
159 | ruleBuilder.withTreatment(tb); | 160 | ruleBuilder.withTreatment(tb); |
160 | ruleBuilder.forTable(MAC_TABLE); | 161 | ruleBuilder.forTable(MAC_TABLE); |
161 | } else { | 162 | } else { |
162 | - ruleBuilder.withPriority(PORT_TABLE_PRIORITY); | ||
163 | TrafficTreatment.Builder newTraffic = DefaultTrafficTreatment.builder(); | 163 | TrafficTreatment.Builder newTraffic = DefaultTrafficTreatment.builder(); |
164 | tb.allInstructions().forEach(t -> newTraffic.add(t)); | 164 | tb.allInstructions().forEach(t -> newTraffic.add(t)); |
165 | newTraffic.transition(MAC_TABLE); | 165 | newTraffic.transition(MAC_TABLE); | ... | ... |
... | @@ -115,5 +115,10 @@ | ... | @@ -115,5 +115,10 @@ |
115 | <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" | 115 | <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" |
116 | impl="org.onosproject.driver.handshaker.CalientFiberSwitchHandshaker"/> | 116 | impl="org.onosproject.driver.handshaker.CalientFiberSwitchHandshaker"/> |
117 | </driver> | 117 | </driver> |
118 | + <driver name="onosfw" extends="default" | ||
119 | + manufacturer="" hwVersion="" swVersion=""> | ||
120 | + <behaviour api="org.onosproject.net.behaviour.Pipeliner" | ||
121 | + impl="org.onosproject.driver.pipeline.OpenVSwitchPipeline"/> | ||
122 | + </driver> | ||
118 | </drivers> | 123 | </drivers> |
119 | 124 | ... | ... |
... | @@ -212,7 +212,7 @@ public interface OvsdbClientService extends OvsdbRPC { | ... | @@ -212,7 +212,7 @@ public interface OvsdbClientService extends OvsdbRPC { |
212 | void removeRow(String dbName, String tableName, String uuid); | 212 | void removeRow(String dbName, String tableName, String uuid); |
213 | 213 | ||
214 | /** | 214 | /** |
215 | - * Update the local ovsdb store. | 215 | + * Updates the local ovsdb store. |
216 | * | 216 | * |
217 | * @param dbName database name | 217 | * @param dbName database name |
218 | * @param tableName table name | 218 | * @param tableName table name |
... | @@ -221,4 +221,11 @@ public interface OvsdbClientService extends OvsdbRPC { | ... | @@ -221,4 +221,11 @@ public interface OvsdbClientService extends OvsdbRPC { |
221 | */ | 221 | */ |
222 | void updateOvsdbStore(String dbName, String tableName, String uuid, Row row); | 222 | void updateOvsdbStore(String dbName, String tableName, String uuid, Row row); |
223 | 223 | ||
224 | + /** | ||
225 | + * Gets ovsdb local ports. | ||
226 | + * | ||
227 | + * @param ifaceids the ifaceid that needed | ||
228 | + * @return ovsdb ports | ||
229 | + */ | ||
230 | + Set<OvsdbPort> getLocalPorts(Iterable<String> ifaceids); | ||
224 | } | 231 | } | ... | ... |
... | @@ -46,6 +46,7 @@ import org.onosproject.ovsdb.rfc.message.OperationResult; | ... | @@ -46,6 +46,7 @@ import org.onosproject.ovsdb.rfc.message.OperationResult; |
46 | import org.onosproject.ovsdb.rfc.message.TableUpdates; | 46 | import org.onosproject.ovsdb.rfc.message.TableUpdates; |
47 | import org.onosproject.ovsdb.rfc.notation.Condition; | 47 | import org.onosproject.ovsdb.rfc.notation.Condition; |
48 | import org.onosproject.ovsdb.rfc.notation.Mutation; | 48 | import org.onosproject.ovsdb.rfc.notation.Mutation; |
49 | +import org.onosproject.ovsdb.rfc.notation.OvsdbMap; | ||
49 | import org.onosproject.ovsdb.rfc.notation.OvsdbSet; | 50 | import org.onosproject.ovsdb.rfc.notation.OvsdbSet; |
50 | import org.onosproject.ovsdb.rfc.notation.Row; | 51 | import org.onosproject.ovsdb.rfc.notation.Row; |
51 | import org.onosproject.ovsdb.rfc.notation.UUID; | 52 | import org.onosproject.ovsdb.rfc.notation.UUID; |
... | @@ -74,6 +75,7 @@ import com.fasterxml.jackson.databind.JsonNode; | ... | @@ -74,6 +75,7 @@ import com.fasterxml.jackson.databind.JsonNode; |
74 | import com.google.common.base.Function; | 75 | import com.google.common.base.Function; |
75 | import com.google.common.collect.Lists; | 76 | import com.google.common.collect.Lists; |
76 | import com.google.common.collect.Maps; | 77 | import com.google.common.collect.Maps; |
78 | +import com.google.common.collect.Sets; | ||
77 | import com.google.common.util.concurrent.Futures; | 79 | import com.google.common.util.concurrent.Futures; |
78 | import com.google.common.util.concurrent.ListenableFuture; | 80 | import com.google.common.util.concurrent.ListenableFuture; |
79 | import com.google.common.util.concurrent.SettableFuture; | 81 | import com.google.common.util.concurrent.SettableFuture; |
... | @@ -1125,4 +1127,62 @@ public class DefaultOvsdbClient | ... | @@ -1125,4 +1127,62 @@ public class DefaultOvsdbClient |
1125 | Iterator<Integer> it = ofPorts.iterator(); | 1127 | Iterator<Integer> it = ofPorts.iterator(); |
1126 | return Long.parseLong(it.next().toString()); | 1128 | return Long.parseLong(it.next().toString()); |
1127 | } | 1129 | } |
1130 | + | ||
1131 | + @Override | ||
1132 | + public Set<OvsdbPort> getLocalPorts(Iterable<String> ifaceids) { | ||
1133 | + Set<OvsdbPort> ovsdbPorts = new HashSet<OvsdbPort>(); | ||
1134 | + OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME); | ||
1135 | + if (tableStore == null) { | ||
1136 | + return null; | ||
1137 | + } | ||
1138 | + OvsdbRowStore rowStore = tableStore.getRows(OvsdbConstant.INTERFACE); | ||
1139 | + if (rowStore == null) { | ||
1140 | + return null; | ||
1141 | + } | ||
1142 | + ConcurrentMap<String, Row> rows = rowStore.getRowStore(); | ||
1143 | + for (String uuid : rows.keySet()) { | ||
1144 | + Row row = getRow(OvsdbConstant.DATABASENAME, | ||
1145 | + OvsdbConstant.INTERFACE, uuid); | ||
1146 | + DatabaseSchema dbSchema = getDatabaseSchema(OvsdbConstant.DATABASENAME); | ||
1147 | + Interface intf = (Interface) TableGenerator | ||
1148 | + .getTable(dbSchema, row, OvsdbTable.INTERFACE); | ||
1149 | + if (intf == null || getIfaceid(intf) == null) { | ||
1150 | + continue; | ||
1151 | + } | ||
1152 | + String portName = intf.getName(); | ||
1153 | + Set<String> ifaceidSet = Sets.newHashSet(ifaceids); | ||
1154 | + if (portName.startsWith("vxlan") | ||
1155 | + || !ifaceidSet.contains(getIfaceid(intf))) { | ||
1156 | + continue; | ||
1157 | + } | ||
1158 | + long ofPort = getOfPort(intf); | ||
1159 | + if ((ofPort < 0) || (portName == null)) { | ||
1160 | + continue; | ||
1161 | + } | ||
1162 | + | ||
1163 | + OvsdbPort ovsdbPort = new OvsdbPort(new OvsdbPortNumber(ofPort), | ||
1164 | + new OvsdbPortName(portName)); | ||
1165 | + if (ovsdbPort != null) { | ||
1166 | + ovsdbPorts.add(ovsdbPort); | ||
1167 | + } | ||
1168 | + } | ||
1169 | + return ovsdbPorts; | ||
1170 | + } | ||
1171 | + | ||
1172 | + private String getIfaceid(Interface intf) { | ||
1173 | + OvsdbMap ovsdbMap = (OvsdbMap) intf.getExternalIdsColumn().data(); | ||
1174 | + @SuppressWarnings("unchecked") | ||
1175 | + Map<String, String> externalIds = ovsdbMap.map(); | ||
1176 | + if (externalIds.isEmpty()) { | ||
1177 | + log.warn("The external_ids is null"); | ||
1178 | + return null; | ||
1179 | + } | ||
1180 | + String ifaceid = externalIds | ||
1181 | + .get(OvsdbConstant.EXTERNAL_ID_INTERFACE_ID); | ||
1182 | + if (ifaceid == null) { | ||
1183 | + log.warn("The ifaceid is null"); | ||
1184 | + return null; | ||
1185 | + } | ||
1186 | + return ifaceid; | ||
1187 | + } | ||
1128 | } | 1188 | } | ... | ... |
... | @@ -220,7 +220,6 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -220,7 +220,6 @@ public class OvsdbControllerImpl implements OvsdbController { |
220 | log.debug("Begin to process table updates uuid: {}, databaseName: {}, tableName: {}", | 220 | log.debug("Begin to process table updates uuid: {}, databaseName: {}, tableName: {}", |
221 | uuid.value(), dbName, tableName); | 221 | uuid.value(), dbName, tableName); |
222 | 222 | ||
223 | - Row oldRow = update.getOld(uuid); | ||
224 | Row newRow = update.getNew(uuid); | 223 | Row newRow = update.getNew(uuid); |
225 | if (newRow != null) { | 224 | if (newRow != null) { |
226 | clientService.updateOvsdbStore(dbName, tableName, | 225 | clientService.updateOvsdbStore(dbName, tableName, |
... | @@ -228,18 +227,19 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -228,18 +227,19 @@ public class OvsdbControllerImpl implements OvsdbController { |
228 | 227 | ||
229 | if (OvsdbConstant.INTERFACE.equals(tableName)) { | 228 | if (OvsdbConstant.INTERFACE.equals(tableName)) { |
230 | dispatchInterfaceEvent(clientService, | 229 | dispatchInterfaceEvent(clientService, |
231 | - newRow, null, | 230 | + newRow, |
232 | OvsdbEvent.Type.PORT_ADDED, | 231 | OvsdbEvent.Type.PORT_ADDED, |
233 | dbSchema); | 232 | dbSchema); |
234 | } | 233 | } |
235 | } else if (update.getOld(uuid) != null) { | 234 | } else if (update.getOld(uuid) != null) { |
236 | - clientService.removeRow(dbName, tableName, uuid.value()); | 235 | + if (OvsdbConstant.INTERFACE.equals(tableName)) { |
237 | - if (OvsdbConstant.PORT.equals(tableName)) { | 236 | + Row row = clientService.getRow(OvsdbConstant.DATABASENAME, tableName, uuid.value()); |
238 | - dispatchInterfaceEvent(clientService, null, | 237 | + dispatchInterfaceEvent(clientService, |
239 | - oldRow, | 238 | + row, |
240 | OvsdbEvent.Type.PORT_REMOVED, | 239 | OvsdbEvent.Type.PORT_REMOVED, |
241 | dbSchema); | 240 | dbSchema); |
242 | } | 241 | } |
242 | + clientService.removeRow(dbName, tableName, uuid.value()); | ||
243 | } | 243 | } |
244 | } | 244 | } |
245 | } | 245 | } |
... | @@ -255,13 +255,13 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -255,13 +255,13 @@ public class OvsdbControllerImpl implements OvsdbController { |
255 | * @param dbSchema ovsdb database schema | 255 | * @param dbSchema ovsdb database schema |
256 | */ | 256 | */ |
257 | private void dispatchInterfaceEvent(OvsdbClientService clientService, | 257 | private void dispatchInterfaceEvent(OvsdbClientService clientService, |
258 | - Row newRow, Row oldRow, | 258 | + Row row, |
259 | Type eventType, | 259 | Type eventType, |
260 | DatabaseSchema dbSchema) { | 260 | DatabaseSchema dbSchema) { |
261 | 261 | ||
262 | long dpid = getDataPathid(clientService, dbSchema); | 262 | long dpid = getDataPathid(clientService, dbSchema); |
263 | Interface intf = (Interface) TableGenerator | 263 | Interface intf = (Interface) TableGenerator |
264 | - .getTable(dbSchema, newRow, OvsdbTable.INTERFACE); | 264 | + .getTable(dbSchema, row, OvsdbTable.INTERFACE); |
265 | if (intf == null) { | 265 | if (intf == null) { |
266 | return; | 266 | return; |
267 | } | 267 | } | ... | ... |
-
Please register or login to post a comment