blob: 8c6641a00a602f879ae7da9dabe8337ec119ee85 [file] [log] [blame]
Matteo Scandolo4a036262020-08-17 15:56:13 -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
17package devices
18
19import (
Matteo Scandolo618a6582020-09-09 12:21:29 -070020 "encoding/hex"
Matteo Scandolo4a036262020-08-17 15:56:13 -070021 "github.com/looplab/fsm"
22 "github.com/opencord/bbsim/internal/bbsim/packetHandlers"
23 "github.com/opencord/bbsim/internal/bbsim/responders/dhcp"
24 "github.com/opencord/bbsim/internal/bbsim/responders/eapol"
Matteo Scandolo618a6582020-09-09 12:21:29 -070025 "github.com/opencord/bbsim/internal/bbsim/responders/igmp"
Matteo Scandolo4a036262020-08-17 15:56:13 -070026 bbsimTypes "github.com/opencord/bbsim/internal/bbsim/types"
27 log "github.com/sirupsen/logrus"
28 "net"
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -070029 "time"
Matteo Scandolo4a036262020-08-17 15:56:13 -070030)
31
32var serviceLogger = log.WithFields(log.Fields{
33 "module": "SERVICE",
34})
35
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -070036// time to wait before fail EAPOL/DHCP
37// (it's a variable and not a constant so it can be overridden in the tests)
Matteo Scandolo24a88c42020-09-17 14:55:28 -070038var eapolWaitTime = 60 * time.Second
39var dhcpWaitTime = 60 * time.Second
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -070040
Matteo Scandolo4a036262020-08-17 15:56:13 -070041type ServiceIf interface {
Matteo Scandolobd875b32020-09-18 17:46:31 -070042 HandlePackets() // start listening on the PacketCh
43 HandleAuth() // Sends the EapoStart packet
44 HandleDhcp(pbit uint8, cTag int) // Sends the DHCPDiscover packet
Matteo Scandolo75ed5b92020-09-03 09:03:16 -070045
Matteo Scandoloadc72a82020-09-08 18:46:08 -070046 Initialize(stream bbsimTypes.Stream)
Matteo Scandolo75ed5b92020-09-03 09:03:16 -070047 Disable()
Matteo Scandolo4a036262020-08-17 15:56:13 -070048}
49
50type Service struct {
51 Name string
52 HwAddress net.HardwareAddr
53 Onu *Onu
54 CTag int
55 STag int
56 NeedsEapol bool
57 NeedsDhcp bool
58 NeedsIgmp bool
59 TechnologyProfileID int
60 UniTagMatch int
61 ConfigureMacAddress bool
Matteo Scandolo8d281372020-09-03 16:23:37 -070062 UsPonCTagPriority uint8
63 UsPonSTagPriority uint8
64 DsPonCTagPriority uint8
65 DsPonSTagPriority uint8
Matteo Scandolo4a036262020-08-17 15:56:13 -070066
67 // state
Matteo Scandolo75ed5b92020-09-03 09:03:16 -070068 GemPort uint32
69 InternalState *fsm.FSM
70 EapolState *fsm.FSM
71 DHCPState *fsm.FSM
Matteo Scandolo618a6582020-09-09 12:21:29 -070072 IGMPState *fsm.FSM
Matteo Scandoloadc72a82020-09-08 18:46:08 -070073 Channel chan Message // drive Service lifecycle
74 PacketCh chan OnuPacketMessage // handle packets
75 Stream bbsimTypes.Stream // the gRPC stream to communicate with the adapter, created in the initialize transition
Matteo Scandolo4a036262020-08-17 15:56:13 -070076}
77
78func NewService(name string, hwAddress net.HardwareAddr, onu *Onu, cTag int, sTag int,
79 needsEapol bool, needsDchp bool, needsIgmp bool, tpID int, uniTagMatch int, configMacAddress bool,
Matteo Scandolo8d281372020-09-03 16:23:37 -070080 usPonCTagPriority uint8, usPonSTagPriority uint8, dsPonCTagPriority uint8, dsPonSTagPriority uint8) (*Service, error) {
Matteo Scandolo4a036262020-08-17 15:56:13 -070081
82 service := Service{
83 Name: name,
84 HwAddress: hwAddress,
85 Onu: onu,
86 CTag: cTag,
87 STag: sTag,
88 NeedsEapol: needsEapol,
89 NeedsDhcp: needsDchp,
90 NeedsIgmp: needsIgmp,
91 TechnologyProfileID: tpID,
92 UniTagMatch: uniTagMatch,
93 ConfigureMacAddress: configMacAddress,
94 UsPonCTagPriority: usPonCTagPriority,
95 UsPonSTagPriority: usPonSTagPriority,
96 DsPonCTagPriority: dsPonCTagPriority,
97 DsPonSTagPriority: dsPonSTagPriority,
Matteo Scandolo4a036262020-08-17 15:56:13 -070098 }
99
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700100 service.InternalState = fsm.NewFSM(
101 "created",
102 fsm.Events{
103 {Name: "initialized", Src: []string{"created", "disabled"}, Dst: "initialized"},
104 {Name: "disabled", Src: []string{"initialized"}, Dst: "disabled"},
105 },
106 fsm.Callbacks{
107 "enter_state": func(e *fsm.Event) {
108 service.logStateChange("InternalState", e.Src, e.Dst)
109 },
110 "enter_initialized": func(e *fsm.Event) {
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700111
112 stream, ok := e.Args[0].(bbsimTypes.Stream)
113 if !ok {
114 serviceLogger.Fatal("initialize invoke with wrong arguments")
115 }
116
117 service.Stream = stream
118
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700119 service.PacketCh = make(chan OnuPacketMessage)
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700120 service.Channel = make(chan Message)
121
122 go service.HandlePackets()
123 go service.HandleChannel()
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700124 },
125 "enter_disabled": func(e *fsm.Event) {
126 // reset the state machines
127 service.EapolState.SetState("created")
128 service.DHCPState.SetState("created")
129
130 // stop listening for packets
131 close(service.PacketCh)
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700132 close(service.Channel)
133
134 service.PacketCh = nil
135 service.Channel = nil
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700136 },
137 },
138 )
139
Matteo Scandolo4a036262020-08-17 15:56:13 -0700140 service.EapolState = fsm.NewFSM(
141 "created",
142 fsm.Events{
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700143 {Name: "start_auth", Src: []string{"created", "eap_response_success_received", "auth_failed"}, Dst: "auth_started"},
Matteo Scandolo4a036262020-08-17 15:56:13 -0700144 {Name: "eap_start_sent", Src: []string{"auth_started"}, Dst: "eap_start_sent"},
145 {Name: "eap_response_identity_sent", Src: []string{"eap_start_sent"}, Dst: "eap_response_identity_sent"},
146 {Name: "eap_response_challenge_sent", Src: []string{"eap_response_identity_sent"}, Dst: "eap_response_challenge_sent"},
147 {Name: "eap_response_success_received", Src: []string{"eap_response_challenge_sent"}, Dst: "eap_response_success_received"},
148 {Name: "auth_failed", Src: []string{"auth_started", "eap_start_sent", "eap_response_identity_sent", "eap_response_challenge_sent"}, Dst: "auth_failed"},
149 },
150 fsm.Callbacks{
151 "enter_state": func(e *fsm.Event) {
152 service.logStateChange("EapolState", e.Src, e.Dst)
153 },
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700154 "before_start_auth": func(e *fsm.Event) {
155 msg := Message{
156 Type: StartEAPOL,
157 }
158 service.Channel <- msg
159 },
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700160 "enter_auth_started": func(e *fsm.Event) {
161 go func() {
162
163 loop:
164 for {
165 select {
166 case <-service.Onu.PonPort.Olt.enableContext.Done():
167 // if the OLT is disabled, then cancel
168 break loop
169 case <-time.After(eapolWaitTime):
170 if service.EapolState.Current() != "eap_response_success_received" {
171 serviceLogger.WithFields(log.Fields{
172 "OnuId": service.Onu.ID,
173 "IntfId": service.Onu.PonPortID,
174 "OnuSn": service.Onu.Sn(),
175 "Name": service.Name,
176 "EapolState": service.EapolState.Current(),
177 }).Warn("EAPOL failed, resetting EAPOL State")
178 _ = service.EapolState.Event("auth_failed")
Matteo Scandolo294da602020-09-21 17:43:03 -0700179 break loop
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700180 }
181 }
182
183 }
184 }()
185 },
Matteo Scandolo4a036262020-08-17 15:56:13 -0700186 },
187 )
188
189 service.DHCPState = fsm.NewFSM(
190 "created",
191 fsm.Events{
Matteo Scandolo7f656fb2020-09-08 15:18:15 -0700192 // TODO only allow transitions to dhcp_start from success or failure, not in-between states
193 // TODO forcefully fail DHCP if we don't get an ack in X seconds
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700194 {Name: "start_dhcp", Src: []string{"created", "dhcp_ack_received", "dhcp_failed"}, Dst: "dhcp_started"},
Matteo Scandolo4a036262020-08-17 15:56:13 -0700195 {Name: "dhcp_discovery_sent", Src: []string{"dhcp_started"}, Dst: "dhcp_discovery_sent"},
196 {Name: "dhcp_request_sent", Src: []string{"dhcp_discovery_sent"}, Dst: "dhcp_request_sent"},
197 {Name: "dhcp_ack_received", Src: []string{"dhcp_request_sent"}, Dst: "dhcp_ack_received"},
198 {Name: "dhcp_failed", Src: []string{"dhcp_started", "dhcp_discovery_sent", "dhcp_request_sent"}, Dst: "dhcp_failed"},
199 },
200 fsm.Callbacks{
201 "enter_state": func(e *fsm.Event) {
202 service.logStateChange("DHCPState", e.Src, e.Dst)
203 },
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700204 "before_start_dhcp": func(e *fsm.Event) {
205 msg := Message{
206 Type: StartDHCP,
207 }
208 service.Channel <- msg
209 },
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700210 "enter_dhcp_started": func(e *fsm.Event) {
211 go func() {
212
213 loop:
214 for {
215 select {
216 case <-service.Onu.PonPort.Olt.enableContext.Done():
217 // if the OLT is disabled, then cancel
218 break loop
219 case <-time.After(dhcpWaitTime):
220 if service.DHCPState.Current() != "dhcp_ack_received" {
221 serviceLogger.WithFields(log.Fields{
222 "OnuId": service.Onu.ID,
223 "IntfId": service.Onu.PonPortID,
224 "OnuSn": service.Onu.Sn(),
225 "Name": service.Name,
226 "DHCPState": service.DHCPState.Current(),
227 }).Warn("DHCP failed, resetting DHCP State")
228 _ = service.DHCPState.Event("dhcp_failed")
Matteo Scandolo294da602020-09-21 17:43:03 -0700229 break loop
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700230 }
231 }
232
233 }
234 }()
235 },
Matteo Scandolo4a036262020-08-17 15:56:13 -0700236 },
237 )
238
Matteo Scandolo618a6582020-09-09 12:21:29 -0700239 service.IGMPState = fsm.NewFSM(
240 "created",
241 fsm.Events{
242 {Name: "igmp_join_start", Src: []string{"created", "igmp_left", "igmp_join_error", "igmp_join_started"}, Dst: "igmp_join_started"},
243 {Name: "igmp_join_startv3", Src: []string{"igmp_left", "igmp_join_error", "igmp_join_started"}, Dst: "igmp_join_started"},
244 {Name: "igmp_join_error", Src: []string{"igmp_join_started"}, Dst: "igmp_join_error"},
245 {Name: "igmp_leave", Src: []string{"igmp_join_started"}, Dst: "igmp_left"},
246 },
247 fsm.Callbacks{
248 "igmp_join_start": func(e *fsm.Event) {
249 msg := Message{
250 Type: IGMPMembershipReportV2,
251 }
252 service.Channel <- msg
253 },
254 "igmp_leave": func(e *fsm.Event) {
255 msg := Message{
256 Type: IGMPLeaveGroup}
257 service.Channel <- msg
258 },
259 "igmp_join_startv3": func(e *fsm.Event) {
260 msg := Message{
261 Type: IGMPMembershipReportV3,
262 }
263 service.Channel <- msg
264 },
265 },
266 )
267
Matteo Scandolo4a036262020-08-17 15:56:13 -0700268 return &service, nil
269}
270
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700271// HandleAuth is used to start EAPOL for a particular Service when the corresponding flow is received
272func (s *Service) HandleAuth() {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700273
274 if !s.NeedsEapol {
275 serviceLogger.WithFields(log.Fields{
276 "OnuId": s.Onu.ID,
277 "IntfId": s.Onu.PonPortID,
278 "OnuSn": s.Onu.Sn(),
279 "Name": s.Name,
280 "NeedsEapol": s.NeedsEapol,
281 }).Debug("Won't start authentication as EAPOL is not required")
282 return
283 }
284
Matteo Scandolo4a036262020-08-17 15:56:13 -0700285 if err := s.EapolState.Event("start_auth"); err != nil {
286 serviceLogger.WithFields(log.Fields{
287 "OnuId": s.Onu.ID,
288 "IntfId": s.Onu.PonPortID,
289 "OnuSn": s.Onu.Sn(),
290 "Name": s.Name,
291 "err": err.Error(),
292 }).Error("Can't start auth for this Service")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700293 }
294}
295
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700296// HandleDhcp is used to start DHCP for a particular Service when the corresponding flow is received
Matteo Scandolobd875b32020-09-18 17:46:31 -0700297func (s *Service) HandleDhcp(pbit uint8, cTag int) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700298
Matteo Scandolobd875b32020-09-18 17:46:31 -0700299 if s.CTag != cTag || (s.UsPonCTagPriority != pbit && pbit != 255) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700300 serviceLogger.WithFields(log.Fields{
301 "OnuId": s.Onu.ID,
302 "IntfId": s.Onu.PonPortID,
303 "OnuSn": s.Onu.Sn(),
304 "Name": s.Name,
Matteo Scandolo7f656fb2020-09-08 15:18:15 -0700305 }).Trace("DHCP flow is not for this service, ignoring")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700306 return
307 }
308
Matteo Scandolo4a036262020-08-17 15:56:13 -0700309 if !s.NeedsDhcp {
310 serviceLogger.WithFields(log.Fields{
311 "OnuId": s.Onu.ID,
312 "IntfId": s.Onu.PonPortID,
313 "OnuSn": s.Onu.Sn(),
314 "Name": s.Name,
315 "NeedsDhcp": s.NeedsDhcp,
Matteo Scandolo7f656fb2020-09-08 15:18:15 -0700316 }).Trace("Won't start DHCP as it is not required")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700317 return
318 }
319
Matteo Scandolo7f656fb2020-09-08 15:18:15 -0700320 // TODO check if the DHCP flow was received before starting auth
Matteo Scandolo4a036262020-08-17 15:56:13 -0700321
322 if err := s.DHCPState.Event("start_dhcp"); err != nil {
323 serviceLogger.WithFields(log.Fields{
324 "OnuId": s.Onu.ID,
325 "IntfId": s.Onu.PonPortID,
326 "OnuSn": s.Onu.Sn(),
327 "Name": s.Name,
328 "err": err.Error(),
329 }).Error("Can't start DHCP for this Service")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700330 }
331}
332
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700333func (s *Service) HandlePackets() {
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700334 serviceLogger.WithFields(log.Fields{
335 "OnuId": s.Onu.ID,
336 "IntfId": s.Onu.PonPortID,
337 "OnuSn": s.Onu.Sn(),
338 "GemPortId": s.GemPort,
339 "Name": s.Name,
340 }).Debug("Listening on Service Packet Channel")
341
342 defer func() {
343 serviceLogger.WithFields(log.Fields{
344 "OnuId": s.Onu.ID,
345 "IntfId": s.Onu.PonPortID,
346 "OnuSn": s.Onu.Sn(),
347 "GemPortId": s.GemPort,
348 "Name": s.Name,
349 }).Debug("Done Listening on Service Packet Channel")
350 }()
351
352 for msg := range s.PacketCh {
353 serviceLogger.WithFields(log.Fields{
354 "OnuId": s.Onu.ID,
355 "IntfId": s.Onu.PonPortID,
356 "OnuSn": s.Onu.Sn(),
357 "Name": s.Name,
358 "messageType": msg.Type,
Matteo Scandolo7f656fb2020-09-08 15:18:15 -0700359 }).Trace("Received message on Service Packet Channel")
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700360
361 if msg.Type == packetHandlers.EAPOL {
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700362 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, s.GemPort, s.Onu.Sn(), s.Onu.PortNo, s.EapolState, msg.Packet, s.Stream, nil)
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700363 } else if msg.Type == packetHandlers.DHCP {
Matteo Scandolo24a88c42020-09-17 14:55:28 -0700364 _ = dhcp.HandleNextPacket(s.Onu.ID, s.Onu.PonPortID, s.Name, s.Onu.Sn(), s.Onu.PortNo, s.CTag, s.GemPort, s.HwAddress, s.DHCPState, msg.Packet, s.UsPonCTagPriority, s.Stream)
Matteo Scandolo618a6582020-09-09 12:21:29 -0700365 } else if msg.Type == packetHandlers.IGMP {
366 log.Warn(hex.EncodeToString(msg.Packet.Data()))
367 _ = igmp.HandleNextPacket(s.Onu.PonPortID, s.Onu.ID, s.Onu.Sn(), s.Onu.PortNo, s.GemPort, s.HwAddress, msg.Packet, s.CTag, s.UsPonCTagPriority, s.Stream)
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700368 }
369 }
370}
371
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700372func (s *Service) HandleChannel() {
373 serviceLogger.WithFields(log.Fields{
374 "OnuId": s.Onu.ID,
375 "IntfId": s.Onu.PonPortID,
376 "OnuSn": s.Onu.Sn(),
377 "GemPortId": s.GemPort,
378 "Name": s.Name,
379 }).Debug("Listening on Service Channel")
380
381 defer func() {
382 serviceLogger.WithFields(log.Fields{
383 "OnuId": s.Onu.ID,
384 "IntfId": s.Onu.PonPortID,
385 "OnuSn": s.Onu.Sn(),
386 "GemPortId": s.GemPort,
387 "Name": s.Name,
388 }).Debug("Done Listening on Service Channel")
389 }()
390 for msg := range s.Channel {
Matteo Scandolo618a6582020-09-09 12:21:29 -0700391 switch msg.Type {
392 case StartEAPOL:
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700393 if err := s.handleEapolStart(s.Stream); err != nil {
394 serviceLogger.WithFields(log.Fields{
395 "OnuId": s.Onu.ID,
396 "IntfId": s.Onu.PonPortID,
397 "OnuSn": s.Onu.Sn(),
398 "Name": s.Name,
399 "err": err,
400 }).Error("Error while sending EapolStart packet")
401 _ = s.EapolState.Event("auth_failed")
402 }
Matteo Scandolo618a6582020-09-09 12:21:29 -0700403 case StartDHCP:
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700404 if err := s.handleDHCPStart(s.Stream); err != nil {
405 serviceLogger.WithFields(log.Fields{
406 "OnuId": s.Onu.ID,
407 "IntfId": s.Onu.PonPortID,
408 "OnuSn": s.Onu.Sn(),
409 "Name": s.Name,
410 "err": err,
411 }).Error("Error while sending DHCPDiscovery packet")
412 _ = s.DHCPState.Event("dhcp_failed")
Matteo Scandolo618a6582020-09-09 12:21:29 -0700413
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700414 }
Matteo Scandolo618a6582020-09-09 12:21:29 -0700415 case IGMPMembershipReportV2:
416 serviceLogger.WithFields(log.Fields{
417 "OnuId": s.Onu.ID,
418 "IntfId": s.Onu.PonPortID,
419 "OnuSn": s.Onu.Sn(),
420 "Name": s.Name,
421 }).Debug("Recieved IGMPMembershipReportV2 message on ONU channel")
422 _ = igmp.SendIGMPMembershipReportV2(s.Onu.PonPortID, s.Onu.ID, s.Onu.Sn(), s.Onu.PortNo, s.GemPort, s.HwAddress, s.CTag, s.UsPonCTagPriority, s.Stream)
423 case IGMPLeaveGroup:
424 serviceLogger.WithFields(log.Fields{
425 "OnuId": s.Onu.ID,
426 "IntfId": s.Onu.PonPortID,
427 "OnuSn": s.Onu.Sn(),
428 "Name": s.Name,
429 }).Debug("Recieved IGMPLeaveGroupV2 message on ONU channel")
430 _ = igmp.SendIGMPLeaveGroupV2(s.Onu.PonPortID, s.Onu.ID, s.Onu.Sn(), s.Onu.PortNo, s.GemPort, s.HwAddress, s.CTag, s.UsPonCTagPriority, s.Stream)
431 case IGMPMembershipReportV3:
432 serviceLogger.WithFields(log.Fields{
433 "OnuId": s.Onu.ID,
434 "IntfId": s.Onu.PonPortID,
435 "OnuSn": s.Onu.Sn(),
436 "Name": s.Name,
437 }).Debug("Recieved IGMPMembershipReportV3 message on ONU channel")
438 _ = igmp.SendIGMPMembershipReportV3(s.Onu.PonPortID, s.Onu.ID, s.Onu.Sn(), s.Onu.PortNo, s.GemPort, s.HwAddress, s.CTag, s.UsPonCTagPriority, s.Stream)
439
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700440 }
441 }
442}
443
444func (s *Service) Initialize(stream bbsimTypes.Stream) {
445 if err := s.InternalState.Event("initialized", stream); err != nil {
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700446 serviceLogger.WithFields(log.Fields{
447 "OnuId": s.Onu.ID,
448 "IntfId": s.Onu.PonPortID,
449 "OnuSn": s.Onu.Sn(),
450 "Name": s.Name,
451 "Err": err,
452 }).Error("Cannot initialize service")
453 }
454}
455
456func (s *Service) Disable() {
457 if err := s.InternalState.Event("disabled"); err != nil {
458 serviceLogger.WithFields(log.Fields{
459 "OnuId": s.Onu.ID,
460 "IntfId": s.Onu.PonPortID,
461 "OnuSn": s.Onu.Sn(),
462 "Name": s.Name,
463 "Err": err,
464 }).Error("Cannot disable service")
465 }
466}
467
Matteo Scandolo4a036262020-08-17 15:56:13 -0700468func (s *Service) handleEapolStart(stream bbsimTypes.Stream) error {
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700469 // TODO fail Auth if it does not succeed in 30 seconds
Matteo Scandolo4a036262020-08-17 15:56:13 -0700470 serviceLogger.WithFields(log.Fields{
471 "OnuId": s.Onu.ID,
472 "IntfId": s.Onu.PonPortID,
473 "OnuSn": s.Onu.Sn(),
474 "GemPort": s.GemPort,
475 "Name": s.Name,
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700476 }).Trace("handleEapolStart")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700477
478 if err := eapol.SendEapStart(s.Onu.ID, s.Onu.PonPortID, s.Onu.Sn(), s.Onu.PortNo,
479 s.HwAddress, s.GemPort, s.EapolState, stream); err != nil {
480 serviceLogger.WithFields(log.Fields{
481 "OnuId": s.Onu.ID,
482 "IntfId": s.Onu.PonPortID,
483 "OnuSn": s.Onu.Sn(),
484 "GemPort": s.GemPort,
485 "Name": s.Name,
486 }).Error("handleEapolStart")
487 return err
488 }
489 return nil
490}
491
492func (s *Service) handleDHCPStart(stream bbsimTypes.Stream) error {
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700493 // TODO fail DHCP if it does not succeed in 30 seconds
Matteo Scandolo4a036262020-08-17 15:56:13 -0700494 serviceLogger.WithFields(log.Fields{
495 "OnuId": s.Onu.ID,
496 "IntfId": s.Onu.PonPortID,
497 "OnuSn": s.Onu.Sn(),
498 "Name": s.Name,
499 "GemPortId": s.GemPort,
500 }).Debugf("HandleDHCPStart")
501
Matteo Scandolo24a88c42020-09-17 14:55:28 -0700502 if err := dhcp.SendDHCPDiscovery(s.Onu.PonPortID, s.Onu.ID, s.Name, int(s.CTag), s.GemPort,
Matteo Scandolo8d281372020-09-03 16:23:37 -0700503 s.Onu.Sn(), s.Onu.PortNo, s.DHCPState, s.HwAddress, s.UsPonCTagPriority, stream); err != nil {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700504 serviceLogger.WithFields(log.Fields{
505 "OnuId": s.Onu.ID,
506 "IntfId": s.Onu.PonPortID,
507 "OnuSn": s.Onu.Sn(),
508 "Name": s.Name,
509 "GemPortId": s.GemPort,
510 }).Error("HandleDHCPStart")
511 return err
512 }
513 return nil
514}
515
Matteo Scandolo4a036262020-08-17 15:56:13 -0700516func (s *Service) logStateChange(stateMachine string, src string, dst string) {
517 serviceLogger.WithFields(log.Fields{
518 "OnuId": s.Onu.ID,
519 "IntfId": s.Onu.PonPortID,
520 "OnuSn": s.Onu.Sn(),
521 "Name": s.Name,
522 }).Debugf("Changing Service.%s InternalState from %s to %s", stateMachine, src, dst)
523}