/* Generated from of10/packet_in.data */ static int test_of10_packet_in(void) { uint8_t binary[] = { 0x01, 0x0a, 0x00, 0x15, 0x12, 0x34, 0x56, 0x78, 0xab, 0xcd, 0xef, 0x01, 0x00, 0x09, 0xff, 0xfe, 0x01, 0x00, 0x61, 0x62, 0x63, }; of_object_t *obj; obj = of_packet_in_new(OF_VERSION_1_0); of_packet_in_buffer_id_set(obj, 2882400001); { of_octets_t data = { .bytes=3, .data=(uint8_t *)"\x61\x62\x63" }; of_packet_in_data_set(obj, &data); } of_packet_in_in_port_set(obj, 65534); of_packet_in_reason_set(obj, 1); of_packet_in_total_len_set(obj, 9); of_packet_in_xid_set(obj, 305419896); if (sizeof(binary) != WBUF_CURRENT_BYTES(OF_OBJECT_TO_WBUF(obj)) || memcmp(binary, WBUF_BUF(OF_OBJECT_TO_WBUF(obj)), sizeof(binary))) { show_failure(binary, sizeof(binary), WBUF_BUF(OF_OBJECT_TO_WBUF(obj)), WBUF_CURRENT_BYTES(OF_OBJECT_TO_WBUF(obj))); of_object_delete(obj); return TEST_FAIL; } of_object_delete(obj); return TEST_PASS; } /* Generated from of10/packet_out.data */ static int test_of10_packet_out(void) { uint8_t binary[] = { 0x01, 0x0d, 0x00, 0x23, 0x12, 0x34, 0x56, 0x78, 0xab, 0xcd, 0xef, 0x01, 0xff, 0xfe, 0x00, 0x10, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x02, 0x00, 0x00, 0x61, 0x62, 0x63, }; of_object_t *obj; obj = of_packet_out_new(OF_VERSION_1_0); of_packet_out_buffer_id_set(obj, 2882400001); of_packet_out_in_port_set(obj, 65534); of_packet_out_xid_set(obj, 305419896); { of_object_t *list = of_list_action_new(OF_VERSION_1_0); { of_object_t *obj = of_action_output_new(OF_VERSION_1_0); of_action_output_max_len_set(obj, 0); of_action_output_port_set(obj, 1); of_list_append(list, obj); of_object_delete(obj); } { of_object_t *obj = of_action_output_new(OF_VERSION_1_0); of_action_output_max_len_set(obj, 0); of_action_output_port_set(obj, 2); of_list_append(list, obj); of_object_delete(obj); } of_packet_out_actions_set(obj, list); of_object_delete(list); } { of_octets_t data = { .bytes=3, .data=(uint8_t *)"\x61\x62\x63" }; of_packet_out_data_set(obj, &data); } if (sizeof(binary) != WBUF_CURRENT_BYTES(OF_OBJECT_TO_WBUF(obj)) || memcmp(binary, WBUF_BUF(OF_OBJECT_TO_WBUF(obj)), sizeof(binary))) { show_failure(binary, sizeof(binary), WBUF_BUF(OF_OBJECT_TO_WBUF(obj)), WBUF_CURRENT_BYTES(OF_OBJECT_TO_WBUF(obj))); of_object_delete(obj); return TEST_FAIL; } of_object_delete(obj); return TEST_PASS; } /* Generated from of10/port_desc.data */ static int test_of10_port_desc(void) { uint8_t binary[] = { 0xff, 0xfd, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x66, 0x6f, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, }; of_object_t *obj; obj = of_port_desc_new(OF_VERSION_1_0); of_port_desc_advertised_set(obj, 32); of_port_desc_config_set(obj, 16); of_port_desc_curr_set(obj, 1); { of_mac_addr_t hw_addr = { { 1, 2, 3, 4, 5, 6 } }; of_port_desc_hw_addr_set(obj, hw_addr); } { of_port_name_t name = "foo"; of_port_desc_name_set(obj, name); } of_port_desc_peer_set(obj, 2048); of_port_desc_port_no_set(obj, 65533); of_port_desc_state_set(obj, 512); of_port_desc_supported_set(obj, 512); if (sizeof(binary) != WBUF_CURRENT_BYTES(OF_OBJECT_TO_WBUF(obj)) || memcmp(binary, WBUF_BUF(OF_OBJECT_TO_WBUF(obj)), sizeof(binary))) { show_failure(binary, sizeof(binary), WBUF_BUF(OF_OBJECT_TO_WBUF(obj)), WBUF_CURRENT_BYTES(OF_OBJECT_TO_WBUF(obj))); of_object_delete(obj); return TEST_FAIL; } of_object_delete(obj); return TEST_PASS; }
int test_discovery_pkt_in(int port_no, int indigo_ret_expected) { #define OUT_PKT_BUF_SIZE 1500 uint8_t buf[OUT_PKT_BUF_SIZE]; int rv = 0; of_packet_in_t *obj = 0; ppe_packet_t ppep; of_octets_t data = { .bytes = sizeof(Dhcp_discovery) //346 bytes (342 + 4byteVLAN }; /* Timeout due to re-register the timer */ printf("\n\n*******************************\n"); printf("TEST 1 DHCP Discovery: PKT_IN on port:%d\nExpect Option Added\n", port_no); printf("pkt_in bytes = %d\n", data.bytes); printf("*******************************\n"); /* Set up GOLDEN Expected pkt*/ AIM_TRUE_OR_DIE(sizeof(Dhcp_discovery_expected) <= OUT_PKT_BUF_SIZE); convert_chars_to_bytes(Dhcp_discovery_expected, Dhcp_discovery_expected_hex_stream, sizeof(Dhcp_discovery_expected)); /* Setup discovery pkt */ AIM_TRUE_OR_DIE(sizeof(Dhcp_discovery) <= OUT_PKT_BUF_SIZE); convert_chars_to_bytes(Dhcp_discovery, Dhcp_discovery_hex_stream, sizeof(Dhcp_discovery)); memcpy(buf, Dhcp_discovery, sizeof(Dhcp_discovery)); data.data = buf; obj = of_packet_in_new(OF_VERSION_1_0); AIM_TRUE_OR_DIE(obj); of_packet_in_reason_set(obj, OF_PACKET_IN_REASON_BSN_DHCP); of_packet_in_in_port_set(obj,port_no); if(of_packet_in_data_set(obj, &data) < 0) { AIM_TRUE_OR_DIE(obj); } /* Dump pkt in obj */ // of_object_dump((loci_writer_f)aim_printf, &aim_pvs_stdout, obj); ppe_packet_init(&ppep, data.data, data.bytes); if (ppe_parse(&ppep) < 0) { printf("\nERROR: Packet parsing failed. packet=%p, len=%u", data.data, data.bytes); } /* Dump up to DHCP hdr */ // ppe_packet_dump(&ppep,&aim_pvs_stdout); // parse_dhcp_options(&ppep, data.bytes, 0, 0); /* Handle packet */ rv = dhcpra_handle_pkt (obj); AIM_TRUE_OR_DIE(rv == indigo_ret_expected); of_packet_in_delete(obj); return rv; } int test_offer_pkt_in(int port_no) { #define OUT_PKT_BUF_SIZE 1500 uint8_t buf[OUT_PKT_BUF_SIZE]; int rv = 0; of_packet_in_t *obj; ppe_packet_t ppep; of_octets_t data = { .bytes = sizeof(Dhcp_offer) //354 (342 + 4byte VLAN + 8bytes CirID) }; printf("\n\n*******************************\n" "TEST 2 DHCP OFFER: PKT_IN on port:%d\nExpect Option Removed\n", port_no); printf("pkt_in bytes = %d\n", data.bytes); printf("*******************************\n\n"); /* Set up GOLDEN Expected pkt*/ //printf("Expected Offer pkt:\n"); AIM_TRUE_OR_DIE(sizeof(Dhcp_offer_expected) <= OUT_PKT_BUF_SIZE); convert_chars_to_bytes(Dhcp_offer_expected, Dhcp_offer_expected_hex_stream, sizeof(Dhcp_offer_expected)); /* Setup offer pkt */ //printf("Offer pkt:\n"); AIM_TRUE_OR_DIE(sizeof(Dhcp_offer) <= OUT_PKT_BUF_SIZE); convert_chars_to_bytes(Dhcp_offer, Dhcp_offer_hex_stream, sizeof(Dhcp_offer)); memcpy(buf, Dhcp_offer, sizeof(Dhcp_offer)); data.data = buf; obj = of_packet_in_new(OF_VERSION_1_0); AIM_TRUE_OR_DIE(obj); of_packet_in_in_port_set(obj,port_no); of_packet_in_reason_set(obj, OF_PACKET_IN_REASON_BSN_DHCP); if(of_packet_in_data_set(obj, &data) < 0) { AIM_TRUE_OR_DIE(obj); } /* Dump pkt in obj */ //of_object_dump((loci_writer_f)aim_printf, &aim_pvs_stdout, obj); ppe_packet_init(&ppep, data.data, data.bytes); if (ppe_parse(&ppep) < 0) { printf("\nERROR: Packet parsing failed. packet=%p, len=%u", data.data, data.bytes); } /* Dump up to DHCP hdr */ //ppe_packet_dump(&ppep,&aim_pvs_stdout); //parse_dhcp_options(&ppep, data.bytes, 0, 0); /* Handle packet */ rv = dhcpra_handle_pkt (obj); if (rv == INDIGO_CORE_LISTENER_RESULT_PASS) { printf("\nError: NOT DHCP packet-in\n"); } else if (rv == INDIGO_CORE_LISTENER_RESULT_DROP) printf("\nIS DHCP packet-in\n"); else printf("\nError: Unsupport packet-in\n"); of_packet_in_delete(obj); return rv; } int aim_main(int argc, char* argv[]) { printf("dhcpra Utest Is Empty\n"); dhcpra_config_show(&aim_pvs_stdout); dhcpra_system_init(); printf("\n*********\n0. PRE-TEST TABLE\n********\n"); test_pass[0] = fill_all_vlan_dhcpr_table_test(); printf("\n*********\nI. TEST PASS AFTER ADD and MOD\n********\n"); add_entry_to_dhcpr_table(); mod_entry_to_dhcpr_table(); //Port 1: Correct setup, packet process //Driver will take care of sending L2_SRC_MISSED to controller test_discovery_pkt_in(1, INDIGO_CORE_LISTENER_RESULT_DROP); test_offer_pkt_in(1); printf("\n\nSUMMARY:\nDISCOV:\t%s\n", dhcp_pkt_matched[0] ? "PASSED" : "FAILED"); printf("OFFER:\t%s\n", dhcp_pkt_matched[1] ? "PASSED" : "FAILED"); test_pass[1] = dhcp_pkt_matched[0]; test_pass[2] = dhcp_pkt_matched[1]; printf("\n*********\nII. TEST FAILED AFTER DELETE\n********\n"); dhcp_pkt_matched[0] = 0; dhcp_pkt_matched[1] = 0; del_entry_to_dhcpr_table(); //Incorrect VLAN pass packet test_discovery_pkt_in(1, INDIGO_CORE_LISTENER_RESULT_PASS); test_offer_pkt_in(1); printf("\n\nSUMMARY:\nDISCOV:\t%s\n", dhcp_pkt_matched[0] ? "PASSED" : "FAILED"); printf("OFFER:\t%s\n", dhcp_pkt_matched[1] ? "PASSED" : "FAILED"); test_pass[3] = !dhcp_pkt_matched[0]; test_pass[4] = !dhcp_pkt_matched[1]; printf("\n\n*****SUMMARY ALL 3 TESTS*****\n"); printf("TEST DHCP TABLE: %s\n", test_pass[0] ? "PASSED" : "FAILED"); printf("TEST DISCOVER with valid table: %s\n", test_pass[1] ? "PASSED" : "FAILED"); printf("TEST OFFER with valid table: %s\n", test_pass[2] ? "PASSED" : "FAILED"); printf("TEST DISCOVER with in valid table: %s\n", test_pass[3] ? "PASSED" : "FAILED"); printf("TEST OFFER with in valid table: %s\n", test_pass[4] ? "PASSED" : "FAILED"); return 0; }