void test_match_basic_PHY_PORT(void) { struct lagopus_packet pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* prepare packet */ memset(&port, 0, sizeof(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 = allocate_test_flow(10 * sizeof(struct match)); /* Port */ FLOW_ADD_PORT_MATCH(flow, 4); add_match(&flow->match_list, 4, OFPXMT_OFB_IN_PHY_PORT << 1, 0x00, 0x00, 0x00, 0x04); refresh_match(flow); lagopus_packet_init(&pkt, m, &port); pkt.oob_data.in_port = htonl(4); pkt.oob_data.in_phy_port = htonl(1); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IN_PHY_PORT mismatch error."); pkt.oob_data.in_phy_port = htonl(4); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IN_PHY_PORT match error."); }
void test_match_basic_METADATA_W(void) { static const uint8_t metadata[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 }; struct lagopus_packet pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* 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; /* prepare flow */ flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match)); TAILQ_INIT(&flow->match_list); /* metadata */ pkt.oob_data.metadata = 0; add_match(&flow->match_list, 16, (OFPXMT_OFB_METADATA << 1) + 1, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00); refresh_match(flow); lagopus_packet_init(&pkt, m, &port); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "METAADTA_W mismatch error."); memcpy(&pkt.oob_data.metadata, metadata, sizeof(pkt.oob_data.metadata)); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "METADATA_W match error."); }
void test_match_basic_IPV4_PROTO(void) { struct lagopus_packet pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* 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, 0x08, 0x00); /* IP proto */ add_match(&flow->match_list, 1, OFPXMT_OFB_IP_PROTO << 1, IPPROTO_TCP); refresh_match(flow); m->data[12] = 0x08; m->data[13] = 0x00; m->data[14] = 0x45; m->data[23] = IPPROTO_UDP; lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IP_PROTO mismatch error."); m->data[23] = IPPROTO_TCP; lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IP_PROTO match error."); m->data[12] = 0x81; m->data[13] = 0x00; m->data[16] = 0x08; m->data[17] = 0x00; m->data[18] = 0x45; m->data[27] = IPPROTO_UDP; lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IP_PROTO mismatch(vlan) error."); m->data[27] = IPPROTO_TCP; lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IP_PROTO match(vlan) error."); free(m); }
void test_match_basic_IPV4_SRC(void) { struct lagopus_packet pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* 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, 0x08, 0x00); m->data[12] = 0x81; m->data[13] = 0x00; m->data[16] = 0x08; m->data[17] = 0x00; m->data[18] = 0x45; /* IP src */ add_match(&flow->match_list, 4, OFPXMT_OFB_IPV4_SRC << 1, 192, 168, 0, 1); m->data[30] = 192; m->data[31] = 167; m->data[32] = 0; m->data[33] = 1; refresh_match(flow); lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IPV4_SRC mismatch(1) error."); add_match(&flow->match_list, 4, OFPXMT_OFB_IPV4_SRC << 1, 192, 168, 0, 1); refresh_match(flow); m->data[30] = 1; m->data[31] = 0; m->data[32] = 168; m->data[33] = 192; lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IPV4_SRC mismatch(2) error."); m->data[30] = 192; m->data[31] = 168; m->data[32] = 0; m->data[33] = 1; lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IPV4_SRC match error."); free(m); }
void test_match_basic_IPV4_PROTO(void) { struct lagopus_packet *pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* prepare packet */ pkt = alloc_lagopus_packet(); TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error."); m = pkt->mbuf; OS_M_APPEND(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, 0x08, 0x00); /* IP proto */ add_match(&flow->match_list, 1, OFPXMT_OFB_IP_PROTO << 1, IPPROTO_TCP); refresh_match(flow); 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 *)[23] = IPPROTO_UDP; lagopus_packet_init(pkt, m, &port); rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IP_PROTO mismatch error."); OS_MTOD(m, uint8_t *)[23] = IPPROTO_TCP; lagopus_packet_init(pkt, m, &port); rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IP_PROTO match error."); OS_MTOD(m, uint8_t *)[12] = 0x81; OS_MTOD(m, uint8_t *)[13] = 0x00; OS_MTOD(m, uint8_t *)[16] = 0x08; OS_MTOD(m, uint8_t *)[17] = 0x00; OS_MTOD(m, uint8_t *)[18] = 0x45; OS_MTOD(m, uint8_t *)[27] = IPPROTO_UDP; lagopus_packet_init(pkt, m, &port); rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IP_PROTO mismatch(vlan) error."); OS_MTOD(m, uint8_t *)[27] = IPPROTO_TCP; lagopus_packet_init(pkt, m, &port); rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IP_PROTO match(vlan) error."); free(m); }
void test_match_basic_IPV4_SRC(void) { struct lagopus_packet *pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* prepare packet */ pkt = alloc_lagopus_packet(); TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error."); m = pkt->mbuf; OS_M_APPEND(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, 0x08, 0x00); OS_MTOD(m, uint8_t *)[12] = 0x81; OS_MTOD(m, uint8_t *)[13] = 0x00; OS_MTOD(m, uint8_t *)[16] = 0x08; OS_MTOD(m, uint8_t *)[17] = 0x00; OS_MTOD(m, uint8_t *)[18] = 0x45; /* IP src */ add_match(&flow->match_list, 4, OFPXMT_OFB_IPV4_SRC << 1, 192, 168, 0, 1); OS_MTOD(m, uint8_t *)[30] = 192; OS_MTOD(m, uint8_t *)[31] = 167; OS_MTOD(m, uint8_t *)[32] = 0; OS_MTOD(m, uint8_t *)[33] = 1; refresh_match(flow); lagopus_packet_init(pkt, m, &port); rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IPV4_SRC mismatch(1) error."); add_match(&flow->match_list, 4, OFPXMT_OFB_IPV4_SRC << 1, 192, 168, 0, 1); refresh_match(flow); OS_MTOD(m, uint8_t *)[30] = 1; OS_MTOD(m, uint8_t *)[31] = 0; OS_MTOD(m, uint8_t *)[32] = 168; OS_MTOD(m, uint8_t *)[33] = 192; lagopus_packet_init(pkt, m, &port); rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IPV4_SRC mismatch(2) error."); OS_MTOD(m, uint8_t *)[30] = 192; OS_MTOD(m, uint8_t *)[31] = 168; OS_MTOD(m, uint8_t *)[32] = 0; OS_MTOD(m, uint8_t *)[33] = 1; lagopus_packet_init(pkt, m, &port); rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IPV4_SRC match error."); free(m); }
void test_match_basic_IPV6_SCTP_DST(void) { struct lagopus_packet pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* 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) = 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); m->data[12] = 0x86; m->data[13] = 0xdd; add_match(&flow->match_list, 1, OFPXMT_OFB_IP_PROTO << 1, IPPROTO_SCTP); m->data[20] = IPPROTO_SCTP; /* SCTP_DST */ add_match(&flow->match_list, 2, OFPXMT_OFB_SCTP_DST << 1, 0xf0, 0x00); m->data[56] = 0; m->data[57] = 0xf0; refresh_match(flow); lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IPV6_SCTP_DST mismatch error."); m->data[56] = 0xf0; m->data[57] = 0x00; rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IPV6_SCTP_DST match error."); m->data[20] = IPPROTO_DSTOPTS; m->data[54] = IPPROTO_SCTP; m->data[55] = 0; lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); m->data[64] = 0x00; m->data[65] = 0xf0; TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IPV6_SCTP_DST mismatch(next hdr) error."); m->data[64] = 0xf0; m->data[65] = 0x00; rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IPV6_SCTP_DST match(next hdr) error."); free(m); }
void test_match_basic_IPV6_ICMPV6_CODE(void) { struct lagopus_packet pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* 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); /* 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[20] = IPPROTO_ICMPV6; add_match(&flow->match_list, 1, OFPXMT_OFB_ICMPV6_CODE << 1, ICMP6_DST_UNREACH_ADDR); m->data[55] = ICMP6_DST_UNREACH_ADMIN; refresh_match(flow); lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "ICMPV6_CODE mismatch error."); m->data[55] = ICMP6_DST_UNREACH_ADDR; rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "ICMPV6_CODE match error."); m->data[20] = IPPROTO_DSTOPTS; m->data[54] = IPPROTO_ICMPV6; m->data[55] = 0; m->data[63] = ICMP6_DST_UNREACH_ADMIN; lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "ICMPV6_CODE mismatch(next hdr) error."); m->data[63] = ICMP6_DST_UNREACH_ADDR; lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "ICMPV6_CODE match(next hdr) 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_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 */ 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 *)[19] = 0x80; /* PLEN */ OS_MTOD(m, uint8_t *)[20] = IPPROTO_ICMPV6; OS_MTOD(m, uint8_t *)[54] = ND_NEIGHBOR_ADVERT; OS_MTOD(m, uint8_t *)[78] = ND_OPT_SOURCE_LINKADDR; OS_MTOD(m, uint8_t *)[79] = 1; OS_MTOD(m, uint8_t *)[86] = ND_OPT_TARGET_LINKADDR; OS_MTOD(m, uint8_t *)[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_packet_init(pkt, m, &port); rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IPV6_ND_TLL mismatch error."); i = 88; OS_MTOD(m, uint8_t *)[i++] = 0xe0; OS_MTOD(m, uint8_t *)[i++] = 0x4d; OS_MTOD(m, uint8_t *)[i++] = 0x01; OS_MTOD(m, uint8_t *)[i++] = 0x34; OS_MTOD(m, uint8_t *)[i++] = 0x56; OS_MTOD(m, uint8_t *)[i++] = 0x78; rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IPV6_ND_TLL match error."); }
void test_match_basic_IPV6_EXTHDR_W(void) { struct lagopus_packet pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* 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) = 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); m->data[12] = 0x86; m->data[13] = 0xdd; add_match(&flow->match_list, 1, OFPXMT_OFB_IP_PROTO << 1, IPPROTO_TCP); m->data[20] = IPPROTO_DSTOPTS; m->data[54] = IPPROTO_TCP; m->data[55] = 4; add_match(&flow->match_list, 4, (OFPXMT_OFB_IPV6_EXTHDR << 1) + 1, OFPIEH_UNSEQ >> 8, 0, OFPIEH_UNSEQ >> 8, OFPIEH_UNREP); refresh_match(flow); lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IPV6_EXTHDR_W mismatch error."); m->data[54] = IPPROTO_HOPOPTS; m->data[55] = 0; m->data[62] = IPPROTO_ESP; m->data[63] = 0; m->data[70] = IPPROTO_AH; m->data[72] = 0; m->data[78] = IPPROTO_ROUTING; m->data[79] = 0; m->data[86] = IPPROTO_FRAGMENT; m->data[94] = IPPROTO_NONE; m->data[95] = 0; m->data[102] = IPPROTO_TCP; lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IPV6_EXTHDR_W match error."); }
void test_match_basic_MPLSMC_BOS(void) { struct lagopus_packet pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* 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, 0x88, 0x48); m->data[12] = 0x88; m->data[13] = 0x48; /* MPLSMC_BOS */ add_match(&flow->match_list, 1, OFPXMT_OFB_MPLS_BOS << 1, 1); m->data[14] = 0xff; m->data[15] = 0xff; m->data[16] = 0xfe; m->data[17] = 0xff; refresh_match(flow); lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "MPLSMC_BOS mismatch(1) error."); m->data[14] = 0x00; m->data[15] = 0x01; m->data[16] = 0x00; m->data[17] = 0x00; lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "MPLSMC_BOS mismatch(2) error."); m->data[14] = 0x00; m->data[15] = 0x00; m->data[16] = 0x01; m->data[17] = 0x00; lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "MPLSMC_BOS match error."); }
void test_match_basic_PBB_ISID_W(void) { struct lagopus_packet pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* 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; /* prepare flow */ flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match)); TAILQ_INIT(&flow->match_list); #ifndef PBB_IS_VLAN add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1, 0x88, 0xe7); #endif m->data[12] = 0x88; m->data[13] = 0xe7; add_match(&flow->match_list, 6, (OFPXMT_OFB_PBB_ISID << 1) + 1, 0x5a, 0xc3, 0x00, 0xff, 0xff, 0x00); refresh_match(flow); lagopus_packet_init(&pkt, m, &port); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "PBB_ISID_W mismatch(1) error."); m->data[15] = 0x3c; m->data[16] = 0xc3; m->data[17] = 0x5a; rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "PBB_ISID_W mismatch(2) error."); m->data[15] = 0x5a; m->data[16] = 0xc3; m->data[17] = 0x3c; rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "PBB_ISID_W match error."); }
void test_match_basic_PBB_ISID_W(void) { struct lagopus_packet *pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* prepare packet */ pkt = alloc_lagopus_packet(); TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error."); m = PKT2MBUF(pkt); OS_M_APPEND(m, 64); /* prepare flow */ flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match)); TAILQ_INIT(&flow->match_list); #ifndef PBB_IS_VLAN add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1, 0x88, 0xe7); #endif OS_MTOD(m, uint8_t *)[12] = 0x88; OS_MTOD(m, uint8_t *)[13] = 0xe7; add_match(&flow->match_list, 6, (OFPXMT_OFB_PBB_ISID << 1) + 1, 0x5a, 0xc3, 0x00, 0xff, 0xff, 0x00); refresh_match(flow); lagopus_packet_init(pkt, m, &port); rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "PBB_ISID_W mismatch(1) error."); OS_MTOD(m, uint8_t *)[15] = 0x3c; OS_MTOD(m, uint8_t *)[16] = 0xc3; OS_MTOD(m, uint8_t *)[17] = 0x5a; rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "PBB_ISID_W mismatch(2) error."); OS_MTOD(m, uint8_t *)[15] = 0x5a; OS_MTOD(m, uint8_t *)[16] = 0xc3; OS_MTOD(m, uint8_t *)[17] = 0x3c; rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "PBB_ISID_W match error."); }
void test_match_basic_IPV6_FLABEL(void) { struct lagopus_packet pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* 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; m->data[15] = 0x00; m->data[16] = 0x12; m->data[17] = 0x34; add_match(&flow->match_list, 4, OFPXMT_OFB_IPV6_FLABEL << 1, 0x00, 0x01, 0x23, 0x45); refresh_match(flow); lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IPV6_FLABEL mismatch error."); m->data[15] = 0x01; m->data[16] = 0x23; m->data[17] = 0x45; lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IPV6_FLABEL match error."); }
void test_match_basic_VLAN_VID_W(void) { struct lagopus_packet *pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* prepare packet */ pkt = alloc_lagopus_packet(); TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error."); m = PKT2MBUF(pkt); OS_M_APPEND(m, 64); /* prepare flow */ flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match)); TAILQ_INIT(&flow->match_list); /* VLAN VID_NONE */ add_match(&flow->match_list, 4, (OFPXMT_OFB_VLAN_VID << 1) + 1, 0x10, 0x00, 0x10, 0x00); refresh_match(flow); OS_MTOD(m, uint8_t *)[12] = 0x08; OS_MTOD(m, uint8_t *)[13] = 0x00; lagopus_packet_init(pkt, m, &port); rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "VLAN_VID_W mismatch error."); OS_MTOD(m, uint8_t *)[12] = 0x81; OS_MTOD(m, uint8_t *)[13] = 0x00; OS_MTOD(m, uint8_t *)[14] = 0x00; OS_MTOD(m, uint8_t *)[15] = 0xff; lagopus_packet_init(pkt, m, &port); rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "VLAN VID_W match error."); free(m); }
void test_match_basic_IPV4_IP_ECN(void) { struct lagopus_packet pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* 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, 0x08, 0x00); refresh_match(flow); m->data[12] = 0x08; m->data[13] = 0x00; m->data[14] = 0x45; add_match(&flow->match_list, 1, OFPXMT_OFB_IP_ECN << 1, 0x3); m->data[15] = 0xcc; refresh_match(flow); lagopus_packet_init(&pkt, m); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IP_ECN mismatch error."); m->data[15] = 0x03; rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IP_ECN match error."); }
void test_match_basic_IPV4_IP_ECN(void) { struct lagopus_packet *pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* prepare packet */ pkt = alloc_lagopus_packet(); TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error."); m = pkt->mbuf; OS_M_APPEND(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, 0x08, 0x00); refresh_match(flow); OS_MTOD(m, uint8_t *)[12] = 0x08; OS_MTOD(m, uint8_t *)[13] = 0x00; OS_MTOD(m, uint8_t *)[14] = 0x45; add_match(&flow->match_list, 1, OFPXMT_OFB_IP_ECN << 1, 0x3); OS_MTOD(m, uint8_t *)[15] = 0xcc; refresh_match(flow); lagopus_packet_init(pkt, m, &port); rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IP_ECN mismatch error."); OS_MTOD(m, uint8_t *)[15] = 0x03; rv = match_basic(pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IP_ECN match error."); }
void test_match_basic_IN_PORT(void) { struct lagopus_packet pkt; struct port port; struct flow *flow; OS_MBUF *m; bool rv; /* 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; /* prepare flow */ flow = allocate_test_flow(10 * sizeof(struct match)); refresh_match(flow); /* Port */ pkt.oob_data.in_port = htonl(2); lagopus_packet_init(&pkt, m, &port); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IN_PORT wildcard match error."); FLOW_ADD_PORT_MATCH(flow, 1); refresh_match(flow); pkt.oob_data.in_port = htonl(2); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IN_PORT mismatch error."); pkt.oob_data.in_port = htonl(1); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, true, "IN_PORT match error."); free(m); }
void test_match_basic_IPV6_DST_W(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 = 38; 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, 32, (OFPXMT_OFB_IPV6_DST << 1) + 1, 0x20, 0x01, 0x00, 0x00, 0xe0, 0x45, 0x22, 0xeb, 0x09, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00); refresh_match(flow); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IPV6_DST_W mismatch error."); i = 38; 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_DST_W match error."); }
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."); }
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.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) = 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[20] = IPPROTO_ICMPV6; m->data[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; 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); rv = match_basic(&pkt, flow); TEST_ASSERT_EQUAL_MESSAGE(rv, false, "IPV6_ND_TARGET mismatch error."); i = 62; 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_ND_TARGET match error."); }