Shad Ansari | 2eac6a4 | 2018-11-14 22:35:39 -0800 | [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 core |
| 18 | |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 19 | import ( |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 20 | "context" |
Keita NISHIMOTO | 9617c85 | 2019-06-17 21:46:44 +0900 | [diff] [blame] | 21 | |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 22 | "gerrit.opencord.org/voltha-bbsim/common/logger" |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 23 | openolt "gerrit.opencord.org/voltha-bbsim/protos" |
Shad Ansari | b744bf2 | 2019-01-17 11:36:46 -0800 | [diff] [blame] | 24 | omci "github.com/opencord/omci-sim" |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 25 | ) |
| 26 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 27 | // RunOmciResponder starts a go routine to process/respond to OMCI messages from VOLTHA |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 28 | func (s *Server) RunOmciResponder(ctx context.Context, omciOut chan openolt.OmciMsg, omciIn chan openolt.OmciIndication, errch chan error) { |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 29 | go func() { |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 30 | defer logger.Debug("Omci response process was done") |
Shad Ansari | 65fed64 | 2019-01-16 14:04:19 -0800 | [diff] [blame] | 31 | |
| 32 | var resp openolt.OmciIndication |
| 33 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 34 | for { |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 35 | select { |
| 36 | case m := <-omciOut: |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 37 | respPkt, err := omci.OmciSim(m.IntfId, m.OnuId, HexDecode(m.Pkt)) |
Shad Ansari | 65fed64 | 2019-01-16 14:04:19 -0800 | [diff] [blame] | 38 | switch err := err.(type) { |
| 39 | case nil: |
| 40 | // Success |
| 41 | resp.IntfId = m.IntfId |
| 42 | resp.OnuId = m.OnuId |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 43 | resp.Pkt = respPkt |
Shad Ansari | 65fed64 | 2019-01-16 14:04:19 -0800 | [diff] [blame] | 44 | omciIn <- resp |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 45 | s.handleOmciAction(resp.Pkt, resp.IntfId, resp.OnuId) |
| 46 | |
Shad Ansari | b744bf2 | 2019-01-17 11:36:46 -0800 | [diff] [blame] | 47 | case *omci.OmciError: |
Shad Ansari | 65fed64 | 2019-01-16 14:04:19 -0800 | [diff] [blame] | 48 | // Error in processing omci message. Log and carry on. |
| 49 | logger.Debug("%s", err.Msg) |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 50 | continue |
Shad Ansari | 65fed64 | 2019-01-16 14:04:19 -0800 | [diff] [blame] | 51 | default: |
| 52 | // Fatal error, exit. |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 53 | errch <- err |
| 54 | return |
| 55 | } |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 56 | case <-ctx.Done(): |
| 57 | return |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 58 | } |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 59 | } |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 60 | }() |
Shad Ansari | 2eac6a4 | 2018-11-14 22:35:39 -0800 | [diff] [blame] | 61 | } |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 62 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 63 | // HexDecode converts the hex encoding to binary |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 64 | func HexDecode(pkt []byte) []byte { |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 65 | // TODO - Change openolt adapter to send raw binary instead of hex encoded |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 66 | p := make([]byte, len(pkt)/2) |
| 67 | for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 { |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 68 | // Go figure this ;) |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 69 | u := (pkt[i] & 15) + (pkt[i]>>6)*9 |
| 70 | l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9 |
| 71 | p[j] = u<<4 + l |
| 72 | } |
| 73 | logger.Debug("Omci decoded: %x.", p) |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 74 | return p |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 75 | } |
| 76 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 77 | func (s *Server) handleOmciAction(pkt []byte, IntfID uint32, OnuID uint32) { |
| 78 | logger.Debug("handleOmciAction invoked") |
| 79 | MEClass := omci.OmciClass(uint16(pkt[5]) | uint16(pkt[4])<<8) |
| 80 | msgType := omci.OmciMsgType(pkt[2] & 0x1F) |
| 81 | logger.Debug("ME Class %d, msgType %d", MEClass, msgType) |
| 82 | |
| 83 | if MEClass == omci.ONUG { |
| 84 | switch msgType { |
| 85 | case omci.Reboot: |
| 86 | logger.Info("ONU reboot recieved") |
| 87 | s.handleONUSoftReboot(IntfID, OnuID) |
| 88 | } |
| 89 | } |
| 90 | } |