2021-06-24 17:22:02 +02:00
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import socket
|
|
|
|
import time
|
|
|
|
|
|
|
|
from coapthon.client.helperclient import HelperClient
|
2021-07-01 15:19:17 +02:00
|
|
|
from coapthon.client.superviseur import SuperviseurLocal, SuperviseurLocalFiltre
|
2021-06-24 17:22:02 +02:00
|
|
|
from coapthon.utils import parse_uri
|
|
|
|
|
|
|
|
|
|
|
|
host, port, path = parse_uri("coap://localhost:5683/basic")
|
|
|
|
try:
|
|
|
|
tmp = socket.gethostbyname(host)
|
|
|
|
host = tmp
|
|
|
|
except socket.gaierror:
|
|
|
|
pass
|
|
|
|
print('start client')
|
|
|
|
client = HelperClient(server=(host, port))
|
|
|
|
print('client started')
|
|
|
|
client.protocol.superviseur = SuperviseurLocalFiltre(client)
|
|
|
|
super = client.protocol.superviseur
|
|
|
|
|
|
|
|
rtt_l = []
|
|
|
|
rtt_s = []
|
|
|
|
|
2021-07-01 15:19:17 +02:00
|
|
|
N_rep = 100
|
2021-06-24 17:39:13 +02:00
|
|
|
|
|
|
|
for n_rep in range(N_rep):
|
2021-06-24 17:22:02 +02:00
|
|
|
# print('rep{}'.format(n_rep))
|
|
|
|
response = client.get(path)
|
2021-07-01 15:19:17 +02:00
|
|
|
rtt_l.append(super._RTT_L)
|
|
|
|
rtt_s.append(super._RTT_S)
|
2021-06-24 17:22:02 +02:00
|
|
|
# time.sleep(1)
|
|
|
|
# print("{} : \n{}".format(n_rep, response.pretty_print()))
|
|
|
|
client.stop()
|
|
|
|
|
|
|
|
print(super.min_RTT, super.avg_RTT, super.tau_retransmission)
|
|
|
|
|
|
|
|
fig, axs = plt.subplots(2)
|
|
|
|
|
|
|
|
axs[0].hist(super.RTTs, 100, density=True)
|
|
|
|
|
|
|
|
axs[0].set_xlabel('RTT (s)')
|
|
|
|
axs[0].set_xlim(left=0)
|
|
|
|
|
2021-06-24 17:39:13 +02:00
|
|
|
# axs[1].step(range(N_rep), super.RTTs, where='post', label='$RTT$')
|
2021-06-24 17:22:02 +02:00
|
|
|
axs[1].plot(rtt_s, label="$RTT_S$")
|
2021-06-24 17:39:13 +02:00
|
|
|
axs[1].plot(rtt_l, label="$RTT_L$")
|
2021-06-24 17:22:02 +02:00
|
|
|
|
|
|
|
axs[1].set_ylim(bottom=0)
|
|
|
|
axs[1].set_xlabel('Nombre de message')
|
|
|
|
axs[1].set_ylabel('RTT (s)')
|
|
|
|
axs[1].legend()
|
|
|
|
|
|
|
|
fig.suptitle('Resultat sur un serveur local')
|
|
|
|
|
|
|
|
fig.tight_layout()
|
|
|
|
fig.savefig('demo.png')
|