/// <summary> /// Processes an event and updates the current state. /// </summary> /// <param name="e">The event to process.</param> /// <param name="currentState">The current watchdog state.</param> /// <returns>The new watchdog state.</returns> internal static Zen <SwitchState> ProcessEvent(Zen <Event> e, Zen <SwitchState> currentState) { var stormStartEvent = Event.EventTypeAsInt(EventType.PfcStormStartEvent); var stormEndEvent = Event.EventTypeAsInt(EventType.PfcStormEndEvent); var pollingIntervalEvent = Event.EventTypeAsInt(EventType.PollingIntervalEvent); var isStormStartOn1 = And(e.GetEventType() == stormStartEvent, e.GetPriorityClass() == 0); var isStormStartOn2 = And(e.GetEventType() == stormStartEvent, e.GetPriorityClass() == 1); var stateStormStartOn1 = currentState.SetStormStartedTime1(e.GetTimeStamp()); var stateStormStartOn2 = currentState.SetStormStartedTime2(e.GetTimeStamp()); var isStormEndOn1 = And(e.GetEventType() == stormEndEvent, e.GetPriorityClass() == 0); var isStormEndOn2 = And(e.GetEventType() == stormEndEvent, e.GetPriorityClass() == 1); var stateStormEndOn1 = currentState.SetStormEndedTime1(e.GetTimeStamp()); var stateStormEndOn2 = currentState.SetStormEndedTime2(e.GetTimeStamp()); var isDetectionEvent1 = And( e.GetEventType() == pollingIntervalEvent, currentState.GetStormStartedTime1() > currentState.GetStormEndedTime1(), e.GetTimeStamp() - currentState.GetStormStartedTime1() >= detectionInterval); var isDetectionEvent2 = And( e.GetEventType() == pollingIntervalEvent, currentState.GetStormStartedTime2() > currentState.GetStormEndedTime2(), e.GetTimeStamp() - currentState.GetStormStartedTime2() >= detectionInterval); var stateDetectionOn1 = currentState.SetWatchdogStartDropTime1(e.GetTimeStamp()).SetWatchdogDropPackets1(true); var stateDetectionOn2 = currentState.SetWatchdogStartDropTime2(e.GetTimeStamp()).SetWatchdogDropPackets2(true); var isRestorationEvent1 = And( e.GetEventType() == pollingIntervalEvent, currentState.GetStormEndedTime1() > currentState.GetStormStartedTime1(), e.GetTimeStamp() - currentState.GetWatchdogStartDropTime1() >= restorationInterval); var isRestorationEvent2 = And( e.GetEventType() == pollingIntervalEvent, currentState.GetStormEndedTime2() > currentState.GetStormStartedTime2(), e.GetTimeStamp() - currentState.GetWatchdogStartDropTime2() >= restorationInterval); var stateRestorationOn1 = currentState.SetWatchdogDropPackets1(false); var stateRestorationOn2 = currentState.SetWatchdogDropPackets2(false); return(Cases(currentState, (isStormStartOn1, stateStormStartOn1), (isStormStartOn2, stateStormStartOn2), (isStormEndOn1, stateStormEndOn1), (isStormEndOn2, stateStormEndOn2), (isDetectionEvent1, stateDetectionOn1), (isDetectionEvent2, stateDetectionOn2), (isRestorationEvent1, stateRestorationOn1), (isRestorationEvent2, stateRestorationOn2))); }