예제 #1
0
  private void populateRoutingRules(Host host, Set<OpenstackSubnet> osSubNets) {
    String osSubNetId = host.annotations().value(SUBNET_ID);
    if (osSubNetId == null) {
      return;
    }

    DeviceId localDevice = host.location().deviceId();
    PortNumber localPort = host.location().port();
    if (!nodeService.dataIp(localDevice).isPresent()) {
      log.warn("Failed to populate L3 rules");
      return;
    }

    Map<String, String> vniMap = new HashMap<>();
    openstackService.networks().stream().forEach(n -> vniMap.put(n.id(), n.segmentId()));

    // TODO improve pipeline, do we have to install access rules between networks
    // for every single VMs?
    osSubNets
        .stream()
        .filter(osSubNet -> !osSubNet.id().equals(osSubNetId))
        .forEach(
            osSubNet -> {
              populateRoutingRulestoSameNode(
                  host.ipAddresses().stream().findFirst().get().getIp4Address(),
                  host.mac(),
                  localPort,
                  localDevice,
                  Long.valueOf(vniMap.get(osSubNet.networkId())),
                  osSubNet.cidr());

              nodeService
                  .completeNodes()
                  .stream()
                  .filter(node -> node.type().equals(COMPUTE))
                  .filter(node -> !node.intBridge().equals(localDevice))
                  .forEach(
                      node ->
                          populateRoutingRulestoDifferentNode(
                              host.ipAddresses().stream().findFirst().get().getIp4Address(),
                              Long.valueOf(vniMap.get(osSubNet.networkId())),
                              node.intBridge(),
                              nodeService.dataIp(localDevice).get().getIp4Address(),
                              osSubNet.cidr()));
            });
  }
예제 #2
0
  private void removeRoutingRules(Host host, Set<OpenstackSubnet> osSubNets) {
    String osSubNetId = host.annotations().value(SUBNET_ID);
    if (osSubNetId == null) {
      return;
    }

    Map<String, String> vniMap = new HashMap<>();
    openstackService.networks().stream().forEach(n -> vniMap.put(n.id(), n.segmentId()));

    osSubNets
        .stream()
        .filter(osSubNet -> !osSubNet.id().equals(osSubNetId))
        .forEach(
            osSubNet -> {
              TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
              sBuilder
                  .matchEthType(Ethernet.TYPE_IPV4)
                  .matchIPDst(host.ipAddresses().stream().findFirst().get().toIpPrefix())
                  .matchIPSrc(IpPrefix.valueOf(osSubNet.cidr()))
                  .matchTunnelId(Long.valueOf(vniMap.get(osSubNet.networkId())));

              nodeService
                  .completeNodes()
                  .stream()
                  .filter(node -> node.type().equals(COMPUTE))
                  .forEach(
                      node ->
                          RulePopulatorUtil.removeRule(
                              flowObjectiveService,
                              appId,
                              node.intBridge(),
                              sBuilder.build(),
                              ForwardingObjective.Flag.SPECIFIC,
                              EW_ROUTING_RULE_PRIORITY));
            });
    log.debug("Removed routing rule from {} to {}", host, osSubNets);
  }