blob: 2ec674ccde85d70fa10e8e3f23f4e7e58c3133f9 [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
Pragya Arya1cbefa42020-01-13 12:15:29 +053081func CreateONU(olt *OltDevice, pon PonPort, id uint32, sTag int, cTag int, auth bool, dhcp bool, isMock 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)?
Pragya Arya1cbefa42020-01-13 12:15:29 +0530121 {Name: "disable", Src: []string{"enabled", "eapol_flow_received", "gem_port_added", "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)
Pragya Arya1cbefa42020-01-13 12:15:29 +0530149 if !isMock {
150 // start ProcessOnuMessages Go routine
151 go o.ProcessOnuMessages(olt.enableContext, *olt.OpenoltStream, nil)
152 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100153 },
154 "enter_discovered": func(e *fsm.Event) {
155 msg := Message{
156 Type: OnuDiscIndication,
157 Data: OnuDiscIndicationMessage{
158 Onu: &o,
159 OperState: UP,
160 },
161 }
162 o.Channel <- msg
163 },
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700164 "enter_enabled": func(event *fsm.Event) {
165 msg := Message{
166 Type: OnuIndication,
167 Data: OnuIndicationMessage{
168 OnuSN: o.SerialNumber,
169 PonPortID: o.PonPortID,
170 OperState: UP,
171 },
172 }
173 o.Channel <- msg
174 },
175 "enter_disabled": func(event *fsm.Event) {
176 msg := Message{
177 Type: OnuIndication,
178 Data: OnuIndicationMessage{
179 OnuSN: o.SerialNumber,
180 PonPortID: o.PonPortID,
181 OperState: DOWN,
182 },
183 }
184 o.Channel <- msg
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100185 // terminate the ONU's ProcessOnuMessages Go routine
186 close(o.Channel)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700187 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700188 "enter_auth_started": func(e *fsm.Event) {
189 o.logStateChange(e.Src, e.Dst)
190 msg := Message{
191 Type: StartEAPOL,
192 Data: PacketMessage{
193 PonPortID: o.PonPortID,
194 OnuID: o.ID,
195 },
196 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700197 o.Channel <- msg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700198 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700199 "enter_auth_failed": func(e *fsm.Event) {
200 onuLogger.WithFields(log.Fields{
201 "OnuId": o.ID,
202 "IntfId": o.PonPortID,
203 "OnuSn": o.Sn(),
204 }).Errorf("ONU failed to authenticate!")
205 },
Matteo Scandolo99f18462019-10-28 14:14:28 -0700206 "before_start_dhcp": func(e *fsm.Event) {
207 if o.DhcpFlowReceived == false {
208 e.Cancel(errors.New("cannot-go-to-dhcp-started-as-dhcp-flow-is-missing"))
209 }
210 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700211 "enter_dhcp_started": func(e *fsm.Event) {
212 msg := Message{
213 Type: StartDHCP,
214 Data: PacketMessage{
215 PonPortID: o.PonPortID,
216 OnuID: o.ID,
217 },
218 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700219 o.Channel <- msg
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700220 },
221 "enter_dhcp_failed": func(e *fsm.Event) {
222 onuLogger.WithFields(log.Fields{
223 "OnuId": o.ID,
224 "IntfId": o.PonPortID,
225 "OnuSn": o.Sn(),
226 }).Errorf("ONU failed to DHCP!")
227 },
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700228 "enter_eapol_flow_sent": func(e *fsm.Event) {
229 msg := Message{
230 Type: SendEapolFlow,
231 }
232 o.Channel <- msg
233 },
234 "enter_dhcp_flow_sent": func(e *fsm.Event) {
235 msg := Message{
236 Type: SendDhcpFlow,
237 }
238 o.Channel <- msg
239 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700240 },
241 )
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100242
Matteo Scandolo27428702019-10-11 16:21:16 -0700243 return &o
Matteo Scandolo4747d292019-08-05 11:50:18 -0700244}
245
William Kurkian0418bc82019-11-06 12:16:24 -0500246func (o *Onu) logStateChange(src string, dst string) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700247 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700248 "OnuId": o.ID,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700249 "IntfId": o.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700250 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700251 }).Debugf("Changing ONU InternalState from %s to %s", src, dst)
252}
253
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100254// ProcessOnuMessages starts indication channel for each ONU
David Bainbridge103cf022019-12-16 20:11:35 +0000255func (o *Onu) ProcessOnuMessages(ctx context.Context, stream openolt.Openolt_EnableIndicationServer, client openolt.OpenoltClient) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700256 onuLogger.WithFields(log.Fields{
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100257 "onuID": o.ID,
258 "onuSN": o.Sn(),
259 "ponPort": o.PonPortID,
260 }).Debug("Starting ONU Indication Channel")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700261
David Bainbridge103cf022019-12-16 20:11:35 +0000262loop:
263 for {
264 select {
265 case <-ctx.Done():
266 onuLogger.WithFields(log.Fields{
267 "onuID": o.ID,
268 "onuSN": o.Sn(),
269 }).Tracef("ONU message handling canceled via context")
270 break loop
271 case message, ok := <-o.Channel:
272 if !ok || ctx.Err() != nil {
273 onuLogger.WithFields(log.Fields{
274 "onuID": o.ID,
275 "onuSN": o.Sn(),
276 }).Tracef("ONU message handling canceled via channel close")
277 break loop
Matteo Scandolo075b1892019-10-07 12:11:07 -0700278 }
David Bainbridge103cf022019-12-16 20:11:35 +0000279 onuLogger.WithFields(log.Fields{
280 "onuID": o.ID,
281 "onuSN": o.Sn(),
282 "messageType": message.Type,
283 }).Tracef("Received message on ONU Channel")
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700284
David Bainbridge103cf022019-12-16 20:11:35 +0000285 switch message.Type {
286 case OnuDiscIndication:
287 msg, _ := message.Data.(OnuDiscIndicationMessage)
288 // NOTE we need to slow down and send ONU Discovery Indication in batches to better emulate a real scenario
289 time.Sleep(time.Duration(int(o.ID)*o.PonPort.Olt.Delay) * time.Millisecond)
290 o.sendOnuDiscIndication(msg, stream)
291 case OnuIndication:
292 msg, _ := message.Data.(OnuIndicationMessage)
293 o.sendOnuIndication(msg, stream)
294 case OMCI:
295 msg, _ := message.Data.(OmciMessage)
296 o.handleOmciMessage(msg, stream)
297 case FlowUpdate:
298 msg, _ := message.Data.(OnuFlowUpdateMessage)
299 o.handleFlowUpdate(msg)
300 case StartEAPOL:
301 log.Infof("Receive StartEAPOL message on ONU Channel")
302 eapol.SendEapStart(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.InternalState, stream)
303 case StartDHCP:
304 log.Infof("Receive StartDHCP message on ONU Channel")
305 // FIXME use id, ponId as SendEapStart
306 dhcp.SendDHCPDiscovery(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.InternalState, o.HwAddress, o.CTag, stream)
307 case OnuPacketOut:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700308
David Bainbridge103cf022019-12-16 20:11:35 +0000309 msg, _ := message.Data.(OnuPacketMessage)
310
311 log.WithFields(log.Fields{
312 "IntfId": msg.IntfId,
313 "OnuId": msg.OnuId,
314 "pktType": msg.Type,
315 }).Trace("Received OnuPacketOut Message")
316
317 if msg.Type == packetHandlers.EAPOL {
318 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
319 } else if msg.Type == packetHandlers.DHCP {
320 // NOTE here we receive packets going from the DHCP Server to the ONU
321 // for now we expect them to be double-tagged, but ideally the should be single tagged
322 dhcp.HandleNextPacket(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.CTag, o.InternalState, msg.Packet, stream)
323 }
324 case OnuPacketIn:
325 // NOTE we only receive BBR packets here.
326 // Eapol.HandleNextPacket can handle both BBSim and BBr cases so the call is the same
327 // in the DHCP case VOLTHA only act as a proxy, the behaviour is completely different thus we have a dhcp.HandleNextBbrPacket
328 msg, _ := message.Data.(OnuPacketMessage)
329
330 log.WithFields(log.Fields{
331 "IntfId": msg.IntfId,
332 "OnuId": msg.OnuId,
333 "pktType": msg.Type,
334 }).Trace("Received OnuPacketIn Message")
335
336 if msg.Type == packetHandlers.EAPOL {
337 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
338 } else if msg.Type == packetHandlers.DHCP {
339 dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.STag, o.HwAddress, o.DoneChannel, msg.Packet, client)
340 }
341 case DyingGaspIndication:
342 msg, _ := message.Data.(DyingGaspIndicationMessage)
343 o.sendDyingGaspInd(msg, stream)
344 case OmciIndication:
345 msg, _ := message.Data.(OmciIndicationMessage)
346 o.handleOmci(msg, client)
347 case SendEapolFlow:
348 o.sendEapolFlow(client)
349 case SendDhcpFlow:
350 o.sendDhcpFlow(client)
351 default:
352 onuLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700353 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700354 }
355 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100356 onuLogger.WithFields(log.Fields{
357 "onuID": o.ID,
358 "onuSN": o.Sn(),
359 }).Debug("Stopped handling ONU Indication Channel")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700360}
361
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800362func (o *Onu) processOmciMessage(message omcisim.OmciChMessage, stream openolt.Openolt_EnableIndicationServer) {
William Kurkian9dadc5b2019-10-22 13:51:57 -0400363 switch message.Type {
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800364 case omcisim.UniLinkUp, omcisim.UniLinkDown:
365 onuLogger.WithFields(log.Fields{
366 "OnuId": message.Data.OnuId,
367 "IntfId": message.Data.IntfId,
368 "Type": message.Type,
369 }).Infof("UNI Link Alarm")
370 // TODO send to OLT
371
372 omciInd := openolt.OmciIndication{
373 IntfId: message.Data.IntfId,
374 OnuId: message.Data.OnuId,
375 Pkt: message.Packet,
376 }
377
378 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
379 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
380 onuLogger.WithFields(log.Fields{
381 "IntfId": o.PonPortID,
382 "SerialNumber": o.Sn(),
383 "Type": message.Type,
384 "omciPacket": omciInd.Pkt,
385 }).Errorf("Failed to send UNI Link Alarm: %v", err)
386 return
387 }
388
389 onuLogger.WithFields(log.Fields{
390 "IntfId": o.PonPortID,
391 "SerialNumber": o.Sn(),
392 "Type": message.Type,
393 "omciPacket": omciInd.Pkt,
394 }).Info("UNI Link alarm sent")
395
William Kurkian9dadc5b2019-10-22 13:51:57 -0400396 case omcisim.GemPortAdded:
397 log.WithFields(log.Fields{
398 "OnuId": message.Data.OnuId,
399 "IntfId": message.Data.IntfId,
400 }).Infof("GemPort Added")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700401
William Kurkian9dadc5b2019-10-22 13:51:57 -0400402 // NOTE if we receive the GemPort but we don't have EAPOL flows
403 // go an intermediate state, otherwise start auth
404 if o.InternalState.Is("enabled") {
405 if err := o.InternalState.Event("add_gem_port"); err != nil {
406 log.Errorf("Can't go to gem_port_added: %v", err)
407 }
408 } else if o.InternalState.Is("eapol_flow_received") {
Matteo Scandolo3c656a12019-12-10 09:54:51 -0800409 if o.Auth == true {
410 if err := o.InternalState.Event("start_auth"); err != nil {
411 log.Warnf("Can't go to auth_started: %v", err)
412 }
413 } else {
414 onuLogger.WithFields(log.Fields{
415 "IntfId": o.PonPortID,
416 "OnuId": o.ID,
417 "SerialNumber": o.Sn(),
418 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700419 }
420 }
421 }
422}
423
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100424func (o Onu) NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700425
426 sn := new(openolt.SerialNumber)
427
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700428 //sn = new(openolt.SerialNumber)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700429 sn.VendorId = []byte("BBSM")
430 sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)}
431
432 return sn
433}
434
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700435// NOTE handle_/process methods can change the ONU internal state as they are receiving messages
436// send method should not change the ONU state
437
William Kurkian0418bc82019-11-06 12:16:24 -0500438func (o *Onu) sendDyingGaspInd(msg DyingGaspIndicationMessage, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700439 alarmData := &openolt.AlarmIndication_DyingGaspInd{
440 DyingGaspInd: &openolt.DyingGaspIndication{
441 IntfId: msg.PonPortID,
442 OnuId: msg.OnuID,
443 Status: "on",
444 },
445 }
446 data := &openolt.Indication_AlarmInd{AlarmInd: &openolt.AlarmIndication{Data: alarmData}}
447
448 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
449 onuLogger.Errorf("Failed to send DyingGaspInd : %v", err)
450 return err
451 }
452 onuLogger.WithFields(log.Fields{
453 "IntfId": msg.PonPortID,
454 "OnuSn": o.Sn(),
455 "OnuId": msg.OnuID,
456 }).Info("sendDyingGaspInd")
457 return nil
458}
459
William Kurkian0418bc82019-11-06 12:16:24 -0500460func (o *Onu) sendOnuDiscIndication(msg OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700461 discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700462 IntfId: msg.Onu.PonPortID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700463 SerialNumber: msg.Onu.SerialNumber,
464 }}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700465
Matteo Scandolo4747d292019-08-05 11:50:18 -0700466 if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700467 log.Errorf("Failed to send Indication_OnuDiscInd: %v", err)
Matteo Scandolo99f18462019-10-28 14:14:28 -0700468 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700469 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700470
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700471 onuLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700472 "IntfId": msg.Onu.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700473 "OnuSn": msg.Onu.Sn(),
474 "OnuId": o.ID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700475 }).Debug("Sent Indication_OnuDiscInd")
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800476
477 // after DiscoveryRetryDelay check if the state is the same and in case send a new OnuDiscIndication
478 go func(delay time.Duration) {
Matteo Scandolo569e7172019-12-20 11:51:51 -0800479 time.Sleep(delay)
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800480 if o.InternalState.Current() == "discovered" {
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800481 o.sendOnuDiscIndication(msg, stream)
482 }
483 }(o.DiscoveryRetryDelay)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700484}
485
William Kurkian0418bc82019-11-06 12:16:24 -0500486func (o *Onu) sendOnuIndication(msg OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700487 // NOTE voltha returns an ID, but if we use that ID then it complains:
488 // expected_onu_id: 1, received_onu_id: 1024, event: ONU-id-mismatch, can happen if both voltha and the olt rebooted
489 // so we're using the internal ID that is 1
490 // o.ID = msg.OnuID
Matteo Scandolo4747d292019-08-05 11:50:18 -0700491
492 indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700493 IntfId: o.PonPortID,
494 OnuId: o.ID,
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700495 OperState: msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700496 AdminState: o.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700497 SerialNumber: o.SerialNumber,
498 }}
499 if err := stream.Send(&openolt.Indication{Data: indData}); err != nil {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700500 // TODO do we need to transition to a broken state?
Matteo Scandolo11006992019-08-28 11:29:46 -0700501 log.Errorf("Failed to send Indication_OnuInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700502 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700503 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700504 "IntfId": o.PonPortID,
505 "OnuId": o.ID,
506 "OperState": msg.OperState.String(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700507 "AdminState": msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700508 "OnuSn": o.Sn(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700509 }).Debug("Sent Indication_OnuInd")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700510
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700511}
512
William Kurkian0418bc82019-11-06 12:16:24 -0500513func (o *Onu) handleOmciMessage(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700514
515 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700516 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700517 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700518 "omciPacket": msg.omciMsg.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700519 }).Tracef("Received OMCI message")
520
521 var omciInd openolt.OmciIndication
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700522 respPkt, err := omcisim.OmciSim(o.PonPortID, o.ID, HexDecode(msg.omciMsg.Pkt))
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700523 if err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700524 onuLogger.WithFields(log.Fields{
525 "IntfId": o.PonPortID,
526 "SerialNumber": o.Sn(),
527 "omciPacket": omciInd.Pkt,
528 "msg": msg,
529 }).Errorf("Error handling OMCI message %v", msg)
530 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700531 }
532
533 omciInd.IntfId = o.PonPortID
534 omciInd.OnuId = o.ID
535 omciInd.Pkt = respPkt
536
537 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
538 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700539 onuLogger.WithFields(log.Fields{
540 "IntfId": o.PonPortID,
541 "SerialNumber": o.Sn(),
542 "omciPacket": omciInd.Pkt,
543 "msg": msg,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700544 }).Errorf("send omcisim indication failed: %v", err)
Matteo Scandolo27428702019-10-11 16:21:16 -0700545 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700546 }
547 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700548 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700549 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700550 "omciPacket": omciInd.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700551 }).Tracef("Sent OMCI message")
552}
553
Matteo Scandolo27428702019-10-11 16:21:16 -0700554func (o *Onu) storePortNumber(portNo uint32) {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700555 // NOTE this needed only as long as we don't support multiple UNIs
Matteo Scandolo27428702019-10-11 16:21:16 -0700556 // we need to add support for multiple UNIs
557 // the action plan is:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700558 // - refactor the omcisim-sim library to use https://github.com/cboling/omci instead of canned messages
Matteo Scandolo27428702019-10-11 16:21:16 -0700559 // - change the library so that it reports a single UNI and remove this workaroung
560 // - add support for multiple UNIs in BBSim
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700561 if o.PortNo == 0 || portNo < o.PortNo {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700562 onuLogger.WithFields(log.Fields{
563 "IntfId": o.PonPortID,
564 "OnuId": o.ID,
565 "SerialNumber": o.Sn(),
566 "OnuPortNo": o.PortNo,
567 "FlowPortNo": portNo,
568 }).Debug("Storing ONU portNo")
Matteo Scandolo27428702019-10-11 16:21:16 -0700569 o.PortNo = portNo
570 }
571}
572
William Kurkian0418bc82019-11-06 12:16:24 -0500573func (o *Onu) SetID(id uint32) {
574 o.ID = id
575}
576
Matteo Scandolo813402b2019-10-23 19:24:52 -0700577func (o *Onu) handleFlowUpdate(msg OnuFlowUpdateMessage) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700578 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700579 "DstPort": msg.Flow.Classifier.DstPort,
580 "EthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType),
581 "FlowId": msg.Flow.FlowId,
582 "FlowType": msg.Flow.FlowType,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700583 "InnerVlan": msg.Flow.Classifier.IVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700584 "IntfId": msg.Flow.AccessIntfId,
585 "IpProto": msg.Flow.Classifier.IpProto,
586 "OnuId": msg.Flow.OnuId,
587 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700588 "OuterVlan": msg.Flow.Classifier.OVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700589 "PortNo": msg.Flow.PortNo,
590 "SrcPort": msg.Flow.Classifier.SrcPort,
591 "UniID": msg.Flow.UniId,
592 }).Debug("ONU receives Flow")
593
Matteo Scandolo813402b2019-10-23 19:24:52 -0700594 if msg.Flow.UniId != 0 {
595 // as of now BBSim only support a single UNI, so ignore everything that is not targeted to it
596 onuLogger.WithFields(log.Fields{
597 "IntfId": o.PonPortID,
598 "OnuId": o.ID,
599 "SerialNumber": o.Sn(),
600 }).Debug("Ignoring flow as it's not for the first UNI")
601 return
602 }
603
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700604 if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) && msg.Flow.Classifier.OVid == 4091 {
Matteo Scandolo27428702019-10-11 16:21:16 -0700605 // NOTE storing the PortNO, it's needed when sending PacketIndications
Matteo Scandolo813402b2019-10-23 19:24:52 -0700606 o.storePortNumber(uint32(msg.Flow.PortNo))
Matteo Scandolo27428702019-10-11 16:21:16 -0700607
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700608 // NOTE if we receive the EAPOL flows but we don't have GemPorts
609 // go an intermediate state, otherwise start auth
610 if o.InternalState.Is("enabled") {
611 if err := o.InternalState.Event("receive_eapol_flow"); err != nil {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700612 log.Warnf("Can't go to eapol_flow_received: %v", err)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700613 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700614 } else if o.InternalState.Is("gem_port_added") {
Matteo Scandoloc1147092019-10-29 09:38:33 -0700615
616 if o.Auth == true {
617 if err := o.InternalState.Event("start_auth"); err != nil {
618 log.Warnf("Can't go to auth_started: %v", err)
619 }
620 } else {
621 onuLogger.WithFields(log.Fields{
622 "IntfId": o.PonPortID,
623 "OnuId": o.ID,
624 "SerialNumber": o.Sn(),
625 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700626 }
Matteo Scandoloc1147092019-10-29 09:38:33 -0700627
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700628 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700629 } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) &&
630 msg.Flow.Classifier.SrcPort == uint32(68) &&
631 msg.Flow.Classifier.DstPort == uint32(67) {
Matteo Scandolo99f18462019-10-28 14:14:28 -0700632
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100633 // 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 -0700634 o.DhcpFlowReceived = true
Matteo Scandoloc1147092019-10-29 09:38:33 -0700635
636 if o.Dhcp == true {
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100637 // NOTE we are receiving multiple DHCP flows but we shouldn't call the transition multiple times
Matteo Scandoloc1147092019-10-29 09:38:33 -0700638 if err := o.InternalState.Event("start_dhcp"); err != nil {
639 log.Errorf("Can't go to dhcp_started: %v", err)
640 }
641 } else {
642 onuLogger.WithFields(log.Fields{
643 "IntfId": o.PonPortID,
644 "OnuId": o.ID,
645 "SerialNumber": o.Sn(),
646 }).Warn("Not starting DHCP as Dhcp bit is not set in CLI parameters")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700647 }
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700648 }
649}
650
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700651// HexDecode converts the hex encoding to binary
652func HexDecode(pkt []byte) []byte {
653 p := make([]byte, len(pkt)/2)
654 for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 {
655 // Go figure this ;)
656 u := (pkt[i] & 15) + (pkt[i]>>6)*9
657 l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9
658 p[j] = u<<4 + l
659 }
660 onuLogger.Tracef("Omci decoded: %x.", p)
661 return p
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700662}
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700663
664// BBR methods
665
666func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) {
667 omciMsg := openolt.OmciMsg{
668 IntfId: intfId,
669 OnuId: onuId,
670 Pkt: pktBytes,
671 }
672
673 if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil {
674 log.WithFields(log.Fields{
675 "IntfId": intfId,
676 "OnuId": onuId,
677 "SerialNumber": common.OnuSnToString(sn),
678 "Pkt": omciMsg.Pkt,
679 }).Fatalf("Failed to send MIB Reset")
680 }
681 log.WithFields(log.Fields{
682 "IntfId": intfId,
683 "OnuId": onuId,
684 "SerialNumber": common.OnuSnToString(sn),
685 "Pkt": omciMsg.Pkt,
686 }).Tracef("Sent OMCI message %s", msgType)
687}
688
689func (onu *Onu) getNextTid(highPriority ...bool) uint16 {
690 var next uint16
691 if len(highPriority) > 0 && highPriority[0] {
692 next = onu.hpTid
693 onu.hpTid += 1
694 if onu.hpTid < 0x8000 {
695 onu.hpTid = 0x8000
696 }
697 } else {
698 next = onu.tid
699 onu.tid += 1
700 if onu.tid >= 0x8000 {
701 onu.tid = 1
702 }
703 }
704 return next
705}
706
707// TODO move this method in responders/omcisim
708func (o *Onu) StartOmci(client openolt.OpenoltClient) {
709 mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false))
710 sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client)
711}
712
713func (o *Onu) handleOmci(msg OmciIndicationMessage, client openolt.OpenoltClient) {
714 msgType, packet := omcilib.DecodeOmci(msg.OmciInd.Pkt)
715
716 log.WithFields(log.Fields{
717 "IntfId": msg.OmciInd.IntfId,
718 "OnuId": msg.OmciInd.OnuId,
719 "OnuSn": common.OnuSnToString(o.SerialNumber),
720 "Pkt": msg.OmciInd.Pkt,
721 "msgType": msgType,
722 }).Trace("ONU Receveives OMCI Msg")
723 switch msgType {
724 default:
Matteo Scandolo813402b2019-10-23 19:24:52 -0700725 log.WithFields(log.Fields{
726 "IntfId": msg.OmciInd.IntfId,
727 "OnuId": msg.OmciInd.OnuId,
728 "OnuSn": common.OnuSnToString(o.SerialNumber),
729 "Pkt": msg.OmciInd.Pkt,
730 "msgType": msgType,
731 }).Fatalf("unexpected frame: %v", packet)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700732 case omci.MibResetResponseType:
733 mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false))
734 sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client)
735 case omci.MibUploadResponseType:
736 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
737 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
738 case omci.MibUploadNextResponseType:
739 o.seqNumber++
740
741 if o.seqNumber > 290 {
742 // NOTE we are done with the MIB Upload (290 is the number of messages the omci-sim library will respond to)
743 galEnet, _ := omcilib.CreateGalEnetRequest(o.getNextTid(false))
744 sendOmciMsg(galEnet, o.PonPortID, o.ID, o.SerialNumber, "CreateGalEnetRequest", client)
745 } else {
746 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
747 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
748 }
749 case omci.CreateResponseType:
750 // NOTE Creating a GemPort,
751 // BBsim actually doesn't care about the values, so we can do we want with the parameters
752 // In the same way we can create a GemPort even without setting up UNIs/TConts/...
753 // but we need the GemPort to trigger the state change
754
755 if !o.HasGemPort {
756 // NOTE this sends a CreateRequestType and BBSim replies with a CreateResponseType
757 // thus we send this request only once
758 gemReq, _ := omcilib.CreateGemPortRequest(o.getNextTid(false))
759 sendOmciMsg(gemReq, o.PonPortID, o.ID, o.SerialNumber, "CreateGemPortRequest", client)
760 o.HasGemPort = true
761 } else {
762 if err := o.InternalState.Event("send_eapol_flow"); err != nil {
763 onuLogger.WithFields(log.Fields{
764 "OnuId": o.ID,
765 "IntfId": o.PonPortID,
766 "OnuSn": o.Sn(),
767 }).Errorf("Error while transitioning ONU State %v", err)
768 }
769 }
770
771 }
772}
773
774func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) {
775
776 classifierProto := openolt.Classifier{
777 EthType: uint32(layers.EthernetTypeEAPOL),
778 OVid: 4091,
779 }
780
781 actionProto := openolt.Action{}
782
783 downstreamFlow := openolt.Flow{
784 AccessIntfId: int32(o.PonPortID),
785 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700786 UniId: int32(0), // NOTE do not hardcode this, we need to support multiple UNIs
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700787 FlowId: uint32(o.ID),
788 FlowType: "downstream",
789 AllocId: int32(0),
790 NetworkIntfId: int32(0),
791 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
792 Classifier: &classifierProto,
793 Action: &actionProto,
794 Priority: int32(100),
795 Cookie: uint64(o.ID),
796 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
797 }
798
799 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
800 log.WithFields(log.Fields{
801 "IntfId": o.PonPortID,
802 "OnuId": o.ID,
803 "FlowId": downstreamFlow.FlowId,
804 "PortNo": downstreamFlow.PortNo,
805 "SerialNumber": common.OnuSnToString(o.SerialNumber),
806 }).Fatalf("Failed to EAPOL Flow")
807 }
808 log.WithFields(log.Fields{
809 "IntfId": o.PonPortID,
810 "OnuId": o.ID,
811 "FlowId": downstreamFlow.FlowId,
812 "PortNo": downstreamFlow.PortNo,
813 "SerialNumber": common.OnuSnToString(o.SerialNumber),
814 }).Info("Sent EAPOL Flow")
815}
816
817func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) {
818 classifierProto := openolt.Classifier{
819 EthType: uint32(layers.EthernetTypeIPv4),
820 SrcPort: uint32(68),
821 DstPort: uint32(67),
822 }
823
824 actionProto := openolt.Action{}
825
826 downstreamFlow := openolt.Flow{
827 AccessIntfId: int32(o.PonPortID),
828 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700829 UniId: int32(0), // FIXME do not hardcode this
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700830 FlowId: uint32(o.ID),
831 FlowType: "downstream",
832 AllocId: int32(0),
833 NetworkIntfId: int32(0),
834 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
835 Classifier: &classifierProto,
836 Action: &actionProto,
837 Priority: int32(100),
838 Cookie: uint64(o.ID),
839 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
840 }
841
842 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
843 log.WithFields(log.Fields{
844 "IntfId": o.PonPortID,
845 "OnuId": o.ID,
846 "FlowId": downstreamFlow.FlowId,
847 "PortNo": downstreamFlow.PortNo,
848 "SerialNumber": common.OnuSnToString(o.SerialNumber),
849 }).Fatalf("Failed to send DHCP Flow")
850 }
851 log.WithFields(log.Fields{
852 "IntfId": o.PonPortID,
853 "OnuId": o.ID,
854 "FlowId": downstreamFlow.FlowId,
855 "PortNo": downstreamFlow.PortNo,
856 "SerialNumber": common.OnuSnToString(o.SerialNumber),
857 }).Info("Sent DHCP Flow")
858}