sangho
Committed by Gerrit Code Review

[ONOS-4926] floating Ip flow rules handling when restarting ONOS

Change-Id: I844ebf8c0ef48289675124c79c96edd886bbff16
...@@ -40,6 +40,8 @@ import org.onosproject.net.flowobjective.FlowObjectiveService; ...@@ -40,6 +40,8 @@ import org.onosproject.net.flowobjective.FlowObjectiveService;
40 import org.onosproject.net.flowobjective.ForwardingObjective; 40 import org.onosproject.net.flowobjective.ForwardingObjective;
41 import org.onosproject.net.host.HostService; 41 import org.onosproject.net.host.HostService;
42 import org.onosproject.openstackinterface.OpenstackFloatingIP; 42 import org.onosproject.openstackinterface.OpenstackFloatingIP;
43 +import org.onosproject.openstackinterface.OpenstackInterfaceService;
44 +import org.onosproject.openstacknetworking.AbstractVmHandler;
43 import org.onosproject.openstacknetworking.Constants; 45 import org.onosproject.openstacknetworking.Constants;
44 import org.onosproject.openstacknetworking.OpenstackFloatingIpService; 46 import org.onosproject.openstacknetworking.OpenstackFloatingIpService;
45 import org.onosproject.openstacknetworking.RulePopulatorUtil; 47 import org.onosproject.openstacknetworking.RulePopulatorUtil;
...@@ -70,7 +72,7 @@ import static org.onosproject.openstacknode.OpenstackNodeService.NodeType.GATEWA ...@@ -70,7 +72,7 @@ import static org.onosproject.openstacknode.OpenstackNodeService.NodeType.GATEWA
70 72
71 @Service 73 @Service
72 @Component(immediate = true) 74 @Component(immediate = true)
73 -public class OpenstackFloatingIpManager implements OpenstackFloatingIpService { 75 +public class OpenstackFloatingIpManager extends AbstractVmHandler implements OpenstackFloatingIpService {
74 76
75 private final Logger log = LoggerFactory.getLogger(getClass()); 77 private final Logger log = LoggerFactory.getLogger(getClass());
76 78
...@@ -95,6 +97,9 @@ public class OpenstackFloatingIpManager implements OpenstackFloatingIpService { ...@@ -95,6 +97,9 @@ public class OpenstackFloatingIpManager implements OpenstackFloatingIpService {
95 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 97 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
96 protected ScalableGatewayService gatewayService; 98 protected ScalableGatewayService gatewayService;
97 99
100 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
101 + protected OpenstackInterfaceService openstackService;
102 +
98 private static final String NOT_ASSOCIATED = "null"; 103 private static final String NOT_ASSOCIATED = "null";
99 private static final KryoNamespace.Builder FLOATING_IP_SERIALIZER = 104 private static final KryoNamespace.Builder FLOATING_IP_SERIALIZER =
100 KryoNamespace.newBuilder().register(KryoNamespaces.API); 105 KryoNamespace.newBuilder().register(KryoNamespaces.API);
...@@ -108,6 +113,7 @@ public class OpenstackFloatingIpManager implements OpenstackFloatingIpService { ...@@ -108,6 +113,7 @@ public class OpenstackFloatingIpManager implements OpenstackFloatingIpService {
108 113
109 @Activate 114 @Activate
110 protected void activate() { 115 protected void activate() {
116 + super.activate();
111 appId = coreService.registerApplication(ROUTING_APP_ID); 117 appId = coreService.registerApplication(ROUTING_APP_ID);
112 nodeService.addListener(nodeListener); 118 nodeService.addListener(nodeListener);
113 floatingIpMap = storageService.<IpAddress, Host>consistentMapBuilder() 119 floatingIpMap = storageService.<IpAddress, Host>consistentMapBuilder()
...@@ -121,11 +127,34 @@ public class OpenstackFloatingIpManager implements OpenstackFloatingIpService { ...@@ -121,11 +127,34 @@ public class OpenstackFloatingIpManager implements OpenstackFloatingIpService {
121 127
122 @Deactivate 128 @Deactivate
123 protected void deactivate() { 129 protected void deactivate() {
130 + super.deactivate();
124 nodeService.removeListener(nodeListener); 131 nodeService.removeListener(nodeListener);
125 log.info("Stopped"); 132 log.info("Stopped");
126 } 133 }
127 134
128 @Override 135 @Override
136 + protected void hostDetected(Host host) {
137 + IpAddress hostIp = host.ipAddresses().stream().findFirst().get();
138 + Optional<OpenstackFloatingIP> floatingIp = openstackService.floatingIps().stream()
139 + .filter(fip -> fip.fixedIpAddress() != null && fip.fixedIpAddress().equals(hostIp))
140 + .findFirst();
141 + if (floatingIp.isPresent()) {
142 + eventExecutor.execute(() -> associateFloatingIp(floatingIp.get()));
143 + }
144 + }
145 +
146 + @Override
147 + protected void hostRemoved(Host host) {
148 + IpAddress hostIp = host.ipAddresses().stream().findFirst().get();
149 + Optional<OpenstackFloatingIP> floatingIp = openstackService.floatingIps().stream()
150 + .filter(fip -> fip.fixedIpAddress() != null && fip.fixedIpAddress().equals(hostIp))
151 + .findFirst();
152 + if (floatingIp.isPresent()) {
153 + eventExecutor.execute(() -> disassociateFloatingIp(floatingIp.get()));
154 + }
155 + }
156 +
157 + @Override
129 public void createFloatingIp(OpenstackFloatingIP floatingIp) { 158 public void createFloatingIp(OpenstackFloatingIP floatingIp) {
130 } 159 }
131 160
...@@ -285,18 +314,6 @@ public class OpenstackFloatingIpManager implements OpenstackFloatingIpService { ...@@ -285,18 +314,6 @@ public class OpenstackFloatingIpManager implements OpenstackFloatingIpService {
285 }); 314 });
286 } 315 }
287 316
288 - private void reloadFloatingIpRules() {
289 - floatingIpMap.entrySet().stream().forEach(entry -> {
290 - IpAddress floatingIp = entry.getKey();
291 - Host associatedVm = entry.getValue().value();
292 -
293 - populateFloatingIpRules(floatingIp, associatedVm);
294 - log.debug("Reload floating IP {} mapped to {}",
295 - floatingIp, associatedVm.ipAddresses());
296 - });
297 - }
298 -
299 - // TODO apply existing floating IPs on service start-up by handling host event
300 // TODO consider the case that port with associated floating IP is attached to a VM 317 // TODO consider the case that port with associated floating IP is attached to a VM
301 318
302 private class InternalNodeListener implements OpenstackNodeListener { 319 private class InternalNodeListener implements OpenstackNodeListener {
...@@ -316,7 +333,6 @@ public class OpenstackFloatingIpManager implements OpenstackFloatingIpService { ...@@ -316,7 +333,6 @@ public class OpenstackFloatingIpManager implements OpenstackFloatingIpService {
316 .uplinkIntf(node.externalPortName().get()) 333 .uplinkIntf(node.externalPortName().get())
317 .build(); 334 .build();
318 gatewayService.addGatewayNode(gnode); 335 gatewayService.addGatewayNode(gnode);
319 - reloadFloatingIpRules();
320 }); 336 });
321 } 337 }
322 break; 338 break;
......