mirror of https://github.com/ARMmbed/mbed-os.git
Added new test NET_14 - datagram PHY/data layer benchmark
parent
23b696133a
commit
c62f8cd1d1
|
@ -0,0 +1,147 @@
|
|||
#include "mbed.h"
|
||||
#include "rtos.h"
|
||||
#include "EthernetInterface.h"
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* How to use:
|
||||
* make.py -m LPC1768 -t ARM -d E:\ -n NET_14
|
||||
* udp_link_layer_auto.py -p COM20 -d E:\ -t 10
|
||||
*/
|
||||
|
||||
// Evil globals
|
||||
namespace {
|
||||
Mutex cli_serv_mutex;
|
||||
// cli_serv_mutex.lock(); // LOCK
|
||||
// cli_serv_mutex.unlock(); // LOCK
|
||||
|
||||
const int ECHO_SERVER_PORT = 7;
|
||||
const int BUFFER_SIZE = 256;
|
||||
|
||||
// Forwarding packet queue
|
||||
std::list<std::string> datagram_queue;
|
||||
|
||||
// IP and port used to store HOST address info
|
||||
char host_address[32] = { 0 };
|
||||
volatile int host_port = 0;
|
||||
|
||||
// Statistics (mbed)
|
||||
volatile int received_packets = 0;
|
||||
volatile int forwarded_packets = 0;
|
||||
volatile int max_queue_len = 0;
|
||||
}
|
||||
|
||||
void udp_server_task(void const *argument)
|
||||
{
|
||||
UDPSocket server;
|
||||
|
||||
server.bind(ECHO_SERVER_PORT);
|
||||
// printf("[udp_server_task] Start\r\n");
|
||||
|
||||
Endpoint client;
|
||||
char buffer[BUFFER_SIZE] = { 0 };
|
||||
while (true) {
|
||||
//printf("[udp_server_task] Wait for packet...\r\n");
|
||||
int n = server.receiveFrom(client, buffer, sizeof(buffer));
|
||||
if (n > 0) {
|
||||
//printf("[udp_server_task] Received packet from: %s\r\n", client.get_address());
|
||||
const int buffer_string_end_index = n >= BUFFER_SIZE ? BUFFER_SIZE - 1 : n;
|
||||
buffer[buffer_string_end_index] = '\0';
|
||||
//printf("[udp_server_task] Server received: %s\r\n", buffer);
|
||||
if (host_port == 0) {
|
||||
strcpy(host_address, client.get_address());
|
||||
host_port = ECHO_SERVER_PORT + 1;
|
||||
//printf("[udp_server_task] Set host address and port: %s:%d\r\n", host_address, host_port);
|
||||
}
|
||||
// Dispatch data to client for sending to test HOST
|
||||
cli_serv_mutex.lock(); // LOCK
|
||||
// Push to datagram queue
|
||||
datagram_queue.push_front(std::string(buffer));
|
||||
max_queue_len = datagram_queue.size() > max_queue_len ? datagram_queue.size() : max_queue_len;
|
||||
received_packets++;
|
||||
cli_serv_mutex.unlock(); // LOCK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void udp_client_task(void const *argument)
|
||||
{
|
||||
while (host_port == 0) {
|
||||
// Waiting for HOST port notification
|
||||
}
|
||||
|
||||
UDPSocket socket;
|
||||
socket.init();
|
||||
|
||||
Endpoint echo_server;
|
||||
echo_server.set_address(host_address, host_port);
|
||||
//printf("[udp_client_task] Start: %s:%d\r\n", host_address, host_port);
|
||||
|
||||
while (1) {
|
||||
std::string datagram;
|
||||
bool sent_datagram = false;
|
||||
cli_serv_mutex.lock(); // LOCK
|
||||
if (datagram_queue.size() > 0) {
|
||||
// POP from datagram queue
|
||||
datagram = datagram_queue.back();
|
||||
datagram_queue.pop_back();
|
||||
sent_datagram = true;
|
||||
}
|
||||
cli_serv_mutex.unlock(); // LOCK
|
||||
if (sent_datagram) {
|
||||
//printf("[udp_client_task] Forwarded datagram: %s\r\n", datagram.c_str());
|
||||
socket.sendTo(echo_server, (char *)datagram.c_str(), datagram.length());
|
||||
forwarded_packets++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
EthernetInterface eth;
|
||||
|
||||
eth.init(); //Use DHCP
|
||||
eth.connect();
|
||||
printf("Server IP Address is %s:%d\n", eth.getIPAddress(), ECHO_SERVER_PORT);
|
||||
|
||||
Thread UdpServerTask(udp_server_task, NULL, osPriorityNormal, DEFAULT_STACK_SIZE * 2.25);
|
||||
Thread UdpClientTask(udp_client_task, NULL, osPriorityNormal, DEFAULT_STACK_SIZE * 2.25);
|
||||
|
||||
// Control TCP server to get mbed statistics
|
||||
{
|
||||
const int TELNET_SERVER_PORT = 23;
|
||||
const int BUFFER_SIZE = 256;
|
||||
TCPSocketServer server;
|
||||
server.bind(TELNET_SERVER_PORT);
|
||||
server.listen();
|
||||
|
||||
while (true) {
|
||||
printf("Wait for new connection...\n");
|
||||
TCPSocketConnection client;
|
||||
server.accept(client);
|
||||
client.set_blocking(false, 1500); // Timeout after (1.5)s
|
||||
printf("Connection from: %s\n", client.get_address());
|
||||
|
||||
char buffer[BUFFER_SIZE] = { 0 };
|
||||
while (true) {
|
||||
int n = client.receive(buffer, sizeof(buffer));
|
||||
//if (n <= 0) break;
|
||||
if (n > 0) {
|
||||
printf("Recv %d chars\r\n", n);
|
||||
const int buffer_string_end_index = n >= BUFFER_SIZE ? BUFFER_SIZE - 1 : n;
|
||||
buffer[buffer_string_end_index] = '\0';
|
||||
// client.send_all(buffer, strlen(buffer));
|
||||
if (strncmp(buffer, "stat", 4) == 0) {
|
||||
sprintf(buffer, "received_packets %d\nforwarded_packets %d\nmax_queue_len %d",
|
||||
received_packets, forwarded_packets, max_queue_len);
|
||||
client.send_all(buffer, strlen(buffer));
|
||||
// printf("%s", buffer);
|
||||
}
|
||||
}
|
||||
//if (n <= 0) break;
|
||||
}
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,158 @@
|
|||
"""
|
||||
mbed SDK
|
||||
Copyright (c) 2011-2013 ARM Limited
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
"""
|
||||
How to use:
|
||||
make.py -m LPC1768 -t ARM -d E:\ -n NET_14
|
||||
udp_link_layer_auto.py -p COM20 -d E:\ -t 10
|
||||
"""
|
||||
|
||||
import thread
|
||||
from SocketServer import BaseRequestHandler, UDPServer
|
||||
# from socket import socket, AF_INET, SOCK_DGRAM
|
||||
import socket
|
||||
import re
|
||||
from host_test import Test, DefaultTest
|
||||
from time import time, sleep
|
||||
from sys import stdout
|
||||
|
||||
|
||||
# Received datagrams (with time)
|
||||
dict_udp_recv_datagrams = dict()
|
||||
|
||||
# Sent datagrams (with time)
|
||||
dict_udp_sent_datagrams = dict()
|
||||
|
||||
|
||||
class UDPEchoClient_Handler(BaseRequestHandler):
|
||||
def handle(self):
|
||||
""" One handle per connection """
|
||||
data, socket = self.request
|
||||
# Process received datagram
|
||||
data_str = repr(data)[1:-1]
|
||||
dict_udp_recv_datagrams[data_str] = time()
|
||||
# print "[UDP_COUNTER] [" + data_str + "]"
|
||||
# print ".",
|
||||
|
||||
|
||||
|
||||
def udp_packet_recv(threadName, server_ip, server_port):
|
||||
""" This function will receive packet stream from mbed device """
|
||||
server = UDPServer((server_ip, server_port), UDPEchoClient_Handler)
|
||||
print "[UDP_COUNTER] Listening for connections... %s:%d"%(server_ip, server_port)
|
||||
server.serve_forever()
|
||||
|
||||
|
||||
class UDPEchoServerTest(DefaultTest):
|
||||
ECHO_SERVER_ADDRESS = "" # UDP IP of datagram bursts
|
||||
ECHO_PORT = 0 # UDP port for datagram bursts
|
||||
CONTROL_PORT = 23 # TCP port used to get stats from mbed device, e.g. counters
|
||||
s = None # Socket
|
||||
|
||||
TEST_PACKET_COUNT = 1000 # how many packets should be send
|
||||
TEST_STRESS_FACTOR = 0.001 # )in seconds) 10 ms
|
||||
|
||||
pattern_server_ip = "^Server IP Address is (\d+).(\d+).(\d+).(\d+):(\d+)"
|
||||
re_detect_server_ip = re.compile(pattern_server_ip)
|
||||
|
||||
def print_result(self, result):
|
||||
print "\n{%s}\n{end}" % result
|
||||
|
||||
def get_control_data(self, command="stat\n"):
|
||||
BUFFER_SIZE = 256
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((self.ECHO_SERVER_ADDRESS, self.CONTROL_PORT))
|
||||
s.send(command)
|
||||
data = s.recv(BUFFER_SIZE)
|
||||
s.close()
|
||||
return data
|
||||
|
||||
def run(self):
|
||||
ip_msg_timeout = self.mbed.options.timeout
|
||||
serial_ip_msg = ""
|
||||
start_serial_pool = time();
|
||||
while (time() - start_serial_pool) < ip_msg_timeout:
|
||||
c = self.mbed.serial.read(512)
|
||||
stdout.write(c)
|
||||
stdout.flush()
|
||||
serial_ip_msg += c
|
||||
# Searching for IP address and port prompted by server
|
||||
m = self.re_detect_server_ip.search(serial_ip_msg)
|
||||
if m and len(m.groups()):
|
||||
self.ECHO_SERVER_ADDRESS = ".".join(m.groups()[:4])
|
||||
self.ECHO_PORT = int(m.groups()[4]) # must be integer for socket.connect method
|
||||
duration = time() - start_serial_pool
|
||||
print "UDP Server found at: " + self.ECHO_SERVER_ADDRESS + ":" + str(self.ECHO_PORT) + " after " + "%.2f" % duration + " sec"
|
||||
stdout.flush()
|
||||
break
|
||||
else:
|
||||
print "Error: No IP and port information sent from server"
|
||||
self.print_result('error')
|
||||
exit(-2)
|
||||
|
||||
# Open client socket to burst datagrams to UDP server in mbed
|
||||
try:
|
||||
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
except Exception, e:
|
||||
print "Error: %s" % e
|
||||
self.print_result('error')
|
||||
exit(-1)
|
||||
|
||||
# UDP replied receiver works in background to get echoed datagrams
|
||||
SERVER_IP = str(socket.gethostbyname(socket.getfqdn()))
|
||||
SERVER_PORT = self.ECHO_PORT + 1
|
||||
thread.start_new_thread( udp_packet_recv, ("Thread-udp-recv", SERVER_IP, SERVER_PORT) )
|
||||
sleep(0.5)
|
||||
|
||||
# Burst part
|
||||
TEST_STRING = 'Hello, world !!!'
|
||||
for no in range(self.TEST_PACKET_COUNT):
|
||||
payload = str(no) + "__" + TEST_STRING
|
||||
self.s.sendto(payload, (self.ECHO_SERVER_ADDRESS, self.ECHO_PORT))
|
||||
dict_udp_sent_datagrams[payload] = time()
|
||||
sleep(self.TEST_STRESS_FACTOR)
|
||||
self.s.close()
|
||||
|
||||
# Wait 5 seconds for packets to come
|
||||
print
|
||||
print "Test Summary:"
|
||||
for d in range(5):
|
||||
sleep(1)
|
||||
summary_datagram_success = (float(len(dict_udp_recv_datagrams)) / float(self.TEST_PACKET_COUNT)) * 100.0
|
||||
# print dict_udp_recv_datagrams
|
||||
print "Datagrams recved after +%d sec: %.3f%% (%d / %d), stress=%.3f ms" % (d, summary_datagram_success, len(dict_udp_recv_datagrams), self.TEST_PACKET_COUNT, self.TEST_STRESS_FACTOR)
|
||||
|
||||
# Getting control data from test
|
||||
print
|
||||
print "Mbed Summary:"
|
||||
mbed_stats = self.get_control_data()
|
||||
print mbed_stats
|
||||
print
|
||||
|
||||
# Receiving serial data from mbed
|
||||
print
|
||||
print "Remaining mbed serial port data:"
|
||||
try:
|
||||
while True:
|
||||
c = self.mbed.serial.read(512)
|
||||
stdout.write(c)
|
||||
stdout.flush()
|
||||
except KeyboardInterrupt, _:
|
||||
print "\n[CTRL+c] exit"
|
||||
|
||||
if __name__ == '__main__':
|
||||
UDPEchoServerTest().run()
|
|
@ -82,7 +82,7 @@ TESTS = [
|
|||
"automated": True,
|
||||
},
|
||||
{
|
||||
"id": "MBED_A2", "description": "semihost file system",
|
||||
"id": "MBED_A2", "description": "Semihost file system",
|
||||
"source_dir": join(TEST_DIR, "mbed", "file"),
|
||||
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
|
||||
"automated": True,
|
||||
|
@ -212,7 +212,7 @@ TESTS = [
|
|||
"id": "MBED_A21", "description": "Call function before main (mbed_main)",
|
||||
"source_dir": join(TEST_DIR, "mbed", "call_before_main"),
|
||||
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
|
||||
"automated": True,
|
||||
"automated": False,
|
||||
},
|
||||
{
|
||||
"id": "MBED_A22", "description": "SPIFI for LPC4088 (test 1)",
|
||||
|
@ -403,6 +403,7 @@ TESTS = [
|
|||
"source_dir": join(TEST_DIR, "mbed", "semihost"),
|
||||
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
|
||||
"automated": True,
|
||||
"mcu": ["LPC1768", "LPC2368", "LPC11U24", "KL05Z", "KL25Z", "KL46Z"]
|
||||
},
|
||||
{
|
||||
"id": "MBED_23", "description": "Ticker Int us",
|
||||
|
@ -521,7 +522,8 @@ TESTS = [
|
|||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES],
|
||||
"duration": 15,
|
||||
"automated": True,
|
||||
"host_test": "wait_us_auto"
|
||||
"host_test": "wait_us_auto",
|
||||
"mcu": ["LPC1768", "LPC11U24", "LPC812", "KL25Z", "K64F", "KL46Z"],
|
||||
},
|
||||
{
|
||||
"id": "RTOS_2", "description": "Mutex resource lock",
|
||||
|
@ -529,6 +531,7 @@ TESTS = [
|
|||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, TEST_MBED_LIB],
|
||||
"duration": 20,
|
||||
"automated": True,
|
||||
"mcu": ["LPC1768", "LPC11U24", "LPC812", "KL25Z", "K64F", "KL46Z"],
|
||||
},
|
||||
{
|
||||
"id": "RTOS_3", "description": "Semaphore resource lock",
|
||||
|
@ -536,24 +539,28 @@ TESTS = [
|
|||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, TEST_MBED_LIB],
|
||||
"duration": 20,
|
||||
"automated": True,
|
||||
"mcu": ["LPC1768", "LPC11U24", "LPC812", "KL25Z", "K64F", "KL46Z"],
|
||||
},
|
||||
{
|
||||
"id": "RTOS_4", "description": "Signals messaging",
|
||||
"source_dir": join(TEST_DIR, "rtos", "mbed", "signals"),
|
||||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, TEST_MBED_LIB],
|
||||
"automated": True,
|
||||
"mcu": ["LPC1768", "LPC11U24", "LPC812", "KL25Z", "K64F", "KL46Z"],
|
||||
},
|
||||
{
|
||||
"id": "RTOS_5", "description": "Queue messaging",
|
||||
"source_dir": join(TEST_DIR, "rtos", "mbed", "queue"),
|
||||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, TEST_MBED_LIB],
|
||||
"automated": True,
|
||||
"mcu": ["LPC1768", "LPC11U24", "LPC812", "KL25Z", "K64F", "KL46Z"],
|
||||
},
|
||||
{
|
||||
"id": "RTOS_6", "description": "Mail messaging",
|
||||
"source_dir": join(TEST_DIR, "rtos", "mbed", "mail"),
|
||||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, TEST_MBED_LIB],
|
||||
"automated": True,
|
||||
"mcu": ["LPC1768", "LPC11U24", "LPC812", "KL25Z", "K64F", "KL46Z"],
|
||||
},
|
||||
{
|
||||
"id": "RTOS_7", "description": "Timer",
|
||||
|
@ -561,20 +568,23 @@ TESTS = [
|
|||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES],
|
||||
"duration": 15,
|
||||
"automated": True,
|
||||
"host_test": "wait_us_auto"
|
||||
"host_test": "wait_us_auto",
|
||||
"mcu": ["LPC1768", "LPC11U24", "LPC812", "KL25Z", "K64F", "KL46Z"],
|
||||
},
|
||||
{
|
||||
"id": "RTOS_8", "description": "ISR (Queue)",
|
||||
"source_dir": join(TEST_DIR, "rtos", "mbed", "isr"),
|
||||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, TEST_MBED_LIB],
|
||||
"automated": True,
|
||||
"mcu": ["LPC1768", "LPC11U24", "LPC812", "KL25Z", "K64F", "KL46Z"],
|
||||
},
|
||||
{
|
||||
"id": "RTOS_9", "description": "SD File write-read",
|
||||
"source_dir": join(TEST_DIR, "rtos", "mbed", "file"),
|
||||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, TEST_MBED_LIB, SD_FS, FAT_FS],
|
||||
"automated": True,
|
||||
"peripherals": ["SD"]
|
||||
"peripherals": ["SD"],
|
||||
"mcu": ["LPC1768", "LPC11U24", "LPC812", "KL25Z", "K64F", "KL46Z"],
|
||||
},
|
||||
|
||||
# Networking Tests
|
||||
|
@ -674,6 +684,15 @@ TESTS = [
|
|||
"host_test": "tcpecho_client_auto",
|
||||
"peripherals": ["ethernet"],
|
||||
},
|
||||
{
|
||||
"id": "NET_14", "description": "UDP PHY/Data link layer",
|
||||
"source_dir": join(TEST_DIR, "net", "echo", "udp_link_layer"),
|
||||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
|
||||
"automated": False,
|
||||
"duration": 15,
|
||||
"host_test": "udp_link_layer_auto.py",
|
||||
"peripherals": ["ethernet"],
|
||||
},
|
||||
|
||||
# u-blox tests
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue