Committed by
Gerrit Code Review
CORD-564 Remove flow rules completely when a VM or dependency removed
Change-Id: I5d1956992c9353c9a9080bf6f59a8ff73cce32c0
Showing
3 changed files
with
30 additions
and
51 deletions
... | @@ -176,7 +176,7 @@ public final class CordService { | ... | @@ -176,7 +176,7 @@ public final class CordService { |
176 | * @param netName network name | 176 | * @param netName network name |
177 | * @return network type, or PRIVATE if it doesn't match any type | 177 | * @return network type, or PRIVATE if it doesn't match any type |
178 | */ | 178 | */ |
179 | - public static ServiceType getServiceType(String netName) { | 179 | + private ServiceType getServiceType(String netName) { |
180 | checkNotNull(netName); | 180 | checkNotNull(netName); |
181 | 181 | ||
182 | String name = netName.toUpperCase(); | 182 | String name = netName.toUpperCase(); | ... | ... |
... | @@ -30,7 +30,6 @@ import org.onlab.packet.IpAddress; | ... | @@ -30,7 +30,6 @@ import org.onlab.packet.IpAddress; |
30 | import org.onlab.packet.MacAddress; | 30 | import org.onlab.packet.MacAddress; |
31 | import org.onlab.packet.VlanId; | 31 | import org.onlab.packet.VlanId; |
32 | import org.onosproject.cordvtn.api.CordService; | 32 | import org.onosproject.cordvtn.api.CordService; |
33 | -import org.onosproject.cordvtn.api.CordService.ServiceType; | ||
34 | import org.onosproject.cordvtn.api.CordServiceId; | 33 | import org.onosproject.cordvtn.api.CordServiceId; |
35 | import org.onosproject.cordvtn.api.CordVtnConfig; | 34 | import org.onosproject.cordvtn.api.CordVtnConfig; |
36 | import org.onosproject.cordvtn.api.CordVtnNode; | 35 | import org.onosproject.cordvtn.api.CordVtnNode; |
... | @@ -88,7 +87,6 @@ import java.util.stream.StreamSupport; | ... | @@ -88,7 +87,6 @@ import java.util.stream.StreamSupport; |
88 | import static com.google.common.base.Preconditions.checkNotNull; | 87 | import static com.google.common.base.Preconditions.checkNotNull; |
89 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | 88 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
90 | import static org.onlab.util.Tools.groupedThreads; | 89 | import static org.onlab.util.Tools.groupedThreads; |
91 | -import static org.onosproject.cordvtn.api.CordService.getServiceType; | ||
92 | import static org.slf4j.LoggerFactory.getLogger; | 90 | import static org.slf4j.LoggerFactory.getLogger; |
93 | 91 | ||
94 | /** | 92 | /** |
... | @@ -234,7 +232,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro | ... | @@ -234,7 +232,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro |
234 | } | 232 | } |
235 | 233 | ||
236 | log.info("Service dependency from {} to {} created.", tService.id().id(), pService.id().id()); | 234 | log.info("Service dependency from {} to {} created.", tService.id().id(), pService.id().id()); |
237 | - ruleInstaller.populateServiceDependencyRules(tService, pService, isBidirectional); | 235 | + ruleInstaller.populateServiceDependencyRules(tService, pService, isBidirectional, true); |
238 | } | 236 | } |
239 | 237 | ||
240 | @Override | 238 | @Override |
... | @@ -248,7 +246,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro | ... | @@ -248,7 +246,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro |
248 | } | 246 | } |
249 | 247 | ||
250 | log.info("Service dependency from {} to {} removed.", tService.id().id(), pService.id().id()); | 248 | log.info("Service dependency from {} to {} removed.", tService.id().id(), pService.id().id()); |
251 | - ruleInstaller.removeServiceDependencyRules(tService, pService); | 249 | + ruleInstaller.populateServiceDependencyRules(tService, pService, true, false); |
252 | } | 250 | } |
253 | 251 | ||
254 | @Override | 252 | @Override |
... | @@ -434,10 +432,9 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro | ... | @@ -434,10 +432,9 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro |
434 | CordServiceId serviceId = CordServiceId.of(osNet.getId()); | 432 | CordServiceId serviceId = CordServiceId.of(osNet.getId()); |
435 | // here it assumes all cord service networks has only one subnet | 433 | // here it assumes all cord service networks has only one subnet |
436 | Subnet osSubnet = osNet.getNeutronSubnets().stream() | 434 | Subnet osSubnet = osNet.getNeutronSubnets().stream() |
437 | - .findFirst() | 435 | + .findFirst().orElse(null); |
438 | - .orElse(null); | ||
439 | if (osSubnet == null) { | 436 | if (osSubnet == null) { |
440 | - log.warn("Couldn't find OpenStack subnet for service {}", serviceId.id()); | 437 | + log.warn("Couldn't find OpenStack subnet for network {}", serviceId.id()); |
441 | return null; | 438 | return null; |
442 | } | 439 | } |
443 | 440 | ||
... | @@ -445,12 +442,11 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro | ... | @@ -445,12 +442,11 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro |
445 | .stream() | 442 | .stream() |
446 | .collect(Collectors.toMap(host -> host, this::getTunnelIp)); | 443 | .collect(Collectors.toMap(host -> host, this::getTunnelIp)); |
447 | 444 | ||
448 | - ServiceType serviceType = getServiceType(osNet.getName()); | ||
449 | // allows working without XOS for now | 445 | // allows working without XOS for now |
450 | Set<CordServiceId> tServices = Sets.newHashSet(); | 446 | Set<CordServiceId> tServices = Sets.newHashSet(); |
451 | Set<CordServiceId> pServices = Sets.newHashSet(); | 447 | Set<CordServiceId> pServices = Sets.newHashSet(); |
452 | 448 | ||
453 | - if (xosClient.access() != null && serviceType != ServiceType.MANAGEMENT) { | 449 | + if (xosClient.access() != null) { |
454 | tServices = xosClient.vtnServiceApi().getTenantServices(serviceId.id()) | 450 | tServices = xosClient.vtnServiceApi().getTenantServices(serviceId.id()) |
455 | .stream() | 451 | .stream() |
456 | .map(CordServiceId::of) | 452 | .map(CordServiceId::of) |
... | @@ -561,27 +557,17 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro | ... | @@ -561,27 +557,17 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro |
561 | virtualSubscriberGatewayAdded(host, serviceVlan); | 557 | virtualSubscriberGatewayAdded(host, serviceVlan); |
562 | } | 558 | } |
563 | 559 | ||
564 | - String osNetId = host.annotations().value(SERVICE_ID); | 560 | + String serviceId = host.annotations().value(SERVICE_ID); |
565 | - if (osNetId == null) { | 561 | + if (serviceId == null) { |
566 | - // ignore this host, it is not the service VM, or it's a vSG | 562 | + // ignore this host, it is not a service VM |
567 | return; | 563 | return; |
568 | } | 564 | } |
569 | 565 | ||
570 | - OSClient osClient = OSFactory.clientFromAccess(osAccess); | 566 | + log.info("VM is detected, MAC: {} IP: {}", host.mac(), host.ipAddresses()); |
571 | - Network osNet = osClient.networking().network().get(osNetId); | ||
572 | - if (osNet == null) { | ||
573 | - log.warn("Failed to get OpenStack network {} for VM {}.", | ||
574 | - osNetId, host.id()); | ||
575 | - return; | ||
576 | - } | ||
577 | 567 | ||
578 | - log.info("VM is detected, MAC: {} IP: {}", | 568 | + CordService service = getCordService(CordServiceId.of(serviceId)); |
579 | - host.mac(), | ||
580 | - host.ipAddresses().stream().findFirst().get()); | ||
581 | - | ||
582 | - CordService service = getCordService(osNet); | ||
583 | if (service == null) { | 569 | if (service == null) { |
584 | - log.warn("Failed to get CordService for {}", osNet.getName()); | 570 | + log.warn("Failed to get CordService for {}", serviceId); |
585 | return; | 571 | return; |
586 | } | 572 | } |
587 | 573 | ||
... | @@ -599,7 +585,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro | ... | @@ -599,7 +585,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro |
599 | service.providerServices().stream().forEach( | 585 | service.providerServices().stream().forEach( |
600 | pServiceId -> createServiceDependency(service.id(), pServiceId, true)); | 586 | pServiceId -> createServiceDependency(service.id(), pServiceId, true)); |
601 | 587 | ||
602 | - ruleInstaller.updateServiceGroup(service); | 588 | + ruleInstaller.updateProviderServiceGroup(service); |
603 | // sends gratuitous ARP here for the case of adding existing VMs | 589 | // sends gratuitous ARP here for the case of adding existing VMs |
604 | // when ONOS or cordvtn app is restarted | 590 | // when ONOS or cordvtn app is restarted |
605 | arpProxy.sendGratuitousArpForGateway(service.serviceIp(), Sets.newHashSet(host)); | 591 | arpProxy.sendGratuitousArpForGateway(service.serviceIp(), Sets.newHashSet(host)); |
... | @@ -607,7 +593,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro | ... | @@ -607,7 +593,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro |
607 | } | 593 | } |
608 | 594 | ||
609 | registerDhcpLease(host, service); | 595 | registerDhcpLease(host, service); |
610 | - ruleInstaller.populateBasicConnectionRules(host, getTunnelIp(host), osNet); | 596 | + ruleInstaller.populateBasicConnectionRules(host, service, true); |
611 | } | 597 | } |
612 | 598 | ||
613 | /** | 599 | /** |
... | @@ -618,52 +604,45 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro | ... | @@ -618,52 +604,45 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro |
618 | private void serviceVmRemoved(Host host) { | 604 | private void serviceVmRemoved(Host host) { |
619 | checkNotNull(osAccess, "OpenStack access is not set"); | 605 | checkNotNull(osAccess, "OpenStack access is not set"); |
620 | 606 | ||
621 | - String serviceVlan = host.annotations().value(S_TAG); | 607 | + if (host.annotations().value(S_TAG) != null) { |
622 | - if (serviceVlan != null) { | ||
623 | virtualSubscriberGatewayRemoved(host); | 608 | virtualSubscriberGatewayRemoved(host); |
624 | } | 609 | } |
625 | 610 | ||
626 | - String osNetId = host.annotations().value(SERVICE_ID); | 611 | + String serviceId = host.annotations().value(SERVICE_ID); |
627 | - if (osNetId == null) { | 612 | + if (serviceId == null) { |
628 | - // ignore it, it's not the service VM or it's a vSG | 613 | + // ignore it, it's not a service VM |
629 | - return; | ||
630 | - } | ||
631 | - | ||
632 | - OSClient osClient = OSFactory.clientFromAccess(osAccess); | ||
633 | - Network osNet = osClient.networking().network().get(osNetId); | ||
634 | - if (osNet == null) { | ||
635 | - log.warn("Failed to get OpenStack network {} for VM {}", | ||
636 | - osNetId, host.id()); | ||
637 | return; | 614 | return; |
638 | } | 615 | } |
639 | 616 | ||
640 | - log.info("VM is vanished, MAC: {} IP: {}", | 617 | + log.info("VM is vanished, MAC: {} IP: {}", host.mac(), host.ipAddresses()); |
641 | - host.mac(), | ||
642 | - host.ipAddresses().stream().findFirst().get()); | ||
643 | 618 | ||
644 | - ruleInstaller.removeBasicConnectionRules(host); | 619 | + CordService service = getCordService(CordServiceId.of(serviceId)); |
645 | - dhcpService.removeStaticMapping(host.mac()); | ||
646 | - | ||
647 | - CordService service = getCordService(osNet); | ||
648 | if (service == null) { | 620 | if (service == null) { |
621 | + log.warn("Failed to get CORD service for {}", serviceId); | ||
649 | return; | 622 | return; |
650 | } | 623 | } |
624 | + // TODO need to consider the case that the network is removed also | ||
651 | 625 | ||
652 | switch (service.serviceType()) { | 626 | switch (service.serviceType()) { |
653 | case MANAGEMENT: | 627 | case MANAGEMENT: |
654 | - ruleInstaller.removeManagementNetworkRules(host, service); | ||
655 | break; | 628 | break; |
656 | case PRIVATE: | 629 | case PRIVATE: |
657 | - if (getHostsWithOpenstackNetwork(osNet).isEmpty()) { | 630 | + if (service.hosts().isEmpty()) { |
658 | arpProxy.removeGateway(service.serviceIp()); | 631 | arpProxy.removeGateway(service.serviceIp()); |
659 | } | 632 | } |
660 | case PUBLIC: | 633 | case PUBLIC: |
661 | default: | 634 | default: |
662 | if (!service.tenantServices().isEmpty()) { | 635 | if (!service.tenantServices().isEmpty()) { |
663 | - ruleInstaller.updateServiceGroup(service); | 636 | + ruleInstaller.updateProviderServiceGroup(service); |
637 | + } | ||
638 | + if (!service.providerServices().isEmpty()) { | ||
639 | + ruleInstaller.updateTenantServiceVm(host, service); | ||
664 | } | 640 | } |
665 | break; | 641 | break; |
666 | } | 642 | } |
643 | + | ||
644 | + dhcpService.removeStaticMapping(host.mac()); | ||
645 | + ruleInstaller.populateBasicConnectionRules(host, service, false); | ||
667 | } | 646 | } |
668 | 647 | ||
669 | 648 | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment