Skip to content

Commit

Permalink
Merge pull request #177 from MichaelWasher/state_machine_clean
Browse files Browse the repository at this point in the history
Clean State Machine Graphs
  • Loading branch information
gizmoguy authored Aug 13, 2019
2 parents c7bfb60 + d1ace21 commit dab415d
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 140 deletions.
15 changes: 9 additions & 6 deletions chewie/chewie.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ def send_preemptive_identity_request(self, port_id):

def reauth_port(self, src_mac, port_id):
"""
Send an Identity Request to src_mac, on port_id. prompting the supplicant to re authenticate.
Send an Identity Request to src_mac, on port_id. prompting
the supplicant to re authenticate.
Args:
src_mac (MacAddress):
port_id (str):
Expand Down Expand Up @@ -288,17 +289,19 @@ def setup_radius_socket(self):
self.radius_server_port,
log_prefix)
self.radius_socket.setup()
self.logger.info("Radius Listening on %s:%d" % (self.radius_listen_ip,
self.radius_listen_port))
self.logger.info("Radius Listening on %s:%d",
self.radius_listen_ip,
self.radius_listen_port)

def send_eap_messages(self):
"""Send EAP messages to Supplicant forever."""
while self.running():
sleep(0)
eap_queue_message = self.eap_output_messages.get()
self.logger.info("Sending message %s from %s to %s" %
(eap_queue_message.message, str(eap_queue_message.port_mac),
str(eap_queue_message.src_mac)))
self.logger.info("Sending message %s from %s to %s",
eap_queue_message.message,
str(eap_queue_message.port_mac),
str(eap_queue_message.src_mac))
self.eap_socket.send(MessagePacker.ethernet_pack(eap_queue_message.message,
eap_queue_message.port_mac,
eap_queue_message.src_mac))
Expand Down
44 changes: 44 additions & 0 deletions chewie/state_machines/abstract_state_machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""This Module provides the Abstract Design Requirements for a State Machine in Chewie"""
from transitions.extensions import GraphMachine


class AbstractStateMachine:
"""This Class provides the Abstract Design Requirements for a State Machine in Chewie"""

PROGRESS_STATES = []

SUCCESS_STATES = []
FAILURE_STATES = []
COMPLETION_STATES = FAILURE_STATES + SUCCESS_STATES
INITIAL_STATE = None
STATES = COMPLETION_STATES + PROGRESS_STATES

ERROR_TRANSTIONS = []

CORE_TRANSITIONS = []
TRANSITIONS = CORE_TRANSITIONS + ERROR_TRANSTIONS
port_enabled = None
state = None

def is_in_progress(self):
"""
Returns true if the state machine is currently in progress
"""
return self.port_enabled and self.state not in self.COMPLETION_STATES

def is_success(self):
"""
Returns true if the state machine currently in a successful completion state and enabled
"""
return self.port_enabled and self.state in self.SUCCESS_STATES

@classmethod
def build_state_graph(cls, filename):
"Build a graphc representation of the state machine and store in 'filename'.png"
model = type('model', (object,), {})()
GraphMachine(model=model, states=cls.STATES,
title=cls.__name__,
transitions=cls.CORE_TRANSITIONS,
queued=True,
initial=cls.INITIAL_STATE)
model.get_graph().draw(filename, prog='dot') # pylint: disable=no-member
Loading

0 comments on commit dab415d

Please sign in to comment.