예제 #1
0
void
test_set_field_PBB_ISID(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);

  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64;
  m->data[12] = 0x88;
  m->data[13] = 0xe7;

  lagopus_packet_init(&pkt, m, &port);
  set_match(action_set->field, 3, OFPXMT_OFB_PBB_ISID << 1,
            0xa5, 0x5a, 0xc3);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[15], 0xa5,
                            "SET_FIELD PBB_ISID[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x5a,
                            "SET_FIELD PBB_ISID[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0xc3,
                            "SET_FIELD PBB_ISID[2] error.");
}
예제 #2
0
void
test_set_field_METADATA(void) {
  struct port port;
  static const uint8_t metadata[] =
  { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);

  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  pkt.oob_data.metadata = 0;
  lagopus_set_in_port(&pkt, &port);
  lagopus_packet_init(&pkt, m);
  set_match(action_set->field, 8, OFPXMT_OFB_METADATA << 1,
            0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(&pkt.oob_data.metadata, metadata, 8,
                                        "SET_FIELD METADATA error.");
}
예제 #3
0
void
test_set_field_IPV6_IP_ECN(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet *pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = PKT2MBUF(pkt);

  OS_M_APPEND(m, 64);
  OS_MTOD(m, uint8_t *)[12] = 0x86;
  OS_MTOD(m, uint8_t *)[13] = 0xdd;
  lagopus_packet_init(pkt, m, &port);
  set_match(action_set->field, 1, OFPXMT_OFB_IP_ECN << 1,
            0x03);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[14], 0x00,
                            "SET_FIELD IPV6_IP_ECN[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[15], 0x30,
                            "SET_FIELD IPV6_IP_ECN[1] error.");
}
예제 #4
0
Active_window_condition::Active_window_condition( Windowdef_list* window_P,
    Condition_list_base* parent_P )
    : Condition( parent_P ), _window( window_P )
    {
    init();
    set_match();
    }
예제 #5
0
void
test_set_field_IPV6_IP_ECN(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64;
  m->data[12] = 0x86;
  m->data[13] = 0xdd;
  lagopus_packet_init(&pkt, m, &port);
  set_match(action_set->field, 1, OFPXMT_OFB_IP_ECN << 1,
            0x03);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[14], 0x00,
                            "SET_FIELD IPV6_IP_ECN[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[15], 0x30,
                            "SET_FIELD IPV6_IP_ECN[1] error.");
}
예제 #6
0
Active_window_condition::Active_window_condition( KConfigGroup& cfg_P, Condition_list_base* parent_P )
    : Condition( cfg_P, parent_P )
    {
    KConfigGroup windowConfig( cfg_P.config(), cfg_P.name() + "Window" );
    _window = new Windowdef_list( windowConfig );
    init();
    set_match();
    }
예제 #7
0
Existing_window_condition::Existing_window_condition( TDEConfig& cfg_P, Condition_list_base* parent_P )
    : Condition( cfg_P, parent_P )
    {
    TQString save_cfg_group = cfg_P.group();
    cfg_P.setGroup( save_cfg_group + "Window" );
    _window = new Windowdef_list( cfg_P );
    cfg_P.setGroup( save_cfg_group );
    init();
    set_match();
    }
