Difference between revisions of "VPP/Progressive VPP Tutorial"

From fd.io
< VPP
Jump to: navigation, search
(Action: Run vpp)
(Action: Create vpp host- interface)
Line 254: Line 254:
 
=== Action: Create vpp host- interface ===
 
=== Action: Create vpp host- interface ===
  
 +
Create a host interface attached to '''vpp1out'''.
 
<pre style="background-color:palegreen">
 
<pre style="background-color:palegreen">
 
sudo vppctl -p vpp1 create host-interface name vpp1out
 
sudo vppctl -p vpp1 create host-interface name vpp1out
sudo vppctl -p vpp1 set int state host-vpp1out up
+
</pre>
sudo vppctl -p vpp1 set int ip address host-vpp1out 10.10.1.2/24
+
 
 +
Output:
 +
 
 +
<pre style="background-color:Khaki">
 +
host-vpp1out
 +
 
 +
</pre>
 +
 
 +
Confirm the interface:
 +
<pre style="background-color:palegreen">
 
sudo vppctl -p vpp1 show hardware
 
sudo vppctl -p vpp1 show hardware
 +
</pre>
 +
 +
Example Output:
 +
<pre style="background-color:Khaki">
 +
              Name                Idx  Link  Hardware
 +
host-vpp1out                      1    up  host-vpp1out
 +
  Ethernet address 02:fe:48:ec:d5:a7
 +
  Linux PACKET socket interface
 +
local0                            0    down  local0
 +
  local
 +
 +
</pre>
 +
 +
 +
Turn up the interface:
 +
<pre style="background-color:palegreen">
 +
sudo vppctl -p vpp1 set int state host-vpp1out up
 +
</pre>
 +
 +
Confirm the interface is up:
 +
<pre style="background-color:palegreen">
 
sudo vppctl -p vpp1 show int
 
sudo vppctl -p vpp1 show int
 +
</pre>
 +
 +
<pre style="background-color:Khaki">
 +
              Name              Idx      State          Counter          Count   
 +
host-vpp1out                      1        up     
 +
local0                            0        down
 +
</pre>
 +
 +
Assign ip address 10.10.1.2/24
 +
<pre style="background-color:palegreen">
 +
sudo vppctl -p vpp1 set int ip address host-vpp1out 10.10.1.2/24
 +
</pre>
 +
 +
Confirm the ip address is assigned:
 +
 +
<pre style="background-color:palegreen">
 
sudo vppctl -p vpp1 show int addr
 
sudo vppctl -p vpp1 show int addr
 +
</pre>
 +
 +
<pre style="background-color:Khaki">
 +
host-vpp1out (up):
 +
  10.10.1.2/24
 +
local0 (dn):
 
</pre>
 
</pre>
  

Revision as of 23:58, 30 January 2017

Contents

Exercise: Setting up your environment

All of these exercises are designed to be performed on an Ubuntu 16.04 (Xenial) box.

If you have an Ubuntu 16.04 box on which you have sudo, you can feel free to use that.

If you do not, a Vagrantfile is provided to setup a basic Ubuntu 16.04 box for you

Vagrant Set up

Action: Install Virtualbox

If you do not already have virtualbox on your laptop (or if it is not up to date), please download and install it:

https://www.virtualbox.org/wiki/Downloads

Action: Install Vagrant

If you do not already have Vagrant on your laptop (or if it is not up to date), please download it:

https://www.vagrantup.com/downloads.html

Action: Create a Vagrant Directory

Create a directory on your laptop:

mkdir fdio-tutorial
cd fdio-tutorial/

Create a Vagrantfile containing:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|

  config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm"
  config.vm.box_check_update = false

  vmcpu=(ENV['VPP_VAGRANT_VMCPU'] || 2)
  vmram=(ENV['VPP_VAGRANT_VMRAM'] || 4096)

  config.ssh.forward_agent = true

  config.vm.provider "virtualbox" do |vb|
      vb.customize ["modifyvm", :id, "--ioapic", "on"]
      vb.memory = "#{vmram}"
      vb.cpus = "#{vmcpu}"
      #support for the SSE4.x instruction is required in some versions of VB.
      vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.1", "1"]
      vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.2", "1"]
  end
end

Action: Vagrant Up

Bring up your Vagrant VM:

vagrant up

Action: ssh to Vagrant VM

vagrant ssh

Exercise: Install vpp

Skills to be learned

  1. Learn how to install vpp binary packges using apt-get.

Note: This tutorial is using a special packaging of vpp called vpp_lite that allows you to run multiple vpp processes simultaneously. We will be building topologies of these vpp processes to allow us to perform labs which require multiple instances of 'routers' or 'switches'. Because of this, we will be getting our vpp packages from a slightly non-standard apt repository.

The installation mechanism is very similar to the standard Install VPP from Binary Packages instructions.

Action: Add key for apt repo

curl -L https://packagecloud.io/fdio/tutorial/gpgkey | sudo apt-key add -

Action: Add repo to apt sources.list.d

With your favorite text editor (and sudo), create a file:

/etc/apt/sources.list.d/fdio_tutorial.list

containing

deb https://packagecloud.io/fdio/tutorial/ubuntu/ xenial main
deb-src https://packagecloud.io/fdio/tutorial/ubuntu/ xenial main

Action: apt-get install vpp

Run

sudo apt-get update
sudo apt-get install vpp

Exercise: vpp basics

Skills to be Learned

By the end of the exerise you should be able to:

  1. Run a vpp instance in a mode which allows multiple vpp processes to run
  2. Issue vpp commands from the unix shell
  3. Run a vpp shell and issue it commands


vpp command learned in this exercise

  1. show ver

Action: Run vpp

vpp 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. In those circumstances you usually run a single instance of vpp.

For 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 a topology. Fortunately, vpp supports this.

When running multiple vpp instances, each instance needs to have specified a 'name' or 'prefix'. In the example below, the 'name' or 'prefix' is "vpp1"

sudo vpp api-segment { prefix vpp1 }

Example Output:

unix_physmem_init: use huge pages
vlib_plugin_early_init:230: plugin path /usr/lib/vpp_plugins
0: api_main_init:52: vam 6acb60

Action: Using vppctl to send commands to vpp

You can send vpp commands with a utility called
vppctl
.

When running vppctl against a named version of vpp, you will need to run:

sudo vppctl -p ${name} ${cmd}

So to run 'show ver' against the vpp instance named vpp1 you would run:

sudo vppctl -p vpp1 show ver

Output:

vpp v17.04-rc0~177-g006eb47 built by ubuntu on fdio-ubuntu1604-sevt at Mon Jan 30 18:30:12 UTC 2017


Action: Using vppctl to start a vpp shell

You can also use vppctl to launch a vpp shell with which you can run multiple vpp commands interactively by running:

sudo vppctl -p ${name}

which will give you a command prompt.

Try doing show ver that way:

sudo vppctl -p vpp1
vpp1# show ver

Output:

vpp v17.04-rc0~177-g006eb47 built by ubuntu on fdio-ubuntu1604-sevt at Mon Jan 30 18:30:12 UTC 2017

vpp1#

Exercise: Create an Interface

Skills to be Learned

  1. Create a veth interface in Linux host
  2. Assign an IP address to one end of the veth interface in the Linux host
  3. Create a vpp host-interface that connected to one end of a veth interface via AF_PACKET
  4. Add an ip address to a vpp interface
  5. Setup a 'trace'
  6. View a 'trace'
  7. Clear a 'trace'
  8. Verify using ping from host
  9. Ping from vpp

vpp command learned in this exercise

  1. create host-interface
  2. set int state
  3. set int ip address
  4. show hardware
  5. show int
  6. show int addr
  7. trace add
  8. clear trace
  9. ping

Initial State

The initial state here is presumed to be the final state from the exercise VPP Basics

Action: Create veth interfaces on host

In Linux, there is a type of interface call 'veth'. Think of a 'veth' interface as being an interface that has two ends to it (rather than one).

Create a veth interface with one end named vpp1out and the other named vpp1host

sudo ip link add name vpp1out type veth peer name vpp1host

Turn up both ends:

sudo ip link set dev vpp1out up
sudo ip link set dev vpp1host up

Assign an IP address

sudo ip addr add 10.10.1.1/24 dev vpp1host

Display the result:

sudo ip addr show vpp1host

Example Output:

10: vpp1host@vpp1out: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 5e:97:e3:41:aa:b8 brd ff:ff:ff:ff:ff:ff
    inet 10.10.1.1/24 scope global vpp1host
       valid_lft forever preferred_lft forever
    inet6 fe80::5c97:e3ff:fe41:aab8/64 scope link 
       valid_lft forever preferred_lft forever

Action: Create vpp host- interface

Create a host interface attached to vpp1out.

sudo vppctl -p vpp1 create host-interface name vpp1out

Output:

host-vpp1out

Confirm the interface:

sudo vppctl -p vpp1 show hardware

Example Output:

              Name                Idx   Link  Hardware
host-vpp1out                       1     up   host-vpp1out
  Ethernet address 02:fe:48:ec:d5:a7
  Linux PACKET socket interface
local0                             0    down  local0
  local


Turn up the interface:

sudo vppctl -p vpp1 set int state host-vpp1out up

Confirm the interface is up:

sudo vppctl -p vpp1 show int
              Name               Idx       State          Counter          Count     
host-vpp1out                      1         up       
local0                            0        down

Assign ip address 10.10.1.2/24

sudo vppctl -p vpp1 set int ip address host-vpp1out 10.10.1.2/24

Confirm the ip address is assigned:

sudo vppctl -p vpp1 show int addr
host-vpp1out (up):
  10.10.1.2/24
local0 (dn):

Action: Ping from host to vpp and vpp to host

sudo vppctl -p vpp1 trace add af-packet-input 10
ping -c 1 10.10.1.2
sudo vppctl -p vpp1 show trace
sudo vppctl -p vpp1 clear  trace
sudo vppctl -p vpp1 show ip arp
sudo vppctl -p vpp1 show ip fib

Connecting two vpp instances

Skills to be Learned

You should be able to perform this exercise with the following skills learned in previous exercises:

  1. Create a veth interface in Linux host
  2. Create a vpp host-interface that connected to one end of a veth interface via AF_PACKET
  3. Add an ip address to a vpp interface
  4. Ping from vpp

Initial state

The initial state here is presumed to be the final state from the exercise Create an Interface

Running a second vpp instances

You should already have a vpp instance running named: vpp1.

Run a second vpp instance named: vpp2.

Create veth interface on host to connect the two vpp instances

Create a veth interface on the Linux host with one end named vpp1vpp2 and the other named vpp2vpp1.

Don't assign an ip address to either end on the host.

Create vpp host interfaces

Create a host interface on vpp1 connected to vpp1vpp2. Assign it the address 10.10.2.1/24

Create a host interface on vpp2 connected to vpp2vpp1. Assign it the address 10.10.2.2/24

Running a second vpp instances

sudo vpp api-segment { prefix vpp2 }

Create veth interface on host to connect the two vpp instances

Using skills from the previous exercise, create a veth interface on the host with one end named vpp1vpp2 and the other named vpp2vpp1. Don't assign an ip address to either end on the host.

Create vpp host interfaces

Using skills from the previous exercise, create a host interface on vpp1 connected to vpp1vpp2. Assign it the address 10.10.2.1/30 Using skills from the previous exercise, create a host interface on vpp2 connected to vpp2vpp1. Assign it the address 10.10.2.2/30

Ping from vpp1 to vpp2

sudo vppctl -p vpp1 ping 10.10.2.2
sudo vppctl -p vpp2 ping 10.10.2.1
sudo vppctl -p vpp1 ping 10.10.2.3

Routing

Setup route host

sudo ip route add 10.10.2.0/24 via 10.10.1.2
ip route

Setup return route on vpp2

sudo vppctl -p vpp2 ip route add 10.10.1.0/24  via 10.10.2.1
sudo vppctl -p vpp2 show ip fib

Ping from host through vpp1 to vpp2

ping -c1 10.10.2.2

Ping from vpp2 through vpp1 to host

sudo vppctl -p vpp2 ping 10.10.1.1

Switching

Cleanup previous exercises

Note: You will lose all your existing config in your vpp instances!

ps -ef | grep vpp | awk '{print $2}'| xargs sudo kill
sudo ip link del dev vpp1host
sudo ip link del dev vpp1vpp2

Configure the topology below using previous skills

Configure bridge domain on vpp1

Source NAT

Configure Source NAT

Verify Source NAT

Test Source NAT

LW46

Configure LW46

Verify LW46

Test LW46