blob: 5a568254e8e4aafbc899da3399278e07682fa492 [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
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070019import (
20 "github.com/looplab/fsm"
21 "github.com/opencord/voltha-protos/go/openolt"
22 "strconv"
23)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070024
Matteo Scandolo11006992019-08-28 11:29:46 -070025var newFSM = fsm.NewFSM
26
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070027func getOperStateFSM(cb fsm.Callback) *fsm.FSM {
Matteo Scandolo11006992019-08-28 11:29:46 -070028 return newFSM(
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070029 "down",
30 fsm.Events{
31 {Name: "enable", Src: []string{"down"}, Dst: "up"},
32 {Name: "disable", Src: []string{"up"}, Dst: "down"},
33 },
34 fsm.Callbacks{
35 "enter_state": func(e *fsm.Event) {
36 cb(e)
37 },
38 },
39 )
40}
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070041
42func onuSnToString(sn *openolt.SerialNumber) string {
43 s := string(sn.VendorId)
44 for _, i := range sn.VendorSpecific {
45 s = s + strconv.FormatInt(int64(i/16), 16) + strconv.FormatInt(int64(i%16), 16)
46 }
47 return s
48}