void test_classify_packet_PBB(void) { struct port port; struct lagopus_packet pkt; OS_MBUF *m; m = calloc(1, sizeof(*m)); TEST_ASSERT_NOT_EQUAL_MESSAGE(m, NULL, "calloc error."); m->data = &m->dat[128]; OS_M_PKTLEN(m) = 128; #ifdef PBB_IS_VLAN m->data[12] = 0x88; m->data[13] = 0xe7; m->data[30] = 0x08; m->data[31] = 0x00; pkt.mbuf = (OS_MBUF *)m; lagopus_set_in_port(&pkt, &port); classify_packet(&pkt); TEST_ASSERT_EQUAL_MESSAGE(pkt.ether_type, ETHERTYPE_IP, "ether_type error."); /* with VLAN */ m->data[12] = 0x81; m->data[13] = 0x00; m->data[16] = 0x88; m->data[17] = 0xe7; m->data[34] = 0x08; m->data[35] = 0x00; pkt.mbuf = (OS_MBUF *)m; classify_packet(&pkt); TEST_ASSERT_EQUAL_MESSAGE(pkt.ether_type, ETHERTYPE_IP, "ether_type(vlan) error."); #else m->data[12] = 0x88; m->data[13] = 0xe7; pkt.mbuf = (OS_MBUF *)m; lagopus_set_in_port(&pkt, &port); classify_packet(&pkt); TEST_ASSERT_EQUAL_MESSAGE(pkt.ether_type, ETHERTYPE_PBB, "ether_type error."); /* with VLAN */ m->data[12] = 0x81; m->data[13] = 0x00; m->data[16] = 0x88; m->data[17] = 0xe7; pkt.mbuf = (OS_MBUF *)m; classify_packet(&pkt); TEST_ASSERT_EQUAL_MESSAGE(pkt.ether_type, ETHERTYPE_PBB, "ether_type(vlan) error."); #endif }
void test_set_nw_ttl_IPV6(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_nw_ttl *action_set; struct lagopus_packet pkt; OS_MBUF *m; TAILQ_INIT(&action_list); action = calloc(1, sizeof(*action) + 64); action_set = (struct ofp_action_nw_ttl *)&action->ofpat; action_set->type = OFPAT_SET_NW_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] = 0x86; m->data[13] = 0xdd; m->data[20] = IPPROTO_TCP; lagopus_set_in_port(&pkt, &port); lagopus_packet_init(&pkt, m); action_set->nw_ttl = 240; execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(m->data[21], 240, "SET_NW_TTL_IPV6 error."); }
void test_copy_ttl_out_IPV6_to_MPLS(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_COPY_TTL_OUT; 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[16] = 0x01; /* BOS */ m->data[17] = 100; /* MPLS TTL */ m->data[18] = 0x60; m->data[25] = 10; /* IPv6 TTL */ lagopus_set_in_port(&pkt, &port); lagopus_packet_init(&pkt, m); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(m->data[25], 10, "COPY_TTL_OUT_IPv6_to_MPLS(inner) error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 10, "COPY_TTL_OUT_IPv6_to_MPLS(outer) error."); }
void test_classify_packet_MPLSMC(void) { struct port port; struct lagopus_packet pkt; OS_MBUF *m; m = calloc(1, sizeof(*m)); TEST_ASSERT_NOT_EQUAL_MESSAGE(m, NULL, "calloc error."); m->data = &m->dat[128]; OS_M_PKTLEN(m) = 128; m->data[12] = 0x88; m->data[13] = 0x48; pkt.mbuf = (OS_MBUF *)m; lagopus_set_in_port(&pkt, &port); classify_packet(&pkt); TEST_ASSERT_EQUAL_MESSAGE(pkt.ether_type, ETHERTYPE_MPLS_MCAST, "ether_type error."); /* with VLAN */ m->data[12] = 0x81; m->data[13] = 0x00; m->data[16] = 0x88; m->data[17] = 0x48; pkt.mbuf = (OS_MBUF *)m; classify_packet(&pkt); TEST_ASSERT_EQUAL_MESSAGE(pkt.ether_type, ETHERTYPE_MPLS_MCAST, "ether_type(vlan) error."); }
void test_set_field_METADATA(void) { struct port port; static const uint8_t metadata[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 }; 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]; pkt.oob_data.metadata = 0; lagopus_set_in_port(&pkt, &port); lagopus_packet_init(&pkt, m); set_match(action_set->field, 8, OFPXMT_OFB_METADATA << 1, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(&pkt.oob_data.metadata, metadata, 8, "SET_FIELD METADATA error."); }
void test_lagopus_receive_packet(void) { struct lagopus_packet pkt; struct dpmgr *my_dpmgr; struct port nport, *port; struct bridge *bridge; OS_MBUF *m; lagopus_result_t rv; my_dpmgr = dpmgr_alloc(); TEST_ASSERT_NOT_NULL_MESSAGE(my_dpmgr, "alloc error"); rv = dpmgr_bridge_add(my_dpmgr, "br0", 0); TEST_ASSERT_EQUAL_MESSAGE(rv, LAGOPUS_RESULT_OK, "bridge add error\n"); nport.type = LAGOPUS_PORT_TYPE_NULL; /* for test */ nport.ifindex = 0; nport.ofp_port.hw_addr[0] = 1; dpmgr_port_add(my_dpmgr, &nport); nport.ifindex = 1; dpmgr_port_add(my_dpmgr, &nport); rv = dpmgr_bridge_port_add(my_dpmgr, "br0", 0, 1); TEST_ASSERT_EQUAL(rv, LAGOPUS_RESULT_OK); rv = dpmgr_bridge_port_add(my_dpmgr, "br0", 1, 2); TEST_ASSERT_EQUAL(rv, LAGOPUS_RESULT_OK); bridge = dpmgr_bridge_lookup(my_dpmgr, "br0"); TEST_ASSERT_NOT_NULL(bridge); /* prepare packet */ m = calloc(1, sizeof(*m)); TEST_ASSERT_NOT_NULL_MESSAGE(m, "m: calloc error."); m->data = &m->dat[128]; m->data[12] = 0x08; m->data[13] = 0x00; m->data[14] = 0x45; m->data[23] = IPPROTO_TCP; m->refcnt = 2; pkt.cache = NULL; pkt.table_id = 0; pkt.flags = 0; port = port_lookup(bridge->ports, 1); TEST_ASSERT_NOT_NULL_MESSAGE(port, "port lookup error."); lagopus_set_in_port(&pkt, port); TEST_ASSERT_EQUAL_MESSAGE(pkt.in_port, port, "port error."); TEST_ASSERT_EQUAL(pkt.in_port->bridge, bridge); lagopus_packet_init(&pkt, m); lagopus_receive_packet(port, &pkt); TEST_ASSERT_NOT_EQUAL_MESSAGE(pkt.in_port, NULL, "port error."); TEST_ASSERT_EQUAL_MESSAGE(m->refcnt, 1, "m->refcnt error."); dpmgr_free(my_dpmgr); }
void test_lagopus_match_and_action(void) { struct action_list action_list; struct dpmgr *my_dpmgr; struct bridge *bridge; struct table *table; struct action *action; struct ofp_action_output *action_set; struct port nport, *port; 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.ifindex = 0; nport.ofp_port.hw_addr[0] = 1; dpmgr_port_add(my_dpmgr, &nport); nport.ifindex = 1; dpmgr_port_add(my_dpmgr, &nport); dpmgr_bridge_port_add(my_dpmgr, "br0", 0, 1); dpmgr_bridge_port_add(my_dpmgr, "br0", 1, 2); bridge = dpmgr_bridge_lookup(my_dpmgr, "br0"); TEST_ASSERT_NOT_NULL(bridge); flowdb_switch_mode_set(bridge->flowdb, SWITCH_MODE_OPENFLOW); table = table_get(bridge->flowdb, 0); table->userdata = new_flowinfo_eth_type(); 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); m = calloc(1, sizeof(*m)); TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error."); m->data = &m->dat[128]; m->refcnt = 2; port = port_lookup(bridge->ports, 1); TEST_ASSERT_NOT_NULL(port); lagopus_set_in_port(&pkt, port); TEST_ASSERT_EQUAL(pkt.in_port, port); TEST_ASSERT_EQUAL(pkt.in_port->bridge, bridge); pkt.table_id = 0; lagopus_packet_init(&pkt, m); lagopus_match_and_action(&pkt); TEST_ASSERT_EQUAL_MESSAGE(m->refcnt, 1, "match_and_action refcnt error."); free(m); dpmgr_free(my_dpmgr); }
void test_lagopus_set_in_port(void) { struct lagopus_packet pkt; struct port port; lagopus_set_in_port(&pkt, &port); TEST_ASSERT_EQUAL_MESSAGE(pkt.in_port, &port, "port error."); }
void test_classify_packet_IPV4_TCP(void) { struct port port; struct lagopus_packet pkt; OS_MBUF *m; /* prepare packet */ m = calloc(1, sizeof(*m)); TEST_ASSERT_NOT_EQUAL_MESSAGE(m, NULL, "calloc error."); m->data = &m->dat[128]; OS_M_PKTLEN(m) = 128; m->data[12] = 0x08; m->data[13] = 0x00; m->data[14] = 0x45; m->data[23] = IPPROTO_TCP; pkt.mbuf = (OS_MBUF *)m; lagopus_set_in_port(&pkt, &port); classify_packet(&pkt); TEST_ASSERT_EQUAL_MESSAGE(pkt.ether_type, ETHERTYPE_IP, "ether_type error."); TEST_ASSERT_EQUAL_MESSAGE(pkt.l3_hdr, &m->data[14], "l3_hdr error."); TEST_ASSERT_EQUAL_MESSAGE(pkt.l4_hdr, &m->data[34], "l4_hdr error."); /* with VLAN */ m->data[12] = 0x81; m->data[13] = 0x00; m->data[16] = 0x08; m->data[17] = 0x00; m->data[18] = 0x45; m->data[27] = IPPROTO_TCP; pkt.mbuf = (OS_MBUF *)m; lagopus_set_in_port(&pkt, &port); classify_packet(&pkt); TEST_ASSERT_EQUAL_MESSAGE(pkt.ether_type, ETHERTYPE_IP, "ether_type(vlan) error."); TEST_ASSERT_EQUAL_MESSAGE(pkt.l3_hdr, &m->data[18], "l3_hdr(vlan) error."); TEST_ASSERT_EQUAL_MESSAGE(pkt.l4_hdr, &m->data[38], "l4_hdr(vlan) error."); }
void test_match_basic_IPV6_ND_TLL(void) { struct lagopus_packet pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; int 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) = 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); m->data[12] = 0x86; m->data[13] = 0xdd; m->data[19] = 0x80; /* PLEN */ m->data[20] = IPPROTO_ICMPV6; m->data[54] = ND_NEIGHBOR_ADVERT; m->data[78] = ND_OPT_SOURCE_LINKADDR; m->data[79] = 1; m->data[86] = ND_OPT_TARGET_LINKADDR; m->data[87] = 1; add_match(&flow->match_list, ETH_ALEN, OFPXMT_OFB_IPV6_ND_TLL << 1, 0xe0, 0x4d, 0x01, 0x34, 0x56, 0x78); refresh_match(flow); lagopus_set_in_port(&pkt, &port); lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IPV6_ND_TLL mismatch error."); i = 88; m->data[i++] = 0xe0; m->data[i++] = 0x4d; m->data[i++] = 0x01; m->data[i++] = 0x34; m->data[i++] = 0x56; m->data[i++] = 0x78; rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IPV6_ND_TLL match error."); }
void test_pop_pbb(void) { static const uint8_t odhost[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab }; static const uint8_t oshost[] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54 }; static const uint8_t idhost[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; static const uint8_t ishost[] = { 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb }; 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)); action_pop = (struct ofp_action_pop_mpls *)&action->ofpat; action_pop->type = OFPAT_POP_PBB; 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 + 18; OS_MEMCPY(&m->data[0], odhost, ETH_ALEN); OS_MEMCPY(&m->data[6], oshost, ETH_ALEN); m->data[12] = 0x88; m->data[13] = 0xe7; m->data[14] = 0x00; m->data[15] = 0x11; m->data[16] = 0x22; m->data[17] = 0x33; /* dhost and shost */ OS_MEMCPY(&m->data[18], idhost, ETH_ALEN); OS_MEMCPY(&m->data[24], ishost, ETH_ALEN); m->data[30] = 0x08; m->data[31] = 0x00; m->data[32] = 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, "POP_PBB length error."); TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(&m->data[0], idhost, ETH_ALEN, "POP_PBB ether_dhost error."); TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(&m->data[6], ishost, ETH_ALEN, "POP_PBB ether_shost error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x08, "POP_PBB ethertype[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0x00, "POP_PBB ethertype[1] error."); }
void test_set_field_IPV6_ND_TLL(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) = 128; m->data[12] = 0x86; m->data[13] = 0xdd; m->data[19] = 0x80; /* PLEN */ m->data[20] = IPPROTO_ICMPV6; m->data[54] = ND_NEIGHBOR_ADVERT; m->data[78] = ND_OPT_SOURCE_LINKADDR; m->data[79] = 1; m->data[86] = ND_OPT_TARGET_LINKADDR; m->data[87] = 1; lagopus_set_in_port(&pkt, &port); lagopus_packet_init(&pkt, m); set_match(action_set->field, ETH_ALEN, OFPXMT_OFB_IPV6_ND_TLL << 1, 0xe0, 0x4d, 0x01, 0x34, 0x56, 0x78); execute_action(&pkt, &action_list); i = 88; TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xe0, "SET_FIELD IPV6_ND_TLL[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x4d, "SET_FIELD IPV6_ND_TLL[1] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x01, "SET_FIELD IPV6_ND_TLL[2] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x34, "SET_FIELD IPV6_ND_TLL[3] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x56, "SET_FIELD IPV6_ND_TLL[4] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x78, "SET_FIELD IPV6_ND_TLL[5] error."); }
void test_pop_vlan(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)); action_pop = (struct ofp_action_pop_mpls *)&action->ofpat; action_pop->type = OFPAT_POP_VLAN; 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 + 4; m->data[12] = 0x81; m->data[13] = 0x00; m->data[14] = 0x30; m->data[15] = 50; m->data[16] = 0x08; m->data[17] = 0x00; m->data[18] = 0x45; m->data[26] = 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, "POP_VLAN length error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x08, "POP_VLAN ethertype[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0x00, "POP_VLAN ethertype[1] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[14], 0x45, "POP_VLAN ip_vhl error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[22], 240, "POP_VLAN ip_ttl error."); }
void test_classify_packet_IPV6_other(void) { struct port port; struct lagopus_packet pkt; OS_MBUF *m; 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] = 0x86; m->data[13] = 0xdd; m->data[20] = IPPROTO_RSVP; pkt.mbuf = (OS_MBUF *)m; lagopus_set_in_port(&pkt, &port); classify_packet(&pkt); TEST_ASSERT_EQUAL_MESSAGE(pkt.ether_type, ETHERTYPE_IPV6, "ether_type error."); /* with exthdr */ m->data[20] = IPPROTO_DSTOPTS; m->data[54] = IPPROTO_RSVP; m->data[55] = 0; classify_packet(&pkt); TEST_ASSERT_EQUAL_MESSAGE(pkt.ether_type, ETHERTYPE_IPV6, "ether_type(exthdr) error."); /* with VLAN */ m->data[12] = 0x81; m->data[13] = 0x00; m->data[16] = 0x86; m->data[17] = 0xdd; m->data[24] = IPPROTO_RSVP; classify_packet(&pkt); TEST_ASSERT_EQUAL_MESSAGE(pkt.ether_type, ETHERTYPE_IPV6, "ether_type(vlan) error."); /* with VLAN and exthdr */ m->data[24] = IPPROTO_DSTOPTS; m->data[58] = IPPROTO_RSVP; m->data[59] = 0; classify_packet(&pkt); TEST_ASSERT_EQUAL_MESSAGE(pkt.ether_type, ETHERTYPE_IPV6, "ether_type(vlan+exthdr) error."); }
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."); }
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."); }
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."); }
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."); }
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."); }
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); m = calloc(1, sizeof(*m)); TEST_ASSERT_NOT_EQUAL_MESSAGE(m, NULL, "calloc error."); m->data = &m->dat[128]; OS_M_PKTLEN(m) = 64; OS_MEMCPY(&m->data[0], dhost, ETH_ALEN); OS_MEMCPY(&m->data[6], shost, ETH_ALEN); 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 + 18, "PUSH_PBB length error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x88, "PUSH_PBB TPID[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0xe7, "PUSH_PBB TPID[1] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[14], 0, "PUSH_PBB pcp_dei error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[15], 0x00, "PUSH_PBB i_sid[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x00, "PUSH_PBB i_sid[1] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0x00, "PUSH_PBB i_sid[2] error."); TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(&m->data[18], dhost, ETH_ALEN, "PUSH_PBB dhost error."); TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(&m->data[24], shost, ETH_ALEN, "PUSH_PBB shost error."); m->data[15] = 0xab; m->data[16] = 0xcd; m->data[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(m->data[15], 0xab, "PUSH_PBB(2) i_sid[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0xcd, "PUSH_PBB(2) i_sid[1] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0xef, "PUSH_PBB(2) i_sid[2] error."); }
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_set_in_port(&pkt, &port); lagopus_packet_init(&pkt, m); 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."); }
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."); }
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_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."); 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."); }
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); }