// implements ExplorePolicy interface func (p *MyPolicy) QueueNextEvent(event signal.Event) { // Possible events: // - JavaFunctionEvent // - PacketEvent // - FilesystemEvent // - ProcSetEvent (Linux procfs) // - LogEvent fmt.Printf("Event: %s\n", event) // You can also inject fault actions // - PacketFaultAction // - FilesystemFaultAction // - ProcSetSchedAction // - ShellAction action, err := event.DefaultAction() if err != nil { panic(err) } // send in a goroutine so as to make the function non-blocking. // (Note that earthquake/util/queue/TimeBoundedQueue provides // better semantics and determinism, this is just an example.) go func() { fmt.Printf("Action ready: %s\n", action) p.nextActionChan <- action fmt.Printf("Action passed: %s\n", action) }() }
func (r *Random) QueueNextEvent(event signal.Event) { minInterval := r.MinInterval maxInterval := r.MaxInterval _, prioritized := r.PrioritizedEntities[event.EntityID()] if prioritized { // FIXME: magic coefficient for prioritizing (decrease intervals) minInterval = time.Duration(float64(minInterval) * 0.8) maxInterval = time.Duration(float64(maxInterval) * 0.8) } item, err := queue.NewBasicTBQueueItem(event, minInterval, maxInterval) if err != nil { panic(log.Critical(err)) } r.queue.Enqueue(item) }
// for dequeueRoutine() func (r *Random) makeActionForEvent(event signal.Event) (signal.Action, error) { switch event.(type) { case *signal.ProcSetEvent: return r.makeActionForProcSetEvent(event.(*signal.ProcSetEvent)) } defaultAction, defaultActionErr := event.DefaultAction() faultAction, faultActionErr := event.DefaultFaultAction() if faultAction == nil { return defaultAction, defaultActionErr } if rand.Intn(999) < int(r.FaultActionProbability*1000.0) { log.Debugf("Injecting fault %s for %s", faultAction, event) return faultAction, faultActionErr } else { return defaultAction, defaultActionErr } }