blob: ef25770200d94ea22b357eafca3c5a71c5ddf541 [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?)
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800123 {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
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800358func (o *Onu) processOmciMessage(message omcisim.OmciChMessage, stream openolt.Openolt_EnableIndicationServer) {
William Kurkian9dadc5b2019-10-22 13:51:57 -0400359 switch message.Type {
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800360 case omcisim.UniLinkUp, omcisim.UniLinkDown:
361 onuLogger.WithFields(log.Fields{
362 "OnuId": message.Data.OnuId,
363 "IntfId": message.Data.IntfId,
364 "Type": message.Type,
365 }).Infof("UNI Link Alarm")
366 // TODO send to OLT
367
368 omciInd := openolt.OmciIndication{
369 IntfId: message.Data.IntfId,
370 OnuId: message.Data.OnuId,
371 Pkt: message.Packet,
372 }
373
374 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
375 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
376 onuLogger.WithFields(log.Fields{
377 "IntfId": o.PonPortID,
378 "SerialNumber": o.Sn(),
379 "Type": message.Type,
380 "omciPacket": omciInd.Pkt,
381 }).Errorf("Failed to send UNI Link Alarm: %v", err)
382 return
383 }
384
385 onuLogger.WithFields(log.Fields{
386 "IntfId": o.PonPortID,
387 "SerialNumber": o.Sn(),
388 "Type": message.Type,
389 "omciPacket": omciInd.Pkt,
390 }).Info("UNI Link alarm sent")
391
William Kurkian9dadc5b2019-10-22 13:51:57 -0400392 case omcisim.GemPortAdded:
393 log.WithFields(log.Fields{
394 "OnuId": message.Data.OnuId,
395 "IntfId": message.Data.IntfId,
396 }).Infof("GemPort Added")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700397
William Kurkian9dadc5b2019-10-22 13:51:57 -0400398 // NOTE if we receive the GemPort but we don't have EAPOL flows
399 // go an intermediate state, otherwise start auth
400 if o.InternalState.Is("enabled") {
401 if err := o.InternalState.Event("add_gem_port"); err != nil {
402 log.Errorf("Can't go to gem_port_added: %v", err)
403 }
404 } else if o.InternalState.Is("eapol_flow_received") {
Matteo Scandolo3c656a12019-12-10 09:54:51 -0800405 if o.Auth == true {
406 if err := o.InternalState.Event("start_auth"); err != nil {
407 log.Warnf("Can't go to auth_started: %v", err)
408 }
409 } else {
410 onuLogger.WithFields(log.Fields{
411 "IntfId": o.PonPortID,
412 "OnuId": o.ID,
413 "SerialNumber": o.Sn(),
414 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700415 }
416 }
417 }
418}
419
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100420func (o Onu) NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700421
422 sn := new(openolt.SerialNumber)
423
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700424 //sn = new(openolt.SerialNumber)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700425 sn.VendorId = []byte("BBSM")
426 sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)}
427
428 return sn
429}
430
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700431// NOTE handle_/process methods can change the ONU internal state as they are receiving messages
432// send method should not change the ONU state
433
William Kurkian0418bc82019-11-06 12:16:24 -0500434func (o *Onu) sendDyingGaspInd(msg DyingGaspIndicationMessage, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700435 alarmData := &openolt.AlarmIndication_DyingGaspInd{
436 DyingGaspInd: &openolt.DyingGaspIndication{
437 IntfId: msg.PonPortID,
438 OnuId: msg.OnuID,
439 Status: "on",
440 },
441 }
442 data := &openolt.Indication_AlarmInd{AlarmInd: &openolt.AlarmIndication{Data: alarmData}}
443
444 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
445 onuLogger.Errorf("Failed to send DyingGaspInd : %v", err)
446 return err
447 }
448 onuLogger.WithFields(log.Fields{
449 "IntfId": msg.PonPortID,
450 "OnuSn": o.Sn(),
451 "OnuId": msg.OnuID,
452 }).Info("sendDyingGaspInd")
453 return nil
454}
455
William Kurkian0418bc82019-11-06 12:16:24 -0500456func (o *Onu) sendOnuDiscIndication(msg OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700457 discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700458 IntfId: msg.Onu.PonPortID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700459 SerialNumber: msg.Onu.SerialNumber,
460 }}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700461
Matteo Scandolo4747d292019-08-05 11:50:18 -0700462 if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700463 log.Errorf("Failed to send Indication_OnuDiscInd: %v", err)
Matteo Scandolo99f18462019-10-28 14:14:28 -0700464 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700465 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700466
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700467 onuLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700468 "IntfId": msg.Onu.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700469 "OnuSn": msg.Onu.Sn(),
470 "OnuId": o.ID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700471 }).Debug("Sent Indication_OnuDiscInd")
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800472
473 // after DiscoveryRetryDelay check if the state is the same and in case send a new OnuDiscIndication
474 go func(delay time.Duration) {
Matteo Scandolo569e7172019-12-20 11:51:51 -0800475 time.Sleep(delay)
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800476 if o.InternalState.Current() == "discovered" {
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800477 o.sendOnuDiscIndication(msg, stream)
478 }
479 }(o.DiscoveryRetryDelay)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700480}
481
William Kurkian0418bc82019-11-06 12:16:24 -0500482func (o *Onu) sendOnuIndication(msg OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700483 // NOTE voltha returns an ID, but if we use that ID then it complains:
484 // expected_onu_id: 1, received_onu_id: 1024, event: ONU-id-mismatch, can happen if both voltha and the olt rebooted
485 // so we're using the internal ID that is 1
486 // o.ID = msg.OnuID
Matteo Scandolo4747d292019-08-05 11:50:18 -0700487
488 indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700489 IntfId: o.PonPortID,
490 OnuId: o.ID,
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700491 OperState: msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700492 AdminState: o.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700493 SerialNumber: o.SerialNumber,
494 }}
495 if err := stream.Send(&openolt.Indication{Data: indData}); err != nil {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700496 // TODO do we need to transition to a broken state?
Matteo Scandolo11006992019-08-28 11:29:46 -0700497 log.Errorf("Failed to send Indication_OnuInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700498 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700499 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700500 "IntfId": o.PonPortID,
501 "OnuId": o.ID,
502 "OperState": msg.OperState.String(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700503 "AdminState": msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700504 "OnuSn": o.Sn(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700505 }).Debug("Sent Indication_OnuInd")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700506
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700507}
508
William Kurkian0418bc82019-11-06 12:16:24 -0500509func (o *Onu) handleOmciMessage(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) {
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": msg.omciMsg.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700515 }).Tracef("Received OMCI message")
516
517 var omciInd openolt.OmciIndication
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700518 respPkt, err := omcisim.OmciSim(o.PonPortID, o.ID, HexDecode(msg.omciMsg.Pkt))
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700519 if err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700520 onuLogger.WithFields(log.Fields{
521 "IntfId": o.PonPortID,
522 "SerialNumber": o.Sn(),
523 "omciPacket": omciInd.Pkt,
524 "msg": msg,
525 }).Errorf("Error handling OMCI message %v", msg)
526 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700527 }
528
529 omciInd.IntfId = o.PonPortID
530 omciInd.OnuId = o.ID
531 omciInd.Pkt = respPkt
532
533 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
534 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700535 onuLogger.WithFields(log.Fields{
536 "IntfId": o.PonPortID,
537 "SerialNumber": o.Sn(),
538 "omciPacket": omciInd.Pkt,
539 "msg": msg,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700540 }).Errorf("send omcisim indication failed: %v", err)
Matteo Scandolo27428702019-10-11 16:21:16 -0700541 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700542 }
543 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700544 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700545 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700546 "omciPacket": omciInd.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700547 }).Tracef("Sent OMCI message")
548}
549
Matteo Scandolo27428702019-10-11 16:21:16 -0700550func (o *Onu) storePortNumber(portNo uint32) {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700551 // NOTE this needed only as long as we don't support multiple UNIs
Matteo Scandolo27428702019-10-11 16:21:16 -0700552 // we need to add support for multiple UNIs
553 // the action plan is:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700554 // - refactor the omcisim-sim library to use https://github.com/cboling/omci instead of canned messages
Matteo Scandolo27428702019-10-11 16:21:16 -0700555 // - change the library so that it reports a single UNI and remove this workaroung
556 // - add support for multiple UNIs in BBSim
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700557 if o.PortNo == 0 || portNo < o.PortNo {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700558 onuLogger.WithFields(log.Fields{
559 "IntfId": o.PonPortID,
560 "OnuId": o.ID,
561 "SerialNumber": o.Sn(),
562 "OnuPortNo": o.PortNo,
563 "FlowPortNo": portNo,
564 }).Debug("Storing ONU portNo")
Matteo Scandolo27428702019-10-11 16:21:16 -0700565 o.PortNo = portNo
566 }
567}
568
William Kurkian0418bc82019-11-06 12:16:24 -0500569func (o *Onu) SetID(id uint32) {
570 o.ID = id
571}
572
Matteo Scandolo813402b2019-10-23 19:24:52 -0700573func (o *Onu) handleFlowUpdate(msg OnuFlowUpdateMessage) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700574 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700575 "DstPort": msg.Flow.Classifier.DstPort,
576 "EthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType),
577 "FlowId": msg.Flow.FlowId,
578 "FlowType": msg.Flow.FlowType,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700579 "InnerVlan": msg.Flow.Classifier.IVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700580 "IntfId": msg.Flow.AccessIntfId,
581 "IpProto": msg.Flow.Classifier.IpProto,
582 "OnuId": msg.Flow.OnuId,
583 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700584 "OuterVlan": msg.Flow.Classifier.OVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700585 "PortNo": msg.Flow.PortNo,
586 "SrcPort": msg.Flow.Classifier.SrcPort,
587 "UniID": msg.Flow.UniId,
588 }).Debug("ONU receives Flow")
589
Matteo Scandolo813402b2019-10-23 19:24:52 -0700590 if msg.Flow.UniId != 0 {
591 // as of now BBSim only support a single UNI, so ignore everything that is not targeted to it
592 onuLogger.WithFields(log.Fields{
593 "IntfId": o.PonPortID,
594 "OnuId": o.ID,
595 "SerialNumber": o.Sn(),
596 }).Debug("Ignoring flow as it's not for the first UNI")
597 return
598 }
599
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700600 if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) && msg.Flow.Classifier.OVid == 4091 {
Matteo Scandolo27428702019-10-11 16:21:16 -0700601 // NOTE storing the PortNO, it's needed when sending PacketIndications
Matteo Scandolo813402b2019-10-23 19:24:52 -0700602 o.storePortNumber(uint32(msg.Flow.PortNo))
Matteo Scandolo27428702019-10-11 16:21:16 -0700603
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700604 // NOTE if we receive the EAPOL flows but we don't have GemPorts
605 // go an intermediate state, otherwise start auth
606 if o.InternalState.Is("enabled") {
607 if err := o.InternalState.Event("receive_eapol_flow"); err != nil {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700608 log.Warnf("Can't go to eapol_flow_received: %v", err)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700609 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700610 } else if o.InternalState.Is("gem_port_added") {
Matteo Scandoloc1147092019-10-29 09:38:33 -0700611
612 if o.Auth == true {
613 if err := o.InternalState.Event("start_auth"); err != nil {
614 log.Warnf("Can't go to auth_started: %v", err)
615 }
616 } else {
617 onuLogger.WithFields(log.Fields{
618 "IntfId": o.PonPortID,
619 "OnuId": o.ID,
620 "SerialNumber": o.Sn(),
621 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700622 }
Matteo Scandoloc1147092019-10-29 09:38:33 -0700623
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700624 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700625 } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) &&
626 msg.Flow.Classifier.SrcPort == uint32(68) &&
627 msg.Flow.Classifier.DstPort == uint32(67) {
Matteo Scandolo99f18462019-10-28 14:14:28 -0700628
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100629 // 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 -0700630 o.DhcpFlowReceived = true
Matteo Scandoloc1147092019-10-29 09:38:33 -0700631
632 if o.Dhcp == true {
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100633 // NOTE we are receiving multiple DHCP flows but we shouldn't call the transition multiple times
Matteo Scandoloc1147092019-10-29 09:38:33 -0700634 if err := o.InternalState.Event("start_dhcp"); err != nil {
635 log.Errorf("Can't go to dhcp_started: %v", err)
636 }
637 } else {
638 onuLogger.WithFields(log.Fields{
639 "IntfId": o.PonPortID,
640 "OnuId": o.ID,
641 "SerialNumber": o.Sn(),
642 }).Warn("Not starting DHCP as Dhcp bit is not set in CLI parameters")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700643 }
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700644 }
645}
646
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700647// HexDecode converts the hex encoding to binary
648func HexDecode(pkt []byte) []byte {
649 p := make([]byte, len(pkt)/2)
650 for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 {
651 // Go figure this ;)
652 u := (pkt[i] & 15) + (pkt[i]>>6)*9
653 l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9
654 p[j] = u<<4 + l
655 }
656 onuLogger.Tracef("Omci decoded: %x.", p)
657 return p
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700658}
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700659
660// BBR methods
661
662func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) {
663 omciMsg := openolt.OmciMsg{
664 IntfId: intfId,
665 OnuId: onuId,
666 Pkt: pktBytes,
667 }
668
669 if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil {
670 log.WithFields(log.Fields{
671 "IntfId": intfId,
672 "OnuId": onuId,
673 "SerialNumber": common.OnuSnToString(sn),
674 "Pkt": omciMsg.Pkt,
675 }).Fatalf("Failed to send MIB Reset")
676 }
677 log.WithFields(log.Fields{
678 "IntfId": intfId,
679 "OnuId": onuId,
680 "SerialNumber": common.OnuSnToString(sn),
681 "Pkt": omciMsg.Pkt,
682 }).Tracef("Sent OMCI message %s", msgType)
683}
684
685func (onu *Onu) getNextTid(highPriority ...bool) uint16 {
686 var next uint16
687 if len(highPriority) > 0 && highPriority[0] {
688 next = onu.hpTid
689 onu.hpTid += 1
690 if onu.hpTid < 0x8000 {
691 onu.hpTid = 0x8000
692 }
693 } else {
694 next = onu.tid
695 onu.tid += 1
696 if onu.tid >= 0x8000 {
697 onu.tid = 1
698 }
699 }
700 return next
701}
702
703// TODO move this method in responders/omcisim
704func (o *Onu) StartOmci(client openolt.OpenoltClient) {
705 mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false))
706 sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client)
707}
708
709func (o *Onu) handleOmci(msg OmciIndicationMessage, client openolt.OpenoltClient) {
710 msgType, packet := omcilib.DecodeOmci(msg.OmciInd.Pkt)
711
712 log.WithFields(log.Fields{
713 "IntfId": msg.OmciInd.IntfId,
714 "OnuId": msg.OmciInd.OnuId,
715 "OnuSn": common.OnuSnToString(o.SerialNumber),
716 "Pkt": msg.OmciInd.Pkt,
717 "msgType": msgType,
718 }).Trace("ONU Receveives OMCI Msg")
719 switch msgType {
720 default:
Matteo Scandolo813402b2019-10-23 19:24:52 -0700721 log.WithFields(log.Fields{
722 "IntfId": msg.OmciInd.IntfId,
723 "OnuId": msg.OmciInd.OnuId,
724 "OnuSn": common.OnuSnToString(o.SerialNumber),
725 "Pkt": msg.OmciInd.Pkt,
726 "msgType": msgType,
727 }).Fatalf("unexpected frame: %v", packet)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700728 case omci.MibResetResponseType:
729 mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false))
730 sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client)
731 case omci.MibUploadResponseType:
732 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
733 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
734 case omci.MibUploadNextResponseType:
735 o.seqNumber++
736
737 if o.seqNumber > 290 {
738 // NOTE we are done with the MIB Upload (290 is the number of messages the omci-sim library will respond to)
739 galEnet, _ := omcilib.CreateGalEnetRequest(o.getNextTid(false))
740 sendOmciMsg(galEnet, o.PonPortID, o.ID, o.SerialNumber, "CreateGalEnetRequest", client)
741 } else {
742 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
743 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
744 }
745 case omci.CreateResponseType:
746 // NOTE Creating a GemPort,
747 // BBsim actually doesn't care about the values, so we can do we want with the parameters
748 // In the same way we can create a GemPort even without setting up UNIs/TConts/...
749 // but we need the GemPort to trigger the state change
750
751 if !o.HasGemPort {
752 // NOTE this sends a CreateRequestType and BBSim replies with a CreateResponseType
753 // thus we send this request only once
754 gemReq, _ := omcilib.CreateGemPortRequest(o.getNextTid(false))
755 sendOmciMsg(gemReq, o.PonPortID, o.ID, o.SerialNumber, "CreateGemPortRequest", client)
756 o.HasGemPort = true
757 } else {
758 if err := o.InternalState.Event("send_eapol_flow"); err != nil {
759 onuLogger.WithFields(log.Fields{
760 "OnuId": o.ID,
761 "IntfId": o.PonPortID,
762 "OnuSn": o.Sn(),
763 }).Errorf("Error while transitioning ONU State %v", err)
764 }
765 }
766
767 }
768}
769
770func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) {
771
772 classifierProto := openolt.Classifier{
773 EthType: uint32(layers.EthernetTypeEAPOL),
774 OVid: 4091,
775 }
776
777 actionProto := openolt.Action{}
778
779 downstreamFlow := openolt.Flow{
780 AccessIntfId: int32(o.PonPortID),
781 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700782 UniId: int32(0), // NOTE do not hardcode this, we need to support multiple UNIs
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700783 FlowId: uint32(o.ID),
784 FlowType: "downstream",
785 AllocId: int32(0),
786 NetworkIntfId: int32(0),
787 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
788 Classifier: &classifierProto,
789 Action: &actionProto,
790 Priority: int32(100),
791 Cookie: uint64(o.ID),
792 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
793 }
794
795 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
796 log.WithFields(log.Fields{
797 "IntfId": o.PonPortID,
798 "OnuId": o.ID,
799 "FlowId": downstreamFlow.FlowId,
800 "PortNo": downstreamFlow.PortNo,
801 "SerialNumber": common.OnuSnToString(o.SerialNumber),
802 }).Fatalf("Failed to EAPOL Flow")
803 }
804 log.WithFields(log.Fields{
805 "IntfId": o.PonPortID,
806 "OnuId": o.ID,
807 "FlowId": downstreamFlow.FlowId,
808 "PortNo": downstreamFlow.PortNo,
809 "SerialNumber": common.OnuSnToString(o.SerialNumber),
810 }).Info("Sent EAPOL Flow")
811}
812
813func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) {
814 classifierProto := openolt.Classifier{
815 EthType: uint32(layers.EthernetTypeIPv4),
816 SrcPort: uint32(68),
817 DstPort: uint32(67),
818 }
819
820 actionProto := openolt.Action{}
821
822 downstreamFlow := openolt.Flow{
823 AccessIntfId: int32(o.PonPortID),
824 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700825 UniId: int32(0), // FIXME do not hardcode this
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700826 FlowId: uint32(o.ID),
827 FlowType: "downstream",
828 AllocId: int32(0),
829 NetworkIntfId: int32(0),
830 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
831 Classifier: &classifierProto,
832 Action: &actionProto,
833 Priority: int32(100),
834 Cookie: uint64(o.ID),
835 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
836 }
837
838 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
839 log.WithFields(log.Fields{
840 "IntfId": o.PonPortID,
841 "OnuId": o.ID,
842 "FlowId": downstreamFlow.FlowId,
843 "PortNo": downstreamFlow.PortNo,
844 "SerialNumber": common.OnuSnToString(o.SerialNumber),
845 }).Fatalf("Failed to send DHCP Flow")
846 }
847 log.WithFields(log.Fields{
848 "IntfId": o.PonPortID,
849 "OnuId": o.ID,
850 "FlowId": downstreamFlow.FlowId,
851 "PortNo": downstreamFlow.PortNo,
852 "SerialNumber": common.OnuSnToString(o.SerialNumber),
853 }).Info("Sent DHCP Flow")
854}