blob: d1b43322adc83d288415a02a174d90d35aba2fcf [file] [log] [blame]
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -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 */
16package core
17
18import (
19 "errors"
20 "fmt"
21 "sync"
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070022)
23
24type OnuOmciState struct {
25 gemPortId uint16
26 mibUploadCtr uint16
27 extraMibUploadCtr uint16 // this is only for debug purposes, will be removed in the future
28 uniGInstance uint8
29 tcontInstance uint8
30 pptpInstance uint8
31 priorQInstance uint8 // To assign incrementing value to PQ instance-Id
32 priorQPriority uint8 // Priority of the PriorityQueueG (0-7)
33 tcontPointer uint8 // Tcont Pointer for PriorQ
34 state istate
35}
36
37type istate int
38
39// TODO - Needs to reflect real ONU/OMCI state
40const (
41 INCOMPLETE istate = iota
42 DONE
Matteo Scandolo732c0752020-01-28 07:24:13 -080043 LOCKED
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070044)
45
46var OnuOmciStateMap = map[OnuKey]*OnuOmciState{}
47var OnuOmciStateMapLock = sync.RWMutex{}
48
49func NewOnuOmciState() *OnuOmciState {
50 return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, tcontInstance: 0, pptpInstance: 1}
51}
52func (s *OnuOmciState) ResetOnuOmciState() {
53 // Resetting the counters
54 s.mibUploadCtr = 0
55 s.extraMibUploadCtr = 0
56 s.gemPortId = 0
57 s.uniGInstance = 1
58 s.tcontInstance = 0
59 s.pptpInstance = 1
60 s.tcontPointer = 0
61 s.priorQPriority = 0
62}
Matteo Scandolo7b512202020-11-09 16:38:10 -080063func GetOnuOmciState(oltId int, intfId uint32, onuId uint32) istate {
64 key := OnuKey{oltId,intfId, onuId}
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070065 OnuOmciStateMapLock.RLock()
66 defer OnuOmciStateMapLock.RUnlock()
67 if onu, ok := OnuOmciStateMap[key]; ok {
68 return onu.state
69 } else {
70 return INCOMPLETE
71 }
72}
73
Matteo Scandolo7b512202020-11-09 16:38:10 -080074func GetGemPortId(oltId int, intfId uint32, onuId uint32) (uint16, error) {
75 key := OnuKey{oltId, intfId, onuId}
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070076 OnuOmciStateMapLock.RLock()
77 defer OnuOmciStateMapLock.RUnlock()
78 if OnuOmciState, ok := OnuOmciStateMap[key]; ok {
79 if OnuOmciState.state != DONE {
80 errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Not DONE (GemportID is not set)", intfId, onuId)
81 return 0, errors.New(errmsg)
82 }
83 return OnuOmciState.gemPortId, nil
84 }
85 errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Failed to find a key in OnuOmciStateMap", intfId, onuId)
86 return 0, errors.New(errmsg)
87}