本文整理汇总了C++中OS_M_PKTLEN函数的典型用法代码示例。如果您正苦于以下问题:C++ OS_M_PKTLEN函数的具体用法?C++ OS_M_PKTLEN怎么用?C++ OS_M_PKTLEN使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OS_M_PKTLEN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_set_field_IPV6_SCTP_SRC
void
test_set_field_IPV6_SCTP_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_PKTLEN(m) = 128;
OS_MTOD(m, uint8_t *)[12] = 0x86;
OS_MTOD(m, uint8_t *)[13] = 0xdd;
OS_MTOD(m, uint8_t *)[20] = IPPROTO_SCTP;
lagopus_packet_init(pkt, m, &port);
set_match(action_set->field, 2, OFPXMT_OFB_SCTP_SRC << 1,
0x80, 0x21);
execute_action(pkt, &action_list);
TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[54], 0x80,
"SET_FIELD IPV6_SCTP_SRC[0] error.");
TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[55], 0x21,
"SET_FIELD IPV6_SCTP_SRC[1] error.");
OS_MTOD(m, uint8_t *)[20] = IPPROTO_DSTOPTS;
OS_MTOD(m, uint8_t *)[54] = IPPROTO_SCTP;
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_SCTP,
"SET_FIELD IPV6_SCTP_SRC proto error.");
TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[62], 0x80,
"SET_FIELD IPV6_SCTP_SRC[0](next hdr) error.");
TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[63], 0x21,
"SET_FIELD IPV6_SCTP_SRC[1](next hdr) error.");
}
示例2: test_set_field_IPV6_SCTP_DST
void
test_set_field_IPV6_SCTP_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) = 128;
m->data[12] = 0x86;
m->data[13] = 0xdd;
m->data[20] = IPPROTO_SCTP;
lagopus_packet_init(&pkt, m, &port);
set_match(action_set->field, 2, OFPXMT_OFB_SCTP_DST << 1,
0x80, 0x21);
execute_action(&pkt, &action_list);
TEST_ASSERT_EQUAL_MESSAGE(m->data[56], 0x80,
"SET_FIELD IPV6_SCTP_DST[0] error.");
TEST_ASSERT_EQUAL_MESSAGE(m->data[57], 0x21,
"SET_FIELD IPV6_SCTP_DST[1] error.");
m->data[20] = IPPROTO_DSTOPTS;
m->data[54] = IPPROTO_SCTP;
m->data[55] = 0;
lagopus_packet_init(&pkt, m, &port);
execute_action(&pkt, &action_list);
TEST_ASSERT_EQUAL_MESSAGE(m->data[54], IPPROTO_SCTP,
"SET_FIELD IPV6_SCTP_DST proto error.");
TEST_ASSERT_EQUAL_MESSAGE(m->data[64], 0x80,
"SET_FIELD IPV6_SCTP_DST[0](next hdr) error.");
TEST_ASSERT_EQUAL_MESSAGE(m->data[65], 0x21,
"SET_FIELD IPV6_SCTP_DST[1](next hdr) error.");
}
示例3: test_match_basic_IPV4_SCTP_SRC
void
test_match_basic_IPV4_SCTP_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;
add_match(&flow->match_list, 1, OFPXMT_OFB_IP_PROTO << 1,
IPPROTO_SCTP);
m->data[27] = IPPROTO_SCTP;
/* SCTP_SRC */
add_match(&flow->match_list, 2, OFPXMT_OFB_SCTP_SRC << 1,
0xf0, 0x00);
m->data[38] = 0;
m->data[39] = 0xf0;
refresh_match(flow);
lagopus_packet_init(&pkt, m);
rv = match_basic(&pkt, flow);
TEST_ASSERT_EQUAL_MESSAGE(rv, false,
"SCTP_SRC mismatch error.");
m->data[38] = 0xf0;
m->data[39] = 0x00;
rv = match_basic(&pkt, flow);
TEST_ASSERT_EQUAL_MESSAGE(rv, true,
"SCTP_SRC match error.");
free(m);
}
示例4: test_pop_vlan
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);
pkt = alloc_lagopus_packet();
TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
m = pkt->mbuf;
OS_M_APPEND(m, 64 + 4);
OS_MTOD(m, uint8_t *)[12] = 0x81;
OS_MTOD(m, uint8_t *)[13] = 0x00;
OS_MTOD(m, uint8_t *)[14] = 0x30;
OS_MTOD(m, uint8_t *)[15] = 50;
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 *)[26] = 240;
lagopus_packet_init(pkt, m, &port);
execute_action(pkt, &action_list);
TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64,
"POP_VLAN length error.");
TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[12], 0x08,
"POP_VLAN ethertype[0] error.");
TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[13], 0x00,
"POP_VLAN ethertype[1] error.");
TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[14], 0x45,
"POP_VLAN ip_vhl error.");
TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[22], 240,
"POP_VLAN ip_ttl error.");
}
示例5: test_classify_packet_IPV4_TCP
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.");
}
示例6: test_classify_packet_IPV6_other
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.");
}
示例7: test_match_basic_PBB_ISID_W
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.");
}
示例8: test_set_field_ETH_TYPE
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.");
}
示例9: copy_packet
/**
* Copy packet for output.
*/
struct lagopus_packet *
copy_packet(struct lagopus_packet *src_pkt) {
struct rte_mbuf *mbuf;
struct lagopus_packet *pkt;
size_t pktlen;
pkt = alloc_lagopus_packet();
if (pkt == NULL) {
lagopus_msg_error("alloc_lagopus_packet failed\n");
return NULL;
}
mbuf = pkt->mbuf;
pktlen = OS_M_PKTLEN(src_pkt->mbuf);
OS_M_APPEND(mbuf, pktlen);
memcpy(OS_MTOD(pkt->mbuf, char *), OS_MTOD(src_pkt->mbuf, char *), pktlen);
pkt->in_port = src_pkt->in_port;
/* other pkt members are not used in physical output. */
return pkt;
}
示例10: test_set_field_ETH_SRC
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.");
}
示例11: test_set_field_ICMPV6_TYPE
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.");
}
示例12: test_set_field_ETH_DST
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.");
}
示例13: test_match_basic_IPV6_FLABEL
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.");
}
示例14: test_classify_packet_IPV4_UDP
void
test_classify_packet_IPV4_UDP(void) {
struct port port;
struct lagopus_packet *pkt;
OS_MBUF *m;
/* prepare packet */
pkt = alloc_lagopus_packet();
TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
m = PKT2MBUF(pkt);
OS_M_PKTLEN(m) = 128;
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);
TEST_ASSERT_EQUAL_MESSAGE(pkt->ether_type, ETHERTYPE_IP,
"ether_type error.");
TEST_ASSERT_EQUAL_MESSAGE(pkt->l3_hdr, &OS_MTOD(m, uint8_t *)[14],
"l3_hdr error.");
TEST_ASSERT_EQUAL_MESSAGE(pkt->l4_hdr, &OS_MTOD(m, uint8_t *)[34],
"l4_hdr error.");
/* with VLAN */
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;
classify_ether_packet(pkt);
TEST_ASSERT_EQUAL_MESSAGE(pkt->ether_type, ETHERTYPE_IP,
"ether_type(vlan) error.");
TEST_ASSERT_EQUAL_MESSAGE(pkt->l3_hdr, &OS_MTOD(m, uint8_t *)[18],
"l3_hdr(vlan) error.");
TEST_ASSERT_EQUAL_MESSAGE(pkt->l4_hdr, &OS_MTOD(m, uint8_t *)[38],
"l4_hdr(vlan) error.");
}
示例15: test_dec_mpls_ttl
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.");
}