@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());
  }
  /**
   * Parses logical routers data from message and puts it into routerModel.
   *
   * @param routerModel to store parsed data
   * @param message to parse logical routers data from
   * @return routerModel updated with logical routers information from message.
   * @throws IOException
   * @throws SAXException
   */
  private System parseLRs(System routerModel, String message) throws IOException, SAXException {

    // remove LR from the model before parsing new configuration
    routerModel.removeAllremoveManagedSystemElementByType(ComputerSystem.class);

    DigesterEngine listLogicalRoutersParser = new ListLogicalRoutersParser();
    listLogicalRoutersParser.init();
    listLogicalRoutersParser.configurableParse(new ByteArrayInputStream(message.getBytes()));

    // put new LR in the model
    for (String key : listLogicalRoutersParser.getMapElements().keySet()) {
      ComputerSystem system = new ComputerSystem();
      system.setName((String) listLogicalRoutersParser.getMapElements().get(key));
      routerModel.addManagedSystemElement(system);
    }

    return routerModel;
  }
  @Test
  public void testGREDeleteTunnelAction() throws CapabilityException, ProtocolException {
    log.info("TEST GRE TUNNEL ACTION");
    IGRETunnelCapability greCapability =
        (IGRETunnelCapability)
            routerResource.getCapability(
                InitializerTestHelper.getCapabilityInformation(TestsConstants.GRE_CAPABILITY_TYPE));

    // add gre tunnel service to the router model.
    GRETunnelService greTunnelService = new GRETunnelService();
    greTunnelService.setName(TUNNEL_NAME);

    ComputerSystem model = (ComputerSystem) routerResource.getModel();
    model.addHostedService(greTunnelService);
    routerResource.setModel(model);

    greCapability.deleteGRETunnel(
        ParamCreationHelper.getGRETunnelService(TUNNEL_NAME, null, null, null, null));

    IQueueManagerCapability queueCapability =
        (IQueueManagerCapability)
            routerResource.getCapability(
                InitializerTestHelper.getCapabilityInformation(
                    TestsConstants.QUEUE_CAPABILIY_TYPE));

    List<IAction> queue = (List<IAction>) queueCapability.getActions();
    Assert.assertEquals(queue.size(), 1);

    QueueResponse queueResponse = (QueueResponse) queueCapability.execute();
    Assert.assertEquals(queueResponse.getResponses().size(), 1);

    Assert.assertEquals(queueResponse.getPrepareResponse().getStatus(), ActionResponse.STATUS.OK);
    Assert.assertEquals(queueResponse.getConfirmResponse().getStatus(), ActionResponse.STATUS.OK);
    Assert.assertEquals(queueResponse.getRefreshResponse().getStatus(), ActionResponse.STATUS.OK);
    Assert.assertEquals(
        queueResponse.getRestoreResponse().getStatus(), ActionResponse.STATUS.PENDING);

    Assert.assertTrue(queueResponse.isOk());

    queue = (List<IAction>) queueCapability.getActions();
    Assert.assertEquals(queue.size(), 0);
  }
Beispiel #4
0
  private LogicalDevice getLogicalDevice(String nameInterface, ComputerSystem router)
      throws Exception {
    Iterator<LogicalDevice> iterator = router.getLogicalDevices().iterator();

    while (iterator.hasNext()) {
      LogicalDevice logicalDevice = iterator.next();
      if (logicalDevice.getName().equals(nameInterface)) return logicalDevice;
    }

    throw new Exception("Not found logical device");
  }
