Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 1 | /* |
| 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 Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 17 | package devices |
| 18 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 19 | import ( |
| 20 | "github.com/looplab/fsm" |
Matteo Scandolo | 3de9de0 | 2019-11-14 13:40:03 -0800 | [diff] [blame] | 21 | "github.com/opencord/voltha-protos/v2/go/openolt" |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 22 | "strconv" |
| 23 | ) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 24 | |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame^] | 25 | type mode int |
| 26 | |
| 27 | // Constants for Controlled Activation modes |
| 28 | const ( |
| 29 | Default mode = iota |
| 30 | OnlyONU |
| 31 | OnlyPON |
| 32 | Both |
| 33 | ) |
| 34 | |
| 35 | // ControlledActivationModes maps string to int value of mode |
| 36 | var ControlledActivationModes = map[string]mode{ |
| 37 | "default": Default, |
| 38 | "only-onu": OnlyONU, |
| 39 | "only-pon": OnlyPON, |
| 40 | "both": Both, |
| 41 | } |
| 42 | |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 43 | var newFSM = fsm.NewFSM |
| 44 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 45 | func getOperStateFSM(cb fsm.Callback) *fsm.FSM { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 46 | return newFSM( |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 47 | "down", |
| 48 | fsm.Events{ |
| 49 | {Name: "enable", Src: []string{"down"}, Dst: "up"}, |
| 50 | {Name: "disable", Src: []string{"up"}, Dst: "down"}, |
| 51 | }, |
| 52 | fsm.Callbacks{ |
| 53 | "enter_state": func(e *fsm.Event) { |
| 54 | cb(e) |
| 55 | }, |
| 56 | }, |
| 57 | ) |
| 58 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 59 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 60 | // deprecated |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 61 | func onuSnToString(sn *openolt.SerialNumber) string { |
| 62 | s := string(sn.VendorId) |
| 63 | for _, i := range sn.VendorSpecific { |
| 64 | s = s + strconv.FormatInt(int64(i/16), 16) + strconv.FormatInt(int64(i%16), 16) |
| 65 | } |
| 66 | return s |
| 67 | } |