Browse Source

[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>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
c0d2aebdcf
1 changed files with 18 additions and 8 deletions
  1. 18
    8
      src/usr/lotest.c

+ 18
- 8
src/usr/lotest.c View File

175
  */
175
  */
176
 int loopback_test ( struct net_device *sender, struct net_device *receiver,
176
 int loopback_test ( struct net_device *sender, struct net_device *receiver,
177
 		    size_t mtu ) {
177
 		    size_t mtu ) {
178
-	uint8_t buf[mtu];
178
+	uint8_t *buf;
179
+	uint32_t *seq;
179
 	struct io_buffer *iobuf;
180
 	struct io_buffer *iobuf;
180
 	unsigned int i;
181
 	unsigned int i;
181
 	unsigned int successes;
182
 	unsigned int successes;
193
 	if ( ( rc = iflinkwait ( receiver, LINK_WAIT_MS ) ) != 0 )
194
 	if ( ( rc = iflinkwait ( receiver, LINK_WAIT_MS ) ) != 0 )
194
 		return rc;
195
 		return rc;
195
 
196
 
197
+	/* Allocate data buffer */
198
+	if ( mtu < sizeof ( *seq ) )
199
+		mtu = sizeof ( *seq );
200
+	buf = malloc ( mtu );
201
+	if ( ! buf )
202
+		return -ENOMEM;
203
+	seq = ( ( void * ) buf );
204
+
196
 	/* Print initial statistics */
205
 	/* Print initial statistics */
197
 	printf ( "Performing loopback test from %s to %s with %zd byte MTU\n",
206
 	printf ( "Performing loopback test from %s to %s with %zd byte MTU\n",
198
 		 sender->name, receiver->name, mtu );
207
 		 sender->name, receiver->name, mtu );
211
 		printf ( "\r%d", successes );
220
 		printf ( "\r%d", successes );
212
 
221
 
213
 		/* Generate random packet */
222
 		/* Generate random packet */
214
-		for ( i = 0 ; i < sizeof ( buf ) ; i++ )
223
+		*seq = htonl ( successes );
224
+		for ( i = sizeof ( *seq ) ; i < mtu ; i++ )
215
 			buf[i] = random();
225
 			buf[i] = random();
216
-		iobuf = alloc_iob ( MAX_LL_HEADER_LEN + sizeof ( buf ) );
226
+		iobuf = alloc_iob ( MAX_LL_HEADER_LEN + mtu );
217
 		if ( ! iobuf ) {
227
 		if ( ! iobuf ) {
218
 			printf ( "\nFailed to allocate I/O buffer" );
228
 			printf ( "\nFailed to allocate I/O buffer" );
219
 			rc = -ENOMEM;
229
 			rc = -ENOMEM;
220
 			break;
230
 			break;
221
 		}
231
 		}
222
 		iob_reserve ( iobuf, MAX_LL_HEADER_LEN );
232
 		iob_reserve ( iobuf, MAX_LL_HEADER_LEN );
223
-		memcpy ( iob_put ( iobuf, sizeof ( buf ) ),
224
-			 buf, sizeof ( buf ) );
233
+		memcpy ( iob_put ( iobuf, mtu ), buf, mtu );
225
 
234
 
226
 		/* Transmit packet */
235
 		/* Transmit packet */
227
 		if ( ( rc = net_tx ( iob_disown ( iobuf ), sender,
236
 		if ( ( rc = net_tx ( iob_disown ( iobuf ), sender,
233
 		}
242
 		}
234
 
243
 
235
 		/* Wait for received packet */
244
 		/* Wait for received packet */
236
-		if ( ( rc = loopback_wait ( receiver, buf,
237
-					    sizeof ( buf ) ) ) != 0 ) {
245
+		if ( ( rc = loopback_wait ( receiver, buf, mtu ) ) != 0 )
238
 			break;
246
 			break;
239
-		}
240
 	}
247
 	}
241
 
248
 
242
 	printf ( "\n");
249
 	printf ( "\n");
246
 	ifstat ( sender );
253
 	ifstat ( sender );
247
 	ifstat ( receiver );
254
 	ifstat ( receiver );
248
 
255
 
256
+	/* Free buffer */
257
+	free ( buf );
258
+
249
 	return 0;
259
 	return 0;
250
 }
260
 }

Loading…
Cancel
Save