Beispiel #5
0
  @Test
  public void UpDownActionTest() throws CapabilityException {
    Response resp;
    QueueResponse queueResponse;

    resp = (Response) chassisCapability.sendMessage(ActionConstants.GETCONFIG, null);
    Assert.assertEquals(Status.QUEUED, resp.getStatus());
    Assert.assertTrue(resp.getErrors().size() == 0);

    queueResponse = (QueueResponse) queueCapability.sendMessage(QueueConstants.EXECUTE, null);
    Assert.assertTrue(queueResponse.isOk());

    String str = "";
    ComputerSystem model = (ComputerSystem) mockResource.getModel();
    Assert.assertNotNull(model);
    for (LogicalDevice device : model.getLogicalDevices()) {
      if (device instanceof EthernetPort) {
        EthernetPort port = (EthernetPort) device;
        Assert.assertNotNull("OperationalStatus must be set", port.getOperationalStatus());

        str += "- EthernetPort: " + '\n';
        str += port.getName() + '.' + port.getPortNumber() + '\n';
        str += port.getOperationalStatus();
        str += '\n';
        for (ProtocolEndpoint protocolEndpoint : port.getProtocolEndpoint()) {
          if (protocolEndpoint instanceof IPProtocolEndpoint) {
            IPProtocolEndpoint ipProtocol = (IPProtocolEndpoint) protocolEndpoint;
            str += "ipv4: " + ipProtocol.getIPv4Address() + '\n';
            str += "ipv6: " + ipProtocol.getIPv6Address() + '\n';
          }
        }

      } else {
        str += "not searched device";
      }
    }

    log.info(str);

    String interfaceName = "fe-0/1/3";

    /* check model */
    LogicalDevice logicalDevice = null;
    try {
      logicalDevice = getLogicalDevice(interfaceName, (ComputerSystem) mockResource.getModel());
    } catch (Exception ex) {
      Assert.fail("LogicalDevice not found");
    }

    if (logicalDevice.getOperationalStatus() != OperationalStatus.OK) {
      Assert.fail("The test can't be executed because the needed interface is down");
    }

    /* send to change status */
    resp =
        (Response)
            chassisCapability.sendMessage(
                ActionConstants.CONFIGURESTATUS,
                newParamsConfigureStatus(interfaceName, OperationalStatus.STOPPED));
    Assert.assertEquals(Status.QUEUED, resp.getStatus());
    Assert.assertTrue(resp.getErrors().size() == 0);

    Assert.assertTrue(
        ((List<IAction>) queueCapability.sendMessage(QueueConstants.GETQUEUE, null)).size() == 1);
    queueResponse = (QueueResponse) queueCapability.sendMessage(QueueConstants.EXECUTE, null);
    Assert.assertTrue(queueResponse.isOk());
    Assert.assertTrue(
        ((List<IAction>) queueCapability.sendMessage(QueueConstants.GETQUEUE, null)).size() == 0);

    if (!isMock) {
      checkOperationalStatus(
          (ComputerSystem) mockResource.getModel(), interfaceName, OperationalStatus.STOPPED);
    }

    /* send to change status */
    resp =
        (Response)
            chassisCapability.sendMessage(
                ActionConstants.CONFIGURESTATUS,
                newParamsConfigureStatus(interfaceName, OperationalStatus.OK));
    Assert.assertEquals(Status.QUEUED, resp.getStatus());
    Assert.assertTrue(resp.getErrors().size() == 0);

    Assert.assertTrue(
        ((List<IAction>) queueCapability.sendMessage(QueueConstants.GETQUEUE, null)).size() == 1);
    queueResponse = (QueueResponse) queueCapability.sendMessage(QueueConstants.EXECUTE, null);
    Assert.assertTrue(queueResponse.isOk());
    Assert.assertTrue(
        ((List<IAction>) queueCapability.sendMessage(QueueConstants.GETQUEUE, null)).size() == 0);

    if (!isMock) {
      checkOperationalStatus(
          (ComputerSystem) mockResource.getModel(), interfaceName, OperationalStatus.OK);
    }
  }
Beispiel #6
0
  private static IModel getComputerSystem() {

    ComputerSystem model = new ComputerSystem();
    model.addHostedService(getGRETunnelService());
    return model;
  }
 public static ComputerSystem newParamsLRWithInterface(String lrName) {
   ComputerSystem lrModel = new ComputerSystem();
   lrModel.setName(lrName);
   lrModel.setElementName(lrName);
   return lrModel;
 }
 public static ComputerSystem getLogicalRouter(String lrName) {
   ComputerSystem lrModel = new ComputerSystem();
   lrModel.setName(lrName);
   lrModel.setElementName(lrName);
   return lrModel;
 }