@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));
   }
 }
Esempio n. 2
0
  protected GameState updateThis(float et) {
    music.update(et);
    factory.update(et, player.getSpeed());
    field.update(et);
    tunnel.update(et);
    float offset = -getNearClippingPlane() - player.getL() / 2;
    totalDistance += -player.getZ() + offset;
    distortion.translateZ(player, offset, player.getSpeed());
    tunnel.translateZ(player, offset);
    field.translateZ(player, offset);

    if (player.isAlive()) {
      return this;
    } else if (fadeOut > 0) {
      fadeOut -= FADE_OUT_RATE * et;
      return this;
    } else {
      // TODO: Better end-of-game
      System.out.println("Game over!");
      System.out.println("Your score: " + score);
      System.out.println("Your speed: " + player.getSpeed());
      System.out.println("Your distance: " + totalDistance);
      return null;
    }
  }
 private void setDelegation(final PlspId plspId, final PccSession session) {
   final Tunnel tunnel = this.tunnels.get(plspId);
   final int sessionId;
   if (session != null) {
     sessionId = session.getId();
   } else {
     sessionId = PCC_DELEGATION;
   }
   tunnel.setDelegationHolder(sessionId);
 }
Esempio n. 4
0
    private void doConnect(InetSocketAddress addr) throws IOException {
      dest = new Socket();
      try {
        dest.connect(addr, 10000);
      } catch (SocketTimeoutException ex) {
        sendError(HOST_UNREACHABLE);
        return;
      } catch (ConnectException cex) {
        sendError(CONN_REFUSED);
        return;
      }
      // Success
      InetAddress iadd = addr.getAddress();
      if (iadd instanceof Inet4Address) {
        out.write(PROTO_VERS);
        out.write(REQUEST_OK);
        out.write(0);
        out.write(IPV4);
        out.write(iadd.getAddress());
      } else if (iadd instanceof Inet6Address) {
        out.write(PROTO_VERS);
        out.write(REQUEST_OK);
        out.write(0);
        out.write(IPV6);
        out.write(iadd.getAddress());
      } else {
        sendError(GENERAL_FAILURE);
        return;
      }
      out.write((addr.getPort() >> 8) & 0xff);
      out.write((addr.getPort() >> 0) & 0xff);
      out.flush();

      InputStream in2 = dest.getInputStream();
      OutputStream out2 = dest.getOutputStream();

      Tunnel tunnel = new Tunnel(in2, out);
      tunnel.start();

      int b = 0;
      do {
        // Note that the socket might be closed from another thread (the tunnel)
        try {
          b = in.read();
          if (b == -1) {
            in.close();
            out2.close();
            return;
          }
          out2.write(b);
        } catch (IOException ioe) {
        }
      } while (!client.isClosed());
    }
Esempio n. 5
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);
    }
  }
Esempio n. 6
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;
      }
    }
  }
 private void startStateTimeout(final Tunnel tunnel, final PlspId plspId) {
   if (this.stateTimeout > -1) {
     final Timeout newStateTimeout =
         this.timer.newTimeout(
             new TimerTask() {
               @Override
               public void run(final Timeout timeout) throws Exception {
                 if (tunnel.getType() == LspType.PCE_LSP) {
                   PccTunnelManagerImpl.this.tunnels.remove(plspId);
                   // report tunnel removal to all
                   sendToAll(
                       tunnel,
                       plspId,
                       Collections.<Subobject>emptyList(),
                       createSrp(0),
                       new PathBuilder().build(),
                       createLsp(plspId.getValue(), false, Optional.<Tlvs>absent(), false, true));
                 }
               }
             },
             this.stateTimeout,
             TimeUnit.SECONDS);
     tunnel.setStateTimeout(newStateTimeout);
   }
 }
Esempio n. 8
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;
 }
 @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));
   }
 }
