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