VDE - Virtual Distributed Ethernet

Kvm、VMware、Virtualbox、Xen、Qemu 等
回复
tdls
帖子: 4
注册时间: 2011-05-11 17:42

VDE - Virtual Distributed Ethernet

#1

帖子 tdls » 2012-10-10 15:58

VDE - Virtual Distributed Ethernet

官网:
http://vde.sourceforge.net/

VDE - 虚拟以太网,是一个以太网兼容的虚拟网络

文档:
http://wiki.virtualsquare.org/wiki/index.php/VDE

主要特点:
支持VLAN、Fast Spanning Tree Protocol、Command line management

当启动vde_switch,有几个自定义选项:
端口数、工作模式、交换机的MAC地址、配置文件、管理接口的权限、数据接口的权限、tap接口

使用范例:

默认选项

$vde_switch
vde:

默认工作目录为 /tmp/vde.ctl,默认应用模式是2700,按回车键进入vde_switch命令管理介面。

vde$

常用管理命令:

vde$ help

0000 DATA END WITH '.'
COMMAND PATH SYNTAX HELP
------------ -------------- ------------
ds ============ DATA SOCKET MENU
ds/showinfo show ds info
help [arg] Help (limited to arg when specified)
logout logout from this mgmt terminal
shutdown shutdown of the switch
showinfo show switch version and info
load path load a configuration script
debug ============ DEBUG MENU
debug/list list debug categories
debug/add dbgpath enable debug info for a given category
debug/del dbgpath disable debug info for a given category
plugin ============ PLUGINS MENU
plugin/list list plugins
plugin/add library load a plugin
plugin/del name unload a plugin
hash ============ HASH TABLE MENU
hash/showinfo show hash info
hash/setsize N change hash size
hash/setgcint N change garbage collector interval
hash/setexpire N change hash entries expire time
hash/setminper N minimum persistence time
hash/print print the hash table
hash/find MAC [VLAN] MAC lookup
fstp ============ FAST SPANNING TREE MENU
fstp/showinfo show fstp info
fstp/setfstp 0/1 Fast spanning tree protocol 1=ON 0=OFF
fstp/setedge VLAN PORT 1/0 Define an edge port for a vlan 1=Y 0=N
fstp/bonus VLAN PORT COST set the port bonus for a vlan
fstp/print [N] print fst data for the defined vlan
port ============ PORT STATUS MENU
port/showinfo show port info
port/setnumports N set the number of ports
port/sethub 0/1 1=HUB 0=switch
port/setvlan N VLAN set port VLAN (untagged)
port/create N create the port N (inactive|notallocatable)
port/remove N remove the port N
port/allocatable N 0/1 Is the port allocatable as unnamed? 1=Y 0=N
port/setuser N user access control: set user
port/setgroup N user access control: set group
port/epclose N ID remove the endpoint port N/id ID
port/resetcounter [N] reset the port (N) counters
port/print [N] print the port/endpoint table
port/allprint [N] print the port/endpoint table (including inactive port)
vlan ============ VLAN MANAGEMENT MENU
vlan/create N create the VLAN with tag N
vlan/remove N remove the VLAN with tag N
vlan/addport N PORT add port to the vlan N (tagged)
vlan/delport N PORT add port to the vlan N (tagged)
vlan/print [N] print the list of defined vlan
vlan/allprint [N] print the list of defined vlan (including inactive port)
.

Customizing daemon/定义守护进程

$ vde_switch --daemon --sock /tmp/myvde.ctl --mgmt /tmp/myvde.mgmt

现在可以通过unix socket /tmp/myvde.mgmt 连接管理虚拟交换机

$ vdeterm /tmp/myvde.mgmt

------------------------------------------
VDE switch V.2.3.1
(C) Virtual Square Team (coord. R. Davoli) 2005,2006,2007 - GPLv2

vde[/tmp/muvde.mgmt]:

--------------------------------------------

vde的socket是标准的PF_FILE stream socket;所以很容易找到其它的应用程序,如socat:

$ socat READLINE unix:/tmp/muvde.mgmt

-----------------------------------------------------
VDE switch V.2.3.1
(C) Virtual Square Team (coord. R. Davoli) 2005,2006,2007 - GPLv2

vde$

--------------------------------------------------------

连接tap接口

# tunctl -u username -t tap0
# ifconfig tap0 192.168.0.1 netmask 255.255.255.0

转用户

$ vde_switch --tap tap0

vde: port/allprint
0000 DATA END WITH '.'
Port 0001 untagged_vlan=0000 ACTIVE - Unnamed Allocatable
-- endpoint ID 0006 module tuntap : tap0

-------------------------------------------------------------

dpipe

可以连接两个vde_plug,dpipe也被称为双向的管道,能够运行两个或多个命令的第一个命令的标准输出转移到第二个命令的标准输入,反之亦然。

$ dpipe vde_plug /tmp/vde1.ctl = vde_plug /tmp/vde2.ctl
这个例子,连接两个vde_switches

$ dpipe vde_plug /tmp/vde.ctl = ssh foo@remote.host.org vde_plug /tmp/vde_remote.ctl
这个例子,本地的vde_switch连接到远程vde_switch并使用了安全ssh通道

$ dpipe vde_plug /tmp/vde.ctl = nc -l -u -p 8000
这个例子,vde_switch通过netcat监听UDP端口8000,数据未作加密

$ dpipe vde_plug /tmp/vde_local.ctl = nc -u 8000 remove.host.address.org
这个例子,本地vde_switch通过netcat客户端连接到远程机器

vde_cryptcab

$ vde_cryptcab -s /tmp/vde.ctl -p 12000
开启vde_cryptcab服务监听UDP 12000端口

