Ejemplo n.º 1
0
void
test_set_field_ETH_TYPE(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] = 0x08;
  m->data[13] = 0x00;

  lagopus_packet_init(&pkt, m, &port);
  set_match(action_set->field, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x20, 0xf1);
  execute_action(&pkt, &action_list);

  TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x20,
                            "SET_FIELD ETH_TYPE[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0xf1,
                            "SET_FIELD ETH_TYPE[1] error.");
  m->data[12] = 0x81;
  m->data[13] = 0x00;

  lagopus_packet_init(&pkt, m, &port);
  execute_action(&pkt, &action_list);

  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x20,
                            "SET_FIELD(vlan) ETH_TYPE[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0xf1,
                            "SET_FIELD(vlan) ETH_TYPE[1] error.");
}
Ejemplo n.º 2
0
void
test_set_field_IN_PORT(void) {
  datastore_bridge_info_t info;
  struct action_list action_list;
  struct bridge *bridge;
  struct port *port;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct port nport;
  struct lagopus_packet pkt;
  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);

  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];

  bridge = dp_bridge_lookup("br0");
  TEST_ASSERT_NOT_NULL(bridge);
  pkt.in_port = port_lookup(bridge->ports, 1);
  TEST_ASSERT_NOT_NULL(pkt.in_port);
  lagopus_packet_init(&pkt, m);
  set_match(action_set->field, 4, OFPXMT_OFB_IN_PORT << 1,
            0x00, 0x00, 0x00, 0x02);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(pkt.in_port->ofp_port.port_no, 2,
                            "SET_FIELD IN_PORT error.");
}
Ejemplo n.º 3
0
void
test_set_field_ARP_TPA(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 = pkt->mbuf;

  OS_M_APPEND(m, 64);
  OS_MTOD(m, uint8_t *)[12] = 0x08;
  OS_MTOD(m, uint8_t *)[13] = 0x06;
  OS_MTOD(m, uint8_t *)[20] = 0x00;
  OS_MTOD(m, uint8_t *)[21] = ARPOP_REQUEST;
  OS_MTOD(m, uint8_t *)[38] = 172;
  OS_MTOD(m, uint8_t *)[39] = 21;
  OS_MTOD(m, uint8_t *)[40] = 0;
  OS_MTOD(m, uint8_t *)[31] = 1;

  lagopus_packet_init(pkt, m, &port);
  set_match(action_set->field, 4, OFPXMT_OFB_ARP_TPA << 1,
            192, 168, 1, 2);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[38], 192,
                            "SET_FIELD ARP_TPA[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[39], 168,
                            "SET_FIELD ARP_TPA[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[40], 1,
                            "SET_FIELD ARP_TPA[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[41], 2,
                            "SET_FIELD ARP_TPA[3] error.");
}
Ejemplo n.º 4
0
void
test_set_field_ETH_SRC(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] = 0x08;
  m->data[13] = 0x00;

  lagopus_packet_init(&pkt, m, &port);
  set_match(action_set->field, 6, OFPXMT_OFB_ETH_SRC << 1,
            0x22, 0x44, 0x66, 0x88, 0xaa, 0xcc);
  execute_action(&pkt, &action_list);
  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.");
}
Ejemplo n.º 5
0
void
test_set_field_ETH_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);


  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] = 0x08;
  m->data[13] = 0x00;

  lagopus_packet_init(&pkt, m, &port);
  set_match(action_set->field, 6, OFPXMT_OFB_ETH_DST << 1,
            0x23, 0x45, 0x67, 0x89, 0xab, 0xcd);
  execute_action(&pkt, &action_list);
  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.");
}
Ejemplo n.º 6
0
void
test_set_field_ICMPV6_TYPE(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] = 0x86;
  m->data[13] = 0xdd;
  m->data[20] = IPPROTO_ICMPV6;

  lagopus_packet_init(&pkt, m, &port);
  set_match(action_set->field, 2, OFPXMT_OFB_ICMPV6_TYPE << 1,
            ICMP6_ECHO_REQUEST);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[54], ICMP6_ECHO_REQUEST,
                            "SET_FIELD ICMPV6_TYPE error.");
  m->data[20] = IPPROTO_DSTOPTS;
  m->data[54] = IPPROTO_ICMPV6;
  m->data[55] = 0;
  lagopus_packet_init(&pkt, m, &port);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[54], IPPROTO_ICMPV6,
                            "SET_FIELD ICMPV6_TYPE proto error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[62], ICMP6_ECHO_REQUEST,
                            "SET_FIELD ICMPV6_TYPE(next hdr) error.");
}
Ejemplo n.º 7
0
void
test_set_field_ICMPV6_TYPE(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;
  OS_MTOD(m, uint8_t *)[20] = IPPROTO_ICMPV6;

  lagopus_packet_init(pkt, m, &port);
  set_match(action_set->field, 2, OFPXMT_OFB_ICMPV6_TYPE << 1,
            ICMP6_ECHO_REQUEST);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[54], ICMP6_ECHO_REQUEST,
                            "SET_FIELD ICMPV6_TYPE error.");
  OS_MTOD(m, uint8_t *)[20] = IPPROTO_DSTOPTS;
  OS_MTOD(m, uint8_t *)[54] = IPPROTO_ICMPV6;
  OS_MTOD(m, uint8_t *)[55] = 0;
  lagopus_packet_init(pkt, m, &port);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[54], IPPROTO_ICMPV6,
                            "SET_FIELD ICMPV6_TYPE proto error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[62], ICMP6_ECHO_REQUEST,
                            "SET_FIELD ICMPV6_TYPE(next hdr) error.");
}
Ejemplo n.º 8
0
void
test_set_field_ETH_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] = 0x08;
  OS_MTOD(m, uint8_t *)[13] = 0x00;

  lagopus_packet_init(pkt, m, &port);
  set_match(action_set->field, 6, OFPXMT_OFB_ETH_DST << 1,
            0x23, 0x45, 0x67, 0x89, 0xab, 0xcd);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[0], 0x23,
                            "SET_FIELD ETH_DST[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[1], 0x45,
                            "SET_FIELD ETH_DST[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[2], 0x67,
                            "SET_FIELD ETH_DST[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[3], 0x89,
                            "SET_FIELD ETH_DST[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[4], 0xab,
                            "SET_FIELD ETH_DST[4] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[5], 0xcd,
                            "SET_FIELD ETH_DST[5] error.");
}
Ejemplo n.º 9
0
void
test_set_field_ETH_SRC(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] = 0x08;
  OS_MTOD(m, uint8_t *)[13] = 0x00;

  lagopus_packet_init(pkt, m, &port);
  set_match(action_set->field, 6, OFPXMT_OFB_ETH_SRC << 1,
            0x22, 0x44, 0x66, 0x88, 0xaa, 0xcc);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[6], 0x22,
                            "SET_FIELD ETH_SRC[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[7], 0x44,
                            "SET_FIELD ETH_SRC[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[8], 0x66,
                            "SET_FIELD ETH_SRC[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[9], 0x88,
                            "SET_FIELD ETH_SRC[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[10], 0xaa,
                            "SET_FIELD ETH_SRC[4] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[11], 0xcc,
                            "SET_FIELD ETH_SRC[5] error.");
}
Ejemplo n.º 10
0
void
test_dec_mpls_ttl(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action->ofpat.type = OFPAT_DEC_MPLS_TTL;
  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] = 0x88;
  m->data[13] = 0x47;
  m->data[17] = 100;

  lagopus_set_in_port(&pkt, &port);
  lagopus_packet_init(&pkt, m);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 99,
                            "DEC_MPLS_TTL error.");

  m->data[12] = 0x88;
  m->data[13] = 0x48;
  m->data[17] = 0;

  lagopus_packet_init(&pkt, m);
  pkt.in_port = NULL;
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0,
                            "DEC_MPLS_TTL(0) error.");
}
Ejemplo n.º 11
0
void
test_set_field_IPV6_FLABEL(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] = 0x86;
  m->data[13] = 0xdd;
  m->data[14] = 0x6f;
  lagopus_packet_init(&pkt, m, &port);
  set_match(action_set->field, 4, OFPXMT_OFB_IPV6_FLABEL << 1,
            0x00, 0x0e, 0xab, 0xcd);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[14], 0x6f,
                            "SET_FIELD IPV6_IPV6_FLABEL[0] error");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[15], 0x0e,
                            "SET_FIELD IPV6_IPV6_FLABEL[1] error");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0xab,
                            "SET_FIELD IPV6_IPV6_FLABEL[2] error");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0xcd,
                            "SET_FIELD IPV6_IPV6_FLABEL[3] error");
}
Ejemplo n.º 12
0
void
test_set_field_IPV6_FLABEL(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;
  OS_MTOD(m, uint8_t *)[14] = 0x6f;
  lagopus_packet_init(pkt, m, &port);
  set_match(action_set->field, 4, OFPXMT_OFB_IPV6_FLABEL << 1,
            0x00, 0x0e, 0xab, 0xcd);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[14], 0x6f,
                            "SET_FIELD IPV6_IPV6_FLABEL[0] error");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[15], 0x0e,
                            "SET_FIELD IPV6_IPV6_FLABEL[1] error");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[16], 0xab,
                            "SET_FIELD IPV6_IPV6_FLABEL[2] error");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[17], 0xcd,
                            "SET_FIELD IPV6_IPV6_FLABEL[3] error");
}
Ejemplo n.º 13
0
void
test_set_field_PBB_ISID(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] = 0xe7;

  lagopus_set_in_port(&pkt, &port);
  lagopus_packet_init(&pkt, m);
  set_match(action_set->field, 3, OFPXMT_OFB_PBB_ISID << 1,
            0xa5, 0x5a, 0xc3);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[15], 0xa5,
                            "SET_FIELD PBB_ISID[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x5a,
                            "SET_FIELD PBB_ISID[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0xc3,
                            "SET_FIELD PBB_ISID[2] error.");
}
Ejemplo n.º 14
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.");
}
Ejemplo n.º 15
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.");
}
Ejemplo n.º 16
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.");
}
Ejemplo n.º 17
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.");
}
Ejemplo n.º 18
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.");
}
Ejemplo n.º 19
0
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.");
}
Ejemplo n.º 20
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.");
}
Ejemplo n.º 21
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);
}
Ejemplo n.º 22
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);


  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;

  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(m->data[38], 0x20,
                            "SET_FIELD IPV6_DST[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[39], 0x01,
                            "SET_FIELD IPV6_DST[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[40], 0x00,
                            "SET_FIELD IPV6_DST[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[41], 0x00,
                            "SET_FIELD IPV6_DST[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[42], 0xe0,
                            "SET_FIELD IPV6_DST[4] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[43], 0x45,
                            "SET_FIELD IPV6_DST[5] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[44], 0x22,
                            "SET_FIELD IPV6_DST[6] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[45], 0xeb,
                            "SET_FIELD IPV6_DST[7] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[46], 0x09,
                            "SET_FIELD IPV6_DST[8] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[47], 0x00,
                            "SET_FIELD IPV6_DST[9] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[48], 0x00,
                            "SET_FIELD IPV6_DST[10] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[49], 0x08,
                            "SET_FIELD IPV6_DST[11] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[50], 0xdc,
                            "SET_FIELD IPV6_DST[12] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[51], 0x18,
                            "SET_FIELD IPV6_DST[13] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[52], 0x94,
                            "SET_FIELD IPV6_DST[14] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[53], 0xad,
                            "SET_FIELD IPV6_DST[15] error.");
}
Ejemplo n.º 23
0
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.");
}
Ejemplo n.º 24
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.");
}
Ejemplo n.º 25
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.");
}