blob: c7983a4684fe2776a21b64de600e47c25c157cd4 [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"
Matteo Scandolo76c3ff62020-09-24 18:03:01 -070027 "github.com/opencord/bbsim/internal/common"
Matteo Scandolo4a036262020-08-17 15:56:13 -070028 log "github.com/sirupsen/logrus"
29 "net"
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -070030 "time"
Matteo Scandolo4a036262020-08-17 15:56:13 -070031)
32
33var serviceLogger = log.WithFields(log.Fields{
34 "module": "SERVICE",
35})
36
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -070037// time to wait before fail EAPOL/DHCP
38// (it's a variable and not a constant so it can be overridden in the tests)
Matteo Scandolo24a88c42020-09-17 14:55:28 -070039var eapolWaitTime = 60 * time.Second
40var dhcpWaitTime = 60 * time.Second
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -070041
Matteo Scandolo4a036262020-08-17 15:56:13 -070042type ServiceIf interface {
Matteo Scandolobd875b32020-09-18 17:46:31 -070043 HandlePackets() // start listening on the PacketCh
44 HandleAuth() // Sends the EapoStart packet
45 HandleDhcp(pbit uint8, cTag int) // Sends the DHCPDiscover packet
Matteo Scandolo75ed5b92020-09-03 09:03:16 -070046
Matteo Scandoloadc72a82020-09-08 18:46:08 -070047 Initialize(stream bbsimTypes.Stream)
Matteo Scandolo75ed5b92020-09-03 09:03:16 -070048 Disable()
Matteo Scandolo4a036262020-08-17 15:56:13 -070049}
50
51type Service struct {
52 Name string
53 HwAddress net.HardwareAddr
54 Onu *Onu
55 CTag int
56 STag int
57 NeedsEapol bool
58 NeedsDhcp bool
59 NeedsIgmp bool
60 TechnologyProfileID int
61 UniTagMatch int
62 ConfigureMacAddress bool
Matteo Scandolo8d281372020-09-03 16:23:37 -070063 UsPonCTagPriority uint8
64 UsPonSTagPriority uint8
65 DsPonCTagPriority uint8
66 DsPonSTagPriority uint8
Matteo Scandolo4a036262020-08-17 15:56:13 -070067
68 // state
Matteo Scandolo75ed5b92020-09-03 09:03:16 -070069 GemPort uint32
70 InternalState *fsm.FSM
71 EapolState *fsm.FSM
72 DHCPState *fsm.FSM
Matteo Scandolo618a6582020-09-09 12:21:29 -070073 IGMPState *fsm.FSM
Matteo Scandoloadc72a82020-09-08 18:46:08 -070074 Channel chan Message // drive Service lifecycle
75 PacketCh chan OnuPacketMessage // handle packets
76 Stream bbsimTypes.Stream // the gRPC stream to communicate with the adapter, created in the initialize transition
Matteo Scandolo4a036262020-08-17 15:56:13 -070077}
78
79func NewService(name string, hwAddress net.HardwareAddr, onu *Onu, cTag int, sTag int,
80 needsEapol bool, needsDchp bool, needsIgmp bool, tpID int, uniTagMatch int, configMacAddress bool,
Matteo Scandolo8d281372020-09-03 16:23:37 -070081 usPonCTagPriority uint8, usPonSTagPriority uint8, dsPonCTagPriority uint8, dsPonSTagPriority uint8) (*Service, error) {
Matteo Scandolo4a036262020-08-17 15:56:13 -070082
83 service := Service{
84 Name: name,
85 HwAddress: hwAddress,
86 Onu: onu,
87 CTag: cTag,
88 STag: sTag,
89 NeedsEapol: needsEapol,
90 NeedsDhcp: needsDchp,
91 NeedsIgmp: needsIgmp,
92 TechnologyProfileID: tpID,
93 UniTagMatch: uniTagMatch,
94 ConfigureMacAddress: configMacAddress,
95 UsPonCTagPriority: usPonCTagPriority,
96 UsPonSTagPriority: usPonSTagPriority,
97 DsPonCTagPriority: dsPonCTagPriority,
98 DsPonSTagPriority: dsPonSTagPriority,
Matteo Scandolo4a036262020-08-17 15:56:13 -070099 }
100
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700101 service.InternalState = fsm.NewFSM(
102 "created",
103 fsm.Events{
104 {Name: "initialized", Src: []string{"created", "disabled"}, Dst: "initialized"},
105 {Name: "disabled", Src: []string{"initialized"}, Dst: "disabled"},
106 },
107 fsm.Callbacks{
108 "enter_state": func(e *fsm.Event) {
109 service.logStateChange("InternalState", e.Src, e.Dst)
110 },
111 "enter_initialized": func(e *fsm.Event) {
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700112
113 stream, ok := e.Args[0].(bbsimTypes.Stream)
114 if !ok {
115 serviceLogger.Fatal("initialize invoke with wrong arguments")
116 }
117
118 service.Stream = stream
119
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700120 service.PacketCh = make(chan OnuPacketMessage)
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700121 service.Channel = make(chan Message)
122
123 go service.HandlePackets()
124 go service.HandleChannel()
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700125 },
126 "enter_disabled": func(e *fsm.Event) {
127 // reset the state machines
128 service.EapolState.SetState("created")
129 service.DHCPState.SetState("created")
130
131 // stop listening for packets
132 close(service.PacketCh)
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700133 close(service.Channel)
134
135 service.PacketCh = nil
136 service.Channel = nil
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700137 },
138 },
139 )
140
Matteo Scandolo4a036262020-08-17 15:56:13 -0700141 service.EapolState = fsm.NewFSM(
142 "created",
143 fsm.Events{
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700144 {Name: "start_auth", Src: []string{"created", "eap_response_success_received", "auth_failed"}, Dst: "auth_started"},
Matteo Scandolo4a036262020-08-17 15:56:13 -0700145 {Name: "eap_start_sent", Src: []string{"auth_started"}, Dst: "eap_start_sent"},
146 {Name: "eap_response_identity_sent", Src: []string{"eap_start_sent"}, Dst: "eap_response_identity_sent"},
147 {Name: "eap_response_challenge_sent", Src: []string{"eap_response_identity_sent"}, Dst: "eap_response_challenge_sent"},
148 {Name: "eap_response_success_received", Src: []string{"eap_response_challenge_sent"}, Dst: "eap_response_success_received"},
149 {Name: "auth_failed", Src: []string{"auth_started", "eap_start_sent", "eap_response_identity_sent", "eap_response_challenge_sent"}, Dst: "auth_failed"},
150 },
151 fsm.Callbacks{
152 "enter_state": func(e *fsm.Event) {
153 service.logStateChange("EapolState", e.Src, e.Dst)
154 },
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700155 "before_start_auth": func(e *fsm.Event) {
156 msg := Message{
157 Type: StartEAPOL,
158 }
159 service.Channel <- msg
160 },
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700161 "enter_auth_started": func(e *fsm.Event) {
162 go func() {
163
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700164 for {
165 select {
166 case <-service.Onu.PonPort.Olt.enableContext.Done():
167 // if the OLT is disabled, then cancel
Matteo Scandolo6e7afb02020-09-24 11:32:18 -0700168 return
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700169 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")
Matteo Scandolo76c3ff62020-09-24 18:03:01 -0700178
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700179 _ = service.EapolState.Event("auth_failed")
Matteo Scandolo76c3ff62020-09-24 18:03:01 -0700180 if common.Config.BBSim.AuthRetry {
181 _ = service.EapolState.Event("start_auth")
182 }
183
Matteo Scandolo6e7afb02020-09-24 11:32:18 -0700184 return
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700185 }
186 }
187
188 }
189 }()
190 },
Matteo Scandolo4a036262020-08-17 15:56:13 -0700191 },
192 )
193
194 service.DHCPState = fsm.NewFSM(
195 "created",
196 fsm.Events{
Matteo Scandolo7f656fb2020-09-08 15:18:15 -0700197 // TODO only allow transitions to dhcp_start from success or failure, not in-between states
198 // TODO forcefully fail DHCP if we don't get an ack in X seconds
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700199 {Name: "start_dhcp", Src: []string{"created", "dhcp_ack_received", "dhcp_failed"}, Dst: "dhcp_started"},
Matteo Scandolo4a036262020-08-17 15:56:13 -0700200 {Name: "dhcp_discovery_sent", Src: []string{"dhcp_started"}, Dst: "dhcp_discovery_sent"},
201 {Name: "dhcp_request_sent", Src: []string{"dhcp_discovery_sent"}, Dst: "dhcp_request_sent"},
202 {Name: "dhcp_ack_received", Src: []string{"dhcp_request_sent"}, Dst: "dhcp_ack_received"},
203 {Name: "dhcp_failed", Src: []string{"dhcp_started", "dhcp_discovery_sent", "dhcp_request_sent"}, Dst: "dhcp_failed"},
204 },
205 fsm.Callbacks{
206 "enter_state": func(e *fsm.Event) {
207 service.logStateChange("DHCPState", e.Src, e.Dst)
208 },
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700209 "before_start_dhcp": func(e *fsm.Event) {
210 msg := Message{
211 Type: StartDHCP,
212 }
213 service.Channel <- msg
214 },
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700215 "enter_dhcp_started": func(e *fsm.Event) {
216 go func() {
217
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700218 for {
219 select {
220 case <-service.Onu.PonPort.Olt.enableContext.Done():
221 // if the OLT is disabled, then cancel
Matteo Scandolo6e7afb02020-09-24 11:32:18 -0700222 return
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700223 case <-time.After(dhcpWaitTime):
224 if service.DHCPState.Current() != "dhcp_ack_received" {
225 serviceLogger.WithFields(log.Fields{
226 "OnuId": service.Onu.ID,
227 "IntfId": service.Onu.PonPortID,
228 "OnuSn": service.Onu.Sn(),
229 "Name": service.Name,
230 "DHCPState": service.DHCPState.Current(),
231 }).Warn("DHCP failed, resetting DHCP State")
Matteo Scandolo76c3ff62020-09-24 18:03:01 -0700232
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700233 _ = service.DHCPState.Event("dhcp_failed")
Matteo Scandolo76c3ff62020-09-24 18:03:01 -0700234 if common.Config.BBSim.DhcpRetry {
235 _ = service.DHCPState.Event("start_dhcp")
236 }
237
Matteo Scandolo6e7afb02020-09-24 11:32:18 -0700238 return
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700239 }
240 }
241
242 }
243 }()
244 },
Matteo Scandolo4a036262020-08-17 15:56:13 -0700245 },
246 )
247
Matteo Scandolo618a6582020-09-09 12:21:29 -0700248 service.IGMPState = fsm.NewFSM(
249 "created",
250 fsm.Events{
251 {Name: "igmp_join_start", Src: []string{"created", "igmp_left", "igmp_join_error", "igmp_join_started"}, Dst: "igmp_join_started"},
252 {Name: "igmp_join_startv3", Src: []string{"igmp_left", "igmp_join_error", "igmp_join_started"}, Dst: "igmp_join_started"},
253 {Name: "igmp_join_error", Src: []string{"igmp_join_started"}, Dst: "igmp_join_error"},
254 {Name: "igmp_leave", Src: []string{"igmp_join_started"}, Dst: "igmp_left"},
255 },
256 fsm.Callbacks{
257 "igmp_join_start": func(e *fsm.Event) {
258 msg := Message{
259 Type: IGMPMembershipReportV2,
260 }
261 service.Channel <- msg
262 },
263 "igmp_leave": func(e *fsm.Event) {
264 msg := Message{
265 Type: IGMPLeaveGroup}
266 service.Channel <- msg
267 },
268 "igmp_join_startv3": func(e *fsm.Event) {
269 msg := Message{
270 Type: IGMPMembershipReportV3,
271 }
272 service.Channel <- msg
273 },
274 },
275 )
276
Matteo Scandolo4a036262020-08-17 15:56:13 -0700277 return &service, nil
278}
279
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700280// HandleAuth is used to start EAPOL for a particular Service when the corresponding flow is received
281func (s *Service) HandleAuth() {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700282
283 if !s.NeedsEapol {
284 serviceLogger.WithFields(log.Fields{
285 "OnuId": s.Onu.ID,
286 "IntfId": s.Onu.PonPortID,
287 "OnuSn": s.Onu.Sn(),
288 "Name": s.Name,
289 "NeedsEapol": s.NeedsEapol,
290 }).Debug("Won't start authentication as EAPOL is not required")
291 return
292 }
293
Matteo Scandolo4a036262020-08-17 15:56:13 -0700294 if err := s.EapolState.Event("start_auth"); err != nil {
295 serviceLogger.WithFields(log.Fields{
296 "OnuId": s.Onu.ID,
297 "IntfId": s.Onu.PonPortID,
298 "OnuSn": s.Onu.Sn(),
299 "Name": s.Name,
300 "err": err.Error(),
301 }).Error("Can't start auth for this Service")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700302 }
303}
304
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700305// HandleDhcp is used to start DHCP for a particular Service when the corresponding flow is received
Matteo Scandolobd875b32020-09-18 17:46:31 -0700306func (s *Service) HandleDhcp(pbit uint8, cTag int) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700307
Matteo Scandolobd875b32020-09-18 17:46:31 -0700308 if s.CTag != cTag || (s.UsPonCTagPriority != pbit && pbit != 255) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700309 serviceLogger.WithFields(log.Fields{
310 "OnuId": s.Onu.ID,
311 "IntfId": s.Onu.PonPortID,
312 "OnuSn": s.Onu.Sn(),
313 "Name": s.Name,
Matteo Scandolo7f656fb2020-09-08 15:18:15 -0700314 }).Trace("DHCP flow is not for this service, ignoring")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700315 return
316 }
317
Matteo Scandolo4a036262020-08-17 15:56:13 -0700318 if !s.NeedsDhcp {
319 serviceLogger.WithFields(log.Fields{
320 "OnuId": s.Onu.ID,
321 "IntfId": s.Onu.PonPortID,
322 "OnuSn": s.Onu.Sn(),
323 "Name": s.Name,
324 "NeedsDhcp": s.NeedsDhcp,
Matteo Scandolo7f656fb2020-09-08 15:18:15 -0700325 }).Trace("Won't start DHCP as it is not required")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700326 return
327 }
328
Matteo Scandolo7f656fb2020-09-08 15:18:15 -0700329 // TODO check if the DHCP flow was received before starting auth
Matteo Scandolo4a036262020-08-17 15:56:13 -0700330
331 if err := s.DHCPState.Event("start_dhcp"); err != nil {
332 serviceLogger.WithFields(log.Fields{
333 "OnuId": s.Onu.ID,
334 "IntfId": s.Onu.PonPortID,
335 "OnuSn": s.Onu.Sn(),
336 "Name": s.Name,
337 "err": err.Error(),
338 }).Error("Can't start DHCP for this Service")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700339 }
340}
341
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700342func (s *Service) HandlePackets() {
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700343 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("Listening on Service Packet Channel")
350
351 defer func() {
352 serviceLogger.WithFields(log.Fields{
353 "OnuId": s.Onu.ID,
354 "IntfId": s.Onu.PonPortID,
355 "OnuSn": s.Onu.Sn(),
356 "GemPortId": s.GemPort,
357 "Name": s.Name,
358 }).Debug("Done Listening on Service Packet Channel")
359 }()
360
361 for msg := range s.PacketCh {
362 serviceLogger.WithFields(log.Fields{
363 "OnuId": s.Onu.ID,
364 "IntfId": s.Onu.PonPortID,
365 "OnuSn": s.Onu.Sn(),
366 "Name": s.Name,
367 "messageType": msg.Type,
Matteo Scandolo7f656fb2020-09-08 15:18:15 -0700368 }).Trace("Received message on Service Packet Channel")
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700369
370 if msg.Type == packetHandlers.EAPOL {
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700371 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 -0700372 } else if msg.Type == packetHandlers.DHCP {
Matteo Scandolo24a88c42020-09-17 14:55:28 -0700373 _ = 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 -0700374 } else if msg.Type == packetHandlers.IGMP {
375 log.Warn(hex.EncodeToString(msg.Packet.Data()))
376 _ = 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 -0700377 }
378 }
379}
380
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700381func (s *Service) HandleChannel() {
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("Listening on Service Channel")
389
390 defer func() {
391 serviceLogger.WithFields(log.Fields{
392 "OnuId": s.Onu.ID,
393 "IntfId": s.Onu.PonPortID,
394 "OnuSn": s.Onu.Sn(),
395 "GemPortId": s.GemPort,
396 "Name": s.Name,
397 }).Debug("Done Listening on Service Channel")
398 }()
399 for msg := range s.Channel {
Matteo Scandolo618a6582020-09-09 12:21:29 -0700400 switch msg.Type {
401 case StartEAPOL:
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700402 if err := s.handleEapolStart(s.Stream); err != nil {
403 serviceLogger.WithFields(log.Fields{
404 "OnuId": s.Onu.ID,
405 "IntfId": s.Onu.PonPortID,
406 "OnuSn": s.Onu.Sn(),
407 "Name": s.Name,
408 "err": err,
409 }).Error("Error while sending EapolStart packet")
410 _ = s.EapolState.Event("auth_failed")
411 }
Matteo Scandolo618a6582020-09-09 12:21:29 -0700412 case StartDHCP:
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700413 if err := s.handleDHCPStart(s.Stream); err != nil {
414 serviceLogger.WithFields(log.Fields{
415 "OnuId": s.Onu.ID,
416 "IntfId": s.Onu.PonPortID,
417 "OnuSn": s.Onu.Sn(),
418 "Name": s.Name,
419 "err": err,
420 }).Error("Error while sending DHCPDiscovery packet")
421 _ = s.DHCPState.Event("dhcp_failed")
Matteo Scandolo618a6582020-09-09 12:21:29 -0700422
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700423 }
Matteo Scandolo618a6582020-09-09 12:21:29 -0700424 case IGMPMembershipReportV2:
425 serviceLogger.WithFields(log.Fields{
426 "OnuId": s.Onu.ID,
427 "IntfId": s.Onu.PonPortID,
428 "OnuSn": s.Onu.Sn(),
429 "Name": s.Name,
430 }).Debug("Recieved IGMPMembershipReportV2 message on ONU channel")
431 _ = igmp.SendIGMPMembershipReportV2(s.Onu.PonPortID, s.Onu.ID, s.Onu.Sn(), s.Onu.PortNo, s.GemPort, s.HwAddress, s.CTag, s.UsPonCTagPriority, s.Stream)
432 case IGMPLeaveGroup:
433 serviceLogger.WithFields(log.Fields{
434 "OnuId": s.Onu.ID,
435 "IntfId": s.Onu.PonPortID,
436 "OnuSn": s.Onu.Sn(),
437 "Name": s.Name,
438 }).Debug("Recieved IGMPLeaveGroupV2 message on ONU channel")
439 _ = igmp.SendIGMPLeaveGroupV2(s.Onu.PonPortID, s.Onu.ID, s.Onu.Sn(), s.Onu.PortNo, s.GemPort, s.HwAddress, s.CTag, s.UsPonCTagPriority, s.Stream)
440 case IGMPMembershipReportV3:
441 serviceLogger.WithFields(log.Fields{
442 "OnuId": s.Onu.ID,
443 "IntfId": s.Onu.PonPortID,
444 "OnuSn": s.Onu.Sn(),
445 "Name": s.Name,
446 }).Debug("Recieved IGMPMembershipReportV3 message on ONU channel")
447 _ = igmp.SendIGMPMembershipReportV3(s.Onu.PonPortID, s.Onu.ID, s.Onu.Sn(), s.Onu.PortNo, s.GemPort, s.HwAddress, s.CTag, s.UsPonCTagPriority, s.Stream)
448
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700449 }
450 }
451}
452
453func (s *Service) Initialize(stream bbsimTypes.Stream) {
454 if err := s.InternalState.Event("initialized", stream); err != nil {
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700455 serviceLogger.WithFields(log.Fields{
456 "OnuId": s.Onu.ID,
457 "IntfId": s.Onu.PonPortID,
458 "OnuSn": s.Onu.Sn(),
459 "Name": s.Name,
460 "Err": err,
461 }).Error("Cannot initialize service")
462 }
463}
464
465func (s *Service) Disable() {
466 if err := s.InternalState.Event("disabled"); err != nil {
467 serviceLogger.WithFields(log.Fields{
468 "OnuId": s.Onu.ID,
469 "IntfId": s.Onu.PonPortID,
470 "OnuSn": s.Onu.Sn(),
471 "Name": s.Name,
472 "Err": err,
473 }).Error("Cannot disable service")
474 }
475}
476
Matteo Scandolo4a036262020-08-17 15:56:13 -0700477func (s *Service) handleEapolStart(stream bbsimTypes.Stream) error {
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700478 // TODO fail Auth if it does not succeed in 30 seconds
Matteo Scandolo4a036262020-08-17 15:56:13 -0700479 serviceLogger.WithFields(log.Fields{
480 "OnuId": s.Onu.ID,
481 "IntfId": s.Onu.PonPortID,
482 "OnuSn": s.Onu.Sn(),
483 "GemPort": s.GemPort,
484 "Name": s.Name,
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700485 }).Trace("handleEapolStart")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700486
487 if err := eapol.SendEapStart(s.Onu.ID, s.Onu.PonPortID, s.Onu.Sn(), s.Onu.PortNo,
488 s.HwAddress, s.GemPort, s.EapolState, stream); err != nil {
489 serviceLogger.WithFields(log.Fields{
490 "OnuId": s.Onu.ID,
491 "IntfId": s.Onu.PonPortID,
492 "OnuSn": s.Onu.Sn(),
493 "GemPort": s.GemPort,
494 "Name": s.Name,
495 }).Error("handleEapolStart")
496 return err
497 }
498 return nil
499}
500
501func (s *Service) handleDHCPStart(stream bbsimTypes.Stream) error {
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700502 // TODO fail DHCP if it does not succeed in 30 seconds
Matteo Scandolo4a036262020-08-17 15:56:13 -0700503 serviceLogger.WithFields(log.Fields{
504 "OnuId": s.Onu.ID,
505 "IntfId": s.Onu.PonPortID,
506 "OnuSn": s.Onu.Sn(),
507 "Name": s.Name,
508 "GemPortId": s.GemPort,
509 }).Debugf("HandleDHCPStart")
510
Matteo Scandolo24a88c42020-09-17 14:55:28 -0700511 if err := dhcp.SendDHCPDiscovery(s.Onu.PonPortID, s.Onu.ID, s.Name, int(s.CTag), s.GemPort,
Matteo Scandolo8d281372020-09-03 16:23:37 -0700512 s.Onu.Sn(), s.Onu.PortNo, s.DHCPState, s.HwAddress, s.UsPonCTagPriority, stream); err != nil {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700513 serviceLogger.WithFields(log.Fields{
514 "OnuId": s.Onu.ID,
515 "IntfId": s.Onu.PonPortID,
516 "OnuSn": s.Onu.Sn(),
517 "Name": s.Name,
518 "GemPortId": s.GemPort,
519 }).Error("HandleDHCPStart")
520 return err
521 }
522 return nil
523}
524
Matteo Scandolo4a036262020-08-17 15:56:13 -0700525func (s *Service) logStateChange(stateMachine string, src string, dst string) {
526 serviceLogger.WithFields(log.Fields{
527 "OnuId": s.Onu.ID,
528 "IntfId": s.Onu.PonPortID,
529 "OnuSn": s.Onu.Sn(),
530 "Name": s.Name,
531 }).Debugf("Changing Service.%s InternalState from %s to %s", stateMachine, src, dst)
532}