aboutsummaryrefslogtreecommitdiffstats
path: root/docs/reference/vppvagrant/boxSetup.rst
blob: 374ba3494585f10a905eb5d11b0b221f2061ef44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
.. _boxSetup:

.. toctree::


Vagrantfiles
============

A `Vagrantfile <https://www.vagrantup.com/docs/vagrantfile/>`_ contains the box and provision configuration settings for your VM. The syntax of Vagrantfiles is Ruby (Ruby experience is not necessary).

The command **vagrant up** creates a *Vagrant Box* based on your Vagrantfile. A Vagrant box is one of the motivations for using Vagrant - its a "development-ready box" that can be copied to other machines to recreate the same environment. 

It's common for people to think that a Vagrant box *is* the VM. But rather, the VM is *inside* a Vagrant box, with the box containing additional configuration options you can set, such as VM options, scripts to run on boot, etc.

This `Vagrant website for boxes <https://app.vagrantup.com/boxes/search>`_  shows you how to configure a basic Vagrantfile for your specific OS and VM software.


Box configuration 
_________________


Looking at the :ref:`vppVagrantfile`, we can see that the default OS is Ubuntu 16.04 (since the variable *distro* equals *ubuntu1604* if there is no VPP_VAGRANT_DISTRO variable set - thus the **else** case is executed.)

.. code-block:: ruby

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

    Vagrant.configure(2) do |config|

      # Pick the right distro and bootstrap, default is ubuntu1604
      distro = ( ENV['VPP_VAGRANT_DISTRO'] || "ubuntu1604")
      if distro == 'centos7'
        config.vm.box = "centos/7"
        config.vm.box_version = "1708.01"
        config.ssh.insert_key = false
      elsif distro == 'opensuse'
        config.vm.box = "opensuse/openSUSE-42.3-x86_64"
        config.vm.box_version = "1.0.4.20170726"
      else
        config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm"

As mentioned in the previous page, you can specify which OS and VM provider you want for your Vagrant box from the `Vagrant boxes page <https://app.vagrantup.com/boxes/search>`_, and setting your ENV variable appropriately in *env.sh*.

Next in the Vagrantfile, you see some *config.vm.provision* commands. As paraphrased from `Basic usage of Provisioners <https://www.vagrantup.com/docs/provisioning/basic_usage.html>`_, by default these are only run *once* - during the first boot of the box.

.. code-block:: ruby

    config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"update.sh")
    config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"build.sh"), :args => "/vpp vagrant"

The two lines above set the VM to run two scripts during its first bootup: an update script *update.sh* that does basic updating and installation of some useful tools, as well as *build.sh* that builds (but does **not** install) VPP in the VM. You can view these scripts on your own for more detail on the commands used.


Looking further in the :ref:`vppVagrantfile`, you can see more Ruby variables being set to ENV's or to a default value:

.. code-block:: ruby

    # Define some physical ports for your VMs to be used by DPDK
    nics = (ENV['VPP_VAGRANT_NICS'] || "2").to_i(10)
    for i in 1..nics
      config.vm.network "private_network", type: "dhcp"
    end

    # use http proxy if avaiable
    if ENV['http_proxy'] && Vagrant.has_plugin?("vagrant-proxyconf")
     config.proxy.http     = ENV['http_proxy']
     config.proxy.https    = ENV['https_proxy']
     config.proxy.no_proxy = "localhost,127.0.0.1"
    end

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


You can see how the box or VM is configured, such as the amount of NICs (defaults to 3 NICs: 1 x NAT - host access and 2 x VPP DPDK enabled), CPUs (defaults to 2), and RAM (defaults to 4096 MB).


Box bootup
__________


Once you're satisfied with your *Vagrantfile*, boot the box with:

.. code-block:: shell

    $ vagrant up

Doing this above command will take quite some time, since you are installing a VM and building VPP. Take a break and get some scooby snacks while you wait.

To confirm it is up, show the status and information of Vagrant boxes with: 

.. code-block:: console

  $ vagrant global-status
  id       name    provider   state    directory                                           
  -----------------------------------------------------------------------------------------
  d90a17b  default virtualbox poweroff /home/centos/andrew-vpp/vppsb/vpp-userdemo          
  77b085e  default virtualbox poweroff /home/centos/andrew-vpp/vppsb2/vpp-userdemo         
  c1c8952  default virtualbox poweroff /home/centos/andrew-vpp/testingVPPSB/extras/vagrant 
  c199140  default virtualbox running  /home/centos/andrew-vpp/vppsb3/vpp-userdemo 

  You will have only one machine running, but I have multiple as shown above.

