예제 #1
0
파일: lookup.c 프로젝트: drurowin/netmap
void LookUp::init_cache() 
{
    //init cache

    cout << indent(1) << "Reading lookup cache" << endl;
    
    // TODO: iter over a list that the user can add to with a command line
    // switch
    read_hostfile(hostcache_file);

    for(list<string>::iterator e_iter = extra_hostcaches.begin();
	e_iter != extra_hostcaches.end(); e_iter++)
	read_hostfile(*e_iter);

    read_failedip(failedip_file);
}
예제 #2
0
int main(){
	printf("Teste persist.c\n");
	host_network_param_t		host_param = { "192.168.100.79","255.255.255.0","192.168.100.1"};
	
	rx_param_t			rx_param = { "1","224.0.1.1","5004","1"};
	inetd_t				inetd_param = {"TSxpress","00:00:00:00:00:00:00"};
	
	printf("***** Host network parameters *****\n");		
	write_hostfile("host_param.txt",&host_param);
	read_hostfile("host_param.txt",&host_param);
	print_host_param(&host_param);
	printf("***** TX parameters *****\n");	
	write_txfile("tx_param.txt",&tx_param);
	read_txfile("tx_param.txt",&tx_param);
	print_tx_param(&tx_param);	
	printf("***** RX parameters *****\n");	
	write_rxfile("rx_param.txt",&rx_param);
	read_rxfile("rx_param.txt",&rx_param);
	print_rx_param(&rx_param);
	//if(setIPAddress("eth0")<0){
	//	printf("Failed\n");
	//}
	

}
예제 #3
0
/**
 * Command line analysis function.
 *
 * mpirun [-debug] [-xterm] -np N [-hostfile hfile | h1 h2 h3 ... hN] a.out [args]
 */
