2
0
mirror of https://github.com/xcat2/xNBA.git synced 2024-11-22 17:41:55 +00:00

[lotest] Include sequence number within loopback test packets

Include a sequence number as the first four bytes of the loopback test
packet payload.  When a content mismatch occurs, this gives some
information about the source of the mismatched packet.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2013-07-14 11:37:17 +02:00
parent 7016164056
commit c0d2aebdcf

View File

@ -175,7 +175,8 @@ static int loopback_wait ( struct net_device *receiver, void *data,
*/
int loopback_test ( struct net_device *sender, struct net_device *receiver,
size_t mtu ) {
uint8_t buf[mtu];
uint8_t *buf;
uint32_t *seq;
struct io_buffer *iobuf;
unsigned int i;
unsigned int successes;
@ -193,6 +194,14 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
if ( ( rc = iflinkwait ( receiver, LINK_WAIT_MS ) ) != 0 )
return rc;
/* Allocate data buffer */
if ( mtu < sizeof ( *seq ) )
mtu = sizeof ( *seq );
buf = malloc ( mtu );
if ( ! buf )
return -ENOMEM;
seq = ( ( void * ) buf );
/* Print initial statistics */
printf ( "Performing loopback test from %s to %s with %zd byte MTU\n",
sender->name, receiver->name, mtu );
@ -211,17 +220,17 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
printf ( "\r%d", successes );
/* Generate random packet */
for ( i = 0 ; i < sizeof ( buf ) ; i++ )
*seq = htonl ( successes );
for ( i = sizeof ( *seq ) ; i < mtu ; i++ )
buf[i] = random();
iobuf = alloc_iob ( MAX_LL_HEADER_LEN + sizeof ( buf ) );
iobuf = alloc_iob ( MAX_LL_HEADER_LEN + mtu );
if ( ! iobuf ) {
printf ( "\nFailed to allocate I/O buffer" );
rc = -ENOMEM;
break;
}
iob_reserve ( iobuf, MAX_LL_HEADER_LEN );
memcpy ( iob_put ( iobuf, sizeof ( buf ) ),
buf, sizeof ( buf ) );
memcpy ( iob_put ( iobuf, mtu ), buf, mtu );
/* Transmit packet */
if ( ( rc = net_tx ( iob_disown ( iobuf ), sender,
@ -233,10 +242,8 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
}
/* Wait for received packet */
if ( ( rc = loopback_wait ( receiver, buf,
sizeof ( buf ) ) ) != 0 ) {
if ( ( rc = loopback_wait ( receiver, buf, mtu ) ) != 0 )
break;
}
}
printf ( "\n");
@ -246,5 +253,8 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
ifstat ( sender );
ifstat ( receiver );
/* Free buffer */
free ( buf );
return 0;
}