Gestion de l'absence de RTT
This commit is contained in:
parent
4d3db32cbc
commit
b235cdd151
1 changed files with 86 additions and 6 deletions
|
@ -5,10 +5,22 @@ import numpy as np
|
||||||
from coapthon import defines
|
from coapthon import defines
|
||||||
|
|
||||||
|
|
||||||
|
class SupervisorError(Exception):
|
||||||
|
def __init__(self, *args: object) -> None:
|
||||||
|
super().__init__(*args)
|
||||||
|
|
||||||
|
|
||||||
|
class NoRttError(SupervisorError):
|
||||||
|
def __init__(self, *args: object) -> None:
|
||||||
|
super().__init__(*args)
|
||||||
|
|
||||||
|
|
||||||
class SuperviseurLocalPlaceHolder():
|
class SuperviseurLocalPlaceHolder():
|
||||||
"""Class de base pour le superviseur
|
"""Class de base pour le superviseur
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
N_MESURE = 0
|
||||||
|
|
||||||
def __init__(self, client_CoAP) -> None:
|
def __init__(self, client_CoAP) -> None:
|
||||||
client_CoAP.superviseur = self
|
client_CoAP.superviseur = self
|
||||||
self.client = client_CoAP
|
self.client = client_CoAP
|
||||||
|
@ -28,6 +40,9 @@ class SuperviseurLocalPlaceHolder():
|
||||||
def reception_token(self, tokken) -> None:
|
def reception_token(self, tokken) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def failed_request(self):
|
||||||
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def RTTs(self):
|
def RTTs(self):
|
||||||
return self._RTTs
|
return self._RTTs
|
||||||
|
@ -39,15 +54,20 @@ class SuperviseurLocalPlaceHolder():
|
||||||
@property
|
@property
|
||||||
def min_RTT(self):
|
def min_RTT(self):
|
||||||
"""Valeur minimum du RTT"""
|
"""Valeur minimum du RTT"""
|
||||||
return min(self.RTTs)
|
if len(self.RTTs):
|
||||||
|
return min(self.RTTs)
|
||||||
|
raise NoRttError
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def avg_RTT(self):
|
def avg_RTT(self):
|
||||||
"""Moyenne du RTT."""
|
"""Moyenne du RTT."""
|
||||||
return sum(self.RTTs)/len(self.RTTs)
|
if len(self.RTTs):
|
||||||
|
return sum(self.RTTs)/len(self.RTTs)
|
||||||
|
raise NoRttError
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def RTO(self):
|
def RTO(self):
|
||||||
|
return self._RTO
|
||||||
return random.uniform(self._RTO, (self._RTO * defines.ACK_RANDOM_FACTOR))
|
return random.uniform(self._RTO, (self._RTO * defines.ACK_RANDOM_FACTOR))
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,11 +76,14 @@ class SuperviseurLocal(SuperviseurLocalPlaceHolder):
|
||||||
Class implementant la supervision local de chaque client.
|
Class implementant la supervision local de chaque client.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
N_MESURE = 2
|
||||||
|
|
||||||
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._n_envoie = 0
|
self._n_envoie = 0
|
||||||
self._n_tokken = 0
|
self._n_token = 0
|
||||||
|
self._n_echec = 0
|
||||||
|
|
||||||
def envoie_token(self, token) -> None:
|
def envoie_token(self, token) -> None:
|
||||||
"""Enregistre l'envoie d'un token
|
"""Enregistre l'envoie d'un token
|
||||||
|
@ -69,9 +92,9 @@ class SuperviseurLocal(SuperviseurLocalPlaceHolder):
|
||||||
token (int): Token à enregistrer
|
token (int): Token à enregistrer
|
||||||
"""
|
"""
|
||||||
self._n_envoie += 1
|
self._n_envoie += 1
|
||||||
self._n_tokken += not(token in self._dict_envoie)
|
self._n_token += not(token in self._dict_envoie)
|
||||||
self._dict_envoie[token] = time.time()
|
self._dict_envoie[token] = time.time()
|
||||||
self._taux_retransmition = 1 - self._n_tokken/self._n_envoie
|
self._taux_retransmition = 1 - self._n_token/self._n_envoie
|
||||||
|
|
||||||
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
|
||||||
|
@ -87,17 +110,25 @@ class SuperviseurLocal(SuperviseurLocalPlaceHolder):
|
||||||
else:
|
else:
|
||||||
pass # raise ValueError("Tokken inconnue")
|
pass # raise ValueError("Tokken inconnue")
|
||||||
|
|
||||||
|
def failed_request(self):
|
||||||
|
self._n_echec += 1
|
||||||
|
return super().failed_request()
|
||||||
|
|
||||||
def callback_new_rtt(self, rtt):
|
def callback_new_rtt(self, rtt):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self._dict_envoie = {}
|
self._dict_envoie = {}
|
||||||
self._n_envoie = 0
|
self._n_envoie = 0
|
||||||
self._n_tokken = 0
|
self._n_token = 0
|
||||||
|
self._n_echec = 0
|
||||||
self._RTTs = []
|
self._RTTs = []
|
||||||
|
|
||||||
|
|
||||||
class SuperviseurLocalFiltre(SuperviseurLocal):
|
class SuperviseurLocalFiltre(SuperviseurLocal):
|
||||||
|
|
||||||
|
N_MESURE = 3
|
||||||
|
|
||||||
def __init__(self, client_CoAP, rtt_init=0.01, alpha_l=0.01, alpha_s=0.1) -> None:
|
def __init__(self, client_CoAP, rtt_init=0.01, alpha_l=0.01, alpha_s=0.1) -> None:
|
||||||
super().__init__(client_CoAP)
|
super().__init__(client_CoAP)
|
||||||
self.alpha_l = alpha_l
|
self.alpha_l = alpha_l
|
||||||
|
@ -120,6 +151,8 @@ class SuperviseurLocalFiltre(SuperviseurLocal):
|
||||||
|
|
||||||
|
|
||||||
class SuperviseurGlobal():
|
class SuperviseurGlobal():
|
||||||
|
nombre_mesure = 3
|
||||||
|
|
||||||
def __init__(self, clients, superviseur_type, *superviseur_args) -> None:
|
def __init__(self, clients, superviseur_type, *superviseur_args) -> None:
|
||||||
"""Genère un superviseur global pour la liste de client donnée
|
"""Genère un superviseur global pour la liste de client donnée
|
||||||
|
|
||||||
|
@ -131,8 +164,17 @@ class SuperviseurGlobal():
|
||||||
self.superviseurs = [superviseur_type(
|
self.superviseurs = [superviseur_type(
|
||||||
client, *superviseur_args) for client in clients]
|
client, *superviseur_args) for client in clients]
|
||||||
|
|
||||||
|
self._last_state = np.zeros((superviseur_type.N_MESURE, len(clients)))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
"""[summary]
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
[type]: [description]
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
taux_retransmissions = np.array(
|
taux_retransmissions = np.array(
|
||||||
[superviseur.taux_retransmission for superviseur in self.superviseurs])
|
[superviseur.taux_retransmission for superviseur in self.superviseurs])
|
||||||
|
|
||||||
|
@ -156,3 +198,41 @@ class SuperviseurGlobal():
|
||||||
representation_etat = np.array([taux_retransmissions, ratio_rtts])
|
representation_etat = np.array([taux_retransmissions, ratio_rtts])
|
||||||
|
|
||||||
return representation_etat
|
return representation_etat
|
||||||
|
"""
|
||||||
|
|
||||||
|
vecteurs = []
|
||||||
|
for n, superviseur in enumerate(self.superviseurs):
|
||||||
|
if isinstance(superviseur, SuperviseurLocalFiltre):
|
||||||
|
try :
|
||||||
|
vecteurs.append(np.array([[superviseur.taux_retransmission, superviseur.min_RTT/superviseur.avg_RTT, superviseur.RTT_S/superviseur.RTT_L]], dtype=np.float32))
|
||||||
|
except NoRttError:
|
||||||
|
vecteurs.append(self._last_state[:,n])
|
||||||
|
return np.concatenate(vecteurs, axis=0).T
|
||||||
|
|
||||||
|
def application_action(self, actions):
|
||||||
|
for n, alpha in enumerate(actions):
|
||||||
|
if alpha >= 0:
|
||||||
|
g = 1 + alpha
|
||||||
|
else:
|
||||||
|
g = 1/(1-alpha)
|
||||||
|
self.superviseurs[n]._RTO *= g
|
||||||
|
self.superviseurs[n]._RTO = min([self.superviseurs[n]._RTO, 2])
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
[superviseur.reset() for superviseur in self.superviseurs]
|
||||||
|
|
||||||
|
def qualite(self, n_request, beta_retransmission, beta_equite, beta_RTO):
|
||||||
|
|
||||||
|
n_envoies = np.array([
|
||||||
|
superviseur._n_envoie for superviseur in self.superviseurs])
|
||||||
|
n_tokens = np.array([superviseur._n_token for superviseur in self.superviseurs])
|
||||||
|
RTOs = np.array([superviseur.RTO for superviseur in self.superviseurs])
|
||||||
|
|
||||||
|
qualite = 0
|
||||||
|
qualite -= beta_retransmission * sum(n_tokens)/sum(n_envoies)
|
||||||
|
qualite += beta_equite * \
|
||||||
|
(sum(n_envoies/n_tokens))**2 / \
|
||||||
|
(len(n_envoies) * sum((n_envoies/n_tokens)**2))
|
||||||
|
qualite -= beta_RTO * np.max(RTOs)
|
||||||
|
|
||||||
|
return qualite
|
||||||
|
|
Loading…
Reference in a new issue