blob: 78640e33a9e712045b16fe3719a38e6d1461b81b [file] [log] [blame]
Matteo Scandoloef4e8f82021-05-17 11:20:49 -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 "fmt"
21 "github.com/looplab/fsm"
22 omcilib "github.com/opencord/bbsim/internal/common/omci"
23 log "github.com/sirupsen/logrus"
24)
25
26const maxUniPorts = 4
27
28type UniPort struct {
29 ID uint32
30 MeId omcilib.EntityID
31 OperState *fsm.FSM
32 Onu *Onu
33}
34
35func NewUniPort(ID uint32, onu *Onu) (*UniPort, error) {
36
37 // IDs starts from 0, thus the maximum UNI supported is maxUniPorts - 1
38 if ID > (maxUniPorts - 1) {
39 return nil, fmt.Errorf("%d-is-higher-than-the-maximum-supported-unis-%d", ID, maxUniPorts)
40 }
41
42 uni := UniPort{
43 ID: ID,
44 Onu: onu,
45 MeId: omcilib.GenerateUniPortEntityId(ID + 1),
46 }
47
48 uni.OperState = getOperStateFSM(func(e *fsm.Event) {
49 onuLogger.WithFields(log.Fields{
50 "ID": uni.ID,
51 "OnuSn": onu.Sn(),
52 }).Debugf("changing-uni-operstate-from-%s-to-%s", e.Src, e.Dst)
53 })
54
55 return &uni, nil
56}