1/*
2 * Copyright (c) 2007-12 ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
8 */
9#include <barrelfish/barrelfish.h>
10#include <barrelfish/dispatch.h>
11#include <barrelfish/waitset.h>
12#include <net_device_manager/net_device_manager.h>
13#include <barrelfish/nameservice_client.h>
14#include "NGD_mng_debug.h"
15#include <trace/trace.h>
16
17#include <stdio.h>
18#include <string.h>
19#include <stdlib.h>
20/*
21#include <barrelfish/net_constants.h>
22*/
23
24
25#if CONFIG_TRACE && NETWORK_STACK_TRACE
26#define TRACE_ETHERSRV_MODE 1
27#endif // CONFIG_TRACE && NETWORK_STACK_TRACE
28
29
30// handle events in infinite loop
31static void event_loop(void)
32{
33
34    errval_t err;
35    struct waitset *ws = get_default_waitset();
36    while (1) {
37        err = event_dispatch(ws);
38        if (err_is_fail(err)) {
39            DEBUG_ERR(err, "in event_dispatch");
40            break;
41        }
42    } // end while: infinite
43} // end function: event_loop
44
45
46int main(int argc, char **argv)
47{
48    char *card_name = NULL;
49    uint64_t minbase = -1, maxbase = -1;
50    uint64_t total_queues = 1;
51    uint8_t filter_type = 0; // 0 = software filtering
52
53//    char *device = "loopback";
54    // Read commandline args
55    for (int i = 0; i < argc; i++) {
56        if (strncmp(argv[i], "affinitymin=", strlen("affinitymin=")) == 0) {
57            minbase = atol(argv[i] + strlen("affinitymin="));
58            NGKDM_DEBUG("minbase = %" PRIu64 "\n", minbase);
59        }
60        if (strncmp(argv[i], "affinitymax=", strlen("affinitymax=") - 1) == 0) {
61            maxbase = atol(argv[i] + strlen("affinitymax="));
62            NGKDM_DEBUG("maxbase = %" PRIu64 "\n", maxbase);
63        }
64        if (strncmp(argv[i], "cardname=", strlen("cardname=") - 1) == 0) {
65            card_name = argv[i] + strlen("cardname=");
66            NGKDM_DEBUG("card name = %s\n", card_name);
67        }
68        if (strncmp(argv[i], "totalqueues=", strlen("totalqueues=") - 1) == 0) {
69            total_queues = atol(argv[i] + strlen("totalqueues="));
70            NGKDM_DEBUG("total queues= %"PRIu64"\n", total_queues);
71        }
72        if (strncmp(argv[i], "filtertype=", strlen("filtertype=") - 1) == 0) {
73            filter_type = (uint8_t) atoi(argv[i] + strlen("filtertype="));
74            NGKDM_DEBUG("filter type= %"PRIu8"\n", filter_type);
75        }
76    }
77
78    if (card_name == NULL) {
79        fprintf(stderr,
80                "Error: net_dev_mng: card name not specified, but it is required\n");
81        fprintf(stderr, "Hint: try \"%s cardname=e1000\"\n", argv[0]);
82        return 1;
83    }
84
85    assert(total_queues > 0);
86
87//    NGKDM_DEBUG
88    printf("Started net_dev_manager for [%s] Q[%"PRIu64"] QT[%"PRIu8"]\n",
89            card_name, total_queues, filter_type);
90
91    errval_t err = init_device_manager(card_name, total_queues, filter_type);
92    if (err_is_fail(err)) {
93        DEBUG_ERR(err, "in init_device_manager");
94        return 1;
95    }
96
97    NGKDM_DEBUG("done with most of things for device[%s]\n", card_name);
98
99#if TRACE_ETHERSRV_MODE
100    set_cond_termination(trace_conditional_termination);
101#endif
102
103    event_loop();
104} // end function: main
105
106
107