Ejemplo n.º 1
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_packet_init(&pkt, m, &port);
  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.º 2
0
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.");
}
Ejemplo n.º 3
0
static void
pipeline_stage_create(lagopus_pipeline_stage_t *sptr,
                      lagopus_pipeline_stage_pre_pause_proc_t pre_pause_proc,
                      lagopus_pipeline_stage_sched_proc_t sched_proc,
                      lagopus_pipeline_stage_setup_proc_t setup_proc,
                      lagopus_pipeline_stage_fetch_proc_t fetch_proc,
                      lagopus_pipeline_stage_main_proc_t main_proc,
                      lagopus_pipeline_stage_throw_proc_t throw_proc,
                      lagopus_pipeline_stage_shutdown_proc_t shutdown_proc,
                      lagopus_pipeline_stage_finalize_proc_t finalize_proc,
                      lagopus_pipeline_stage_freeup_proc_t freeup_proc) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  size_t nthd = 1;

  ret = lagopus_pipeline_stage_create(sptr, 0,
                                      "lagopus_pipeline_stage_create",
                                      nthd,
                                      sizeof(void *), 1024,
                                      pre_pause_proc,
                                      sched_proc,
                                      setup_proc,
                                      fetch_proc,
                                      main_proc,
                                      throw_proc,
                                      shutdown_proc,
                                      finalize_proc,
                                      freeup_proc);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                            "lagopus_pipeline_stage_create error.");
  TEST_ASSERT_NOT_EQUAL_MESSAGE(NULL, *sptr,
                                "stage is NULL.");
}
Ejemplo n.º 4
0
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.");
}
Ejemplo n.º 5
0
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.");
}
Ejemplo n.º 6
0
void
setUp(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;

  /* create. */
  ret = lagopus_dstring_create(&ds);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                            "lagopus_dstring_create error.");
  TEST_ASSERT_NOT_EQUAL_MESSAGE(NULL, ds,
                                "dstring is null.");

  ret = lagopus_dstring_create(&ds2);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                            "lagopus_dstring_create error.");
  TEST_ASSERT_NOT_EQUAL_MESSAGE(NULL, ds2,
                                "dstring is null.");
}
Ejemplo n.º 7
0
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);
}
Ejemplo n.º 8
0
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
}
Ejemplo n.º 9
0
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.");
}
Ejemplo n.º 10
0
void
test_lagopus_pipeline_stage_create_already_exists(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  lagopus_pipeline_stage_t stage1 = NULL;
  lagopus_pipeline_stage_t stage2 = NULL;
  size_t nthd = 1;

  /* set data */
  ret = lagopus_pipeline_stage_create(&stage1, 0,
                                      "lagopus_pipeline_stage_create",
                                      nthd,
                                      sizeof(void *), 1024,
                                      pipeline_pre_pause,
                                      pipeline_sched,
                                      pipeline_setup,
                                      pipeline_fetch,
                                      pipeline_main,
                                      pipeline_throw,
                                      pipeline_shutdown,
                                      pipeline_finalize,
                                      pipeline_freeup);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                            "lagopus_pipeline_stage_create error.");
  TEST_ASSERT_NOT_EQUAL_MESSAGE(NULL, stage1,
                                "stage is NULL.");

  /* call func. */
  ret = lagopus_pipeline_stage_create(&stage2, 0,
                                      "lagopus_pipeline_stage_create",
                                      nthd,
                                      sizeof(void *), 1024,
                                      pipeline_pre_pause,
                                      pipeline_sched,
                                      pipeline_setup,
                                      pipeline_fetch,
                                      pipeline_main,
                                      pipeline_throw,
                                      pipeline_shutdown,
                                      pipeline_finalize,
                                      pipeline_freeup);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_ALREADY_EXISTS, ret,
                            "not already exists.");
  TEST_ASSERT_EQUAL_MESSAGE(NULL, stage2,
                            "stage is NULL.");

  /* after. */
  lagopus_pipeline_stage_destroy(&stage1);
  lagopus_pipeline_stage_destroy(&stage2);
}
Ejemplo n.º 11
0
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.");
}
Ejemplo n.º 12
0
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.");
}
Ejemplo n.º 13
0
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.");
}
Ejemplo n.º 14
0
void
test_lagopus_pipeline_stage_find_normal(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  lagopus_pipeline_stage_t stage = NULL;
  lagopus_pipeline_stage_t ret_stage1 = NULL;
  lagopus_pipeline_stage_t ret_stage2 = NULL;

  /* create data. */
  pipeline_stage_create(&stage,
                        pipeline_pre_pause,
                        pipeline_sched,
                        pipeline_setup,
                        pipeline_fetch,
                        pipeline_main,
                        pipeline_throw,
                        pipeline_shutdown,
                        pipeline_finalize,
                        pipeline_freeup);

  /* call func (normal - found). */
  ret = lagopus_pipeline_stage_find("lagopus_pipeline_stage_create",
                                    &ret_stage1);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                            "lagopus_pipeline_stage_find(normal - found) error.");
  TEST_ASSERT_NOT_EQUAL_MESSAGE(NULL, ret_stage1,
                                "ret_stage is NULL.");

  /* call func (normal - not found). */
  ret = lagopus_pipeline_stage_find("test_not_found",
                                    &ret_stage2);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_NOT_FOUND, ret,
                            "lagopus_pipeline_stage_find(normal- not found) "
                            "error.");
  TEST_ASSERT_EQUAL_MESSAGE(NULL, ret_stage2,
                            "ret_stage is not NULL.");

  /* after. */
  do_stop = true;
  lagopus_pipeline_stage_destroy(&stage);
}
Ejemplo n.º 15
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.º 16
0
void
test_channel_session_get_set(void) {
    struct channel *channel;
    lagopus_session_t session;
    lagopus_session_t ret_session;

    channel = s_create_data_channel();

    (void) session_create(SESSION_TCP|SESSION_ACTIVE, &session);
    TEST_ASSERT_NOT_EQUAL_MESSAGE(session, channel_session_get(channel),
                                  "session error.");
    session_destroy(channel_session_get(channel));

    /* Call func. */
    channel_session_set(channel, session);
    ret_session = channel_session_get(channel);

    TEST_ASSERT_EQUAL_MESSAGE(ret_session, session,
                              "session error.");

    session_destroy(channel_session_get(channel));
    free(channel);
}
Ejemplo n.º 17
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.º 18
0
void
test_ofp_bridgeq_mgr_bridgeqs_to_array_unregister(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  uint64_t i, j, delete_target = 1;
  uint64_t data_num = MAX_LENGTH;
  struct {
    uint64_t dpid;
    const char *name;
    bool b;
  } bridges[MAX_LENGTH] = {
    {0x01, "test_bridge01", false},
    {0x02, "test_bridge02", false},
    {0x03, "test_bridge02", false}
  };
  struct ofp_bridgeq *bridgeqs[MAX_BRIDGES];
  struct ofp_bridge *bridge;
  uint64_t poll_count = 0;
  uint64_t bridgeq_count = 0;
  lagopus_qmuxer_poll_t *polls =
    (lagopus_qmuxer_poll_t *) calloc(MAX_LENGTH * MAX_BRIDGE_POLLS,
                                     sizeof(lagopus_qmuxer_poll_t));
  lagopus_qmuxer_poll_t *dp_polls =
    (lagopus_qmuxer_poll_t *) calloc(MAX_LENGTH * MAX_BRIDGE_DP_POLLS,
                                     sizeof(lagopus_qmuxer_poll_t));
  datastore_bridge_info_t info = {0};
  datastore_bridge_queue_info_t q_info =
      {1000LL, 1000LL, 1000LL, 1000LL, 1000LL, 1000LL};

  /* register bridge. */
  for (i = 0; i < data_num; i++) {
    ret = ofp_bridgeq_mgr_bridge_register(bridges[i].dpid,
                                          bridges[i].name,
                                          &info,
                                          &q_info);
    TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                              "ofp_bridgeq_mgr_bridge_register error.");
  }

  ret = ofp_bridgeq_mgr_bridgeqs_to_array(bridgeqs, &bridgeq_count, MAX_LENGTH);

  /* delete entry. */
  bridge = ofp_bridgeq_mgr_bridge_get(bridgeqs[delete_target]);
  ofp_bridgeq_mgr_bridge_unregister(bridge->dpid);

  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                            "ofp_bridgeq_mgr_bridgeqs_to_array(normal) error.");
  TEST_ASSERT_EQUAL_MESSAGE(MAX_LENGTH, bridgeq_count,
                            "index error.");

  for (i = 0; i < data_num; i++) {
    for (j = 0; j < data_num; j++) {
      bridge = ofp_bridgeq_mgr_bridge_get(bridgeqs[i]);
      if (bridge->dpid == bridges[j].dpid) {
        /* check duplicate. */
        if (bridges[j].b == false) {
          bridges[j].b = true;
        } else {
          TEST_FAIL_MESSAGE("duplicate error.");
        }
      }
    }
  }
  /* check dpid. */
  for (i = 0; i < data_num; i++) {
    TEST_ASSERT_EQUAL_MESSAGE(true, bridges[i].b,
                              "dpid error.");
  }

  /* test ofp_bridgeq_mgr_polls_get() */
  poll_count = 0;
  ret = ofp_bridgeq_mgr_polls_get(polls, bridgeqs,
                                  &poll_count, data_num);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                            "ofp_bridgeq_mgr_polls_get(normal) error.");
  TEST_ASSERT_EQUAL_MESSAGE(data_num * MAX_BRIDGE_POLLS, poll_count,
                            "poll_count error.");
  for (i = 0; i < data_num * MAX_BRIDGE_POLLS; i++) {
    TEST_ASSERT_NOT_EQUAL_MESSAGE(NULL,
                                  polls[i],
                                  "polls error.");
  }

  /* test ofp_bridgeq_mgr_dp_polls_get() */
  poll_count = 0;
  ret = ofp_bridgeq_mgr_dp_polls_get(dp_polls, bridgeqs,
                                     &poll_count, data_num);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                            "ofp_bridgeq_mgr_dp_polls_get(normal) error.");
  TEST_ASSERT_EQUAL_MESSAGE(data_num * MAX_BRIDGE_DP_POLLS, poll_count,
                            "poll_count(DP) error.");
  for (i = 0; i < data_num * MAX_BRIDGE_DP_POLLS; i++) {
    TEST_ASSERT_NOT_EQUAL_MESSAGE(NULL,
                                  dp_polls[i],
                                  "polls error.");
  }

  /* test ofp_bridgeq_mgr_bridgeqs_free. */
  /* Call func.*/
  ofp_bridgeq_mgr_bridgeqs_free(bridgeqs, bridgeq_count);

  free(polls);
  free(dp_polls);
}
Ejemplo n.º 19
0
void
test_ofp_bridgeq_mgr_bridge(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  uint64_t dpid = 0x01;
  const char *bridge_name = "test_bridge01";
  char *test_bridge_name = NULL;
  struct ofp_bridgeq *bridgeq = NULL;
  lagopus_qmuxer_poll_t poll = NULL;
  datastore_bridge_info_t info =
      {1LL, 2LL, 3LL, 4LL, 5LL,
       6LL, 7LL, 8LL, 9LL, 10LL,
       11LL, 12LL};
  datastore_bridge_info_t test_info;
  datastore_bridge_queue_info_t q_info =
      {1000LL, 1000LL, 1000LL, 1000LL, 1000LL, 1000LL};

  /* register bridge. */
  ret = ofp_bridgeq_mgr_bridge_register(dpid, bridge_name, &info, &q_info);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                            "ofp_bridgeq_mgr_bridge_register error.");

  /* register same bridge. */
  ret = ofp_bridgeq_mgr_bridge_register(dpid, bridge_name, &info, &q_info);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_ALREADY_EXISTS, ret,
                            "ofp_bridgeq_mgr_bridge_register(same bridge) error.");

  /* lookup. */
  ret = ofp_bridgeq_mgr_bridge_lookup(dpid, &bridgeq);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                            "ofp_bridgeq_mgr_bridge_lookup error.");
  TEST_ASSERT_NOT_EQUAL_MESSAGE(NULL, bridgeq,
                                "bridgeq error.");

  /* get bridge name. */
  ret = ofp_bridgeq_mgr_name_get(dpid, &test_bridge_name);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                            "ofp_bridgeq_mgr_name_get error.");
  TEST_ASSERT_EQUAL_MESSAGE(0, strcmp(bridge_name, test_bridge_name),
                            "bad bridge name.");
  free(test_bridge_name);
  test_bridge_name = NULL;

  /* get bridge name (not found). */
  ret = ofp_bridgeq_mgr_name_get(0x999, &test_bridge_name);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_NOT_FOUND, ret,
                            "ofp_bridgeq_mgr_name_get error.");
  TEST_ASSERT_EQUAL_MESSAGE(NULL, test_bridge_name,
                            "bad bridge name.");

  /* get bridge info. */
  ret = ofp_bridgeq_mgr_info_get(dpid, &test_info);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                            "ofp_bridgeq_mgr_info_get error.");
  TEST_ASSERT_EQUAL_MESSAGE(1, ((info.dpid == test_info.dpid) &&
                                (info.fail_mode == test_info.fail_mode) &&
                                (info.max_buffered_packets ==
                                 test_info.max_buffered_packets) &&
                                (info.max_ports == test_info.max_ports) &&
                                (info.max_tables == test_info.max_tables) &&
                                (info.max_flows == test_info.max_flows) &&
                                (info.capabilities == test_info.capabilities) &&
                                (info.action_types == test_info.action_types) &&
                                (info.instruction_types ==
                                 test_info.instruction_types) &&
                                (info.reserved_port_types ==
                                 test_info.reserved_port_types) &&
                                (info.group_types == test_info.group_types) &&
                                (info.group_capabilities ==
                                 test_info.group_capabilities)),
                            "bad bridge info.");

  /* get bridge info (not found). */
  ret = ofp_bridgeq_mgr_info_get(0x999, &test_info);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_NOT_FOUND, ret,
                            "ofp_bridgeq_mgr_info_get error.");

  /* check getter. */
  poll = NULL;
  poll = ofp_bridgeq_mgr_eventq_poll_get(bridgeq);
  TEST_ASSERT_NOT_EQUAL_MESSAGE(NULL, poll,
                                "ofp_bridgeq_mgr_eventq_poll_get error.");
  poll = NULL;
  poll = ofp_bridgeq_mgr_dataq_poll_get(bridgeq);
  TEST_ASSERT_NOT_EQUAL_MESSAGE(NULL, poll,
                                "ofp_bridgeq_mgr_dataq_poll_get error.");

  /* decrement refs. */
  ofp_bridgeq_mgr_bridgeq_free(bridgeq);

  /* unregister bridge. */
  ret = ofp_bridgeq_mgr_bridge_unregister(dpid);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                            "ofp_bridgeq_mgr_bridge_unregister error.");

  /* lookup. */
  bridgeq = NULL;
  ret = ofp_bridgeq_mgr_bridge_lookup(dpid, &bridgeq);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_NOT_FOUND, ret,
                            "ofp_bridgeq_mgr_bridge_lookup error.");
}
Ejemplo n.º 20
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.º 21
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.º 22
0
void
test_group_stats(void) {
  struct bridge *bridge;
  struct group_table *group_table;
  struct group *group;
  struct ofp_group_mod group_mod;
  struct bucket_list bucket_list;
  struct ofp_group_stats_request request;
  struct group_stats_list group_stats_list;
  struct group_stats *stats;
  struct ofp_error error;
  struct ofp_flow_mod flow_mod;
  struct match_list match_list;
  struct instruction_list instruction_list;
  struct instruction *instruction;
  struct action *action;
  lagopus_result_t ret;

  bridge = dp_bridge_lookup("br0");
  TEST_ASSERT_NOT_NULL_MESSAGE(bridge, "bridge alloc error.");
  TAILQ_INIT(&bucket_list);
  group_table = group_table_alloc(bridge);
  TEST_ASSERT_NOT_NULL_MESSAGE(bridge, "group_table alloc error.");
  bridge->group_table = group_table;

  group_mod.group_id = 1;
  group_mod.type = OFPGT_ALL;
  group = group_alloc(&group_mod, &bucket_list);
  ret = group_table_add(group_table, group, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "group_table_add error");

  group_mod.group_id = 1000000;
  group_mod.type = OFPGT_ALL;
  group = group_alloc(&group_mod, &bucket_list);
  ret = group_table_add(group_table, group, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "group_table_add error");

  request.group_id = 1;
  TAILQ_INIT(&group_stats_list);
  ret = group_stats(group_table, &request, &group_stats_list, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "get stats error");
  stats = TAILQ_FIRST(&group_stats_list);
  TEST_ASSERT_NOT_NULL_MESSAGE(stats, "group not found");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.group_id, 1,
                            "group id error");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.duration_sec, 0,
                            "duration sec error");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.ref_count, 0,
                            "ref_count error");
  stats = TAILQ_NEXT(stats, entry);
  TEST_ASSERT_NULL_MESSAGE(stats, "number of groups error");

  TAILQ_INIT(&match_list);
  TAILQ_INIT(&instruction_list);
  instruction = instruction_alloc();
  TEST_ASSERT_NOT_NULL_MESSAGE(instruction, "instruction alloc error.");
  instruction->ofpit.type = OFPIT_APPLY_ACTIONS;
  TAILQ_INIT(&instruction->action_list);
  action = action_alloc(sizeof(struct ofp_action_group));
  TEST_ASSERT_NOT_NULL_MESSAGE(action, "action alloc error.");
  action->ofpat.type = OFPAT_GROUP;
  ((struct ofp_action_group *)&action->ofpat)->group_id = 5;
  TAILQ_INSERT_TAIL(&instruction->action_list, action, entry);
  TAILQ_INSERT_TAIL(&instruction_list, instruction, entry);
  flow_mod.table_id = 0;
  flow_mod.priority = 1;
  flow_mod.flags = 0;
  flow_mod.cookie = 0;
  ret = flowdb_flow_add(bridge, &flow_mod, &match_list,
                        &instruction_list, &error);
  TEST_ASSERT_NOT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                                "flowdb_flow_add: group check error");
  TAILQ_INIT(&match_list);
  TAILQ_INIT(&instruction_list);
  instruction = instruction_alloc();
  TEST_ASSERT_NOT_NULL_MESSAGE(instruction, "instruction alloc error.");
  instruction->ofpit.type = OFPIT_APPLY_ACTIONS;
  TAILQ_INIT(&instruction->action_list);
  action = action_alloc(sizeof(struct ofp_action_group));
  TEST_ASSERT_NOT_NULL_MESSAGE(action, "action alloc error.");
  action->ofpat.type = OFPAT_GROUP;
  ((struct ofp_action_group *)&action->ofpat)->group_id = 1;
  TAILQ_INSERT_TAIL(&instruction->action_list, action, entry);
  TAILQ_INSERT_TAIL(&instruction_list, instruction, entry);
  ret = flowdb_flow_add(bridge, &flow_mod, &match_list,
                        &instruction_list, &error);
  printf("%d.%d\n", error.type, error.code);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "flowdb_flow_add: add to empty table error");

  request.group_id = 1;
  TAILQ_INIT(&group_stats_list);
  ret = group_stats(group_table, &request, &group_stats_list, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "get stats error");
  stats = TAILQ_FIRST(&group_stats_list);
  TEST_ASSERT_NOT_NULL_MESSAGE(stats, "group not found");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.group_id, 1,
                            "group id error");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.duration_sec, 0,
                            "duration sec error");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.ref_count, 1,
                            "ref_count error");
  stats = TAILQ_NEXT(stats, entry);
  TEST_ASSERT_NULL_MESSAGE(stats, "number of groups error");

  request.group_id = OFPG_ALL;
  TAILQ_INIT(&group_stats_list);
  ret = group_stats(group_table, &request, &group_stats_list, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "get stats error");
  stats = TAILQ_FIRST(&group_stats_list);
  TEST_ASSERT_NOT_NULL_MESSAGE(stats, "group not found");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.group_id, 1,
                            "group id error");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.duration_sec, 0,
                            "duration sec error");
  stats = TAILQ_NEXT(stats, entry);
  TEST_ASSERT_NOT_NULL_MESSAGE(stats, "group not found");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.group_id, 1000000,
                            "group id error");
  stats = TAILQ_NEXT(stats, entry);
  TEST_ASSERT_NULL_MESSAGE(stats, "number of groups error");

  sleep(1);
  TAILQ_INIT(&group_stats_list);
  ret = group_stats(group_table, &request, &group_stats_list, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "get stats error");
  stats = TAILQ_FIRST(&group_stats_list);
  TEST_ASSERT_NOT_NULL_MESSAGE(stats, "group not found");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.group_id, 1,
                            "group id error");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.duration_sec, 1,
                            "duration sec error");

  request.group_id = 20;
  TAILQ_INIT(&group_stats_list);
  ret = group_stats(group_table, &request, &group_stats_list, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "get stats error");
  stats = TAILQ_FIRST(&group_stats_list);
  TEST_ASSERT_NULL_MESSAGE(stats, "stats is not empry");
}
Ejemplo n.º 23
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);


  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_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(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.");
}