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) |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame^] | 237 | o.handleFlowUpdate(msg) |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 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: |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 283 | msg, _ := message.Data.(OmciIndicationMessage) |
| 284 | o.handleOmci(msg, client) |
| 285 | case SendEapolFlow: |
| 286 | o.sendEapolFlow(client) |
| 287 | case SendDhcpFlow: |
| 288 | o.sendDhcpFlow(client) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 289 | default: |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 290 | 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] | 291 | } |
| 292 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 293 | } |
| 294 | |
William Kurkian | 9dadc5b | 2019-10-22 13:51:57 -0400 | [diff] [blame] | 295 | func (o Onu) processOmciMessage(message omcisim.OmciChMessage) { |
| 296 | switch message.Type { |
| 297 | case omcisim.GemPortAdded: |
| 298 | log.WithFields(log.Fields{ |
| 299 | "OnuId": message.Data.OnuId, |
| 300 | "IntfId": message.Data.IntfId, |
| 301 | }).Infof("GemPort Added") |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 302 | |
William Kurkian | 9dadc5b | 2019-10-22 13:51:57 -0400 | [diff] [blame] | 303 | // NOTE if we receive the GemPort but we don't have EAPOL flows |
| 304 | // go an intermediate state, otherwise start auth |
| 305 | if o.InternalState.Is("enabled") { |
| 306 | if err := o.InternalState.Event("add_gem_port"); err != nil { |
| 307 | log.Errorf("Can't go to gem_port_added: %v", err) |
| 308 | } |
| 309 | } else if o.InternalState.Is("eapol_flow_received") { |
| 310 | if err := o.InternalState.Event("start_auth"); err != nil { |
| 311 | log.Errorf("Can't go to auth_started: %v", err) |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 317 | func (o Onu) NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber { |
| 318 | |
| 319 | sn := new(openolt.SerialNumber) |
| 320 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 321 | //sn = new(openolt.SerialNumber) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 322 | sn.VendorId = []byte("BBSM") |
| 323 | sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)} |
| 324 | |
| 325 | return sn |
| 326 | } |
| 327 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 328 | // NOTE handle_/process methods can change the ONU internal state as they are receiving messages |
| 329 | // send method should not change the ONU state |
| 330 | |
| 331 | func (o Onu) sendDyingGaspInd(msg DyingGaspIndicationMessage, stream openolt.Openolt_EnableIndicationServer) error { |
| 332 | alarmData := &openolt.AlarmIndication_DyingGaspInd{ |
| 333 | DyingGaspInd: &openolt.DyingGaspIndication{ |
| 334 | IntfId: msg.PonPortID, |
| 335 | OnuId: msg.OnuID, |
| 336 | Status: "on", |
| 337 | }, |
| 338 | } |
| 339 | data := &openolt.Indication_AlarmInd{AlarmInd: &openolt.AlarmIndication{Data: alarmData}} |
| 340 | |
| 341 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 342 | onuLogger.Errorf("Failed to send DyingGaspInd : %v", err) |
| 343 | return err |
| 344 | } |
| 345 | onuLogger.WithFields(log.Fields{ |
| 346 | "IntfId": msg.PonPortID, |
| 347 | "OnuSn": o.Sn(), |
| 348 | "OnuId": msg.OnuID, |
| 349 | }).Info("sendDyingGaspInd") |
| 350 | return nil |
| 351 | } |
| 352 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 353 | func (o Onu) sendOnuDiscIndication(msg OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 354 | discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 355 | IntfId: msg.Onu.PonPortID, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 356 | SerialNumber: msg.Onu.SerialNumber, |
| 357 | }} |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 358 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 359 | if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 360 | log.Errorf("Failed to send Indication_OnuDiscInd: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 361 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 362 | |
| 363 | if err := o.InternalState.Event("discover"); err != nil { |
| 364 | oltLogger.WithFields(log.Fields{ |
| 365 | "IntfId": o.PonPortID, |
| 366 | "OnuSn": o.Sn(), |
| 367 | "OnuId": o.ID, |
| 368 | }).Infof("Failed to transition ONU to discovered state: %s", err.Error()) |
| 369 | } |
| 370 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 371 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 372 | "IntfId": msg.Onu.PonPortID, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 373 | "OnuSn": msg.Onu.Sn(), |
| 374 | "OnuId": o.ID, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 375 | }).Debug("Sent Indication_OnuDiscInd") |
| 376 | } |
| 377 | |
| 378 | func (o Onu) sendOnuIndication(msg OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 379 | // NOTE voltha returns an ID, but if we use that ID then it complains: |
| 380 | // expected_onu_id: 1, received_onu_id: 1024, event: ONU-id-mismatch, can happen if both voltha and the olt rebooted |
| 381 | // so we're using the internal ID that is 1 |
| 382 | // o.ID = msg.OnuID |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 383 | |
| 384 | indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 385 | IntfId: o.PonPortID, |
| 386 | OnuId: o.ID, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 387 | OperState: msg.OperState.String(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 388 | AdminState: o.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 389 | SerialNumber: o.SerialNumber, |
| 390 | }} |
| 391 | if err := stream.Send(&openolt.Indication{Data: indData}); err != nil { |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 392 | // TODO do we need to transition to a broken state? |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 393 | log.Errorf("Failed to send Indication_OnuInd: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 394 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 395 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 396 | "IntfId": o.PonPortID, |
| 397 | "OnuId": o.ID, |
| 398 | "OperState": msg.OperState.String(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 399 | "AdminState": msg.OperState.String(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 400 | "OnuSn": o.Sn(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 401 | }).Debug("Sent Indication_OnuInd") |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 402 | |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | func (o Onu) handleOmciMessage(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 406 | |
| 407 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 408 | "IntfId": o.PonPortID, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 409 | "SerialNumber": o.Sn(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 410 | "omciPacket": msg.omciMsg.Pkt, |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 411 | }).Tracef("Received OMCI message") |
| 412 | |
| 413 | var omciInd openolt.OmciIndication |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 414 | respPkt, err := omcisim.OmciSim(o.PonPortID, o.ID, HexDecode(msg.omciMsg.Pkt)) |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 415 | if err != nil { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 416 | onuLogger.WithFields(log.Fields{ |
| 417 | "IntfId": o.PonPortID, |
| 418 | "SerialNumber": o.Sn(), |
| 419 | "omciPacket": omciInd.Pkt, |
| 420 | "msg": msg, |
| 421 | }).Errorf("Error handling OMCI message %v", msg) |
| 422 | return |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | omciInd.IntfId = o.PonPortID |
| 426 | omciInd.OnuId = o.ID |
| 427 | omciInd.Pkt = respPkt |
| 428 | |
| 429 | omci := &openolt.Indication_OmciInd{OmciInd: &omciInd} |
| 430 | if err := stream.Send(&openolt.Indication{Data: omci}); err != nil { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 431 | onuLogger.WithFields(log.Fields{ |
| 432 | "IntfId": o.PonPortID, |
| 433 | "SerialNumber": o.Sn(), |
| 434 | "omciPacket": omciInd.Pkt, |
| 435 | "msg": msg, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 436 | }).Errorf("send omcisim indication failed: %v", err) |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 437 | return |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 438 | } |
| 439 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 440 | "IntfId": o.PonPortID, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 441 | "SerialNumber": o.Sn(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 442 | "omciPacket": omciInd.Pkt, |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 443 | }).Tracef("Sent OMCI message") |
| 444 | } |
| 445 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 446 | func (o *Onu) storePortNumber(portNo uint32) { |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame^] | 447 | // NOTE this needed only as long as we don't support multiple UNIs |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 448 | // we need to add support for multiple UNIs |
| 449 | // the action plan is: |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 450 | // - 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] | 451 | // - change the library so that it reports a single UNI and remove this workaroung |
| 452 | // - add support for multiple UNIs in BBSim |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 453 | if o.PortNo == 0 || portNo < o.PortNo { |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame^] | 454 | onuLogger.WithFields(log.Fields{ |
| 455 | "IntfId": o.PonPortID, |
| 456 | "OnuId": o.ID, |
| 457 | "SerialNumber": o.Sn(), |
| 458 | "OnuPortNo": o.PortNo, |
| 459 | "FlowPortNo": portNo, |
| 460 | }).Debug("Storing ONU portNo") |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 461 | o.PortNo = portNo |
| 462 | } |
| 463 | } |
| 464 | |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame^] | 465 | func (o *Onu) handleFlowUpdate(msg OnuFlowUpdateMessage) { |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 466 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 467 | "DstPort": msg.Flow.Classifier.DstPort, |
| 468 | "EthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType), |
| 469 | "FlowId": msg.Flow.FlowId, |
| 470 | "FlowType": msg.Flow.FlowType, |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 471 | "InnerVlan": msg.Flow.Classifier.IVid, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 472 | "IntfId": msg.Flow.AccessIntfId, |
| 473 | "IpProto": msg.Flow.Classifier.IpProto, |
| 474 | "OnuId": msg.Flow.OnuId, |
| 475 | "OnuSn": o.Sn(), |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 476 | "OuterVlan": msg.Flow.Classifier.OVid, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 477 | "PortNo": msg.Flow.PortNo, |
| 478 | "SrcPort": msg.Flow.Classifier.SrcPort, |
| 479 | "UniID": msg.Flow.UniId, |
| 480 | }).Debug("ONU receives Flow") |
| 481 | |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame^] | 482 | if msg.Flow.UniId != 0 { |
| 483 | // as of now BBSim only support a single UNI, so ignore everything that is not targeted to it |
| 484 | onuLogger.WithFields(log.Fields{ |
| 485 | "IntfId": o.PonPortID, |
| 486 | "OnuId": o.ID, |
| 487 | "SerialNumber": o.Sn(), |
| 488 | }).Debug("Ignoring flow as it's not for the first UNI") |
| 489 | return |
| 490 | } |
| 491 | |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 492 | 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] | 493 | // NOTE storing the PortNO, it's needed when sending PacketIndications |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame^] | 494 | o.storePortNumber(uint32(msg.Flow.PortNo)) |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 495 | |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 496 | // NOTE if we receive the EAPOL flows but we don't have GemPorts |
| 497 | // go an intermediate state, otherwise start auth |
| 498 | if o.InternalState.Is("enabled") { |
| 499 | if err := o.InternalState.Event("receive_eapol_flow"); err != nil { |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 500 | log.Warnf("Can't go to eapol_flow_received: %v", err) |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 501 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 502 | } else if o.InternalState.Is("gem_port_added") { |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 503 | if err := o.InternalState.Event("start_auth"); err != nil { |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 504 | log.Warnf("Can't go to auth_started: %v", err) |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 505 | } |
| 506 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 507 | } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) && |
| 508 | msg.Flow.Classifier.SrcPort == uint32(68) && |
| 509 | msg.Flow.Classifier.DstPort == uint32(67) { |
| 510 | // NOTE we are receiving mulitple DHCP flows but we shouldn't call the transition multiple times |
| 511 | if err := o.InternalState.Event("start_dhcp"); err != nil { |
| 512 | log.Warnf("Can't go to dhcp_started: %v", err) |
| 513 | } |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 517 | // HexDecode converts the hex encoding to binary |
| 518 | func HexDecode(pkt []byte) []byte { |
| 519 | p := make([]byte, len(pkt)/2) |
| 520 | for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 { |
| 521 | // Go figure this ;) |
| 522 | u := (pkt[i] & 15) + (pkt[i]>>6)*9 |
| 523 | l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9 |
| 524 | p[j] = u<<4 + l |
| 525 | } |
| 526 | onuLogger.Tracef("Omci decoded: %x.", p) |
| 527 | return p |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 528 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 529 | |
| 530 | // BBR methods |
| 531 | |
| 532 | func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) { |
| 533 | omciMsg := openolt.OmciMsg{ |
| 534 | IntfId: intfId, |
| 535 | OnuId: onuId, |
| 536 | Pkt: pktBytes, |
| 537 | } |
| 538 | |
| 539 | if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil { |
| 540 | log.WithFields(log.Fields{ |
| 541 | "IntfId": intfId, |
| 542 | "OnuId": onuId, |
| 543 | "SerialNumber": common.OnuSnToString(sn), |
| 544 | "Pkt": omciMsg.Pkt, |
| 545 | }).Fatalf("Failed to send MIB Reset") |
| 546 | } |
| 547 | log.WithFields(log.Fields{ |
| 548 | "IntfId": intfId, |
| 549 | "OnuId": onuId, |
| 550 | "SerialNumber": common.OnuSnToString(sn), |
| 551 | "Pkt": omciMsg.Pkt, |
| 552 | }).Tracef("Sent OMCI message %s", msgType) |
| 553 | } |
| 554 | |
| 555 | func (onu *Onu) getNextTid(highPriority ...bool) uint16 { |
| 556 | var next uint16 |
| 557 | if len(highPriority) > 0 && highPriority[0] { |
| 558 | next = onu.hpTid |
| 559 | onu.hpTid += 1 |
| 560 | if onu.hpTid < 0x8000 { |
| 561 | onu.hpTid = 0x8000 |
| 562 | } |
| 563 | } else { |
| 564 | next = onu.tid |
| 565 | onu.tid += 1 |
| 566 | if onu.tid >= 0x8000 { |
| 567 | onu.tid = 1 |
| 568 | } |
| 569 | } |
| 570 | return next |
| 571 | } |
| 572 | |
| 573 | // TODO move this method in responders/omcisim |
| 574 | func (o *Onu) StartOmci(client openolt.OpenoltClient) { |
| 575 | mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false)) |
| 576 | sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client) |
| 577 | } |
| 578 | |
| 579 | func (o *Onu) handleOmci(msg OmciIndicationMessage, client openolt.OpenoltClient) { |
| 580 | msgType, packet := omcilib.DecodeOmci(msg.OmciInd.Pkt) |
| 581 | |
| 582 | log.WithFields(log.Fields{ |
| 583 | "IntfId": msg.OmciInd.IntfId, |
| 584 | "OnuId": msg.OmciInd.OnuId, |
| 585 | "OnuSn": common.OnuSnToString(o.SerialNumber), |
| 586 | "Pkt": msg.OmciInd.Pkt, |
| 587 | "msgType": msgType, |
| 588 | }).Trace("ONU Receveives OMCI Msg") |
| 589 | switch msgType { |
| 590 | default: |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame^] | 591 | log.WithFields(log.Fields{ |
| 592 | "IntfId": msg.OmciInd.IntfId, |
| 593 | "OnuId": msg.OmciInd.OnuId, |
| 594 | "OnuSn": common.OnuSnToString(o.SerialNumber), |
| 595 | "Pkt": msg.OmciInd.Pkt, |
| 596 | "msgType": msgType, |
| 597 | }).Fatalf("unexpected frame: %v", packet) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 598 | case omci.MibResetResponseType: |
| 599 | mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false)) |
| 600 | sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client) |
| 601 | case omci.MibUploadResponseType: |
| 602 | mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber) |
| 603 | sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client) |
| 604 | case omci.MibUploadNextResponseType: |
| 605 | o.seqNumber++ |
| 606 | |
| 607 | if o.seqNumber > 290 { |
| 608 | // NOTE we are done with the MIB Upload (290 is the number of messages the omci-sim library will respond to) |
| 609 | galEnet, _ := omcilib.CreateGalEnetRequest(o.getNextTid(false)) |
| 610 | sendOmciMsg(galEnet, o.PonPortID, o.ID, o.SerialNumber, "CreateGalEnetRequest", client) |
| 611 | } else { |
| 612 | mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber) |
| 613 | sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client) |
| 614 | } |
| 615 | case omci.CreateResponseType: |
| 616 | // NOTE Creating a GemPort, |
| 617 | // BBsim actually doesn't care about the values, so we can do we want with the parameters |
| 618 | // In the same way we can create a GemPort even without setting up UNIs/TConts/... |
| 619 | // but we need the GemPort to trigger the state change |
| 620 | |
| 621 | if !o.HasGemPort { |
| 622 | // NOTE this sends a CreateRequestType and BBSim replies with a CreateResponseType |
| 623 | // thus we send this request only once |
| 624 | gemReq, _ := omcilib.CreateGemPortRequest(o.getNextTid(false)) |
| 625 | sendOmciMsg(gemReq, o.PonPortID, o.ID, o.SerialNumber, "CreateGemPortRequest", client) |
| 626 | o.HasGemPort = true |
| 627 | } else { |
| 628 | if err := o.InternalState.Event("send_eapol_flow"); err != nil { |
| 629 | onuLogger.WithFields(log.Fields{ |
| 630 | "OnuId": o.ID, |
| 631 | "IntfId": o.PonPortID, |
| 632 | "OnuSn": o.Sn(), |
| 633 | }).Errorf("Error while transitioning ONU State %v", err) |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) { |
| 641 | |
| 642 | classifierProto := openolt.Classifier{ |
| 643 | EthType: uint32(layers.EthernetTypeEAPOL), |
| 644 | OVid: 4091, |
| 645 | } |
| 646 | |
| 647 | actionProto := openolt.Action{} |
| 648 | |
| 649 | downstreamFlow := openolt.Flow{ |
| 650 | AccessIntfId: int32(o.PonPortID), |
| 651 | OnuId: int32(o.ID), |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame^] | 652 | UniId: int32(0), // NOTE do not hardcode this, we need to support multiple UNIs |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 653 | FlowId: uint32(o.ID), |
| 654 | FlowType: "downstream", |
| 655 | AllocId: int32(0), |
| 656 | NetworkIntfId: int32(0), |
| 657 | GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode |
| 658 | Classifier: &classifierProto, |
| 659 | Action: &actionProto, |
| 660 | Priority: int32(100), |
| 661 | Cookie: uint64(o.ID), |
| 662 | PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU |
| 663 | } |
| 664 | |
| 665 | if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil { |
| 666 | log.WithFields(log.Fields{ |
| 667 | "IntfId": o.PonPortID, |
| 668 | "OnuId": o.ID, |
| 669 | "FlowId": downstreamFlow.FlowId, |
| 670 | "PortNo": downstreamFlow.PortNo, |
| 671 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 672 | }).Fatalf("Failed to EAPOL Flow") |
| 673 | } |
| 674 | log.WithFields(log.Fields{ |
| 675 | "IntfId": o.PonPortID, |
| 676 | "OnuId": o.ID, |
| 677 | "FlowId": downstreamFlow.FlowId, |
| 678 | "PortNo": downstreamFlow.PortNo, |
| 679 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 680 | }).Info("Sent EAPOL Flow") |
| 681 | } |
| 682 | |
| 683 | func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) { |
| 684 | classifierProto := openolt.Classifier{ |
| 685 | EthType: uint32(layers.EthernetTypeIPv4), |
| 686 | SrcPort: uint32(68), |
| 687 | DstPort: uint32(67), |
| 688 | } |
| 689 | |
| 690 | actionProto := openolt.Action{} |
| 691 | |
| 692 | downstreamFlow := openolt.Flow{ |
| 693 | AccessIntfId: int32(o.PonPortID), |
| 694 | OnuId: int32(o.ID), |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame^] | 695 | UniId: int32(0), // FIXME do not hardcode this |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 696 | FlowId: uint32(o.ID), |
| 697 | FlowType: "downstream", |
| 698 | AllocId: int32(0), |
| 699 | NetworkIntfId: int32(0), |
| 700 | GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode |
| 701 | Classifier: &classifierProto, |
| 702 | Action: &actionProto, |
| 703 | Priority: int32(100), |
| 704 | Cookie: uint64(o.ID), |
| 705 | PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU |
| 706 | } |
| 707 | |
| 708 | if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil { |
| 709 | log.WithFields(log.Fields{ |
| 710 | "IntfId": o.PonPortID, |
| 711 | "OnuId": o.ID, |
| 712 | "FlowId": downstreamFlow.FlowId, |
| 713 | "PortNo": downstreamFlow.PortNo, |
| 714 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 715 | }).Fatalf("Failed to send DHCP Flow") |
| 716 | } |
| 717 | log.WithFields(log.Fields{ |
| 718 | "IntfId": o.PonPortID, |
| 719 | "OnuId": o.ID, |
| 720 | "FlowId": downstreamFlow.FlowId, |
| 721 | "PortNo": downstreamFlow.PortNo, |
| 722 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 723 | }).Info("Sent DHCP Flow") |
| 724 | } |