示例#1
0
void
PHV::push_back_header(const std::string &header_name,
                      header_id_t header_index,
                      const HeaderType &header_type,
                      const std::set<int> &arith_offsets,
                      const bool metadata) {
  assert(header_index < static_cast<int>(capacity));
  assert(header_index == static_cast<int>(headers.size()));
  // cannot call push_back here, as the Header constructor passes "this" to the
  // Field constructor (i.e. Header cannot be moved or the pointer would be
  // invalid); this is not a very robust design
  headers.emplace_back(
      header_name, header_index, header_type, arith_offsets, metadata);
  headers.back().set_packet_id(&packet_id);

  headers_map.emplace(header_name, get_header(header_index));

  for (int i = 0; i < header_type.get_num_fields(); i++) {
    const std::string name = header_name + "." + header_type.get_field_name(i);
    // std::cout << header_index << " " << i << " " << name << std::endl;
    fields_map.emplace(name, get_field(header_index, i));
  }

  if (header_type.is_VL_header()) {
    headers.back().VL_expr = header_type.resolve_VL_expr(header_index);

    if (headers.back().VL_expr != nullptr) {
      for (const int offset : header_type.get_VL_input_offsets())
        headers.back()[offset].set_arith(true);
    }
  }
}
 ConditionalsTest()
   : testHeaderType("test_t", 0) {
   testHeaderType.push_back_field("f32", 32);
   testHeaderType.push_back_field("f48", 48);
   testHeaderType.push_back_field("f8", 8);
   testHeaderType.push_back_field("f16", 16);
   testHeaderType.push_back_field("f128", 128);
   phv_factory.push_back_header("test1", testHeader1, testHeaderType);
   phv_factory.push_back_header("test2", testHeader2, testHeaderType);
 }
示例#3
0
void
PHVFactory::push_back_header(const std::string &header_name,
                             const header_id_t header_index,
                             const HeaderType &header_type,
                             const bool metadata) {
  HeaderDesc desc(header_name, header_index, header_type, metadata);
  // cannot use operator[] because it requires default constructibility
  header_descs.insert(std::make_pair(header_index, desc));
  for (int i = 0; i < header_type.get_num_fields(); i++) {
    field_names.insert(header_name + "." + header_type.get_field_name(i));
  }
}
  CalculationTest()
      : testHeaderType("test_t", 0),
        oneParseState("parse_state", 0),
        parser("test_parser", 0),
        phv_source(PHVSourceIface::make_phv_source()) {
    testHeaderType.push_back_field("f16", 16);
    testHeaderType.push_back_field("f48", 48);
    testHeaderType.push_back_field("f32_1", 32);
    testHeaderType.push_back_field("f32_2", 32);
    testHeaderType.push_back_field("f5", 5);
    testHeaderType.push_back_field("f19", 19);

    phv_factory.push_back_header("test1", testHeader1, testHeaderType);
    phv_factory.push_back_header("test2", testHeader2, testHeaderType);
  }
  TableIndirectWS() 
    : testHeaderType("test_t", 0), action_fn("actionA", 0) {
    testHeaderType.push_back_field("f16", 16);
    testHeaderType.push_back_field("f48", 48);
    phv_factory.push_back_header("test1", testHeader1, testHeaderType);
    phv_factory.push_back_header("test2", testHeader2, testHeaderType);

    key_builder.push_back_field(testHeader1, 0, 16);

    // with counters, without ageing
    table = MatchTableIndirectWS::create("exact", "test_table", 0,
					 table_size, key_builder,
					 true, false);
    table->set_next_node(0, nullptr);

    BufBuilder builder;
    
    builder.push_back_field(testHeader1, 1, 48); // h1.f48
    builder.push_back_field(testHeader2, 0, 16); // h2.f16
    builder.push_back_field(testHeader2, 1, 48); // h2.f48

    std::unique_ptr<Calculation<hash_t> > calc(new Calculation<hash_t>(builder));
    calc->set_compute_fn(hash::xxh64<hash_t>);

    table->set_hash(std::move(calc));
  }
  TableSizeTwo()
    : testHeaderType("test_t", 0), action_fn("actionA", 0) {
    testHeaderType.push_back_field("f16", 16);
    testHeaderType.push_back_field("f48", 48);
    phv_factory.push_back_header("test1", testHeader1, testHeaderType);
    phv_factory.push_back_header("test2", testHeader2, testHeaderType);

    key_builder.push_back_field(testHeader1, 0, 16);

    key_builder_w_valid.push_back_field(testHeader1, 0, 16);
    key_builder_w_valid.push_back_valid_header(testHeader2);

    std::unique_ptr<MUType> match_unit;

    // true enables counters
    match_unit = std::unique_ptr<MUType>(new MUType(2, key_builder));
    table = std::unique_ptr<MatchTable>(
      new MatchTable("test_table", 0, std::move(match_unit), true)
    );
    table->set_next_node(0, nullptr);

    match_unit = std::unique_ptr<MUType>(new MUType(2, key_builder_w_valid));
    table_w_valid = std::unique_ptr<MatchTable>(
      new MatchTable("test_table", 0, std::move(match_unit))
    );
    table_w_valid->set_next_node(0, nullptr);
  }
 PHVTest()
   : testHeaderType("test_t", 0) {
   testHeaderType.push_back_field("f16", 16);
   testHeaderType.push_back_field("f48", 48);
   phv_factory.push_back_header("test1", testHeader1, testHeaderType);
   phv_factory.push_back_header("test2", testHeader2, testHeaderType);
 }
  AgeingTest()
      : testHeaderType("test_t", 0),
        action_fn("actionA", 0),
        ageing_writer(new MemoryAccessor(4096)),
        phv_source(PHVSourceIface::make_phv_source()) {
    testHeaderType.push_back_field("f16", 16);
    testHeaderType.push_back_field("f48", 48);
    phv_factory.push_back_header("test1", testHeader1, testHeaderType);
    phv_factory.push_back_header("test2", testHeader2, testHeaderType);

    key_builder.push_back_field(testHeader1, 0, 16, MatchKeyParam::Type::EXACT);

    typedef MatchTableAbstract::ActionEntry ActionEntry;
    typedef MatchUnitExact<ActionEntry> MUExact;

    LookupStructureFactory factory;

    std::unique_ptr<MUExact> match_unit(new MUExact(1, key_builder, &factory));

    // counters disabled, ageing enabled
    table = std::unique_ptr<MatchTable>(
      new MatchTable("test_table", 0, std::move(match_unit), false, true)
    );
    table->set_next_node(0, nullptr);
  }
 LearningTest()
   : testHeaderType("test_t", 0),
     learn_writer(new MemoryAccessor(4096)) {
   testHeaderType.push_back_field("f16", 16);
   testHeaderType.push_back_field("f48", 48);
   phv_factory.push_back_header("test1", testHeader1, testHeaderType);
   phv_factory.push_back_header("test2", testHeader2, testHeaderType);
 }
