Package com.cloud.agent.api

Examples of com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer


            continue;
          }
         
          if (rule.getDstPortRange()[0] != rule.getDstPortRange()[1] ||
                  rule.getSrcPortRange()[0] != rule.getSrcPortRange()[1]    ) {
            return new ConfigurePortForwardingRulesOnLogicalRouterAnswer(cmd, false, "Nicira NVP doesn't support port ranges for port forwarding");
          }
         
          NatRule[] rulepair = generatePortForwardingRulePair(rule.getDstIp(), rule.getDstPortRange(), rule.getSrcIp(), rule.getSrcPortRange(), rule.getProtocol());
       
        NatRule incoming = null;
        NatRule outgoing = null;

        for (NatRule storedRule : existingRules.getResults()) {
            if (storedRule.equalsIgnoreUuid(rulepair[1])) {
            // The outgoing rule exists
              outgoing = storedRule;
              s_logger.debug("Found matching outgoing rule " + outgoing.getUuid());
              if (incoming != null) {
                break;
              }
              }             
            else if (storedRule.equalsIgnoreUuid(rulepair[0])) {
              // The incoming rule exists
              incoming = storedRule;
              s_logger.debug("Found matching incoming rule " + incoming.getUuid());
              if (outgoing != null) {
                break;
              }
            }
        }
        if (incoming != null && outgoing != null) {
          if (rule.revoked()) {
            s_logger.debug("Deleting incoming rule " + incoming.getUuid());
            _niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), incoming.getUuid());
           
            s_logger.debug("Deleting outgoing rule " + outgoing.getUuid());
            _niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), outgoing.getUuid());
          }
        }
        else {
          if (rule.revoked()) {
            s_logger.warn("Tried deleting a rule that does not exist, " +
                rule.getSrcIp() + " -> " + rule.getDstIp());
            break;
          }
         
          rulepair[0] = _niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0]);
          s_logger.debug("Created " + natRuleToString(rulepair[0]));
         
          try {
            rulepair[1] = _niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[1]);
            s_logger.debug("Created " + natRuleToString(rulepair[1]));
          } catch (NiciraNvpApiException ex) {
            s_logger.warn("NiciraNvpApiException during create call, rolling back previous create");
            _niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0].getUuid());
            throw ex; // Rethrow the original exception
          }
         
        }
        }
        return new ConfigurePortForwardingRulesOnLogicalRouterAnswer(cmd, true, cmd.getRules().size() +" PortForwarding rules applied");
        } catch (NiciraNvpApiException e) {
          if (numRetries > 0) {
            return retry(cmd, --numRetries);
          }
          else {
            return new ConfigurePortForwardingRulesOnLogicalRouterAnswer(cmd, e);
          }
        }
     
    }
View Full Code Here


            portForwardingRules.add(ruleTO);
        }

        ConfigurePortForwardingRulesOnLogicalRouterCommand cmd =
                new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules);
        ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);

        return answer.getResult();
    }
View Full Code Here

    NatRule[] rulepair = _resource.generatePortForwardingRulePair("10.10.10.10", new int[] { 8080, 8080 }, "11.11.11.11", new int[] { 80, 80}, "tcp");
    rulepair[0].setUuid(UUID.randomUUID());
    rulepair[1].setUuid(UUID.randomUUID());
    when(_nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);
   
    ConfigurePortForwardingRulesOnLogicalRouterAnswer a = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) _resource.executeRequest(cmd);
   
    assertTrue(a.getResult());
    verify(_nvpApi, atLeast(2)).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<NatRule>() {
      @Override
      public boolean matches(Object argument) {
        NatRule rule = (NatRule) argument;
        if (rule.getType().equals("DestinationNatRule") &&
View Full Code Here

    NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
    when(storedRules.getResultCount()).thenReturn(2);
    when(storedRules.getResults()).thenReturn(Arrays.asList(rulepair));
    when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
   
    ConfigurePortForwardingRulesOnLogicalRouterAnswer a = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) _resource.executeRequest(cmd);
   
    assertTrue(a.getResult());
    verify(_nvpApi, never()).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<NatRule>() {
      @Override
      public boolean matches(Object argument) {
        NatRule rule = (NatRule) argument;
        if (rule.getType().equals("DestinationNatRule") &&
View Full Code Here

    NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
    when(storedRules.getResultCount()).thenReturn(2);
    when(storedRules.getResults()).thenReturn(Arrays.asList(rulepair));
    when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
   
    ConfigurePortForwardingRulesOnLogicalRouterAnswer a = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) _resource.executeRequest(cmd);
   
    assertTrue(a.getResult());
    verify(_nvpApi, atLeast(2)).deleteLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<UUID>() {
      @Override
      public boolean matches(Object argument) {
        UUID uuid = (UUID) argument;
        if (rule0Uuid.equals(uuid) || rule1Uuid.equals(uuid)) {
View Full Code Here

    @SuppressWarnings("unchecked")
    NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
    when(storedRules.getResultCount()).thenReturn(0);
    when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
   
    ConfigurePortForwardingRulesOnLogicalRouterAnswer a = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) _resource.executeRequest(cmd);
   
    assertFalse(a.getResult());
    verify(_nvpApi, atLeastOnce()).deleteLogicalRouterNatRule(eq("aaaaa"), eq(rulepair[0].getUuid()));
  }
View Full Code Here

    NatRule[] rulepair = _resource.generatePortForwardingRulePair("10.10.10.10", new int[] { 80, 85 }, "11.11.11.11", new int[] { 80, 85}, "tcp");
    rulepair[0].setUuid(UUID.randomUUID());
    rulepair[1].setUuid(UUID.randomUUID());
    when(_nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);
   
    ConfigurePortForwardingRulesOnLogicalRouterAnswer a = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) _resource.executeRequest(cmd);
   
    // The expected result is false, Nicira does not support port ranges in DNAT
    assertFalse(a.getResult());

  }
View Full Code Here

                    // Don't need to do anything
                    continue;
                }

                if (rule.getDstPortRange()[0] != rule.getDstPortRange()[1] || rule.getSrcPortRange()[0] != rule.getSrcPortRange()[1]) {
                    return new ConfigurePortForwardingRulesOnLogicalRouterAnswer(cmd, false, "Nicira NVP doesn't support port ranges for port forwarding");
                }

                NatRule[] rulepair = generatePortForwardingRulePair(rule.getDstIp(), rule.getDstPortRange(), rule.getSrcIp(), rule.getSrcPortRange(), rule.getProtocol());

                NatRule incoming = null;
                NatRule outgoing = null;

                for (NatRule storedRule : existingRules.getResults()) {
                    if (storedRule.equalsIgnoreUuid(rulepair[1])) {
                        // The outgoing rule exists
                        outgoing = storedRule;
                        s_logger.debug("Found matching outgoing rule " + outgoing.getUuid());
                        if (incoming != null) {
                            break;
                        }
                    } else if (storedRule.equalsIgnoreUuid(rulepair[0])) {
                        // The incoming rule exists
                        incoming = storedRule;
                        s_logger.debug("Found matching incoming rule " + incoming.getUuid());
                        if (outgoing != null) {
                            break;
                        }
                    }
                }
                if (incoming != null && outgoing != null) {
                    if (rule.revoked()) {
                        s_logger.debug("Deleting incoming rule " + incoming.getUuid());
                        niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), incoming.getUuid());

                        s_logger.debug("Deleting outgoing rule " + outgoing.getUuid());
                        niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), outgoing.getUuid());
                    }
                } else {
                    if (rule.revoked()) {
                        s_logger.warn("Tried deleting a rule that does not exist, " + rule.getSrcIp() + " -> " + rule.getDstIp());
                        break;
                    }

                    rulepair[0] = niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0]);
                    s_logger.debug("Created " + natRuleToString(rulepair[0]));

                    try {
                        rulepair[1] = niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[1]);
                        s_logger.debug("Created " + natRuleToString(rulepair[1]));
                    } catch (NiciraNvpApiException ex) {
                        s_logger.warn("NiciraNvpApiException during create call, rolling back previous create");
                        niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0].getUuid());
                        throw ex; // Rethrow the original exception
                    }

                }
            }
            return new ConfigurePortForwardingRulesOnLogicalRouterAnswer(cmd, true, cmd.getRules().size() + " PortForwarding rules applied");
        } catch (NiciraNvpApiException e) {
            if (numRetries > 0) {
                return retry(cmd, --numRetries);
            } else {
                return new ConfigurePortForwardingRulesOnLogicalRouterAnswer(cmd, e);
            }
        }

    }
View Full Code Here

        final NatRule[] rulepair = resource.generatePortForwardingRulePair("10.10.10.10", new int[] {8080, 8080}, "11.11.11.11", new int[] {80, 80}, "tcp");
        rulepair[0].setUuid(UUID.randomUUID());
        rulepair[1].setUuid(UUID.randomUUID());
        when(nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);

        final ConfigurePortForwardingRulesOnLogicalRouterAnswer a = (ConfigurePortForwardingRulesOnLogicalRouterAnswer)resource.executeRequest(cmd);

        assertTrue(a.getResult());
        verify(nvpApi, atLeast(2)).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<NatRule>() {
            @Override
            public boolean matches(final Object argument) {
                final NatRule rule = (NatRule)argument;
                if (rule.getType().equals("DestinationNatRule") && ((DestinationNatRule)rule).getToDestinationIpAddress().equals("10.10.10.10")) {
View Full Code Here

        NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
        when(storedRules.getResultCount()).thenReturn(2);
        when(storedRules.getResults()).thenReturn(Arrays.asList(rulepair));
        when(nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);

        final ConfigurePortForwardingRulesOnLogicalRouterAnswer a = (ConfigurePortForwardingRulesOnLogicalRouterAnswer)resource.executeRequest(cmd);

        assertTrue(a.getResult());
        verify(nvpApi, never()).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<NatRule>() {
            @Override
            public boolean matches(final Object argument) {
                final NatRule rule = (NatRule)argument;
                if (rule.getType().equals("DestinationNatRule") && ((DestinationNatRule)rule).getToDestinationIpAddress().equals("10.10.10.10")) {
View Full Code Here

TOP

Related Classes of com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.