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