blob: 09b300e3e21542ec0e1cadb615d5f402b6e40df3 [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"
21)
22
Shad Ansari1106b022019-01-16 22:22:35 -080023type OnuOmciState struct {
24 gemPortId uint16
25 mibUploadCtr uint16
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080026 extraMibUploadCtr uint16 //this is only for debug purposes, will be removed in the future
Shad Ansari1106b022019-01-16 22:22:35 -080027 uniGInstance uint8
28 tcontInstance uint8
29 pptpInstance uint8
30 state istate
31}
32
33type istate int
34
35// TODO - Needs to reflect real ONU/OMCI state
36const (
37 INCOMPLETE istate = iota
38 DONE
39)
40
41var OnuOmciStateMap = map[OnuKey]*OnuOmciState{}
42
43func NewOnuOmciState() *OnuOmciState {
44 return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, tcontInstance: 0, pptpInstance: 1}
45}
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080046func (s *OnuOmciState) ResetOnuOmciState(){
47 s.mibUploadCtr = 0
48 s.extraMibUploadCtr = 0
49 s.gemPortId = 0
50 s.uniGInstance = 1
51 s.tcontInstance = 0
52 s.pptpInstance = 1
53}
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090054func GetOnuOmciState(intfId uint32, onuId uint32) istate {
Shad Ansari3259e6d2019-01-17 15:51:19 -080055 key := OnuKey{intfId, onuId}
56 if onu, ok := OnuOmciStateMap[key]; ok {
57 return onu.state
58 } else {
59 return INCOMPLETE
60 }
Shad Ansari1106b022019-01-16 22:22:35 -080061}
62
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090063func GetGemPortId(intfId uint32, onuId uint32) (uint16, error) {
Shad Ansari1106b022019-01-16 22:22:35 -080064 key := OnuKey{intfId, onuId}
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090065 if OnuOmciState, ok := OnuOmciStateMap[key]; ok {
66 return OnuOmciState.gemPortId, nil
67 }
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080068 errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Failed to find a key in OnuOmciStateMap", intfId, onuId)
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090069 return 0, errors.New(errmsg)
Shad Ansari1106b022019-01-16 22:22:35 -080070}