示例#10
0
Header::Header(const std::string &name, p4object_id_t id,
               const HeaderType &header_type,
               const std::set<int> &arith_offsets,
               const bool metadata)
  : NamedP4Object(name, id), header_type(header_type), metadata(metadata) {
  // header_type_id = header_type.get_type_id();
  for (int i = 0; i < header_type.get_num_fields(); i++) {
    // use emplace_back instead?
    bool arith_flag = true;
    if (arith_offsets.find(i) == arith_offsets.end()) {
      arith_flag = false;
    }
    fields.push_back(Field(header_type.get_bit_width(i), arith_flag));
    nbytes_phv += fields.back().get_nbytes();
    nbytes_packet += fields.back().get_nbits();
  }
  assert(nbytes_packet % 8 == 0);
  nbytes_packet /= 8;
}
  ActionsTest()
      : testHeaderType("test_t", 0),
        testActionFn("test_action", 0),
        testActionFnEntry(&testActionFn),
        phv_source(PHVSourceIface::make_phv_source()) {
    testHeaderType.push_back_field("f32", 32);
    testHeaderType.push_back_field("f48", 48);
    testHeaderType.push_back_field("f8", 8);
    testHeaderType.push_back_field("f16", 16);
    testHeaderType.push_back_field("f128", 128);

    phv_factory.push_back_header("test1", testHeader1, testHeaderType);
    phv_factory.push_back_header("test2", testHeader2, testHeaderType);

    phv_factory.push_back_header("testS0", testHeaderS0, testHeaderType);
    phv_factory.push_back_header("testS1", testHeaderS1, testHeaderType);
    phv_factory.push_back_header_stack("test_stack", testHeaderStack,
				       testHeaderType,
				       {testHeaderS0, testHeaderS1});
  }
  HeaderStackTest()
    : testHeaderType("test_t", 0) {
    testHeaderType.push_back_field("f16", 16);
    testHeaderType.push_back_field("f48", 48);
    phv_factory.push_back_header("test_0", testHeader_0, testHeaderType);
    phv_factory.push_back_header("test_1", testHeader_1, testHeaderType);
    phv_factory.push_back_header("test_2", testHeader_2, testHeaderType);

    const std::vector<header_id_t> headers =
      {testHeader_0, testHeader_1, testHeader_2};
    phv_factory.push_back_header_stack("test_stack", testHeaderStack,
				       testHeaderType, headers);
  }
  TableIndirect() 
    : testHeaderType("test_t", 0), action_fn("actionA", 0) {
    testHeaderType.push_back_field("f16", 16);
    testHeaderType.push_back_field("f48", 48);
    phv_factory.push_back_header("test1", testHeader1, testHeaderType);
    phv_factory.push_back_header("test2", testHeader2, testHeaderType);

    key_builder.push_back_field(testHeader1, 0, 16);

    // with counters, without ageing
    table = MatchTableIndirect::create("exact", "test_table", 0,
				       table_size, key_builder,
				       true, false);
    table->set_next_node(0, nullptr);
  }