找回密码
 注册
查看: 4306|回复: 3

ovs-ofctl dump-ports 输出交换机的端口统计信息,包括收发包、丢包、错误包等数量。

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2019-10-25 10:00:33 | 显示全部楼层 |阅读模式
ovs-ofctl dump-ports 输出交换机的端口统计信息,包括收发包、丢包、错误包等数量。 ovs-ofctl dump-flows alubr0  
" q* H6 n% s3 L6 L2 `$ m& lOFPST_FLOW reply (xid=0x2): flags=[more]$ D& Y6 I: x5 \! j4 N3 _1 }
cookie=0x1, duration=1263.439s, table=0, n_packets=572, n_bytes=27498, priority=1 actions=move:NXM_OF_VLAN_TCI[0..11]->NXM_NX_REG1[
% A+ Z- a  }& [& U( ^0..11],strip_vlan,resubmit(,22),resubmit(,23),move:NXM_OF_IN_PORT[]->NXM_NX_REG4[0..15],move:NXM_NX_REG1[0..15]->NXM_OF_IN_PORT[],re7 m  G; N5 b* m% ^
submit(,4)
# b3 Z+ y% m# J. e* K cookie=0x1, duration=1263.439s, table=4, n_packets=36175, n_bytes=26587191, priority=0 actions=resubmit(,27)2 C+ K8 R7 b0 ?, i1 z, ]5 I
cookie=0x1, duration=1263.439s, table=5, n_packets=35646, n_bytes=26564073, priority=0 actions=resubmit(,7)
! ~( F6 |5 a! l. ^7 |2 U cookie=0x1, duration=1193.636s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=18038,dl_src=fa:16:3e:83:4c:69 actions=drop, x+ D0 J/ w' D$ [
cookie=0x1, duration=1253.085s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=3575,dl_src=fa:16:3e:e8:53:ed actions=drop5 c1 a: @; U" \. L
cookie=0x1, duration=1190.175s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=291,dl_src=fa:16:3e:b2:1c:91 actions=drop. j! u% t. [0 Z: a+ N# |- c
cookie=0x1, duration=1176.930s, table=7, n_packets=522, n_bytes=21924, priority=32769,in_port=21588,dl_src=fa:16:3e:f7:f2:b0 action; q& s; e3 Z9 I* k7 F1 {2 Z) e. r
s=drop2 L' D: n$ c$ f
cookie=0x1, duration=1256.088s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=5670,dl_src=fa:16:3e:35:a6:e0 actions=drop
3 o6 X' G/ X) P# ^8 C cookie=0x1, duration=1197.461s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=29064,dl_src=fa:16:3e:82:2c:2c actions=drop8 ^1 J5 Z5 U: [" y4 y6 E5 W
cookie=0x1, duration=1196.999s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=249,dl_src=fa:16:3e:83:aa:df actions=drop
% f& Q& x/ ?4 } cookie=0x1, duration=1195.700s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=422,dl_src=fa:16:3e:c9:6d:72 actions=drop, V2 s/ A# z6 g& y. e3 k
cookie=0x1, duration=1198.286s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=19360,dl_src=fa:16:3e:95:46:90 actions=drop/ L; m( T& o; s7 {. \0 ?- ]6 p/ X
cookie=0x1, duration=1195.371s, table=7, n_packets=246, n_bytes=22388, priority=32769,in_port=440,dl_src=fa:16:3e:21:d3:7c actions=# P  V* ?' G8 Z+ m( T( u* t6 i2 g
drop# K/ ]# R" J  j' @! p) v: c
cookie=0x1, duration=1214.428s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=417,dl_src=fa:16:3e:ca:06:53 actions=drop
4 ], w- L( \( |/ `3 P/ ~! u cookie=0x1, duration=1207.443s, table=7, n_packets=22, n_bytes=3454, priority=32769,in_port=386,dl_src=fa:16:3e:34:aa:b7 actions=dr
' u- r  G9 c7 m  {$ U$ yop
1 q! O) E# Z8 e0 }3 c% d cookie=0x1, duration=1185.017s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=29117,dl_src=fa:16:3e:ec:aa:39 actions=drop# O9 x# I, @  c, J" L& @
cookie=0x1, duration=1204.103s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=15250,dl_src=fa:16:3e:d7:f6:f5 actions=drop( y7 L( Y/ ^* T3 w4 T7 U. N0 I+ z  O7 t
cookie=0x1, duration=1197.818s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=28265,dl_src=fa:16:3e:f4:c0:f1 actions=drop
) E4 f* G) X( l+ _, e2 Y cookie=0x1, duration=1185.573s, table=7, n_packets=283, n_bytes=28562, priority=32769,in_port=275,dl_src=fa:16:3e:ed:7d:60 actions=. F+ N2 b  X) V+ Z9 W3 _3 e/ K. w
drop
. \7 p# j! M6 Y: H1 J1 |0 O6 h) v  t1 l cookie=0x1, duration=1191.564s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=185,dl_src=fa:16:3e:55:06:7c actions=drop
& ?( b* k# F! T& v0 ~. ]! O* N cookie=0x1, duration=1210.767s, table=7, n_packets=8553, n_bytes=549905, priority=32769,in_port=526,dl_src=fa:16:3e:62:2a:1b action
" O, G( P1 K; Ms=drop
$ W* M! N5 l8 l/ d cookie=0x1, duration=1231.485s, table=7, n_packets=5, n_bytes=450, priority=32769,in_port=8163,dl_src=fa:16:3e:cd:48:42 actions=dro- [  a4 X1 D% W( `/ z: ]
p
4 M0 v( m- O5 L' r3 ?; I& V cookie=0x1, duration=1254.538s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=799,dl_src=fa:16:3e:da:fe:ec actions=drop# R! A/ J* e- P

  `  ^( j" V# s
7 I! q  A6 a9 L如果设为fail-secure mode,则初始情况下flow table是空的,否则会有normal$ sudo ovs-vsctl add-br helloworld1
. U) z! `& K8 a: l$ sudo ovs-ofctl show helloworld1
6 A* f' P0 t' `* u- q$ sudo ovs-ofctl dump-flows helloworld1 ) V/ `9 u/ J' x( p- Q( {8 J
NXST_FLOW reply (xid=0x4):   W# @5 I7 P/ \* n% x1 m3 V- u
cookie=0x0, duration=31.467s, table=0, n_packets=8, n_bytes=648, idle_age=21, priority=0 actions=NORMAL接下来,创建四个veth pairsudo ip link add first_br type veth peer name first_if
/ p3 n9 v+ `: Ssudo ip link add second_br type veth peer name second_if   
' u7 j+ G6 m" ]2 Z* W9 P4 |sudo ip link add third_br type veth peer name third_if      
0 k( Z& \. o7 y3 Z3 ]sudo ip link add forth_br type veth peer name forth_ifxxx_br将是添加到bridge上的。我们添加四个端口portsudo ovs-vsctl add-port helloworld first_br -- set Interface first_br ofport_request=1 # r$ U" t1 O; O" s$ C/ V: S; P
sudo ovs-vsctl add-port helloworld second_br -- set Interface second_br ofport_request=2
3 |' v$ [5 T* |+ Q! \$ B2 Psudo ovs-vsctl add-port helloworld third_br -- set Interface third_br ofport_request=3 # _$ ]) ?5 M% S: s, `6 Q
sudo ovs-vsctl add-port helloworld forth_br -- set Interface forth_br ofport_request=4ofport_request是指定端口号新添加的port都是出于DOWN的状态
% f- w, v# i9 y9 R

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2019-10-25 10:00:34 | 显示全部楼层
把它们设为UP
5 ~6 Z3 ~% R. l9 d1 @
9 J' y2 s' g* y7 n/ ^4 h3 y2 o1 ksudo ip link set first_if up
- z" l1 Y- D' o. S% x6 _sudo ip link set first_br up " z4 d  p5 |  c& i% N
sudo ip link set second_br up     8 Q; k8 l1 D( G' `; Q; Q+ ]. f9 p8 I
sudo ip link set second_if up / S7 S6 A$ z5 w) j
sudo ip link set third_if up      & g$ t1 V$ {  m4 f9 C/ g, {5 i
sudo ip link set third_br up     
8 V/ m4 v  z0 S3 @( Jsudo ip link set forth_br up         
' \; K, J" L6 f+ V4 ~# Asudo ip link set forth_if up- T; r8 Y7 K5 s2 G

; m' {8 e5 I* p. H/ T" D" e也可以用下面的命令
/ r/ N( t7 y2 x8 T4 {) _& j
- z9 Z$ t9 _1 D7 Wovs-ofctl mod-port helloworld first_br up

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2019-10-25 10:00:35 | 显示全部楼层
实现第一个Table 0,Admission control
* N  ?- q1 {9 _+ A, I5 t( {) X( q  J2 a7 j6 [2 p
包进入vswitch的时候首先进入Table 0,我们在这里可以设定规则,控制那些包可以进入,那些包不可以进入。" l; O3 b+ A7 M! J* j9 W+ m

$ Z5 x/ Q, z; H9 t. f" o0 K0 O比如,如果source address是multicast的就不允许进入。
( u1 G" l( L0 T, s" O" c$ o4 c- F8 _' p# G8 H+ z1 R4 z
01:00:00:00:00:00/01:00:00:00:00:00是广播地址
# h' [6 O( E/ F# `" i6 M. @00:00:00:00:00:00/01:00:00:00:00:00是单播地址
* x+ Z" @; G) R8 l8 I+ j这种表示形式类似CIDR
6 y% ^& u3 {% h  L3 G于是我们添加下面的规则:) z  y- T  H* j  F6 e
sudo ovs-ofctl add-flow helloworld "table=0, dl_src=01:00:00:00:00:00/01:00:00:00:00:00, actions=drop"$ B/ a  ~( O7 p) J7 `
STP的也不接受
% t) F& v. |+ Gsudo ovs-ofctl add-flow helloworld "table=0, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0, actions=drop"
) a' B( \$ S5 e- f; U$ J7 C我们在添加最后一个flow,这个flow的priority低于default,如果上面两个不匹配,则我们进入table 1$ X2 p; B/ G  k% c2 `2 E( \1 E
sudo ovs-ofctl add-flow helloworld "table=0, priority=0, actions=resubmit(,1)"* G/ }- p* ]! f6 b5 Q8 a
我们查看一下所有的flow
% r. u  S& K, a* b$ sudo ovs-ofctl dump-flows helloworld        
9 n3 X7 T& @3 n! T5 YNXST_FLOW reply (xid=0x4): ; @" l( N- I7 V  w2 F
cookie=0x0, duration=42.162s, table=0, n_packets=0, n_bytes=0, idle_age=42, priority=0 actions=resubmit(,1)
* Y) u* ?6 V1 K* Q9 Z  r2 `cookie=0x0, duration=232.121s, table=0, n_packets=0, n_bytes=0, idle_age=232, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop
1 \5 c% w5 E! i+ L9 |" gcookie=0x0, duration=167.636s, table=0, n_packets=0, n_bytes=0, idle_age=167, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
+ v4 k! N( t2 A( \: Q. H& j" L* @& B) ^* m. s- g, z
测试Table 0
' W8 @  d0 _% s" _
2 S: @# h7 S+ m有个很好的工具ovs-appctl ofproto/trace9 J; K4 C' M# K8 v- g$ A8 n

; v) l& N  r0 Y2 Y6 Q6 k不满足条件DROP
7 I7 x# {' ^1 v; p& J8 [, u+ i/ \. q; J: ?  h- M% ?
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:05
  |/ _8 \' L% _4 CFlow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=01:80:c2:00:00:05,dl_type=0x0000
; R) G) p; T1 h0 y1 \. d$ }( |Rule: table=0 cookie=0 dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0
9 K! ]) e: k4 ?- h! G; MOpenFlow actions=drop+ G4 B* V% a7 ?  X( B- i/ l1 k

, I3 d! O/ \4 Q3 G; b! KFinal flow: unchanged % C; U- ~0 Z3 g2 M+ z
Relevant fields: skb_priority=0,in_port=1,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
4 D3 X! D- U1 s* X, r; vDatapath actions: drop
0 A! J0 l1 E. `' N% _  u. H
) y* D; k' N4 t$ _6 @4 m满足条件RESUBMIT- @' c8 U6 K% [; _4 W1 a

# [+ p  G& u) ]1 F  g+ f$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:10
. N8 ?% _; R# @+ e0 [* UFlow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=01:80:c2:00:00:10,dl_type=0x0000 3 c& x5 \0 A$ Q8 i
Rule: table=0 cookie=0 priority=0
7 Z3 ?8 O. @/ ]7 y( oOpenFlow actions=resubmit(,1)6 i# f' i2 S6 r1 }  H
- x# a! q. [1 K) b
        Resubmitted flow: unchanged
1 t5 `' M* L) {* Y; T* {9 m        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
2 p) n, s- M7 ^0 A        Resubmitted  odp: drop
3 A' i9 O7 f: r% n        No match
9 I% G$ K7 m7 C9 \
& S0 l2 ?" S4 q1 dFinal flow: unchanged
& A5 R5 ~. E, {* BRelevant fields: skb_priority=0,in_port=1,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=01:80:c2:00:00:10/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no ; e) `, f* {' K5 h6 {: h; n+ `$ ]- i
Datapath actions: drop
0 ?) t8 N/ R& \' e" l3 q( X! E! ^4 n& O' v7 t$ P9 w* U
实现第二个Table 1:VLAN Input Processing& n$ X. x9 K9 _% t2 }* T+ r1 F

, c, p9 F. ]% h; X& J3 Z首先添加一个最低优先级的DROP的规则7 G% J. r0 \& D: X3 I, d/ c, @

( g8 A6 c1 G' D, `: N' Asudo ovs-ofctl add-flow helloworld "table=1, priority=0, actions=drop"0 ?' V6 ]5 Z& m6 @+ y' B

# W' b1 Q. P# u) ^& S+ L对于port 1,是trunk口,无论有没有VLAN Header都接受。2 s* Z. N9 {2 b6 h1 O9 K6 R" L6 k

' |3 K$ ^" H( l1 esudo ovs-ofctl add-flow helloworld "table=1, priority=99, in_port=1, actions=resubmit(,2)"' y- z+ k- z; {6 ?
: b8 T' y0 j( j2 B3 {7 d
对于port 2, 3, 4, 我们希望没有VLAN Tag,然后我们给打上VLAN Tag/ W0 q. r# |& \) C' j

5 X, Y$ [+ p0 c5 X5 P$ sudo ovs-ofctl add-flows helloworld - <<'EOF'
( E! @# G- O+ @* @. w+ ltable=1, priority=99, in_port=2, vlan_tci=0, actions=mod_vlan_vid:20, resubmit(,2) 7 v! p, h( H7 ?
table=1, priority=99, in_port=3, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2) " z7 \" Y' z# j
table=1, priority=99, in_port=4, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2)
0 q2 B! b/ F( Z% n2 e3 Q. iEOF
: m3 U* K7 e* w; G' q$ j8 Y3 A- i4 D6 e$ l
$ sudo ovs-ofctl dump-flows helloworld
* D7 B* M; y1 e, xNXST_FLOW reply (xid=0x4): ! v$ U' W0 y, N  \: C
cookie=0x0, duration=4478.582s, table=0, n_packets=0, n_bytes=0, idle_age=4478, priority=0 actions=resubmit(,1) $ \5 k( M9 S1 J: O
cookie=0x0, duration=4668.541s, table=0, n_packets=0, n_bytes=0, idle_age=4668, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop
. {; L# Y+ j$ N. r& L( {8 e% ycookie=0x0, duration=4604.056s, table=0, n_packets=0, n_bytes=0, idle_age=4604, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
0 t2 U# Q0 k! t) y8 Gcookie=0x0, duration=89.273s, table=1, n_packets=0, n_bytes=0, idle_age=89, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2)
8 f" M# z; T1 E) K+ X, f7 Y. Kcookie=0x0, duration=89.273s, table=1, n_packets=0, n_bytes=0, idle_age=89, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
' G" H) [3 Z8 Z( W8 A! Ucookie=0x0, duration=89.273s, table=1, n_packets=0, n_bytes=0, idle_age=89, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
9 v2 R5 G. i+ _# hcookie=0x0, duration=220.318s, table=1, n_packets=0, n_bytes=0, idle_age=220, priority=99,in_port=1 actions=resubmit(,2)
0 Y1 Q; _. i* z3 C0 S5 F$ Gcookie=0x0, duration=298.739s, table=1, n_packets=0, n_bytes=0, idle_age=298, priority=0 actions=drop
! `# Q  U; s$ j1 T1 n" h; J; x2 r/ @5 l  r! l
测试一个从port 1进入,tag为5的
) z( }# F( v9 B
9 L9 T5 B6 {1 I; ]& z0 k) Y$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=5 & \. X7 r' O9 ^' U0 X
Flow: metadata=0,in_port=1,vlan_tci=0x0005,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000
$ r6 v, r: s, S1 U3 e+ KRule: table=0 cookie=0 priority=0
6 v# c3 d. ^. D, p7 `) y2 T2 gOpenFlow actions=resubmit(,1)# Q) g9 ~8 w9 l4 u8 K( ^6 }5 A+ ?
- O7 V, `' o* J& T2 Y+ l
        Resubmitted flow: unchanged 9 T# J- Q& q# \( ~! _
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 % `: {$ S5 ?+ Q" U) a# V
        Resubmitted  odp: drop 6 @% q5 W! B/ o% t% D3 ?5 R/ g
        Rule: table=1 cookie=0 priority=99,in_port=1
$ ^: G; s$ V6 n  |3 |1 p; o        OpenFlow actions=resubmit(,2)# H4 t$ q- c3 e: y: t& k4 q

9 q& E  k$ b8 q- F4 d                Resubmitted flow: unchanged
( o8 z  M5 d+ i( R( W                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & l) Z& b1 k+ z0 w. ~5 {! t1 b
                Resubmitted  odp: drop
# A  d7 V4 X. P# L4 _                No match; R6 X8 |, v) I" `1 u' {+ _$ F) p
4 u  q9 ~; M2 a+ P$ m& u- [$ {
Final flow: unchanged " y! `, X% _! n$ H+ O$ r( w
Relevant fields: skb_priority=0,in_port=1,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no # `! _# E' E9 O3 ^2 a( Y4 b
Datapath actions: drop
. B8 f3 Z  i  R  M
, N/ o9 C  x, B6 d% e测试二,从port 2进入,没有打Tag的" b# B0 C) W3 K, R* {3 }3 l6 x

) t% P7 t3 v- ~. ?! G$ sudo ovs-appctl ofproto/trace helloworld in_port=2
2 e" B& l* I, D. CFlow: metadata=0,in_port=2,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000 $ J, w4 d- I5 Y
Rule: table=0 cookie=0 priority=0 1 Z  g0 l' A, \# f* C# X5 n0 x
OpenFlow actions=resubmit(,1)
& {2 b! |9 K0 g5 }- g8 j
, j" }2 W& y" |8 g0 g4 [0 g$ |: h4 o        Resubmitted flow: unchanged & l0 c3 r7 H: E" T, [* w! h
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ' [* j$ w2 S, N/ H+ F. ]# m
        Resubmitted  odp: drop % T+ i: P6 e( z
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 0 V" ]' J! r# j4 W8 u5 w3 z$ d
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
' Y8 M, v* U% b& U8 e/ j5 r$ j  `
: e3 m" o- S6 Z0 [                Resubmitted flow: metadata=0,in_port=2,dl_vlan=20这里被打上了Tag,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000 $ O; C' s: v5 Z3 k8 J
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 9 C$ ?+ n9 Q$ q- ?) u7 Y
                Resubmitted  odp: drop
$ D( P" Y% m9 v$ H% d' T  ^! t6 ~                No match/ \; t, a1 F5 k1 t: [( W

8 Y7 B( _  R" iFinal flow: unchanged
7 v& l# U  x7 Q; C# gRelevant fields: skb_priority=0,in_port=2,vlan_tci=0x0000,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
, I" Y! w4 G0 r3 u- EDatapath actions: drop9 E) B4 W& E) f# d
9 i! P: l. r# d8 R- T
测试三:从port进入,带Tag 5的
) ^6 [% h2 V  S* Z6 t
9 {! c. }: p1 U$ y: Z5 W$ sudo ovs-appctl ofproto/trace helloworld in_port=2,vlan_tci=5
2 _" t9 A# ]+ G: @" `- k6 s1 P, pFlow: metadata=0,in_port=2,vlan_tci=0x0005,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000
, W8 Y% `, [7 l  e3 SRule: table=0 cookie=0 priority=0 , @/ n" r3 {+ o6 a
OpenFlow actions=resubmit(,1)0 {; H1 L: a8 d5 S' Z
( i2 n3 @; k2 G8 t  u6 [
        Resubmitted flow: unchanged - s% y# U& j: n% _" r4 m- M
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
9 e6 H6 @$ c) a9 d  B% r: N: {        Resubmitted  odp: drop & `6 \$ ^4 w7 v7 ~0 E6 \
        Rule: table=1 cookie=0 priority=0
/ J) ~/ P6 r& i" \2 A        OpenFlow actions=drop6 D2 G$ R% I( v$ V; o, Y
& G: {3 f) h% y$ x3 n  z
Final flow: unchanged 2 [( @' {2 v' N
Relevant fields: skb_priority=0,in_port=2,vlan_tci=0x0005,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no 3 `4 B* J+ y$ I0 \, H
Datapath actions: drop7 Q, S' }! |: Q9 ^

4 F+ Q4 U3 Y* u- J; u9 V1 i' y实现第三个Table 2: MAC, VLAN learning for ingress port
: c) G! N, O& t8 Z8 e, A& b, |4 l2 E
) d2 F: p4 P' `3 s对于普通的switch,都会有这个学习的过程,当一个包到来的时候,由于包里面有MAC,VLAN Tag,以及从哪个口进来的这个信息。于是switch学习后,维护了一个表格port –> MAC –> VLAN Tag。6 `* H$ V8 C" k1 r' L

3 N- M7 O* e' r' ]" f* {这样以后如果有需要发给这个MAC的包,不用ARP,switch自然之道应该发给哪个port,应该打什么VLAN Tag。
. G6 ?0 `" K. @7 i. a7 p7 b  [: C$ t
OVS也要学习这个,并维护三个之间的mapping关系。
# u% Q( g" @) {9 E( C# L7 D
. c5 v; U( P' }4 e8 M在我们的例子中,无论是从port进来的本身就带Tag的,还是从port 2, 3, 4进来的后来被打上Tag的,都需要学习。3 e* A6 K0 t2 {; h; Z0 |
  L$ \2 `0 `7 G
sudo ovs-ofctl add-flow helloworld "table=2 actions=learn(table=10, NXM_OF_VLAN_TCI[0..11], NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[], load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]), resubmit(,3)"0 U" P: A  W" i6 {6 H$ D$ \" `
0 @1 K- Y$ U: b! i) M
这一句比较难理解。4 b9 o  n# e" O# ~. n  c8 g! b

/ b& {% q2 ~! w0 v/ Elearn表示这是一个学习的action% ]! \. ]" N4 n4 u" j
: T' u! Q& h; a: C
table 10,这是一个MAC learning table,学习的结果会放在这个table中。
- A- ?/ O7 k8 T/ t7 g$ R# u2 ?7 Z, k/ R  p* j8 U- F0 Y  Q* ?
NXM_OF_VLAN_TCI这个是VLAN Tag,在MAC Learning table中,每一个entry都是仅仅对某一个VLAN来说的,不同VLAN的learning table是分开的。在学习的结果的entry中,会标出这个entry是对于哪个VLAN的。6 J" x! o* d4 {% Y# v

8 Z) |  \; {9 D2 m3 zNXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]这个的意思是当前包里面的MAC Source Address会被放在学习结果的entry里面的dl_dst里面。这是因为每个switch都是通过Ingress包来学习,某个MAC从某个port进来,switch就应该记住以后发往这个MAC的包要从这个port出去,因而MAC source address就被放在了Mac destination address里面,因为这是为发送用的。
9 M+ N3 C7 f% m; T- u; i; C$ z' f' U8 p0 C' u( _
NXM_OF_IN_PORT[]->NXM_NX_REG0将portf放入register.
8 S. s1 T- F. p9 u
' V* f. s( s$ V一般对于学习的entry还需要有hard_timeout,这是的每个学习结果都会expire,需要重新学习。
/ b6 V7 e9 E- H9 p# R+ R# y  k( j7 i+ b. Z# ~
我们再来分析一个实践中,openstack中使用openvswitch的情况,这是br-tun上的规则。4 v9 Z/ G4 |6 B4 f$ @: Z, S/ n6 W3 o

1 R6 v' r2 L8 I% a- [* mcookie=0x0, duration=802188.071s, table=10, n_packets=4885, n_bytes=347789, idle_age=730, hard_age=65534, priority=1 actions=learn(table=20,hard_timeout=300,priority=1,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:0->NXM_OF_VLAN_TCI[],load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[],output:NXM_OF_IN_PORT[]),output:1
6 w: O7 s5 R# u0 N3 F# F6 T" J; |7 ycookie=0x0, duration=802187.786s, table=20, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,21) ' `4 ?" O8 Q. L: t1 b
cookie=0x0, duration=802038.514s, table=20, n_packets=1239, n_bytes=83620, idle_age=735, hard_age=65534, priority=2,dl_vlan=1,dl_dst=fa:16:3e:7e:ab:cc actions=strip_vlan,set_tunnel:0x3e9,output:2 ! e7 m: \* R% T- P! P8 q% I
cookie=0x0, duration=802187.653s, table=21, n_packets=17, n_bytes=1426, idle_age=65534, hard_age=65534, priority=0 actions=drop 8 p0 {7 t% Q4 R
cookie=0x0, duration=802055.878s, table=21, n_packets=40, n_bytes=1736, idle_age=65534, hard_age=65534, dl_vlan=1 actions=strip_vlan,set_tunnel:0x3e9,output:2- m1 q$ a  p# o5 Q

* `9 b' \% l( M+ o这里table 10是用来学习的。table 20是learning table。如果table 20是空的,也即还没有学到什么,则会通过priority=0的规则resubmit到table 21.( v9 E% R, u4 e* d5 T+ i  z  {& k
! k' q, e3 y1 G, I% {7 e
table 21是发送规则,将br-int上的vlan tag消除,然后打上gre tunnel的id。4 W$ m0 }+ N) H& v- m& \
% s. M5 `1 y9 X0 e
上面的情况中,table 20不是空的,也即发送给dl_dst=fa:16:3e:7e:ab:cc的包不用走默认规则,直接通过table 20就发送出去了。
$ P' n7 R; M6 A) C
, R# H) A4 V5 A  ~0 f/ F; Wtable 20的规则是通过table 10学习得到的,table 10是一个接受规则。最终output 1,发送给了br-int* K5 O' J) r9 A9 Z8 J% I5 B

' o7 u1 L& c9 o% iNXM_OF_VLAN_TCI[0..11]是记录vlan tag,所以学习结果中有dl_vlan=1  Z; v5 y# t2 l) P
# u& Q& u9 {- Q6 N* k) F! z
NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]是将mac source address记录,所以结果中有dl_dst=fa:16:3e:7e:ab:cc
; c, l( V9 W  ?1 i! J, _" x3 H' \& X* u, K
load:0->NXM_OF_VLAN_TCI[]意思是发送出去的时候,vlan tag设为0,所以结果中有actions=strip_vlan
! U6 e: S; L3 W) P% K# Y7 [8 G. x
! W8 T7 m% J0 rload:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[]意思是发出去的时候,设置tunnul id,所以结果中有set_tunnel:0x3e9
: M" X% y6 Y$ f' \9 v
2 ^" @# ?% J; [/ D0 K, g. [8 koutput:NXM_OF_IN_PORT[]意思是发送给哪个port,由于是从port2进来的,因而结果中有output:2
, N( I+ V/ Y1 D5 b$ ~5 m
+ k. H8 U) Z7 Y+ h  n* @5 k' d测试一:从port 1来一个vlan为20的mac为50:00:00:00:00:01的包
0 m9 Z- h1 j( }( r- @0 u* k+ Z4 M( w! r
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=20,dl_src=50:00:00:00:00:01 -generate   / L! K' S; D; d' C
Flow: metadata=0,in_port=1,vlan_tci=0x0014,dl_src=50:00:00:00:00:01,dl_dst=00:00:00:00:00:00,dl_type=0x0000
3 R6 k4 P6 i! m  HRule: table=0 cookie=0 priority=0 $ \. B; ^% d! Q4 ~1 L
OpenFlow actions=resubmit(,1)6 r* n$ a9 c9 s7 B/ J3 F
# |# d! c. e4 S& }
        Resubmitted flow: unchanged
! O# p" D1 ]8 r% ^' ]" y& q        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 - v: v& G9 M4 C! Y
        Resubmitted  odp: drop
3 O9 k' d0 {3 m# g3 H! B        Rule: table=1 cookie=0 priority=99,in_port=1
& o% V/ }/ `; _* w( ~- o4 A        OpenFlow actions=resubmit(,2)
  q. u# g/ @& i& m) V+ e! K3 V1 u& o0 k- l  O: r, b
                Resubmitted flow: unchanged " |  W+ |" ^2 m( h# Q7 |
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
: o1 t) r) x- |5 ]                Resubmitted  odp: drop " |; N3 b: w+ q: H6 q
                Rule: table=2 cookie=0 0 H1 v* e( P2 v$ c
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)4 v1 N" T, T* R- g

0 _( {9 {* R) x) n& P- @: V                        Resubmitted flow: unchanged * T$ j: x5 J+ x& O3 e7 j  a) {/ P. {
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
! M& S, q$ B/ A6 j% C2 ~                        Resubmitted  odp: drop : r0 N7 [) q' g+ W$ |
                        No match
9 U/ {9 P" u+ Z( u) k% ~- S) X3 E
# x# s6 m7 c6 SFinal flow: unchanged
+ Z" u! i" |2 e) F" d! d6 sRelevant fields: skb_priority=0,in_port=1,vlan_tci=0x0014/0x0fff,dl_src=50:00:00:00:00:01,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
$ ]2 _. k0 ^$ [5 jDatapath actions: drop
* \7 v) Z) p" w  g& ^2 T, ^
7 T7 q4 E5 T: w2 K  t5 v$ sudo ovs-ofctl dump-flows helloworld
" [. f2 b: B  O* j) I1 DNXST_FLOW reply (xid=0x4):
' i- d+ U7 c# X0 T3 z- X8 Lcookie=0x0, duration=90537.25s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
- L5 J: w2 C' j  [7 w3 Y  Ncookie=0x0, duration=90727.209s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop ! K0 E* O1 \9 O: h
cookie=0x0, duration=90662.724s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
  v8 z* k4 R( f% Lcookie=0x0, duration=86147.941s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2) 1 N8 ?. Z. f9 E  o
cookie=0x0, duration=86147.941s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) 5 A( X; x  C0 h- G  n
cookie=0x0, duration=86147.941s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) / d; I% }, u7 Z( K3 m9 \9 O4 q
cookie=0x0, duration=86278.986s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2)
0 ?3 }) \/ p8 o( n: Gcookie=0x0, duration=86357.407s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
& ~4 K0 A: M& |! v( w( x5 Xcookie=0x0, duration=83587.281s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3) 8 p4 U* a) H8 U( b
cookie=0x0, duration=31.258s, table=10, n_packets=0, n_bytes=0, idle_age=31, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15], S& Z3 [6 [7 N  T3 p
- |% P6 L- \/ ?- H
table 10多了一条,vlan为20,dl_dst为50:00:00:00:00:01,发送的时候从port 1出去。
) q& S2 [8 Y6 R: m' w1 }! y
* M4 x9 f% k, u$ d0 Y0 r4 b2 @测试二:从port 2进来,被打上了vlan 20,mac为50:00:00:00:00:02
. i! u! B. a  p( F3 I9 {$ K5 T, d+ A: u+ v) G$ z
$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=50:00:00:00:00:02 -generate   
5 \& @0 E: E% f; L: J8 UFlow: metadata=0,in_port=2,vlan_tci=0x0000,dl_src=50:00:00:00:00:02,dl_dst=00:00:00:00:00:00,dl_type=0x0000
8 G+ a+ s, W1 x! F3 A" C+ e1 FRule: table=0 cookie=0 priority=0
6 C; ]! X% K4 b$ ~" p- gOpenFlow actions=resubmit(,1)% {  e8 s: L& |" J9 O
; ^" J* b4 ^5 A% {) X* h7 u, z
        Resubmitted flow: unchanged $ f# w( V4 m- Y
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
$ w6 K" x6 s9 ?7 s        Resubmitted  odp: drop % Z2 S4 c' B: F2 K  c/ ^2 K
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
; \, P1 F4 V; ?3 e        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)+ m4 D  s3 Q9 t& e$ G& g0 Y5 D
6 J( Y- Z8 X( E
                Resubmitted flow: metadata=0,in_port=2,dl_vlan=20,dl_vlan_pcp=0,dl_src=50:00:00:00:00:02,dl_dst=00:00:00:00:00:00,dl_type=0x0000 / ^7 W$ R5 Y6 l7 O  W
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 + s' _+ b9 _1 K2 v; w
                Resubmitted  odp: drop
- Z# t3 B( D1 D: l$ b                Rule: table=2 cookie=0
1 S& z/ U: h8 p* E* v$ O1 n                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
) L0 w& Q+ k6 Y% g# `: Y7 I, {6 R" D, g9 {
                        Resubmitted flow: unchanged
! D6 |' Q* C' i4 U$ Q9 U* @$ N                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
2 d( i3 x3 ?% H  \                        Resubmitted  odp: drop
0 h! P6 f* x% S1 v. C                        No match5 V. q" i. w) _+ J% ?6 d3 @8 T
$ r. d! g8 B( O5 g9 M6 D
Final flow: unchanged
  d0 d  ]" b' p; g; z- }Relevant fields: skb_priority=0,in_port=2,vlan_tci=0x0000,dl_src=50:00:00:00:00:02,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
! S* Z& s; v1 j7 H' X' h/ iDatapath actions: drop
" z7 ^/ y) ]$ [1 V- |4 }5 E" v# e
; h! o$ W( y# X0 x+ l. M$ sudo ovs-ofctl dump-flows helloworld                                                
& a' x2 m# {' }( D1 ]' VNXST_FLOW reply (xid=0x4):
9 m  w; G; |; t) B' I' N7 e% Wcookie=0x0, duration=90823.14s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
4 [$ K( B" U, K. p6 W" v+ o# K8 ?cookie=0x0, duration=91013.099s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop
% i( {8 S& t& v# Z) icookie=0x0, duration=90948.614s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop 7 Z3 V! t) A3 z4 p
cookie=0x0, duration=86433.831s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2) * M( H- c) M, d. t0 E8 y' o  g8 N
cookie=0x0, duration=86433.831s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) 3 m2 P1 |& v2 r% ]4 t. a3 a
cookie=0x0, duration=86433.831s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) - c4 r  o  y: F& P8 }; l
cookie=0x0, duration=86564.876s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2) ; u) K1 H5 J1 [$ ^: n
cookie=0x0, duration=86643.297s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
$ A6 B( ~/ e' L/ z+ P( x6 {! W3 acookie=0x0, duration=83873.171s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
6 \# O: Z1 x9 r2 N9 [ cookie=0x0, duration=4.472s, table=10, n_packets=0, n_bytes=0, idle_age=4, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:02 actions=load:0x2->NXM_NX_REG0[0..15]
3 q  r/ [* f+ k. \# scookie=0x0, duration=317.148s, table=10, n_packets=0, n_bytes=0, idle_age=317, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]
9 T" d) o2 G0 L2 d3 x4 B
2 ]+ P" R# t# X; n# C实现第四个table 3: Look Up Destination Port
8 |+ s- O" k5 l1 c0 h) _" ^6 Q* W5 U5 n" E4 u- \
在table 2中,vswtich通过进入的包,学习了vlanid –> mac –> port的映射后,对于要发送的包,可以根据学习到的table 10里面的内容,根据destination mac和vlan,来找到相应的port发送出去,而不用每次都flood
+ [* h# `% S& K% D' q2 T9 u, w  s4 C  e$ w5 V: A) l& A) A, Z' |7 R" R
sudo ovs-ofctl add-flow helloworld "table=3 priority=50 actions=resubmit(,10), resubmit(,4)"
- S3 s( f6 x, ^: }
7 Z# `& p& y& p0 x$ E' M; Q添加这条规则,首先到table 10中查找learn table entry,如果找不到则到table 4% z* z% A! r. P" y, y

6 w6 M4 x5 C& ~' j1 B7 X: C! {如果包本身就是multicast的或者broadcast的,则不用去table 10里面取查找。, }; X1 c' O3 H+ l7 u
, L3 M- X& @3 r5 z  ]: K
sudo ovs-ofctl add-flow helloworld "table=3 priority=99 dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,4)"4 ]% u$ y4 v2 F4 B5 v& ]; J

$ j6 o7 p7 J# d2 h* Z/ q8 @我们进行一项测试
. T% y, }, ~2 l9 [  `8 B* ?2 `- R4 ]3 e
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=20,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01 -generate   
1 g: Y4 h- D( AFlow: metadata=0,in_port=1,dl_vlan=20,dl_vlan_pcp=0,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000 & Y5 E" j6 S* r
Rule: table=0 cookie=0 priority=0
5 M, X/ |  n) U+ COpenFlow actions=resubmit(,1)
" B$ x" b' K* F6 N0 _0 ?' y. R" h% X
- l  {* {% S. g. Q. ?: O6 U9 M" T        Resubmitted flow: unchanged   r9 M& _2 d' w7 k, ?0 J  B* i4 y
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
% Y. a* x# z  f5 a2 L        Resubmitted  odp: drop
" d3 i! F/ i7 e( V        Rule: table=1 cookie=0 priority=99,in_port=1 ; Q3 i* ?, K0 _! f( l4 z
        OpenFlow actions=resubmit(,2)
/ z8 W6 e2 G# G, U; J5 p; r( d. R0 \2 r
                Resubmitted flow: unchanged
0 l$ ~  R3 e( \* n                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 2 e3 c4 X; ~1 F' s1 I" \
                Resubmitted  odp: drop 7 Z) w2 L' n" w) M0 ]$ c
                Rule: table=2 cookie=0
4 w& V) r* K+ V' a0 R" [6 L- X                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
# ?" T( ~6 Z6 z2 _) p! ^
+ m8 [" ]1 ?# x1 a# v9 X  Z                        Resubmitted flow: unchanged 4 e  E4 b& A+ B; g" a0 Q6 Q$ i
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 : T4 l: ]' l6 {: R1 V
                        Resubmitted  odp: drop ; U3 l( k3 ?8 y2 j! [, O0 F7 k& }
                        Rule: table=3 cookie=0 priority=50
( R( V" @/ j7 x                        OpenFlow actions=resubmit(,10),resubmit(,4)
& A& @1 ~" h& b( E0 x: |: j: |1 h' j9 g/ U0 o+ N  Q: i3 V6 y
                                Resubmitted flow: unchanged
/ F& i* h8 c& B4 L0 Z                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 " |; M" y" B3 l  D4 }( I) V) V
                                Resubmitted  odp: drop 4 K8 S8 L3 ^5 J: Y
                                No match+ V' y' `" ~$ a" ?: X2 m) B

  \/ o& a' y' k( I                                Resubmitted flow: unchanged
' x$ Z% G2 X; p                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
7 T: W3 t3 H& ?4 a5 c! k  O7 o9 K1 G                                Resubmitted  odp: drop 6 Z7 G( b4 n  |$ s9 a" Y. H
                                No match. T2 m) x9 X5 X) V- `
" _: K$ [/ S8 f4 p
Final flow: unchanged
( L  d$ M$ B; ~% v. z  X1 iRelevant fields: skb_priority=0,in_port=1,vlan_tci=0x0014/0x0fff,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000,nw_frag=no 9 f9 c1 @, \& I" ?: h% D& n7 l1 X$ V& S! [
Datapath actions: drop; K6 d" S4 m5 ]( |' |

! |1 v5 U- `7 N0 y+ n由于目标地址f0:00:00:00:00:01没有在table 10中找到,因而到达table 4.
/ p- @6 ?& m9 ^* ?/ {0 [5 v* J& E+ H
' e+ v; f6 e) y: k. l. H# L  l但是这次测试使得table 10中学习到了mac地址90:00:00:00:00:01
+ o3 H) ]! \7 h, r& q( z# j3 ~1 G
. C: }( Z  \6 Q4 o- A  F' V! f: U6 a$ sudo ovs-ofctl dump-flows helloworld % m, ], z( Q  x& L4 u
NXST_FLOW reply (xid=0x4): 2 r# {' G: S2 m3 o- p
cookie=0x0, duration=91588.452s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) 4 a4 s1 Y6 |# N. B
cookie=0x0, duration=91778.411s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop & b5 B/ E5 y* R7 @: r
cookie=0x0, duration=91713.926s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop : F# z! T6 i4 |8 R1 z1 w  j/ O) s2 h
cookie=0x0, duration=87199.143s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2) . j) k$ _& R- S
cookie=0x0, duration=87199.143s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) 8 D8 ?. d  c. A8 k- G* S& N
cookie=0x0, duration=87199.143s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) 7 t: b7 h  \' x* R
cookie=0x0, duration=87330.188s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2)
& D) E: s. Q2 c9 u9 ccookie=0x0, duration=87408.609s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
2 Y$ R  L. t/ {+ Y/ Y5 k" A( l5 H2 e- Ycookie=0x0, duration=84638.483s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3) 5 X* c1 ?" X: ?' U4 ?
cookie=0x0, duration=352.841s, table=3, n_packets=0, n_bytes=0, idle_age=352, priority=50 actions=resubmit(,10),resubmit(,4)
7 S" G$ f$ D* @. f4 zcookie=0x0, duration=212.704s, table=3, n_packets=0, n_bytes=0, idle_age=212, priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,4)
- C3 a6 h, p: y2 s1 c cookie=0x0, duration=117.364s, table=10, n_packets=0, n_bytes=0, idle_age=117, vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]
( ]! [, r! k& v  rcookie=0x0, duration=769.784s, table=10, n_packets=0, n_bytes=0, idle_age=769, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:02 actions=load:0x2->NXM_NX_REG0[0..15]
7 g$ ^5 I; G& g: C$ V% \- Fcookie=0x0, duration=1082.46s, table=10, n_packets=0, n_bytes=0, idle_age=1082, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]! r; S% \- K2 k2 Q* [
' {9 Q: w! r  J6 w8 l* J4 [
下面我们进行另一个测试
) l: a" P% y. Q7 Z4 p& B+ d8 O
1 S. l9 w( ]* A- `& [$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01 -generate   
) U3 B+ P& K. V- bFlow: metadata=0,in_port=2,vlan_tci=0x0000,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01,dl_type=0x0000 6 B' Q! e8 `$ f4 |# U
Rule: table=0 cookie=0 priority=0 # @9 M6 U# w  x$ V+ k9 `
OpenFlow actions=resubmit(,1)( {1 r% v! ]; e# z3 h) q/ l* h
# o+ b1 U, @9 B
        Resubmitted flow: unchanged
- U5 o! ~1 K3 w. U: ?        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 , w2 F' N9 |0 T5 Z+ H, B
        Resubmitted  odp: drop , L5 A0 V# z! ?" a. @
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 0 Q* E- R+ o1 N1 G
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
( h1 C$ C, |* W" {
* `4 y+ B2 W1 r- `                Resubmitted flow: metadata=0,in_port=2,dl_vlan=20,dl_vlan_pcp=0,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01,dl_type=0x0000 * N0 R4 ~: p- |2 o
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & A# k* Y. [9 p/ @5 Q2 K8 X1 m
                Resubmitted  odp: drop ! a$ |. s! R4 [0 U# X
                Rule: table=2 cookie=0 : \& V6 G) y4 u' I2 \. }
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)- A  S  @5 {7 q' g( Q

  w. x) ^0 U6 C$ s                        Resubmitted flow: unchanged
7 {4 x0 r4 O) U. {                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
  N% O* I$ q+ `% z8 T4 g( c7 Y" W7 T                        Resubmitted  odp: drop 7 t! S# U9 o( Z) K& c
                        Rule: table=3 cookie=0 priority=50
! H; V4 P7 i' K1 d, ?0 Q! q" `                        OpenFlow actions=resubmit(,10),resubmit(,4)* f8 e0 Q' ]! n9 h+ R9 ^0 e1 g4 [

' x. _* J; q  M, [                                Resubmitted flow: unchanged   c9 S- _- p7 g1 e( a
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 2 U( e# t3 ^( d2 T
                                Resubmitted  odp: drop
+ p* j* N( d" K/ c                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01
' |7 J( @; S! j0 o7 \! W0 o  v                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]
% e  |- r) ~' G! A( i+ e4 |1 e' }0 B$ \  v; \
                                Resubmitted flow: reg0=0x1,metadata=0,in_port=2,dl_vlan=20,dl_vlan_pcp=0,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01,dl_type=0x0000 - C# b* e5 t9 }- r( x7 _
                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
- ^& ~) M; D! _, {! ?  U                                Resubmitted  odp: drop
: c  }8 ?2 n$ a                                No match  @/ y( W- }6 A

0 \8 {! N  {( \0 H# h4 xFinal flow: unchanged . x" N3 }& Q- z' }3 L
Relevant fields: skb_priority=0,in_port=2,vlan_tci=0x0000,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01,dl_type=0x0000,nw_frag=no   E" ^0 q% T. s3 \
Datapath actions: drop- O+ ]! i3 w: u% a! b9 r- ^6 l( Y2 j

* s4 ?. g" s* K: g* ]' I因为刚才学习到了mac地址f0:00:00:00:00:01,所以这次在table 10中找到了这条记录,这次同时也学习到了mac地址90:00:00:00:00:01
: N% j  K) w' ]/ Y/ Z2 i1 V# G& \3 a; x& ]
下面我们再发送第一次的包
; L" z+ A; I* n! u) K/ `1 X( L" G& U% F
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=20,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01 -generate
+ j$ f: U' q0 pFlow: metadata=0,in_port=1,dl_vlan=20,dl_vlan_pcp=0,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000 ( f+ v5 h- W* _8 q) d1 `) k. L
Rule: table=0 cookie=0 priority=0 4 O3 U4 Y6 w$ c( t) l1 X
OpenFlow actions=resubmit(,1)
$ `# J2 b& s' y  G. {: {
: |& j0 x- C1 p8 H) P1 s        Resubmitted flow: unchanged 4 V) {* E/ ]* e2 v5 P9 l) |
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 9 y5 c' t# W" s( B9 Z# l3 z0 D( s
        Resubmitted  odp: drop 9 e, K; L! G/ N! |
        Rule: table=1 cookie=0 priority=99,in_port=1
" Y' a0 N8 Q2 h1 N) _9 ?6 e        OpenFlow actions=resubmit(,2): \3 H0 C$ U/ p5 n, i2 F
6 B, h7 S+ j9 w4 ]
                Resubmitted flow: unchanged & y; B) r7 G- C# o
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
% m$ N4 L' \2 _. A                Resubmitted  odp: drop
6 B( e& l  |& K& L+ h                Rule: table=2 cookie=0 2 n  V+ k1 `3 G$ D, O+ p4 f% ^; S
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)5 G6 u( g) R- y

3 [- Z8 a  Q" \1 L                        Resubmitted flow: unchanged
. G, h: j$ O  v+ A8 P% K( X                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 - X( }: Z% [: _; _0 q
                        Resubmitted  odp: drop ( N; s; T; v5 |- Q4 H$ c
                        Rule: table=3 cookie=0 priority=50 / Q+ H7 q  l4 G% X/ G1 w  ~  Y/ q
                        OpenFlow actions=resubmit(,10),resubmit(,4)! g8 U4 M% d8 m/ R4 V0 w6 Z1 y% h

3 k- [7 M! |# |9 a5 J0 ^( v                                Resubmitted flow: unchanged
4 h1 K- J& ^5 N& D8 u9 h                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ( _0 X" w% |7 |' z5 ?
                                Resubmitted  odp: drop + Z+ j" ]' g3 V7 Q$ p/ I$ H$ l! c5 ~
                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01 8 B# E! G! i3 n: @9 F  r
                                OpenFlow actions=load:0x2->NXM_NX_REG0[0..15]
1 X: g' V. |' D" j- }4 i2 {$ x: b+ {$ X
                                Resubmitted flow: reg0=0x2,metadata=0,in_port=1,dl_vlan=20,dl_vlan_pcp=0,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000 7 L9 g) c1 o; |) `& M' C* V/ ?6 \  D
                                Resubmitted regs: reg0=0x2 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ' `+ U& m) _2 H1 a- A" m' f
                                Resubmitted  odp: drop
5 v1 Y3 l0 s0 E6 ]) [                                No match
2 c: h0 [. \2 S0 p  C9 n/ H  @2 c6 V+ r- S8 Y" I% ^0 M, P6 T
Final flow: unchanged
3 y  w! U, |# T; RRelevant fields: skb_priority=0,in_port=1,vlan_tci=0x0014/0x0fff,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000,nw_frag=no ' k! q% b, r* \, _2 J3 [# L
Datapath actions: drop
2 E- a/ b& v( D+ l2 N8 W) g6 W9 D5 S8 p9 c
发现也在table 10中找到了记录
# l# n2 L9 J0 R1 l3 D' V: q5 u) a6 v$ S7 Y! d" n% [
实现第五个table 4: Output Processing
' ^" _- Q& H9 p7 v  M: V0 F; y# s* E/ w
这个时候,register 0中包含了output port,如果是0则说明是flood。
+ @* }8 A( x2 `# s& q1 @% n
5 k; `: w* O* A对于port 1来讲,是trunk port,所以携带的vlan tag就让他带着,从port 1出去。
" {9 u# t! Y; P; x* D! }3 ~7 w! O, w
sudo ovs-ofctl add-flow helloworld "table=4 reg0=1 actions=1"
- _4 R. {, ~; I
- `. V7 \4 S9 L& A- D2 i4 A5 d对于port 2来讲,是vlan 20的,然而出去的时候,vlan tag会被抹掉,从port 2发出去
5 s/ O  z  @% }! m( W- f/ |1 v  i& e, Y' z* r( S  C& R2 L
对于port 3, 4来讲,是vlan 30的,然而出去的时候,vlan tag会被抹掉,从port 3, 4出去9 S$ `3 X# [/ j" ~

# F6 S" P, u. f0 j1 `$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   
- F1 B# V+ m4 @9 G. z8 w. h        table=4 reg0=2 actions=strip_vlan,2 0 u: ~7 h1 H9 Y. K% S. T
        table=4 reg0=3 actions=strip_vlan,3
3 F1 E) O; k$ Q' o* ^) R. _( F( U        table=4 reg0=4 actions=strip_vlan,4
2 k- |! n4 B  {EOF
( v4 w/ l! A# h0 `# M
& n. r$ F, |1 p; c) ~对于broadcast来讲,我们希望一个vlan的broadcast仅仅在这个vlan里面发送,不影响其他的vlan。
6 U' |8 \, x' E6 h$ C# j# g3 F+ ^8 i1 B& o& `& @! j, {
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   , {) X$ n, Q$ j1 |+ f
        table=4 reg0=0 priority=99 dl_vlan=20 actions=1,strip_vlan,2
' z4 Z; A8 |1 P        table=4 reg0=0 priority=99 dl_vlan=30 actions=1,strip_vlan,3,4
# p$ p5 U, p* [! d! W; O        table=4 reg0=0 priority=50            actions=1
9 B) f: u4 U3 o; ZEOF
7 b0 |$ M: h4 u: ]' x4 r' K7 g+ Q( V; [, D
所以对于register = 0的,也即是broadcast的,属于vlan 20的,则从port 1, 2出去,属于vlan 30的,则从port 1, 3, 4出去。
: {0 ^. {1 A5 O* l. z( X8 z. i" D! z+ Z
$ sudo ovs-ofctl dump-flows helloworld - p0 f) ~% N- f4 x3 j, ^/ j
NXST_FLOW reply (xid=0x4):   E# e& e6 \4 w3 n8 P0 r# ^
cookie=0x0, duration=92909.119s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
4 p5 [0 R. r) y/ X0 K+ lcookie=0x0, duration=93099.078s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop
# }1 B7 \8 D! Z5 d. f( Acookie=0x0, duration=93034.593s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
* J1 t* n& D5 f+ T: kcookie=0x0, duration=88519.81s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2) ! i% y: l0 z# A7 C, D
cookie=0x0, duration=88519.81s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) " @6 t4 R$ |6 Q. |7 S4 ^7 b7 R
cookie=0x0, duration=88519.81s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) + z5 v7 t0 Z/ F8 V' g& d( E& T- s2 x
cookie=0x0, duration=88650.855s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2) 0 h) I" O, n' ^1 {) y/ W
cookie=0x0, duration=88729.276s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
% g+ B+ q9 j  T/ j7 s! j  |- xcookie=0x0, duration=85959.15s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
1 V+ x! |, W6 h' d* X# J: R: acookie=0x0, duration=1673.508s, table=3, n_packets=0, n_bytes=0, idle_age=1673, priority=50 actions=resubmit(,10),resubmit(,4)
  ^( B) @2 W! H: n7 g( xcookie=0x0, duration=1533.371s, table=3, n_packets=0, n_bytes=0, idle_age=1533, priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,4)
/ Y( `; v9 Q3 l  Z+ _' Jcookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x3 actions=strip_vlan,output:3 6 Z2 y& N$ G2 I/ B+ Z6 z% k  e: I
cookie=0x0, duration=228.839s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=50,reg0=0x0 actions=output:1 * c) _( d* \4 u$ |+ ]3 u
cookie=0x0, duration=483.068s, table=4, n_packets=0, n_bytes=0, idle_age=483, reg0=0x1 actions=output:1 0 K# x* [4 h4 Y( k  b+ s. `
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x4 actions=strip_vlan,output:4
& c5 r% K% F: |& ecookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x2 actions=strip_vlan,output:2 2 u+ `9 k8 l8 B) p
cookie=0x0, duration=228.84s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=99,reg0=0x0,dl_vlan=30 actions=output:1,strip_vlan,output:3,output:4 # F; p0 t1 V- `. V$ z
cookie=0x0, duration=228.84s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=99,reg0=0x0,dl_vlan=20 actions=output:1,strip_vlan,output:2 1 A# s: q% `. |5 f7 s
cookie=0x0, duration=1438.031s, table=10, n_packets=0, n_bytes=0, idle_age=1438, hard_age=1109, vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]
; B* J* j/ E* T: F; kcookie=0x0, duration=2090.451s, table=10, n_packets=0, n_bytes=0, idle_age=2090, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:02 actions=load:0x2->NXM_NX_REG0[0..15] 1 q. Y7 T# y5 S$ D' n8 V
cookie=0x0, duration=1258.881s, table=10, n_packets=0, n_bytes=0, idle_age=1258, vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01 actions=load:0x2->NXM_NX_REG0[0..15]
( j* @9 F0 |  r) L# ]" t2 e; Wcookie=0x0, duration=2403.127s, table=10, n_packets=0, n_bytes=0, idle_age=2403, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]
: y# l0 V/ o9 K# ~+ m+ F
% l# [6 g1 m4 _  I6 B3 v首先来测试一个multicast和broadcast
. ]+ b8 n! T8 [" O+ t0 R9 W  m0 q9 _$ n/ N! W( L
如果是一个port 1来的vlan 30的broadcast" b6 e) `7 m: c  ?

4 I2 R7 T% |: H- l9 b* X$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=ff:ff:ff:ff:ff:ff,dl_vlan=30
9 A' M  f4 g% `+ Y* \1 c  y9 a. fFlow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000
2 E6 o( {( D  t0 Q% p1 Z9 F# BRule: table=0 cookie=0 priority=0
( `8 J/ i8 m+ K& G5 X) `OpenFlow actions=resubmit(,1)
: r2 Q& T- ~% B* G) e9 a, a) @
$ z7 ~( x( S' d        Resubmitted flow: unchanged   v. m0 G% h# p  \' u$ E
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 . a3 S! r0 z5 c) ?7 D
        Resubmitted  odp: drop . _" r0 }3 o  ?. [" ~" U, I  C
        Rule: table=1 cookie=0 priority=99,in_port=1 ! n+ n( H6 z  d8 i5 m+ v
        OpenFlow actions=resubmit(,2)! N' v1 e  E5 D; R1 `9 J6 n9 r" R

$ S% Z0 ~8 p8 ~) b2 g                Resubmitted flow: unchanged
1 ]( w9 l& X% n9 W# |- @                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 " k2 K, b- h( d( I
                Resubmitted  odp: drop
# y$ P( W. @5 I1 `+ R+ h                Rule: table=2 cookie=0 : W# C2 K0 d- M4 t" ~6 `* S3 ^
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
' K0 N$ P8 Z6 j8 m2 @
# V5 d6 i* g. g9 J                        Resubmitted flow: unchanged 1 ?% E% M6 i6 ^# T2 J: E  S
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 2 C# Z. P# l8 z  {( y6 s
                        Resubmitted  odp: drop
2 t8 R9 M; U" |! A% c% z! T                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00
+ i+ k( W. {- K8 I                        OpenFlow actions=resubmit(,4)% p7 I. o1 D/ M% I& J  w4 x

& n% K! E6 f8 l0 `+ N$ g7 O3 T                                Resubmitted flow: unchanged % R5 C+ O+ [7 }! [
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
# |. b: D% X' z                                Resubmitted  odp: drop 5 l/ A$ O( O( G# T& s( c. T0 ^0 n$ d
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 ; P" D3 E: m6 G* d" Q) J1 X" h
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
: s5 |& C3 Q- g0 [                                skipping output to input port
8 Q/ _, ^  Q; D3 Y  Y$ y- X& {  i4 S+ h- n' q
Final flow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000
3 N( C( I$ l5 @2 V, A6 Q0 {Relevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:f0/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
& W& p( r2 K0 ]  D1 K% HDatapath actions: pop_vlan,12,13/ F1 D8 ~8 k4 D

  S/ U! T* e- u( I" M: O结果是port 1就不发送了,发送给了port 3, 4
( f; @0 ]9 \+ T- {9 d0 K: w, ^% E) P3 _
" _; M- U& l- d8 n! c) U$ sudo ovs-appctl ofproto/trace helloworld in_port=3,dl_dst=ff:ff:ff:ff:ff:ff : ]# R6 R0 f2 a+ Z
Flow: metadata=0,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000 - ?8 c2 T5 w0 d1 }3 k
Rule: table=0 cookie=0 priority=0 9 r+ V0 o; r0 C2 `2 P- e6 B7 u
OpenFlow actions=resubmit(,1)
$ ~% L9 Y9 h- p1 V* Z( l1 S: T+ U+ C0 g. n2 W
        Resubmitted flow: unchanged 1 D3 d' X, x. H% u% ~- B, i
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
' ~8 Q" `* u! j  [) b% ]- a        Resubmitted  odp: drop ; `3 A& ?0 v  z2 [! U0 I: `) c
        Rule: table=1 cookie=0 priority=99,in_port=3,vlan_tci=0x0000 ! r7 T* C9 e5 T  ]7 Z# T6 H
        OpenFlow actions=mod_vlan_vid:30,resubmit(,2): M$ g8 v7 e  i, M. D
+ c; D* [; H. f
                Resubmitted flow: metadata=0,in_port=3,dl_vlan=30,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000 4 M$ Z* J+ J4 z5 Q& J, e) L/ H# [
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
. v  e+ g# T2 p3 x& u                Resubmitted  odp: drop
. E! e; X$ a  n# k                Rule: table=2 cookie=0
+ e! s) w. c( _. c- z( U                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3); {4 @8 t( S' w- m0 u2 K9 \
% m9 }3 Q$ S6 Z' r& B; w
                        Resubmitted flow: unchanged
1 ^5 e2 `& }2 y6 j: ^                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
& B7 l1 h/ \5 K, J, j! ~4 x                        Resubmitted  odp: drop
9 a* K2 j/ u1 V7 {                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00
. H7 b+ M6 E. J' y! W$ c# X                        OpenFlow actions=resubmit(,4)
" ?5 N1 p- B& b  k+ U7 p. z5 S2 C: v, c$ F, \3 u( c+ y) y* }+ g
                                Resubmitted flow: unchanged
9 \% F2 e/ k6 s. W6 R                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 5 ~7 E% B4 ?8 z' E/ d
                                Resubmitted  odp: drop 7 {' u+ C/ C# B6 E* c( B4 q! `# d' X
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
$ ]9 Z2 \8 q4 D- Y9 V) F                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
) {3 i! S4 B# Q                                skipping output to input port& S9 G" Z7 V1 F" C

3 M$ W+ Y; m6 K* R) dFinal flow: metadata=0,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000 ( D7 A4 y" \9 d
Relevant fields: skb_priority=0,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:f0/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no $ M' R6 V# a) E9 x
Datapath actions: push_vlan(vid=30,pcp=0),10,pop_vlan,137 j1 Z, f3 K- }1 e! e' ~

) m, a+ [. d$ ^( |/ l接着我们测试mac learning
" P) a* L" |& |  O, A. F$ O/ P9 l/ t, A
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=30,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01 -generate   
" t/ G$ L8 A" ?, a$ z+ F4 ?, o4 u; xFlow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000 / n6 D. D; {/ h: w
Rule: table=0 cookie=0 priority=0
9 N; {- T4 P% v8 d5 ^- GOpenFlow actions=resubmit(,1)
- n: g: O$ Y* V/ k( Q/ Q: k0 [. @+ Z: v
        Resubmitted flow: unchanged 0 f% d! a' {# C" i+ ~! H- l
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 2 f" `, J  A; s& s' Z6 x
        Resubmitted  odp: drop ( M  h$ S; X5 L5 X; J* d7 P
        Rule: table=1 cookie=0 priority=99,in_port=1
3 L/ W5 l/ |% h8 A" _0 n% W        OpenFlow actions=resubmit(,2)& `- x, ]4 L2 e
* a; H3 P# i4 z, x6 h7 I) s
                Resubmitted flow: unchanged : ]6 `' b% y( l
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
# D9 \4 x+ C# J6 ~7 D& a5 H& K                Resubmitted  odp: drop
- w' X8 T/ p% m8 e5 ?                Rule: table=2 cookie=0   j  G$ j+ B- N! F0 L0 F
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)# \/ x7 X6 V& E5 @% e; O

' P) A- U+ d: t) ]                        Resubmitted flow: unchanged
! Z% J) D0 h* \  [                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ( S+ Y, \- H; ^1 O4 d! d
                        Resubmitted  odp: drop 7 l" r% J2 N. F2 _! {3 e
                        Rule: table=3 cookie=0 priority=50
0 {+ z/ n( |4 t9 d. k, p                        OpenFlow actions=resubmit(,10),resubmit(,4): q) s% N4 w) P0 a+ l( f# e% w0 c% x

! n3 b! k8 J8 |" \                                Resubmitted flow: unchanged
" j+ O( X& n" U8 F: W* q% U0 {                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 2 [1 _9 R. b. I
                                Resubmitted  odp: drop 3 T6 S, x  p) Z6 P* L: i# L% j
                                No match
; r8 q! f  d; `4 b# [0 A6 U
: K! E* F9 _2 |1 q                                Resubmitted flow: unchanged   g) v3 D) p- }) G9 _
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & E& _9 @) a; L# @2 K
                                Resubmitted  odp: drop
4 M0 ]9 A( i: k# j1 }                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 " x& G4 e$ @3 e; K  ~
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
0 t1 l) `3 k1 e1 x                                skipping output to input port4 ?6 q. t! h- v" J; g

. y  j* q5 a/ |Final flow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000
' D6 l5 i) E6 Z0 z# {Relevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000,nw_frag=no 6 Q$ g5 a( ?9 ^; q- b2 @1 K
Datapath actions: pop_vlan,12,135 d0 c4 T4 X1 [/ T

, R4 V5 ~6 J* ]0 n$ c6 d由于这两个地址没有出现过,则除了进行学习以外,广播发送给port 3,4( H7 N4 y) U# X3 t

* }- m3 A1 B! _# o$ sudo ovs-appctl ofproto/trace helloworld in_port=4,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01 -generate   # n4 w$ e4 m$ \
Flow: metadata=0,in_port=4,vlan_tci=0x0000,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01,dl_type=0x0000
7 a. v" q9 o7 E4 l7 D8 gRule: table=0 cookie=0 priority=0 - i+ x2 l* S) }+ g/ T) \( d1 _; C: ?
OpenFlow actions=resubmit(,1)
" \5 J1 }/ r' t9 R9 Q6 \9 W% C# Q# J4 ?/ e
        Resubmitted flow: unchanged 0 ~9 R  h  O: n% X% {
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
* F3 h9 M) }. a, R3 ^        Resubmitted  odp: drop 7 h2 W1 ]4 {/ Z2 N6 f
        Rule: table=1 cookie=0 priority=99,in_port=4,vlan_tci=0x0000 / L  y/ O( N/ L9 ^
        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)
' p5 F  L3 A. n0 V( W% i4 G1 n) F7 N
                Resubmitted flow: metadata=0,in_port=4,dl_vlan=30,dl_vlan_pcp=0,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01,dl_type=0x0000 , Y8 T8 c1 _  {6 D
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 # d/ ^) }/ |1 \* @
                Resubmitted  odp: drop 6 D8 i" N# d8 T; ~9 o
                Rule: table=2 cookie=0 ! T3 T& H5 \- A  o" R
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)% `; o5 }' ~( W2 D

) J8 E1 h4 ]8 C1 b1 ~1 c' Z                        Resubmitted flow: unchanged 7 {& k1 S( ~4 K. e
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
0 L4 ~' C" E- d6 i2 d* e; d                        Resubmitted  odp: drop / B, H* p; I, f
                        Rule: table=3 cookie=0 priority=50 7 o: O1 l/ |" @8 i1 t4 P# X
                        OpenFlow actions=resubmit(,10),resubmit(,4)1 k& |; @5 r; |0 [6 e
9 L( s7 b4 d$ A' K+ U$ h2 \
                                Resubmitted flow: unchanged
* }( G8 b0 X5 A6 ]                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
5 g; y( }& R4 f# ?                                Resubmitted  odp: drop
. a) n( b8 a6 S) {( x                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=10:00:00:00:00:01 * \6 l' U0 }; P$ ]# \; {2 y
                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]9 a% T) f" x7 v' q

, P3 E# s" w) S' t8 Z9 D" g) c" S                                Resubmitted flow: reg0=0x1,metadata=0,in_port=4,dl_vlan=30,dl_vlan_pcp=0,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01,dl_type=0x0000 * J; p1 \% E3 f' T" s
                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 8 H! @' W5 j5 [4 S2 K; N/ d+ G( p, a
                                Resubmitted  odp: drop
: P- s: v4 g/ |7 g6 m  l) ]& @* f                                Rule: table=4 cookie=0 reg0=0x1
. b) i2 E9 ?5 e9 i                                OpenFlow actions=output:11 Q3 N. `' X$ ~, G
' n) W% W0 t" M0 Q7 _9 ~" l# R- K
Final flow: unchanged
8 H: q: j  b5 gRelevant fields: skb_priority=0,in_port=4,vlan_tci=0x0000,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01,dl_type=0x0000,nw_frag=no - T. W5 ^6 q& X& o4 t* `0 _+ v+ I4 Z
Datapath actions: push_vlan(vid=30,pcp=0),10
4 i3 M. o1 {4 e/ Z/ o7 x+ n1 B+ @, \6 X' u# y
回复的时候,由于学习过了,则仅仅从port 1发送出去。
+ A3 z2 Y+ R" m) `1 t9 f3 |. I
, N/ i7 ?9 b: i0 u9 p* ]$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=30,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01 -generate & h7 Z- ]6 ^# j/ a$ i5 s- m
Flow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000 7 G8 `3 J* N; k. ]. M& E
Rule: table=0 cookie=0 priority=0
/ T! R6 ~0 z3 v# Q9 ZOpenFlow actions=resubmit(,1)
4 W) S6 i; m9 Y$ [* c: {4 W& `+ X5 w, F; n- a: x
        Resubmitted flow: unchanged & Q; o$ o. L6 a6 [% {% u2 M: \
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 + c' S1 m2 [2 H2 F
        Resubmitted  odp: drop
( E7 j7 G$ _) G- J0 Y+ ~- T6 a' S$ V        Rule: table=1 cookie=0 priority=99,in_port=1 2 r2 ~2 ~! P4 ~  \4 F/ G
        OpenFlow actions=resubmit(,2)6 I  [4 v+ A& u( C

+ I- L7 Z% s5 h3 Y0 ?/ V                Resubmitted flow: unchanged   v  j; ]! u1 {( _8 q& L" s- I5 C
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
3 e( W% h: A7 ~% W) V& g                Resubmitted  odp: drop ( n% ?) g6 N& \
                Rule: table=2 cookie=0
0 E! ]( Y, n9 Z4 P% f# p                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
7 L; B! A% M: ?' c" O7 r
- f& q7 w" |: c1 t                        Resubmitted flow: unchanged
% L" T; L1 o' e, ~                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
7 ?7 `4 V. _4 f6 \  [                        Resubmitted  odp: drop
8 |' ]) K' e0 S2 h# ?                        Rule: table=3 cookie=0 priority=50
7 k1 O. _" p, z! H' J# F+ J                        OpenFlow actions=resubmit(,10),resubmit(,4)6 J0 L8 R$ F8 ~6 y$ g* ~, U8 c

, P0 X' T7 V2 O9 D8 X                                Resubmitted flow: unchanged   p9 u  z- I: S" o% K2 W9 ^# i
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0   X4 ^# `! |, V, I! U5 h
                                Resubmitted  odp: drop ! P$ R7 [1 G/ ~8 S( \6 |1 C
                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=20:00:00:00:00:01
- u! G8 N. v+ A$ p3 @" u3 o                                OpenFlow actions=load:0x4->NXM_NX_REG0[0..15]1 q/ e7 b" K8 ~' g; Q# V/ c- r

7 _2 ~4 `3 t9 X& q! @                                Resubmitted flow: reg0=0x4,metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000 0 o1 u' y, n7 i: D8 }( X. {  c
                                Resubmitted regs: reg0=0x4 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 / S- l0 r4 I* H9 o3 [3 b2 f+ r
                                Resubmitted  odp: drop / j; w' @8 `1 d5 W, u
                                Rule: table=4 cookie=0 reg0=0x4
! }% T5 @: f, `4 b5 V+ d2 o; w                                OpenFlow actions=strip_vlan,output:4
2 d- a, |0 J! i# ~5 N4 ~
  s) J9 s2 O$ m  KFinal flow: reg0=0x4,metadata=0,in_port=1,vlan_tci=0x0000,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000
" V" b& I9 J6 ?Relevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000,nw_frag=no 4 Y+ A1 @/ q2 D' ^& s
Datapath actions: pop_vlan,13
+ A% T! a, F3 J' A1 e
! \7 i  V5 m. v% n/ v) l& L由于在回复中进行了学习,因而发送的时候,仅仅发送port 4

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2019-10-25 10:00:36 | 显示全部楼层
实现第一个Table 0,Admission control
! h% R/ R( t+ j/ ?0 f3 J4 r& b. v3 U% ~4 X$ f' T# _4 B3 r" K" g
包进入vswitch的时候首先进入Table 0,我们在这里可以设定规则,控制那些包可以进入,那些包不可以进入。/ w" k+ A; u# _, \+ k8 Q
  S7 G- c$ ^5 j9 b: f4 _: V) M9 O
比如,如果source address是multicast的就不允许进入。2 B: h) K$ u; a9 N
; P$ e, [" h/ I' e. i( `' y" X
01:00:00:00:00:00/01:00:00:00:00:00是广播地址+ d1 b# K! B  m; Y* s% r- U
00:00:00:00:00:00/01:00:00:00:00:00是单播地址
) }0 {& [$ l7 [- V这种表示形式类似CIDR
' @# @  v5 K' O3 T' |3 z于是我们添加下面的规则:
9 f8 }* s# R# d! {' Usudo ovs-ofctl add-flow helloworld "table=0, dl_src=01:00:00:00:00:00/01:00:00:00:00:00, actions=drop"
' C, ^/ {0 e! fSTP的也不接受/ S% n7 C1 F3 Y8 X
sudo ovs-ofctl add-flow helloworld "table=0, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0, actions=drop"
( P6 \. v. h( E  u* x3 m" ^我们在添加最后一个flow,这个flow的priority低于default,如果上面两个不匹配,则我们进入table 12 g" `/ A- O% m% e
sudo ovs-ofctl add-flow helloworld "table=0, priority=0, actions=resubmit(,1)"
. O/ s3 D. X1 Y  g1 Y" h) Z  X我们查看一下所有的flow3 {* {: F' U! M2 K! ^
$ sudo ovs-ofctl dump-flows helloworld        
, i2 _  V0 [6 \6 h* o7 @* _" WNXST_FLOW reply (xid=0x4): 4 y( T& m6 i' B7 q" w
cookie=0x0, duration=42.162s, table=0, n_packets=0, n_bytes=0, idle_age=42, priority=0 actions=resubmit(,1) 4 u  P: E  O9 U  t4 V% Z6 h
cookie=0x0, duration=232.121s, table=0, n_packets=0, n_bytes=0, idle_age=232, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop 6 A( B- v# @6 z  [8 ~( Q
cookie=0x0, duration=167.636s, table=0, n_packets=0, n_bytes=0, idle_age=167, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
) J! g- K: _( h. q, w5 P3 G5 X+ R: l% c
测试Table 0
' j1 V" n+ Y: ^  F' W* Q7 S$ n+ A6 _3 q  M; ?  Y
有个很好的工具ovs-appctl ofproto/trace
; K9 g( [% q1 y2 C- F! w5 r
* J% q  d" s8 o+ |1 r- q不满足条件DROP8 t" d/ \, C. h- r) U$ \
2 a+ W5 J8 ]" r
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:05
: C9 X+ H3 s; vFlow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=01:80:c2:00:00:05,dl_type=0x0000
2 T$ D, K" `$ s( `" _" hRule: table=0 cookie=0 dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0
2 i- D- l' [9 YOpenFlow actions=drop4 g$ Q2 ~' X5 N* [6 r
* e) h5 K. H6 r1 C: |6 x6 F# y
Final flow: unchanged
( s* V3 `0 q& n. v: tRelevant fields: skb_priority=0,in_port=1,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no ' E; z8 d3 |; n7 V8 ]2 P
Datapath actions: drop
& h$ j: B( n* m, C5 v) }% L, Y+ j3 ~0 \/ R+ d
满足条件RESUBMIT# B- H2 f1 L& v: R  c4 ?
7 f& }( u$ ~! g- @6 t7 o  N, L+ E
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:10
$ m' t' H5 B0 b7 I4 r  _$ a7 cFlow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=01:80:c2:00:00:10,dl_type=0x0000
/ l3 k6 V$ S6 {1 V2 Y! ERule: table=0 cookie=0 priority=0
6 }3 b  V( W- t4 c) oOpenFlow actions=resubmit(,1)
2 x0 B2 X+ Q$ g6 K: q
7 j% [1 m3 z  b: `, z+ J. ^        Resubmitted flow: unchanged
" M& C" b( {0 r1 [5 ]        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 6 }9 E7 n1 {/ r+ o$ K0 _
        Resubmitted  odp: drop
4 k$ [0 K2 ]# e/ ?/ i        No match6 l( e, F$ X- L+ Y, ]4 B3 P! m

! ~8 N' _+ o1 Y- hFinal flow: unchanged
8 X: I8 }7 P; n# I7 F( P- HRelevant fields: skb_priority=0,in_port=1,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=01:80:c2:00:00:10/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no $ s! a& {/ r, |2 t  ?6 F
Datapath actions: drop# C! P) ]1 ?& M/ a# B
- T! K% F) {( d4 T; }
实现第二个Table 1:VLAN Input Processing
7 M& u0 p  ~' b# }9 u
& @! G7 |0 z. d+ }8 v  p/ }首先添加一个最低优先级的DROP的规则6 Z0 l+ c1 a+ p# l; G! |

- G  D- D7 I" k" E4 ^  Ksudo ovs-ofctl add-flow helloworld "table=1, priority=0, actions=drop"
% M) ?1 v- S! V2 z% k7 v* ^& {- I, ]8 P7 l6 \8 D
对于port 1,是trunk口,无论有没有VLAN Header都接受。
* w: T: N; I9 o2 W$ S
/ T6 U! F' n4 }# M9 {sudo ovs-ofctl add-flow helloworld "table=1, priority=99, in_port=1, actions=resubmit(,2)"% u  L$ k; ]$ a! G; l- G6 ^+ `
# x9 i: p3 m! ~( n) Z, g
对于port 2, 3, 4, 我们希望没有VLAN Tag,然后我们给打上VLAN Tag
* e% ]7 a, q' P' Y3 T: r- _' ^5 q
$ sudo ovs-ofctl add-flows helloworld - <<'EOF' ; l' L+ n' _) U
table=1, priority=99, in_port=2, vlan_tci=0, actions=mod_vlan_vid:20, resubmit(,2) ) }% Q6 N: ^4 d
table=1, priority=99, in_port=3, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2) # ^. l. Z, m  E1 l0 N
table=1, priority=99, in_port=4, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2) 1 O. j& P5 }9 I9 t* T! @
EOF7 S! I3 ]# @+ ~+ p
% D8 h. o& Q) B$ v2 j8 [; L) c
$ sudo ovs-ofctl dump-flows helloworld
4 }' w5 h% t7 [$ M7 u! {NXST_FLOW reply (xid=0x4):
3 ?9 s, d& _/ K% Bcookie=0x0, duration=4478.582s, table=0, n_packets=0, n_bytes=0, idle_age=4478, priority=0 actions=resubmit(,1) ) Q8 ]7 R% ]0 n7 m0 ^
cookie=0x0, duration=4668.541s, table=0, n_packets=0, n_bytes=0, idle_age=4668, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop * z" H  m5 C) C
cookie=0x0, duration=4604.056s, table=0, n_packets=0, n_bytes=0, idle_age=4604, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop 5 G. V" X, ^7 p' |* R: B! O
cookie=0x0, duration=89.273s, table=1, n_packets=0, n_bytes=0, idle_age=89, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2) 3 b9 e3 _- l7 j9 c3 g; q
cookie=0x0, duration=89.273s, table=1, n_packets=0, n_bytes=0, idle_age=89, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
2 x9 H1 ]1 b4 K9 b$ @: Kcookie=0x0, duration=89.273s, table=1, n_packets=0, n_bytes=0, idle_age=89, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) - I* I+ X1 U3 D: h: Z
cookie=0x0, duration=220.318s, table=1, n_packets=0, n_bytes=0, idle_age=220, priority=99,in_port=1 actions=resubmit(,2)
, A# @- s6 [7 p' ycookie=0x0, duration=298.739s, table=1, n_packets=0, n_bytes=0, idle_age=298, priority=0 actions=drop6 E9 `" R3 P) m8 ~, d& a; |

% n. }1 F! E6 G测试一个从port 1进入,tag为5的/ b- B3 O( N- h$ G0 B4 v2 c
* o/ k' t7 E( d1 M, r
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=5
1 l$ b, V! b; Z7 x! i$ xFlow: metadata=0,in_port=1,vlan_tci=0x0005,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000 3 D2 z. V4 G3 Y. v" r* h
Rule: table=0 cookie=0 priority=0 1 ?$ V4 _, Z( k2 l/ d; _7 w
OpenFlow actions=resubmit(,1)( U' s" G1 H8 k: k$ @
5 R  X1 o* H- ?4 d
        Resubmitted flow: unchanged # G8 S3 o+ b1 x$ q
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 # P. c" R, U" k) D: \) P  j& U; X5 ?
        Resubmitted  odp: drop 9 n( ]& {. l8 `6 B4 r* y/ `' ]
        Rule: table=1 cookie=0 priority=99,in_port=1
  m/ M' t& U' T1 D        OpenFlow actions=resubmit(,2)
6 I- B4 u  j( G& Z1 U& }" m/ W2 S# K! b0 A( }" t
                Resubmitted flow: unchanged # {0 {3 }9 h' e  ^
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
$ h6 w$ b( _( W. T+ L% [                Resubmitted  odp: drop 9 V- e5 [; a( t5 _6 J# {  c# W  Y$ {
                No match  |6 _: B5 p0 w0 a% G8 E% B) g

/ }) @, R# T8 @3 r7 S1 {Final flow: unchanged 3 J# e9 K2 t( v" `. p7 {$ m
Relevant fields: skb_priority=0,in_port=1,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
0 w3 k2 y4 f! r. V+ C" p5 wDatapath actions: drop9 z  `/ B! f; T5 g9 M9 K3 F+ i
% |% X7 O0 R, s) h
测试二,从port 2进入,没有打Tag的
2 w4 l5 w4 a% y' ]& @& r7 B
" w& q4 o' N  ?) U& \$ sudo ovs-appctl ofproto/trace helloworld in_port=2 ) t; b; m( X$ b- w$ O0 C
Flow: metadata=0,in_port=2,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000 - c8 ^) m1 c: }' @; R# `+ L& n
Rule: table=0 cookie=0 priority=0 5 p1 d. T- v0 v( e; V- l" X1 W
OpenFlow actions=resubmit(,1)
5 A6 i3 X$ K& M9 e5 ]
9 m0 o$ d  n. `0 F7 y2 J& i        Resubmitted flow: unchanged
0 G( R! \! U' R3 t        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
7 P) b- _, c" w1 G9 V        Resubmitted  odp: drop
0 U3 k! S0 x  b1 y' ^/ _        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 + l1 p1 \7 P: n; v- B
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
- c7 {7 {) ?+ v: |( z* f3 `% a$ t7 S# d: P- v
                Resubmitted flow: metadata=0,in_port=2,dl_vlan=20这里被打上了Tag,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000
8 a; {2 }( ~8 _+ |/ v7 ~                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 $ X, h" a( a: i/ c' |- l
                Resubmitted  odp: drop
  |: b0 M- a+ d1 D+ x                No match
  V; s) j3 C% h3 D/ N0 M" E6 H' \+ r; y+ z6 u  |4 j% x) w/ w
Final flow: unchanged % A7 E: w& p' p' m. x8 C
Relevant fields: skb_priority=0,in_port=2,vlan_tci=0x0000,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no 7 f0 I! J3 i/ T7 a
Datapath actions: drop
  }1 ~  X% e9 u+ H& C, z! Y+ _7 S$ I! r* L- ~
测试三:从port进入,带Tag 5的
/ L8 x/ _# \; t+ P
1 A- H- x/ F6 K- ^3 @) Z$ sudo ovs-appctl ofproto/trace helloworld in_port=2,vlan_tci=5
( ^+ Q* u. }/ w* Y' e, jFlow: metadata=0,in_port=2,vlan_tci=0x0005,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000
% A5 e  ?* _' M: @' K3 xRule: table=0 cookie=0 priority=0
" j+ k8 K: x: y( `+ @! IOpenFlow actions=resubmit(,1)$ ^' O9 E6 `* S( w* e' w  l+ w: j

, B  ^' g/ O) c% l5 n  k        Resubmitted flow: unchanged 4 f8 S# x( ]- K8 x
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 " m5 K2 i( a* }, P; L4 k' L9 N& \) t
        Resubmitted  odp: drop - [2 y; v! j1 z0 }
        Rule: table=1 cookie=0 priority=0 2 R- R, M/ P+ Y' r% }1 H# H  J2 V# Y
        OpenFlow actions=drop5 ]' a) R7 G" |, b( R( Q

! f4 \; _; J. S; C! XFinal flow: unchanged ; d- \2 t8 K  c# }9 {& f1 w- n
Relevant fields: skb_priority=0,in_port=2,vlan_tci=0x0005,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
1 G/ Z' o; E7 B, w8 ODatapath actions: drop/ e% ~* o7 P+ O% p$ t4 K5 R

7 C3 G& J/ z+ ^0 p; V6 z. _0 b实现第三个Table 2: MAC, VLAN learning for ingress port
3 O" t7 F: v5 ?# w* |  W
9 U4 }$ l5 W) o% P9 y3 S对于普通的switch,都会有这个学习的过程,当一个包到来的时候,由于包里面有MAC,VLAN Tag,以及从哪个口进来的这个信息。于是switch学习后,维护了一个表格port –> MAC –> VLAN Tag。& h- S6 S. i* z/ z

4 b; G2 ?  q. |4 E  o这样以后如果有需要发给这个MAC的包,不用ARP,switch自然之道应该发给哪个port,应该打什么VLAN Tag。; ?) b1 @& u1 B% H" q% C
* l2 f4 G$ x9 U9 M# X: r# }1 Y
OVS也要学习这个,并维护三个之间的mapping关系。
) U3 e, q0 ^0 k8 Q
4 Z0 J, c# I1 Z. |$ A: s6 E在我们的例子中,无论是从port进来的本身就带Tag的,还是从port 2, 3, 4进来的后来被打上Tag的,都需要学习。8 Q) x/ o9 g& n0 X
2 |0 u' b! h! y' Z
sudo ovs-ofctl add-flow helloworld "table=2 actions=learn(table=10, NXM_OF_VLAN_TCI[0..11], NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[], load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]), resubmit(,3)"
$ M8 J1 C) I& n8 `7 t, X& x  s" p- T  x. ?- Z, A
这一句比较难理解。( P9 z) W; R1 N- t

% X2 A  A4 h3 h# plearn表示这是一个学习的action
: m  s$ X& N6 M
& M. |4 F+ q: s; gtable 10,这是一个MAC learning table,学习的结果会放在这个table中。
, C* h& T1 }) x# B
( x7 w3 ]3 N: @9 I- @NXM_OF_VLAN_TCI这个是VLAN Tag,在MAC Learning table中,每一个entry都是仅仅对某一个VLAN来说的,不同VLAN的learning table是分开的。在学习的结果的entry中,会标出这个entry是对于哪个VLAN的。
+ @6 @, h/ w7 m) y
7 b% W* t$ w9 b# z- N0 D. }NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]这个的意思是当前包里面的MAC Source Address会被放在学习结果的entry里面的dl_dst里面。这是因为每个switch都是通过Ingress包来学习,某个MAC从某个port进来,switch就应该记住以后发往这个MAC的包要从这个port出去,因而MAC source address就被放在了Mac destination address里面,因为这是为发送用的。
% u) Q9 J; ]% X2 O
" i( u2 w4 I( [1 c  F4 w! P! lNXM_OF_IN_PORT[]->NXM_NX_REG0将portf放入register.5 y' N; e- U' V2 J
% u" w- _$ U* F* F6 N- [$ \. L  @
一般对于学习的entry还需要有hard_timeout,这是的每个学习结果都会expire,需要重新学习。7 v3 ]9 ]* q' Z; G$ D# J# A" O

- h% y# k+ E/ S, ?7 t& o) t我们再来分析一个实践中,openstack中使用openvswitch的情况,这是br-tun上的规则。
5 Y2 \9 `8 g) {" P, ~+ D: D+ t1 @8 d
cookie=0x0, duration=802188.071s, table=10, n_packets=4885, n_bytes=347789, idle_age=730, hard_age=65534, priority=1 actions=learn(table=20,hard_timeout=300,priority=1,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:0->NXM_OF_VLAN_TCI[],load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[],output:NXM_OF_IN_PORT[]),output:1
& R% Z8 g2 j  Vcookie=0x0, duration=802187.786s, table=20, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,21) $ i5 U! c/ B; N. N% o+ \, l4 ~. _  I
cookie=0x0, duration=802038.514s, table=20, n_packets=1239, n_bytes=83620, idle_age=735, hard_age=65534, priority=2,dl_vlan=1,dl_dst=fa:16:3e:7e:ab:cc actions=strip_vlan,set_tunnel:0x3e9,output:2
& b: ^# g) [+ D; `1 l' @cookie=0x0, duration=802187.653s, table=21, n_packets=17, n_bytes=1426, idle_age=65534, hard_age=65534, priority=0 actions=drop 0 k. M" ^4 J1 X  H$ g* g
cookie=0x0, duration=802055.878s, table=21, n_packets=40, n_bytes=1736, idle_age=65534, hard_age=65534, dl_vlan=1 actions=strip_vlan,set_tunnel:0x3e9,output:2# N% }! E5 q( {' g7 h" J
* _7 V# c; T/ [6 n& p! D* |
这里table 10是用来学习的。table 20是learning table。如果table 20是空的,也即还没有学到什么,则会通过priority=0的规则resubmit到table 21./ h" Z- d; c  U! b# l
( g9 j. }+ z2 j8 }
table 21是发送规则,将br-int上的vlan tag消除,然后打上gre tunnel的id。
7 p! P" R. g* d' R2 P- ], e$ s: F/ C, q& @* w  R+ J- Z/ m! m  i; k
上面的情况中,table 20不是空的,也即发送给dl_dst=fa:16:3e:7e:ab:cc的包不用走默认规则,直接通过table 20就发送出去了。; ^" ?& [+ [& v5 d( H

# u: I; I, H- X$ n2 Ktable 20的规则是通过table 10学习得到的,table 10是一个接受规则。最终output 1,发送给了br-int. h+ v; E  B9 w! y
9 ~+ [: t+ Y5 P+ o3 x. m( Q
NXM_OF_VLAN_TCI[0..11]是记录vlan tag,所以学习结果中有dl_vlan=1
& [7 F2 R2 S, H5 r+ W8 P
( F! S/ g3 b2 `0 W' D" B0 Z: K1 XNXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]是将mac source address记录,所以结果中有dl_dst=fa:16:3e:7e:ab:cc
  A+ Q  Q1 R! `; a+ F: r; s$ ?+ N! T
load:0->NXM_OF_VLAN_TCI[]意思是发送出去的时候,vlan tag设为0,所以结果中有actions=strip_vlan, j6 W$ }+ V; L5 Q  ?$ L
6 i, Z  z. }0 A& j# ~9 }3 ?2 g
load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[]意思是发出去的时候,设置tunnul id,所以结果中有set_tunnel:0x3e9( o+ j! C/ y2 t, m8 N' u" A1 z

) \# J0 b- \& f- p! L5 f7 {output:NXM_OF_IN_PORT[]意思是发送给哪个port,由于是从port2进来的,因而结果中有output:2
4 J$ v  y+ _; p: ~' R5 o( R( X+ t! p  ~' g, M' H" p
测试一:从port 1来一个vlan为20的mac为50:00:00:00:00:01的包
9 L/ Y" m% z7 ~
9 `4 Q' [. n1 g+ r1 [8 ~8 a7 q$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=20,dl_src=50:00:00:00:00:01 -generate   
9 k' E8 s6 C$ q8 ]Flow: metadata=0,in_port=1,vlan_tci=0x0014,dl_src=50:00:00:00:00:01,dl_dst=00:00:00:00:00:00,dl_type=0x0000 , Q1 u* p8 X7 t, K4 D+ f7 ]
Rule: table=0 cookie=0 priority=0 1 l9 X, q0 j0 O7 h8 Q6 v/ U
OpenFlow actions=resubmit(,1)
/ L, K" o$ |9 E7 m8 f+ |  J* o: K& o
        Resubmitted flow: unchanged . @% D. s2 C" s8 D( s- S
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
" M% N, h; y( L, o2 c+ n" {        Resubmitted  odp: drop
: D0 Y+ u6 E$ y. z* z8 G        Rule: table=1 cookie=0 priority=99,in_port=1
4 w% U+ m% M# r) K1 d        OpenFlow actions=resubmit(,2)
. z0 e" N9 p/ c) U0 V
  l( @/ a& i3 w9 M                Resubmitted flow: unchanged
5 u$ N% a$ ?! H8 _3 K                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 - G( r/ E: C- F/ ~% {( D6 y
                Resubmitted  odp: drop
0 @- L- p" {, P5 P0 D3 b  w# e                Rule: table=2 cookie=0
3 X2 O( ]! n8 K: l4 D  D- `+ }& O                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)3 }# J; P# g6 _- X
2 ]( `0 d$ N2 N
                        Resubmitted flow: unchanged 1 c& C% F! u1 g, P5 A
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 % t. H& ?% M3 ?0 c0 V
                        Resubmitted  odp: drop * _8 g0 w9 a6 ?. l
                        No match
. n4 r; F  F$ s$ o" B1 D# I& l" M4 W& L" i& f
Final flow: unchanged . k  @7 f! Z5 s% o3 s6 H
Relevant fields: skb_priority=0,in_port=1,vlan_tci=0x0014/0x0fff,dl_src=50:00:00:00:00:01,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
  }5 B" ^* Z. S* }* A1 pDatapath actions: drop
' O. e' d/ X3 u1 h$ ?1 {7 j1 y
' r" i; _0 s" A$ sudo ovs-ofctl dump-flows helloworld 0 @8 A( \, N! ?& o
NXST_FLOW reply (xid=0x4): , k! m* i3 q6 D8 d0 J
cookie=0x0, duration=90537.25s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
6 d6 e8 M0 P% ]+ x1 i' J$ {; ]# k0 Ucookie=0x0, duration=90727.209s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop
, p5 h# x) D8 e3 \cookie=0x0, duration=90662.724s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop 6 H6 s0 W# B' v2 P  `
cookie=0x0, duration=86147.941s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2) 1 J; [, K' [. a5 g/ B+ B
cookie=0x0, duration=86147.941s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) * u% g" y) U5 B% E! Y+ n5 z4 E
cookie=0x0, duration=86147.941s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
2 E3 T/ x3 U+ R' z1 S. x9 bcookie=0x0, duration=86278.986s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2)
. _$ H3 {0 Q/ m% c3 [2 mcookie=0x0, duration=86357.407s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop # u- f2 ]& @5 ]6 W3 d; w
cookie=0x0, duration=83587.281s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3) 4 q" L' S' q1 D2 Q$ B3 i% g
cookie=0x0, duration=31.258s, table=10, n_packets=0, n_bytes=0, idle_age=31, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]5 p/ m/ M) u# ]. v+ v' L

5 i2 x6 {# a: g% X  H7 ktable 10多了一条,vlan为20,dl_dst为50:00:00:00:00:01,发送的时候从port 1出去。) D, [( F% D% ~/ m4 G9 u6 h8 e

! X4 j3 i5 Z& j' _测试二:从port 2进来,被打上了vlan 20,mac为50:00:00:00:00:02
/ n( d$ ]( ~0 V9 T+ F* ?8 L* R: Q' _% Z4 V! v4 \
$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=50:00:00:00:00:02 -generate   
2 D7 ?# e/ J0 JFlow: metadata=0,in_port=2,vlan_tci=0x0000,dl_src=50:00:00:00:00:02,dl_dst=00:00:00:00:00:00,dl_type=0x0000
5 W9 \1 a6 v7 }  t; p: zRule: table=0 cookie=0 priority=0
0 f0 f* U* I5 }OpenFlow actions=resubmit(,1)5 l/ |) R* j1 l" K7 L5 @: A
4 x3 y8 d, E. B; y
        Resubmitted flow: unchanged # N( _9 O! M) a6 ]+ o% \
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 4 a! _4 A+ u9 l" l. c9 `) e
        Resubmitted  odp: drop
' L9 `" E& y5 o        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
- V8 N( d- X4 B8 W2 O        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)0 g: ~4 b: ]4 b* y+ ~
( Q5 I4 J3 m4 Z3 h6 i# y9 E6 E2 V
                Resubmitted flow: metadata=0,in_port=2,dl_vlan=20,dl_vlan_pcp=0,dl_src=50:00:00:00:00:02,dl_dst=00:00:00:00:00:00,dl_type=0x0000 / z( K) Y$ @& G& x1 ~+ j
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
  p& O# w( s2 ~                Resubmitted  odp: drop , i  N8 n# R+ @+ I
                Rule: table=2 cookie=0
& l( |+ C- @: U3 O: ~' f9 D                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)9 C+ Q* z3 @$ @* g  q

7 R1 ~. I6 F& g4 P2 s                        Resubmitted flow: unchanged
/ D/ F, i$ U8 \. m: w7 w' S                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
* q' a2 ]( E1 u  \/ f$ @                        Resubmitted  odp: drop , F* J, D) c4 w
                        No match! n- H* d, u( t

% x( B2 p( N9 S6 H/ M3 |. CFinal flow: unchanged
3 F/ D& e) B: D7 a% ^# [Relevant fields: skb_priority=0,in_port=2,vlan_tci=0x0000,dl_src=50:00:00:00:00:02,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
" @/ p( C5 K7 c$ U0 {. fDatapath actions: drop* S# s. a! u4 [, @
* z7 \. W5 j, H) k9 q
$ sudo ovs-ofctl dump-flows helloworld                                                 * I4 j1 A, J7 v6 ~: H
NXST_FLOW reply (xid=0x4): $ h0 d$ O% ?4 U2 @) E7 d
cookie=0x0, duration=90823.14s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
% |5 t+ E6 Y- r& |3 `: ~/ B) g! Bcookie=0x0, duration=91013.099s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop % M$ b. ^1 z- k. g7 y% j
cookie=0x0, duration=90948.614s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
# P* d3 j0 Q8 x4 t$ tcookie=0x0, duration=86433.831s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2)
$ F/ K9 A3 k1 y/ [4 M( ucookie=0x0, duration=86433.831s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) , D. Z; G/ s) j1 F, n9 s
cookie=0x0, duration=86433.831s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) 3 J4 O$ l4 V- t, a! y; g
cookie=0x0, duration=86564.876s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2)
/ l5 p  W, h9 c7 gcookie=0x0, duration=86643.297s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
. s6 b  v/ a8 i8 Icookie=0x0, duration=83873.171s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3) / t: m" Y! }0 {! @
cookie=0x0, duration=4.472s, table=10, n_packets=0, n_bytes=0, idle_age=4, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:02 actions=load:0x2->NXM_NX_REG0[0..15] % ^( w  Z" }* B) W( L/ B4 @
cookie=0x0, duration=317.148s, table=10, n_packets=0, n_bytes=0, idle_age=317, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]
7 }- Z) q5 ^& q5 R% c
) }; Z) P+ z" I6 v! y* o& g$ \实现第四个table 3: Look Up Destination Port
9 X% n! ^2 o$ o+ s: o3 E0 W& k2 B+ G2 d9 t
在table 2中,vswtich通过进入的包,学习了vlanid –> mac –> port的映射后,对于要发送的包,可以根据学习到的table 10里面的内容,根据destination mac和vlan,来找到相应的port发送出去,而不用每次都flood, m& }7 H* T3 e  o

3 w$ o! `. _/ L2 y6 J, |sudo ovs-ofctl add-flow helloworld "table=3 priority=50 actions=resubmit(,10), resubmit(,4)"! N. c  H; R) K

) k2 u3 x0 j, X3 r! E# ~& |7 I添加这条规则,首先到table 10中查找learn table entry,如果找不到则到table 4" h/ b2 h3 `4 W1 K7 O# k# t
! h% u9 `$ V/ J1 C: R: ?
如果包本身就是multicast的或者broadcast的,则不用去table 10里面取查找。: b! A0 }' s4 l( f: K

7 k3 J* F* P2 @; B2 `, K1 ~sudo ovs-ofctl add-flow helloworld "table=3 priority=99 dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,4)"' D9 H$ E) p3 j* K; j5 z" d: i, I: {
* [1 M9 v1 i+ ?' ~3 G! O9 n
我们进行一项测试4 C2 V- J& G+ ^- \$ G1 e
2 i7 F4 |$ x. K* A5 `! k; J, R* G. i; p
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=20,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01 -generate   
- t( p9 ?) ~3 [8 XFlow: metadata=0,in_port=1,dl_vlan=20,dl_vlan_pcp=0,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000
# p# C& l) S# O/ |3 zRule: table=0 cookie=0 priority=0 6 O, p' i2 V0 c
OpenFlow actions=resubmit(,1)
/ P- X9 |4 l' c  n* s- `; a% o# e; N  U; |1 ^9 w
        Resubmitted flow: unchanged 2 \/ Q9 b- W- D3 m
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
( e; Y) U  ~3 e; K* N# _7 c2 [        Resubmitted  odp: drop
) t, Y5 t' I5 C9 j8 @. r        Rule: table=1 cookie=0 priority=99,in_port=1
4 m0 u" G8 q- n* Q9 q& r+ Y8 x2 B# H        OpenFlow actions=resubmit(,2)
! p. C* n$ t7 h! x" Z& l8 J0 c! X: N: a2 a: i) ?
                Resubmitted flow: unchanged 3 O- P( e" S. U" f
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
- C9 a) G. A& {( X6 e; T' m: P                Resubmitted  odp: drop
5 P7 \; g6 ~0 r! C/ X+ c                Rule: table=2 cookie=0
! N5 {- H: R. W                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
0 I/ @; l3 W9 p( j, k! a/ i6 g( [# y
+ N7 R5 U6 ^5 r, u                        Resubmitted flow: unchanged
6 J5 X; D0 I# g( f                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 6 H8 |. c3 V+ H$ S2 L
                        Resubmitted  odp: drop # K/ y( \! B' f9 h9 O
                        Rule: table=3 cookie=0 priority=50 ( a& l) L, Y1 G
                        OpenFlow actions=resubmit(,10),resubmit(,4)
' x* N: |2 c# ~. ]# M" v2 L9 Y3 s: v) a- d# _  i1 a# V
                                Resubmitted flow: unchanged ! r! O& v- M; u
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 7 B" ?; m: P+ {! M
                                Resubmitted  odp: drop * I/ N8 a  E2 ?2 A
                                No match
1 @  j, V3 |2 N9 g
! d0 ~6 J7 `9 f7 R. x* S                                Resubmitted flow: unchanged 7 a/ w, C( `& u3 ]* I6 Z
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 . P6 _1 u5 s, z) J( _5 Z/ o. d0 E( k
                                Resubmitted  odp: drop ' i* e5 z4 Q# |$ v
                                No match
; C  Z% o' Q0 D' l' P4 Z% }; K
; J6 H5 U* U8 mFinal flow: unchanged ) n/ R3 ]9 \& t" T. O
Relevant fields: skb_priority=0,in_port=1,vlan_tci=0x0014/0x0fff,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000,nw_frag=no
( N: V7 q/ Q, _1 _5 _Datapath actions: drop
  J5 P& H3 J/ d8 q0 K, d  Y# `7 g# V7 v) n1 b4 I: J
由于目标地址f0:00:00:00:00:01没有在table 10中找到,因而到达table 4.
! P- ?3 ?( w5 H9 R
  E0 m% w$ W: ]" h4 R- a( b" V但是这次测试使得table 10中学习到了mac地址90:00:00:00:00:01
! o6 r- O5 d' n: t! H% x' B
  @; @7 U$ i+ W8 p: q: O$ sudo ovs-ofctl dump-flows helloworld - c7 C3 S2 f4 n( Q( ]
NXST_FLOW reply (xid=0x4): 0 y" N; l* Z) J9 V' l- m6 z5 K
cookie=0x0, duration=91588.452s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) $ H* H9 {8 G7 l. }- v+ S$ a. L- @
cookie=0x0, duration=91778.411s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop 2 c8 S4 ^. ~- L
cookie=0x0, duration=91713.926s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
- f, M6 c6 D6 Acookie=0x0, duration=87199.143s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2)
" T1 Q' l" n+ z) Ccookie=0x0, duration=87199.143s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
- z7 o3 B" y( hcookie=0x0, duration=87199.143s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)   y& o0 D9 Z' g
cookie=0x0, duration=87330.188s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2)
* n3 M8 T; K8 d, gcookie=0x0, duration=87408.609s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop $ t% I3 D! [& l! U* }$ t
cookie=0x0, duration=84638.483s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
6 M4 N; w+ R3 Q# X" V" m: u" K+ `cookie=0x0, duration=352.841s, table=3, n_packets=0, n_bytes=0, idle_age=352, priority=50 actions=resubmit(,10),resubmit(,4)
& |- c0 r1 E6 |: {/ Ycookie=0x0, duration=212.704s, table=3, n_packets=0, n_bytes=0, idle_age=212, priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,4)
1 F3 k8 v0 n0 g! M2 v# |& \ cookie=0x0, duration=117.364s, table=10, n_packets=0, n_bytes=0, idle_age=117, vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]
9 z/ [- B7 ?  \2 ]; bcookie=0x0, duration=769.784s, table=10, n_packets=0, n_bytes=0, idle_age=769, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:02 actions=load:0x2->NXM_NX_REG0[0..15]
  e1 N% d/ D7 C6 w  d0 C6 ?cookie=0x0, duration=1082.46s, table=10, n_packets=0, n_bytes=0, idle_age=1082, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]
8 z0 ]! W9 X3 F3 K5 H% j
. z9 l+ M, ?$ G7 e) ]4 d% y. X下面我们进行另一个测试' F; J3 f; I2 Z( {( o7 l

