├── LICENSE ├── README.md ├── fabric ├── NOTICE.txt ├── README.md ├── p4src │ ├── acl.p4 │ ├── constants.p4 │ ├── headers.p4 │ ├── pppoe.p4 │ ├── processor_bng.p4 │ └── se.p4 └── wireshark-dissectors │ ├── README.md │ ├── cpu_header.lua │ └── init.lua └── generic ├── README.md ├── __init__.py ├── p4src ├── headers.p4 ├── includes │ └── intrinsic.p4 └── se.p4 ├── platf_bm_oss ├── README.md ├── autotest ├── bot ├── runtime │ ├── __init__.py │ ├── setup_initruntime.py │ └── test.py └── vars ├── platf_p4netfpga ├── .gitignore ├── netfpga_runtime │ ├── __init__.py │ ├── p4netfpga_runtime.py │ ├── simple_test.py │ └── simple_test.sh └── src │ ├── header_16.p4 │ └── p4-BNG.p4 ├── runtime ├── __init__.py ├── meterbuckets.py ├── meterbuckets_test.py ├── p4_userplane_exception.py ├── runtime_p4_manager.py ├── simple_stats.py ├── thriftcli_runtime_mgr.py └── utils │ ├── __init__.py │ └── simple_subscriber.py └── tests ├── __init__.py └── simple_test.py /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # p4se 2 | 3 | BNG/PPPoE P4 software 4 | 5 | ## Generic 6 | 7 | The directory `generic` contains a cross-platform P4 implementation 8 | for devices intended to be attached to a leaf switch, tested against bmv2. 9 | 10 | ## Fabric 11 | 12 | The directory `fabric` contains a P4 implementation integrated into a 13 | leaf switch of a CORD-like leaf-spine topology. The code has been tested 14 | against the Barefoot Tofino. 15 | -------------------------------------------------------------------------------- /fabric/NOTICE.txt: -------------------------------------------------------------------------------- 1 | This program, the P4 Service Edge data plane, is designed to terminate 2 | residential network access customers using PPPoE. 3 | 4 | Authors: Jeremias Blendin, Leonhard Nobach 5 | 6 | This program is licensed under the Apache-2.0 License (http://opensource.org/licenses/Apache-2.0). See also file LICENSING 7 | Development sponsored by Deutsche Telekom AG [ opensource@telekom.de ] 8 | 9 | Modification sections: 10 | 1. 2017-2018, Blendin, Jeremias and Nobach, Leonhard: Initial Development. 11 | 12 | Disclaimer of Warranty 13 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION 14 | 15 | Limitation of Liability' 16 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17 | -------------------------------------------------------------------------------- /fabric/README.md: -------------------------------------------------------------------------------- 1 | 2 | P4 CORD Service Edge 3 | ==================== 4 | 5 | This repository contains a P4 program that implements 6 | a residential network access service data plane. The data plane has been 7 | designed to support a typical large-scale residential broadband access 8 | network using PPPoE for subscriber access. 9 | 10 | The repository contains the data plane only, no control plane is included at 11 | the moment. The current status of the program is described in the following 12 | status section. 13 | 14 | Status 15 | ------ 16 | 17 | The generic part of the service edge should be understood as 18 | a prototype to support the subscriber termination and has not been tested 19 | in detail yet. The code does not include a control plane. 20 | All tests have been conducted using the Barefoot SDE 8.0.0.19 and the Barefoot 21 | Tofino simulator. 22 | 23 | Open tasks 24 | 25 | - Running tests on an Barefoot Tofino hardware switch 26 | - Testing the data plane together with a control plane and physical residential 27 | gateway devices 28 | 29 | Directory Layout 30 | ---------------- 31 | 32 | ''' 33 | ./p4src 34 | The P4 source code. 35 | 36 | ./wireshark-dissectors/ 37 | Wireshark dissector for the data plane to control plane communication protocol. 38 | ''' 39 | 40 | Build Instructions 41 | ------------------ 42 | 43 | Requirements: Barefoot SDE 8.0.0.19 44 | 45 | ``` 46 | cd $SDE 47 | ./p4_build.sh /p4src/se.p4 48 | ``` 49 | 50 | For details on testing and the Wireshark dissectors, please refer to 51 | `README.md` in the respective folders. 52 | 53 | -------------------------------------------------------------------------------- /fabric/p4src/acl.p4: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present Open Networking Foundation and Barefoot Networks 3 | * 4 | * This file is adapted from an original acl.p4 from Barefoot Networks. 5 | * 6 | * Contributed and sponsored by Deutsche Telekom AG. 7 | * Originally developed as part of the D-Nets 6 P4 Service Edge project 8 | * in collaboration with Technische Universitaet Darmstadt. 9 | * Authors: Jeremias Blendin, Leonhard Nobach 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | * For details see the file LICENSE in the top project directory. 24 | */ 25 | 26 | /*****************************************************************************/ 27 | /* Egress System ACL */ 28 | /*****************************************************************************/ 29 | 30 | action ingress_redirect_to_cpu_with_reason(reason_code) { 31 | modify_field(cpu_md.reason_code, reason_code); 32 | modify_field(cpu_md.handling_type, HANDLING_TYPE_ERROR); 33 | modify_field(serviceedge_md.fwd_net_proto, NET_PROTO_CP); 34 | modify_field(serviceedge_md.out_net_proto, NET_PROTO_CP); 35 | } 36 | 37 | /* 38 | MRU/MTU check for the tunnel should be done in 39 | the processor. The details have not been worked out yet. 40 | action ingress_pkt_too_big() { 41 | ingress_redirect_to_cpu_with_reason(CPU_ERROR_PKT_TOO_BIG); 42 | } 43 | */ 44 | 45 | action egress_copy_to_cpu(mirror_id) { 46 | clone_egress_pkt_to_egress(mirror_id, error_fields); 47 | } 48 | 49 | action egress_redirect_to_cpu(mirror_id) { 50 | egress_copy_to_cpu(mirror_id); 51 | drop(); 52 | } 53 | 54 | action egress_copy_to_cpu_with_reason(mirror_id, reason_code) { 55 | modify_field(cpu_md.reason_code, reason_code); 56 | egress_copy_to_cpu(mirror_id); 57 | } 58 | 59 | action egress_redirect_to_cpu_with_reason(mirror_id, reason_code) { 60 | egress_copy_to_cpu_with_reason(mirror_id, reason_code); 61 | drop(); 62 | } 63 | 64 | 65 | action egress_pkt_too_big(mirror_id) { 66 | modify_field(cpu_md.expected_value, serviceedge_md.mtu_out); 67 | modify_field(cpu_md.actual_value, serviceedge_md.pkt_len_out); 68 | modify_field(cpu_md.handling_type, HANDLING_TYPE_ERROR); 69 | modify_field(serviceedge_md.out_net_proto, NET_PROTO_CP); 70 | egress_copy_to_cpu_with_reason(mirror_id, CPU_ERROR_PKT_TOO_BIG); 71 | drop(); 72 | } 73 | 74 | 75 | table ingress_system_acl { 76 | reads { 77 | serviceedge_md.in_net_proto : ternary; 78 | serviceedge_md.fwd_net_proto : ternary; 79 | serviceedge_md.out_net_proto : ternary; 80 | serviceedge_md.processor_ingress : ternary; 81 | serviceedge_md.processor_egress : ternary; 82 | serviceedge_md.next_hop_id : ternary; 83 | mcast_md.is_multicast : ternary; 84 | ipv4.valid : ternary; 85 | ipv4.ttl : ternary; 86 | ipv4.totalLen : ternary; 87 | ipv6.valid : ternary; 88 | ipv6.hopLimit : ternary; 89 | ipv6.payloadLen : ternary; 90 | } 91 | actions { 92 | _nop; 93 | _drop; 94 | ingress_redirect_to_cpu_with_reason; 95 | } 96 | size : 64; 97 | } 98 | 99 | control process_ingress_system_acl { 100 | apply(ingress_system_acl); 101 | } 102 | 103 | table egress_system_acl { 104 | reads { 105 | ig_intr_md_for_tm.packet_color : ternary; 106 | eg_intr_md.egress_port : ternary; 107 | eg_intr_md_from_parser_aux.clone_src : ternary; 108 | cpu_md.packet_color : ternary; 109 | pcr_bng_md.ds_packet_color : ternary; 110 | serviceedge_md.pkt_len_out : ternary; 111 | serviceedge_md.mtu_out : ternary; 112 | serviceedge_md.mtu_check : ternary; 113 | serviceedge_md.in_net_proto : ternary; 114 | serviceedge_md.fwd_net_proto : ternary; 115 | serviceedge_md.out_net_proto : ternary; 116 | serviceedge_md.next_hop_id : ternary; 117 | } 118 | actions { 119 | _nop; 120 | _drop; 121 | egress_pkt_too_big; 122 | egress_copy_to_cpu; 123 | egress_redirect_to_cpu; 124 | egress_copy_to_cpu_with_reason; 125 | egress_redirect_to_cpu_with_reason; 126 | } 127 | size : 64; 128 | } 129 | 130 | control process_egress_system_acl { 131 | apply(egress_system_acl); 132 | } 133 | 134 | -------------------------------------------------------------------------------- /fabric/p4src/constants.p4: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present Open Networking Foundation 3 | * 4 | * Contributed and sponsored by Deutsche Telekom AG. 5 | * Originally developed as part of the D-Nets 6 P4 Service Edge project 6 | * in collaboration with Technische Universitaet Darmstadt. 7 | * Authors: Jeremias Blendin, Leonhard Nobach 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * For details see the file LICENSE in the top project directory. 22 | */ 23 | 24 | 25 | #define ROUTE_CAPACITY 256 26 | #define NEXT_HOP_CAPACITY 256 27 | #define ACL_CAPACITY 128 28 | 29 | #define VLAN_SERVICE_VID 7 30 | 31 | #define MPLS_TUNNEL 9000 32 | #define MPLS_IPV4 16384 33 | #define MPLS_IPV6 16385 34 | #define MPLS_IP 16386 35 | 36 | #define NEXT_HOP_CP 255 37 | 38 | #define FALSE 0 39 | #define TRUE 1 40 | 41 | #define IN_CLASSIFY_TABLE_SIZE 64 42 | 43 | #define PROCESSOR_NONE 0 44 | #define PROCESSOR_SR_FWD 1 45 | #define PROCESSOR_SR_TERM 2 46 | #define PROCESSOR_BNG 3 47 | #define PROCESSOR_WHOLESALE 4 48 | 49 | #define NET_PROTO_UNDEFINED 0 50 | #define NET_PROTO_IP 1 51 | #define NET_PROTO_SR 2 // Segment Routing 52 | #define NET_PROTO_CP 3 // Control Plane 53 | 54 | #define PKT_LEN_OPERATOR_NOCHANGE 0 55 | #define PKT_LEN_OPERATOR_INC 0 56 | #define PKT_LEN_OPERATOR_DEC 0 57 | 58 | #define CPU_ERROR_NONE 0 59 | #define CPU_ERROR_PKT_TOO_BIG 1 60 | #define HANDLING_TYPE_ERROR 1 61 | #define HANDLING_TYPE_CP_PRC_US 2 62 | #define HANDLING_TYPE_PRC_DS_CP 3 63 | 64 | //#define CPU_MIRROR_SESSION_ID 250 65 | #define CPU_MIRROR_SESSION_ID 100 66 | 67 | #define CPU_PORT 64 68 | 69 | #define SR_SERVICE_TYPE_NONE 0 70 | #define SR_SERVICE_TYPE_IP 1 71 | #define SR_SERVICE_TYPE_SUBSCRIBER_TUNNEL 2 72 | 73 | #define ETHERTYPE_IPV4 0x0800 74 | #define ETHERTYPE_IPV6 0x86DD 75 | #define ETHERTYPE_VLAN 0x8100 76 | #define ETHERTYPE_PPPOED 0x8863 77 | #define ETHERTYPE_PPPOES 0x8864 78 | #define ETHERTYPE_MPLS 0x8847 79 | #define ETHERTYPE_CPUHEADER 0xeeee 80 | 81 | #define PPPOE_PROTOCOL_IPV4 0x0021 82 | #define PPPOE_PROTOCOL_IPV6 0x0057 83 | 84 | -------------------------------------------------------------------------------- /fabric/p4src/headers.p4: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present Open Networking Foundation 3 | * 4 | * Contributed and sponsored by Deutsche Telekom AG. 5 | * Originally developed as part of the D-Nets 6 P4 Service Edge project 6 | * in collaboration with Technische Universitaet Darmstadt. 7 | * Authors: Jeremias Blendin, Leonhard Nobach 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * For details see the file LICENSE in the top project directory. 22 | */ 23 | 24 | /************************************************************************* 25 | *********************** M E T A D A T A ******************************* 26 | *************************************************************************/ 27 | 28 | header_type serviceedge_md_t { 29 | fields { 30 | processor_ingress : 4; 31 | processor_egress : 4; 32 | //processor_state : 4; 33 | processor_add_header_len : 8; 34 | in_net_proto : 4; 35 | fwd_net_proto : 4; 36 | out_net_proto : 4; 37 | pad_1 : 4; 38 | 39 | next_hop_id : 8; 40 | pad_2 : 8; 41 | // Number of bytes left for increasing the packet size. If this 42 | // value is 0 the packet must be redirected to the control plane. 43 | mtu_check : 16 (saturating); 44 | // MTU of the next hop. The next hop MTU is used 45 | // because inside of the CORD POD the MTU is expected to be large 46 | // enough to host any kind of forwarded packet. Therefore, the bottleneck 47 | // MTU is the MTU of the link of the next hop and not our interfaces MTU. 48 | mtu_out : 16; 49 | // Overall length of the packet as it will be send out the port. 50 | pkt_len_out : 16; 51 | // Expected length of the packet after adding the headers length added in the egress 52 | // to the packet as processed in the traffic manager. 53 | pkt_len_out_decr : 16; 54 | } 55 | } 56 | 57 | header_type cpu_md_t { 58 | fields { 59 | in_classifier : 8; 60 | handling_type : 8; 61 | reason_code : 8; 62 | pad_1 : 16; 63 | expected_value : 32; 64 | actual_value : 32; 65 | meter_id: 16; 66 | packet_color: 2; 67 | pad_2 : 6; 68 | } 69 | } 70 | 71 | header_type sr_md_t { 72 | fields { 73 | // MPLS service label for this traffic 74 | mpls_service_label : 20; 75 | bos_tc : 3; 76 | bos_s : 1; 77 | bos_ttl : 8; 78 | 79 | // MPLS next hop node label for this traffic 80 | mpls_next_node_label : 20; 81 | non_bos_tc : 3; 82 | non_bos_s : 1; 83 | non_bos_ttl : 8; 84 | 85 | // Topmost MPLS label 86 | mpls_top_label : 20; 87 | top_tc : 3; 88 | top_s : 1; 89 | top_ttl : 8; 90 | 91 | // Number of MPLS labels extracted 92 | // Use only after checking that the packet source of serviceedge_md 93 | // is PACKET_SOURCE_TRANSPORT_SR 94 | in_stack_depth : 3; 95 | in_bos_parsed : 1; 96 | 97 | in_service_tag_type : 4; 98 | 99 | enabled : 1; 100 | pad_0 : 7; 101 | 102 | in_classifier : 8; 103 | } 104 | } 105 | 106 | header_type mcast_md_t { 107 | fields { 108 | is_multicast : 1; 109 | pad_0 : 7; 110 | in_classifier : 8; 111 | } 112 | } 113 | 114 | header_type qos_md_t { 115 | fields { 116 | pad_0 : 5; 117 | phb : 3; 118 | } 119 | } 120 | 121 | header_type l2_md_t { 122 | fields { 123 | in_ok : 1; 124 | pad_0 : 7; 125 | in_classifier : 8; 126 | } 127 | } 128 | 129 | header_type ip_md_t { 130 | fields { 131 | in_classifier_dst : 8; 132 | in_classifier_src : 8; 133 | in_ipv4_classifier_dst : 8; 134 | in_ipv4_classifier_src : 8; 135 | in_ipv6_classifier_dst : 8; 136 | in_ipv6_classifier_src : 8; 137 | vrf : 8; 138 | } 139 | } 140 | 141 | 142 | /************************************************************************* 143 | *********************** H E A D E R S ********************************* 144 | *************************************************************************/ 145 | 146 | header_type cpu_header_t { 147 | fields { 148 | handling_type: 8; 149 | reason: 8; 150 | pcr_bng_access_node_id: 8; 151 | pcr_bng_access_node_mpls_label : 20; 152 | padding: 4; 153 | pcr_bng_session_id: 16; 154 | etherType: 16; 155 | } 156 | } 157 | 158 | header_type ethernet_t { 159 | fields { 160 | dstAddr : 48; 161 | srcAddr : 48; 162 | etherType : 16; 163 | } 164 | } 165 | 166 | header_type mpls_t { 167 | fields { 168 | label : 20; 169 | tc : 3; 170 | s : 1; 171 | ttl : 8; 172 | } 173 | } 174 | 175 | header_type vlan_t { 176 | fields { 177 | pcp : 3; 178 | dei : 1; 179 | vlanID: 12; 180 | etherType: 16; 181 | } 182 | } 183 | 184 | header_type ipv4_t { 185 | fields { 186 | #ifndef SELECT_MOVING_OFFSET 187 | version : 4; 188 | #endif 189 | ihl : 4; 190 | phb : 3; 191 | dscp : 3; 192 | ecn : 2; 193 | totalLen : 16; 194 | identification : 16; 195 | flags : 3; 196 | fragOffset : 13; 197 | ttl : 8; 198 | protocol : 8; 199 | hdrChecksum : 16; 200 | srcAddr : 32; 201 | dstAddr: 32; 202 | } 203 | } 204 | 205 | header_type ipv6_t { 206 | fields { 207 | #ifndef SELECT_MOVING_OFFSET 208 | version : 4; 209 | #endif 210 | phb : 3; 211 | dscp : 3; 212 | ecn : 2; 213 | flowLabel : 20; 214 | payloadLen : 16; 215 | nextHdr : 8; 216 | hopLimit : 8; 217 | srcAddr : 128; 218 | dstAddr : 128; 219 | } 220 | } 221 | 222 | //@pragma header_ordering ethernet ipv4 ipv4_option_security ipv4_option_NOP ipv4_option_timestamp ipv4_option_EOL 223 | 224 | /************************************************************************* 225 | *************** C A L C U L A T E D F I E L D S *********************** 226 | *************************************************************************/ 227 | 228 | 229 | field_list ipv4_field_list { 230 | ipv4.version; 231 | ipv4.ihl; 232 | ipv4.phb; 233 | ipv4.dscp; 234 | ipv4.ecn; 235 | ipv4.totalLen; 236 | ipv4.identification; 237 | ipv4.flags; 238 | ipv4.fragOffset; 239 | ipv4.ttl; 240 | ipv4.protocol; 241 | ipv4.srcAddr; 242 | ipv4.dstAddr; 243 | } 244 | 245 | field_list_calculation ipv4_chksum_calc { 246 | input { 247 | ipv4_field_list; 248 | } 249 | algorithm : csum16; 250 | output_width: 16; 251 | } 252 | 253 | calculated_field ipv4.hdrChecksum { 254 | verify ipv4_chksum_calc; 255 | update ipv4_chksum_calc; 256 | } 257 | 258 | field_list error_fields { 259 | cpu_md.handling_type; 260 | cpu_md.reason_code; 261 | cpu_md.expected_value; 262 | cpu_md.actual_value; 263 | cpu_md.meter_id; 264 | serviceedge_md.in_net_proto; 265 | serviceedge_md.fwd_net_proto; 266 | serviceedge_md.out_net_proto; 267 | serviceedge_md.processor_ingress; 268 | serviceedge_md.processor_egress; 269 | serviceedge_md.next_hop_id; 270 | pcr_bng_md.access_node_id; 271 | pcr_bng_md.session_id; 272 | } 273 | 274 | /************************************************************************* 275 | *********************** P A R S E R *********************************** 276 | *************************************************************************/ 277 | 278 | metadata serviceedge_md_t serviceedge_md; 279 | metadata cpu_md_t cpu_md; 280 | metadata sr_md_t sr_md; 281 | metadata mcast_md_t mcast_md; 282 | metadata qos_md_t qos_md; 283 | metadata l2_md_t l2_md; 284 | 285 | metadata ip_md_t ip_md; 286 | 287 | header cpu_header_t cpu_header; 288 | 289 | header ethernet_t ethernet_outer; 290 | header mpls_t mpls[7]; 291 | header mpls_t mpls_bos; 292 | 293 | header ethernet_t ethernet_inner; 294 | 295 | header vlan_t vlan_subsc; 296 | header vlan_t vlan_service; 297 | 298 | header ipv4_t ipv4; 299 | header ipv6_t ipv6; 300 | 301 | #define MPLS_BOS current(23, 1) 302 | @pragma parser_value_set_size 2 303 | parser_value_set mpls_service_subscriber_tunnel; 304 | @pragma parser_value_set_size 2 305 | parser_value_set mpls_service_ip; 306 | 307 | parser start { 308 | set_metadata(sr_md.bos_s, 1); 309 | set_metadata(sr_md.non_bos_s, 0); 310 | return parse_ethernet_outer; 311 | } 312 | 313 | parser parse_ethernet_outer { 314 | extract(ethernet_outer); 315 | return select(latest.etherType) { 316 | ETHERTYPE_MPLS : parse_mpls; 317 | ETHERTYPE_IPV4 : parse_ipv4; 318 | ETHERTYPE_IPV6 : parse_ipv6; 319 | ETHERTYPE_CPUHEADER : parse_cpu_header; 320 | default: ingress; 321 | } 322 | } 323 | 324 | parser parse_cpu_header { 325 | extract(cpu_header); 326 | return select(latest.etherType) { 327 | ETHERTYPE_MPLS : parse_mpls; 328 | ETHERTYPE_IPV4 : parse_ipv4; 329 | ETHERTYPE_IPV6 : parse_ipv6; 330 | ETHERTYPE_VLAN : parse_vlan_subsc; 331 | default: ingress; 332 | } 333 | } 334 | 335 | parser parse_mpls { 336 | return select(MPLS_BOS) { 337 | 0: parse_mpls_non_bos; 338 | 1: parse_mpls_bos; 339 | } 340 | } 341 | 342 | parser parse_mpls_non_bos { 343 | extract(mpls[next]); 344 | return parse_mpls; 345 | } 346 | 347 | parser parse_mpls_bos { 348 | extract(mpls_bos); 349 | return select (latest.label) { 350 | mpls_service_subscriber_tunnel : parse_mpls_service_subscriber_tunnel; 351 | mpls_service_ip : parse_mpls_service_ip; 352 | default : ingress; 353 | } 354 | } 355 | 356 | parser parse_mpls_service_subscriber_tunnel { 357 | set_metadata(sr_md.in_service_tag_type, SR_SERVICE_TYPE_SUBSCRIBER_TUNNEL); 358 | return parse_ethernet_inner; 359 | } 360 | 361 | parser parse_mpls_service_ip { 362 | set_metadata(sr_md.in_service_tag_type, SR_SERVICE_TYPE_IP); 363 | return parse_ip; 364 | } 365 | 366 | parser parse_ethernet_inner { 367 | extract(ethernet_inner); 368 | return select(latest.etherType) { 369 | ETHERTYPE_VLAN : parse_vlan_subsc; 370 | //TODO: check which double-tagging ethtype format must be used. 371 | // alternatively allow both tags or use PVST 372 | default: ingress; 373 | } 374 | } 375 | 376 | parser parse_vlan_subsc { 377 | extract(vlan_subsc); 378 | return select(latest.etherType) { 379 | ETHERTYPE_VLAN : parse_vlan_service; 380 | //In this case we have no service field 381 | ETHERTYPE_PPPOED : parse_pppoed; 382 | ETHERTYPE_PPPOES : parse_pppoes; 383 | default: ingress; 384 | } 385 | } 386 | 387 | parser parse_vlan_service { 388 | extract(vlan_service); 389 | return select(latest.etherType) { 390 | ETHERTYPE_PPPOED : parse_pppoed; 391 | ETHERTYPE_PPPOES : parse_pppoes; 392 | default: ingress; 393 | } 394 | } 395 | 396 | parser parse_pppoed { 397 | extract(pppoe); 398 | set_metadata(pppoe_md.ppp_proto, PPPOE_PROTO_DISCOVERY); 399 | return ingress; 400 | } 401 | 402 | parser parse_pppoes { 403 | extract(pppoe); 404 | extract(pppoes_protocol); 405 | set_metadata(pppoe_md.ppp_proto, PPPOE_PROTO_SESSION); 406 | return select(latest.protocol) { 407 | PPPOE_PROTOCOL_IPV4: parse_ipv4; 408 | PPPOE_PROTOCOL_IPV6: parse_ipv6; 409 | default: ingress; 410 | } 411 | } 412 | 413 | parser parse_ip { 414 | //We cannot get the IP version from the ethertype or MPLS label. Thus, get it 415 | //from the IP packet's first 4 bytes. 416 | return select(current(0, 4)) { 417 | 4 : parse_ipv4; 418 | 6 : parse_ipv6; 419 | default : ingress; 420 | } 421 | } 422 | 423 | parser parse_ipv4 { 424 | extract(ipv4); 425 | return select(ipv4.ihl) { 426 | default : ingress; 427 | } 428 | } 429 | 430 | parser parse_ipv6 { 431 | extract(ipv6); 432 | return ingress; 433 | } 434 | 435 | 436 | -------------------------------------------------------------------------------- /fabric/p4src/pppoe.p4: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present Open Networking Foundation 3 | * 4 | * Contributed and sponsored by Deutsche Telekom AG. 5 | * Originally developed as part of the D-Nets 6 P4 Service Edge project 6 | * in collaboration with Technische Universitaet Darmstadt. 7 | * Authors: Jeremias Blendin, Leonhard Nobach 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * For details see the file LICENSE in the top project directory. 22 | */ 23 | 24 | 25 | #define PPPOE_PROTO_DISCOVERY 0 26 | #define PPPOE_PROTO_SESSION 1 27 | 28 | 29 | header_type pppoe_md_t { 30 | fields { 31 | ppp_proto : 1; 32 | pad_1: 7; 33 | protocol : 16; // PPP protocol field 34 | totalLength : 16; // PPP lengths field 35 | mru : 16; // PPP maximum receive unit (RFC 4638) 36 | mru_check : 16 (saturating); 37 | } 38 | } 39 | 40 | header_type pppoe_t { 41 | fields { 42 | version : 4; 43 | typeID : 4; 44 | code : 8; 45 | sessionID : 16; 46 | totalLength : 16; 47 | } 48 | } 49 | 50 | header_type pppoes_protocol_t { 51 | fields { 52 | protocol : 16; 53 | /* 54 | * See http://www.iana.org/assignments/ppp-numbers/ppp-numbers.xhtml 55 | * Dataplane: IP: 0021, IPv6: 0057, 56 | * Control plane: LCP: c021, IPv6CP: 8057 57 | */ 58 | } 59 | } 60 | 61 | header pppoe_t pppoe; 62 | header pppoes_protocol_t pppoes_protocol; 63 | -------------------------------------------------------------------------------- /fabric/p4src/processor_bng.p4: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present Open Networking Foundation 3 | * 4 | * Contributed and sponsored by Deutsche Telekom AG. 5 | * Originally developed as part of the D-Nets 6 P4 Service Edge project 6 | * in collaboration with Technische Universitaet Darmstadt. 7 | * Authors: Jeremias Blendin, Leonhard Nobach 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * For details see the file LICENSE in the top project directory. 22 | */ 23 | 24 | /************************************************************************* 25 | **************************** D E F I N E S ****************************** 26 | *************************************************************************/ 27 | 28 | #define PCR_BNG_DIRECTION_UNDEF 0 29 | #define PCR_BNG_DIRECTION_DS 1 30 | #define PCR_BNG_DIRECTION_US 2 31 | 32 | #define IPV6_ADDR_TYPE_LL_64 0 33 | #define IPV6_ADDR_TYPE_GU_64 1 34 | #define IPV6_ADDR_TYPE_GU_56 2 35 | #define IPV4_ADDR_TYPE_GU_32 3 36 | 37 | #define LINE_CAPACITY 4096 38 | #define LINE_CAPACITY_BITS 14 39 | #define SUBSC_CAPACITY 4096 40 | #define SUBSC_CAPACITY_x2 8192 41 | #define SUBSC_CAPACITY_x3 12288 42 | #define SUBSC_CAPACITY_x4 16384 43 | #define SUBSC_CAPACITY_BITS 14 44 | 45 | /************************************************************************* 46 | *********************** H E A D E R S ********************************* 47 | *************************************************************************/ 48 | 49 | 50 | /* 51 | * Metadata for the BNG processor 52 | */ 53 | header_type pcr_bng_md_t { 54 | fields { 55 | // Store src or dst address for direction-agnostic matching 56 | address_ipv6 : 128; 57 | pad_1 : 7; 58 | session_established : 1; 59 | address_ipv4 : 32; 60 | 61 | session_id : 16; // set either by bng address matcher or by the bng processor 62 | 63 | access_node_id : 8; 64 | access_node_tunnel_mpls_label : 20; 65 | pad_2 : 4; 66 | 67 | subscr_cpe_pppoe_session : 16; 68 | 69 | //traffic_type : 2; 70 | direction : 2; 71 | // IPv6 prefix matcher space compression 72 | ipv6_prefix_id : 2; 73 | // Address type: see IPV6_ADDR_TYPE_* 74 | address_type : 2; 75 | pad_3 : 2; 76 | 77 | us_access_node_id : 8; // US: set in line match table 78 | us_vlan_id : 8; // US: set in line match table 79 | us_line_session_id : 16; // US: set in line match table 80 | us_line_session_id_check : 16; // US: set in line match table 81 | 82 | // Check bits 83 | address_match_ok : 1; 84 | mtu_check_ok : 1; 85 | us_cpe_match_ok : 1; 86 | us_line_match_ok : 1; 87 | 88 | ds_packet_color : 2; 89 | 90 | pad_4 : 2; 91 | } 92 | } 93 | 94 | header_type pcr_bng_vlan_md_t { 95 | fields { 96 | vlan_outer_pcp : 3; 97 | vlan_outer_dei : 1; 98 | vlan_outer_id : 12; 99 | vlan_outer_etherType : 16; 100 | 101 | vlan_inner_pcp : 3; 102 | vlan_inner_dei : 1; 103 | vlan_inner_id : 12; 104 | vlan_inner_etherType : 16; 105 | } 106 | } 107 | 108 | metadata pcr_bng_md_t pcr_bng_md; 109 | 110 | metadata pcr_bng_vlan_md_t pcr_bng_vlan_md; 111 | 112 | metadata pppoe_md_t pppoe_md; 113 | 114 | /************************************************************************* 115 | ********************** T A B L E S & A C T I O N S ********************** 116 | *************************************************************************/ 117 | 118 | // === Classifier actions for this processor 119 | 120 | action a_in_select_processor_bng() { 121 | modify_field(serviceedge_md.processor_ingress, PROCESSOR_BNG); 122 | modify_field(serviceedge_md.processor_egress, PROCESSOR_BNG); 123 | } 124 | 125 | 126 | action a_in_select_processor_bng_ds_ipv4(vrf) { 127 | a_in_select_processor_bng(); 128 | modify_field(pcr_bng_md.direction, PCR_BNG_DIRECTION_DS); 129 | remove_header(mpls_bos); 130 | remove_header(mpls[0]); 131 | 132 | modify_field(ethernet_outer.etherType, ETHERTYPE_IPV4); 133 | modify_field(ethernet_inner.etherType, ETHERTYPE_IPV4); 134 | 135 | modify_field(pcr_bng_md.address_type, IPV4_ADDR_TYPE_GU_32); 136 | modify_field(pcr_bng_md.address_ipv4, ipv4.dstAddr); 137 | 138 | add(pppoe_md.totalLength, ipv4.totalLen, 2); 139 | modify_field(pppoe_md.protocol, 0x0021); 140 | modify_field(pppoe_md.ppp_proto, PPPOE_PROTO_SESSION); 141 | modify_field(pcr_bng_vlan_md.vlan_inner_etherType, ETHERTYPE_PPPOES); 142 | 143 | modify_field(ip_md.vrf, vrf); 144 | } 145 | 146 | action a_in_select_processor_bng_ds_ipv6(address_type, prefix_id, vrf) { 147 | a_in_select_processor_bng(); 148 | modify_field(pcr_bng_md.direction, PCR_BNG_DIRECTION_DS); 149 | remove_header(mpls_bos); 150 | remove_header(mpls[0]); 151 | 152 | modify_field(ethernet_outer.etherType, ETHERTYPE_IPV6); 153 | modify_field(ethernet_inner.etherType, ETHERTYPE_IPV6); 154 | 155 | modify_field(pcr_bng_md.address_type, address_type); 156 | modify_field(pcr_bng_md.ipv6_prefix_id, prefix_id); 157 | modify_field(pcr_bng_md.address_ipv6, ipv6.dstAddr); 158 | 159 | add(pppoe_md.totalLength, ipv6.payloadLen, 42); 160 | modify_field(pppoe_md.protocol, 0x0057); 161 | modify_field(pppoe_md.ppp_proto, PPPOE_PROTO_SESSION); 162 | modify_field(pcr_bng_vlan_md.vlan_inner_etherType, ETHERTYPE_PPPOES); 163 | 164 | modify_field(ip_md.vrf, vrf); 165 | } 166 | 167 | action a_in_select_processor_bng_us_ipv4(vrf) { 168 | a_in_select_processor_bng(); 169 | modify_field(pcr_bng_md.direction, PCR_BNG_DIRECTION_US); 170 | remove_header(mpls_bos); 171 | remove_header(mpls[0]); 172 | 173 | modify_field(ethernet_outer.etherType, ETHERTYPE_IPV4); 174 | modify_field(ethernet_inner.etherType, ETHERTYPE_IPV4); 175 | 176 | modify_field(pcr_bng_md.address_type, IPV4_ADDR_TYPE_GU_32); 177 | modify_field(pcr_bng_md.address_ipv4, ipv4.srcAddr); 178 | 179 | modify_field(pppoe_md.protocol, pppoes_protocol.protocol); 180 | modify_field(pppoe_md.totalLength, pppoe.totalLength); 181 | modify_field(pppoe_md.ppp_proto, PPPOE_PROTO_SESSION); 182 | 183 | modify_field(ip_md.vrf, vrf); 184 | } 185 | 186 | action a_in_select_processor_bng_us_ipv6(address_type, prefix_id, vrf) { 187 | a_in_select_processor_bng(); 188 | modify_field(pcr_bng_md.direction, PCR_BNG_DIRECTION_US); 189 | remove_header(mpls_bos); 190 | remove_header(mpls[0]); 191 | 192 | modify_field(ethernet_outer.etherType, ETHERTYPE_IPV6); 193 | modify_field(ethernet_inner.etherType, ETHERTYPE_IPV6); 194 | 195 | modify_field(pcr_bng_md.address_type, address_type); 196 | modify_field(pcr_bng_md.ipv6_prefix_id, prefix_id); 197 | modify_field(pcr_bng_md.address_ipv6, ipv6.srcAddr); 198 | 199 | modify_field(pppoe_md.protocol, pppoes_protocol.protocol); 200 | modify_field(pppoe_md.totalLength, pppoe.totalLength); 201 | modify_field(pppoe_md.ppp_proto, PPPOE_PROTO_SESSION); 202 | 203 | modify_field(ip_md.vrf, vrf); 204 | } 205 | 206 | action a_in_select_processor_bng_us_pppoed() { 207 | a_in_select_processor_bng(); 208 | modify_field(pcr_bng_md.direction, PCR_BNG_DIRECTION_US); 209 | 210 | modify_field(pppoe_md.totalLength, pppoe.totalLength); 211 | modify_field(pppoe_md.ppp_proto, PPPOE_PROTO_DISCOVERY); 212 | } 213 | 214 | action a_in_select_processor_bng_ds_pppoed() { 215 | modify_field(serviceedge_md.processor_egress, PROCESSOR_BNG); 216 | modify_field(serviceedge_md.in_net_proto, NET_PROTO_CP); 217 | modify_field(serviceedge_md.fwd_net_proto, NET_PROTO_CP); 218 | modify_field(pcr_bng_md.access_node_id, cpu_header.pcr_bng_access_node_id); 219 | modify_field(pcr_bng_md.session_id, cpu_header.pcr_bng_session_id); 220 | modify_field(pcr_bng_md.direction, PCR_BNG_DIRECTION_DS); 221 | 222 | modify_field(pppoe_md.totalLength, pppoe.totalLength); 223 | modify_field(pppoe_md.ppp_proto, PPPOE_PROTO_DISCOVERY); 224 | modify_field(pcr_bng_vlan_md.vlan_inner_etherType, ETHERTYPE_PPPOED); 225 | 226 | remove_header(cpu_header); 227 | modify_field(ethernet_outer.etherType, ETHERTYPE_VLAN); 228 | modify_field(ethernet_inner.etherType, ETHERTYPE_VLAN); 229 | } 230 | 231 | action a_in_select_processor_bng_ds_ipv6_fromcp(address_type, prefix_id, vrf) { 232 | a_in_select_processor_bng(); 233 | modify_field(serviceedge_md.in_net_proto, NET_PROTO_CP); 234 | modify_field(serviceedge_md.fwd_net_proto, NET_PROTO_IP); 235 | modify_field(pcr_bng_md.access_node_id, cpu_header.pcr_bng_access_node_id); 236 | modify_field(pcr_bng_md.session_id, cpu_header.pcr_bng_session_id); 237 | modify_field(pcr_bng_md.direction, PCR_BNG_DIRECTION_DS); 238 | modify_field(pcr_bng_md.address_type, address_type); 239 | modify_field(pcr_bng_md.ipv6_prefix_id, prefix_id); 240 | modify_field(pcr_bng_md.address_ipv6, ipv6.dstAddr); 241 | 242 | remove_header(cpu_header); 243 | modify_field(ethernet_outer.etherType, ETHERTYPE_IPV6); 244 | modify_field(ethernet_inner.etherType, ETHERTYPE_IPV6); 245 | 246 | add(pppoe_md.totalLength, ipv6.payloadLen, 42); 247 | modify_field(pppoe_md.protocol, 0x0057); 248 | modify_field(pppoe_md.ppp_proto, PPPOE_PROTO_SESSION); 249 | modify_field(pcr_bng_vlan_md.vlan_inner_etherType, ETHERTYPE_PPPOES); 250 | 251 | modify_field(ip_md.vrf, vrf); 252 | } 253 | 254 | /************************************** 255 | * Upstream (Subscriber -> Core or Subscriber -> Subscriber) 256 | *************************************/ 257 | 258 | 259 | // ===== t_pcr_bng_us_line_map 260 | 261 | table t_pcr_bng_us_line_map { 262 | reads { 263 | sr_md.mpls_service_label : exact; 264 | vlan_subsc.vlanID : exact; 265 | } 266 | actions { 267 | a_pcr_bng_us_line_map_pass; 268 | a_pcr_bng_us_line_map_fail; 269 | } 270 | size : SUBSC_CAPACITY; 271 | } 272 | 273 | action a_pcr_bng_us_line_map_pass(session_id, access_node_id, mru) { 274 | modify_field(pcr_bng_md.us_access_node_id, access_node_id); 275 | modify_field(pcr_bng_md.us_line_session_id, session_id); 276 | modify_field(pcr_bng_md.us_line_match_ok, TRUE); 277 | 278 | subtract(pcr_bng_md.us_line_session_id_check, session_id, pcr_bng_md.session_id); 279 | 280 | subtract(pppoe_md.mru_check, mru, pppoe_md.totalLength); 281 | } 282 | action a_pcr_bng_us_line_map_fail() { 283 | modify_field(pcr_bng_md.us_line_match_ok, FALSE); 284 | } 285 | 286 | // ===== t_pcr_bng_us_antispoof_mac 287 | 288 | table t_pcr_bng_us_antispoof_mac { 289 | reads { 290 | pcr_bng_md.us_line_session_id : exact; 291 | ethernet_inner.srcAddr : exact; 292 | } 293 | actions { 294 | a_pcr_bng_us_antispoof_mac_pass; 295 | a_pcr_bng_us_antispoof_mac_fail; 296 | } 297 | size : SUBSC_CAPACITY; 298 | } 299 | 300 | action a_pcr_bng_us_antispoof_mac_pass() { 301 | modify_field(pcr_bng_md.us_cpe_match_ok, TRUE); 302 | } 303 | action a_pcr_bng_us_antispoof_mac_fail() { 304 | modify_field(pcr_bng_md.us_cpe_match_ok, FALSE); 305 | } 306 | 307 | // ===== t_pcr_bng_mtu_init/check 308 | /* 309 | TODO: MRU/MTU check for the tunnel should be done in 310 | the processor. 311 | table t_pcr_bng_mru_check_failed { 312 | actions { 313 | a_pcr_bng_mtu_too_big; 314 | } 315 | } 316 | 317 | action a_pcr_bng_mtu_too_big() { 318 | ingress_pkt_too_big(); 319 | } 320 | */ 321 | // ===== t_pcr_bng_us_verify 322 | 323 | table t_pcr_bng_us_verify { 324 | /* 325 | * Packets matched by this table have been checked for equality of 326 | * pcr_bng_md.in_line_session_id and session_id, and was as 327 | * pcr_bng_md.in_line_session_id_ok == 1 328 | */ 329 | reads { 330 | pcr_bng_md.address_type : ternary; 331 | pcr_bng_md.address_match_ok : ternary; 332 | pcr_bng_md.us_cpe_match_ok : ternary; 333 | pcr_bng_md.us_line_match_ok : ternary; 334 | ethernet_inner.dstAddr : ternary; 335 | vlan_service.vlanID : ternary; 336 | vlan_service.etherType : ternary; 337 | pppoe_md.mru_check : ternary; 338 | pppoe_md.protocol : ternary; 339 | pppoe_md.ppp_proto : ternary; 340 | } 341 | actions { 342 | _drop; 343 | a_pcr_bng_accept_us_session; 344 | } 345 | size : IN_CLASSIFY_TABLE_SIZE; 346 | } 347 | 348 | table t_pcr_bng_verify { 349 | reads { 350 | pcr_bng_md.direction : ternary; 351 | pcr_bng_md.address_type : ternary; 352 | pcr_bng_md.address_match_ok : ternary; 353 | pcr_bng_md.us_cpe_match_ok : ternary; 354 | pcr_bng_md.us_line_match_ok : ternary; 355 | ethernet_inner.dstAddr : ternary; 356 | vlan_service.vlanID : ternary; 357 | vlan_service.etherType : ternary; 358 | pppoe_md.mru_check : ternary; 359 | pppoe_md.protocol : ternary; 360 | pppoe_md.ppp_proto : ternary; 361 | } 362 | actions { 363 | _drop; 364 | a_pcr_bng_accept_us_no_session; 365 | a_pcr_bng_accept_ds; 366 | } 367 | size : IN_CLASSIFY_TABLE_SIZE; 368 | } 369 | 370 | action a_pcr_bng_accept() { 371 | modify_field(cpu_md.meter_id, pcr_bng_md.session_id); 372 | modify_field(pppoe_md.ppp_proto, PPPOE_PROTO_SESSION); 373 | } 374 | 375 | action a_pcr_bng_accept_us() { 376 | remove_header(vlan_subsc); 377 | remove_header(vlan_service); 378 | copy_header(ethernet_outer, ethernet_inner); 379 | remove_header(ethernet_inner); 380 | remove_header(pppoe); 381 | remove_header(pppoes_protocol); 382 | } 383 | 384 | action a_pcr_bng_accept_us_session() { 385 | a_pcr_bng_accept_us(); 386 | modify_field(pcr_bng_md.session_established, TRUE); 387 | modify_field(serviceedge_md.fwd_net_proto, NET_PROTO_IP); 388 | modify_field(cpu_md.meter_id, pcr_bng_md.session_id); 389 | } 390 | 391 | action a_pcr_bng_accept_us_no_session() { 392 | modify_field(pppoe_md.ppp_proto, PPPOE_PROTO_DISCOVERY); 393 | modify_field(serviceedge_md.fwd_net_proto, NET_PROTO_CP); 394 | modify_field(pcr_bng_md.access_node_id, pcr_bng_md.us_access_node_id); 395 | modify_field(pcr_bng_md.session_id, pcr_bng_md.us_line_session_id); 396 | modify_field(cpu_md.handling_type, HANDLING_TYPE_PRC_DS_CP); 397 | modify_field(cpu_md.meter_id, pcr_bng_md.us_line_session_id); 398 | } 399 | 400 | action a_pcr_bng_accept_ds() { 401 | a_pcr_bng_accept(); 402 | modify_field(pcr_bng_md.session_established, TRUE); 403 | modify_field(serviceedge_md.fwd_net_proto, NET_PROTO_IP); 404 | } 405 | 406 | // ===== direction-agnostic classification of IPs to Subscriber sessions 407 | 408 | table t_pcr_bng_subsc_match_ipv4 { 409 | reads { 410 | pcr_bng_md.address_ipv4 : exact; 411 | } 412 | action_profile : ap_pcr_bng_set_subscriber_id; 413 | size : SUBSC_CAPACITY; 414 | } 415 | 416 | // ===== t_ds_subsc_match_ipv6 417 | 418 | table t_pcr_bng_subsc_match_ipv6_net64_ll { 419 | reads { 420 | pcr_bng_md.address_ipv6 mask 0x0000000000000000ffffffffffffffff: exact; 421 | } 422 | action_profile : ap_pcr_bng_set_subscriber_id; 423 | size : SUBSC_CAPACITY; 424 | } 425 | 426 | table t_pcr_bng_subsc_match_ipv6_net64 { 427 | reads { 428 | pcr_bng_md.ipv6_prefix_id : exact; 429 | pcr_bng_md.address_ipv6 mask 0x0000000000003fff0000000000000000 : exact; 430 | } 431 | action_profile : ap_pcr_bng_set_subscriber_id; 432 | size : SUBSC_CAPACITY; 433 | } 434 | 435 | table t_pcr_bng_subsc_match_ipv6_net56 { 436 | reads { 437 | pcr_bng_md.ipv6_prefix_id : exact; 438 | pcr_bng_md.address_ipv6 mask 0x00000000003fff000000000000000000: exact; 439 | } 440 | action_profile : ap_pcr_bng_set_subscriber_id; 441 | size : SUBSC_CAPACITY; 442 | } 443 | 444 | // ==== Tag subscriber traffic 445 | 446 | 447 | action_profile ap_pcr_bng_set_subscriber_id { 448 | actions { 449 | a_pcr_bng_no_match; 450 | a_pcr_bng_set_subscriber_id; 451 | } 452 | size : SUBSC_CAPACITY; 453 | } 454 | 455 | action a_pcr_bng_no_match() { 456 | modify_field(pcr_bng_md.address_match_ok, FALSE); 457 | } 458 | 459 | action a_pcr_bng_set_subscriber_data(session_id, 460 | access_node_id, 461 | access_node_tunnel_mpls_label, 462 | subscr_cpe_pppoe_session) { 463 | modify_field(pcr_bng_md.session_id, session_id); 464 | modify_field(pcr_bng_md.access_node_id, access_node_id); 465 | modify_field(pcr_bng_md.access_node_tunnel_mpls_label, access_node_tunnel_mpls_label); 466 | modify_field(pcr_bng_md.subscr_cpe_pppoe_session, subscr_cpe_pppoe_session); 467 | } 468 | 469 | action a_pcr_bng_set_subscriber_id(session_id, 470 | access_node_id, 471 | access_node_tunnel_mpls_label, 472 | subscr_cpe_pppoe_session, 473 | mru) { 474 | a_pcr_bng_set_subscriber_data(session_id, 475 | access_node_id, 476 | access_node_tunnel_mpls_label, 477 | subscr_cpe_pppoe_session); 478 | 479 | modify_field(pcr_bng_md.address_match_ok, TRUE); 480 | /* 481 | * set mru to mru+1, if mru_check is 0, the packet is considered too large 482 | */ 483 | subtract(pppoe_md.mru_check, mru, pppoe_md.totalLength); 484 | } 485 | 486 | // ==== Forwarding Actions 487 | 488 | action a_pcr_bng_forward_tocp_us() { 489 | modify_field(serviceedge_md.next_hop_id, NEXT_HOP_CP); 490 | modify_field(serviceedge_md.out_net_proto, NET_PROTO_CP); 491 | 492 | modify_field(sr_md.mpls_service_label, pcr_bng_md.access_node_tunnel_mpls_label); 493 | modify_field(cpu_md.handling_type, HANDLING_TYPE_PRC_DS_CP); 494 | } 495 | 496 | action a_pcr_bng_forward_fromcp_ds() { 497 | modify_field(serviceedge_md.next_hop_id, cpu_header.pcr_bng_access_node_id); 498 | modify_field(serviceedge_md.out_net_proto, NET_PROTO_SR); 499 | modify_field(sr_md.mpls_service_label, cpu_header.pcr_bng_access_node_mpls_label); 500 | } 501 | 502 | action a_pcr_bng_forward_nexthop_sr_bng_ds() { 503 | modify_field(serviceedge_md.out_net_proto, NET_PROTO_SR); 504 | modify_field(sr_md.mpls_service_label, pcr_bng_md.access_node_tunnel_mpls_label); 505 | modify_field(serviceedge_md.next_hop_id, pcr_bng_md.access_node_id); 506 | } 507 | 508 | action a_pcr_bng_forward_ipv4_nexthop_sr_bng_ds() { 509 | a_pcr_bng_forward_nexthop_sr_bng_ds(); 510 | add_to_field(ipv4.ttl, -1); 511 | } 512 | 513 | action a_pcr_bng_forward_ipv6_nexthop_sr_bng_ds() { 514 | a_pcr_bng_forward_nexthop_sr_bng_ds(); 515 | add_to_field(ipv6.hopLimit, -1); 516 | } 517 | 518 | 519 | // ==== Tag multicast traffic 520 | 521 | table t_pcr_bng_mcast_egress { 522 | reads { 523 | ig_intr_md_for_tm.mcast_grp_a : exact; 524 | eg_intr_md.egress_port : exact; 525 | eg_intr_md.egress_rid : exact; 526 | } 527 | action_profile : ap_pcr_bng_mcast_set_subscriber_id; 528 | size : SUBSC_CAPACITY_x2; 529 | } 530 | 531 | 532 | action_profile ap_pcr_bng_mcast_set_subscriber_id { 533 | actions { 534 | _drop; 535 | a_pcr_bng_mcast_set_subscriber_id; 536 | } 537 | size : SUBSC_CAPACITY; 538 | } 539 | 540 | action a_pcr_bng_mcast_set_subscriber_id(session_id, 541 | access_node_id, 542 | access_node_tunnel_mpls_label, 543 | subscr_cpe_pppoe_session) { 544 | a_pcr_bng_set_subscriber_data(session_id, 545 | access_node_id, 546 | access_node_tunnel_mpls_label, 547 | subscr_cpe_pppoe_session); 548 | modify_field(serviceedge_md.next_hop_id, access_node_id); 549 | modify_field(sr_md.mpls_service_label, access_node_tunnel_mpls_label); 550 | } 551 | 552 | // ==== Add transport headers for downstream traffic 553 | 554 | table t_pcr_bng_ds_set_session { 555 | reads { 556 | pcr_bng_md.session_id : exact; 557 | } 558 | actions { 559 | _drop; 560 | a_pcr_bng_ds_set_session; 561 | } 562 | size : SUBSC_CAPACITY; 563 | } 564 | 565 | action a_pcr_bng_ds_set_session(subscr_cpe_mac, subscr_vid) { 566 | add_header(ethernet_inner); 567 | modify_field(ethernet_inner.dstAddr, subscr_cpe_mac); 568 | modify_field(ethernet_inner.etherType, ETHERTYPE_VLAN); 569 | 570 | modify_field(pcr_bng_vlan_md.vlan_outer_id, subscr_vid); 571 | modify_field(pcr_bng_vlan_md.vlan_outer_etherType, ETHERTYPE_VLAN); 572 | 573 | modify_field(pcr_bng_vlan_md.vlan_inner_id, VLAN_SERVICE_VID); 574 | //modify_field(pcr_bng_vlan_md.vlan_inner_etherType, ETHERTYPE_PPPOED); 575 | } 576 | 577 | table t_pcr_bng_ds_pushstack_vlan { 578 | actions { 579 | a_pcr_bng_ds_pushstack_vlan; 580 | } 581 | } 582 | 583 | action a_pcr_bng_ds_pushstack_vlan() { 584 | add_header(vlan_subsc); 585 | modify_field(vlan_subsc.vlanID, pcr_bng_vlan_md.vlan_outer_id); 586 | modify_field(vlan_subsc.pcp, pcr_bng_vlan_md.vlan_outer_pcp); 587 | modify_field(vlan_subsc.dei, pcr_bng_vlan_md.vlan_outer_dei); 588 | modify_field(vlan_subsc.etherType, pcr_bng_vlan_md.vlan_outer_etherType); 589 | 590 | add_header(vlan_service); 591 | modify_field(vlan_service.vlanID, pcr_bng_vlan_md.vlan_inner_id); 592 | modify_field(vlan_service.pcp, pcr_bng_vlan_md.vlan_inner_pcp); 593 | modify_field(vlan_service.dei, pcr_bng_vlan_md.vlan_inner_dei); 594 | modify_field(vlan_service.etherType,pcr_bng_vlan_md.vlan_inner_etherType); 595 | } 596 | 597 | table t_pcr_bng_ds_pushstack_session_pppoes { 598 | actions { 599 | a_pcr_bng_ds_pushstack_session_pppoes; 600 | } 601 | size : SUBSC_CAPACITY; 602 | } 603 | 604 | action a_pcr_bng_ds_pushstack_session_pppoes() { 605 | //modify_field(vlan_service.etherType, ETHERTYPE_PPPOES); 606 | //modify_field(pcr_bng_vlan_md.vlan_inner_etherType, ETHERTYPE_PPPOES); 607 | 608 | add_header(pppoe); 609 | modify_field(pppoe.version, 1); 610 | modify_field(pppoe.typeID, 1); 611 | modify_field(pppoe.code, 0); // PPPoE Session Data 612 | modify_field(pppoe.totalLength, pppoe_md.totalLength); 613 | modify_field(pppoe.sessionID, pcr_bng_md.subscr_cpe_pppoe_session); 614 | add_header(pppoes_protocol); 615 | modify_field(pppoes_protocol.protocol, pppoe_md.protocol); 616 | } 617 | 618 | table t_pcr_bng_ds_pushstack_nosession { 619 | actions { 620 | a_pcr_bng_ds_pushstack_nosession; 621 | } 622 | size : SUBSC_CAPACITY; 623 | } 624 | 625 | action a_pcr_bng_ds_pushstack_nosession() { 626 | copy_header(ethernet_inner, ethernet_outer); 627 | } 628 | 629 | // ===== t_pcr_bng_ds_srcmac 630 | 631 | table t_pcr_bng_ds_srcmac { 632 | reads { 633 | eg_intr_md.egress_port : exact; 634 | } 635 | actions { 636 | _drop; 637 | a_pcr_bng_ds_srcmac; 638 | } 639 | size : 128; 640 | } 641 | 642 | action a_pcr_bng_ds_srcmac(inner_src_mac) { 643 | modify_field(ethernet_inner.srcAddr, inner_src_mac); 644 | } 645 | 646 | 647 | // ===== t_ds_meters / counters 648 | 649 | meter mtr_ds_subsc { 650 | type : bytes; 651 | direct : t_pcr_bng_ds_meter; 652 | result : pcr_bng_md.ds_packet_color; 653 | } 654 | 655 | table t_pcr_bng_ds_meter { 656 | reads { 657 | pcr_bng_md.session_id : exact; 658 | } 659 | actions { 660 | _nop; 661 | } 662 | size : SUBSC_CAPACITY; 663 | } 664 | 665 | counter ctr_subsc { 666 | type : bytes; 667 | direct : t_pcr_bng_ds_meter; 668 | } 669 | 670 | table t_pcr_bng_counter { 671 | reads { 672 | pcr_bng_md.session_id : exact; 673 | } 674 | actions { 675 | _nop; 676 | } 677 | size : SUBSC_CAPACITY; 678 | } 679 | 680 | /************************************************************************* 681 | ************** I N G R E S S P R O C E S S I N G ******************* 682 | *************************************************************************/ 683 | 684 | control ingress_processor_bng { 685 | /* 686 | * MTU checks are specific to PPP and therefore should be part of this 687 | * processor. Per-subscriber PPP MRUs are theoretically possible, but 688 | * not supported in this version. For details refer to RFC 4638. 689 | */ 690 | if (pcr_bng_md.address_type == IPV4_ADDR_TYPE_GU_32) { 691 | apply(t_pcr_bng_subsc_match_ipv4); 692 | } else if (pcr_bng_md.address_type == IPV6_ADDR_TYPE_LL_64) { 693 | apply(t_pcr_bng_subsc_match_ipv6_net64_ll); 694 | } else if (pcr_bng_md.address_type == IPV6_ADDR_TYPE_GU_64) { 695 | apply(t_pcr_bng_subsc_match_ipv6_net64); 696 | } else if (pcr_bng_md.address_type == IPV6_ADDR_TYPE_GU_56) { 697 | apply(t_pcr_bng_subsc_match_ipv6_net56); 698 | } 699 | 700 | if (pcr_bng_md.direction == PCR_BNG_DIRECTION_US) { 701 | apply(t_pcr_bng_us_line_map); // set pcr_bng_md.in_line_* values 702 | if (pcr_bng_md.subscr_cpe_pppoe_session == pppoe.sessionID) { 703 | apply(t_pcr_bng_us_antispoof_mac); // set pcr_bng_md.in_mac_* values 704 | } 705 | } 706 | 707 | /* 708 | if (pppoe_md.mru_check == 0) { 709 | apply(t_pcr_bng_mru_check_failed); 710 | } 711 | */ 712 | /* 713 | * Put all information together. Enable parallelization for the tables 714 | * before this point. 715 | */ 716 | if (pcr_bng_md.address_match_ok == TRUE and 717 | pcr_bng_md.us_line_match_ok == TRUE and 718 | pcr_bng_md.us_line_session_id == pcr_bng_md.session_id) { 719 | apply(t_pcr_bng_us_verify); 720 | } else { 721 | /* Handle DS traffic and US traffic that has no valid session_id. */ 722 | apply(t_pcr_bng_verify); 723 | } 724 | } 725 | 726 | 727 | /************************************************************************* 728 | **************** E G R E S S P R O C E S S I N G ******************* 729 | *************************************************************************/ 730 | 731 | control egress_processor_bng { 732 | if (pcr_bng_md.direction == PCR_BNG_DIRECTION_DS) { 733 | if (mcast_md.is_multicast==TRUE) { 734 | apply(t_pcr_bng_mcast_egress); 735 | } 736 | apply(t_pcr_bng_ds_meter); 737 | } 738 | apply(t_pcr_bng_counter); 739 | if (serviceedge_md.out_net_proto == NET_PROTO_SR) { 740 | if (pcr_bng_md.direction == PCR_BNG_DIRECTION_DS) { 741 | if (pcr_bng_md.session_established == TRUE) { 742 | apply(t_pcr_bng_ds_set_session); 743 | apply(t_pcr_bng_ds_pushstack_vlan); 744 | if (pppoe_md.ppp_proto == PPPOE_PROTO_SESSION) { 745 | apply(t_pcr_bng_ds_pushstack_session_pppoes); 746 | } 747 | } else { 748 | apply(t_pcr_bng_ds_pushstack_nosession); 749 | } 750 | apply(t_pcr_bng_ds_srcmac); 751 | } 752 | } 753 | } 754 | 755 | -------------------------------------------------------------------------------- /fabric/p4src/se.p4: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present Open Networking Foundation 3 | * 4 | * Contributed and sponsored by Deutsche Telekom AG. 5 | * Originally developed as part of the D-Nets 6 P4 Service Edge project 6 | * in collaboration with Technische Universitaet Darmstadt. 7 | * Authors: Jeremias Blendin, Leonhard Nobach 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * For details see the file LICENSE in the top project directory. 22 | */ 23 | 24 | #include "constants.p4" 25 | #include "pppoe.p4" 26 | #include "headers.p4" 27 | #include "acl.p4" 28 | #include "processor_bng.p4" 29 | #include 30 | #include 31 | 32 | /************************************************************************* 33 | **************************** D E F I N E S ****************************** 34 | *************************************************************************/ 35 | 36 | action _nop() { } 37 | 38 | action _drop() { drop(); } 39 | 40 | /************************************************************************* 41 | ************** I N G R E S S T A B L E S & A C T I O N S ************* 42 | *************************************************************************/ 43 | 44 | // ============= General Tables 45 | 46 | action a_in_analyze_sr_none() { 47 | modify_field(sr_md.in_stack_depth, 0); 48 | } 49 | 50 | action a_in_analyze_base(in_bos_parsed) { 51 | modify_field(sr_md.in_bos_parsed, in_bos_parsed); 52 | modify_field(serviceedge_md.in_net_proto, NET_PROTO_SR); 53 | } 54 | 55 | table t_in_classify_sr { 56 | reads { 57 | mpls_bos.valid : ternary; 58 | mpls[0].valid : ternary; 59 | mpls[1].valid : ternary; 60 | mpls[2].valid : ternary; 61 | mpls[3].valid : ternary; 62 | mpls[4].valid : ternary; 63 | mpls[5].valid : ternary; 64 | mpls[6].valid : ternary; 65 | mpls_bos.label : ternary; 66 | mpls[0].label : ternary; 67 | mpls[1].label : ternary; 68 | sr_md.in_service_tag_type : ternary; 69 | } 70 | actions { 71 | _nop; 72 | a_in_analyze_sr_none; 73 | a_in_classify_sr_cls; 74 | a_in_classify_sr_cls_remove_mpls0; 75 | a_in_analyze_sr_set_stack_depth_bos_1; 76 | a_in_analyze_sr_set_stack_depth_bos_2; 77 | a_in_analyze_sr_set_stack_depth_bos_3; 78 | a_in_analyze_sr_set_stack_depth_bos_4; 79 | a_in_analyze_sr_set_stack_depth_bos_5; 80 | a_in_analyze_sr_set_stack_depth_bos_6; 81 | a_in_analyze_sr_set_stack_depth_bos_7; 82 | } 83 | size : IN_CLASSIFY_TABLE_SIZE; 84 | } 85 | 86 | action a_in_classify_sr_cls_remove_mpls0(in_classifier) { 87 | modify_field(sr_md.in_classifier, in_classifier); 88 | modify_field(sr_md.in_stack_depth, 2); 89 | modify_field(sr_md.mpls_top_label, mpls[0].label); 90 | modify_field(sr_md.mpls_service_label, mpls_bos.label); 91 | modify_field(sr_md.bos_tc, mpls_bos.tc); 92 | modify_field(sr_md.bos_ttl, mpls_bos.ttl); 93 | remove_header(mpls[0]); 94 | remove_header(mpls_bos); 95 | } 96 | 97 | action a_in_classify_sr_cls(in_classifier) { 98 | modify_field(sr_md.in_classifier, in_classifier); 99 | modify_field(sr_md.in_stack_depth, 1); 100 | modify_field(sr_md.mpls_top_label, mpls_bos.label); 101 | modify_field(sr_md.mpls_service_label, mpls_bos.label); 102 | modify_field(sr_md.bos_tc, mpls_bos.tc); 103 | modify_field(sr_md.bos_ttl, mpls_bos.ttl); 104 | remove_header(mpls_bos); 105 | } 106 | 107 | action a_in_analyze_sr_set_stack_depth_bos_1(in_classifier) { 108 | modify_field(sr_md.in_stack_depth, 1); 109 | modify_field(sr_md.mpls_top_label, mpls_bos.label); 110 | modify_field(sr_md.mpls_service_label, mpls_bos.label); 111 | modify_field(sr_md.in_classifier, in_classifier); 112 | modify_field(sr_md.bos_tc, mpls_bos.tc); 113 | modify_field(sr_md.bos_ttl, mpls_bos.ttl); 114 | a_in_analyze_base(1); 115 | } 116 | action a_in_analyze_sr_set_stack_depth_bos_2(in_classifier) { 117 | modify_field(sr_md.in_stack_depth, 2); 118 | modify_field(sr_md.mpls_top_label, mpls[0].label); 119 | modify_field(sr_md.mpls_service_label, mpls_bos.label); 120 | modify_field(sr_md.in_classifier, in_classifier); 121 | modify_field(sr_md.bos_tc, mpls_bos.tc); 122 | modify_field(sr_md.bos_ttl, mpls_bos.ttl); 123 | a_in_analyze_base(1); 124 | } 125 | action a_in_analyze_sr_set_stack_depth_bos_3(in_classifier) { 126 | modify_field(sr_md.in_stack_depth, 3); 127 | modify_field(sr_md.mpls_top_label, mpls[1].label); 128 | modify_field(sr_md.mpls_service_label, mpls_bos.label); 129 | modify_field(sr_md.in_classifier, in_classifier); 130 | modify_field(sr_md.bos_tc, mpls_bos.tc); 131 | modify_field(sr_md.bos_ttl, mpls_bos.ttl); 132 | a_in_analyze_base(1); 133 | } 134 | action a_in_analyze_sr_set_stack_depth_bos_4(in_classifier) { 135 | modify_field(sr_md.in_stack_depth, 4); 136 | modify_field(sr_md.mpls_top_label, mpls[2].label); 137 | modify_field(sr_md.mpls_service_label, mpls_bos.label); 138 | modify_field(sr_md.in_classifier, in_classifier); 139 | modify_field(sr_md.bos_tc, mpls_bos.tc); 140 | modify_field(sr_md.bos_ttl, mpls_bos.ttl); 141 | a_in_analyze_base(1); 142 | } 143 | action a_in_analyze_sr_set_stack_depth_bos_5(in_classifier) { 144 | modify_field(sr_md.in_stack_depth, 5); 145 | modify_field(sr_md.mpls_top_label, mpls[3].label); 146 | modify_field(sr_md.mpls_service_label, mpls_bos.label); 147 | modify_field(sr_md.in_classifier, in_classifier); 148 | modify_field(sr_md.bos_tc, mpls_bos.tc); 149 | modify_field(sr_md.bos_ttl, mpls_bos.ttl); 150 | a_in_analyze_base(1); 151 | } 152 | action a_in_analyze_sr_set_stack_depth_bos_6(in_classifier) { 153 | modify_field(sr_md.in_stack_depth, 6); 154 | modify_field(sr_md.mpls_top_label, mpls[4].label); 155 | modify_field(sr_md.mpls_service_label, mpls_bos.label); 156 | modify_field(sr_md.in_classifier, in_classifier); 157 | modify_field(sr_md.bos_tc, mpls_bos.tc); 158 | modify_field(sr_md.bos_ttl, mpls_bos.ttl); 159 | a_in_analyze_base(1); 160 | } 161 | action a_in_analyze_sr_set_stack_depth_bos_7(in_classifier) { 162 | modify_field(sr_md.in_stack_depth, 7); 163 | modify_field(sr_md.mpls_top_label, mpls[5].label); 164 | modify_field(sr_md.mpls_service_label, mpls_bos.label); 165 | modify_field(sr_md.in_classifier, in_classifier); 166 | modify_field(sr_md.bos_tc, mpls_bos.tc); 167 | modify_field(sr_md.bos_ttl, mpls_bos.ttl); 168 | a_in_analyze_base(1); 169 | } 170 | 171 | table t_in_classify_l2 { 172 | reads { 173 | ig_intr_md.ingress_port : ternary; 174 | ethernet_outer.srcAddr : ternary; 175 | ethernet_outer.dstAddr : ternary; 176 | } 177 | actions { 178 | _nop; 179 | a_in_classify_l2_cls; 180 | } 181 | size : IN_CLASSIFY_TABLE_SIZE; 182 | } 183 | 184 | action a_in_classify_l2_cls(in_classifier) { 185 | modify_field(l2_md.in_classifier, in_classifier); 186 | } 187 | 188 | table t_in_classify_cp { 189 | reads { 190 | cpu_header.valid : ternary; 191 | cpu_header.handling_type : ternary; 192 | cpu_header.reason : ternary; 193 | } 194 | actions { 195 | _nop; 196 | a_in_classify_cp_cls; 197 | } 198 | size : IN_CLASSIFY_TABLE_SIZE; 199 | } 200 | 201 | action a_in_classify_cp_cls(in_classifier) { 202 | modify_field(cpu_md.in_classifier, in_classifier); 203 | } 204 | 205 | table t_in_classify_ipv4_dst { 206 | reads { 207 | ipv4.dstAddr : ternary; 208 | } 209 | actions { 210 | _nop; 211 | a_in_classify_ip_cls_ip_dst; 212 | a_in_classify_ipv4_cls_ipv4_dst; 213 | a_in_classify_ipv4_cls_ip_ipv4_dst; 214 | } 215 | size : IN_CLASSIFY_TABLE_SIZE; 216 | } 217 | 218 | action a_in_classify_ip_cls_ip_dst(in_ip_classifier) { 219 | modify_field(ip_md.in_classifier_dst, in_ip_classifier); 220 | } 221 | action a_in_classify_ipv4_cls_ipv4_dst(in_ipv4_classifier) { 222 | modify_field(ip_md.in_ipv4_classifier_dst, in_ipv4_classifier); 223 | } 224 | action a_in_classify_ipv4_cls_ip_ipv4_dst(in_ip_classifier, in_ipv4_classifier) { 225 | modify_field(ip_md.in_classifier_dst, in_ip_classifier); 226 | modify_field(ip_md.in_ipv4_classifier_dst, in_ipv4_classifier); 227 | } 228 | 229 | table t_in_classify_ipv4_src { 230 | reads { 231 | ipv4.srcAddr : ternary; 232 | } 233 | actions { 234 | _nop; 235 | a_in_classify_ip_cls_ip_src; 236 | a_in_classify_ipv4_cls_ipv4_src; 237 | a_in_classify_ipv4_cls_ip_ipv4_src; 238 | } 239 | size : IN_CLASSIFY_TABLE_SIZE; 240 | } 241 | 242 | action a_in_classify_ip_cls_ip_src(in_ip_classifier) { 243 | modify_field(ip_md.in_classifier_src, in_ip_classifier); 244 | } 245 | action a_in_classify_ipv4_cls_ipv4_src(in_ipv4_classifier) { 246 | modify_field(ip_md.in_ipv4_classifier_src, in_ipv4_classifier); 247 | } 248 | action a_in_classify_ipv4_cls_ip_ipv4_src(in_ip_classifier, in_ipv4_classifier) { 249 | modify_field(ip_md.in_classifier_src, in_ip_classifier); 250 | modify_field(ip_md.in_ipv4_classifier_src, in_ipv4_classifier); 251 | } 252 | 253 | table t_in_classify_ipv6_dst { 254 | reads { 255 | ipv6.dstAddr mask 0xffffffffffffffff0000000000000000: ternary; 256 | } 257 | actions { 258 | _nop; 259 | a_in_classify_ip_cls_ip_dst; 260 | a_in_classify_ipv6_cls_ipv6_dst; 261 | a_in_classify_ipv6_cls_ip_ipv6_dst; 262 | } 263 | size : IN_CLASSIFY_TABLE_SIZE; 264 | } 265 | 266 | action a_in_classify_ipv6_cls_ipv6_dst(in_ipv6_classifier) { 267 | modify_field(ip_md.in_ipv6_classifier_dst, in_ipv6_classifier); 268 | } 269 | action a_in_classify_ipv6_cls_ip_ipv6_dst(in_ip_classifier, in_ipv6_classifier) { 270 | modify_field(ip_md.in_classifier_dst, in_ip_classifier); 271 | modify_field(ip_md.in_ipv6_classifier_dst, in_ipv6_classifier); 272 | } 273 | 274 | table t_in_classify_ipv6_src { 275 | reads { 276 | ipv6.srcAddr mask 0xffffffffffffffff0000000000000000 : ternary; 277 | } 278 | actions { 279 | _nop; 280 | a_in_classify_ip_cls_ip_src; 281 | a_in_classify_ipv6_cls_ipv6_src; 282 | a_in_classify_ipv6_cls_ip_ipv6_src; 283 | } 284 | size : IN_CLASSIFY_TABLE_SIZE; 285 | } 286 | 287 | action a_in_classify_ipv6_cls_ipv6_src(in_ipv6_classifier) { 288 | modify_field(ip_md.in_ipv6_classifier_src, in_ipv6_classifier); 289 | } 290 | action a_in_classify_ipv6_cls_ip_ipv6_src(in_ip_classifier, in_ipv6_classifier) { 291 | modify_field(ip_md.in_classifier_src, in_ip_classifier); 292 | modify_field(ip_md.in_ipv6_classifier_src, in_ipv6_classifier); 293 | } 294 | 295 | 296 | table t_in_count_parser_errors { 297 | reads { 298 | ig_intr_md_from_parser_aux.ingress_parser_err : exact; 299 | } 300 | actions { 301 | _nop; 302 | } 303 | size : 16; 304 | } 305 | 306 | counter ctr_in_count_parser_errors { 307 | type : packets; 308 | direct : t_in_count_parser_errors; 309 | } 310 | 311 | 312 | table t_in_select_processor_fwd { 313 | reads { 314 | ig_intr_md.resubmit_flag : ternary; 315 | l2_md.in_classifier : ternary; 316 | cpu_md.in_classifier : ternary; 317 | sr_md.in_classifier : ternary; 318 | ip_md.in_classifier_dst : ternary; 319 | ip_md.in_classifier_src : ternary; 320 | ip_md.in_ipv4_classifier_dst : ternary; 321 | ip_md.in_ipv4_classifier_src : ternary; 322 | ip_md.in_ipv6_classifier_dst : ternary; 323 | ip_md.in_ipv6_classifier_src : ternary; 324 | ig_intr_md_from_parser_aux.ingress_parser_err : ternary; 325 | } 326 | actions { 327 | _nop; 328 | _drop; 329 | // PROCESSOR_BNG actions 330 | // actions are defined in processor_bng.p4 331 | a_in_select_processor_bng_ds_ipv4; 332 | a_in_select_processor_bng_ds_ipv6; 333 | a_in_select_processor_bng_us_ipv4; 334 | a_in_select_processor_bng_us_ipv6; 335 | a_in_select_processor_bng_us_pppoed; 336 | a_in_select_processor_bng_ds_pppoed; 337 | a_in_select_processor_bng_ds_ipv6_fromcp; 338 | } 339 | size : IN_CLASSIFY_TABLE_SIZE; 340 | } 341 | 342 | #ifdef DEBUG_COUNTERS 343 | 344 | counter ctr_debug { 345 | type : packets; 346 | instance_count : 16; 347 | } 348 | 349 | #endif 350 | 351 | 352 | /************************************** 353 | * 354 | * Ingress 355 | * 356 | *************************************/ 357 | 358 | // ===== t_acl_v4|6 359 | 360 | table t_acl_ipv4 { 361 | reads { 362 | ip_md.vrf : ternary; 363 | ipv4.dstAddr : lpm; 364 | ipv4.srcAddr : ternary; 365 | } 366 | actions { 367 | _drop; 368 | _nop; 369 | /* TODO 370 | Set QoS fields 371 | */ 372 | a_set_qos_ip; 373 | a_set_qos_se; 374 | } 375 | size : ACL_CAPACITY; 376 | } 377 | 378 | table t_acl_ipv6 { 379 | reads { 380 | ip_md.vrf : ternary; 381 | ipv6.dstAddr : lpm; 382 | ipv6.srcAddr : ternary; 383 | } 384 | actions { 385 | _drop; 386 | _nop; 387 | /* TODO 388 | Set QoS fields 389 | */ 390 | a_set_qos_ip; 391 | a_set_qos_se; 392 | } 393 | size : ACL_CAPACITY; 394 | } 395 | 396 | action a_set_qos_for_tm(qid, packet_color) { 397 | modify_field(ig_intr_md_for_tm.qid, qid); 398 | modify_field(ig_intr_md_for_tm.packet_color, packet_color); 399 | } 400 | 401 | action a_set_qos_ip(phb, qid, packet_color) { 402 | a_set_qos_for_tm(qid, packet_color); 403 | modify_field(qos_md.phb, phb); 404 | } 405 | 406 | action a_set_qos_se(phb, qid, packet_color) { 407 | a_set_qos_for_tm(qid, packet_color); 408 | modify_field(qos_md.phb, phb); 409 | modify_field(sr_md.bos_tc, phb); 410 | modify_field(sr_md.non_bos_tc, phb); 411 | modify_field(pcr_bng_vlan_md.vlan_inner_pcp, phb); 412 | modify_field(pcr_bng_vlan_md.vlan_outer_pcp, phb); 413 | } 414 | 415 | table t_forward_cp { 416 | reads { 417 | pcr_bng_md.direction : ternary; 418 | } 419 | actions { 420 | a_pcr_bng_forward_tocp_us; 421 | a_pcr_bng_forward_fromcp_ds; 422 | } 423 | size : 2; 424 | } 425 | 426 | /************************************** 427 | * Downstream (Core -> Subscriber) 428 | *************************************/ 429 | 430 | 431 | // ===== t_forward_ipv4 432 | 433 | table t_forward_ipv4 { 434 | reads { 435 | ip_md.vrf : exact; 436 | ipv4.dstAddr : lpm; 437 | } 438 | actions { 439 | _drop; 440 | a_forward_ipv4_to_cp; 441 | a_forward_ipv4_nexthop_sr; 442 | a_forward_ipv4_mcast_sr; 443 | a_pcr_bng_forward_ipv4_nexthop_sr_bng_ds; 444 | } 445 | 446 | size : 256; 447 | } 448 | 449 | action a_forward_ipv4_to_cp(mpls_service_label) { 450 | modify_field(serviceedge_md.out_net_proto, NET_PROTO_CP); 451 | modify_field(serviceedge_md.next_hop_id, NEXT_HOP_CP); 452 | modify_field(sr_md.mpls_service_label, mpls_service_label); 453 | add_to_field(ipv4.ttl, -1); 454 | } 455 | 456 | action a_forward_ipv4_nexthop_sr(next_hop_id, mpls_service_label) { 457 | modify_field(serviceedge_md.out_net_proto, NET_PROTO_SR); 458 | modify_field(serviceedge_md.next_hop_id, next_hop_id); 459 | modify_field(sr_md.mpls_service_label, mpls_service_label); 460 | add_to_field(ipv4.ttl, -1); 461 | } 462 | 463 | action a_forward_ipv4_mcast_sr() { 464 | modify_field(serviceedge_md.out_net_proto, NET_PROTO_SR); 465 | modify_field(mcast_md.is_multicast, 1); 466 | add_to_field(ipv4.ttl, -1); 467 | } 468 | 469 | // ===== t_forward_ipv6 470 | 471 | table t_forward_ipv6 { 472 | reads { 473 | ip_md.vrf : exact; 474 | ipv6.dstAddr mask 0xffffffffffffffff0000000000000000: lpm; 475 | } 476 | actions { 477 | _drop; 478 | a_forward_ipv6_to_cp; 479 | a_forward_ipv6_nexthop_sr; 480 | a_forward_ipv6_mcast_sr; 481 | a_pcr_bng_forward_ipv6_nexthop_sr_bng_ds; 482 | } 483 | 484 | size : 256; 485 | } 486 | 487 | action a_forward_ipv6_to_cp() { 488 | modify_field(serviceedge_md.out_net_proto, NET_PROTO_CP); 489 | modify_field(serviceedge_md.next_hop_id, NEXT_HOP_CP); 490 | modify_field(cpu_md.handling_type, HANDLING_TYPE_PRC_DS_CP); 491 | add_to_field(ipv6.hopLimit, -1); 492 | } 493 | 494 | action a_forward_ipv6_nexthop_sr(next_hop_id, mpls_service_label) { 495 | modify_field(serviceedge_md.out_net_proto, NET_PROTO_SR); 496 | modify_field(serviceedge_md.next_hop_id, next_hop_id); 497 | modify_field(sr_md.mpls_service_label, mpls_service_label); 498 | add_to_field(ipv6.hopLimit, -1); 499 | } 500 | 501 | action a_forward_ipv6_mcast_sr(mpls_service_label) { 502 | modify_field(serviceedge_md.out_net_proto, NET_PROTO_SR); 503 | modify_field(sr_md.mpls_service_label, mpls_service_label); 504 | add_to_field(ipv6.hopLimit, -1); 505 | modify_field(mcast_md.is_multicast, 1); 506 | } 507 | 508 | // ===== t_forward_to_sr_ttl 509 | 510 | action a_forward_to_sr_mpls_ttl(ttl) { 511 | modify_field(sr_md.bos_ttl, ttl); 512 | modify_field(sr_md.non_bos_ttl, ttl); 513 | } 514 | 515 | 516 | table t_forward_to_sr_ttl_ipv4 { 517 | actions { 518 | a_forward_to_sr_ttl_ipv4; 519 | } 520 | } 521 | 522 | action a_forward_to_sr_ttl_ipv4() { 523 | a_forward_to_sr_mpls_ttl(ipv4.ttl); 524 | } 525 | 526 | table t_forward_to_sr_ttl_ipv6 { 527 | actions { 528 | a_forward_to_sr_ttl_ipv6; 529 | } 530 | } 531 | 532 | action a_forward_to_sr_ttl_ipv6() { 533 | a_forward_to_sr_mpls_ttl(ipv6.hopLimit); 534 | } 535 | 536 | table t_forward_to_sr_ttl_default { 537 | actions { 538 | a_forward_to_sr_ttl_default; 539 | } 540 | } 541 | 542 | action a_forward_to_sr_ttl_default(default_ttl) { 543 | a_forward_to_sr_mpls_ttl(default_ttl); 544 | } 545 | 546 | /************************************** 547 | * Multicast 548 | *************************************/ 549 | 550 | table t_mcast_ipv4 { 551 | reads { 552 | ipv4.srcAddr : exact; 553 | ipv4.dstAddr : exact; 554 | } 555 | actions { 556 | _nop; 557 | a_do_mcast; 558 | } 559 | size : 256; 560 | } 561 | 562 | table t_mcast_ipv6 { 563 | reads { 564 | ipv6.srcAddr : exact; 565 | ipv6.dstAddr : exact; 566 | } 567 | actions { 568 | _nop; 569 | a_do_mcast; 570 | } 571 | size : 256; 572 | } 573 | 574 | action a_do_mcast(group_id) { 575 | modify_field(ig_intr_md_for_tm.mcast_grp_a, group_id); 576 | } 577 | 578 | /************************************************************************* 579 | ********************** E G R E S S T A B L E S ************************ 580 | *************************************************************************/ 581 | 582 | table t_init_pkt_len_change { 583 | reads { 584 | serviceedge_md.in_net_proto : ternary; 585 | serviceedge_md.fwd_net_proto : ternary; 586 | serviceedge_md.out_net_proto : ternary; 587 | serviceedge_md.processor_ingress : ternary; 588 | serviceedge_md.processor_egress : ternary; 589 | } 590 | actions { 591 | a_init_pkt_len_nochange; 592 | a_init_pkt_len_increase; 593 | a_init_pkt_len_decrease; 594 | } 595 | size : 16; 596 | } 597 | 598 | action a_init_pkt_len_nochange() { 599 | modify_field(serviceedge_md.pkt_len_out, eg_intr_md.pkt_length); 600 | } 601 | 602 | action a_init_pkt_len_increase(diff) { 603 | add(serviceedge_md.pkt_len_out, diff, eg_intr_md.pkt_length); 604 | } 605 | 606 | action a_init_pkt_len_decrease(diff) { 607 | modify_field(serviceedge_md.pkt_len_out, eg_intr_md.pkt_length); 608 | modify_field(serviceedge_md.pkt_len_out_decr, diff); 609 | } 610 | 611 | table t_init_pkt_len_change_dec { 612 | actions { 613 | a_init_pkt_len_do_dec; 614 | } 615 | } 616 | 617 | action a_init_pkt_len_do_dec() { 618 | subtract_from_field(serviceedge_md.pkt_len_out, serviceedge_md.pkt_len_out_decr); 619 | } 620 | 621 | table t_init_mtu { 622 | reads { 623 | serviceedge_md.in_net_proto : ternary; 624 | serviceedge_md.fwd_net_proto : ternary; 625 | serviceedge_md.out_net_proto : ternary; 626 | mcast_md.is_multicast : ternary; 627 | eg_intr_md.egress_port : ternary; 628 | serviceedge_md.next_hop_id : ternary; 629 | serviceedge_md.processor_ingress : ternary; 630 | serviceedge_md.processor_egress : ternary; 631 | } 632 | actions { 633 | a_init_mtu; 634 | } 635 | size : 64; 636 | } 637 | 638 | action a_init_mtu(mtu) { 639 | // Set MTU to MTU+1 to ensure the mtu_check result is > if the 640 | // packet is valid. 641 | add_to_field(serviceedge_md.mtu_out, mtu); 642 | } 643 | 644 | 645 | table t_mtu_diff { 646 | actions { 647 | a_mtu_diff; 648 | } 649 | } 650 | 651 | action a_mtu_diff() { 652 | subtract(serviceedge_md.mtu_check, 653 | serviceedge_md.mtu_out, 654 | serviceedge_md.pkt_len_out); 655 | } 656 | 657 | // ===== t_srcdstmac 658 | 659 | table t_srcdstmac { 660 | reads { 661 | eg_intr_md.egress_port : exact; 662 | } 663 | actions { 664 | _drop; 665 | _nop; 666 | a_srcdstmac; 667 | } 668 | size : 64; 669 | } 670 | 671 | action a_srcdstmac(src_mac, dst_mac) { 672 | modify_field(ethernet_outer.srcAddr, src_mac); 673 | modify_field(ethernet_outer.dstAddr, dst_mac); 674 | #ifdef DEBUG_COUNTERS 675 | count(ctr_debug, 2); 676 | #endif 677 | } 678 | 679 | // ===== t_next_hop 680 | 681 | table t_next_hop { 682 | reads { 683 | serviceedge_md.next_hop_id : exact; 684 | serviceedge_md.out_net_proto : exact; 685 | } 686 | actions { 687 | _drop; 688 | a_next_hop_set_port; 689 | } 690 | size : 256; 691 | } 692 | 693 | action a_next_hop_set_port(out_port) { 694 | modify_field(ig_intr_md_for_tm.ucast_egress_port, out_port); 695 | } 696 | 697 | // ===== t_tocp_meter 698 | 699 | meter mtr_tocp { 700 | type : packets; 701 | direct : t_tocp_meter; 702 | result : cpu_md.packet_color; 703 | } 704 | 705 | table t_tocp_meter { 706 | reads { 707 | cpu_md.meter_id : exact; 708 | } 709 | actions { 710 | _nop; 711 | } 712 | size : 33000; 713 | } 714 | 715 | // ===== t_tocp_header 716 | 717 | table t_tocp_header { 718 | actions { 719 | a_tocp_header; 720 | } 721 | } 722 | 723 | action a_tocp_header() { 724 | add_header(cpu_header); 725 | modify_field(cpu_header.handling_type, cpu_md.handling_type); 726 | modify_field(cpu_header.reason, cpu_md.reason_code); 727 | modify_field(cpu_header.pcr_bng_access_node_id, pcr_bng_md.access_node_id); 728 | //modify_field(cpu_header.pcr_bng_access_node_mpls_label, pcr_bng_md.access_node_mpls_label); 729 | modify_field(cpu_header.pcr_bng_session_id, pcr_bng_md.session_id); 730 | modify_field(cpu_header.etherType, ethernet_outer.etherType); 731 | modify_field(ethernet_outer.etherType, ETHERTYPE_CPUHEADER); 732 | } 733 | 734 | 735 | // ===== t_next_hop_egress 736 | 737 | table t_next_hop_egress { 738 | reads { 739 | serviceedge_md.next_hop_id : exact; 740 | } 741 | actions { 742 | _drop; 743 | a_next_hop_egress; 744 | } 745 | size : NEXT_HOP_CAPACITY; 746 | } 747 | 748 | action a_next_hop_egress(hop_nodelabel) { 749 | modify_field(sr_md.mpls_next_node_label, hop_nodelabel); 750 | } 751 | 752 | table t_next_hop_egress_postprocess { 753 | actions { 754 | a_next_hop_egress_postprocess; 755 | } 756 | } 757 | 758 | action a_next_hop_egress_postprocess() { 759 | modify_field(ethernet_outer.etherType, ETHERTYPE_MPLS); 760 | 761 | add_header(mpls_bos); 762 | modify_field(mpls_bos.label, sr_md.mpls_service_label); 763 | modify_field(mpls_bos.tc, sr_md.bos_tc); 764 | modify_field(mpls_bos.s, sr_md.bos_s); 765 | modify_field(mpls_bos.ttl, sr_md.bos_ttl); 766 | 767 | add_header(mpls[0]); 768 | modify_field(mpls[0].label, sr_md.mpls_next_node_label); 769 | modify_field(mpls[0].tc, sr_md.non_bos_tc); 770 | modify_field(mpls[0].s, sr_md.non_bos_s); 771 | modify_field(mpls[0].ttl, sr_md.non_bos_ttl); 772 | } 773 | 774 | /************************************** 775 | * Segment Routing Forwarding 776 | *************************************/ 777 | 778 | table t_sr_start { 779 | actions { 780 | _drop; 781 | } 782 | } 783 | 784 | 785 | /************************************************************************* 786 | ************** I N G R E S S P R O C E S S I N G ******************* 787 | *************************************************************************/ 788 | 789 | 790 | control ingress { 791 | #if DEBUG_UNROLL_MPLS_ANALYSIS 792 | apply(t_in_analyze_sr); 793 | if (sr_md.in_stack_depth > 0) { 794 | apply(t_in_classify_sr); 795 | } 796 | #else 797 | apply(t_in_classify_sr); 798 | #endif 799 | if (valid(ipv4)){ 800 | apply(t_in_classify_ipv4_dst); 801 | apply(t_in_classify_ipv4_src); 802 | } else if (valid(ipv6)){ 803 | apply(t_in_classify_ipv6_dst); 804 | apply(t_in_classify_ipv6_src); 805 | } 806 | apply(t_in_classify_l2); 807 | apply(t_in_classify_cp); 808 | apply(t_in_count_parser_errors); 809 | 810 | apply(t_in_select_processor_fwd); 811 | /* 812 | * At this point the in transport and the processing must be set. 813 | */ 814 | 815 | // Classification and service processing selection until this point 816 | 817 | 818 | /************************** PROCESSORS ************************************/ 819 | if (serviceedge_md.processor_ingress == PROCESSOR_BNG) { 820 | ingress_processor_bng(); 821 | /* 822 | * serviceedge_md.fwd_net_proto is set in t_bng_subsc_match actions. 823 | */ 824 | } else if (serviceedge_md.processor_ingress == PROCESSOR_SR_TERM) { 825 | // Terminate the SR transport here 826 | } 827 | 828 | /*************************** FWD ********************************/ 829 | if (serviceedge_md.fwd_net_proto == NET_PROTO_SR) { 830 | // TODO: SR forwarding 831 | apply(t_sr_start); 832 | } else if (serviceedge_md.fwd_net_proto == NET_PROTO_IP) { 833 | // Select output port and next hop id 834 | 835 | if (valid(ipv4)) { 836 | apply(t_forward_ipv4); 837 | apply(t_acl_ipv4); 838 | } else if (valid(ipv6)) { 839 | apply(t_forward_ipv6); 840 | apply(t_acl_ipv6); 841 | } 842 | 843 | if (mcast_md.is_multicast==TRUE) { 844 | if (valid(ipv4)) { 845 | apply(t_mcast_ipv4); 846 | } else if (valid(ipv6)) { 847 | apply(t_mcast_ipv6); 848 | } 849 | } 850 | } else if (serviceedge_md.fwd_net_proto == NET_PROTO_CP) { 851 | apply(t_forward_cp); 852 | } 853 | 854 | if (mcast_md.is_multicast==FALSE) { 855 | apply(t_next_hop); 856 | } 857 | 858 | // Add ECMP here if needed 859 | /* 860 | * At this point the out transport must be set or the packet must be 861 | * dropped by the ACL. 862 | * IMPORTANT: Drop packets that are too large for PPPoE here. 863 | * Dropping them after duplication is not efficient. 864 | */ 865 | process_ingress_system_acl(); 866 | } 867 | 868 | /************************************************************************* 869 | **************** E G R E S S P R O C E S S I N G ******************* 870 | *************************************************************************/ 871 | 872 | control egress { 873 | if (eg_intr_md_from_parser_aux.clone_src == NOT_CLONED) { 874 | apply(t_init_pkt_len_change); 875 | apply(t_init_pkt_len_change_dec); 876 | 877 | if (serviceedge_md.out_net_proto == NET_PROTO_SR and 878 | serviceedge_md.fwd_net_proto != NET_PROTO_SR) { 879 | if (valid(ipv4)) { 880 | apply(t_forward_to_sr_ttl_ipv4); 881 | } else if (valid(ipv6)) { 882 | apply(t_forward_to_sr_ttl_ipv6); 883 | } else { 884 | apply(t_forward_to_sr_ttl_default); 885 | } 886 | } 887 | 888 | /******************* PROCESSORS **************************************/ 889 | if (serviceedge_md.processor_egress == PROCESSOR_BNG) { 890 | egress_processor_bng(); 891 | } 892 | 893 | apply(t_init_mtu); 894 | apply(t_mtu_diff); 895 | } 896 | 897 | /******************* OUT TRANSPORT **********************************/ 898 | if (serviceedge_md.out_net_proto == NET_PROTO_SR) { 899 | apply(t_next_hop_egress); 900 | apply(t_next_hop_egress_postprocess); 901 | // Add ECMP handling if required 902 | } else if (serviceedge_md.out_net_proto == NET_PROTO_IP) { 903 | // Handle link local traffic here 904 | } else if (serviceedge_md.out_net_proto == NET_PROTO_CP) { 905 | // Add CP header as needed by the CP software 906 | apply(t_tocp_meter); 907 | apply(t_tocp_header); 908 | } 909 | apply(t_srcdstmac); 910 | 911 | /********************** MTU/ACL_CHECK *******************************/ 912 | process_egress_system_acl(); 913 | } 914 | 915 | 916 | -------------------------------------------------------------------------------- /fabric/wireshark-dissectors/README.md: -------------------------------------------------------------------------------- 1 | Wireshark Dissector for the Switch to CPU Protocol 2 | ================================================== 3 | 4 | For testing, start with: 5 | ``` 6 | wireshark -X lua_script:cpu_header.lua 7 | ``` 8 | 9 | To enable the dissector for every start of wireshark, 10 | copy `init.lua` into the wireshark config: 11 | ``` 12 | ~/.config/wireshark on Ubuntu 13 | ``` 14 | and copy `cpu_header.lua` into the wireshark Lua folder: 15 | ``` 16 | ~/.config/wireshark/lua 17 | ``` 18 | -------------------------------------------------------------------------------- /fabric/wireshark-dissectors/cpu_header.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2018-present Open Networking Foundation 2 | -- 3 | -- Contributed and sponsored by Deutsche Telekom AG. 4 | -- Originally developed as part of the D-Nets 6 P4 Service Edge project 5 | -- in collaboration with Technische Universitaet Darmstadt. 6 | -- Author: Jeremias Blendin 7 | -- 8 | -- Licensed under the Apache License, Version 2.0 (the "License"); 9 | -- you may not use this file except in compliance with the License. 10 | -- You may obtain a copy of the License at 11 | -- 12 | -- http://www.apache.org/licenses/LICENSE-2.0 13 | -- 14 | -- Unless required by applicable law or agreed to in writing, software 15 | -- distributed under the License is distributed on an "AS IS" BASIS, 16 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | -- See the License for the specific language governing permissions and 18 | -- limitations under the License. 19 | -- 20 | -- For details see the file LICENSE in the top project directory. 21 | -- 22 | -- se.p4 CPU header 23 | -- 24 | -- declare our protocol 25 | sep4cpu_proto = Proto("sep4cpuheader","se.p4 cpu header") 26 | -- create a function to dissect it 27 | function sep4cpu_proto.dissector(buffer,pinfo,tree) 28 | local HEADER_LEN = 10 29 | pinfo.cols.protocol = "SEP4CPUHEADER" 30 | local subtree = tree:add(sep4cpu_proto,buffer(),"se.p4 cpu header") 31 | subtree:add(buffer(0,1),"handling_type " .. buffer(0,1):uint()) 32 | subtree:add(buffer(1,1),"reason " .. buffer(1,1):uint()) 33 | subtree:add(buffer(2,1),"pcr_bng_access_node_id " .. buffer(2,1):uint()) 34 | subtree:add(buffer(3,3),"pcr_bng_access_node_mpls_label " .. buffer(3,3):uint()) 35 | subtree:add(buffer(6,2),"pcr_bng_session_id " .. buffer(6,2):uint()) 36 | subtree:add(buffer(8,2),"ethertype " .. buffer(8,2):uint()) 37 | if buffer:len() > HEADER_LEN then 38 | local next_diss = (DissectorTable.get("ethertype")):get_dissector(buffer(8,2):uint()) 39 | next_diss:call(buffer(HEADER_LEN):tvb(), pinfo, tree) 40 | end 41 | end 42 | -- load the ethertype table 43 | eth_table = DissectorTable.get("ethertype") 44 | -- register our protocol to handle ethertype 0xeeee 45 | eth_table:add(0xeeee,sep4cpu_proto) 46 | -------------------------------------------------------------------------------- /fabric/wireshark-dissectors/init.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2018-present Open Networking Foundation 2 | -- 3 | -- Contributed and sponsored by Deutsche Telekom AG. 4 | -- Originally developed as part of the D-Nets 6 P4 Service Edge project 5 | -- in collaboration with Technische Universitaet Darmstadt. 6 | -- Author: Jeremias Blendin 7 | -- 8 | -- Licensed under the Apache License, Version 2.0 (the "License"); 9 | -- you may not use this file except in compliance with the License. 10 | -- You may obtain a copy of the License at 11 | -- 12 | -- http://www.apache.org/licenses/LICENSE-2.0 13 | -- 14 | -- Unless required by applicable law or agreed to in writing, software 15 | -- distributed under the License is distributed on an "AS IS" BASIS, 16 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | -- See the License for the specific language governing permissions and 18 | -- limitations under the License. 19 | -- 20 | -- For details see the file LICENSE in the top project directory. 21 | -- 22 | -- USER_DIR is initialized in ${GLOBAL_CONFIG_DIR}/init.lua 23 | local basedir = ( USER_DIR or persconffile_path() )..'lua/' 24 | 25 | -- load all Lua scripts in "~/.config/wireshark/lua/" (ascending ASCII order) 26 | for f in Dir.open(basedir, ".lua") do 27 | dofile(basedir..f) 28 | end 29 | 30 | -------------------------------------------------------------------------------- /generic/README.md: -------------------------------------------------------------------------------- 1 | # Generic P4 service edge code. 2 | 3 | ## Platforms 4 | 5 | - bmv2 (a.k.a. behavioral-model) 6 | 7 | ## Supports 8 | 9 | User-plane functionality for: 10 | 11 | - PPPoE termination 12 | - Reverse-path filtering (MAC, IPv4/v6) 13 | - Metering 14 | - TR-101 double-VLAN termination 15 | - 2-label MPLS termination (label behavior depends on control plane) 16 | - Routing, ACLs 17 | 18 | ## Currently missing: 19 | 20 | - Control plane, 21 | - Fully-fledged fabric integration, 22 | - MTU handling 23 | 24 | ## Build Instructions 25 | 26 | - Refer to the specific `platf_*` directory on how to build for your platform. 27 | -------------------------------------------------------------------------------- /generic/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencord/p4se/5fd8de8874fd6a564fd421e42a937ce2a05a90ed/generic/__init__.py -------------------------------------------------------------------------------- /generic/p4src/headers.p4: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Common network header definitions 4 | 5 | Copyright 2013-present Barefoot Networks, Inc. and Open Networking Foundation 6 | 7 | Added by author Leonhard Nobach: 8 | MPLS header 9 | VLAN header 10 | PPPoE header 11 | Graph 12 | 13 | Licensed under the Apache License, Version 2.0 (the "License"); 14 | you may not use this file except in compliance with the License. 15 | You may obtain a copy of the License at 16 | 17 | http://www.apache.org/licenses/LICENSE-2.0 18 | 19 | Unless required by applicable law or agreed to in writing, software 20 | distributed under the License is distributed on an "AS IS" BASIS, 21 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | See the License for the specific language governing permissions and 23 | limitations under the License. 24 | */ 25 | 26 | //Custom header to dispatch control plane (CP) packets over Ethernet. 27 | header_type bng_cp_t { 28 | fields { 29 | stamp : 16; 30 | fwd_port: 32; //Incoming packets -> their output port, 31 | //Outgoing packets -> their input port. 32 | eth_dstAddr: 48; //Fields which are the "actual" encapsulated "Ethernet header". 33 | eth_srcAddr: 48; 34 | eth_etherType: 16; 35 | } 36 | } 37 | 38 | header_type ethernet_t { 39 | fields { 40 | dstAddr : 48; 41 | srcAddr : 48; 42 | etherType : 16; 43 | } 44 | } 45 | 46 | header_type mpls_t { 47 | fields { 48 | label : 20; 49 | tc : 3; 50 | s : 1; 51 | ttl : 8; 52 | } 53 | } 54 | 55 | header_type vlan_t { 56 | fields { 57 | vlanID: 16; 58 | etherType: 16; 59 | } 60 | } 61 | 62 | header_type pppoe_t { 63 | fields { 64 | version : 4; //Always 1 65 | typeID : 4; //Always 1 66 | code : 8; 67 | sessionID : 16; 68 | totalLength : 16; 69 | protocol : 16; //See http://www.iana.org/assignments/ppp-numbers/ppp-numbers.xhtml 70 | //User-plane: IP: 0021, IPv6: 0057, 71 | //Control-plane: LCP: c021, IPv6CP: 8057, IPCP: 72 | } 73 | } 74 | 75 | header_type ipv4_t { 76 | fields { 77 | version : 4; 78 | ihl : 4; 79 | diffserv : 8; //a.k.a. ToS 80 | totalLen : 16; 81 | identification : 16; 82 | flags : 3; 83 | fragOffset : 13; 84 | ttl : 8; 85 | protocol : 8; 86 | hdrChecksum : 16; 87 | srcAddr : 32; 88 | dstAddr: 32; 89 | } 90 | } 91 | 92 | #ifdef ENABLE_IPV6 93 | header_type ipv6_t { 94 | fields { 95 | version : 4; 96 | trafficClass : 8; 97 | flowLabel : 20; 98 | payloadLen : 16; 99 | nextHdr : 8; 100 | hopLimit : 8; 101 | srcAddr : 128; 102 | dstAddr : 128; 103 | } 104 | } 105 | #endif 106 | 107 | /* === */ 108 | 109 | 110 | 111 | field_list ipv4_checksum_list { 112 | ipv4.version; 113 | ipv4.ihl; 114 | ipv4.diffserv; 115 | ipv4.totalLen; 116 | ipv4.identification; 117 | ipv4.flags; 118 | ipv4.fragOffset; 119 | ipv4.ttl; 120 | ipv4.protocol; 121 | ipv4.srcAddr; 122 | ipv4.dstAddr; 123 | } 124 | 125 | field_list_calculation ipv4_checksum { 126 | input { 127 | ipv4_checksum_list; 128 | } 129 | algorithm : csum16; 130 | output_width : 16; 131 | } 132 | 133 | calculated_field ipv4.hdrChecksum { 134 | verify ipv4_checksum; 135 | update ipv4_checksum; 136 | } 137 | 138 | 139 | /* === */ 140 | 141 | parser start { 142 | return parse_ethernet_outer; 143 | } 144 | 145 | #define ETHERTYPE_IPV4 0x0800 146 | #define ETHERTYPE_VLAN 0x8100 147 | #define ETHERTYPE_PPPOED 0x8863 148 | #define ETHERTYPE_PPPOES 0x8864 149 | #define ETHERTYPE_MPLS 0x8847 150 | 151 | #define ETHERTYPE_CP 0x8765 //A (remote) CP packet that must be forwarded on a specific port. 152 | 153 | header ethernet_t ethernet_outer; 154 | 155 | parser parse_ethernet_outer { 156 | extract(ethernet_outer); 157 | return select(latest.etherType) { 158 | ETHERTYPE_MPLS : parse_mpls0; 159 | ETHERTYPE_CP : parse_bng_cp; 160 | default: ingress; 161 | } 162 | } 163 | 164 | header bng_cp_t bng_cp; 165 | 166 | parser parse_bng_cp { 167 | extract(bng_cp); 168 | return ingress; 169 | } 170 | 171 | // We require a parser value set here, as we need to already know 172 | // in the parser whether a label is an access or a core label, to 173 | // be able to parse it correctly 174 | parser_value_set mpls_0_accesslabels; 175 | 176 | header mpls_t mpls0; 177 | 178 | parser parse_mpls0 { 179 | extract(mpls0); 180 | return select(latest.s) { 181 | 1 : ingress; // packets must have 2 labels. 182 | default : parse_mpls1; 183 | } 184 | } 185 | 186 | header mpls_t mpls1; 187 | 188 | parser parse_mpls1 { 189 | extract(mpls1); 190 | return select(latest.s) { 191 | 1 : parse_above_mpls; 192 | default : ingress; //packets must not have more than 2 labels. 193 | } 194 | } 195 | 196 | parser parse_above_mpls { 197 | return select(mpls0.label) { 198 | mpls_0_accesslabels : parse_ethernet_inner; 199 | default : parse_ip; 200 | } 201 | } 202 | 203 | 204 | header ethernet_t ethernet_inner; 205 | 206 | parser parse_ethernet_inner { 207 | extract(ethernet_inner); 208 | return select(latest.etherType) { 209 | ETHERTYPE_VLAN : parse_vlan_subsc; 210 | default: ingress; 211 | } 212 | } 213 | 214 | header vlan_t vlan_subsc; 215 | header vlan_t vlan_service; 216 | 217 | parser parse_vlan_subsc { 218 | extract(vlan_subsc); 219 | return select(latest.etherType) { 220 | ETHERTYPE_VLAN : parse_vlan_service; 221 | ETHERTYPE_PPPOED : parse_pppoe; 222 | ETHERTYPE_PPPOES : parse_pppoe; //In this case we have no service field -> supported! 223 | default: ingress; 224 | } 225 | } 226 | 227 | parser parse_vlan_service { 228 | extract(vlan_service); 229 | return select(latest.etherType) { 230 | ETHERTYPE_PPPOED : parse_pppoe; 231 | ETHERTYPE_PPPOES : parse_pppoe; 232 | default: ingress; 233 | } 234 | } 235 | 236 | #define PPPOE_PROTOCOL_IP4 0x0021 237 | #define PPPOE_PROTOCOL_IP6 0x0057 238 | 239 | header pppoe_t pppoe; 240 | 241 | parser parse_pppoe { 242 | extract(pppoe); 243 | return select(latest.protocol) { 244 | PPPOE_PROTOCOL_IP4: parse_ip; 245 | //Reference parse_ip even though we already know the version... 246 | #ifdef ENABLE_IPV6 247 | PPPOE_PROTOCOL_IP6: parse_ip; 248 | #endif 249 | default: ingress; 250 | } 251 | } 252 | 253 | parser parse_ip { 254 | //We cannot get the IP version from the ethertype or MPLS label. Thus, get it 255 | //from the IP packet's first 4 bits. 256 | return select(current(0, 4)) { 257 | 4 : parse_ipv4; 258 | #ifdef ENABLE_IPV6 259 | 6 : parse_ipv6; 260 | #endif 261 | default : ingress; 262 | } 263 | } 264 | 265 | header ipv4_t ipv4; 266 | 267 | parser parse_ipv4 { 268 | extract(ipv4); 269 | return ingress; 270 | } 271 | 272 | #ifdef ENABLE_IPV6 273 | header ipv6_t ipv6; 274 | 275 | parser parse_ipv6 { 276 | extract(ipv6); 277 | return ingress; 278 | } 279 | #endif 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | -------------------------------------------------------------------------------- /generic/p4src/includes/intrinsic.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type intrinsic_metadata_t { 18 | fields { 19 | ingress_global_timestamp : 48; 20 | lf_field_list : 32; 21 | mcast_grp : 16; 22 | egress_rid : 16; 23 | } 24 | } 25 | 26 | metadata intrinsic_metadata_t intrinsic_metadata; 27 | -------------------------------------------------------------------------------- /generic/p4src/se.p4: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present Open Networking Foundation 3 | * 4 | * Contributed and sponsored by Deutsche Telekom AG. 5 | * Originally developed as part of the D-Nets 6 P4 Service Edge project 6 | * in collaboration with Technische Universitaet Darmstadt. 7 | * Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * For details see the file LICENSE in the top project directory. 22 | */ 23 | 24 | 25 | //#define DEBUG_COUNTERS 26 | #define ENABLE_COUNTERS 27 | #define ENABLE_DS_METERS 28 | #define ENABLE_IPV6 29 | 30 | #include "headers.p4" 31 | #include "includes/intrinsic.p4" 32 | 33 | #define TYPE_DS 0x0 34 | #define TYPE_US 0x1 35 | #define TYPE_INVALID 0x2 36 | 37 | #define SUBSC_CAPACITY 8192 38 | #define NET_CAPACITY 4*SUBSC_CAPACITY 39 | #define ROUTE_CAPACITY 256 40 | 41 | #define NUM_OF_CPS 16 42 | 43 | header_type ingress_md_t { 44 | fields { 45 | usds : 2; //0 if Upstream, double-tag, 1 if Downstream, 2 if invalid (3 undefined). 46 | cp : 1; //0 if still in dataplane, 1 if destined for control plane or coming from control plane. 47 | line_id : 32; //e.g. a DSL line on the DSLAM. 48 | subsc_id : 8; //Subscriber of line (multiple authed subscribers per line possible). 49 | ctr_bucket : 16; //References counters and meters of the current subscriber. 50 | meter_result : 32; 51 | } 52 | } 53 | 54 | metadata ingress_md_t ingress_md; 55 | 56 | action _nop() { } 57 | 58 | #ifdef DEBUG_COUNTERS 59 | 60 | counter ctr_debug { 61 | type : packets; 62 | instance_count : 16; 63 | } 64 | 65 | #endif 66 | 67 | 68 | // ============= General Tables 69 | 70 | 71 | // ===== t_bng_fromcp 72 | 73 | table t_bng_fromcp { 74 | reads { 75 | ethernet_outer.dstAddr : exact; 76 | ethernet_outer.srcAddr : exact; 77 | standard_metadata.ingress_port : exact; 78 | 79 | } 80 | actions { 81 | a_bng_output; 82 | _drop; 83 | } 84 | 85 | max_size : NUM_OF_CPS; 86 | } 87 | 88 | action a_bng_output() { 89 | modify_field(ethernet_outer.dstAddr, bng_cp.eth_dstAddr); 90 | modify_field(ethernet_outer.srcAddr, bng_cp.eth_srcAddr); 91 | modify_field(ethernet_outer.etherType, bng_cp.eth_etherType); 92 | modify_field(standard_metadata.egress_spec, bng_cp.fwd_port); 93 | modify_field(ingress_md.cp, 1); 94 | remove_header(bng_cp); 95 | #ifdef DEBUG_COUNTERS 96 | count(ctr_debug, 13); 97 | #endif 98 | } 99 | 100 | 101 | // ============= CP Tapping 102 | 103 | table t_cptap_outer_ethernet { 104 | reads { 105 | ethernet_outer.dstAddr : exact; 106 | ethernet_outer.etherType : exact; 107 | } 108 | actions { 109 | a_cptap_cp; 110 | a_cptap_dp; 111 | } 112 | max_size : 32; 113 | } 114 | 115 | action a_cptap_cp() { 116 | modify_field(ingress_md.cp, 1); 117 | } 118 | 119 | action a_cptap_dp() { 120 | //Nothing to do. 121 | } 122 | 123 | //This e.g. catches ARP. More tapping tables thinkable - depending on exact CP behavior. 124 | //IP (e.g. v6 link-local) tapping is done in the routing tables. 125 | 126 | // ===== t_usds 127 | 128 | 129 | table t_usds { 130 | reads { 131 | ethernet_outer.dstAddr : exact; 132 | standard_metadata.ingress_port : exact; 133 | mpls0.label : exact; 134 | 135 | } 136 | actions { 137 | a_usds_handle_ds; 138 | a_usds_handle_us; 139 | _mark_drop; 140 | } 141 | 142 | max_size : 256; 143 | } 144 | 145 | action a_usds_handle_ds() { 146 | modify_field(ingress_md.usds, TYPE_DS); 147 | 148 | #ifdef DEBUG_COUNTERS 149 | count(ctr_debug, 0); 150 | #endif 151 | } 152 | 153 | action a_usds_handle_us() { 154 | add_header(vlan_service); 155 | //SPEC says: "If the header instance was invalid, all its 156 | //fields are initialized to 0. If the header instance is 157 | //already valid, it is not changed." 158 | modify_field(ingress_md.usds, TYPE_US); 159 | #ifdef DEBUG_COUNTERS 160 | count(ctr_debug, 1); 161 | #endif 162 | } 163 | 164 | 165 | 166 | 167 | // ============= Upstream (Subscriber -> Core or Subscriber -> Subscriber) 168 | 169 | 170 | // ===== t_subsc_map 171 | 172 | table t_line_map { 173 | reads { 174 | standard_metadata.ingress_port : exact; 175 | mpls0.label : exact; 176 | mpls1.label : exact; 177 | vlan_subsc.vlanID : exact; 178 | } 179 | actions { 180 | _mark_drop; 181 | a_line_map_pass; 182 | } 183 | max_size : SUBSC_CAPACITY; 184 | } 185 | 186 | action a_line_map_pass(line_id) { 187 | modify_field(ingress_md.line_id, line_id); 188 | #ifdef DEBUG_COUNTERS 189 | count(ctr_debug, 2); 190 | #endif 191 | 192 | } 193 | 194 | 195 | // ===== t_pppoe_cpdp 196 | 197 | table t_pppoe_cpdp { 198 | reads { 199 | ethernet_inner.dstAddr : exact; //bcast and mcast. Different services have the same local address 200 | vlan_service.etherType : exact; 201 | pppoe.protocol : exact; 202 | } 203 | actions { 204 | _mark_drop; 205 | a_pppoe_cpdp_to_cp; 206 | a_pppoe_cpdp_pass_ip; 207 | } 208 | max_size : 16; 209 | } 210 | 211 | action a_pppoe_cpdp_to_cp() { 212 | modify_field(ingress_md.cp, 1); 213 | #ifdef DEBUG_COUNTERS 214 | count(ctr_debug, 3); 215 | #endif 216 | } 217 | 218 | action a_pppoe_cpdp_pass_ip(version) { 219 | #ifdef DEBUG_COUNTERS 220 | count(ctr_debug, 4); 221 | #endif 222 | } 223 | 224 | 225 | 226 | // ===== t_antispoof_mac 227 | 228 | table t_antispoof_mac { 229 | reads { 230 | ingress_md.line_id : exact; 231 | vlan_service.vlanID : exact; 232 | ethernet_inner.srcAddr : exact; 233 | pppoe.sessionID : exact; 234 | } 235 | actions { 236 | _mark_drop; 237 | a_antispoof_mac_pass; 238 | } 239 | max_size : SUBSC_CAPACITY; 240 | } 241 | 242 | action a_antispoof_mac_pass(subsc_id, ctr_bucket) { 243 | modify_field(ingress_md.subsc_id, subsc_id); 244 | count(ctr_us_subsc, ctr_bucket); 245 | #ifdef DEBUG_COUNTERS 246 | count(ctr_debug, 5); 247 | #endif 248 | } 249 | 250 | #ifdef ENABLE_COUNTERS 251 | 252 | counter ctr_us_subsc { 253 | type : packets; 254 | instance_count : SUBSC_CAPACITY; 255 | } 256 | 257 | #endif 258 | 259 | 260 | 261 | // ===== t_antispoof_ipv4 262 | 263 | table t_antispoof_ipv4 { 264 | reads { 265 | ipv4.srcAddr : exact; 266 | ingress_md.line_id : exact; 267 | ingress_md.subsc_id : exact; 268 | } 269 | actions { 270 | _mark_drop; 271 | a_antispoof_ipv4v6_pass; 272 | } 273 | max_size : NET_CAPACITY; 274 | } 275 | 276 | action a_antispoof_ipv4v6_pass() { 277 | remove_header(pppoe); 278 | remove_header(vlan_subsc); 279 | remove_header(ethernet_inner); 280 | #ifdef DEBUG_COUNTERS 281 | count(ctr_debug, 6); 282 | #endif 283 | } 284 | 285 | action a_antispoof_ipv4v6_nextpm() { 286 | //No operation 287 | } 288 | 289 | 290 | #ifdef ENABLE_IPV6 291 | 292 | // ===== t_antispoof_ipv6 293 | 294 | table t_antispoof_ipv6_0 { 295 | reads { 296 | //ipv6.srcAddr_0_55 : exact; 297 | //ipv6.srcAddr_56_63 : exact; 298 | ipv6.srcAddr mask 0xffffffffffffffff0000000000000000: exact; 299 | ingress_md.line_id : exact; 300 | ingress_md.subsc_id : exact; 301 | } 302 | actions { 303 | a_antispoof_ipv4v6_pass; 304 | a_antispoof_ipv4v6_nextpm; //Default action: Go to next table (is shown in the control flow) 305 | } 306 | max_size : NET_CAPACITY; 307 | } 308 | 309 | table t_antispoof_ipv6_1 { 310 | reads { 311 | //ipv6.srcAddr_0_55 : exact; 312 | ipv6.srcAddr mask 0xffffffffffffff000000000000000000: exact; 313 | ingress_md.line_id : exact; 314 | ingress_md.subsc_id : exact; 315 | } 316 | actions { 317 | _mark_drop; //Default action: Drop (as there is no next table). 318 | a_antispoof_ipv4v6_pass; 319 | } 320 | max_size : NET_CAPACITY; 321 | } 322 | 323 | #endif 324 | 325 | 326 | // ===== t_us_expiredv4 327 | 328 | table t_us_expiredv4 { 329 | actions { 330 | a_us_routev4v6_tocp; 331 | } 332 | max_size : 1; 333 | } 334 | 335 | // ===== t_us_routev4 336 | 337 | table t_us_routev4 { 338 | reads { 339 | vlan_service.vlanID : exact; 340 | ipv4.dstAddr : lpm; 341 | } 342 | actions { 343 | _mark_drop; 344 | a_us_routev4v6; 345 | a_us_routev4v6_tocp; 346 | } 347 | max_size : ROUTE_CAPACITY ; 348 | } 349 | 350 | action a_us_routev4v6(out_port, mpls0_label, mpls1_label, via_hwaddr) { 351 | remove_header(vlan_service); 352 | modify_field(standard_metadata.egress_spec, out_port); 353 | modify_field(mpls0.label, mpls0_label); 354 | modify_field(mpls1.label, mpls1_label); 355 | modify_field(ethernet_outer.dstAddr, via_hwaddr); 356 | #ifdef DEBUG_COUNTERS 357 | count(ctr_debug, 7); 358 | #endif 359 | } 360 | 361 | action a_us_routev4v6_tocp() { 362 | modify_field(ingress_md.cp, 1); 363 | } 364 | 365 | #ifdef ENABLE_IPV6 366 | 367 | // ===== t_us_expiredv6 368 | 369 | table t_us_expiredv6 { 370 | actions { 371 | a_us_routev4v6_tocp; 372 | } 373 | max_size : 1; 374 | } 375 | 376 | // ===== t_us_routev6 377 | 378 | table t_us_routev6 { 379 | reads { 380 | vlan_service.vlanID : exact; 381 | ipv6.dstAddr : lpm; 382 | } 383 | actions { 384 | _mark_drop; 385 | a_us_routev4v6; 386 | a_us_routev4v6_tocp; 387 | } 388 | max_size : ROUTE_CAPACITY ; 389 | } 390 | 391 | #endif 392 | 393 | 394 | 395 | 396 | // ===== t_bng_tocp 397 | 398 | table t_bng_tocp { 399 | reads { 400 | standard_metadata.ingress_port : exact; 401 | //put here whatever you want to balance your load on. 402 | } 403 | actions { 404 | a_bng_tocp; 405 | } 406 | 407 | max_size : NUM_OF_CPS; 408 | } 409 | 410 | action a_bng_tocp(ourOuterMAC, remoteOuterMAC, cpPhysicalPort) { 411 | 412 | #ifdef DEBUG_COUNTERS 413 | count(ctr_debug, 11); 414 | #endif 415 | 416 | add_header(bng_cp); 417 | modify_field(bng_cp.eth_dstAddr, ethernet_outer.dstAddr); 418 | modify_field(bng_cp.eth_srcAddr, ethernet_outer.srcAddr); 419 | modify_field(bng_cp.eth_etherType, ethernet_outer.etherType); 420 | modify_field(bng_cp.fwd_port, standard_metadata.ingress_port); 421 | 422 | modify_field(ethernet_outer.dstAddr, remoteOuterMAC); 423 | modify_field(ethernet_outer.srcAddr, ourOuterMAC); 424 | modify_field(ethernet_outer.etherType, ETHERTYPE_CP); 425 | 426 | modify_field(standard_metadata.egress_spec, cpPhysicalPort); 427 | 428 | } 429 | 430 | 431 | 432 | // ======= Egress 433 | 434 | // ===== t_us_srcmac 435 | 436 | table t_us_srcmac { 437 | reads { 438 | standard_metadata.egress_port : exact; 439 | mpls0.label : exact; 440 | } 441 | actions { 442 | _nop; 443 | a_us_srcmac; 444 | } 445 | } 446 | 447 | action a_us_srcmac(src_mac) { 448 | modify_field(ethernet_outer.srcAddr, src_mac); 449 | #ifdef DEBUG_COUNTERS 450 | count(ctr_debug, 8); 451 | #endif 452 | } 453 | 454 | // ============= Downstream (Core -> Subscriber) 455 | 456 | // ===== t_ds_expiredv4 457 | 458 | table t_ds_expiredv4 { 459 | actions { 460 | a_ds_route_tocp; 461 | } 462 | max_size : 1; 463 | } 464 | 465 | // ===== t_ds_routev4 466 | 467 | table t_ds_routev4 { 468 | reads { 469 | ipv4.dstAddr : exact; 470 | } 471 | actions { 472 | _mark_drop; 473 | a_ds_route_pushstack; 474 | a_ds_route_tocp; 475 | } 476 | max_size : NET_CAPACITY; 477 | } 478 | 479 | action a_ds_route_pushstack(mpls0_label, mpls1_label, subsc_vid, service_vid, 480 | pppoe_session_id, out_port, inner_cpe_mac, ctr_bucket) { 481 | 482 | modify_field(mpls0.label, mpls0_label); 483 | modify_field(mpls1.label, mpls1_label); 484 | add_header(ethernet_inner); 485 | modify_field(ethernet_inner.dstAddr, inner_cpe_mac); 486 | modify_field(ethernet_inner.etherType, ETHERTYPE_VLAN); 487 | add_header(vlan_subsc); 488 | modify_field(vlan_subsc.vlanID, subsc_vid); 489 | modify_field(vlan_subsc.etherType, ETHERTYPE_VLAN); 490 | add_header(vlan_service); 491 | modify_field(vlan_service.vlanID, service_vid); 492 | modify_field(vlan_service.etherType, ETHERTYPE_PPPOES); 493 | add_header(pppoe); 494 | modify_field(pppoe.version, 1); 495 | modify_field(pppoe.typeID, 1); 496 | //Code can be empty. 497 | modify_field(pppoe.sessionID, pppoe_session_id); 498 | modify_field(standard_metadata.egress_spec, out_port); 499 | modify_field(ingress_md.ctr_bucket, ctr_bucket); 500 | 501 | #ifdef DEBUG_COUNTERS 502 | count(ctr_debug, 9); 503 | #endif 504 | 505 | #ifndef ENABLE_COUNTERS 506 | // count here if no meters, otherwise counting in the meter actions. 507 | // count(ctr_ds_subsc, ingress_md.ctr_bucket); 508 | #endif 509 | 510 | } 511 | 512 | action a_ds_route_nextpm() { 513 | //Nop 514 | } 515 | 516 | action a_ds_route_tocp() { 517 | modify_field(ingress_md.cp, 1); 518 | } 519 | 520 | 521 | 522 | #ifdef ENABLE_IPV6 523 | 524 | // ===== t_ds_expiredv6 525 | 526 | table t_ds_expiredv6 { 527 | actions { 528 | a_ds_route_tocp; 529 | } 530 | max_size : 1; 531 | } 532 | 533 | // ===== t_ds_routev6 534 | 535 | table t_ds_routev6_0 { 536 | reads { 537 | //ipv6.dstAddr_0_55 : exact; 538 | //ipv6.dstAddr_56_63 : exact; 539 | ipv6.dstAddr mask 0xffffffffffffffff0000000000000000: exact; 540 | } 541 | actions { 542 | a_ds_route_pushstack; 543 | a_ds_route_nextpm; 544 | a_ds_route_tocp; 545 | } 546 | max_size : NET_CAPACITY; 547 | } 548 | 549 | table t_ds_routev6_1 { 550 | reads { 551 | //ipv6.dstAddr_0_55 : exact; 552 | ipv6.dstAddr mask 0xffffffffffffff000000000000000000: exact; 553 | } 554 | actions { 555 | a_ds_route_pushstack; 556 | a_ds_route_tocp; 557 | _mark_drop; 558 | } 559 | max_size : NET_CAPACITY; 560 | } 561 | 562 | #endif 563 | 564 | 565 | 566 | 567 | 568 | 569 | #ifdef ENABLE_COUNTERS 570 | 571 | counter ctr_ds_subsc { 572 | type : packets; 573 | instance_count : SUBSC_CAPACITY; 574 | } 575 | 576 | #endif 577 | 578 | 579 | // ===== Various QoS/Meter specific things 580 | 581 | #ifdef ENABLE_DS_METERS 582 | 583 | meter mtr_ds_prio { 584 | type : bytes; 585 | result : ingress_md.meter_result; 586 | instance_count : SUBSC_CAPACITY; 587 | } 588 | 589 | meter mtr_ds_besteff { 590 | type : bytes; 591 | result : ingress_md.meter_result; 592 | instance_count : SUBSC_CAPACITY; 593 | } 594 | 595 | table t_ds_acl_qos_v4 { 596 | reads { 597 | vlan_service.vlanID : exact; 598 | ipv4.diffserv : ternary; 599 | ipv4.srcAddr : lpm; 600 | } 601 | actions { 602 | a_ds_acl_qos_prio; 603 | a_ds_acl_qos_besteff; 604 | _mark_drop; 605 | } 606 | max_size : 32; 607 | } 608 | 609 | table t_ds_acl_qos_v6 { 610 | reads { 611 | vlan_service.vlanID : exact; 612 | ipv6.trafficClass : ternary; 613 | ipv6.srcAddr : ternary; 614 | } 615 | actions { 616 | a_ds_acl_qos_prio; 617 | a_ds_acl_qos_besteff; 618 | _mark_drop; 619 | } 620 | max_size : 32; 621 | } 622 | 623 | action a_ds_acl_qos_prio() { 624 | execute_meter(mtr_ds_prio, ingress_md.ctr_bucket, ingress_md.meter_result); 625 | #ifdef ENABLE_COUNTERS 626 | count(ctr_ds_subsc, ingress_md.ctr_bucket); 627 | #endif 628 | #ifdef DEBUG_COUNTERS 629 | count(ctr_debug, 10); 630 | #endif 631 | } 632 | 633 | action a_ds_acl_qos_besteff() { 634 | execute_meter(mtr_ds_besteff, ingress_md.ctr_bucket, ingress_md.meter_result); 635 | #ifdef ENABLE_COUNTERS 636 | count(ctr_ds_subsc, ingress_md.ctr_bucket); 637 | #endif 638 | #ifdef DEBUG_COUNTERS 639 | count(ctr_debug, 10); 640 | #endif 641 | } 642 | 643 | #endif 644 | 645 | 646 | 647 | // ======= Egress 648 | 649 | // ===== t_ds_pppoe_aftermath_v4 650 | 651 | table t_ds_pppoe_aftermath_v4 { 652 | actions { 653 | a_ds_pppoe_aftermath_v4; 654 | } 655 | } 656 | 657 | action a_ds_pppoe_aftermath_v4() { 658 | add(pppoe.totalLength, ipv4.totalLen, 2); 659 | modify_field(pppoe.protocol, 0x0021); 660 | add(ipv4.ttl, ipv4.ttl, -1); 661 | 662 | #ifdef DEBUG_COUNTERS 663 | count(ctr_debug, 12); 664 | #endif 665 | 666 | } 667 | 668 | #ifdef ENABLE_IPV6 669 | 670 | // ===== t_ds_pppoe_aftermath_v6 671 | 672 | table t_ds_pppoe_aftermath_v6 { 673 | actions { 674 | a_ds_pppoe_aftermath_v6; 675 | } 676 | } 677 | 678 | action a_ds_pppoe_aftermath_v6() { 679 | add(pppoe.totalLength, ipv6.payloadLen, 42); //2 plus 40 bytes IPv6 header. 680 | modify_field(pppoe.protocol, 0x0057); 681 | add(ipv6.hopLimit, ipv6.hopLimit, -1); 682 | 683 | #ifdef DEBUG_COUNTERS 684 | count(ctr_debug, 14); 685 | #endif 686 | 687 | } 688 | 689 | #endif 690 | 691 | 692 | // ===== t_ds_srcmac 693 | 694 | table t_ds_srcmac { 695 | reads { 696 | standard_metadata.egress_port : exact; 697 | mpls0.label : exact; 698 | //Must set the same MAC addresses for every MPLS0 label (except the inner dst MAC) 699 | } 700 | actions { 701 | _drop; 702 | a_ds_srcmac; 703 | } 704 | max_size : 256; 705 | } 706 | 707 | action a_ds_srcmac(outer_src_mac, outer_dst_mac, inner_src_mac) { 708 | 709 | modify_field(ethernet_outer.srcAddr, outer_src_mac); 710 | modify_field(ethernet_outer.dstAddr, outer_dst_mac); 711 | modify_field(ethernet_inner.srcAddr, inner_src_mac); 712 | } 713 | 714 | 715 | table t_drop { 716 | actions { 717 | _drop; 718 | } 719 | } 720 | 721 | action _mark_drop() { 722 | modify_field(ingress_md.usds, TYPE_INVALID); 723 | #ifdef DEBUG_COUNTERS 724 | count(ctr_debug, 15); 725 | #endif 726 | } 727 | 728 | action _drop() { 729 | drop(); 730 | } 731 | 732 | control ingress { 733 | if (valid(bng_cp)) { 734 | apply(t_bng_fromcp); 735 | } else { 736 | apply(t_cptap_outer_ethernet); 737 | if (ingress_md.cp == 0) { 738 | apply(t_usds); 739 | if (ingress_md.usds == TYPE_US and valid(pppoe)) { 740 | ingress_upstream(); 741 | } else if (ingress_md.usds == TYPE_DS) { 742 | ingress_downstream(); 743 | } 744 | } 745 | if (ingress_md.cp == 1) { 746 | apply(t_bng_tocp); 747 | } 748 | } 749 | } 750 | 751 | control ingress_upstream { 752 | apply(t_line_map); 753 | apply(t_pppoe_cpdp); 754 | if (ingress_md.cp == 0) { 755 | apply(t_antispoof_mac); 756 | if (valid(ipv4)) { 757 | apply(t_antispoof_ipv4); 758 | if (ingress_md.usds == TYPE_US) { 759 | if (ipv4.ttl <= 1) apply(t_us_expiredv4); 760 | apply(t_us_routev4); 761 | } 762 | #ifdef ENABLE_IPV6 763 | } else if (valid(ipv6)) { 764 | apply(t_antispoof_ipv6_0) { 765 | a_antispoof_ipv4v6_nextpm { 766 | apply(t_antispoof_ipv6_1); 767 | } 768 | } 769 | if (ingress_md.usds == TYPE_US) { 770 | if (ipv6.hopLimit <= 1) apply(t_us_expiredv6); 771 | apply(t_us_routev6); 772 | } 773 | #endif 774 | } 775 | } 776 | } 777 | 778 | control ingress_downstream { 779 | if (valid(ipv4)) { 780 | if (ipv4.ttl <= 1) { 781 | apply(t_ds_expiredv4); 782 | } 783 | apply(t_ds_routev4); 784 | #ifdef ENABLE_DS_METERS 785 | if (ingress_md.usds == TYPE_DS) apply(t_ds_acl_qos_v4); 786 | #endif 787 | #ifdef ENABLE_IPV6 788 | } else if (valid(ipv6)) { 789 | if (ipv6.hopLimit <= 1) { 790 | apply(t_ds_expiredv6); 791 | } 792 | apply(t_ds_routev6_0) { 793 | a_ds_route_nextpm { 794 | apply(t_ds_routev6_1); 795 | } 796 | } 797 | #ifdef ENABLE_DS_METERS 798 | if (ingress_md.usds == TYPE_DS) apply(t_ds_acl_qos_v6); 799 | #endif 800 | #endif 801 | } 802 | } 803 | 804 | 805 | control egress { 806 | if (ingress_md.cp == 0) { 807 | if (ingress_md.usds == TYPE_US) { 808 | apply(t_us_srcmac); 809 | } if (ingress_md.usds == TYPE_DS) { 810 | if (valid(ipv4)) apply(t_ds_pppoe_aftermath_v4); 811 | #ifdef ENABLE_IPV6 812 | else apply(t_ds_pppoe_aftermath_v6); 813 | #endif 814 | apply(t_ds_srcmac); 815 | } else { 816 | //TYPE_INVALID 817 | apply(t_drop); 818 | } 819 | } 820 | } 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | -------------------------------------------------------------------------------- /generic/platf_bm_oss/README.md: -------------------------------------------------------------------------------- 1 | # p4se for bmv2 2 | 3 | ## Build instructions 4 | 5 | - `docker pull p4lang/p4app:latest` 6 | - Put the Git sources somehow into the Docker container 7 | - Run `./bot auto` for building, running, and testing 8 | -------------------------------------------------------------------------------- /generic/platf_bm_oss/autotest: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # Copyright 2018-present Open Networking Foundation 4 | # 5 | # Contributed and sponsored by Deutsche Telekom AG. 6 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 7 | # in collaboration with Technische Universitaet Darmstadt. 8 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 9 | # 10 | # Licensed under the Apache License, Version 2.0 (the "License"); 11 | # you may not use this file except in compliance with the License. 12 | # You may obtain a copy of the License at 13 | # 14 | # http://www.apache.org/licenses/LICENSE-2.0 15 | # 16 | # Unless required by applicable law or agreed to in writing, software 17 | # distributed under the License is distributed on an "AS IS" BASIS, 18 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | # See the License for the specific language governing permissions and 20 | # limitations under the License. 21 | # 22 | # For details see the file LICENSE in the top project directory. 23 | 24 | echo "Starting runtime manager..." 25 | 26 | $BASEDIR/runtime/test.py "simple_switch_CLI --thrift-port 1337" 27 | sleep 5 28 | 29 | exit 0 30 | -------------------------------------------------------------------------------- /generic/platf_bm_oss/bot: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # Copyright 2018-present Open Networking Foundation 4 | # 5 | # Contributed and sponsored by Deutsche Telekom AG. 6 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 7 | # in collaboration with Technische Universitaet Darmstadt. 8 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 9 | # 10 | # Licensed under the Apache License, Version 2.0 (the "License"); 11 | # you may not use this file except in compliance with the License. 12 | # You may obtain a copy of the License at 13 | # 14 | # http://www.apache.org/licenses/LICENSE-2.0 15 | # 16 | # Unless required by applicable law or agreed to in writing, software 17 | # distributed under the License is distributed on an "AS IS" BASIS, 18 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | # See the License for the specific language governing permissions and 20 | # limitations under the License. 21 | # 22 | # For details see the file LICENSE in the top project directory. 23 | 24 | # This script assumes all P4 bmv2 etc. build tools are in the PATH. 25 | # All tools should also be available in the official p4lang/p4app:latest 26 | # docker container. 27 | 28 | 29 | export BASEDIR=`dirname $(readlink -f $0)` 30 | source $BASEDIR/vars 31 | 32 | 33 | 34 | # ========== auto 35 | 36 | function auto { 37 | echo "======= Cleaning up.." 38 | clean || exit 101 39 | echo "======= Building..." 40 | build || exit 102 41 | echo "======= Running..." 42 | run-test || exit 103 43 | } 44 | 45 | 46 | # ========== clean 47 | 48 | function clean { 49 | 50 | rm -Rf $BASEDIR/build/ 51 | 52 | } 53 | 54 | 55 | # ========== build 56 | 57 | function build { 58 | 59 | SOURCE=$BASEDIR/../p4src/se.p4 60 | TARGET=$BASEDIR/build/p4c 61 | mkdir -p $TARGET 62 | p4c-bm2-ss --p4v 14 $SOURCE --p4runtime-file $TARGET/default.p4runtime --p4runtime-format text -o $TARGET/$PROJ_NAME.json 63 | 64 | } 65 | 66 | 67 | # =========== run-test 68 | 69 | function run-test { 70 | 71 | P4C_RESULT=$BASEDIR/build/p4c/$PROJ_NAME.json 72 | 73 | echo "=== Running simple_switch..." 74 | simple_switch --thrift-port 1337 $P4C_RESULT & 75 | 76 | switch_pid=$! 77 | echo "=== simple_switch started with PID $switch_pid ." 78 | echo "=== Starting tests in new process..." 79 | $BASEDIR/autotest 80 | RESULT=$? 81 | echo "=== Finished tests with return code $RESULT. Terminating switch gracefully..." 82 | kill $switch_pid 83 | wait $switch_pid 84 | exit $RESULT 85 | 86 | } 87 | 88 | 89 | # =========== raw-cli 90 | 91 | function raw-cli { 92 | 93 | P4C_RESULT=$BASEDIR/build/p4c/$PROJ_NAME.json 94 | 95 | echo "=== Running simple_switch..." 96 | simple_switch --thrift-port 1337 $P4C_RESULT & 97 | 98 | switch_pid=$! 99 | echo "=== simple_switch started with PID $switch_pid ." 100 | echo "=== Starting table population in new process..." 101 | $BASEDIR/runtime/test.py "simple_switch_CLI --thrift-port 1337" 102 | echo "=== Starting raw CLI..." 103 | simple_switch_CLI --thrift-port 1337 104 | echo "=== Terminated CLI, terminating switch gracefully..." 105 | kill $switch_pid 106 | wait $switch_pid 107 | exit 0 108 | 109 | } 110 | 111 | 112 | # =========== MAIN 113 | 114 | case "$1" in 115 | clean) 116 | clean 117 | ;; 118 | build) 119 | build 120 | ;; 121 | run-test) 122 | run-test 123 | ;; 124 | raw-cli) 125 | raw-cli 126 | ;; 127 | auto) 128 | auto 129 | ;; 130 | *) 131 | echo "Usage: ./bot {clean,build,run-test,raw-cli,auto}" 132 | exit 1 133 | ;; 134 | esac 135 | 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /generic/platf_bm_oss/runtime/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencord/p4se/5fd8de8874fd6a564fd421e42a937ce2a05a90ed/generic/platf_bm_oss/runtime/__init__.py -------------------------------------------------------------------------------- /generic/platf_bm_oss/runtime/setup_initruntime.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright 2018-present Open Networking Foundation 4 | # 5 | # Contributed and sponsored by Deutsche Telekom AG. 6 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 7 | # in collaboration with Technische Universitaet Darmstadt. 8 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 9 | # 10 | # Licensed under the Apache License, Version 2.0 (the "License"); 11 | # you may not use this file except in compliance with the License. 12 | # You may obtain a copy of the License at 13 | # 14 | # http://www.apache.org/licenses/LICENSE-2.0 15 | # 16 | # Unless required by applicable law or agreed to in writing, software 17 | # distributed under the License is distributed on an "AS IS" BASIS, 18 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | # See the License for the specific language governing permissions and 20 | # limitations under the License. 21 | # 22 | # For details see the file LICENSE in the top project directory. 23 | 24 | 25 | """This script just launches a control plane stub with the initial configuration. 26 | Use it e.g. for testing.""" 27 | 28 | import sys 29 | import os 30 | basedir = os.path.dirname(os.path.dirname( 31 | os.path.dirname(os.path.abspath(__file__)))) 32 | sys.path.append(basedir) 33 | 34 | import runtime.thriftcli_runtime_mgr as thr_rt 35 | import runtime.runtime_p4_manager as gen_cfg 36 | 37 | platf = thr_rt.ThriftCLIRuntimeMgr(sys.argv[1]) 38 | mgr = gen_cfg.RuntimeP4Manager(platf) 39 | mgr.setDefaults() 40 | platf.commitInitial() 41 | -------------------------------------------------------------------------------- /generic/platf_bm_oss/runtime/test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright 2018-present Open Networking Foundation 4 | # 5 | # Contributed and sponsored by Deutsche Telekom AG. 6 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 7 | # in collaboration with Technische Universitaet Darmstadt. 8 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 9 | # 10 | # Licensed under the Apache License, Version 2.0 (the "License"); 11 | # you may not use this file except in compliance with the License. 12 | # You may obtain a copy of the License at 13 | # 14 | # http://www.apache.org/licenses/LICENSE-2.0 15 | # 16 | # Unless required by applicable law or agreed to in writing, software 17 | # distributed under the License is distributed on an "AS IS" BASIS, 18 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | # See the License for the specific language governing permissions and 20 | # limitations under the License. 21 | # 22 | # For details see the file LICENSE in the top project directory. 23 | 24 | """This script is a test based on a control plane stub with the 25 | initial configuration. Use it e.g. for testing.""" 26 | 27 | import sys 28 | import os 29 | basedir = os.path.dirname(os.path.dirname( 30 | os.path.dirname(os.path.abspath(__file__)))) 31 | sys.path.append(basedir) 32 | 33 | import runtime.thriftcli_runtime_mgr as thr_rt 34 | import runtime.runtime_p4_manager as gen_cfg 35 | import tests.simple_test as simple_test 36 | 37 | platf = thr_rt.ThriftCLIRuntimeMgr(sys.argv[1]) 38 | mgr = gen_cfg.RuntimeP4Manager(platf) 39 | mgr.setDefaults() 40 | platf.commitInitial() 41 | 42 | test = simple_test.SimpleTest(mgr) 43 | test.run() 44 | -------------------------------------------------------------------------------- /generic/platf_bm_oss/vars: -------------------------------------------------------------------------------- 1 | 2 | # Copyright 2018-present Open Networking Foundation 3 | # 4 | # Contributed and sponsored by Deutsche Telekom AG. 5 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 6 | # in collaboration with Technische Universitaet Darmstadt. 7 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | # 21 | # For details see the file LICENSE in the top project directory. 22 | 23 | export PROJ_NAME=se_p4 24 | -------------------------------------------------------------------------------- /generic/platf_p4netfpga/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | out/ 3 | -------------------------------------------------------------------------------- /generic/platf_p4netfpga/netfpga_runtime/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencord/p4se/5fd8de8874fd6a564fd421e42a937ce2a05a90ed/generic/platf_p4netfpga/netfpga_runtime/__init__.py -------------------------------------------------------------------------------- /generic/platf_p4netfpga/netfpga_runtime/p4netfpga_runtime.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019-present Open Networking Foundation 2 | # 3 | # Contributed and sponsored by Deutsche Telekom AG. 4 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 5 | # in collaboration with Technische Universitaet Darmstadt. 6 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | # For details see the file LICENSE in the top project directory. 21 | 22 | 23 | import os,json,time,subprocess,threading 24 | 25 | 26 | MAX_ALLOWED_THREADS = 1 27 | THREAD_TIMEOUT = 5 #seconds 28 | 29 | class P4NetfpgaRuntime: 30 | 31 | def __init__(self, targetfile): 32 | self.targetfile = targetfile 33 | tables = {} 34 | self.allTables = ["t_usds", "t_us_srcmac", "t_ds_srcmac", "t_cptap_outer_ethernet", "t_bng_tocp", "t_bng_fromcp", "t_line_map", "t_pppoe_cpdp", "t_us_routev4", "t_ds_routev4", "t_antispoof_ipv4", "t_antispoof_mac"] 35 | self.cli_commands = [] 36 | 37 | 38 | def makeInitial(self): 39 | with open(self.targetfile, 'w') as outfile: 40 | for line in self.cli_commands: 41 | outfile.write("%s\n" % line) 42 | 43 | 44 | 45 | 46 | 47 | def addTableRuleRaw(self, table, name, match, actionName, actionParams): 48 | if not any(table in s for s in self.allTables): 49 | return 0 50 | 51 | if table == "t_antispoof_mac": 52 | new_match = [{},{},{},{}] 53 | for match_entry in match: 54 | if match_entry[0] == "ingress_md.line_id": 55 | new_match[0] = ("line_id", match_entry[1]) 56 | if match_entry[0] == "vlan_service.vlanID": 57 | new_match[1] = ("servicevlan", match_entry[1]) 58 | if match_entry[0] == "ethernet_inner.srcAddr": 59 | new_match[2] = ("innerMac", match_entry[1]) 60 | if match_entry[0] == "pppoe.sessionID": 61 | new_match[3] = ("pppoe-line", match_entry[1]) 62 | match = new_match 63 | 64 | if table == "t_antispoof_ipv4": 65 | new_match = [{},{},{}] 66 | for match_entry in match: 67 | if match_entry[0] == "ipv4.srcAddr": 68 | new_match[0] = ("ipv4src", match_entry[1]) 69 | if match_entry[0] == "ingress_md.line_id": 70 | new_match[1] = ("line_id", match_entry[1]) 71 | if match_entry[0] == "ingress_md.subsc_id": 72 | new_match[2] = ("subsc_id", match_entry[1]) 73 | match = new_match 74 | 75 | if actionName == "a_ds_route_pushstack": 76 | new_actionParams = [{},{},{},{},{},{},{},{}] 77 | for action_entry in actionParams: 78 | if action_entry[0] == "mpls0_label": 79 | new_actionParams[0] = ("mpls0", action_entry[1]) 80 | if action_entry[0] == "mpls1_label": 81 | new_actionParams[1] = ("mpls1", action_entry[1]) 82 | if action_entry[0] == "subsc_vid": 83 | new_actionParams[2] = ("subsc-vid", action_entry[1]) 84 | if action_entry[0] == "service_vid": 85 | new_actionParams[3] = ("service-id", action_entry[1]) 86 | if action_entry[0] == "pppoe_session_id": 87 | new_actionParams[4] = ("pppoe_id", action_entry[1]) 88 | if action_entry[0] == "out_port": 89 | new_actionParams[5] = ("out_port", action_entry[1]) 90 | if action_entry[0] == "inner_cpe_mac": 91 | new_actionParams[6] = ("inner_cpe_mac", action_entry[1]) 92 | if action_entry[0] == "ctr_bucket": 93 | new_actionParams[7] = ("ctr_bucket", action_entry[1]) 94 | actionParams=new_actionParams 95 | 96 | 97 | if table == "t_line_map": 98 | print(match) 99 | 100 | 101 | 102 | cmd = "table_cam_add_entry " + table + " " + actionName + " " 103 | for match_entry in match: 104 | if "/" in str(match_entry[1]): 105 | continue #dirty workaround as p4-netfpga does not support lpm 106 | cmd = cmd + str(match_entry[1]) + " " 107 | cmd = cmd + "=> " 108 | for action_entry in actionParams: 109 | cmd = cmd + str(action_entry[1]) + " " 110 | self.cli_commands.append(cmd) 111 | return 0 112 | 113 | 114 | def delTableRuleRaw(self, table, name): 115 | print("del Rule table currently not supported") 116 | 117 | 118 | 119 | def setTableDefaultRuleRaw(self, table, actionName, actionParams): 120 | if not any(table in s for s in self.allTables): 121 | return 0 122 | print("default rule: "+table +" " + actionName) 123 | return 0 124 | 125 | 126 | #ports of p4-NetFPGA are one-hot encoded: {DMA, NF3, DMA, NF2, DMA, NF1, DMA, NF0} 127 | 128 | def getPort(self, symbol): 129 | print("get Port") 130 | if symbol == "ctrl": 131 | return "2" 132 | if symbol == "access1": 133 | return "1" #external 134 | if symbol == "core1": 135 | return "4" #external 136 | if symbol == "access2": 137 | return "16" #external 138 | if symbol == "core2": 139 | return "64" #external 140 | raise ValueError("P4 port not defined!") 141 | 142 | 143 | 144 | 145 | def setMeterRates(self, name, meter_name, meter_index, meter_count, rate1, burst1): 146 | #currently not supported 147 | return 0 148 | 149 | 150 | 151 | def addParserValueSetEntry(self, name, value, mask=None): 152 | #parser value-set currently not supported 153 | return 0 154 | 155 | valSet = {"value_set": name, "entries":[]} 156 | self._addParserValSetEntryRaw(valSet, value, mask) 157 | self.cf["parser_value_sets"]["configs"].append(valSet) 158 | 159 | def onEnd(self): 160 | if MAX_ALLOWED_THREADS > 1: 161 | print "Waiting for threads to exit..." 162 | time.sleep(THREAD_TIMEOUT) 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /generic/platf_p4netfpga/netfpga_runtime/simple_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | 4 | # Copyright 2019-present Open Networking Foundation 5 | # 6 | # Contributed and sponsored by Deutsche Telekom AG. 7 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 8 | # in collaboration with Technische Universitaet Darmstadt. 9 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 10 | # 11 | # Licensed under the Apache License, Version 2.0 (the "License"); 12 | # you may not use this file except in compliance with the License. 13 | # You may obtain a copy of the License at 14 | # 15 | # http://www.apache.org/licenses/LICENSE-2.0 16 | # 17 | # Unless required by applicable law or agreed to in writing, software 18 | # distributed under the License is distributed on an "AS IS" BASIS, 19 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | # See the License for the specific language governing permissions and 21 | # limitations under the License. 22 | # 23 | # For details see the file LICENSE in the top project directory. 24 | 25 | 26 | ### you might have to install the python dependency ipaddr first: 27 | # pip install ipaddr --user 28 | 29 | 30 | #### Config params: 31 | DO_MOONGEN = True 32 | DO_VERIFICATION = False 33 | FOUR_PORT = False 34 | 35 | 36 | 37 | import sys,os 38 | basedir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 39 | sys.path.append(basedir) 40 | 41 | basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 42 | print(basedir) 43 | sys.path.append(basedir) 44 | 45 | print(basedir) 46 | 47 | import p4netfpga_runtime as fpga_cfg 48 | import runtime.runtime_p4_manager as gen_cfg 49 | import tests.simple_test as simple_test 50 | import runtime.simple_stats as sim 51 | 52 | def do_one_run(runid=0, size=32): 53 | 54 | print "===== Doing run " + str(runid) + ", size=" + str(size) + ".=========" 55 | 56 | stats = sim.SimpleStats(basedir + "/out/p4_netfpga_simple_test_sub" + str(size) + "_run" + str(runid) + ".csv") 57 | 58 | platf = fpga_cfg.P4NetfpgaRuntime(basedir + "/build/CliCommands_"+str(size)+".txt") 59 | mgr = gen_cfg.RuntimeP4Manager(platf) 60 | 61 | 62 | mgr.setDefaults() 63 | 64 | test = simple_test.SimpleTest(mgr, stats) 65 | 66 | test.run() 67 | 68 | test.addManySubs(size) 69 | 70 | platf.makeInitial() 71 | 72 | if DO_MOONGEN: 73 | print("no load generator api found") 74 | ####create your load generator config here, e.g. config file for a MoonGen lua script 75 | 76 | 77 | 78 | do_one_run(128, size=32) 79 | do_one_run(128, size=64) 80 | do_one_run(128, size=128) 81 | do_one_run(128, size=256) 82 | do_one_run(128, size=512) 83 | do_one_run(128, size=1024) 84 | do_one_run(128, size=2048) 85 | do_one_run(128, size=3500) 86 | do_one_run(128, size=4000) 87 | do_one_run(128, size=4096) 88 | 89 | exit() 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /generic/platf_p4netfpga/netfpga_runtime/simple_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | MYDIR=`dirname $(readlink -f $0)` 4 | python $MYDIR/simple_test.py 5 | -------------------------------------------------------------------------------- /generic/platf_p4netfpga/src/header_16.p4: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * 4 | * Contributed and sponsored by Deutsche Telekom AG. 5 | * Originally developed as part of the D-Nets 6 P4 Service Edge project 6 | * in collaboration with Technische Universitaet Darmstadt. 7 | * Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * For details see the file LICENSE in the top project directory. 22 | */ 23 | 24 | struct ingress_md_t { 25 | bit<2> usds; 26 | bit<1> cp; 27 | bit<32> line_id; 28 | bit<8> subsc_id; 29 | bit<16> ctr_bucket; 30 | bit<32> meter_result; 31 | } 32 | 33 | 34 | header bng_cp_t { 35 | bit<16> stamp; 36 | bit<32> fwd_port; //storing bng ingress port for messages to Control Plane 37 | bit<48> eth_dstAddr; 38 | bit<48> eth_srcAddr; 39 | bit<16> eth_etherType; 40 | } 41 | 42 | header ethernet_t { 43 | bit<48> dstAddr; 44 | bit<48> srcAddr; 45 | bit<16> etherType; 46 | } 47 | 48 | header ipv4_t { 49 | bit<4> version; 50 | bit<4> ihl; 51 | bit<8> diffserv; 52 | bit<16> totalLen; 53 | bit<16> identification; 54 | bit<3> flags; 55 | bit<13> fragOffset; 56 | bit<8> ttl; 57 | bit<8> protocol; 58 | bit<16> hdrChecksum; 59 | bit<32> srcAddr; 60 | bit<32> dstAddr; 61 | } 62 | 63 | header ipv6_t { 64 | bit<4> version; 65 | bit<8> trafficClass; 66 | bit<20> flowLabel; 67 | bit<16> payloadLen; 68 | bit<8> nextHdr; 69 | bit<8> hopLimit; 70 | bit<128> srcAddr; 71 | bit<128> dstAddr; 72 | } 73 | 74 | header mpls_t { 75 | bit<20> label; 76 | bit<3> tc; 77 | bit<1> s; 78 | bit<8> ttl; 79 | } 80 | 81 | header pppoe_t { 82 | bit<4> version; 83 | bit<4> typeID; 84 | bit<8> code; 85 | bit<16> sessionID; 86 | bit<16> totalLength; 87 | bit<16> protocol; //See http://www.iana.org/assignments/ppp-numbers/ppp-numbers.xhtml 88 | //User-plane: IPv4: 0x0021, IPv6: 0x0057, 89 | ////Control-plane: LCP: 0xc021, IPv6CP: 0x8057, IPCP: 90 | } 91 | 92 | header vlan_t { 93 | bit<16> vlanID; 94 | bit<16> etherType; 95 | } 96 | #define PPPOE_PROTOCOL_IP4 16w0x0021 97 | #define PPPOE_PROTOCOL_IP6 16w0x0057 98 | 99 | #define ETHERTYPE_IPV4 16w0x0800 100 | #define ETHERTYPE_VLAN 16w0x8100 101 | #define ETHERTYPE_PPPOED 16w0x8863 102 | #define ETHERTYPE_PPPOES 16w0x8864 103 | #define ETHERTYPE_MPLS 16w0x8847 104 | #define ETHERTYPE_CP 16w0x8765 //A (remote) CP packet that must be forwarded on a specific port. 105 | -------------------------------------------------------------------------------- /generic/platf_p4netfpga/src/p4-BNG.p4: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present Open Networking Foundation 3 | * 4 | * Contributed and sponsored by Deutsche Telekom AG. 5 | * Originally developed as part of the D-Nets 6 P4 Service Edge project 6 | * in collaboration with Technische Universitaet Darmstadt. 7 | * Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * For details see the file LICENSE in the top project directory. 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | #include "header_16.p4" 28 | 29 | 30 | //#define ENABLE_COUNTERS //counters are currently not supported 31 | //#define ENABLE_DS_METERS //meters are currently not supported by netfpga 32 | //#define ENABLE_IPV6 33 | 34 | #define TYPE_DS 0x0 35 | #define TYPE_US 0x1 36 | #define TYPE_INVALID 0x2 37 | 38 | #define SUBSC_CAPACITY 4096 39 | #define NET_CAPACITY 3*SUBSC_CAPACITY 40 | #define ROUTE_CAPACITY 256 41 | 42 | #define NUM_OF_CPS 64 43 | 44 | 45 | struct metadata { 46 | ingress_md_t ingress_md; 47 | } 48 | 49 | struct headers { 50 | bng_cp_t bng_cp; 51 | ethernet_t ethernet_inner; 52 | ethernet_t ethernet_outer; 53 | ipv4_t ipv4; 54 | ipv6_t ipv6; 55 | mpls_t mpls0; 56 | mpls_t mpls1; 57 | pppoe_t pppoe; 58 | vlan_t vlan_service; 59 | vlan_t vlan_subsc; 60 | } 61 | struct digest_data_t { 62 | bit<32> foobar; //not used 63 | } 64 | #define mpls_0_accesslabels 0x80001 65 | // Parser Implementation 66 | @Xilinx_MaxPacketRegion(16384) 67 | parser TopParser(packet_in packet, //packet - b 68 | out headers hdr, //hdr - p 69 | out metadata meta, //meta - user_metadata 70 | out digest_data_t digest_data, 71 | inout sume_metadata_t sume_metadata) { //standard metatdata 72 | //value_set>(4) mpls_0_accesslabels; //currently not supported by P4NetFPGA compiler. workaround by hard coded in P4 73 | state parse_above_mpls { 74 | transition select(hdr.mpls0.label) { 75 | mpls_0_accesslabels: parse_ethernet_inner; 76 | //TODO: add further access labes here or replace by P4 parser value set, if supported by hardware 77 | default: parse_ip; 78 | } 79 | } 80 | state parse_bng_cp { 81 | packet.extract(hdr.bng_cp); 82 | transition accept; 83 | } 84 | state parse_ethernet_inner { 85 | packet.extract(hdr.ethernet_inner); 86 | transition select(hdr.ethernet_inner.etherType) { 87 | ETHERTYPE_VLAN: parse_vlan_subsc; 88 | default: accept; 89 | } 90 | } 91 | state parse_ethernet_outer { 92 | packet.extract(hdr.ethernet_outer); 93 | transition select(hdr.ethernet_outer.etherType) { 94 | ETHERTYPE_MPLS: parse_mpls0; 95 | ETHERTYPE_CP: parse_bng_cp; 96 | default: accept; 97 | } 98 | } 99 | state parse_ip { 100 | transition select((packet.lookahead>())[3:0]) { 101 | 4w4: parse_ipv4; 102 | 4w6: parse_ipv6; 103 | default: accept; 104 | } 105 | } 106 | state parse_ipv4 { 107 | packet.extract(hdr.ipv4); 108 | transition accept; 109 | } 110 | state parse_ipv6 { 111 | packet.extract(hdr.ipv6); 112 | transition accept; 113 | } 114 | state parse_mpls0 { 115 | packet.extract(hdr.mpls0); 116 | transition select(hdr.mpls0.s) { 117 | 1w1: accept; 118 | default: parse_mpls1; 119 | } 120 | } 121 | state parse_mpls1 { 122 | packet.extract(hdr.mpls1); 123 | transition select(hdr.mpls1.s) { 124 | 1w1: parse_above_mpls; 125 | default: accept; 126 | } 127 | } 128 | state parse_pppoe { 129 | packet.extract(hdr.pppoe); 130 | transition select(hdr.pppoe.protocol) { 131 | PPPOE_PROTOCOL_IP4: parse_ip; 132 | PPPOE_PROTOCOL_IP6: parse_ip; 133 | default: accept; 134 | } 135 | } 136 | state parse_vlan_service { 137 | packet.extract(hdr.vlan_service); 138 | transition select(hdr.vlan_service.etherType) { 139 | ETHERTYPE_PPPOED: parse_pppoe; 140 | ETHERTYPE_PPPOES: parse_pppoe; 141 | default: accept; 142 | } 143 | } 144 | state parse_vlan_subsc { 145 | packet.extract(hdr.vlan_subsc); 146 | transition select(hdr.vlan_subsc.etherType) { 147 | ETHERTYPE_VLAN: parse_vlan_service; 148 | ETHERTYPE_PPPOED: parse_pppoe; 149 | ETHERTYPE_PPPOES: parse_pppoe; 150 | default: accept; 151 | } 152 | } 153 | state start { 154 | transition parse_ethernet_outer; 155 | } 156 | } 157 | 158 | // match-action pipeline 159 | control TopPipe(inout headers hdr, 160 | inout metadata meta, 161 | inout digest_data_t digest_data, 162 | inout sume_metadata_t sume_metadata) { 163 | 164 | action a_bng_output() { 165 | hdr.ethernet_outer.dstAddr = hdr.bng_cp.eth_dstAddr; 166 | hdr.ethernet_outer.srcAddr = hdr.bng_cp.eth_srcAddr; 167 | hdr.ethernet_outer.etherType = hdr.bng_cp.eth_etherType; 168 | sume_metadata.dst_port = (bit<8>)hdr.bng_cp.fwd_port; 169 | meta.ingress_md.cp = 1w1; 170 | hdr.bng_cp.setInvalid(); 171 | } 172 | action action_drop() { 173 | sume_metadata.drop = 1; 174 | } 175 | action a_bng_tocp(bit<48> ourOuterMAC, bit<48> remoteOuterMAC, bit<8> cpPhysicalPort) { 176 | hdr.bng_cp.setValid(); 177 | hdr.bng_cp.eth_dstAddr = hdr.ethernet_outer.dstAddr; 178 | hdr.bng_cp.eth_srcAddr = hdr.ethernet_outer.srcAddr; 179 | hdr.bng_cp.eth_etherType = hdr.ethernet_outer.etherType; 180 | hdr.bng_cp.fwd_port = (bit<32>)sume_metadata.src_port; 181 | hdr.ethernet_outer.dstAddr = remoteOuterMAC; 182 | hdr.ethernet_outer.srcAddr = ourOuterMAC; 183 | hdr.ethernet_outer.etherType = ETHERTYPE_CP; 184 | sume_metadata.dst_port = cpPhysicalPort; 185 | } 186 | action a_cptap_cp() { 187 | meta.ingress_md.cp = 1w1; 188 | } 189 | action a_cptap_dp() { 190 | } 191 | action a_usds_handle_ds() { 192 | meta.ingress_md.usds = 2w0x0; 193 | } 194 | action a_usds_handle_us() { 195 | hdr.vlan_service.setValid(); 196 | meta.ingress_md.usds = 2w0x1; 197 | } 198 | action mark_to_drop() { 199 | meta.ingress_md.usds = 2w0x2; 200 | } 201 | table t_bng_fromcp { 202 | actions = { 203 | a_bng_output; 204 | action_drop; 205 | } 206 | key = { 207 | hdr.ethernet_outer.dstAddr : exact; 208 | hdr.ethernet_outer.srcAddr : exact; 209 | sume_metadata.src_port : exact; 210 | } 211 | size = NUM_OF_CPS; 212 | } 213 | table t_bng_tocp { 214 | actions = { 215 | a_bng_tocp; 216 | } 217 | key = { 218 | sume_metadata.src_port: exact; 219 | } 220 | size = NUM_OF_CPS; 221 | } 222 | table t_cptap_outer_ethernet { 223 | actions = { 224 | a_cptap_cp; 225 | a_cptap_dp; 226 | } 227 | key = { 228 | hdr.ethernet_outer.dstAddr : exact; 229 | hdr.ethernet_outer.etherType: exact; 230 | } 231 | size = 64; 232 | } 233 | table t_usds { 234 | actions = { 235 | a_usds_handle_ds; 236 | a_usds_handle_us; 237 | mark_to_drop; 238 | } 239 | key = { 240 | hdr.ethernet_outer.dstAddr : exact; 241 | sume_metadata.src_port : exact; 242 | hdr.mpls0.label : exact; 243 | } 244 | size = 256; 245 | } 246 | ///// from ingress downstream 247 | #ifdef ENABLE_COUNTERS 248 | counter(32w8192, CounterType.packets) ctr_ds_subsc; 249 | #endif 250 | 251 | #ifdef ENABLE_DS_METERS 252 | meter(32w8192, MeterType.bytes) mtr_ds_besteff; 253 | meter(32w8192, MeterType.bytes) mtr_ds_prio; 254 | action a_ds_acl_qos_prio() { 255 | mtr_ds_prio.execute_meter((bit<32>)(bit<32>)meta.ingress_md.ctr_bucket, meta.ingress_md.meter_result); 256 | #ifdef ENABLE_COUNTERS 257 | ctr_ds_subsc.count((bit<32>)meta.ingress_md.ctr_bucket); 258 | #endif 259 | } 260 | action a_ds_acl_qos_besteff() { 261 | mtr_ds_besteff.execute_meter((bit<32>)(bit<32>)meta.ingress_md.ctr_bucket, meta.ingress_md.meter_result); 262 | #ifdef ENABLE_COUNTERS 263 | ctr_ds_subsc.count((bit<32>)meta.ingress_md.ctr_bucket); 264 | #endif 265 | } 266 | table t_ds_acl_qos_v4 { 267 | actions = { 268 | a_ds_acl_qos_prio; 269 | a_ds_acl_qos_besteff; 270 | mark_to_drop; 271 | } 272 | key = { 273 | hdr.vlan_service.vlanID: exact; 274 | hdr.ipv4.diffserv : ternary; 275 | hdr.ipv4.srcAddr : lpm; 276 | } 277 | size = 64; 278 | } 279 | table t_ds_acl_qos_v6 { 280 | actions = { 281 | a_ds_acl_qos_prio; 282 | a_ds_acl_qos_besteff; 283 | mark_to_drop; 284 | } 285 | key = { 286 | hdr.vlan_service.vlanID: exact; 287 | hdr.ipv6.trafficClass : ternary; 288 | hdr.ipv6.srcAddr : ternary; 289 | } 290 | size = 64; 291 | } 292 | #endif 293 | 294 | 295 | action a_ds_route_tocp() { 296 | meta.ingress_md.cp = 1w1; 297 | } 298 | action a_ds_route_pushstack(bit<20> mpls0_label, bit<20> mpls1_label, bit<16> subsc_vid, bit<16> service_vid, bit<16> pppoe_session_id, bit<8> out_port, bit<48> inner_cpe_mac, bit<16> ctr_bucket) { 299 | hdr.mpls0.label = mpls0_label; 300 | hdr.mpls1.label = mpls1_label; 301 | hdr.ethernet_inner.setValid(); 302 | hdr.ethernet_inner.dstAddr = inner_cpe_mac; 303 | hdr.ethernet_inner.etherType = ETHERTYPE_VLAN; 304 | hdr.vlan_subsc.setValid(); 305 | hdr.vlan_subsc.vlanID = subsc_vid; 306 | hdr.vlan_subsc.etherType = ETHERTYPE_VLAN; 307 | hdr.vlan_service.setValid(); 308 | hdr.vlan_service.vlanID = service_vid; 309 | hdr.vlan_service.etherType = ETHERTYPE_PPPOES; 310 | hdr.pppoe.setValid(); 311 | hdr.pppoe.version = 4w1; 312 | hdr.pppoe.typeID = 4w1; 313 | hdr.pppoe.sessionID = pppoe_session_id; 314 | sume_metadata.dst_port = out_port; 315 | meta.ingress_md.ctr_bucket = ctr_bucket; 316 | } 317 | action a_ds_route_nextpm() { 318 | } 319 | table t_ds_routev4 { 320 | actions = { 321 | mark_to_drop; 322 | a_ds_route_pushstack; 323 | a_ds_route_tocp; 324 | } 325 | key = { 326 | hdr.ipv4.dstAddr: exact; 327 | } 328 | size = SUBSC_CAPACITY; 329 | } 330 | #ifdef ENABLE_IPV6 331 | table t_ds_routev6_0 { 332 | actions = { 333 | a_ds_route_pushstack; 334 | a_ds_route_nextpm; 335 | a_ds_route_tocp; 336 | } 337 | key = { 338 | hdr.ipv6.dstAddr[127:64]: exact @name("ipv6.dstAddr") ; 339 | } 340 | size = NET_CAPACITY; 341 | } 342 | table t_ds_routev6_1 { 343 | actions = { 344 | a_ds_route_pushstack; 345 | a_ds_route_tocp; 346 | mark_to_drop; 347 | } 348 | key = { 349 | hdr.ipv6.dstAddr[127:72]: exact @name("ipv6.dstAddr") ; 350 | } 351 | size = NET_CAPACITY; 352 | } 353 | #endif 354 | 355 | ///From ingress upstream: 356 | #ifdef ENABLE_COUNTERS 357 | counter(32w8192, CounterType.packets) ctr_us_subsc; 358 | #endif 359 | action a_antispoof_ipv4v6_pass() { 360 | hdr.pppoe.setInvalid(); 361 | hdr.vlan_subsc.setInvalid(); 362 | hdr.ethernet_inner.setInvalid(); 363 | } 364 | action a_antispoof_ipv4v6_nextpm() {} 365 | action a_antispoof_mac_pass(bit<8> subsc_id, bit<32> ctr_bucket) { 366 | meta.ingress_md.subsc_id = subsc_id; 367 | #ifdef ENABLE_COUNTERS 368 | ctr_us_subsc.count((bit<32>)ctr_bucket); 369 | #endif 370 | } 371 | action a_line_map_pass(bit<32> line_id) { 372 | meta.ingress_md.line_id = line_id; 373 | } 374 | action a_pppoe_cpdp_to_cp() { 375 | meta.ingress_md.cp = 1w1; 376 | } 377 | action a_pppoe_cpdp_pass_ip() { 378 | } 379 | action a_us_routev4v6_tocp() { 380 | meta.ingress_md.cp = 1w1; 381 | } 382 | action a_us_routev4v6(bit<8> out_port, bit<20> mpls0_label, bit<20> mpls1_label, bit<48> via_hwaddr) { 383 | hdr.vlan_service.setInvalid(); 384 | sume_metadata.dst_port = out_port; 385 | hdr.mpls0.label = mpls0_label; 386 | hdr.mpls1.label = mpls1_label; 387 | hdr.ethernet_outer.dstAddr = via_hwaddr; 388 | } 389 | table t_antispoof_ipv4 { 390 | actions = { 391 | mark_to_drop; 392 | a_antispoof_ipv4v6_pass; 393 | } 394 | key = { 395 | hdr.ipv4.srcAddr : exact; 396 | meta.ingress_md.line_id : exact; 397 | meta.ingress_md.subsc_id: exact; 398 | } 399 | size = SUBSC_CAPACITY; 400 | } 401 | #ifdef ENABLE_IPV6 402 | table t_antispoof_ipv6_0 { 403 | actions = { 404 | a_antispoof_ipv4v6_pass; 405 | a_antispoof_ipv4v6_nextpm; 406 | } 407 | key = { 408 | hdr.ipv6.srcAddr[127:64]: exact @name("ipv6.srcAddr") ; 409 | meta.ingress_md.line_id : exact; 410 | meta.ingress_md.subsc_id: exact; 411 | } 412 | size = NET_CAPACITY; 413 | } 414 | table t_antispoof_ipv6_1 { 415 | actions = { 416 | mark_to_drop; 417 | a_antispoof_ipv4v6_pass; 418 | } 419 | key = { 420 | hdr.ipv6.srcAddr[127:72]: exact @name("ipv6.srcAddr") ; 421 | meta.ingress_md.line_id : exact; 422 | meta.ingress_md.subsc_id: exact; 423 | } 424 | size = NET_CAPACITY; 425 | } 426 | #endif 427 | 428 | 429 | table t_antispoof_mac { 430 | actions = { 431 | mark_to_drop; 432 | a_antispoof_mac_pass; 433 | } 434 | key = { 435 | meta.ingress_md.line_id : exact; 436 | hdr.vlan_service.vlanID : exact; 437 | hdr.ethernet_inner.srcAddr: exact; 438 | hdr.pppoe.sessionID : exact; 439 | } 440 | size = SUBSC_CAPACITY; 441 | } 442 | table t_line_map { 443 | actions = { 444 | mark_to_drop; 445 | a_line_map_pass; 446 | } 447 | key = { 448 | sume_metadata.src_port : exact; 449 | hdr.mpls0.label : exact; 450 | hdr.mpls1.label : exact; 451 | hdr.vlan_subsc.vlanID : exact; 452 | } 453 | size = SUBSC_CAPACITY; 454 | } 455 | table t_pppoe_cpdp { 456 | actions = { 457 | mark_to_drop; 458 | a_pppoe_cpdp_to_cp; 459 | a_pppoe_cpdp_pass_ip; 460 | } 461 | key = { 462 | hdr.ethernet_inner.dstAddr: exact; 463 | hdr.vlan_service.etherType: exact; 464 | hdr.pppoe.protocol : exact; 465 | } 466 | size = NUM_OF_CPS; 467 | } 468 | table t_us_routev4 { 469 | actions = { 470 | mark_to_drop; 471 | a_us_routev4v6; 472 | a_us_routev4v6_tocp; 473 | } 474 | key = { 475 | hdr.vlan_service.vlanID: exact; 476 | } 477 | size = ROUTE_CAPACITY; 478 | } 479 | 480 | #ifdef ENABLE_IPV6 481 | table t_us_routev6 { 482 | actions = { 483 | mark_to_drop; 484 | a_us_routev4v6; 485 | a_us_routev4v6_tocp; 486 | } 487 | key = { 488 | hdr.vlan_service.vlanID: exact; 489 | hdr.ipv6.dstAddr : exact; // lpm - not supported in SDNet for tables with multiple inputs 490 | } 491 | size = ROUTE_CAPACITY; 492 | } 493 | #endif 494 | 495 | ////////////////////// from egress pipeline ///////////////////////////////// 496 | action a_ds_pppoe_aftermath_v4() { 497 | hdr.pppoe.totalLength = hdr.ipv4.totalLen + 16w2; 498 | hdr.pppoe.protocol = 16w0x21; 499 | hdr.ipv4.ttl = hdr.ipv4.ttl + 8w255; 500 | } 501 | 502 | action a_ds_srcmac(bit<48> outer_src_mac, bit<48> outer_dst_mac, bit<48> inner_src_mac) { 503 | hdr.ethernet_outer.srcAddr = outer_src_mac; 504 | hdr.ethernet_outer.dstAddr = outer_dst_mac; 505 | hdr.ethernet_inner.srcAddr = inner_src_mac; 506 | } 507 | action no_op() { 508 | } 509 | action a_us_srcmac(bit<48> src_mac) { 510 | hdr.ethernet_outer.srcAddr = src_mac; 511 | } 512 | #ifdef ENABLE_IPV6 513 | action a_ds_pppoe_aftermath_v6() { 514 | hdr.pppoe.totalLength = hdr.ipv6.payloadLen + 16w42; 515 | hdr.pppoe.protocol = 16w0x57; 516 | hdr.ipv6.hopLimit = hdr.ipv6.hopLimit + 8w255; 517 | } 518 | table t_ds_pppoe_aftermath_v6 { 519 | actions = { 520 | a_ds_pppoe_aftermath_v6; 521 | } 522 | } 523 | #endif 524 | table t_ds_srcmac { 525 | actions = { 526 | mark_to_drop; 527 | a_ds_srcmac; 528 | } 529 | key = { 530 | sume_metadata.dst_port : exact; 531 | hdr.mpls0.label : exact; 532 | } 533 | size = 256; 534 | } 535 | table t_us_srcmac { 536 | actions = { 537 | no_op; 538 | a_us_srcmac; 539 | } 540 | key = { 541 | sume_metadata.dst_port : exact; 542 | hdr.mpls0.label : exact; 543 | } 544 | } 545 | 546 | 547 | ///////////////////////////////////////////////////////////////////////////// 548 | //////////////// Controll Flow Description starts here ////////////////////// 549 | ///////////////////////////////////////////////////////////////////////////// 550 | apply { 551 | if (hdr.bng_cp.isValid()) { 552 | t_bng_fromcp.apply(); 553 | } 554 | else { 555 | t_cptap_outer_ethernet.apply(); 556 | if (meta.ingress_md.cp == 1w0) { 557 | t_usds.apply(); 558 | if (meta.ingress_md.usds == 2w0x1 && hdr.pppoe.isValid()) { 559 | t_line_map.apply(); 560 | t_pppoe_cpdp.apply(); 561 | if (meta.ingress_md.cp == 1w0) { 562 | t_antispoof_mac.apply(); 563 | if (hdr.ipv4.isValid()) { 564 | t_antispoof_ipv4.apply(); 565 | if (meta.ingress_md.usds == 2w0x1) { 566 | if (hdr.ipv4.ttl <= 8w1) { 567 | a_us_routev4v6_tocp(); 568 | } 569 | t_us_routev4.apply(); 570 | } 571 | } 572 | #ifdef ENABLE_IPV6 573 | else { 574 | if (hdr.ipv6.isValid()) { 575 | switch (t_antispoof_ipv6_0.apply().action_run) { 576 | a_antispoof_ipv4v6_nextpm: { 577 | t_antispoof_ipv6_1.apply(); 578 | } 579 | } 580 | 581 | if (meta.ingress_md.usds == 2w0x1) { 582 | if (hdr.ipv6.hopLimit <= 8w1) { 583 | a_us_routev4v6_tocp(); 584 | } 585 | t_us_routev6.apply(); 586 | } 587 | } 588 | } 589 | #endif 590 | } 591 | } 592 | else { 593 | if (meta.ingress_md.usds == 2w0x0) { 594 | if (hdr.ipv4.isValid()) { 595 | if (hdr.ipv4.ttl <= 8w1) { 596 | a_ds_route_tocp(); 597 | } 598 | t_ds_routev4.apply(); 599 | #ifdef ENABLE_DS_METERS 600 | if (meta.ingress_md.usds == 2w0x0) { 601 | t_ds_acl_qos_v4.apply(); 602 | } 603 | #endif 604 | 605 | } 606 | #ifdef ENABLE_IPV6 607 | else { 608 | if (hdr.ipv6.isValid()) { 609 | if (hdr.ipv6.hopLimit <= 8w1) { 610 | a_ds_route_tocp(); 611 | } 612 | switch (t_ds_routev6_0.apply().action_run) { 613 | a_ds_route_nextpm: { 614 | t_ds_routev6_1.apply(); 615 | } 616 | } 617 | #ifdef ENABLE_DS_METERS 618 | if (meta.ingress_md.usds == 2w0x0) { 619 | t_ds_acl_qos_v6.apply(); 620 | } 621 | #endif 622 | } 623 | } 624 | #endif 625 | } 626 | } 627 | } 628 | if (meta.ingress_md.cp == 1w1) { 629 | t_bng_tocp.apply(); 630 | } 631 | } 632 | //P4_14 egress pipe starts here 633 | if (meta.ingress_md.cp == 1w0) { 634 | if (meta.ingress_md.usds == 2w0x1) { 635 | t_us_srcmac.apply(); 636 | } 637 | if (meta.ingress_md.usds == 2w0x0) { 638 | if (hdr.ipv4.isValid()) { 639 | a_ds_pppoe_aftermath_v4(); 640 | } 641 | else { 642 | #ifdef ENABLE_IPV6 643 | t_ds_pppoe_aftermath_v6.apply(); 644 | #endif 645 | } 646 | t_ds_srcmac.apply(); 647 | } 648 | else { 649 | mark_to_drop(); 650 | } 651 | } 652 | } 653 | } 654 | 655 | 656 | // Deparser Implementation 657 | @Xilinx_MaxPacketRegion(16384) 658 | control TopDeparser(packet_out packet, 659 | in headers hdr, 660 | in metadata meta, 661 | inout digest_data_t digest_data, 662 | inout sume_metadata_t sume_metadata) { 663 | apply { 664 | packet.emit(hdr.ethernet_outer); 665 | packet.emit(hdr.bng_cp); 666 | packet.emit(hdr.mpls0); 667 | packet.emit(hdr.mpls1); 668 | packet.emit(hdr.ethernet_inner); 669 | packet.emit(hdr.vlan_subsc); 670 | packet.emit(hdr.vlan_service); 671 | packet.emit(hdr.pppoe); 672 | packet.emit(hdr.ipv6); 673 | packet.emit(hdr.ipv4); 674 | } 675 | } 676 | 677 | 678 | // Instantiate the SimpleSumeSwitch 679 | SimpleSumeSwitch(TopParser(), TopPipe(), TopDeparser()) main; 680 | 681 | -------------------------------------------------------------------------------- /generic/runtime/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencord/p4se/5fd8de8874fd6a564fd421e42a937ce2a05a90ed/generic/runtime/__init__.py -------------------------------------------------------------------------------- /generic/runtime/meterbuckets.py: -------------------------------------------------------------------------------- 1 | 2 | # Copyright 2018-present Open Networking Foundation 3 | # 4 | # Contributed and sponsored by Deutsche Telekom AG. 5 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 6 | # in collaboration with Technische Universitaet Darmstadt. 7 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | # 21 | # For details see the file LICENSE in the top project directory. 22 | 23 | 24 | class MeterBuckets: 25 | 26 | def __init__(self, caller, size, limit): 27 | self.caller = caller 28 | self.size = size 29 | self.limit = limit 30 | self.bucket2occupation = {} 31 | self.subscriber2bucket_occupation_class = {} 32 | self.cls2buckets = {} 33 | 34 | def getSub(self, sub): 35 | bkt, occupationNo, cls = self.subscriber2bucket_occupation_class[sub] 36 | return bkt*self.size+occupationNo 37 | 38 | def addSub(self, sub, cls): 39 | if sub in self.subscriber2bucket_occupation_class: 40 | bkt, occupationNo, cls = self.subscriber2bucket_occupation_class[sub] 41 | return bkt*self.size+occupationNo 42 | 43 | if cls in self.cls2buckets: 44 | for bkt in self.cls2buckets[cls]: 45 | position = self._addSubToBucket(sub, bkt, cls) 46 | if position >= 0: 47 | return bkt*self.size+position 48 | bkt = self._makeBucket(cls) 49 | position = self._addSubToBucket(sub, bkt, cls) 50 | return bkt*self.size+position 51 | 52 | def delSub(self, sub): 53 | if not sub in self.subscriber2bucket_occupation_class: 54 | return None 55 | bucket, occupationNo, cls = self.subscriber2bucket_occupation_class[sub] 56 | del self.bucket2occupation[bucket][occupationNo] 57 | if not self.bucket2occupation[bucket]: 58 | # Delete bucket, as it is unused. 59 | del self.bucket2occupation[bucket] 60 | del self.cls2buckets[cls] 61 | del self.subscriber2bucket_occupation_class[sub] 62 | return bucket*self.size+occupationNo 63 | 64 | def _addSubToBucket(self, sub, bkt, cls): 65 | 66 | occupations = self.bucket2occupation[bkt] 67 | 68 | for i in range(0, self.size): 69 | if not i in occupations: 70 | self.bucket2occupation[bkt][i] = True 71 | self.subscriber2bucket_occupation_class[sub] = bkt, i, cls 72 | return i 73 | return -1 74 | 75 | def _makeBucket(self, cls): 76 | 77 | if not cls in self.cls2buckets: 78 | self.cls2buckets[cls] = {} 79 | 80 | for i in range(0, self.limit): 81 | if not i in self.bucket2occupation: 82 | self.bucket2occupation[i] = {} 83 | self.cls2buckets[cls][i] = True 84 | self.caller.createMeterBucket(cls, i, self.size) 85 | return i 86 | 87 | raise Exception("Meter bucket limit exceeded.") 88 | 89 | def getForDump(self): 90 | return self.bucket2occupation, self.subscriber2bucket_occupation_class, self.cls2buckets 91 | -------------------------------------------------------------------------------- /generic/runtime/meterbuckets_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright 2018-present Open Networking Foundation 4 | # 5 | # Contributed and sponsored by Deutsche Telekom AG. 6 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 7 | # in collaboration with Technische Universitaet Darmstadt. 8 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 9 | # 10 | # Licensed under the Apache License, Version 2.0 (the "License"); 11 | # you may not use this file except in compliance with the License. 12 | # You may obtain a copy of the License at 13 | # 14 | # http://www.apache.org/licenses/LICENSE-2.0 15 | # 16 | # Unless required by applicable law or agreed to in writing, software 17 | # distributed under the License is distributed on an "AS IS" BASIS, 18 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | # See the License for the specific language governing permissions and 20 | # limitations under the License. 21 | # 22 | # For details see the file LICENSE in the top project directory. 23 | 24 | import time 25 | import random 26 | import meterbuckets 27 | 28 | 29 | class MeterBucketsTest: 30 | 31 | def createMeterBucket(self, cls, id, size): 32 | print "T: Creating meter bucket: ", cls, id, size 33 | 34 | 35 | if __name__ == '__main__': 36 | 37 | b = meterbuckets.MeterBuckets(MeterBucketsTest(), 32, 8) 38 | 39 | subs = {} 40 | 41 | while True: 42 | 43 | subint = random.randint(0, 100) 44 | 45 | sub = "Sub" + str(subint) 46 | cls = "Cls" + str(random.randint(0, 3)) 47 | 48 | ret = b.addSub(sub, cls) 49 | print "T: Adding subscriber " + sub + " to " + \ 50 | cls + ", returned " + str(ret) + "as offset." 51 | #print b.getForDump() 52 | subs[subint] = True 53 | 54 | # time.sleep(0.1) 55 | 56 | subint = random.randint(0, 100) 57 | 58 | if not subint in subs: 59 | continue 60 | 61 | sub = "Sub" + str(subint) 62 | cls = "Cls" + str(random.randint(0, 3)) 63 | 64 | ret = b.delSub(sub) 65 | print "T: Deleting subscriber " + sub + " to " + \ 66 | cls + ". returned " + str(ret) + "as offset." 67 | #print b.getForDump() 68 | del subs[subint] 69 | 70 | # time.sleep(0.1) 71 | -------------------------------------------------------------------------------- /generic/runtime/p4_userplane_exception.py: -------------------------------------------------------------------------------- 1 | 2 | # Copyright 2018-present Open Networking Foundation 3 | # 4 | # Contributed and sponsored by Deutsche Telekom AG. 5 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 6 | # in collaboration with Technische Universitaet Darmstadt. 7 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | # 21 | # For details see the file LICENSE in the top project directory. 22 | 23 | class P4UserPlaneException(Exception): 24 | """Raised whenever there is an error while changing the 25 | userplane path""" 26 | 27 | def __init__(self, message, command, output): 28 | self.message = message 29 | self.command = command 30 | self.output = output 31 | 32 | def __str__(self): 33 | return "P4UserPlaneException: '" + self.message + "', '" + self.command + "', '" + self.output + "'" 34 | 35 | -------------------------------------------------------------------------------- /generic/runtime/runtime_p4_manager.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright 2018-present Open Networking Foundation 4 | # 5 | # Contributed and sponsored by Deutsche Telekom AG. 6 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 7 | # in collaboration with Technische Universitaet Darmstadt. 8 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 9 | # 10 | # Licensed under the Apache License, Version 2.0 (the "License"); 11 | # you may not use this file except in compliance with the License. 12 | # You may obtain a copy of the License at 13 | # 14 | # http://www.apache.org/licenses/LICENSE-2.0 15 | # 16 | # Unless required by applicable law or agreed to in writing, software 17 | # distributed under the License is distributed on an "AS IS" BASIS, 18 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | # See the License for the specific language governing permissions and 20 | # limitations under the License. 21 | # 22 | # For details see the file LICENSE in the top project directory. 23 | 24 | # Requires python-ipaddr 25 | 26 | import ipaddr 27 | import binascii 28 | import meterbuckets 29 | import threading 30 | 31 | ENABLE_IPV6 = True 32 | 33 | 34 | METERBUCKET_SIZE = 512 35 | 36 | METER_BWCLASSES = { 37 | "SNAIL": [500, 50, 50, 10], 38 | # [, , , ] (Kbit/s) 39 | # Note: burst must be set to >0, otherwise no traffic will pass! 40 | "SPEED_50": [50000, 5000, 10000, 1000], 41 | "SPEED_100": [50000, 5000, 10000, 1000], 42 | 43 | # 10G god mode for Moongen testing 44 | "TENGIG": [10000000, 1000000, 10000000, 1000000] 45 | } 46 | 47 | # Important: A "labelport" here is the (physical port, MPLS0 label) tuple. 48 | 49 | 50 | class RuntimeP4Manager: 51 | """Platform-independent runtime manager""" 52 | 53 | def __init__(self, platf): 54 | self.platf = platf 55 | self.accessPorts = {} 56 | self.corePorts = {} 57 | self.line_info = {} 58 | self.routesv4 = {} 59 | self.routesv6 = {} 60 | self.SUBSC_FACING_INNERMAC = "52:54:00:01:01:01" 61 | 62 | self.statelock = threading.Lock() 63 | 64 | self.mbuckets = meterbuckets.MeterBuckets( 65 | self, METERBUCKET_SIZE, 128) # FIXME: set the limit better? 66 | 67 | 68 | def setDefaults(self): 69 | """ Sets the initial P4 runtime config. Must always be implemented. 70 | Run at the very start to set initial rules""" 71 | 72 | self.platf.setTableDefaultRuleRaw("t_bng_fromcp", "_drop", []) 73 | self.platf.setTableDefaultRuleRaw( 74 | "t_cptap_outer_ethernet", "a_cptap_dp", []) 75 | 76 | self.platf.setTableDefaultRuleRaw("t_usds", "_mark_drop", []) 77 | self.platf.setTableDefaultRuleRaw("t_line_map", "_mark_drop", []) 78 | self.platf.setTableDefaultRuleRaw( 79 | "t_pppoe_cpdp", "a_pppoe_cpdp_to_cp", []) 80 | 81 | # self.platf_addTableRuleRaw("t_pppoe_cpdp", { "ethernet_inner.dstAddr" : vlan_service.etherType "0xffffffffffff", 0021,0 82 | self.platf.addTableRuleRaw("t_pppoe_cpdp", "V4_DP", 83 | [("ethernet_inner.dstAddr", self.SUBSC_FACING_INNERMAC), ( 84 | "vlan_service.etherType", "0x8864"), ("pppoe.protocol", "0x0021")], 85 | "a_pppoe_cpdp_pass_ip", []) # IPv4 to Dataplane 86 | self.platf.addTableRuleRaw("t_pppoe_cpdp", "V6_DP", 87 | [("ethernet_inner.dstAddr", self.SUBSC_FACING_INNERMAC), ( 88 | "vlan_service.etherType", "0x8864"), ("pppoe.protocol", "0x0057")], 89 | "a_pppoe_cpdp_pass_ip", []) # IPv6 to Dataplane 90 | 91 | self.platf.setTableDefaultRuleRaw("t_antispoof_mac", "_mark_drop", []) 92 | self.platf.setTableDefaultRuleRaw("t_antispoof_ipv4", "_mark_drop", []) 93 | self.platf.setTableDefaultRuleRaw( 94 | "t_us_expiredv4", "a_us_routev4v6_tocp", []) 95 | self.platf.setTableDefaultRuleRaw("t_us_routev4", "_mark_drop", []) 96 | if ENABLE_IPV6: 97 | self.platf.setTableDefaultRuleRaw( 98 | "t_antispoof_ipv6_0", "a_antispoof_ipv4v6_nextpm", []) 99 | self.platf.setTableDefaultRuleRaw( 100 | "t_antispoof_ipv6_1", "_mark_drop", []) 101 | self.platf.setTableDefaultRuleRaw( 102 | "t_us_expiredv6", "a_us_routev4v6_tocp", []) 103 | self.platf.setTableDefaultRuleRaw("t_us_routev6", "_mark_drop", []) 104 | self.platf.setTableDefaultRuleRaw("t_us_srcmac", "_nop", []) 105 | 106 | self.platf.setTableDefaultRuleRaw( 107 | "t_ds_expiredv4", "a_ds_route_tocp", []) 108 | self.platf.setTableDefaultRuleRaw("t_ds_routev4", "_mark_drop", []) 109 | self.platf.setTableDefaultRuleRaw( 110 | "t_ds_pppoe_aftermath_v4", "a_ds_pppoe_aftermath_v4", []) 111 | # could be "drop" for a stricter ACL. 112 | self.platf.setTableDefaultRuleRaw( 113 | "t_ds_acl_qos_v4", "a_ds_acl_qos_besteff", []) 114 | if ENABLE_IPV6: 115 | self.platf.setTableDefaultRuleRaw( 116 | "t_ds_expiredv6", "a_ds_route_tocp", []) 117 | self.platf.setTableDefaultRuleRaw( 118 | "t_ds_routev6_0", "a_ds_route_nextpm", []) 119 | self.platf.setTableDefaultRuleRaw( 120 | "t_ds_routev6_1", "_mark_drop", []) 121 | self.platf.setTableDefaultRuleRaw( 122 | "t_ds_pppoe_aftermath_v6", "a_ds_pppoe_aftermath_v6", []) 123 | # could be "drop" for a stricter ACL. 124 | self.platf.setTableDefaultRuleRaw( 125 | "t_ds_acl_qos_v6", "a_ds_acl_qos_besteff", []) 126 | 127 | self.platf.setTableDefaultRuleRaw("t_ds_srcmac", "_drop", []) 128 | 129 | self.platf.addParserValueSetEntry("mpls_0_accesslabels", "0x80000", mask="0x80000") 130 | 131 | self.connectCP("0x52540000d474", "0x52540001d474", 132 | self.platf.getPort("ctrl"), "Default") 133 | 134 | 135 | 136 | 137 | 138 | def connectCP(self, ourOuterMAC, remoteOuterMAC, physicalPort, name): 139 | """Connects a control plane (CP, preparation to support multiple CP endpoints)""" 140 | 141 | # Default rule, but in the future we could use it for load balancing. 142 | self.platf.setTableDefaultRuleRaw("t_bng_tocp", "a_bng_tocp", [( 143 | "ourOuterMAC", ourOuterMAC), ("remoteOuterMAC", remoteOuterMAC), ("cpPhysicalPort", physicalPort)]) 144 | 145 | # Match incoming from DP to send it out on appropriate CP port. 146 | self.platf.addTableRuleRaw("t_bng_fromcp", name, 147 | [("ethernet_outer.dstAddr", ourOuterMAC), ("ethernet_outer.srcAddr", 148 | remoteOuterMAC), ("standard_metadata.ingress_port", physicalPort)], 149 | "a_bng_output", []) 150 | 151 | 152 | 153 | 154 | def enableLabelPortAccess(self, port, mpls0_label, ourOuterMAC, peerOuterMAC): 155 | """Enables a physical port / MPLS0 label combination as an 156 | access labelport (a labelport where an AN is connected to) 157 | Whatever must be entered in ourOuterMAC, peerOuterMAC, mpls0_label 158 | depends on the way MPLS is done in the network, the dataplane 159 | just matches it (drops it if the fields in the packet are not 160 | as expected). MPLS1 label will be set on a per-subscriber basis later.""" 161 | 162 | # TODO: Consistency check! 163 | 164 | self.platf.addTableRuleRaw("t_usds", "AccessPort_" + str(port) + "_" + str(mpls0_label), 165 | [("ethernet_outer.dstAddr", ourOuterMAC), ( 166 | "standard_metadata.ingress_port", port), ("mpls0.label", mpls0_label)], 167 | "a_usds_handle_us", []) # Note that the outer src MAC is not checked for spoofing at the moment (trusted MPLS net assumed). 168 | 169 | self.platf.addTableRuleRaw("t_ds_srcmac", "AccessPort_" + str(port) + "_" + str(mpls0_label), 170 | [("standard_metadata.egress_port", port), 171 | ("mpls0.label", mpls0_label)], 172 | "a_ds_srcmac", [("outer_src_mac", ourOuterMAC), ("outer_dst_mac", peerOuterMAC), ("inner_src_mac", self.SUBSC_FACING_INNERMAC)]) 173 | 174 | self.statelock.acquire() 175 | if not port in self.accessPorts: 176 | self.accessPorts[port] = {} 177 | self.accessPorts[port][mpls0_label] = { 178 | "our_mac": ourOuterMAC, "peer_mac": peerOuterMAC} 179 | self.statelock.release() 180 | 181 | 182 | 183 | 184 | def enableLabelPortCore(self, port, mpls0_label, ourMAC): 185 | """Enables a physical port / MPLS0 label combination as a core 186 | labelport (a labelport where an uplink gateway is connected to) 187 | Whatever must be entered in ourOuterMAC, peerOuterMAC, mpls0_label 188 | depends on the way MPLS is done in the network, the dataplane just 189 | matches it (drops it if the fields in the packet are not as expected). 190 | The core peer's MAC (e.g. a core router as the "next hop") can 191 | be set in the routing table later.""" 192 | 193 | # TODO: Consistency check! 194 | 195 | self.platf.addTableRuleRaw("t_usds", "CorePort_" + str(port) + "_" + str(mpls0_label), 196 | [("ethernet_outer.dstAddr", ourMAC), ( 197 | "standard_metadata.ingress_port", port), ("mpls0.label", mpls0_label)], 198 | "a_usds_handle_ds", []) # Note that the src MAC is not checked for spoofing at the moment (trusted MPLS net assumed). 199 | 200 | self.platf.addTableRuleRaw("t_us_srcmac", "CorePort_" + str(port) + "_" + str(mpls0_label), 201 | [("standard_metadata.egress_port", port), 202 | ("mpls0.label", mpls0_label)], 203 | "a_us_srcmac", [("src_mac", ourMAC)]) 204 | 205 | self.statelock.acquire() 206 | if not port in self.corePorts: 207 | self.corePorts[port] = {} 208 | self.corePorts[port][mpls0_label] = {"our_mac": ourMAC} 209 | self.statelock.release() 210 | 211 | 212 | 213 | 214 | 215 | def addSubscLine(self, port, mpls0_label, mpls1_label, subsc_vlan_id, line_id): 216 | """Registers a subscriber line. e.g. if a new customer premise is 217 | connected to a DSLAM port. When a line is registered, the SE waits 218 | for PPPoE authentication attempts of subscribers on it. Matches 219 | the expected (port, mpls0_label, mpls1_label, subsc_vlan_id) 220 | combination in this packet and assigns the specified line_id, 221 | which is an arbitrary 32-bit unsigned integer number used to match 222 | the subscriber in the following pipeline.""" 223 | 224 | # TODO: Consistency check! 225 | 226 | self.platf.addTableRuleRaw("t_line_map", "Line_" + str(line_id), 227 | [("standard_metadata.ingress_port", port), ("mpls0.label", mpls0_label), ( 228 | "mpls1.label", mpls1_label), ("vlan_subsc.vlanID", subsc_vlan_id)], 229 | "a_line_map_pass", [("line_id", line_id)]) 230 | 231 | self.statelock.acquire() 232 | self.line_info[line_id] = {"port": port, "mpls0_label": mpls0_label, "mpls1_label": mpls1_label, "subsc_vlan_id": subsc_vlan_id, "line_id": line_id, 233 | "sessions": {}} 234 | self.statelock.release() 235 | 236 | 237 | 238 | 239 | def addSubscSession(self, line_id, line_sub_id, service_id, cpe_mac, pppoe_sess_id, bwClass): 240 | """Establishes a new active session. 241 | Policing data is an array: [, ] (Kbit/s)""" 242 | 243 | # TODO: Consistency check! 244 | 245 | sessid = (line_id << 4) | line_sub_id 246 | ctr_bucket = self.mbuckets.addSub(sessid, bwClass) 247 | 248 | self.platf.addTableRuleRaw("t_antispoof_mac", "Sess_" + str(line_id) + "_" + str(line_sub_id), 249 | [("ingress_md.line_id", line_id), 250 | ("vlan_service.vlanID", service_id), 251 | ("ethernet_inner.srcAddr", cpe_mac), 252 | ("pppoe.sessionID", pppoe_sess_id)], 253 | "a_antispoof_mac_pass", [("subsc_id", line_sub_id), ("ctr_bucket", ctr_bucket)]) 254 | 255 | self.statelock.acquire() 256 | 257 | self.line_info[line_id]["sessions"][line_sub_id] = {"cpe_mac": cpe_mac, "pppoe_sess_id": pppoe_sess_id, "ctr_bucket": ctr_bucket, 258 | "service_id": service_id, "nets_v4": {}, "nets_v6": {}, "bwClass": bwClass} 259 | 260 | self.statelock.release() 261 | 262 | def delSubscSession(self, line_id, line_sub_id): 263 | 264 | sessid = (line_id << 4) | line_sub_id 265 | ctr_bucket = self.mbuckets.delSub(sessid) 266 | 267 | if not line_id in self.line_info: 268 | raise ValueError('Line ID not registered.') 269 | lineSessions = self.line_info[line_id]["sessions"] 270 | if not line_sub_id in lineSessions: 271 | raise ValueError('Line ID not registered.') 272 | session = lineSessions[line_sub_id] 273 | 274 | for net in session["nets_v4"]: 275 | self._delSubscNetV4(line_id, line_sub_id, net) 276 | for net in session["nets_v6"]: 277 | self._delSubscNetV6(line_id, line_sub_id, net) 278 | self.platf.delTableRuleRaw( 279 | "t_antispoof_mac", "Sess_" + str(line_id) + "_" + str(line_sub_id)) 280 | 281 | self.statelock.acquire() 282 | del self.line_info[line_id]["sessions"][line_sub_id] 283 | self.statelock.release() 284 | 285 | def createMeterBucket(self, cls, i, size): 286 | 287 | policingData = METER_BWCLASSES[cls] 288 | 289 | self.platf.setMeterRates( 290 | "ds_prio_bkt_" + str(i), "mtr_ds_prio", i*size, size, policingData[0], policingData[1]) 291 | self.platf.setMeterRates("ds_besteff_bkt_" + str(i), "mtr_ds_besteff", 292 | i*size, size, policingData[2], policingData[3]) 293 | 294 | 295 | def addSubscNetV4(self, line_id, line_sub_id, netv4_cidr_str): 296 | """Add a v4 network to the authenticated subscriber's session.""" 297 | 298 | # TODO: Consistency check! 299 | 300 | id_str = "Net4_" + str(line_id) + "_" + str(line_sub_id) + \ 301 | "_" + netv4_cidr_str.replace("/", "_") 302 | 303 | # Upstream 304 | 305 | self.platf.addTableRuleRaw("t_antispoof_ipv4", id_str, 306 | [("ingress_md.line_id", line_id), 307 | ("ingress_md.subsc_id", line_sub_id), 308 | ("ipv4.srcAddr", netv4_cidr_str)], 309 | "a_antispoof_ipv4v6_pass", []) 310 | 311 | self.statelock.acquire() 312 | lineinfo = self.line_info[line_id] 313 | subscinfo = lineinfo["sessions"][line_sub_id] 314 | subscinfo["nets_v4"][netv4_cidr_str] = True 315 | self.statelock.release() 316 | 317 | # Downstream 318 | 319 | self.platf.addTableRuleRaw("t_ds_routev4", id_str, 320 | [("ipv4.dstAddr", netv4_cidr_str)], 321 | "a_ds_route_pushstack", [("mpls0_label", lineinfo["mpls0_label"]), ("mpls1_label", lineinfo["mpls1_label"]), 322 | ("subsc_vid", lineinfo["subsc_vlan_id"]), ( 323 | "service_vid", subscinfo["service_id"]), 324 | ("pppoe_session_id", subscinfo["pppoe_sess_id"]), ( 325 | "out_port", lineinfo["port"]), 326 | ("inner_cpe_mac", subscinfo["cpe_mac"]), ("ctr_bucket", subscinfo["ctr_bucket"])]) 327 | 328 | 329 | 330 | 331 | def delSubscNetV4(self, line_id, line_sub_id, netv4_cidr_str): 332 | """Delete a v4 network from the authenticated subscriber's session.""" 333 | lineinfo = self.line_info[line_id] 334 | subscinfo = lineinfo["sessions"][line_sub_id] 335 | _delSubscNetV4(line_id, line_sub_id, netv4_cidr_str) 336 | 337 | self.statelock.acquire() 338 | del subscinfo["nets_v4"][netv4_cidr_str] 339 | self.statelock.release() 340 | 341 | 342 | 343 | 344 | def _delSubscNetV4(self, line_id, line_sub_id, netv4_cidr_str): 345 | id_str = "Net4_" + str(line_id) + "_" + str(line_sub_id) + \ 346 | "_" + netv4_cidr_str.replace("/", "_") 347 | self.platf.delTableRuleRaw("t_antispoof_ipv4", id_str) 348 | self.platf.delTableRuleRaw("t_ds_routev4", id_str) 349 | 350 | 351 | 352 | 353 | 354 | def addSubscNetV6(self, line_id, line_sub_id, netv6_addr_cidr): 355 | """Add a v6 network to the authenticated subscriber's session.""" 356 | 357 | # TODO: Consistency check! 358 | 359 | addr = ipaddr.IPv6Network(netv6_addr_cidr) 360 | 361 | netv6 = "0x" + binascii.hexlify(bytes(addr.packed)) 362 | # FIXME: check for 0s above subnet? 363 | 364 | if addr.prefixlen == 64: 365 | table_id = 0 366 | elif addr.prefixlen == 56: 367 | table_id = 1 368 | else: 369 | raise ValueError('Can only assign /56 and /64 subnets.') 370 | 371 | # Populate upstream table 372 | 373 | match_params_us = [("ingress_md.line_id", line_id), 374 | ("ingress_md.subsc_id", line_sub_id), 375 | ("ipv6.srcAddr", netv6)] 376 | 377 | v6_addr_sanitized = netv6_addr_cidr.replace("/", "_").replace(":", "_") 378 | table_name = "t_antispoof_ipv6_" + str(table_id) 379 | rule_name = "Net6_" + str(table_id) + "_" + str(line_id) + \ 380 | "_" + str(line_sub_id) + "_" + v6_addr_sanitized 381 | 382 | self.platf.addTableRuleRaw( 383 | table_name, rule_name, match_params_us, "a_antispoof_ipv4v6_pass", []) 384 | 385 | self.statelock.acquire() 386 | lineinfo = self.line_info[line_id] 387 | subscinfo = lineinfo["sessions"][line_sub_id] 388 | subscinfo["nets_v6"][netv6_addr_cidr] = True 389 | self.statelock.release() 390 | 391 | # Populate downstream table. 392 | 393 | match_params_ds = [("ipv6.dstAddr", netv6)] 394 | 395 | table_name = "t_ds_routev6_" + str(table_id) 396 | 397 | self.platf.addTableRuleRaw(table_name, rule_name, match_params_ds, 398 | "a_ds_route_pushstack", [("mpls0_label", lineinfo["mpls0_label"]), ("mpls1_label", lineinfo["mpls1_label"]), 399 | ("subsc_vid", lineinfo["subsc_vlan_id"]), ( 400 | "service_vid", subscinfo["service_id"]), 401 | ("pppoe_session_id", subscinfo["pppoe_sess_id"]), ( 402 | "out_port", lineinfo["port"]), 403 | ("inner_cpe_mac", subscinfo["cpe_mac"]), ("ctr_bucket", subscinfo["ctr_bucket"])]) 404 | 405 | 406 | 407 | 408 | 409 | 410 | def delSubscNetV6(self, line_id, line_sub_id, netv6_addr_cidr): 411 | """Delete a v6 network from the authenticated subscriber's session.""" 412 | 413 | 414 | lineinfo = self.line_info[line_id] 415 | subscinfo = lineinfo["sessions"][line_sub_id] 416 | _delSubscNetV4(line_id, line_sub_id, netv6_addr_cidr) 417 | 418 | self.statelock.acquire() 419 | del subscinfo["nets_v6"][netv6_addr_cidr] 420 | self.statelock.release() 421 | 422 | 423 | 424 | 425 | def _delSubscNetV6(self, line_id, line_sub_id, netv6_addr_cidr): 426 | 427 | addr = ipaddr.IPv6Network(netv6_addr_cidr) 428 | 429 | if addr.prefixlen == 64: 430 | table_id = 0 431 | elif addr.prefixlen == 56: 432 | table_id = 1 433 | else: 434 | raise ValueError('Can only remove /56 and /64 subnets.') 435 | 436 | v6_addr_sanitized = netv6_addr_cidr.replace("/", "_").replace(":", "_") 437 | table_name = "t_antispoof_ipv6_" + str(table_id) 438 | rule_name = "Net6_" + str(table_id) + "_" + str(line_id) + \ 439 | "_" + str(line_sub_id) + "_" + v6_addr_sanitized 440 | self.platf.delTableRuleRaw(table_name, rule_name) 441 | table_name = "t_ds_routev6_" + str(table_id) 442 | self.platf.delTableRuleRaw(table_name, rule_name) 443 | 444 | 445 | def addUpstreamRouteV4(self, service_id, netv4_cidr_str, coreOutPort, coreOutLabel0, coreOutLabel1, nextHopMac): 446 | """Add a general (non-subscriber-specific) upstream route. 447 | Must be HEX, no v6 address with CIDR-str at the moment""" 448 | 449 | # TODO: Consistency check! 450 | # Check if the respective labelport has been set as a core port. 451 | 452 | self.platf.addTableRuleRaw("t_us_routev4", "Rt4_" + str(netv4_cidr_str).replace("/", "_"), 453 | [("vlan_service.vlanID", service_id), 454 | ("ipv4.dstAddr", netv4_cidr_str)], 455 | "a_us_routev4v6", [("out_port", coreOutPort), ("mpls0_label", coreOutLabel0), 456 | ("mpls1_label", coreOutLabel1), ("via_hwaddr", nextHopMac)]) 457 | 458 | if not service_id in self.routesv4: 459 | self.routesv4[service_id] = {} 460 | self.routesv4[service_id][netv4_cidr_str] = { 461 | "coreOutPort": coreOutPort, "coreOutLabel0": coreOutLabel0, "coreOutLabel1": coreOutLabel1, "via_hwaddr": nextHopMac} 462 | 463 | 464 | 465 | 466 | 467 | 468 | def addUpstreamRouteV6(self, service_id, netv6_cidr_str, coreOutPort, coreOutLabel0, coreOutLabel1, nextHopMac): 469 | """Add a general (non-subscriber-specific) upstream route. Must 470 | be HEX, no v6 address with CIDR-str at the moment""" 471 | 472 | # TODO: Consistency check! Check if the respective labelport has been set as a core port. 473 | 474 | addr = ipaddr.IPv6Network(netv6_cidr_str) 475 | 476 | prefix = addr.prefixlen 477 | netv6 = "0x" + binascii.hexlify(bytes(addr.packed)) 478 | 479 | self.platf.addTableRuleRaw("t_us_routev6", "Rt6_all_" + str(service_id), 480 | [("vlan_service.vlanID", service_id), 481 | ("ipv6.dstAddr", netv6, prefix)], 482 | "a_us_routev4v6", [("out_port", coreOutPort), ("mpls0_label", coreOutLabel0), 483 | ("mpls1_label", coreOutLabel1), ("via_hwaddr", nextHopMac)]) 484 | 485 | if not service_id in self.routesv6: 486 | self.routesv6[service_id] = {} 487 | self.routesv6[service_id]["all"] = { 488 | "coreOutPort": coreOutPort, "coreOutLabel0": coreOutLabel0, "coreOutLabel1": coreOutLabel1, "via_hwaddr": nextHopMac} 489 | -------------------------------------------------------------------------------- /generic/runtime/simple_stats.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019-present Open Networking Foundation 2 | # 3 | # Contributed and sponsored by Deutsche Telekom AG. 4 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 5 | # in collaboration with Technische Universitaet Darmstadt. 6 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | # For details see the file LICENSE in the top project directory. 21 | 22 | import time, threading 23 | 24 | class SimpleStats: 25 | 26 | def __init__(self, statsfile, live=False): 27 | self._out = open(statsfile, 'w') 28 | self._lock = threading.Lock() 29 | self._live = live 30 | 31 | def add(self, eventName, identifier, eventValue): 32 | self._lock.acquire() 33 | self._out.write(str(time.time()) + "," + str(eventName) + "," + str(identifier) + "," + str(eventValue) + "\n") 34 | if self._live: 35 | self._out.flush() 36 | self._lock.release() 37 | 38 | def onEnd(self): 39 | self._out.close() 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /generic/runtime/thriftcli_runtime_mgr.py: -------------------------------------------------------------------------------- 1 | 2 | # Copyright 2018-present Open Networking Foundation 3 | # 4 | # Contributed and sponsored by Deutsche Telekom AG. 5 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 6 | # in collaboration with Technische Universitaet Darmstadt. 7 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | # 21 | # For details see the file LICENSE in the top project directory. 22 | 23 | import pexpect 24 | from runtime import p4_userplane_exception 25 | 26 | dump = True 27 | debug = True 28 | strict = True 29 | 30 | 31 | 32 | class ThriftCLIRuntimeMgr: 33 | def __init__(self, thriftcli_cmd, prompt_command="RuntimeCmd:"): 34 | self.cliproc = pexpect.spawn(thriftcli_cmd) 35 | self.prompt_command = prompt_command 36 | self.cliproc.expect(self.prompt_command) 37 | 38 | 39 | 40 | def sendCmd(self, command): 41 | if dump or debug: 42 | print 43 | command 44 | self.cliproc.sendline(command) 45 | self.cliproc.expect(self.prompt_command) 46 | output = self.cliproc.before 47 | error = "Error" in output or "Invalid match key" in output 48 | 49 | if dump or debug: 50 | print "P4_RUNTIME_CLI: \n#\t" + output.replace("\n", "\n#\t") 51 | if error and strict: 52 | raise p4_userplane_exception.P4UserPlaneException("Thrift command returned error.", command, output) 53 | return error 54 | 55 | 56 | 57 | def commitInitial(self): 58 | pass 59 | # Not required 60 | 61 | 62 | 63 | def _getActionParams(self, tokens): 64 | if len(tokens) > 2: 65 | # we have a mask 66 | return str(tokens[1]) + "/" + str(tokens[2]) 67 | else: 68 | # we have no mask 69 | return str(tokens[1]) 70 | 71 | 72 | 73 | def addTableRuleRaw(self, table, name, match, actionName, actionParams, priority=0): 74 | match_str = ' '.join(self._getActionParams(value) for value in match) 75 | actionParams_str = ' '.join(str(value[1]) for value in actionParams) 76 | cmd = "table_add " + table + " " + actionName + " " + match_str + " => " + actionParams_str + " " 77 | if priority != 0: 78 | # A priority is required for ternary tables 79 | cmd += " " + str(priority) 80 | 81 | # cmd = "table_add " + table + " " + actionName + " " + match_str + ((" => " + actionParams_str) if len(actionParams) != 0 else "") + " 0" 82 | return self.sendCmd(cmd) 83 | 84 | 85 | 86 | def setTableDefaultRuleRaw(self, table, actionName, actionParams): 87 | actionParams_str = ' '.join(str(value[1]) for value in actionParams) 88 | cmd = "table_set_default " + table + " " + actionName + " " + actionParams_str 89 | return self.sendCmd(cmd) 90 | 91 | 92 | 93 | def setMeterRates(self, meter_name, meter_index, rate1, burst1, rate2, burst2): 94 | cmd = "meter_set_rates " + meter_name + " " + str(meter_index) + " " + str(rate1) + ":" + str( 95 | burst1) + " " + str(rate2) + ":" + str(burst2) 96 | return self.sendCmd(cmd) 97 | 98 | 99 | 100 | def addParserValueSetEntry(self, name, value, mask=None): 101 | print "Not implemented yet." 102 | return 0 103 | 104 | 105 | 106 | def getPort(self, symbol): 107 | """Maps the symbolic port (e.g. a label) to a P4-understandable one.""" 108 | 109 | if symbol == "ctrl": 110 | return "0" 111 | if symbol == "access1": 112 | return "1" #internal 113 | if symbol == "core1": 114 | return "2" #internal 115 | if symbol == "access2": 116 | return "3" #internal 117 | if symbol == "core2": 118 | return "4" #internal 119 | raise ValueError("P4 port not defined!") 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /generic/runtime/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencord/p4se/5fd8de8874fd6a564fd421e42a937ce2a05a90ed/generic/runtime/utils/__init__.py -------------------------------------------------------------------------------- /generic/runtime/utils/simple_subscriber.py: -------------------------------------------------------------------------------- 1 | 2 | # Copyright 2018-present Open Networking Foundation 3 | # 4 | # Contributed and sponsored by Deutsche Telekom AG. 5 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 6 | # in collaboration with Technische Universitaet Darmstadt. 7 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | # 21 | # For details see the file LICENSE in the top project directory. 22 | 23 | import time 24 | 25 | from threading import Thread 26 | 27 | 28 | class SimpleSubscriber: 29 | """Creates/removes a subscriber based on our defined IP/MAC testing pattern""" 30 | 31 | def __init__(self, caller, subid, bw_class="TENGIG", stats=None): 32 | self.stats = stats 33 | self.caller = caller 34 | self.subid = subid 35 | self.bw_class = bw_class 36 | 37 | self.line_id = self.subid 38 | self.line_mpls1_label = self.subid/16 + 1 39 | self.line_vlan_id = self.subid % 16 40 | 41 | self.subsc_id = 1 42 | self.service_id = 1 43 | #self.cpe_mac = "0x52540010" + "{0:0{1}x}".format(self.subid,4) 44 | pre_mac = "{0:0{1}x}".format(self.subid, 4) 45 | self.cpe_mac = "52:54:00:10:" + pre_mac[0:2] + ":" + pre_mac[2:4] 46 | self.pppoe_sess_id = self.subid 47 | 48 | octet3 = (self.subid+1)/256 49 | octet4 = (self.subid+1) % 256 50 | self.net4 = "100.69." + str(octet3) + "." + str(octet4) 51 | self.net6_t = "2a02:aaa1:0000:" + \ 52 | "{0:0{1}x}".format(self.subid, 4) + "::/64" 53 | self.net6_s = "2a02:aaa2:00" + \ 54 | "{0:0{1}x}".format(octet3, 2) + ":" + \ 55 | "{0:0{1}x}".format(octet4, 2) + "00::/56" 56 | 57 | def createLine(self, accessPort, accessOuterLabel): 58 | 59 | self.accessPort = accessPort 60 | self.accessOuterLabel = accessOuterLabel 61 | 62 | startTime = time.time() 63 | # Subscriber Line 64 | line_id = self.subid 65 | self.caller.addSubscLine(accessPort, accessOuterLabel, 66 | self.line_mpls1_label, self.line_vlan_id, self.line_id) 67 | endTime = time.time() 68 | self.stats.add("createLineTime", self.subid, float( 69 | endTime-startTime)) if self.stats else None 70 | print "Created line for " + str(self.subid) + "." 71 | 72 | def setAuthed(self): 73 | startTime = time.time() 74 | # Authenticated subsc with networks 75 | self.caller.addSubscSession( 76 | self.line_id, self.subsc_id, self.service_id, self.cpe_mac, self.pppoe_sess_id, self.bw_class) 77 | self.caller.addSubscNetV4(self.line_id, self.subsc_id, self.net4) 78 | self.caller.addSubscNetV6(self.line_id, self.subsc_id, self.net6_t) 79 | self.caller.addSubscNetV6(self.line_id, self.subsc_id, self.net6_s) 80 | 81 | endTime = time.time() 82 | 83 | self.stats.add("authSubTime", self.subid, float( 84 | endTime-startTime)) if self.stats else None 85 | 86 | print "Authenticated subscriber " + str(self.subid) + "." 87 | 88 | def unsetAuthed(self): 89 | 90 | startTime = time.time() 91 | self.caller.delSubscSession(self.line_id, self.subsc_id) 92 | endTime = time.time() 93 | 94 | self.stats.add("unauthSubTime", self.subid, float( 95 | endTime-startTime)) if self.stats else None 96 | -------------------------------------------------------------------------------- /generic/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencord/p4se/5fd8de8874fd6a564fd421e42a937ce2a05a90ed/generic/tests/__init__.py -------------------------------------------------------------------------------- /generic/tests/simple_test.py: -------------------------------------------------------------------------------- 1 | 2 | # Copyright 2018-present Open Networking Foundation 3 | # 4 | # Contributed and sponsored by Deutsche Telekom AG. 5 | # Originally developed as part of the D-Nets 6 P4 Service Edge project 6 | # in collaboration with Technische Universitaet Darmstadt. 7 | # Authors: Leonhard Nobach, Jeremias Blendin, Ralf Kundel 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | # 21 | # For details see the file LICENSE in the top project directory. 22 | 23 | from runtime.utils.simple_subscriber import * 24 | 25 | DEFAULT_SERVICE_ID = 1 26 | 27 | class SimpleTest: 28 | 29 | def __init__(self, caller, stats=None): 30 | self.caller = caller 31 | self.stats = stats 32 | 33 | 34 | 35 | 36 | def run(self): 37 | 38 | # == Port enabling 39 | 40 | # Access Port 1 41 | self.accessPort1 = self.caller.platf.getPort("access1") 42 | self.accessOuterLabel1 = 0x80001 #Note: accessInnerLabel1 defined by subscriber line definitions. 43 | self.accessOurOuterMAC1 = "52:54:00:00:01:01" 44 | self.accessPeerOuterMAC1 = "52:54:00:00:01:02" 45 | self.caller.enableLabelPortAccess(self.accessPort1, self.accessOuterLabel1, self.accessOurOuterMAC1, self.accessPeerOuterMAC1) 46 | 47 | # Core Port 1 48 | corePort1 = self.caller.platf.getPort("core1") 49 | coreOuterLabel1 = 0x00010 50 | coreInnerLabel1 = 200 51 | coreNextHopMac1 = "52:54:00:fe:00:01" 52 | self.caller.enableLabelPortCore(corePort1, coreOuterLabel1, "52:54:00:00:02:01") 53 | 54 | # Upstream Routes 55 | self.caller.addUpstreamRouteV4(DEFAULT_SERVICE_ID, "0.0.0.0/0", corePort1, coreOuterLabel1, coreInnerLabel1, coreNextHopMac1) 56 | self.caller.addUpstreamRouteV6(DEFAULT_SERVICE_ID, "2a02::/16", corePort1, coreOuterLabel1, coreInnerLabel1, coreNextHopMac1) 57 | self.caller.addUpstreamRouteV6(DEFAULT_SERVICE_ID, "2a03::/16", corePort1, coreOuterLabel1, coreInnerLabel1, coreNextHopMac1) 58 | 59 | 60 | 61 | 62 | def addManySubs(self, size): 63 | 64 | 65 | subs = [] 66 | 67 | for i in range(0, size): 68 | subs.append(SimpleSubscriber(self.caller, i, "TENGIG", self.stats)) 69 | 70 | for sub in subs: 71 | sub.createLine(self.accessPort1, self.accessOuterLabel1) 72 | 73 | for sub in subs: 74 | sub.setAuthed() 75 | --------------------------------------------------------------------------------