Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package core |
| 17 | |
Keita NISHIMOTO | 73bb349 | 2019-01-29 07:11:27 +0900 | [diff] [blame] | 18 | import ( |
| 19 | "errors" |
| 20 | "fmt" |
| 21 | ) |
| 22 | |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 23 | type OnuOmciState struct { |
| 24 | gemPortId uint16 |
| 25 | mibUploadCtr uint16 |
Mahir Gunyel | ed7b07b | 2019-02-11 12:06:02 -0800 | [diff] [blame] | 26 | extraMibUploadCtr uint16 //this is only for debug purposes, will be removed in the future |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 27 | uniGInstance uint8 |
| 28 | tcontInstance uint8 |
| 29 | pptpInstance uint8 |
| 30 | state istate |
| 31 | } |
| 32 | |
| 33 | type istate int |
| 34 | |
| 35 | // TODO - Needs to reflect real ONU/OMCI state |
| 36 | const ( |
| 37 | INCOMPLETE istate = iota |
| 38 | DONE |
| 39 | ) |
| 40 | |
| 41 | var OnuOmciStateMap = map[OnuKey]*OnuOmciState{} |
| 42 | |
| 43 | func NewOnuOmciState() *OnuOmciState { |
| 44 | return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, tcontInstance: 0, pptpInstance: 1} |
| 45 | } |
Mahir Gunyel | ed7b07b | 2019-02-11 12:06:02 -0800 | [diff] [blame] | 46 | func (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 NISHIMOTO | 73bb349 | 2019-01-29 07:11:27 +0900 | [diff] [blame] | 54 | func GetOnuOmciState(intfId uint32, onuId uint32) istate { |
Shad Ansari | 3259e6d | 2019-01-17 15:51:19 -0800 | [diff] [blame] | 55 | key := OnuKey{intfId, onuId} |
| 56 | if onu, ok := OnuOmciStateMap[key]; ok { |
| 57 | return onu.state |
| 58 | } else { |
| 59 | return INCOMPLETE |
| 60 | } |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 61 | } |
| 62 | |
Keita NISHIMOTO | 73bb349 | 2019-01-29 07:11:27 +0900 | [diff] [blame] | 63 | func GetGemPortId(intfId uint32, onuId uint32) (uint16, error) { |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 64 | key := OnuKey{intfId, onuId} |
Keita NISHIMOTO | 73bb349 | 2019-01-29 07:11:27 +0900 | [diff] [blame] | 65 | if OnuOmciState, ok := OnuOmciStateMap[key]; ok { |
Keita NISHIMOTO | 5a19cfd | 2019-03-07 08:23:28 +0900 | [diff] [blame^] | 66 | if OnuOmciState.state != DONE { |
| 67 | errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Not DONE (GemportID is not set)", intfId, onuId) |
| 68 | return 0, errors.New(errmsg) |
| 69 | } |
Keita NISHIMOTO | 73bb349 | 2019-01-29 07:11:27 +0900 | [diff] [blame] | 70 | return OnuOmciState.gemPortId, nil |
| 71 | } |
Mahir Gunyel | ed7b07b | 2019-02-11 12:06:02 -0800 | [diff] [blame] | 72 | errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Failed to find a key in OnuOmciStateMap", intfId, onuId) |
Keita NISHIMOTO | 73bb349 | 2019-01-29 07:11:27 +0900 | [diff] [blame] | 73 | return 0, errors.New(errmsg) |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 74 | } |