Beispiel #1
0
void Normalize::normalizeQueueGetConfigReplyV1() {
  Header *hdr = header();

  size_t length = hdr->length();
  if (length < sizeof(QueueGetConfigReply)) {
    markInputInvalid("QueueGetConfigReply is too short");
    return;
  }

  if (hdr->version() == OFP_VERSION_1) {
    // Convert port number to 32-bits -- only for OpenFlow 1.0.
    UInt8 *ptr = buf_.mutableData() + sizeof(Header);
    PortNumber port = PortNumber::fromV1(*Big16_cast(ptr));
    std::memcpy(ptr, &port, sizeof(port));
  }

  // Convert QueueV1 to Queue.
  ByteRange data = SafeByteRange(buf_.mutableData(), buf_.size(),
                                 sizeof(QueueGetConfigReply));
  deprecated::QueueV1Range queues{data};

  Validation context;
  if (!queues.validateInput(&context)) {
    markInputInvalid("QueueGetConfigReply has invalid queues");
    return;
  }

  QueueList newQueues;
  for (auto &queue : queues) {
    QueueBuilder newQueue{queue};
    newQueues.add(newQueue);
  }

  // When converting to the regular `Queue` structure, we may exceed the max
  // message size of 65535.
  if (newQueues.size() > 65535 - sizeof(QueueGetConfigReply)) {
    markInputTooBig("QueueGetConfigReply is too big");
    return;
  }

  buf_.replace(data.begin(), data.end(), newQueues.data(), newQueues.size());
}