blob: afa297cf6b50b6b9f969bba82cfd3e2b9e8df292 [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"
Arjun E K57a7fcb2020-01-30 06:44:45 +000033 "github.com/opencord/bbsim/internal/bbsim/responders/igmp"
Matteo Scandolo40e067f2019-10-16 16:59:41 -070034 "github.com/opencord/bbsim/internal/common"
35 omcilib "github.com/opencord/bbsim/internal/common/omci"
36 omcisim "github.com/opencord/omci-sim"
Matteo Scandolo3de9de02019-11-14 13:40:03 -080037 "github.com/opencord/voltha-protos/v2/go/openolt"
Matteo Scandolo4747d292019-08-05 11:50:18 -070038 log "github.com/sirupsen/logrus"
39)
40
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070041var onuLogger = log.WithFields(log.Fields{
42 "module": "ONU",
43})
44
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070045type Onu struct {
Matteo Scandoloe811ae92019-12-10 17:50:14 -080046 ID uint32
47 PonPortID uint32
48 PonPort PonPort
49 STag int
50 CTag int
51 Auth bool // automatically start EAPOL if set to true
52 Dhcp bool // automatically start DHCP if set to true
53 HwAddress net.HardwareAddr
54 InternalState *fsm.FSM
55 DiscoveryRetryDelay time.Duration
56
57 // ONU State
Matteo Scandolo27428702019-10-11 16:21:16 -070058 // PortNo comes with flows and it's used when sending packetIndications,
59 // There is one PortNo per UNI Port, for now we're only storing the first one
60 // FIXME add support for multiple UNIs
Matteo Scandolo99f18462019-10-28 14:14:28 -070061 PortNo uint32
62 DhcpFlowReceived bool
63
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070064 OperState *fsm.FSM
65 SerialNumber *openolt.SerialNumber
66
67 Channel chan Message // this Channel is to track state changes OMCI messages, EAPOL and DHCP packets
Matteo Scandolo40e067f2019-10-16 16:59:41 -070068
69 // OMCI params
70 tid uint16
71 hpTid uint16
72 seqNumber uint16
73 HasGemPort bool
74
75 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 -070076}
77
Matteo Scandolo99f18462019-10-28 14:14:28 -070078func (o *Onu) Sn() string {
Matteo Scandolo40e067f2019-10-16 16:59:41 -070079 return common.OnuSnToString(o.SerialNumber)
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070080}
81
Pragya Arya1cbefa42020-01-13 12:15:29 +053082func 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 -070083
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070084 o := Onu{
Pragya Arya1881df02020-01-29 18:05:01 +053085 ID: 0,
Matteo Scandoloe811ae92019-12-10 17:50:14 -080086 PonPortID: pon.ID,
87 PonPort: pon,
88 STag: sTag,
89 CTag: cTag,
90 Auth: auth,
91 Dhcp: dhcp,
92 HwAddress: net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, byte(pon.ID), byte(id)},
93 PortNo: 0,
94 tid: 0x1,
95 hpTid: 0x8000,
96 seqNumber: 0,
97 DoneChannel: make(chan bool, 1),
98 DhcpFlowReceived: false,
99 DiscoveryRetryDelay: 60 * time.Second, // this is used to send OnuDiscoveryIndications until an activate call is received
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700100 }
Pragya Arya1881df02020-01-29 18:05:01 +0530101 o.SerialNumber = o.NewSN(olt.ID, pon.ID, id)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700102
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700103 // NOTE this state machine is used to track the operational
104 // state as requested by VOLTHA
105 o.OperState = getOperStateFSM(func(e *fsm.Event) {
106 onuLogger.WithFields(log.Fields{
107 "ID": o.ID,
108 }).Debugf("Changing ONU OperState from %s to %s", e.Src, e.Dst)
109 })
110
111 // NOTE this state machine is used to activate the OMCI, EAPOL and DHCP clients
112 o.InternalState = fsm.NewFSM(
113 "created",
114 fsm.Events{
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700115 // DEVICE Lifecycle
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100116 {Name: "initialize", Src: []string{"created", "disabled"}, Dst: "initialized"},
Pragya Arya6a708d62020-01-01 17:17:20 +0530117 {Name: "discover", Src: []string{"initialized", "pon_disabled"}, Dst: "discovered"},
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700118 {Name: "enable", Src: []string{"discovered", "disabled"}, Dst: "enabled"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700119 {Name: "receive_eapol_flow", Src: []string{"enabled", "gem_port_added"}, Dst: "eapol_flow_received"},
120 {Name: "add_gem_port", Src: []string{"enabled", "eapol_flow_received"}, Dst: "gem_port_added"},
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100121 // NOTE should disabled state be different for oper_disabled (emulating an error) and admin_disabled (received a disabled call via VOLTHA)?
Pragya Arya1881df02020-01-29 18:05:01 +0530122 {Name: "disable", Src: []string{"enabled", "eapol_flow_received", "gem_port_added", "eap_response_success_received", "auth_failed", "dhcp_ack_received", "dhcp_failed", "pon_disabled"}, Dst: "disabled"},
Pragya Arya6a708d62020-01-01 17:17:20 +0530123 // 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 -0800124 {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 -0700125 // EAPOL
Matteo Scandolo5e081b52019-11-21 14:34:25 -0800126 {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 -0700127 {Name: "eap_start_sent", Src: []string{"auth_started"}, Dst: "eap_start_sent"},
128 {Name: "eap_response_identity_sent", Src: []string{"eap_start_sent"}, Dst: "eap_response_identity_sent"},
129 {Name: "eap_response_challenge_sent", Src: []string{"eap_response_identity_sent"}, Dst: "eap_response_challenge_sent"},
130 {Name: "eap_response_success_received", Src: []string{"eap_response_challenge_sent"}, Dst: "eap_response_success_received"},
131 {Name: "auth_failed", Src: []string{"auth_started", "eap_start_sent", "eap_response_identity_sent", "eap_response_challenge_sent"}, Dst: "auth_failed"},
132 // DHCP
Matteo Scandolofe9ac252019-10-25 11:40:17 -0700133 {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 -0700134 {Name: "dhcp_discovery_sent", Src: []string{"dhcp_started"}, Dst: "dhcp_discovery_sent"},
135 {Name: "dhcp_request_sent", Src: []string{"dhcp_discovery_sent"}, Dst: "dhcp_request_sent"},
136 {Name: "dhcp_ack_received", Src: []string{"dhcp_request_sent"}, Dst: "dhcp_ack_received"},
137 {Name: "dhcp_failed", Src: []string{"dhcp_started", "dhcp_discovery_sent", "dhcp_request_sent"}, Dst: "dhcp_failed"},
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700138 // BBR States
139 // TODO add start OMCI state
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100140 {Name: "send_eapol_flow", Src: []string{"initialized"}, Dst: "eapol_flow_sent"},
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700141 {Name: "send_dhcp_flow", Src: []string{"eapol_flow_sent"}, Dst: "dhcp_flow_sent"},
Arjun E K57a7fcb2020-01-30 06:44:45 +0000142 // IGMP
143 {Name: "igmp_join_start", Src: []string{"eap_response_success_received", "gem_port_added", "eapol_flow_received"}, Dst: "igmp_join_start"},
144 {Name: "igmp_join_done", Src: []string{"igmp_join_start"}, Dst: "igmp_join_done"},
145 {Name: "igmp_join_error", Src: []string{"igmp_join_start"}, Dst: "igmp_join_error"},
146 {Name: "igmp_leave", Src: []string{"igmp_join_start"}, Dst: "igmp_left"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700147 },
148 fsm.Callbacks{
149 "enter_state": func(e *fsm.Event) {
150 o.logStateChange(e.Src, e.Dst)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700151 },
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100152 "enter_initialized": func(e *fsm.Event) {
153 // create new channel for ProcessOnuMessages Go routine
154 o.Channel = make(chan Message, 2048)
Pragya Arya1cbefa42020-01-13 12:15:29 +0530155 if !isMock {
156 // start ProcessOnuMessages Go routine
157 go o.ProcessOnuMessages(olt.enableContext, *olt.OpenoltStream, nil)
158 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100159 },
160 "enter_discovered": func(e *fsm.Event) {
161 msg := Message{
162 Type: OnuDiscIndication,
163 Data: OnuDiscIndicationMessage{
164 Onu: &o,
165 OperState: UP,
166 },
167 }
168 o.Channel <- msg
169 },
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700170 "enter_enabled": func(event *fsm.Event) {
171 msg := Message{
172 Type: OnuIndication,
173 Data: OnuIndicationMessage{
174 OnuSN: o.SerialNumber,
175 PonPortID: o.PonPortID,
176 OperState: UP,
177 },
178 }
179 o.Channel <- msg
180 },
181 "enter_disabled": func(event *fsm.Event) {
182 msg := Message{
183 Type: OnuIndication,
184 Data: OnuIndicationMessage{
185 OnuSN: o.SerialNumber,
186 PonPortID: o.PonPortID,
187 OperState: DOWN,
188 },
189 }
190 o.Channel <- msg
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100191 // terminate the ONU's ProcessOnuMessages Go routine
192 close(o.Channel)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700193 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700194 "enter_auth_started": func(e *fsm.Event) {
195 o.logStateChange(e.Src, e.Dst)
196 msg := Message{
197 Type: StartEAPOL,
198 Data: PacketMessage{
199 PonPortID: o.PonPortID,
200 OnuID: o.ID,
201 },
202 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700203 o.Channel <- msg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700204 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700205 "enter_auth_failed": func(e *fsm.Event) {
206 onuLogger.WithFields(log.Fields{
207 "OnuId": o.ID,
208 "IntfId": o.PonPortID,
209 "OnuSn": o.Sn(),
210 }).Errorf("ONU failed to authenticate!")
211 },
Matteo Scandolo99f18462019-10-28 14:14:28 -0700212 "before_start_dhcp": func(e *fsm.Event) {
213 if o.DhcpFlowReceived == false {
214 e.Cancel(errors.New("cannot-go-to-dhcp-started-as-dhcp-flow-is-missing"))
215 }
216 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700217 "enter_dhcp_started": func(e *fsm.Event) {
218 msg := Message{
219 Type: StartDHCP,
220 Data: PacketMessage{
221 PonPortID: o.PonPortID,
222 OnuID: o.ID,
223 },
224 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700225 o.Channel <- msg
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700226 },
227 "enter_dhcp_failed": func(e *fsm.Event) {
228 onuLogger.WithFields(log.Fields{
229 "OnuId": o.ID,
230 "IntfId": o.PonPortID,
231 "OnuSn": o.Sn(),
232 }).Errorf("ONU failed to DHCP!")
233 },
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700234 "enter_eapol_flow_sent": func(e *fsm.Event) {
235 msg := Message{
236 Type: SendEapolFlow,
237 }
238 o.Channel <- msg
239 },
240 "enter_dhcp_flow_sent": func(e *fsm.Event) {
241 msg := Message{
242 Type: SendDhcpFlow,
243 }
244 o.Channel <- msg
245 },
Arjun E K57a7fcb2020-01-30 06:44:45 +0000246 "igmp_join_start": func(e *fsm.Event) {
247 msg := Message{
248 Type: IGMPMembershipReportV2,
249 }
250 o.Channel <- msg
251 },
252 "igmp_leave": func(e *fsm.Event) {
253 msg := Message{
254 Type: IGMPLeaveGroup}
255 o.Channel <- msg
256 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700257 },
258 )
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100259
Matteo Scandolo27428702019-10-11 16:21:16 -0700260 return &o
Matteo Scandolo4747d292019-08-05 11:50:18 -0700261}
262
William Kurkian0418bc82019-11-06 12:16:24 -0500263func (o *Onu) logStateChange(src string, dst string) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700264 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700265 "OnuId": o.ID,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700266 "IntfId": o.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700267 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700268 }).Debugf("Changing ONU InternalState from %s to %s", src, dst)
269}
270
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100271// ProcessOnuMessages starts indication channel for each ONU
David Bainbridge103cf022019-12-16 20:11:35 +0000272func (o *Onu) ProcessOnuMessages(ctx context.Context, stream openolt.Openolt_EnableIndicationServer, client openolt.OpenoltClient) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700273 onuLogger.WithFields(log.Fields{
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100274 "onuID": o.ID,
275 "onuSN": o.Sn(),
276 "ponPort": o.PonPortID,
277 }).Debug("Starting ONU Indication Channel")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700278
David Bainbridge103cf022019-12-16 20:11:35 +0000279loop:
280 for {
281 select {
282 case <-ctx.Done():
283 onuLogger.WithFields(log.Fields{
284 "onuID": o.ID,
285 "onuSN": o.Sn(),
286 }).Tracef("ONU message handling canceled via context")
287 break loop
288 case message, ok := <-o.Channel:
289 if !ok || ctx.Err() != nil {
290 onuLogger.WithFields(log.Fields{
291 "onuID": o.ID,
292 "onuSN": o.Sn(),
293 }).Tracef("ONU message handling canceled via channel close")
294 break loop
Matteo Scandolo075b1892019-10-07 12:11:07 -0700295 }
David Bainbridge103cf022019-12-16 20:11:35 +0000296 onuLogger.WithFields(log.Fields{
297 "onuID": o.ID,
298 "onuSN": o.Sn(),
299 "messageType": message.Type,
300 }).Tracef("Received message on ONU Channel")
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700301
David Bainbridge103cf022019-12-16 20:11:35 +0000302 switch message.Type {
303 case OnuDiscIndication:
304 msg, _ := message.Data.(OnuDiscIndicationMessage)
305 // NOTE we need to slow down and send ONU Discovery Indication in batches to better emulate a real scenario
Pragya Arya1881df02020-01-29 18:05:01 +0530306 time.Sleep(time.Duration(o.PonPort.Olt.Delay) * time.Millisecond)
David Bainbridge103cf022019-12-16 20:11:35 +0000307 o.sendOnuDiscIndication(msg, stream)
308 case OnuIndication:
309 msg, _ := message.Data.(OnuIndicationMessage)
310 o.sendOnuIndication(msg, stream)
311 case OMCI:
312 msg, _ := message.Data.(OmciMessage)
313 o.handleOmciMessage(msg, stream)
314 case FlowUpdate:
315 msg, _ := message.Data.(OnuFlowUpdateMessage)
316 o.handleFlowUpdate(msg)
317 case StartEAPOL:
318 log.Infof("Receive StartEAPOL message on ONU Channel")
319 eapol.SendEapStart(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.InternalState, stream)
320 case StartDHCP:
321 log.Infof("Receive StartDHCP message on ONU Channel")
322 // FIXME use id, ponId as SendEapStart
323 dhcp.SendDHCPDiscovery(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.InternalState, o.HwAddress, o.CTag, stream)
324 case OnuPacketOut:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700325
David Bainbridge103cf022019-12-16 20:11:35 +0000326 msg, _ := message.Data.(OnuPacketMessage)
327
328 log.WithFields(log.Fields{
329 "IntfId": msg.IntfId,
330 "OnuId": msg.OnuId,
331 "pktType": msg.Type,
332 }).Trace("Received OnuPacketOut Message")
333
334 if msg.Type == packetHandlers.EAPOL {
335 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
336 } else if msg.Type == packetHandlers.DHCP {
337 // NOTE here we receive packets going from the DHCP Server to the ONU
338 // for now we expect them to be double-tagged, but ideally the should be single tagged
339 dhcp.HandleNextPacket(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.CTag, o.InternalState, msg.Packet, stream)
340 }
341 case OnuPacketIn:
342 // NOTE we only receive BBR packets here.
343 // Eapol.HandleNextPacket can handle both BBSim and BBr cases so the call is the same
344 // in the DHCP case VOLTHA only act as a proxy, the behaviour is completely different thus we have a dhcp.HandleNextBbrPacket
345 msg, _ := message.Data.(OnuPacketMessage)
346
347 log.WithFields(log.Fields{
348 "IntfId": msg.IntfId,
349 "OnuId": msg.OnuId,
350 "pktType": msg.Type,
351 }).Trace("Received OnuPacketIn Message")
352
353 if msg.Type == packetHandlers.EAPOL {
354 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
355 } else if msg.Type == packetHandlers.DHCP {
356 dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.STag, o.HwAddress, o.DoneChannel, msg.Packet, client)
357 }
358 case DyingGaspIndication:
359 msg, _ := message.Data.(DyingGaspIndicationMessage)
360 o.sendDyingGaspInd(msg, stream)
361 case OmciIndication:
362 msg, _ := message.Data.(OmciIndicationMessage)
363 o.handleOmci(msg, client)
364 case SendEapolFlow:
365 o.sendEapolFlow(client)
366 case SendDhcpFlow:
367 o.sendDhcpFlow(client)
Arjun E K57a7fcb2020-01-30 06:44:45 +0000368 case IGMPMembershipReportV2:
369 log.Infof("Recieved IGMPMembershipReportV2 message on ONU channel")
370 igmp.SendIGMPMembershipReportV2(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
371 case IGMPLeaveGroup:
372 log.Infof("Recieved IGMPLeaveGroupV2 message on ONU channel")
373 igmp.SendIGMPLeaveGroupV2(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
David Bainbridge103cf022019-12-16 20:11:35 +0000374 default:
375 onuLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700376 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700377 }
378 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100379 onuLogger.WithFields(log.Fields{
380 "onuID": o.ID,
381 "onuSN": o.Sn(),
382 }).Debug("Stopped handling ONU Indication Channel")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700383}
384
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800385func (o *Onu) processOmciMessage(message omcisim.OmciChMessage, stream openolt.Openolt_EnableIndicationServer) {
William Kurkian9dadc5b2019-10-22 13:51:57 -0400386 switch message.Type {
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800387 case omcisim.UniLinkUp, omcisim.UniLinkDown:
388 onuLogger.WithFields(log.Fields{
389 "OnuId": message.Data.OnuId,
390 "IntfId": message.Data.IntfId,
391 "Type": message.Type,
392 }).Infof("UNI Link Alarm")
393 // TODO send to OLT
394
395 omciInd := openolt.OmciIndication{
396 IntfId: message.Data.IntfId,
397 OnuId: message.Data.OnuId,
398 Pkt: message.Packet,
399 }
400
401 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
402 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
403 onuLogger.WithFields(log.Fields{
404 "IntfId": o.PonPortID,
405 "SerialNumber": o.Sn(),
406 "Type": message.Type,
407 "omciPacket": omciInd.Pkt,
408 }).Errorf("Failed to send UNI Link Alarm: %v", err)
409 return
410 }
411
412 onuLogger.WithFields(log.Fields{
413 "IntfId": o.PonPortID,
414 "SerialNumber": o.Sn(),
415 "Type": message.Type,
416 "omciPacket": omciInd.Pkt,
417 }).Info("UNI Link alarm sent")
418
William Kurkian9dadc5b2019-10-22 13:51:57 -0400419 case omcisim.GemPortAdded:
420 log.WithFields(log.Fields{
421 "OnuId": message.Data.OnuId,
422 "IntfId": message.Data.IntfId,
423 }).Infof("GemPort Added")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700424
William Kurkian9dadc5b2019-10-22 13:51:57 -0400425 // NOTE if we receive the GemPort but we don't have EAPOL flows
426 // go an intermediate state, otherwise start auth
427 if o.InternalState.Is("enabled") {
428 if err := o.InternalState.Event("add_gem_port"); err != nil {
429 log.Errorf("Can't go to gem_port_added: %v", err)
430 }
431 } else if o.InternalState.Is("eapol_flow_received") {
Matteo Scandolo3c656a12019-12-10 09:54:51 -0800432 if o.Auth == true {
433 if err := o.InternalState.Event("start_auth"); err != nil {
434 log.Warnf("Can't go to auth_started: %v", err)
435 }
436 } else {
437 onuLogger.WithFields(log.Fields{
438 "IntfId": o.PonPortID,
439 "OnuId": o.ID,
440 "SerialNumber": o.Sn(),
441 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700442 }
443 }
444 }
445}
446
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100447func (o Onu) NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700448
449 sn := new(openolt.SerialNumber)
450
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700451 //sn = new(openolt.SerialNumber)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700452 sn.VendorId = []byte("BBSM")
453 sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)}
454
455 return sn
456}
457
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700458// NOTE handle_/process methods can change the ONU internal state as they are receiving messages
459// send method should not change the ONU state
460
William Kurkian0418bc82019-11-06 12:16:24 -0500461func (o *Onu) sendDyingGaspInd(msg DyingGaspIndicationMessage, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700462 alarmData := &openolt.AlarmIndication_DyingGaspInd{
463 DyingGaspInd: &openolt.DyingGaspIndication{
464 IntfId: msg.PonPortID,
465 OnuId: msg.OnuID,
466 Status: "on",
467 },
468 }
469 data := &openolt.Indication_AlarmInd{AlarmInd: &openolt.AlarmIndication{Data: alarmData}}
470
471 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
472 onuLogger.Errorf("Failed to send DyingGaspInd : %v", err)
473 return err
474 }
475 onuLogger.WithFields(log.Fields{
476 "IntfId": msg.PonPortID,
477 "OnuSn": o.Sn(),
478 "OnuId": msg.OnuID,
479 }).Info("sendDyingGaspInd")
480 return nil
481}
482
William Kurkian0418bc82019-11-06 12:16:24 -0500483func (o *Onu) sendOnuDiscIndication(msg OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700484 discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700485 IntfId: msg.Onu.PonPortID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700486 SerialNumber: msg.Onu.SerialNumber,
487 }}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700488
Matteo Scandolo4747d292019-08-05 11:50:18 -0700489 if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700490 log.Errorf("Failed to send Indication_OnuDiscInd: %v", err)
Matteo Scandolo99f18462019-10-28 14:14:28 -0700491 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700492 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700493
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700494 onuLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700495 "IntfId": msg.Onu.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700496 "OnuSn": msg.Onu.Sn(),
497 "OnuId": o.ID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700498 }).Debug("Sent Indication_OnuDiscInd")
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800499
500 // after DiscoveryRetryDelay check if the state is the same and in case send a new OnuDiscIndication
501 go func(delay time.Duration) {
Matteo Scandolo569e7172019-12-20 11:51:51 -0800502 time.Sleep(delay)
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800503 if o.InternalState.Current() == "discovered" {
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800504 o.sendOnuDiscIndication(msg, stream)
505 }
506 }(o.DiscoveryRetryDelay)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700507}
508
William Kurkian0418bc82019-11-06 12:16:24 -0500509func (o *Onu) sendOnuIndication(msg OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700510 // NOTE voltha returns an ID, but if we use that ID then it complains:
511 // expected_onu_id: 1, received_onu_id: 1024, event: ONU-id-mismatch, can happen if both voltha and the olt rebooted
512 // so we're using the internal ID that is 1
513 // o.ID = msg.OnuID
Matteo Scandolo4747d292019-08-05 11:50:18 -0700514
515 indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700516 IntfId: o.PonPortID,
517 OnuId: o.ID,
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700518 OperState: msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700519 AdminState: o.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700520 SerialNumber: o.SerialNumber,
521 }}
522 if err := stream.Send(&openolt.Indication{Data: indData}); err != nil {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700523 // TODO do we need to transition to a broken state?
Matteo Scandolo11006992019-08-28 11:29:46 -0700524 log.Errorf("Failed to send Indication_OnuInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700525 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700526 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700527 "IntfId": o.PonPortID,
528 "OnuId": o.ID,
529 "OperState": msg.OperState.String(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700530 "AdminState": msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700531 "OnuSn": o.Sn(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700532 }).Debug("Sent Indication_OnuInd")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700533
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700534}
535
William Kurkian0418bc82019-11-06 12:16:24 -0500536func (o *Onu) handleOmciMessage(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700537
538 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700539 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700540 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700541 "omciPacket": msg.omciMsg.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700542 }).Tracef("Received OMCI message")
543
544 var omciInd openolt.OmciIndication
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700545 respPkt, err := omcisim.OmciSim(o.PonPortID, o.ID, HexDecode(msg.omciMsg.Pkt))
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700546 if err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700547 onuLogger.WithFields(log.Fields{
548 "IntfId": o.PonPortID,
549 "SerialNumber": o.Sn(),
550 "omciPacket": omciInd.Pkt,
551 "msg": msg,
552 }).Errorf("Error handling OMCI message %v", msg)
553 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700554 }
555
556 omciInd.IntfId = o.PonPortID
557 omciInd.OnuId = o.ID
558 omciInd.Pkt = respPkt
559
560 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
561 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700562 onuLogger.WithFields(log.Fields{
563 "IntfId": o.PonPortID,
564 "SerialNumber": o.Sn(),
565 "omciPacket": omciInd.Pkt,
566 "msg": msg,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700567 }).Errorf("send omcisim indication failed: %v", err)
Matteo Scandolo27428702019-10-11 16:21:16 -0700568 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700569 }
570 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700571 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700572 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700573 "omciPacket": omciInd.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700574 }).Tracef("Sent OMCI message")
575}
576
Matteo Scandolo27428702019-10-11 16:21:16 -0700577func (o *Onu) storePortNumber(portNo uint32) {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700578 // NOTE this needed only as long as we don't support multiple UNIs
Matteo Scandolo27428702019-10-11 16:21:16 -0700579 // we need to add support for multiple UNIs
580 // the action plan is:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700581 // - refactor the omcisim-sim library to use https://github.com/cboling/omci instead of canned messages
Matteo Scandolo27428702019-10-11 16:21:16 -0700582 // - change the library so that it reports a single UNI and remove this workaroung
583 // - add support for multiple UNIs in BBSim
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700584 if o.PortNo == 0 || portNo < o.PortNo {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700585 onuLogger.WithFields(log.Fields{
586 "IntfId": o.PonPortID,
587 "OnuId": o.ID,
588 "SerialNumber": o.Sn(),
589 "OnuPortNo": o.PortNo,
590 "FlowPortNo": portNo,
591 }).Debug("Storing ONU portNo")
Matteo Scandolo27428702019-10-11 16:21:16 -0700592 o.PortNo = portNo
593 }
594}
595
William Kurkian0418bc82019-11-06 12:16:24 -0500596func (o *Onu) SetID(id uint32) {
597 o.ID = id
598}
599
Matteo Scandolo813402b2019-10-23 19:24:52 -0700600func (o *Onu) handleFlowUpdate(msg OnuFlowUpdateMessage) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700601 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700602 "DstPort": msg.Flow.Classifier.DstPort,
603 "EthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType),
604 "FlowId": msg.Flow.FlowId,
605 "FlowType": msg.Flow.FlowType,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700606 "InnerVlan": msg.Flow.Classifier.IVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700607 "IntfId": msg.Flow.AccessIntfId,
608 "IpProto": msg.Flow.Classifier.IpProto,
609 "OnuId": msg.Flow.OnuId,
610 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700611 "OuterVlan": msg.Flow.Classifier.OVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700612 "PortNo": msg.Flow.PortNo,
613 "SrcPort": msg.Flow.Classifier.SrcPort,
614 "UniID": msg.Flow.UniId,
615 }).Debug("ONU receives Flow")
616
Matteo Scandolo813402b2019-10-23 19:24:52 -0700617 if msg.Flow.UniId != 0 {
618 // as of now BBSim only support a single UNI, so ignore everything that is not targeted to it
619 onuLogger.WithFields(log.Fields{
620 "IntfId": o.PonPortID,
621 "OnuId": o.ID,
622 "SerialNumber": o.Sn(),
623 }).Debug("Ignoring flow as it's not for the first UNI")
624 return
625 }
626
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700627 if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) && msg.Flow.Classifier.OVid == 4091 {
Matteo Scandolo27428702019-10-11 16:21:16 -0700628 // NOTE storing the PortNO, it's needed when sending PacketIndications
Matteo Scandolo813402b2019-10-23 19:24:52 -0700629 o.storePortNumber(uint32(msg.Flow.PortNo))
Matteo Scandolo27428702019-10-11 16:21:16 -0700630
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700631 // NOTE if we receive the EAPOL flows but we don't have GemPorts
632 // go an intermediate state, otherwise start auth
633 if o.InternalState.Is("enabled") {
634 if err := o.InternalState.Event("receive_eapol_flow"); err != nil {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700635 log.Warnf("Can't go to eapol_flow_received: %v", err)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700636 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700637 } else if o.InternalState.Is("gem_port_added") {
Matteo Scandoloc1147092019-10-29 09:38:33 -0700638
639 if o.Auth == true {
640 if err := o.InternalState.Event("start_auth"); err != nil {
641 log.Warnf("Can't go to auth_started: %v", err)
642 }
643 } else {
644 onuLogger.WithFields(log.Fields{
645 "IntfId": o.PonPortID,
646 "OnuId": o.ID,
647 "SerialNumber": o.Sn(),
648 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700649 }
Matteo Scandoloc1147092019-10-29 09:38:33 -0700650
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700651 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700652 } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) &&
653 msg.Flow.Classifier.SrcPort == uint32(68) &&
654 msg.Flow.Classifier.DstPort == uint32(67) {
Matteo Scandolo99f18462019-10-28 14:14:28 -0700655
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100656 // 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 -0700657 o.DhcpFlowReceived = true
Matteo Scandoloc1147092019-10-29 09:38:33 -0700658
659 if o.Dhcp == true {
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100660 // NOTE we are receiving multiple DHCP flows but we shouldn't call the transition multiple times
Matteo Scandoloc1147092019-10-29 09:38:33 -0700661 if err := o.InternalState.Event("start_dhcp"); err != nil {
662 log.Errorf("Can't go to dhcp_started: %v", err)
663 }
664 } else {
665 onuLogger.WithFields(log.Fields{
666 "IntfId": o.PonPortID,
667 "OnuId": o.ID,
668 "SerialNumber": o.Sn(),
669 }).Warn("Not starting DHCP as Dhcp bit is not set in CLI parameters")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700670 }
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700671 }
672}
673
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700674// HexDecode converts the hex encoding to binary
675func HexDecode(pkt []byte) []byte {
676 p := make([]byte, len(pkt)/2)
677 for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 {
678 // Go figure this ;)
679 u := (pkt[i] & 15) + (pkt[i]>>6)*9
680 l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9
681 p[j] = u<<4 + l
682 }
683 onuLogger.Tracef("Omci decoded: %x.", p)
684 return p
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700685}
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700686
687// BBR methods
688
689func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) {
690 omciMsg := openolt.OmciMsg{
691 IntfId: intfId,
692 OnuId: onuId,
693 Pkt: pktBytes,
694 }
695
696 if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil {
697 log.WithFields(log.Fields{
698 "IntfId": intfId,
699 "OnuId": onuId,
700 "SerialNumber": common.OnuSnToString(sn),
701 "Pkt": omciMsg.Pkt,
702 }).Fatalf("Failed to send MIB Reset")
703 }
704 log.WithFields(log.Fields{
705 "IntfId": intfId,
706 "OnuId": onuId,
707 "SerialNumber": common.OnuSnToString(sn),
708 "Pkt": omciMsg.Pkt,
709 }).Tracef("Sent OMCI message %s", msgType)
710}
711
712func (onu *Onu) getNextTid(highPriority ...bool) uint16 {
713 var next uint16
714 if len(highPriority) > 0 && highPriority[0] {
715 next = onu.hpTid
716 onu.hpTid += 1
717 if onu.hpTid < 0x8000 {
718 onu.hpTid = 0x8000
719 }
720 } else {
721 next = onu.tid
722 onu.tid += 1
723 if onu.tid >= 0x8000 {
724 onu.tid = 1
725 }
726 }
727 return next
728}
729
730// TODO move this method in responders/omcisim
731func (o *Onu) StartOmci(client openolt.OpenoltClient) {
732 mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false))
733 sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client)
734}
735
736func (o *Onu) handleOmci(msg OmciIndicationMessage, client openolt.OpenoltClient) {
737 msgType, packet := omcilib.DecodeOmci(msg.OmciInd.Pkt)
738
739 log.WithFields(log.Fields{
740 "IntfId": msg.OmciInd.IntfId,
741 "OnuId": msg.OmciInd.OnuId,
742 "OnuSn": common.OnuSnToString(o.SerialNumber),
743 "Pkt": msg.OmciInd.Pkt,
744 "msgType": msgType,
745 }).Trace("ONU Receveives OMCI Msg")
746 switch msgType {
747 default:
Matteo Scandolo813402b2019-10-23 19:24:52 -0700748 log.WithFields(log.Fields{
749 "IntfId": msg.OmciInd.IntfId,
750 "OnuId": msg.OmciInd.OnuId,
751 "OnuSn": common.OnuSnToString(o.SerialNumber),
752 "Pkt": msg.OmciInd.Pkt,
753 "msgType": msgType,
754 }).Fatalf("unexpected frame: %v", packet)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700755 case omci.MibResetResponseType:
756 mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false))
757 sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client)
758 case omci.MibUploadResponseType:
759 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
760 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
761 case omci.MibUploadNextResponseType:
762 o.seqNumber++
763
764 if o.seqNumber > 290 {
765 // NOTE we are done with the MIB Upload (290 is the number of messages the omci-sim library will respond to)
766 galEnet, _ := omcilib.CreateGalEnetRequest(o.getNextTid(false))
767 sendOmciMsg(galEnet, o.PonPortID, o.ID, o.SerialNumber, "CreateGalEnetRequest", client)
768 } else {
769 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
770 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
771 }
772 case omci.CreateResponseType:
773 // NOTE Creating a GemPort,
774 // BBsim actually doesn't care about the values, so we can do we want with the parameters
775 // In the same way we can create a GemPort even without setting up UNIs/TConts/...
776 // but we need the GemPort to trigger the state change
777
778 if !o.HasGemPort {
779 // NOTE this sends a CreateRequestType and BBSim replies with a CreateResponseType
780 // thus we send this request only once
781 gemReq, _ := omcilib.CreateGemPortRequest(o.getNextTid(false))
782 sendOmciMsg(gemReq, o.PonPortID, o.ID, o.SerialNumber, "CreateGemPortRequest", client)
783 o.HasGemPort = true
784 } else {
785 if err := o.InternalState.Event("send_eapol_flow"); err != nil {
786 onuLogger.WithFields(log.Fields{
787 "OnuId": o.ID,
788 "IntfId": o.PonPortID,
789 "OnuSn": o.Sn(),
790 }).Errorf("Error while transitioning ONU State %v", err)
791 }
792 }
793
794 }
795}
796
797func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) {
798
799 classifierProto := openolt.Classifier{
800 EthType: uint32(layers.EthernetTypeEAPOL),
801 OVid: 4091,
802 }
803
804 actionProto := openolt.Action{}
805
806 downstreamFlow := openolt.Flow{
807 AccessIntfId: int32(o.PonPortID),
808 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700809 UniId: int32(0), // NOTE do not hardcode this, we need to support multiple UNIs
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700810 FlowId: uint32(o.ID),
811 FlowType: "downstream",
812 AllocId: int32(0),
813 NetworkIntfId: int32(0),
814 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
815 Classifier: &classifierProto,
816 Action: &actionProto,
817 Priority: int32(100),
818 Cookie: uint64(o.ID),
819 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
820 }
821
822 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
823 log.WithFields(log.Fields{
824 "IntfId": o.PonPortID,
825 "OnuId": o.ID,
826 "FlowId": downstreamFlow.FlowId,
827 "PortNo": downstreamFlow.PortNo,
828 "SerialNumber": common.OnuSnToString(o.SerialNumber),
829 }).Fatalf("Failed to EAPOL Flow")
830 }
831 log.WithFields(log.Fields{
832 "IntfId": o.PonPortID,
833 "OnuId": o.ID,
834 "FlowId": downstreamFlow.FlowId,
835 "PortNo": downstreamFlow.PortNo,
836 "SerialNumber": common.OnuSnToString(o.SerialNumber),
837 }).Info("Sent EAPOL Flow")
838}
839
840func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) {
841 classifierProto := openolt.Classifier{
842 EthType: uint32(layers.EthernetTypeIPv4),
843 SrcPort: uint32(68),
844 DstPort: uint32(67),
845 }
846
847 actionProto := openolt.Action{}
848
849 downstreamFlow := openolt.Flow{
850 AccessIntfId: int32(o.PonPortID),
851 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700852 UniId: int32(0), // FIXME do not hardcode this
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700853 FlowId: uint32(o.ID),
854 FlowType: "downstream",
855 AllocId: int32(0),
856 NetworkIntfId: int32(0),
857 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
858 Classifier: &classifierProto,
859 Action: &actionProto,
860 Priority: int32(100),
861 Cookie: uint64(o.ID),
862 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
863 }
864
865 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
866 log.WithFields(log.Fields{
867 "IntfId": o.PonPortID,
868 "OnuId": o.ID,
869 "FlowId": downstreamFlow.FlowId,
870 "PortNo": downstreamFlow.PortNo,
871 "SerialNumber": common.OnuSnToString(o.SerialNumber),
872 }).Fatalf("Failed to send DHCP Flow")
873 }
874 log.WithFields(log.Fields{
875 "IntfId": o.PonPortID,
876 "OnuId": o.ID,
877 "FlowId": downstreamFlow.FlowId,
878 "PortNo": downstreamFlow.PortNo,
879 "SerialNumber": common.OnuSnToString(o.SerialNumber),
880 }).Info("Sent DHCP Flow")
881}