예제 #8
0
void
test_set_field_IPV6_ND_TLL(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet pkt;
  OS_MBUF *m;
  int i;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);

  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 128;
  m->data[12] = 0x86;
  m->data[13] = 0xdd;
  m->data[19] = 0x80; /* PLEN */
  m->data[20] = IPPROTO_ICMPV6;
  m->data[54] = ND_NEIGHBOR_ADVERT;
  m->data[78] = ND_OPT_SOURCE_LINKADDR;
  m->data[79] = 1;
  m->data[86] = ND_OPT_TARGET_LINKADDR;
  m->data[87] = 1;
  lagopus_set_in_port(&pkt, &port);
  lagopus_packet_init(&pkt, m);
  set_match(action_set->field, ETH_ALEN, OFPXMT_OFB_IPV6_ND_TLL << 1,
            0xe0, 0x4d, 0x01, 0x34, 0x56, 0x78);
  execute_action(&pkt, &action_list);
  i = 88;
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xe0,
                            "SET_FIELD IPV6_ND_TLL[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x4d,
                            "SET_FIELD IPV6_ND_TLL[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x01,
                            "SET_FIELD IPV6_ND_TLL[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x34,
                            "SET_FIELD IPV6_ND_TLL[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x56,
                            "SET_FIELD IPV6_ND_TLL[4] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x78,
                            "SET_FIELD IPV6_ND_TLL[5] error.");
}
예제 #9
0
void
test_set_field_ARP_THA(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet *pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);

  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = pkt->mbuf;

  OS_M_APPEND(m, 64);
  OS_MTOD(m, uint8_t *)[12] = 0x08;
  OS_MTOD(m, uint8_t *)[13] = 0x06;
  OS_MTOD(m, uint8_t *)[20] = 0x00;
  OS_MTOD(m, uint8_t *)[21] = ARPOP_REQUEST;
  OS_MTOD(m, uint8_t *)[32] = 0xaa;
  OS_MTOD(m, uint8_t *)[33] = 0x55;
  OS_MTOD(m, uint8_t *)[34] = 0xaa;
  OS_MTOD(m, uint8_t *)[35] = 0x55;
  OS_MTOD(m, uint8_t *)[36] = 0xaa;
  OS_MTOD(m, uint8_t *)[37] = 0x55;

  lagopus_packet_init(pkt, m, &port);
  set_match(action_set->field, 6, OFPXMT_OFB_ARP_THA << 1,
            0xe0, 0x4d, 0x01, 0x34, 0x56, 0x78);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[32], 0xe0,
                            "SET_FIELD ARP_THA[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[33], 0x4d,
                            "SET_FIELD ARP_THA[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[34], 0x01,
                            "SET_FIELD ARP_THA[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[35], 0x34,
                            "SET_FIELD ARP_THA[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[36], 0x56,
                            "SET_FIELD ARP_THA[4] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[37], 0x78,
                            "SET_FIELD ARP_THA[5] error.");
}
예제 #10
0
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.");
}
예제 #11
0
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.");
}
예제 #12
0
void
test_set_field_IN_PORT(void) {
  datastore_bridge_info_t info;
  struct action_list action_list;
  struct bridge *bridge;
  struct port *port;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct port nport;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  /* setup bridge and port */
  memset(&info, 0, sizeof(info));
  info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE;
  TEST_ASSERT_EQUAL(dp_bridge_create("br0", &info), LAGOPUS_RESULT_OK);
  TEST_ASSERT_EQUAL(dp_port_create("port0"), LAGOPUS_RESULT_OK);
  TEST_ASSERT_EQUAL(dp_port_create("port1"), LAGOPUS_RESULT_OK);
  TEST_ASSERT_EQUAL(dp_bridge_port_set("br0", "port0", 1), LAGOPUS_RESULT_OK);
  TEST_ASSERT_EQUAL(dp_bridge_port_set("br0", "port1", 2), LAGOPUS_RESULT_OK);

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  bridge = dp_bridge_lookup("br0");
  TEST_ASSERT_NOT_NULL(bridge);
  pkt.in_port = port_lookup(bridge->ports, 1);
  TEST_ASSERT_NOT_NULL(pkt.in_port);
  lagopus_packet_init(&pkt, m);
  set_match(action_set->field, 4, OFPXMT_OFB_IN_PORT << 1,
            0x00, 0x00, 0x00, 0x02);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(pkt.in_port->ofp_port.port_no, 2,
                            "SET_FIELD IN_PORT error.");
}
예제 #13
0
void
test_set_field_ARP_SPA(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet *pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = pkt->mbuf;

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

  lagopus_packet_init(pkt, m, &port);
  set_match(action_set->field, 4, OFPXMT_OFB_ARP_SPA << 1,
            192, 168, 1, 2);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[28], 192,
                            "SET_FIELD ARP_SPA[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[29], 168,
                            "SET_FIELD ARP_SPA[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[30], 1,
                            "SET_FIELD ARP_SPA[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[31], 2,
                            "SET_FIELD ARP_SPA[3] error.");
}
예제 #14
0
void
test_set_field_ETH_TYPE(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);

  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64;
  m->data[12] = 0x08;
  m->data[13] = 0x00;

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

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

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

  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x20,
                            "SET_FIELD(vlan) ETH_TYPE[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0xf1,
                            "SET_FIELD(vlan) ETH_TYPE[1] error.");
}
예제 #15
0
void
test_set_field_ETH_TYPE(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet *pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);

  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = PKT2MBUF(pkt);

  OS_M_APPEND(m, 64);
  OS_MTOD(m, uint8_t *)[12] = 0x08;
  OS_MTOD(m, uint8_t *)[13] = 0x00;

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

  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[12], 0x20,
                            "SET_FIELD ETH_TYPE[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[13], 0xf1,
                            "SET_FIELD ETH_TYPE[1] error.");
  OS_MTOD(m, uint8_t *)[12] = 0x81;
  OS_MTOD(m, uint8_t *)[13] = 0x00;

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

  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[16], 0x20,
                            "SET_FIELD(vlan) ETH_TYPE[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[17], 0xf1,
                            "SET_FIELD(vlan) ETH_TYPE[1] error.");
}
예제 #16
0
void
test_set_field_ICMPV6_TYPE(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet *pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = PKT2MBUF(pkt);

  OS_M_APPEND(m, 64);
  OS_MTOD(m, uint8_t *)[12] = 0x86;
  OS_MTOD(m, uint8_t *)[13] = 0xdd;
  OS_MTOD(m, uint8_t *)[20] = IPPROTO_ICMPV6;

  lagopus_packet_init(pkt, m, &port);
  set_match(action_set->field, 2, OFPXMT_OFB_ICMPV6_TYPE << 1,
            ICMP6_ECHO_REQUEST);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[54], ICMP6_ECHO_REQUEST,
                            "SET_FIELD ICMPV6_TYPE error.");
  OS_MTOD(m, uint8_t *)[20] = IPPROTO_DSTOPTS;
  OS_MTOD(m, uint8_t *)[54] = IPPROTO_ICMPV6;
  OS_MTOD(m, uint8_t *)[55] = 0;
  lagopus_packet_init(pkt, m, &port);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[54], IPPROTO_ICMPV6,
                            "SET_FIELD ICMPV6_TYPE proto error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[62], ICMP6_ECHO_REQUEST,
                            "SET_FIELD ICMPV6_TYPE(next hdr) error.");
}
예제 #17
0
void
test_set_field_ETH_SRC(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet *pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = PKT2MBUF(pkt);

  OS_M_APPEND(m, 64);
  OS_MTOD(m, uint8_t *)[12] = 0x08;
  OS_MTOD(m, uint8_t *)[13] = 0x00;

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

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = PKT2MBUF(pkt);

  OS_M_APPEND(m, 64);
  OS_MTOD(m, uint8_t *)[12] = 0x08;
  OS_MTOD(m, uint8_t *)[13] = 0x00;

  lagopus_packet_init(pkt, m, &port);
  set_match(action_set->field, 6, OFPXMT_OFB_ETH_DST << 1,
            0x23, 0x45, 0x67, 0x89, 0xab, 0xcd);
  execute_action(pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[0], 0x23,
                            "SET_FIELD ETH_DST[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[1], 0x45,
                            "SET_FIELD ETH_DST[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[2], 0x67,
                            "SET_FIELD ETH_DST[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[3], 0x89,
                            "SET_FIELD ETH_DST[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[4], 0xab,
                            "SET_FIELD ETH_DST[4] error.");
  TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[5], 0xcd,
                            "SET_FIELD ETH_DST[5] error.");
}
예제 #19
0
void
test_set_field_ETH_SRC(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64;
  m->data[12] = 0x08;
  m->data[13] = 0x00;

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

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64;
  m->data[12] = 0x08;
  m->data[13] = 0x00;

  lagopus_packet_init(&pkt, m, &port);
  set_match(action_set->field, 6, OFPXMT_OFB_ETH_DST << 1,
            0x23, 0x45, 0x67, 0x89, 0xab, 0xcd);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[0], 0x23,
                            "SET_FIELD ETH_DST[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[1], 0x45,
                            "SET_FIELD ETH_DST[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[2], 0x67,
                            "SET_FIELD ETH_DST[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[3], 0x89,
                            "SET_FIELD ETH_DST[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[4], 0xab,
                            "SET_FIELD ETH_DST[4] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[5], 0xcd,
                            "SET_FIELD ETH_DST[5] error.");
}
예제 #21
0
void
test_set_field_ICMPV6_TYPE(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64;
  m->data[12] = 0x86;
  m->data[13] = 0xdd;
  m->data[20] = IPPROTO_ICMPV6;

  lagopus_packet_init(&pkt, m, &port);
  set_match(action_set->field, 2, OFPXMT_OFB_ICMPV6_TYPE << 1,
            ICMP6_ECHO_REQUEST);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[54], ICMP6_ECHO_REQUEST,
                            "SET_FIELD ICMPV6_TYPE error.");
  m->data[20] = IPPROTO_DSTOPTS;
  m->data[54] = IPPROTO_ICMPV6;
  m->data[55] = 0;
  lagopus_packet_init(&pkt, m, &port);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[54], IPPROTO_ICMPV6,
                            "SET_FIELD ICMPV6_TYPE proto error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[62], ICMP6_ECHO_REQUEST,
                            "SET_FIELD ICMPV6_TYPE(next hdr) error.");
}
예제 #22
0
파일: main.c 프로젝트: rpreen/xcsf
void trial(int cnt, _Bool train, double *err)
{
	// get problem function state and solution
	double *state = func_state(train);
	double answer = func_answer(train);
	// create match set
	NODE *mset = NULL, *kset = NULL;
	int msize = 0, mnum = 0;
	set_match(&mset, &msize, &mnum, state, cnt, &kset);
	// calculate system prediction and track performance
	double pre = set_pred(&mset, msize, state);
	err[cnt%PERF_AVG_TRIALS] = fabs(answer - pre);
	if(train) {
		// provide reinforcement to the set
		set_update(&mset, &msize, &mnum, answer, &kset, state);
		// run the genetic algorithm
		ga(&mset, msize, mnum, cnt, &kset);
	}
	// clean up
	set_kill(&kset); // kills deleted classifiers
	set_free(&mset); // frees the match set list
}
예제 #23
0
void
test_set_field_IPV6_DST(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64;
  m->data[12] = 0x86;
  m->data[13] = 0xdd;

  lagopus_packet_init(&pkt, m, &port);
  set_match(action_set->field, 16, OFPXMT_OFB_IPV6_DST << 1,
            0x20, 0x01, 0x00, 0x00, 0xe0, 0x45, 0x22, 0xeb,
            0x09, 0x00, 0x00, 0x08, 0xdc, 0x18, 0x94, 0xad);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[38], 0x20,
                            "SET_FIELD IPV6_DST[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[39], 0x01,
                            "SET_FIELD IPV6_DST[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[40], 0x00,
                            "SET_FIELD IPV6_DST[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[41], 0x00,
                            "SET_FIELD IPV6_DST[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[42], 0xe0,
                            "SET_FIELD IPV6_DST[4] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[43], 0x45,
                            "SET_FIELD IPV6_DST[5] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[44], 0x22,
                            "SET_FIELD IPV6_DST[6] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[45], 0xeb,
                            "SET_FIELD IPV6_DST[7] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[46], 0x09,
                            "SET_FIELD IPV6_DST[8] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[47], 0x00,
                            "SET_FIELD IPV6_DST[9] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[48], 0x00,
                            "SET_FIELD IPV6_DST[10] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[49], 0x08,
                            "SET_FIELD IPV6_DST[11] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[50], 0xdc,
                            "SET_FIELD IPV6_DST[12] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[51], 0x18,
                            "SET_FIELD IPV6_DST[13] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[52], 0x94,
                            "SET_FIELD IPV6_DST[14] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[53], 0xad,
                            "SET_FIELD IPV6_DST[15] error.");
}
예제 #24
0
void Existing_window_condition::window_removed( WId )
    {
    set_match();
    }
