First, follow the setup instructions in INSTALL.Linux to get a working
Open vSwitch installation.
KVM uses tunctl to handle various bridging modes, which you can
install with the Debian/Ubuntu package uml-utilities.
% apt-get install uml-utilities
Next, you will need to modify or create custom versions of the qemu-ifup
and qemu-ifdown scripts. In this guide, we'll create custom versions
that make use of example open vSwitch bridges that we'll describe in this
guide.
Create the following two files and store them in known locations.
For example /etc/ovs-ifup and /etc/ovs-ifdown
/etc/ovs-ifup
--------------------------------------------------------------------
#!/bin/sh
switch='br0'
/sbin/ifconfig $1 0.0.0.0 up
ovs-vsctl add-port ${switch} $1
--------------------------------------------------------------------
/etc/ovs-ifdown
--------------------------------------------------------------------
#!/bin/sh
switch='br0'
/sbin/ifconfig $1 0.0.0.0 down
ovs-vsctl del-port ${switch} $1
--------------------------------------------------------------------
At the end of INSTALL.Linux, it describes basic usage of creating
bridges and ports. If you haven't already, create a bridge named
br0 with the following command:
% ovs-vsctl add-br br0
Then, add a port to the bridge for the NIC that you want your guests
to communicate over (e.g. eth0):
% ovs-vsctl add-port br0 eth0
Please refer to ovs-vsctl(8) for more details.
Next, we'll start a guest that will use our ifup and ifdown scripts.
% kvm -m 512 -net nic,macaddr=00:11:22:EE:EE:EE -net \
tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -drive \
file=/path/to/disk-p_w_picpath,boot=on
This will start the guest and associate a tap device with it. The
ovs-ifup script will add a port on the br0 bridge so that the
guest will be able to communicate over that bridge.
To get some more information and for debugging you can use Open
vSwitch utilities such as ovs-dpctl and ovs-ofctl, For example:
% ovs-dpctl show br0
% ovs-ofctl show br0
You should see tap devices for each KVM guest added as ports to
the bridge (e.g. tap0)
---------------------------------
|
ovs−vsctl add−br br0 |
Alternatively, perform both operations in a single atomic transaction: |
ovs−vsctl add−br br0 −− add−port br0 eth0 |
Delete bridge br0, reporting an error if it does not exist: |
ovs−vsctl del−br br0 |
Delete bridge br0 if it exists (the −− is required to separate del−br’s options from the global options): |
ovs−vsctl −− −−if−exists del−br br0 |
Set the qos column of the Port record for eth0 to point to a new QoS record, which in turn points with its queue 0 to a new Queue record: |
ovs−vsctl −− set port eth0 qos=@newqos −− −−id=@newqos create qos type=linux−htb other−config:max−rate=1000000 queues:0=@newqueue −− −−id=@newqueue create queue other−config:min−rate=1000000 other−config:max−rate=1000000 |
CONFIGURATION COOKBOOK
Port Configuration |
Add an ‘‘internal port’’ vlan10 to bridge br0 as a VLAN access port for VLAN 10, and configure it with an IP address: |
ovs−vsctl add−port br0 vlan10 tag=10 −− set Interface vlan10 type=internal ifconfig vlan10 192.168.0.123 |
Add a GRE tunnel port gre0 to remote IP address 1.2.3.4 to bridge br0: |
ovs−vsctl add−port br0 gre0 −− set Interface gre0 type=gre options:remote_ip=1.2.3.4 |
Port Mirroring |
Mirror all packets received or sent on eth0 or eth1 onto eth2, assuming that all of those ports exist on bridge br0 (as a side-effect this causes any packets received on eth2 to be ignored): |
ovs−vsctl −− set Bridge br0 mirrors=@m \ −− −−id=@eth0 get Port eth0 \ −− −−id=@eth1 get Port eth1 \ −− −−id=@eth2 get Port eth2 \ −− −−id=@m create Mirror name=mymirror select-dst-port=@eth0,@eth1 select-src-port=@eth0,@eth1 output-port=@eth2 |
Remove the mirror created above from br0, which also destroys the Mirror record (since it is now unreferenced): |
remove Bridge br0 mirrors mymirror |
Quality of Service (QoS) |
Create a linux−htb QoS record that points to a few queues and use it on eth0 and eth1: |
ovs−vsctl −− set Port eth0 qos=@newqos \ −− set Port eth1 qos=@newqos \ −− −−id=@newqos create QoS type=linux−htb other−config:max−rate=1000000000 queues=0=@q0,1=@q1 \ −− −−id=@q0 create Queue other−config:min−rate=100000000 other−config:max−rate=100000000 \ −− −−id=@q1 create Queue other−config:min−rate=500000000 |
Deconfigure the QoS record above from eth1 only: |
ovs−vsctl clear Port eth1 qos |
To deconfigure the QoS record from both eth0 and eth1 and then delete the QoS record (which must be done explicitly because unreferenced QoS records are not automatically destroyed): |
ovs−vsctl −− destroy QoS eth0 −− clear Port eth0 qos −− clear Port eth1 qos |
(This command will leave two unreferenced Queue records in the database. To delete them, use "ovs−vsctl list Queue" to find their UUIDs, then "ovs−vsctl destroy Queue uuid1 uuid2" to destroy each of them or use "ovs−vsctl -- --all destroy Queue" to delete all records.) |
Connectivity Monitoring |
Monitor connectivity to a remote maintenance point on eth0. |
ovs−vsctl set Interface eth0 cfm_mpid=1 |
Deconfigure connectivity monitoring from above: |
ovs−vsctl clear Interface eth0 cfm_mpid |
NetFlow |
Configure bridge br0 to send NetFlow records to UDP port 5566 on host 192.168.0.34, with an active timeout of 30 seconds: |
ovs−vsctl −− set Bridge br0 netflow=@nf \ −− −−id=@nf create NetFlow targets=\"192.168.0.34:5566\" active−timeout=30 |
Update the NetFlow configuration created by the previous command to instead use an active timeout of 60 seconds: |
ovs−vsctl set NetFlow br0 active_timeout=60 |
Deconfigure the NetFlow settings from br0, which also destroys the NetFlow record (since it is now unreferenced): |
ovs−vsctl clear Bridge br0 netflow |
sFlow |
Configure bridge br0 to send sFlow records to a collector on 10.0.0.1 at port 6343, using eth1´s IP address as the source, with specific sampling parameters: |
ovs−vsctl −− −−id=@s create sFlow agent=eth1 target=\"10.0.0.1:6343\" header=128 sampling=64 polling=10 \ −− set Bridge br0 sflow=@s |
Deconfigure sFlow from br0, which also destroys the sFlow record (since it is now unreferenced): |
ovs−vsctl −− clear Bridge br0 sflow |
802.1D Spanning Tree Protocol (STP) |
Configure bridge br0 to participate in an 802.1D spanning tree: |
ovs−vsctl set Bridge br0 stp_enable=true |
Set the bridge priority of br0 to 0x7800: |
ovs−vsctl set Bridge br0 other_config:stp-priority=0x7800 |
Set the path cost of port eth0 to 10: |
ovs−vsctl set Port eth0 other_config:stp-path-cost=10 |
Deconfigure STP from above: |
ovs−vsctl clear Bridge br0 stp_enable |
转载于:https://blog.51cto.com/jxwpx/876022