Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package devices |
| 18 | |
| 19 | import ( |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 20 | "encoding/hex" |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 21 | "fmt" |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame^] | 22 | "net" |
| 23 | "time" |
| 24 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 25 | "github.com/looplab/fsm" |
| 26 | "github.com/opencord/bbsim/internal/bbsim/packetHandlers" |
| 27 | "github.com/opencord/bbsim/internal/bbsim/responders/dhcp" |
| 28 | "github.com/opencord/bbsim/internal/bbsim/responders/eapol" |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 29 | "github.com/opencord/bbsim/internal/bbsim/responders/igmp" |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 30 | bbsimTypes "github.com/opencord/bbsim/internal/bbsim/types" |
Matteo Scandolo | 76c3ff6 | 2020-09-24 18:03:01 -0700 | [diff] [blame] | 31 | "github.com/opencord/bbsim/internal/common" |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 32 | log "github.com/sirupsen/logrus" |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | var serviceLogger = log.WithFields(log.Fields{ |
| 36 | "module": "SERVICE", |
| 37 | }) |
| 38 | |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 39 | // time to wait before fail EAPOL/DHCP |
| 40 | // (it's a variable and not a constant so it can be overridden in the tests) |
Matteo Scandolo | 24a88c4 | 2020-09-17 14:55:28 -0700 | [diff] [blame] | 41 | var eapolWaitTime = 60 * time.Second |
| 42 | var dhcpWaitTime = 60 * time.Second |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 43 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 44 | const ( |
| 45 | ServiceStateCreated = "created" |
| 46 | ServiceStateInitialized = "initialized" |
| 47 | ServiceStateDisabled = "disabled" |
| 48 | |
| 49 | ServiceTxInitialize = "initialize" |
| 50 | ServiceTxDisable = "disable" |
| 51 | ) |
| 52 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 53 | type ServiceIf interface { |
Matteo Scandolo | bd875b3 | 2020-09-18 17:46:31 -0700 | [diff] [blame] | 54 | HandlePackets() // start listening on the PacketCh |
| 55 | HandleAuth() // Sends the EapoStart packet |
| 56 | HandleDhcp(pbit uint8, cTag int) // Sends the DHCPDiscover packet |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 57 | |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 58 | Initialize(stream bbsimTypes.Stream) |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 59 | UpdateStream(stream bbsimTypes.Stream) |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 60 | Disable() |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | type Service struct { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 64 | Id uint32 |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 65 | Name string |
| 66 | HwAddress net.HardwareAddr |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 67 | UniPort *UniPort |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 68 | CTag int |
| 69 | STag int |
| 70 | NeedsEapol bool |
| 71 | NeedsDhcp bool |
| 72 | NeedsIgmp bool |
| 73 | TechnologyProfileID int |
| 74 | UniTagMatch int |
| 75 | ConfigureMacAddress bool |
Matteo Scandolo | 8d28137 | 2020-09-03 16:23:37 -0700 | [diff] [blame] | 76 | UsPonCTagPriority uint8 |
| 77 | UsPonSTagPriority uint8 |
| 78 | DsPonCTagPriority uint8 |
| 79 | DsPonSTagPriority uint8 |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 80 | |
| 81 | // state |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 82 | GemPort uint32 |
| 83 | InternalState *fsm.FSM |
| 84 | EapolState *fsm.FSM |
| 85 | DHCPState *fsm.FSM |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 86 | IGMPState *fsm.FSM |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 87 | Channel chan bbsimTypes.Message // drive Service lifecycle |
| 88 | PacketCh chan bbsimTypes.OnuPacketMessage // handle packets |
| 89 | Stream bbsimTypes.Stream // the gRPC stream to communicate with the adapter, created in the initialize transition |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 92 | func NewService(id uint32, name string, hwAddress net.HardwareAddr, uni *UniPort, cTag int, sTag int, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 93 | needsEapol bool, needsDchp bool, needsIgmp bool, tpID int, uniTagMatch int, configMacAddress bool, |
Matteo Scandolo | 8d28137 | 2020-09-03 16:23:37 -0700 | [diff] [blame] | 94 | usPonCTagPriority uint8, usPonSTagPriority uint8, dsPonCTagPriority uint8, dsPonSTagPriority uint8) (*Service, error) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 95 | |
| 96 | service := Service{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 97 | Id: id, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 98 | Name: name, |
| 99 | HwAddress: hwAddress, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 100 | UniPort: uni, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 101 | CTag: cTag, |
| 102 | STag: sTag, |
| 103 | NeedsEapol: needsEapol, |
| 104 | NeedsDhcp: needsDchp, |
| 105 | NeedsIgmp: needsIgmp, |
| 106 | TechnologyProfileID: tpID, |
| 107 | UniTagMatch: uniTagMatch, |
| 108 | ConfigureMacAddress: configMacAddress, |
| 109 | UsPonCTagPriority: usPonCTagPriority, |
| 110 | UsPonSTagPriority: usPonSTagPriority, |
| 111 | DsPonCTagPriority: dsPonCTagPriority, |
| 112 | DsPonSTagPriority: dsPonSTagPriority, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 115 | service.InternalState = fsm.NewFSM( |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 116 | ServiceStateCreated, |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 117 | fsm.Events{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 118 | {Name: ServiceTxInitialize, Src: []string{ServiceStateCreated, ServiceStateDisabled}, Dst: ServiceStateInitialized}, |
| 119 | {Name: ServiceTxDisable, Src: []string{ServiceStateInitialized}, Dst: ServiceStateDisabled}, |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 120 | }, |
| 121 | fsm.Callbacks{ |
| 122 | "enter_state": func(e *fsm.Event) { |
| 123 | service.logStateChange("InternalState", e.Src, e.Dst) |
| 124 | }, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 125 | fmt.Sprintf("enter_%s", ServiceStateInitialized): func(e *fsm.Event) { |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 126 | |
| 127 | stream, ok := e.Args[0].(bbsimTypes.Stream) |
| 128 | if !ok { |
| 129 | serviceLogger.Fatal("initialize invoke with wrong arguments") |
| 130 | } |
| 131 | |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 132 | service.UpdateStream(stream) |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 133 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 134 | service.PacketCh = make(chan bbsimTypes.OnuPacketMessage) |
| 135 | service.Channel = make(chan bbsimTypes.Message) |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 136 | |
| 137 | go service.HandlePackets() |
| 138 | go service.HandleChannel() |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 139 | }, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 140 | fmt.Sprintf("enter_%s", ServiceStateDisabled): func(e *fsm.Event) { |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 141 | // reset the state machines |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame^] | 142 | service.EapolState.SetState(eapol.StateCreated) |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 143 | service.DHCPState.SetState("created") |
| 144 | |
| 145 | // stop listening for packets |
| 146 | close(service.PacketCh) |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 147 | close(service.Channel) |
| 148 | |
| 149 | service.PacketCh = nil |
| 150 | service.Channel = nil |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 151 | }, |
| 152 | }, |
| 153 | ) |
| 154 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 155 | service.EapolState = fsm.NewFSM( |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame^] | 156 | eapol.StateCreated, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 157 | fsm.Events{ |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame^] | 158 | {Name: eapol.EventStartAuth, Src: []string{eapol.StateCreated, eapol.StateResponseSuccessReceived, eapol.StateAuthFailed}, Dst: eapol.StateAuthStarted}, |
| 159 | {Name: eapol.EventStartSent, Src: []string{eapol.StateAuthStarted}, Dst: eapol.StateStartSent}, |
| 160 | {Name: eapol.EventResponseIdentitySent, Src: []string{eapol.StateStartSent}, Dst: eapol.StateResponseIdentitySent}, |
| 161 | {Name: eapol.EventResponseChallengeSent, Src: []string{eapol.StateResponseIdentitySent}, Dst: eapol.StateResponseChallengeSent}, |
| 162 | {Name: eapol.EventResponseSuccessReceived, Src: []string{eapol.StateResponseChallengeSent}, Dst: eapol.StateResponseSuccessReceived}, |
| 163 | {Name: eapol.EventAuthFailed, Src: []string{eapol.StateAuthStarted, eapol.StateStartSent, eapol.StateResponseIdentitySent, eapol.StateResponseChallengeSent}, Dst: eapol.StateAuthFailed}, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 164 | }, |
| 165 | fsm.Callbacks{ |
| 166 | "enter_state": func(e *fsm.Event) { |
| 167 | service.logStateChange("EapolState", e.Src, e.Dst) |
| 168 | }, |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame^] | 169 | fmt.Sprintf("before_%s", eapol.EventStartAuth): func(e *fsm.Event) { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 170 | msg := bbsimTypes.Message{ |
| 171 | Type: bbsimTypes.StartEAPOL, |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 172 | } |
| 173 | service.Channel <- msg |
| 174 | }, |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame^] | 175 | fmt.Sprintf("enter_%s", eapol.StateAuthStarted): func(e *fsm.Event) { |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 176 | go func() { |
| 177 | |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 178 | for { |
| 179 | select { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 180 | case <-service.UniPort.Onu.PonPort.Olt.enableContext.Done(): |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 181 | // if the OLT is disabled, then cancel |
Matteo Scandolo | 6e7afb0 | 2020-09-24 11:32:18 -0700 | [diff] [blame] | 182 | return |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 183 | case <-time.After(eapolWaitTime): |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame^] | 184 | if service.EapolState.Current() != eapol.StateResponseSuccessReceived { |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 185 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 186 | "OnuId": service.UniPort.Onu.ID, |
| 187 | "IntfId": service.UniPort.Onu.PonPortID, |
| 188 | "OnuSn": service.UniPort.Onu.Sn(), |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 189 | "Name": service.Name, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 190 | "PortNo": service.UniPort.PortNo, |
| 191 | "UniId": service.UniPort.ID, |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 192 | "EapolState": service.EapolState.Current(), |
| 193 | }).Warn("EAPOL failed, resetting EAPOL State") |
Matteo Scandolo | 76c3ff6 | 2020-09-24 18:03:01 -0700 | [diff] [blame] | 194 | |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame^] | 195 | _ = service.EapolState.Event(eapol.EventAuthFailed) |
Matteo Scandolo | 76c3ff6 | 2020-09-24 18:03:01 -0700 | [diff] [blame] | 196 | if common.Config.BBSim.AuthRetry { |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame^] | 197 | _ = service.EapolState.Event(eapol.EventStartAuth) |
Matteo Scandolo | 76c3ff6 | 2020-09-24 18:03:01 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Matteo Scandolo | 6e7afb0 | 2020-09-24 11:32:18 -0700 | [diff] [blame] | 200 | return |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
| 204 | } |
| 205 | }() |
| 206 | }, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 207 | }, |
| 208 | ) |
| 209 | |
| 210 | service.DHCPState = fsm.NewFSM( |
| 211 | "created", |
| 212 | fsm.Events{ |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 213 | {Name: "start_dhcp", Src: []string{"created", "dhcp_ack_received", "dhcp_failed"}, Dst: "dhcp_started"}, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 214 | {Name: "dhcp_discovery_sent", Src: []string{"dhcp_started"}, Dst: "dhcp_discovery_sent"}, |
| 215 | {Name: "dhcp_request_sent", Src: []string{"dhcp_discovery_sent"}, Dst: "dhcp_request_sent"}, |
| 216 | {Name: "dhcp_ack_received", Src: []string{"dhcp_request_sent"}, Dst: "dhcp_ack_received"}, |
| 217 | {Name: "dhcp_failed", Src: []string{"dhcp_started", "dhcp_discovery_sent", "dhcp_request_sent"}, Dst: "dhcp_failed"}, |
| 218 | }, |
| 219 | fsm.Callbacks{ |
| 220 | "enter_state": func(e *fsm.Event) { |
| 221 | service.logStateChange("DHCPState", e.Src, e.Dst) |
| 222 | }, |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 223 | "before_start_dhcp": func(e *fsm.Event) { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 224 | msg := bbsimTypes.Message{ |
| 225 | Type: bbsimTypes.StartDHCP, |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 226 | } |
| 227 | service.Channel <- msg |
| 228 | }, |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 229 | "enter_dhcp_started": func(e *fsm.Event) { |
| 230 | go func() { |
| 231 | |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 232 | for { |
| 233 | select { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 234 | case <-service.UniPort.Onu.PonPort.Olt.enableContext.Done(): |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 235 | // if the OLT is disabled, then cancel |
Matteo Scandolo | 6e7afb0 | 2020-09-24 11:32:18 -0700 | [diff] [blame] | 236 | return |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 237 | case <-time.After(dhcpWaitTime): |
| 238 | if service.DHCPState.Current() != "dhcp_ack_received" { |
| 239 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 240 | "OnuId": service.UniPort.Onu.ID, |
| 241 | "IntfId": service.UniPort.Onu.PonPortID, |
| 242 | "OnuSn": service.UniPort.Onu.Sn(), |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 243 | "Name": service.Name, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 244 | "PortNo": service.UniPort.PortNo, |
| 245 | "UniId": service.UniPort.ID, |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 246 | "DHCPState": service.DHCPState.Current(), |
| 247 | }).Warn("DHCP failed, resetting DHCP State") |
Matteo Scandolo | 76c3ff6 | 2020-09-24 18:03:01 -0700 | [diff] [blame] | 248 | |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 249 | _ = service.DHCPState.Event("dhcp_failed") |
Matteo Scandolo | 76c3ff6 | 2020-09-24 18:03:01 -0700 | [diff] [blame] | 250 | if common.Config.BBSim.DhcpRetry { |
| 251 | _ = service.DHCPState.Event("start_dhcp") |
| 252 | } |
| 253 | |
Matteo Scandolo | 6e7afb0 | 2020-09-24 11:32:18 -0700 | [diff] [blame] | 254 | return |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
| 258 | } |
| 259 | }() |
| 260 | }, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 261 | }, |
| 262 | ) |
| 263 | |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 264 | service.IGMPState = fsm.NewFSM( |
| 265 | "created", |
| 266 | fsm.Events{ |
| 267 | {Name: "igmp_join_start", Src: []string{"created", "igmp_left", "igmp_join_error", "igmp_join_started"}, Dst: "igmp_join_started"}, |
| 268 | {Name: "igmp_join_startv3", Src: []string{"igmp_left", "igmp_join_error", "igmp_join_started"}, Dst: "igmp_join_started"}, |
| 269 | {Name: "igmp_join_error", Src: []string{"igmp_join_started"}, Dst: "igmp_join_error"}, |
| 270 | {Name: "igmp_leave", Src: []string{"igmp_join_started"}, Dst: "igmp_left"}, |
| 271 | }, |
| 272 | fsm.Callbacks{ |
| 273 | "igmp_join_start": func(e *fsm.Event) { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 274 | igmpInfo, _ := e.Args[0].(bbsimTypes.IgmpMessage) |
| 275 | msg := bbsimTypes.Message{ |
| 276 | Type: bbsimTypes.IGMPMembershipReportV2, |
| 277 | Data: bbsimTypes.IgmpMessage{ |
Onur Kalinagac | 9f9faca | 2021-01-21 14:04:34 +0000 | [diff] [blame] | 278 | GroupAddress: igmpInfo.GroupAddress, |
| 279 | }, |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 280 | } |
| 281 | service.Channel <- msg |
| 282 | }, |
| 283 | "igmp_leave": func(e *fsm.Event) { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 284 | igmpInfo, _ := e.Args[0].(bbsimTypes.IgmpMessage) |
| 285 | msg := bbsimTypes.Message{ |
| 286 | Type: bbsimTypes.IGMPLeaveGroup, |
| 287 | Data: bbsimTypes.IgmpMessage{ |
Onur Kalinagac | 9f9faca | 2021-01-21 14:04:34 +0000 | [diff] [blame] | 288 | GroupAddress: igmpInfo.GroupAddress, |
| 289 | }, |
| 290 | } |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 291 | service.Channel <- msg |
| 292 | }, |
| 293 | "igmp_join_startv3": func(e *fsm.Event) { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 294 | igmpInfo, _ := e.Args[0].(bbsimTypes.IgmpMessage) |
| 295 | msg := bbsimTypes.Message{ |
| 296 | Type: bbsimTypes.IGMPMembershipReportV3, |
| 297 | Data: bbsimTypes.IgmpMessage{ |
Onur Kalinagac | 9f9faca | 2021-01-21 14:04:34 +0000 | [diff] [blame] | 298 | GroupAddress: igmpInfo.GroupAddress, |
| 299 | }, |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 300 | } |
| 301 | service.Channel <- msg |
| 302 | }, |
| 303 | }, |
| 304 | ) |
| 305 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 306 | return &service, nil |
| 307 | } |
| 308 | |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 309 | func (s *Service) UpdateStream(stream bbsimTypes.Stream) { |
| 310 | s.Stream = stream |
| 311 | } |
| 312 | |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 313 | // HandleAuth is used to start EAPOL for a particular Service when the corresponding flow is received |
| 314 | func (s *Service) HandleAuth() { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 315 | |
| 316 | if !s.NeedsEapol { |
| 317 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 318 | "OnuId": s.UniPort.Onu.ID, |
| 319 | "IntfId": s.UniPort.Onu.PonPortID, |
| 320 | "OnuSn": s.UniPort.Onu.Sn(), |
| 321 | "PortNo": s.UniPort.PortNo, |
| 322 | "UniId": s.UniPort.ID, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 323 | "Name": s.Name, |
| 324 | "NeedsEapol": s.NeedsEapol, |
| 325 | }).Debug("Won't start authentication as EAPOL is not required") |
| 326 | return |
| 327 | } |
| 328 | |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame^] | 329 | if err := s.EapolState.Event(eapol.EventStartAuth); err != nil { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 330 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 331 | "OnuId": s.UniPort.Onu.ID, |
| 332 | "IntfId": s.UniPort.Onu.PonPortID, |
| 333 | "OnuSn": s.UniPort.Onu.Sn(), |
| 334 | "PortNo": s.UniPort.PortNo, |
| 335 | "UniId": s.UniPort.ID, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 336 | "Name": s.Name, |
| 337 | "err": err.Error(), |
| 338 | }).Error("Can't start auth for this Service") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 342 | // HandleDhcp is used to start DHCP for a particular Service when the corresponding flow is received |
Matteo Scandolo | bd875b3 | 2020-09-18 17:46:31 -0700 | [diff] [blame] | 343 | func (s *Service) HandleDhcp(pbit uint8, cTag int) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 344 | |
Matteo Scandolo | bd875b3 | 2020-09-18 17:46:31 -0700 | [diff] [blame] | 345 | if s.CTag != cTag || (s.UsPonCTagPriority != pbit && pbit != 255) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 346 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 347 | "OnuId": s.UniPort.Onu.ID, |
| 348 | "IntfId": s.UniPort.Onu.PonPortID, |
| 349 | "OnuSn": s.UniPort.Onu.Sn(), |
| 350 | "PortNo": s.UniPort.PortNo, |
| 351 | "UniId": s.UniPort.ID, |
| 352 | "Name": s.Name, |
| 353 | "Service.CTag": s.CTag, |
| 354 | "Service.UsPonCTagPriority": s.UsPonCTagPriority, |
| 355 | "cTag": cTag, |
| 356 | "pbit": pbit, |
| 357 | }).Debug("DHCP flow is not for this service, ignoring") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 358 | return |
| 359 | } |
| 360 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 361 | if !s.NeedsDhcp { |
| 362 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 363 | "OnuId": s.UniPort.Onu.ID, |
| 364 | "IntfId": s.UniPort.Onu.PonPortID, |
| 365 | "OnuSn": s.UniPort.Onu.Sn(), |
| 366 | "PortNo": s.UniPort.PortNo, |
| 367 | "UniId": s.UniPort.ID, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 368 | "Name": s.Name, |
| 369 | "NeedsDhcp": s.NeedsDhcp, |
Matteo Scandolo | 7f656fb | 2020-09-08 15:18:15 -0700 | [diff] [blame] | 370 | }).Trace("Won't start DHCP as it is not required") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 371 | return |
| 372 | } |
| 373 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 374 | // TODO check if the DHCP flow was received before starting DHCP |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 375 | |
| 376 | if err := s.DHCPState.Event("start_dhcp"); err != nil { |
| 377 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 378 | "OnuId": s.UniPort.Onu.ID, |
| 379 | "IntfId": s.UniPort.Onu.PonPortID, |
| 380 | "OnuSn": s.UniPort.Onu.Sn(), |
| 381 | "PortNo": s.UniPort.PortNo, |
| 382 | "UniId": s.UniPort.ID, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 383 | "Name": s.Name, |
| 384 | "err": err.Error(), |
| 385 | }).Error("Can't start DHCP for this Service") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 389 | func (s *Service) HandlePackets() { |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 390 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 391 | "OnuId": s.UniPort.Onu.ID, |
| 392 | "IntfId": s.UniPort.Onu.PonPortID, |
| 393 | "OnuSn": s.UniPort.Onu.Sn(), |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 394 | "GemPortId": s.GemPort, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 395 | "PortNo": s.UniPort.PortNo, |
| 396 | "UniId": s.UniPort.ID, |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 397 | "Name": s.Name, |
| 398 | }).Debug("Listening on Service Packet Channel") |
| 399 | |
| 400 | defer func() { |
| 401 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 402 | "OnuId": s.UniPort.Onu.ID, |
| 403 | "IntfId": s.UniPort.Onu.PonPortID, |
| 404 | "OnuSn": s.UniPort.Onu.Sn(), |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 405 | "GemPortId": s.GemPort, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 406 | "PortNo": s.UniPort.PortNo, |
| 407 | "UniId": s.UniPort.ID, |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 408 | "Name": s.Name, |
| 409 | }).Debug("Done Listening on Service Packet Channel") |
| 410 | }() |
| 411 | |
| 412 | for msg := range s.PacketCh { |
| 413 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 414 | "OnuId": s.UniPort.Onu.ID, |
| 415 | "IntfId": s.UniPort.Onu.PonPortID, |
| 416 | "OnuSn": s.UniPort.Onu.Sn(), |
| 417 | "GemPortId": s.GemPort, |
| 418 | "PortNo": s.UniPort.PortNo, |
| 419 | "UniId": s.UniPort.ID, |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 420 | "Name": s.Name, |
| 421 | "messageType": msg.Type, |
Matteo Scandolo | 7f656fb | 2020-09-08 15:18:15 -0700 | [diff] [blame] | 422 | }).Trace("Received message on Service Packet Channel") |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 423 | |
| 424 | if msg.Type == packetHandlers.EAPOL { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 425 | eapol.HandleNextPacket(msg.OnuId, msg.IntfId, s.GemPort, s.UniPort.Onu.Sn(), s.UniPort.PortNo, s.UniPort.ID, s.Id, s.UniPort.Onu.PonPort.Olt.ID, s.EapolState, msg.Packet, s.Stream, nil) |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 426 | } else if msg.Type == packetHandlers.DHCP { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 427 | _ = dhcp.HandleNextPacket(s.UniPort.Onu.ID, s.UniPort.Onu.PonPortID, s.Name, s.UniPort.Onu.Sn(), s.UniPort.PortNo, s.CTag, s.GemPort, s.UniPort.ID, s.HwAddress, s.DHCPState, msg.Packet, s.UsPonCTagPriority, s.Stream) |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 428 | } else if msg.Type == packetHandlers.IGMP { |
| 429 | log.Warn(hex.EncodeToString(msg.Packet.Data())) |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 430 | _ = igmp.HandleNextPacket(s.UniPort.Onu.PonPortID, s.UniPort.Onu.ID, s.UniPort.Onu.Sn(), s.UniPort.PortNo, s.GemPort, s.HwAddress, msg.Packet, s.CTag, s.UsPonCTagPriority, s.Stream) |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | } |
| 434 | |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 435 | func (s *Service) HandleChannel() { |
| 436 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 437 | "OnuId": s.UniPort.Onu.ID, |
| 438 | "IntfId": s.UniPort.Onu.PonPortID, |
| 439 | "OnuSn": s.UniPort.Onu.Sn(), |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 440 | "GemPortId": s.GemPort, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 441 | "PortNo": s.UniPort.PortNo, |
| 442 | "UniId": s.UniPort.ID, |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 443 | "Name": s.Name, |
| 444 | }).Debug("Listening on Service Channel") |
| 445 | |
| 446 | defer func() { |
| 447 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 448 | "OnuId": s.UniPort.Onu.ID, |
| 449 | "IntfId": s.UniPort.Onu.PonPortID, |
| 450 | "OnuSn": s.UniPort.Onu.Sn(), |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 451 | "GemPortId": s.GemPort, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 452 | "PortNo": s.UniPort.PortNo, |
| 453 | "UniId": s.UniPort.ID, |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 454 | "Name": s.Name, |
| 455 | }).Debug("Done Listening on Service Channel") |
| 456 | }() |
| 457 | for msg := range s.Channel { |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 458 | switch msg.Type { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 459 | case bbsimTypes.StartEAPOL: |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 460 | if err := s.handleEapolStart(s.Stream); err != nil { |
| 461 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 462 | "OnuId": s.UniPort.Onu.ID, |
| 463 | "IntfId": s.UniPort.Onu.PonPortID, |
| 464 | "OnuSn": s.UniPort.Onu.Sn(), |
| 465 | "GemPortId": s.GemPort, |
| 466 | "PortNo": s.UniPort.PortNo, |
| 467 | "UniId": s.UniPort.ID, |
| 468 | "Name": s.Name, |
| 469 | "err": err, |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 470 | }).Error("Error while sending EapolStart packet") |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame^] | 471 | _ = s.EapolState.Event(eapol.EventAuthFailed) |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 472 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 473 | case bbsimTypes.StartDHCP: |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 474 | if err := s.handleDHCPStart(s.Stream); err != nil { |
| 475 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 476 | "OnuId": s.UniPort.Onu.ID, |
| 477 | "IntfId": s.UniPort.Onu.PonPortID, |
| 478 | "OnuSn": s.UniPort.Onu.Sn(), |
| 479 | "GemPortId": s.GemPort, |
| 480 | "PortNo": s.UniPort.PortNo, |
| 481 | "UniId": s.UniPort.ID, |
| 482 | "Name": s.Name, |
| 483 | "err": err, |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 484 | }).Error("Error while sending DHCPDiscovery packet") |
| 485 | _ = s.DHCPState.Event("dhcp_failed") |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 486 | |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 487 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 488 | case bbsimTypes.IGMPMembershipReportV2: |
| 489 | igmpInfo, _ := msg.Data.(bbsimTypes.IgmpMessage) |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 490 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 491 | "OnuId": s.UniPort.Onu.ID, |
| 492 | "IntfId": s.UniPort.Onu.PonPortID, |
| 493 | "OnuSn": s.UniPort.Onu.Sn(), |
| 494 | "GemPortId": s.GemPort, |
| 495 | "PortNo": s.UniPort.PortNo, |
| 496 | "UniId": s.UniPort.ID, |
| 497 | "Name": s.Name, |
Onur Kalinagac | 9f9faca | 2021-01-21 14:04:34 +0000 | [diff] [blame] | 498 | }).Debug("Received IGMPMembershipReportV2 message on ONU channel") |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 499 | _ = igmp.SendIGMPMembershipReportV2(s.UniPort.Onu.PonPortID, s.UniPort.Onu.ID, s.UniPort.Onu.Sn(), s.UniPort.PortNo, s.GemPort, s.HwAddress, s.CTag, s.UsPonCTagPriority, s.Stream, igmpInfo.GroupAddress) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 500 | case bbsimTypes.IGMPLeaveGroup: |
| 501 | igmpInfo, _ := msg.Data.(bbsimTypes.IgmpMessage) |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 502 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 503 | "OnuId": s.UniPort.Onu.ID, |
| 504 | "IntfId": s.UniPort.Onu.PonPortID, |
| 505 | "OnuSn": s.UniPort.Onu.Sn(), |
| 506 | "GemPortId": s.GemPort, |
| 507 | "PortNo": s.UniPort.PortNo, |
| 508 | "UniId": s.UniPort.ID, |
| 509 | "Name": s.Name, |
Onur Kalinagac | 9f9faca | 2021-01-21 14:04:34 +0000 | [diff] [blame] | 510 | }).Debug("Received IGMPLeaveGroupV2 message on ONU channel") |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 511 | _ = igmp.SendIGMPLeaveGroupV2(s.UniPort.Onu.PonPortID, s.UniPort.Onu.ID, s.UniPort.Onu.Sn(), s.UniPort.PortNo, s.GemPort, s.HwAddress, s.CTag, s.UsPonCTagPriority, s.Stream, igmpInfo.GroupAddress) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 512 | case bbsimTypes.IGMPMembershipReportV3: |
| 513 | igmpInfo, _ := msg.Data.(bbsimTypes.IgmpMessage) |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 514 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 515 | "OnuId": s.UniPort.Onu.ID, |
| 516 | "IntfId": s.UniPort.Onu.PonPortID, |
| 517 | "OnuSn": s.UniPort.Onu.Sn(), |
| 518 | "GemPortId": s.GemPort, |
| 519 | "PortNo": s.UniPort.PortNo, |
| 520 | "UniId": s.UniPort.ID, |
| 521 | "Name": s.Name, |
Onur Kalinagac | 9f9faca | 2021-01-21 14:04:34 +0000 | [diff] [blame] | 522 | }).Debug("Received IGMPMembershipReportV3 message on ONU channel") |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 523 | _ = igmp.SendIGMPMembershipReportV3(s.UniPort.Onu.PonPortID, s.UniPort.Onu.ID, s.UniPort.Onu.Sn(), s.UniPort.PortNo, s.GemPort, s.HwAddress, s.CTag, s.UsPonCTagPriority, s.Stream, igmpInfo.GroupAddress) |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 524 | |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | func (s *Service) Initialize(stream bbsimTypes.Stream) { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 530 | if err := s.InternalState.Event(ServiceTxInitialize, stream); err != nil { |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 531 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 532 | "OnuId": s.UniPort.Onu.ID, |
| 533 | "IntfId": s.UniPort.Onu.PonPortID, |
| 534 | "OnuSn": s.UniPort.Onu.Sn(), |
| 535 | "GemPortId": s.GemPort, |
| 536 | "PortNo": s.UniPort.PortNo, |
| 537 | "UniId": s.UniPort.ID, |
| 538 | "Name": s.Name, |
| 539 | "Err": err, |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 540 | }).Error("Cannot initialize service") |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | func (s *Service) Disable() { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 545 | if err := s.InternalState.Event(ServiceTxDisable); err != nil { |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 546 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 547 | "OnuId": s.UniPort.Onu.ID, |
| 548 | "IntfId": s.UniPort.Onu.PonPortID, |
| 549 | "OnuSn": s.UniPort.Onu.Sn(), |
| 550 | "GemPortId": s.GemPort, |
| 551 | "PortNo": s.UniPort.PortNo, |
| 552 | "UniId": s.UniPort.ID, |
| 553 | "Name": s.Name, |
| 554 | "Err": err, |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 555 | }).Error("Cannot disable service") |
| 556 | } |
| 557 | } |
| 558 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 559 | func (s *Service) handleEapolStart(stream bbsimTypes.Stream) error { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 560 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 561 | "OnuId": s.UniPort.Onu.ID, |
| 562 | "IntfId": s.UniPort.Onu.PonPortID, |
| 563 | "OnuSn": s.UniPort.Onu.Sn(), |
| 564 | "GemPortId": s.GemPort, |
| 565 | "PortNo": s.UniPort.PortNo, |
| 566 | "UniId": s.UniPort.ID, |
| 567 | "GemPort": s.GemPort, |
| 568 | "Name": s.Name, |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 569 | }).Trace("handleEapolStart") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 570 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 571 | if err := eapol.SendEapStart(s.UniPort.Onu.ID, s.UniPort.Onu.PonPortID, s.UniPort.Onu.Sn(), s.UniPort.PortNo, |
| 572 | s.HwAddress, s.GemPort, s.UniPort.ID, s.EapolState, stream); err != nil { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 573 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 574 | "OnuId": s.UniPort.Onu.ID, |
| 575 | "IntfId": s.UniPort.Onu.PonPortID, |
| 576 | "OnuSn": s.UniPort.Onu.Sn(), |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 577 | "GemPort": s.GemPort, |
| 578 | "Name": s.Name, |
| 579 | }).Error("handleEapolStart") |
| 580 | return err |
| 581 | } |
| 582 | return nil |
| 583 | } |
| 584 | |
| 585 | func (s *Service) handleDHCPStart(stream bbsimTypes.Stream) error { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 586 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 587 | "OnuId": s.UniPort.Onu.ID, |
| 588 | "IntfId": s.UniPort.Onu.PonPortID, |
| 589 | "OnuSn": s.UniPort.Onu.Sn(), |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 590 | "Name": s.Name, |
| 591 | "GemPortId": s.GemPort, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 592 | "PortNo": s.UniPort.PortNo, |
| 593 | "UniId": s.UniPort.ID, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 594 | }).Debugf("HandleDHCPStart") |
| 595 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 596 | if err := dhcp.SendDHCPDiscovery(s.UniPort.Onu.PonPortID, s.UniPort.Onu.ID, s.Name, int(s.CTag), s.GemPort, |
| 597 | s.UniPort.Onu.Sn(), s.UniPort.PortNo, s.UniPort.ID, s.DHCPState, s.HwAddress, s.UsPonCTagPriority, stream); err != nil { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 598 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 599 | "OnuId": s.UniPort.Onu.ID, |
| 600 | "IntfId": s.UniPort.Onu.PonPortID, |
| 601 | "OnuSn": s.UniPort.Onu.Sn(), |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 602 | "Name": s.Name, |
| 603 | "GemPortId": s.GemPort, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 604 | "PortNo": s.UniPort.PortNo, |
| 605 | "UniId": s.UniPort.ID, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 606 | }).Error("HandleDHCPStart") |
| 607 | return err |
| 608 | } |
| 609 | return nil |
| 610 | } |
| 611 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 612 | func (s *Service) logStateChange(stateMachine string, src string, dst string) { |
| 613 | serviceLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 614 | "OnuId": s.UniPort.Onu.ID, |
| 615 | "IntfId": s.UniPort.Onu.PonPortID, |
| 616 | "OnuSn": s.UniPort.Onu.Sn(), |
| 617 | "GemPortId": s.GemPort, |
| 618 | "PortNo": s.UniPort.PortNo, |
| 619 | "UniId": s.UniPort.ID, |
| 620 | "Name": s.Name, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 621 | }).Debugf("Changing Service.%s InternalState from %s to %s", stateMachine, src, dst) |
| 622 | } |