blob: ddb992191abf6d827534635bd3d4d6c599d6979b [file] [log] [blame]
Shad Ansari1106b022019-01-16 22:22:35 -08001/*
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 */
16package core
17
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090018import (
19 "errors"
20 "fmt"
William Kurkian3687c572019-10-11 15:29:17 -040021 "sync"
Matteo Scandoloa0026812019-08-20 11:01:32 -070022 log "github.com/sirupsen/logrus"
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090023)
24
Shad Ansari1106b022019-01-16 22:22:35 -080025type OnuOmciState struct {
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020026 gemPortId uint16
27 mibUploadCtr uint16
Zdravko Bozakov3d762142019-07-15 16:57:17 +020028 extraMibUploadCtr uint16 // this is only for debug purposes, will be removed in the future
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020029 uniGInstance uint8
30 tcontInstance uint8
31 pptpInstance uint8
Zdravko Bozakov3d762142019-07-15 16:57:17 +020032 priorQInstance uint8 // To assign incrementing value to PQ instance-Id
33 priorQPriority uint8 // Priority of the PriorityQueueG (0-7)
34 tcontPointer uint8 // Tcont Pointer for PriorQ
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020035 state istate
Shad Ansari1106b022019-01-16 22:22:35 -080036}
37
38type istate int
39
40// TODO - Needs to reflect real ONU/OMCI state
41const (
42 INCOMPLETE istate = iota
43 DONE
Matt Jeanneret869aeab2020-01-27 20:11:21 -050044 LOCKED
Shad Ansari1106b022019-01-16 22:22:35 -080045)
46
47var OnuOmciStateMap = map[OnuKey]*OnuOmciState{}
William Kurkian3687c572019-10-11 15:29:17 -040048var OnuOmciStateMapLock = sync.RWMutex{}
Shad Ansari1106b022019-01-16 22:22:35 -080049
50func NewOnuOmciState() *OnuOmciState {
51 return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, tcontInstance: 0, pptpInstance: 1}
52}
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020053func (s *OnuOmciState) ResetOnuOmciState() {
Zdravko Bozakov3d762142019-07-15 16:57:17 +020054 // Resetting the counters
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080055 s.mibUploadCtr = 0
56 s.extraMibUploadCtr = 0
57 s.gemPortId = 0
58 s.uniGInstance = 1
59 s.tcontInstance = 0
60 s.pptpInstance = 1
Zdravko Bozakov3d762142019-07-15 16:57:17 +020061 s.tcontPointer = 0
62 s.priorQPriority = 0
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080063}
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090064func GetOnuOmciState(intfId uint32, onuId uint32) istate {
Shad Ansari3259e6d2019-01-17 15:51:19 -080065 key := OnuKey{intfId, onuId}
William Kurkian3687c572019-10-11 15:29:17 -040066 OnuOmciStateMapLock.RLock()
67 defer OnuOmciStateMapLock.RUnlock()
Shad Ansari3259e6d2019-01-17 15:51:19 -080068 if onu, ok := OnuOmciStateMap[key]; ok {
69 return onu.state
70 } else {
71 return INCOMPLETE
72 }
Shad Ansari1106b022019-01-16 22:22:35 -080073}
74
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090075func GetGemPortId(intfId uint32, onuId uint32) (uint16, error) {
Shad Ansari1106b022019-01-16 22:22:35 -080076 key := OnuKey{intfId, onuId}
William Kurkian3687c572019-10-11 15:29:17 -040077 OnuOmciStateMapLock.RLock()
78 defer OnuOmciStateMapLock.RUnlock()
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090079 if OnuOmciState, ok := OnuOmciStateMap[key]; ok {
Keita NISHIMOTO5a19cfd2019-03-07 08:23:28 +090080 if OnuOmciState.state != DONE {
81 errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Not DONE (GemportID is not set)", intfId, onuId)
82 return 0, errors.New(errmsg)
83 }
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090084 return OnuOmciState.gemPortId, nil
85 }
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080086 errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Failed to find a key in OnuOmciStateMap", intfId, onuId)
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090087 return 0, errors.New(errmsg)
Shad Ansari1106b022019-01-16 22:22:35 -080088}
Matteo Scandoloa0026812019-08-20 11:01:32 -070089
90func CheckIsTeo() string {
91 log.Warn("It's TEO!")
92 return "It's TEO!"
93}