MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / configureFSM

Method configureFSM

pkg/rules/sequence.go:230–265  ·  view source on GitHub ↗

configureFSM sets up the states and transitions of the state automata. A simplified representation of the constructed automata is better visualized in the diagram above +-----+ +-----+ +-----+ ----> | 0 | -----> | 1 | -----> | 2 | -----> terminal + +-----+

()

Source from the content-addressed store, hash-verified

228// sequence terminates. In this case, the state machine transitions to the
229// expired state.
230func (s *sequenceState) configureFSM() {
231 for seqID, expr := range s.seq.Expressions {
232 // sequence expression index is the state name
233 s.exprs[seqID] = expr.Expr.String()
234 // is this the last state?
235 if seqID >= len(s.seq.Expressions)-1 {
236 s.fsm.
237 Configure(seqID).
238 Permit(matchTransition, sequenceTerminalState).
239 Permit(cancelTransition, sequenceDeadlineState).
240 Permit(expireTransition, sequenceExpiredState)
241 } else {
242 // the previous state can transition to the next one
243 // via the match transition, or can either go to the
244 // deadline or expired states via cancel and expire
245 // transitions respectively
246 s.fsm.
247 Configure(seqID).
248 Permit(matchTransition, seqID+1).
249 Permit(cancelTransition, sequenceDeadlineState).
250 Permit(expireTransition, sequenceExpiredState)
251 }
252 }
253 // configure reset transitions that are triggered
254 // when the final state is reached of when a deadline
255 // or sequence expiration happens
256 s.fsm.
257 Configure(sequenceTerminalState).
258 Permit(resetTransition, sequenceInitialState)
259 s.fsm.
260 Configure(sequenceDeadlineState).
261 Permit(resetTransition, sequenceInitialState)
262 s.fsm.
263 Configure(sequenceExpiredState).
264 Permit(resetTransition, sequenceInitialState)
265}
266
267func (s *sequenceState) matchTransition(seqID int, e *event.Event) error {
268 s.smu.Lock()

Callers 1

newSequenceStateFunction · 0.95

Calls 1

StringMethod · 0.65

Tested by

no test coverage detected