Beispiel #1
0
void
test_match_basic_IPV6_SRC(void) {
  struct lagopus_packet pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;
  int i;

  /* prepare packet */
  pkt.in_port = &port;
  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];
  OS_M_PKTLEN(m) = 64;

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x86, 0xdd);
  m->data[12] = 0x86;
  m->data[13] = 0xdd;
  i = 22;
  m->data[i++] = 0x20;
  m->data[i++] = 0x01;
  m->data[i++] = 0x20;
  m->data[i++] = 0xff;
  m->data[i++] = 0x00;
  m->data[i++] = 0x00;
  m->data[i++] = 0x10;
  m->data[i++] = 0x20;
  m->data[i++] = 0x11;
  m->data[i++] = 0xe1;
  m->data[i++] = 0x50;
  m->data[i++] = 0x89;
  m->data[i++] = 0xbf;
  m->data[i++] = 0xc6;
  m->data[i++] = 0x43;
  m->data[i++] = 0x11;
  lagopus_packet_init(&pkt, m);
  add_match(&flow->match_list, 16, OFPXMT_OFB_IPV6_SRC << 1,
            0x20, 0x01, 0x00, 0x00, 0xe0, 0x45, 0x22, 0xeb,
            0x09, 0x00, 0x00, 0x08, 0xdc, 0x18, 0x94, 0xad);
  refresh_match(flow);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "IPV6_SRC mismatch error.");
  i = 22;
  m->data[i++] = 0x20;
  m->data[i++] = 0x01;
  m->data[i++] = 0x00;
  m->data[i++] = 0x00;
  m->data[i++] = 0xe0;
  m->data[i++] = 0x45;
  m->data[i++] = 0x22;
  m->data[i++] = 0xeb;
  m->data[i++] = 0x09;
  m->data[i++] = 0x00;
  m->data[i++] = 0x00;
  m->data[i++] = 0x08;
  m->data[i++] = 0xdc;
  m->data[i++] = 0x18;
  m->data[i++] = 0x94;
  m->data[i++] = 0xad;
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "IPV6_SRC match error.");
}
Beispiel #2
0
void
test_push_mpls(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_push *action_push;
  struct lagopus_packet *pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) +
                  sizeof(*action_push) - sizeof(struct ofp_action_header));
  action_push = (struct ofp_action_push *)&action->ofpat;
  action_push->type = OFPAT_PUSH_MPLS;
  action_push->ethertype = 0x8847;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = pkt->mbuf;

  OS_M_APPEND(m, 64);
  OS_MTOD(m, uint8_t *)[12] = 0x08;
  OS_MTOD(m, uint8_t *)[13] = 0x00;
  OS_MTOD(m, uint8_t *)[14] = 0x45;
  OS_MTOD(m, uint8_t *)[22] = 240;

  lagopus_packet_init(pkt, m, &port);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 4,
                            "PUSH_MPLS length error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[12], 0x88,
                            "PUSH_MPLS ethertype[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[13], 0x47,
                            "PUSH_MPLS ethertype[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[16], 1,
                            "PUSH_MPLS BOS error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[17], 240,
                            "PUSH_MPLS TTL error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[18], 0x45,
                            "PUSH_MPLS payload error.");

  OS_MTOD(m, uint8_t *)[14] = 0x12;
  OS_MTOD(m, uint8_t *)[15] = 0x34;
  OS_MTOD(m, uint8_t *)[16] = 0x5f;

  action_push->ethertype = 0x8848;
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 8,
                            "PUSH_MPLS(2) length error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[12], 0x88,
                            "PUSH_MPLS(2) ethertype[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[13], 0x48,
                            "PUSH_MPLS(2) ethertype[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[14], 0x12,
                            "PUSH_MPLS(2) LSE[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[15], 0x34,
                            "PUSH_MPLS(2) LSE[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[16], 0x5e,
                            "PUSH_MPLS(2) LSE[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[17], 240,
                            "PUSH_MPLS(2) LSE[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[18], 0x12,
                            "PUSH_MPLS(2) payload[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[19], 0x34,
                            "PUSH_MPLS(2) payload[1] error.");
}
Beispiel #3
0
void
test_lagopus_find_flow(void) {
    datastore_bridge_info_t info;
    struct bridge *bridge;
    struct port *port;
    struct port nport;
    struct lagopus_packet *pkt;
    struct table *table;
    struct flow *flow;
    OS_MBUF *m;

    /* setup bridge and port */
    memset(&info, 0, sizeof(info));
    info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE;
    TEST_ASSERT_EQUAL(dp_bridge_create("br0", &info), LAGOPUS_RESULT_OK);
    TEST_ASSERT_EQUAL(dp_port_create("port0"), LAGOPUS_RESULT_OK);
    TEST_ASSERT_EQUAL(dp_port_create("port1"), LAGOPUS_RESULT_OK);
    TEST_ASSERT_EQUAL(dp_bridge_port_set("br0", "port0", 1), LAGOPUS_RESULT_OK);
    TEST_ASSERT_EQUAL(dp_bridge_port_set("br0", "port1", 2), LAGOPUS_RESULT_OK);

    pkt = alloc_lagopus_packet();
    TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
    m = pkt->mbuf;
    OS_M_APPEND(m, 64);
    m->refcnt = 2;

    bridge = dp_bridge_lookup("br0");
    TEST_ASSERT_NOT_NULL(bridge);
    lagopus_packet_init(pkt, m, port_lookup(&bridge->ports, 1));
    table = flowdb_get_table(pkt->in_port->bridge->flowdb, 0);
    table->userdata = new_flowinfo_eth_type();
    flow = lagopus_find_flow(pkt, table);
    TEST_ASSERT_EQUAL_MESSAGE(table->lookup_count, 0,
                              "lookup_count(misc) error.");
    TEST_ASSERT_NULL_MESSAGE(flow,
                             "flow(misc) error.");
    OS_MTOD(m, uint8_t *)[14] = 0x08;
    OS_MTOD(m, uint8_t *)[15] = 0x06;
    lagopus_packet_init(pkt, m, &port);
    flow = lagopus_find_flow(pkt, table);
    TEST_ASSERT_EQUAL_MESSAGE(table->lookup_count, 0,
                              "lookup_count(arp) error.");
    TEST_ASSERT_NULL_MESSAGE(flow,
                             "flow(arp) error.");
    OS_MTOD(m, uint8_t *)[14] = 0x08;
    OS_MTOD(m, uint8_t *)[15] = 0x00;
    lagopus_packet_init(pkt, m, port_lookup(&bridge->ports, 1));
    flow = lagopus_find_flow(pkt, table);
    TEST_ASSERT_EQUAL_MESSAGE(table->lookup_count, 0,
                              "lookup_count(ipv4) error.");
    TEST_ASSERT_NULL_MESSAGE(flow,
                             "flow(ipv4) error.");
    OS_MTOD(m, uint8_t *)[14] = 0x86;
    OS_MTOD(m, uint8_t *)[15] = 0xdd;
    OS_MTOD(m, uint8_t *)[20] = IPPROTO_TCP;
    lagopus_packet_init(pkt, m, port_lookup(&bridge->ports, 1));
    flow = lagopus_find_flow(pkt, table);
    TEST_ASSERT_EQUAL_MESSAGE(table->lookup_count, 0,
                              "lookup_count(ipv6) error.");
    TEST_ASSERT_NULL_MESSAGE(flow,
                             "flow(ipv6) error.");
    OS_MTOD(m, uint8_t *)[14] = 0x88;
    OS_MTOD(m, uint8_t *)[15] = 0x47;
    lagopus_packet_init(pkt, m, port_lookup(&bridge->ports, 1));
    flow = lagopus_find_flow(pkt, table);
    TEST_ASSERT_EQUAL_MESSAGE(table->lookup_count, 0,
                              "lookup_count(mpls) error.");
    TEST_ASSERT_NULL_MESSAGE(flow,
                             "flow(mpls) error.");
    OS_MTOD(m, uint8_t *)[14] = 0x88;
    OS_MTOD(m, uint8_t *)[15] = 0x48;
    lagopus_packet_init(pkt, m, port_lookup(&bridge->ports, 1));
    flow = lagopus_find_flow(pkt, table);
    TEST_ASSERT_EQUAL_MESSAGE(table->lookup_count, 0,
                              "lookup_count(mpls-mc) error.");
    TEST_ASSERT_NULL_MESSAGE(flow,
                             "flow(mpls-mc) error.");
    OS_MTOD(m, uint8_t *)[14] = 0x88;
    OS_MTOD(m, uint8_t *)[15] = 0xe7;
    lagopus_packet_init(pkt, m, port_lookup(&bridge->ports, 1));
    flow = lagopus_find_flow(pkt, table);
    TEST_ASSERT_EQUAL_MESSAGE(table->lookup_count, 0,
                              "lookup_count(pbb) error.");
    TEST_ASSERT_NULL_MESSAGE(flow,
                             "flow(pbb) error.");
}
Beispiel #4
0
void
test_push_pbb(void) {
  static const uint8_t dhost[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
  static const uint8_t shost[] = { 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb };
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_push *action_push;
  struct lagopus_packet *pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) +
                  sizeof(*action_push) - sizeof(struct ofp_action_header));
  action_push = (struct ofp_action_push *)&action->ofpat;
  action_push->type = OFPAT_PUSH_PBB;
  action_push->ethertype = 0x88e7;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = pkt->mbuf;

  OS_M_APPEND(m, 64);
  OS_MEMCPY(&OS_MTOD(m, uint8_t *)[0], dhost, ETH_ALEN);
  OS_MEMCPY(&OS_MTOD(m, uint8_t *)[6], shost, ETH_ALEN);

  lagopus_packet_init(pkt, m, &port);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 18,
                            "PUSH_PBB length error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[12], 0x88,
                            "PUSH_PBB TPID[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[13], 0xe7,
                            "PUSH_PBB TPID[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[14], 0,
                            "PUSH_PBB pcp_dei error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[15], 0x00,
                            "PUSH_PBB i_sid[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[16], 0x00,
                            "PUSH_PBB i_sid[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[17], 0x00,
                            "PUSH_PBB i_sid[2] error.");
  TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(&OS_MTOD(m, uint8_t *)[18], dhost, ETH_ALEN,
                                        "PUSH_PBB dhost error.");
  TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(&OS_MTOD(m, uint8_t *)[24], shost, ETH_ALEN,
                                        "PUSH_PBB shost error.");
  OS_MTOD(m, uint8_t *)[15] = 0xab;
  OS_MTOD(m, uint8_t *)[16] = 0xcd;
  OS_MTOD(m, uint8_t *)[17] = 0xef;
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 18 + 18,
                            "PUSH_PBB length error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[15], 0xab,
                            "PUSH_PBB(2) i_sid[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[16], 0xcd,
                            "PUSH_PBB(2) i_sid[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[17], 0xef,
                            "PUSH_PBB(2) i_sid[2] error.");
}
Beispiel #5
0
void
test_pop_mpls(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_pop_mpls *action_pop;
  struct lagopus_packet *pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) +
                  sizeof(*action_pop) - sizeof(struct ofp_action_header));
  action_pop = (struct ofp_action_pop_mpls *)&action->ofpat;
  action_pop->type = OFPAT_POP_MPLS;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = pkt->mbuf;

  OS_M_APPEND(m, 64 + 8);
  /* initial, double taged */
  OS_MTOD(m, uint8_t *)[12] = 0x88;
  OS_MTOD(m, uint8_t *)[13] = 0x48;
  /* outer LSE */
  OS_MTOD(m, uint8_t *)[17] = 50;
  /* innner LSE */
  OS_MTOD(m, uint8_t *)[20] = 0x01;
  OS_MTOD(m, uint8_t *)[21] = 100;
  /* IPv4 */
  OS_MTOD(m, uint8_t *)[22] = 0x45;
  OS_MTOD(m, uint8_t *)[30] = 240;

  lagopus_packet_init(pkt, m, &port);
  action_pop->ethertype = 0x8847;
  TEST_ASSERT_EQUAL(execute_action(pkt, &action_list), LAGOPUS_RESULT_OK);
  TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 4,
                            "POP_MPLS length error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[12], 0x88,
                            "POP_MPLS ethertype[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[13], 0x47,
                            "POP_MPLS ethertype[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[16], 1,
                            "POP_MPLS BOS error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[17], 100,
                            "POP_MPLS TTL error.");
  action_pop->ethertype = 0x0800;
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64,
                            "POP_MPLS(2) length error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[12], 0x08,
                            "POP_MPLS(2) ethertype[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[13], 0x00,
                            "POP_MPLS(2) ethertype[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[14], 0x45,
                            "POP_MPLS(2) ip_vhl error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[22], 240,
                            "POP_MPLS(2) ip_ttl error.");
}
Beispiel #6
0
void
test_match_flow_mpls(void) {
  struct lagopus_packet pkt;
  struct flowinfo *flowinfo;
  struct flow *flow;
  struct port port;
  OS_MBUF *m;
  int32_t prio;
  int i, nflow;

  /* prepare packet */
  pkt.in_port = &port;
  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];
  OS_M_PKTLEN(m) = 64;

  /* prepare flow table */
  test_flow[0] = allocate_test_flow(10 * sizeof(struct match));
  test_flow[0]->priority = 3;
  add_match(&test_flow[0]->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x88, 0x47);
  add_match(&test_flow[0]->match_list, 4, OFPXMT_OFB_MPLS_LABEL << 1,
            0x00, 0x00, 0x00, 0x01);

  test_flow[1] = allocate_test_flow(10 * sizeof(struct match));
  test_flow[1]->priority = 2;
  FLOW_ADD_PORT_MATCH(test_flow[1], 2);

  test_flow[2] = allocate_test_flow(10 * sizeof(struct match));
  test_flow[2]->priority = 1;
  FLOW_ADD_PORT_MATCH(test_flow[2], 3);

  /* create flowinfo */
  flowinfo = new_flowinfo_eth_type();
  nflow = sizeof(test_flow) / sizeof(test_flow[0]);
  for (i = 0; i < nflow; i++) {
    flowinfo->add_func(flowinfo, test_flow[i]);
  }

  /* test */
  prio = 0;
  m->data[12] = 0x88;
  m->data[13] = 0x47;

  m->data[14] = 0xff;
  m->data[15] = 0xff;
  m->data[16] = 0xff;
  m->data[17] = 0xff;
  lagopus_packet_init(&pkt, m);
  flow = flowinfo->match_func(flowinfo, &pkt, &prio);
  TEST_ASSERT_NULL_MESSAGE(flow, "match_flow_mpls mismatch error");
  m->data[14] = 0x00;
  m->data[15] = 0x00;
  m->data[16] = 0x1f;
  m->data[17] = 0xff;
  flow = flowinfo->match_func(flowinfo, &pkt, &prio);
  TEST_ASSERT_EQUAL_MESSAGE(flow, test_flow[0],
                            "match_flow_mpls match flow error.");
  TEST_ASSERT_EQUAL_MESSAGE(prio, 3,
                            "match_flow_mpls match prio error.");
}
void
test_set_field_MPLS_LABEL(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64;
  m->data[12] = 0x88;
  m->data[13] = 0x47;
  m->data[14] = 0xff;
  m->data[15] = 0xff;
  m->data[16] = 0xff;
  m->data[17] = 0xff;

  lagopus_set_in_port(&pkt, &port);
  lagopus_packet_init(&pkt, m);
  set_match(action_set->field, 4, OFPXMT_OFB_MPLS_LABEL << 1,
            0x00, 0x00, 0x01, 0x00);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[14], 0x00,
                            "SET_FIELD MPLS_LABEL[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[15], 0x10,
                            "SET_FIELD MPLS_LABEL[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x0f,
                            "SET_FIELD MPLS_LABEL[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0xff,
                            "SET_FIELD MPLS_LABEL[3] error.");

  m->data[12] = 0x88;
  m->data[13] = 0x48;
  m->data[14] = 0x00;
  m->data[15] = 0x00;
  m->data[16] = 0x00;
  m->data[17] = 0x00;

  lagopus_packet_init(&pkt, m);
  set_match(action_set->field, 4, OFPXMT_OFB_MPLS_LABEL << 1,
            0x00, 0x0c, 0xa4, 0x21);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[14], 0xca,
                            "SET_FIELD MPLS_LABEL(2)[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[15], 0x42,
                            "SET_FIELD MPLS_LABEL(2)[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x10,
                            "SET_FIELD MPLS_LABEL(2)[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0x00,
                            "SET_FIELD MPLS_LABEL(2)[3] error.");
}
Beispiel #8
0
void
test_pop_mpls(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_pop_mpls *action_pop;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) +
                  sizeof(*action_pop) - sizeof(struct ofp_action_header));
  action_pop = (struct ofp_action_pop_mpls *)&action->ofpat;
  action_pop->type = OFPAT_POP_MPLS;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_EQUAL_MESSAGE(m, NULL, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64 + 8;
  /* initial, double taged */
  m->data[12] = 0x88;
  m->data[13] = 0x48;
  /* outer LSE */
  m->data[17] = 50;
  /* innner LSE */
  m->data[20] = 0x01;
  m->data[21] = 100;
  /* IPv4 */
  m->data[22] = 0x45;
  m->data[30] = 240;

  lagopus_packet_init(&pkt, m, &port);
  action_pop->ethertype = 0x8847;
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 4,
                            "POP_MPLS length error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x88,
                            "POP_MPLS ethertype[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0x47,
                            "POP_MPLS ethertype[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 1,
                            "POP_MPLS BOS error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 100,
                            "POP_MPLS TTL error.");
  action_pop->ethertype = 0x0800;
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64,
                            "POP_MPLS(2) length error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x08,
                            "POP_MPLS(2) ethertype[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0x00,
                            "POP_MPLS(2) ethertype[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[14], 0x45,
                            "POP_MPLS(2) ip_vhl error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[22], 240,
                            "POP_MPLS(2) ip_ttl error.");
}
Beispiel #9
0
void
test_push_mpls(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_push *action_push;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) +
                  sizeof(*action_push) - sizeof(struct ofp_action_header));
  action_push = (struct ofp_action_push *)&action->ofpat;
  action_push->type = OFPAT_PUSH_MPLS;
  action_push->ethertype = 0x8847;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_EQUAL_MESSAGE(m, NULL, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64;
  m->data[12] = 0x08;
  m->data[13] = 0x00;
  m->data[14] = 0x45;
  m->data[22] = 240;

  lagopus_packet_init(&pkt, m, &port);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 4,
                            "PUSH_MPLS length error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x88,
                            "PUSH_MPLS ethertype[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0x47,
                            "PUSH_MPLS ethertype[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 1,
                            "PUSH_MPLS BOS error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 240,
                            "PUSH_MPLS TTL error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[18], 0x45,
                            "PUSH_MPLS payload error.");

  m->data[14] = 0x12;
  m->data[15] = 0x34;
  m->data[16] = 0x5f;

  action_push->ethertype = 0x8848;
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 8,
                            "PUSH_MPLS(2) length error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x88,
                            "PUSH_MPLS(2) ethertype[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0x48,
                            "PUSH_MPLS(2) ethertype[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[14], 0x12,
                            "PUSH_MPLS(2) LSE[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[15], 0x34,
                            "PUSH_MPLS(2) LSE[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x5e,
                            "PUSH_MPLS(2) LSE[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 240,
                            "PUSH_MPLS(2) LSE[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[18], 0x12,
                            "PUSH_MPLS(2) payload[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[19], 0x34,
                            "PUSH_MPLS(2) payload[1] error.");
}
Beispiel #10
0
void
test_match_basic_IPV6_ND_TARGET(void) {
  struct lagopus_packet *pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;
  int i;

  /* prepare packet */
  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = pkt->mbuf;
  OS_M_PKTLEN(m) = 128;

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x86, 0xdd);

  /* IP proto */
  add_match(&flow->match_list, 1, OFPXMT_OFB_IP_PROTO << 1,
            IPPROTO_ICMPV6);

  OS_MTOD(m, uint8_t *)[12] = 0x86;
  OS_MTOD(m, uint8_t *)[13] = 0xdd;
  OS_MTOD(m, uint8_t *)[20] = IPPROTO_ICMPV6;
  OS_MTOD(m, uint8_t *)[54] = ND_NEIGHBOR_SOLICIT;
  add_match(&flow->match_list, 16, OFPXMT_OFB_IPV6_ND_TARGET << 1,
            0x20, 0x01, 0x00, 0x00, 0xe0, 0x45, 0x22, 0xeb,
            0x09, 0x00, 0x00, 0x08, 0xdc, 0x18, 0x94, 0xad);
  refresh_match(flow);
  i = 62;
  OS_MTOD(m, uint8_t *)[i++] = 0x20;
  OS_MTOD(m, uint8_t *)[i++] = 0x01;
  OS_MTOD(m, uint8_t *)[i++] = 0x20;
  OS_MTOD(m, uint8_t *)[i++] = 0xff;
  OS_MTOD(m, uint8_t *)[i++] = 0x00;
  OS_MTOD(m, uint8_t *)[i++] = 0x00;
  OS_MTOD(m, uint8_t *)[i++] = 0x10;
  OS_MTOD(m, uint8_t *)[i++] = 0x20;
  OS_MTOD(m, uint8_t *)[i++] = 0x11;
  OS_MTOD(m, uint8_t *)[i++] = 0xe1;
  OS_MTOD(m, uint8_t *)[i++] = 0x50;
  OS_MTOD(m, uint8_t *)[i++] = 0x89;
  OS_MTOD(m, uint8_t *)[i++] = 0xbf;
  OS_MTOD(m, uint8_t *)[i++] = 0xc6;
  OS_MTOD(m, uint8_t *)[i++] = 0x43;
  OS_MTOD(m, uint8_t *)[i++] = 0x11;
  lagopus_packet_init(pkt, m, &port);
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "IPV6_ND_TARGET mismatch error.");
  i = 62;
  OS_MTOD(m, uint8_t *)[i++] = 0x20;
  OS_MTOD(m, uint8_t *)[i++] = 0x01;
  OS_MTOD(m, uint8_t *)[i++] = 0x00;
  OS_MTOD(m, uint8_t *)[i++] = 0x00;
  OS_MTOD(m, uint8_t *)[i++] = 0xe0;
  OS_MTOD(m, uint8_t *)[i++] = 0x45;
  OS_MTOD(m, uint8_t *)[i++] = 0x22;
  OS_MTOD(m, uint8_t *)[i++] = 0xeb;
  OS_MTOD(m, uint8_t *)[i++] = 0x09;
  OS_MTOD(m, uint8_t *)[i++] = 0x00;
  OS_MTOD(m, uint8_t *)[i++] = 0x00;
  OS_MTOD(m, uint8_t *)[i++] = 0x08;
  OS_MTOD(m, uint8_t *)[i++] = 0xdc;
  OS_MTOD(m, uint8_t *)[i++] = 0x18;
  OS_MTOD(m, uint8_t *)[i++] = 0x94;
  OS_MTOD(m, uint8_t *)[i++] = 0xad;
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "IPV6_ND_TARGET match error.");
}
Beispiel #11
0
void
test_push_vlan(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_push *action_push;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) +
                  sizeof(*action_push) - sizeof(struct ofp_action_header));
  action_push = (struct ofp_action_push *)&action->ofpat;
  action_push->type = OFPAT_PUSH_VLAN;
  action_push->ethertype = 0x8100;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_EQUAL_MESSAGE(m, NULL, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64;
  m->data[12] = 0x08;
  m->data[13] = 0x00;
  m->data[14] = 0x45;

  lagopus_set_in_port(&pkt, &port);
  lagopus_packet_init(&pkt, m);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 4,
                            "PUSH_VLAN length error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x81,
                            "PUSH_VLAN TPID[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0x00,
                            "PUSH_VLAN TPID[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x08,
                            "PUSH_VLAN ethertype[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0x00,
                            "PUSH_VLAN ethertype[1] error.");

  m->data[14] = 0xef;
  m->data[15] = 0xfe;
  action_push->ethertype = 0x88a8;
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 8,
                            "PUSH_VLAN(2) length error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x88,
                            "PUSH_VLAN(2) TPID[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0xa8,
                            "PUSH_VLAN(2) TPID[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[14], 0xef,
                            "PUSH_VLAN(2) TCI[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[15], 0xfe,
                            "PUSH_VLAN(2) TCI[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x81,
                            "PUSH_VLAN(2) ethertype[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0x00,
                            "PUSH_VLAN(2) ethertype[1] error.");
}
Beispiel #12
0
void
test_match_flow_basic(void) {
  struct lagopus_packet pkt;
  struct flowinfo *flowinfo;
  struct flow *flow;
  struct port port;
  OS_MBUF *m;
  int32_t prio;
  int i, nflow;

  /* prepare flow table */
  test_flow[0] = allocate_test_flow(10 * sizeof(struct match));
  test_flow[0]->priority = 3;
  FLOW_ADD_PORT_MATCH(test_flow[0], 1);

  test_flow[1] = allocate_test_flow(10 * sizeof(struct match));
  test_flow[1]->priority = 2;
  FLOW_ADD_PORT_MATCH(test_flow[1], 2);

  test_flow[2] = allocate_test_flow(10 * sizeof(struct match));
  test_flow[2]->priority = 1;
  FLOW_ADD_PORT_MATCH(test_flow[2], 3);

  /* create flowinfo */
  flowinfo = new_flowinfo_basic();
  nflow = sizeof(test_flow) / sizeof(test_flow[0]);
  for (i = 0; i < nflow; i++) {
    flowinfo->add_func(flowinfo, test_flow[i]);
  }

  /* prepare packet */
  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];
  OS_M_PKTLEN(m) = 64;
  lagopus_packet_init(&pkt, m, &port);

  /* test */
  prio = 0;
  pkt.oob_data.in_port = htonl(1);
  flow = flowinfo->match_func(flowinfo, &pkt, &prio);
  TEST_ASSERT_EQUAL_MESSAGE(flow, test_flow[0],
                            "Port 1 match (prio 0) flow error.");
  TEST_ASSERT_EQUAL_MESSAGE(prio, 3,
                            "Port 1 match (prio 0) prio error.");
  prio = 1;
  flow = flowinfo->match_func(flowinfo, &pkt, &prio);
  TEST_ASSERT_EQUAL_MESSAGE(flow, test_flow[0],
                            "Port 1 match (prio 1) flow error.");
  TEST_ASSERT_EQUAL_MESSAGE(prio, 3,
                            "Port 1 match (prio 1) prio error.");
  prio = 2;
  flow = flowinfo->match_func(flowinfo, &pkt, &prio);
  TEST_ASSERT_EQUAL_MESSAGE(flow, test_flow[0],
                            "Port 1 match (prio 2) flow error.");
  TEST_ASSERT_EQUAL_MESSAGE(prio, 3,
                            "Port 1 match (prio 2) prio error.");
  flow = flowinfo->match_func(flowinfo, &pkt, &prio);
  TEST_ASSERT_EQUAL_MESSAGE(flow, NULL,
                            "Port 1 match (prio 3) flow error.");
  prio = 0;
  pkt.oob_data.in_port = htonl(2);
  flow = flowinfo->match_func(flowinfo, &pkt, &prio);
  TEST_ASSERT_EQUAL_MESSAGE(flow, test_flow[1],
                            "Port 2 match (prio 0) flow error.");
  TEST_ASSERT_EQUAL_MESSAGE(prio, 2,
                            "Port 2 match (prio 0) prio error.");
  prio = 1;
  flow = flowinfo->match_func(flowinfo, &pkt, &prio);
  TEST_ASSERT_EQUAL_MESSAGE(flow, test_flow[1],
                            "Port 2 match (prio 1) flow error.");
  TEST_ASSERT_EQUAL_MESSAGE(prio, 2,
                            "Port 2 match (prio 1) prio error.");
  flow = flowinfo->match_func(flowinfo, &pkt, &prio);
  TEST_ASSERT_EQUAL_MESSAGE(flow, NULL,
                            "Port 2 match (prio 2) flow error.");
  TEST_ASSERT_EQUAL_MESSAGE(prio, 2,
                            "Port 2 match (prio 2) prio error.");
  prio = 3;
  flow = flowinfo->match_func(flowinfo, &pkt, &prio);
  TEST_ASSERT_EQUAL_MESSAGE(flow, NULL,
                            "Port 2 match (prio 3) flow error.");

  prio = 0;
  pkt.oob_data.in_port = htonl(3);
  flow = flowinfo->match_func(flowinfo, &pkt, &prio);
  TEST_ASSERT_EQUAL_MESSAGE(flow, test_flow[2],
                            "Port 3 match (prio 0) flow error.");
  TEST_ASSERT_EQUAL_MESSAGE(prio, 1,
                            "Port 3 match (prio 0) prio error.");
  flow = flowinfo->match_func(flowinfo, &pkt, &prio);
  TEST_ASSERT_EQUAL_MESSAGE(flow, NULL,
                            "Port 3 match (prio 1) error.");
  prio = 0;
  pkt.oob_data.in_port = htonl(4);
  flow = flowinfo->match_func(flowinfo, &pkt, &prio);
  TEST_ASSERT_NULL_MESSAGE(flow, "mismatch error.");
}
void
test_set_field_IPV6_ND_TARGET(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet pkt;
  OS_MBUF *m;
  int i;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64;
  m->data[12] = 0x86;
  m->data[13] = 0xdd;
  m->data[20] = IPPROTO_ICMPV6;

  lagopus_set_in_port(&pkt, &port);
  lagopus_packet_init(&pkt, m);
  set_match(action_set->field, 16, OFPXMT_OFB_IPV6_ND_TARGET << 1,
            0x20, 0x01, 0x00, 0x00, 0xe0, 0x45, 0x22, 0xeb,
            0x09, 0x00, 0x00, 0x08, 0xdc, 0x18, 0x94, 0xad);
  execute_action(&pkt, &action_list);
  i = 62;
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x20,
                            "SET_FIELD IPV6_ND_TARGET[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x01,
                            "SET_FIELD IPV6_ND_TARGET[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xe0,
                            "SET_FIELD IPV6_ND_TARGET[4] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x45,
                            "SET_FIELD IPV6_ND_TARGET[5] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x22,
                            "SET_FIELD IPV6_ND_TARGET[6] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xeb,
                            "SET_FIELD IPV6_ND_TARGET[7] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x09,
                            "SET_FIELD IPV6_ND_TARGET[8] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[9] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[10] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x08,
                            "SET_FIELD IPV6_ND_TARGET[11] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xdc,
                            "SET_FIELD IPV6_ND_TARGET[12] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x18,
                            "SET_FIELD IPV6_ND_TARGET[13] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x94,
                            "SET_FIELD IPV6_ND_TARGET[14] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xad,
                            "SET_FIELD IPV6_ND_TARGET[15] error.");
  m->data[20] = IPPROTO_DSTOPTS;
  m->data[54] = IPPROTO_ICMPV6;
  m->data[55] = 0;
  lagopus_packet_init(&pkt, m);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[54], IPPROTO_ICMPV6,
                            "SET_FIELD IPV6_ND_TARGET proto error.");
  i = 70;
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x20,
                            "SET_FIELD IPV6_ND_TARGET[0](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x01,
                            "SET_FIELD IPV6_ND_TARGET[1](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[2](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[3](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xe0,
                            "SET_FIELD IPV6_ND_TARGET[4](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x45,
                            "SET_FIELD IPV6_ND_TARGET[5](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x22,
                            "SET_FIELD IPV6_ND_TARGET[6](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xeb,
                            "SET_FIELD IPV6_ND_TARGET[7](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x09,
                            "SET_FIELD IPV6_ND_TARGET[8](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[9](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[10](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x08,
                            "SET_FIELD IPV6_ND_TARGET[11](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xdc,
                            "SET_FIELD IPV6_ND_TARGET[12](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x18,
                            "SET_FIELD IPV6_ND_TARGET[13](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x94,
                            "SET_FIELD IPV6_ND_TARGET[14](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xad,
                            "SET_FIELD IPV6_ND_TARGET[15](next hdr) error.");
}
Beispiel #14
0
void
test_push_MPLS_and_set_field_ETH_DST_SRC(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_push *action_push;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);

  action = calloc(1, sizeof(*action) +
                  sizeof(*action_push) - sizeof(struct ofp_action_header));
  action_push = (struct ofp_action_push *)&action->ofpat;
  action_push->type = OFPAT_PUSH_MPLS;
  action_push->ethertype = 0x8847;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);

  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  set_match(action_set->field, 6, OFPXMT_OFB_ETH_DST << 1,
            0x23, 0x45, 0x67, 0x89, 0xab, 0xcd);
  TAILQ_INSERT_TAIL(&action_list, action, entry);

  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  set_match(action_set->field, 6, OFPXMT_OFB_ETH_SRC << 1,
            0x22, 0x44, 0x66, 0x88, 0xaa, 0xcc);
  TAILQ_INSERT_TAIL(&action_list, action, entry);

  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_EQUAL_MESSAGE(m, NULL, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64;
  m->data[12] = 0x08;
  m->data[13] = 0x00;
  m->data[14] = 0x45;
  m->data[22] = 240;

  lagopus_set_in_port(&pkt, &port);
  lagopus_packet_init(&pkt, m);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 4,
                            "PUSH_MPLS length error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x88,
                            "PUSH_MPLS ethertype[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0x47,
                            "PUSH_MPLS ethertype[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 1,
                            "PUSH_MPLS BOS error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 240,
                            "PUSH_MPLS TTL error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[18], 0x45,
                            "PUSH_MPLS payload error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[0], 0x23,
                            "SET_FIELD ETH_DST[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[1], 0x45,
                            "SET_FIELD ETH_DST[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[2], 0x67,
                            "SET_FIELD ETH_DST[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[3], 0x89,
                            "SET_FIELD ETH_DST[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[4], 0xab,
                            "SET_FIELD ETH_DST[4] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[5], 0xcd,
                            "SET_FIELD ETH_DST[5] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[6], 0x22,
                            "SET_FIELD ETH_SRC[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[7], 0x44,
                            "SET_FIELD ETH_SRC[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[8], 0x66,
                            "SET_FIELD ETH_SRC[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[9], 0x88,
                            "SET_FIELD ETH_SRC[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[10], 0xaa,
                            "SET_FIELD ETH_SRC[4] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[11], 0xcc,
                            "SET_FIELD ETH_SRC[5] error.");
}
Beispiel #15
0
void
test_action_OUTPUT(void) {
  struct action_list action_list;
  struct dpmgr *my_dpmgr;
  struct bridge *bridge;
  struct port *port;
  struct action *action;
  struct ofp_action_output *action_set;
  struct port nport;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  /* setup bridge and port */
  my_dpmgr = dpmgr_alloc();
  dpmgr_bridge_add(my_dpmgr, "br0", 0);
  nport.type = LAGOPUS_PORT_TYPE_NULL; /* for test */
  nport.ofp_port.port_no = 1;
  nport.ifindex = 0;
  nport.ofp_port.hw_addr[0] = 1;
  dpmgr_port_add(my_dpmgr, &nport);
  port = port_lookup(my_dpmgr->ports, 0);
  TEST_ASSERT_NOT_NULL(port);
  port->ofp_port.hw_addr[0] = 0xff;
  nport.ofp_port.port_no = 2;
  nport.ifindex = 1;
  dpmgr_port_add(my_dpmgr, &nport);
  port = port_lookup(my_dpmgr->ports, 1);
  TEST_ASSERT_NOT_NULL(port);
  port->ofp_port.hw_addr[0] = 0xff;
  dpmgr_bridge_port_add(my_dpmgr, "br0", 0, 1);
  dpmgr_bridge_port_add(my_dpmgr, "br0", 1, 2);

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_output *)&action->ofpat;
  action_set->type = OFPAT_OUTPUT;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);

  memset(&pkt, 0, sizeof(pkt));

  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  bridge = dpmgr_bridge_lookup(my_dpmgr, "br0");
  TEST_ASSERT_NOT_NULL(bridge);
  lagopus_set_in_port(&pkt, port_lookup(bridge->ports, 1));
  TEST_ASSERT_NOT_NULL(pkt.in_port);
  lagopus_packet_init(&pkt, m);

  /* output action always decrement reference count. */
  m->refcnt = 2;
  action_set->port = 1;
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->refcnt, 1,
                            "OUTPUT refcnt error.");

  m->refcnt = 2;
  action_set->port = 2;
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->refcnt, 1,
                            "OUTPUT refcnt error.");

  m->refcnt = 2;
  action_set->port = OFPP_ALL;
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->refcnt, 1,
                            "OUTPUT refcnt error.");

  m->refcnt = 2;
  action_set->port = OFPP_NORMAL;
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->refcnt, 1,
                            "OUTPUT refcnt error.");

  m->refcnt = 2;
  action_set->port = OFPP_IN_PORT;
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->refcnt, 1,
                            "OUTPUT refcnt error.");

  m->refcnt = 2;
  action_set->port = OFPP_CONTROLLER;
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->refcnt, 1,
                            "OUTPUT refcnt error.");

  m->refcnt = 2;
  action_set->port = OFPP_FLOOD;
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->refcnt, 1,
                            "OUTPUT refcnt error.");

  m->refcnt = 2;
  action_set->port = OFPP_LOCAL;
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->refcnt, 1,
                            "OUTPUT refcnt error.");

  m->refcnt = 2;
  action_set->port = 0;
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->refcnt, 1,
                            "OUTPUT refcnt error.");
  free(m);
  dpmgr_free(my_dpmgr);
}
Beispiel #16
0
void
test_set_field_IPV6_DST(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet *pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = PKT2MBUF(pkt);

  OS_M_APPEND(m, 64);
  OS_MTOD(m, uint8_t *)[12] = 0x86;
  OS_MTOD(m, uint8_t *)[13] = 0xdd;

  lagopus_packet_init(pkt, m, &port);
  set_match(action_set->field, 16, OFPXMT_OFB_IPV6_DST << 1,
            0x20, 0x01, 0x00, 0x00, 0xe0, 0x45, 0x22, 0xeb,
            0x09, 0x00, 0x00, 0x08, 0xdc, 0x18, 0x94, 0xad);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[38], 0x20,
                            "SET_FIELD IPV6_DST[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[39], 0x01,
                            "SET_FIELD IPV6_DST[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[40], 0x00,
                            "SET_FIELD IPV6_DST[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[41], 0x00,
                            "SET_FIELD IPV6_DST[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[42], 0xe0,
                            "SET_FIELD IPV6_DST[4] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[43], 0x45,
                            "SET_FIELD IPV6_DST[5] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[44], 0x22,
                            "SET_FIELD IPV6_DST[6] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[45], 0xeb,
                            "SET_FIELD IPV6_DST[7] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[46], 0x09,
                            "SET_FIELD IPV6_DST[8] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[47], 0x00,
                            "SET_FIELD IPV6_DST[9] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[48], 0x00,
                            "SET_FIELD IPV6_DST[10] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[49], 0x08,
                            "SET_FIELD IPV6_DST[11] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[50], 0xdc,
                            "SET_FIELD IPV6_DST[12] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[51], 0x18,
                            "SET_FIELD IPV6_DST[13] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[52], 0x94,
                            "SET_FIELD IPV6_DST[14] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[53], 0xad,
                            "SET_FIELD IPV6_DST[15] error.");
}