blob: f157bf95686c94faea508a15a75b44c4d16b8863 [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"
21
22 "github.com/google/gopacket/layers"
23)
24
25const (
vinokuma926cb3e2023-03-29 11:41:06 +053026 // EtherType8100 - EtherType dot1q
Naveen Sampath04696f72022-06-13 15:19:14 +053027 EtherType8100 uint8 = 0
vinokuma926cb3e2023-03-29 11:41:06 +053028 // EtherType88a8 - EtherType dot1ad
Naveen Sampath04696f72022-06-13 15:19:14 +053029 EtherType88a8 uint8 = 1
vinokuma926cb3e2023-03-29 11:41:06 +053030 // EtherType9100 - EtherType dot1ad doubleTag
Naveen Sampath04696f72022-06-13 15:19:14 +053031 EtherType9100 uint8 = 2
vinokuma926cb3e2023-03-29 11:41:06 +053032 // EtherType9200 - EtherType dot1q doubleTag
Naveen Sampath04696f72022-06-13 15:19:14 +053033 EtherType9200 uint8 = 3
34)
35
vinokuma926cb3e2023-03-29 11:41:06 +053036// GetMetadataForL2Protocol - returns metadata value for provide ethertype
Naveen Sampath04696f72022-06-13 15:19:14 +053037func GetMetadataForL2Protocol(etherType layers.EthernetType) (uint8, error) {
38 switch etherType {
39 case layers.EthernetTypeDot1Q:
40 return EtherType8100, nil
41 case layers.EthernetTypeQinQ:
42 return EtherType88a8, nil
43 case layers.EthernetTypeDot1QDoubleTag:
44 return EtherType9100, nil
45 case layers.EthernetTypeQinQDoubleTag:
46 return EtherType9200, nil
47 default:
48 return 0, errors.New("EtherType not supported")
49 }
50}
51
52func convertToUInt64(data string) uint64 {
Naveen Sampath04696f72022-06-13 15:19:14 +053053 value, err := strconv.ParseUint(data, 10, 64)
54 if err != nil {
55 return 0
56 }
57 return value
Naveen Sampath04696f72022-06-13 15:19:14 +053058}