Nathan Skrzypczak | 8acc5ee | 2021-10-12 14:00:25 +0200 | [diff] [blame] | 1 | .. _libmemif_examples_doc: |
| 2 | |
Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame] | 3 | Libmemif Examples |
| 4 | ================= |
Nathan Skrzypczak | 8acc5ee | 2021-10-12 14:00:25 +0200 | [diff] [blame] | 5 | |
Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame] | 6 | Example source code is located in `.../vpp/extras/libmemif/examples/` directory. |
| 7 | The compiled binaries are located in `.../vpp/extras/libmemif/build/examples/`. |
Nathan Skrzypczak | 8acc5ee | 2021-10-12 14:00:25 +0200 | [diff] [blame] | 8 | |
Nathan Skrzypczak | 8acc5ee | 2021-10-12 14:00:25 +0200 | [diff] [blame] | 9 | |
Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame] | 10 | ICMP Responder |
| 11 | -------------- |
| 12 | **Application Source Code**: `.../vpp/extras/libmemif/examples/icmp_responder` |
Nathan Skrzypczak | 8acc5ee | 2021-10-12 14:00:25 +0200 | [diff] [blame] | 13 | |
Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame] | 14 | In this example, memif endpoint connects to an external application. The example |
| 15 | application can resolve ARP and reply to ICMPv4 packets. The program will exit |
| 16 | once the interface is disconnected Memif receive mode: interrupt. |
Nathan Skrzypczak | 8acc5ee | 2021-10-12 14:00:25 +0200 | [diff] [blame] | 17 | |
Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame] | 18 | VPP (memif master) <--> icmp_responder app (memif slave) |
| 19 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 20 | Start VPP and configure memif interface:: |
Nathan Skrzypczak | 8acc5ee | 2021-10-12 14:00:25 +0200 | [diff] [blame] | 21 | |
Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame] | 22 | make run |
| 23 | ... |
| 24 | DBGvpp# create interface memif id 0 master |
| 25 | DBGvpp# set int state memif0/0 up |
| 26 | DBGvpp# set int ip address memif0/0 192.168.1.2/24 |
Nathan Skrzypczak | 8acc5ee | 2021-10-12 14:00:25 +0200 | [diff] [blame] | 27 | |
Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame] | 28 | Start icmp_responder example app:: |
Nathan Skrzypczak | 8acc5ee | 2021-10-12 14:00:25 +0200 | [diff] [blame] | 29 | |
Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame] | 30 | ./examples/icmp_responder |
Nathan Skrzypczak | 8acc5ee | 2021-10-12 14:00:25 +0200 | [diff] [blame] | 31 | |
Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame] | 32 | Memif in slave mode will try to connect every 2 seconds. If connection |
| 33 | establishment is successful, the `memif connected` message will show:: |
Nathan Skrzypczak | 8acc5ee | 2021-10-12 14:00:25 +0200 | [diff] [blame] | 34 | |
Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame] | 35 | INFO: memif connected! |
Nathan Skrzypczak | 8acc5ee | 2021-10-12 14:00:25 +0200 | [diff] [blame] | 36 | |
Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame] | 37 | **Note**: Error messages like "unmatched interface id" are printed only in debug mode. |
Nathan Skrzypczak | 8acc5ee | 2021-10-12 14:00:25 +0200 | [diff] [blame] | 38 | |
Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame] | 39 | Verify that the memif is connected on VPP side:: |
| 40 | |
| 41 | DBGvpp# sh memif |
| 42 | interface memif0/0 |
| 43 | remote-name "ICMP_Responder" |
| 44 | remote-interface "memif_connection" |
| 45 | id 0 mode ethernet file /run/vpp/memif.sock |
| 46 | flags admin-up connected |
| 47 | listener-fd 12 conn-fd 13 |
| 48 | num-s2m-rings 1 num-m2s-rings 1 buffer-size 0 |
| 49 | master-to-slave ring 0: |
| 50 | region 0 offset 32896 ring-size 1024 int-fd 16 |
| 51 | head 0 tail 0 flags 0x0000 interrupts 0 |
| 52 | master-to-slave ring 0: |
| 53 | region 0 offset 0 ring-size 1024 int-fd 15 |
| 54 | head 0 tail 0 flags 0x0001 interrupts 0 |
| 55 | |
| 56 | Send ping from VPP to icmp_responder (Default IPv4: 192.168.1.1):: |
| 57 | |
| 58 | DBGvpp# ping 192.168.1.1 |
| 59 | 64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=.1888 ms |
| 60 | 64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=.1985 ms |
| 61 | 64 bytes from 192.168.1.1: icmp_seq=4 ttl=64 time=.1813 ms |
| 62 | 64 bytes from 192.168.1.1: icmp_seq=5 ttl=64 time=.1929 ms |
| 63 | |
| 64 | Statistics: 5 sent, 4 received, 20% packet loss |
| 65 | |
| 66 | |
| 67 | Loopback |
| 68 | -------- |
| 69 | **Application Source Code**: `.../vpp/extras/libmemif/examples/loopback` |
| 70 | |
| 71 | In this example, two memif endpoints are connected to create a loopback. |
| 72 | Once connected, a test packet is sent out the memif master interface to |
| 73 | the memif slave interface, which replies with the same packet in a |
| 74 | zero-copy way. |
| 75 | In reverse mode, the packet is sent from the slave interface and is |
| 76 | looped back by the master interface. |
| 77 | |
| 78 | Running The Loopback Application |
| 79 | ++++++++++++++++++++++++++++++++ |
| 80 | Start the loopback example:: |
| 81 | |
| 82 | ./examples/loopback |
| 83 | |
| 84 | You should see the `Received correct data.` message:: |
| 85 | |
| 86 | INFO: Received correct data. |
| 87 | INFO: Stopping the program |