blob: be2da361460780ff7b754475ce5914f31616aba4 [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
26 uniGInstance uint8
27 tcontInstance uint8
28 pptpInstance uint8
29 state istate
30}
31
32type istate int
33
34// TODO - Needs to reflect real ONU/OMCI state
35const (
36 INCOMPLETE istate = iota
37 DONE
38)
39
40var OnuOmciStateMap = map[OnuKey]*OnuOmciState{}
41
42func NewOnuOmciState() *OnuOmciState {
43 return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, tcontInstance: 0, pptpInstance: 1}
44}
45
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090046func GetOnuOmciState(intfId uint32, onuId uint32) istate {
Shad Ansari3259e6d2019-01-17 15:51:19 -080047 key := OnuKey{intfId, onuId}
48 if onu, ok := OnuOmciStateMap[key]; ok {
49 return onu.state
50 } else {
51 return INCOMPLETE
52 }
Shad Ansari1106b022019-01-16 22:22:35 -080053}
54
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090055func GetGemPortId(intfId uint32, onuId uint32) (uint16, error) {
Shad Ansari1106b022019-01-16 22:22:35 -080056 key := OnuKey{intfId, onuId}
Keita NISHIMOTO73bb3492019-01-29 07:11:27 +090057 if OnuOmciState, ok := OnuOmciStateMap[key]; ok {
58 return OnuOmciState.gemPortId, nil
59 }
60 errmsg := fmt.Sprintf("Failed to find a key in OnuOmciStateMap key{intfid:%d, onuid:%d}", intfId, onuId)
61 return 0, errors.New(errmsg)
Shad Ansari1106b022019-01-16 22:22:35 -080062}