blob: 920b1d432ce0ff0e22a59cfdaabb3c03e1422982 [file] [log] [blame]
Matteo Scandolo11006992019-08-28 11:29:46 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070017package devices
18
19import "github.com/looplab/fsm"
20
Matteo Scandolo11006992019-08-28 11:29:46 -070021var newFSM = fsm.NewFSM
22
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070023func getOperStateFSM(cb fsm.Callback) *fsm.FSM {
Matteo Scandolo11006992019-08-28 11:29:46 -070024 return newFSM(
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070025 "down",
26 fsm.Events{
27 {Name: "enable", Src: []string{"down"}, Dst: "up"},
28 {Name: "disable", Src: []string{"up"}, Dst: "down"},
29 },
30 fsm.Callbacks{
31 "enter_state": func(e *fsm.Event) {
32 cb(e)
33 },
34 },
35 )
36}