blob: 6af433f1de9df7e9ce79d1e0ca9f3f0b7bfc3b72 [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
Zdravko Bozakov3d762142019-07-15 16:57:17 +020026 extraMibUploadCtr uint16 // this is only for debug purposes, will be removed in the future
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020027 uniGInstance uint8
28 tcontInstance uint8
29 pptpInstance uint8
Zdravko Bozakov3d762142019-07-15 16:57:17 +020030 priorQInstance uint8 // To assign incrementing value to PQ instance-Id
31 priorQPriority uint8 // Priority of the PriorityQueueG (0-7)
32 tcontPointer uint8 // Tcont Pointer for PriorQ
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020033 state istate
Shad Ansari1106b022019-01-16 22:22:35 -080034}
35
36type istate int
37
38// TODO - Needs to reflect real ONU/OMCI state
39const (
40 INCOMPLETE istate = iota
41 DONE
42)
43
44var OnuOmciStateMap = map[OnuKey]*OnuOmciState{}
45
46func NewOnuOmciState() *OnuOmciState {
47 return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, tcontInstance: 0, pptpInstance: 1}
48}
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020049func (s *OnuOmciState) ResetOnuOmciState() {
Zdravko Bozakov3d762142019-07-15 16:57:17 +020050 // Resetting the counters
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080051 s.mibUploadCtr = 0
52 s.extraMibUploadCtr = 0
53 s.gemPortId = 0
54 s.uniGInstance = 1
55 s.tcontInstance = 0
56 s.pptpInstance = 1
Zdravko Bozakov3d762142019-07-15 16:57:17 +020057 s.tcontPointer = 0
58 s.priorQPriority = 0
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080059}
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090060func GetOnuOmciState(intfId uint32, onuId uint32) istate {
Shad Ansari3259e6d2019-01-17 15:51:19 -080061 key := OnuKey{intfId, onuId}
62 if onu, ok := OnuOmciStateMap[key]; ok {
63 return onu.state
64 } else {
65 return INCOMPLETE
66 }
Shad Ansari1106b022019-01-16 22:22:35 -080067}
68
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090069func GetGemPortId(intfId uint32, onuId uint32) (uint16, error) {
Shad Ansari1106b022019-01-16 22:22:35 -080070 key := OnuKey{intfId, onuId}
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090071 if OnuOmciState, ok := OnuOmciStateMap[key]; ok {
Keita NISHIMOTO5a19cfd2019-03-07 08:23:28 +090072 if OnuOmciState.state != DONE {
73 errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Not DONE (GemportID is not set)", intfId, onuId)
74 return 0, errors.New(errmsg)
75 }
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090076 return OnuOmciState.gemPortId, nil
77 }
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080078 errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Failed to find a key in OnuOmciStateMap", intfId, onuId)
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090079 return 0, errors.New(errmsg)
Shad Ansari1106b022019-01-16 22:22:35 -080080}