Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 16 | package application |
| 17 | |
| 18 | import ( |
| 19 | "errors" |
| 20 | "strconv" |
| 21 | |
| 22 | "github.com/google/gopacket/layers" |
| 23 | ) |
| 24 | |
| 25 | const ( |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 26 | // EtherType8100 - EtherType dot1q |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 27 | EtherType8100 uint8 = 0 |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 28 | // EtherType88a8 - EtherType dot1ad |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 29 | EtherType88a8 uint8 = 1 |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 30 | // EtherType9100 - EtherType dot1ad doubleTag |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 31 | EtherType9100 uint8 = 2 |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 32 | // EtherType9200 - EtherType dot1q doubleTag |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 33 | EtherType9200 uint8 = 3 |
| 34 | ) |
| 35 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 36 | // GetMetadataForL2Protocol - returns metadata value for provide ethertype |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 37 | func 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 | |
| 52 | func convertToUInt64(data string) uint64 { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 53 | value, err := strconv.ParseUint(data, 10, 64) |
| 54 | if err != nil { |
| 55 | return 0 |
| 56 | } |
| 57 | return value |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 58 | } |