VirtualRoutingResource { public Answer executeRequest(final NetworkElementCommand cmd) { boolean aggregated = false; String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); Lock lock; if (_vrLockMap.containsKey(routerName)) { lock = _vrLockMap.get(routerName); } else { lock = new ReentrantLock(); _vrLockMap.put(routerName, lock); } lock.lock(); try { ExecutionResult rc = _vrDeployer.prepareCommand(cmd); if (!rc.isSuccess()) { s_logger.error("Failed to prepare VR command due to " + rc.getDetails()); return new Answer(cmd, false, rc.getDetails()); } assert cmd.getRouterAccessIp() != null : "Why there is no access IP for VR?"; if (cmd.isQuery()) { return executeQueryCommand(cmd); } if (cmd instanceof AggregationControlCommand) { return execute((AggregationControlCommand)cmd); } if (_vrAggregateCommandsSet.containsKey(routerName)) { _vrAggregateCommandsSet.get(routerName).add(cmd); aggregated = true; return new Answer(cmd); } List<ConfigItem> cfg = generateCommandCfg(cmd); if (cfg == null) { return Answer.createUnsupportedCommandAnswer(cmd); } return applyConfig(cmd, cfg); } catch (final IllegalArgumentException e) { return new Answer(cmd, false, e.getMessage()); } finally { lock.unlock(); if (!aggregated) { ExecutionResult rc = _vrDeployer.cleanupCommand(cmd); if (!rc.isSuccess()) { s_logger.error("Failed to cleanup VR command due to " + rc.getDetails()); } } } } VirtualRoutingResource(VirtualRouterDeployer deployer); Answer executeRequest(final NetworkElementCommand cmd); boolean configure(final String name, final Map<String, Object> params); boolean connect(final String ipAddress); boolean connect(final String ipAddress, final int port); boolean connect(final String ipAddress, int retry, int sleep);  }
@Test public void testSetMonitorServiceCommand() { final SetMonitorServiceCommand cmd = generateSetMonitorServiceCommand(); final Answer answer = _resource.executeRequest(cmd); assertTrue(answer.getResult()); }
@Test public void testSite2SiteVpnCfgCommand() { _count = 0; Site2SiteVpnCfgCommand cmd = new Site2SiteVpnCfgCommand(true, "64.10.1.10", "64.10.1.1", "192.168.1.1/16", "124.10.1.10", "192.168.100.1/24", "3des-sha1,aes128-sha1;modp1536", "3des-sha1,aes128-md5", "psk", Long.valueOf(1800), Long.valueOf(1800), true, false, false); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, ROUTERNAME); Answer answer = _resource.executeRequest(cmd); assertTrue(answer.getResult()); cmd = new Site2SiteVpnCfgCommand(true, "64.10.1.10", "64.10.1.1", "192.168.1.1/16", "124.10.1.10", "192.168.100.1/24", "3des-sha1,aes128-sha1;modp1536", "3des-sha1,aes128-md5", "psk", Long.valueOf(1800), Long.valueOf(1800), false, true, false); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, ROUTERNAME); answer = _resource.executeRequest(cmd); assertTrue(answer.getResult()); cmd = new Site2SiteVpnCfgCommand(false, "64.10.1.10", "64.10.1.1", "192.168.1.1/16", "124.10.1.10", "192.168.100.1/24", "3des-sha1,aes128-sha1;modp1536", "3des-sha1,aes128-md5", "psk", Long.valueOf(1800), Long.valueOf(1800), false, true, false); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, ROUTERNAME); answer = _resource.executeRequest(cmd); assertTrue(answer.getResult()); }
@Test public void testRemoteAccessVpnCfgCommand() { _count = 0; Answer answer = _resource.executeRequest(generateRemoteAccessVpnCfgCommand1()); assertTrue(answer.getResult()); answer = _resource.executeRequest(generateRemoteAccessVpnCfgCommand2()); assertTrue(answer.getResult()); answer = _resource.executeRequest(generateRemoteAccessVpnCfgCommand3()); assertTrue(answer.getResult()); }
@Test public void testFirewallRulesCommand() { _count = 0; final Answer answer = _resource.executeRequest(generateSetFirewallRulesCommand()); assertTrue(answer.getResult()); }
@Test public void testVmDataCommand() { final Answer answer = _resource.executeRequest(generateVmDataCommand()); assertTrue(answer.getResult()); }
@Test public void testSavePasswordCommand() { final Answer answer = _resource.executeRequest(generateSavePasswordCommand()); assertTrue(answer.getResult()); }
@Test public void testDhcpEntryCommand() { _count = 0; Answer answer = _resource.executeRequest(generateDhcpEntryCommand1()); assertTrue(answer.getResult()); answer = _resource.executeRequest(generateDhcpEntryCommand2()); assertTrue(answer.getResult()); answer = _resource.executeRequest(generateDhcpEntryCommand3()); assertTrue(answer.getResult()); }
@Test public void testCreateIpAliasCommand() { final Answer answer = _resource.executeRequest(generateCreateIpAliasCommand()); assertTrue(answer.getResult()); }
@Test public void testDeleteIpAliasCommand() { final Answer answer = _resource.executeRequest(generateDeleteIpAliasCommand()); assertTrue(answer.getResult()); }
@Test public void testDnsMasqConfigCommand() { final Answer answer = _resource.executeRequest(generateDnsMasqConfigCommand()); assertTrue(answer.getResult()); }
@Test public void testLoadBalancerConfigCommand() { _count = 0; _file = ""; Answer answer = _resource.executeRequest(generateLoadBalancerConfigCommand1()); assertTrue(answer.getResult()); answer = _resource.executeRequest(generateLoadBalancerConfigCommand2()); assertTrue(answer.getResult()); }
@Test @Ignore("Ignore this test while we are experimenting with the commands.") public void testAggregationCommands() { final List<NetworkElementCommand> cmds = new LinkedList<>(); final AggregationControlCommand startCmd = new AggregationControlCommand(Action.Start, ROUTERNAME, ROUTERIP, ROUTERGUESTIP); cmds.add(startCmd); cmds.add(generateIpAssocCommand()); cmds.add(generateIpAssocVpcCommand()); cmds.add(generateSetFirewallRulesCommand()); cmds.add(generateSetPortForwardingRulesCommand()); cmds.add(generateSetPortForwardingRulesVpcCommand()); cmds.add(generateCreateIpAliasCommand()); cmds.add(generateDeleteIpAliasCommand()); cmds.add(generateDnsMasqConfigCommand()); cmds.add(generateRemoteAccessVpnCfgCommand1()); cmds.add(generateRemoteAccessVpnCfgCommand2()); cmds.add(generateRemoteAccessVpnCfgCommand3()); cmds.add(generateSetPortForwardingRulesCommand()); cmds.add(generateSetPortForwardingRulesVpcCommand()); cmds.add(generateDhcpEntryCommand1()); cmds.add(generateDhcpEntryCommand2()); cmds.add(generateDhcpEntryCommand3()); cmds.add(generateSavePasswordCommand()); cmds.add(generateVmDataCommand()); final AggregationControlCommand finishCmd = new AggregationControlCommand(Action.Finish, ROUTERNAME, ROUTERIP, ROUTERGUESTIP); cmds.add(finishCmd); for (final NetworkElementCommand cmd : cmds) { final Answer answer = _resource.executeRequest(cmd); assertTrue(answer.getResult()); } }
@Test public void testBumpUpCommand() { final BumpUpPriorityCommand cmd = new BumpUpPriorityCommand(); final Answer answer = _resource.executeRequest(cmd); assertTrue(answer.getResult()); }
@Test public void testSetPortForwardingRulesVpcCommand() { final SetPortForwardingRulesVpcCommand cmd = generateSetPortForwardingRulesVpcCommand(); _count = 0; final Answer answer = _resource.executeRequest(cmd); assertTrue(answer instanceof GroupAnswer); assertEquals(((GroupAnswer) answer).getResults().length, 2); assertTrue(answer.getResult()); }
@Test public void testSetPortForwardingRulesCommand() { final SetPortForwardingRulesCommand cmd = generateSetPortForwardingRulesCommand(); _count = 0; final Answer answer = _resource.executeRequest(cmd); assertTrue(answer instanceof GroupAnswer); assertEquals(((GroupAnswer) answer).getResults().length, 2); assertTrue(answer.getResult()); }
@Test public void testIpAssocCommand() { final IpAssocCommand cmd = generateIpAssocCommand(); _count = 0; final Answer answer = _resource.executeRequest(cmd); assertTrue(answer instanceof GroupAnswer); assertEquals(2, ((GroupAnswer)answer).getResults().length); assertTrue(answer.getResult()); }
@Test public void testIpAssocVpcCommand() { final IpAssocVpcCommand cmd = generateIpAssocVpcCommand(); _count = 0; final Answer answer = _resource.executeRequest(cmd); assertTrue(answer instanceof GroupAnswer); assertEquals(2, ((GroupAnswer)answer).getResults().length); assertTrue(answer.getResult()); }
@Test public void testSourceNatCommand() { final SetSourceNatCommand cmd = generateSetSourceNatCommand(); final Answer answer = _resource.executeRequest(cmd); assertTrue(answer.getResult()); }
@Test public void testNetworkACLCommand() { final SetNetworkACLCommand cmd = generateSetNetworkACLCommand(); _count = 0; Answer answer = _resource.executeRequest(cmd); assertTrue(answer.getResult()); cmd.setAccessDetail(NetworkElementCommand.VPC_PRIVATE_GATEWAY, String.valueOf(VpcGateway.Type.Private)); answer = _resource.executeRequest(cmd); assertTrue(answer.getResult()); }
@Test public void testSetupGuestNetworkCommand() { final SetupGuestNetworkCommand cmd = generateSetupGuestNetworkCommand(); final Answer answer = _resource.executeRequest(cmd); assertTrue(answer.getResult()); }