blob: f27510f0ecc507adaf7d543cbf6b1fd9c3bf8fd1 [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"
23 "github.com/looplab/fsm"
24 "github.com/opencord/voltha-protos/go/openolt"
25)
26
27type PonPort struct {
28 // BBSIM Internals
29 ID uint32
30 NumOnu int
Matteo Scandolo27428702019-10-11 16:21:16 -070031 Onus []*Onu
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070032 Olt OltDevice
33
34 // PON Attributes
35 OperState *fsm.FSM
36 Type string
37
38 // NOTE do we need a state machine for the PON Ports?
39}
40
Matteo Scandolo40e067f2019-10-16 16:59:41 -070041func (p PonPort) GetOnuBySn(sn *openolt.SerialNumber) (*Onu, error) {
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070042 for _, onu := range p.Onus {
43 if bytes.Equal(onu.SerialNumber.VendorSpecific, sn.VendorSpecific) {
Matteo Scandolo27428702019-10-11 16:21:16 -070044 return onu, nil
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070045 }
46 }
47 return nil, errors.New(fmt.Sprintf("Cannot find Onu with serial number %d in PonPort %d", sn, p.ID))
48}
49
Matteo Scandolo40e067f2019-10-16 16:59:41 -070050func (p PonPort) GetOnuById(id uint32) (*Onu, error) {
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070051 for _, onu := range p.Onus {
52 if onu.ID == id {
Matteo Scandolo27428702019-10-11 16:21:16 -070053 return onu, nil
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070054 }
55 }
56 return nil, errors.New(fmt.Sprintf("Cannot find Onu with id %d in PonPort %d", id, p.ID))
57}