Committed by
Gerrit Code Review
[ONOS-4205] support east-west routing in openstackRouting
- Supports east-west routing traffic - Fixes javadocs Change-Id: I23d9b9497cc2be667fbc9554812c7f5b49c35364
Showing
3 changed files
with
151 additions
and
24 deletions
... | @@ -20,71 +20,78 @@ import org.onosproject.openstackinterface.OpenstackRouter; | ... | @@ -20,71 +20,78 @@ import org.onosproject.openstackinterface.OpenstackRouter; |
20 | import org.onosproject.openstackinterface.OpenstackRouterInterface; | 20 | import org.onosproject.openstackinterface.OpenstackRouterInterface; |
21 | 21 | ||
22 | /** | 22 | /** |
23 | - * The Interface of Openstack Routing. | 23 | + * Supports L3 management REST API for openstack. |
24 | */ | 24 | */ |
25 | public interface OpenstackRoutingService { | 25 | public interface OpenstackRoutingService { |
26 | 26 | ||
27 | /** | 27 | /** |
28 | - * Stores the Floating IP information created by Openstack. | 28 | + * Stores the floating IP information created by openstack. |
29 | * | 29 | * |
30 | - * @param openstackFloatingIP Floating IP information | 30 | + * @param openstackFloatingIp Floating IP information |
31 | */ | 31 | */ |
32 | - void createFloatingIP(OpenstackFloatingIP openstackFloatingIP); | 32 | + void createFloatingIP(OpenstackFloatingIP openstackFloatingIp); |
33 | 33 | ||
34 | /** | 34 | /** |
35 | - * Updates flow rules corresponding to the Floating IP information updated by Openstack. | 35 | + * Updates flow rules corresponding to the floating IP information updated by openstack. |
36 | * | 36 | * |
37 | - * @param openstackFloatingIP Floating IP information | 37 | + * @param openstackFloatingIp Floating IP information |
38 | */ | 38 | */ |
39 | - void updateFloatingIP(OpenstackFloatingIP openstackFloatingIP); | 39 | + void updateFloatingIP(OpenstackFloatingIP openstackFloatingIp); |
40 | 40 | ||
41 | /** | 41 | /** |
42 | - * Removes flow rules corresponding to Floating IP information removed by Openstack. | 42 | + * Removes flow rules corresponding to floating IP information removed by openstack. |
43 | * | 43 | * |
44 | * @param id Deleted Floating IP`s ID | 44 | * @param id Deleted Floating IP`s ID |
45 | */ | 45 | */ |
46 | void deleteFloatingIP(String id); | 46 | void deleteFloatingIP(String id); |
47 | 47 | ||
48 | /** | 48 | /** |
49 | - * Stores the router information created by Openstack. | 49 | + * Stores the router information created by openstack. |
50 | * | 50 | * |
51 | - * @param openstackRouter Floating IP information | 51 | + * @param openstackRouter Router information |
52 | */ | 52 | */ |
53 | void createRouter(OpenstackRouter openstackRouter); | 53 | void createRouter(OpenstackRouter openstackRouter); |
54 | 54 | ||
55 | /** | 55 | /** |
56 | - * Updates flow rules corresponding to the router information updated by Openstack. | 56 | + * Updates flow rules corresponding to the router information updated by openstack. |
57 | * | 57 | * |
58 | * @param openstackRouter Router information | 58 | * @param openstackRouter Router information |
59 | */ | 59 | */ |
60 | void updateRouter(OpenstackRouter openstackRouter); | 60 | void updateRouter(OpenstackRouter openstackRouter); |
61 | 61 | ||
62 | /** | 62 | /** |
63 | - * Removes flow rules corresponding to the router information removed by Openstack. | 63 | + * Removes flow rules corresponding to the router information removed by openstack. |
64 | * | 64 | * |
65 | * @param id Deleted router`s ID | 65 | * @param id Deleted router`s ID |
66 | */ | 66 | */ |
67 | void deleteRouter(String id); | 67 | void deleteRouter(String id); |
68 | 68 | ||
69 | /** | 69 | /** |
70 | - * Updates flow rules corresponding to the router information updated by Openstack. | 70 | + * Updates flow rules corresponding to the router information updated by openstack. |
71 | * | 71 | * |
72 | - * @param openstackRouterInterface Router information | 72 | + * @param openstackRouterInterface Router interface information |
73 | */ | 73 | */ |
74 | void updateRouterInterface(OpenstackRouterInterface openstackRouterInterface); | 74 | void updateRouterInterface(OpenstackRouterInterface openstackRouterInterface); |
75 | 75 | ||
76 | /** | 76 | /** |
77 | - * Removes flow rules corresponding to the router information removed by Openstack. | 77 | + * Removes flow rules corresponding to the router information removed by openstack. |
78 | * | 78 | * |
79 | - * @param openstackRouterInterface Router information | 79 | + * @param openstackRouterInterface Router interface information |
80 | */ | 80 | */ |
81 | void removeRouterInterface(OpenstackRouterInterface openstackRouterInterface); | 81 | void removeRouterInterface(OpenstackRouterInterface openstackRouterInterface); |
82 | 82 | ||
83 | /** | 83 | /** |
84 | - * Checks floatingIp deassociation when corresponding deleted vm. | 84 | + * Checks floatingIp disassociation when corresponding deleted vm. |
85 | * | 85 | * |
86 | * @param portId Deleted vm | 86 | * @param portId Deleted vm |
87 | * @param portInfo stored information about deleted vm | 87 | * @param portInfo stored information about deleted vm |
88 | */ | 88 | */ |
89 | void checkDisassociatedFloatingIp(String portId, OpenstackPortInfo portInfo); | 89 | void checkDisassociatedFloatingIp(String portId, OpenstackPortInfo portInfo); |
90 | + | ||
91 | + /** | ||
92 | + * Returns network id for routerInterface. | ||
93 | + * | ||
94 | + * @param portId routerInterface`s port id | ||
95 | + */ | ||
96 | + String networkIdForRouterInterface(String portId); | ||
90 | } | 97 | } | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -54,12 +54,15 @@ import org.onosproject.openstackinterface.OpenstackSubnet; | ... | @@ -54,12 +54,15 @@ import org.onosproject.openstackinterface.OpenstackSubnet; |
54 | import org.onosproject.openstackinterface.OpenstackFloatingIP; | 54 | import org.onosproject.openstackinterface.OpenstackFloatingIP; |
55 | import org.onosproject.openstacknetworking.OpenstackNetworkingConfig; | 55 | import org.onosproject.openstacknetworking.OpenstackNetworkingConfig; |
56 | import org.onosproject.openstacknetworking.OpenstackPortInfo; | 56 | import org.onosproject.openstacknetworking.OpenstackPortInfo; |
57 | +import org.onosproject.openstacknetworking.OpenstackRoutingService; | ||
57 | import org.slf4j.Logger; | 58 | import org.slf4j.Logger; |
58 | import org.slf4j.LoggerFactory; | 59 | import org.slf4j.LoggerFactory; |
59 | 60 | ||
61 | +import java.util.List; | ||
60 | import java.util.stream.StreamSupport; | 62 | import java.util.stream.StreamSupport; |
61 | 63 | ||
62 | import static com.google.common.base.Preconditions.checkNotNull; | 64 | import static com.google.common.base.Preconditions.checkNotNull; |
65 | +import static org.onlab.osgi.DefaultServiceDirectory.getService; | ||
63 | 66 | ||
64 | /** | 67 | /** |
65 | * Populates Routing Flow Rules. | 68 | * Populates Routing Flow Rules. |
... | @@ -99,11 +102,11 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -99,11 +102,11 @@ public class OpenstackRoutingRulePopulator { |
99 | * The constructor of openstackRoutingRulePopulator. | 102 | * The constructor of openstackRoutingRulePopulator. |
100 | * | 103 | * |
101 | * @param appId Caller`s appId | 104 | * @param appId Caller`s appId |
102 | - * @param openstackService OpenstackNetworkingService | 105 | + * @param openstackService Opestack REST request handler |
103 | * @param flowObjectiveService FlowObjectiveService | 106 | * @param flowObjectiveService FlowObjectiveService |
104 | * @param deviceService DeviceService | 107 | * @param deviceService DeviceService |
105 | * @param driverService DriverService | 108 | * @param driverService DriverService |
106 | - * @param config OpenstackRoutingConfig | 109 | + * @param config Configuration for openstack environment |
107 | */ | 110 | */ |
108 | public OpenstackRoutingRulePopulator(ApplicationId appId, OpenstackInterfaceService openstackService, | 111 | public OpenstackRoutingRulePopulator(ApplicationId appId, OpenstackInterfaceService openstackService, |
109 | FlowObjectiveService flowObjectiveService, DeviceService deviceService, | 112 | FlowObjectiveService flowObjectiveService, DeviceService deviceService, |
... | @@ -187,6 +190,7 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -187,6 +190,7 @@ public class OpenstackRoutingRulePopulator { |
187 | .add(); | 190 | .add(); |
188 | 191 | ||
189 | flowObjectiveService.forward(inboundPacket.receivedFrom().deviceId(), fo); | 192 | flowObjectiveService.forward(inboundPacket.receivedFrom().deviceId(), fo); |
193 | + | ||
190 | } | 194 | } |
191 | 195 | ||
192 | private Port getPortOfExternalInterface() { | 196 | private Port getPortOfExternalInterface() { |
... | @@ -252,8 +256,8 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -252,8 +256,8 @@ public class OpenstackRoutingRulePopulator { |
252 | String openstackPortName = PORTNAME_PREFIX_VM + openstackPort.id().substring(0, 11); | 256 | String openstackPortName = PORTNAME_PREFIX_VM + openstackPort.id().substring(0, 11); |
253 | Device device = StreamSupport.stream(deviceService.getDevices().spliterator(), false) | 257 | Device device = StreamSupport.stream(deviceService.getDevices().spliterator(), false) |
254 | .filter(d -> findPortinDevice(d, openstackPortName)) | 258 | .filter(d -> findPortinDevice(d, openstackPortName)) |
255 | - .findAny() | 259 | + .iterator() |
256 | - .orElse(null); | 260 | + .next(); |
257 | checkNotNull(device, DEVICENOTNULL); | 261 | checkNotNull(device, DEVICENOTNULL); |
258 | return device; | 262 | return device; |
259 | } | 263 | } |
... | @@ -268,7 +272,7 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -268,7 +272,7 @@ public class OpenstackRoutingRulePopulator { |
268 | } | 272 | } |
269 | 273 | ||
270 | /** | 274 | /** |
271 | - * Builds NiciraExtension for tagging remoteIp of vxlan. | 275 | + * Builds Nicira extension for tagging remoteIp of vxlan. |
272 | * | 276 | * |
273 | * @param id Device Id of vxlan source device | 277 | * @param id Device Id of vxlan source device |
274 | * @param hostIp Remote Ip of vxlan destination device | 278 | * @param hostIp Remote Ip of vxlan destination device |
... | @@ -401,8 +405,8 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -401,8 +405,8 @@ public class OpenstackRoutingRulePopulator { |
401 | StreamSupport.stream(deviceService.getDevices().spliterator(), false) | 405 | StreamSupport.stream(deviceService.getDevices().spliterator(), false) |
402 | .forEach(d -> { | 406 | .forEach(d -> { |
403 | ForwardingObjective.Flag flag = checkGatewayNode(d.id()) ? | 407 | ForwardingObjective.Flag flag = checkGatewayNode(d.id()) ? |
404 | - ForwardingObjective.Flag.VERSATILE : ForwardingObjective.Flag.SPECIFIC; | 408 | + ForwardingObjective.Flag.VERSATILE : |
405 | - | 409 | + ForwardingObjective.Flag.SPECIFIC; |
406 | removeRule(d.id(), sBuilder, flag, ROUTING_RULE_PRIORITY); | 410 | removeRule(d.id(), sBuilder, flag, ROUTING_RULE_PRIORITY); |
407 | }); | 411 | }); |
408 | 412 | ||
... | @@ -514,4 +518,120 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -514,4 +518,120 @@ public class OpenstackRoutingRulePopulator { |
514 | removeRule(getGatewayNode().id(), sIncomingBuilder, ForwardingObjective.Flag.VERSATILE, FLOATING_RULE_PRIORITY); | 518 | removeRule(getGatewayNode().id(), sIncomingBuilder, ForwardingObjective.Flag.VERSATILE, FLOATING_RULE_PRIORITY); |
515 | } | 519 | } |
516 | 520 | ||
521 | + /** | ||
522 | + * Populates L3 rules for east to west traffic. | ||
523 | + * | ||
524 | + * @param p target VM | ||
525 | + * @param targetList target openstackRouterInterfaces | ||
526 | + */ | ||
527 | + public void populateL3Rules(OpenstackPort p, List<OpenstackRouterInterface> targetList) { | ||
528 | + Device device = getDevicefromOpenstackPort(p); | ||
529 | + Port port = getPortFromOpenstackPort(device, p); | ||
530 | + Ip4Address vmIp = (Ip4Address) p.fixedIps().values().iterator().next(); | ||
531 | + | ||
532 | + if (port == null) { | ||
533 | + return; | ||
534 | + } | ||
535 | + | ||
536 | + targetList.forEach(routerInterface -> { | ||
537 | + OpenstackPort openstackPort = openstackService.port(routerInterface.portId()); | ||
538 | + long vni = getVni(openstackPort.networkId()); | ||
539 | + | ||
540 | + if (vmIp == null) { | ||
541 | + return; | ||
542 | + } | ||
543 | + | ||
544 | + populateL3RulestoSameNode(vmIp, p, port, device, vni); | ||
545 | + | ||
546 | + deviceService.getAvailableDevices().forEach(d -> { | ||
547 | + if (!d.equals(device) && !d.equals(getGatewayNode())) { | ||
548 | + populateL3RulestoDifferentNode(vmIp, vni, d.id(), getHostIpfromOpenstackPort(p)); | ||
549 | + } | ||
550 | + }); | ||
551 | + | ||
552 | + }); | ||
553 | + } | ||
554 | + | ||
555 | + private void populateL3RulestoDifferentNode(Ip4Address vmIp, long vni, DeviceId deviceId, Ip4Address hostIp) { | ||
556 | + TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); | ||
557 | + TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); | ||
558 | + | ||
559 | + sBuilder.matchEthType(Ethernet.TYPE_IPV4) | ||
560 | + .matchTunnelId(vni) | ||
561 | + .matchIPDst(vmIp.toIpPrefix()); | ||
562 | + tBuilder.extension(buildNiciraExtenstion(deviceId, hostIp), deviceId) | ||
563 | + .setOutput(getTunnelPort(deviceId)); | ||
564 | + | ||
565 | + ForwardingObjective fo = DefaultForwardingObjective.builder() | ||
566 | + .withSelector(sBuilder.build()) | ||
567 | + .withTreatment(tBuilder.build()) | ||
568 | + .withPriority(ROUTING_RULE_PRIORITY) | ||
569 | + .withFlag(ForwardingObjective.Flag.SPECIFIC) | ||
570 | + .fromApp(appId) | ||
571 | + .add(); | ||
572 | + | ||
573 | + flowObjectiveService.forward(deviceId, fo); | ||
574 | + } | ||
575 | + | ||
576 | + private void populateL3RulestoSameNode(Ip4Address vmIp, OpenstackPort p, Port port, Device device, long vni) { | ||
577 | + TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); | ||
578 | + TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); | ||
579 | + | ||
580 | + sBuilder.matchEthType(Ethernet.TYPE_IPV4) | ||
581 | + .matchIPDst(vmIp.toIpPrefix()) | ||
582 | + .matchTunnelId(vni); | ||
583 | + | ||
584 | + tBuilder.setEthDst(p.macAddress()) | ||
585 | + .setOutput(port.number()); | ||
586 | + | ||
587 | + ForwardingObjective fo = DefaultForwardingObjective.builder() | ||
588 | + .withSelector(sBuilder.build()) | ||
589 | + .withTreatment(tBuilder.build()) | ||
590 | + .withPriority(ROUTING_RULE_PRIORITY) | ||
591 | + .withFlag(ForwardingObjective.Flag.SPECIFIC) | ||
592 | + .fromApp(appId) | ||
593 | + .add(); | ||
594 | + | ||
595 | + flowObjectiveService.forward(device.id(), fo); | ||
596 | + } | ||
597 | + | ||
598 | + private Port getPortFromOpenstackPort(Device device, OpenstackPort p) { | ||
599 | + String openstackPortName = PORTNAME_PREFIX_VM + p.id().substring(0, 11); | ||
600 | + return deviceService.getPorts(device.id()) | ||
601 | + .stream() | ||
602 | + .filter(pt -> pt.annotations().value(PORTNAME).equals(openstackPortName)) | ||
603 | + .findAny() | ||
604 | + .orElse(null); | ||
605 | + } | ||
606 | + | ||
607 | + /** | ||
608 | + * Removes L3 rules for routerInterface events. | ||
609 | + * | ||
610 | + * @param vmIp Corresponding Vm ip | ||
611 | + * @param routerInterfaces Corresponding routerInterfaces | ||
612 | + */ | ||
613 | + public void removeL3Rules(Ip4Address vmIp, List<OpenstackRouterInterface> routerInterfaces) { | ||
614 | + if (vmIp == null) { | ||
615 | + return; | ||
616 | + } | ||
617 | + | ||
618 | + OpenstackRoutingService routingService = getService(OpenstackRoutingService.class); | ||
619 | + | ||
620 | + deviceService.getAvailableDevices().forEach(d -> { | ||
621 | + if (!d.equals(getGatewayNode())) { | ||
622 | + routerInterfaces.forEach(routerInterface -> { | ||
623 | + String networkId = routingService.networkIdForRouterInterface(routerInterface.portId()); | ||
624 | + long vni = getVni(networkId); | ||
625 | + | ||
626 | + TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); | ||
627 | + | ||
628 | + sBuilder.matchEthType(Ethernet.TYPE_IPV4) | ||
629 | + .matchIPDst(vmIp.toIpPrefix()) | ||
630 | + .matchTunnelId(vni); | ||
631 | + | ||
632 | + removeRule(d.id(), sBuilder, ForwardingObjective.Flag.SPECIFIC, ROUTING_RULE_PRIORITY); | ||
633 | + }); | ||
634 | + } | ||
635 | + }); | ||
636 | + } | ||
517 | } | 637 | } | ... | ... |
-
Please register or login to post a comment