blob: 618e66805aa0f59ee68294df6e8b9a633f9a0302 [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
Keita NISHIMOTO3f080622019-01-16 10:21:22 +090019import "sync"
20
21type DeviceState int
22
23type Device interface {
24 Initialize()
25 UpdateIntState(intstate DeviceState)
26 GetIntState() DeviceState
27 GetDevkey() Devkey
28}
29
30type Devkey struct {
31 ID uint32
32 Intfid uint32
33}
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090034
35type Olt struct {
36 ID uint32
37 NumPonIntf uint32
38 NumNniIntf uint32
39 Mac string
40 SerialNumber string
41 Manufacture string
42 Name string
Keita NISHIMOTO3f080622019-01-16 10:21:22 +090043 InternalState DeviceState
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090044 OperState string
45 Intfs []intf
46 HeartbeatSignature uint32
Keita NISHIMOTO3f080622019-01-16 10:21:22 +090047 mu *sync.Mutex
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090048}
49
50type intf struct {
51 Type string
52 IntfID uint32
53 OperState string
54}
55
Keita NISHIMOTO3f080622019-01-16 10:21:22 +090056/* OltState
57OLT_INACTIVE -> OLT_PREACTIVE -> ACTIVE
58 (ActivateOLT) (Enable)
59 <- <-
60*/
61
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090062const (
Keita NISHIMOTO3f080622019-01-16 10:21:22 +090063 OLT_INACTIVE DeviceState = iota // OLT/ONUs are not instantiated
64 OLT_PREACTIVE // Before PacketInDaemon Running
65 OLT_ACTIVE // After PacketInDaemon Running
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090066)
67
Keita NISHIMOTO9708e042018-10-27 09:24:44 +090068func NewOlt(oltid uint32, npon uint32, nnni uint32) *Olt {
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090069 olt := Olt{}
70 olt.ID = oltid
71 olt.NumPonIntf = npon
72 olt.NumNniIntf = nnni
73 olt.Name = "BBSIM OLT"
Keita NISHIMOTO3f080622019-01-16 10:21:22 +090074 olt.InternalState = OLT_INACTIVE
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090075 olt.OperState = "up"
76 olt.Intfs = make([]intf, olt.NumPonIntf+olt.NumNniIntf)
77 olt.HeartbeatSignature = oltid
Keita NISHIMOTO3f080622019-01-16 10:21:22 +090078 olt.mu = &sync.Mutex{}
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090079 for i := uint32(0); i < olt.NumNniIntf; i++ {
80 olt.Intfs[i].IntfID = i
81 olt.Intfs[i].OperState = "up"
82 olt.Intfs[i].Type = "nni"
83 }
84 for i := uint32(olt.NumNniIntf); i < olt.NumPonIntf+olt.NumNniIntf; i++ {
85 olt.Intfs[i].IntfID = i
86 olt.Intfs[i].OperState = "up"
87 olt.Intfs[i].Type = "pon"
88 }
89 return &olt
90}
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090091
Keita NISHIMOTO3f080622019-01-16 10:21:22 +090092func (olt *Olt) Initialize() {
93 olt.InternalState = OLT_INACTIVE
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090094 olt.OperState = "up"
95 for i := uint32(0); i < olt.NumNniIntf; i++ {
96 olt.Intfs[i].IntfID = i
97 olt.Intfs[i].OperState = "up"
98 olt.Intfs[i].Type = "nni"
99 }
100 for i := uint32(olt.NumNniIntf); i < olt.NumPonIntf+olt.NumNniIntf; i++ {
101 olt.Intfs[i].IntfID = i
102 olt.Intfs[i].OperState = "up"
103 olt.Intfs[i].Type = "pon"
104 }
105}
Keita NISHIMOTO3f080622019-01-16 10:21:22 +0900106
107func (olt *Olt) GetIntState() DeviceState {
108 olt.mu.Lock()
109 defer olt.mu.Unlock()
110 return olt.InternalState
111}
112
113func (olt *Olt) GetDevkey () Devkey {
114 return Devkey{ID: olt.ID}
115}
116
117func (olt *Olt) UpdateIntState(intstate DeviceState) {
118 olt.mu.Lock()
119 defer olt.mu.Unlock()
120 olt.InternalState = intstate
121}