| Patrick Williams | d849ec7 | 2016-08-17 14:59:38 -0500 | [diff] [blame] | 1 | Simple setup for connecting openvswitch to qemu/kvm | 
|  | 2 | =================================================== | 
|  | 3 | This example brings up openvswitch using a private network. | 
|  | 4 |  | 
|  | 5 | Preliminary notes | 
|  | 6 | ================= | 
|  | 7 | 1. Make sure to build kernel support for openvswitch as a module.  The | 
|  | 8 | openvswitch init scripts expect to load a module and upon success | 
|  | 9 | continue to setup the switch.  If openvswitch is compiled | 
|  | 10 | statically, the init scripts not load the ovs-vswitchd daemon | 
|  | 11 | and none of the configured bridges will show up in the interfaces | 
|  | 12 | table (ifconfig).  You can get around this limiation by running the | 
|  | 13 | following by hand: | 
|  | 14 | # ovs-vswitchd --pidfile --detach | 
|  | 15 |  | 
|  | 16 | 2. Verify that ovs-vswitchd is running before proceeding: | 
|  | 17 | # /etc/init.d/openvswitch-switch status | 
|  | 18 | ovsdb-server is running with pid 1867 | 
|  | 19 | ovs-vswitchd is running with pid 1877 | 
|  | 20 |  | 
|  | 21 | 3. A kernel and rootfs is required for qemu bring up. | 
|  | 22 |  | 
|  | 23 | Qemu Setup | 
|  | 24 | ========== | 
|  | 25 | The host requires a /etc/qemu-ifup script to setup the bridging and tap | 
|  | 26 | devices.  Qemu will invoke this qemu-ifup script at startup.  Here is | 
|  | 27 | an example script: | 
|  | 28 | $ cat /etc/qemu-fup | 
|  | 29 | #!/bin/sh | 
|  | 30 | # the tap is dynamically assigned and passed into this script | 
|  | 31 | # as a parameter | 
|  | 32 | TAP=$1 | 
|  | 33 |  | 
|  | 34 | # Note: if booting over NFS, once the $ETH0 device is added to the bridge, | 
|  | 35 | # your host will be unusable.  In that case, setup networking | 
|  | 36 | # init scripts appropriately and change the following to work | 
|  | 37 | # with it. | 
|  | 38 | ETH0="eth1" | 
|  | 39 | NETMASK=255.255.255.0 | 
|  | 40 | IP=192.168.1.1 | 
|  | 41 | GATEWAY= | 
|  | 42 | SWITCH=ovsbr0 | 
|  | 43 | if [ -n "$TAP" ];then | 
|  | 44 | ifconfig $TAP up | 
|  | 45 | ifconfig $SWITCH down &>/dev/null | 
|  | 46 | ovs-vsctl del-br $SWITCH | 
|  | 47 | ovs-vsctl add-br $SWITCH | 
|  | 48 | ifconfig $ETH0 0.0.0.0 | 
|  | 49 | ifconfig $SWITCH $IP up netmask $NETMASK | 
|  | 50 | #-- external access not required for this test. | 
|  | 51 | #route add default gw $GATEWAY | 
|  | 52 | ovs-vsctl add-port $SWITCH $ETH0 | 
|  | 53 | ovs-vsctl add-port $SWITCH $TAP | 
|  | 54 | exit 0 | 
|  | 55 | else | 
|  | 56 | echo "$0: No tap device" | 
|  | 57 | exit 1 | 
|  | 58 | fi | 
|  | 59 |  | 
|  | 60 | Start Qemu | 
|  | 61 | ========== | 
|  | 62 | This example will bring up qemu with a tap network interface. | 
|  | 63 | Note: this command must be run as root due to the networking setup. | 
|  | 64 |  | 
|  | 65 | $ qemu-system-x86_64 -nographic -k en-us -m 1024  \ | 
|  | 66 | -net nic,macaddr=1a:46:0b:ca:bc:7a,model=virtio \ | 
|  | 67 | -net tap -enable-kvm\ | 
|  | 68 | -kernel /opt/dpdk-guest-kernel \ | 
|  | 69 | -append 'root=/dev/vda ro console=ttyS0' \ | 
|  | 70 | -drive file=/opt/intel-xeon-core-ovp-kvm-preempt-rt-dist.ext3,cache=none,if=virtio | 
|  | 71 |  | 
|  | 72 | Once the guest OS is up and running, configure the quest network interface: | 
|  | 73 | $ ifconfig eth0 192.168.1.10 | 
|  | 74 |  | 
|  | 75 | Ping the bridge: | 
|  | 76 | $ ping 192.168.1.1 | 
|  | 77 |  | 
|  | 78 | From the host, view the bridged network: | 
|  | 79 | $ ovs-vsctl show | 
|  | 80 | c1212b96-ef49-4a8e-b598-09b05b854dd0 | 
|  | 81 | Bridge "ovsbr0" | 
|  | 82 | Port "tap0" | 
|  | 83 | Interface "tap0" | 
|  | 84 | Port "eth1" | 
|  | 85 | Interface "eth1" | 
|  | 86 | Port "ovsbr0" | 
|  | 87 | Interface "ovsbr0" | 
|  | 88 | type: internal | 
|  | 89 |  | 
|  | 90 | At this point, openvswitch is up and running.  If you want external | 
|  | 91 | network access, you need to set a GATEWAY in the qemu-ifup script and | 
|  | 92 | make sure the external device is part of the bridge. | 
|  | 93 |  | 
|  | 94 | Note: | 
|  | 95 | Proper setup will require a /etc/qemu-ifdown script to tear down the | 
|  | 96 | bridge and interfaces. (not provided here). |