Esempio n. 10
0
    private void doBind(InetSocketAddress addr) throws IOException {
      ServerSocket svr = new ServerSocket();
      svr.bind(null);
      InetSocketAddress bad = (InetSocketAddress) svr.getLocalSocketAddress();
      out.write(PROTO_VERS);
      out.write(REQUEST_OK);
      out.write(0);
      out.write(IPV4);
      out.write(bad.getAddress().getAddress());
      out.write((bad.getPort() >> 8) & 0xff);
      out.write((bad.getPort() & 0xff));
      out.flush();
      dest = svr.accept();
      bad = (InetSocketAddress) dest.getRemoteSocketAddress();
      out.write(PROTO_VERS);
      out.write(REQUEST_OK);
      out.write(0);
      out.write(IPV4);
      out.write(bad.getAddress().getAddress());
      out.write((bad.getPort() >> 8) & 0xff);
      out.write((bad.getPort() & 0xff));
      out.flush();
      InputStream in2 = dest.getInputStream();
      OutputStream out2 = dest.getOutputStream();

      Tunnel tunnel = new Tunnel(in2, out);
      tunnel.start();

      int b = 0;
      do {
        // Note that the socket might be close from another thread (the tunnel)
        try {
          b = in.read();
          if (b == -1) {
            in.close();
            out2.close();
            return;
          }
          out2.write(b);
        } catch (IOException ioe) {
        }
      } while (!client.isClosed());
    }
Esempio n. 11
0
 @Override
 public void addTunnel(final Requests request, final PccSession session) {
   final PlspId plspId = new PlspId(this.plspIDsCounter.incrementAndGet());
   final Tunnel tunnel =
       new Tunnel(
           request.getLsp().getTlvs().getSymbolicPathName().getPathName().getValue(),
           session.getId(),
           LspType.PCE_LSP,
           reqToRptPath(request));
   sendToAll(
       tunnel,
       plspId,
       request.getEro().getSubobject(),
       createSrp(request.getSrp().getOperationId().getValue()),
       tunnel.getLspState(),
       new LspBuilder(request.getLsp())
           .addAugmentation(Lsp1.class, new Lsp1Builder().setCreate(true).build())
           .build());
   this.tunnels.put(plspId, tunnel);
 }
Esempio n. 12
0
 @Override
 public synchronized void onSessionUp(final PccSession session) {
   // first session - delegate all PCC's LSPs
   // only when reporting at startup
   if (!this.sessions.containsKey(session.getId()) && session.getId() == 0) {
     for (final PlspId plspId : this.tunnels.keySet()) {
       setDelegation(plspId, session);
     }
   }
   this.sessions.put(session.getId(), session);
   if (!this.tunnels.isEmpty()) {
     // report all known LSPs
     for (final Entry<PlspId, Tunnel> entry : this.tunnels.entrySet()) {
       final Tunnel tunnel = entry.getValue();
       final boolean delegation = hasDelegation(tunnel, session);
       if (delegation) {
         tunnel.cancelTimeouts();
       }
       final long plspId = entry.getKey().getValue();
       final Tlvs tlvs =
           MsgBuilderUtil.createLspTlvs(
               plspId,
               true,
               getDestinationAddress(tunnel.getLspState().getEro().getSubobject(), this.address),
               this.address,
               this.address,
               Optional.of(tunnel.getPathName()));
       session.sendReport(
           createPcRtpMessage(
               createLsp(plspId, true, Optional.<Tlvs>fromNullable(tlvs), delegation, false),
               NO_SRP,
               tunnel.getLspState()));
     }
     // end-of-sync marker
     session.sendReport(
         createPcRtpMessage(
             createLsp(0, false, Optional.<Tlvs>absent(), true, false),
             NO_SRP,
             createPath(Collections.<Subobject>emptyList())));
   }
 }
Esempio n. 13
0
 @Override
 public void reportToAll(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) {
     if (hasDelegation(tunnel, session)) {
       final Srp srp = createSrp(update.getSrp().getOperationId().getValue());
       final Path path = updToRptPath(update.getPath());
       final List<Subobject> subobjects = update.getPath().getEro().getSubobject();
       final Lsp lsp = update.getLsp();
       sendToAll(tunnel, plspId, subobjects, srp, path, lsp);
       // update tunnel state
       tunnel.setLspState(path);
     } else {
       session.sendError(MsgBuilderUtil.createErrorMsg(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, srpId));
     }
   } else {
     session.sendError(MsgBuilderUtil.createErrorMsg(PCEPErrors.UNKNOWN_PLSP_ID, srpId));
   }
 }
Esempio n. 14
0
  void stopRemoteTunnels(MultiplexedConnection agent, Collection<Tunnel> tunnels)
      throws CoreException {

    CoreException e = null;

    for (Tunnel tunnel : tunnels) {
      try {
        RemoteTunnel rt =
            RemoteTunnelManagerFactory.getInstance().getRemoteTunnel(tunnel.getResourceId());
        if (rt != null) {
          rt.stopListener();
        } else {
          throw new Exception("No active with ID for " + tunnel.getResourceId());
        }
      } catch (Exception ex) {
        throw new TunnelException(TunnelException.INTERNAL_ERROR, ex);
      }
    }
    if (e != null) {
      throw e;
    }
  }
Esempio n. 15
0
  void stopLocalTunnels(MultiplexedConnection agent, Collection<Tunnel> tunnels)
      throws CoreException {

    CoreException e = null;

    for (Tunnel tunnel : tunnels) {
      try {
        ByteArrayWriter msg = new ByteArrayWriter();
        msg.writeInt(tunnel.getResourceId());
        if (!agent.sendRequest(new Request(STOP_LOCAL_TUNNEL, msg.toByteArray()), false)
            && e == null) {
          e =
              new TunnelException(
                  TunnelException.AGENT_REFUSED_LOCAL_TUNNEL_STOP, (Throwable) null);
        }
      } catch (IOException ex) {
        throw new TunnelException(TunnelException.INTERNAL_ERROR, ex);
      }
    }
    if (e != null) {
      throw e;
    }
  }
Esempio n. 16
0
  @SuppressWarnings("unchecked")
  void notifyAutoStartTunnels() {
    try {
      SessionInfo session = agent.getSession();
      List<Tunnel> tunnels =
          ResourceUtil.getGrantedResource(session, TunnelPlugin.SSL_TUNNEL_RESOURCE_TYPE);

      List<BundleActionMessage> tunnelFailures = new ArrayList<BundleActionMessage>();
      for (Tunnel tunnel : tunnels) {
        if (tunnel.isAutoStart()) {
          try {
            Policy policy =
                PolicyDatabaseFactory.getInstance()
                    .getGrantingPolicyForUser(session.getUser(), tunnel);
            LaunchSession launchSession =
                LaunchSessionFactory.getInstance().createLaunchSession(session, tunnel, policy);
            startTunnel(launchSession);
          } catch (TunnelException tne) {
            log.error("failed to start tunnel: '" + tunnel + "'", tne);
            tunnelFailures.add(tne.getBundleActionMessage());
          }
        }
      }

      if (!tunnelFailures.isEmpty()) {
        tunnelFailures.add(
            0,
            new BundleActionMessage("tunnels", "error.tunnels.autostart", tunnelFailures.size()));
        for (BundleActionMessage actionMessage : tunnelFailures) {
          GlobalWarning globalWarning = new GlobalWarning(session.getHttpSession(), actionMessage);
          GlobalWarningManager.getInstance().addToSession(globalWarning);
        }
      }
    } catch (Exception e) {
      log.error("Failed to start auto-start tunnels", e);
    }
  }
Esempio n. 17
0
 private void startRedelegationTimer(
     final Tunnel tunnel, final PlspId plspId, final PccSession session) {
   final Timeout newRedelegationTimeout =
       this.timer.newTimeout(
           new TimerTask() {
             @Override
             public void run(final Timeout timeout) throws Exception {
               // remove delegation
               PccTunnelManagerImpl.this.setDelegation(plspId, null);
               // delegate to another PCE
               int index = session.getId();
               for (int i = 1; i < PccTunnelManagerImpl.this.sessions.size(); i++) {
                 index++;
                 if (index == PccTunnelManagerImpl.this.sessions.size()) {
                   index = 0;
                 }
                 final PccSession nextSession = PccTunnelManagerImpl.this.sessions.get(index);
                 if (nextSession != null) {
                   tunnel.cancelTimeouts();
                   final Tlvs tlvs =
                       createLspTlvs(
                           plspId.getValue(),
                           true,
                           getDestinationAddress(
                               tunnel.getLspState().getEro().getSubobject(),
                               PccTunnelManagerImpl.this.address),
                           PccTunnelManagerImpl.this.address,
                           PccTunnelManagerImpl.this.address,
                           Optional.of(tunnel.getPathName()));
                   nextSession.sendReport(
                       createPcRtpMessage(
                           createLsp(
                               plspId.getValue(),
                               true,
                               Optional.<Tlvs>fromNullable(tlvs),
                               true,
                               false),
                           NO_SRP,
                           tunnel.getLspState()));
                   tunnel.setDelegationHolder(nextSession.getId());
                   break;
                 }
               }
             }
           },
           this.redelegationTimeout,
           TimeUnit.SECONDS);
   tunnel.setRedelegationTimeout(newRedelegationTimeout);
 }
