blob: f558e879f3e1a2d29ae3be331367f9fd3150b97a [file] [log] [blame]
John DeNisco06dcd452018-07-26 12:45:10 -04001.. _vagrant:
2
3.. toctree::
4
5.. _introduction-to-vpp-vagrant:
6
7Introduction
8---------------
9
10This tutorial is designed for you to be able to run it on a single Ubuntu 16.04 VM on your laptop.
11It walks you through some very basic vpp senarios, with a focus on learning vpp commands, doing common actions,
12and being able to discover common things about the state of a running vpp.
13
14This is *not* intended to be a 'how to run in a production environment' set of instructions.
15
16Exercise: Setting up your environment
17-------------------------------------
18
19All of these exercises are designed to be performed on an Ubuntu 16.04 (Xenial) box.
20
21If you have an Ubuntu 16.04 box on which you have sudo, you can feel free to use that.
22
23If you do not, a Vagrantfile is provided to setup a basic Ubuntu 16.04 box for you
24
25.. _vagrant-set-up:
26
27Vagrant Set Up
28--------------
29
30Action: Install Virtualbox
31^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32
33If you do not already have virtualbox on your laptop (or if it is not up to date), please download and install it:
34
35https://www.virtualbox.org/wiki/Downloads
36
37Action: Install Vagrant
38^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39
40If you do not already have Vagrant on your laptop (or if it is not up to date), please download it:
41
42https://www.vagrantup.com/downloads.html
43
44Action: Create a Vagrant Directory
45^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
46Create a directory on your laptop
47
48.. code-block:: console
49
50 mkdir fdio-tutorial
51 cd fdio-tutorial/
52
53.. _create-vagrant-file:
54
55Create a Vagrantfile
56^^^^^^^^^^^^^^^^^^^^
57
58.. code-block:: console
59
60 # -*- mode: ruby -*-
61 # vi: set ft=ruby :
62
63 Vagrant.configure(2) do |config|
64
65 config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm"
66 config.vm.box_check_update = false
67
68 vmcpu=(ENV['VPP_VAGRANT_VMCPU'] || 2)
69 vmram=(ENV['VPP_VAGRANT_VMRAM'] || 4096)
70
71 config.ssh.forward_agent = true
72
73 config.vm.provider "virtualbox" do |vb|
74 vb.customize ["modifyvm", :id, "--ioapic", "on"]
75 vb.memory = "#{vmram}"
76 vb.cpus = "#{vmcpu}"
77 #support for the SSE4.x instruction is required in some versions of VB.
78 vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.1", "1"]
79 vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.2", "1"]
80 end
81 end
82
83Action: Vagrant Up
84^^^^^^^^^^^^^^^^^^
85
86Bring up your Vagrant VM:
87
88.. code-block:: console
89
90 vagrant up
91
92
93Action: ssh to Vagrant VM
94^^^^^^^^^^^^^^^^^^^^^^^^^^^^
95
96.. code-block:: console
97
98 vagrant ssh
99
100Exercise: Install VPP
101---------------------
102**Skills to be Learned**
103
104 * Learn how to install vpp binary packges using apt-get.
105
106Follow the instructions at :ref:`Installing VPP Binaries <install_vpp>` for installing xenial vpp packages from the release repo. Please note, certain aspects of this tutorial require vpp 17.10 or later.
107
108Exercise: VPP basics
109---------------------
110**Skills to be Learned**
111
112By the end of the exercise you should be able to:
113
114* Run a vpp instance in a mode which allows multiple vpp processes to run
115* Issue vpp commands from the unix shell
116* Run a vpp shell and issue it commands
117
118
119VPP command learned in this exercise
120--------------------------------------
121
122* `show ver <https://docs.fd.io/vpp/17.04/clicmd_src_vpp_app.html#clicmd_show_version>`_
123
124Action: Remove dpdk plugin
125--------------------------
126In this tutorial, we will be running multiple vpp instances. DPDK does not work well with multiple instances, and so to run multiple instances we will need to disable the dpdk-plugin by removing it:
127
128.. code-block:: console
129
130 sudo rm -rf /usr/lib/vpp_plugins/dpdk_plugin.so
131
132..how-to-run-vpp:
133
134Action: Run VPP
135-----------------
136
137VPP runs in userspace. In a production environment you will often run it with DPDK to connect to real NICs or vhost to connect to VMs.
138In those circumstances you usually run a single instance of vpp.
139
140For purposes of this tutorial, it is going to be extremely useful to run multiple instances of vpp, and connect them to each other to form
141a topology. Fortunately, vpp supports this.
142
143When running multiple vpp instances, each instance needs to have specified a 'name' or 'prefix'. In the example below, the 'name' or 'prefix' is "vpp1". Note that only one instance can use the dpdk plugin, since this plugin is trying to acquire a lock on a file.
144
145.. code-block:: console
146
147 sudo vpp unix {cli-listen /run/vpp/cli-vpp1.sock} api-segment { prefix vpp1 }
148
149**Example Output:**
150
151.. code-block:: console
152
153 vlib_plugin_early_init:230: plugin path /usr/lib/vpp_plugins
154
155Please note:
156
157* "api-segment {prefix vpp1}" tells vpp how to name the files in /dev/shm/ for your vpp instance differently from the default.
158* "unix {cli-listen /run/vpp/cli-vpp1.sock}" tells vpp to use a non-default socket file when being addressed by vppctl.
159
160If you can't see the vpp process running on the host, activate the nodaemon option to better understand what is happening
161
162.. code-block:: console
163
164 sudo vpp unix {nodaemon cli-listen /run/vpp/cli-vpp1.sock} api-segment { prefix vpp1 }
165
166**Example Output with errors from the dpdk plugin:**
167
168.. code-block:: console
169
170 vlib_plugin_early_init:356: plugin path /usr/lib/vpp_plugins
171 load_one_plugin:184: Loaded plugin: acl_plugin.so (Access Control Lists)
172 load_one_plugin:184: Loaded plugin: dpdk_plugin.so (Data Plane Development Kit (DPDK))
173 load_one_plugin:184: Loaded plugin: flowprobe_plugin.so (Flow per Packet)
174 load_one_plugin:184: Loaded plugin: gtpu_plugin.so (GTPv1-U)
175 load_one_plugin:184: Loaded plugin: ila_plugin.so (Identifier-locator addressing for IPv6)
176 load_one_plugin:184: Loaded plugin: ioam_plugin.so (Inbound OAM)
177 load_one_plugin:114: Plugin disabled (default): ixge_plugin.so
178 load_one_plugin:184: Loaded plugin: kubeproxy_plugin.so (kube-proxy data plane)
179 load_one_plugin:184: Loaded plugin: l2e_plugin.so (L2 Emulation)
180 load_one_plugin:184: Loaded plugin: lb_plugin.so (Load Balancer)
181 load_one_plugin:184: Loaded plugin: libsixrd_plugin.so (IPv6 Rapid Deployment on IPv4 Infrastructure (RFC5969))
182 load_one_plugin:184: Loaded plugin: memif_plugin.so (Packet Memory Interface (experimetal))
183 load_one_plugin:184: Loaded plugin: nat_plugin.so (Network Address Translation)
184 load_one_plugin:184: Loaded plugin: pppoe_plugin.so (PPPoE)
185 load_one_plugin:184: Loaded plugin: stn_plugin.so (VPP Steals the NIC for Container integration)
186 vpp[10211]: vlib_pci_bind_to_uio: Skipping PCI device 0000:00:03.0 as host interface eth0 is up
187 vpp[10211]: vlib_pci_bind_to_uio: Skipping PCI device 0000:00:04.0 as host interface eth1 is up
188 vpp[10211]: dpdk_config:1240: EAL init args: -c 1 -n 4 --huge-dir /run/vpp/hugepages --file-prefix vpp -b 0000:00:03.0 -b 0000:00:04.0 --master-lcore 0 --socket-mem 64
189 EAL: No free hugepages reported in hugepages-1048576kB
190 EAL: Error - exiting with code: 1
191 Cause: Cannot create lock on '/var/run/.vpp_config'. Is another primary process running?
192
193Action: Send commands to VPP using vppctl
194---------------------------------------------------------------
195
196You can send vpp commands with a utility called *vppctl*.
197
198When running vppctl against a named version of vpp, you will need to run:
199
200.. code-block:: console
201
202 sudo vppctl -s /run/vpp/cli-${name}.sock ${cmd}
203
204**Note**
205
206.. code-block:: console
207
208 /run/vpp/cli-${name}.sock
209
210is the particular naming convention used in this tutorial. By default you can set vpp to use what ever socket file name you would like at startup (the default config file uses /run/vpp/cli.sock) if two different vpps are being run (as in this tutorial) you must use distinct socket files for each one.
211
212So to run 'show ver' against the vpp instance named vpp1 you would run:
213
214.. code-block:: console
215
216 sudo vppctl -s /run/vpp/cli-vpp1.sock show ver
217
218**Output:**
219
220.. code-block:: console
221
222 vpp v17.04-rc0~177-g006eb47 built by ubuntu on fdio-ubuntu1604-sevt at Mon Jan 30 18:30:12 UTC 2017
223
224Action: Start a VPP shell using vppctl
225---------------------------------------------------------------
226You can also use vppctl to launch a vpp shell with which you can run multiple vpp commands interactively by running:
227
228.. code-block:: console
229
230 sudo vppctl -s /run/vpp/cli-${name}.sock
231
232which will give you a command prompt.
233
234Try doing show ver that way:
235
236.. code-block:: console
237
238 sudo vppctl -s /run/vpp/cli-vpp1.sock
239 vpp# show ver
240
241Output:
242
243.. code-block:: console
244
245 vpp v17.04-rc0~177-g006eb47 built by ubuntu on fdio-ubuntu1604-sevt at Mon Jan 30 18:30:12 UTC 2017
246
247 vpp#
248
249To exit the vppctl shell:
250
251.. code-block:: console
252
253 vpp# quit
254
255Exercise: Create an interface
256-----------------------------
257
258Skills to be Learned
259^^^^^^^^^^^^^^^^^^^^
260
261#. Create a veth interface in Linux host
262#. Assign an IP address to one end of the veth interface in the Linux host
263#. Create a vpp host-interface that connected to one end of a veth interface via AF_PACKET
264#. Add an ip address to a vpp interface
265#. Setup a 'trace'
266#. View a 'trace'
267#. Clear a 'trace'
268#. Verify using ping from host
269#. Ping from vpp
270#. Examine Arp Table
271#. Examine ip fib
272
273VPP command learned in this exercise
274^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
275#. `create host-interface <https://docs.fd.io/vpp/17.04/clicmd_src_vnet_devices_af_packet.html#clicmd_create_host-interface>`_
276#. `set int state <https://docs.fd.io/vpp/17.04/clicmd_src_vnet.html#clicmd_set_interface_state>`_
277#. `set int ip address <https://docs.fd.io/vpp/17.04/clicmd_src_vnet_ip.html#clicmd_set_interface_ip_address>`_
278#. `show hardware <https://docs.fd.io/vpp/17.04/clicmd_src_vnet.html#clicmd_show_hardware-interfaces>`_
279#. `show int <https://docs.fd.io/vpp/17.04/clicmd_src_vnet.html#clicmd_show_interfaces>`_
280#. `show int addr <https://docs.fd.io/vpp/17.04/clicmd_src_vnet.html#clicmd_show_interfaces>`_
281#. `trace add <https://docs.fd.io/vpp/17.04/clicmd_src_vlib.html#clicmd_trace_add>`_
282#. `clear trace <https://docs.fd.io/vpp/17.04/clicmd_src_vlib.html#clicmd_clear_trace>`_
283#. `ping <https://docs.fd.io/vpp/17.04/clicmd_src_vnet_ip.html#clicmd_ping>`_
284#. `show ip arp <https://docs.fd.io/vpp/17.04/clicmd_src_vnet_ethernet.html#clicmd_show_ip_arp>`_
285#. `show ip fib <https://docs.fd.io/vpp/17.04/clicmd_src_vnet_fib.html#clicmd_show_ip_fib>`_
286
287Topology
288~~~~~~~~
289
290.. figure:: /_images/Create_Interface_Topology.jpg
291 :alt: Figure: Create Interface Topology
292
293 Figure: Create Interface Topology
294
295Initial State
296~~~~~~~~~~~~~
297
298The initial state here is presumed to be the final state from the
299exercise `VPP Basics <VPP/Progressive_VPP_Tutorial#Exercise:_vpp_basics>`__
300
301Action: Create veth interfaces on host
302~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
303
304In Linux, there is a type of interface call 'veth'. Think of a 'veth'
305interface as being an interface that has two ends to it (rather than
306one).
307
308Create a veth interface with one end named **vpp1out** and the other
309named **vpp1host**
310
311::
312
313 sudo ip link add name vpp1out type veth peer name vpp1host
314
315Turn up both ends:
316
317::
318
319 sudo ip link set dev vpp1out up
320 sudo ip link set dev vpp1host up
321
322Assign an IP address
323
324::
325
326 sudo ip addr add 10.10.1.1/24 dev vpp1host
327
328Display the result:
329
330::
331
332 sudo ip addr show vpp1host
333
334Example Output:
335
336::
337
338 10: vpp1host@vpp1out: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
339 link/ether 5e:97:e3:41:aa:b8 brd ff:ff:ff:ff:ff:ff
340 inet 10.10.1.1/24 scope global vpp1host
341 valid_lft forever preferred_lft forever
342 inet6 fe80::5c97:e3ff:fe41:aab8/64 scope link
343 valid_lft forever preferred_lft forever
344
345Action: Create vpp host- interface
346~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
347
348Create a host interface attached to **vpp1out**.
349
350::
351
352 sudo vppctl -s /run/vpp/cli-vpp1.sock create host-interface name vpp1out
353
354Output:
355
356::
357
358 host-vpp1out
359
360Confirm the interface:
361
362::
363
364 sudo vppctl -s /run/vpp/cli-vpp1.sock show hardware
365
366Example Output:
367
368::
369
370 Name Idx Link Hardware
371 host-vpp1out 1 up host-vpp1out
372 Ethernet address 02:fe:48:ec:d5:a7
373 Linux PACKET socket interface
374 local0 0 down local0
375 local
376
377Turn up the interface:
378
379::
380
381 sudo vppctl -s /run/vpp/cli-vpp1.sock set int state host-vpp1out up
382
383Confirm the interface is up:
384
385::
386
387 sudo vppctl -s /run/vpp/cli-vpp1.sock show int
388
389::
390
391 Name Idx State Counter Count
392 host-vpp1out 1 up
393 local0 0 down
394
395Assign ip address 10.10.1.2/24
396
397::
398
399 sudo vppctl -s /run/vpp/cli-vpp1.sock set int ip address host-vpp1out 10.10.1.2/24
400
401Confirm the ip address is assigned:
402
403::
404
405 sudo vppctl -s /run/vpp/cli-vpp1.sock show int addr
406
407::
408
409 host-vpp1out (up):
410 10.10.1.2/24
411 local0 (dn):
412
413Action: Add trace
414~~~~~~~~~~~~~~~~~
415
416::
417
418 sudo vppctl -s /run/vpp/cli-vpp1.sock trace add af-packet-input 10
419
420Action: Ping from host to vpp
421~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
422
423::
424
425 ping -c 1 10.10.1.2
426
427::
428
429 PING 10.10.1.2 (10.10.1.2) 56(84) bytes of data.
430 64 bytes from 10.10.1.2: icmp_seq=1 ttl=64 time=0.557 ms
431
432 --- 10.10.1.2 ping statistics ---
433 1 packets transmitted, 1 received, 0% packet loss, time 0ms
434 rtt min/avg/max/mdev = 0.557/0.557/0.557/0.000 ms
435
436Action: Examine Trace of ping from host to vpp
437~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
438
439::
440
441 sudo vppctl -s /run/vpp/cli-vpp1.sock show trace
442
443::
444
445 ------------------- Start of thread 0 vpp_main -------------------
446 Packet 1
447
448 00:09:30:397798: af-packet-input
449 af_packet: hw_if_index 1 next-index 4
450 tpacket2_hdr:
451 status 0x20000001 len 42 snaplen 42 mac 66 net 80
452 sec 0x588fd3ac nsec 0x375abde7 vlan 0 vlan_tpid 0
453 00:09:30:397906: ethernet-input
454 ARP: fa:13:55:ac:d9:50 -> ff:ff:ff:ff:ff:ff
455 00:09:30:397912: arp-input
456 request, type ethernet/IP4, address size 6/4
457 fa:13:55:ac:d9:50/10.10.1.1 -> 00:00:00:00:00:00/10.10.1.2
458 00:09:30:398191: host-vpp1out-output
459 host-vpp1out
460 ARP: 02:fe:48:ec:d5:a7 -> fa:13:55:ac:d9:50
461 reply, type ethernet/IP4, address size 6/4
462 02:fe:48:ec:d5:a7/10.10.1.2 -> fa:13:55:ac:d9:50/10.10.1.1
463
464 Packet 2
465
466 00:09:30:398227: af-packet-input
467 af_packet: hw_if_index 1 next-index 4
468 tpacket2_hdr:
469 status 0x20000001 len 98 snaplen 98 mac 66 net 80
470 sec 0x588fd3ac nsec 0x37615060 vlan 0 vlan_tpid 0
471 00:09:30:398295: ethernet-input
472 IP4: fa:13:55:ac:d9:50 -> 02:fe:48:ec:d5:a7
473 00:09:30:398298: ip4-input
474 ICMP: 10.10.1.1 -> 10.10.1.2
475 tos 0x00, ttl 64, length 84, checksum 0x9b46
476 fragment id 0x894c, flags DONT_FRAGMENT
477 ICMP echo_request checksum 0x83c
478 00:09:30:398300: ip4-lookup
479 fib 0 dpo-idx 5 flow hash: 0x00000000
480 ICMP: 10.10.1.1 -> 10.10.1.2
481 tos 0x00, ttl 64, length 84, checksum 0x9b46
482 fragment id 0x894c, flags DONT_FRAGMENT
483 ICMP echo_request checksum 0x83c
484 00:09:30:398303: ip4-local
485 ICMP: 10.10.1.1 -> 10.10.1.2
486 tos 0x00, ttl 64, length 84, checksum 0x9b46
487 fragment id 0x894c, flags DONT_FRAGMENT
488 ICMP echo_request checksum 0x83c
489 00:09:30:398305: ip4-icmp-input
490 ICMP: 10.10.1.1 -> 10.10.1.2
491 tos 0x00, ttl 64, length 84, checksum 0x9b46
492 fragment id 0x894c, flags DONT_FRAGMENT
493 ICMP echo_request checksum 0x83c
494 00:09:30:398307: ip4-icmp-echo-request
495 ICMP: 10.10.1.1 -> 10.10.1.2
496 tos 0x00, ttl 64, length 84, checksum 0x9b46
497 fragment id 0x894c, flags DONT_FRAGMENT
498 ICMP echo_request checksum 0x83c
499 00:09:30:398317: ip4-load-balance
500 fib 0 dpo-idx 10 flow hash: 0x0000000e
501 ICMP: 10.10.1.2 -> 10.10.1.1
502 tos 0x00, ttl 64, length 84, checksum 0xbef3
503 fragment id 0x659f, flags DONT_FRAGMENT
504 ICMP echo_reply checksum 0x103c
505 00:09:30:398318: ip4-rewrite
506 tx_sw_if_index 1 dpo-idx 2 : ipv4 via 10.10.1.1 host-vpp1out: IP4: 02:fe:48:ec:d5:a7 -> fa:13:55:ac:d9:50 flow hash: 0x00000000
507 IP4: 02:fe:48:ec:d5:a7 -> fa:13:55:ac:d9:50
508 ICMP: 10.10.1.2 -> 10.10.1.1
509 tos 0x00, ttl 64, length 84, checksum 0xbef3
510 fragment id 0x659f, flags DONT_FRAGMENT
511 ICMP echo_reply checksum 0x103c
512 00:09:30:398320: host-vpp1out-output
513 host-vpp1out
514 IP4: 02:fe:48:ec:d5:a7 -> fa:13:55:ac:d9:50
515 ICMP: 10.10.1.2 -> 10.10.1.1
516 tos 0x00, ttl 64, length 84, checksum 0xbef3
517 fragment id 0x659f, flags DONT_FRAGMENT
518 ICMP echo_reply checksum 0x103c
519
520Action: Clear trace buffer
521~~~~~~~~~~~~~~~~~~~~~~~~~~
522
523::
524
525 sudo vppctl -s /run/vpp/cli-vpp1.sock clear trace
526
527Action: ping from vpp to host
528~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
529
530::
531
532 sudo vppctl -s /run/vpp/cli-vpp1.sock ping 10.10.1.1
533
534::
535
536 64 bytes from 10.10.1.1: icmp_seq=1 ttl=64 time=.0865 ms
537 64 bytes from 10.10.1.1: icmp_seq=2 ttl=64 time=.0914 ms
538 64 bytes from 10.10.1.1: icmp_seq=3 ttl=64 time=.0943 ms
539 64 bytes from 10.10.1.1: icmp_seq=4 ttl=64 time=.0959 ms
540 64 bytes from 10.10.1.1: icmp_seq=5 ttl=64 time=.0858 ms
541
542 Statistics: 5 sent, 5 received, 0% packet loss
543
544Action: Examine Trace of ping from vpp to host
545~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
546
547::
548
549 sudo vppctl -s /run/vpp/cli-vpp1.sock show trace
550
551::
552
553 ------------------- Start of thread 0 vpp_main -------------------
554 Packet 1
555
556 00:12:47:155326: af-packet-input
557 af_packet: hw_if_index 1 next-index 4
558 tpacket2_hdr:
559 status 0x20000001 len 98 snaplen 98 mac 66 net 80
560 sec 0x588fd471 nsec 0x161c61ad vlan 0 vlan_tpid 0
561 00:12:47:155331: ethernet-input
562 IP4: fa:13:55:ac:d9:50 -> 02:fe:48:ec:d5:a7
563 00:12:47:155334: ip4-input
564 ICMP: 10.10.1.1 -> 10.10.1.2
565 tos 0x00, ttl 64, length 84, checksum 0x2604
566 fragment id 0x3e8f
567 ICMP echo_reply checksum 0x1a83
568 00:12:47:155335: ip4-lookup
569 fib 0 dpo-idx 5 flow hash: 0x00000000
570 ICMP: 10.10.1.1 -> 10.10.1.2
571 tos 0x00, ttl 64, length 84, checksum 0x2604
572 fragment id 0x3e8f
573 ICMP echo_reply checksum 0x1a83
574 00:12:47:155336: ip4-local
575 ICMP: 10.10.1.1 -> 10.10.1.2
576 tos 0x00, ttl 64, length 84, checksum 0x2604
577 fragment id 0x3e8f
578 ICMP echo_reply checksum 0x1a83
579 00:12:47:155339: ip4-icmp-input
580 ICMP: 10.10.1.1 -> 10.10.1.2
581 tos 0x00, ttl 64, length 84, checksum 0x2604
582 fragment id 0x3e8f
583 ICMP echo_reply checksum 0x1a83
584 00:12:47:155342: ip4-icmp-echo-reply
585 ICMP echo id 17572 seq 1
586 00:12:47:155349: error-drop
587 ip4-icmp-input: unknown type
588
589 Packet 2
590
591 00:12:48:155330: af-packet-input
592 af_packet: hw_if_index 1 next-index 4
593 tpacket2_hdr:
594 status 0x20000001 len 98 snaplen 98 mac 66 net 80
595 sec 0x588fd472 nsec 0x1603e95b vlan 0 vlan_tpid 0
596 00:12:48:155337: ethernet-input
597 IP4: fa:13:55:ac:d9:50 -> 02:fe:48:ec:d5:a7
598 00:12:48:155341: ip4-input
599 ICMP: 10.10.1.1 -> 10.10.1.2
600 tos 0x00, ttl 64, length 84, checksum 0x2565
601 fragment id 0x3f2e
602 ICMP echo_reply checksum 0x7405
603 00:12:48:155343: ip4-lookup
604 fib 0 dpo-idx 5 flow hash: 0x00000000
605 ICMP: 10.10.1.1 -> 10.10.1.2
606 tos 0x00, ttl 64, length 84, checksum 0x2565
607 fragment id 0x3f2e
608 ICMP echo_reply checksum 0x7405
609 00:12:48:155344: ip4-local
610 ICMP: 10.10.1.1 -> 10.10.1.2
611 tos 0x00, ttl 64, length 84, checksum 0x2565
612 fragment id 0x3f2e
613 ICMP echo_reply checksum 0x7405
614 00:12:48:155346: ip4-icmp-input
615 ICMP: 10.10.1.1 -> 10.10.1.2
616 tos 0x00, ttl 64, length 84, checksum 0x2565
617 fragment id 0x3f2e
618 ICMP echo_reply checksum 0x7405
619 00:12:48:155348: ip4-icmp-echo-reply
620 ICMP echo id 17572 seq 2
621 00:12:48:155351: error-drop
622 ip4-icmp-input: unknown type
623
624 Packet 3
625
626 00:12:49:155331: af-packet-input
627 af_packet: hw_if_index 1 next-index 4
628 tpacket2_hdr:
629 status 0x20000001 len 98 snaplen 98 mac 66 net 80
630 sec 0x588fd473 nsec 0x15eb77ef vlan 0 vlan_tpid 0
631 00:12:49:155337: ethernet-input
632 IP4: fa:13:55:ac:d9:50 -> 02:fe:48:ec:d5:a7
633 00:12:49:155341: ip4-input
634 ICMP: 10.10.1.1 -> 10.10.1.2
635 tos 0x00, ttl 64, length 84, checksum 0x249e
636 fragment id 0x3ff5
637 ICMP echo_reply checksum 0xf446
638 00:12:49:155343: ip4-lookup
639 fib 0 dpo-idx 5 flow hash: 0x00000000
640 ICMP: 10.10.1.1 -> 10.10.1.2
641 tos 0x00, ttl 64, length 84, checksum 0x249e
642 fragment id 0x3ff5
643 ICMP echo_reply checksum 0xf446
644 00:12:49:155345: ip4-local
645 ICMP: 10.10.1.1 -> 10.10.1.2
646 tos 0x00, ttl 64, length 84, checksum 0x249e
647 fragment id 0x3ff5
648 ICMP echo_reply checksum 0xf446
649 00:12:49:155349: ip4-icmp-input
650 ICMP: 10.10.1.1 -> 10.10.1.2
651 tos 0x00, ttl 64, length 84, checksum 0x249e
652 fragment id 0x3ff5
653 ICMP echo_reply checksum 0xf446
654 00:12:49:155350: ip4-icmp-echo-reply
655 ICMP echo id 17572 seq 3
656 00:12:49:155354: error-drop
657 ip4-icmp-input: unknown type
658
659 Packet 4
660
661 00:12:50:155335: af-packet-input
662 af_packet: hw_if_index 1 next-index 4
663 tpacket2_hdr:
664 status 0x20000001 len 98 snaplen 98 mac 66 net 80
665 sec 0x588fd474 nsec 0x15d2ffb6 vlan 0 vlan_tpid 0
666 00:12:50:155341: ethernet-input
667 IP4: fa:13:55:ac:d9:50 -> 02:fe:48:ec:d5:a7
668 00:12:50:155346: ip4-input
669 ICMP: 10.10.1.1 -> 10.10.1.2
670 tos 0x00, ttl 64, length 84, checksum 0x2437
671 fragment id 0x405c
672 ICMP echo_reply checksum 0x5b6e
673 00:12:50:155347: ip4-lookup
674 fib 0 dpo-idx 5 flow hash: 0x00000000
675 ICMP: 10.10.1.1 -> 10.10.1.2
676 tos 0x00, ttl 64, length 84, checksum 0x2437
677 fragment id 0x405c
678 ICMP echo_reply checksum 0x5b6e
679 00:12:50:155350: ip4-local
680 ICMP: 10.10.1.1 -> 10.10.1.2
681 tos 0x00, ttl 64, length 84, checksum 0x2437
682 fragment id 0x405c
683 ICMP echo_reply checksum 0x5b6e
684 00:12:50:155351: ip4-icmp-input
685 ICMP: 10.10.1.1 -> 10.10.1.2
686 tos 0x00, ttl 64, length 84, checksum 0x2437
687 fragment id 0x405c
688 ICMP echo_reply checksum 0x5b6e
689 00:12:50:155353: ip4-icmp-echo-reply
690 ICMP echo id 17572 seq 4
691 00:12:50:155356: error-drop
692 ip4-icmp-input: unknown type
693
694 Packet 5
695
696 00:12:51:155324: af-packet-input
697 af_packet: hw_if_index 1 next-index 4
698 tpacket2_hdr:
699 status 0x20000001 len 98 snaplen 98 mac 66 net 80
700 sec 0x588fd475 nsec 0x15ba8726 vlan 0 vlan_tpid 0
701 00:12:51:155331: ethernet-input
702 IP4: fa:13:55:ac:d9:50 -> 02:fe:48:ec:d5:a7
703 00:12:51:155335: ip4-input
704 ICMP: 10.10.1.1 -> 10.10.1.2
705 tos 0x00, ttl 64, length 84, checksum 0x23cc
706 fragment id 0x40c7
707 ICMP echo_reply checksum 0xedb3
708 00:12:51:155337: ip4-lookup
709 fib 0 dpo-idx 5 flow hash: 0x00000000
710 ICMP: 10.10.1.1 -> 10.10.1.2
711 tos 0x00, ttl 64, length 84, checksum 0x23cc
712 fragment id 0x40c7
713 ICMP echo_reply checksum 0xedb3
714 00:12:51:155338: ip4-local
715 ICMP: 10.10.1.1 -> 10.10.1.2
716 tos 0x00, ttl 64, length 84, checksum 0x23cc
717 fragment id 0x40c7
718 ICMP echo_reply checksum 0xedb3
719 00:12:51:155341: ip4-icmp-input
720 ICMP: 10.10.1.1 -> 10.10.1.2
721 tos 0x00, ttl 64, length 84, checksum 0x23cc
722 fragment id 0x40c7
723 ICMP echo_reply checksum 0xedb3
724 00:12:51:155343: ip4-icmp-echo-reply
725 ICMP echo id 17572 seq 5
726 00:12:51:155346: error-drop
727 ip4-icmp-input: unknown type
728
729 Packet 6
730
731 00:12:52:175185: af-packet-input
732 af_packet: hw_if_index 1 next-index 4
733 tpacket2_hdr:
734 status 0x20000001 len 42 snaplen 42 mac 66 net 80
735 sec 0x588fd476 nsec 0x16d05dd0 vlan 0 vlan_tpid 0
736 00:12:52:175195: ethernet-input
737 ARP: fa:13:55:ac:d9:50 -> 02:fe:48:ec:d5:a7
738 00:12:52:175200: arp-input
739 request, type ethernet/IP4, address size 6/4
740 fa:13:55:ac:d9:50/10.10.1.1 -> 00:00:00:00:00:00/10.10.1.2
741 00:12:52:175214: host-vpp1out-output
742 host-vpp1out
743 ARP: 02:fe:48:ec:d5:a7 -> fa:13:55:ac:d9:50
744 reply, type ethernet/IP4, address size 6/4
745 02:fe:48:ec:d5:a7/10.10.1.2 -> fa:13:55:ac:d9:50/10.10.1.1
746
747After examinging the trace, clear it again.
748
749Action: Examine arp tables
750~~~~~~~~~~~~~~~~~~~~~~~~~~
751
752::
753
754 sudo vppctl -s /run/vpp/cli-vpp1.sock show ip arp
755
756::
757
758 Time IP4 Flags Ethernet Interface
759 570.4092 10.10.1.1 D fa:13:55:ac:d9:50 host-vpp1out
760
761Action: Examine routing table
762~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
763
764::
765
766 sudo vppctl -s /run/vpp/cli-vpp1.sock show ip fib
767
768::
769
770 ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto
771 0.0.0.0/0
772 unicast-ip4-chain
773 [@0]: dpo-load-balance: [index:0 buckets:1 uRPF:0 to:[0:0]]
774 [0] [@0]: dpo-drop ip4
775 0.0.0.0/32
776 unicast-ip4-chain
777 [@0]: dpo-load-balance: [index:1 buckets:1 uRPF:1 to:[0:0]]
778 [0] [@0]: dpo-drop ip4
779 10.10.1.1/32
780 unicast-ip4-chain
781 [@0]: dpo-load-balance: [index:10 buckets:1 uRPF:9 to:[5:420] via:[1:84]]
782 [0] [@5]: ipv4 via 10.10.1.1 host-vpp1out: IP4: 02:fe:48:ec:d5:a7 -> fa:13:55:ac:d9:50
783 10.10.1.0/24
784 unicast-ip4-chain
785 [@0]: dpo-load-balance: [index:8 buckets:1 uRPF:7 to:[0:0]]
786 [0] [@4]: ipv4-glean: host-vpp1out
787 10.10.1.2/32
788 unicast-ip4-chain
789 [@0]: dpo-load-balance: [index:9 buckets:1 uRPF:8 to:[6:504]]
790 [0] [@2]: dpo-receive: 10.10.1.2 on host-vpp1out
791 224.0.0.0/4
792 unicast-ip4-chain
793 [@0]: dpo-load-balance: [index:3 buckets:1 uRPF:3 to:[0:0]]
794 [0] [@0]: dpo-drop ip4
795 240.0.0.0/4
796 unicast-ip4-chain
797 [@0]: dpo-load-balance: [index:2 buckets:1 uRPF:2 to:[0:0]]
798 [0] [@0]: dpo-drop ip4
799 255.255.255.255/32
800 unicast-ip4-chain
801 [@0]: dpo-load-balance: [index:4 buckets:1 uRPF:4 to:[0:0]]
802 [0] [@0]: dpo-drop ip4
803
804Exercise: Connecting two vpp instances
805--------------------------------------
806
807.. _background-1:
808
809Background
810^^^^^^^^^^^^^^^^^^^^^^^^^^
811
812memif is a very high performance, direct memory interface type which can
813be used between vpp instances to form a topology. It uses a file socket
814for a control channel to set up that shared memory.
815
816.. _skills-to-be-learned-1:
817
818Skills to be Learned
819^^^^^^^^^^^^^^^^^^^^^^^^^^
820
821You will learn the following new skill in this exercise:
822
823#. Create a memif interface between two vpp instances
824
825You should be able to perform this exercise with the following skills
826learned in previous exercises:
827
828#. Run a second vpp instance
829#. Add an ip address to a vpp interface
830#. Ping from vpp
831
832.. _topology-1:
833
834Topology
835^^^^^^^^^^^^^
836
837.. figure:: /_images/Connecting_two_vpp_instances_with_memif.png
838 :alt: Connect two vpp topolgy
839
840 Connect two vpp topolgy
841
842.. _initial-state-1:
843
844Initial state
845^^^^^^^^^^^^^
846
847The initial state here is presumed to be the final state from the
848exercise `Create an
849Interface <VPP/Progressive_VPP_Tutorial#Exercise:_Create_an_Interface>`__
850
851.. _action-running-a-second-vpp-instances-1:
852
853Action: Running a second vpp instances
854^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
855
856You should already have a vpp instance running named: vpp1.
857
858Run a second vpp instance named: vpp2.
859
860.. _action-create-memif-interface-on-vpp1-1:
861
862Action: Create memif interface on vpp1
863^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
864
865Create a memif interface on vpp1:
866
867::
868
869 sudo vppctl -s /run/vpp/cli-vpp1.sock create memif id 0 master
870
871This will create an interface on vpp1 memif0/0 using /run/vpp/memif as
872its socket file. The role of vpp1 for this memif inteface is 'master'.
873
874Use your previously used skills to:
875
876#. Set the memif0/0 state to up.
877#. Assign IP address 10.10.2.1/24 to memif0/0
878#. Examine memif0/0 via show commands
879
880.. _action-create-memif-interface-on-vpp2-1:
881
882Action: Create memif interface on vpp2
883^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
884
885We want vpp2 to pick up the 'slave' role using the same
886run/vpp/memif-vpp1vpp2 socket file
887
888::
889
890 sudo vppctl -s /run/vpp/cli-vpp2.sock create memif id 0 slave
891
892This will create an interface on vpp2 memif0/0 using /run/vpp/memif as
893its socket file. The role of vpp1 for this memif inteface is 'slave'.
894
895Use your previously used skills to:
896
897#. Set the memif0/0 state to up.
898#. Assign IP address 10.10.2.2/24 to memif0/0
899#. Examine memif0/0 via show commands
900
901.. _action-ping-from-vpp1-to-vpp2-1:
902
903Action: Ping from vpp1 to vpp2
904^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
905
906Ping 10.10.2.2 from vpp1
907
908Ping 10.10.2.1 from vpp2
909
910Exercise: Routing
911-----------------
912
913Skills to be Learned
914^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
915
916In this exercise you will learn these new skills:
917
918#. Add route to Linux Host routing table
919#. Add route to vpp routing table
920
921And revisit the old ones:
922
923#. Examine vpp routing table
924#. Enable trace on vpp1 and vpp2
925#. ping from host to vpp
926#. Examine and clear trace on vpp1 and vpp2
927#. ping from vpp to host
928#. Examine and clear trace on vpp1 and vpp2
929
930vpp command learned in this exercise
931^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
932
933#. `ip route
934 add <https://docs.fd.io/vpp/17.04/clicmd_src_vnet_ip.html#clicmd_ip_route>`__
935
936Topology
937^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
938
939.. figure:: /_images/Connecting_two_vpp_instances_with_memif.png
940 :alt: Connect two vpp topology
941
942 Connect two vpp topology
943
944Initial State
945^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
946
947The initial state here is presumed to be the final state from the
948exercise `Connecting two vpp
949instances <VPP/Progressive_VPP_Tutorial#Connecting_two_vpp_instances>`__
950
951Action: Setup host route
952^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
953
954::
955
956 sudo ip route add 10.10.2.0/24 via 10.10.1.2
957 ip route
958
959::
960
961 default via 10.0.2.2 dev enp0s3
962 10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15
963 10.10.1.0/24 dev vpp1host proto kernel scope link src 10.10.1.1
964 10.10.2.0/24 via 10.10.1.2 dev vpp1host
965
966Setup return route on vpp2
967^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
968
969::
970
971 sudo vppctl -s /run/vpp/cli-vpp2.sock ip route add 10.10.1.0/24 via 10.10.2.1
972
973Ping from host through vpp1 to vpp2
974^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
975
976#. Setup a trace on vpp1 and vpp2
977#. Ping 10.10.2.2 from the host
978#. Examine the trace on vpp1 and vpp2
979#. Clear the trace on vpp1 and vpp2
980
981Exercise: Switching
982-------------------
983
984Skills to be Learned
985^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
986
987#. Associate an interface with a bridge domain
988#. Create a loopback interaface
989#. Create a BVI (Bridge Virtual Interface) for a bridge domain
990#. Examine a bridge domain
991
992vpp command learned in this exercise
993^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
994
995#. `show
996 bridge <https://docs.fd.io/vpp/17.04/clicmd_src_vnet_l2.html#clicmd_show_bridge-domain>`__
997#. `show bridge
998 detail <https://docs.fd.io/vpp/17.04/clicmd_src_vnet_l2.html#clicmd_show_bridge-domain>`__
999#. `set int l2
1000 bridge <https://docs.fd.io/vpp/17.04/clicmd_src_vnet_l2.html#clicmd_set_interface_l2_bridge>`__
1001#. `show l2fib
1002 verbose <https://docs.fd.io/vpp/17.04/clicmd_src_vnet_l2.html#clicmd_show_l2fib>`__
1003
1004Topology
1005^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1006
1007.. figure:: /_images/Switching_Topology.jpg
1008 :alt: Switching Topology
1009
1010 Switching Topology
1011
1012Initial state
1013^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1014
1015Unlike previous exercises, for this one you want to start tabula rasa.
1016
1017Note: You will lose all your existing config in your vpp instances!
1018
1019To clear existing config from previous exercises run:
1020
1021::
1022
1023 ps -ef | grep vpp | awk '{print $2}'| xargs sudo kill
1024 sudo ip link del dev vpp1host
1025 sudo ip link del dev vpp1vpp2
1026
1027Action: Run vpp instances
1028^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1029
1030#. Run a vpp instance named **vpp1**
1031#. Run a vpp instance named **vpp2**
1032
1033Action: Connect vpp1 to host
1034^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1035
1036#. Create a veth with one end named vpp1host and the other named
1037 vpp1out.
1038#. Connect vpp1out to vpp1
1039#. Add ip address 10.10.1.1/24 on vpp1host
1040
1041Action: Connect vpp1 to vpp2
1042^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1043
1044#. Create a veth with one end named vpp1vpp2 and the other named
1045 vpp2vpp1.
1046#. Connect vpp1vpp2 to vpp1.
1047#. Connect vpp2vpp1 to vpp2.
1048
1049Action: Configure Bridge Domain on vpp1
1050^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1051
1052Check to see what bridge domains already exist, and select the first
1053bridge domain number not in use:
1054
1055::
1056
1057 sudo vppctl -s /run/vpp/cli-vpp1.sock show bridge-domain
1058
1059::
1060
1061 ID Index Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf
1062 0 0 off off off off off local0
1063
1064In the example above, there is bridge domain ID '0' already. Even though
1065sometimes we might get feedback as below:
1066
1067::
1068
1069 no bridge-domains in use
1070
1071the bridge domain ID '0' still exists, where no operations are
1072supported. For instance, if we try to add host-vpp1out and host-vpp1vpp2
1073to bridge domain ID 0, we will get nothing setup.
1074
1075::
1076
1077 sudo vppctl -s /run/vpp/cli-vpp1.sock set int l2 bridge host-vpp1out 0
1078 sudo vppctl -s /run/vpp/cli-vpp1.sock set int l2 bridge host-vpp1vpp2 0
1079 sudo vppctl -s /run/vpp/cli-vpp1.sock show bridge-domain 0 detail
1080
1081::
1082
1083 show bridge-domain: No operations on the default bridge domain are supported
1084
1085So we will create bridge domain 1 instead of playing with the default
1086bridge domain ID 0.
1087
1088Add host-vpp1out to bridge domain ID 1
1089
1090::
1091
1092 sudo vppctl -s /run/vpp/cli-vpp1.sock set int l2 bridge host-vpp1out 1
1093
1094Add host-vpp1vpp2 to bridge domain ID1
1095
1096::
1097
1098 sudo vppctl -s /run/vpp/cli-vpp1.sock set int l2 bridge host-vpp1vpp2 1
1099
1100Examine bridge domain 1:
1101
1102::
1103
1104 sudo vppctl -s /run/vpp/cli-vpp1.sock show bridge-domain 1 detail
1105
1106::
1107
1108 BD-ID Index BSN Age(min) Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf
1109 1 1 0 off on on on on off N/A
1110
1111 Interface If-idx ISN SHG BVI TxFlood VLAN-Tag-Rewrite
1112 host-vpp1out 1 1 0 - * none
1113 host-vpp1vpp2 2 1 0 - * none
1114
1115Action: Configure loopback interface on vpp2
1116^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1117
1118::
1119
1120 sudo vppctl -s /run/vpp/cli-vpp2.sock create loopback interface
1121
1122::
1123
1124 loop0
1125
1126Add the ip address 10.10.1.2/24 to vpp2 interface loop0. Set the state
1127of interface loop0 on vpp2 to 'up'
1128
1129Action: Configure bridge domain on vpp2
1130^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1131
1132Check to see the first available bridge domain ID (it will be 1 in this
1133case)
1134
1135Add interface loop0 as a bridge virtual interface (bvi) to bridge domain
11361
1137
1138::
1139
1140 sudo vppctl -s /run/vpp/cli-vpp2.sock set int l2 bridge loop0 1 bvi
1141
1142Add interface vpp2vpp1 to bridge domain 1
1143
1144::
1145
1146 sudo vppctl -s /run/vpp/cli-vpp2.sock set int l2 bridge host-vpp2vpp1 1
1147
1148Examine the bridge domain and interfaces.
1149
1150Action: Ping from host to vpp and vpp to host
1151^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1152
1153#. Add trace on vpp1 and vpp2
1154#. ping from host to 10.10.1.2
1155#. Examine and clear trace on vpp1 and vpp2
1156#. ping from vpp2 to 10.10.1.1
1157#. Examine and clear trace on vpp1 and vpp2
1158
1159Action: Examine l2 fib
1160^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1161
1162::
1163
1164 sudo vppctl -s /run/vpp/cli-vpp1.sock show l2fib verbose
1165
1166::
1167
1168 Mac Address BD Idx Interface Index static filter bvi Mac Age (min)
1169 de:ad:00:00:00:00 1 host-vpp1vpp2 2 0 0 0 disabled
1170 c2:f6:88:31:7b:8e 1 host-vpp1out 1 0 0 0 disabled
1171 2 l2fib entries
1172
1173::
1174
1175 sudo vppctl -s /run/vpp/cli-vpp2.sock show l2fib verbose
1176
1177::
1178
1179 Mac Address BD Idx Interface Index static filter bvi Mac Age (min)
1180 de:ad:00:00:00:00 1 loop0 2 1 0 1 disabled
1181 c2:f6:88:31:7b:8e 1 host-vpp2vpp1 1 0 0 0 disabled
1182 2 l2fib entries
1183
1184Source NAT
1185----------
1186
1187Skills to be Learned
1188^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1189
1190#. Abusing networks namespaces for fun and profit
1191#. Configuring snat address
1192#. Configuring snat inside and outside interfaces
1193
1194vpp command learned in this exercise
1195^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1196
1197#. `snat add interface
1198 address <https://docs.fd.io/vpp/17.04/clicmd_src_plugins_snat.html#clicmd_snat_add_interface_address>`__
1199#. `set interface
1200 snat <https://docs.fd.io/vpp/17.04/clicmd_src_plugins_snat.html#clicmd_set_interface_snat>`__
1201
1202Topology
1203^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1204
1205.. figure:: /_images/SNAT_Topology.jpg
1206 :alt: SNAT Topology
1207
1208 SNAT Topology
1209
1210Initial state
1211^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
1213Unlike previous exercises, for this one you want to start tabula rasa.
1214
1215Note: You will lose all your existing config in your vpp instances!
1216
1217To clear existing config from previous exercises run:
1218
1219::
1220
1221 ps -ef | grep vpp | awk '{print $2}'| xargs sudo kill
1222 sudo ip link del dev vpp1host
1223 sudo ip link del dev vpp1vpp2
1224
1225Action: Install vpp-plugins
1226^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1227
1228Snat is supported by a plugin, so vpp-plugins need to be installed
1229
1230::
1231
1232 sudo apt-get install vpp-plugins
1233
1234Action: Create vpp instance
1235^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1236
1237Create one vpp instance named vpp1.
1238
1239Confirm snat plugin is present:
1240
1241::
1242
1243 sudo vppctl -s /run/vpp/cli-vpp1.sock show plugins
1244
1245::
1246
1247 Plugin path is: /usr/lib/vpp_plugins
1248 Plugins loaded:
1249 1.ioam_plugin.so
1250 2.ila_plugin.so
1251 3.acl_plugin.so
1252 4.flowperpkt_plugin.so
1253 5.snat_plugin.so
1254 6.libsixrd_plugin.so
1255 7.lb_plugin.so
1256
1257Action: Create veth interfaces
1258^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1259
1260#. Create a veth interface with one end named vpp1outside and the other
1261 named vpp1outsidehost
1262#. Assign IP address 10.10.1.1/24 to vpp1outsidehost
1263#. Create a veth interface with one end named vpp1inside and the other
1264 named vpp1insidehost
1265#. Assign IP address 10.10.2.1/24 to vpp1outsidehost
1266
1267Because we'd like to be able to route \*via\* our vpp instance to an
1268interface on the same host, we are going to put vpp1insidehost into a
1269network namespace
1270
1271Create a new network namespace 'inside'
1272
1273::
1274
1275 sudo ip netns add inside
1276
1277Move interface vpp1inside into the 'inside' namespace:
1278
1279::
1280
1281 sudo ip link set dev vpp1insidehost up netns inside
1282
1283Assign an ip address to vpp1insidehost
1284
1285::
1286
1287 sudo ip netns exec inside ip addr add 10.10.2.1/24 dev vpp1insidehost
1288
1289Create a route inside the netns:
1290
1291::
1292
1293 sudo ip netns exec inside ip route add 10.10.1.0/24 via 10.10.2.2
1294
1295Action: Configure vpp outside interface
1296^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1297
1298#. Create a vpp host interface connected to vpp1outside
1299#. Assign ip address 10.10.1.2/24
1300#. Create a vpp host interface connected to vpp1inside
1301#. Assign ip address 10.10.2.2/24
1302
1303Action: Configure snat
1304^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1305
1306Configure snat to use the address of host-vpp1outside
1307
1308::
1309
1310 sudo vppctl -s /run/vpp/cli-vpp1.sock snat add interface address host-vpp1outside
1311
1312Configure snat inside and outside interfaces
1313
1314::
1315
1316 sudo vppctl -s /run/vpp/cli-vpp1.sock set interface snat in host-vpp1inside out host-vpp1outside
1317
1318Action: Prepare to Observe Snat
1319^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1320
1321Observing snat in this configuration is interesting. To do so, vagrant
1322ssh a second time into your VM and run:
1323
1324::
1325
1326 sudo tcpdump -s 0 -i vpp1outsidehost
1327
1328Also enable tracing on vpp1
1329
1330Action: Ping via snat
1331^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1332
1333::
1334
1335 sudo ip netns exec inside ping -c 1 10.10.1.1
1336
1337Action: Confirm snat
1338^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1339
1340Examine the tcpdump output and vpp1 trace to confirm snat occurred.
1341