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.messages.response import Response
|
||||||
from coapthon.serializer import Serializer
|
from coapthon.serializer import Serializer
|
||||||
|
|
||||||
from coapthon.client.superviseur_local import SuperviseurLocalBase
|
from coapthon.client.superviseur_local import SuperviseurLocalPlaceHolder
|
||||||
|
|
||||||
__author__ = 'Giacomo Tanganelli'
|
__author__ = 'Giacomo Tanganelli'
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ class CoAP(object):
|
||||||
|
|
||||||
self._receiver_thread = None
|
self._receiver_thread = None
|
||||||
|
|
||||||
self.superviseur = SuperviseurLocalBase(self)
|
self.superviseur = SuperviseurLocalPlaceHolder(self)
|
||||||
|
|
||||||
def purge_transactions(self, timeout_time=defines.EXCHANGE_LIFETIME):
|
def purge_transactions(self, timeout_time=defines.EXCHANGE_LIFETIME):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
class SuperviseurLocalBase():
|
class SuperviseurLocalPlaceHolder():
|
||||||
"""Class de base pour le superviseur
|
"""Class de base pour le superviseur
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, client_CoAP) -> None:
|
def __init__(self, client_CoAP) -> None:
|
||||||
self.client = client_CoAP
|
self.client = client_CoAP
|
||||||
self._n_tokken = 0
|
self._RTTs = []
|
||||||
self._n_envoie = 0
|
self._taux_retransmition = 0
|
||||||
|
|
||||||
def envoie_message(self, message) -> None:
|
def envoie_message(self, message) -> None:
|
||||||
self.envoie_token(message.token)
|
self.envoie_token(message.token)
|
||||||
|
@ -15,6 +16,20 @@ class SuperviseurLocalBase():
|
||||||
def reception_message(self, message) -> None:
|
def reception_message(self, message) -> None:
|
||||||
self.reception_token(message.token)
|
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
|
@property
|
||||||
def min_RTT(self):
|
def min_RTT(self):
|
||||||
"""Valeur minimum du RTT"""
|
"""Valeur minimum du RTT"""
|
||||||
|
@ -25,13 +40,8 @@ class SuperviseurLocalBase():
|
||||||
"""Moyenne du RTT."""
|
"""Moyenne du RTT."""
|
||||||
return sum(self.RTTs)/len(self.RTTs)
|
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(SuperviseurLocalPlaceHolder):
|
||||||
class SuperviseurLocal(SuperviseurLocalBase):
|
|
||||||
"""
|
"""
|
||||||
Class implementant la supervision local de chaque client.
|
Class implementant la supervision local de chaque client.
|
||||||
"""
|
"""
|
||||||
|
@ -39,16 +49,8 @@ class SuperviseurLocal(SuperviseurLocalBase):
|
||||||
def __init__(self, client_CoAP) -> None:
|
def __init__(self, client_CoAP) -> None:
|
||||||
super().__init__(client_CoAP)
|
super().__init__(client_CoAP)
|
||||||
self._dict_envoie = {}
|
self._dict_envoie = {}
|
||||||
self._dict_reception = {}
|
self._n_envoie = 0
|
||||||
|
self._n_tokken = 0
|
||||||
@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
|
|
||||||
|
|
||||||
def envoie_token(self, token) -> None:
|
def envoie_token(self, token) -> None:
|
||||||
"""Enregistre l'envoie d'un token
|
"""Enregistre l'envoie d'un token
|
||||||
|
@ -57,11 +59,8 @@ class SuperviseurLocal(SuperviseurLocalBase):
|
||||||
token (int): Token à enregistrer
|
token (int): Token à enregistrer
|
||||||
"""
|
"""
|
||||||
self._n_envoie += 1
|
self._n_envoie += 1
|
||||||
if token in self._dict_envoie:
|
self._n_tokken += not(token in self._dict_envoie)
|
||||||
self._dict_envoie[token].append(time.time())
|
self._dict_envoie[token] = time.time()
|
||||||
else:
|
|
||||||
self._n_tokken += 1
|
|
||||||
self._dict_envoie[token] = [time.time()]
|
|
||||||
|
|
||||||
def reception_token(self, token) -> None:
|
def reception_token(self, token) -> None:
|
||||||
"""Enregistre l'arrivée d'un token
|
"""Enregistre l'arrivée d'un token
|
||||||
|
@ -69,40 +68,41 @@ class SuperviseurLocal(SuperviseurLocalBase):
|
||||||
Args:
|
Args:
|
||||||
token (int): Token à enregister
|
token (int): Token à enregister
|
||||||
"""
|
"""
|
||||||
if token in self._dict_reception:
|
if token in self._dict_envoie:
|
||||||
self._dict_reception[token].append(time.time())
|
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:
|
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:
|
def __init__(self, client_CoAP, rtt_init=0.001, alpha_l=0.01, alpha_s=0.1) -> None:
|
||||||
super().__init__(client_CoAP)
|
super().__init__(client_CoAP)
|
||||||
self._dict_envoie = {}
|
self._dict_envoie = {}
|
||||||
self.alpha_l = alpha_l
|
self.alpha_l = alpha_l
|
||||||
self.alpha_s = alpha_s
|
self.alpha_s = alpha_s
|
||||||
self.RTT_L = rtt_init
|
self._RTT_L = rtt_init
|
||||||
self.RTT_S = rtt_init
|
self._RTT_S = rtt_init
|
||||||
self.RTTs = []
|
|
||||||
|
|
||||||
def envoie_token(self, token) -> None:
|
def callback_new_rtt(self, rtt):
|
||||||
"""Enregistre l'envoie d'un token
|
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:
|
@property
|
||||||
token (int): Token à enregistrer
|
def RTT_L(self):
|
||||||
"""
|
return self._RTT_L
|
||||||
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()]
|
|
||||||
|
|
||||||
def reception_token(self, token) -> None:
|
@property
|
||||||
if token in self._dict_envoie:
|
def RTT_S(self):
|
||||||
r = time.time() - self._dict_envoie[token][-1]
|
return self._RTT_S
|
||||||
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
|
|
||||||
|
|
Loading…
Reference in a new issue