void
PipelineInterests::handleData(const Interest& interest, const Data& data)
{
  BOOST_ASSERT(data.getName().equals(interest.getName()));

  uint64_t recv_segno = data.getName()[-1].toSegment();
  if (m_highData < recv_segno) {
    m_highData = recv_segno;
  }

  shared_ptr<SegmentInfo> seg_info = m_segmentInfoMap[recv_segno];
  BOOST_ASSERT(seg_info != nullptr);
  if (seg_info->state == retransmitReceived) {
    m_segmentInfoMap.erase(recv_segno);
    return; // ignore already-received segment
  }

  if (m_options.isVerbose) {
    duration_in_ms rtt = time::steady_clock::now() - seg_info->timeSent;
    std::cerr << "Received the segment #" << recv_segno
              << ", rtt=" << rtt.count() << "ms"
              << ", rto=" << seg_info->rto << "ms" << std::endl;
  }

  // for segments in retransmission queue, no need to decrement m_inFligh since
  // it's already been decremented when segments timed out.
  if (seg_info->state != inRetxQueue && m_inFlight > 0) {
    m_inFlight--;
  }

  m_numOfSegmentReceived++;
  adjustCwnd();
  m_onData(interest, data);

  if (seg_info->state == firstTimeSent ||
      seg_info->state == inRetxQueue) { // donot sample RTT for retransmitted segments
    m_rttEstimator.rttMeasurement(recv_segno, seg_info->timeSent, seg_info->rto);
    m_segmentInfoMap.erase(recv_segno); // remove the entry associated with the received segment
  }
  else { // retransmission
    seg_info->state = retransmitReceived;
  }

  if (allSegmentsReceived() == true) {
    printSummary();
    if (m_options.keepStats) {
      writeStats();
      m_rttEstimator.writeStats();
    }
    cancel();
  }
  else {
    schedulePackets();
  }
}
Example #2
0
uint32_t ESP8266::checkIPD(String& data)
{
    //Serial.print("### check: ");
    //Serial.println(data);

    int32_t index_PIPDcomma = -1;
    int32_t index_colon = -1; /* : */
    int32_t index_comma = -1; /* , */
    int32_t len = -1;
    int8_t id = -1;
    { // Just for easier diffing
        index_PIPDcomma = data.indexOf("+IPD,");
        if (index_PIPDcomma != -1) {
            index_colon = data.indexOf(':', index_PIPDcomma + 5);
            if (index_colon != -1) {
                index_comma = data.indexOf(',', index_PIPDcomma + 5);
                /* +IPD,id,len:data */
                if (index_comma != -1 && index_comma < index_colon) { 
                    id = data.substring(index_PIPDcomma + 5, index_comma).toInt();
                    if (id < 0 || id > 4) {
                        return 0;
                    }
                    len = data.substring(index_comma + 1, index_colon).toInt();
                    if (len <= 0) {
                        return 0;
                    }
                } else { /* +IPD,len:data */
                    len = data.substring(index_PIPDcomma + 5, index_colon).toInt();
                    if (len <= 0) {
                        return 0;
                    }
                }
                if (m_onData) {
                    m_onData(id, len, m_onDataPtr);
                }
                return len;
            }
        }
    }
    return 0;
}
void
PipelineInterests::handleDataFirstSegment(const Interest& interest, const Data& data)
{
  BOOST_ASSERT(data.getName().equals(interest.getName()));

  uint64_t recv_segno = data.getName()[-1].toSegment();
  if (m_highData < recv_segno) {
    m_highData = recv_segno; // record the highest segment number of data received so far
  }

  m_segmentSize = data.getContent().value_size(); // get segment size
  shared_ptr<SegmentInfo> seg_info = m_segmentInfoMap[recv_segno];

  if (m_options.isVerbose) {
    duration_in_ms rtt = time::steady_clock::now() - seg_info->timeSent;
    std::cerr << "Received the first segment #" << recv_segno
              << ", rtt=" << rtt.count() << "ms"
              << ", rto=" << seg_info->rto << "ms" << std::endl;
  }

  // initiate RTT measurement
  m_rttEstimator.rttMeasurementFirstTime(recv_segno,
                                         seg_info->timeSent,
                                         seg_info->rto);
  m_onData(interest, data);

  if (m_inFlight > 0) m_inFlight--;

  m_numOfSegmentReceived++;
  m_segmentInfoMap.erase(recv_segno);
  adjustCwnd();

  if (allSegmentsReceived() == true)
    cancel();
  else
    schedulePackets();
}