def applySession(self, session): # retrieve the automata automata = self.project.getGrammar().getAutomata() self.log.debug("automata: %s" % automata.getDotCode()) if automata is None: self.log.warn("Cannot apply a session on the current automata because it doesn't exist") return None difference = None # Configure the role-play environment # with : # - a memory memory = Memory() # memory = Memory(None) # - an abstraction layer abstractionLayer = AbstractionLayer(None, self.project.getVocabulary(), memory, None, None) currentState = automata.getInitialState() # We execute the opening transition if len(currentState.getTransitions()) == 1 and currentState.getTransitions()[0].getType() == OpenChannelTransition.TYPE: currentState = currentState.getTransitions()[0].getOutputState() isInput = True for message in session.getMessages(): self.log.debug("Inject message: %s" % (message.getData())) # we abstract the message symbol = abstractionLayer.abstract(TypeConvertor.netzobRawToBitArray(str(message.getData()))) if isInput: # We simulate the reception of the message # - verify its a valid input symbol # - find out the associated transition currentTransition = None for transition in currentState.getTransitions(): if transition.getInputSymbol() == symbol: currentTransition = transition break if currentTransition is None: self.log.warn("Input symbol %s doesn't match any existing transition in current state %s" % (symbol.getName(), currentState.getName())) self.log.warn("We forget this message.") else: self.log.debug("Input symbol %s matchs the transition %s from state %s" % (symbol.getName(), currentTransition.getName(), currentState.getName())) isInput = False else: # We simulate emiting the message # - we just verify the symbol matches available output message in current transition found = False for (outputSymbol, probability, time) in currentTransition.getOutputSymbols(): if symbol.getID() == outputSymbol.getID(): found = True isInput = True currentState = currentTransition.getOutputState() break if not found: self.log.info("A difference has been found, symbol %s is not an output symbol of transition %s" % (symbol.getName(), currentTransition.getName())) return (currentTransition, symbol) return difference
def displaySession(self, session): memory = Memory(None) # - an abstraction layer abstractionLayer = AbstractionLayer(None, self.project.getVocabulary(), memory, None, None) symbols = [] for message in session.getMessages(): symbols.append(abstractionLayer.abstract(TypeConvertor.netzobRawToBitArray(str(message.getData())))) for symbol in symbols: self.log.debug("- %s" % symbol.getName())
def displaySession(self, session): memory = Memory() # memory = Memory(None) # - an abstraction layer abstractionLayer = AbstractionLayer(None, self.project.getVocabulary(), memory, None, None) symbols = [] for message in session.getMessages(): symbols.append( abstractionLayer.abstract( TypeConvertor.netzobRawToBitArray(str(message.getData())))) for symbol in symbols: self.log.debug("- %s" % symbol.getName())
def applySession(self, session): # retrieve the automata automata = self.project.getGrammar().getAutomata() self.log.debug("automata: %s" % automata.getDotCode()) if automata is None: self.log.warn( "Cannot apply a session on the current automata because it doesn't exist" ) return None difference = None # Configure the role-play environment # with : # - a memory memory = Memory() # memory = Memory(None) # - an abstraction layer abstractionLayer = AbstractionLayer(None, self.project.getVocabulary(), memory, None, None) currentState = automata.getInitialState() # We execute the opening transition if len(currentState.getTransitions() ) == 1 and currentState.getTransitions()[0].getType( ) == OpenChannelTransition.TYPE: currentState = currentState.getTransitions()[0].getOutputState() isInput = True for message in session.getMessages(): self.log.debug("Inject message: %s" % (message.getData())) # we abstract the message symbol = abstractionLayer.abstract( TypeConvertor.netzobRawToBitArray(str(message.getData()))) if isInput: # We simulate the reception of the message # - verify its a valid input symbol # - find out the associated transition currentTransition = None for transition in currentState.getTransitions(): if transition.getInputSymbol() == symbol: currentTransition = transition break if currentTransition is None: self.log.warn( "Input symbol %s doesn't match any existing transition in current state %s" % (symbol.getName(), currentState.getName())) self.log.warn("We forget this message.") else: self.log.debug( "Input symbol %s matchs the transition %s from state %s" % (symbol.getName(), currentTransition.getName(), currentState.getName())) isInput = False else: # We simulate emiting the message # - we just verify the symbol matches available output message in current transition found = False for (outputSymbol, probability, time) in currentTransition.getOutputSymbols(): if symbol.getID() == outputSymbol.getID(): found = True isInput = True currentState = currentTransition.getOutputState() break if not found: self.log.info( "A difference has been found, symbol %s is not an output symbol of transition %s" % (symbol.getName(), currentTransition.getName())) return (currentTransition, symbol) return difference