blob: 01ff50026fffda91c2629de3e4a2e29eaa6e52fc [file] [log] [blame]
Girish Gowdra64503432020-01-07 10:59:10 +05301/*
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
17package core
18
19import (
20 "fmt"
21 "github.com/opencord/voltha-lib-go/v2/pkg/log"
22 "github.com/opencord/voltha-protos/v2/go/openolt"
23)
24
25var AttCtag map[uint32]uint32
26
27func init() {
28 _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
29 AttCtag = make(map[uint32]uint32)
30}
31
32const (
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
42var vendorSpecificId = 1000
43
44func 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
58func 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
66func 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
78func GetAttStag(ponIntf uint32) uint32 {
79 // start with stag 2
80 return ponIntf + 2
81}
82
83// TODO: More workflow support to be added here
84func 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
94func 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}