blob: a88820704d2c421159c0b7cb2587f0a10554c8a0 [file] [log] [blame]
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001/*
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 "errors"
23 "strconv"
24
25 //"sync"
26 //"time"
27
28 //"github.com/opencord/voltha-lib-go/v3/pkg/kafka"
29 "github.com/opencord/voltha-lib-go/v3/pkg/log"
30 vc "github.com/opencord/voltha-protos/v3/go/common"
31 "github.com/opencord/voltha-protos/v3/go/voltha"
32 //ic "github.com/opencord/voltha-protos/v3/go/inter_container"
33 //"github.com/opencord/voltha-protos/v3/go/openflow_13"
34 //"github.com/opencord/voltha-protos/v3/go/voltha"
35)
36
37type UniPortType uint8
38
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000039// UniPPTP Interface type - re-use values from G.988 TP type definition (directly used in OMCI!)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000040const (
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000041 // UniPPTP relates to PPTP
42 UniPPTP UniPortType = 1 // relates to PPTP
43 // UniPPTP relates to VEIP
44 UniVEIP UniPortType = 11 // relates to VEIP
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000045)
46
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000047//OnuUniPort structure holds information about the ONU attached Uni Ports
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000048type OnuUniPort struct {
49 enabled bool
50 name string
51 portNo uint32
52 portType UniPortType
53 ofpPortNo string
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000054 uniId uint8
55 macBpNo uint8
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000056 entityId uint16
57 adminState vc.AdminState_Types
58 operState vc.OperStatus_Types
59 pPort *voltha.Port
60}
61
62//NewOnuUniPort returns a new instance of a OnuUniPort
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000063func NewOnuUniPort(a_uniId uint8, a_portNo uint32, a_InstNo uint16,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000064 a_portType UniPortType) *OnuUniPort {
65 logger.Infow("init-onuUniPort", log.Fields{"uniId": a_uniId,
66 "portNo": a_portNo, "InstNo": a_InstNo, "type": a_portType})
67 var onuUniPort OnuUniPort
68 onuUniPort.enabled = false
69 onuUniPort.name = "uni-" + strconv.FormatUint(uint64(a_portNo), 10)
70 onuUniPort.portNo = a_portNo
71 onuUniPort.portType = a_portType
72 // so far it seems as here ofpPortNo/Name ist the same as the original port name ...??
73 onuUniPort.ofpPortNo = onuUniPort.name
74 onuUniPort.uniId = a_uniId
75 onuUniPort.macBpNo = a_uniId + 1 //ensure >0 instanceNo
76 onuUniPort.entityId = a_InstNo
77 onuUniPort.adminState = vc.AdminState_ENABLED //enabled per create
78 onuUniPort.operState = vc.OperStatus_UNKNOWN
79 onuUniPort.pPort = nil // to be set on create
80 return &onuUniPort
81}
82
Holger Hildebrandt24d51952020-05-04 14:03:42 +000083//creates the Voltha port based on ONU UNI Port
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000084func (oo *OnuUniPort) CreateVolthaPort(a_pDeviceHandler *DeviceHandler) error {
85 logger.Debug("adding-uni-port")
86 pUniPort := &voltha.Port{
87 PortNo: oo.portNo,
88 Label: oo.name,
89 Type: voltha.Port_ETHERNET_UNI,
90 AdminState: oo.adminState,
91 OperStatus: oo.operState,
92 // obviously empty peer setting
93 }
94 if pUniPort != nil {
95 if err := a_pDeviceHandler.coreProxy.PortCreated(context.TODO(),
96 a_pDeviceHandler.deviceID, pUniPort); err != nil {
97 logger.Fatalf("adding-uni-port: create-VOLTHA-Port-failed-%s", err)
98 return err
99 }
100 logger.Infow("Voltha onuUniPort-added", log.Fields{"for PortNo": oo.portNo})
101 oo.pPort = pUniPort
102 oo.operState = vc.OperStatus_DISCOVERED
103 } else {
104 logger.Warnw("could not create Voltha UniPort - nil pointer",
105 log.Fields{"for PortNo": oo.portNo})
106 return errors.New("create Voltha UniPort failed")
107 }
108 return nil
109}
Holger Hildebrandt24d51952020-05-04 14:03:42 +0000110
111//mofify OperState of the the UniPort
112func (oo *OnuUniPort) SetOperState(a_NewOperState vc.OperStatus_Types) {
113 oo.operState = a_NewOperState
114}