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 ( |
| 26 | //EtherType8100 - EtherType dot1q |
| 27 | EtherType8100 uint8 = 0 |
| 28 | //EtherType88a8 - EtherType dot1ad |
| 29 | EtherType88a8 uint8 = 1 |
| 30 | //EtherType9100 - EtherType dot1ad doubleTag |
| 31 | EtherType9100 uint8 = 2 |
| 32 | //EtherType9200 - EtherType dot1q doubleTag |
| 33 | EtherType9200 uint8 = 3 |
| 34 | ) |
| 35 | |
| 36 | //GetMetadataForL2Protocol - returns metadata value for provide ethertype |
| 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 { |
| 53 | |
| 54 | value, err := strconv.ParseUint(data, 10, 64) |
| 55 | if err != nil { |
| 56 | return 0 |
| 57 | } |
| 58 | return value |
| 59 | |
| 60 | } |