Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -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 | package core |
| 17 | |
| 18 | import ( |
| 19 | "errors" |
| 20 | "fmt" |
| 21 | "sync" |
| 22 | log "github.com/sirupsen/logrus" |
| 23 | ) |
| 24 | |
| 25 | type OnuOmciState struct { |
| 26 | gemPortId uint16 |
| 27 | mibUploadCtr uint16 |
| 28 | extraMibUploadCtr uint16 // this is only for debug purposes, will be removed in the future |
| 29 | uniGInstance uint8 |
| 30 | tcontInstance uint8 |
| 31 | pptpInstance uint8 |
| 32 | 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 |
| 35 | state istate |
| 36 | } |
| 37 | |
| 38 | type istate int |
| 39 | |
| 40 | // TODO - Needs to reflect real ONU/OMCI state |
| 41 | const ( |
| 42 | INCOMPLETE istate = iota |
| 43 | DONE |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 44 | LOCKED |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 45 | ) |
| 46 | |
| 47 | var OnuOmciStateMap = map[OnuKey]*OnuOmciState{} |
| 48 | var OnuOmciStateMapLock = sync.RWMutex{} |
| 49 | |
| 50 | func NewOnuOmciState() *OnuOmciState { |
| 51 | return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, tcontInstance: 0, pptpInstance: 1} |
| 52 | } |
| 53 | func (s *OnuOmciState) ResetOnuOmciState() { |
| 54 | // Resetting the counters |
| 55 | s.mibUploadCtr = 0 |
| 56 | s.extraMibUploadCtr = 0 |
| 57 | s.gemPortId = 0 |
| 58 | s.uniGInstance = 1 |
| 59 | s.tcontInstance = 0 |
| 60 | s.pptpInstance = 1 |
| 61 | s.tcontPointer = 0 |
| 62 | s.priorQPriority = 0 |
| 63 | } |
| 64 | func GetOnuOmciState(intfId uint32, onuId uint32) istate { |
| 65 | key := OnuKey{intfId, onuId} |
| 66 | OnuOmciStateMapLock.RLock() |
| 67 | defer OnuOmciStateMapLock.RUnlock() |
| 68 | if onu, ok := OnuOmciStateMap[key]; ok { |
| 69 | return onu.state |
| 70 | } else { |
| 71 | return INCOMPLETE |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | func GetGemPortId(intfId uint32, onuId uint32) (uint16, error) { |
| 76 | key := OnuKey{intfId, onuId} |
| 77 | OnuOmciStateMapLock.RLock() |
| 78 | defer OnuOmciStateMapLock.RUnlock() |
| 79 | if OnuOmciState, ok := OnuOmciStateMap[key]; ok { |
| 80 | 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 | } |
| 84 | return OnuOmciState.gemPortId, nil |
| 85 | } |
| 86 | errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Failed to find a key in OnuOmciStateMap", intfId, onuId) |
| 87 | return 0, errors.New(errmsg) |
| 88 | } |
| 89 | |
| 90 | func CheckIsTeo() string { |
| 91 | log.Warn("It's TEO!") |
| 92 | return "It's TEO!" |
| 93 | } |