Ejemplo n.º 1
0
 private RpcResult<NetconfMessage> createErrorRpcResult(
     RpcError.ErrorType errorType, String message) {
   return RpcResultBuilder.<NetconfMessage>failed()
       .withError(
           errorType, NetconfDocumentedException.ErrorTag.operation_failed.getTagValue(), message)
       .build();
 }
Ejemplo n.º 2
0
  /**
   * This method gets all necessary information for a system to construct a NSH header and
   * associated overlay packet to target the first service hop of a Rendered Service Path
   *
   * <p>
   *
   * @param input RPC input including a Rendered Service Path name
   * @return RPC output including a renderedServicePathFirstHop.
   */
  @Override
  public Future<RpcResult<ReadRenderedServicePathFirstHopOutput>> readRenderedServicePathFirstHop(
      ReadRenderedServicePathFirstHopInput input) {

    RenderedServicePathFirstHop renderedServicePathFirstHop = null;
    RpcResultBuilder<ReadRenderedServicePathFirstHopOutput> rpcResultBuilder;

    renderedServicePathFirstHop =
        SfcProviderRenderedPathAPI.readRenderedServicePathFirstHop(input.getName());

    ReadRenderedServicePathFirstHopOutput renderedServicePathFirstHopOutput = null;
    if (renderedServicePathFirstHop != null) {
      ReadRenderedServicePathFirstHopOutputBuilder renderedServicePathFirstHopOutputBuilder =
          new ReadRenderedServicePathFirstHopOutputBuilder();
      renderedServicePathFirstHopOutputBuilder.setRenderedServicePathFirstHop(
          renderedServicePathFirstHop);
      renderedServicePathFirstHopOutput = renderedServicePathFirstHopOutputBuilder.build();

      rpcResultBuilder = RpcResultBuilder.success(renderedServicePathFirstHopOutput);
    } else {
      String message = "Error Reading RSP First Hop from DataStore: " + input.getName();
      rpcResultBuilder =
          RpcResultBuilder.<ReadRenderedServicePathFirstHopOutput>failed()
              .withError(ErrorType.APPLICATION, message);
    }

    return Futures.immediateFuture(rpcResultBuilder.build());
  }
Ejemplo n.º 3
0
  @Override
  public Future<RpcResult<DeleteRenderedPathOutput>> deleteRenderedPath(
      DeleteRenderedPathInput input) {

    boolean ret;
    RpcResultBuilder<DeleteRenderedPathOutput> rpcResultBuilder;
    // If a RSP is deleted we delete both SF and SFF operational states.
    SfcProviderServiceForwarderAPI.deletePathFromServiceForwarderStateExecutor(input.getName());
    SfcProviderServiceFunctionAPI.deleteServicePathFromServiceFunctionStateExecutor(
        input.getName());

    ret = SfcProviderRenderedPathAPI.deleteRenderedServicePathExecutor(input.getName());
    DeleteRenderedPathOutputBuilder deleteRenderedPathOutputBuilder =
        new DeleteRenderedPathOutputBuilder();
    deleteRenderedPathOutputBuilder.setResult(ret);
    if (ret) {
      rpcResultBuilder = RpcResultBuilder.success(deleteRenderedPathOutputBuilder.build());
    } else {
      String message = "Error Deleting Rendered Service Path: " + input.getName();
      rpcResultBuilder =
          RpcResultBuilder.<DeleteRenderedPathOutput>failed()
              .withError(ErrorType.APPLICATION, message);
    }

    return Futures.immediateFuture(rpcResultBuilder.build());
  }
Ejemplo n.º 4
0
 @Override
 public RpcResult<TransactionStatus> apply(final DOMRpcResult input) {
   if (isSuccess(input)) {
     return RpcResultBuilder.success(TransactionStatus.COMMITED).build();
   } else {
     final RpcResultBuilder<TransactionStatus> failed = RpcResultBuilder.failed();
     for (final RpcError rpcError : input.getErrors()) {
       failed.withError(
           rpcError.getErrorType(),
           rpcError.getTag(),
           rpcError.getMessage(),
           rpcError.getApplicationTag(),
           rpcError.getInfo(),
           rpcError.getCause());
     }
     return failed.build();
   }
 }
Ejemplo n.º 5
0
  private void processMessage(final NetconfMessage message) {
    Request request = null;
    sessionLock.lock();
    try {
      request = requests.peek();
      if (request.future.isUncancellable()) {
        requests.poll();
      } else {
        request = null;
        logger.warn("{}: Ignoring unsolicited message {}", id, msgToS(message));
      }
    } finally {
      sessionLock.unlock();
    }

    if (request != null) {

      logger.debug("{}: Message received {}", id, message);

      if (logger.isTraceEnabled()) {
        logger.trace(
            "{}: Matched request: {} to response: {}",
            id,
            msgToS(request.request),
            msgToS(message));
      }

      try {
        NetconfMessageTransformUtil.checkValidReply(request.request, message);
      } catch (final NetconfDocumentedException e) {
        logger.warn(
            "{}: Invalid request-reply match, reply message contains different message-id, request: {}, response: {}",
            id,
            msgToS(request.request),
            msgToS(message),
            e);

        request.future.set(
            RpcResultBuilder.<NetconfMessage>failed()
                .withRpcError(NetconfMessageTransformUtil.toRpcError(e))
                .build());
        return;
      }

      try {
        NetconfMessageTransformUtil.checkSuccessReply(message);
      } catch (final NetconfDocumentedException e) {
        logger.warn(
            "{}: Error reply from remote device, request: {}, response: {}",
            id,
            msgToS(request.request),
            msgToS(message),
            e);

        request.future.set(
            RpcResultBuilder.<NetconfMessage>failed()
                .withRpcError(NetconfMessageTransformUtil.toRpcError(e))
                .build());
        return;
      }

      request.future.set(RpcResultBuilder.success(message).build());
    }
  }
Ejemplo n.º 6
0
  @Override
  public Future<RpcResult<CreateRenderedPathOutput>> createRenderedPath(
      CreateRenderedPathInput createRenderedPathInput) {

    ServiceFunctionPath createdServiceFunctionPath;
    RenderedServicePath renderedServicePath;
    RenderedServicePath revRenderedServicePath;
    CreateRenderedPathOutputBuilder createRenderedPathOutputBuilder =
        new CreateRenderedPathOutputBuilder();
    RpcResult<CreateRenderedPathOutput> rpcResult;
    String retRspName = null;

    createdServiceFunctionPath =
        SfcProviderServicePathAPI.readServiceFunctionPathExecutor(
            createRenderedPathInput.getParentServiceFunctionPath());

    if (createdServiceFunctionPath != null) {
      renderedServicePath =
          SfcProviderRenderedPathAPI.createRenderedServicePathAndState(
              createdServiceFunctionPath, createRenderedPathInput);
      if (renderedServicePath != null) {
        retRspName = renderedServicePath.getName();
        createRenderedPathOutputBuilder.setName(retRspName);
        rpcResult = RpcResultBuilder.success(createRenderedPathOutputBuilder.build()).build();

        if ((createdServiceFunctionPath.getClassifier() != null)
            && SfcProviderServiceClassifierAPI.readServiceClassifierExecutor(
                    createdServiceFunctionPath.getClassifier())
                != null) {
          SfcProviderServiceClassifierAPI.addRenderedPathToServiceClassifierStateExecutor(
              createdServiceFunctionPath.getClassifier(), renderedServicePath.getName());
        } else {
          LOG.warn("Classifier not provided or does not exist");
        }

        if ((createdServiceFunctionPath.isSymmetric() != null)
            && createdServiceFunctionPath.isSymmetric()) {

          revRenderedServicePath =
              SfcProviderRenderedPathAPI.createSymmetricRenderedServicePathAndState(
                  renderedServicePath);
          if (revRenderedServicePath == null) {
            LOG.error("Failed to create symmetric service path: {}");
          } else if ((createdServiceFunctionPath.getSymmetricClassifier() != null)
              && SfcProviderServiceClassifierAPI.readServiceClassifierExecutor(
                      createdServiceFunctionPath.getSymmetricClassifier())
                  != null) {
            SfcProviderServiceClassifierAPI.addRenderedPathToServiceClassifierStateExecutor(
                createdServiceFunctionPath.getSymmetricClassifier(),
                revRenderedServicePath.getName());

          } else {
            LOG.warn("Symmetric Classifier not provided or does not exist");
          }
        }
      } else {
        rpcResult =
            RpcResultBuilder.<CreateRenderedPathOutput>failed()
                .withError(ErrorType.APPLICATION, "Failed to create RSP")
                .build();
      }

    } else {
      rpcResult =
          RpcResultBuilder.<CreateRenderedPathOutput>failed()
              .withError(ErrorType.APPLICATION, "Service Function Path does not exist")
              .build();
    }
    return Futures.immediateFuture(rpcResult);
  }