Example #1
0
  /**
   * Stop all forwards giving the resource ID of the <i>SSL-Tunnel</i> that started them.
   *
   * @param launchSession launch session
   * @throws NoPermissionException if not allowed
   * @throws CoreException on any other error
   */
  public void stopTunnels(LaunchSession launchSession) throws NoPermissionException, CoreException {
    if (!DefaultAgentManager.getInstance().hasActiveAgent(launchSession.getSession())) {
      throw new TunnelException(TunnelException.INTERNAL_ERROR, (Throwable) null, "No agent.");
    }

    Tunnel tunnel = (Tunnel) launchSession.getResource();
    launchSession.checkAccessRights(null, agent.getSession());
    MultiplexedConnection agent =
        DefaultAgentManager.getInstance().getAgentBySession(launchSession.getSession());

    try {
      if (tunnel.getType() == TransportType.LOCAL_TUNNEL_ID) {
        Collection<Tunnel> l = new ArrayList<Tunnel>();
        l.add(tunnel);
        stopLocalTunnels(agent, l);
      } else if (tunnel.getType() == TransportType.REMOTE_TUNNEL_ID) {
        Collection<Tunnel> l = new ArrayList<Tunnel>();
        l.add(tunnel);
        stopRemoteTunnels(agent, l);
      } else {
        throw new TunnelException(
            TunnelException.INTERNAL_ERROR,
            (Throwable) null,
            "Unknown tunnel type " + tunnel.getType());
      }

      CoreServlet.getServlet()
          .fireCoreEvent(
              new ResourceAccessEvent(
                  this,
                  TunnelsEventConstants.TUNNEL_CLOSED,
                  launchSession.getResource(),
                  launchSession.getPolicy(),
                  launchSession.getSession(),
                  CoreEvent.STATE_SUCCESSFUL));

    } catch (TunnelException te) {
      CoreServlet.getServlet()
          .fireCoreEvent(
              new ResourceAccessEvent(
                  this,
                  TunnelsEventConstants.TUNNEL_CLOSED,
                  launchSession.getResource(),
                  launchSession.getPolicy(),
                  launchSession.getSession(),
                  te));
      throw te;
    } finally {
      LaunchSessionFactory.getInstance().removeLaunchSession(launchSession);
    }
  }
Example #2
0
  /**
   * Start port forwards for the <i>SSL Tunnel</i> specified by the provided resource ID.
   *
   * @param launchSession launch session
   * @throws NoPermissionException if not allowed
   * @throws TunnelException on any other other
   * @throws PolicyException on any other determininig policy
   */
  public void startTunnel(LaunchSession launchSession)
      throws NoPermissionException, TunnelException, PolicyException {

    if (!DefaultAgentManager.getInstance().hasActiveAgent(launchSession.getSession())) {
      throw new TunnelException(TunnelException.INTERNAL_ERROR, (Throwable) null, "No agent.");
    } else {
      Tunnel tunnel = (Tunnel) launchSession.getResource();
      launchSession.checkAccessRights(null, agent.getSession());
      AgentTunnel agent =
          DefaultAgentManager.getInstance().getAgentBySession(launchSession.getSession());

      try {
        if (tunnel.getType() == TransportType.LOCAL_TUNNEL_ID) {
          startLocalTunnel(agent, tunnel, launchSession);
        } else if (tunnel.getType() == TransportType.REMOTE_TUNNEL_ID) {
          startRemoteTunnel(agent, tunnel, launchSession);
        } else {
          throw new TunnelException(
              TunnelException.INTERNAL_ERROR,
              (Throwable) null,
              "Unknown tunnel type " + tunnel.getType());
        }

        // Fire event
        CoreServlet.getServlet()
            .fireCoreEvent(
                new ResourceAccessEvent(
                    this,
                    TunnelsEventConstants.TUNNEL_OPENED,
                    launchSession.getResource(),
                    launchSession.getPolicy(),
                    launchSession.getSession(),
                    CoreEvent.STATE_SUCCESSFUL));
      } catch (TunnelException te) {

        // Fire event
        CoreServlet.getServlet()
            .fireCoreEvent(
                new ResourceAccessEvent(
                    this,
                    TunnelsEventConstants.TUNNEL_OPENED,
                    launchSession.getResource(),
                    launchSession.getPolicy(),
                    launchSession.getSession(),
                    te));

        throw te;
      }
    }
  }
 @Override
 public void removeTunnel(final Requests request, final PccSession session) {
   final PlspId plspId = request.getLsp().getPlspId();
   final Tunnel tunnel = this.tunnels.get(plspId);
   final long srpId = request.getSrp().getOperationId().getValue();
   if (tunnel != null) {
     if (tunnel.getType() == LspType.PCE_LSP) {
       if (hasDelegation(tunnel, session)) {
         this.tunnels.remove(plspId);
         sendToAll(
             tunnel,
             plspId,
             tunnel.getLspState().getEro().getSubobject(),
             new SrpBuilder(request.getSrp())
                 .addAugmentation(Srp1.class, new Srp1Builder().setRemove(true).build())
                 .build(),
             reqToRptPath(request),
             request.getLsp());
       } else {
         session.sendError(
             MsgBuilderUtil.createErrorMsg(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, srpId));
       }
     } else {
       session.sendError(MsgBuilderUtil.createErrorMsg(PCEPErrors.LSP_NOT_PCE_INITIATED, srpId));
     }
   } else {
     session.sendError(MsgBuilderUtil.createErrorMsg(PCEPErrors.UNKNOWN_PLSP_ID, srpId));
   }
 }
