blob: 640297733787a56860821fc23c9d8e4bb060ce07 [file] [log] [blame]
Nathan Skrzypczak8acc5ee2021-10-12 14:00:25 +02001.. _libmemif_examples_doc:
2
Jakub Grajciare74c04f2021-01-04 11:28:33 +01003Libmemif Examples
4=================
Nathan Skrzypczak8acc5ee2021-10-12 14:00:25 +02005
Jakub Grajciare74c04f2021-01-04 11:28:33 +01006Example source code is located in `.../vpp/extras/libmemif/examples/` directory.
7The compiled binaries are located in `.../vpp/extras/libmemif/build/examples/`.
Nathan Skrzypczak8acc5ee2021-10-12 14:00:25 +02008
Nathan Skrzypczak8acc5ee2021-10-12 14:00:25 +02009
Jakub Grajciare74c04f2021-01-04 11:28:33 +010010ICMP Responder
11--------------
12**Application Source Code**: `.../vpp/extras/libmemif/examples/icmp_responder`
Nathan Skrzypczak8acc5ee2021-10-12 14:00:25 +020013
Jakub Grajciare74c04f2021-01-04 11:28:33 +010014In this example, memif endpoint connects to an external application. The example
15application can resolve ARP and reply to ICMPv4 packets. The program will exit
16once the interface is disconnected Memif receive mode: interrupt.
Nathan Skrzypczak8acc5ee2021-10-12 14:00:25 +020017
Jakub Grajciare74c04f2021-01-04 11:28:33 +010018VPP (memif master) <--> icmp_responder app (memif slave)
19++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20Start VPP and configure memif interface::
Nathan Skrzypczak8acc5ee2021-10-12 14:00:25 +020021
Jakub Grajciare74c04f2021-01-04 11:28:33 +010022 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 Skrzypczak8acc5ee2021-10-12 14:00:25 +020027
Jakub Grajciare74c04f2021-01-04 11:28:33 +010028Start icmp_responder example app::
Nathan Skrzypczak8acc5ee2021-10-12 14:00:25 +020029
Jakub Grajciare74c04f2021-01-04 11:28:33 +010030 ./examples/icmp_responder
Nathan Skrzypczak8acc5ee2021-10-12 14:00:25 +020031
Jakub Grajciare74c04f2021-01-04 11:28:33 +010032Memif in slave mode will try to connect every 2 seconds. If connection
33establishment is successful, the `memif connected` message will show::
Nathan Skrzypczak8acc5ee2021-10-12 14:00:25 +020034
Jakub Grajciare74c04f2021-01-04 11:28:33 +010035 INFO: memif connected!
Nathan Skrzypczak8acc5ee2021-10-12 14:00:25 +020036
Jakub Grajciare74c04f2021-01-04 11:28:33 +010037**Note**: Error messages like "unmatched interface id" are printed only in debug mode.
Nathan Skrzypczak8acc5ee2021-10-12 14:00:25 +020038
Jakub Grajciare74c04f2021-01-04 11:28:33 +010039Verify 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
56Send 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
67Loopback
68--------
69**Application Source Code**: `.../vpp/extras/libmemif/examples/loopback`
70
71In this example, two memif endpoints are connected to create a loopback.
72Once connected, a test packet is sent out the memif master interface to
73the memif slave interface, which replies with the same packet in a
74zero-copy way.
75In reverse mode, the packet is sent from the slave interface and is
76looped back by the master interface.
77
78Running The Loopback Application
79++++++++++++++++++++++++++++++++
80Start the loopback example::
81
82 ./examples/loopback
83
84You should see the `Received correct data.` message::
85
86 INFO: Received correct data.
87 INFO: Stopping the program