From 4b48679249d40b8203ca2a6ec06a458d24deb615 Mon Sep 17 00:00:00 2001 From: Alexander Lane Date: Fri, 21 Jun 2019 11:54:23 -0500 Subject: [PATCH 1/3] Add code for optional reassociation callback method --- mn_wifi/mobility.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mn_wifi/mobility.py b/mn_wifi/mobility.py index 0878aece5..bd3affc75 100644 --- a/mn_wifi/mobility.py +++ b/mn_wifi/mobility.py @@ -235,6 +235,11 @@ def handover(cls, sta, ap, wlan, ap_wlan): if not sta.params['associatedTo'][wlan] or changeAP: if ap not in sta.params['associatedTo']: Association.associate_infra(sta, ap, wlan=wlan, ap_wlan=ap_wlan) + if "reassoc_callback" in sta.params: + if "reassoc_callback_args" in sta.params: + sta.params["reassoc_callback"](*sta.params['reassoc_callback_args']) + else: + sta.params["reassoc_callback"]() @classmethod def models(cls, **kwargs): From afac74f6cf3e6443ac17e6f18286692c9b3b42cf Mon Sep 17 00:00:00 2001 From: Alexander Lane Date: Wed, 26 Jun 2019 16:54:49 -0500 Subject: [PATCH 2/3] Add locks to handle shell contention from callback methods --- mn_wifi/node.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mn_wifi/node.py b/mn_wifi/node.py index 1a458fa5f..dc84759d4 100644 --- a/mn_wifi/node.py +++ b/mn_wifi/node.py @@ -33,6 +33,7 @@ import numpy as np from scipy.spatial.distance import pdist from six import string_types +from threading import Lock from mininet.log import info, error, warn, debug from mininet.util import (quietRun, errRun, errFail, mountCgroups, @@ -85,6 +86,7 @@ def __init__(self, name, inNamespace=True, **params): self.lastPid, self.lastCmd, self.pollOut) = ( None, None, None, None, None, None, None, None) self.waiting = False + self.lock = Lock() self.readbuf = '' # Start command interpreter shell @@ -664,7 +666,10 @@ def sendCmd(self, *args, **kwargs): and return without waiting for the command to complete. args: command and arguments, or string printPid: print command's PID? (False)""" + #Lock object helps avoid contention when using callbacks + self.lock.acquire() assert self.shell and not self.waiting + self.waiting = True printPid = kwargs.get('printPid', False) # Allow sendCmd( [ list ] ) if len(args) == 1 and isinstance(args[ 0 ], list): @@ -736,6 +741,8 @@ def waitOutput(self, verbose=False, findPid=True): data = self.monitor(findPid=findPid) output += data log(data) + #Wait to release lock until all output has been stored + self.lock.release() return output def cmd(self, *args, **kwargs): From 70c6fb05d5abceb17e10db37f0a4659d8baef3de Mon Sep 17 00:00:00 2001 From: Alexander Lane Date: Wed, 26 Jun 2019 17:35:21 -0500 Subject: [PATCH 3/3] Quick lock fix to avoid interfering with stop scripts --- mn_wifi/node.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mn_wifi/node.py b/mn_wifi/node.py index dc84759d4..51f792ff7 100644 --- a/mn_wifi/node.py +++ b/mn_wifi/node.py @@ -33,7 +33,7 @@ import numpy as np from scipy.spatial.distance import pdist from six import string_types -from threading import Lock +from threading import Lock, ThreadError from mininet.log import info, error, warn, debug from mininet.util import (quietRun, errRun, errFail, mountCgroups, @@ -667,7 +667,6 @@ def sendCmd(self, *args, **kwargs): args: command and arguments, or string printPid: print command's PID? (False)""" #Lock object helps avoid contention when using callbacks - self.lock.acquire() assert self.shell and not self.waiting self.waiting = True printPid = kwargs.get('printPid', False) @@ -742,7 +741,10 @@ def waitOutput(self, verbose=False, findPid=True): output += data log(data) #Wait to release lock until all output has been stored - self.lock.release() + try: + self.lock.release() + except ThreadError: + pass return output def cmd(self, *args, **kwargs): @@ -752,6 +754,7 @@ def cmd(self, *args, **kwargs): log = info if verbose else debug log('*** %s : %s\n' % (self.name, args)) if self.shell: + self.lock.acquire() self.sendCmd(*args, **kwargs) return self.waitOutput(verbose) else: