blob: c1ada1ca0460390212e0b3658bf47e095795c06a [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
Pragya Arya2225f202020-01-29 18:05:01 +053055 DiscoveryRetryDelay time.Duration // this is the time between subsequent Discovery Indication
56 DiscoveryDelay time.Duration // this is the time to send the first Discovery Indication
Matteo Scandoloe811ae92019-12-10 17:50:14 -080057
58 // ONU State
Matteo Scandolo27428702019-10-11 16:21:16 -070059 // PortNo comes with flows and it's used when sending packetIndications,
60 // There is one PortNo per UNI Port, for now we're only storing the first one
61 // FIXME add support for multiple UNIs
Matteo Scandolo99f18462019-10-28 14:14:28 -070062 PortNo uint32
63 DhcpFlowReceived bool
64
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070065 OperState *fsm.FSM
66 SerialNumber *openolt.SerialNumber
67
68 Channel chan Message // this Channel is to track state changes OMCI messages, EAPOL and DHCP packets
Matteo Scandolo40e067f2019-10-16 16:59:41 -070069
70 // OMCI params
71 tid uint16
72 hpTid uint16
73 seqNumber uint16
74 HasGemPort bool
75
76 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 -070077}
78
Matteo Scandolo99f18462019-10-28 14:14:28 -070079func (o *Onu) Sn() string {
Matteo Scandolo40e067f2019-10-16 16:59:41 -070080 return common.OnuSnToString(o.SerialNumber)
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070081}
82
Pragya Arya2225f202020-01-29 18:05:01 +053083func CreateONU(olt *OltDevice, pon PonPort, id uint32, sTag int, cTag int, auth bool, dhcp bool, delay time.Duration, isMock bool) *Onu {
Matteo Scandolo4747d292019-08-05 11:50:18 -070084
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070085 o := Onu{
Pragya Arya2225f202020-01-29 18:05:01 +053086 ID: 0,
Matteo Scandoloe811ae92019-12-10 17:50:14 -080087 PonPortID: pon.ID,
88 PonPort: pon,
89 STag: sTag,
90 CTag: cTag,
91 Auth: auth,
92 Dhcp: dhcp,
93 HwAddress: net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, byte(pon.ID), byte(id)},
94 PortNo: 0,
95 tid: 0x1,
96 hpTid: 0x8000,
97 seqNumber: 0,
98 DoneChannel: make(chan bool, 1),
99 DhcpFlowReceived: false,
100 DiscoveryRetryDelay: 60 * time.Second, // this is used to send OnuDiscoveryIndications until an activate call is received
Pragya Arya2225f202020-01-29 18:05:01 +0530101 DiscoveryDelay: delay,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700102 }
Pragya Arya2225f202020-01-29 18:05:01 +0530103 o.SerialNumber = o.NewSN(olt.ID, pon.ID, id)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700104
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700105 // NOTE this state machine is used to track the operational
106 // state as requested by VOLTHA
107 o.OperState = getOperStateFSM(func(e *fsm.Event) {
108 onuLogger.WithFields(log.Fields{
109 "ID": o.ID,
110 }).Debugf("Changing ONU OperState from %s to %s", e.Src, e.Dst)
111 })
112
113 // NOTE this state machine is used to activate the OMCI, EAPOL and DHCP clients
114 o.InternalState = fsm.NewFSM(
115 "created",
116 fsm.Events{
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700117 // DEVICE Lifecycle
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100118 {Name: "initialize", Src: []string{"created", "disabled"}, Dst: "initialized"},
Pragya Arya6a708d62020-01-01 17:17:20 +0530119 {Name: "discover", Src: []string{"initialized", "pon_disabled"}, Dst: "discovered"},
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700120 {Name: "enable", Src: []string{"discovered", "disabled"}, Dst: "enabled"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700121 {Name: "receive_eapol_flow", Src: []string{"enabled", "gem_port_added"}, Dst: "eapol_flow_received"},
122 {Name: "add_gem_port", Src: []string{"enabled", "eapol_flow_received"}, Dst: "gem_port_added"},
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100123 // NOTE should disabled state be different for oper_disabled (emulating an error) and admin_disabled (received a disabled call via VOLTHA)?
Pragya Arya2225f202020-01-29 18:05:01 +0530124 {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 +0530125 // 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 -0800126 {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 -0700127 // EAPOL
Matteo Scandolo5e081b52019-11-21 14:34:25 -0800128 {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 -0700129 {Name: "eap_start_sent", Src: []string{"auth_started"}, Dst: "eap_start_sent"},
130 {Name: "eap_response_identity_sent", Src: []string{"eap_start_sent"}, Dst: "eap_response_identity_sent"},
131 {Name: "eap_response_challenge_sent", Src: []string{"eap_response_identity_sent"}, Dst: "eap_response_challenge_sent"},
132 {Name: "eap_response_success_received", Src: []string{"eap_response_challenge_sent"}, Dst: "eap_response_success_received"},
133 {Name: "auth_failed", Src: []string{"auth_started", "eap_start_sent", "eap_response_identity_sent", "eap_response_challenge_sent"}, Dst: "auth_failed"},
134 // DHCP
Matteo Scandolofe9ac252019-10-25 11:40:17 -0700135 {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 -0700136 {Name: "dhcp_discovery_sent", Src: []string{"dhcp_started"}, Dst: "dhcp_discovery_sent"},
137 {Name: "dhcp_request_sent", Src: []string{"dhcp_discovery_sent"}, Dst: "dhcp_request_sent"},
138 {Name: "dhcp_ack_received", Src: []string{"dhcp_request_sent"}, Dst: "dhcp_ack_received"},
139 {Name: "dhcp_failed", Src: []string{"dhcp_started", "dhcp_discovery_sent", "dhcp_request_sent"}, Dst: "dhcp_failed"},
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700140 // BBR States
141 // TODO add start OMCI state
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100142 {Name: "send_eapol_flow", Src: []string{"initialized"}, Dst: "eapol_flow_sent"},
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700143 {Name: "send_dhcp_flow", Src: []string{"eapol_flow_sent"}, Dst: "dhcp_flow_sent"},
Arjun E K57a7fcb2020-01-30 06:44:45 +0000144 // IGMP
145 {Name: "igmp_join_start", Src: []string{"eap_response_success_received", "gem_port_added", "eapol_flow_received"}, Dst: "igmp_join_start"},
146 {Name: "igmp_join_done", Src: []string{"igmp_join_start"}, Dst: "igmp_join_done"},
147 {Name: "igmp_join_error", Src: []string{"igmp_join_start"}, Dst: "igmp_join_error"},
148 {Name: "igmp_leave", Src: []string{"igmp_join_start"}, Dst: "igmp_left"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700149 },
150 fsm.Callbacks{
151 "enter_state": func(e *fsm.Event) {
152 o.logStateChange(e.Src, e.Dst)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700153 },
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100154 "enter_initialized": func(e *fsm.Event) {
155 // create new channel for ProcessOnuMessages Go routine
156 o.Channel = make(chan Message, 2048)
Pragya Arya1cbefa42020-01-13 12:15:29 +0530157 if !isMock {
158 // start ProcessOnuMessages Go routine
159 go o.ProcessOnuMessages(olt.enableContext, *olt.OpenoltStream, nil)
160 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100161 },
162 "enter_discovered": func(e *fsm.Event) {
163 msg := Message{
164 Type: OnuDiscIndication,
165 Data: OnuDiscIndicationMessage{
166 Onu: &o,
167 OperState: UP,
168 },
169 }
170 o.Channel <- msg
171 },
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700172 "enter_enabled": func(event *fsm.Event) {
173 msg := Message{
174 Type: OnuIndication,
175 Data: OnuIndicationMessage{
176 OnuSN: o.SerialNumber,
177 PonPortID: o.PonPortID,
178 OperState: UP,
179 },
180 }
181 o.Channel <- msg
182 },
183 "enter_disabled": func(event *fsm.Event) {
184 msg := Message{
185 Type: OnuIndication,
186 Data: OnuIndicationMessage{
187 OnuSN: o.SerialNumber,
188 PonPortID: o.PonPortID,
189 OperState: DOWN,
190 },
191 }
192 o.Channel <- msg
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100193 // terminate the ONU's ProcessOnuMessages Go routine
194 close(o.Channel)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700195 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700196 "enter_auth_started": func(e *fsm.Event) {
197 o.logStateChange(e.Src, e.Dst)
198 msg := Message{
199 Type: StartEAPOL,
200 Data: PacketMessage{
201 PonPortID: o.PonPortID,
202 OnuID: o.ID,
203 },
204 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700205 o.Channel <- msg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700206 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700207 "enter_auth_failed": func(e *fsm.Event) {
208 onuLogger.WithFields(log.Fields{
209 "OnuId": o.ID,
210 "IntfId": o.PonPortID,
211 "OnuSn": o.Sn(),
212 }).Errorf("ONU failed to authenticate!")
213 },
Matteo Scandolo99f18462019-10-28 14:14:28 -0700214 "before_start_dhcp": func(e *fsm.Event) {
215 if o.DhcpFlowReceived == false {
216 e.Cancel(errors.New("cannot-go-to-dhcp-started-as-dhcp-flow-is-missing"))
217 }
218 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700219 "enter_dhcp_started": func(e *fsm.Event) {
220 msg := Message{
221 Type: StartDHCP,
222 Data: PacketMessage{
223 PonPortID: o.PonPortID,
224 OnuID: o.ID,
225 },
226 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700227 o.Channel <- msg
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700228 },
229 "enter_dhcp_failed": func(e *fsm.Event) {
230 onuLogger.WithFields(log.Fields{
231 "OnuId": o.ID,
232 "IntfId": o.PonPortID,
233 "OnuSn": o.Sn(),
234 }).Errorf("ONU failed to DHCP!")
235 },
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700236 "enter_eapol_flow_sent": func(e *fsm.Event) {
237 msg := Message{
238 Type: SendEapolFlow,
239 }
240 o.Channel <- msg
241 },
242 "enter_dhcp_flow_sent": func(e *fsm.Event) {
243 msg := Message{
244 Type: SendDhcpFlow,
245 }
246 o.Channel <- msg
247 },
Arjun E K57a7fcb2020-01-30 06:44:45 +0000248 "igmp_join_start": func(e *fsm.Event) {
249 msg := Message{
250 Type: IGMPMembershipReportV2,
251 }
252 o.Channel <- msg
253 },
254 "igmp_leave": func(e *fsm.Event) {
255 msg := Message{
256 Type: IGMPLeaveGroup}
257 o.Channel <- msg
258 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700259 },
260 )
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100261
Matteo Scandolo27428702019-10-11 16:21:16 -0700262 return &o
Matteo Scandolo4747d292019-08-05 11:50:18 -0700263}
264
William Kurkian0418bc82019-11-06 12:16:24 -0500265func (o *Onu) logStateChange(src string, dst string) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700266 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700267 "OnuId": o.ID,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700268 "IntfId": o.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700269 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700270 }).Debugf("Changing ONU InternalState from %s to %s", src, dst)
271}
272
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100273// ProcessOnuMessages starts indication channel for each ONU
David Bainbridge103cf022019-12-16 20:11:35 +0000274func (o *Onu) ProcessOnuMessages(ctx context.Context, stream openolt.Openolt_EnableIndicationServer, client openolt.OpenoltClient) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700275 onuLogger.WithFields(log.Fields{
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100276 "onuID": o.ID,
277 "onuSN": o.Sn(),
278 "ponPort": o.PonPortID,
279 }).Debug("Starting ONU Indication Channel")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700280
David Bainbridge103cf022019-12-16 20:11:35 +0000281loop:
282 for {
283 select {
284 case <-ctx.Done():
285 onuLogger.WithFields(log.Fields{
286 "onuID": o.ID,
287 "onuSN": o.Sn(),
288 }).Tracef("ONU message handling canceled via context")
289 break loop
290 case message, ok := <-o.Channel:
291 if !ok || ctx.Err() != nil {
292 onuLogger.WithFields(log.Fields{
293 "onuID": o.ID,
294 "onuSN": o.Sn(),
295 }).Tracef("ONU message handling canceled via channel close")
296 break loop
Matteo Scandolo075b1892019-10-07 12:11:07 -0700297 }
David Bainbridge103cf022019-12-16 20:11:35 +0000298 onuLogger.WithFields(log.Fields{
299 "onuID": o.ID,
300 "onuSN": o.Sn(),
301 "messageType": message.Type,
302 }).Tracef("Received message on ONU Channel")
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700303
David Bainbridge103cf022019-12-16 20:11:35 +0000304 switch message.Type {
305 case OnuDiscIndication:
306 msg, _ := message.Data.(OnuDiscIndicationMessage)
307 // NOTE we need to slow down and send ONU Discovery Indication in batches to better emulate a real scenario
Pragya Arya2225f202020-01-29 18:05:01 +0530308 time.Sleep(o.DiscoveryDelay)
David Bainbridge103cf022019-12-16 20:11:35 +0000309 o.sendOnuDiscIndication(msg, stream)
310 case OnuIndication:
311 msg, _ := message.Data.(OnuIndicationMessage)
312 o.sendOnuIndication(msg, stream)
313 case OMCI:
314 msg, _ := message.Data.(OmciMessage)
315 o.handleOmciMessage(msg, stream)
316 case FlowUpdate:
317 msg, _ := message.Data.(OnuFlowUpdateMessage)
318 o.handleFlowUpdate(msg)
319 case StartEAPOL:
320 log.Infof("Receive StartEAPOL message on ONU Channel")
321 eapol.SendEapStart(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.InternalState, stream)
322 case StartDHCP:
323 log.Infof("Receive StartDHCP message on ONU Channel")
324 // FIXME use id, ponId as SendEapStart
325 dhcp.SendDHCPDiscovery(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.InternalState, o.HwAddress, o.CTag, stream)
326 case OnuPacketOut:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700327
David Bainbridge103cf022019-12-16 20:11:35 +0000328 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 OnuPacketOut 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 // NOTE here we receive packets going from the DHCP Server to the ONU
340 // for now we expect them to be double-tagged, but ideally the should be single tagged
341 dhcp.HandleNextPacket(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.CTag, o.InternalState, msg.Packet, stream)
342 }
343 case OnuPacketIn:
344 // NOTE we only receive BBR packets here.
345 // Eapol.HandleNextPacket can handle both BBSim and BBr cases so the call is the same
346 // in the DHCP case VOLTHA only act as a proxy, the behaviour is completely different thus we have a dhcp.HandleNextBbrPacket
347 msg, _ := message.Data.(OnuPacketMessage)
348
349 log.WithFields(log.Fields{
350 "IntfId": msg.IntfId,
351 "OnuId": msg.OnuId,
352 "pktType": msg.Type,
353 }).Trace("Received OnuPacketIn Message")
354
355 if msg.Type == packetHandlers.EAPOL {
356 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
357 } else if msg.Type == packetHandlers.DHCP {
358 dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.STag, o.HwAddress, o.DoneChannel, msg.Packet, client)
359 }
360 case DyingGaspIndication:
361 msg, _ := message.Data.(DyingGaspIndicationMessage)
362 o.sendDyingGaspInd(msg, stream)
363 case OmciIndication:
364 msg, _ := message.Data.(OmciIndicationMessage)
365 o.handleOmci(msg, client)
366 case SendEapolFlow:
367 o.sendEapolFlow(client)
368 case SendDhcpFlow:
369 o.sendDhcpFlow(client)
Arjun E K57a7fcb2020-01-30 06:44:45 +0000370 case IGMPMembershipReportV2:
371 log.Infof("Recieved IGMPMembershipReportV2 message on ONU channel")
372 igmp.SendIGMPMembershipReportV2(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
373 case IGMPLeaveGroup:
374 log.Infof("Recieved IGMPLeaveGroupV2 message on ONU channel")
375 igmp.SendIGMPLeaveGroupV2(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
David Bainbridge103cf022019-12-16 20:11:35 +0000376 default:
377 onuLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700378 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700379 }
380 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100381 onuLogger.WithFields(log.Fields{
382 "onuID": o.ID,
383 "onuSN": o.Sn(),
384 }).Debug("Stopped handling ONU Indication Channel")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700385}
386
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800387func (o *Onu) processOmciMessage(message omcisim.OmciChMessage, stream openolt.Openolt_EnableIndicationServer) {
William Kurkian9dadc5b2019-10-22 13:51:57 -0400388 switch message.Type {
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800389 case omcisim.UniLinkUp, omcisim.UniLinkDown:
390 onuLogger.WithFields(log.Fields{
391 "OnuId": message.Data.OnuId,
392 "IntfId": message.Data.IntfId,
393 "Type": message.Type,
394 }).Infof("UNI Link Alarm")
395 // TODO send to OLT
396
397 omciInd := openolt.OmciIndication{
398 IntfId: message.Data.IntfId,
399 OnuId: message.Data.OnuId,
400 Pkt: message.Packet,
401 }
402
403 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
404 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
405 onuLogger.WithFields(log.Fields{
406 "IntfId": o.PonPortID,
407 "SerialNumber": o.Sn(),
408 "Type": message.Type,
409 "omciPacket": omciInd.Pkt,
410 }).Errorf("Failed to send UNI Link Alarm: %v", err)
411 return
412 }
413
414 onuLogger.WithFields(log.Fields{
415 "IntfId": o.PonPortID,
416 "SerialNumber": o.Sn(),
417 "Type": message.Type,
418 "omciPacket": omciInd.Pkt,
419 }).Info("UNI Link alarm sent")
420
William Kurkian9dadc5b2019-10-22 13:51:57 -0400421 case omcisim.GemPortAdded:
422 log.WithFields(log.Fields{
423 "OnuId": message.Data.OnuId,
424 "IntfId": message.Data.IntfId,
425 }).Infof("GemPort Added")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700426
William Kurkian9dadc5b2019-10-22 13:51:57 -0400427 // NOTE if we receive the GemPort but we don't have EAPOL flows
428 // go an intermediate state, otherwise start auth
429 if o.InternalState.Is("enabled") {
430 if err := o.InternalState.Event("add_gem_port"); err != nil {
431 log.Errorf("Can't go to gem_port_added: %v", err)
432 }
433 } else if o.InternalState.Is("eapol_flow_received") {
Matteo Scandolo3c656a12019-12-10 09:54:51 -0800434 if o.Auth == true {
435 if err := o.InternalState.Event("start_auth"); err != nil {
436 log.Warnf("Can't go to auth_started: %v", err)
437 }
438 } else {
439 onuLogger.WithFields(log.Fields{
440 "IntfId": o.PonPortID,
441 "OnuId": o.ID,
442 "SerialNumber": o.Sn(),
443 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700444 }
445 }
446 }
447}
448
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100449func (o Onu) NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700450
451 sn := new(openolt.SerialNumber)
452
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700453 //sn = new(openolt.SerialNumber)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700454 sn.VendorId = []byte("BBSM")
455 sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)}
456
457 return sn
458}
459
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700460// NOTE handle_/process methods can change the ONU internal state as they are receiving messages
461// send method should not change the ONU state
462
William Kurkian0418bc82019-11-06 12:16:24 -0500463func (o *Onu) sendDyingGaspInd(msg DyingGaspIndicationMessage, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700464 alarmData := &openolt.AlarmIndication_DyingGaspInd{
465 DyingGaspInd: &openolt.DyingGaspIndication{
466 IntfId: msg.PonPortID,
467 OnuId: msg.OnuID,
468 Status: "on",
469 },
470 }
471 data := &openolt.Indication_AlarmInd{AlarmInd: &openolt.AlarmIndication{Data: alarmData}}
472
473 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
474 onuLogger.Errorf("Failed to send DyingGaspInd : %v", err)
475 return err
476 }
477 onuLogger.WithFields(log.Fields{
478 "IntfId": msg.PonPortID,
479 "OnuSn": o.Sn(),
480 "OnuId": msg.OnuID,
481 }).Info("sendDyingGaspInd")
482 return nil
483}
484
William Kurkian0418bc82019-11-06 12:16:24 -0500485func (o *Onu) sendOnuDiscIndication(msg OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700486 discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700487 IntfId: msg.Onu.PonPortID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700488 SerialNumber: msg.Onu.SerialNumber,
489 }}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700490
Matteo Scandolo4747d292019-08-05 11:50:18 -0700491 if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700492 log.Errorf("Failed to send Indication_OnuDiscInd: %v", err)
Matteo Scandolo99f18462019-10-28 14:14:28 -0700493 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700494 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700495
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700496 onuLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700497 "IntfId": msg.Onu.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700498 "OnuSn": msg.Onu.Sn(),
499 "OnuId": o.ID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700500 }).Debug("Sent Indication_OnuDiscInd")
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800501
502 // after DiscoveryRetryDelay check if the state is the same and in case send a new OnuDiscIndication
503 go func(delay time.Duration) {
Matteo Scandolo569e7172019-12-20 11:51:51 -0800504 time.Sleep(delay)
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800505 if o.InternalState.Current() == "discovered" {
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800506 o.sendOnuDiscIndication(msg, stream)
507 }
508 }(o.DiscoveryRetryDelay)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700509}
510
William Kurkian0418bc82019-11-06 12:16:24 -0500511func (o *Onu) sendOnuIndication(msg OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700512 // NOTE voltha returns an ID, but if we use that ID then it complains:
513 // expected_onu_id: 1, received_onu_id: 1024, event: ONU-id-mismatch, can happen if both voltha and the olt rebooted
514 // so we're using the internal ID that is 1
515 // o.ID = msg.OnuID
Matteo Scandolo4747d292019-08-05 11:50:18 -0700516
517 indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700518 IntfId: o.PonPortID,
519 OnuId: o.ID,
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700520 OperState: msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700521 AdminState: o.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700522 SerialNumber: o.SerialNumber,
523 }}
524 if err := stream.Send(&openolt.Indication{Data: indData}); err != nil {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700525 // TODO do we need to transition to a broken state?
Matteo Scandolo11006992019-08-28 11:29:46 -0700526 log.Errorf("Failed to send Indication_OnuInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700527 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700528 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700529 "IntfId": o.PonPortID,
530 "OnuId": o.ID,
531 "OperState": msg.OperState.String(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700532 "AdminState": msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700533 "OnuSn": o.Sn(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700534 }).Debug("Sent Indication_OnuInd")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700535
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700536}
537
William Kurkian0418bc82019-11-06 12:16:24 -0500538func (o *Onu) handleOmciMessage(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700539
540 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700541 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700542 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700543 "omciPacket": msg.omciMsg.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700544 }).Tracef("Received OMCI message")
545
546 var omciInd openolt.OmciIndication
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700547 respPkt, err := omcisim.OmciSim(o.PonPortID, o.ID, HexDecode(msg.omciMsg.Pkt))
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700548 if err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700549 onuLogger.WithFields(log.Fields{
550 "IntfId": o.PonPortID,
551 "SerialNumber": o.Sn(),
552 "omciPacket": omciInd.Pkt,
553 "msg": msg,
554 }).Errorf("Error handling OMCI message %v", msg)
555 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700556 }
557
558 omciInd.IntfId = o.PonPortID
559 omciInd.OnuId = o.ID
560 omciInd.Pkt = respPkt
561
562 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
563 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700564 onuLogger.WithFields(log.Fields{
565 "IntfId": o.PonPortID,
566 "SerialNumber": o.Sn(),
567 "omciPacket": omciInd.Pkt,
568 "msg": msg,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700569 }).Errorf("send omcisim indication failed: %v", err)
Matteo Scandolo27428702019-10-11 16:21:16 -0700570 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700571 }
572 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700573 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700574 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700575 "omciPacket": omciInd.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700576 }).Tracef("Sent OMCI message")
577}
578
Matteo Scandolo27428702019-10-11 16:21:16 -0700579func (o *Onu) storePortNumber(portNo uint32) {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700580 // NOTE this needed only as long as we don't support multiple UNIs
Matteo Scandolo27428702019-10-11 16:21:16 -0700581 // we need to add support for multiple UNIs
582 // the action plan is:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700583 // - refactor the omcisim-sim library to use https://github.com/cboling/omci instead of canned messages
Matteo Scandolo27428702019-10-11 16:21:16 -0700584 // - change the library so that it reports a single UNI and remove this workaroung
585 // - add support for multiple UNIs in BBSim
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700586 if o.PortNo == 0 || portNo < o.PortNo {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700587 onuLogger.WithFields(log.Fields{
588 "IntfId": o.PonPortID,
589 "OnuId": o.ID,
590 "SerialNumber": o.Sn(),
591 "OnuPortNo": o.PortNo,
592 "FlowPortNo": portNo,
593 }).Debug("Storing ONU portNo")
Matteo Scandolo27428702019-10-11 16:21:16 -0700594 o.PortNo = portNo
595 }
596}
597
William Kurkian0418bc82019-11-06 12:16:24 -0500598func (o *Onu) SetID(id uint32) {
599 o.ID = id
600}
601
Matteo Scandolo813402b2019-10-23 19:24:52 -0700602func (o *Onu) handleFlowUpdate(msg OnuFlowUpdateMessage) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700603 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700604 "DstPort": msg.Flow.Classifier.DstPort,
605 "EthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType),
606 "FlowId": msg.Flow.FlowId,
607 "FlowType": msg.Flow.FlowType,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700608 "InnerVlan": msg.Flow.Classifier.IVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700609 "IntfId": msg.Flow.AccessIntfId,
610 "IpProto": msg.Flow.Classifier.IpProto,
611 "OnuId": msg.Flow.OnuId,
612 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700613 "OuterVlan": msg.Flow.Classifier.OVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700614 "PortNo": msg.Flow.PortNo,
615 "SrcPort": msg.Flow.Classifier.SrcPort,
616 "UniID": msg.Flow.UniId,
617 }).Debug("ONU receives Flow")
618
Matteo Scandolo813402b2019-10-23 19:24:52 -0700619 if msg.Flow.UniId != 0 {
620 // as of now BBSim only support a single UNI, so ignore everything that is not targeted to it
621 onuLogger.WithFields(log.Fields{
622 "IntfId": o.PonPortID,
623 "OnuId": o.ID,
624 "SerialNumber": o.Sn(),
625 }).Debug("Ignoring flow as it's not for the first UNI")
626 return
627 }
628
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700629 if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) && msg.Flow.Classifier.OVid == 4091 {
Matteo Scandolo27428702019-10-11 16:21:16 -0700630 // NOTE storing the PortNO, it's needed when sending PacketIndications
Matteo Scandolo813402b2019-10-23 19:24:52 -0700631 o.storePortNumber(uint32(msg.Flow.PortNo))
Matteo Scandolo27428702019-10-11 16:21:16 -0700632
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700633 // NOTE if we receive the EAPOL flows but we don't have GemPorts
634 // go an intermediate state, otherwise start auth
635 if o.InternalState.Is("enabled") {
636 if err := o.InternalState.Event("receive_eapol_flow"); err != nil {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700637 log.Warnf("Can't go to eapol_flow_received: %v", err)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700638 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700639 } else if o.InternalState.Is("gem_port_added") {
Matteo Scandoloc1147092019-10-29 09:38:33 -0700640
641 if o.Auth == true {
642 if err := o.InternalState.Event("start_auth"); err != nil {
643 log.Warnf("Can't go to auth_started: %v", err)
644 }
645 } else {
646 onuLogger.WithFields(log.Fields{
647 "IntfId": o.PonPortID,
648 "OnuId": o.ID,
649 "SerialNumber": o.Sn(),
650 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700651 }
Matteo Scandoloc1147092019-10-29 09:38:33 -0700652
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700653 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700654 } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) &&
655 msg.Flow.Classifier.SrcPort == uint32(68) &&
656 msg.Flow.Classifier.DstPort == uint32(67) {
Matteo Scandolo99f18462019-10-28 14:14:28 -0700657
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100658 // 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 -0700659 o.DhcpFlowReceived = true
Matteo Scandoloc1147092019-10-29 09:38:33 -0700660
661 if o.Dhcp == true {
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100662 // NOTE we are receiving multiple DHCP flows but we shouldn't call the transition multiple times
Matteo Scandoloc1147092019-10-29 09:38:33 -0700663 if err := o.InternalState.Event("start_dhcp"); err != nil {
664 log.Errorf("Can't go to dhcp_started: %v", err)
665 }
666 } else {
667 onuLogger.WithFields(log.Fields{
668 "IntfId": o.PonPortID,
669 "OnuId": o.ID,
670 "SerialNumber": o.Sn(),
671 }).Warn("Not starting DHCP as Dhcp bit is not set in CLI parameters")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700672 }
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700673 }
674}
675
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700676// HexDecode converts the hex encoding to binary
677func HexDecode(pkt []byte) []byte {
678 p := make([]byte, len(pkt)/2)
679 for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 {
680 // Go figure this ;)
681 u := (pkt[i] & 15) + (pkt[i]>>6)*9
682 l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9
683 p[j] = u<<4 + l
684 }
685 onuLogger.Tracef("Omci decoded: %x.", p)
686 return p
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700687}
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700688
689// BBR methods
690
691func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) {
692 omciMsg := openolt.OmciMsg{
693 IntfId: intfId,
694 OnuId: onuId,
695 Pkt: pktBytes,
696 }
697
698 if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil {
699 log.WithFields(log.Fields{
700 "IntfId": intfId,
701 "OnuId": onuId,
702 "SerialNumber": common.OnuSnToString(sn),
703 "Pkt": omciMsg.Pkt,
704 }).Fatalf("Failed to send MIB Reset")
705 }
706 log.WithFields(log.Fields{
707 "IntfId": intfId,
708 "OnuId": onuId,
709 "SerialNumber": common.OnuSnToString(sn),
710 "Pkt": omciMsg.Pkt,
711 }).Tracef("Sent OMCI message %s", msgType)
712}
713
714func (onu *Onu) getNextTid(highPriority ...bool) uint16 {
715 var next uint16
716 if len(highPriority) > 0 && highPriority[0] {
717 next = onu.hpTid
718 onu.hpTid += 1
719 if onu.hpTid < 0x8000 {
720 onu.hpTid = 0x8000
721 }
722 } else {
723 next = onu.tid
724 onu.tid += 1
725 if onu.tid >= 0x8000 {
726 onu.tid = 1
727 }
728 }
729 return next
730}
731
732// TODO move this method in responders/omcisim
733func (o *Onu) StartOmci(client openolt.OpenoltClient) {
734 mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false))
735 sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client)
736}
737
738func (o *Onu) handleOmci(msg OmciIndicationMessage, client openolt.OpenoltClient) {
739 msgType, packet := omcilib.DecodeOmci(msg.OmciInd.Pkt)
740
741 log.WithFields(log.Fields{
742 "IntfId": msg.OmciInd.IntfId,
743 "OnuId": msg.OmciInd.OnuId,
744 "OnuSn": common.OnuSnToString(o.SerialNumber),
745 "Pkt": msg.OmciInd.Pkt,
746 "msgType": msgType,
747 }).Trace("ONU Receveives OMCI Msg")
748 switch msgType {
749 default:
Matteo Scandolo813402b2019-10-23 19:24:52 -0700750 log.WithFields(log.Fields{
751 "IntfId": msg.OmciInd.IntfId,
752 "OnuId": msg.OmciInd.OnuId,
753 "OnuSn": common.OnuSnToString(o.SerialNumber),
754 "Pkt": msg.OmciInd.Pkt,
755 "msgType": msgType,
756 }).Fatalf("unexpected frame: %v", packet)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700757 case omci.MibResetResponseType:
758 mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false))
759 sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client)
760 case omci.MibUploadResponseType:
761 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
762 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
763 case omci.MibUploadNextResponseType:
764 o.seqNumber++
765
766 if o.seqNumber > 290 {
767 // NOTE we are done with the MIB Upload (290 is the number of messages the omci-sim library will respond to)
768 galEnet, _ := omcilib.CreateGalEnetRequest(o.getNextTid(false))
769 sendOmciMsg(galEnet, o.PonPortID, o.ID, o.SerialNumber, "CreateGalEnetRequest", client)
770 } else {
771 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
772 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
773 }
774 case omci.CreateResponseType:
775 // NOTE Creating a GemPort,
776 // BBsim actually doesn't care about the values, so we can do we want with the parameters
777 // In the same way we can create a GemPort even without setting up UNIs/TConts/...
778 // but we need the GemPort to trigger the state change
779
780 if !o.HasGemPort {
781 // NOTE this sends a CreateRequestType and BBSim replies with a CreateResponseType
782 // thus we send this request only once
783 gemReq, _ := omcilib.CreateGemPortRequest(o.getNextTid(false))
784 sendOmciMsg(gemReq, o.PonPortID, o.ID, o.SerialNumber, "CreateGemPortRequest", client)
785 o.HasGemPort = true
786 } else {
787 if err := o.InternalState.Event("send_eapol_flow"); err != nil {
788 onuLogger.WithFields(log.Fields{
789 "OnuId": o.ID,
790 "IntfId": o.PonPortID,
791 "OnuSn": o.Sn(),
792 }).Errorf("Error while transitioning ONU State %v", err)
793 }
794 }
795
796 }
797}
798
799func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) {
800
801 classifierProto := openolt.Classifier{
802 EthType: uint32(layers.EthernetTypeEAPOL),
803 OVid: 4091,
804 }
805
806 actionProto := openolt.Action{}
807
808 downstreamFlow := openolt.Flow{
809 AccessIntfId: int32(o.PonPortID),
810 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700811 UniId: int32(0), // NOTE do not hardcode this, we need to support multiple UNIs
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700812 FlowId: uint32(o.ID),
813 FlowType: "downstream",
814 AllocId: int32(0),
815 NetworkIntfId: int32(0),
816 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
817 Classifier: &classifierProto,
818 Action: &actionProto,
819 Priority: int32(100),
820 Cookie: uint64(o.ID),
821 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
822 }
823
824 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
825 log.WithFields(log.Fields{
826 "IntfId": o.PonPortID,
827 "OnuId": o.ID,
828 "FlowId": downstreamFlow.FlowId,
829 "PortNo": downstreamFlow.PortNo,
830 "SerialNumber": common.OnuSnToString(o.SerialNumber),
831 }).Fatalf("Failed to EAPOL Flow")
832 }
833 log.WithFields(log.Fields{
834 "IntfId": o.PonPortID,
835 "OnuId": o.ID,
836 "FlowId": downstreamFlow.FlowId,
837 "PortNo": downstreamFlow.PortNo,
838 "SerialNumber": common.OnuSnToString(o.SerialNumber),
839 }).Info("Sent EAPOL Flow")
840}
841
842func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) {
843 classifierProto := openolt.Classifier{
844 EthType: uint32(layers.EthernetTypeIPv4),
845 SrcPort: uint32(68),
846 DstPort: uint32(67),
847 }
848
849 actionProto := openolt.Action{}
850
851 downstreamFlow := openolt.Flow{
852 AccessIntfId: int32(o.PonPortID),
853 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700854 UniId: int32(0), // FIXME do not hardcode this
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700855 FlowId: uint32(o.ID),
856 FlowType: "downstream",
857 AllocId: int32(0),
858 NetworkIntfId: int32(0),
859 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
860 Classifier: &classifierProto,
861 Action: &actionProto,
862 Priority: int32(100),
863 Cookie: uint64(o.ID),
864 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
865 }
866
867 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
868 log.WithFields(log.Fields{
869 "IntfId": o.PonPortID,
870 "OnuId": o.ID,
871 "FlowId": downstreamFlow.FlowId,
872 "PortNo": downstreamFlow.PortNo,
873 "SerialNumber": common.OnuSnToString(o.SerialNumber),
874 }).Fatalf("Failed to send DHCP Flow")
875 }
876 log.WithFields(log.Fields{
877 "IntfId": o.PonPortID,
878 "OnuId": o.ID,
879 "FlowId": downstreamFlow.FlowId,
880 "PortNo": downstreamFlow.PortNo,
881 "SerialNumber": common.OnuSnToString(o.SerialNumber),
882 }).Info("Sent DHCP Flow")
883}