1 u+ {9 n* u# z$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01 -generate   
9 d4 I: X( ?& w2 A, Q5 I: L! BFlow: metadata=0,in_port=2,vlan_tci=0x0000,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01,dl_type=0x0000
0 s! @9 h5 H9 A5 ^7 q2 A# VRule: table=0 cookie=0 priority=0
4 i8 b/ v! o5 Z9 WOpenFlow actions=resubmit(,1)
' i2 G# J7 R% T% [8 y9 P) ?
8 w0 A. q; ~# @& E9 S* W        Resubmitted flow: unchanged
( l% o. R' o5 }5 c' Y        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ' t' Q# }. _; R9 v. s2 U6 H1 G& @; R
        Resubmitted  odp: drop
' I2 E! d/ ]; F7 \% B* g/ e        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 , F; O" H+ E6 y2 a4 e0 h
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2). O2 V3 G  J% Q8 m9 B( D4 B

$ c, K7 M: s) p4 V# r  ]                Resubmitted flow: metadata=0,in_port=2,dl_vlan=20,dl_vlan_pcp=0,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01,dl_type=0x0000
7 W7 R5 W  T2 E/ t; d# J                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
. c1 f" Q' _! t8 |' ^  q& `9 f- @                Resubmitted  odp: drop ; N& x; q% u8 H) U7 a/ i" ]
                Rule: table=2 cookie=0 ( q) W5 i% `* `  V& b7 o
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)- z& E7 H9 z1 ~7 W+ ]$ q
- {$ L0 A6 U, Y8 g
                        Resubmitted flow: unchanged   K- V; O& ]6 G' D! L
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
6 {" r. N* i9 \6 R1 S! ^                        Resubmitted  odp: drop + [) ?: T$ h9 K& O
                        Rule: table=3 cookie=0 priority=50 " k' M" N+ \; P" t
                        OpenFlow actions=resubmit(,10),resubmit(,4)
6 t* `6 D* W8 g) G7 Y& N% K6 |9 Y" O: A2 m, J; j0 Z
                                Resubmitted flow: unchanged
$ o1 ~: n4 O- T$ q( h4 }) O4 c4 o+ u                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ' ]1 s$ y  t2 ~/ [% V+ q
                                Resubmitted  odp: drop * l! w' a. D4 [3 T" S
                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01 & ~4 @# z  ^* D+ p; T  c
                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]
) F6 O+ w" o) _3 d- ~
3 N( P2 h/ ]+ y2 f/ H" {( L                                Resubmitted flow: reg0=0x1,metadata=0,in_port=2,dl_vlan=20,dl_vlan_pcp=0,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01,dl_type=0x0000 6 `- f  u) L7 O4 s( n
                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
0 o- \% M5 |5 c5 K0 M                                Resubmitted  odp: drop 3 ]3 B! W* m' k9 C
                                No match, G& b" Z* f$ Y: \1 F# a8 |$ w

