@Test
  public void testExecuteforLogicalTunnel() throws ActionException {

    LogicalPort ltIface = createLogicalTunnelPort("lt-1/2/0", 12);
    ltIface = addVlanToIface(ltIface, 2);

    setVlanAction.setParams(ltIface);
    ActionResponse response = setVlanAction.execute(protocolSessionManager);
    Assert.assertEquals(ActionConstants.SET_VLANID, response.getActionID());
    List<Response> responses = response.getResponses();
    for (Response resp : responses) {
      Assert.assertEquals(Response.Status.OK, resp.getStatus());
    }

    // FIXME This test fails due to mock router not filering config
    // setEncapsulationAction.setParams(ltIface);
    // response = setEncapsulationAction.execute(protocolSessionManager);
    // Assert.assertEquals(ActionConstants.SET_TAGGEDETHERNET_ENCAPSULATION,
    // response.getActionID());
    // responses = response.getResponses();
    // for (Response resp : responses) {
    // Assert.assertEquals(Response.Status.OK, resp.getStatus());
    // }

    removeEncapsulationAction.setParams(ltIface);
    response = removeEncapsulationAction.execute(protocolSessionManager);
    Assert.assertEquals(
        ActionConstants.REMOVE_TAGGEDETHERNET_ENCAPSULATION, response.getActionID());
    responses = response.getResponses();
    for (Response resp : responses) {
      Assert.assertEquals(Response.Status.OK, resp.getStatus());
    }
  }
  /**
   * TODO, it is necessary to implement the dummy state to configure vlans
   *
   * @throws ActionException
   */
  @Test
  public void testExecuteforETH() throws ActionException {

    LogicalPort feIface = createEthernetPort("fe-0/3/2", 4);
    feIface = addVlanToIface(feIface, 3);

    setVlanAction.setParams(feIface);
    ActionResponse response = setVlanAction.execute(protocolSessionManager);
    Assert.assertEquals(ActionConstants.SET_VLANID, response.getActionID());
    List<Response> responses = response.getResponses();
    for (Response resp : responses) {
      Assert.assertEquals(Response.Status.OK, resp.getStatus());
    }

    // An interface with vlan-tagging and subinterfaces with vlans
    LogicalPort phyFeIface = createPhysicalInterface("fe-0/1/3");

    // FIXME This test fails due to mock router not filering config
    // setEncapsulationAction.setParams(phyFeIface);
    // response = setEncapsulationAction.execute(protocolSessionManager);
    // Assert.assertEquals(ActionConstants.SET_TAGGEDETHERNET_ENCAPSULATION,
    // response.getActionID());
    // responses = response.getResponses();
    // for (Response resp : responses) {
    // Assert.assertEquals(Response.Status.OK, resp.getStatus());
    // }

    try {
      removeEncapsulationAction.setParams(phyFeIface);
      response = removeEncapsulationAction.execute(protocolSessionManager);
      // Assert.assertEquals(ActionConstants.REMOVE_TAGGEDETHERNET_ENCAPSULATION,
      // response.getActionID());
      // responses = response.getResponses();
      // for (Response resp : responses) {
      // Assert.assertEquals(Response.Status.OK, resp.getStatus());
      // }
    } catch (ActionException e) {
      Assert.assertTrue(
          e.getLocalizedMessage()
              .contains(
                  "Interface has subinterfaces with vlanId. Please remove them before changing encapsulation."));
    }
  }
