Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package device |
| 18 | |
| 19 | type oltState int |
| 20 | |
| 21 | type Olt struct { |
| 22 | ID uint32 |
| 23 | NumPonIntf uint32 |
| 24 | NumNniIntf uint32 |
| 25 | Mac string |
| 26 | SerialNumber string |
| 27 | Manufacture string |
| 28 | Name string |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 29 | InternalState *oltState |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 30 | OperState string |
| 31 | Intfs []intf |
| 32 | HeartbeatSignature uint32 |
| 33 | } |
| 34 | |
| 35 | type intf struct { |
| 36 | Type string |
| 37 | IntfID uint32 |
| 38 | OperState string |
| 39 | } |
| 40 | |
| 41 | const ( |
| 42 | PRE_ENABLE oltState = iota |
| 43 | OLT_UP |
| 44 | PONIF_UP |
| 45 | ONU_DISCOVERED |
| 46 | ) |
| 47 | |
| 48 | func 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 NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 54 | olt.InternalState = new(oltState) |
| 55 | *olt.InternalState = PRE_ENABLE |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 56 | 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 NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 71 | |
| 72 | func (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 | } |