Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2021-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <core.p4> |
| 18 | #include <v1model.p4> |
| 19 | |
| 20 | #include "../header.p4" |
| 21 | |
| 22 | control PreNext(inout parsed_headers_t hdr, |
| 23 | inout fabric_metadata_t fabric_metadata) { |
| 24 | /* |
| 25 | * Next MPLS table. |
| 26 | * Set the MPLS label based on the next ID. |
| 27 | */ |
| 28 | |
| 29 | direct_counter(CounterType.packets_and_bytes) next_mpls_counter; |
| 30 | |
| 31 | action set_mpls_label(mpls_label_t label) { |
| 32 | fabric_metadata.mpls_label = label; |
| 33 | next_mpls_counter.count(); |
| 34 | } |
| 35 | |
| 36 | table next_mpls { |
| 37 | key = { |
| 38 | fabric_metadata.next_id: exact @name("next_id"); |
| 39 | } |
| 40 | actions = { |
| 41 | set_mpls_label; |
| 42 | @defaultonly nop; |
| 43 | } |
| 44 | const default_action = nop(); |
| 45 | counters = next_mpls_counter; |
| 46 | size = NEXT_MPLS_TABLE_SIZE; |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | * Next VLAN table. |
| 51 | * Modify VLAN ID based on next ID. |
| 52 | */ |
| 53 | |
| 54 | direct_counter(CounterType.packets_and_bytes) next_vlan_counter; |
| 55 | |
| 56 | action set_vlan(vlan_id_t vlan_id) { |
| 57 | fabric_metadata.vlan_id = vlan_id; |
| 58 | next_vlan_counter.count(); |
| 59 | } |
| 60 | |
| 61 | #ifdef WITH_DOUBLE_VLAN_TERMINATION |
| 62 | action set_double_vlan(vlan_id_t outer_vlan_id, vlan_id_t inner_vlan_id) { |
| 63 | set_vlan(outer_vlan_id); |
| 64 | fabric_metadata.push_double_vlan = _TRUE; |
| 65 | fabric_metadata.inner_vlan_id = inner_vlan_id; |
| 66 | #ifdef WITH_BNG |
| 67 | fabric_metadata.bng.s_tag = outer_vlan_id; |
| 68 | fabric_metadata.bng.c_tag = inner_vlan_id; |
| 69 | #endif // WITH_BNG |
| 70 | } |
| 71 | #endif // WITH_DOUBLE_VLAN_TERMINATION |
| 72 | |
| 73 | table next_vlan { |
| 74 | key = { |
| 75 | fabric_metadata.next_id: exact @name("next_id"); |
| 76 | } |
| 77 | actions = { |
| 78 | set_vlan; |
| 79 | #ifdef WITH_DOUBLE_VLAN_TERMINATION |
| 80 | set_double_vlan; |
| 81 | #endif // WITH_DOUBLE_VLAN_TERMINATION |
| 82 | @defaultonly nop; |
| 83 | } |
| 84 | const default_action = nop(); |
| 85 | counters = next_vlan_counter; |
| 86 | size = NEXT_VLAN_TABLE_SIZE; |
| 87 | } |
| 88 | |
| 89 | apply { |
| 90 | next_mpls.apply(); |
| 91 | next_vlan.apply(); |
| 92 | } |
| 93 | } |