Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -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 | |
Zdravko Bozakov | 3d76214 | 2019-07-15 16:57:17 +0200 | [diff] [blame] | 19 | import ( |
| 20 | "fmt" |
Matteo Scandolo | a002681 | 2019-08-20 11:01:32 -0700 | [diff] [blame] | 21 | log "github.com/sirupsen/logrus" |
Zdravko Bozakov | 3d76214 | 2019-07-15 16:57:17 +0200 | [diff] [blame] | 22 | ) |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 23 | |
| 24 | type OmciError struct { |
| 25 | Msg string |
| 26 | } |
| 27 | |
| 28 | func (e *OmciError) Error() string { |
| 29 | return fmt.Sprintf("%s", e.Msg) |
| 30 | } |
| 31 | |
| 32 | type OnuKey struct { |
| 33 | IntfId, OnuId uint32 |
| 34 | } |
Mahir Gunyel | ed7b07b | 2019-02-11 12:06:02 -0800 | [diff] [blame] | 35 | |
| 36 | func (k OnuKey) String() string { |
| 37 | return fmt.Sprintf("Onu {intfid:%d, onuid:%d}", k.IntfId, k.OnuId) |
| 38 | } |
Zdravko Bozakov | 3d76214 | 2019-07-15 16:57:17 +0200 | [diff] [blame] | 39 | |
| 40 | func GetAttributes(class OmciClass, content OmciContent, key OnuKey, pkt []byte) []byte { |
Matteo Scandolo | a002681 | 2019-08-20 11:01:32 -0700 | [diff] [blame] | 41 | log.WithFields(log.Fields{ |
| 42 | "IntfId": key.IntfId, |
| 43 | "OnuId": key.OnuId, |
| 44 | }).Tracef("GetAttributes() invoked") |
Zdravko Bozakov | 3d76214 | 2019-07-15 16:57:17 +0200 | [diff] [blame] | 45 | |
| 46 | switch class { |
| 47 | case ANIG: |
| 48 | pos := uint(11) |
| 49 | pkt, _ = GetANIGAttributes(&pos, pkt, content) |
| 50 | return pkt |
| 51 | |
| 52 | case EthernetPMHistoryData: |
| 53 | pos := uint(11) |
| 54 | pkt, _ = GetEthernetPMHistoryDataAttributes(&pos, pkt, content) |
| 55 | return pkt |
| 56 | default: |
| 57 | // For unimplemented MEs, just fill in the attribute mask and return 0 values for the requested attributes |
| 58 | // TODO implement Get for unimplemented MEs as well |
Matteo Scandolo | a002681 | 2019-08-20 11:01:32 -0700 | [diff] [blame] | 59 | log.WithFields(log.Fields{ |
| 60 | "IntfId": key.IntfId, |
| 61 | "OnuId": key.OnuId, |
| 62 | "class": class, |
Matteo Scandolo | 203314b | 2019-08-26 14:28:42 -0700 | [diff] [blame] | 63 | }).Tracef("Unimplemeted GetAttributes for ME Class: %v " + |
Zdravko Bozakov | 3d76214 | 2019-07-15 16:57:17 +0200 | [diff] [blame] | 64 | "Filling with zero value for the requested attributes", class) |
| 65 | AttributesMask := getAttributeMask(content) |
| 66 | pkt[8] = 0x00 // Command Processed Successfully |
| 67 | pkt[9] = uint8(AttributesMask >> 8) |
| 68 | pkt[10] = uint8(AttributesMask & 0xFF) |
| 69 | |
| 70 | return pkt |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | func getAttributeMask(content OmciContent) int { |
| 75 | // mask is present in pkt[8] and pkt[9] |
Matteo Scandolo | a002681 | 2019-08-20 11:01:32 -0700 | [diff] [blame] | 76 | log.WithFields(log.Fields{ |
| 77 | "content[0]": content[0], |
| 78 | "content[1]": content[1], |
| 79 | }).Tracef("GetAttributeMask() invoked") |
Zdravko Bozakov | 3d76214 | 2019-07-15 16:57:17 +0200 | [diff] [blame] | 80 | return (int(content[0]) << 8) | int(content[1]) |
| 81 | } |