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
24FILE_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 */
48};
49
50/** "lotest" option list */
51static struct option_descriptor lotest_opts[] = {
52 OPTION_DESC ( "mtu", 'm', required_argument,
54 OPTION_DESC ( "broadcast", 'b', no_argument,
55 struct lotest_options, broadcast, parse_flag ),
56};
57
58/** "lotest" command descriptor */
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 */
70static 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 */
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
#define COMMAND(name, exec)
Definition command.h:27
uint32_t mtu
Maximum MTU.
Definition ena.h:17
int optind
Current option index.
Definition getopt.c:52
Parse command-line options.
@ required_argument
Option requires an argument.
Definition getopt.h:19
@ no_argument
Option does not take an argument.
Definition getopt.h:17
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define ETH_MAX_MTU
Definition if_ether.h:15
String functions.
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
Loopback testing.
static struct option_descriptor lotest_opts[]
"lotest" option list
Definition lotest_cmd.c:51
static struct command_descriptor lotest_cmd
"lotest" command descriptor
Definition lotest_cmd.c:59
static int lotest_exec(int argc, char **argv)
"lotest" command
Definition lotest_cmd.c:70
Network device management.
int parse_netdev(char *text, struct net_device **netdev)
Parse network device name.
Definition parseopt.c:159
int parse_flag(char *text __unused, int *flag)
Parse flag.
Definition parseopt.c:227
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition parseopt.c:92
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition parseopt.c:485
Command line option parsing.
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition parseopt.h:68
struct stp_switch sender
Sender switch.
Definition stp.h:19
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
A command descriptor.
Definition parseopt.h:78
"lotest" options
Definition lotest_cmd.c:43
int broadcast
Broadcast.
Definition lotest_cmd.c:47
unsigned int mtu
MTU.
Definition lotest_cmd.c:45
A network device.
Definition netdevice.h:353
A command-line option descriptor.
Definition parseopt.h:24
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465