blob: a37455e7f1c43e89a151ca0180e874bde1dd198f [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"
Matteo Scandolo99f18462019-10-28 14:14:28 -070021 "errors"
Matteo Scandolo3bc73742019-08-20 14:04:04 -070022 "fmt"
Zdravko Bozakov681364d2019-11-10 14:28:46 +010023 "net"
24
25 "time"
26
Matteo Scandolo40e067f2019-10-16 16:59:41 -070027 "github.com/cboling/omci"
Matteo Scandolo3bc73742019-08-20 14:04:04 -070028 "github.com/google/gopacket/layers"
Matteo Scandolo4747d292019-08-05 11:50:18 -070029 "github.com/looplab/fsm"
Matteo Scandolo075b1892019-10-07 12:11:07 -070030 "github.com/opencord/bbsim/internal/bbsim/packetHandlers"
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070031 "github.com/opencord/bbsim/internal/bbsim/responders/dhcp"
32 "github.com/opencord/bbsim/internal/bbsim/responders/eapol"
Matteo Scandolo40e067f2019-10-16 16:59:41 -070033 "github.com/opencord/bbsim/internal/common"
34 omcilib "github.com/opencord/bbsim/internal/common/omci"
35 omcisim "github.com/opencord/omci-sim"
Matteo Scandolo3de9de02019-11-14 13:40:03 -080036 "github.com/opencord/voltha-protos/v2/go/openolt"
Matteo Scandolo4747d292019-08-05 11:50:18 -070037 log "github.com/sirupsen/logrus"
38)
39
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070040var onuLogger = log.WithFields(log.Fields{
41 "module": "ONU",
42})
43
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070044type Onu struct {
Matteo Scandoloe811ae92019-12-10 17:50:14 -080045 ID uint32
46 PonPortID uint32
47 PonPort PonPort
48 STag int
49 CTag int
50 Auth bool // automatically start EAPOL if set to true
51 Dhcp bool // automatically start DHCP if set to true
52 HwAddress net.HardwareAddr
53 InternalState *fsm.FSM
54 DiscoveryRetryDelay time.Duration
55
56 // ONU State
Matteo Scandolo27428702019-10-11 16:21:16 -070057 // PortNo comes with flows and it's used when sending packetIndications,
58 // There is one PortNo per UNI Port, for now we're only storing the first one
59 // FIXME add support for multiple UNIs
Matteo Scandolo99f18462019-10-28 14:14:28 -070060 PortNo uint32
61 DhcpFlowReceived bool
62
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070063 OperState *fsm.FSM
64 SerialNumber *openolt.SerialNumber
65
66 Channel chan Message // this Channel is to track state changes OMCI messages, EAPOL and DHCP packets
Matteo Scandolo40e067f2019-10-16 16:59:41 -070067
68 // OMCI params
69 tid uint16
70 hpTid uint16
71 seqNumber uint16
72 HasGemPort bool
73
74 DoneChannel chan bool // this channel is used to signal once the onu is complete (when the struct is used by BBR)
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070075}
76
Matteo Scandolo99f18462019-10-28 14:14:28 -070077func (o *Onu) Sn() string {
Matteo Scandolo40e067f2019-10-16 16:59:41 -070078 return common.OnuSnToString(o.SerialNumber)
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070079}
80
Matteo Scandoloc1147092019-10-29 09:38:33 -070081func CreateONU(olt OltDevice, pon PonPort, id uint32, sTag int, cTag int, auth bool, dhcp bool) *Onu {
Matteo Scandolo4747d292019-08-05 11:50:18 -070082
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070083 o := Onu{
Matteo Scandoloe811ae92019-12-10 17:50:14 -080084 ID: id,
85 PonPortID: pon.ID,
86 PonPort: pon,
87 STag: sTag,
88 CTag: cTag,
89 Auth: auth,
90 Dhcp: dhcp,
91 HwAddress: net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, byte(pon.ID), byte(id)},
92 PortNo: 0,
93 tid: 0x1,
94 hpTid: 0x8000,
95 seqNumber: 0,
96 DoneChannel: make(chan bool, 1),
97 DhcpFlowReceived: false,
98 DiscoveryRetryDelay: 60 * time.Second, // this is used to send OnuDiscoveryIndications until an activate call is received
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070099 }
100 o.SerialNumber = o.NewSN(olt.ID, pon.ID, o.ID)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700101
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700102 // NOTE this state machine is used to track the operational
103 // state as requested by VOLTHA
104 o.OperState = getOperStateFSM(func(e *fsm.Event) {
105 onuLogger.WithFields(log.Fields{
106 "ID": o.ID,
107 }).Debugf("Changing ONU OperState from %s to %s", e.Src, e.Dst)
108 })
109
110 // NOTE this state machine is used to activate the OMCI, EAPOL and DHCP clients
111 o.InternalState = fsm.NewFSM(
112 "created",
113 fsm.Events{
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700114 // DEVICE Lifecycle
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100115 {Name: "initialize", Src: []string{"created", "disabled"}, Dst: "initialized"},
Pragya Arya6a708d62020-01-01 17:17:20 +0530116 {Name: "discover", Src: []string{"initialized", "pon_disabled"}, Dst: "discovered"},
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700117 {Name: "enable", Src: []string{"discovered", "disabled"}, Dst: "enabled"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700118 {Name: "receive_eapol_flow", Src: []string{"enabled", "gem_port_added"}, Dst: "eapol_flow_received"},
119 {Name: "add_gem_port", Src: []string{"enabled", "eapol_flow_received"}, Dst: "gem_port_added"},
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100120 // NOTE should disabled state be different for oper_disabled (emulating an error) and admin_disabled (received a disabled call via VOLTHA)?
121 {Name: "disable", Src: []string{"enabled", "eap_response_success_received", "auth_failed", "dhcp_ack_received", "dhcp_failed"}, Dst: "disabled"},
Pragya Arya6a708d62020-01-01 17:17:20 +0530122 // ONU state when PON port is disabled but ONU is power ON(more states should be added in src?)
123 {Name: "pon_disabled", Src: []string{"enabled", "gem_port_added", "eapol_flow_received", "eap_response_success_received", "auth_failed", "dhcp_ack_received", "dhcp_failed"}, Dst:"pon_disabled"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700124 // EAPOL
Matteo Scandolo5e081b52019-11-21 14:34:25 -0800125 {Name: "start_auth", Src: []string{"eapol_flow_received", "gem_port_added", "eap_start_sent", "eap_response_identity_sent", "eap_response_challenge_sent", "eap_response_success_received", "auth_failed", "dhcp_ack_received", "dhcp_failed"}, Dst: "auth_started"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700126 {Name: "eap_start_sent", Src: []string{"auth_started"}, Dst: "eap_start_sent"},
127 {Name: "eap_response_identity_sent", Src: []string{"eap_start_sent"}, Dst: "eap_response_identity_sent"},
128 {Name: "eap_response_challenge_sent", Src: []string{"eap_response_identity_sent"}, Dst: "eap_response_challenge_sent"},
129 {Name: "eap_response_success_received", Src: []string{"eap_response_challenge_sent"}, Dst: "eap_response_success_received"},
130 {Name: "auth_failed", Src: []string{"auth_started", "eap_start_sent", "eap_response_identity_sent", "eap_response_challenge_sent"}, Dst: "auth_failed"},
131 // DHCP
Matteo Scandolofe9ac252019-10-25 11:40:17 -0700132 {Name: "start_dhcp", Src: []string{"eap_response_success_received", "dhcp_discovery_sent", "dhcp_request_sent", "dhcp_ack_received", "dhcp_failed"}, Dst: "dhcp_started"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700133 {Name: "dhcp_discovery_sent", Src: []string{"dhcp_started"}, Dst: "dhcp_discovery_sent"},
134 {Name: "dhcp_request_sent", Src: []string{"dhcp_discovery_sent"}, Dst: "dhcp_request_sent"},
135 {Name: "dhcp_ack_received", Src: []string{"dhcp_request_sent"}, Dst: "dhcp_ack_received"},
136 {Name: "dhcp_failed", Src: []string{"dhcp_started", "dhcp_discovery_sent", "dhcp_request_sent"}, Dst: "dhcp_failed"},
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700137 // BBR States
138 // TODO add start OMCI state
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100139 {Name: "send_eapol_flow", Src: []string{"initialized"}, Dst: "eapol_flow_sent"},
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700140 {Name: "send_dhcp_flow", Src: []string{"eapol_flow_sent"}, Dst: "dhcp_flow_sent"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700141 },
142 fsm.Callbacks{
143 "enter_state": func(e *fsm.Event) {
144 o.logStateChange(e.Src, e.Dst)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700145 },
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100146 "enter_initialized": func(e *fsm.Event) {
147 // create new channel for ProcessOnuMessages Go routine
148 o.Channel = make(chan Message, 2048)
149 },
150 "enter_discovered": func(e *fsm.Event) {
151 msg := Message{
152 Type: OnuDiscIndication,
153 Data: OnuDiscIndicationMessage{
154 Onu: &o,
155 OperState: UP,
156 },
157 }
158 o.Channel <- msg
159 },
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700160 "enter_enabled": func(event *fsm.Event) {
161 msg := Message{
162 Type: OnuIndication,
163 Data: OnuIndicationMessage{
164 OnuSN: o.SerialNumber,
165 PonPortID: o.PonPortID,
166 OperState: UP,
167 },
168 }
169 o.Channel <- msg
170 },
171 "enter_disabled": func(event *fsm.Event) {
172 msg := Message{
173 Type: OnuIndication,
174 Data: OnuIndicationMessage{
175 OnuSN: o.SerialNumber,
176 PonPortID: o.PonPortID,
177 OperState: DOWN,
178 },
179 }
180 o.Channel <- msg
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100181 // terminate the ONU's ProcessOnuMessages Go routine
182 close(o.Channel)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700183 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700184 "enter_auth_started": func(e *fsm.Event) {
185 o.logStateChange(e.Src, e.Dst)
186 msg := Message{
187 Type: StartEAPOL,
188 Data: PacketMessage{
189 PonPortID: o.PonPortID,
190 OnuID: o.ID,
191 },
192 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700193 o.Channel <- msg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700194 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700195 "enter_auth_failed": func(e *fsm.Event) {
196 onuLogger.WithFields(log.Fields{
197 "OnuId": o.ID,
198 "IntfId": o.PonPortID,
199 "OnuSn": o.Sn(),
200 }).Errorf("ONU failed to authenticate!")
201 },
Matteo Scandolo99f18462019-10-28 14:14:28 -0700202 "before_start_dhcp": func(e *fsm.Event) {
203 if o.DhcpFlowReceived == false {
204 e.Cancel(errors.New("cannot-go-to-dhcp-started-as-dhcp-flow-is-missing"))
205 }
206 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700207 "enter_dhcp_started": func(e *fsm.Event) {
208 msg := Message{
209 Type: StartDHCP,
210 Data: PacketMessage{
211 PonPortID: o.PonPortID,
212 OnuID: o.ID,
213 },
214 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700215 o.Channel <- msg
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700216 },
217 "enter_dhcp_failed": func(e *fsm.Event) {
218 onuLogger.WithFields(log.Fields{
219 "OnuId": o.ID,
220 "IntfId": o.PonPortID,
221 "OnuSn": o.Sn(),
222 }).Errorf("ONU failed to DHCP!")
223 },
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700224 "enter_eapol_flow_sent": func(e *fsm.Event) {
225 msg := Message{
226 Type: SendEapolFlow,
227 }
228 o.Channel <- msg
229 },
230 "enter_dhcp_flow_sent": func(e *fsm.Event) {
231 msg := Message{
232 Type: SendDhcpFlow,
233 }
234 o.Channel <- msg
235 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700236 },
237 )
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100238
Matteo Scandolo27428702019-10-11 16:21:16 -0700239 return &o
Matteo Scandolo4747d292019-08-05 11:50:18 -0700240}
241
William Kurkian0418bc82019-11-06 12:16:24 -0500242func (o *Onu) logStateChange(src string, dst string) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700243 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700244 "OnuId": o.ID,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700245 "IntfId": o.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700246 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700247 }).Debugf("Changing ONU InternalState from %s to %s", src, dst)
248}
249
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100250// ProcessOnuMessages starts indication channel for each ONU
David Bainbridge103cf022019-12-16 20:11:35 +0000251func (o *Onu) ProcessOnuMessages(ctx context.Context, stream openolt.Openolt_EnableIndicationServer, client openolt.OpenoltClient) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700252 onuLogger.WithFields(log.Fields{
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100253 "onuID": o.ID,
254 "onuSN": o.Sn(),
255 "ponPort": o.PonPortID,
256 }).Debug("Starting ONU Indication Channel")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700257
David Bainbridge103cf022019-12-16 20:11:35 +0000258loop:
259 for {
260 select {
261 case <-ctx.Done():
262 onuLogger.WithFields(log.Fields{
263 "onuID": o.ID,
264 "onuSN": o.Sn(),
265 }).Tracef("ONU message handling canceled via context")
266 break loop
267 case message, ok := <-o.Channel:
268 if !ok || ctx.Err() != nil {
269 onuLogger.WithFields(log.Fields{
270 "onuID": o.ID,
271 "onuSN": o.Sn(),
272 }).Tracef("ONU message handling canceled via channel close")
273 break loop
Matteo Scandolo075b1892019-10-07 12:11:07 -0700274 }
David Bainbridge103cf022019-12-16 20:11:35 +0000275 onuLogger.WithFields(log.Fields{
276 "onuID": o.ID,
277 "onuSN": o.Sn(),
278 "messageType": message.Type,
279 }).Tracef("Received message on ONU Channel")
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700280
David Bainbridge103cf022019-12-16 20:11:35 +0000281 switch message.Type {
282 case OnuDiscIndication:
283 msg, _ := message.Data.(OnuDiscIndicationMessage)
284 // NOTE we need to slow down and send ONU Discovery Indication in batches to better emulate a real scenario
285 time.Sleep(time.Duration(int(o.ID)*o.PonPort.Olt.Delay) * time.Millisecond)
286 o.sendOnuDiscIndication(msg, stream)
287 case OnuIndication:
288 msg, _ := message.Data.(OnuIndicationMessage)
289 o.sendOnuIndication(msg, stream)
290 case OMCI:
291 msg, _ := message.Data.(OmciMessage)
292 o.handleOmciMessage(msg, stream)
293 case FlowUpdate:
294 msg, _ := message.Data.(OnuFlowUpdateMessage)
295 o.handleFlowUpdate(msg)
296 case StartEAPOL:
297 log.Infof("Receive StartEAPOL message on ONU Channel")
298 eapol.SendEapStart(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.InternalState, stream)
299 case StartDHCP:
300 log.Infof("Receive StartDHCP message on ONU Channel")
301 // FIXME use id, ponId as SendEapStart
302 dhcp.SendDHCPDiscovery(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.InternalState, o.HwAddress, o.CTag, stream)
303 case OnuPacketOut:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700304
David Bainbridge103cf022019-12-16 20:11:35 +0000305 msg, _ := message.Data.(OnuPacketMessage)
306
307 log.WithFields(log.Fields{
308 "IntfId": msg.IntfId,
309 "OnuId": msg.OnuId,
310 "pktType": msg.Type,
311 }).Trace("Received OnuPacketOut Message")
312
313 if msg.Type == packetHandlers.EAPOL {
314 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
315 } else if msg.Type == packetHandlers.DHCP {
316 // NOTE here we receive packets going from the DHCP Server to the ONU
317 // for now we expect them to be double-tagged, but ideally the should be single tagged
318 dhcp.HandleNextPacket(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.CTag, o.InternalState, msg.Packet, stream)
319 }
320 case OnuPacketIn:
321 // NOTE we only receive BBR packets here.
322 // Eapol.HandleNextPacket can handle both BBSim and BBr cases so the call is the same
323 // in the DHCP case VOLTHA only act as a proxy, the behaviour is completely different thus we have a dhcp.HandleNextBbrPacket
324 msg, _ := message.Data.(OnuPacketMessage)
325
326 log.WithFields(log.Fields{
327 "IntfId": msg.IntfId,
328 "OnuId": msg.OnuId,
329 "pktType": msg.Type,
330 }).Trace("Received OnuPacketIn Message")
331
332 if msg.Type == packetHandlers.EAPOL {
333 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
334 } else if msg.Type == packetHandlers.DHCP {
335 dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.STag, o.HwAddress, o.DoneChannel, msg.Packet, client)
336 }
337 case DyingGaspIndication:
338 msg, _ := message.Data.(DyingGaspIndicationMessage)
339 o.sendDyingGaspInd(msg, stream)
340 case OmciIndication:
341 msg, _ := message.Data.(OmciIndicationMessage)
342 o.handleOmci(msg, client)
343 case SendEapolFlow:
344 o.sendEapolFlow(client)
345 case SendDhcpFlow:
346 o.sendDhcpFlow(client)
347 default:
348 onuLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700349 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700350 }
351 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100352 onuLogger.WithFields(log.Fields{
353 "onuID": o.ID,
354 "onuSN": o.Sn(),
355 }).Debug("Stopped handling ONU Indication Channel")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700356}
357
William Kurkian0418bc82019-11-06 12:16:24 -0500358func (o *Onu) processOmciMessage(message omcisim.OmciChMessage) {
William Kurkian9dadc5b2019-10-22 13:51:57 -0400359 switch message.Type {
360 case omcisim.GemPortAdded:
361 log.WithFields(log.Fields{
362 "OnuId": message.Data.OnuId,
363 "IntfId": message.Data.IntfId,
364 }).Infof("GemPort Added")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700365
William Kurkian9dadc5b2019-10-22 13:51:57 -0400366 // NOTE if we receive the GemPort but we don't have EAPOL flows
367 // go an intermediate state, otherwise start auth
368 if o.InternalState.Is("enabled") {
369 if err := o.InternalState.Event("add_gem_port"); err != nil {
370 log.Errorf("Can't go to gem_port_added: %v", err)
371 }
372 } else if o.InternalState.Is("eapol_flow_received") {
Matteo Scandolo3c656a12019-12-10 09:54:51 -0800373 if o.Auth == true {
374 if err := o.InternalState.Event("start_auth"); err != nil {
375 log.Warnf("Can't go to auth_started: %v", err)
376 }
377 } else {
378 onuLogger.WithFields(log.Fields{
379 "IntfId": o.PonPortID,
380 "OnuId": o.ID,
381 "SerialNumber": o.Sn(),
382 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700383 }
384 }
385 }
386}
387
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100388func (o Onu) NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700389
390 sn := new(openolt.SerialNumber)
391
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700392 //sn = new(openolt.SerialNumber)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700393 sn.VendorId = []byte("BBSM")
394 sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)}
395
396 return sn
397}
398
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700399// NOTE handle_/process methods can change the ONU internal state as they are receiving messages
400// send method should not change the ONU state
401
William Kurkian0418bc82019-11-06 12:16:24 -0500402func (o *Onu) sendDyingGaspInd(msg DyingGaspIndicationMessage, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700403 alarmData := &openolt.AlarmIndication_DyingGaspInd{
404 DyingGaspInd: &openolt.DyingGaspIndication{
405 IntfId: msg.PonPortID,
406 OnuId: msg.OnuID,
407 Status: "on",
408 },
409 }
410 data := &openolt.Indication_AlarmInd{AlarmInd: &openolt.AlarmIndication{Data: alarmData}}
411
412 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
413 onuLogger.Errorf("Failed to send DyingGaspInd : %v", err)
414 return err
415 }
416 onuLogger.WithFields(log.Fields{
417 "IntfId": msg.PonPortID,
418 "OnuSn": o.Sn(),
419 "OnuId": msg.OnuID,
420 }).Info("sendDyingGaspInd")
421 return nil
422}
423
William Kurkian0418bc82019-11-06 12:16:24 -0500424func (o *Onu) sendOnuDiscIndication(msg OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700425 discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700426 IntfId: msg.Onu.PonPortID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700427 SerialNumber: msg.Onu.SerialNumber,
428 }}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700429
Matteo Scandolo4747d292019-08-05 11:50:18 -0700430 if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700431 log.Errorf("Failed to send Indication_OnuDiscInd: %v", err)
Matteo Scandolo99f18462019-10-28 14:14:28 -0700432 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700433 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700434
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700435 onuLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700436 "IntfId": msg.Onu.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700437 "OnuSn": msg.Onu.Sn(),
438 "OnuId": o.ID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700439 }).Debug("Sent Indication_OnuDiscInd")
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800440
441 // after DiscoveryRetryDelay check if the state is the same and in case send a new OnuDiscIndication
442 go func(delay time.Duration) {
Matteo Scandolo569e7172019-12-20 11:51:51 -0800443 time.Sleep(delay)
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800444 if o.InternalState.Current() == "discovered" {
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800445 o.sendOnuDiscIndication(msg, stream)
446 }
447 }(o.DiscoveryRetryDelay)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700448}
449
William Kurkian0418bc82019-11-06 12:16:24 -0500450func (o *Onu) sendOnuIndication(msg OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700451 // NOTE voltha returns an ID, but if we use that ID then it complains:
452 // expected_onu_id: 1, received_onu_id: 1024, event: ONU-id-mismatch, can happen if both voltha and the olt rebooted
453 // so we're using the internal ID that is 1
454 // o.ID = msg.OnuID
Matteo Scandolo4747d292019-08-05 11:50:18 -0700455
456 indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700457 IntfId: o.PonPortID,
458 OnuId: o.ID,
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700459 OperState: msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700460 AdminState: o.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700461 SerialNumber: o.SerialNumber,
462 }}
463 if err := stream.Send(&openolt.Indication{Data: indData}); err != nil {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700464 // TODO do we need to transition to a broken state?
Matteo Scandolo11006992019-08-28 11:29:46 -0700465 log.Errorf("Failed to send Indication_OnuInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700466 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700467 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700468 "IntfId": o.PonPortID,
469 "OnuId": o.ID,
470 "OperState": msg.OperState.String(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700471 "AdminState": msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700472 "OnuSn": o.Sn(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700473 }).Debug("Sent Indication_OnuInd")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700474
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700475}
476
William Kurkian0418bc82019-11-06 12:16:24 -0500477func (o *Onu) handleOmciMessage(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700478
479 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700480 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700481 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700482 "omciPacket": msg.omciMsg.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700483 }).Tracef("Received OMCI message")
484
485 var omciInd openolt.OmciIndication
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700486 respPkt, err := omcisim.OmciSim(o.PonPortID, o.ID, HexDecode(msg.omciMsg.Pkt))
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700487 if err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700488 onuLogger.WithFields(log.Fields{
489 "IntfId": o.PonPortID,
490 "SerialNumber": o.Sn(),
491 "omciPacket": omciInd.Pkt,
492 "msg": msg,
493 }).Errorf("Error handling OMCI message %v", msg)
494 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700495 }
496
497 omciInd.IntfId = o.PonPortID
498 omciInd.OnuId = o.ID
499 omciInd.Pkt = respPkt
500
501 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
502 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700503 onuLogger.WithFields(log.Fields{
504 "IntfId": o.PonPortID,
505 "SerialNumber": o.Sn(),
506 "omciPacket": omciInd.Pkt,
507 "msg": msg,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700508 }).Errorf("send omcisim indication failed: %v", err)
Matteo Scandolo27428702019-10-11 16:21:16 -0700509 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700510 }
511 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700512 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700513 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700514 "omciPacket": omciInd.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700515 }).Tracef("Sent OMCI message")
516}
517
Matteo Scandolo27428702019-10-11 16:21:16 -0700518func (o *Onu) storePortNumber(portNo uint32) {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700519 // NOTE this needed only as long as we don't support multiple UNIs
Matteo Scandolo27428702019-10-11 16:21:16 -0700520 // we need to add support for multiple UNIs
521 // the action plan is:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700522 // - refactor the omcisim-sim library to use https://github.com/cboling/omci instead of canned messages
Matteo Scandolo27428702019-10-11 16:21:16 -0700523 // - change the library so that it reports a single UNI and remove this workaroung
524 // - add support for multiple UNIs in BBSim
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700525 if o.PortNo == 0 || portNo < o.PortNo {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700526 onuLogger.WithFields(log.Fields{
527 "IntfId": o.PonPortID,
528 "OnuId": o.ID,
529 "SerialNumber": o.Sn(),
530 "OnuPortNo": o.PortNo,
531 "FlowPortNo": portNo,
532 }).Debug("Storing ONU portNo")
Matteo Scandolo27428702019-10-11 16:21:16 -0700533 o.PortNo = portNo
534 }
535}
536
William Kurkian0418bc82019-11-06 12:16:24 -0500537func (o *Onu) SetID(id uint32) {
538 o.ID = id
539}
540
Matteo Scandolo813402b2019-10-23 19:24:52 -0700541func (o *Onu) handleFlowUpdate(msg OnuFlowUpdateMessage) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700542 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700543 "DstPort": msg.Flow.Classifier.DstPort,
544 "EthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType),
545 "FlowId": msg.Flow.FlowId,
546 "FlowType": msg.Flow.FlowType,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700547 "InnerVlan": msg.Flow.Classifier.IVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700548 "IntfId": msg.Flow.AccessIntfId,
549 "IpProto": msg.Flow.Classifier.IpProto,
550 "OnuId": msg.Flow.OnuId,
551 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700552 "OuterVlan": msg.Flow.Classifier.OVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700553 "PortNo": msg.Flow.PortNo,
554 "SrcPort": msg.Flow.Classifier.SrcPort,
555 "UniID": msg.Flow.UniId,
556 }).Debug("ONU receives Flow")
557
Matteo Scandolo813402b2019-10-23 19:24:52 -0700558 if msg.Flow.UniId != 0 {
559 // as of now BBSim only support a single UNI, so ignore everything that is not targeted to it
560 onuLogger.WithFields(log.Fields{
561 "IntfId": o.PonPortID,
562 "OnuId": o.ID,
563 "SerialNumber": o.Sn(),
564 }).Debug("Ignoring flow as it's not for the first UNI")
565 return
566 }
567
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700568 if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) && msg.Flow.Classifier.OVid == 4091 {
Matteo Scandolo27428702019-10-11 16:21:16 -0700569 // NOTE storing the PortNO, it's needed when sending PacketIndications
Matteo Scandolo813402b2019-10-23 19:24:52 -0700570 o.storePortNumber(uint32(msg.Flow.PortNo))
Matteo Scandolo27428702019-10-11 16:21:16 -0700571
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700572 // NOTE if we receive the EAPOL flows but we don't have GemPorts
573 // go an intermediate state, otherwise start auth
574 if o.InternalState.Is("enabled") {
575 if err := o.InternalState.Event("receive_eapol_flow"); err != nil {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700576 log.Warnf("Can't go to eapol_flow_received: %v", err)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700577 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700578 } else if o.InternalState.Is("gem_port_added") {
Matteo Scandoloc1147092019-10-29 09:38:33 -0700579
580 if o.Auth == true {
581 if err := o.InternalState.Event("start_auth"); err != nil {
582 log.Warnf("Can't go to auth_started: %v", err)
583 }
584 } else {
585 onuLogger.WithFields(log.Fields{
586 "IntfId": o.PonPortID,
587 "OnuId": o.ID,
588 "SerialNumber": o.Sn(),
589 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700590 }
Matteo Scandoloc1147092019-10-29 09:38:33 -0700591
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700592 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700593 } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) &&
594 msg.Flow.Classifier.SrcPort == uint32(68) &&
595 msg.Flow.Classifier.DstPort == uint32(67) {
Matteo Scandolo99f18462019-10-28 14:14:28 -0700596
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100597 // keep track that we received the DHCP Flows so that we can transition the state to dhcp_started
Matteo Scandolo99f18462019-10-28 14:14:28 -0700598 o.DhcpFlowReceived = true
Matteo Scandoloc1147092019-10-29 09:38:33 -0700599
600 if o.Dhcp == true {
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100601 // NOTE we are receiving multiple DHCP flows but we shouldn't call the transition multiple times
Matteo Scandoloc1147092019-10-29 09:38:33 -0700602 if err := o.InternalState.Event("start_dhcp"); err != nil {
603 log.Errorf("Can't go to dhcp_started: %v", err)
604 }
605 } else {
606 onuLogger.WithFields(log.Fields{
607 "IntfId": o.PonPortID,
608 "OnuId": o.ID,
609 "SerialNumber": o.Sn(),
610 }).Warn("Not starting DHCP as Dhcp bit is not set in CLI parameters")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700611 }
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700612 }
613}
614
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700615// HexDecode converts the hex encoding to binary
616func HexDecode(pkt []byte) []byte {
617 p := make([]byte, len(pkt)/2)
618 for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 {
619 // Go figure this ;)
620 u := (pkt[i] & 15) + (pkt[i]>>6)*9
621 l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9
622 p[j] = u<<4 + l
623 }
624 onuLogger.Tracef("Omci decoded: %x.", p)
625 return p
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700626}
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700627
628// BBR methods
629
630func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) {
631 omciMsg := openolt.OmciMsg{
632 IntfId: intfId,
633 OnuId: onuId,
634 Pkt: pktBytes,
635 }
636
637 if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil {
638 log.WithFields(log.Fields{
639 "IntfId": intfId,
640 "OnuId": onuId,
641 "SerialNumber": common.OnuSnToString(sn),
642 "Pkt": omciMsg.Pkt,
643 }).Fatalf("Failed to send MIB Reset")
644 }
645 log.WithFields(log.Fields{
646 "IntfId": intfId,
647 "OnuId": onuId,
648 "SerialNumber": common.OnuSnToString(sn),
649 "Pkt": omciMsg.Pkt,
650 }).Tracef("Sent OMCI message %s", msgType)
651}
652
653func (onu *Onu) getNextTid(highPriority ...bool) uint16 {
654 var next uint16
655 if len(highPriority) > 0 && highPriority[0] {
656 next = onu.hpTid
657 onu.hpTid += 1
658 if onu.hpTid < 0x8000 {
659 onu.hpTid = 0x8000
660 }
661 } else {
662 next = onu.tid
663 onu.tid += 1
664 if onu.tid >= 0x8000 {
665 onu.tid = 1
666 }
667 }
668 return next
669}
670
671// TODO move this method in responders/omcisim
672func (o *Onu) StartOmci(client openolt.OpenoltClient) {
673 mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false))
674 sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client)
675}
676
677func (o *Onu) handleOmci(msg OmciIndicationMessage, client openolt.OpenoltClient) {
678 msgType, packet := omcilib.DecodeOmci(msg.OmciInd.Pkt)
679
680 log.WithFields(log.Fields{
681 "IntfId": msg.OmciInd.IntfId,
682 "OnuId": msg.OmciInd.OnuId,
683 "OnuSn": common.OnuSnToString(o.SerialNumber),
684 "Pkt": msg.OmciInd.Pkt,
685 "msgType": msgType,
686 }).Trace("ONU Receveives OMCI Msg")
687 switch msgType {
688 default:
Matteo Scandolo813402b2019-10-23 19:24:52 -0700689 log.WithFields(log.Fields{
690 "IntfId": msg.OmciInd.IntfId,
691 "OnuId": msg.OmciInd.OnuId,
692 "OnuSn": common.OnuSnToString(o.SerialNumber),
693 "Pkt": msg.OmciInd.Pkt,
694 "msgType": msgType,
695 }).Fatalf("unexpected frame: %v", packet)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700696 case omci.MibResetResponseType:
697 mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false))
698 sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client)
699 case omci.MibUploadResponseType:
700 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
701 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
702 case omci.MibUploadNextResponseType:
703 o.seqNumber++
704
705 if o.seqNumber > 290 {
706 // NOTE we are done with the MIB Upload (290 is the number of messages the omci-sim library will respond to)
707 galEnet, _ := omcilib.CreateGalEnetRequest(o.getNextTid(false))
708 sendOmciMsg(galEnet, o.PonPortID, o.ID, o.SerialNumber, "CreateGalEnetRequest", client)
709 } else {
710 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
711 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
712 }
713 case omci.CreateResponseType:
714 // NOTE Creating a GemPort,
715 // BBsim actually doesn't care about the values, so we can do we want with the parameters
716 // In the same way we can create a GemPort even without setting up UNIs/TConts/...
717 // but we need the GemPort to trigger the state change
718
719 if !o.HasGemPort {
720 // NOTE this sends a CreateRequestType and BBSim replies with a CreateResponseType
721 // thus we send this request only once
722 gemReq, _ := omcilib.CreateGemPortRequest(o.getNextTid(false))
723 sendOmciMsg(gemReq, o.PonPortID, o.ID, o.SerialNumber, "CreateGemPortRequest", client)
724 o.HasGemPort = true
725 } else {
726 if err := o.InternalState.Event("send_eapol_flow"); err != nil {
727 onuLogger.WithFields(log.Fields{
728 "OnuId": o.ID,
729 "IntfId": o.PonPortID,
730 "OnuSn": o.Sn(),
731 }).Errorf("Error while transitioning ONU State %v", err)
732 }
733 }
734
735 }
736}
737
738func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) {
739
740 classifierProto := openolt.Classifier{
741 EthType: uint32(layers.EthernetTypeEAPOL),
742 OVid: 4091,
743 }
744
745 actionProto := openolt.Action{}
746
747 downstreamFlow := openolt.Flow{
748 AccessIntfId: int32(o.PonPortID),
749 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700750 UniId: int32(0), // NOTE do not hardcode this, we need to support multiple UNIs
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700751 FlowId: uint32(o.ID),
752 FlowType: "downstream",
753 AllocId: int32(0),
754 NetworkIntfId: int32(0),
755 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
756 Classifier: &classifierProto,
757 Action: &actionProto,
758 Priority: int32(100),
759 Cookie: uint64(o.ID),
760 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
761 }
762
763 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
764 log.WithFields(log.Fields{
765 "IntfId": o.PonPortID,
766 "OnuId": o.ID,
767 "FlowId": downstreamFlow.FlowId,
768 "PortNo": downstreamFlow.PortNo,
769 "SerialNumber": common.OnuSnToString(o.SerialNumber),
770 }).Fatalf("Failed to EAPOL Flow")
771 }
772 log.WithFields(log.Fields{
773 "IntfId": o.PonPortID,
774 "OnuId": o.ID,
775 "FlowId": downstreamFlow.FlowId,
776 "PortNo": downstreamFlow.PortNo,
777 "SerialNumber": common.OnuSnToString(o.SerialNumber),
778 }).Info("Sent EAPOL Flow")
779}
780
781func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) {
782 classifierProto := openolt.Classifier{
783 EthType: uint32(layers.EthernetTypeIPv4),
784 SrcPort: uint32(68),
785 DstPort: uint32(67),
786 }
787
788 actionProto := openolt.Action{}
789
790 downstreamFlow := openolt.Flow{
791 AccessIntfId: int32(o.PonPortID),
792 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700793 UniId: int32(0), // FIXME do not hardcode this
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700794 FlowId: uint32(o.ID),
795 FlowType: "downstream",
796 AllocId: int32(0),
797 NetworkIntfId: int32(0),
798 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
799 Classifier: &classifierProto,
800 Action: &actionProto,
801 Priority: int32(100),
802 Cookie: uint64(o.ID),
803 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
804 }
805
806 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
807 log.WithFields(log.Fields{
808 "IntfId": o.PonPortID,
809 "OnuId": o.ID,
810 "FlowId": downstreamFlow.FlowId,
811 "PortNo": downstreamFlow.PortNo,
812 "SerialNumber": common.OnuSnToString(o.SerialNumber),
813 }).Fatalf("Failed to send DHCP Flow")
814 }
815 log.WithFields(log.Fields{
816 "IntfId": o.PonPortID,
817 "OnuId": o.ID,
818 "FlowId": downstreamFlow.FlowId,
819 "PortNo": downstreamFlow.PortNo,
820 "SerialNumber": common.OnuSnToString(o.SerialNumber),
821 }).Info("Sent DHCP Flow")
822}