void commandLine(int argc, char *argv[], char *totalview_cmd, char **env)
{
    int i;
    int c, option_index;

    size_t hostname_len = 0;

    do {
        c = getopt_long_only(argc, argv, "+", option_table, &option_index);
        switch (c) {
        case '?':
        case ':':
            usage();
            exit(EXIT_FAILURE);
            break;
        case EOF:
            break;
        case 0:
            switch (option_index) {
            case 0:            /* -np */
                nprocs = atoi(optarg);
                if (nprocs < 1) {
                    usage();
                    exit(EXIT_FAILURE);
                }
                break;
            case 1:            /* -debug */
                debug_on = 1;
                xterm_on = 1;
                break;
            case 2:            /* -xterm */
                xterm_on = 1;
                break;
            case 3:            /* -hostfile */
                hostfile_on = 1;
                strncpy(hostfile, optarg, HOSTFILE_LEN);
                if (strlen(optarg) >= HOSTFILE_LEN - 1)
                    hostfile[HOSTFILE_LEN] = '\0';
                break;
            case 4:
                show_on = 1;
                break;
            case 5:
                use_rsh = 1;
                break;
            case 6:
                use_rsh = 0;
                break;
            case 7:
                usage();
                exit(EXIT_SUCCESS);
                break;
            case 8:
                PRINT_MVAPICH2_VERSION();
                exit(EXIT_SUCCESS);
                break;
            case 9:
                {
                    /* -tv */
                    char *tv_env;
                    int count, idx;
                    char **new_argv;
                    tv_env = getenv("TOTALVIEW");
                    if (tv_env != NULL) {
                        strncpy(totalview_cmd, tv_env, TOTALVIEW_CMD_LEN);
                    } else {
                        fprintf(stderr, "TOTALVIEW env is NULL, use default: %s\n", TOTALVIEW_CMD);
                        sprintf(totalview_cmd, "%s", TOTALVIEW_CMD);
                    }
                    new_argv = (char **) malloc(sizeof(char **) * argc + 3);
                    new_argv[0] = totalview_cmd;
                    new_argv[1] = argv[0];
                    new_argv[2] = "-a";
                    new_argv[3] = "-startedByTv";
                    idx = 4;
                    for (count = 1; count < argc; count++) {
                        if (strcmp(argv[count], "-tv"))
                            new_argv[idx++] = argv[count];
                    }
                    new_argv[idx] = NULL;
                    if (execv(new_argv[0], new_argv)) {
                        perror("execv");
                        exit(EXIT_FAILURE);
                    }

                }
                break;
            case 10:
                legacy_startup = 1;
                break;
            case 11:
                /* -startedByTv */
                use_totalview = 1;
                debug_on = 1;
                break;
            case 12:           /* spawnspec given */
                spawnfile = strdup(optarg);
                DBG(fprintf(stderr, "spawn spec file = %s\n", spawnfile));
                break;
            case 13:
                dpm = 1;
                break;
            case 14:           /* -fastssh */
#ifndef CKPT
                USE_LINEAR_SSH = 0;
#endif                          /* CKPT */
                break;
                //With this option the user want to activate the mpmd
            case 15:
                configfile_on = 1;
                strncpy(configfile, optarg, CONFILE_LEN);
                if (strlen(optarg) >= CONFILE_LEN - 1)
                    configfile[CONFILE_LEN] = '\0';
                break;
            case 16:
                spinf.totspawns = atoi(optarg);
                break;
            case 17:
                /* sg: change the active group */
                change_group = optarg;
                DBG(printf("Group change requested: '%s'\n", change_group));
                break;
            case 18:
#if defined(CKPT) && defined(CR_FTB)
                sparehosts_on = 1;
                strncpy(sparehostfile, optarg, HOSTFILE_LEN);
                if (strlen(optarg) >= HOSTFILE_LEN - 1)
                    sparehostfile[HOSTFILE_LEN] = 0;
#else
                usage();
                exit(EXIT_SUCCESS);
#endif
                break;
            default:
                fprintf(stderr, "Unknown option\n");
                usage();
                exit(EXIT_FAILURE);
                break;
            }
            break;
        default:
            fprintf(stderr, "Unreachable statement!\n");
            usage();
            exit(EXIT_FAILURE);
            break;
        }
    }
    while (c != EOF);

    if (!nprocs && !configfile_on) {
        usage();
        exit(EXIT_FAILURE);
    }

    binary_dirname = dirname(strdup(argv[0]));
    if (strlen(binary_dirname) == 1 && argv[0][0] != '.') {
        use_dirname = 0;
    }
    //If the mpmd is active we need to parse the configuration file
    if (configfile_on) {
        /*TODO In the future the user can add the nprocs on the command line. Now the
         * number of processes is defined in the configfile */
        nprocs = 0;
        plist = parse_config(configfile, &nprocs);
        DBG(fprintf(stderr, "PARSED CONFIG FILE\n"));

    }

    if (!hostfile_on) {
        /* get hostnames from argument list */
        if (strchr(argv[optind], '=') || argc - optind < nprocs + 1) {
            sprintf(hostfile, "%s/.mpirun_hosts", env2str("HOME"));
            if (file_exists(hostfile)) {
                hostfile_on = 1;
                aout_index = optind;
                goto cont;
            } else {
                fprintf(stderr, "Without hostfile option, hostnames must be " "specified on command line.\n");
                usage();
                exit(EXIT_FAILURE);
            }
        }
        aout_index = nprocs + optind;
    } else {                    /* if (!hostfile_on) */

        aout_index = optind;
    }

  cont:
    if (!configfile_on) {
        plist = malloc(nprocs * sizeof(process));
        if (plist == NULL) {
            perror("malloc");
            exit(EXIT_FAILURE);
        }

        for (i = 0; i < nprocs; i++) {
            plist[i].state = P_NOTSTARTED;
            plist[i].device = NULL;
            plist[i].port = -1;
            plist[i].remote_pid = 0;
            //TODO ADD EXECNAME AND ARGS

        }
    }

    /* grab hosts from command line or file */
    /* TODO: remove  hostname_len variable */
    hostname_len = 0;
    if (hostfile_on) {
        hostname_len = read_hostfile(hostfile);
    } else {
        for (i = 0; i < nprocs; i++) {
            plist[i].hostname = (char *) strndup(argv[optind + i], 100);
            if (hostname_len < strlen(plist[i].hostname)) {
                hostname_len = strlen(plist[i].hostname);
            }
        }
    }

}