OVS组件
OVS包括三个重要组件:ovsdb-server、ovs-vswitchd、以及OVS内核模块。
- ovsdb-server:OVS用于记录网桥、端口、QOS为控制器和其他网络配置信息ovs-vswitchd提供OVSDB操作接口。
- ovs-vswitchd:OVS对控制器发布的所有流表进行保存和管理OVS内核模块提供流表查询功能和控制器OpenFlow协议的操作接口。
- OVS核心模块:缓存一些常用流表,并负责数据包的转发。当遇到不匹配的报纸时,模块将向前移动ovs-vswitchd发送pack-in请求,取得报文处理指令。
#ps -ef | grep ovs-vswitchd root 987 1 0 Jan24 ? 02:43:11 ovs-vswitchd unix:/var/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --no-chdir --log-file=/var/log/openvswitch/ovs-vswitchd.log --pidfile=/var/run/openvswitch/ovs-vswitchd.pid --detach
ovs-vswitchd监听本机db.sock文件,这个socket就是openvswitch的ovsdb的链接,ovs-vswitchd通过这个socket写下配置信息ovsdb
默认数据库:Open_vSwitch 默认db路径:/etc/openvswitch/conf.db 默认schema:/usr/share/openvswitch/vswitch.ovsschema 默认socket:/var/run/openvswitch/db.sock ovs-vsctl add-br br-int ovs-vsctl add-port ovs-veth10
1、Insert:插入,无任何相关项
ovsdb-client transact '["Open_vSwitch",{"op":"insert","table":"xxx","row":{"name":"xxx","value":"xxx"}}]'
2、Selsect:根据where条件筛选
ovsdb-client transact '["Open_vSwitch",{"op":"select","table":"xxx","where":[["name","==","xxx"]]}]'
3、Update:更新表项
ovsdb-client transact '["Open_vSwitch",{"op":"update","table":"xxx","where":[["name","==","xxx"]],"row":{'name':"xxx"}}]'
4、Delete:删除表项
ovsdb-client transact '["Open_vSwitch",{"op":"delete","table":"xxx","where":[["name","==","xxx"]]}]'
5、Mutate:联合操作在table1里insert数据,where里找到关联table2的元素,uuid-name和set保持一致,mutations第一个参数是table2的column在table1里作为uuid
ovsdb-client transact '["Open_vSwitch",{"op":"insert","table":"xxx1","row":{'name':"xxx"},"uuid-name":"abc"},{"op":"mutate","table":"xxx2","where":[["name","==","xxx"]],"mutations":[["name","insert",["set",[["named-uuid","abc"]]]]]}]'
查看ovsdb里对ovs可以看到的操作Open_vSwitch在表中添加记录,Bridge表中添加一个记录,Port增加两个记录
ovsdb-tool show-log -m record 0: "Open_vSwitch" schema, version="8.2.0", cksum="xxx" record 1: 2022-07-11 06:42:10.679 "compacting database online" table Interface insert row "ovs-veth10" (92dee19b): table Port insert row "br-int" (ccfd1042): table Port insert row "ovs-veth10" (751976fd): table Bridge insert row "br-int" (64043d26): table Open_vSwitch insert row 097bf88c: 列出ovsdb所有数据库,默认是Open_vSwitch ovsdb-client list-dbs Open_vSwitch 列出ovsdb里的所有table ovsdb-client list-tables Open_vSwitch Table Controller Bridge Queue IPFIX NetFlow Open_vSwitch CT_Zone QoS Datapath SSL Port sFlow Flow_Sample_Collector_Set CT_Timeout_Policy Mirror Flow_Table Interface AutoAttach Manager
查看Open_vSwitch表新内容,bridges网桥将不断更新id,同时会记录cur_cfg和next_cfg
ovsdb-client dump Open_vSwitch Open_vSwitch Open_vSwitch table _uuid bridges cur_cfg datapath_types datapaths db_version dpdk_initialized dpdk_version external_ids iface_types manager_options next_cfg other_config ovs_version ssl statistics system_type system_version
--------------------------------------------------------------------------------
097bf88c-b5c3-4e62-b795-51ea0f0c0053 [64043d26-8311-4a68-837a-f58b6bd3293c] 183 [netdev, system] {
} "8.2.0" false none {
hostname=ubuntu, rundir="/var/run/openvswitch", system-id="e73b1ede-9e48-4412-9665-c0f998fec762"} [erspan, geneve, gre, internal, ip6erspan, ip6gre, lisp, patch, stt, system, tap, vxlan] [] 183 {
} "2.13.3" [] {
} ubuntu "20.04"
查看数据库Open_vSwitch中Bridge表内容,看到一个br-int网桥
ovsdb-client dump Open_vSwitch Bridge
Bridge table
_uuid auto_attach controller datapath_id datapath_type datapath_version external_ids fail_mode flood_vlans flow_tables ipfix mcast_snooping_enable mirrors name netflow other_config ports protocols rstp_enable rstp_status sflow status stp_enable
--------------------------------------------------------------------------------
64043d26-8311-4a68-837a-f58b6bd3293c [] [] "0000263d0464684a" "" "<unknown>" {
} [] [] {
} [] false [] br-int [] {
} [28e2a8cf-5bad-43c1-a6e9-b6bb635295bb, 751976fd-0cec-42bc-ada2-cf7bee05453d, 9f4d9f67-5b0e-4cbd-ba8b-9386dcbf3c65, c0e09899-3197-4763-9bf0-a1de941f0d32, ccfd1042-55f4-4af6-9bc7-49ddb29c09de] [] false {
} [] {
} false
查看数据库Open_vSwitch中Port表内容,看到一个网桥同名接口br-int和自建接口ovs-veth10,每个port都关联一个interface
ovsdb-client dump Open_vSwitch Port
Port table
_uuid bond_active_slave bond_downdelay bond_fake_iface bond_mode bond_updelay cvlans external_ids fake_bridge interfaces lacp mac name other_config protected qos rstp_statistics rstp_status statistics status tag trunks vlan_mode
--------------------------------------------------------------------------------
ccfd1042-55f4-4af6-9bc7-49ddb29c09de [] 0 false [] 0 [] {
} false [58c5bd1a-6165-46d5-bd74-b5879874ed28] [] [] br-int {
} false [] {
} {
} {
} {
} [] [] []
751976fd-0cec-42bc-ada2-cf7bee05453d [] 0 false [] 0 [] {
} false [92dee19b-7042-4ec4-81eb-2b8f10095c5c] [] [] ovs-veth10 {
} false [] {
} {
} {
} {
} [] [] []
监控数据库Open_vSwitch中Port表变动
ovsdb-client monitor Open_vSwitch Port
查看数据库Open_vSwitch中Interface表内容,看到port关联的interface里对应的ofport就是网桥的编号
ovsdb-client dump Open_vSwitch Interface
Interface table
_uuid admin_state bfd bfd_status cfm_fault cfm_fault_status cfm_flap_count cfm_health cfm_mpid cfm_remote_mpids cfm_remote_opstate duplex error external_ids ifindex ingress_policing_burst ingress_policing_rate lacp_current link_resets link_speed link_state lldp mac mac_in_use mtu mtu_request name ofport ofport_request options other_config statistics status type
--------------------------------------------------------------------------------
58c5bd1a-6165-46d5-bd74-b5879874ed28 down {
} {
} [] [] [] [] [] [] [] [] [] {
} 137 0 0 [] 0 [] down {
} [] "26:3d:04:64:68:4a" 1500 [] br-int 65534 [] {
} {
} {
collisions=0, rx_bytes=0, rx_crc_err=0, rx_dropped=66459, rx_errors=0, rx_frame_err=0, rx_missed_errors=0, rx_over_err=0, rx_packets=0, tx_bytes=0, tx_dropped=0, tx_errors=0, tx_packets=0} {
driver_name=openvswitch} internal
92dee19b-7042-4ec4-81eb-2b8f10095c5c up {
} {
} [] [] [] [] [] [] [] full [] {
} 138 0 0 [] 1 10000000000 up {
} [] "f2:85:c5:5c:e2:8e" 1500 [] ovs-veth10 2 [] {
} {
} {
collisions=0, rx_bytes=57076, rx_crc_err=0, rx_dropped=0, rx_errors=0, rx_frame_err=0, rx_missed_errors=0, rx_over_err=0, rx_packets=722, tx_bytes=22453284, tx_dropped=0, tx_errors=0, tx_packets=66450} {
driver_name=veth, driver_version="1.0", firmware_version=""} ""
自建数据库
1、创建schema文件amber.schema
{
"name": "Amber",
"version": "1.0.1",
"cksum": "xxx",
"tables": {
"Information": {
"columns":{
"name": {
"type": {
"key": "string",
"max": 1,
"min": 0
}
},
"age": {
"type": {
"key": "integer",
"max": 1,
"min": 0
}
},
"number": {
"type": {
"key": {
"type": "string", "minLength": 17, "maxLength": 17}}}
},
"isRoot": true,
"maxRows": 1
},
"Score": {
"columns": {
"math":{
"type": {
"key": {
"type": "integer",
"max": 1,
"min": 1
}
},
"mutable": false
},
"chinese": {
"type": {
"key": {
"type": "integer",
"max": 1,
"min": 1
}
},
"mutable": false
},
"english": {
"type": "integer"
"max": 1,
"min": 1
},
"isRoot": true
},}
注意,名称值可选性说明“columns”{: , …}必选包含的表格的UUID、版本信息等“maxRows”可选表格的最大行数“isRoot”可选表格内是否存在强依赖关系“indexes”[*]可选用于标识表格列”type”必选列的类型“ephemeral”< boolean >可选数据是否持久化“mutable”可选数据是否可修改
2、创建ovsdb数据库:ovsdb-tool create amber.db amber.schema
3、启动ovsdb数据库:ovsdb-server -vconsole:off -vfile:info --log-file=/root/amberd.log --remote=punix:/var/run/amber/amberd.sock --pidfile=/var/run/amberd.pid --unixctl=/var/run/amberd.ctl --detach --monitor /root/sdn/platform/src/ctrlplane/ovsdb/amber.db
4、查看数据库Table时要指定socket
ovsdb-client list-tables unix:/var/run/amber/amberd.sock DP_Option
ovsdb-client dump unix:/var/run/amber/amberd.sock DP_Option DP_Option
ovsdb-client transact unix:/var/run/amber/amberd.sock '["DP_Option",{"op":"select","table":"DP_Option","where":[]}]'