; @) X: D$ d+ Z# T, YFinal flow: unchanged 7 B" \: M3 \/ U  B! S' `3 j# y
Relevant fields: skb_priority=0,in_port=2,vlan_tci=0x0000,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01,dl_type=0x0000,nw_frag=no
+ q( v$ W; {5 m7 _% t. P5 d7 FDatapath actions: drop4 i- d4 c- ^/ j* c
) W0 V' l+ B( `* j8 V
因为刚才学习到了mac地址f0:00:00:00:00:01,所以这次在table 10中找到了这条记录,这次同时也学习到了mac地址90:00:00:00:00:01
4 u8 B" D, [8 C$ F' p* {: o# `3 _  q, F: W0 L
下面我们再发送第一次的包
5 \7 V) n! |8 \% V  O6 }' x+ [6 |" W" H0 f& ?  l) N: C
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=20,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01 -generate 9 n$ E( X2 S6 G
Flow: metadata=0,in_port=1,dl_vlan=20,dl_vlan_pcp=0,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000 ! p9 T/ v1 T' v/ ^
Rule: table=0 cookie=0 priority=0 4 q  c) B8 Z7 o
OpenFlow actions=resubmit(,1)
% m1 I: O& K, ~/ _& K
# }( U1 u% B1 t" a0 J+ B        Resubmitted flow: unchanged % ^3 n3 }2 @& R3 D* ]( k7 P/ T" g1 X
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 / R" b4 E. L* p/ M% Y: a$ {
        Resubmitted  odp: drop 8 H6 J' M+ a& N3 M1 `+ E
        Rule: table=1 cookie=0 priority=99,in_port=1 ; w2 s' ^" u. {; ]; J: [" s
        OpenFlow actions=resubmit(,2)( C7 A2 j4 j# X/ q

0 f% Q4 C! s5 L& Z6 ?" T. b4 I# O                Resubmitted flow: unchanged # P  S5 h. p4 O/ w, Q6 U+ ^
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 5 T7 q4 C& r- N
                Resubmitted  odp: drop
9 p$ R5 N$ Z8 E* s# v4 H                Rule: table=2 cookie=0 1 O3 c& @" M7 M! @) a: [
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
% `# ]# y1 C9 X0 ]
0 z( B) }4 m9 P" b) N                        Resubmitted flow: unchanged / D6 ~. z4 W2 m
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! f. F! d, v; p+ a$ T2 P2 p
                        Resubmitted  odp: drop
8 `( L; v' v8 |' V' [" r                        Rule: table=3 cookie=0 priority=50
7 z5 O/ P; r# q+ \7 b                        OpenFlow actions=resubmit(,10),resubmit(,4)
0 s# x1 d7 f# j- X) i6 z3 m4 H; @
2 o0 c  S% _6 K* X  x6 l                                Resubmitted flow: unchanged 8 {6 `% T) d! q) T% _  {+ |
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
' F/ ]( s. d. Y9 r! O: p                                Resubmitted  odp: drop
/ I, I5 f7 K$ H, Z8 k' l8 {+ N; `                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01
$ _! f# ]. ^$ H# ~' }7 l                                OpenFlow actions=load:0x2->NXM_NX_REG0[0..15]
& w( \8 y5 i& h0 C! _; s
+ S$ |6 v! f9 ?' a, z& b8 R* i& x& C                                Resubmitted flow: reg0=0x2,metadata=0,in_port=1,dl_vlan=20,dl_vlan_pcp=0,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000
. G' |$ G# Z1 s+ W* j4 \                                Resubmitted regs: reg0=0x2 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
2 x' l' h% b9 m& ^$ N/ J# r                                Resubmitted  odp: drop . N: L# C* I3 K- @' Y1 ?
                                No match
; y" w; K- F" C) H$ r) X
; P% ~: I- y; X* v3 S# x+ eFinal flow: unchanged
) F7 h9 O  G3 lRelevant fields: skb_priority=0,in_port=1,vlan_tci=0x0014/0x0fff,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000,nw_frag=no
4 Y: f% D/ H2 M4 P9 LDatapath actions: drop
$ }1 Y1 t% X5 W+ a- g
! K* s/ f/ \* n4 k$ q发现也在table 10中找到了记录. ^9 M! l+ {$ D3 |- E# S  X
' U8 x- A+ [2 |: z
实现第五个table 4: Output Processing
; L: w# S# Q$ s/ E
( q/ w6 w. K0 z4 C/ w这个时候,register 0中包含了output port,如果是0则说明是flood。
5 h# M7 T+ D! I$ K* ~+ a8 j  o6 W  D
对于port 1来讲,是trunk port,所以携带的vlan tag就让他带着,从port 1出去。
& m! `* w% b# e5 v, I- s$ I6 l6 h3 s
sudo ovs-ofctl add-flow helloworld "table=4 reg0=1 actions=1"
7 w2 i! Z( }% W9 [2 q2 _$ Q
" E" l, k" l# y7 Q4 r  x4 x3 I对于port 2来讲,是vlan 20的,然而出去的时候,vlan tag会被抹掉,从port 2发出去
* T2 \6 i: H8 A' z% |6 `
, B' W& s3 K7 T* ^对于port 3, 4来讲,是vlan 30的,然而出去的时候,vlan tag会被抹掉,从port 3, 4出去
# q1 q) Q  u. F* L- v, b/ f& y3 ~2 j. A
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   
1 f, }0 m# D: x( {  {4 k; D, {        table=4 reg0=2 actions=strip_vlan,2
# E$ ~- r3 n# m        table=4 reg0=3 actions=strip_vlan,3
; l& Q. [6 I4 E: i7 k7 l        table=4 reg0=4 actions=strip_vlan,4
3 O5 V0 P0 ]) ]" c- o3 cEOF
" w: T# j0 S$ {$ q2 n- n2 s. \; e( Q# W* @; Y! p5 b$ e- U
对于broadcast来讲,我们希望一个vlan的broadcast仅仅在这个vlan里面发送,不影响其他的vlan。
3 [9 ~2 S3 K/ Y" ]) W+ o2 \4 L& d. {6 e$ b- z- ~7 ]
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   
6 G. s2 G$ M. n        table=4 reg0=0 priority=99 dl_vlan=20 actions=1,strip_vlan,2 7 _8 `9 [0 y) y5 g& e$ N6 A
        table=4 reg0=0 priority=99 dl_vlan=30 actions=1,strip_vlan,3,4 1 x, X/ p( y: J% l3 l
        table=4 reg0=0 priority=50            actions=1
+ k* D* Y+ v5 J+ P9 {4 KEOF
1 a9 @! ?% i0 V/ L5 N3 M- E& Z* p5 d2 x$ T8 M9 s5 D. y
所以对于register = 0的,也即是broadcast的,属于vlan 20的,则从port 1, 2出去,属于vlan 30的,则从port 1, 3, 4出去。
8 @) L* h3 ]+ r! n* O9 ?; Q) L; V3 e  R4 U+ q8 a- {; @$ N
$ sudo ovs-ofctl dump-flows helloworld $ a' R( [" T8 R9 B) ~" K  F4 s
NXST_FLOW reply (xid=0x4):
# t6 v* X4 F, X5 U" L! vcookie=0x0, duration=92909.119s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
4 ?6 a( U8 Z1 V" e8 Ocookie=0x0, duration=93099.078s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop 2 ?) ]( U$ X! t2 M+ s& R, g8 Q) D1 y
cookie=0x0, duration=93034.593s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
+ }6 b9 r% ]# H; ycookie=0x0, duration=88519.81s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2) 7 t2 Q" g& m' J7 ~
cookie=0x0, duration=88519.81s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
) @- a, O7 H' Ncookie=0x0, duration=88519.81s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
5 v, U: D8 n1 e4 }3 Ccookie=0x0, duration=88650.855s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2) % E* d# g! c1 W. O# ]9 z
cookie=0x0, duration=88729.276s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
7 T! Y9 n( j: a8 Kcookie=0x0, duration=85959.15s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
; `! r7 Y# t- @+ R3 G: ?+ c" fcookie=0x0, duration=1673.508s, table=3, n_packets=0, n_bytes=0, idle_age=1673, priority=50 actions=resubmit(,10),resubmit(,4)
8 A: b+ A8 [# d1 l* O  scookie=0x0, duration=1533.371s, table=3, n_packets=0, n_bytes=0, idle_age=1533, priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,4)
. y% K% l- z3 j$ C! Mcookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x3 actions=strip_vlan,output:3
7 N8 Z4 _) D/ K1 wcookie=0x0, duration=228.839s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=50,reg0=0x0 actions=output:1 1 r6 |9 G5 r( y  r6 _' W  |
cookie=0x0, duration=483.068s, table=4, n_packets=0, n_bytes=0, idle_age=483, reg0=0x1 actions=output:1
" e' k- s6 i2 S" U7 |# a4 I" @cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x4 actions=strip_vlan,output:4
" i( t, m, D/ c% u* H3 Q. ycookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x2 actions=strip_vlan,output:2
8 H# b( ~7 \1 \% Mcookie=0x0, duration=228.84s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=99,reg0=0x0,dl_vlan=30 actions=output:1,strip_vlan,output:3,output:4
: R2 X( R: {& Q! Z% Icookie=0x0, duration=228.84s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=99,reg0=0x0,dl_vlan=20 actions=output:1,strip_vlan,output:2
  v% c' D8 g6 gcookie=0x0, duration=1438.031s, table=10, n_packets=0, n_bytes=0, idle_age=1438, hard_age=1109, vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]
4 E$ I! ]2 C: p0 S, G& Zcookie=0x0, duration=2090.451s, table=10, n_packets=0, n_bytes=0, idle_age=2090, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:02 actions=load:0x2->NXM_NX_REG0[0..15] : g/ z9 m" U9 B7 ~
cookie=0x0, duration=1258.881s, table=10, n_packets=0, n_bytes=0, idle_age=1258, vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01 actions=load:0x2->NXM_NX_REG0[0..15]
; I# a- v- E& h/ ocookie=0x0, duration=2403.127s, table=10, n_packets=0, n_bytes=0, idle_age=2403, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]
1 @7 i  u( s1 ^& r5 m+ ?0 ^: S9 o
首先来测试一个multicast和broadcast
) z5 e$ F: ]' p' ^; `8 h9 }: F) ~. n8 P6 e% @! \7 ~1 V
如果是一个port 1来的vlan 30的broadcast) h0 ]1 v5 _3 x' j
/ @2 }0 W  @- B* d7 f$ R
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=ff:ff:ff:ff:ff:ff,dl_vlan=30
  `8 H, d5 `2 H( g6 F7 uFlow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000 / f* c. T( o1 x4 d) E! X
Rule: table=0 cookie=0 priority=0 , J* Q: I6 |! @; u0 w
OpenFlow actions=resubmit(,1)- {- ?0 H0 N' S5 [4 {8 l  B

' Z7 m. h; e6 J8 z; r6 `  G  I        Resubmitted flow: unchanged
2 L0 N9 @1 r5 ?  R        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
  p: K# D# n6 |7 e3 O' e; A/ N4 K; B        Resubmitted  odp: drop
4 n. @7 B4 h8 D. w/ Z        Rule: table=1 cookie=0 priority=99,in_port=1
) ]( \+ d. G4 E% Y. c        OpenFlow actions=resubmit(,2)" B9 k8 k( e" @# k% I! Y
  F$ X1 Q% b# C" V
                Resubmitted flow: unchanged ; ]0 f" D! I9 F$ U$ j/ f( `0 G; a8 m
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
4 D2 k" P- D* I2 o# j  A                Resubmitted  odp: drop , @9 g$ {4 X# _3 h. M& g6 t8 h
                Rule: table=2 cookie=0 5 h0 J4 }- H, z, X+ T9 i3 Y3 |1 G; w
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
, j6 I5 O1 X% [" }
2 m: M0 H, o# l# N2 i$ _                        Resubmitted flow: unchanged
- ]# ~# I* d7 y! ^                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
2 n$ D, H8 A# m+ u  _% r                        Resubmitted  odp: drop ) A4 @4 l5 Q7 H  j4 \( ^2 x$ V2 X
                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00
