blob: ac1bdb70657002be36bed59733bf8fe6877cf74c [file] [log] [blame]
Matteo Scandolo86e8ce62019-10-11 12:03:10 -07001/*
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
17package devices
18
19import (
20 "bytes"
21 "errors"
22 "fmt"
Zdravko Bozakov2da76342019-10-21 09:47:35 +020023
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070024 "github.com/looplab/fsm"
25 "github.com/opencord/voltha-protos/go/openolt"
26)
27
28type PonPort struct {
29 // BBSIM Internals
30 ID uint32
31 NumOnu int
Matteo Scandolo27428702019-10-11 16:21:16 -070032 Onus []*Onu
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070033 Olt OltDevice
34
35 // PON Attributes
36 OperState *fsm.FSM
37 Type string
38
39 // NOTE do we need a state machine for the PON Ports?
40}
41
Matteo Scandolo40e067f2019-10-16 16:59:41 -070042func (p PonPort) GetOnuBySn(sn *openolt.SerialNumber) (*Onu, error) {
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070043 for _, onu := range p.Onus {
44 if bytes.Equal(onu.SerialNumber.VendorSpecific, sn.VendorSpecific) {
Matteo Scandolo27428702019-10-11 16:21:16 -070045 return onu, nil
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070046 }
47 }
48 return nil, errors.New(fmt.Sprintf("Cannot find Onu with serial number %d in PonPort %d", sn, p.ID))
49}
50
Matteo Scandolo40e067f2019-10-16 16:59:41 -070051func (p PonPort) GetOnuById(id uint32) (*Onu, error) {
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070052 for _, onu := range p.Onus {
53 if onu.ID == id {
Matteo Scandolo27428702019-10-11 16:21:16 -070054 return onu, nil
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070055 }
56 }
57 return nil, errors.New(fmt.Sprintf("Cannot find Onu with id %d in PonPort %d", id, p.ID))
58}