Skip to content

Commit

Permalink
[lotest] Include sequence number within loopback test packets
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mcb30 committed Jul 14, 2013
1 parent 7016164 commit c0d2aeb
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/usr/lotest.c
Expand Up @@ -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;
Expand All @@ -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 );
Expand All @@ -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,
Expand All @@ -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");
Expand All @@ -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;
}

0 comments on commit c0d2aeb

Please sign in to comment.