Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2020-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 | |
| 17 | //Package adaptercoreonu provides the utility for onu devices, flows and statistics |
| 18 | package adaptercoreonu |
| 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "errors" |
| 23 | |
| 24 | "github.com/opencord/omci-lib-go" |
| 25 | me "github.com/opencord/omci-lib-go/generated" |
| 26 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 27 | ) |
| 28 | |
| 29 | //OnuDeviceDB structure holds information about known ME's |
| 30 | type OnuDeviceDB struct { |
| 31 | ctx context.Context |
| 32 | pOnuDeviceEntry *OnuDeviceEntry |
| 33 | unigMeCount uint16 |
| 34 | unigMe []*me.ManagedEntity |
| 35 | pptpEthUniMeCount uint16 |
| 36 | pptpEthUniMe []*me.ManagedEntity |
| 37 | AnigMe *me.ManagedEntity |
| 38 | VeipMe *me.ManagedEntity |
| 39 | } |
| 40 | |
| 41 | //OnuDeviceDB returns a new instance for a specific ONU_Device_Entry |
| 42 | func NewOnuDeviceDB(ctx context.Context, a_pOnuDeviceEntry *OnuDeviceEntry) *OnuDeviceDB { |
| 43 | logger.Debugw("Init OnuDeviceDB for:", log.Fields{"deviceId": a_pOnuDeviceEntry.deviceID}) |
| 44 | var onuDeviceDB OnuDeviceDB |
| 45 | onuDeviceDB.ctx = ctx |
| 46 | onuDeviceDB.pOnuDeviceEntry = a_pOnuDeviceEntry |
| 47 | onuDeviceDB.unigMeCount = 0 |
| 48 | onuDeviceDB.unigMe = make([]*me.ManagedEntity, 4, MaxUnisPerOnu) |
| 49 | onuDeviceDB.pptpEthUniMeCount = 0 |
| 50 | onuDeviceDB.pptpEthUniMe = make([]*me.ManagedEntity, 4, MaxUnisPerOnu) |
| 51 | onuDeviceDB.AnigMe = nil |
| 52 | onuDeviceDB.VeipMe = nil |
| 53 | return &onuDeviceDB |
| 54 | } |
| 55 | |
| 56 | func (onuDeviceDB *OnuDeviceDB) UnigAdd(meParamData me.ParamData) error { |
| 57 | var omciErr me.OmciErrors |
| 58 | onuDeviceDB.unigMe[onuDeviceDB.unigMeCount], omciErr = me.NewUniG(meParamData) |
| 59 | if omciErr.StatusCode() != me.Success { |
| 60 | logger.Errorw("UniG could not be parsed for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID}) |
| 61 | return errors.New("UniG could not be parsed") |
| 62 | } |
| 63 | logger.Debugw("UniG instance stored for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID, |
| 64 | "UnigMe ": onuDeviceDB.unigMe[onuDeviceDB.unigMeCount], "unigMeCount": onuDeviceDB.unigMeCount}) |
| 65 | if onuDeviceDB.unigMeCount < MaxUnisPerOnu { |
| 66 | onuDeviceDB.unigMeCount++ |
| 67 | } else { |
| 68 | logger.Errorw("Max number of UniGs exceeded for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID}) |
| 69 | return errors.New("Max number of UniGs exceeded") |
| 70 | } |
| 71 | return nil |
| 72 | } |
| 73 | |
| 74 | func (onuDeviceDB *OnuDeviceDB) PptpEthUniAdd(meParamData me.ParamData) error { |
| 75 | var omciErr me.OmciErrors |
| 76 | onuDeviceDB.pptpEthUniMe[onuDeviceDB.pptpEthUniMeCount], omciErr = me.NewPhysicalPathTerminationPointEthernetUni(meParamData) |
| 77 | if omciErr.StatusCode() != me.Success { |
| 78 | logger.Errorw("pptpEthUni could not be parsed for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID}) |
| 79 | return errors.New("pptpEthUni could not be parsed") |
| 80 | } |
| 81 | logger.Debugw("pptpEthUni instance stored for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID, |
| 82 | "pptpEthUniMe ": onuDeviceDB.pptpEthUniMe[onuDeviceDB.pptpEthUniMeCount], "pptpEthUniMeCount": onuDeviceDB.pptpEthUniMeCount}) |
| 83 | if onuDeviceDB.pptpEthUniMeCount < MaxUnisPerOnu { |
| 84 | onuDeviceDB.pptpEthUniMeCount++ |
| 85 | } else { |
| 86 | logger.Errorw("Max number of pptpEthUnis exceeded for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID}) |
| 87 | return errors.New("Max number of pptpEthUnis exceeded") |
| 88 | } |
| 89 | return nil |
| 90 | } |
| 91 | |
| 92 | func (onuDeviceDB *OnuDeviceDB) AnigAdd(meParamData me.ParamData) error { |
| 93 | var omciErr me.OmciErrors |
| 94 | onuDeviceDB.AnigMe, omciErr = me.NewAniG(meParamData) |
| 95 | if omciErr.StatusCode() != me.Success { |
| 96 | logger.Errorw("AniG could not be parsed for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID}) |
| 97 | return errors.New("AniG could not be parsed") |
| 98 | } |
| 99 | logger.Debugw("AniG instance stored for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID, "AnigMe ": onuDeviceDB.AnigMe}) |
| 100 | return nil |
| 101 | } |
| 102 | |
| 103 | func (onuDeviceDB *OnuDeviceDB) VeipAdd(meParamData me.ParamData) error { |
| 104 | var omciErr me.OmciErrors |
| 105 | onuDeviceDB.VeipMe, omciErr = me.NewVirtualEthernetInterfacePoint(meParamData) |
| 106 | if omciErr.StatusCode() != me.Success { |
| 107 | logger.Errorw("VEIP could not be parsed for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID}) |
| 108 | return errors.New("VEIP could not be parsed") |
| 109 | } |
| 110 | logger.Debugw("VEIP instance stored for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID, "VeipMe ": onuDeviceDB.VeipMe}) |
| 111 | return nil |
| 112 | } |
| 113 | |
| 114 | func (onuDeviceDB *OnuDeviceDB) StoreMe(a_pMibUpResp *omci.MibUploadNextResponse) error { |
| 115 | |
| 116 | meParamData := me.ParamData{ |
| 117 | EntityID: a_pMibUpResp.ReportedME.GetEntityID(), |
| 118 | Attributes: a_pMibUpResp.ReportedME.GetAttributeValueMap(), |
| 119 | } |
| 120 | |
| 121 | switch a_pMibUpResp.ReportedME.GetClassID() { |
| 122 | case me.UniGClassID: |
| 123 | onuDeviceDB.UnigAdd(meParamData) |
| 124 | case me.PhysicalPathTerminationPointEthernetUniClassID: |
| 125 | onuDeviceDB.PptpEthUniAdd(meParamData) |
| 126 | case me.AniGClassID: |
| 127 | onuDeviceDB.AnigAdd(meParamData) |
| 128 | case me.VirtualEthernetInterfacePointClassID: |
| 129 | onuDeviceDB.VeipAdd(meParamData) |
| 130 | default: |
| 131 | //ME won't be stored currently |
| 132 | } |
| 133 | return nil |
| 134 | } |