. f2 w/ L( l9 k$ @6 N7 ?                        OpenFlow actions=resubmit(,4)6 n5 r; Q3 B1 U
" ?2 S7 h- u: ]0 y7 w# d
                                Resubmitted flow: unchanged * }1 j0 E& Q3 j5 I! z
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 5 d; O3 i; a" m/ K" a/ f
                                Resubmitted  odp: drop
' e) K9 D: o# w, r                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
8 Z$ |5 J; c9 `0 U8 |. `7 N                                OpenFlow actions=output:1,strip_vlan,output:3,output:4 , e% Z/ l" H* O: }, Z7 I% D+ {
                                skipping output to input port
- C% w% L& \4 e, f' b1 B
; g0 v7 l1 n; E, V! YFinal flow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000
7 U! w3 t7 Y6 Y7 CRelevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:f0/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no ; y# w; ?4 k5 N# x
Datapath actions: pop_vlan,12,13
3 G1 L1 h1 F* ?, Q2 |$ l' ^0 E" q
! N% S( _; D: P* [2 G结果是port 1就不发送了,发送给了port 3, 4
! S" u" l7 g  t( Q  w% l  k9 o7 g3 I% k# }
$ sudo ovs-appctl ofproto/trace helloworld in_port=3,dl_dst=ff:ff:ff:ff:ff:ff " l" q- u6 ]& \$ b8 }
Flow: metadata=0,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000 * Y5 X6 V7 r% x, Q  g
Rule: table=0 cookie=0 priority=0 , ^& j; m% Y: Z) V6 @& A! X! l
OpenFlow actions=resubmit(,1), [; ]' A  k4 Z* Q

