blob: 8378073bf24bb930d39555b7a138c24b1e2c52cf [file] [log] [blame]
kesavandfdf77632021-01-26 23:40:33 -05001/*
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
18package adaptercoreonu
19
20import (
21 "context"
22 "github.com/opencord/omci-lib-go"
23 me "github.com/opencord/omci-lib-go/generated"
24 "github.com/opencord/voltha-lib-go/v4/pkg/log"
25 "github.com/opencord/voltha-protos/v4/go/extension"
26 "time"
27)
28
29const (
30 uniStatusTimeout = 3
31 adminState = "AdministrativeState"
32 operationalState = "OperationalState"
33 configInd = "ConfigurationInd"
34)
35
36//UniPortStatus implements methods to get uni port status info
37type UniPortStatus struct {
38 omciRespChn chan Message
39 pOmiCC *omciCC
40 pLastTxMeInstance *me.ManagedEntity
41}
42
43//NewUniPortStatus creates a new instance of UniPortStatus
44func NewUniPortStatus(pOmicc *omciCC) *UniPortStatus {
45 return &UniPortStatus{
46 omciRespChn: make(chan Message),
47 pOmiCC: pOmicc,
48 }
49
50}
51
52func (portStatus *UniPortStatus) getUniPortStatus(ctx context.Context, uniIdx uint32) *extension.SingleGetValueResponse {
53 for _, uniPort := range portStatus.pOmiCC.pBaseDeviceHandler.uniEntityMap {
54
55 if uniPort.uniID == uint8(uniIdx) && uniPort.portType == uniPPTP {
56
57 requestedAttributes := me.AttributeValueMap{adminState: 0, operationalState: 0, configInd: 0}
Girish Gowdra0b235842021-03-09 13:06:46 -080058 // Note: No reference to fetch the OMCI timeout configuration value, so hard code it to 10s
59 if meInstance := portStatus.pOmiCC.sendGetMe(ctx, me.PhysicalPathTerminationPointEthernetUniClassID, uniPort.entityID, requestedAttributes, 10, true, portStatus.omciRespChn); meInstance != nil {
kesavandfdf77632021-01-26 23:40:33 -050060 portStatus.pLastTxMeInstance = meInstance
61
62 //verify response
63 return portStatus.waitforgetUniPortStatus(ctx, meInstance)
64 }
65 }
66 }
67 logger.Errorw(ctx, "getUniPortStatus uniIdx is not valid", log.Fields{"uniIdx": uniIdx})
68 return postUniStatusErrResponse(extension.GetValueResponse_INVALID_PORT_TYPE)
69}
70
71func (portStatus *UniPortStatus) waitforgetUniPortStatus(ctx context.Context, apMeInstance *me.ManagedEntity) *extension.SingleGetValueResponse {
72
73 select {
74 // maybe be also some outside cancel (but no context modeled for the moment ...)
75 case <-ctx.Done():
76 logger.Errorf(ctx, "waitforgetUniPortStatus Context done")
77 return postUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR)
78 case <-time.After(uniStatusTimeout * time.Second):
79 logger.Errorf(ctx, "waitforgetUniPortStatus timeout")
80 return postUniStatusErrResponse(extension.GetValueResponse_TIMEOUT)
81
82 case omciMsg := <-portStatus.omciRespChn:
83 if omciMsg.Type != OMCI {
84 return postUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR)
85 }
86 msg, _ := omciMsg.Data.(OmciMessage)
87 return portStatus.processGetUnitStatusResp(ctx, msg)
88 }
89
90}
91
92func (portStatus *UniPortStatus) processGetUnitStatusResp(ctx context.Context, msg OmciMessage) *extension.SingleGetValueResponse {
93 logger.Debugw(ctx, "processGetUniStatusResp:", log.Fields{"msg.Omci.MessageType": msg.OmciMsg.MessageType,
94 "msg.OmciMsg.TransactionID": msg.OmciMsg.TransactionID, "DeviceIdentfier": msg.OmciMsg.DeviceIdentifier})
95
96 if msg.OmciMsg.MessageType != omci.GetResponseType {
97 logger.Debugw(ctx, "processGetUniStatusResp error", log.Fields{"incorrect RespType": msg.OmciMsg.MessageType,
98 "expected": omci.GetResponseType})
99 return postUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR)
100 }
101
102 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
103 if msgLayer == nil {
104 logger.Errorf(ctx, "processGetUniStatusResp omci Msg layer not found - ")
105 return postUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR)
106
107 }
108 msgObj, msgOk := msgLayer.(*omci.GetResponse)
109 if !msgOk {
110 logger.Errorf(ctx, "processGetUniStatusResp omci msgObj layer could not be found ")
111 return postUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR)
112
113 }
114
115 if msgObj.Result != me.Success {
116 return postUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR)
117 }
118 meAttributes := msgObj.Attributes
119
120 singleValResp := extension.SingleGetValueResponse{
121 Response: &extension.GetValueResponse{
122 Status: extension.GetValueResponse_OK,
123 Response: &extension.GetValueResponse_UniInfo{
124 UniInfo: &extension.GetOnuUniInfoResponse{},
125 },
126 },
127 }
128 if meAttributes[operationalState].(uint8) == 0 {
129 singleValResp.Response.GetUniInfo().OperState = extension.GetOnuUniInfoResponse_ENABLED
130 } else if meAttributes[operationalState].(uint8) == 1 {
131 singleValResp.Response.GetUniInfo().OperState = extension.GetOnuUniInfoResponse_DISABLED
132 } else {
133 singleValResp.Response.GetUniInfo().OperState = extension.GetOnuUniInfoResponse_OPERSTATE_UNDEFINED
134 }
135
136 if meAttributes[adminState].(uint8) == 0 {
137 singleValResp.Response.GetUniInfo().AdmState = extension.GetOnuUniInfoResponse_UNLOCKED
138 } else if meAttributes[adminState].(uint8) == 1 {
139 singleValResp.Response.GetUniInfo().AdmState = extension.GetOnuUniInfoResponse_LOCKED
140 } else {
141 singleValResp.Response.GetUniInfo().AdmState = extension.GetOnuUniInfoResponse_ADMSTATE_UNDEFINED
142 }
143 configIndMap := map[uint8]extension.GetOnuUniInfoResponse_ConfigurationInd{
144 0: 0,
145 1: extension.GetOnuUniInfoResponse_TEN_BASE_T_FDX,
146 2: extension.GetOnuUniInfoResponse_HUNDRED_BASE_T_FDX,
147 3: extension.GetOnuUniInfoResponse_GIGABIT_ETHERNET_FDX,
148 4: extension.GetOnuUniInfoResponse_TEN_G_ETHERNET_FDX,
149 17: extension.GetOnuUniInfoResponse_TEN_BASE_T_HDX,
150 18: extension.GetOnuUniInfoResponse_HUNDRED_BASE_T_HDX,
151 19: extension.GetOnuUniInfoResponse_GIGABIT_ETHERNET_HDX,
152 }
153 configInd := meAttributes[configInd].(uint8)
154 singleValResp.Response.GetUniInfo().ConfigInd = configIndMap[configInd]
155 return &singleValResp
156}
157
158func postUniStatusErrResponse(reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse {
159 return &extension.SingleGetValueResponse{
160 Response: &extension.GetValueResponse{
161 Status: extension.GetValueResponse_ERROR,
162 ErrReason: reason,
163 },
164 }
165}