Superviseur locaux fonctionels
This commit is contained in:
parent
07b171cfc4
commit
dbb6b88c22
2 changed files with 52 additions and 52 deletions
|
@ -16,7 +16,7 @@ from coapthon.messages.request import Request
|
|||
from coapthon.messages.response import Response
|
||||
from coapthon.serializer import Serializer
|
||||
|
||||
from coapthon.client.superviseur_local import SuperviseurLocalBase
|
||||
from coapthon.client.superviseur_local import SuperviseurLocalPlaceHolder
|
||||
|
||||
__author__ = 'Giacomo Tanganelli'
|
||||
|
||||
|
@ -67,7 +67,7 @@ class CoAP(object):
|
|||
|
||||
self._receiver_thread = None
|
||||
|
||||
self.superviseur = SuperviseurLocalBase(self)
|
||||
self.superviseur = SuperviseurLocalPlaceHolder(self)
|
||||
|
||||
def purge_transactions(self, timeout_time=defines.EXCHANGE_LIFETIME):
|
||||
"""
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import time
|
||||
|
||||
|
||||
class SuperviseurLocalBase():
|
||||
class SuperviseurLocalPlaceHolder():
|
||||
"""Class de base pour le superviseur
|
||||
"""
|
||||
|
||||
def __init__(self, client_CoAP) -> None:
|
||||
self.client = client_CoAP
|
||||
self._n_tokken = 0
|
||||
self._n_envoie = 0
|
||||
self._RTTs = []
|
||||
self._taux_retransmition = 0
|
||||
|
||||
def envoie_message(self, message) -> None:
|
||||
self.envoie_token(message.token)
|
||||
|
@ -15,6 +16,20 @@ class SuperviseurLocalBase():
|
|||
def reception_message(self, message) -> None:
|
||||
self.reception_token(message.token)
|
||||
|
||||
def envoie_token(self, token) -> None:
|
||||
pass
|
||||
|
||||
def reception_token(self, tokken) -> None:
|
||||
pass
|
||||
|
||||
@property
|
||||
def RTTs(self):
|
||||
return self._RTTs
|
||||
|
||||
@property
|
||||
def taux_retransmition(self):
|
||||
return self._taux_retransmition
|
||||
|
||||
@property
|
||||
def min_RTT(self):
|
||||
"""Valeur minimum du RTT"""
|
||||
|
@ -25,13 +40,8 @@ class SuperviseurLocalBase():
|
|||
"""Moyenne du RTT."""
|
||||
return sum(self.RTTs)/len(self.RTTs)
|
||||
|
||||
@property
|
||||
def tau_retransmission(self):
|
||||
"""Rapport du nombre de message correspondant à des restransmission sur le nombre de message total."""
|
||||
return 1 - self._n_tokken/self._n_envoie
|
||||
|
||||
|
||||
class SuperviseurLocal(SuperviseurLocalBase):
|
||||
class SuperviseurLocal(SuperviseurLocalPlaceHolder):
|
||||
"""
|
||||
Class implementant la supervision local de chaque client.
|
||||
"""
|
||||
|
@ -39,16 +49,8 @@ class SuperviseurLocal(SuperviseurLocalBase):
|
|||
def __init__(self, client_CoAP) -> None:
|
||||
super().__init__(client_CoAP)
|
||||
self._dict_envoie = {}
|
||||
self._dict_reception = {}
|
||||
|
||||
@property
|
||||
def RTTs(self):
|
||||
RTTs = []
|
||||
for token in self._dict_reception:
|
||||
if token in self._dict_envoie:
|
||||
RTTs.append(
|
||||
self._dict_reception[token][0] - self._dict_envoie[token][-1])
|
||||
return RTTs
|
||||
self._n_envoie = 0
|
||||
self._n_tokken = 0
|
||||
|
||||
def envoie_token(self, token) -> None:
|
||||
"""Enregistre l'envoie d'un token
|
||||
|
@ -57,11 +59,8 @@ class SuperviseurLocal(SuperviseurLocalBase):
|
|||
token (int): Token à enregistrer
|
||||
"""
|
||||
self._n_envoie += 1
|
||||
if token in self._dict_envoie:
|
||||
self._dict_envoie[token].append(time.time())
|
||||
else:
|
||||
self._n_tokken += 1
|
||||
self._dict_envoie[token] = [time.time()]
|
||||
self._n_tokken += not(token in self._dict_envoie)
|
||||
self._dict_envoie[token] = time.time()
|
||||
|
||||
def reception_token(self, token) -> None:
|
||||
"""Enregistre l'arrivée d'un token
|
||||
|
@ -69,40 +68,41 @@ class SuperviseurLocal(SuperviseurLocalBase):
|
|||
Args:
|
||||
token (int): Token à enregister
|
||||
"""
|
||||
if token in self._dict_reception:
|
||||
self._dict_reception[token].append(time.time())
|
||||
if token in self._dict_envoie:
|
||||
rtt = time.time() - self._dict_envoie[token]
|
||||
self._RTTs.append(time.time() - self._dict_envoie[token])
|
||||
del self._dict_envoie[token]
|
||||
self.callback_new_rtt(rtt)
|
||||
else:
|
||||
self._dict_reception[token] = [time.time()]
|
||||
pass #raise ValueError("Tokken inconnue")
|
||||
|
||||
@property
|
||||
def tau_retransmission(self):
|
||||
"""Rapport du nombre de message correspondant à des restransmission sur le nombre de message total."""
|
||||
return 1 - self._n_tokken/self._n_envoie
|
||||
|
||||
def callback_new_rtt(self, rtt):
|
||||
pass
|
||||
|
||||
|
||||
class SuperviseurLocalFiltre(SuperviseurLocalBase):
|
||||
class SuperviseurLocalFiltre(SuperviseurLocal):
|
||||
def __init__(self, client_CoAP, rtt_init=0.001, alpha_l=0.01, alpha_s=0.1) -> None:
|
||||
super().__init__(client_CoAP)
|
||||
self._dict_envoie = {}
|
||||
self.alpha_l = alpha_l
|
||||
self.alpha_s = alpha_s
|
||||
self.RTT_L = rtt_init
|
||||
self.RTT_S = rtt_init
|
||||
self.RTTs = []
|
||||
self._RTT_L = rtt_init
|
||||
self._RTT_S = rtt_init
|
||||
|
||||
def envoie_token(self, token) -> None:
|
||||
"""Enregistre l'envoie d'un token
|
||||
def callback_new_rtt(self, rtt):
|
||||
self._RTT_L = rtt*self.alpha_l + (1 - self.alpha_l) * self._RTT_L
|
||||
self._RTT_S = rtt*self.alpha_s + (1 - self.alpha_s) * self._RTT_S
|
||||
return super().callback_new_rtt(rtt)
|
||||
|
||||
Args:
|
||||
token (int): Token à enregistrer
|
||||
"""
|
||||
self._n_envoie += 1
|
||||
if token in self._dict_envoie:
|
||||
self._dict_envoie[token].append(time.time())
|
||||
else:
|
||||
self._n_tokken += 1
|
||||
self._dict_envoie[token] = [time.time()]
|
||||
@property
|
||||
def RTT_L(self):
|
||||
return self._RTT_L
|
||||
|
||||
def reception_token(self, token) -> None:
|
||||
if token in self._dict_envoie:
|
||||
r = time.time() - self._dict_envoie[token][-1]
|
||||
self.RTTs.append(r)
|
||||
self.RTT_L = r*self.alpha_l + (1 - self.alpha_l) * self.RTT_L
|
||||
self.RTT_S = r*self.alpha_s + (1 - self.alpha_s) * self.RTT_S
|
||||
else:
|
||||
raise ValueError
|
||||
@property
|
||||
def RTT_S(self):
|
||||
return self._RTT_S
|
||||
|
|
Loading…
Reference in a new issue