public void startLSP(LSPTE lsp, ERO eroRSVP) {
    lsp.setEro(eroRSVP);

    boolean check = resourceManager.checkResources(lsp);
    if (check == false) {
      // No Resources Available --> Remove LSP from List
      LSPList.remove(new LSPKey(localIP, lsp.getIdLSP()));

      // FIXME: Crear el pathErr para enviar
      // Creamos Path Error Message
      RSVPPathErrMessage PathErr = new RSVPPathErrMessage();
      log.warning("There are no resources available");
    } else {
      // FIXME: ver si añadimos la lambda al LSP en otro momento o no
      // de momento la información de lambda asociada la tenemos en el RSVP Manager
      // lsp.setLambda(resourceManager.getLambda());
      Inet4Address prox = null;
      RSVPTEPathMessage path = resourceManager.getRSVPTEPathMessageFromPCEPResponse(lsp);
      // prox = (resourceManager.getProxHopIPv4List()).get(new
      // LSPKey((resourceManager.getProxHopIPv4List()).keys().nextElement().getSourceAddress(),
      // (resourceManager.getProxHopIPv4List()).keys().nextElement().getLspId()));
      prox =
          (resourceManager.getProxHopIPv4List()).get(new LSPKey(lsp.getIdSource(), lsp.getIdLSP()));
      timeEnd_Node = System.nanoTime();
      log.info(
          "LSP Time to Process RSVP Path Mssg in Node (ms): "
              + ((timeEnd_Node - timeIni_Node) / 1000000)
              + " --> Sending RSVP path Message to "
              + prox.toString()
              + " !");
      sendRSVPMessage(path, prox);
    }
  }
 public void teardownLSP(LSPTE lsp) {
   resourceManager.freeResources(lsp);
   RSVPPathTearMessage tear = new RSVPPathTearMessage();
   tear = resourceManager.getRSVPPathTearMessage(lsp);
   Inet4Address prox =
       resourceManager.getProxHopIPv4List().get(new LSPKey(lsp.getIdSource(), lsp.getIdLSP()));
   log.info("Sending RSVP PATH Tear Message to " + prox.toString());
   sendRSVPMessage(tear, prox);
 }
  /**
   * Method to add a new TE LSP from a previous Path message received
   *
   * @param lsp
   * @param path
   */
  public void forwardRSVPpath(LSPTE lsp, RSVPTEPathMessage path) throws LSPCreationException {
    log.info("Forwarding and Processing RSVP Path Message");
    int nodeType = LSPParameters.LSP_NODE_TYPE_TRANSIT;

    if (lsp == null) log.info("Cosa Mala...");
    if (lsp.getIdDestination() == null) log.info("IPDest is null");
    if (localIP == null) log.info("IPLocal is null");
    log.info(
        "Comparando: "
            + lsp.getIdDestination().getHostAddress()
            + " y "
            + localIP.getHostAddress());
    if ((lsp.getIdDestination().getHostAddress()).equals(localIP.getHostAddress())) {
      nodeType = LSPParameters.LSP_NODE_TYPE_DESTINATION;
      log.info("New LSP, I am node Destination!");
    }
    /*
     	log.info("localIP.getHostAddress()::"+localIP.getHostAddress());
     	if(localIP.getHostAddress().equals("192.168.1.8"))
     	{

     	}

     	if(localIP.getHostAddress().equals("192.168.1.9"))
     	{
     		nodeType = LSPParameters.LSP_NODE_TYPE_DESTINATION;
     	}
    */
    // DESTINATION NODE //

    if (nodeType == LSPParameters.LSP_NODE_TYPE_DESTINATION) {
      // crear el RSPV RESV y enviarlo de vuelta

      RSVPTEResvMessage resv = new RSVPTEResvMessage();

      resv = resourceManager.getRSVPResvMessageFromDestination(path, lsp);

      LSPKey key = new LSPKey(lsp.getIdSource(), lsp.getIdLSP());

      // Guardamos el LSP en la lista
      LSPList.put(key, lsp);

      // Enviamos el mensaje
      if (resv != null) {
        Inet4Address prox = resourceManager.getPreviousHopIPv4List().get(key);
        timeEnd_Node = System.nanoTime();
        log.info("LSP Time Path Node Process (ms): " + ((timeEnd_Node - timeIni_Node) / 1000000));
        log.info("Sending RSVP Resv message to " + prox.toString() + " !");
        sendRSVPMessage(resv, prox);
      }
      // TRANSIT NODE //
    } else if (nodeType == LSPParameters.LSP_NODE_TYPE_TRANSIT) {
      log.info("New LSP, I am transit node");

      ERO eroRSVP = new ERO();
      LinkedList<EROSubobject> clone =
          (LinkedList<EROSubobject>) path.getEro().getEroSubobjects().clone();
      eroRSVP.setEroSubobjects(clone);
      lsp.setEro(eroRSVP);

      boolean check = resourceManager.checkResources(lsp);
      if (check == false) {
        log.info("Error! No Resources in the Node!");
        throw new LSPCreationException(LSPCreationErrorTypes.NO_RESOURCES);
      } else {
        LSPKey key = new LSPKey(lsp.getIdSource(), lsp.getIdLSP());

        // Put the LSP in the list
        LSPList.put(key, lsp);

        RSVPTEPathMessage NewPath = resourceManager.forwardRSVPpath(lsp, path);
        timeEnd_Node = System.nanoTime();
        log.info(
            "LSP Time to Process RSVP Path in Node (ms): "
                + ((timeEnd_Node - timeIni_Node) / 1000000));
        Inet4Address prox = (resourceManager.getProxHopIPv4List()).get(key);
        log.info("Sending the RSVP PATH message to " + prox.toString() + " !");
        sendRSVPMessage(NewPath, prox);
      }
    }
  }
  /**
   * startLSP() Envía y recibe la respuesta del PCE con la ruta calculada Se encarga de crear el
   * mensaje RSVP path y enviarlo al primera nodo de destino
   *
   * <p>Hay que comprobar si tenemos interfaz disponible en el roadm para que enviar los datos. *
   *
   * @throws LSPCreationException
   */
  public void startLSP(LSPTE lsp) throws LSPCreationException {
    // Get specific request from Resource Manager
    PCEPRequest req = resourceManager.getPCEPRequest(lsp);
    // Send Request to the PCE
    PCEPResponse pr;

    try {
      pr = pcc.getCrm().newRequest(req);
    } catch (Exception e) {
      log.info(UtilsFunctions.exceptionToString(e));
      throw new LSPCreationException(LSPCreationErrorTypes.ERROR_REQUEST);
    }
    // No Response from PCE
    if (pr == null) {
      LSPList.remove(new LSPKey(localIP, lsp.getIdLSP()));
      throw new LSPCreationException(LSPCreationErrorTypes.NO_RESPONSE);
    }
    Response resp = pr.getResponse(0);
    // Response No Path from PCE
    if (resp.getNoPath() != null) {
      log.info("Response : No PATH: --> " + resp.getNoPath().toString());
      lsp.setPcepResponse(resp);
      LSPList.remove(new LSPKey(localIP, lsp.getIdLSP()));
      throw new LSPCreationException(LSPCreationErrorTypes.NO_PATH);
    }
    ERO eroRSVP = new ERO();
    if (rsvpMode == false) {
      log.info("Response : " + pr.toString());
      log.info("RSVP Mode false --> enviamos Notify LSP Established");
      established = true;
      lsp.setPcepResponse(resp);

      LinkedList<EROSubobject> clone =
          (LinkedList<EROSubobject>)
              resp.getPathList().get(0).geteRO().getEROSubobjectList().clone();
      eroRSVP.setEroSubobjects(clone);
      lsp.setEro(eroRSVP);
    } else {
      log.info("Response : " + pr.toString());
      // saveEroStats(resp.getPath(0).geteRO());
      // Response OK
      lsp.setPcepResponse(resp);
      if (resp.getPathList().get(0).geteRO() != null) {
        LinkedList<EROSubobject> clone =
            (LinkedList<EROSubobject>)
                resp.getPathList().get(0).geteRO().getEROSubobjectList().clone();
        eroRSVP.setEroSubobjects(clone);
        lsp.setEro(eroRSVP);

        boolean check = resourceManager.checkResources(lsp);
        if (check == false) {
          // No Resources Available --> Remove LSP from List
          LSPList.remove(new LSPKey(localIP, lsp.getIdLSP()));

          // FIXME: Crear el pathErr para enviar
          // Creamos Path Error Message
          RSVPPathErrMessage PathErr = new RSVPPathErrMessage();
          log.warning("There are no resources available");
          throw new LSPCreationException(LSPCreationErrorTypes.NO_RESOURCES);
        } else {
          // FIXME: ver si añadimos la lambda al LSP en otro momento o no
          // de momento la información de lambda asociada la tenemos en el RSVP Manager
          // lsp.setLambda(resourceManager.getLambda());
          Inet4Address prox = null;
          RSVPTEPathMessage path = resourceManager.getRSVPTEPathMessageFromPCEPResponse(lsp);
          // prox = (resourceManager.getProxHopIPv4List()).get(new
          // LSPKey((resourceManager.getProxHopIPv4List()).keys().nextElement().getSourceAddress(),
          // (resourceManager.getProxHopIPv4List()).keys().nextElement().getLspId()));
          prox =
              (resourceManager.getProxHopIPv4List())
                  .get(new LSPKey(lsp.getIdSource(), lsp.getIdLSP()));
          timeEnd_Node = System.nanoTime();
          log.info(
              "LSP Time to Process RSVP Path Mssg in Node (ms): "
                  + ((timeEnd_Node - timeIni_Node) / 1000000)
                  + " --> Sending RSVP path Message to "
                  + prox.toString()
                  + " !");
          sendRSVPMessage(path, prox);
        }
      } else if (resp.getPathList().get(0).geteRO() != null) {
        ExplicitRouteObject srero = new ExplicitRouteObject();
        LinkedList<EROSubobject> clone =
            (LinkedList<EROSubobject>)
                resp.getPathList().get(0).geteRO().getEROSubobjectList().clone();
        srero.setEROSubobjectList(clone);
        lsp.setSRERO(srero);
        log.info("SID encontrado: " + srero.toString());

        //				boolean check = resourceManager.checkResources(lsp);
        //				if (check==false){
        //					// No Resources Available --> Remove LSP from List
        //					LSPList.remove(new LSPKey(localIP, lsp.getIdLSP()));
        //
        //					//FIXME: Crear el pathErr para enviar
        //					//Creamos Path Error Message
        //					RSVPPathErrMessage PathErr = new RSVPPathErrMessage();
        //					log.warning("There are no resources available");
        //					throw new LSPCreationException(LSPCreationErrorTypes.NO_RESOURCES);
        //				}else{
        //					//FIXME: ver si añadimos la lambda al LSP en otro momento o no
        //					// de momento la información de lambda asociada la tenemos en el RSVP Manager
        //					//lsp.setLambda(resourceManager.getLambda());
        //					Inet4Address prox = null;
        //					RSVPTEPathMessage path = resourceManager.getRSVPTEPathMessageFromPCEPResponse(lsp);
        //					//prox = (resourceManager.getProxHopIPv4List()).get(new
        // LSPKey((resourceManager.getProxHopIPv4List()).keys().nextElement().getSourceAddress(),
        // (resourceManager.getProxHopIPv4List()).keys().nextElement().getLspId()));
        //					prox = (resourceManager.getProxHopIPv4List()).get(new LSPKey(lsp.getIdSource(),
        // lsp.getIdLSP()));
        //					timeEnd_Node=System.nanoTime();
        //					log.info("LSP Time to Process RSVP Path Mssg in Node (ms):
        // "+((timeEnd_Node-timeIni_Node)/1000000) + " --> Sending RSVP path Message to
        // "+prox.toString()+" !");
        //					sendRSVPMessage(path,prox);
        //				}

      }
    }
  }