blob: 0fb5313758349214f95a1947233a3c1ab5bfeb42 [file] [log] [blame]
Naveen Sampath04696f72022-06-13 15:19:14 +05301/*
2* Copyright 2022-present Open Networking Foundation
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14 */
15
16package application
17
18import (
19 "errors"
20 "strconv"
Hitesh Chhabra2b2347d2023-07-31 17:36:48 +053021 "voltha-go-controller/log"
Naveen Sampath04696f72022-06-13 15:19:14 +053022
23 "github.com/google/gopacket/layers"
24)
25
26const (
vinokuma926cb3e2023-03-29 11:41:06 +053027 // EtherType8100 - EtherType dot1q
Naveen Sampath04696f72022-06-13 15:19:14 +053028 EtherType8100 uint8 = 0
vinokuma926cb3e2023-03-29 11:41:06 +053029 // EtherType88a8 - EtherType dot1ad
Naveen Sampath04696f72022-06-13 15:19:14 +053030 EtherType88a8 uint8 = 1
vinokuma926cb3e2023-03-29 11:41:06 +053031 // EtherType9100 - EtherType dot1ad doubleTag
Naveen Sampath04696f72022-06-13 15:19:14 +053032 EtherType9100 uint8 = 2
vinokuma926cb3e2023-03-29 11:41:06 +053033 // EtherType9200 - EtherType dot1q doubleTag
Naveen Sampath04696f72022-06-13 15:19:14 +053034 EtherType9200 uint8 = 3
35)
36
vinokuma926cb3e2023-03-29 11:41:06 +053037// GetMetadataForL2Protocol - returns metadata value for provide ethertype
Naveen Sampath04696f72022-06-13 15:19:14 +053038func GetMetadataForL2Protocol(etherType layers.EthernetType) (uint8, error) {
Hitesh Chhabra2b2347d2023-07-31 17:36:48 +053039 logger.Debugw(ctx, " GetMetadataForL2Protocol", log.Fields{"EtherType ": etherType})
Naveen Sampath04696f72022-06-13 15:19:14 +053040 switch etherType {
41 case layers.EthernetTypeDot1Q:
42 return EtherType8100, nil
43 case layers.EthernetTypeQinQ:
44 return EtherType88a8, nil
45 case layers.EthernetTypeDot1QDoubleTag:
46 return EtherType9100, nil
47 case layers.EthernetTypeQinQDoubleTag:
48 return EtherType9200, nil
49 default:
50 return 0, errors.New("EtherType not supported")
51 }
52}
53
54func convertToUInt64(data string) uint64 {
Naveen Sampath04696f72022-06-13 15:19:14 +053055 value, err := strconv.ParseUint(data, 10, 64)
56 if err != nil {
57 return 0
58 }
59 return value
Naveen Sampath04696f72022-06-13 15:19:14 +053060}