Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code for optional reassociation callback method #233

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions mn_wifi/mobility.py
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions mn_wifi/node.py
Expand Up @@ -33,6 +33,7 @@
import numpy as np
from scipy.spatial.distance import pdist
from six import string_types
from threading import Lock, ThreadError

from mininet.log import info, error, warn, debug
from mininet.util import (quietRun, errRun, errFail, mountCgroups,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -664,7 +666,9 @@ 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
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):
Expand Down Expand Up @@ -736,6 +740,11 @@ 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
try:
self.lock.release()
except ThreadError:
pass
return output

def cmd(self, *args, **kwargs):
Expand All @@ -745,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:
Expand Down