Package com.cloud.agent.api.to

Examples of com.cloud.agent.api.to.StaticNatRuleTO


        HostVO ciscoVnmcHost = _hostDao.findById(ciscoVnmcDevice.getHostId());

        List<StaticNatRuleTO> rulesTO = new ArrayList<StaticNatRuleTO>();
        for (StaticNat rule : rules) {
            IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
            StaticNatRuleTO ruleTO = new StaticNatRuleTO(rule.getSourceIpAddressId(), sourceIp.getAddress().addr(), null,
                    null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
            rulesTO.add(ruleTO);
        }

        if (!rulesTO.isEmpty()) {
View Full Code Here


        for (FirewallRuleTO rule : allRules) {
            String ipPair;

            if (rule.getPurpose().equals(Purpose.StaticNat)) {
                StaticNatRuleTO staticNatRule = (StaticNatRuleTO) rule;
                ipPair = staticNatRule.getSrcIp() + "-" + staticNatRule.getDstIp();
            } else if (rule.getPurpose().equals(Purpose.PortForwarding)) {
                PortForwardingRuleTO portForwardingRule = (PortForwardingRuleTO) rule;
                ipPair = portForwardingRule.getSrcIp() + "-" + portForwardingRule.getDstIp();
            } else {
                continue;
View Full Code Here

        List<StaticNatRuleTO> rulesTO = null;
        if (rules != null) {
            rulesTO = new ArrayList<StaticNatRuleTO>();
            for (StaticNatRule rule : rules) {
                IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
                StaticNatRuleTO ruleTO = new StaticNatRuleTO(rule, null, sourceIp.getAddress().addr(), rule.getDestIpAddress());
                rulesTO.add(ruleTO);
            }
        }

        SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO, router.getVpcId());
View Full Code Here

        List<StaticNatRuleTO> rulesTO = null;
        if (rules != null) {
            rulesTO = new ArrayList<StaticNatRuleTO>();
            for (StaticNat rule : rules) {
                IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
                StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null,
                        null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
                rulesTO.add(ruleTO);
            }
        }
View Full Code Here

       
        for (StaticNat rule : rules) {
            IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
            Vlan vlan = _vlanDao.findById(sourceIp.getVlanId());

            StaticNatRuleTO ruleTO = new StaticNatRuleTO(0,vlan.getVlanTag(), sourceIp.getAddress().addr(), -1, -1, rule.getDestIpAddress(), -1, -1, "any", rule.isForRevoke(), false);
            staticNatRules.add(ruleTO);
        }

        sendStaticNatRules(staticNatRules, zone, externalFirewall.getId());
View Full Code Here

        List<StaticNatRuleTO> rulesTO = null;
        if (rules != null) {
            rulesTO = new ArrayList<StaticNatRuleTO>();
            for (StaticNatRule rule : rules) {
                IpAddress sourceIp = _networkMgr.getIp(rule.getSourceIpAddressId());
                StaticNatRuleTO ruleTO = new StaticNatRuleTO(rule, null, sourceIp.getAddress().addr(), rule.getDestIpAddress());
                rulesTO.add(ruleTO);
            }
        }

        SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO, router.getVpcId());
View Full Code Here

        List<StaticNatRuleTO> rulesTO = null;
        if (rules != null) {
            rulesTO = new ArrayList<StaticNatRuleTO>();
            for (StaticNat rule : rules) {
                IpAddress sourceIp = _networkMgr.getIp(rule.getSourceIpAddressId());
                StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null,
                        null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
                rulesTO.add(ruleTO);
            }
        }
View Full Code Here

        for (StaticNat rule : rules) {
            IpAddress sourceIp = networkModel.getIp(rule.getSourceIpAddressId());
            // Force the nat rule into the StaticNatRuleTO, no use making a new TO object
            // we only need the source and destination ip. Unfortunately no mention if a rule
            // is new.
            StaticNatRuleTO ruleTO =
                    new StaticNatRuleTO(1, sourceIp.getAddress().addr(), MIN_PORT, MAX_PORT, rule.getDestIpAddress(), MIN_PORT, MAX_PORT, "any", rule.isForRevoke(), false);
            staticNatRules.add(ruleTO);
        }

        ConfigureStaticNatRulesOnLogicalRouterCommand cmd = new ConfigureStaticNatRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), staticNatRules);
        ConfigureStaticNatRulesOnLogicalRouterAnswer answer = (ConfigureStaticNatRulesOnLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
View Full Code Here

         * Inside IP:  10.10.10.10
         */

        // Mock the command
        final ConfigureStaticNatRulesOnLogicalRouterCommand cmd = mock(ConfigureStaticNatRulesOnLogicalRouterCommand.class);
        final StaticNatRuleTO rule = new StaticNatRuleTO(1, "11.11.11.11", null, null, "10.10.10.10", null, null, null, false, false);
        final List<StaticNatRuleTO> rules = new ArrayList<StaticNatRuleTO>();
        rules.add(rule);
        when(cmd.getRules()).thenReturn(rules);
        when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");

        // Mock the api find call
        @SuppressWarnings("unchecked")
        final
        NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
        when(nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);

        // Mock the api create calls
        final NatRule[] rulepair = resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11");
        rulepair[0].setUuid(UUID.randomUUID());
        rulepair[1].setUuid(UUID.randomUUID());
        when(nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);

        final ConfigureStaticNatRulesOnLogicalRouterAnswer a = (ConfigureStaticNatRulesOnLogicalRouterAnswer)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")) {
                    return true;
                }
                if (rule.getType().equals("SourceNatRule") && ((SourceNatRule)rule).getToSourceIpAddressMin().equals("11.11.11.11")) {
                    return true;
                }
                return false;
            }
        }));
View Full Code Here

         * Inside IP:  10.10.10.10
         */

        // Mock the command
        final ConfigureStaticNatRulesOnLogicalRouterCommand cmd = mock(ConfigureStaticNatRulesOnLogicalRouterCommand.class);
        final StaticNatRuleTO rule = new StaticNatRuleTO(1, "11.11.11.11", null, null, "10.10.10.10", null, null, null, false, false);
        final List<StaticNatRuleTO> rules = new ArrayList<StaticNatRuleTO>();
        rules.add(rule);
        when(cmd.getRules()).thenReturn(rules);
        when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");

        // Mock the api create calls
        final NatRule[] rulepair = resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11");
        rulepair[0].setUuid(UUID.randomUUID());
        rulepair[1].setUuid(UUID.randomUUID());
        when(nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);

        // Mock the api find call
        @SuppressWarnings("unchecked")
        final
        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 ConfigureStaticNatRulesOnLogicalRouterAnswer a = (ConfigureStaticNatRulesOnLogicalRouterAnswer)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")) {
                    return true;
                }
                if (rule.getType().equals("SourceNatRule") && ((SourceNatRule)rule).getToSourceIpAddressMin().equals("11.11.11.11")) {
                    return true;
                }
                return false;
            }
        }));
View Full Code Here

TOP

Related Classes of com.cloud.agent.api.to.StaticNatRuleTO

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.