$ vde_cryptcab -s /tmp/vde_local.ctl -c username@remote.host.org:12000
开启vde_cryptcab,通过ssh认证连接到远程UDP 12000端口

wirefilter

用于测试的一个工具,模拟真实网络的连接问题,如:延时、丢包等;此工具可插入一个双向管道在两个vde_switches间引入虚拟错误长限制。

wirefilter参数:
丢包百分比
数据包的传输延迟
数据包重复的百分比
信道带宽
接口速度
数据包队列的最大容量
最大传输单元
每兆字节损坏的位
包的排序

$ dpipe vde_plug /tmp/vde1.ctl = wirefilter -M /tmp/wiremgmt = vde_plug /tmp/vde2.ctl
这个例子,wirefilter是个双向的管道,连接在两个vde_switches之间。这有可能从左向右或从右向左过滤,可以通过wirefilter指定的socket连接管理wirefilter:

$ vdeterm /tmp/wiremgmt

--------------------------------------------------------
VDE wirefilter V.2.3.1
(C) R.Davoli 2005,2006 - GPLv2

VDEwf[/tmp/wiremgmt]:help

COMMAND HELP
------------ ------------
help print a summary of mgmt commands
load load a configuration file
showinfo show status and parameter values
loss set loss percentage
lostburst mean length of lost packet bursts
delay set delay ms
dup set dup packet percentage
bandwidth set channel bandwidth bytes/sec
speed set interface speed bytes/sec
noise set noise factor bits/Mbyte
mtu set channel MTU (bytes)
chanbufsize set channel buffer size (bytes)
fifo set channel fifoness
shutdown shut the channel down
logout log out from this mgmt session
...
Success

--------------------------------------------------------------

slirpvde

slirpvde是一个SLIRP的接口,它就像一台路由器连接到vde_switch,提供NAT、DHCP、DNS请求重新映射等。

$ slirpvde -d -s /tmp/vde.ctl -dhcp
启动slirpvde并指定连接vde_switch的socket提供外部网络访问,额外的-dhcp参数告诉slirpvde提供DHCP服务。

$ vdeterm /tmp/mgmt

-------------------------------------------------------------
...
vde[/tmp/mgmt]: port/print
0000 DATA END WITH '.'
Port 0001 untagged_vlan=0000 ACTIVE - Unnamed Allocatable
-- endpoint ID 0006 module tuntap : tap0
Port 0002 untagged_vlan=0000 ACTIVE - Unnamed Allocatable
-- endpoint ID 0007 module unix prog : vdeqemu user=render PID=14422 SOCK=/tmp/vde.14422-00000
Port 0003 untagged_vlan=0000 ACTIVE - Unnamed Allocatable
-- endpoint ID 0009 module unix prog : slirpvde: user=render PID=14554 SOCK=/tmp/vde.14554-00000
.
Success

----------------------------------------------------------------------

slirpvde6

slirpvde6是一个根据LWIPv6新实施slirpvde,同时支持IPv4和IPv6.

$ slirpvde6 -d -s /tmp/vde.ctl -dhcp
在这里,slirpvde6提供一个IPv4 SLIRP服务。的默认网关地址是10.0.2.1/24。 slirpvde6它的所有服务,如DNS转发器或DHCP服务器使用相同的接口。在交换机上的端口列表slirpvde6出现作为一个LWIPv6服务:

Port 0002 untagged_vlan=0000 ACTIVE - Unnamed Allocatable
Current User: renzo Access Control: (User: NONE - Group: NONE)
IN: pkts 482 bytes 141526
OUT: pkts 2893 bytes 189153
-- endpoint ID 0011 module unix prog : LWIPv6 if=vd0
user=renzo PID=5260 SOCK=/var/run/vde.ctl/.05260-00000

slirpvde6支持多个地址,用户可以指定IPv4和IPv6地址的任意组合:

$ slirpvde6 -d -H10.0.2.1/24 -H2001::1/64 -s /tmp/vde.ctl -dhcp -r

-r选项是启动的路由器守护进程自动配置

--------------------------------------------------------------------------------

debian常用vde2配置
/etc/network/interfaces

#开机启动tap0,连接到vde虚拟交换机tap0,设置IP地址,启动vde2-slirp提供NAT服务

auto tap0
iface tap0 inet static
address 172.16.10.254
netmask 255.255.255.0
vde2-switch -
vde2-slirp -n 172.16.10.0

#开机启动tap1,连接到vde虚拟交换机tap1,设置IP地址,启动vde2-slirp提供NAT、DHCP服务

auto tap1
iface tap1 inet static
address 172.16.100.254
netmask 255.255.255.0
vde2-switch -
vde2-slirp -n 172.16.100.0 -dhcp

#开机启动tap2,连接到vde虚拟交换机tap2,设置IP地址

auto tap2
iface tap2 inet static
address 172.16.20.254
netmask 255.255.255.0
vde2-switch -

------------------------------------------------------------------

#在kvm配置文件里加上下面的设置就可以连接VDE

#设置使用virtio网卡,设置MAC地址“52-55-00-12-01-01”
-net nic,model=virtio,macaddr=52-55-00-12-01-01 \
#连接VDE,sock的路径为/var/run/vde2/(默认位置),tap1.ctl对应VDE交换机的名称
-net vde,sock=/var/run/vde2/tap1.ctl
tdls
帖子: 4
注册时间: 2011-05-11 17:42

Re: VDE - Virtual Distributed Ethernet

#2

帖子 tdls » 2012-10-11 11:22

本人是个菜鸟,不会写高深的东西,只能 简单介绍VDE软件和KVM里简单应用
大侠的文章很棒,小弟读了很多。
回复