linux-cp: Fix API response
[vpp.git] / extras / libmemif / examples / example_setup_doc.rst
1 .. _libmemif_example_setup_doc:
2
3 Example setup
4 =============
5
6 VPP-memif master icmp_responder slave
7 -------------------------------------
8
9    Libmemif example app(s) use memif default socket file:
10    ``/run/vpp/memif.sock``.
11
12 Run VPP and icmpr-epoll example (default example when running in
13 container).
14
15    Other examples work similar to icmpr-epoll. Brief explanation can be
16    found in :ref:`libmemif_examples_doc` .
17
18 VPP-side config:
19
20 ::
21
22    DBGvpp# create interface memif id 0 master
23    DBGvpp# set int state memif0/0 up
24    DBGvpp# set int ip address memif0/0 192.168.1.1/24
25
26 icmpr-epoll:
27
28 ::
29
30    conn 0 0
31
32 Memif in slave mode will try to connect every 2 seconds. If connection
33 establishment is successful, a message will show.
34
35 ::
36
37    INFO: memif connected!
38
39 ..
40
41    Error messages like “unmatched interface id” are printed only in
42    debug mode.
43
44 Check connected status. Use show command in icmpr-epoll:
45
46 ::
47
48    show
49    MEMIF DETAILS
50    ==============================
51    interface index: 0
52        interface ip: 192.168.1.2
53        interface name: memif_connection
54        app name: ICMP_Responder
55        remote interface name: memif0/0
56        remote app name: VPP 17.10-rc0~132-g62f9cdd
57        id: 0
58        secret:
59        role: slave
60        mode: ethernet
61        socket filename: /run/vpp/memif.sock
62        rx queues:
63            queue id: 0
64            ring size: 1024
65            buffer size: 2048
66        tx queues:
67            queue id: 0
68            ring size: 1024
69            buffer size: 2048
70        link: up
71    interface index: 1
72        no connection
73
74 Use sh memif command in VPP:
75
76 ::
77
78    DBGvpp# sh memif
79    interface memif0/0
80      remote-name "ICMP_Responder"
81      remote-interface "memif_connection"
82      id 0 mode ethernet file /run/vpp/memif.sock
83      flags admin-up connected
84      listener-fd 12 conn-fd 13
85      num-s2m-rings 1 num-m2s-rings 1 buffer-size 0
86        master-to-slave ring 0:
87          region 0 offset 32896 ring-size 1024 int-fd 16
88          head 0 tail 0 flags 0x0000 interrupts 0
89        master-to-slave ring 0:
90          region 0 offset 0 ring-size 1024 int-fd 15
91          head 0 tail 0 flags 0x0001 interrupts 0
92
93 Send ping from VPP to icmpr-epoll:
94
95 ::
96
97    DBGvpp# ping 192.168.1.2
98    64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=.1888 ms
99    64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=.1985 ms
100    64 bytes from 192.168.1.2: icmp_seq=4 ttl=64 time=.1813 ms
101    64 bytes from 192.168.1.2: icmp_seq=5 ttl=64 time=.1929 ms
102
103    Statistics: 5 sent, 4 received, 20% packet loss
104
105 multiple queues VPP-memif slave icmp_responder master
106 -----------------------------------------------------
107
108 Run icmpr-epoll as in previous example setup. Run VPP with startup conf,
109 enabling 2 worker threads. Example startup.conf:
110
111 ::
112
113    unix {
114      interactive
115      nodaemon
116      full-coredump
117    }
118
119    cpu {
120      workers 2
121    }
122
123 VPP-side config:
124
125 ::
126
127    DBGvpp# create memif id 0 slave rx-queues 2 tx-queues 2
128    DBGvpp# set int state memif0/0 up
129    DBGvpp# set int ip address memif0/0 192.168.1.1/24
130
131 icmpr-epoll:
132
133 ::
134
135    conn 0 1
136
137 When connection is established a message will print:
138
139 ::
140
141    INFO: memif connected!
142
143 ..
144
145    Error messages like “unmatched interface id” are printed only in
146    debug mode.
147
148 Check connected status. Use show command in icmpr-epoll:
149
150 ::
151
152    show
153    MEMIF DETAILS
154    ==============================
155    interface index: 0
156        interface ip: 192.168.1.2
157        interface name: memif_connection
158        app name: ICMP_Responder
159        remote interface name: memif0/0
160        remote app name: VPP 17.10-rc0~132-g62f9cdd
161        id: 0
162        secret:
163        role: master
164        mode: ethernet
165        socket filename: /run/vpp/memif.sock
166        rx queues:
167            queue id: 0
168            ring size: 1024
169            buffer size: 2048
170            queue id: 1
171            ring size: 1024
172            buffer size: 2048
173        tx queues:
174            queue id: 0
175            ring size: 1024
176            buffer size: 2048
177            queue id: 1
178            ring size: 1024
179            buffer size: 2048
180        link: up
181    interface index: 1
182        no connection
183
184 Use sh memif command in VPP:
185
186 ::
187
188    DBGvpp# sh memif
189    interface memif0/0
190      remote-name "ICMP_Responder"
191      remote-interface "memif_connection"
192      id 0 mode ethernet file /run/vpp/memif.sock
193      flags admin-up slave connected
194      listener-fd -1 conn-fd 12
195      num-s2m-rings 2 num-m2s-rings 2 buffer-size 2048
196        slave-to-master ring 0:
197          region 0 offset 0 ring-size 1024 int-fd 14
198          head 0 tail 0 flags 0x0000 interrupts 0
199        slave-to-master ring 1:
200          region 0 offset 32896 ring-size 1024 int-fd 15
201          head 0 tail 0 flags 0x0000 interrupts 0
202        slave-to-master ring 0:
203          region 0 offset 65792 ring-size 1024 int-fd 16
204          head 0 tail 0 flags 0x0001 interrupts 0
205        slave-to-master ring 1:
206          region 0 offset 98688 ring-size 1024 int-fd 17
207          head 0 tail 0 flags 0x0001 interrupts 0
208
209 Send ping from VPP to icmpr-epoll:
210
211 ::
212
213    DBGvpp# ping 192.168.1.2
214    64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=.1439 ms
215    64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=.2184 ms
216    64 bytes from 192.168.1.2: icmp_seq=4 ttl=64 time=.1458 ms
217    64 bytes from 192.168.1.2: icmp_seq=5 ttl=64 time=.1687 ms
218
219    Statistics: 5 sent, 4 received, 20% packet loss
220
221 icmp_responder master icmp_responder slave
222 ------------------------------------------
223
224    This setup creates connection between two applications using
225    libmemif. Traffic functionality is the same as when connection to
226    VPP. App can receive ARP/ICMP request and transmit response.
227
228 Run two instances of icmpr-epoll example. > If not running in container,
229 make sure folder /run/vpp/ exists before creating memif master. Instance
230 1 will be in master mode, instance 2 in slave mode. instance 1:
231
232 ::
233
234    conn 0 1
235
236 instance 2:
237
238 ::
239
240    conn 0 0
241
242 In 2 seconds, both instances should print connected! message:
243
244 ::
245
246    INFO: memif connected!
247
248 Check peer interface names using show command.