blob: b87bc536bd9f90ed0a7cb379298421af1cb8b03d [file] [log] [blame]
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +09001/*
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 device
18
19type oltState int
20
21type Olt struct {
22 ID uint32
23 NumPonIntf uint32
24 NumNniIntf uint32
25 Mac string
26 SerialNumber string
27 Manufacture string
28 Name string
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090029 InternalState *oltState
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090030 OperState string
31 Intfs []intf
32 HeartbeatSignature uint32
33}
34
35type intf struct {
36 Type string
37 IntfID uint32
38 OperState string
39}
40
41const (
42 PRE_ENABLE oltState = iota
43 OLT_UP
44 PONIF_UP
45 ONU_DISCOVERED
46)
47
48func CreateOlt(oltid uint32, npon uint32, nnni uint32) *Olt {
49 olt := Olt{}
50 olt.ID = oltid
51 olt.NumPonIntf = npon
52 olt.NumNniIntf = nnni
53 olt.Name = "BBSIM OLT"
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090054 olt.InternalState = new(oltState)
55 *olt.InternalState = PRE_ENABLE
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090056 olt.OperState = "up"
57 olt.Intfs = make([]intf, olt.NumPonIntf+olt.NumNniIntf)
58 olt.HeartbeatSignature = oltid
59 for i := uint32(0); i < olt.NumNniIntf; i++ {
60 olt.Intfs[i].IntfID = i
61 olt.Intfs[i].OperState = "up"
62 olt.Intfs[i].Type = "nni"
63 }
64 for i := uint32(olt.NumNniIntf); i < olt.NumPonIntf+olt.NumNniIntf; i++ {
65 olt.Intfs[i].IntfID = i
66 olt.Intfs[i].OperState = "up"
67 olt.Intfs[i].Type = "pon"
68 }
69 return &olt
70}
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090071
72func (olt *Olt)InitializeStatus(){
73 *olt.InternalState = PRE_ENABLE
74 olt.OperState = "up"
75 for i := uint32(0); i < olt.NumNniIntf; i++ {
76 olt.Intfs[i].IntfID = i
77 olt.Intfs[i].OperState = "up"
78 olt.Intfs[i].Type = "nni"
79 }
80 for i := uint32(olt.NumNniIntf); i < olt.NumPonIntf+olt.NumNniIntf; i++ {
81 olt.Intfs[i].IntfID = i
82 olt.Intfs[i].OperState = "up"
83 olt.Intfs[i].Type = "pon"
84 }
85}