Esempio n. 1
0
  /**
   * Get the GRETunnelService
   *
   * @return GRETunnelService
   * @throws IOException
   */
  public static GRETunnelService getGRETunnelService(
      String tunnelName, String ipv4Address, String subnetMask, String ipSource, String ipDestiny) {
    GRETunnelService greService = new GRETunnelService();
    greService.setElementName("");
    greService.setName(tunnelName);

    GRETunnelConfiguration greConfig = new GRETunnelConfiguration();
    greConfig.setSourceAddress(ipSource);
    greConfig.setDestinationAddress(ipDestiny);

    GRETunnelEndpoint gE = new GRETunnelEndpoint();
    gE.setIPv4Address(ipv4Address);
    gE.setSubnetMask(subnetMask);

    greService.setGRETunnelConfiguration(greConfig);
    greService.addProtocolEndpoint(gE);

    return greService;
  }
  /**
   * Get the GRETunnelService
   *
   * @return GRETunnelService
   * @throws IOException
   */
  private GRETunnelService getGRETunnelService() {

    GRETunnelService greService = new GRETunnelService();
    greService.setElementName("");
    greService.setName("gr-0/1/1.2");

    GRETunnelConfiguration greConfig = new GRETunnelConfiguration();
    greConfig.setSourceAddress("147.56.89.62");
    greConfig.setDestinationAddress("193.45.23.1");

    GRETunnelEndpoint gE = new GRETunnelEndpoint();
    gE.setIPv6Address("51:4F3::3A:B1");
    gE.setPrefixLength(Short.valueOf("64"));
    gE.setProtocolIFType(ProtocolIFType.IPV6);

    greService.setGRETunnelConfiguration(greConfig);
    greService.addProtocolEndpoint(gE);

    return greService;
  }
  @Test
  public void showGRETunnelConfigurationTest() throws CapabilityException, ProtocolException {
    log.info("Test showGRETunnelConfiguration method");

    IGRETunnelCapability greCapability =
        (IGRETunnelCapability)
            routerResource.getCapability(
                InitializerTestHelper.getCapabilityInformation(TestsConstants.GRE_CAPABILITY_TYPE));

    ComputerSystem routerModel = (ComputerSystem) routerResource.getModel();
    routerModel.addHostedService(
        ParamCreationHelper.getGRETunnelService(TUNNEL_NAME, IPv4_ADDRESS, IP_SOURCE, IP_DESTINY));
    routerModel.addHostedService(
        ParamCreationHelper.getGRETunnelService(TUNNEL_NAME, IPv6_ADDRESS, IP_SOURCE, IP_DESTINY));

    List<GRETunnelService> greServices = greCapability.showGRETunnelConfiguration();
    Assert.assertEquals(greServices.size(), 2);

    GRETunnelService greService = greServices.get(0);
    Assert.assertEquals(TUNNEL_NAME, greService.getName());

    Assert.assertNotNull(greService.getGRETunnelConfiguration());
    GRETunnelConfiguration greConfig = greService.getGRETunnelConfiguration();
    Assert.assertEquals(IP_SOURCE, greConfig.getSourceAddress());
    Assert.assertEquals(IP_DESTINY, greConfig.getDestinationAddress());

    Assert.assertEquals(greService.getProtocolEndpoint().size(), 1);
    ProtocolEndpoint pE = greService.getProtocolEndpoint().get(0);
    Assert.assertTrue(pE instanceof GRETunnelEndpoint);
    GRETunnelEndpoint gE = (GRETunnelEndpoint) pE;
    Assert.assertEquals(IPUtilsHelper.getAddressFromIP(IPv4_ADDRESS), gE.getIPv4Address());
    Assert.assertEquals(
        IPUtilsHelper.getPrefixFromIp(IPv4_ADDRESS),
        IPUtilsHelper.parseLongToShortIpv4NetMask(gE.getSubnetMask()));
    Assert.assertEquals(ProtocolIFType.IPV4, gE.getProtocolIFType());

    greService = greServices.get(1);
    Assert.assertEquals(TUNNEL_NAME, greService.getName());

    Assert.assertNotNull(greService.getGRETunnelConfiguration());
    greConfig = greService.getGRETunnelConfiguration();
    Assert.assertEquals(IP_SOURCE, greConfig.getSourceAddress());
    Assert.assertEquals(IP_DESTINY, greConfig.getDestinationAddress());

    Assert.assertEquals(greService.getProtocolEndpoint().size(), 1);
    pE = greService.getProtocolEndpoint().get(0);
    Assert.assertTrue(pE instanceof GRETunnelEndpoint);
    gE = (GRETunnelEndpoint) pE;
    Assert.assertEquals(IPUtilsHelper.getAddressFromIP(IPv6_ADDRESS), gE.getIPv6Address());
    Assert.assertEquals(
        IPUtilsHelper.getPrefixFromIp(IPv6_ADDRESS), String.valueOf(gE.getPrefixLength()));
    Assert.assertEquals(ProtocolIFType.IPV6, gE.getProtocolIFType());
  }