예제 #25
0
void Active_window_condition::active_window_changed( WId )
    {
    set_match();
    }
예제 #26
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.");
}
예제 #27
0
void
test_set_field_MPLS_LABEL(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet pkt;
  OS_MBUF *m;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64;
  m->data[12] = 0x88;
  m->data[13] = 0x47;
  m->data[14] = 0xff;
  m->data[15] = 0xff;
  m->data[16] = 0xff;
  m->data[17] = 0xff;

  lagopus_set_in_port(&pkt, &port);
  lagopus_packet_init(&pkt, m);
  set_match(action_set->field, 4, OFPXMT_OFB_MPLS_LABEL << 1,
            0x00, 0x00, 0x01, 0x00);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[14], 0x00,
                            "SET_FIELD MPLS_LABEL[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[15], 0x10,
                            "SET_FIELD MPLS_LABEL[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x0f,
                            "SET_FIELD MPLS_LABEL[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0xff,
                            "SET_FIELD MPLS_LABEL[3] error.");

  m->data[12] = 0x88;
  m->data[13] = 0x48;
  m->data[14] = 0x00;
  m->data[15] = 0x00;
  m->data[16] = 0x00;
  m->data[17] = 0x00;

  lagopus_packet_init(&pkt, m);
  set_match(action_set->field, 4, OFPXMT_OFB_MPLS_LABEL << 1,
            0x00, 0x0c, 0xa4, 0x21);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[14], 0xca,
                            "SET_FIELD MPLS_LABEL(2)[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[15], 0x42,
                            "SET_FIELD MPLS_LABEL(2)[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x10,
                            "SET_FIELD MPLS_LABEL(2)[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0x00,
                            "SET_FIELD MPLS_LABEL(2)[3] error.");
}
예제 #28
0
void Existing_window_condition::window_added( WId w_P )
    {
    set_match( w_P );
    }
