예제 #1
0
        /// <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>
        private static Zen <SwitchState> ProcessEvent(Zen <Event> e, Zen <SwitchState> currentState)
        {
            var switchState = currentState;

            var burstEvent      = Event.EventTypeAsByte(EventType.PacketBurstEvent);
            var stormStartEvent = Event.EventTypeAsByte(EventType.PfcStormStartEvent);
            var stormEndEvent   = Event.EventTypeAsByte(EventType.PfcStormEndEvent);

            // update the watchdog state based on detection
            var conservativeDetectionTime   = (ushort)(2 * detectionInterval);
            var conservativeRestorationTime = (ushort)(2 * restorationInterval);

            var isDetectionEvent1 = And(
                switchState.GetStormStartedTime1() > switchState.GetStormEndedTime1(),
                e.GetTimeStamp() - switchState.GetStormStartedTime1() >= conservativeDetectionTime);

            var isDetectionEvent2 = And(
                switchState.GetStormStartedTime2() > switchState.GetStormEndedTime2(),
                e.GetTimeStamp() - switchState.GetStormStartedTime2() >= conservativeDetectionTime);

            var isRestorationEvent1 = And(
                switchState.GetStormEndedTime1() > switchState.GetStormStartedTime1(),
                e.GetTimeStamp() - switchState.GetWatchdogStartDropTime1() >= conservativeRestorationTime);

            var isRestorationEvent2 = And(
                switchState.GetStormEndedTime2() > switchState.GetStormStartedTime2(),
                e.GetTimeStamp() - switchState.GetWatchdogStartDropTime2() >= conservativeRestorationTime);

            switchState = If(isRestorationEvent1, switchState.SetWatchdogDropPackets1(false), switchState);
            switchState = If(isRestorationEvent2, switchState.SetWatchdogDropPackets2(false), switchState);
            switchState = If(isDetectionEvent1, switchState.SetWatchdogStartDropTime1(e.GetTimeStamp()).SetWatchdogDropPackets1(true), switchState);
            switchState = If(isDetectionEvent2, switchState.SetWatchdogStartDropTime2(e.GetTimeStamp()).SetWatchdogDropPackets2(true), switchState);

            // update the watchdog state
            var isBurstOn1 = And(e.GetEventType() == burstEvent, e.GetPriorityClass() == 0);
            var isBurstOn2 = And(e.GetEventType() == burstEvent, e.GetPriorityClass() == 1);

            var stateBurst1 = switchState.AddPacket(Pair(e.GetTimeStamp(), Pair <byte, bool>(0, currentState.GetWatchdogDropPackets1())));
            var stateBurst2 = switchState.AddPacket(Pair(e.GetTimeStamp(), Pair <byte, bool>(1, currentState.GetWatchdogDropPackets1())));

            var isStormStartOn1 = And(e.GetEventType() == stormStartEvent, e.GetPriorityClass() == 0);
            var isStormStartOn2 = And(e.GetEventType() == stormStartEvent, e.GetPriorityClass() == 1);

            var stateStormStartOn1 = switchState.SetStormStartedTime1(e.GetTimeStamp());
            var stateStormStartOn2 = switchState.SetStormStartedTime2(e.GetTimeStamp());

            var isStormEndOn1 = And(e.GetEventType() == stormEndEvent, e.GetPriorityClass() == 0);
            var isStormEndOn2 = And(e.GetEventType() == stormEndEvent, e.GetPriorityClass() == 1);

            var stateStormEndOn1 = switchState.SetStormEndedTime1(e.GetTimeStamp());
            var stateStormEndOn2 = switchState.SetStormEndedTime2(e.GetTimeStamp());

            return(Cases(switchState,
                         (isStormStartOn1, stateStormStartOn1),
                         (isStormStartOn2, stateStormStartOn2),
                         (isStormEndOn1, stateStormEndOn1),
                         (isStormEndOn2, stateStormEndOn2),
                         (isBurstOn1, stateBurst1),
                         (isBurstOn2, stateBurst2)));
        }
예제 #2
0
        /// <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)));
        }