1/**
2 * \file
3 * \brief Echo server main
4 */
5
6/*
7 * Copyright (c) 2007, 2008, 2009, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
18#include <barrelfish/barrelfish.h>
19#include <lwip/init.h>
20#include "echoserver.h"
21
22static uint64_t minbase = -1, maxbase = -1;
23
24void network_polling_loop(void);
25
26static void connect_to_network(char *card_name, uint64_t queueid)
27{
28    if (lwip_init(card_name, queueid) == false) {
29        printf("Error in lwip_init: could not start networking!!!\n");
30        abort();
31    }
32
33    printf("ECHOSERVER: starting TCP server on port 7\n");
34    int r = tcp_echo_server_init();
35    assert(r == 0);
36
37    printf("ECHOSERVER: starting UDP server on port 7\n");
38    r = udp_echo_server_init();
39    assert(r == 0);
40}
41
42int main(int argc, char**argv)
43{
44
45    static uint64_t allocated_queueid = 0;
46    printf("%s running on core %u\n", argv[0], disp_get_core_id());
47
48    /* Read commandline args */
49    char *card_name = NULL;
50    for (int i = 0; i < argc; i++) {
51        if(strncmp(argv[i],"affinitymin=",strlen("affinitymin="))==0) {
52            minbase = atol(argv[i] + strlen("affinitymin="));
53            printf("minbase = %"PRIu64"\n", minbase);
54        }
55        if(strncmp(argv[i],"affinitymax=",strlen("affinitymax=")-1)==0) {
56            maxbase = atol(argv[i] + strlen("affinitymax="));
57            printf("maxbase = %"PRIu64"\n", maxbase);
58        }
59        if(strncmp(argv[i],"cardname=",strlen("cardname=")-1)==0) {
60            card_name = argv[i] + strlen("cardname=");
61            printf("card name = %s\n", card_name);
62        }
63        if(strncmp(argv[i],"queue=",strlen("queue=")-1)==0) {
64            allocated_queueid = atol(argv[i] + strlen("queue="));
65            printf("queue = %"PRIu64"\n", allocated_queueid);
66        }
67    }
68
69    /* Set memory affinity if requested */
70    if ((minbase != -1) && (maxbase != -1)) {
71        ram_set_affinity(minbase, maxbase);
72    }
73
74    /* Connect to e1000 driver */
75    printf("%s: trying to connect to the NIC driver...\n", argv[0]);
76    connect_to_network(card_name, allocated_queueid);
77
78    printf("echoserver: init finished.\n");
79
80    network_polling_loop();
81
82    return 0;
83}
84
85