Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / hci / commands / lotest_cmd.c
1 /*
2  * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19
20 FILE_LICENCE ( GPL2_OR_LATER );
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <getopt.h>
26 #include <ipxe/netdevice.h>
27 #include <ipxe/command.h>
28 #include <ipxe/parseopt.h>
29 #include <ipxe/if_ether.h>
30 #include <usr/lotest.h>
31
32 /** @file
33  *
34  * Loopback testing commands
35  *
36  */
37
38 /** "lotest" options */
39 struct lotest_options {
40         /** MTU */
41         unsigned int mtu;
42 };
43
44 /** "lotest" option list */
45 static struct option_descriptor lotest_opts[] = {
46         OPTION_DESC ( "mtu", 'm', required_argument,
47                       struct lotest_options, mtu, parse_integer ),
48 };
49
50 /** "lotest" command descriptor */
51 static struct command_descriptor lotest_cmd =
52         COMMAND_DESC ( struct lotest_options, lotest_opts, 2, 2,
53                        "<sending interface> <receiving interface>" );
54
55 /**
56  * "lotest" command
57  *
58  * @v argc              Argument count
59  * @v argv              Argument list
60  * @ret rc              Return status code
61  */
62 static int lotest_exec ( int argc, char **argv ) {
63         struct lotest_options opts;
64         struct net_device *sender;
65         struct net_device *receiver;
66         int rc;
67
68         /* Parse options */
69         if ( ( rc = parse_options ( argc, argv, &lotest_cmd, &opts ) ) != 0 )
70                 return rc;
71
72         /* Parse sending interface name */
73         if ( ( rc = parse_netdev ( argv[optind], &sender ) ) != 0 )
74                 return rc;
75
76         /* Parse receiving interface name */
77         if ( ( rc = parse_netdev ( argv[ optind + 1 ], &receiver ) ) != 0 )
78                 return rc;
79
80         /* Use default MTU if none specified */
81         if ( ! opts.mtu )
82                 opts.mtu = ETH_MAX_MTU;
83
84         /* Perform loopback test */
85         if ( ( rc = loopback_test ( sender, receiver, opts.mtu ) ) != 0 ) {
86                 printf ( "Test failed: %s\n", strerror ( rc ) );
87                 return rc;
88         }
89
90         return 0;
91 }
92
93 /** Loopback testing commands */
94 struct command lotest_command __command = {
95         .name = "lotest",
96         .exec = lotest_exec,
97 };