Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [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 | |
| 19 | import ( |
| 20 | "fmt" |
| 21 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
| 22 | "github.com/opencord/voltha-protos/v2/go/openolt" |
| 23 | ) |
| 24 | |
| 25 | var AttCtag map[uint32]uint32 |
| 26 | |
| 27 | func init() { |
| 28 | _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil) |
| 29 | AttCtag = make(map[uint32]uint32) |
| 30 | } |
| 31 | |
| 32 | const ( |
| 33 | vendorName = "ABCD" |
| 34 | // Number of bits for the physical UNI of the ONUs |
| 35 | bitsForUniID = 4 |
| 36 | // Number of bits for the ONU ID |
| 37 | bitsForONUID = 8 |
| 38 | //MaxOnusPerPon is Max number of ONUs on any PON port |
| 39 | MaxOnusPerPon = 1 << bitsForONUID |
| 40 | ) |
| 41 | |
| 42 | var vendorSpecificId = 1000 |
| 43 | |
| 44 | func GenerateNextONUSerialNumber() *openolt.SerialNumber { |
| 45 | |
| 46 | vi := []byte(vendorName) |
| 47 | |
| 48 | vendorSpecificId += 1 |
| 49 | vs := []byte(fmt.Sprint(vendorSpecificId)) |
| 50 | // log.Infow("vendor-id-and-vendor-specific", log.Fields{"vi":vi, "vs":vs}) |
| 51 | sn := &openolt.SerialNumber{VendorId: vi, VendorSpecific: vs} |
| 52 | // log.Infow("serial-num", log.Fields{"sn":sn}) |
| 53 | |
| 54 | return sn |
| 55 | } |
| 56 | |
| 57 | //MkUniPortNum returns new UNIportNum based on intfID, inuID and uniID |
| 58 | func MkUniPortNum(intfID, onuID, uniID uint32) uint32 { |
| 59 | var limit = int(onuID) |
| 60 | if limit > MaxOnusPerPon { |
| 61 | log.Warn("Warning: exceeded the MAX ONUS per PON") |
| 62 | } |
| 63 | return (intfID << (bitsForUniID + bitsForONUID)) | (onuID << bitsForUniID) | uniID |
| 64 | } |
| 65 | |
| 66 | func GetAttCtag(ponIntf uint32) uint32 { |
| 67 | var currCtag uint32 |
| 68 | var ok bool |
| 69 | if currCtag, ok = AttCtag[ponIntf]; !ok { |
| 70 | // Start with ctag 2 |
| 71 | AttCtag[ponIntf] = 2 |
| 72 | return AttCtag[ponIntf] |
| 73 | } |
| 74 | AttCtag[ponIntf] = currCtag + 1 |
| 75 | return AttCtag[ponIntf] |
| 76 | } |
| 77 | |
| 78 | func GetAttStag(ponIntf uint32) uint32 { |
| 79 | // start with stag 2 |
| 80 | return ponIntf + 2 |
| 81 | } |
| 82 | |
| 83 | // TODO: More workflow support to be added here |
| 84 | func GetCtag(workFlowName string, ponIntf uint32) uint32 { |
| 85 | switch workFlowName { |
| 86 | case "ATT": |
| 87 | return GetAttCtag(ponIntf) |
| 88 | default: |
| 89 | log.Errorw("unknown-workflowname", log.Fields{"workflow": workFlowName}) |
| 90 | } |
| 91 | return 0 |
| 92 | } |
| 93 | |
| 94 | func GetStag(workFlowName string, ponIntf uint32) uint32 { |
| 95 | switch workFlowName { |
| 96 | case "ATT": |
| 97 | return GetAttStag(ponIntf) |
| 98 | default: |
| 99 | log.Errorw("unknown-workflowname", log.Fields{"workflow": workFlowName}) |
| 100 | } |
| 101 | return 0 |
| 102 | } |