blob: 1353a50228540bf1e6dbb0f55f565f2365fc31d5 [file] [log] [blame]
Matteo Scandolo11006992019-08-28 11:29:46 -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
Matteo Scandolo4747d292019-08-05 11:50:18 -070017package devices
18
19import (
Matteo Scandolo40e067f2019-10-16 16:59:41 -070020 "context"
Himani Chawla4ff5fab2021-11-09 19:19:29 +053021 "encoding/binary"
Matteo Scandolo618a6582020-09-09 12:21:29 -070022 "encoding/hex"
Matteo Scandolo3bc73742019-08-20 14:04:04 -070023 "fmt"
Elia Battistonfe017662022-01-05 11:43:16 +010024 "math/rand"
Mahir Gunyela1753ae2021-06-23 00:24:56 -070025 "sync"
26
Matteo Scandolo8a574812021-05-20 15:18:53 -070027 "github.com/opencord/bbsim/internal/bbsim/packetHandlers"
28 "github.com/opencord/bbsim/internal/bbsim/responders/dhcp"
29 "github.com/opencord/bbsim/internal/bbsim/responders/eapol"
Holger Hildebrandtc10bab12021-04-27 09:23:48 +000030
Matteo Scandolof9d43412021-01-12 11:11:34 -080031 pb "github.com/opencord/bbsim/api/bbsim"
32 "github.com/opencord/bbsim/internal/bbsim/alarmsim"
Holger Hildebrandtc10bab12021-04-27 09:23:48 +000033
34 "net"
35 "strconv"
36 "time"
Himani Chawla13b1ee02021-03-15 01:43:53 +053037
Matteo Scandolo4b077aa2021-02-16 17:33:37 -080038 bbsim "github.com/opencord/bbsim/internal/bbsim/types"
Andrea Campanella10426e22021-10-15 17:58:04 +020039 me "github.com/opencord/omci-lib-go/v2/generated"
Zdravko Bozakov681364d2019-11-10 14:28:46 +010040
Himani Chawla4ff5fab2021-11-09 19:19:29 +053041 "github.com/boguslaw-wojcik/crc32a"
Matteo Scandolo3bc73742019-08-20 14:04:04 -070042 "github.com/google/gopacket/layers"
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070043 "github.com/jpillora/backoff"
Matteo Scandolo4747d292019-08-05 11:50:18 -070044 "github.com/looplab/fsm"
Matteo Scandolo40e067f2019-10-16 16:59:41 -070045 "github.com/opencord/bbsim/internal/common"
46 omcilib "github.com/opencord/bbsim/internal/common/omci"
Andrea Campanella10426e22021-10-15 17:58:04 +020047 "github.com/opencord/omci-lib-go/v2"
David K. Bainbridgec415efe2021-08-19 13:05:21 +000048 "github.com/opencord/voltha-protos/v5/go/openolt"
49 "github.com/opencord/voltha-protos/v5/go/tech_profile"
Matteo Scandolo4747d292019-08-05 11:50:18 -070050 log "github.com/sirupsen/logrus"
51)
52
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070053var onuLogger = log.WithFields(log.Fields{
54 "module": "ONU",
55})
56
Matteo Scandolocedde462021-03-09 17:37:16 -080057const (
Holger Hildebrandtc10bab12021-04-27 09:23:48 +000058 maxOmciMsgCounter = 10
59)
60
61const (
Matteo Scandolocedde462021-03-09 17:37:16 -080062 // ONU transitions
63 OnuTxInitialize = "initialize"
64 OnuTxDiscover = "discover"
65 OnuTxEnable = "enable"
66 OnuTxDisable = "disable"
67 OnuTxPonDisable = "pon_disable"
68 OnuTxStartImageDownload = "start_image_download"
69 OnuTxProgressImageDownload = "progress_image_download"
70 OnuTxCompleteImageDownload = "complete_image_download"
71 OnuTxFailImageDownload = "fail_image_download"
72 OnuTxActivateImage = "activate_image"
73 OnuTxCommitImage = "commit_image"
74
75 // ONU States
76 OnuStateCreated = "created"
77 OnuStateInitialized = "initialized"
78 OnuStateDiscovered = "discovered"
79 OnuStateEnabled = "enabled"
80 OnuStateDisabled = "disabled"
81 OnuStatePonDisabled = "pon_disabled"
82 OnuStateImageDownloadStarted = "image_download_started"
83 OnuStateImageDownloadInProgress = "image_download_in_progress"
84 OnuStateImageDownloadComplete = "image_download_completed"
85 OnuStateImageDownloadError = "image_download_error"
86 OnuStateImageActivated = "software_image_activated"
87 OnuStateImageCommitted = "software_image_committed"
88
89 // BBR ONU States and Transitions
90 BbrOnuTxSendEapolFlow = "send_eapol_flow"
91 BbrOnuStateEapolFlowSent = "eapol_flow_sent"
92 BbrOnuTxSendDhcpFlow = "send_dhcp_flow"
93 BbrOnuStateDhcpFlowSent = "dhcp_flow_sent"
94)
95
Andrea Campanellacc9b1662022-01-26 17:47:48 +010096type FlowKey struct {
yasin saplic07b9522022-01-27 11:23:54 +000097 ID uint64
Andrea Campanellacc9b1662022-01-26 17:47:48 +010098}
99
Matteo Scandolo86e8ce62019-10-11 12:03:10 -0700100type Onu struct {
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800101 ID uint32
102 PonPortID uint32
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700103 PonPort *PonPort
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800104 InternalState *fsm.FSM
Pragya Arya2225f202020-01-29 18:05:01 +0530105 DiscoveryRetryDelay time.Duration // this is the time between subsequent Discovery Indication
106 DiscoveryDelay time.Duration // this is the time to send the first Discovery Indication
Matteo Scandolo4a036262020-08-17 15:56:13 -0700107
Matteo Scandolo4a036262020-08-17 15:56:13 -0700108 Backoff *backoff.Backoff
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800109 // ONU State
Elia Battistonac63b112022-01-12 18:40:49 +0100110 UniPorts []UniPortIf
111 PotsPorts []PotsPortIf
Andrea Campanellacc9b1662022-01-26 17:47:48 +0100112 Flows []FlowKey
Elia Battistonac63b112022-01-12 18:40:49 +0100113 FlowIds []uint64 // keep track of the flows we currently have in the ONU
Matteo Scandolo99f18462019-10-28 14:14:28 -0700114
Matteo Scandolo86e8ce62019-10-11 12:03:10 -0700115 OperState *fsm.FSM
116 SerialNumber *openolt.SerialNumber
117
Girish Gowdra1ddcb202021-06-25 12:17:09 -0700118 AdminLockState uint8 // 0 is enabled, 1 is disabled.
119
Matteo Scandolof9d43412021-01-12 11:11:34 -0800120 Channel chan bbsim.Message // this Channel is to track state changes OMCI messages, EAPOL and DHCP packets
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700121
122 // OMCI params
Matteo Scandolocedde462021-03-09 17:37:16 -0800123 MibDataSync uint8
124 ImageSoftwareExpectedSections int
125 ImageSoftwareReceivedSections int
126 ActiveImageEntityId uint16
127 CommittedImageEntityId uint16
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700128 StandbyImageVersion string
129 ActiveImageVersion string
Matteo Scandolo76f6b892021-11-15 16:13:06 -0800130 InDownloadImageVersion string
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700131 CommittedImageVersion string
Holger Hildebrandtc10bab12021-04-27 09:23:48 +0000132 OmciResponseRate uint8
133 OmciMsgCounter uint8
Himani Chawla4ff5fab2021-11-09 19:19:29 +0530134 ImageSectionData []byte
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800135
136 // OMCI params (Used in BBR)
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700137 tid uint16
138 hpTid uint16
139 seqNumber uint16
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700140 MibDb *omcilib.MibDb
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700141
Anand S Katti09541352020-01-29 15:54:01 +0530142 DoneChannel chan bool // this channel is used to signal once the onu is complete (when the struct is used by BBR)
143 TrafficSchedulers *tech_profile.TrafficSchedulers
Himani Chawla13b1ee02021-03-15 01:43:53 +0530144 onuAlarmsInfoLock sync.RWMutex
145 onuAlarmsInfo map[omcilib.OnuAlarmInfoMapKey]omcilib.OnuAlarmInfo
Matteo Scandolo86e8ce62019-10-11 12:03:10 -0700146}
147
Matteo Scandolo99f18462019-10-28 14:14:28 -0700148func (o *Onu) Sn() string {
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700149 return common.OnuSnToString(o.SerialNumber)
Matteo Scandolo86e8ce62019-10-11 12:03:10 -0700150}
151
Matteo Scandolo8a574812021-05-20 15:18:53 -0700152func CreateONU(olt *OltDevice, pon *PonPort, id uint32, delay time.Duration, nextCtag map[string]int, nextStag map[string]int, isMock bool) *Onu {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700153
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700154 o := Onu{
Matteo Scandolocedde462021-03-09 17:37:16 -0800155 ID: id,
156 PonPortID: pon.ID,
157 PonPort: pon,
Matteo Scandolocedde462021-03-09 17:37:16 -0800158 tid: 0x1,
159 hpTid: 0x8000,
160 seqNumber: 0,
161 DoneChannel: make(chan bool, 1),
162 DiscoveryRetryDelay: 60 * time.Second, // this is used to send OnuDiscoveryIndications until an activate call is received
Andrea Campanellacc9b1662022-01-26 17:47:48 +0100163 Flows: []FlowKey{},
Matteo Scandolocedde462021-03-09 17:37:16 -0800164 DiscoveryDelay: delay,
165 MibDataSync: 0,
166 ImageSoftwareExpectedSections: 0, // populated during OMCI StartSoftwareDownloadRequest
167 ImageSoftwareReceivedSections: 0,
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700168 //TODO this needs reworking, it's always 0 or 1, possibly base all on the version
169 ActiveImageEntityId: 0, // when we start the SoftwareImage with ID 0 is active and committed
170 CommittedImageEntityId: 0,
171 StandbyImageVersion: "BBSM_IMG_00000",
172 ActiveImageVersion: "BBSM_IMG_00001",
173 CommittedImageVersion: "BBSM_IMG_00001",
174 OmciResponseRate: olt.OmciResponseRate,
175 OmciMsgCounter: 0,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700176 }
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800177 o.SerialNumber = NewSN(olt.ID, pon.ID, id)
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700178 // NOTE this state machine is used to track the operational
179 // state as requested by VOLTHA
180 o.OperState = getOperStateFSM(func(e *fsm.Event) {
181 onuLogger.WithFields(log.Fields{
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700182 "OnuId": o.ID,
183 "IntfId": o.PonPortID,
184 "OnuSn": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700185 }).Debugf("Changing ONU OperState from %s to %s", e.Src, e.Dst)
186 })
Himani Chawla13b1ee02021-03-15 01:43:53 +0530187 o.onuAlarmsInfo = make(map[omcilib.OnuAlarmInfoMapKey]omcilib.OnuAlarmInfo)
Himani Chawla908a1f52022-01-27 14:39:44 +0530188
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700189 // NOTE this state machine is used to activate the OMCI, EAPOL and DHCP clients
190 o.InternalState = fsm.NewFSM(
Matteo Scandolocedde462021-03-09 17:37:16 -0800191 OnuStateCreated,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700192 fsm.Events{
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700193 // DEVICE Lifecycle
Matteo Scandolocedde462021-03-09 17:37:16 -0800194 {Name: OnuTxInitialize, Src: []string{OnuStateCreated, OnuStateDisabled, OnuStatePonDisabled}, Dst: OnuStateInitialized},
195 {Name: OnuTxDiscover, Src: []string{OnuStateInitialized}, Dst: OnuStateDiscovered},
196 {Name: OnuTxEnable, Src: []string{OnuStateDiscovered, OnuStatePonDisabled}, Dst: OnuStateEnabled},
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100197 // NOTE should disabled state be different for oper_disabled (emulating an error) and admin_disabled (received a disabled call via VOLTHA)?
Matteo Scandolocedde462021-03-09 17:37:16 -0800198 {Name: OnuTxDisable, Src: []string{OnuStateEnabled, OnuStatePonDisabled, OnuStateImageActivated, OnuStateImageDownloadError, OnuStateImageCommitted}, Dst: OnuStateDisabled},
Pragya Arya6a708d62020-01-01 17:17:20 +0530199 // ONU state when PON port is disabled but ONU is power ON(more states should be added in src?)
Matteo Scandolo9f4bf4f2021-06-22 09:41:02 +0200200 {Name: OnuTxPonDisable, Src: []string{OnuStateEnabled, OnuStateImageActivated, OnuStateImageDownloadError, OnuStateImageCommitted, OnuStateImageDownloadComplete}, Dst: OnuStatePonDisabled},
Matteo Scandolocedde462021-03-09 17:37:16 -0800201 // Software Image Download related states
Matteo Scandolo9f4bf4f2021-06-22 09:41:02 +0200202 {Name: OnuTxStartImageDownload, Src: []string{OnuStateEnabled, OnuStateImageDownloadComplete, OnuStateImageDownloadError, OnuStateImageCommitted}, Dst: OnuStateImageDownloadStarted},
Matteo Scandolocedde462021-03-09 17:37:16 -0800203 {Name: OnuTxProgressImageDownload, Src: []string{OnuStateImageDownloadStarted}, Dst: OnuStateImageDownloadInProgress},
204 {Name: OnuTxCompleteImageDownload, Src: []string{OnuStateImageDownloadInProgress}, Dst: OnuStateImageDownloadComplete},
205 {Name: OnuTxFailImageDownload, Src: []string{OnuStateImageDownloadInProgress}, Dst: OnuStateImageDownloadError},
206 {Name: OnuTxActivateImage, Src: []string{OnuStateImageDownloadComplete}, Dst: OnuStateImageActivated},
207 {Name: OnuTxCommitImage, Src: []string{OnuStateEnabled}, Dst: OnuStateImageCommitted}, // the image is committed after a ONU reboot
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700208 // BBR States
209 // TODO add start OMCI state
Matteo Scandolocedde462021-03-09 17:37:16 -0800210 {Name: BbrOnuTxSendEapolFlow, Src: []string{OnuStateInitialized}, Dst: BbrOnuStateEapolFlowSent},
211 {Name: BbrOnuTxSendDhcpFlow, Src: []string{BbrOnuStateEapolFlowSent}, Dst: BbrOnuStateDhcpFlowSent},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700212 },
213 fsm.Callbacks{
214 "enter_state": func(e *fsm.Event) {
215 o.logStateChange(e.Src, e.Dst)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700216 },
Matteo Scandolod15c0b42021-03-22 11:38:13 -0700217 fmt.Sprintf("enter_%s", OnuStateInitialized): func(e *fsm.Event) {
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100218 // create new channel for ProcessOnuMessages Go routine
Matteo Scandolof9d43412021-01-12 11:11:34 -0800219 o.Channel = make(chan bbsim.Message, 2048)
Matteo Scandolod7cc6d32020-02-26 16:51:12 -0800220
Matteo Scandolocedde462021-03-09 17:37:16 -0800221 if err := o.OperState.Event(OnuTxEnable); err != nil {
Matteo Scandolod7cc6d32020-02-26 16:51:12 -0800222 onuLogger.WithFields(log.Fields{
223 "OnuId": o.ID,
224 "IntfId": o.PonPortID,
225 "OnuSn": o.Sn(),
226 }).Errorf("Cannot change ONU OperState to up: %s", err.Error())
227 }
228
Pragya Arya1cbefa42020-01-13 12:15:29 +0530229 if !isMock {
230 // start ProcessOnuMessages Go routine
Matteo Scandolo4a036262020-08-17 15:56:13 -0700231 go o.ProcessOnuMessages(olt.enableContext, olt.OpenoltStream, nil)
Pragya Arya1cbefa42020-01-13 12:15:29 +0530232 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100233 },
Matteo Scandolod15c0b42021-03-22 11:38:13 -0700234 fmt.Sprintf("enter_%s", OnuStateDiscovered): func(e *fsm.Event) {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800235 msg := bbsim.Message{
236 Type: bbsim.OnuDiscIndication,
237 Data: bbsim.OnuDiscIndicationMessage{
238 OperState: bbsim.UP,
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100239 },
240 }
241 o.Channel <- msg
242 },
Matteo Scandolod15c0b42021-03-22 11:38:13 -0700243 fmt.Sprintf("enter_%s", OnuStateEnabled): func(event *fsm.Event) {
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800244
245 if used, sn := o.PonPort.isOnuIdAllocated(o.ID); used {
246 onuLogger.WithFields(log.Fields{
247 "IntfId": o.PonPortID,
248 "OnuId": o.ID,
249 "SerialNumber": o.Sn(),
Matteo Scandolod15c0b42021-03-22 11:38:13 -0700250 }).Errorf("onu-id-duplicated-with-%s", common.OnuSnToString(sn))
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800251 return
252 } else {
253 o.PonPort.storeOnuId(o.ID, o.SerialNumber)
254 }
255
Matteo Scandolof9d43412021-01-12 11:11:34 -0800256 msg := bbsim.Message{
257 Type: bbsim.OnuIndication,
258 Data: bbsim.OnuIndicationMessage{
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700259 OnuSN: o.SerialNumber,
260 PonPortID: o.PonPortID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800261 OperState: bbsim.UP,
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700262 },
263 }
264 o.Channel <- msg
265 },
Matteo Scandolod15c0b42021-03-22 11:38:13 -0700266 fmt.Sprintf("enter_%s", OnuStateDisabled): func(event *fsm.Event) {
Matteo Scandolo47ef64b2020-04-20 14:16:07 -0700267
Matteo Scandolod15c0b42021-03-22 11:38:13 -0700268 o.cleanupOnuState()
Matteo Scandolo47ef64b2020-04-20 14:16:07 -0700269
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700270 // set the OperState to disabled
Matteo Scandolod7cc6d32020-02-26 16:51:12 -0800271 if err := o.OperState.Event("disable"); err != nil {
272 onuLogger.WithFields(log.Fields{
273 "OnuId": o.ID,
274 "IntfId": o.PonPortID,
275 "OnuSn": o.Sn(),
276 }).Errorf("Cannot change ONU OperState to down: %s", err.Error())
277 }
Matteo Scandolo47ef64b2020-04-20 14:16:07 -0700278 // send the OnuIndication DOWN event
Matteo Scandolof9d43412021-01-12 11:11:34 -0800279 msg := bbsim.Message{
280 Type: bbsim.OnuIndication,
281 Data: bbsim.OnuIndicationMessage{
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700282 OnuSN: o.SerialNumber,
283 PonPortID: o.PonPortID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800284 OperState: bbsim.DOWN,
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700285 },
286 }
287 o.Channel <- msg
Hardik Windlass7b3405b2020-07-08 15:10:05 +0530288
Matteo Scandolo8a574812021-05-20 15:18:53 -0700289 // disable the UNI ports
290 for _, uni := range o.UniPorts {
291 _ = uni.Disable()
292 }
293
Elia Battistonac63b112022-01-12 18:40:49 +0100294 // disable the POTS UNI ports
295 for _, pots := range o.PotsPorts {
296 _ = pots.Disable()
297 }
298
Hardik Windlass7b3405b2020-07-08 15:10:05 +0530299 // verify all the flows removes are handled and
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100300 // terminate the ONU's ProcessOnuMessages Go routine
Matteo Scandolo8a574812021-05-20 15:18:53 -0700301 // NOTE may need to wait for the UNIs to be down too before shutting down the channel
Hardik Windlass7b3405b2020-07-08 15:10:05 +0530302 if len(o.FlowIds) == 0 {
303 close(o.Channel)
304 }
Matteo Scandolod15c0b42021-03-22 11:38:13 -0700305 },
306 fmt.Sprintf("enter_%s", OnuStatePonDisabled): func(event *fsm.Event) {
307 o.cleanupOnuState()
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700308 },
Matteo Scandolo4a036262020-08-17 15:56:13 -0700309 // BBR states
Matteo Scandolod15c0b42021-03-22 11:38:13 -0700310 fmt.Sprintf("enter_%s", BbrOnuStateEapolFlowSent): func(e *fsm.Event) {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800311 msg := bbsim.Message{
312 Type: bbsim.SendEapolFlow,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700313 }
314 o.Channel <- msg
315 },
Matteo Scandolod15c0b42021-03-22 11:38:13 -0700316 fmt.Sprintf("enter_%s", BbrOnuStateDhcpFlowSent): func(e *fsm.Event) {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800317 msg := bbsim.Message{
318 Type: bbsim.SendDhcpFlow,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700319 }
320 o.Channel <- msg
321 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700322 },
323 )
Mahir Gunyela1753ae2021-06-23 00:24:56 -0700324 onuLogger.WithFields(log.Fields{
Elia Battistonac63b112022-01-12 18:40:49 +0100325 "OnuId": o.ID,
326 "IntfId": o.PonPortID,
327 "OnuSn": o.Sn(),
328 "NumUni": olt.NumUni,
329 "NumPots": olt.NumPots,
Mahir Gunyela1753ae2021-06-23 00:24:56 -0700330 }).Debug("creating-uni-ports")
Elia Battistonac63b112022-01-12 18:40:49 +0100331
332 // create Ethernet UNIs
Mahir Gunyela1753ae2021-06-23 00:24:56 -0700333 for i := 0; i < olt.NumUni; i++ {
Matteo Scandolo8a574812021-05-20 15:18:53 -0700334 uni, err := NewUniPort(uint32(i), &o, nextCtag, nextStag)
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700335 if err != nil {
336 onuLogger.WithFields(log.Fields{
337 "OnuId": o.ID,
338 "IntfId": o.PonPortID,
339 "OnuSn": o.Sn(),
340 "Err": err,
341 }).Fatal("cannot-create-uni-port")
342 }
343 o.UniPorts = append(o.UniPorts, uni)
344 }
Elia Battistonac63b112022-01-12 18:40:49 +0100345 // create POTS UNIs, with progressive IDs
346 for i := olt.NumUni; i < (olt.NumUni + olt.NumPots); i++ {
347 pots, err := NewPotsPort(uint32(i), &o)
348 if err != nil {
349 onuLogger.WithFields(log.Fields{
350 "OnuId": o.ID,
351 "IntfId": o.PonPortID,
352 "OnuSn": o.Sn(),
353 "Err": err,
354 }).Fatal("cannot-create-pots-port")
355 }
356 o.PotsPorts = append(o.PotsPorts, pots)
357 }
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700358
Elia Battistonac63b112022-01-12 18:40:49 +0100359 mibDb, err := omcilib.GenerateMibDatabase(len(o.UniPorts), len(o.PotsPorts))
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700360 if err != nil {
361 onuLogger.WithFields(log.Fields{
362 "OnuId": o.ID,
363 "IntfId": o.PonPortID,
364 "OnuSn": o.Sn(),
365 }).Fatal("cannot-generate-mibdb-for-onu")
366 }
367 o.MibDb = mibDb
368
Matteo Scandolo27428702019-10-11 16:21:16 -0700369 return &o
Matteo Scandolo4747d292019-08-05 11:50:18 -0700370}
371
William Kurkian0418bc82019-11-06 12:16:24 -0500372func (o *Onu) logStateChange(src string, dst string) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700373 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700374 "OnuId": o.ID,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700375 "IntfId": o.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700376 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700377 }).Debugf("Changing ONU InternalState from %s to %s", src, dst)
378}
379
Matteo Scandolod15c0b42021-03-22 11:38:13 -0700380// cleanupOnuState this method is to clean the local state when the ONU is disabled
381func (o *Onu) cleanupOnuState() {
382 // clean the ONU state
Andrea Campanellacc9b1662022-01-26 17:47:48 +0100383 o.Flows = []FlowKey{}
Matteo Scandolod15c0b42021-03-22 11:38:13 -0700384 o.PonPort.removeOnuId(o.ID)
Andrea Campanellabef00d52022-02-04 09:47:52 +0100385 o.PonPort.removeAllocId(o.SerialNumber)
Matteo Scandolod15c0b42021-03-22 11:38:13 -0700386 o.PonPort.removeGemPortBySn(o.SerialNumber)
387
388 o.onuAlarmsInfoLock.Lock()
389 o.onuAlarmsInfo = make(map[omcilib.OnuAlarmInfoMapKey]omcilib.OnuAlarmInfo) //Basically reset everything on onu disable
390 o.onuAlarmsInfoLock.Unlock()
391}
392
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100393// ProcessOnuMessages starts indication channel for each ONU
David Bainbridge103cf022019-12-16 20:11:35 +0000394func (o *Onu) ProcessOnuMessages(ctx context.Context, stream openolt.Openolt_EnableIndicationServer, client openolt.OpenoltClient) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700395 onuLogger.WithFields(log.Fields{
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100396 "onuID": o.ID,
397 "onuSN": o.Sn(),
398 "ponPort": o.PonPortID,
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700399 "stream": stream,
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100400 }).Debug("Starting ONU Indication Channel")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700401
Matteo Scandolob307d8a2021-05-10 15:19:27 -0700402 defer onuLogger.WithFields(log.Fields{
403 "onuID": o.ID,
404 "onuSN": o.Sn(),
405 "stream": stream,
406 }).Debug("Stopped handling ONU Indication Channel")
407
David Bainbridge103cf022019-12-16 20:11:35 +0000408loop:
409 for {
410 select {
411 case <-ctx.Done():
412 onuLogger.WithFields(log.Fields{
413 "onuID": o.ID,
414 "onuSN": o.Sn(),
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700415 }).Debug("ONU message handling canceled via context")
416 break loop
417 case <-stream.Context().Done():
418 onuLogger.WithFields(log.Fields{
419 "onuID": o.ID,
420 "onuSN": o.Sn(),
421 }).Debug("ONU message handling canceled via stream context")
David Bainbridge103cf022019-12-16 20:11:35 +0000422 break loop
423 case message, ok := <-o.Channel:
424 if !ok || ctx.Err() != nil {
425 onuLogger.WithFields(log.Fields{
426 "onuID": o.ID,
427 "onuSN": o.Sn(),
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700428 }).Debug("ONU message handling canceled via channel close")
David Bainbridge103cf022019-12-16 20:11:35 +0000429 break loop
Matteo Scandolo075b1892019-10-07 12:11:07 -0700430 }
David Bainbridge103cf022019-12-16 20:11:35 +0000431 onuLogger.WithFields(log.Fields{
432 "onuID": o.ID,
433 "onuSN": o.Sn(),
434 "messageType": message.Type,
435 }).Tracef("Received message on ONU Channel")
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700436
David Bainbridge103cf022019-12-16 20:11:35 +0000437 switch message.Type {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800438 case bbsim.OnuDiscIndication:
439 msg, _ := message.Data.(bbsim.OnuDiscIndicationMessage)
David Bainbridge103cf022019-12-16 20:11:35 +0000440 // NOTE we need to slow down and send ONU Discovery Indication in batches to better emulate a real scenario
Pragya Arya2225f202020-01-29 18:05:01 +0530441 time.Sleep(o.DiscoveryDelay)
David Bainbridge103cf022019-12-16 20:11:35 +0000442 o.sendOnuDiscIndication(msg, stream)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800443 case bbsim.OnuIndication:
444 msg, _ := message.Data.(bbsim.OnuIndicationMessage)
David Bainbridge103cf022019-12-16 20:11:35 +0000445 o.sendOnuIndication(msg, stream)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800446 case bbsim.OMCI:
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800447 // these are OMCI messages received by the ONU
Matteo Scandolof9d43412021-01-12 11:11:34 -0800448 msg, _ := message.Data.(bbsim.OmciMessage)
Andrea Campanellabe1b7cf2021-04-30 09:53:40 +0200449 _ = o.handleOmciRequest(msg, stream)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800450 case bbsim.UniStatusAlarm:
451 msg, _ := message.Data.(bbsim.UniStatusAlarmMessage)
Himani Chawla13b1ee02021-03-15 01:43:53 +0530452 onuAlarmMapKey := omcilib.OnuAlarmInfoMapKey{
453 MeInstance: msg.EntityID,
454 MeClassID: me.PhysicalPathTerminationPointEthernetUniClassID,
455 }
456 seqNo := o.IncrementAlarmSequenceNumber(onuAlarmMapKey)
457 o.onuAlarmsInfoLock.Lock()
458 var alarmInfo = o.onuAlarmsInfo[onuAlarmMapKey]
459 pkt, alarmBitMap := omcilib.CreateUniStatusAlarm(msg.RaiseOMCIAlarm, msg.EntityID, seqNo)
460 if pkt != nil { //pkt will be nil if we are unable to create the alarm
461 if err := o.sendOmciIndication(pkt, 0, stream); err != nil {
462 onuLogger.WithFields(log.Fields{
463 "IntfId": o.PonPortID,
464 "SerialNumber": o.Sn(),
465 "omciPacket": pkt,
466 "adminState": msg.AdminState,
467 "entityID": msg.EntityID,
468 }).Errorf("failed-to-send-UNI-Link-Alarm: %v", err)
469 alarmInfo.SequenceNo--
470 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800471 onuLogger.WithFields(log.Fields{
472 "IntfId": o.PonPortID,
473 "SerialNumber": o.Sn(),
474 "omciPacket": pkt,
475 "adminState": msg.AdminState,
476 "entityID": msg.EntityID,
Himani Chawla13b1ee02021-03-15 01:43:53 +0530477 }).Trace("UNI-Link-alarm-sent")
478 if alarmBitMap == [28]byte{0} {
479 delete(o.onuAlarmsInfo, onuAlarmMapKey)
480 } else {
481 alarmInfo.AlarmBitMap = alarmBitMap
482 o.onuAlarmsInfo[onuAlarmMapKey] = alarmInfo
483 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800484 }
Himani Chawla13b1ee02021-03-15 01:43:53 +0530485 o.onuAlarmsInfoLock.Unlock()
Matteo Scandolof9d43412021-01-12 11:11:34 -0800486 case bbsim.FlowAdd:
487 msg, _ := message.Data.(bbsim.OnuFlowUpdateMessage)
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700488 o.handleFlowAdd(msg)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800489 case bbsim.FlowRemoved:
490 msg, _ := message.Data.(bbsim.OnuFlowUpdateMessage)
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700491 o.handleFlowRemove(msg)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800492 case bbsim.OnuPacketOut:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700493
Matteo Scandolof9d43412021-01-12 11:11:34 -0800494 msg, _ := message.Data.(bbsim.OnuPacketMessage)
David Bainbridge103cf022019-12-16 20:11:35 +0000495
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700496 onuLogger.WithFields(log.Fields{
David Bainbridge103cf022019-12-16 20:11:35 +0000497 "IntfId": msg.IntfId,
498 "OnuId": msg.OnuId,
499 "pktType": msg.Type,
500 }).Trace("Received OnuPacketOut Message")
501
Matteo Scandolo8a574812021-05-20 15:18:53 -0700502 uni, err := o.findUniByPortNo(msg.PortNo)
Matteo Scandolo618a6582020-09-09 12:21:29 -0700503
Matteo Scandolo8a574812021-05-20 15:18:53 -0700504 if err != nil {
505 onuLogger.WithFields(log.Fields{
506 "IntfId": msg.IntfId,
507 "OnuId": msg.OnuId,
508 "pktType": msg.Type,
509 "portNo": msg.PortNo,
510 "MacAddress": msg.MacAddress,
511 "Pkt": hex.EncodeToString(msg.Packet.Data()),
512 "OnuSn": o.Sn(),
513 }).Error("Cannot find Uni associated with packet")
514 return
David Bainbridge103cf022019-12-16 20:11:35 +0000515 }
Matteo Scandolo8a574812021-05-20 15:18:53 -0700516 uni.PacketCh <- msg
517 // BBR specific messages
Matteo Scandolof9d43412021-01-12 11:11:34 -0800518 case bbsim.OnuPacketIn:
David Bainbridge103cf022019-12-16 20:11:35 +0000519 // NOTE we only receive BBR packets here.
520 // Eapol.HandleNextPacket can handle both BBSim and BBr cases so the call is the same
521 // in the DHCP case VOLTHA only act as a proxy, the behaviour is completely different thus we have a dhcp.HandleNextBbrPacket
Matteo Scandolof9d43412021-01-12 11:11:34 -0800522 msg, _ := message.Data.(bbsim.OnuPacketMessage)
David Bainbridge103cf022019-12-16 20:11:35 +0000523
Matteo Scandolo8a574812021-05-20 15:18:53 -0700524 onuLogger.WithFields(log.Fields{
525 "IntfId": msg.IntfId,
526 "OnuId": msg.OnuId,
527 "PortNo": msg.PortNo,
528 "GemPortId": msg.GemPortId,
529 "pktType": msg.Type,
David Bainbridge103cf022019-12-16 20:11:35 +0000530 }).Trace("Received OnuPacketIn Message")
531
Matteo Scandolo8a574812021-05-20 15:18:53 -0700532 uni, err := o.findUniByPortNo(msg.PortNo)
533 if err != nil {
534 onuLogger.WithFields(log.Fields{
535 "IntfId": msg.IntfId,
536 "OnuId": msg.OnuId,
537 "PortNo": msg.PortNo,
538 "GemPortId": msg.GemPortId,
539 "pktType": msg.Type,
540 }).Error(err.Error())
541 }
542
543 // BBR has one service and one UNI
544 serviceId := uint32(0)
545 oltId := 0
David Bainbridge103cf022019-12-16 20:11:35 +0000546 if msg.Type == packetHandlers.EAPOL {
Matteo Scandolo8a574812021-05-20 15:18:53 -0700547 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, msg.GemPortId, o.Sn(), msg.PortNo, uni.ID, serviceId, oltId, o.InternalState, msg.Packet, stream, client)
David Bainbridge103cf022019-12-16 20:11:35 +0000548 } else if msg.Type == packetHandlers.DHCP {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700549 _ = dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.DoneChannel, msg.Packet, client)
David Bainbridge103cf022019-12-16 20:11:35 +0000550 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800551 case bbsim.OmciIndication:
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800552 // these are OMCI messages received by BBR (VOLTHA emulator)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800553 msg, _ := message.Data.(bbsim.OmciIndicationMessage)
554 o.handleOmciResponse(msg, client)
555 case bbsim.SendEapolFlow:
David Bainbridge103cf022019-12-16 20:11:35 +0000556 o.sendEapolFlow(client)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800557 case bbsim.SendDhcpFlow:
David Bainbridge103cf022019-12-16 20:11:35 +0000558 o.sendDhcpFlow(client)
559 default:
560 onuLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700561 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700562 }
563 }
Matteo Scandolo4747d292019-08-05 11:50:18 -0700564}
565
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800566func NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700567 sn := new(openolt.SerialNumber)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700568 sn.VendorId = []byte("BBSM")
569 sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)}
Matteo Scandolo4747d292019-08-05 11:50:18 -0700570 return sn
571}
572
Matteo Scandolof9d43412021-01-12 11:11:34 -0800573func (o *Onu) sendOnuDiscIndication(msg bbsim.OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700574 discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800575 IntfId: o.PonPortID,
576 SerialNumber: o.SerialNumber,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700577 }}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700578
Matteo Scandolo4747d292019-08-05 11:50:18 -0700579 if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700580 log.Errorf("Failed to send Indication_OnuDiscInd: %v", err)
Matteo Scandolo99f18462019-10-28 14:14:28 -0700581 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700582 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700583
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700584 onuLogger.WithFields(log.Fields{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800585 "IntfId": o.PonPortID,
586 "OnuSn": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700587 "OnuId": o.ID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700588 }).Debug("Sent Indication_OnuDiscInd")
Matteo Scandolof9d43412021-01-12 11:11:34 -0800589 publishEvent("ONU-discovery-indication-sent", int32(o.PonPortID), int32(o.ID), o.Sn())
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800590
591 // after DiscoveryRetryDelay check if the state is the same and in case send a new OnuDiscIndication
592 go func(delay time.Duration) {
Matteo Scandolo569e7172019-12-20 11:51:51 -0800593 time.Sleep(delay)
Matteo Scandolocedde462021-03-09 17:37:16 -0800594 if o.InternalState.Current() == OnuStateDiscovered {
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800595 o.sendOnuDiscIndication(msg, stream)
596 }
597 }(o.DiscoveryRetryDelay)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700598}
599
Matteo Scandolof9d43412021-01-12 11:11:34 -0800600func (o *Onu) sendOnuIndication(msg bbsim.OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800601 // NOTE the ONU ID is set by VOLTHA in the ActivateOnu call (via openolt.proto)
602 // and stored in the Onu struct via onu.SetID
Matteo Scandolo4747d292019-08-05 11:50:18 -0700603
604 indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700605 IntfId: o.PonPortID,
606 OnuId: o.ID,
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700607 OperState: msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700608 AdminState: o.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700609 SerialNumber: o.SerialNumber,
610 }}
611 if err := stream.Send(&openolt.Indication{Data: indData}); err != nil {
Matteo Scandolod7cc6d32020-02-26 16:51:12 -0800612 // NOTE do we need to transition to a broken state?
Matteo Scandolo11006992019-08-28 11:29:46 -0700613 log.Errorf("Failed to send Indication_OnuInd: %v", err)
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700614 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700615 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700616 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800617 "IntfId": o.PonPortID,
618 "OnuId": o.ID,
619 "VolthaOnuId": msg.OnuID,
620 "OperState": msg.OperState.String(),
621 "AdminState": msg.OperState.String(),
622 "OnuSn": o.Sn(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700623 }).Debug("Sent Indication_OnuInd")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700624
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700625}
626
Matteo Scandolof9d43412021-01-12 11:11:34 -0800627func (o *Onu) HandleShutdownONU() error {
628
629 dyingGasp := pb.ONUAlarmRequest{
630 AlarmType: "DYING_GASP",
631 SerialNumber: o.Sn(),
632 Status: "on",
633 }
634
635 if err := alarmsim.SimulateOnuAlarm(&dyingGasp, o.ID, o.PonPortID, o.PonPort.Olt.channel); err != nil {
636 onuLogger.WithFields(log.Fields{
637 "OnuId": o.ID,
638 "IntfId": o.PonPortID,
639 "OnuSn": o.Sn(),
640 }).Errorf("Cannot send Dying Gasp: %s", err.Error())
641 return err
642 }
643
644 losReq := pb.ONUAlarmRequest{
645 AlarmType: "ONU_ALARM_LOS",
646 SerialNumber: o.Sn(),
647 Status: "on",
648 }
649
650 if err := alarmsim.SimulateOnuAlarm(&losReq, o.ID, o.PonPortID, o.PonPort.Olt.channel); err != nil {
651 onuLogger.WithFields(log.Fields{
652 "OnuId": o.ID,
653 "IntfId": o.PonPortID,
654 "OnuSn": o.Sn(),
655 }).Errorf("Cannot send LOS: %s", err.Error())
656
657 return err
658 }
Himani Chawla13b1ee02021-03-15 01:43:53 +0530659 o.SendOMCIAlarmNotificationMsg(true, losReq.AlarmType)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800660 // TODO if it's the last ONU on the PON, then send a PON LOS
661
Matteo Scandolocedde462021-03-09 17:37:16 -0800662 if err := o.InternalState.Event(OnuTxDisable); err != nil {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800663 onuLogger.WithFields(log.Fields{
664 "OnuId": o.ID,
665 "IntfId": o.PonPortID,
666 "OnuSn": o.Sn(),
667 }).Errorf("Cannot shutdown ONU: %s", err.Error())
668 return err
669 }
670
671 return nil
672}
673
674func (o *Onu) HandlePowerOnONU() error {
675 intitalState := o.InternalState.Current()
676
677 // initialize the ONU
Matteo Scandolocedde462021-03-09 17:37:16 -0800678 if intitalState == OnuStateCreated || intitalState == OnuStateDisabled {
679 if err := o.InternalState.Event(OnuTxInitialize); err != nil {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800680 onuLogger.WithFields(log.Fields{
681 "OnuId": o.ID,
682 "IntfId": o.PonPortID,
683 "OnuSn": o.Sn(),
684 }).Errorf("Cannot poweron ONU: %s", err.Error())
685 return err
686 }
687 }
688
689 // turn off the LOS Alarm
690 losReq := pb.ONUAlarmRequest{
691 AlarmType: "ONU_ALARM_LOS",
692 SerialNumber: o.Sn(),
693 Status: "off",
694 }
695
696 if err := alarmsim.SimulateOnuAlarm(&losReq, o.ID, o.PonPortID, o.PonPort.Olt.channel); err != nil {
697 onuLogger.WithFields(log.Fields{
698 "OnuId": o.ID,
699 "IntfId": o.PonPortID,
700 "OnuSn": o.Sn(),
701 }).Errorf("Cannot send LOS: %s", err.Error())
702 return err
703 }
Himani Chawla13b1ee02021-03-15 01:43:53 +0530704 o.SendOMCIAlarmNotificationMsg(false, losReq.AlarmType)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800705
706 // Send a ONU Discovery indication
Matteo Scandolocedde462021-03-09 17:37:16 -0800707 if err := o.InternalState.Event(OnuTxDiscover); err != nil {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800708 onuLogger.WithFields(log.Fields{
709 "OnuId": o.ID,
710 "IntfId": o.PonPortID,
711 "OnuSn": o.Sn(),
712 }).Errorf("Cannot poweron ONU: %s", err.Error())
713 return err
714 }
715
716 // move o directly to enable state only when its a powercycle case
717 // in case of first time o poweron o will be moved to enable on
718 // receiving ActivateOnu request from openolt adapter
Matteo Scandolocedde462021-03-09 17:37:16 -0800719 if intitalState == OnuStateDisabled {
720 if err := o.InternalState.Event(OnuTxEnable); err != nil {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800721 onuLogger.WithFields(log.Fields{
722 "OnuId": o.ID,
723 "IntfId": o.PonPortID,
724 "OnuSn": o.Sn(),
725 }).Errorf("Cannot enable ONU: %s", err.Error())
726 return err
727 }
728 }
729
730 return nil
731}
732
733func (o *Onu) SetAlarm(alarmType string, status string) error {
734 alarmReq := pb.ONUAlarmRequest{
735 AlarmType: alarmType,
736 SerialNumber: o.Sn(),
737 Status: status,
738 }
739
740 err := alarmsim.SimulateOnuAlarm(&alarmReq, o.ID, o.PonPortID, o.PonPort.Olt.channel)
741 if err != nil {
742 return err
743 }
Himani Chawla13b1ee02021-03-15 01:43:53 +0530744 raiseAlarm := false
745 if alarmReq.Status == "on" {
746 raiseAlarm = true
747 }
748 o.SendOMCIAlarmNotificationMsg(raiseAlarm, alarmReq.AlarmType)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800749 return nil
750}
751
752func (o *Onu) publishOmciEvent(msg bbsim.OmciMessage) {
Pragya Arya324337e2020-02-20 14:35:08 +0530753 if olt.PublishEvents {
Matteo Scandolob5913142021-03-19 16:10:18 -0700754 _, omciMsg, err := omcilib.ParseOpenOltOmciPacket(msg.OmciPkt.Data())
Pragya Arya324337e2020-02-20 14:35:08 +0530755 if err != nil {
756 log.Errorf("error in getting msgType %v", err)
757 return
758 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800759 if omciMsg.MessageType == omci.MibUploadRequestType {
Pragya Arya324337e2020-02-20 14:35:08 +0530760 o.seqNumber = 0
761 publishEvent("MIB-upload-received", int32(o.PonPortID), int32(o.ID), common.OnuSnToString(o.SerialNumber))
Matteo Scandolof9d43412021-01-12 11:11:34 -0800762 } else if omciMsg.MessageType == omci.MibUploadNextRequestType {
Pragya Arya324337e2020-02-20 14:35:08 +0530763 o.seqNumber++
764 if o.seqNumber > 290 {
765 publishEvent("MIB-upload-done", int32(o.PonPortID), int32(o.ID), common.OnuSnToString(o.SerialNumber))
766 }
767 }
768 }
769}
770
Matteo Scandolof9d43412021-01-12 11:11:34 -0800771// handleOmciRequest is responsible to parse the OMCI packets received from the openolt adapter
772// and generate the appropriate response to it
Andrea Campanellabe1b7cf2021-04-30 09:53:40 +0200773func (o *Onu) handleOmciRequest(msg bbsim.OmciMessage, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800774
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700775 onuLogger.WithFields(log.Fields{
Matteo Scandolob5913142021-03-19 16:10:18 -0700776 "omciMsgType": msg.OmciMsg.MessageType,
777 "transCorrId": strconv.FormatInt(int64(msg.OmciMsg.TransactionID), 16),
778 "DeviceIdent": msg.OmciMsg.DeviceIdentifier,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700779 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700780 "SerialNumber": o.Sn(),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800781 }).Trace("omci-message-decoded")
782
Holger Hildebrandtc10bab12021-04-27 09:23:48 +0000783 if o.OmciMsgCounter < maxOmciMsgCounter {
784 o.OmciMsgCounter++
785 } else {
786 o.OmciMsgCounter = 1
787 }
788 if o.OmciMsgCounter > o.OmciResponseRate {
789 onuLogger.WithFields(log.Fields{
790 "OmciMsgCounter": o.OmciMsgCounter,
791 "OmciResponseRate": o.OmciResponseRate,
792 "omciMsgType": msg.OmciMsg.MessageType,
Matteo Scandoloa96e2242021-09-28 10:13:17 -0700793 "txId": msg.OmciMsg.TransactionID,
Andrea Campanellabe1b7cf2021-04-30 09:53:40 +0200794 }).Debug("skipping-omci-msg-response")
795 return fmt.Errorf("skipping-omci-msg-response-because-of-response-rate-%d", o.OmciResponseRate)
Holger Hildebrandtc10bab12021-04-27 09:23:48 +0000796 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800797 var responsePkt []byte
Girish Gowdrae2683102021-03-05 08:24:26 -0800798 var errResp error
Matteo Scandolob5913142021-03-19 16:10:18 -0700799 switch msg.OmciMsg.MessageType {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800800 case omci.MibResetRequestType:
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800801 onuLogger.WithFields(log.Fields{
802 "IntfId": o.PonPortID,
803 "OnuId": o.ID,
804 "SerialNumber": o.Sn(),
Matteo Scandolo2fdc3b82021-04-23 15:27:21 -0700805 }).Debug("received-mib-reset-request")
Matteo Scandolob5913142021-03-19 16:10:18 -0700806 if responsePkt, errResp = omcilib.CreateMibResetResponse(msg.OmciMsg.TransactionID); errResp == nil {
Girish Gowdrae2683102021-03-05 08:24:26 -0800807 o.MibDataSync = 0
Matteo Scandolo2fdc3b82021-04-23 15:27:21 -0700808
809 // if the MIB reset is successful then remove all the stored AllocIds and GemPorts
Andrea Campanellabef00d52022-02-04 09:47:52 +0100810 o.PonPort.removeAllocId(o.SerialNumber)
Matteo Scandolo2fdc3b82021-04-23 15:27:21 -0700811 o.PonPort.removeGemPortBySn(o.SerialNumber)
Girish Gowdrae2683102021-03-05 08:24:26 -0800812 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800813 case omci.MibUploadRequestType:
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700814 responsePkt, _ = omcilib.CreateMibUploadResponse(msg.OmciMsg.TransactionID, o.MibDb.NumberOfCommands)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800815 case omci.MibUploadNextRequestType:
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700816 responsePkt, _ = omcilib.CreateMibUploadNextResponse(msg.OmciPkt, msg.OmciMsg, o.MibDataSync, o.MibDb)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800817 case omci.GetRequestType:
Girish Gowdra1ddcb202021-06-25 12:17:09 -0700818 onuDown := o.AdminLockState == 1
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700819 responsePkt, _ = omcilib.CreateGetResponse(msg.OmciPkt, msg.OmciMsg, o.SerialNumber, o.MibDataSync, o.ActiveImageEntityId,
820 o.CommittedImageEntityId, o.StandbyImageVersion, o.ActiveImageVersion, o.CommittedImageVersion, onuDown)
Himani Chawla908a1f52022-01-27 14:39:44 +0530821
Matteo Scandolof9d43412021-01-12 11:11:34 -0800822 case omci.SetRequestType:
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800823 success := true
Matteo Scandolob5913142021-03-19 16:10:18 -0700824 msgObj, _ := omcilib.ParseSetRequest(msg.OmciPkt)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800825 switch msgObj.EntityClass {
826 case me.PhysicalPathTerminationPointEthernetUniClassID:
827 // if we're Setting a PPTP state
Matteo Scandolo8a574812021-05-20 15:18:53 -0700828 // we need to send the appropriate alarm (handled in the UNI struct)
829 uni, err := o.FindUniByEntityId(msgObj.EntityInstance)
830 if err != nil {
831 onuLogger.Error(err)
832 success = false
833 } else {
834 // 1 locks the UNI, 0 unlocks it
Elia Battiston9bfe1102022-02-03 10:38:03 +0100835 adminState := msgObj.Attributes[me.PhysicalPathTerminationPointEthernetUni_AdministrativeState].(uint8)
Matteo Scandolo8a574812021-05-20 15:18:53 -0700836 var err error
Himani Chawla13b1ee02021-03-15 01:43:53 +0530837 if adminState == 1 {
Matteo Scandolo8a574812021-05-20 15:18:53 -0700838 err = uni.Disable()
Girish Gowdra996d81e2021-04-21 16:16:27 -0700839 } else {
Matteo Scandolo8a574812021-05-20 15:18:53 -0700840 err = uni.Enable()
Himani Chawla13b1ee02021-03-15 01:43:53 +0530841 }
Matteo Scandolo8a574812021-05-20 15:18:53 -0700842 if err != nil {
843 onuLogger.WithFields(log.Fields{
844 "IntfId": o.PonPortID,
845 "OnuId": o.ID,
846 "UniMeId": uni.MeId,
847 "UniId": uni.ID,
848 "SerialNumber": o.Sn(),
849 "Err": err.Error(),
850 }).Warn("cannot-change-uni-status")
Matteo Scandolof9d43412021-01-12 11:11:34 -0800851 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800852 }
Elia Battistonac63b112022-01-12 18:40:49 +0100853 case me.PhysicalPathTerminationPointPotsUniClassID:
854 // if we're Setting a PPTP state
855 // we need to send the appropriate alarm (handled in the POTS struct)
856 pots, err := o.FindPotsByEntityId(msgObj.EntityInstance)
857 if err != nil {
858 onuLogger.Error(err)
859 success = false
860 } else {
861 // 1 locks the UNI, 0 unlocks it
Elia Battiston9bfe1102022-02-03 10:38:03 +0100862 adminState := msgObj.Attributes[me.PhysicalPathTerminationPointPotsUni_AdministrativeState].(uint8)
Elia Battistonac63b112022-01-12 18:40:49 +0100863 var err error
864 if adminState == 1 {
865 err = pots.Disable()
866 } else {
867 err = pots.Enable()
868 }
869 if err != nil {
870 onuLogger.WithFields(log.Fields{
871 "IntfId": o.PonPortID,
872 "OnuId": o.ID,
873 "PotsMeId": pots.MeId,
874 "PotsId": pots.ID,
875 "SerialNumber": o.Sn(),
876 "Err": err.Error(),
877 }).Warn("cannot-change-pots-status")
878 }
879 }
Girish Gowdra1ddcb202021-06-25 12:17:09 -0700880 case me.OnuGClassID:
Elia Battiston9bfe1102022-02-03 10:38:03 +0100881 o.AdminLockState = msgObj.Attributes[me.OnuG_AdministrativeState].(uint8)
Girish Gowdra1ddcb202021-06-25 12:17:09 -0700882 onuLogger.WithFields(log.Fields{
883 "IntfId": o.PonPortID,
884 "OnuId": o.ID,
885 "SerialNumber": o.Sn(),
886 "AdminLockState": o.AdminLockState,
887 }).Debug("set-onu-admin-lock-state")
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800888 case me.TContClassID:
Elia Battiston9bfe1102022-02-03 10:38:03 +0100889 allocId := msgObj.Attributes[me.TCont_AllocId].(uint16)
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800890
891 // if the AllocId is 255 (0xFF) or 65535 (0xFFFF) it means we are removing it,
892 // otherwise we are adding it
893 if allocId == 255 || allocId == 65535 {
894 onuLogger.WithFields(log.Fields{
895 "IntfId": o.PonPortID,
896 "OnuId": o.ID,
897 "TContId": msgObj.EntityInstance,
898 "AllocId": allocId,
899 "SerialNumber": o.Sn(),
900 }).Trace("freeing-alloc-id-via-omci")
Andrea Campanellabef00d52022-02-04 09:47:52 +0100901 o.PonPort.removeAllocId(o.SerialNumber)
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800902 } else {
Andrea Campanellabef00d52022-02-04 09:47:52 +0100903 if used, sn := o.PonPort.isAllocIdAllocated(allocId); used {
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800904 onuLogger.WithFields(log.Fields{
905 "IntfId": o.PonPortID,
906 "OnuId": o.ID,
907 "AllocId": allocId,
908 "SerialNumber": o.Sn(),
Andrea Campanellabef00d52022-02-04 09:47:52 +0100909 }).Errorf("allocid-already-allocated-to-onu-with-sn-%s", common.OnuSnToString(sn))
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800910 success = false
911 } else {
912 onuLogger.WithFields(log.Fields{
913 "IntfId": o.PonPortID,
914 "OnuId": o.ID,
915 "TContId": msgObj.EntityInstance,
916 "AllocId": allocId,
917 "SerialNumber": o.Sn(),
918 }).Trace("storing-alloc-id-via-omci")
Andrea Campanellabef00d52022-02-04 09:47:52 +0100919 o.PonPort.storeAllocId(allocId, o.SerialNumber)
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800920 }
921 }
Himani Chawla908a1f52022-01-27 14:39:44 +0530922 case me.EthernetFrameExtendedPmClassID,
923 me.EthernetFrameExtendedPm64BitClassID:
924 onuLogger.WithFields(log.Fields{
925 "me-instance": msgObj.EntityInstance,
926 }).Debug("set-request-received")
927 // No need to reset counters as onu adapter will simply send the set control block request to actually reset
928 // the counters, and respond with 0's without sending the get request to device.
929 // Also, if we even reset the counters here in cache, then on get we need to restore the counters back which
930 // would be of no use as ultimately the counters need to be restored.
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800931 }
932
933 if success {
Matteo Scandolob5913142021-03-19 16:10:18 -0700934 if responsePkt, errResp = omcilib.CreateSetResponse(msg.OmciPkt, msg.OmciMsg, me.Success); errResp == nil {
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800935 o.MibDataSync++
936 }
937 } else {
Matteo Scandolob5913142021-03-19 16:10:18 -0700938 responsePkt, _ = omcilib.CreateSetResponse(msg.OmciPkt, msg.OmciMsg, me.AttributeFailure)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800939 }
940 case omci.CreateRequestType:
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800941 // check for GemPortNetworkCtp and make sure there are no duplicates on the same PON
942 var used bool
943 var sn *openolt.SerialNumber
Matteo Scandolob5913142021-03-19 16:10:18 -0700944 msgObj, err := omcilib.ParseCreateRequest(msg.OmciPkt)
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800945 if err == nil {
946 if msgObj.EntityClass == me.GemPortNetworkCtpClassID {
Matteo Scandolo973b0182021-04-08 11:24:42 -0700947 // GemPort 4069 is reserved for multicast and shared across ONUs
948 if msgObj.EntityInstance != 4069 {
949 if used, sn = o.PonPort.isGemPortAllocated(msgObj.EntityInstance); used {
950 onuLogger.WithFields(log.Fields{
951 "IntfId": o.PonPortID,
952 "OnuId": o.ID,
953 "GemPortId": msgObj.EntityInstance,
954 "SerialNumber": o.Sn(),
955 }).Errorf("gemport-already-allocated-to-onu-with-sn-%s", common.OnuSnToString(sn))
956 } else {
957 onuLogger.WithFields(log.Fields{
958 "IntfId": o.PonPortID,
959 "OnuId": o.ID,
960 "GemPortId": msgObj.EntityInstance,
961 "SerialNumber": o.Sn(),
962 }).Trace("storing-gem-port-id-via-omci")
963 o.PonPort.storeGemPort(msgObj.EntityInstance, o.SerialNumber)
964 }
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800965 }
966 }
967 }
968
969 // if the gemPort is valid then increment the MDS and return a successful response
970 // otherwise fail the request
971 // for now the CreateRequeste for the gemPort is the only one that can fail, if we start supporting multiple
972 // validation this check will need to be rewritten
973 if !used {
Matteo Scandolob5913142021-03-19 16:10:18 -0700974 if responsePkt, errResp = omcilib.CreateCreateResponse(msg.OmciPkt, msg.OmciMsg, me.Success); errResp == nil {
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800975 o.MibDataSync++
976 }
977 } else {
Matteo Scandolob5913142021-03-19 16:10:18 -0700978 responsePkt, _ = omcilib.CreateCreateResponse(msg.OmciPkt, msg.OmciMsg, me.ProcessingError)
Girish Gowdrae2683102021-03-05 08:24:26 -0800979 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800980 case omci.DeleteRequestType:
Matteo Scandolob5913142021-03-19 16:10:18 -0700981 msgObj, err := omcilib.ParseDeleteRequest(msg.OmciPkt)
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800982 if err == nil {
983 if msgObj.EntityClass == me.GemPortNetworkCtpClassID {
984 onuLogger.WithFields(log.Fields{
985 "IntfId": o.PonPortID,
986 "OnuId": o.ID,
987 "GemPortId": msgObj.EntityInstance,
988 "SerialNumber": o.Sn(),
989 }).Trace("freeing-gem-port-id-via-omci")
990 o.PonPort.removeGemPort(msgObj.EntityInstance)
991 }
992 }
993
Matteo Scandolob5913142021-03-19 16:10:18 -0700994 if responsePkt, errResp = omcilib.CreateDeleteResponse(msg.OmciPkt, msg.OmciMsg); errResp == nil {
Girish Gowdrae2683102021-03-05 08:24:26 -0800995 o.MibDataSync++
996 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800997 case omci.RebootRequestType:
998
Matteo Scandolob5913142021-03-19 16:10:18 -0700999 responsePkt, _ = omcilib.CreateRebootResponse(msg.OmciPkt, msg.OmciMsg)
Matteo Scandolof9d43412021-01-12 11:11:34 -08001000
1001 // powercycle the ONU
Matteo Scandolocedde462021-03-09 17:37:16 -08001002 // we run this in a separate goroutine so that
1003 // the RebootRequestResponse is sent to VOLTHA
Matteo Scandolof9d43412021-01-12 11:11:34 -08001004 go func() {
Matteo Scandolocedde462021-03-09 17:37:16 -08001005 if err := o.Reboot(10 * time.Second); err != nil {
1006 log.WithFields(log.Fields{
1007 "IntfId": o.PonPortID,
1008 "OnuId": o.ID,
1009 "SerialNumber": o.Sn(),
1010 "err": err,
1011 }).Error("cannot-reboot-onu-after-omci-reboot-request")
1012 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001013 }()
1014 case omci.TestRequestType:
Girish Gowdra161d27a2021-05-05 12:01:44 -07001015 var classID me.ClassID
1016 var omciResult me.Results
1017 var instID uint16
1018 responsePkt, errResp, classID, instID, omciResult = omcilib.CreateTestResponse(msg.OmciPkt, msg.OmciMsg)
1019 // Send TestResult only in case the TestResponse omci result code is me.Success
1020 if responsePkt != nil && errResp == nil && omciResult == me.Success {
1021 if testResultPkt, err := omcilib.CreateTestResult(classID, instID, msg.OmciMsg.TransactionID); err == nil {
1022 // send test results asynchronously
1023 go func() {
1024 // Send test results after a second to emulate async behavior
1025 time.Sleep(1 * time.Second)
1026 if testResultPkt != nil {
1027 if err := o.sendOmciIndication(testResultPkt, msg.OmciMsg.TransactionID, stream); err != nil {
1028 onuLogger.WithFields(log.Fields{
1029 "IntfId": o.PonPortID,
1030 "SerialNumber": o.Sn(),
1031 "omciPacket": testResultPkt,
1032 "msg.OmciMsgType": msg.OmciMsg.MessageType,
1033 "transCorrId": msg.OmciMsg.TransactionID,
1034 }).Errorf("failed-to-send-omci-message: %v", err)
1035 }
1036 }
1037 }()
Matteo Scandolof9d43412021-01-12 11:11:34 -08001038 }
1039 }
Girish Gowdraa539f522021-02-15 23:00:45 -08001040 case omci.SynchronizeTimeRequestType:
1041 // MDS counter increment is not required for this message type
Matteo Scandolob5913142021-03-19 16:10:18 -07001042 responsePkt, _ = omcilib.CreateSyncTimeResponse(msg.OmciPkt, msg.OmciMsg)
Matteo Scandolocedde462021-03-09 17:37:16 -08001043 case omci.StartSoftwareDownloadRequestType:
1044
1045 o.ImageSoftwareReceivedSections = 0
Himani Chawla4ff5fab2021-11-09 19:19:29 +05301046 o.ImageSectionData = []byte{}
Matteo Scandolob5913142021-03-19 16:10:18 -07001047 o.ImageSoftwareExpectedSections = omcilib.ComputeDownloadSectionsCount(msg.OmciPkt)
Matteo Scandolocedde462021-03-09 17:37:16 -08001048
Matteo Scandolob5913142021-03-19 16:10:18 -07001049 if responsePkt, errResp = omcilib.CreateStartSoftwareDownloadResponse(msg.OmciPkt, msg.OmciMsg); errResp == nil {
Matteo Scandolocedde462021-03-09 17:37:16 -08001050 o.MibDataSync++
1051 if err := o.InternalState.Event(OnuTxStartImageDownload); err != nil {
1052 onuLogger.WithFields(log.Fields{
1053 "OnuId": o.ID,
1054 "IntfId": o.PonPortID,
1055 "OnuSn": o.Sn(),
1056 "Err": err.Error(),
1057 }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageDownloadStarted)
1058 }
1059 } else {
1060 onuLogger.WithFields(log.Fields{
Matteo Scandolob5913142021-03-19 16:10:18 -07001061 "OmciMsgType": msg.OmciMsg.MessageType,
1062 "TransCorrId": msg.OmciMsg.TransactionID,
1063 "Err": errResp.Error(),
Matteo Scandolocedde462021-03-09 17:37:16 -08001064 "IntfId": o.PonPortID,
1065 "SerialNumber": o.Sn(),
1066 }).Error("error-while-processing-start-software-download-request")
1067 }
1068 case omci.DownloadSectionRequestType:
Matteo Scandolob5913142021-03-19 16:10:18 -07001069 if msgObj, err := omcilib.ParseDownloadSectionRequest(msg.OmciPkt); err == nil {
Matteo Scandolocedde462021-03-09 17:37:16 -08001070 onuLogger.WithFields(log.Fields{
Matteo Scandolob5913142021-03-19 16:10:18 -07001071 "OmciMsgType": msg.OmciMsg.MessageType,
1072 "TransCorrId": msg.OmciMsg.TransactionID,
Matteo Scandolocedde462021-03-09 17:37:16 -08001073 "EntityInstance": msgObj.EntityInstance,
1074 "SectionNumber": msgObj.SectionNumber,
1075 "SectionData": msgObj.SectionData,
1076 }).Trace("received-download-section-request")
Matteo Scandoloc00e97a2021-05-27 11:45:27 -07001077 //Extracting the first 14 bytes to use as a version for this image.
1078 if o.ImageSoftwareReceivedSections == 0 {
Matteo Scandolo76f6b892021-11-15 16:13:06 -08001079 o.InDownloadImageVersion = string(msgObj.SectionData[0:14])
Matteo Scandoloc00e97a2021-05-27 11:45:27 -07001080 }
Himani Chawla4ff5fab2021-11-09 19:19:29 +05301081 o.ImageSectionData = append(o.ImageSectionData, msgObj.SectionData...)
Matteo Scandolocedde462021-03-09 17:37:16 -08001082 o.ImageSoftwareReceivedSections++
1083 if o.InternalState.Current() != OnuStateImageDownloadInProgress {
1084 if err := o.InternalState.Event(OnuTxProgressImageDownload); err != nil {
1085 onuLogger.WithFields(log.Fields{
1086 "OnuId": o.ID,
1087 "IntfId": o.PonPortID,
1088 "OnuSn": o.Sn(),
1089 "Err": err.Error(),
1090 }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageDownloadInProgress)
1091 }
1092 }
1093 }
1094 case omci.DownloadSectionRequestWithResponseType:
1095 // NOTE we only need to respond if an ACK is requested
Himani Chawla4ff5fab2021-11-09 19:19:29 +05301096 if msgObj, err := omcilib.ParseDownloadSectionRequest(msg.OmciPkt); err == nil {
Matteo Scandolocedde462021-03-09 17:37:16 -08001097 onuLogger.WithFields(log.Fields{
Himani Chawla4ff5fab2021-11-09 19:19:29 +05301098 "OmciMsgType": msg.OmciMsg.MessageType,
1099 "TransCorrId": msg.OmciMsg.TransactionID,
1100 "EntityInstance": msgObj.EntityInstance,
1101 "SectionNumber": msgObj.SectionNumber,
1102 "SectionData": msgObj.SectionData,
1103 }).Trace("received-download-section-request-with-response-type")
1104 o.ImageSectionData = append(o.ImageSectionData, msgObj.SectionData...)
1105 responsePkt, errResp = omcilib.CreateDownloadSectionResponse(msg.OmciPkt, msg.OmciMsg)
1106
1107 if errResp != nil {
1108 onuLogger.WithFields(log.Fields{
1109 "OmciMsgType": msg.OmciMsg.MessageType,
1110 "TransCorrId": msg.OmciMsg.TransactionID,
1111 "Err": errResp.Error(),
1112 "IntfId": o.PonPortID,
1113 "SerialNumber": o.Sn(),
1114 }).Error("error-while-processing-create-download-section-response")
1115 return fmt.Errorf("error-while-processing-create-download-section-response: %s", errResp.Error())
1116 }
1117 o.ImageSoftwareReceivedSections++
Matteo Scandolocedde462021-03-09 17:37:16 -08001118 }
Matteo Scandolocedde462021-03-09 17:37:16 -08001119 case omci.EndSoftwareDownloadRequestType:
Matteo Scandolo76f6b892021-11-15 16:13:06 -08001120 success := o.handleEndSoftwareDownloadRequest(msg)
Matteo Scandolocedde462021-03-09 17:37:16 -08001121
Matteo Scandolocedde462021-03-09 17:37:16 -08001122 if success {
Matteo Scandolob5913142021-03-19 16:10:18 -07001123 if responsePkt, errResp = omcilib.CreateEndSoftwareDownloadResponse(msg.OmciPkt, msg.OmciMsg, me.Success); errResp == nil {
Matteo Scandolocedde462021-03-09 17:37:16 -08001124 o.MibDataSync++
1125 if err := o.InternalState.Event(OnuTxCompleteImageDownload); err != nil {
1126 onuLogger.WithFields(log.Fields{
1127 "OnuId": o.ID,
1128 "IntfId": o.PonPortID,
1129 "OnuSn": o.Sn(),
1130 "Err": err.Error(),
1131 }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageDownloadComplete)
1132 }
1133 } else {
1134 onuLogger.WithFields(log.Fields{
Matteo Scandolob5913142021-03-19 16:10:18 -07001135 "OmciMsgType": msg.OmciMsg.MessageType,
1136 "TransCorrId": msg.OmciMsg.TransactionID,
1137 "Err": errResp.Error(),
Matteo Scandolocedde462021-03-09 17:37:16 -08001138 "IntfId": o.PonPortID,
1139 "SerialNumber": o.Sn(),
Matteo Scandolo76f6b892021-11-15 16:13:06 -08001140 }).Error("error-while-responding-to-end-software-download-request")
Matteo Scandolocedde462021-03-09 17:37:16 -08001141 }
1142 } else {
Matteo Scandolob5913142021-03-19 16:10:18 -07001143 if responsePkt, errResp = omcilib.CreateEndSoftwareDownloadResponse(msg.OmciPkt, msg.OmciMsg, me.ProcessingError); errResp == nil {
Matteo Scandolocedde462021-03-09 17:37:16 -08001144 if err := o.InternalState.Event(OnuTxFailImageDownload); err != nil {
1145 onuLogger.WithFields(log.Fields{
1146 "OnuId": o.ID,
1147 "IntfId": o.PonPortID,
1148 "OnuSn": o.Sn(),
1149 "Err": err.Error(),
1150 }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageDownloadError)
1151 }
1152 }
1153 }
Matteo Scandolocedde462021-03-09 17:37:16 -08001154 case omci.ActivateSoftwareRequestType:
Matteo Scandolob5913142021-03-19 16:10:18 -07001155 if responsePkt, errResp = omcilib.CreateActivateSoftwareResponse(msg.OmciPkt, msg.OmciMsg); errResp == nil {
Matteo Scandolocedde462021-03-09 17:37:16 -08001156 o.MibDataSync++
1157 if err := o.InternalState.Event(OnuTxActivateImage); err != nil {
1158 onuLogger.WithFields(log.Fields{
1159 "OnuId": o.ID,
1160 "IntfId": o.PonPortID,
1161 "OnuSn": o.Sn(),
1162 "Err": err.Error(),
1163 }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageActivated)
1164 }
Matteo Scandolob5913142021-03-19 16:10:18 -07001165 if msgObj, err := omcilib.ParseActivateSoftwareRequest(msg.OmciPkt); err == nil {
Matteo Scandolocedde462021-03-09 17:37:16 -08001166 o.ActiveImageEntityId = msgObj.EntityInstance
Matteo Scandoloc00e97a2021-05-27 11:45:27 -07001167 previousActiveImage := o.ActiveImageVersion
1168 o.ActiveImageVersion = o.StandbyImageVersion
1169 o.StandbyImageVersion = previousActiveImage
Matteo Scandolocedde462021-03-09 17:37:16 -08001170 } else {
1171 onuLogger.Errorf("something-went-wrong-while-activating: %s", err)
1172 }
1173 onuLogger.WithFields(log.Fields{
1174 "OnuId": o.ID,
1175 "IntfId": o.PonPortID,
1176 "OnuSn": o.Sn(),
1177 "ActiveImageEntityId": o.ActiveImageEntityId,
1178 "CommittedImageEntityId": o.CommittedImageEntityId,
1179 }).Info("onu-software-image-activated")
1180
1181 // powercycle the ONU
1182 // we run this in a separate goroutine so that
1183 // the ActivateSoftwareResponse is sent to VOLTHA
1184 // NOTE do we need to wait before rebooting?
1185 go func() {
1186 if err := o.Reboot(10 * time.Second); err != nil {
1187 log.WithFields(log.Fields{
1188 "IntfId": o.PonPortID,
1189 "OnuId": o.ID,
1190 "SerialNumber": o.Sn(),
1191 "err": err,
1192 }).Error("cannot-reboot-onu-after-omci-activate-software-request")
1193 }
1194 }()
1195 }
1196 case omci.CommitSoftwareRequestType:
Matteo Scandolob5913142021-03-19 16:10:18 -07001197 if responsePkt, errResp = omcilib.CreateCommitSoftwareResponse(msg.OmciPkt, msg.OmciMsg); errResp == nil {
Matteo Scandolocedde462021-03-09 17:37:16 -08001198 o.MibDataSync++
Matteo Scandolob5913142021-03-19 16:10:18 -07001199 if msgObj, err := omcilib.ParseCommitSoftwareRequest(msg.OmciPkt); err == nil {
Matteo Scandolocedde462021-03-09 17:37:16 -08001200 // TODO validate that the image to commit is:
1201 // - active
1202 // - not already committed
Matteo Scandoloc00e97a2021-05-27 11:45:27 -07001203 o.ActiveImageEntityId = msgObj.EntityInstance
Matteo Scandolocedde462021-03-09 17:37:16 -08001204 o.CommittedImageEntityId = msgObj.EntityInstance
Matteo Scandoloc00e97a2021-05-27 11:45:27 -07001205 //committed becomes standby
1206 o.StandbyImageVersion = o.CommittedImageVersion
1207 o.CommittedImageVersion = o.ActiveImageVersion
Matteo Scandolocedde462021-03-09 17:37:16 -08001208 } else {
1209 onuLogger.Errorf("something-went-wrong-while-committing: %s", err)
1210 }
1211 if err := o.InternalState.Event(OnuTxCommitImage); err != nil {
1212 onuLogger.WithFields(log.Fields{
1213 "OnuId": o.ID,
1214 "IntfId": o.PonPortID,
1215 "OnuSn": o.Sn(),
1216 "Err": err.Error(),
1217 }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageCommitted)
1218 }
1219 onuLogger.WithFields(log.Fields{
1220 "OnuId": o.ID,
1221 "IntfId": o.PonPortID,
1222 "OnuSn": o.Sn(),
1223 "ActiveImageEntityId": o.ActiveImageEntityId,
1224 "CommittedImageEntityId": o.CommittedImageEntityId,
1225 }).Info("onu-software-image-committed")
1226 }
Himani Chawla13b1ee02021-03-15 01:43:53 +05301227 case omci.GetAllAlarmsRequestType:
1228 // Reset the alarm sequence number on receiving get all alarms request.
1229 o.onuAlarmsInfoLock.Lock()
1230 for key, alarmInfo := range o.onuAlarmsInfo {
1231 // reset the alarm sequence no
1232 alarmInfo.SequenceNo = 0
1233 o.onuAlarmsInfo[key] = alarmInfo
1234 }
1235 o.onuAlarmsInfoLock.Unlock()
Matteo Scandolob5913142021-03-19 16:10:18 -07001236 responsePkt, _ = omcilib.CreateGetAllAlarmsResponse(msg.OmciMsg.TransactionID, o.onuAlarmsInfo)
Himani Chawla13b1ee02021-03-15 01:43:53 +05301237 case omci.GetAllAlarmsNextRequestType:
Matteo Scandolob5913142021-03-19 16:10:18 -07001238 if responsePkt, errResp = omcilib.CreateGetAllAlarmsNextResponse(msg.OmciPkt, msg.OmciMsg, o.onuAlarmsInfo); errResp != nil {
Himani Chawla13b1ee02021-03-15 01:43:53 +05301239 responsePkt = nil //Do not send any response for error case
1240 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001241 default:
Matteo Scandolocedde462021-03-09 17:37:16 -08001242 onuLogger.WithFields(log.Fields{
Matteo Scandolob5913142021-03-19 16:10:18 -07001243 "omciBytes": hex.EncodeToString(msg.OmciPkt.Data()),
1244 "omciPkt": msg.OmciPkt,
1245 "omciMsgType": msg.OmciMsg.MessageType,
1246 "transCorrId": msg.OmciMsg.TransactionID,
Matteo Scandolof9d43412021-01-12 11:11:34 -08001247 "IntfId": o.PonPortID,
1248 "SerialNumber": o.Sn(),
1249 }).Warnf("OMCI-message-not-supported")
1250 }
1251
1252 if responsePkt != nil {
Matteo Scandolob5913142021-03-19 16:10:18 -07001253 if err := o.sendOmciIndication(responsePkt, msg.OmciMsg.TransactionID, stream); err != nil {
Matteo Scandolof9d43412021-01-12 11:11:34 -08001254 onuLogger.WithFields(log.Fields{
Matteo Scandolob5913142021-03-19 16:10:18 -07001255 "IntfId": o.PonPortID,
1256 "SerialNumber": o.Sn(),
1257 "omciPacket": responsePkt,
1258 "msg.OmciMsgType": msg.OmciMsg.MessageType,
1259 "transCorrId": msg.OmciMsg.TransactionID,
Matteo Scandolof9d43412021-01-12 11:11:34 -08001260 }).Errorf("failed-to-send-omci-message: %v", err)
1261 }
1262 }
Matteo Scandoloc559ef12019-08-20 13:24:21 -07001263
Pragya Arya324337e2020-02-20 14:35:08 +05301264 o.publishOmciEvent(msg)
Andrea Campanellabe1b7cf2021-04-30 09:53:40 +02001265 return nil
Matteo Scandolof9d43412021-01-12 11:11:34 -08001266}
Pragya Arya324337e2020-02-20 14:35:08 +05301267
Matteo Scandolof9d43412021-01-12 11:11:34 -08001268// sendOmciIndication takes an OMCI packet and sends it up to VOLTHA
1269func (o *Onu) sendOmciIndication(responsePkt []byte, txId uint16, stream bbsim.Stream) error {
1270 indication := &openolt.Indication_OmciInd{
1271 OmciInd: &openolt.OmciIndication{
1272 IntfId: o.PonPortID,
1273 OnuId: o.ID,
1274 Pkt: responsePkt,
1275 },
Matteo Scandoloc559ef12019-08-20 13:24:21 -07001276 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001277 if err := stream.Send(&openolt.Indication{Data: indication}); err != nil {
1278 return fmt.Errorf("failed-to-send-omci-message: %v", err)
Matteo Scandoloc559ef12019-08-20 13:24:21 -07001279 }
1280 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001281 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -07001282 "SerialNumber": o.Sn(),
Matteo Scandolof9d43412021-01-12 11:11:34 -08001283 "omciPacket": indication.OmciInd.Pkt,
1284 "transCorrId": txId,
1285 }).Trace("omci-message-sent")
1286 return nil
Matteo Scandoloc559ef12019-08-20 13:24:21 -07001287}
1288
Matteo Scandolo8a574812021-05-20 15:18:53 -07001289// FindUniById retrieves a UNI by ID
1290func (o *Onu) FindUniById(uniID uint32) (*UniPort, error) {
1291 for _, u := range o.UniPorts {
1292 uni := u.(*UniPort)
1293 if uni.ID == uniID {
1294 return uni, nil
1295 }
Matteo Scandolo27428702019-10-11 16:21:16 -07001296 }
Matteo Scandolo8a574812021-05-20 15:18:53 -07001297 return nil, fmt.Errorf("cannot-find-uni-with-id-%d-on-onu-%s", uniID, o.Sn())
1298}
1299
Elia Battistonac63b112022-01-12 18:40:49 +01001300// FindPotsById retrieves a POTS port by ID
1301func (o *Onu) FindPotsById(uniID uint32) (*PotsPort, error) {
1302 for _, p := range o.PotsPorts {
1303 pots := p.(*PotsPort)
1304 if pots.ID == uniID {
1305 return pots, nil
1306 }
1307 }
1308 return nil, fmt.Errorf("cannot-find-pots-with-id-%d-on-onu-%s", uniID, o.Sn())
1309}
1310
Matteo Scandolo8a574812021-05-20 15:18:53 -07001311// FindUniByEntityId retrieves a uni by MeID (the OMCI entity ID)
1312func (o *Onu) FindUniByEntityId(meId uint16) (*UniPort, error) {
1313 entityId := omcilib.EntityID{}.FromUint16(meId)
1314 for _, u := range o.UniPorts {
1315 uni := u.(*UniPort)
1316 if uni.MeId.Equals(entityId) {
1317 return uni, nil
1318 }
1319 }
1320 return nil, fmt.Errorf("cannot-find-uni-with-meid-%s-on-onu-%s", entityId.ToString(), o.Sn())
Matteo Scandolo27428702019-10-11 16:21:16 -07001321}
1322
Elia Battistonac63b112022-01-12 18:40:49 +01001323// FindPotsByEntityId retrieves a POTS uni by MeID (the OMCI entity ID)
1324func (o *Onu) FindPotsByEntityId(meId uint16) (*PotsPort, error) {
1325 entityId := omcilib.EntityID{}.FromUint16(meId)
1326 for _, p := range o.PotsPorts {
1327 pots := p.(*PotsPort)
1328 if pots.MeId.Equals(entityId) {
1329 return pots, nil
1330 }
1331 }
1332 return nil, fmt.Errorf("cannot-find-pots-with-meid-%s-on-onu-%s", entityId.ToString(), o.Sn())
1333}
1334
William Kurkian0418bc82019-11-06 12:16:24 -05001335func (o *Onu) SetID(id uint32) {
Matteo Scandolo583f17d2020-02-13 10:35:17 -08001336 onuLogger.WithFields(log.Fields{
1337 "IntfId": o.PonPortID,
1338 "OnuId": id,
1339 "SerialNumber": o.Sn(),
1340 }).Debug("Storing OnuId ")
William Kurkian0418bc82019-11-06 12:16:24 -05001341 o.ID = id
1342}
1343
Matteo Scandolof9d43412021-01-12 11:11:34 -08001344func (o *Onu) handleFlowAdd(msg bbsim.OnuFlowUpdateMessage) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -07001345 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001346 "AllocId": msg.Flow.AllocId,
Matteo Scandoloedf30c72020-09-18 18:15:28 -07001347 "Cookie": msg.Flow.Cookie,
1348 "DstPort": msg.Flow.Classifier.DstPort,
1349 "FlowId": msg.Flow.FlowId,
1350 "FlowType": msg.Flow.FlowType,
1351 "GemportId": msg.Flow.GemportId,
1352 "InnerVlan": msg.Flow.Classifier.IVid,
1353 "IntfId": msg.Flow.AccessIntfId,
1354 "IpProto": msg.Flow.Classifier.IpProto,
1355 "OnuId": msg.Flow.OnuId,
1356 "OnuSn": o.Sn(),
1357 "OuterVlan": msg.Flow.Classifier.OVid,
1358 "PortNo": msg.Flow.PortNo,
1359 "SrcPort": msg.Flow.Classifier.SrcPort,
1360 "UniID": msg.Flow.UniId,
1361 "ClassifierEthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType),
1362 "ClassifierOPbits": msg.Flow.Classifier.OPbits,
1363 "ClassifierIVid": msg.Flow.Classifier.IVid,
1364 "ClassifierOVid": msg.Flow.Classifier.OVid,
Matteo Scandolo4f4ac792020-10-01 16:33:21 -07001365 "ReplicateFlow": msg.Flow.ReplicateFlow,
1366 "PbitToGemport": msg.Flow.PbitToGemport,
Matteo Scandoloedf30c72020-09-18 18:15:28 -07001367 }).Debug("OLT receives FlowAdd for ONU")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001368
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -07001369 o.FlowIds = append(o.FlowIds, msg.Flow.FlowId)
Matteo Scandolo4f4ac792020-10-01 16:33:21 -07001370
1371 var gemPortId uint32
1372 if msg.Flow.ReplicateFlow {
1373 // This means that the OLT should replicate the flow for each PBIT, for BBSim it's enough to use the
1374 // first available gemport (we only need to send one packet)
1375 // NOTE different TP may create different mapping between PBits and GemPorts, this may require some changes
1376 gemPortId = msg.Flow.PbitToGemport[0]
1377 } else {
1378 // if replicateFlows is false, then the flow is carrying the correct GemPortId
1379 gemPortId = uint32(msg.Flow.GemportId)
1380 }
Matteo Scandolo8a574812021-05-20 15:18:53 -07001381
1382 uni, err := o.FindUniById(uint32(msg.Flow.UniId))
1383 if err != nil {
1384 onuLogger.WithFields(log.Fields{
1385 "IntfId": o.PonPortID,
1386 "OnuId": o.ID,
1387 "UniId": msg.Flow.UniId,
1388 "PortNo": msg.Flow.PortNo,
1389 "SerialNumber": o.Sn(),
1390 "FlowId": msg.Flow.FlowId,
1391 "FlowType": msg.Flow.FlowType,
1392 }).Error("cannot-find-uni-port-for-flow")
1393 }
1394
1395 uni.addGemPortToService(gemPortId, msg.Flow.Classifier.EthType, msg.Flow.Classifier.OVid, msg.Flow.Classifier.IVid)
1396 uni.StorePortNo(msg.Flow.PortNo)
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -07001397
Matteo Scandolo3bc73742019-08-20 14:04:04 -07001398 if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) && msg.Flow.Classifier.OVid == 4091 {
Matteo Scandolo8a574812021-05-20 15:18:53 -07001399 uni.HandleAuth()
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001400 } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) &&
1401 msg.Flow.Classifier.SrcPort == uint32(68) &&
Matteo Scandolobd875b32020-09-18 17:46:31 -07001402 msg.Flow.Classifier.DstPort == uint32(67) {
Matteo Scandolo8a574812021-05-20 15:18:53 -07001403 uni.HandleDhcp(uint8(msg.Flow.Classifier.OPbits), int(msg.Flow.Classifier.OVid))
Matteo Scandolo3bc73742019-08-20 14:04:04 -07001404 }
1405}
1406
Matteo Scandolof9d43412021-01-12 11:11:34 -08001407func (o *Onu) handleFlowRemove(msg bbsim.OnuFlowUpdateMessage) {
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -07001408 onuLogger.WithFields(log.Fields{
1409 "IntfId": o.PonPortID,
1410 "OnuId": o.ID,
1411 "SerialNumber": o.Sn(),
1412 "FlowId": msg.Flow.FlowId,
1413 "FlowType": msg.Flow.FlowType,
1414 }).Debug("ONU receives FlowRemove")
1415
1416 for idx, flow := range o.FlowIds {
1417 // If the gemport is found, delete it from local cache.
1418 if flow == msg.Flow.FlowId {
1419 o.FlowIds = append(o.FlowIds[:idx], o.FlowIds[idx+1:]...)
1420 break
1421 }
1422 }
1423
1424 if len(o.FlowIds) == 0 {
1425 onuLogger.WithFields(log.Fields{
1426 "IntfId": o.PonPortID,
1427 "OnuId": o.ID,
1428 "SerialNumber": o.Sn(),
1429 }).Info("Resetting GemPort")
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -07001430
Hardik Windlass7b3405b2020-07-08 15:10:05 +05301431 // check if ONU delete is performed and
1432 // terminate the ONU's ProcessOnuMessages Go routine
Matteo Scandolocedde462021-03-09 17:37:16 -08001433 if o.InternalState.Current() == OnuStateDisabled {
Hardik Windlass7b3405b2020-07-08 15:10:05 +05301434 close(o.Channel)
1435 }
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -07001436 }
1437}
1438
Matteo Scandolocedde462021-03-09 17:37:16 -08001439func (o *Onu) Reboot(timeout time.Duration) error {
1440 onuLogger.WithFields(log.Fields{
1441 "IntfId": o.PonPortID,
1442 "OnuId": o.ID,
1443 "SerialNumber": o.Sn(),
1444 }).Debug("shutting-down-onu")
1445 if err := o.HandleShutdownONU(); err != nil {
1446 return err
1447 }
1448 time.Sleep(timeout)
1449 onuLogger.WithFields(log.Fields{
1450 "IntfId": o.PonPortID,
1451 "OnuId": o.ID,
1452 "SerialNumber": o.Sn(),
1453 }).Debug("power-on-onu")
1454 if err := o.HandlePowerOnONU(); err != nil {
1455 return err
1456 }
1457 return nil
1458}
1459
Matteo Scandolo76f6b892021-11-15 16:13:06 -08001460// returns true if the request is successful, false otherwise
1461func (o *Onu) handleEndSoftwareDownloadRequest(msg bbsim.OmciMessage) bool {
1462 msgObj, err := omcilib.ParseEndSoftwareDownloadRequest(msg.OmciPkt)
1463 if err != nil {
1464 onuLogger.WithFields(log.Fields{
1465 "OmciMsgType": msg.OmciMsg.MessageType,
1466 "TransCorrId": msg.OmciMsg.TransactionID,
1467 "Err": err.Error(),
1468 "IntfId": o.PonPortID,
1469 "SerialNumber": o.Sn(),
1470 }).Error("error-while-processing-end-software-download-request")
1471 return false
1472 }
1473
1474 onuLogger.WithFields(log.Fields{
1475 "OnuId": o.ID,
1476 "IntfId": o.PonPortID,
1477 "OnuSn": o.Sn(),
1478 "msgObj": msgObj,
1479 }).Trace("EndSoftwareDownloadRequest received message")
1480
1481 // if the image download is ongoing and we receive a message with
1482 // ImageSize = 0 and Crc = 4294967295 (0xFFFFFFFF) respond with success
1483 if o.ImageSoftwareReceivedSections > 0 &&
1484 msgObj.ImageSize == 0 &&
1485 msgObj.CRC32 == 4294967295 {
1486 o.ImageSoftwareReceivedSections = 0
1487 // NOTE potentially we may want to add a ONU state to reflect
1488 // the software download abort
1489 return true
1490 }
1491
1492 // In the startSoftwareDownload we get the image size and the window size.
1493 // We calculate how many DownloadSection we should receive and validate
1494 // that we got the correct amount when we receive this message
1495 // If the received sections are different from the expected sections
1496 // respond with failure
1497 if o.ImageSoftwareExpectedSections != o.ImageSoftwareReceivedSections {
1498 onuLogger.WithFields(log.Fields{
1499 "OnuId": o.ID,
1500 "IntfId": o.PonPortID,
1501 "OnuSn": o.Sn(),
1502 "ExpectedSections": o.ImageSoftwareExpectedSections,
1503 "ReceivedSections": o.ImageSoftwareReceivedSections,
1504 }).Errorf("onu-did-not-receive-all-image-sections")
1505 return false
1506 }
1507
1508 // check the received CRC vs the computed CRC
1509 computedCRC := crc32a.Checksum(o.ImageSectionData[:int(msgObj.ImageSize)])
1510 //Convert the crc to network byte order
1511 var byteSlice = make([]byte, 4)
1512 binary.LittleEndian.PutUint32(byteSlice, computedCRC)
1513 computedCRC = binary.BigEndian.Uint32(byteSlice)
1514 if msgObj.CRC32 != computedCRC {
1515 onuLogger.WithFields(log.Fields{
1516 "OnuId": o.ID,
1517 "IntfId": o.PonPortID,
1518 "OnuSn": o.Sn(),
1519 "ReceivedCRC": msgObj.CRC32,
1520 "CalculatedCRC": computedCRC,
1521 }).Errorf("onu-image-crc-validation-failed")
1522 return false
1523 }
1524
1525 o.StandbyImageVersion = o.InDownloadImageVersion
1526 onuLogger.WithFields(log.Fields{
1527 "OnuId": o.ID,
1528 "IntfId": o.PonPortID,
1529 "OnuSn": o.Sn(),
1530 "StandbyVersion": o.StandbyImageVersion,
1531 }).Debug("onu-image-version-updated")
1532 return true
1533}
1534
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001535// BBR methods
1536
1537func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) {
1538 omciMsg := openolt.OmciMsg{
1539 IntfId: intfId,
1540 OnuId: onuId,
1541 Pkt: pktBytes,
1542 }
1543
1544 if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil {
1545 log.WithFields(log.Fields{
1546 "IntfId": intfId,
1547 "OnuId": onuId,
1548 "SerialNumber": common.OnuSnToString(sn),
1549 "Pkt": omciMsg.Pkt,
1550 }).Fatalf("Failed to send MIB Reset")
1551 }
1552 log.WithFields(log.Fields{
1553 "IntfId": intfId,
1554 "OnuId": onuId,
1555 "SerialNumber": common.OnuSnToString(sn),
1556 "Pkt": omciMsg.Pkt,
1557 }).Tracef("Sent OMCI message %s", msgType)
1558}
1559
1560func (onu *Onu) getNextTid(highPriority ...bool) uint16 {
1561 var next uint16
1562 if len(highPriority) > 0 && highPriority[0] {
1563 next = onu.hpTid
1564 onu.hpTid += 1
1565 if onu.hpTid < 0x8000 {
1566 onu.hpTid = 0x8000
1567 }
1568 } else {
1569 next = onu.tid
1570 onu.tid += 1
1571 if onu.tid >= 0x8000 {
1572 onu.tid = 1
1573 }
1574 }
1575 return next
1576}
1577
1578// TODO move this method in responders/omcisim
Matteo Scandolo8a574812021-05-20 15:18:53 -07001579// StartOmci is called in BBR to start the OMCI state machine
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001580func (o *Onu) StartOmci(client openolt.OpenoltClient) {
1581 mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false))
1582 sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client)
1583}
1584
Matteo Scandolof9d43412021-01-12 11:11:34 -08001585// handleOmciResponse is used in BBR to generate the OMCI packets the openolt-adapter would send to the device
1586func (o *Onu) handleOmciResponse(msg bbsim.OmciIndicationMessage, client openolt.OpenoltClient) {
1587
1588 // we need to encode the packet in HEX
1589 pkt := make([]byte, len(msg.OmciInd.Pkt)*2)
1590 hex.Encode(pkt, msg.OmciInd.Pkt)
1591 packet, omciMsg, err := omcilib.ParseOpenOltOmciPacket(pkt)
1592 if err != nil {
1593 log.WithFields(log.Fields{
1594 "IntfId": o.PonPortID,
1595 "SerialNumber": o.Sn(),
1596 "omciPacket": msg.OmciInd.Pkt,
1597 }).Error("BBR Cannot parse OMCI packet")
1598 }
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001599
1600 log.WithFields(log.Fields{
1601 "IntfId": msg.OmciInd.IntfId,
1602 "OnuId": msg.OmciInd.OnuId,
Matteo Scandolof9d43412021-01-12 11:11:34 -08001603 "OnuSn": o.Sn(),
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001604 "Pkt": msg.OmciInd.Pkt,
Matteo Scandolof9d43412021-01-12 11:11:34 -08001605 "msgType": omciMsg.MessageType,
Anand S Katti09541352020-01-29 15:54:01 +05301606 }).Trace("ONU Receives OMCI Msg")
Matteo Scandolof9d43412021-01-12 11:11:34 -08001607 switch omciMsg.MessageType {
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001608 default:
Matteo Scandolo813402b2019-10-23 19:24:52 -07001609 log.WithFields(log.Fields{
1610 "IntfId": msg.OmciInd.IntfId,
1611 "OnuId": msg.OmciInd.OnuId,
Matteo Scandolof9d43412021-01-12 11:11:34 -08001612 "OnuSn": o.Sn(),
Matteo Scandolo813402b2019-10-23 19:24:52 -07001613 "Pkt": msg.OmciInd.Pkt,
Matteo Scandolof9d43412021-01-12 11:11:34 -08001614 "msgType": omciMsg.MessageType,
Matteo Scandolo813402b2019-10-23 19:24:52 -07001615 }).Fatalf("unexpected frame: %v", packet)
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001616 case omci.MibResetResponseType:
1617 mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false))
1618 sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client)
1619 case omci.MibUploadResponseType:
1620 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
1621 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
1622 case omci.MibUploadNextResponseType:
1623 o.seqNumber++
Matteo Scandolo8a574812021-05-20 15:18:53 -07001624 // once the mibUpload is complete send a SetRequest for the PPTP to enable the UNI
1625 // NOTE that in BBR we only enable the first UNI
1626 if o.seqNumber == o.MibDb.NumberOfCommands {
1627 meId := omcilib.GenerateUniPortEntityId(1)
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001628
Matteo Scandolo8a574812021-05-20 15:18:53 -07001629 meParams := me.ParamData{
1630 EntityID: meId.ToUint16(),
Elia Battiston9bfe1102022-02-03 10:38:03 +01001631 Attributes: me.AttributeValueMap{me.PhysicalPathTerminationPointEthernetUni_AdministrativeState: 0},
Matteo Scandolo8a574812021-05-20 15:18:53 -07001632 }
1633 managedEntity, omciError := me.NewPhysicalPathTerminationPointEthernetUni(meParams)
1634 if omciError.GetError() != nil {
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001635 onuLogger.WithFields(log.Fields{
1636 "OnuId": o.ID,
1637 "IntfId": o.PonPortID,
1638 "OnuSn": o.Sn(),
Matteo Scandolo8a574812021-05-20 15:18:53 -07001639 }).Fatal(omciError.GetError())
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001640 }
Matteo Scandolo8a574812021-05-20 15:18:53 -07001641
1642 setPPtp, _ := omcilib.CreateSetRequest(managedEntity, 1)
1643 sendOmciMsg(setPPtp, o.PonPortID, o.ID, o.SerialNumber, "setRquest", client)
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001644 } else {
1645 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
1646 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001647 }
Matteo Scandolo8a574812021-05-20 15:18:53 -07001648 case omci.SetResponseType:
1649 // once we set the PPTP to active we can start sending flows
1650
1651 if err := o.InternalState.Event(BbrOnuTxSendEapolFlow); err != nil {
1652 onuLogger.WithFields(log.Fields{
1653 "OnuId": o.ID,
1654 "IntfId": o.PonPortID,
1655 "OnuSn": o.Sn(),
1656 }).Errorf("Error while transitioning ONU State %v", err)
1657 }
1658 case omci.AlarmNotificationType:
1659 log.Info("bbr-received-alarm")
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001660 }
1661}
1662
1663func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) {
1664
1665 classifierProto := openolt.Classifier{
1666 EthType: uint32(layers.EthernetTypeEAPOL),
1667 OVid: 4091,
1668 }
1669
1670 actionProto := openolt.Action{}
1671
1672 downstreamFlow := openolt.Flow{
1673 AccessIntfId: int32(o.PonPortID),
1674 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -07001675 UniId: int32(0), // NOTE do not hardcode this, we need to support multiple UNIs
Matteo Scandolo4f4ac792020-10-01 16:33:21 -07001676 FlowId: uint64(o.ID),
Elia Battiston560e9552022-01-31 10:44:15 +01001677 FlowType: flowTypeDownstream,
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001678 NetworkIntfId: int32(0),
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001679 Classifier: &classifierProto,
1680 Action: &actionProto,
1681 Priority: int32(100),
1682 Cookie: uint64(o.ID),
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001683 PortNo: o.ID, // NOTE we are using this to map an incoming packetIndication to an ONU
1684 // AllocId and GemPorts need to be unique per PON
1685 // for now use the ONU-ID, will need to change once we support multiple UNIs
1686 AllocId: int32(o.ID),
1687 GemportId: int32(o.ID),
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001688 }
1689
1690 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
1691 log.WithFields(log.Fields{
1692 "IntfId": o.PonPortID,
1693 "OnuId": o.ID,
1694 "FlowId": downstreamFlow.FlowId,
1695 "PortNo": downstreamFlow.PortNo,
1696 "SerialNumber": common.OnuSnToString(o.SerialNumber),
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001697 "Err": err,
Matteo Scandolob0e3e622020-04-23 17:00:29 -07001698 }).Fatalf("Failed to add EAPOL Flow")
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001699 }
1700 log.WithFields(log.Fields{
1701 "IntfId": o.PonPortID,
1702 "OnuId": o.ID,
1703 "FlowId": downstreamFlow.FlowId,
1704 "PortNo": downstreamFlow.PortNo,
1705 "SerialNumber": common.OnuSnToString(o.SerialNumber),
1706 }).Info("Sent EAPOL Flow")
1707}
1708
1709func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) {
Matteo Scandolo4a036262020-08-17 15:56:13 -07001710
Matteo Scandolo8a574812021-05-20 15:18:53 -07001711 // BBR only works with a single UNI and a single service (ATT HSIA)
1712 hsia := o.UniPorts[0].(*UniPort).Services[0].(*Service)
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001713 classifierProto := openolt.Classifier{
1714 EthType: uint32(layers.EthernetTypeIPv4),
1715 SrcPort: uint32(68),
1716 DstPort: uint32(67),
Matteo Scandolo4a036262020-08-17 15:56:13 -07001717 OVid: uint32(hsia.CTag),
Matteo Scandolo8a574812021-05-20 15:18:53 -07001718 OPbits: 255,
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001719 }
1720
1721 actionProto := openolt.Action{}
1722
1723 downstreamFlow := openolt.Flow{
1724 AccessIntfId: int32(o.PonPortID),
1725 OnuId: int32(o.ID),
Matteo Scandolo8a574812021-05-20 15:18:53 -07001726 UniId: int32(0), // BBR only supports a single UNI
Matteo Scandolo4f4ac792020-10-01 16:33:21 -07001727 FlowId: uint64(o.ID),
Elia Battiston560e9552022-01-31 10:44:15 +01001728 FlowType: flowTypeDownstream,
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001729 NetworkIntfId: int32(0),
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001730 Classifier: &classifierProto,
1731 Action: &actionProto,
1732 Priority: int32(100),
1733 Cookie: uint64(o.ID),
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001734 PortNo: o.ID, // NOTE we are using this to map an incoming packetIndication to an ONU
1735 // AllocId and GemPorts need to be unique per PON
1736 // for now use the ONU-ID, will need to change once we support multiple UNIs
1737 AllocId: int32(o.ID),
1738 GemportId: int32(o.ID),
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001739 }
1740
1741 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
1742 log.WithFields(log.Fields{
1743 "IntfId": o.PonPortID,
1744 "OnuId": o.ID,
1745 "FlowId": downstreamFlow.FlowId,
1746 "PortNo": downstreamFlow.PortNo,
1747 "SerialNumber": common.OnuSnToString(o.SerialNumber),
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001748 "Err": err,
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001749 }).Fatalf("Failed to send DHCP Flow")
1750 }
1751 log.WithFields(log.Fields{
1752 "IntfId": o.PonPortID,
1753 "OnuId": o.ID,
1754 "FlowId": downstreamFlow.FlowId,
1755 "PortNo": downstreamFlow.PortNo,
1756 "SerialNumber": common.OnuSnToString(o.SerialNumber),
1757 }).Info("Sent DHCP Flow")
1758}
Pragya Arya8bdb4532020-03-02 17:08:09 +05301759
Andrea Campanellacc9b1662022-01-26 17:47:48 +01001760// DeleteFlow method search and delete flowKey from the onu flows slice
1761func (onu *Onu) DeleteFlow(key FlowKey) {
1762 for pos, flowKey := range onu.Flows {
1763 if flowKey == key {
1764 // delete the flowKey by shifting all flowKeys by one
1765 onu.Flows = append(onu.Flows[:pos], onu.Flows[pos+1:]...)
1766 t := make([]FlowKey, len(onu.Flows))
1767 copy(t, onu.Flows)
1768 onu.Flows = t
Pragya Arya8bdb4532020-03-02 17:08:09 +05301769 break
1770 }
1771 }
1772}
Hardik Windlass7b3405b2020-07-08 15:10:05 +05301773
1774func (onu *Onu) ReDiscoverOnu() {
1775 // Wait for few seconds to be sure of the cleanup
1776 time.Sleep(5 * time.Second)
1777
1778 onuLogger.WithFields(log.Fields{
1779 "IntfId": onu.PonPortID,
1780 "OnuId": onu.ID,
1781 "OnuSn": onu.Sn(),
1782 }).Debug("Send ONU Re-Discovery")
1783
1784 // ONU Re-Discovery
Matteo Scandolocedde462021-03-09 17:37:16 -08001785 if err := onu.InternalState.Event(OnuTxInitialize); err != nil {
Hardik Windlass7b3405b2020-07-08 15:10:05 +05301786 log.WithFields(log.Fields{
1787 "IntfId": onu.PonPortID,
1788 "OnuSn": onu.Sn(),
1789 "OnuId": onu.ID,
Matteo Scandolocedde462021-03-09 17:37:16 -08001790 }).Infof("Failed to transition ONU to %s state: %s", OnuStateInitialized, err.Error())
Hardik Windlass7b3405b2020-07-08 15:10:05 +05301791 }
1792
Matteo Scandolocedde462021-03-09 17:37:16 -08001793 if err := onu.InternalState.Event(OnuTxDiscover); err != nil {
Hardik Windlass7b3405b2020-07-08 15:10:05 +05301794 log.WithFields(log.Fields{
1795 "IntfId": onu.PonPortID,
1796 "OnuSn": onu.Sn(),
1797 "OnuId": onu.ID,
Matteo Scandolocedde462021-03-09 17:37:16 -08001798 }).Infof("Failed to transition ONU to %s state: %s", OnuStateDiscovered, err.Error())
Hardik Windlass7b3405b2020-07-08 15:10:05 +05301799 }
1800}
Matteo Scandolo4a036262020-08-17 15:56:13 -07001801
Matteo Scandolo8a574812021-05-20 15:18:53 -07001802// deprecated, delegate this to the uniPort
Matteo Scandolo4a036262020-08-17 15:56:13 -07001803func (onu *Onu) findServiceByMacAddress(macAddress net.HardwareAddr) (*Service, error) {
Matteo Scandolo8a574812021-05-20 15:18:53 -07001804 // FIXME is there a better way to avoid this loop?
1805 for _, u := range onu.UniPorts {
1806 uni := u.(*UniPort)
1807 for _, s := range uni.Services {
1808 service := s.(*Service)
1809 if service.HwAddress.String() == macAddress.String() {
1810 return service, nil
1811 }
Matteo Scandolo4a036262020-08-17 15:56:13 -07001812 }
1813 }
1814 return nil, fmt.Errorf("cannot-find-service-with-mac-address-%s", macAddress.String())
1815}
Himani Chawla13b1ee02021-03-15 01:43:53 +05301816
Matteo Scandolo8a574812021-05-20 15:18:53 -07001817func (onu *Onu) findUniByPortNo(portNo uint32) (*UniPort, error) {
1818 for _, u := range onu.UniPorts {
1819 uni := u.(*UniPort)
1820 if uni.PortNo == portNo {
1821 return uni, nil
1822 }
1823 }
1824 return nil, fmt.Errorf("cannot-find-uni-with-port-no-%d", portNo)
1825}
1826
Himani Chawla13b1ee02021-03-15 01:43:53 +05301827func (o *Onu) SendOMCIAlarmNotificationMsg(raiseOMCIAlarm bool, alarmType string) {
1828 switch alarmType {
1829 case "ONU_ALARM_LOS":
1830 msg := bbsim.Message{
1831 Type: bbsim.UniStatusAlarm,
1832 Data: bbsim.UniStatusAlarmMessage{
1833 OnuSN: o.SerialNumber,
1834 OnuID: o.ID,
1835 EntityID: 257,
1836 RaiseOMCIAlarm: raiseOMCIAlarm,
1837 },
1838 }
1839 o.Channel <- msg
1840 }
1841
1842}
1843
1844func (o *Onu) IncrementAlarmSequenceNumber(key omcilib.OnuAlarmInfoMapKey) uint8 {
1845 o.onuAlarmsInfoLock.Lock()
1846 defer o.onuAlarmsInfoLock.Unlock()
1847 if alarmInfo, ok := o.onuAlarmsInfo[key]; ok {
1848 if alarmInfo.SequenceNo == 255 {
1849 alarmInfo.SequenceNo = 1
1850 } else {
1851 alarmInfo.SequenceNo++
1852 }
1853 o.onuAlarmsInfo[key] = alarmInfo
1854 return alarmInfo.SequenceNo
1855 } else {
1856 // This is the first time alarm notification message is being sent
1857 o.onuAlarmsInfo[key] = omcilib.OnuAlarmInfo{
1858 SequenceNo: 1,
1859 }
1860 return 1
1861 }
1862}
Elia Battistonfe017662022-01-05 11:43:16 +01001863
1864func (o *Onu) InvalidateMibDataSync() {
1865 rand.Seed(time.Now().UnixNano())
1866 r := uint8(rand.Intn(10) + 1)
1867
1868 o.MibDataSync += r
1869
1870 // Since MibDataSync is a uint8, summing to it will never
1871 // result in a value higher than 255, but could be 0
1872 if o.MibDataSync == 0 {
1873 o.MibDataSync++
1874 }
1875}