Esempio n. 18
0
 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);
   }
 }
Esempio n. 19
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;
  }
Esempio n. 20
0
 @Override
 public void takeDelegation(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) {
     // check if tunnel has no delegation
     if (tunnel.type == LspType.PCE_LSP
         && (tunnel.getDelegationHolder() == -1
             || tunnel.getDelegationHolder() == session.getId())) {
       // set delegation
       tunnel.cancelTimeouts();
       setDelegation(plspId, session);
       // send report
       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(request.getLsp())
                   .setSync(true)
                   .setOperational(OperationalStatus.Up)
                   .setDelegate(true)
                   .setTlvs(tlvs)
                   .build(),
               Optional.of(createSrp(srpId)),
               tunnel.getLspState()));
     } else {
       session.sendError(MsgBuilderUtil.createErrorMsg(PCEPErrors.LSP_NOT_PCE_INITIATED, srpId));
     }
   } else {
     session.sendError(MsgBuilderUtil.createErrorMsg(PCEPErrors.UNKNOWN_PLSP_ID, srpId));
   }
 }
Esempio n. 21
0
    private void getRequestV4() throws IOException {
      int ver = in.read();
      int cmd = in.read();
      if (ver == -1 || cmd == -1) {
        // EOF
        in.close();
        out.close();
        return;
      }

      if (ver != 0 && ver != 4) {
        out.write(PROTO_VERS4);
        out.write(91); // Bad Request
        out.write(0);
        out.write(0);
        out.write(0);
        out.write(0);
        out.write(0);
        out.write(0);
        out.write(0);
        out.flush();
        purge();
        out.close();
        in.close();
        return;
      }

      if (cmd == CONNECT) {
        int port = ((in.read() & 0xff) << 8);
        port += (in.read() & 0xff);
        byte[] buf = new byte[4];
        readBuf(in, buf);
        InetAddress addr = InetAddress.getByAddress(buf);
        // We don't use the username...
        int c;
        do {
          c = (in.read() & 0xff);
        } while (c != 0);
        boolean ok = true;
        try {
          dest = new Socket(addr, port);
        } catch (IOException e) {
          ok = false;
        }
        if (!ok) {
          out.write(PROTO_VERS4);
          out.write(91);
          out.write(0);
          out.write(0);
          out.write(buf);
          out.flush();
          purge();
          out.close();
          in.close();
          return;
        }
        out.write(PROTO_VERS4);
        out.write(90); // Success
        out.write((port >> 8) & 0xff);
        out.write(port & 0xff);
        out.write(buf);
        out.flush();
        InputStream in2 = dest.getInputStream();
        OutputStream out2 = dest.getOutputStream();

        Tunnel tunnel = new Tunnel(in2, out);
        tunnel.start();

        int b = 0;
        do {
          try {
            b = in.read();
            if (b == -1) {
              in.close();
              out2.close();
              return;
            }
            out2.write(b);
          } catch (IOException ex) {
          }
        } while (!client.isClosed());
      }
    }
Esempio n. 22
0
 protected void drawThis(GL2 gl) {
   gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
   configureGL(gl);
   tunnel.draw(gl, distortion);
   field.draw(gl);
 }
Esempio n. 23
0
 private static boolean hasDelegation(final Tunnel tunnel, final PccSession session) {
   return tunnel.getDelegationHolder() == session.getId();
 }