Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -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 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 17 | package devices |
| 18 | |
| 19 | import ( |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 20 | "context" |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 21 | "fmt" |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 22 | "github.com/cboling/omci" |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 23 | "github.com/google/gopacket/layers" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 24 | "github.com/looplab/fsm" |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 25 | "github.com/opencord/bbsim/internal/bbsim/packetHandlers" |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 26 | "github.com/opencord/bbsim/internal/bbsim/responders/dhcp" |
| 27 | "github.com/opencord/bbsim/internal/bbsim/responders/eapol" |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 28 | "github.com/opencord/bbsim/internal/common" |
| 29 | omcilib "github.com/opencord/bbsim/internal/common/omci" |
| 30 | omcisim "github.com/opencord/omci-sim" |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 31 | "github.com/opencord/voltha-protos/go/openolt" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 32 | log "github.com/sirupsen/logrus" |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 33 | "net" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 34 | ) |
| 35 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 36 | var onuLogger = log.WithFields(log.Fields{ |
| 37 | "module": "ONU", |
| 38 | }) |
| 39 | |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 40 | type Onu struct { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 41 | ID uint32 |
| 42 | PonPortID uint32 |
| 43 | PonPort PonPort |
| 44 | STag int |
| 45 | CTag int |
| 46 | // PortNo comes with flows and it's used when sending packetIndications, |
| 47 | // There is one PortNo per UNI Port, for now we're only storing the first one |
| 48 | // FIXME add support for multiple UNIs |
| 49 | PortNo uint32 |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 50 | HwAddress net.HardwareAddr |
| 51 | InternalState *fsm.FSM |
| 52 | |
| 53 | OperState *fsm.FSM |
| 54 | SerialNumber *openolt.SerialNumber |
| 55 | |
| 56 | Channel chan Message // this Channel is to track state changes OMCI messages, EAPOL and DHCP packets |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 57 | |
| 58 | // OMCI params |
| 59 | tid uint16 |
| 60 | hpTid uint16 |
| 61 | seqNumber uint16 |
| 62 | HasGemPort bool |
| 63 | |
| 64 | DoneChannel chan bool // this channel is used to signal once the onu is complete (when the struct is used by BBR) |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | func (o Onu) Sn() string { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 68 | return common.OnuSnToString(o.SerialNumber) |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 71 | func CreateONU(olt OltDevice, pon PonPort, id uint32, sTag int, cTag int) *Onu { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 72 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 73 | o := Onu{ |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 74 | ID: id, |
| 75 | PonPortID: pon.ID, |
| 76 | PonPort: pon, |
| 77 | STag: sTag, |
| 78 | CTag: cTag, |
| 79 | HwAddress: net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, byte(pon.ID), byte(id)}, |
| 80 | PortNo: 0, |
| 81 | Channel: make(chan Message, 2048), |
| 82 | tid: 0x1, |
| 83 | hpTid: 0x8000, |
| 84 | seqNumber: 0, |
| 85 | DoneChannel: make(chan bool, 1), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 86 | } |
| 87 | o.SerialNumber = o.NewSN(olt.ID, pon.ID, o.ID) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 88 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 89 | // NOTE this state machine is used to track the operational |
| 90 | // state as requested by VOLTHA |
| 91 | o.OperState = getOperStateFSM(func(e *fsm.Event) { |
| 92 | onuLogger.WithFields(log.Fields{ |
| 93 | "ID": o.ID, |
| 94 | }).Debugf("Changing ONU OperState from %s to %s", e.Src, e.Dst) |
| 95 | }) |
| 96 | |
| 97 | // NOTE this state machine is used to activate the OMCI, EAPOL and DHCP clients |
| 98 | o.InternalState = fsm.NewFSM( |
| 99 | "created", |
| 100 | fsm.Events{ |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 101 | // DEVICE Lifecycle |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 102 | {Name: "discover", Src: []string{"created"}, Dst: "discovered"}, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 103 | {Name: "enable", Src: []string{"discovered", "disabled"}, Dst: "enabled"}, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 104 | {Name: "receive_eapol_flow", Src: []string{"enabled", "gem_port_added"}, Dst: "eapol_flow_received"}, |
| 105 | {Name: "add_gem_port", Src: []string{"enabled", "eapol_flow_received"}, Dst: "gem_port_added"}, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 106 | // NOTE should disabled state be diffente for oper_disabled (emulating an error) and admin_disabled (received a disabled call via VOLTHA)? |
| 107 | {Name: "disable", Src: []string{"eap_response_success_received", "auth_failed", "dhcp_ack_received", "dhcp_failed"}, Dst: "disabled"}, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 108 | // EAPOL |
| 109 | {Name: "start_auth", Src: []string{"eapol_flow_received", "gem_port_added"}, Dst: "auth_started"}, |
| 110 | {Name: "eap_start_sent", Src: []string{"auth_started"}, Dst: "eap_start_sent"}, |
| 111 | {Name: "eap_response_identity_sent", Src: []string{"eap_start_sent"}, Dst: "eap_response_identity_sent"}, |
| 112 | {Name: "eap_response_challenge_sent", Src: []string{"eap_response_identity_sent"}, Dst: "eap_response_challenge_sent"}, |
| 113 | {Name: "eap_response_success_received", Src: []string{"eap_response_challenge_sent"}, Dst: "eap_response_success_received"}, |
| 114 | {Name: "auth_failed", Src: []string{"auth_started", "eap_start_sent", "eap_response_identity_sent", "eap_response_challenge_sent"}, Dst: "auth_failed"}, |
| 115 | // DHCP |
| 116 | {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"}, |
| 117 | {Name: "dhcp_discovery_sent", Src: []string{"dhcp_started"}, Dst: "dhcp_discovery_sent"}, |
| 118 | {Name: "dhcp_request_sent", Src: []string{"dhcp_discovery_sent"}, Dst: "dhcp_request_sent"}, |
| 119 | {Name: "dhcp_ack_received", Src: []string{"dhcp_request_sent"}, Dst: "dhcp_ack_received"}, |
| 120 | {Name: "dhcp_failed", Src: []string{"dhcp_started", "dhcp_discovery_sent", "dhcp_request_sent"}, Dst: "dhcp_failed"}, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 121 | // BBR States |
| 122 | // TODO add start OMCI state |
| 123 | {Name: "send_eapol_flow", Src: []string{"created"}, Dst: "eapol_flow_sent"}, |
| 124 | {Name: "send_dhcp_flow", Src: []string{"eapol_flow_sent"}, Dst: "dhcp_flow_sent"}, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 125 | }, |
| 126 | fsm.Callbacks{ |
| 127 | "enter_state": func(e *fsm.Event) { |
| 128 | o.logStateChange(e.Src, e.Dst) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 129 | }, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 130 | "enter_enabled": func(event *fsm.Event) { |
| 131 | msg := Message{ |
| 132 | Type: OnuIndication, |
| 133 | Data: OnuIndicationMessage{ |
| 134 | OnuSN: o.SerialNumber, |
| 135 | PonPortID: o.PonPortID, |
| 136 | OperState: UP, |
| 137 | }, |
| 138 | } |
| 139 | o.Channel <- msg |
| 140 | }, |
| 141 | "enter_disabled": func(event *fsm.Event) { |
| 142 | msg := Message{ |
| 143 | Type: OnuIndication, |
| 144 | Data: OnuIndicationMessage{ |
| 145 | OnuSN: o.SerialNumber, |
| 146 | PonPortID: o.PonPortID, |
| 147 | OperState: DOWN, |
| 148 | }, |
| 149 | } |
| 150 | o.Channel <- msg |
| 151 | }, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 152 | "enter_auth_started": func(e *fsm.Event) { |
| 153 | o.logStateChange(e.Src, e.Dst) |
| 154 | msg := Message{ |
| 155 | Type: StartEAPOL, |
| 156 | Data: PacketMessage{ |
| 157 | PonPortID: o.PonPortID, |
| 158 | OnuID: o.ID, |
| 159 | }, |
| 160 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 161 | o.Channel <- msg |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 162 | }, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 163 | "enter_auth_failed": func(e *fsm.Event) { |
| 164 | onuLogger.WithFields(log.Fields{ |
| 165 | "OnuId": o.ID, |
| 166 | "IntfId": o.PonPortID, |
| 167 | "OnuSn": o.Sn(), |
| 168 | }).Errorf("ONU failed to authenticate!") |
| 169 | }, |
| 170 | "enter_dhcp_started": func(e *fsm.Event) { |
| 171 | msg := Message{ |
| 172 | Type: StartDHCP, |
| 173 | Data: PacketMessage{ |
| 174 | PonPortID: o.PonPortID, |
| 175 | OnuID: o.ID, |
| 176 | }, |
| 177 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 178 | o.Channel <- msg |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 179 | }, |
| 180 | "enter_dhcp_failed": func(e *fsm.Event) { |
| 181 | onuLogger.WithFields(log.Fields{ |
| 182 | "OnuId": o.ID, |
| 183 | "IntfId": o.PonPortID, |
| 184 | "OnuSn": o.Sn(), |
| 185 | }).Errorf("ONU failed to DHCP!") |
| 186 | }, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 187 | "enter_eapol_flow_sent": func(e *fsm.Event) { |
| 188 | msg := Message{ |
| 189 | Type: SendEapolFlow, |
| 190 | } |
| 191 | o.Channel <- msg |
| 192 | }, |
| 193 | "enter_dhcp_flow_sent": func(e *fsm.Event) { |
| 194 | msg := Message{ |
| 195 | Type: SendDhcpFlow, |
| 196 | } |
| 197 | o.Channel <- msg |
| 198 | }, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 199 | }, |
| 200 | ) |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 201 | return &o |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 204 | func (o Onu) logStateChange(src string, dst string) { |
| 205 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 206 | "OnuId": o.ID, |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 207 | "IntfId": o.PonPortID, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 208 | "OnuSn": o.Sn(), |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 209 | }).Debugf("Changing ONU InternalState from %s to %s", src, dst) |
| 210 | } |
| 211 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 212 | func (o Onu) ProcessOnuMessages(stream openolt.Openolt_EnableIndicationServer, client openolt.OpenoltClient) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 213 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 214 | "onuID": o.ID, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 215 | "onuSN": o.Sn(), |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 216 | }).Debug("Started ONU Indication Channel") |
| 217 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 218 | for message := range o.Channel { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 219 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 220 | "onuID": o.ID, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 221 | "onuSN": o.Sn(), |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 222 | "messageType": message.Type, |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 223 | }).Tracef("Received message on ONU Channel") |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 224 | |
| 225 | switch message.Type { |
| 226 | case OnuDiscIndication: |
| 227 | msg, _ := message.Data.(OnuDiscIndicationMessage) |
| 228 | o.sendOnuDiscIndication(msg, stream) |
| 229 | case OnuIndication: |
| 230 | msg, _ := message.Data.(OnuIndicationMessage) |
| 231 | o.sendOnuIndication(msg, stream) |
| 232 | case OMCI: |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 233 | msg, _ := message.Data.(OmciMessage) |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 234 | o.handleOmciMessage(msg, stream) |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 235 | case FlowUpdate: |
| 236 | msg, _ := message.Data.(OnuFlowUpdateMessage) |
| 237 | o.handleFlowUpdate(msg, stream) |
| 238 | case StartEAPOL: |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 239 | log.Infof("Receive StartEAPOL message on ONU Channel") |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 240 | eapol.SendEapStart(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.InternalState, stream) |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 241 | case StartDHCP: |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 242 | log.Infof("Receive StartDHCP message on ONU Channel") |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 243 | // FIXME use id, ponId as SendEapStart |
| 244 | dhcp.SendDHCPDiscovery(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.InternalState, o.HwAddress, o.CTag, stream) |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 245 | case OnuPacketOut: |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 246 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 247 | msg, _ := message.Data.(OnuPacketMessage) |
| 248 | |
| 249 | log.WithFields(log.Fields{ |
| 250 | "IntfId": msg.IntfId, |
| 251 | "OnuId": msg.OnuId, |
| 252 | "pktType": msg.Type, |
| 253 | }).Trace("Received OnuPacketOut Message") |
| 254 | |
| 255 | if msg.Type == packetHandlers.EAPOL { |
| 256 | eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client) |
| 257 | } else if msg.Type == packetHandlers.DHCP { |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 258 | // NOTE here we receive packets going from the DHCP Server to the ONU |
| 259 | // for now we expect them to be double-tagged, but ideally the should be single tagged |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 260 | dhcp.HandleNextPacket(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.CTag, o.InternalState, msg.Packet, stream) |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 261 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 262 | case OnuPacketIn: |
| 263 | // NOTE we only receive BBR packets here. |
| 264 | // Eapol.HandleNextPacket can handle both BBSim and BBr cases so the call is the same |
| 265 | // in the DHCP case VOLTHA only act as a proxy, the behaviour is completely different thus we have a dhcp.HandleNextBbrPacket |
| 266 | msg, _ := message.Data.(OnuPacketMessage) |
| 267 | |
| 268 | log.WithFields(log.Fields{ |
| 269 | "IntfId": msg.IntfId, |
| 270 | "OnuId": msg.OnuId, |
| 271 | "pktType": msg.Type, |
| 272 | }).Trace("Received OnuPacketIn Message") |
| 273 | |
| 274 | if msg.Type == packetHandlers.EAPOL { |
| 275 | eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client) |
| 276 | } else if msg.Type == packetHandlers.DHCP { |
| 277 | dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.STag, o.HwAddress, o.DoneChannel, msg.Packet, client) |
| 278 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 279 | case DyingGaspIndication: |
| 280 | msg, _ := message.Data.(DyingGaspIndicationMessage) |
| 281 | o.sendDyingGaspInd(msg, stream) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 282 | case OmciIndication: |
| 283 | // TODO handle me! |
| 284 | // here https://gerrit.opencord.org/#/c/15521/11/internal/bbr/onu.go in startOmci |
| 285 | msg, _ := message.Data.(OmciIndicationMessage) |
| 286 | o.handleOmci(msg, client) |
| 287 | case SendEapolFlow: |
| 288 | o.sendEapolFlow(client) |
| 289 | case SendDhcpFlow: |
| 290 | o.sendDhcpFlow(client) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 291 | default: |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 292 | onuLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 297 | func (o Onu) processOmciMessages(stream openolt.Openolt_EnableIndicationServer) { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 298 | ch := omcisim.GetChannel() |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 299 | |
| 300 | onuLogger.WithFields(log.Fields{ |
| 301 | "onuID": o.ID, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 302 | "onuSN": o.Sn(), |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 303 | }).Debug("Started OMCI Indication Channel") |
| 304 | |
| 305 | for message := range ch { |
| 306 | switch message.Type { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 307 | case omcisim.GemPortAdded: |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 308 | log.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 309 | "OnuId": message.Data.OnuId, |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 310 | "IntfId": message.Data.IntfId, |
| 311 | }).Infof("GemPort Added") |
| 312 | |
| 313 | // NOTE if we receive the GemPort but we don't have EAPOL flows |
| 314 | // go an intermediate state, otherwise start auth |
| 315 | if o.InternalState.Is("enabled") { |
| 316 | if err := o.InternalState.Event("add_gem_port"); err != nil { |
| 317 | log.Errorf("Can't go to gem_port_added: %v", err) |
| 318 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 319 | } else if o.InternalState.Is("eapol_flow_received") { |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 320 | if err := o.InternalState.Event("start_auth"); err != nil { |
| 321 | log.Errorf("Can't go to auth_started: %v", err) |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 328 | func (o Onu) NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber { |
| 329 | |
| 330 | sn := new(openolt.SerialNumber) |
| 331 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 332 | //sn = new(openolt.SerialNumber) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 333 | sn.VendorId = []byte("BBSM") |
| 334 | sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)} |
| 335 | |
| 336 | return sn |
| 337 | } |
| 338 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 339 | // NOTE handle_/process methods can change the ONU internal state as they are receiving messages |
| 340 | // send method should not change the ONU state |
| 341 | |
| 342 | func (o Onu) sendDyingGaspInd(msg DyingGaspIndicationMessage, stream openolt.Openolt_EnableIndicationServer) error { |
| 343 | alarmData := &openolt.AlarmIndication_DyingGaspInd{ |
| 344 | DyingGaspInd: &openolt.DyingGaspIndication{ |
| 345 | IntfId: msg.PonPortID, |
| 346 | OnuId: msg.OnuID, |
| 347 | Status: "on", |
| 348 | }, |
| 349 | } |
| 350 | data := &openolt.Indication_AlarmInd{AlarmInd: &openolt.AlarmIndication{Data: alarmData}} |
| 351 | |
| 352 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 353 | onuLogger.Errorf("Failed to send DyingGaspInd : %v", err) |
| 354 | return err |
| 355 | } |
| 356 | onuLogger.WithFields(log.Fields{ |
| 357 | "IntfId": msg.PonPortID, |
| 358 | "OnuSn": o.Sn(), |
| 359 | "OnuId": msg.OnuID, |
| 360 | }).Info("sendDyingGaspInd") |
| 361 | return nil |
| 362 | } |
| 363 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 364 | func (o Onu) sendOnuDiscIndication(msg OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 365 | discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 366 | IntfId: msg.Onu.PonPortID, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 367 | SerialNumber: msg.Onu.SerialNumber, |
| 368 | }} |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 369 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 370 | if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 371 | log.Errorf("Failed to send Indication_OnuDiscInd: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 372 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 373 | |
| 374 | if err := o.InternalState.Event("discover"); err != nil { |
| 375 | oltLogger.WithFields(log.Fields{ |
| 376 | "IntfId": o.PonPortID, |
| 377 | "OnuSn": o.Sn(), |
| 378 | "OnuId": o.ID, |
| 379 | }).Infof("Failed to transition ONU to discovered state: %s", err.Error()) |
| 380 | } |
| 381 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 382 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 383 | "IntfId": msg.Onu.PonPortID, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 384 | "OnuSn": msg.Onu.Sn(), |
| 385 | "OnuId": o.ID, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 386 | }).Debug("Sent Indication_OnuDiscInd") |
| 387 | } |
| 388 | |
| 389 | func (o Onu) sendOnuIndication(msg OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 390 | // NOTE voltha returns an ID, but if we use that ID then it complains: |
| 391 | // expected_onu_id: 1, received_onu_id: 1024, event: ONU-id-mismatch, can happen if both voltha and the olt rebooted |
| 392 | // so we're using the internal ID that is 1 |
| 393 | // o.ID = msg.OnuID |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 394 | |
| 395 | indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 396 | IntfId: o.PonPortID, |
| 397 | OnuId: o.ID, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 398 | OperState: msg.OperState.String(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 399 | AdminState: o.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 400 | SerialNumber: o.SerialNumber, |
| 401 | }} |
| 402 | if err := stream.Send(&openolt.Indication{Data: indData}); err != nil { |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 403 | // TODO do we need to transition to a broken state? |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 404 | log.Errorf("Failed to send Indication_OnuInd: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 405 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 406 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 407 | "IntfId": o.PonPortID, |
| 408 | "OnuId": o.ID, |
| 409 | "OperState": msg.OperState.String(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 410 | "AdminState": msg.OperState.String(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 411 | "OnuSn": o.Sn(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 412 | }).Debug("Sent Indication_OnuInd") |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 413 | |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | func (o Onu) handleOmciMessage(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 417 | |
| 418 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 419 | "IntfId": o.PonPortID, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 420 | "SerialNumber": o.Sn(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 421 | "omciPacket": msg.omciMsg.Pkt, |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 422 | }).Tracef("Received OMCI message") |
| 423 | |
| 424 | var omciInd openolt.OmciIndication |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 425 | respPkt, err := omcisim.OmciSim(o.PonPortID, o.ID, HexDecode(msg.omciMsg.Pkt)) |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 426 | if err != nil { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 427 | onuLogger.WithFields(log.Fields{ |
| 428 | "IntfId": o.PonPortID, |
| 429 | "SerialNumber": o.Sn(), |
| 430 | "omciPacket": omciInd.Pkt, |
| 431 | "msg": msg, |
| 432 | }).Errorf("Error handling OMCI message %v", msg) |
| 433 | return |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | omciInd.IntfId = o.PonPortID |
| 437 | omciInd.OnuId = o.ID |
| 438 | omciInd.Pkt = respPkt |
| 439 | |
| 440 | omci := &openolt.Indication_OmciInd{OmciInd: &omciInd} |
| 441 | if err := stream.Send(&openolt.Indication{Data: omci}); err != nil { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 442 | onuLogger.WithFields(log.Fields{ |
| 443 | "IntfId": o.PonPortID, |
| 444 | "SerialNumber": o.Sn(), |
| 445 | "omciPacket": omciInd.Pkt, |
| 446 | "msg": msg, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 447 | }).Errorf("send omcisim indication failed: %v", err) |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 448 | return |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 449 | } |
| 450 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 451 | "IntfId": o.PonPortID, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 452 | "SerialNumber": o.Sn(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 453 | "omciPacket": omciInd.Pkt, |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 454 | }).Tracef("Sent OMCI message") |
| 455 | } |
| 456 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 457 | func (o *Onu) storePortNumber(portNo uint32) { |
| 458 | // FIXME this is a workaround to always use the SN-1 entry in sadis, |
| 459 | // we need to add support for multiple UNIs |
| 460 | // the action plan is: |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 461 | // - refactor the omcisim-sim library to use https://github.com/cboling/omci instead of canned messages |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 462 | // - change the library so that it reports a single UNI and remove this workaroung |
| 463 | // - add support for multiple UNIs in BBSim |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 464 | if o.PortNo == 0 || portNo < o.PortNo { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 465 | o.PortNo = portNo |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | func (o *Onu) handleFlowUpdate(msg OnuFlowUpdateMessage, stream openolt.Openolt_EnableIndicationServer) { |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 470 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 471 | "DstPort": msg.Flow.Classifier.DstPort, |
| 472 | "EthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType), |
| 473 | "FlowId": msg.Flow.FlowId, |
| 474 | "FlowType": msg.Flow.FlowType, |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 475 | "InnerVlan": msg.Flow.Classifier.IVid, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 476 | "IntfId": msg.Flow.AccessIntfId, |
| 477 | "IpProto": msg.Flow.Classifier.IpProto, |
| 478 | "OnuId": msg.Flow.OnuId, |
| 479 | "OnuSn": o.Sn(), |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 480 | "OuterVlan": msg.Flow.Classifier.OVid, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 481 | "PortNo": msg.Flow.PortNo, |
| 482 | "SrcPort": msg.Flow.Classifier.SrcPort, |
| 483 | "UniID": msg.Flow.UniId, |
| 484 | }).Debug("ONU receives Flow") |
| 485 | |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 486 | if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) && msg.Flow.Classifier.OVid == 4091 { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 487 | // NOTE storing the PortNO, it's needed when sending PacketIndications |
| 488 | if o.PortNo == 0 { |
| 489 | o.storePortNumber(uint32(msg.Flow.PortNo)) |
| 490 | } |
| 491 | |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 492 | // NOTE if we receive the EAPOL flows but we don't have GemPorts |
| 493 | // go an intermediate state, otherwise start auth |
| 494 | if o.InternalState.Is("enabled") { |
| 495 | if err := o.InternalState.Event("receive_eapol_flow"); err != nil { |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 496 | log.Warnf("Can't go to eapol_flow_received: %v", err) |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 497 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 498 | } else if o.InternalState.Is("gem_port_added") { |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 499 | if err := o.InternalState.Event("start_auth"); err != nil { |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 500 | log.Warnf("Can't go to auth_started: %v", err) |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 501 | } |
| 502 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 503 | } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) && |
| 504 | msg.Flow.Classifier.SrcPort == uint32(68) && |
| 505 | msg.Flow.Classifier.DstPort == uint32(67) { |
| 506 | // NOTE we are receiving mulitple DHCP flows but we shouldn't call the transition multiple times |
| 507 | if err := o.InternalState.Event("start_dhcp"); err != nil { |
| 508 | log.Warnf("Can't go to dhcp_started: %v", err) |
| 509 | } |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 513 | // HexDecode converts the hex encoding to binary |
| 514 | func HexDecode(pkt []byte) []byte { |
| 515 | p := make([]byte, len(pkt)/2) |
| 516 | for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 { |
| 517 | // Go figure this ;) |
| 518 | u := (pkt[i] & 15) + (pkt[i]>>6)*9 |
| 519 | l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9 |
| 520 | p[j] = u<<4 + l |
| 521 | } |
| 522 | onuLogger.Tracef("Omci decoded: %x.", p) |
| 523 | return p |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 524 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 525 | |
| 526 | // BBR methods |
| 527 | |
| 528 | func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) { |
| 529 | omciMsg := openolt.OmciMsg{ |
| 530 | IntfId: intfId, |
| 531 | OnuId: onuId, |
| 532 | Pkt: pktBytes, |
| 533 | } |
| 534 | |
| 535 | if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil { |
| 536 | log.WithFields(log.Fields{ |
| 537 | "IntfId": intfId, |
| 538 | "OnuId": onuId, |
| 539 | "SerialNumber": common.OnuSnToString(sn), |
| 540 | "Pkt": omciMsg.Pkt, |
| 541 | }).Fatalf("Failed to send MIB Reset") |
| 542 | } |
| 543 | log.WithFields(log.Fields{ |
| 544 | "IntfId": intfId, |
| 545 | "OnuId": onuId, |
| 546 | "SerialNumber": common.OnuSnToString(sn), |
| 547 | "Pkt": omciMsg.Pkt, |
| 548 | }).Tracef("Sent OMCI message %s", msgType) |
| 549 | } |
| 550 | |
| 551 | func (onu *Onu) getNextTid(highPriority ...bool) uint16 { |
| 552 | var next uint16 |
| 553 | if len(highPriority) > 0 && highPriority[0] { |
| 554 | next = onu.hpTid |
| 555 | onu.hpTid += 1 |
| 556 | if onu.hpTid < 0x8000 { |
| 557 | onu.hpTid = 0x8000 |
| 558 | } |
| 559 | } else { |
| 560 | next = onu.tid |
| 561 | onu.tid += 1 |
| 562 | if onu.tid >= 0x8000 { |
| 563 | onu.tid = 1 |
| 564 | } |
| 565 | } |
| 566 | return next |
| 567 | } |
| 568 | |
| 569 | // TODO move this method in responders/omcisim |
| 570 | func (o *Onu) StartOmci(client openolt.OpenoltClient) { |
| 571 | mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false)) |
| 572 | sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client) |
| 573 | } |
| 574 | |
| 575 | func (o *Onu) handleOmci(msg OmciIndicationMessage, client openolt.OpenoltClient) { |
| 576 | msgType, packet := omcilib.DecodeOmci(msg.OmciInd.Pkt) |
| 577 | |
| 578 | log.WithFields(log.Fields{ |
| 579 | "IntfId": msg.OmciInd.IntfId, |
| 580 | "OnuId": msg.OmciInd.OnuId, |
| 581 | "OnuSn": common.OnuSnToString(o.SerialNumber), |
| 582 | "Pkt": msg.OmciInd.Pkt, |
| 583 | "msgType": msgType, |
| 584 | }).Trace("ONU Receveives OMCI Msg") |
| 585 | switch msgType { |
| 586 | default: |
| 587 | log.Fatalf("unexpected frame: %v", packet) |
| 588 | case omci.MibResetResponseType: |
| 589 | mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false)) |
| 590 | sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client) |
| 591 | case omci.MibUploadResponseType: |
| 592 | mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber) |
| 593 | sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client) |
| 594 | case omci.MibUploadNextResponseType: |
| 595 | o.seqNumber++ |
| 596 | |
| 597 | if o.seqNumber > 290 { |
| 598 | // NOTE we are done with the MIB Upload (290 is the number of messages the omci-sim library will respond to) |
| 599 | galEnet, _ := omcilib.CreateGalEnetRequest(o.getNextTid(false)) |
| 600 | sendOmciMsg(galEnet, o.PonPortID, o.ID, o.SerialNumber, "CreateGalEnetRequest", client) |
| 601 | } else { |
| 602 | mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber) |
| 603 | sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client) |
| 604 | } |
| 605 | case omci.CreateResponseType: |
| 606 | // NOTE Creating a GemPort, |
| 607 | // BBsim actually doesn't care about the values, so we can do we want with the parameters |
| 608 | // In the same way we can create a GemPort even without setting up UNIs/TConts/... |
| 609 | // but we need the GemPort to trigger the state change |
| 610 | |
| 611 | if !o.HasGemPort { |
| 612 | // NOTE this sends a CreateRequestType and BBSim replies with a CreateResponseType |
| 613 | // thus we send this request only once |
| 614 | gemReq, _ := omcilib.CreateGemPortRequest(o.getNextTid(false)) |
| 615 | sendOmciMsg(gemReq, o.PonPortID, o.ID, o.SerialNumber, "CreateGemPortRequest", client) |
| 616 | o.HasGemPort = true |
| 617 | } else { |
| 618 | if err := o.InternalState.Event("send_eapol_flow"); err != nil { |
| 619 | onuLogger.WithFields(log.Fields{ |
| 620 | "OnuId": o.ID, |
| 621 | "IntfId": o.PonPortID, |
| 622 | "OnuSn": o.Sn(), |
| 623 | }).Errorf("Error while transitioning ONU State %v", err) |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) { |
| 631 | |
| 632 | classifierProto := openolt.Classifier{ |
| 633 | EthType: uint32(layers.EthernetTypeEAPOL), |
| 634 | OVid: 4091, |
| 635 | } |
| 636 | |
| 637 | actionProto := openolt.Action{} |
| 638 | |
| 639 | downstreamFlow := openolt.Flow{ |
| 640 | AccessIntfId: int32(o.PonPortID), |
| 641 | OnuId: int32(o.ID), |
| 642 | UniId: int32(0x101), // FIXME do not hardcode this |
| 643 | FlowId: uint32(o.ID), |
| 644 | FlowType: "downstream", |
| 645 | AllocId: int32(0), |
| 646 | NetworkIntfId: int32(0), |
| 647 | GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode |
| 648 | Classifier: &classifierProto, |
| 649 | Action: &actionProto, |
| 650 | Priority: int32(100), |
| 651 | Cookie: uint64(o.ID), |
| 652 | PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU |
| 653 | } |
| 654 | |
| 655 | if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil { |
| 656 | log.WithFields(log.Fields{ |
| 657 | "IntfId": o.PonPortID, |
| 658 | "OnuId": o.ID, |
| 659 | "FlowId": downstreamFlow.FlowId, |
| 660 | "PortNo": downstreamFlow.PortNo, |
| 661 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 662 | }).Fatalf("Failed to EAPOL Flow") |
| 663 | } |
| 664 | log.WithFields(log.Fields{ |
| 665 | "IntfId": o.PonPortID, |
| 666 | "OnuId": o.ID, |
| 667 | "FlowId": downstreamFlow.FlowId, |
| 668 | "PortNo": downstreamFlow.PortNo, |
| 669 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 670 | }).Info("Sent EAPOL Flow") |
| 671 | } |
| 672 | |
| 673 | func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) { |
| 674 | classifierProto := openolt.Classifier{ |
| 675 | EthType: uint32(layers.EthernetTypeIPv4), |
| 676 | SrcPort: uint32(68), |
| 677 | DstPort: uint32(67), |
| 678 | } |
| 679 | |
| 680 | actionProto := openolt.Action{} |
| 681 | |
| 682 | downstreamFlow := openolt.Flow{ |
| 683 | AccessIntfId: int32(o.PonPortID), |
| 684 | OnuId: int32(o.ID), |
| 685 | UniId: int32(0x101), // FIXME do not hardcode this |
| 686 | FlowId: uint32(o.ID), |
| 687 | FlowType: "downstream", |
| 688 | AllocId: int32(0), |
| 689 | NetworkIntfId: int32(0), |
| 690 | GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode |
| 691 | Classifier: &classifierProto, |
| 692 | Action: &actionProto, |
| 693 | Priority: int32(100), |
| 694 | Cookie: uint64(o.ID), |
| 695 | PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU |
| 696 | } |
| 697 | |
| 698 | if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil { |
| 699 | log.WithFields(log.Fields{ |
| 700 | "IntfId": o.PonPortID, |
| 701 | "OnuId": o.ID, |
| 702 | "FlowId": downstreamFlow.FlowId, |
| 703 | "PortNo": downstreamFlow.PortNo, |
| 704 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 705 | }).Fatalf("Failed to send DHCP Flow") |
| 706 | } |
| 707 | log.WithFields(log.Fields{ |
| 708 | "IntfId": o.PonPortID, |
| 709 | "OnuId": o.ID, |
| 710 | "FlowId": downstreamFlow.FlowId, |
| 711 | "PortNo": downstreamFlow.PortNo, |
| 712 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 713 | }).Info("Sent DHCP Flow") |
| 714 | } |