Example #4
0
 public boolean processRequest(Request request, MultiplexedConnection connection) {
   AgentTunnel agent = (AgentTunnel) connection;
   if (request.getRequestName().equals(SETUP_AND_LAUNCH_TUNNEL)
       && request.getRequestData() != null) {
     try {
       ByteArrayReader reader = new ByteArrayReader(request.getRequestData());
       int id = (int) reader.readInt();
       Tunnel resource = (Tunnel) TunnelPlugin.SSL_TUNNEL_RESOURCE_TYPE.getResourceById(id);
       if (resource == null) {
         throw new Exception("No resource with ID " + id);
       }
       Policy policy =
           LaunchSessionManager.getLaunchRequestPolicy(null, agent.getSession(), resource);
       if (resource.sessionPasswordRequired(agent.getSession())) {
         // TODO: prompt user for credentials through agent!
         return true;
       } else {
         LaunchSession launchSession =
             LaunchSessionFactory.getInstance()
                 .createLaunchSession(agent.getSession(), resource, policy);
         launchSession.checkAccessRights(null, agent.getSession());
         if (resource.getType() == TransportType.LOCAL_TUNNEL_ID) {
           try {
             Request req = buildLocalTunnel(resource, launchSession);
             request.setRequestData(req.getRequestData());
             return true;
           } catch (IOException ioe) {
             throw new TunnelException(TunnelException.INTERNAL_ERROR, ioe);
           }
         } else if (resource.getType() == TransportType.REMOTE_TUNNEL_ID) {
           startRemoteTunnel(agent, resource, launchSession);
           request.setRequestData(null);
           return true;
         } else {
           throw new TunnelException(
               TunnelException.INTERNAL_ERROR,
               (Throwable) null,
               "Unknown tunnel type " + resource.getType());
         }
       }
     } catch (Exception e) {
       log.error("Failed to start tunnel.", e);
       return false;
     }
   }
   return false;
 }
Example #5
0
  Request buildLocalTunnel(Tunnel tunnel, LaunchSession launchSession) throws IOException {
    // Process destination host and port for replacement variables
    VariableReplacement r = new VariableReplacement();
    r.setLaunchSession(launchSession);
    String destHost = r.replace(tunnel.getDestination().getHost());

    ByteArrayWriter msg = new ByteArrayWriter();
    msg.writeString(launchSession == null ? "" : launchSession.getId());
    msg.writeInt(tunnel.getResourceId());
    msg.writeString(tunnel.getResourceName());
    msg.writeInt(tunnel.getType());
    msg.writeString(tunnel.getTransport());
    msg.writeString(tunnel.getSourceInterface());
    msg.writeInt(tunnel.getSourcePort());
    msg.writeInt(tunnel.getDestination().getPort());
    msg.writeString(destHost);
    Request req = new Request(START_LOCAL_TUNNEL, msg.toByteArray());
    return req;
  }
 @Override
 public void returnDelegation(final Updates update, final PccSession session) {
   final PlspId plspId = update.getLsp().getPlspId();
   final Tunnel tunnel = this.tunnels.get(plspId);
   final long srpId = update.getSrp().getOperationId().getValue();
   if (tunnel != null) {
     // check if session really has a delegation
     if (hasDelegation(tunnel, session)) {
       // send report D=0
       final Tlvs tlvs =
           createLspTlvs(
               plspId.getValue(),
               true,
               getDestinationAddress(tunnel.getLspState().getEro().getSubobject(), this.address),
               this.address,
               this.address,
               Optional.of(tunnel.getPathName()));
       session.sendReport(
           createPcRtpMessage(
               new LspBuilder(update.getLsp())
                   .setSync(true)
                   .setOperational(OperationalStatus.Up)
                   .setDelegate(false)
                   .setTlvs(tlvs)
                   .build(),
               Optional.of(createSrp(srpId)),
               tunnel.getLspState()));
       // start state timer
       startStateTimeout(tunnel, plspId);
       // if PCC's LSP, start re-delegation timer
       if (tunnel.getType() == LspType.PCC_LSP) {
         startRedelegationTimer(tunnel, plspId, session);
       } else {
         // if PCE-initiated LSP, revoke delegation instantly
         setDelegation(plspId, null);
       }
     } else {
       session.sendError(MsgBuilderUtil.createErrorMsg(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, srpId));
     }
   } else {
     session.sendError(MsgBuilderUtil.createErrorMsg(PCEPErrors.UNKNOWN_PLSP_ID, srpId));
   }
 }
 private void sendToAll(
     final Tunnel tunnel,
     final PlspId plspId,
     final List<Subobject> subobjects,
     final Srp srp,
     final Path path,
     final Lsp lsp) {
   for (final PccSession session : this.sessions.values()) {
     final boolean isDelegated = hasDelegation(tunnel, session);
     final Tlvs tlvs =
         createLspTlvs(
             plspId.getValue(),
             true,
             getDestinationAddress(subobjects, this.address),
             this.address,
             this.address,
             Optional.of(tunnel.getPathName()));
     final Pcrpt pcRpt =
         createPcRtpMessage(
             new LspBuilder(lsp)
                 .setPlspId(plspId)
                 .setOperational(OperationalStatus.Up)
                 .setDelegate(isDelegated)
                 .setSync(true)
                 .addAugmentation(
                     Lsp1.class,
                     new Lsp1Builder()
                         .setCreate(tunnel.getType() == LspType.PCE_LSP ? true : false)
                         .build())
                 .setTlvs(tlvs)
                 .build(),
             Optional.fromNullable(srp),
             path);
     session.sendReport(pcRpt);
   }
 }