Beispiel #1
0
  private void handleIOEvent(FVIOEvent e) {
    if (!this.isConnected) {
      try {
        if (!this.sock.finishConnect()) return; // not done yet

      } catch (IOException e1) {
        FVLog.log(
            LogLevel.DEBUG,
            this,
            "retrying connection in ",
            this.reconnectSeconds,
            " seconds; got: ",
            e1);
        this.reconnectLater();
        return;
      }
      FVLog.log(LogLevel.DEBUG, this, "connected");
      this.isConnected = true;
      this.connectCount++;
      HashMap<String, Object> info = this.getStatusInfo();
      TopologyController tc = TopologyController.getRunningInstance();
      if (tc != null)
        tc.sliceConnectionJustChanged(info, TopologyCallback.EventType.SLICE_CONNECTED);
      this.reconnectSeconds = 0;
      try {
        msgStream = new FVMessageAsyncStream(this.sock, new FVMessageFactory(), this, this.stats);
      } catch (IOException e1) {
        FVLog.log(
            LogLevel.WARN,
            this,
            "Trying again later; while creating OFMessageAsyncStream, got: ",
            e1);
        this.reconnectLater();
        return;
      }
      sendMsg(new OFHello(), this); // send initial handshake
    }
    try {
      if (msgStream.needsFlush()) // flush any pending messages
      msgStream.flush();
      List<OFMessage> msgs = this.msgStream.read();
      // .read(FVSlicer.MessagesPerRead); // read any new
      // messages
      if (msgs == null) throw new IOException("got null from read()");
      for (OFMessage msg : msgs) {
        FVLog.log(LogLevel.DEBUG, this, "recv from controller: ", msg);
        this.stats.increment(FVStatsType.SEND, this, msg);
        if ((msg instanceof SanityCheckable) && (!((SanityCheckable) msg).isSane())) {
          FVLog.log(LogLevel.CRIT, this, "msg failed sanity check; dropping: " + msg);
          continue;
        }
        if (msg instanceof Slicable) {
          // mark this channel as still alive
          this.keepAlive.registerPong();
          if (msg.getType() != OFType.HELLO && !fvClassifier.isRateLimited(this.getSliceName())) {
            FVLog.log(
                LogLevel.WARN,
                this,
                "dropping msg because slice",
                this.getSliceName(),
                " is rate limited: ",
                msg);
            this.sendMsg(FVMessageUtil.makeErrorMsg(OFBadRequestCode.OFPBRC_EPERM, msg), this);

            continue;
          }
          ((Slicable) msg).sliceFromController(fvClassifier, this);

        } else
          FVLog.log(LogLevel.CRIT, this, "dropping msg that doesn't implement classify: ", msg);
      }
    } catch (IOException e1) {
      FVLog.log(LogLevel.WARN, this, "got i/o error; tearing down and reconnecting: ", e1);
      reconnect();
    } catch (Exception e2) {
      e2.printStackTrace();
      FVLog.log(LogLevel.ALERT, this, "got unknown error; tearing down and reconnecting: ", e2);

      reconnect();
    }
    // no need to setup for next select; done in eventloop
  }
 @Override
 public void sliceFromController(
     FVStatisticsRequest msg, FVClassifier fvClassifier, FVSlicer fvSlicer) {
   FVMessageUtil.translateXidAndSend(msg, fvClassifier, fvSlicer);
 }