示例#3
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);
    }
  }
  @Test
  public void MakeRemoveConnectionsResourceTest() throws Exception {

    ResourceDescriptor resourceDescriptor = ResourceHelper.newResourceDescriptorProteus("roadm");

    /* create resource */
    Resource resource = (Resource) repository.createResource(resourceDescriptor);

    Assert.assertNotNull(resource.getResourceIdentifier());
    Assert.assertNotNull(resource.getResourceDescriptor());
    Assert.assertTrue(resource.getCapabilities().isEmpty());
    Assert.assertNull(resource.getModel());
    Assert.assertNull(resource.getProfile());

    Assert.assertFalse(repository.listResources().isEmpty());

    // add protocol for resource
    createProtocolForResource(resource.getResourceIdentifier().getId());

    /* start resource */
    repository.startResource(resource.getResourceIdentifier().getId());
    Assert.assertFalse(resource.getCapabilities().isEmpty());
    Assert.assertNotNull(resource.getModel());
    // Assert.assertNotNull(resource.getProfile());

    IConnectionsCapability connections =
        (IConnectionsCapability) resource.getCapabilityByInterface(IConnectionsCapability.class);
    if (connections == null) Assert.fail("Capability not found");
    IQueueManagerCapability queueCapability =
        (IQueueManagerCapability) resource.getCapabilityByInterface(IQueueManagerCapability.class);
    if (queueCapability == null) Assert.fail("Capability not found");

    /* checking model */
    // TODO CHECK NEW MODEL CONFIG

    /* refresh connection */
    // Response resp = (Response) connections.sendMessage(ActionConstants.REFRESHCONNECTIONS, null);
    // List<ActionResponse> responses = (List<ActionResponse>)
    // queueCapability.sendMessage(QueueManagerConstants.EXECUTE, null);
    //
    // Assert.assertTrue(responses.size() == 2);
    // ActionResponse actionResponse = responses.get(0);
    // Assert.assertEquals(ActionConstants.REFRESHCONNECTIONS, actionResponse.getActionID());
    // for (Response response : actionResponse.getResponses()) {
    // Assert.assertTrue(response.getStatus() == Response.Status.OK);
    // }
    //
    // List<IAction> queue = (List<IAction>)
    // queueCapability.sendMessage(QueueManagerConstants.GETQUEUE, null);
    // Assert.assertTrue(queue.size() == 0);

    OpticalSwitchFactory opticalSwitchFactory = new OpticalSwitchFactory();
    resource.setModel(opticalSwitchFactory.newPedrosaProteusOpticalSwitch());

    /* make connection */
    FiberConnection connectionRequest =
        newMakeConnectionParams((ProteusOpticalSwitch) resource.getModel());
    connections.makeConnection(connectionRequest);
    QueueResponse queueResponse = queueCapability.execute();

    Assert.assertTrue(queueResponse.isOk());

    boolean foundAndOk = false;
    for (ActionResponse response : queueResponse.getResponses()) {
      if (response.getActionID().equals(ActionConstants.MAKECONNECTION)) {
        if (response.getStatus() == STATUS.OK) {
          foundAndOk = true;
          for (Response subresponse : response.getResponses()) {
            Assert.assertTrue(subresponse.getStatus() == Response.Status.OK);
          }
        }
      }
    }
    Assert.assertTrue(foundAndOk);

    List<IAction> queue = (List<IAction>) queueCapability.getActions();
    Assert.assertTrue(queue.size() == 0);

    /* checking model */
    Assert.assertNotNull(
        getFiberConnection(connectionRequest, (ProteusOpticalSwitch) resource.getModel()));
    // checking for model intern details is in action tests

    /* remove connection */
    connections.removeConnection(connectionRequest);
    queueResponse = (QueueResponse) queueCapability.execute();

    Assert.assertTrue(queueResponse.isOk());

    foundAndOk = false;
    for (ActionResponse response : queueResponse.getResponses()) {
      if (response.getActionID().equals(ActionConstants.REMOVECONNECTION)) {
        if (response.getStatus() == STATUS.OK) {
          foundAndOk = true;
          for (Response subresponse : response.getResponses()) {
            Assert.assertTrue(subresponse.getStatus() == Response.Status.OK);
          }
        }
      }
    }
    Assert.assertTrue(foundAndOk);

    queue = (List<IAction>) queueCapability.getActions();
    Assert.assertTrue(queue.size() == 0);

    /* checking model */
    Assert.assertNull(
        getFiberConnection(connectionRequest, (ProteusOpticalSwitch) resource.getModel()));

    /* stop resource */
    repository.stopResource(resource.getResourceIdentifier().getId());

    Assert.assertNotNull(resource.getResourceIdentifier());
    Assert.assertNotNull(resource.getResourceDescriptor());
    Assert.assertTrue(resource.getCapabilities().isEmpty());
    Assert.assertNull(resource.getModel());
    // Assert.assertNull(resource.getProfile());
    Assert.assertFalse(repository.listResources().isEmpty());

    /* remove resource */

    createProtocolForResource(resource.getResourceIdentifier().getId());
    repository.removeResource(resource.getResourceIdentifier().getId());

    Assert.assertTrue(resource.getCapabilities().isEmpty());
    Assert.assertNull(resource.getModel());
    Assert.assertNull(resource.getProfile());
    // Assert.assertTrue(repository.listResources().isEmpty());
  }