iPXE
lotest_cmd.c
Go to the documentation of this file.
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 */
44  /** MTU */
45  unsigned int mtu;
46  /** Broadcast */
47  int broadcast;
48 };
49 
50 /** "lotest" option list */
51 static struct option_descriptor lotest_opts[] = {
52  OPTION_DESC ( "mtu", 'm', required_argument,
53  struct lotest_options, mtu, parse_integer ),
54  OPTION_DESC ( "broadcast", 'b', no_argument,
55  struct lotest_options, broadcast, parse_flag ),
56 };
57 
58 /** "lotest" command descriptor */
60  COMMAND_DESC ( struct lotest_options, lotest_opts, 2, 2,
61  "<sending interface> <receiving interface>" );
62 
63 /**
64  * "lotest" command
65  *
66  * @v argc Argument count
67  * @v argv Argument list
68  * @ret rc Return status code
69  */
70 static int lotest_exec ( int argc, char **argv ) {
71  struct lotest_options opts;
72  struct net_device *sender;
73  struct net_device *receiver;
74  int rc;
75 
76  /* Parse options */
77  if ( ( rc = parse_options ( argc, argv, &lotest_cmd, &opts ) ) != 0 )
78  return rc;
79 
80  /* Parse sending interface name */
81  if ( ( rc = parse_netdev ( argv[optind], &sender ) ) != 0 )
82  return rc;
83 
84  /* Parse receiving interface name */
85  if ( ( rc = parse_netdev ( argv[ optind + 1 ], &receiver ) ) != 0 )
86  return rc;
87 
88  /* Use default MTU if none specified */
89  if ( ! opts.mtu )
90  opts.mtu = ETH_MAX_MTU;
91 
92  /* Perform loopback test */
93  if ( ( rc = loopback_test ( sender, receiver, opts.mtu,
94  opts.broadcast ) ) != 0 ) {
95  printf ( "Test failed: %s\n", strerror ( rc ) );
96  return rc;
97  }
98 
99  return 0;
100 }
101 
102 /** Loopback testing commands */
103 struct command lotest_command __command = {
104  .name = "lotest",
105  .exec = lotest_exec,
106 };
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:88
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int mtu
MTU.
Definition: lotest_cmd.c:45
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
static int lotest_exec(int argc, char **argv)
"lotest" command
Definition: lotest_cmd.c:70
int optind
Current option index.
Definition: getopt.c:51
A command-line command.
Definition: command.h:9
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:447
#define ETH_MAX_MTU
Definition: if_ether.h:14
A command descriptor.
Definition: parseopt.h:76
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int loopback_test(struct net_device *sender, struct net_device *receiver, size_t mtu, int broadcast)
Perform loopback test between two network devices.
Definition: lotest.c:194
struct command lotest_command __command
Loopback testing commands.
Definition: lotest_cmd.c:103
Parse command-line options.
"lotest" options
Definition: lotest_cmd.c:43
int broadcast
Broadcast.
Definition: lotest_cmd.c:47
static union @423 opts
"cert<xxx>" option list
int parse_flag(char *text __unused, int *flag)
Parse flag.
Definition: parseopt.c:200
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static struct option_descriptor lotest_opts[]
"lotest" option list
Definition: lotest_cmd.c:51
Command line option parsing.
A network device.
Definition: netdevice.h:348
Option does not take an argument.
Definition: getopt.h:16
struct stp_switch sender
Sender switch.
Definition: stp.h:30
const char * name
Name of the command.
Definition: command.h:11
Network device management.
uint32_t mtu
Maximum MTU.
Definition: ena.h:28
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:66
Option requires an argument.
Definition: getopt.h:18
A command-line option descriptor.
Definition: parseopt.h:22
Loopback testing.
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:107
static struct command_descriptor lotest_cmd
"lotest" command descriptor
Definition: lotest_cmd.c:59
String functions.
int parse_netdev(char *text, struct net_device **netdev)
Parse network device name.
Definition: parseopt.c:132