Exemple #1
0
int
aim_main(int argc, char* argv[])
{
    AIM_LOG_STRUCT_REGISTER();

    /*
     * We queue many (up to 20) 64KB messages before sending them on the socket
     * with a single writev(). After we free all the messages the malloc
     * implementation would see we have more than 128KB (the default trim value)
     * free and return it to the OS with a call to brk(). Every time we
     * allocate a new message we have to get the memory with brk() all over
     * again.
     *
     * Increasing the trim threshold above the size of our working set
     * eliminates this churn.
     */
    mallopt(M_TRIM_THRESHOLD, 2*1024*1024);

    loci_logger = ivs_loci_logger;

    core_cfg.expire_flows = 1;
    core_cfg.stats_check_ms = 900;
    core_cfg.disconnected_mode = INDIGO_CORE_DISCONNECTED_MODE_STICKY;

    parse_options(argc, argv);

    /* Setup logging from command line options */

    if (loglevel >= LOGLEVEL_DEFAULT) {
        aim_log_fid_set_all(AIM_LOG_FLAG_FATAL, 1);
        aim_log_fid_set_all(AIM_LOG_FLAG_ERROR, 1);
        aim_log_fid_set_all(AIM_LOG_FLAG_WARN, 1);
    }

    if (loglevel >= LOGLEVEL_VERBOSE) {
        aim_log_fid_set_all(AIM_LOG_FLAG_VERBOSE, 1);
    }

    if (loglevel >= LOGLEVEL_TRACE) {
        aim_log_fid_set_all(AIM_LOG_FLAG_TRACE, 1);
    }

    if (use_syslog) {
        aim_log_pvs_set_all(aim_pvs_syslog_open("ivs", LOG_NDELAY, LOG_DAEMON));
    }

    AIM_LOG_MSG("Starting %s (%s) pid %d", program_version, AIM_STRINGIFY(BUILD_ID), getpid());

    /* Initialize all modules */

    if (ind_soc_init(&soc_cfg) < 0) {
        AIM_LOG_FATAL("Failed to initialize Indigo socket manager");
        return 1;
    }

    if (ind_cxn_init(&cxn_cfg) < 0) {
        AIM_LOG_FATAL("Failed to initialize Indigo connection manager");
        return 1;
    }

    if (ind_core_init(&core_cfg) < 0) {
        AIM_LOG_FATAL("Failed to initialize Indigo core module");
        return 1;
    }

    if (ind_ovs_init(datapath_name, max_flows) < 0) {
        AIM_LOG_FATAL("Failed to initialize OVSDriver module");
        return 1;
    }

    if (lacpa_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize LACP Agent module");
        return 1;
    }

    if (lldpa_system_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize LLDP Agent module");
        return 1;
    }

    if (arpa_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize ARP Agent module");
        return 1;
    }

    if (router_ip_table_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize Router IP table module");
        return 1;
    }

    if (icmpa_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize ICMP Agent module");
        return 1;
    }

    if (dhcpra_system_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize DHCP relay table and agent module");
        return 1;
    }

    if (enable_tunnel) {
        if (ind_ovs_tunnel_init() < 0) {
            AIM_LOG_FATAL("Failed to initialize tunneling");
            return 1;
        }
    }

    if (pipeline == NULL) {
        if (openflow_version == NULL || !strcmp(openflow_version, "1.0")) {
            pipeline = "standard-1.0";
        } else if (!strcmp(openflow_version, "1.3")) {
            pipeline = "standard-1.3";
        } else {
            AIM_DIE("unexpected OpenFlow version");
        }
    }

    AIM_LOG_INFO("Initializing forwarding pipeline '%s'", pipeline);
    indigo_error_t rv = pipeline_set(pipeline);
    if (rv < 0) {
        AIM_LOG_FATAL("Failed to set pipeline: %s", indigo_strerror(rv));
        return 1;
    }

#if 0
    /* TODO Configuration module installs its own SIGHUP handler. */
    if (ind_cfg_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize Indigo configuration module");
        return 1;
    }
#endif

    if (config_filename) {
        ind_cfg_filename_set(config_filename);
        if (ind_cfg_load() < 0) {
            AIM_LOG_FATAL("Failed to load configuration file");
            return 1;
        }
    }

    if (dpid) {
        indigo_core_dpid_set(dpid);
    }

    /* Enable all modules */

    if (ind_soc_enable_set(1) < 0) {
        AIM_LOG_FATAL("Failed to enable Indigo socket manager");
        return 1;
    }

    if (ind_cxn_enable_set(1) < 0) {
        AIM_LOG_FATAL("Failed to enable Indigo connection manager");
        return 1;
    }

    if (ind_core_enable_set(1) < 0) {
        AIM_LOG_FATAL("Failed to enable Indigo core module");
        return 1;
    }

    /* Add interfaces from command line */
    {
        biglist_t *element;
        char *str;
        int index = 1;
        BIGLIST_FOREACH_DATA(element, interfaces, char *, str) {
            AIM_LOG_MSG("Adding interface %s (port %d)", str, index);
            if (indigo_port_interface_add(str, index, NULL)) {
                AIM_LOG_FATAL("Failed to add interface %s", str);
                return 1;
            }
            index++;
        }
    }
Exemple #2
0
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;
}