blob: aebd0f132524c828d5b1a09cb601e14257ff0d4a [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
Shubham Sharmabd4b6572020-02-12 13:00:44 +0000128 {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", "igmp_join_started", "igmp_left", "igmp_join_error"}, 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
Shubham Sharmabd4b6572020-02-12 13:00:44 +0000135 {Name: "start_dhcp", Src: []string{"eap_response_success_received", "dhcp_discovery_sent", "dhcp_request_sent", "dhcp_ack_received", "dhcp_failed", "igmp_join_started", "igmp_left", "igmp_join_error"}, 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
Shubham Sharmabd4b6572020-02-12 13:00:44 +0000145 {Name: "igmp_join_start", Src: []string{"eap_response_success_received", "gem_port_added", "eapol_flow_received", "dhcp_ack_received", "igmp_left", "igmp_join_error"}, Dst: "igmp_join_started"},
146 {Name: "igmp_join_error", Src: []string{"igmp_join_started"}, Dst: "igmp_join_error"},
147 {Name: "igmp_leave", Src: []string{"igmp_join_started", "gem_port_added", "eapol_flow_received", "eap_response_success_received", "dhcp_ack_received"}, Dst: "igmp_left"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700148 },
149 fsm.Callbacks{
150 "enter_state": func(e *fsm.Event) {
151 o.logStateChange(e.Src, e.Dst)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700152 },
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100153 "enter_initialized": func(e *fsm.Event) {
154 // create new channel for ProcessOnuMessages Go routine
155 o.Channel = make(chan Message, 2048)
Pragya Arya1cbefa42020-01-13 12:15:29 +0530156 if !isMock {
157 // start ProcessOnuMessages Go routine
158 go o.ProcessOnuMessages(olt.enableContext, *olt.OpenoltStream, nil)
159 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100160 },
161 "enter_discovered": func(e *fsm.Event) {
162 msg := Message{
163 Type: OnuDiscIndication,
164 Data: OnuDiscIndicationMessage{
165 Onu: &o,
166 OperState: UP,
167 },
168 }
169 o.Channel <- msg
170 },
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700171 "enter_enabled": func(event *fsm.Event) {
172 msg := Message{
173 Type: OnuIndication,
174 Data: OnuIndicationMessage{
175 OnuSN: o.SerialNumber,
176 PonPortID: o.PonPortID,
177 OperState: UP,
178 },
179 }
180 o.Channel <- msg
181 },
182 "enter_disabled": func(event *fsm.Event) {
183 msg := Message{
184 Type: OnuIndication,
185 Data: OnuIndicationMessage{
186 OnuSN: o.SerialNumber,
187 PonPortID: o.PonPortID,
188 OperState: DOWN,
189 },
190 }
191 o.Channel <- msg
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100192 // terminate the ONU's ProcessOnuMessages Go routine
193 close(o.Channel)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700194 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700195 "enter_auth_started": func(e *fsm.Event) {
196 o.logStateChange(e.Src, e.Dst)
197 msg := Message{
198 Type: StartEAPOL,
199 Data: PacketMessage{
200 PonPortID: o.PonPortID,
201 OnuID: o.ID,
202 },
203 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700204 o.Channel <- msg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700205 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700206 "enter_auth_failed": func(e *fsm.Event) {
207 onuLogger.WithFields(log.Fields{
208 "OnuId": o.ID,
209 "IntfId": o.PonPortID,
210 "OnuSn": o.Sn(),
211 }).Errorf("ONU failed to authenticate!")
212 },
Matteo Scandolo99f18462019-10-28 14:14:28 -0700213 "before_start_dhcp": func(e *fsm.Event) {
214 if o.DhcpFlowReceived == false {
215 e.Cancel(errors.New("cannot-go-to-dhcp-started-as-dhcp-flow-is-missing"))
216 }
217 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700218 "enter_dhcp_started": func(e *fsm.Event) {
219 msg := Message{
220 Type: StartDHCP,
221 Data: PacketMessage{
222 PonPortID: o.PonPortID,
223 OnuID: o.ID,
224 },
225 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700226 o.Channel <- msg
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700227 },
228 "enter_dhcp_failed": func(e *fsm.Event) {
229 onuLogger.WithFields(log.Fields{
230 "OnuId": o.ID,
231 "IntfId": o.PonPortID,
232 "OnuSn": o.Sn(),
233 }).Errorf("ONU failed to DHCP!")
234 },
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700235 "enter_eapol_flow_sent": func(e *fsm.Event) {
236 msg := Message{
237 Type: SendEapolFlow,
238 }
239 o.Channel <- msg
240 },
241 "enter_dhcp_flow_sent": func(e *fsm.Event) {
242 msg := Message{
243 Type: SendDhcpFlow,
244 }
245 o.Channel <- msg
246 },
Arjun E K57a7fcb2020-01-30 06:44:45 +0000247 "igmp_join_start": func(e *fsm.Event) {
248 msg := Message{
249 Type: IGMPMembershipReportV2,
250 }
251 o.Channel <- msg
252 },
253 "igmp_leave": func(e *fsm.Event) {
254 msg := Message{
255 Type: IGMPLeaveGroup}
256 o.Channel <- msg
257 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700258 },
259 )
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100260
Matteo Scandolo27428702019-10-11 16:21:16 -0700261 return &o
Matteo Scandolo4747d292019-08-05 11:50:18 -0700262}
263
William Kurkian0418bc82019-11-06 12:16:24 -0500264func (o *Onu) logStateChange(src string, dst string) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700265 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700266 "OnuId": o.ID,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700267 "IntfId": o.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700268 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700269 }).Debugf("Changing ONU InternalState from %s to %s", src, dst)
270}
271
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100272// ProcessOnuMessages starts indication channel for each ONU
David Bainbridge103cf022019-12-16 20:11:35 +0000273func (o *Onu) ProcessOnuMessages(ctx context.Context, stream openolt.Openolt_EnableIndicationServer, client openolt.OpenoltClient) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700274 onuLogger.WithFields(log.Fields{
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100275 "onuID": o.ID,
276 "onuSN": o.Sn(),
277 "ponPort": o.PonPortID,
278 }).Debug("Starting ONU Indication Channel")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700279
David Bainbridge103cf022019-12-16 20:11:35 +0000280loop:
281 for {
282 select {
283 case <-ctx.Done():
284 onuLogger.WithFields(log.Fields{
285 "onuID": o.ID,
286 "onuSN": o.Sn(),
287 }).Tracef("ONU message handling canceled via context")
288 break loop
289 case message, ok := <-o.Channel:
290 if !ok || ctx.Err() != nil {
291 onuLogger.WithFields(log.Fields{
292 "onuID": o.ID,
293 "onuSN": o.Sn(),
294 }).Tracef("ONU message handling canceled via channel close")
295 break loop
Matteo Scandolo075b1892019-10-07 12:11:07 -0700296 }
David Bainbridge103cf022019-12-16 20:11:35 +0000297 onuLogger.WithFields(log.Fields{
298 "onuID": o.ID,
299 "onuSN": o.Sn(),
300 "messageType": message.Type,
301 }).Tracef("Received message on ONU Channel")
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700302
David Bainbridge103cf022019-12-16 20:11:35 +0000303 switch message.Type {
304 case OnuDiscIndication:
305 msg, _ := message.Data.(OnuDiscIndicationMessage)
306 // 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 +0530307 time.Sleep(o.DiscoveryDelay)
David Bainbridge103cf022019-12-16 20:11:35 +0000308 o.sendOnuDiscIndication(msg, stream)
309 case OnuIndication:
310 msg, _ := message.Data.(OnuIndicationMessage)
311 o.sendOnuIndication(msg, stream)
312 case OMCI:
313 msg, _ := message.Data.(OmciMessage)
314 o.handleOmciMessage(msg, stream)
315 case FlowUpdate:
316 msg, _ := message.Data.(OnuFlowUpdateMessage)
317 o.handleFlowUpdate(msg)
318 case StartEAPOL:
319 log.Infof("Receive StartEAPOL message on ONU Channel")
320 eapol.SendEapStart(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.InternalState, stream)
321 case StartDHCP:
322 log.Infof("Receive StartDHCP message on ONU Channel")
323 // FIXME use id, ponId as SendEapStart
324 dhcp.SendDHCPDiscovery(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.InternalState, o.HwAddress, o.CTag, stream)
325 case OnuPacketOut:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700326
David Bainbridge103cf022019-12-16 20:11:35 +0000327 msg, _ := message.Data.(OnuPacketMessage)
328
329 log.WithFields(log.Fields{
330 "IntfId": msg.IntfId,
331 "OnuId": msg.OnuId,
332 "pktType": msg.Type,
333 }).Trace("Received OnuPacketOut Message")
334
335 if msg.Type == packetHandlers.EAPOL {
336 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
337 } else if msg.Type == packetHandlers.DHCP {
338 // NOTE here we receive packets going from the DHCP Server to the ONU
339 // for now we expect them to be double-tagged, but ideally the should be single tagged
340 dhcp.HandleNextPacket(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.CTag, o.InternalState, msg.Packet, stream)
341 }
342 case OnuPacketIn:
343 // NOTE we only receive BBR packets here.
344 // Eapol.HandleNextPacket can handle both BBSim and BBr cases so the call is the same
345 // in the DHCP case VOLTHA only act as a proxy, the behaviour is completely different thus we have a dhcp.HandleNextBbrPacket
346 msg, _ := message.Data.(OnuPacketMessage)
347
348 log.WithFields(log.Fields{
349 "IntfId": msg.IntfId,
350 "OnuId": msg.OnuId,
351 "pktType": msg.Type,
352 }).Trace("Received OnuPacketIn Message")
353
354 if msg.Type == packetHandlers.EAPOL {
355 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
356 } else if msg.Type == packetHandlers.DHCP {
357 dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.STag, o.HwAddress, o.DoneChannel, msg.Packet, client)
358 }
359 case DyingGaspIndication:
360 msg, _ := message.Data.(DyingGaspIndicationMessage)
361 o.sendDyingGaspInd(msg, stream)
362 case OmciIndication:
363 msg, _ := message.Data.(OmciIndicationMessage)
364 o.handleOmci(msg, client)
365 case SendEapolFlow:
366 o.sendEapolFlow(client)
367 case SendDhcpFlow:
368 o.sendDhcpFlow(client)
Arjun E K57a7fcb2020-01-30 06:44:45 +0000369 case IGMPMembershipReportV2:
370 log.Infof("Recieved IGMPMembershipReportV2 message on ONU channel")
371 igmp.SendIGMPMembershipReportV2(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
372 case IGMPLeaveGroup:
373 log.Infof("Recieved IGMPLeaveGroupV2 message on ONU channel")
374 igmp.SendIGMPLeaveGroupV2(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
David Bainbridge103cf022019-12-16 20:11:35 +0000375 default:
376 onuLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700377 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700378 }
379 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100380 onuLogger.WithFields(log.Fields{
381 "onuID": o.ID,
382 "onuSN": o.Sn(),
383 }).Debug("Stopped handling ONU Indication Channel")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700384}
385
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800386func (o *Onu) processOmciMessage(message omcisim.OmciChMessage, stream openolt.Openolt_EnableIndicationServer) {
William Kurkian9dadc5b2019-10-22 13:51:57 -0400387 switch message.Type {
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800388 case omcisim.UniLinkUp, omcisim.UniLinkDown:
389 onuLogger.WithFields(log.Fields{
390 "OnuId": message.Data.OnuId,
391 "IntfId": message.Data.IntfId,
392 "Type": message.Type,
393 }).Infof("UNI Link Alarm")
394 // TODO send to OLT
395
396 omciInd := openolt.OmciIndication{
397 IntfId: message.Data.IntfId,
398 OnuId: message.Data.OnuId,
399 Pkt: message.Packet,
400 }
401
402 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
403 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
404 onuLogger.WithFields(log.Fields{
405 "IntfId": o.PonPortID,
406 "SerialNumber": o.Sn(),
407 "Type": message.Type,
408 "omciPacket": omciInd.Pkt,
409 }).Errorf("Failed to send UNI Link Alarm: %v", err)
410 return
411 }
412
413 onuLogger.WithFields(log.Fields{
414 "IntfId": o.PonPortID,
415 "SerialNumber": o.Sn(),
416 "Type": message.Type,
417 "omciPacket": omciInd.Pkt,
418 }).Info("UNI Link alarm sent")
419
William Kurkian9dadc5b2019-10-22 13:51:57 -0400420 case omcisim.GemPortAdded:
421 log.WithFields(log.Fields{
422 "OnuId": message.Data.OnuId,
423 "IntfId": message.Data.IntfId,
424 }).Infof("GemPort Added")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700425
William Kurkian9dadc5b2019-10-22 13:51:57 -0400426 // NOTE if we receive the GemPort but we don't have EAPOL flows
427 // go an intermediate state, otherwise start auth
428 if o.InternalState.Is("enabled") {
429 if err := o.InternalState.Event("add_gem_port"); err != nil {
430 log.Errorf("Can't go to gem_port_added: %v", err)
431 }
432 } else if o.InternalState.Is("eapol_flow_received") {
Matteo Scandolo3c656a12019-12-10 09:54:51 -0800433 if o.Auth == true {
434 if err := o.InternalState.Event("start_auth"); err != nil {
435 log.Warnf("Can't go to auth_started: %v", err)
436 }
437 } else {
438 onuLogger.WithFields(log.Fields{
439 "IntfId": o.PonPortID,
440 "OnuId": o.ID,
441 "SerialNumber": o.Sn(),
442 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700443 }
444 }
445 }
446}
447
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100448func (o Onu) NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700449
450 sn := new(openolt.SerialNumber)
451
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700452 //sn = new(openolt.SerialNumber)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700453 sn.VendorId = []byte("BBSM")
454 sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)}
455
456 return sn
457}
458
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700459// NOTE handle_/process methods can change the ONU internal state as they are receiving messages
460// send method should not change the ONU state
461
William Kurkian0418bc82019-11-06 12:16:24 -0500462func (o *Onu) sendDyingGaspInd(msg DyingGaspIndicationMessage, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700463 alarmData := &openolt.AlarmIndication_DyingGaspInd{
464 DyingGaspInd: &openolt.DyingGaspIndication{
465 IntfId: msg.PonPortID,
466 OnuId: msg.OnuID,
467 Status: "on",
468 },
469 }
470 data := &openolt.Indication_AlarmInd{AlarmInd: &openolt.AlarmIndication{Data: alarmData}}
471
472 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
473 onuLogger.Errorf("Failed to send DyingGaspInd : %v", err)
474 return err
475 }
476 onuLogger.WithFields(log.Fields{
477 "IntfId": msg.PonPortID,
478 "OnuSn": o.Sn(),
479 "OnuId": msg.OnuID,
480 }).Info("sendDyingGaspInd")
481 return nil
482}
483
William Kurkian0418bc82019-11-06 12:16:24 -0500484func (o *Onu) sendOnuDiscIndication(msg OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700485 discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700486 IntfId: msg.Onu.PonPortID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700487 SerialNumber: msg.Onu.SerialNumber,
488 }}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700489
Matteo Scandolo4747d292019-08-05 11:50:18 -0700490 if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700491 log.Errorf("Failed to send Indication_OnuDiscInd: %v", err)
Matteo Scandolo99f18462019-10-28 14:14:28 -0700492 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700493 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700494
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700495 onuLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700496 "IntfId": msg.Onu.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700497 "OnuSn": msg.Onu.Sn(),
498 "OnuId": o.ID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700499 }).Debug("Sent Indication_OnuDiscInd")
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800500
501 // after DiscoveryRetryDelay check if the state is the same and in case send a new OnuDiscIndication
502 go func(delay time.Duration) {
Matteo Scandolo569e7172019-12-20 11:51:51 -0800503 time.Sleep(delay)
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800504 if o.InternalState.Current() == "discovered" {
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800505 o.sendOnuDiscIndication(msg, stream)
506 }
507 }(o.DiscoveryRetryDelay)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700508}
509
William Kurkian0418bc82019-11-06 12:16:24 -0500510func (o *Onu) sendOnuIndication(msg OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700511 // NOTE voltha returns an ID, but if we use that ID then it complains:
512 // expected_onu_id: 1, received_onu_id: 1024, event: ONU-id-mismatch, can happen if both voltha and the olt rebooted
513 // so we're using the internal ID that is 1
514 // o.ID = msg.OnuID
Matteo Scandolo4747d292019-08-05 11:50:18 -0700515
516 indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700517 IntfId: o.PonPortID,
518 OnuId: o.ID,
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700519 OperState: msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700520 AdminState: o.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700521 SerialNumber: o.SerialNumber,
522 }}
523 if err := stream.Send(&openolt.Indication{Data: indData}); err != nil {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700524 // TODO do we need to transition to a broken state?
Matteo Scandolo11006992019-08-28 11:29:46 -0700525 log.Errorf("Failed to send Indication_OnuInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700526 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700527 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700528 "IntfId": o.PonPortID,
529 "OnuId": o.ID,
530 "OperState": msg.OperState.String(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700531 "AdminState": msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700532 "OnuSn": o.Sn(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700533 }).Debug("Sent Indication_OnuInd")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700534
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700535}
536
William Kurkian0418bc82019-11-06 12:16:24 -0500537func (o *Onu) handleOmciMessage(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700538
539 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700540 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700541 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700542 "omciPacket": msg.omciMsg.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700543 }).Tracef("Received OMCI message")
544
545 var omciInd openolt.OmciIndication
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700546 respPkt, err := omcisim.OmciSim(o.PonPortID, o.ID, HexDecode(msg.omciMsg.Pkt))
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700547 if err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700548 onuLogger.WithFields(log.Fields{
549 "IntfId": o.PonPortID,
550 "SerialNumber": o.Sn(),
551 "omciPacket": omciInd.Pkt,
552 "msg": msg,
553 }).Errorf("Error handling OMCI message %v", msg)
554 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700555 }
556
557 omciInd.IntfId = o.PonPortID
558 omciInd.OnuId = o.ID
559 omciInd.Pkt = respPkt
560
561 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
562 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700563 onuLogger.WithFields(log.Fields{
564 "IntfId": o.PonPortID,
565 "SerialNumber": o.Sn(),
566 "omciPacket": omciInd.Pkt,
567 "msg": msg,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700568 }).Errorf("send omcisim indication failed: %v", err)
Matteo Scandolo27428702019-10-11 16:21:16 -0700569 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700570 }
571 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700572 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700573 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700574 "omciPacket": omciInd.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700575 }).Tracef("Sent OMCI message")
576}
577
Matteo Scandolo27428702019-10-11 16:21:16 -0700578func (o *Onu) storePortNumber(portNo uint32) {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700579 // NOTE this needed only as long as we don't support multiple UNIs
Matteo Scandolo27428702019-10-11 16:21:16 -0700580 // we need to add support for multiple UNIs
581 // the action plan is:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700582 // - refactor the omcisim-sim library to use https://github.com/cboling/omci instead of canned messages
Matteo Scandolo27428702019-10-11 16:21:16 -0700583 // - change the library so that it reports a single UNI and remove this workaroung
584 // - add support for multiple UNIs in BBSim
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700585 if o.PortNo == 0 || portNo < o.PortNo {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700586 onuLogger.WithFields(log.Fields{
587 "IntfId": o.PonPortID,
588 "OnuId": o.ID,
589 "SerialNumber": o.Sn(),
590 "OnuPortNo": o.PortNo,
591 "FlowPortNo": portNo,
592 }).Debug("Storing ONU portNo")
Matteo Scandolo27428702019-10-11 16:21:16 -0700593 o.PortNo = portNo
594 }
595}
596
William Kurkian0418bc82019-11-06 12:16:24 -0500597func (o *Onu) SetID(id uint32) {
598 o.ID = id
599}
600
Matteo Scandolo813402b2019-10-23 19:24:52 -0700601func (o *Onu) handleFlowUpdate(msg OnuFlowUpdateMessage) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700602 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700603 "DstPort": msg.Flow.Classifier.DstPort,
604 "EthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType),
605 "FlowId": msg.Flow.FlowId,
606 "FlowType": msg.Flow.FlowType,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700607 "InnerVlan": msg.Flow.Classifier.IVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700608 "IntfId": msg.Flow.AccessIntfId,
609 "IpProto": msg.Flow.Classifier.IpProto,
610 "OnuId": msg.Flow.OnuId,
611 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700612 "OuterVlan": msg.Flow.Classifier.OVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700613 "PortNo": msg.Flow.PortNo,
614 "SrcPort": msg.Flow.Classifier.SrcPort,
615 "UniID": msg.Flow.UniId,
616 }).Debug("ONU receives Flow")
617
Matteo Scandolo813402b2019-10-23 19:24:52 -0700618 if msg.Flow.UniId != 0 {
619 // as of now BBSim only support a single UNI, so ignore everything that is not targeted to it
620 onuLogger.WithFields(log.Fields{
621 "IntfId": o.PonPortID,
622 "OnuId": o.ID,
623 "SerialNumber": o.Sn(),
624 }).Debug("Ignoring flow as it's not for the first UNI")
625 return
626 }
627
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700628 if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) && msg.Flow.Classifier.OVid == 4091 {
Matteo Scandolo27428702019-10-11 16:21:16 -0700629 // NOTE storing the PortNO, it's needed when sending PacketIndications
Matteo Scandolo813402b2019-10-23 19:24:52 -0700630 o.storePortNumber(uint32(msg.Flow.PortNo))
Matteo Scandolo27428702019-10-11 16:21:16 -0700631
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700632 // NOTE if we receive the EAPOL flows but we don't have GemPorts
633 // go an intermediate state, otherwise start auth
634 if o.InternalState.Is("enabled") {
635 if err := o.InternalState.Event("receive_eapol_flow"); err != nil {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700636 log.Warnf("Can't go to eapol_flow_received: %v", err)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700637 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700638 } else if o.InternalState.Is("gem_port_added") {
Matteo Scandoloc1147092019-10-29 09:38:33 -0700639
640 if o.Auth == true {
641 if err := o.InternalState.Event("start_auth"); err != nil {
642 log.Warnf("Can't go to auth_started: %v", err)
643 }
644 } else {
645 onuLogger.WithFields(log.Fields{
646 "IntfId": o.PonPortID,
647 "OnuId": o.ID,
648 "SerialNumber": o.Sn(),
649 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700650 }
Matteo Scandoloc1147092019-10-29 09:38:33 -0700651
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700652 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700653 } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) &&
654 msg.Flow.Classifier.SrcPort == uint32(68) &&
655 msg.Flow.Classifier.DstPort == uint32(67) {
Matteo Scandolo99f18462019-10-28 14:14:28 -0700656
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100657 // 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 -0700658 o.DhcpFlowReceived = true
Matteo Scandoloc1147092019-10-29 09:38:33 -0700659
660 if o.Dhcp == true {
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100661 // NOTE we are receiving multiple DHCP flows but we shouldn't call the transition multiple times
Matteo Scandoloc1147092019-10-29 09:38:33 -0700662 if err := o.InternalState.Event("start_dhcp"); err != nil {
663 log.Errorf("Can't go to dhcp_started: %v", err)
664 }
665 } else {
666 onuLogger.WithFields(log.Fields{
667 "IntfId": o.PonPortID,
668 "OnuId": o.ID,
669 "SerialNumber": o.Sn(),
670 }).Warn("Not starting DHCP as Dhcp bit is not set in CLI parameters")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700671 }
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700672 }
673}
674
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700675// HexDecode converts the hex encoding to binary
676func HexDecode(pkt []byte) []byte {
677 p := make([]byte, len(pkt)/2)
678 for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 {
679 // Go figure this ;)
680 u := (pkt[i] & 15) + (pkt[i]>>6)*9
681 l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9
682 p[j] = u<<4 + l
683 }
684 onuLogger.Tracef("Omci decoded: %x.", p)
685 return p
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700686}
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700687
688// BBR methods
689
690func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) {
691 omciMsg := openolt.OmciMsg{
692 IntfId: intfId,
693 OnuId: onuId,
694 Pkt: pktBytes,
695 }
696
697 if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil {
698 log.WithFields(log.Fields{
699 "IntfId": intfId,
700 "OnuId": onuId,
701 "SerialNumber": common.OnuSnToString(sn),
702 "Pkt": omciMsg.Pkt,
703 }).Fatalf("Failed to send MIB Reset")
704 }
705 log.WithFields(log.Fields{
706 "IntfId": intfId,
707 "OnuId": onuId,
708 "SerialNumber": common.OnuSnToString(sn),
709 "Pkt": omciMsg.Pkt,
710 }).Tracef("Sent OMCI message %s", msgType)
711}
712
713func (onu *Onu) getNextTid(highPriority ...bool) uint16 {
714 var next uint16
715 if len(highPriority) > 0 && highPriority[0] {
716 next = onu.hpTid
717 onu.hpTid += 1
718 if onu.hpTid < 0x8000 {
719 onu.hpTid = 0x8000
720 }
721 } else {
722 next = onu.tid
723 onu.tid += 1
724 if onu.tid >= 0x8000 {
725 onu.tid = 1
726 }
727 }
728 return next
729}
730
731// TODO move this method in responders/omcisim
732func (o *Onu) StartOmci(client openolt.OpenoltClient) {
733 mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false))
734 sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client)
735}
736
737func (o *Onu) handleOmci(msg OmciIndicationMessage, client openolt.OpenoltClient) {
738 msgType, packet := omcilib.DecodeOmci(msg.OmciInd.Pkt)
739
740 log.WithFields(log.Fields{
741 "IntfId": msg.OmciInd.IntfId,
742 "OnuId": msg.OmciInd.OnuId,
743 "OnuSn": common.OnuSnToString(o.SerialNumber),
744 "Pkt": msg.OmciInd.Pkt,
745 "msgType": msgType,
746 }).Trace("ONU Receveives OMCI Msg")
747 switch msgType {
748 default:
Matteo Scandolo813402b2019-10-23 19:24:52 -0700749 log.WithFields(log.Fields{
750 "IntfId": msg.OmciInd.IntfId,
751 "OnuId": msg.OmciInd.OnuId,
752 "OnuSn": common.OnuSnToString(o.SerialNumber),
753 "Pkt": msg.OmciInd.Pkt,
754 "msgType": msgType,
755 }).Fatalf("unexpected frame: %v", packet)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700756 case omci.MibResetResponseType:
757 mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false))
758 sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client)
759 case omci.MibUploadResponseType:
760 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
761 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
762 case omci.MibUploadNextResponseType:
763 o.seqNumber++
764
765 if o.seqNumber > 290 {
766 // NOTE we are done with the MIB Upload (290 is the number of messages the omci-sim library will respond to)
767 galEnet, _ := omcilib.CreateGalEnetRequest(o.getNextTid(false))
768 sendOmciMsg(galEnet, o.PonPortID, o.ID, o.SerialNumber, "CreateGalEnetRequest", client)
769 } else {
770 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
771 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
772 }
773 case omci.CreateResponseType:
774 // NOTE Creating a GemPort,
775 // BBsim actually doesn't care about the values, so we can do we want with the parameters
776 // In the same way we can create a GemPort even without setting up UNIs/TConts/...
777 // but we need the GemPort to trigger the state change
778
779 if !o.HasGemPort {
780 // NOTE this sends a CreateRequestType and BBSim replies with a CreateResponseType
781 // thus we send this request only once
782 gemReq, _ := omcilib.CreateGemPortRequest(o.getNextTid(false))
783 sendOmciMsg(gemReq, o.PonPortID, o.ID, o.SerialNumber, "CreateGemPortRequest", client)
784 o.HasGemPort = true
785 } else {
786 if err := o.InternalState.Event("send_eapol_flow"); err != nil {
787 onuLogger.WithFields(log.Fields{
788 "OnuId": o.ID,
789 "IntfId": o.PonPortID,
790 "OnuSn": o.Sn(),
791 }).Errorf("Error while transitioning ONU State %v", err)
792 }
793 }
794
795 }
796}
797
798func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) {
799
800 classifierProto := openolt.Classifier{
801 EthType: uint32(layers.EthernetTypeEAPOL),
802 OVid: 4091,
803 }
804
805 actionProto := openolt.Action{}
806
807 downstreamFlow := openolt.Flow{
808 AccessIntfId: int32(o.PonPortID),
809 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700810 UniId: int32(0), // NOTE do not hardcode this, we need to support multiple UNIs
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700811 FlowId: uint32(o.ID),
812 FlowType: "downstream",
813 AllocId: int32(0),
814 NetworkIntfId: int32(0),
815 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
816 Classifier: &classifierProto,
817 Action: &actionProto,
818 Priority: int32(100),
819 Cookie: uint64(o.ID),
820 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
821 }
822
823 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
824 log.WithFields(log.Fields{
825 "IntfId": o.PonPortID,
826 "OnuId": o.ID,
827 "FlowId": downstreamFlow.FlowId,
828 "PortNo": downstreamFlow.PortNo,
829 "SerialNumber": common.OnuSnToString(o.SerialNumber),
830 }).Fatalf("Failed to EAPOL Flow")
831 }
832 log.WithFields(log.Fields{
833 "IntfId": o.PonPortID,
834 "OnuId": o.ID,
835 "FlowId": downstreamFlow.FlowId,
836 "PortNo": downstreamFlow.PortNo,
837 "SerialNumber": common.OnuSnToString(o.SerialNumber),
838 }).Info("Sent EAPOL Flow")
839}
840
841func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) {
842 classifierProto := openolt.Classifier{
843 EthType: uint32(layers.EthernetTypeIPv4),
844 SrcPort: uint32(68),
845 DstPort: uint32(67),
846 }
847
848 actionProto := openolt.Action{}
849
850 downstreamFlow := openolt.Flow{
851 AccessIntfId: int32(o.PonPortID),
852 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700853 UniId: int32(0), // FIXME do not hardcode this
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700854 FlowId: uint32(o.ID),
855 FlowType: "downstream",
856 AllocId: int32(0),
857 NetworkIntfId: int32(0),
858 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
859 Classifier: &classifierProto,
860 Action: &actionProto,
861 Priority: int32(100),
862 Cookie: uint64(o.ID),
863 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
864 }
865
866 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
867 log.WithFields(log.Fields{
868 "IntfId": o.PonPortID,
869 "OnuId": o.ID,
870 "FlowId": downstreamFlow.FlowId,
871 "PortNo": downstreamFlow.PortNo,
872 "SerialNumber": common.OnuSnToString(o.SerialNumber),
873 }).Fatalf("Failed to send DHCP Flow")
874 }
875 log.WithFields(log.Fields{
876 "IntfId": o.PonPortID,
877 "OnuId": o.ID,
878 "FlowId": downstreamFlow.FlowId,
879 "PortNo": downstreamFlow.PortNo,
880 "SerialNumber": common.OnuSnToString(o.SerialNumber),
881 }).Info("Sent DHCP Flow")
882}