blob: 4050b2227bccce9b75b0458011ba18fd8bb2bbf5 [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 {
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020024 gemPortId uint16
25 mibUploadCtr uint16
26 extraMibUploadCtr uint16 //this is only for debug purposes, will be removed in the future
27 uniGInstance uint8
28 tcontInstance uint8
29 pptpInstance uint8
30 priorQInstance uint8 //To assign incrementing value to PQ instance-Id
31 state istate
Shad Ansari1106b022019-01-16 22:22:35 -080032}
33
34type istate int
35
36// TODO - Needs to reflect real ONU/OMCI state
37const (
38 INCOMPLETE istate = iota
39 DONE
40)
41
42var OnuOmciStateMap = map[OnuKey]*OnuOmciState{}
43
44func NewOnuOmciState() *OnuOmciState {
45 return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, tcontInstance: 0, pptpInstance: 1}
46}
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020047func (s *OnuOmciState) ResetOnuOmciState() {
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080048 s.mibUploadCtr = 0
49 s.extraMibUploadCtr = 0
50 s.gemPortId = 0
51 s.uniGInstance = 1
52 s.tcontInstance = 0
53 s.pptpInstance = 1
54}
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090055func GetOnuOmciState(intfId uint32, onuId uint32) istate {
Shad Ansari3259e6d2019-01-17 15:51:19 -080056 key := OnuKey{intfId, onuId}
57 if onu, ok := OnuOmciStateMap[key]; ok {
58 return onu.state
59 } else {
60 return INCOMPLETE
61 }
Shad Ansari1106b022019-01-16 22:22:35 -080062}
63
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090064func GetGemPortId(intfId uint32, onuId uint32) (uint16, error) {
Shad Ansari1106b022019-01-16 22:22:35 -080065 key := OnuKey{intfId, onuId}
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090066 if OnuOmciState, ok := OnuOmciStateMap[key]; ok {
Keita NISHIMOTO5a19cfd2019-03-07 08:23:28 +090067 if OnuOmciState.state != DONE {
68 errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Not DONE (GemportID is not set)", intfId, onuId)
69 return 0, errors.New(errmsg)
70 }
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090071 return OnuOmciState.gemPortId, nil
72 }
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080073 errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Failed to find a key in OnuOmciStateMap", intfId, onuId)
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090074 return 0, errors.New(errmsg)
Shad Ansari1106b022019-01-16 22:22:35 -080075}