* n9 G& [; B6 _; Z- z1 |        Resubmitted flow: unchanged - O5 H% K* }9 X6 v4 i) y* F: b1 j
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 6 K0 ~- o* n+ W  h
        Resubmitted  odp: drop
% c( H- }& I+ k0 \' O        Rule: table=1 cookie=0 priority=99,in_port=3,vlan_tci=0x0000   w7 T+ m3 w+ d7 X5 H2 Q8 u3 o& M! r0 x' }
        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)' b3 s% y; }; y) b: l
3 U$ L) d6 A" ~, W7 |( P! P
                Resubmitted flow: metadata=0,in_port=3,dl_vlan=30,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000
$ r# \9 Y8 l7 m% s6 O. c                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
' n3 S5 |. w: X* x$ a( A                Resubmitted  odp: drop
1 U7 ~: u! O# h                Rule: table=2 cookie=0 0 R) t; d' k' k# V$ d- y
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)5 h1 w1 d, j$ e% [& J& ~- i/ u, X# v
$ j. _) S9 A& R2 Q& y4 D$ d* B& F
                        Resubmitted flow: unchanged 1 m8 S, }3 \6 ]8 ~  |" i9 a
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
; X2 @$ K& }; _/ X7 {8 K, s- N) c                        Resubmitted  odp: drop
) Y2 K2 R% S3 Q- n' r. E; l                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 8 W, X3 N6 D0 l) J
                        OpenFlow actions=resubmit(,4)* _. g. T. B! k! w! r2 x( U
4 s  w8 O. a5 O- o$ N1 U, `* p; Z7 Q
                                Resubmitted flow: unchanged 5 k+ ^- p- ^$ B& }) Q6 o6 f  U
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 1 |+ ]8 g" |, C: i* Q; F3 P" w1 y
                                Resubmitted  odp: drop
3 |2 n+ L  Q" ~5 n* R1 N5 ^+ c2 d4 N                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 0 q, i1 C" u1 u' ~
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4 2 p) d6 K/ h0 ]$ x7 O" a
                                skipping output to input port7 g$ Y" f4 t; V

7 ?9 C1 v& c5 b" C2 [& m$ _Final flow: metadata=0,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000 " h: x1 |% G- I5 p) n" b; U! e
Relevant fields: skb_priority=0,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:f0/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
8 P! U* F# f  w) i4 `9 Z" QDatapath actions: push_vlan(vid=30,pcp=0),10,pop_vlan,13
& j- V8 |+ N' A9 j/ ^# w8 |* b1 H- V+ ]9 l6 I4 \
接着我们测试mac learning5 r  Y- g4 D6 F8 ^
8 g+ |% a! g$ @+ L9 p
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=30,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01 -generate   4 V6 X1 K* t' O1 ~
Flow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000 2 `1 S! C: n/ I7 v
Rule: table=0 cookie=0 priority=0
; c% R: w+ x2 m6 ~; }! h0 j4 lOpenFlow actions=resubmit(,1)
! \2 ?: ]4 u4 N0 X" k5 {' X( n+ r! O: S, p+ y7 H, ]
        Resubmitted flow: unchanged
0 Q- }# j% V7 n( H4 w        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 / D, y8 ~3 {* ?- {; D. b' }3 n
        Resubmitted  odp: drop
. {, `, Q4 R, d) K3 p; h        Rule: table=1 cookie=0 priority=99,in_port=1
* h- E2 M" V5 n+ o: \        OpenFlow actions=resubmit(,2)0 i4 b5 n, U) A" `- \

3 t5 [. c) C, k! D, K8 Z- X; _2 \" ~  I                Resubmitted flow: unchanged
( C; u& ^/ |% @! @                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 $ s* H/ ^$ M8 H
                Resubmitted  odp: drop
; g& V6 c9 r0 n( y4 b" _                Rule: table=2 cookie=0
5 N8 |. y/ w. d- s' |                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)- u1 D' X  {  F% a; Y# |9 y
( ^& K5 J' S  m1 L' r( x4 u
                        Resubmitted flow: unchanged
7 j: h0 Q/ F7 `+ J$ z. F5 ]; W  B9 q+ ]                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 % d  T' S! W% Z$ e& ~  H2 \
                        Resubmitted  odp: drop
