├── LEGAL_TERMS ├── Layer-2 ├── Layer-2.png └── Readme.md ├── Layer-3 ├── Layer-3.png └── Readme.md ├── License.txt └── README.md /LEGAL_TERMS: -------------------------------------------------------------------------------- 1 | The software content under NPLang is provided under the MIT License, as described in the License.txt file. 2 | 3 | Copyright 2019 Broadcom. All rights reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 4 | -------------------------------------------------------------------------------- /Layer-2/Layer-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nplang/NPL-Example-Applications/8795a4f03bac5239049b6f43aea7468094657281/Layer-2/Layer-2.png -------------------------------------------------------------------------------- /Layer-2/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # Layer-2 Switching NPL Example 3 | 4 | We have created sample ```l2_switch``` NPL example which define packet pipeline with Layer-2 Switching for ethernet packets. 5 | 6 | Main features of this NPL program includes: 7 | - Basic L2 unicast switching 8 | - Basic L2 multicast support 9 | - VLAN membership and spanning tree checks 10 | 11 | At a high level below is how Layer-2 packet pipeline looks like based on this NPL Program. 12 | 13 | ![Layer-2 Pipeline](/Layer-2/Layer-2.png) 14 | 15 | Directory Structure of Layer-2 Examples 16 | 17 | ````` 18 | (ncsc-1.3.3rc4) npl@npl-VirtualBox:~/ncsc-1.3.3rc4/examples/l2_switch$ tree 19 | . 20 | ├── bm_tests 21 | │ ├── l2_test 22 | │ │ ├── tbl_cfg.txt 23 | │ │ └── test.py 24 | │ └── sf_definition 25 | │ └── bm_sfc.cpp 26 | ├── Makefile 27 | └── npl 28 | ├── config.ini 29 | ├── l2_bus.npl 30 | ├── l2_header_format.npl 31 | ├── l2_parser.npl 32 | ├── l2_sf_defines.npl 33 | └── l2_switch.npl 34 | 35 | 4 directories, 10 files 36 | (ncsc-1.3.3rc4) npl@npl-VirtualBox:~/ncsc-1.3.3rc4/examples/l2_switch$ 37 | 38 | 39 | ````` 40 | 41 | To execute this example, follow below steps 42 | 43 | 1. Make sure [build environment](https://github.com/nplang/NPL-Tutorials#npl-build-enivronment) was properly setup as described earlier 44 | 2. Once the environmental variables were setup execute below commands. 45 | ```` 46 | 47 | export NPL_EXAMPLES=/home/npl/ncsc-1.3.3rc4/examples 48 | cd $NPL_EXAMPLES/l2_switch 49 | make fe_nplsim 50 | make nplsim_comp 51 | make nplsim_run 52 | 53 | ```` 54 | 55 | Now you will see two xterm windows one with name ```BMODEL``` and another with ```BMCLI```. 56 | 57 | Before you inject packets you need populate Logical tables using pre-defined table configurations through ```BMCLI``` window. Command to use is as below 58 | 59 | ```` 60 | 61 | rcload /home/npl/ncsc-1.3.3rc4/examples/l2_switch/bm_tests/l2_test/tbl_cfg.txt 62 | 63 | ```` 64 | 65 | You can now inject packet using below command from original console widow where you compiled the NPL code. 66 | 67 | ```` 68 | python bm_tests/l2_test/test.py 69 | 70 | ```` 71 | 72 | The above test.py sends an ingress packet to port 1. And you can see packet being switched to Port 2 based on NPL switching program. 73 | 74 | You can experience complete NPL program for this example located at below location 75 | 76 | ```` 77 | 78 | $NPL_EXAMPLES/l2_switch/npl/ 79 | 80 | ```` 81 | 82 | ## Next Tutorial 83 | 84 | Congratulations :+1: 85 | 86 | You have experienced how a simple ```Layer-2 Swicthing``` works. You can now move on to next example [Layer-3 Routing & tunneling example](https://github.com/nplang/NPL-Example-Applications/tree/master/Layer-3) 87 | -------------------------------------------------------------------------------- /Layer-3/Layer-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nplang/NPL-Example-Applications/8795a4f03bac5239049b6f43aea7468094657281/Layer-3/Layer-3.png -------------------------------------------------------------------------------- /Layer-3/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Layer-3 Switching NPL Example 4 | 5 | We have created ```l3_app``` which is simple NPL Program to define swithcing pipeline with basic L3 Routing and Tunneling function for IP Packets. 6 | 7 | 8 | Main features of basic router NPL program include: 9 | - Packet parser supports single vlan tagged or untagged packets, IPv4, IPv6 and TCP/UDP header 10 | - Basic L3 switching 11 | - Basic L3 tunneling 12 | - ECMP support 13 | 14 | This NPL program defines several data paths, one of them is for basic layer 3 routing of IPv4 packets shown below: 15 | 16 | ![Layer-3 Pipeline](/Layer-3/Layer-3.png) 17 | 18 | ### Directory Structure of Layer-3 Examples 19 | 20 | ````` 21 | npl@npl-VirtualBox:~/ncsc-1.3.3rc4/examples/l3_app$ tree 22 | . 23 | ├── bm_tests 24 | │ ├── ipv4_test 25 | │ │ ├── tbl_cfg.txt 26 | │ │ └── test.py 27 | │ ├── ipv4_tunnel_test 28 | │ │ ├── tbl_cfg.txt 29 | │ │ └── test.py 30 | │ ├── ipv6_test 31 | │ │ ├── tbl_cfg.txt 32 | │ │ └── test.py 33 | │ ├── multi_protocol_test 34 | │ │ ├── tbl_cfg.txt 35 | │ │ └── test.py 36 | │ └── sf_definition 37 | │ └── bm_sfc.cpp 38 | ├── Makefile 39 | └── npl 40 | ├── config.ini 41 | ├── l3_app_bus.npl 42 | ├── l3_app.npl 43 | ├── l3_header_format.npl 44 | ├── l3_parser.npl 45 | └── l3_sf_defines.npl 46 | 47 | 7 directories, 16 files 48 | 49 | ````` 50 | 51 | To execute above example tests, follow below steps 52 | 53 | 1. Make sure [build environment](https://github.com/nplang/NPL-Tutorials#npl-build-enivronment) was properly setup as described earlier 54 | 2. Once the environmental variables were setup execute below commands. 55 | ```` 56 | 57 | export NPL_EXAMPLES=/home/npl/ncsc-1.3.3rc4/examples 58 | cd $NPL_EXAMPLES/l3_app 59 | make fe_nplsim 60 | make nplsim_comp 61 | make nplsim_run 62 | 63 | ```` 64 | 65 | Now you will see two xterm windows one with name ```BMODEL``` and another with ```BMCLI```. 66 | 67 | ### Packet Tests 68 | 69 | There are several tests available under ```bm_tests``` directory for l3_app program. Each test has its respective table configurations in ```tbl_cfg.txt``` 70 | 71 | - 'ipv4_test' : Simple l3 routing test with IPv4 host entry 72 | - 'ipv4_tunnel_test' : IPv4 tunnel termination test case. 73 | - 'ipv6_test' : Simple l3 routing test with IPv6 host entry 74 | - 'multi_protocol_test' : Collective multiple datapath (IPV4/6, tunnel, L2) simulation test 75 | 76 | 77 | Before you inject packets you need populate Logical tables using pre-defined table configurations through ```BMCLI``` window. Command to use is as below 78 | 79 | ```` 80 | 81 | # Change the below command based on the test you exercise. Example given for 'ipv4_test' 82 | rcload /home/npl/ncsc-1.3.3rc4/examples/l3_app/bm_tests/ipv4_test/tbl_cfg.txt 83 | 84 | ```` 85 | 86 | You can now inject packet using below command from original console widow where you compiled the NPL code. 87 | 88 | ```` 89 | 90 | python bm_tests/ipv4_test/test.py 91 | 92 | ```` 93 | 94 | The above test.py sends two IPV4 packets (under ipv4_test) 95 | 96 | ```` 97 | 98 | 1. The first packet ingress on port 0 with vlan 1 and is routed to the destination host on port 3 with vlan 6 based on dest. IP of the packet. 99 | 100 | 2. The test packet with vlan 1 ingresses on port 5 which is switched to dest port 18 using l2_host table entries. 101 | 102 | ````` 103 | 104 | Make sure you execute other sample tests created for you to experience IPv6 Forwarding, IP tunneling and ECMP. 105 | 106 | Complete NPL program for this example is located at below location 107 | 108 | ```` 109 | 110 | $NPL_EXAMPLES/l3_app/npl/ 111 | 112 | ```` 113 | 114 | ## Congratulations :+1: :+1: 115 | ## You have finished working with NPL Example Applications. 116 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright 2019 Broadcom. All rights reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NPL Example Applications 2 | 3 | Welcome to the NPL Example Aplications. 4 | 5 | We have created example NPL Applications for users to get hands-on experience on the compilation and verification workflow using NPL Front End Compiler and Behavior Model. Each of these example NPL applications also contains example test files to populate the logical tables using ```BMCLI``` and inject packets to verify the NPL application. These example NPL applicaitons may not be complete from protocol perspective. 6 | 7 | ## Basic Packet Forwarding 8 | 9 | - [Layer-2 Switching NPL Application](https://github.com/nplang/NPL-Example-Applications/tree/master/Layer-2) 10 | 11 | - [Layer-3 Routing & Tunneling NPL Application](https://github.com/nplang/NPL-Example-Applications/tree/master/Layer-3) 12 | 13 | 14 | In case if you are looking for Working Environment, you can use instructions given in [How to get Working Environment](https://github.com/nplang/NPL-Tutorials#how-to-get-a-working-environment) 15 | 16 | ## Feedback or Questions 17 | Feedback or questions should be sent to npl-feedback.pdl@broadcom.com. 18 | --------------------------------------------------------------------------------