예제 #29
0
int main(int argc, char* argv[]){

//variabili

fd_set read_temp_set;
fd_set write_temp_set;
int error;
int max_fd_set;
timeout.tv_sec=60;
timeout.tv_usec=0;
char port[6];
char command [30];
int right=0;
int max_try=3;


// fase iniziale : connessione al server

if(argc!=3){
  	printf("Errore nell'inserimento dei parametri, chiusura in corso...\n");
  	exit(1);
	}

printf("Connessione in corso al server (indirizzo di ascolto %s, porta di ascolto %s)\n",argv[1],argv[2]);
tcp_socket=socket(AF_INET,SOCK_STREAM,0);
if(tcp_socket==-1){
  	perror("Errore creazione socket tcp");
  	exit(1);
	}
udp_socket=socket(AF_INET,SOCK_DGRAM,0);
if(udp_socket==-1){
 	perror("Errore creazione socket udp");
 	close(tcp_socket);
 	exit(1);
	}
	
max_fd_set=(tcp_socket>udp_socket)?tcp_socket:udp_socket;
memset(&server,0, sizeof(server));
memset(&client,0, sizeof(client));
memset(&enemy, 0, sizeof(enemy));
memset(&work, 0, sizeof(work));
enemy.sin_family=AF_INET;
work.sin_family=AF_INET;
client.sin_family=AF_INET;
server.sin_family=AF_INET;
// per il server
server.sin_port=htons(atoi(argv[2]));
inet_pton(AF_INET, argv[1], &server.sin_addr.s_addr);

error=connect(tcp_socket,(struct sockaddr*)&server,addrlen);
if(error==-1){
 	perror("Impossibile connettersi al server");
 	close(tcp_socket);
 	close(udp_socket);
 	exit(1); 
	}

printf("Connessione con il server %s sulla porta %s avvenuta con successo.\n", argv[1], argv[2]);
// segue l'inserimento del nome e della porta di ascolto udp
error=record_name(client_name);
while(error==-1){
	if(max_try!=0){
		printf("Riproviamo...\n");
		error=record_name(client_name);
		max_try--;
		}
	else if(max_try==0){
		printf("Problemi nell'inserimento del nome.Disconnessione...\n");
		close(tcp_socket);
		close(udp_socket);
		exit(1);
	    	}
	}
do{
  	printf("Per favore inserisci il numero di porta udp per il gioco:\n");
	fgets(port,6,stdin);
	if(port[strlen(port)-1]!='\n')
	fflush(stdin);
    	udp_port=atoi(port);
	if(udp_port<1024 || udp_port>=65535)
	printf("Porta upd inserita non valida...\n");
	else right=1;		
	}while(right==0);
udp_port=htons(udp_port);
error=record_udp_port(udp_port);	
if(error==-1){
	printf("Problemi nell'inserimento della porta udp.Disconnessione...\n");
	close(tcp_socket);
	close(udp_socket);
	exit(1);   
	}
// bind() per socket udp
client.sin_port=udp_port;
client.sin_addr.s_addr = INADDR_ANY; // usa il mio indirizzo IP
error=bind(udp_socket, (struct sockaddr*)&client, addrlen);
if(error==-1){
	perror("Errore nella bind della socket udp in ricezione(porta occupata)");
        printf("Server in chiusura...\n");
	close(tcp_socket);
	close(udp_socket);
	exit(1); 
	}
else
printf("Porta udp registrata correttamente presso il server.\n");
// il client deve inserire le varie navi

set_match();
show_commands();
			 
// inizializzo i descrittori

FD_ZERO(&master_read_set);
FD_ZERO(&master_write_set);
FD_SET(0, &master_read_set);//stdin
FD_SET(tcp_socket, &master_read_set);
FD_SET(udp_socket, &master_read_set);
		  
// comincia il corpo del client

do{
	read_temp_set=master_read_set;
	write_temp_set=master_write_set;
	if(shell==0){
	   	if(started_match==0)
		printf(">");
	   	else
		printf("#");
	  	shell=1;
	 	}
	fflush(stdout);
	error=select(max_fd_set+1, &read_temp_set, &write_temp_set, NULL, &timeout);
	if(error==-1){
	   	perror("Errore nella select");
	   	close(tcp_socket);
	   	close(udp_socket);
	   	exit(1);
		}
	else if((error==0) && (started_match!=0)){ // non e' successo niente per 60s durante una partita
	   	printf("Inattivita' durante una partita.\n");
	   	printf("Chiudo la partita con %s. \n",enemy_name);
	   	busy=0;
	   	started_match=0;
	   	tcp_senddim=4;
	   	tcp_message=malloc(4);
	  	*(int*)tcp_message=4;
	   	udp_message[0]=7;//TIPO messaggio
	   	FD_SET(tcp_socket, &master_write_set);
	   	FD_SET(udp_socket, &master_write_set);
	   	FD_CLR(tcp_socket, &master_read_set);
		}
  	// altrimenti controlliamo i socket in lettura
    	if(FD_ISSET(0, &read_temp_set)){
  		// leggo un comando da tastiera
	   	shell = 0;
	   	fgets(command,30, stdin);
	   	if(command[strlen(command)-1]!='\n') fflush(stdin);
	   	else command[strlen(command)-1]='\0';
	   	manage_stdin_command(command);
    		}
    
	if(FD_ISSET(tcp_socket, &read_temp_set)){
		if(tcp_recv1==1){
	   		msg_buffer=malloc(INTEGER);
	   		error=recv(tcp_socket,msg_buffer,INTEGER,0);
	   		if(error==0){
		  		printf("Il server ha chiuso la connessione");
		  		close_conn=1;
		  		break;
        			}
	   		if(error==-1 || error<INTEGER){
		  		perror("Errore nella recive");
		  		close_conn=1;
		  		break;
				}
			tcp_recvdim=*(int*)msg_buffer;
			free(msg_buffer);
			tcp_recv1=0;
			}
		else{
	   		msg_buffer=malloc(tcp_recvdim);
	   		error=recv(tcp_socket,msg_buffer,tcp_recvdim,0);
	   		if(error==0){
		  		printf("Il server ha chiuso la connessione");
		  		close_conn=1;
		  		break;
				}
	   		if(error==-1 || error<tcp_recvdim){
		  		perror("Errore nella recive");
		  		close_conn=1;
		  		break;
				}
			error=manage_tcp_command(msg_buffer);
			free(msg_buffer);
	   		if(error==-1){
		  		printf("Errore nella recive");
		  		close_conn=1;
		  		break;
				}
			tcp_recv1=1;
			shell=0;
			}
  		}
  	if(FD_ISSET(udp_socket, &read_temp_set)){
	 	msg_buffer=malloc(12);
	 	error=recvfrom(udp_socket,msg_buffer,12,0,(struct sockaddr*)&work,&addrlen);
		if(error==-1){
			perror("Errore nella recvfrom");
			close_conn=1;
			break;
			}
	 
    		if((busy==1) && work.sin_addr.s_addr==enemy.sin_addr.s_addr){
			shell=0;
			error=manage_udp_command((int*)msg_buffer);
			if(error==-1){
				printf("Errore nella gestione del comando ricevuto dall'altro giocatore.\n");
				close_conn=1;
				break;
				}
			free(msg_buffer); /***************************************************************/
			}
		// altrimenti ho ricevuto un pacchetto da qualcun'altro
		}
  
  	// controlliamo i socket in scrittura
  
  	if(FD_ISSET(tcp_socket,&write_temp_set)){
	 	if(tcp_send1==1){
			msg_buffer=malloc(INTEGER);
			*(int*)msg_buffer=tcp_senddim;
			error=send(tcp_socket,msg_buffer,INTEGER,0);
			if(error==-1){
		  		perror("Errore nella send");
		  		close_conn=1;
		  		break;
	    			}
			free(msg_buffer);
			tcp_send1=0;			
	  		}
	 	else{
			error=send(tcp_socket,tcp_message,tcp_senddim,0);
			if(error==-1){
		  		perror("Errore nella send");
		  		close_conn=1;
		  		break;
				}
			if(*(int*)tcp_message==5)
			close_conn=1;
			free(tcp_message);
			tcp_send1=1;
			FD_CLR(tcp_socket, &master_write_set);
			FD_SET(tcp_socket, &master_read_set);
			}
		}
  	if(FD_ISSET(udp_socket,&write_temp_set)){
	 	error=sendto(udp_socket,(void*)&udp_message,12,0,(struct sockaddr*)&enemy,addrlen);
	 	if(error==-1){
		 	perror("Errore nella sendto");
		 	close_conn=1;
		 	break;
	  		}
		FD_CLR(udp_socket, &master_write_set);
		}
	}while(close_conn==0);
close(tcp_socket);
close(udp_socket);
printf("\nBye bye!\n");
return 0;	  
}
예제 #30
0
void
test_set_field_IPV6_ND_TARGET(void) {
  struct port port;
  struct action_list action_list;
  struct action *action;
  struct ofp_action_set_field *action_set;
  struct lagopus_packet pkt;
  OS_MBUF *m;
  int i;

  TAILQ_INIT(&action_list);
  action = calloc(1, sizeof(*action) + 64);
  action_set = (struct ofp_action_set_field *)&action->ofpat;
  action_set->type = OFPAT_SET_FIELD;
  lagopus_set_action_function(action);
  TAILQ_INSERT_TAIL(&action_list, action, entry);


  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];

  OS_M_PKTLEN(m) = 64;
  m->data[12] = 0x86;
  m->data[13] = 0xdd;
  m->data[20] = IPPROTO_ICMPV6;

  lagopus_set_in_port(&pkt, &port);
  lagopus_packet_init(&pkt, m);
  set_match(action_set->field, 16, OFPXMT_OFB_IPV6_ND_TARGET << 1,
            0x20, 0x01, 0x00, 0x00, 0xe0, 0x45, 0x22, 0xeb,
            0x09, 0x00, 0x00, 0x08, 0xdc, 0x18, 0x94, 0xad);
  execute_action(&pkt, &action_list);
  i = 62;
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x20,
                            "SET_FIELD IPV6_ND_TARGET[0] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x01,
                            "SET_FIELD IPV6_ND_TARGET[1] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[2] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[3] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xe0,
                            "SET_FIELD IPV6_ND_TARGET[4] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x45,
                            "SET_FIELD IPV6_ND_TARGET[5] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x22,
                            "SET_FIELD IPV6_ND_TARGET[6] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xeb,
                            "SET_FIELD IPV6_ND_TARGET[7] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x09,
                            "SET_FIELD IPV6_ND_TARGET[8] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[9] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[10] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x08,
                            "SET_FIELD IPV6_ND_TARGET[11] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xdc,
                            "SET_FIELD IPV6_ND_TARGET[12] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x18,
                            "SET_FIELD IPV6_ND_TARGET[13] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x94,
                            "SET_FIELD IPV6_ND_TARGET[14] error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xad,
                            "SET_FIELD IPV6_ND_TARGET[15] error.");
  m->data[20] = IPPROTO_DSTOPTS;
  m->data[54] = IPPROTO_ICMPV6;
  m->data[55] = 0;
  lagopus_packet_init(&pkt, m);
  execute_action(&pkt, &action_list);
  TEST_ASSERT_EQUAL_MESSAGE(m->data[54], IPPROTO_ICMPV6,
                            "SET_FIELD IPV6_ND_TARGET proto error.");
  i = 70;
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x20,
                            "SET_FIELD IPV6_ND_TARGET[0](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x01,
                            "SET_FIELD IPV6_ND_TARGET[1](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[2](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[3](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xe0,
                            "SET_FIELD IPV6_ND_TARGET[4](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x45,
                            "SET_FIELD IPV6_ND_TARGET[5](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x22,
                            "SET_FIELD IPV6_ND_TARGET[6](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xeb,
                            "SET_FIELD IPV6_ND_TARGET[7](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x09,
                            "SET_FIELD IPV6_ND_TARGET[8](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[9](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x00,
                            "SET_FIELD IPV6_ND_TARGET[10](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x08,
                            "SET_FIELD IPV6_ND_TARGET[11](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xdc,
                            "SET_FIELD IPV6_ND_TARGET[12](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x18,
                            "SET_FIELD IPV6_ND_TARGET[13](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x94,
                            "SET_FIELD IPV6_ND_TARGET[14](next hdr) error.");
  TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xad,
                            "SET_FIELD IPV6_ND_TARGET[15](next hdr) error.");
}