These changes are the raw update to qemu-2.6.
[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  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <getopt.h>
30 #include <ipxe/netdevice.h>
31 #include <ipxe/command.h>
32 #include <ipxe/parseopt.h>
33 #include <ipxe/if_ether.h>
34 #include <usr/lotest.h>
35
36 /** @file
37  *
38  * Loopback testing commands
39  *
40  */
41
42 /** "lotest" options */
43 struct lotest_options {
44         /** MTU */
45         unsigned int mtu;
46 };
47
48 /** "lotest" option list */
49 static struct option_descriptor lotest_opts[] = {
50         OPTION_DESC ( "mtu", 'm', required_argument,
51                       struct lotest_options, mtu, parse_integer ),
52 };
53
54 /** "lotest" command descriptor */
55 static struct command_descriptor lotest_cmd =
56         COMMAND_DESC ( struct lotest_options, lotest_opts, 2, 2,
57                        "<sending interface> <receiving interface>" );
58
59 /**
60  * "lotest" command
61  *
62  * @v argc              Argument count
63  * @v argv              Argument list
64  * @ret rc              Return status code
65  */
66 static int lotest_exec ( int argc, char **argv ) {
67         struct lotest_options opts;
68         struct net_device *sender;
69         struct net_device *receiver;
70         int rc;
71
72         /* Parse options */
73         if ( ( rc = parse_options ( argc, argv, &lotest_cmd, &opts ) ) != 0 )
74                 return rc;
75
76         /* Parse sending interface name */
77         if ( ( rc = parse_netdev ( argv[optind], &sender ) ) != 0 )
78                 return rc;
79
80         /* Parse receiving interface name */
81         if ( ( rc = parse_netdev ( argv[ optind + 1 ], &receiver ) ) != 0 )
82                 return rc;
83
84         /* Use default MTU if none specified */
85         if ( ! opts.mtu )
86                 opts.mtu = ETH_MAX_MTU;
87
88         /* Perform loopback test */
89         if ( ( rc = loopback_test ( sender, receiver, opts.mtu ) ) != 0 ) {
90                 printf ( "Test failed: %s\n", strerror ( rc ) );
91                 return rc;
92         }
93
94         return 0;
95 }
96
97 /** Loopback testing commands */
98 struct command lotest_command __command = {
99         .name = "lotest",
100         .exec = lotest_exec,
101 };