Exemple #1
0
int Port::ByteSize() const {
  int total_size = 0;

  if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
    // required int32 port_num = 1;
    if (has_port_num()) {
      total_size += 1 +
        ::google::protobuf::internal::WireFormatLite::Int32Size(
          this->port_num());
    }

    // required string ip = 2;
    if (has_ip()) {
      total_size += 1 +
        ::google::protobuf::internal::WireFormatLite::StringSize(
          this->ip());
    }

  }
  if (!unknown_fields().empty()) {
    total_size +=
      ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
        unknown_fields());
  }
  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
  _cached_size_ = total_size;
  GOOGLE_SAFE_CONCURRENT_WRITES_END();
  return total_size;
}
Exemple #2
0
::google::protobuf::uint8* Port::SerializeWithCachedSizesToArray(
    ::google::protobuf::uint8* target) const {
  // @@protoc_insertion_point(serialize_to_array_start:port.Port)
  // required int32 port_num = 1;
  if (has_port_num()) {
    target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->port_num(), target);
  }

  // required string ip = 2;
  if (has_ip()) {
    ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
      this->ip().data(), this->ip().length(),
      ::google::protobuf::internal::WireFormat::SERIALIZE,
      "ip");
    target =
      ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
        2, this->ip(), target);
  }

  if (!unknown_fields().empty()) {
    target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
        unknown_fields(), target);
  }
  // @@protoc_insertion_point(serialize_to_array_end:port.Port)
  return target;
}
Exemple #3
0
int p4ns_db_add_port(p4ns_db_cxt_t c,
		     const char *name, const char *iface, uint16_t port_num) {
  redisReply *reply;
  char ports_key[128];
  char port_nums_key[128];
  get_ports_key(ports_key, name);
  get_port_nums_key(port_nums_key, name);

  if(!p4ns_db_has_datapath(c, name)) { /* datapath does not exist */
    return P4NSDB_ERROR_INVALID_DATAPATH;
  }
  
  if(has_port(c, ports_key, iface)) { /* port exists */
    return P4NSDB_ERROR_PORT_EXISTS;
  }

  if(has_port_num(c, port_nums_key, port_num)) { /* port num taken */
    return P4NSDB_ERROR_PORT_NUM_TAKEN;
  }

  p4ns_port_t p4ns_port;
  memset(&p4ns_port, 0, sizeof(p4ns_port_t));
  p4ns_port.port_num = port_num;
  strncpy(p4ns_port.iface, iface, 64);

  reply = redisCommand(c, "HSET %s %s %b", ports_key, iface, &p4ns_port, sizeof(p4ns_port_t));
  assert(reply->integer == 1);
  freeReplyObject(reply);

  reply = redisCommand(c, "SADD %s %d", port_nums_key, port_num);
  assert(reply->integer == 1);
  freeReplyObject(reply);

  return 0;
}
Exemple #4
0
int p4ns_db_has_port_num(p4ns_db_cxt_t c,
			 const char *name, uint16_t port_num) {
  char port_nums_key[128];
  get_port_nums_key(port_nums_key, name);

  if(!p4ns_db_has_datapath(c, name)) { /* datapath does not exist */
    return 0;
  }
  
  return has_port_num(c, port_nums_key, port_num);
}
Exemple #5
0
void Port::SerializeWithCachedSizes(
    ::google::protobuf::io::CodedOutputStream* output) const {
  // @@protoc_insertion_point(serialize_start:port.Port)
  // required int32 port_num = 1;
  if (has_port_num()) {
    ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->port_num(), output);
  }

  // required string ip = 2;
  if (has_ip()) {
    ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
      this->ip().data(), this->ip().length(),
      ::google::protobuf::internal::WireFormat::SERIALIZE,
      "ip");
    ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
      2, this->ip(), output);
  }

  if (!unknown_fields().empty()) {
    ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
        unknown_fields(), output);
  }
  // @@protoc_insertion_point(serialize_end:port.Port)
}