# ?0 b! [* g, H8 H9 U, Z! D                        Rule: table=3 cookie=0 priority=50
/ b9 k7 ?* O4 ~                        OpenFlow actions=resubmit(,10),resubmit(,4)
! M) K4 f: z3 W& \, I1 V  r! t% g
3 A' o" ]6 K2 J1 ]                                Resubmitted flow: unchanged 5 ]- a5 }/ h6 X- O4 {
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 6 s. M* B% C2 |( ]
                                Resubmitted  odp: drop
/ O8 l! @; k) L* x1 Y6 e8 K                                No match3 A  p/ a* h2 W

2 t* R, X: w. g% a( @/ ^                                Resubmitted flow: unchanged
& G: Y# u) {$ N# e' U                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
5 H% g2 B- H3 e3 C+ C1 `                                Resubmitted  odp: drop
3 h+ N# `% e' n2 r9 U* m$ t9 S                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 3 ?" x9 e% h; H8 ]2 P* h
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
3 C/ N+ k5 A3 ^& f- m. L3 N# z; j2 q                                skipping output to input port
+ [! H% H2 l; E' o" q7 W/ ^5 E5 c+ H( M5 Q* J1 O5 o' N  A
Final flow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000 : s- z$ B  c6 r6 O; L! u# X
Relevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000,nw_frag=no
! v& K3 G. t8 s) PDatapath actions: pop_vlan,12,13
6 x/ z6 T  e/ b! e2 f) k
$ r8 F7 U0 ?+ t* E" P由于这两个地址没有出现过,则除了进行学习以外,广播发送给port 3,4
& m. {7 T! x( p) C6 Z  v: P# g; P! v
$ sudo ovs-appctl ofproto/trace helloworld in_port=4,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01 -generate   
3 H) O9 j- [' |2 }( eFlow: metadata=0,in_port=4,vlan_tci=0x0000,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01,dl_type=0x0000 7 ^; R6 g$ Y* ?
Rule: table=0 cookie=0 priority=0 1 `, w" `, b+ Q
OpenFlow actions=resubmit(,1)
. m  X" W* q* L2 {2 L9 N9 |& z. K  O* l8 W
        Resubmitted flow: unchanged
( ?" u7 m$ ~7 Z+ z4 N7 [8 m3 l$ v        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 2 C& _  F% b/ s. C: ~! Q
        Resubmitted  odp: drop 2 W0 B& g8 f/ J0 l# w6 E
        Rule: table=1 cookie=0 priority=99,in_port=4,vlan_tci=0x0000
# C$ G$ F( b6 V3 A1 @        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)
. {- t, A% P$ ~3 D" D, B7 N" O' A" S5 ^
                Resubmitted flow: metadata=0,in_port=4,dl_vlan=30,dl_vlan_pcp=0,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01,dl_type=0x0000 2 U4 _/ q( @  D$ M- A; n
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 , [6 C$ q  r' A
                Resubmitted  odp: drop ; Q/ K% \6 U2 U8 C7 B; R1 l
                Rule: table=2 cookie=0 ! e. w$ U3 w8 F0 j
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
! B4 Q! I; h/ f3 t
  @1 m7 V8 r" h4 O( R% X                        Resubmitted flow: unchanged
+ L$ @# e! d( \. D. }                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! M# f% Y$ c* i7 N4 J
                        Resubmitted  odp: drop
( n8 G5 B7 {' [" y4 Z# u- j                        Rule: table=3 cookie=0 priority=50 - r7 k) @: O. x  }, M0 f
                        OpenFlow actions=resubmit(,10),resubmit(,4)
% b1 N/ W* \& D6 g8 @, ~8 o" d
1 o9 U' v6 i: T6 }                                Resubmitted flow: unchanged # ^0 a! u, W' _* w5 o7 Z
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ; j+ k& M8 H# l3 z# O9 A' Y6 I
                                Resubmitted  odp: drop
. D0 g- C0 e. S3 z5 n                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=10:00:00:00:00:01 7 u' O. z9 Z8 W7 S# D+ n* {
                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]6 A  Q, z; k. c
8 y2 ^& I1 G/ J# G5 c% i
                                Resubmitted flow: reg0=0x1,metadata=0,in_port=4,dl_vlan=30,dl_vlan_pcp=0,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01,dl_type=0x0000 6 V$ X- f& |- I% b$ D" d
                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
0 z) c9 Z7 `& d$ T3 N                                Resubmitted  odp: drop / e3 b0 U5 W% A" e; A* k6 r9 H
                                Rule: table=4 cookie=0 reg0=0x1 8 k- h9 O+ @6 Y7 S8 N% v
                                OpenFlow actions=output:1
! e2 _: D2 `. A9 [- ?" {4 H$ L& I
1 R7 z1 F0 t$ X7 Z8 NFinal flow: unchanged
0 t2 n6 ~; j) p2 [1 ~- B" {" ARelevant fields: skb_priority=0,in_port=4,vlan_tci=0x0000,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01,dl_type=0x0000,nw_frag=no ; S2 g# P/ }8 T6 j) ^
Datapath actions: push_vlan(vid=30,pcp=0),10
( b" b- U. @7 l6 s( f' g2 ]: z+ P2 O) [
回复的时候,由于学习过了,则仅仅从port 1发送出去。
0 P2 j2 e* m2 |/ u' G1 B$ r5 j: E9 l! G9 X2 w. O
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=30,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01 -generate ) n2 T: E# v8 d8 l, {7 V
Flow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000 # F9 u. \* D  S+ e: s1 L& b
Rule: table=0 cookie=0 priority=0
6 Z# H" @8 ?* ^9 @; ~# e" uOpenFlow actions=resubmit(,1)6 F$ ]3 i. P& L0 v3 a+ }: ?: l

- I& _! ^' B7 H" G! l) t# P* b- }        Resubmitted flow: unchanged 6 x8 g9 Y3 q- v' ]3 h4 O
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
* J7 x4 _  R; W, q6 u- ?8 l        Resubmitted  odp: drop
# t: [8 E* ^' f        Rule: table=1 cookie=0 priority=99,in_port=1 / ?0 Z% ]/ K7 y. ?
        OpenFlow actions=resubmit(,2)! J, m& n4 X' E6 H5 z

" k& j9 x' `) D7 X5 A; ]' G                Resubmitted flow: unchanged
* L& B* d! G, T0 h2 ^                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 5 {; a9 x+ K: C, P
                Resubmitted  odp: drop ) E4 B: ^! G1 F: z  m5 u# u! Q& _
                Rule: table=2 cookie=0
- m; K! r" \% R$ y                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)( G& `8 U% \8 v0 F

4 X# W" p/ ]- ~7 ^+ r                        Resubmitted flow: unchanged
7 a1 [4 |" v" \( [  v9 J. X                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
# @3 \0 Y$ Q: D+ t% X$ r                        Resubmitted  odp: drop , F, s/ B, Q/ @3 H
                        Rule: table=3 cookie=0 priority=50
& F: r! J# W% {* B- q+ h' b                        OpenFlow actions=resubmit(,10),resubmit(,4)
5 S( D8 l2 A: O; y$ N$ x5 _6 B
7 e/ @" @- d2 \2 u                                Resubmitted flow: unchanged   @; i, f4 l/ i5 l/ p4 N
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 8 ~4 [+ _3 {# L& v: V0 u5 W
                                Resubmitted  odp: drop 4 W) n! F6 k3 T/ f! y
                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=20:00:00:00:00:01
9 w7 m6 n7 ~; Z* n                                OpenFlow actions=load:0x4->NXM_NX_REG0[0..15]) u, f+ m: L7 q2 K) T2 f8 e3 [& w

$ a( d) g7 c6 w8 C5 s2 @                                Resubmitted flow: reg0=0x4,metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000 $ [! s. p4 J$ V0 o
                                Resubmitted regs: reg0=0x4 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
2 V7 E8 D% M) J/ L                                Resubmitted  odp: drop - t6 [; }  V' H
                                Rule: table=4 cookie=0 reg0=0x4
' y: V) O, I# |  f& U                                OpenFlow actions=strip_vlan,output:4: g0 @* ~5 l- q  h$ u7 `
5 L0 t) K( y( I) `6 c* r
Final flow: reg0=0x4,metadata=0,in_port=1,vlan_tci=0x0000,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000
$ p" r. Y' {1 p+ k3 O8 X1 K) jRelevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000,nw_frag=no
% j, Z8 m5 Q% f) L( oDatapath actions: pop_vlan,13; }" Y6 x4 L8 v+ o

' L3 B7 l5 J# W- K由于在回复中进行了学习,因而发送的时候,仅仅发送port 4
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 00:14 , Processed in 0.022592 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表