コード例 #1
0
ファイル: UpDownTest.java プロジェクト: eliRigol/opennaas
  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");
  }
コード例 #2
0
  /*
   * (non-Javadoc)
   *
   * @see org.opennaas.extensions.router.capability.ip.IIPCapability#setIPv4(org.opennaas.extensions.router.model.LogicalPort)
   */
  @Override
  public void setIPv4(LogicalDevice iface, IPProtocolEndpoint ipProtocolEndpoint)
      throws CapabilityException {
    NetworkPort param = new NetworkPort();
    param.setName(iface.getName());
    if (iface instanceof NetworkPort) {
      param.setPortNumber(((NetworkPort) iface).getPortNumber());
      param.setLinkTechnology(((NetworkPort) iface).getLinkTechnology());
    }
    IPProtocolEndpoint ip = new IPProtocolEndpoint();
    ip.setIPv4Address(ipProtocolEndpoint.getIPv4Address());
    ip.setSubnetMask(ipProtocolEndpoint.getSubnetMask());
    param.addProtocolEndpoint(ipProtocolEndpoint);

    IAction action = createActionAndCheckParams(IPActionSet.SET_IPv4, param);
    queueAction(action);
  }
コード例 #3
0
ファイル: UpDownTest.java プロジェクト: eliRigol/opennaas
  @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);
    }
  }