blob: 11ffe87eed7c8a2f776b7482666b178ee9423ed4 [file] [log] [blame]
Mahir Gunyel6781f962021-05-16 23:30:08 -07001/*
2 * Copyright 2020-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 adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
19
20import (
21 "fmt"
22)
23
24const (
25 tpIDStart = 64
26 tpIDEnd = 256
27 tpRange = tpIDEnd - tpIDStart
28 maxUni = 256
29 ieeMaperServiceProfileBaseEID = uint16(0x1001)
30 macBridgePortAniBaseEID = uint16(0x1001)
31 macBridgePortUniBaseEID = uint16(0x201)
32 macBridgePortAniMcastBaseEID = uint16(0xA01)
33 galEthernetEID = uint16(1)
34 macBridgeServiceProfileEID = uint16(0x201)
35)
36
37func generateIeeMaperServiceProfileEID(uniPortMacBpNo uint16, tpID uint16) (uint16, error) {
38 if tpID < tpIDStart || tpID >= tpIDEnd {
39 return 0, fmt.Errorf("tech profile id out of range - %d", tpID)
40 }
41 if uniPortMacBpNo > maxUni {
42 return 0, fmt.Errorf("uni macbpno out of range - %d", uniPortMacBpNo)
43 }
44 return (ieeMaperServiceProfileBaseEID + uniPortMacBpNo*tpRange + tpID - tpIDStart), nil
45}
46
47func generateANISideMBPCDEID(uniPortMacBpNo uint16, tpID uint16) (uint16, error) {
48 if tpID < tpIDStart || tpID >= tpIDEnd {
49 return 0, fmt.Errorf("tech profile id out of range - %d", tpID)
50 }
51 if uniPortMacBpNo > maxUni {
52 return 0, fmt.Errorf("uni macbpno out of range - %d", uniPortMacBpNo)
53 }
54 return (macBridgePortAniBaseEID + uniPortMacBpNo*tpRange + tpID - tpIDStart), nil
55}
56
57func generateUNISideMBPCDEID(uniPortMacBpNo uint16) (uint16, error) {
58 if uniPortMacBpNo > maxUni {
59 return 0, fmt.Errorf("uni macbpno out of range - %d", uniPortMacBpNo)
60 }
61 return (macBridgePortUniBaseEID + uniPortMacBpNo), nil
62}
63
64func generateMcastANISideMBPCDEID(uniPortMacBpNo uint16) (uint16, error) {
65
66 if uniPortMacBpNo > maxUni {
67 return 0, fmt.Errorf("uni macbpno out of range - %d", uniPortMacBpNo)
68 }
69 return (macBridgePortAniMcastBaseEID + uniPortMacBpNo), nil
70}