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" |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 21 | "voltha-go-controller/log" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 22 | |
| 23 | "github.com/google/gopacket/layers" |
| 24 | ) |
| 25 | |
| 26 | const ( |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 27 | // EtherType8100 - EtherType dot1q |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 28 | EtherType8100 uint8 = 0 |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 29 | // EtherType88a8 - EtherType dot1ad |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 30 | EtherType88a8 uint8 = 1 |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 31 | // EtherType9100 - EtherType dot1ad doubleTag |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 32 | EtherType9100 uint8 = 2 |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 33 | // EtherType9200 - EtherType dot1q doubleTag |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 34 | EtherType9200 uint8 = 3 |
| 35 | ) |
| 36 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 37 | // GetMetadataForL2Protocol - returns metadata value for provide ethertype |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 38 | func GetMetadataForL2Protocol(etherType layers.EthernetType) (uint8, error) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 39 | logger.Debugw(ctx, " GetMetadataForL2Protocol", log.Fields{"EtherType ": etherType}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 40 | 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 | |
| 54 | func convertToUInt64(data string) uint64 { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 55 | value, err := strconv.ParseUint(data, 10, 64) |
| 56 | if err != nil { |
| 57 | return 0 |
| 58 | } |
| 59 | return value |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 60 | } |