.. note::

  To poweroff your VM, type:

  .. code-block:: shell

     $ vagrant halt <id>

  To resume your VM, type:

  .. code-block:: shell

     $ vagrant resume <id>
     
  To destroy your VM, type:

  .. code-block:: shell

     $ vagrant destroy <id>

  Note that "destroying" a VM does not erase the box, but rather destroys all resources allocated for that VM. For other Vagrant commands, such as destroying a box, refer to the `Vagrant CLI Page <https://www.vagrantup.com/docs/cli/>`_.
pan class="p">], sw_if_index, ~0); l3xc_db[fproto][sw_if_index] = ~0; } static void l3xc_stack (l3xc_t * l3xc) { /* * stack the DPO on the forwarding contributed by the path-list */ dpo_id_t via_dpo = DPO_INVALID; fib_path_list_contribute_forwarding (l3xc->l3xc_pl, (FIB_PROTOCOL_IP4 == l3xc->l3xc_proto ? FIB_FORW_CHAIN_TYPE_UNICAST_IP4 : FIB_FORW_CHAIN_TYPE_UNICAST_IP6), FIB_PATH_LIST_FWD_FLAG_NONE, &via_dpo); dpo_stack_from_node ((FIB_PROTOCOL_IP4 == l3xc->l3xc_proto ? l3xc_ip4_node.index : l3xc_ip6_node.index), &l3xc->l3xc_dpo, &via_dpo); dpo_reset (&via_dpo); } int l3xc_update (u32 sw_if_index, u8 is_ip6, const fib_route_path_t * rpaths) { fib_protocol_t fproto; l3xc_t *l3xc; u32 l3xci; fproto = (is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); l3xci = l3xc_find (sw_if_index, fproto); if (INDEX_INVALID == l3xci) { /* * create a new x-connect */ pool_get_aligned_zero (l3xc_pool, l3xc, CLIB_CACHE_LINE_BYTES); l3xci = l3xc - l3xc_pool; fib_node_init (&l3xc->l3xc_node, l3xc_fib_node_type); l3xc->l3xc_sw_if_index = sw_if_index; l3xc->l3xc_proto = fproto; /* * create and become a child of a path list so we get poked when * the forwarding changes and stack on the DPO the path-list provides */ l3xc->l3xc_pl = fib_path_list_create ((FIB_PATH_LIST_FLAG_SHARED | FIB_PATH_LIST_FLAG_NO_URPF), rpaths); l3xc->l3xc_sibling = fib_path_list_child_add (l3xc->l3xc_pl, l3xc_fib_node_type, l3xci); l3xc_stack (l3xc); /* * add this new policy to the DB and enable the feature on input interface */ l3xc_db_add (sw_if_index, fproto, l3xci); vnet_feature_enable_disable ((FIB_PROTOCOL_IP4 == fproto ? "ip4-unicast" : "ip6-unicast"), (FIB_PROTOCOL_IP4 == fproto ? "l3xc-input-ip4" : "l3xc-input-ip6"), l3xc->l3xc_sw_if_index, 1, &l3xci, sizeof (l3xci)); } else { /* * update an existing x-connect. * - add the path to the path-list and swap our ancestry */ l3xc = l3xc_get (l3xci); if (FIB_NODE_INDEX_INVALID != l3xc->l3xc_pl) { fib_path_list_child_remove (l3xc->l3xc_pl, l3xc->l3xc_sibling); } l3xc->l3xc_pl = fib_path_list_create ((FIB_PATH_LIST_FLAG_SHARED | FIB_PATH_LIST_FLAG_NO_URPF), rpaths); l3xc->l3xc_sibling = fib_path_list_child_add (l3xc->l3xc_pl, l3xc_fib_node_type, l3xci); } return (0); } int l3xc_delete (u32 sw_if_index, u8 is_ip6) { fib_protocol_t fproto; l3xc_t *l3xc; u32 l3xci; fproto = (is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); l3xci = l3xc_find (sw_if_index, fproto); if (INDEX_INVALID == l3xci) { /* * no such policy */ return (VNET_API_ERROR_INVALID_VALUE); } else { l3xc = l3xc_get (l3xci); vnet_feature_enable_disable ((FIB_PROTOCOL_IP4 == fproto ? "ip4-unicast" : "ip6-unicast"), (FIB_PROTOCOL_IP4 == fproto ? "l3xc-input-ip4" : "l3xc-input-ip6"), l3xc->l3xc_sw_if_index, 0, &l3xci, sizeof (l3xci)); fib_path_list_child_remove (l3xc->l3xc_pl, l3xc->l3xc_sibling); l3xc_db_remove (l3xc->l3xc_sw_if_index, fproto); pool_put (l3xc_pool, l3xc); } return (0); } static clib_error_t * l3xc_cmd (vlib_main_t * vm, unformat_input_t * main_input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; fib_route_path_t *rpaths = NULL, rpath; u32 sw_if_index, is_del, is_ip6; dpo_proto_t payload_proto; vnet_main_t *vnm; int rv = 0; is_ip6 = is_del = 0; sw_if_index = ~0; vnm = vnet_get_main (); /* Get a line of input. */ if (!unformat_user (main_input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) ; else if (unformat (line_input, "ip6")) is_ip6 = 1; else if (unformat (line_input, "ip4")) is_ip6 = 0; else if (unformat (line_input, "del")) is_del = 1; else if (unformat (line_input, "add")) is_del = 0; else if (unformat (line_input, "via %U", unformat_fib_route_path, &rpath, &payload_proto)) vec_add1 (rpaths, rpath); else return (clib_error_return (0, "unknown input '%U'", format_unformat_error, line_input)); } if (~0 == sw_if_index) { vlib_cli_output (vm, "Specify an input interface"); goto out; } if (vec_len (rpaths) == 0) { vlib_cli_output (vm, "Specify some paths"); goto out; } if (!is_del) { rv = l3xc_update (sw_if_index, is_ip6, rpaths); if (rv) { vlib_cli_output (vm, "Failed: %d", rv); goto out; } } else { l3xc_delete (sw_if_index, is_ip6); } out: unformat_free (line_input); return (NULL); } /* *INDENT-OFF* */ /** * Create an L3XC policy. */ VLIB_CLI_COMMAND (l3xc_cmd_node, static) = { .path = "l3xc", .function = l3xc_cmd, .short_help = "l3xc [add|del] <INTERFACE> via ...", .is_mp_safe = 1, }; /* *INDENT-ON* */ static u8 * format_l3xc (u8 * s, va_list * args) { l3xc_t *l3xc = va_arg (*args, l3xc_t *); vnet_main_t *vnm = vnet_get_main (); s = format (s, "l3xc:[%d]: %U", l3xc - l3xc_pool, format_vnet_sw_if_index_name, vnm, l3xc->l3xc_sw_if_index); s = format (s, "\n"); if (FIB_NODE_INDEX_INVALID == l3xc->l3xc_pl) { s = format (s, "no forwarding"); } else { s = fib_path_list_format (l3xc->l3xc_pl, s); s = format (s, "\n %U", format_dpo_id, &l3xc->l3xc_dpo, 4); } return (s); } void l3xc_walk (l3xc_walk_cb_t cb, void *ctx) { u32 l3xci; /* *INDENT-OFF* */ pool_foreach_index(l3xci, l3xc_pool, ({ if (!cb(l3xci, ctx)) break; })); /* *INDENT-ON* */ } static clib_error_t * l3xc_show_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { l3xc_t *l3xc; /* *INDENT-OFF* */ pool_foreach(l3xc, l3xc_pool, ({ vlib_cli_output(vm, "%U", format_l3xc, l3xc); })); /* *INDENT-ON* */ return (NULL); } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (l3xc_show_cmd_node, static) = { .path = "show l3xc", .function = l3xc_show_cmd, .short_help = "show l3xc", .is_mp_safe = 1, }; /* *INDENT-ON* */ static fib_node_t * l3xc_get_node (fib_node_index_t index) { l3xc_t *l3xc = l3xc_get (index); return (&(l3xc->l3xc_node)); } static l3xc_t * l3xc_get_from_node (fib_node_t * node) { return ((l3xc_t *) (((char *) node) - STRUCT_OFFSET_OF (l3xc_t, l3xc_node))); } static void l3xc_last_lock_gone (fib_node_t * node) { } /* * A back walk has reached this L3XC policy */ static fib_node_back_walk_rc_t l3xc_back_walk_notify (fib_node_t * node, fib_node_back_walk_ctx_t * ctx) { l3xc_stack (l3xc_get_from_node (node)); return (FIB_NODE_BACK_WALK_CONTINUE); } /* * The BIER fmask's graph node virtual function table */ static const fib_node_vft_t l3xc_vft = { .fnv_get = l3xc_get_node, .fnv_last_lock = l3xc_last_lock_gone, .fnv_back_walk = l3xc_back_walk_notify, }; static clib_error_t * l3xc_init (vlib_main_t * vm) { l3xc_fib_node_type = fib_node_register_new_type (&l3xc_vft); return (NULL); } VLIB_INIT_FUNCTION (l3xc_init); /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */