易陆发现互联网技术论坛

 找回密码
 开始注册
查看: 4305|回复: 3
收起左侧

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

[复制链接]
发表于 2019-10-25 10:00:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?开始注册

x
ovs-ofctl dump-ports 输出交换机的端口统计信息,包括收发包、丢包、错误包等数量。 ovs-ofctl dump-flows alubr0  
0 H& j4 M5 C! {) d  |OFPST_FLOW reply (xid=0x2): flags=[more]& u/ o+ j: m1 b; I% o% q2 P5 ^8 a
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[
8 u/ z) F6 _$ k' [3 p! j( y0..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[],re
2 S* u! F7 t$ H/ R: x$ x! {submit(,4)- i! W3 @* [7 c: o& Z" u8 \0 C
cookie=0x1, duration=1263.439s, table=4, n_packets=36175, n_bytes=26587191, priority=0 actions=resubmit(,27)
  o8 \9 y4 e: G5 h cookie=0x1, duration=1263.439s, table=5, n_packets=35646, n_bytes=26564073, priority=0 actions=resubmit(,7)' }. M. d) D9 f1 B- _' b% }5 P9 B
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
7 B$ E  M+ ^# o! z) R% _ 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=drop# h. n/ Z& j% [+ A% M6 I" n
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
4 h  O) u1 f4 E6 @: a$ n 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 action5 m) a% t! y& b0 y, J5 p3 T
s=drop
* F3 `* R" T1 l  i 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=drop1 C1 c# b; D9 E
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=drop. F4 v$ z9 A9 f* J
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
" V# \/ p  e+ ^/ y8 \ 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
, p1 k8 C% a4 ~) [+ n 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: K+ G) a0 g, T) `6 C6 D2 o: 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=
8 ?# I/ [! ?" t: `( sdrop& L9 e# C. z+ P
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=drop9 m4 A4 J1 K" N5 i
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
7 C6 z7 Z( X3 `  yop
2 |& J' J) D$ p  h' _ 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
4 B" T5 A! r: 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; p. o, X: W' K0 V) S
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
" U. v2 H8 d8 ~ 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=! D: j. S$ i6 F1 g" c& d
drop
% f" I  }* h9 s  \" e$ a 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, i; V# B0 h! X: c7 b# ]
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/ d3 Y+ t+ c2 K7 j  j
s=drop
  q0 T! A; V! x 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
0 @- [2 `+ j+ ^/ \* P# Zp5 V  u/ h+ A4 {/ v9 g1 j" M
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=drop7 K3 {- G8 C0 ^
) J6 x: {$ X4 n1 w! O2 Z" k
- `; P' ^$ I1 d( z
如果设为fail-secure mode,则初始情况下flow table是空的,否则会有normal$ sudo ovs-vsctl add-br helloworld1 / }! w, Z, K2 l5 C+ E6 G
$ sudo ovs-ofctl show helloworld1 ! z) C3 H  I: ~2 q
$ sudo ovs-ofctl dump-flows helloworld1 , B) M/ Z0 E8 {! C1 P, ]
NXST_FLOW reply (xid=0x4): + \( T0 s# K4 P5 B$ E. ?
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 & r. x* ?/ k+ H3 p
sudo ip link add second_br type veth peer name second_if    * e  F2 G& M7 s+ j
sudo ip link add third_br type veth peer name third_if      
, r6 K- x* }' E3 esudo 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
5 Y1 ^+ `5 V( E$ j' ysudo ovs-vsctl add-port helloworld second_br -- set Interface second_br ofport_request=2 ) `8 c, ]. D0 L4 s% a" W: ?8 Y: y
sudo ovs-vsctl add-port helloworld third_br -- set Interface third_br ofport_request=3 ' q- A. B( g# Q* o$ e
sudo ovs-vsctl add-port helloworld forth_br -- set Interface forth_br ofport_request=4ofport_request是指定端口号新添加的port都是出于DOWN的状态- O& s, K" m6 s- D4 C  a
 楼主| 发表于 2019-10-25 10:00:34 | 显示全部楼层
把它们设为UP/ i: j; s* _2 Y6 u7 k
4 }1 J. t0 g% \, H$ U1 B
sudo ip link set first_if up
6 U7 Y$ z) e( ~+ j/ Vsudo ip link set first_br up
( a) o& o$ n8 q8 L, _  _sudo ip link set second_br up     
9 c! d! _  P0 A$ `* o& `# o; A1 ksudo ip link set second_if up 0 Z7 S8 ^+ e) O1 C
sudo ip link set third_if up      
" I+ b/ W# `- D* ~* @9 p' @0 k0 psudo ip link set third_br up     * y# z: u$ k5 p. V6 b- _
sudo ip link set forth_br up         
- l" X5 U5 r8 u& L6 }, [! m! asudo ip link set forth_if up: ^& W) r; O' v! V( o, w' e
- ^8 {7 k4 L3 [2 A
也可以用下面的命令
1 z. I) x$ u) J8 B7 H9 ~
  A* i# V6 U, j+ @0 v0 z8 ^  N! I6 lovs-ofctl mod-port helloworld first_br up
 楼主| 发表于 2019-10-25 10:00:35 | 显示全部楼层
实现第一个Table 0,Admission control
, }% t0 v/ I9 Y/ W
$ t: F3 m3 T# @- n包进入vswitch的时候首先进入Table 0,我们在这里可以设定规则,控制那些包可以进入,那些包不可以进入。7 I. g- q* e2 _: z! x7 w

% \1 D& h  j1 }比如,如果source address是multicast的就不允许进入。$ h6 H; |2 B6 A* `- K

* i1 y$ W$ q6 {9 K" `' H. Z+ n- n! e* Q- b01:00:00:00:00:00/01:00:00:00:00:00是广播地址
0 T" n) i2 E+ x: T4 n& I3 g2 y00:00:00:00:00:00/01:00:00:00:00:00是单播地址% Z/ g$ y* k2 W3 i8 o' o
这种表示形式类似CIDR  q3 ?) |5 h7 j& V$ {
于是我们添加下面的规则:. ^3 Q( S; t/ n% p* I
sudo ovs-ofctl add-flow helloworld "table=0, dl_src=01:00:00:00:00:00/01:00:00:00:00:00, actions=drop"
7 M* o  ~% \" l  _# m( B$ `  VSTP的也不接受
, `' F- B; C: K2 |. E/ F0 {  esudo ovs-ofctl add-flow helloworld "table=0, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0, actions=drop"
& ~2 A3 `1 s+ y/ w我们在添加最后一个flow,这个flow的priority低于default,如果上面两个不匹配,则我们进入table 1
9 s6 ^6 Q% k& a+ i5 I2 isudo ovs-ofctl add-flow helloworld "table=0, priority=0, actions=resubmit(,1)"/ u" u# C" B5 J8 I  c: y
我们查看一下所有的flow1 B7 x' j  l0 K, m1 j6 z1 h( {/ @9 {
$ sudo ovs-ofctl dump-flows helloworld        
" M2 y1 ]- v/ W. L2 X+ BNXST_FLOW reply (xid=0x4):
* ^. a) `0 Y  E: B9 L% u2 _. {6 Vcookie=0x0, duration=42.162s, table=0, n_packets=0, n_bytes=0, idle_age=42, priority=0 actions=resubmit(,1) ! B/ a, R+ d3 @- ]* b! a2 X
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 : v+ R6 x# d. |
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
4 f  f0 h" T% R9 |4 Y# @( ^* C1 V* Q7 H$ u9 E: P
测试Table 0+ h4 y/ c% J! F* |3 z6 A1 N1 b

0 W; ?! ^. h7 r- }有个很好的工具ovs-appctl ofproto/trace
- T, }* @$ ~( n( H( B  Z2 c* s8 x; s) S% b0 t* l- @3 ]
不满足条件DROP# B- d7 ^9 q% V5 E8 H; ^
# m! R4 T5 [0 ]
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:05
$ U; s6 d! R, x. b" j# H1 R# rFlow: 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 ) o4 x3 @  e' H* c2 ?
Rule: table=0 cookie=0 dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 9 |1 k4 V/ d; V
OpenFlow actions=drop
8 s6 F2 g# D1 e( d! t4 C) d; [0 z0 O, c
Final flow: unchanged . d( o7 D& q, t( V, {5 l$ D
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
7 V/ _* a' T& R+ F( `+ yDatapath actions: drop: H5 P# R1 x% {# ]* I. f& ~  q

: j8 g( w4 N4 `9 r* j6 n- X满足条件RESUBMIT
& s+ I' i# r% [& H3 [6 D
; w/ l6 K1 E1 g( Q2 I# C$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:10 2 S5 r% {6 B) R" ^/ h  C
Flow: 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 , r9 m, q' C% U6 [
Rule: table=0 cookie=0 priority=0 - l; I& t4 T& c' N# e" L$ a$ j% T
OpenFlow actions=resubmit(,1)
" G" S4 w8 _. n' a$ b  O& o$ U
5 Y7 K- t" M" c2 M$ [5 V        Resubmitted flow: unchanged 7 e2 Z/ u5 ~* `9 ?
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! w4 e, R, w( n
        Resubmitted  odp: drop 8 L+ {3 ]/ L- J! \6 `  V
        No match
% g9 ~" l9 \; N& ^2 t$ f3 C7 R8 z. B# m/ V* `/ A8 R
Final flow: unchanged
2 _3 D3 @3 L2 Q# Q* aRelevant 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 1 m$ L5 `8 U4 b1 ^' D/ `& Z
Datapath actions: drop4 B- k! k/ b7 b" f& G

5 J7 D  ?6 D' e& W实现第二个Table 1:VLAN Input Processing
$ N0 V1 Z* V$ M8 {: v& k. I0 d* A
! W7 ^& @0 ?. z- O首先添加一个最低优先级的DROP的规则% G# C8 _5 J& C( a; ?
3 E. b+ S$ U2 }/ |- `0 e! ?
sudo ovs-ofctl add-flow helloworld "table=1, priority=0, actions=drop"6 S  t9 }% @8 y) X
( ~" \! \" M$ C5 j  {
对于port 1,是trunk口,无论有没有VLAN Header都接受。1 X; x4 T, J6 e, Q" e) `% @, I
! b( w1 g8 ^1 O! N6 ]5 M" U6 q
sudo ovs-ofctl add-flow helloworld "table=1, priority=99, in_port=1, actions=resubmit(,2)"
1 c* [' X8 R% N: a' H! [. B
& b$ W4 _. f% ], y. F对于port 2, 3, 4, 我们希望没有VLAN Tag,然后我们给打上VLAN Tag: x' ~) v: ^0 D& K% |/ ]

; O7 V, Z. |& q" w) o$ O6 V$ m2 E9 C$ sudo ovs-ofctl add-flows helloworld - <<'EOF' ) N) u1 S1 d# U% }' j
table=1, priority=99, in_port=2, vlan_tci=0, actions=mod_vlan_vid:20, resubmit(,2) ' f1 i' O' D! E$ u! y
table=1, priority=99, in_port=3, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2) 4 ^2 F. d' _" s) l/ X6 E* J& t
table=1, priority=99, in_port=4, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2) " g5 Q% h% }% d* K" C3 ~
EOF' p8 q7 L) e4 H0 R8 ^. a
$ [* C4 m) U' P
$ sudo ovs-ofctl dump-flows helloworld
) _! S, n2 Z3 d- ONXST_FLOW reply (xid=0x4):
5 y) [. Y# P& {8 y, C: i8 I# Xcookie=0x0, duration=4478.582s, table=0, n_packets=0, n_bytes=0, idle_age=4478, priority=0 actions=resubmit(,1)
8 A" e6 {/ P- C6 w7 R+ Y5 ~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
1 T3 E0 W9 J8 q  }, wcookie=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
. W1 x3 g' e: X& |  S- Dcookie=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) * V  t8 i6 Q) l
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)
1 n$ Q' w" `8 R* G" @; U" g5 c% [cookie=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) ! f& p( r' W  `! L
cookie=0x0, duration=220.318s, table=1, n_packets=0, n_bytes=0, idle_age=220, priority=99,in_port=1 actions=resubmit(,2)
& r" o$ ^# L0 f/ [2 Ocookie=0x0, duration=298.739s, table=1, n_packets=0, n_bytes=0, idle_age=298, priority=0 actions=drop
7 Q6 m9 T' m3 P: S# ]0 L8 o2 ?
+ |- K. R+ m: ?( o' g% n测试一个从port 1进入,tag为5的3 n1 [, d( }4 X( v2 p/ X: s
/ K/ T3 q  @% S* D( f
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=5
( O! X; W! O9 F  G2 c" [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 - D' O- q$ N8 I* K0 P
Rule: table=0 cookie=0 priority=0
6 Q5 i4 j! _- ~0 g  I. u  nOpenFlow actions=resubmit(,1)
& }+ R5 S8 q* N: w9 y7 s" ^' I" r# Y2 h) U! U: N) ~& m' }' P
        Resubmitted flow: unchanged
- u( ]) [  S( _        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 8 D4 n  q; s) u8 t
        Resubmitted  odp: drop
0 b- Y- P6 t" u, T        Rule: table=1 cookie=0 priority=99,in_port=1
* @! O$ J' U. W        OpenFlow actions=resubmit(,2)
6 B1 q. V2 d7 c7 [+ w0 R8 q5 `, H8 _
                Resubmitted flow: unchanged
( U+ B' k7 Z  N                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
- X4 F$ E$ H4 F0 @# L+ i                Resubmitted  odp: drop
0 _9 ~3 x6 @" v% m0 E% L7 X$ q3 C! w  e* \                No match
- v' L) j( g  P. p
) y" U6 N4 c" d# R* q( OFinal flow: unchanged ; ^/ a! W( l9 g% j; ^
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
$ k8 \6 v5 Z2 O/ O& b% N9 IDatapath actions: drop) q$ ]  [: ]6 g9 G
1 M& W' I6 B  G0 N6 S+ ?% Y4 d; x
测试二,从port 2进入,没有打Tag的
$ x: x  P9 d* X( N, z# A' T0 H  g* j# \$ A9 ?4 h4 b8 X4 k
$ sudo ovs-appctl ofproto/trace helloworld in_port=2 : X% }0 r0 H4 {: |
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
$ m! C( n8 U' h/ m. q: zRule: table=0 cookie=0 priority=0 ; o, l- C. g! s  |- c
OpenFlow actions=resubmit(,1)7 u1 R$ q! p( h0 V: v3 g

: w9 s) S* B$ `( r        Resubmitted flow: unchanged : [! [" n  m4 u8 }. H" ?
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! F% H7 T2 p* z: Z- P% m5 h8 G
        Resubmitted  odp: drop 0 j& M7 ?* r0 s; l# l
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 , `* A) H+ @: N" e5 a
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)% P# e. w2 R9 l7 Y7 F

2 z5 _: Y9 C, j  G: \                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
7 W7 {" ~* v, o4 d, s/ X' b3 f                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
2 g2 c1 K  Z- l- h) E: R                Resubmitted  odp: drop # f% {/ x) b  q2 n5 O
                No match$ v  w+ N8 B0 }# y
. ~0 x! C5 n# {. a
Final flow: unchanged   \& M% \, U2 a+ t4 H$ j3 n8 X( `
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 : H/ [, O' z/ J: g) E
Datapath actions: drop
3 J, X  j  _; H  K& Z. C
$ Q- A2 G$ ]+ O, g测试三:从port进入,带Tag 5的
, [4 [( N5 K. a7 G+ C
; o. M7 T) i  S) U% Q0 M3 _$ sudo ovs-appctl ofproto/trace helloworld in_port=2,vlan_tci=5
; o5 U) R3 B* L3 C2 `4 M" l8 BFlow: 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
" M1 P/ y( \" VRule: table=0 cookie=0 priority=0 ; a! s! a7 W. s! L
OpenFlow actions=resubmit(,1)
* I9 {- C3 a- W- O8 r- C* ^: @: c  w" r5 Y
        Resubmitted flow: unchanged
& m3 i" a* n4 f1 o: ?0 P        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 " a% D$ z) H9 I3 e
        Resubmitted  odp: drop 2 }# ]0 _* N' A0 O4 C+ y
        Rule: table=1 cookie=0 priority=0 % x, G  a/ H+ Z
        OpenFlow actions=drop
1 Y4 M6 s' b5 K1 }; ^8 D* K  o
% w! m. O" r5 ]1 \- ]2 a/ r8 H* |- IFinal flow: unchanged + |! b1 b" M8 E1 K1 ^  L
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
( A* b! o# c$ z2 B6 NDatapath actions: drop! z3 A4 e% Z3 w

5 F! u$ L+ c8 \  b( |$ B1 n/ N实现第三个Table 2: MAC, VLAN learning for ingress port
. ^1 [3 ^) X9 E8 ?- |2 j; G
9 O- W. r. o: x对于普通的switch,都会有这个学习的过程,当一个包到来的时候,由于包里面有MAC,VLAN Tag,以及从哪个口进来的这个信息。于是switch学习后,维护了一个表格port –> MAC –> VLAN Tag。/ R9 _0 T# O$ R. ?: m5 ?
4 d* Q- y) M' ^- G( {- o) m, ?
这样以后如果有需要发给这个MAC的包,不用ARP,switch自然之道应该发给哪个port,应该打什么VLAN Tag。
3 v: {- V3 X6 s$ O1 M: ?1 F& N
7 M  G) T& I* i1 V! eOVS也要学习这个,并维护三个之间的mapping关系。. L6 [; A% k" w& m; Y- b+ P
5 x: T* @9 l# ^/ E: F- K) w
在我们的例子中,无论是从port进来的本身就带Tag的,还是从port 2, 3, 4进来的后来被打上Tag的,都需要学习。, P6 f7 F& z  [1 {
6 x4 @5 {  ^0 m
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)". M3 @5 \2 I% V8 y
% F5 @2 b4 B; r2 @2 c3 p& Z' y, n/ _
这一句比较难理解。, X) C1 P. T; i. j* D
6 i9 u1 O8 W( L9 v
learn表示这是一个学习的action0 w2 F5 ?# B, T6 P9 @1 a

6 D- a7 Z6 A2 L0 `: a: U' K- E- btable 10,这是一个MAC learning table,学习的结果会放在这个table中。
* h4 V7 K+ n( a! ?- p2 |8 M3 n1 t1 T! r6 I! T5 y) d# u
NXM_OF_VLAN_TCI这个是VLAN Tag,在MAC Learning table中,每一个entry都是仅仅对某一个VLAN来说的,不同VLAN的learning table是分开的。在学习的结果的entry中,会标出这个entry是对于哪个VLAN的。/ M7 d0 t; q9 z/ s* P" z

1 [1 Z; ~" J: CNXM_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里面,因为这是为发送用的。
/ C$ V1 ?' m7 U' Q9 p  z' i1 ^- A0 G( d! O- J9 a- [$ N4 \
NXM_OF_IN_PORT[]->NXM_NX_REG0将portf放入register.
0 I$ t$ d1 U# z! E3 }' K$ p# J- n* ^) p
一般对于学习的entry还需要有hard_timeout,这是的每个学习结果都会expire,需要重新学习。
! T3 e1 {0 ]0 n! X: v2 B
0 ~: l3 P6 M1 V我们再来分析一个实践中,openstack中使用openvswitch的情况,这是br-tun上的规则。/ S1 B1 \" g) ]8 o) ]+ |8 T

" L4 @, ^# _3 `9 h0 W* H/ ~. y) J4 pcookie=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
2 I9 j, `$ |/ icookie=0x0, duration=802187.786s, table=20, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,21)
" j, R  C( s  T6 F: E 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 * _* u( q) Z9 F7 t3 ~3 R6 c% n. u
cookie=0x0, duration=802187.653s, table=21, n_packets=17, n_bytes=1426, idle_age=65534, hard_age=65534, priority=0 actions=drop
( O6 b  k7 c4 b8 ]0 v* t) Jcookie=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
2 o9 Z: @! `3 B( x! T! [6 g1 T# w+ R, p0 ?1 e9 K0 Z% ^# s8 G% H, G$ f
这里table 10是用来学习的。table 20是learning table。如果table 20是空的,也即还没有学到什么,则会通过priority=0的规则resubmit到table 21.# X% |2 q1 X6 X" N. \
: p% K5 c4 E1 m9 o/ }. N
table 21是发送规则,将br-int上的vlan tag消除,然后打上gre tunnel的id。
* `) y( z, A; V+ j' W) A
: Y. ^1 ~9 O, V7 k2 ^; T上面的情况中,table 20不是空的,也即发送给dl_dst=fa:16:3e:7e:ab:cc的包不用走默认规则,直接通过table 20就发送出去了。
, }( J: l* A% P" A8 P4 ~
9 D, S( k( v7 l" G5 A/ T5 ^: T5 Jtable 20的规则是通过table 10学习得到的,table 10是一个接受规则。最终output 1,发送给了br-int
0 V* y: y9 I/ `5 W
+ u4 w, ]! y8 C' E5 r( w# y  ]3 bNXM_OF_VLAN_TCI[0..11]是记录vlan tag,所以学习结果中有dl_vlan=1' Z  q$ C4 D  @  H! o; z& ^& B

7 r/ w8 k+ S. SNXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]是将mac source address记录,所以结果中有dl_dst=fa:16:3e:7e:ab:cc4 L& Q3 `2 e/ Q$ ?
! [9 w  i, b# \# y) q- D
load:0->NXM_OF_VLAN_TCI[]意思是发送出去的时候,vlan tag设为0,所以结果中有actions=strip_vlan
5 J* U4 R+ W. I9 f8 o$ t; M5 v. x; G* P% f" p* c, w
load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[]意思是发出去的时候,设置tunnul id,所以结果中有set_tunnel:0x3e9! n  U/ Z0 L# G  [( S
* _: a! g0 o: c" B
output:NXM_OF_IN_PORT[]意思是发送给哪个port,由于是从port2进来的,因而结果中有output:2
! T0 l. @' y5 a( s
6 a+ X& Z* J* D- r2 ~测试一:从port 1来一个vlan为20的mac为50:00:00:00:00:01的包
( ^! i/ u' v/ z. v" p' C# y! b* c% t. O! y0 L+ x! M7 O3 R
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=20,dl_src=50:00:00:00:00:01 -generate   3 r* Z& e% Z" g. c: i
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
5 e6 _, P' [% V: IRule: table=0 cookie=0 priority=0
" `6 L1 e% `! L& X' d: Q# q9 ZOpenFlow actions=resubmit(,1)/ d8 F; D; x3 i, b

  u6 U8 M7 e$ ^" j/ I$ o' g0 C        Resubmitted flow: unchanged - G, S' e. v! {5 O. ]
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
+ n' t  |. B) G5 V        Resubmitted  odp: drop 0 {! j& d7 |! S+ i' H) w
        Rule: table=1 cookie=0 priority=99,in_port=1
9 B- O: I( G/ U! a; \  d3 L* T) a        OpenFlow actions=resubmit(,2)7 K1 I; K: f* l- n! Y" D: z
4 S) C$ {( t' n: ~$ [# f
                Resubmitted flow: unchanged & X9 b. u: S+ v6 b
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0   N9 \5 Z; w/ K* Z- W, P, N
                Resubmitted  odp: drop
) B2 P9 a7 d0 X9 |% W                Rule: table=2 cookie=0   D' [" r6 P" ]% o( s0 ~
                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)
- C/ s% \; W8 W& D9 J, N# x+ U0 p  ]* O! Q0 c# `4 K
                        Resubmitted flow: unchanged & G( z- J# Q9 {2 t  @. P% O( z5 ?, B
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 , T' x) d% g' `/ U6 k
                        Resubmitted  odp: drop
) r3 o; Q2 J  q! W- B# |2 k1 c                        No match+ t3 \4 c- g. X. q9 K( e

) A0 ~4 x& U/ c3 y+ v: N7 R; v/ J! FFinal flow: unchanged
# \% B' {9 |  L0 @& u5 P% g6 Q7 |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
, q6 N! F$ Y5 z& H2 f9 Z# M9 l. qDatapath actions: drop+ j4 M8 ^- y' W* I4 _' n8 }

  P. }0 Q' y1 H! z% r- Q! p$ sudo ovs-ofctl dump-flows helloworld ) b; M; {& u2 T- Q+ _
NXST_FLOW reply (xid=0x4): # L# w+ e( `1 R
cookie=0x0, duration=90537.25s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
+ ]; w# v$ {, Ccookie=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
0 Y, ]6 r# q# f& p, y' `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
$ i1 P9 h9 c, X. V( S5 u" l$ Ycookie=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) * |" h" a6 M7 H6 d2 {& k
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)
" E  `# l  d( f3 Rcookie=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)
: A( z1 X6 T* d, Q/ P* m* qcookie=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) 7 F3 j" P' N" ]" s# P8 Z' d2 J, O
cookie=0x0, duration=86357.407s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop ; n& k/ G& l  \! H2 ~- O9 N
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)
- g7 v. M) a. f 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]
+ ?1 P- W! c' T5 Q* c! \! J% Z$ q1 h$ f1 E# D
table 10多了一条,vlan为20,dl_dst为50:00:00:00:00:01,发送的时候从port 1出去。2 |9 K9 g0 [" [  _
* t; L& N4 {8 x$ ^
测试二:从port 2进来,被打上了vlan 20,mac为50:00:00:00:00:02) I  o7 a9 {) ]1 [5 `
$ A0 w, ?7 R1 z1 u) I. d3 x
$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=50:00:00:00:00:02 -generate   
& q* _% X3 H- r+ s4 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
" h4 ]3 o: _4 z; Q0 TRule: table=0 cookie=0 priority=0 , p5 `3 Q0 }$ O+ a) M: q: i* l
OpenFlow actions=resubmit(,1)/ r) K: z8 R( ]/ |+ f
2 [/ y: J% O) x3 f/ L5 _
        Resubmitted flow: unchanged 3 \9 [6 _+ Q' d4 F
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
8 u2 ]6 }0 d& V; {. a        Resubmitted  odp: drop
& k  ?/ e5 G/ A' o8 Y        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
- Z8 B% Q6 g2 M8 f0 I$ w: R( ^        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
. _$ Z( y  A: S$ {
0 j' _: y+ o! W0 l4 I9 S3 ~                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 I: u" X; ]5 y+ M' Q3 `                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 , G" u  A) ?7 L) |9 u2 D- h
                Resubmitted  odp: drop
4 ]# `, x2 N( E0 N- j, ]$ ~                Rule: table=2 cookie=0
: _1 f& F" K5 ?) r) a/ 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)
8 ^7 E9 P- T8 d% F
8 \5 T$ Y1 u7 O                        Resubmitted flow: unchanged - U6 F6 h$ V$ E' ?
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
% m+ a  ]& K% F                        Resubmitted  odp: drop ; O! s& V( \" _
                        No match
; q8 `0 L- Y  l, L5 j7 m/ E) W3 S# ]" [: J, D8 h
Final flow: unchanged 4 U! c4 Y. L) N! V% E& `9 ?" {
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
- I# }0 a' s7 i0 {( sDatapath actions: drop) s% A4 Z3 l# S5 r% s( e5 d
6 [, N0 m. J/ S/ _" N  R# _' k1 ]
$ sudo ovs-ofctl dump-flows helloworld                                                 + Y% k" {0 v. `2 s
NXST_FLOW reply (xid=0x4):   i4 [8 I& C; _. U8 h
cookie=0x0, duration=90823.14s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
9 W/ R4 ~4 b) h; I# Z( _3 T9 p2 Ncookie=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 0 u8 C  \" G' j! N  w9 H  E
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 6 s$ P" k* S+ f" H! G
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) : k( N$ R. E, f: M  H
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) 9 X. E: r6 v$ N2 y0 |
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)
/ [2 n6 ^/ y, ]( Bcookie=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) / E* y" R7 z0 Y( S1 }
cookie=0x0, duration=86643.297s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop 0 \# ]$ ?/ L& A" {& b. X, P
cookie=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) 1 V% M) x* c9 \& S$ N8 `/ A% {
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] # q6 j; @2 ~6 h5 ]! S# [
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]
$ R. A1 `, Z4 x  S" J# Q, w+ @4 V6 Q. Q) s$ z
实现第四个table 3: Look Up Destination Port; V) k& m  e4 T% }  _8 e
2 a6 O3 }, m4 z% Q& \) `
在table 2中,vswtich通过进入的包,学习了vlanid –> mac –> port的映射后,对于要发送的包,可以根据学习到的table 10里面的内容,根据destination mac和vlan,来找到相应的port发送出去,而不用每次都flood
3 S8 ^3 A" l! {, w' Z6 J
8 ]4 c- L- Y2 |sudo ovs-ofctl add-flow helloworld "table=3 priority=50 actions=resubmit(,10), resubmit(,4)"1 G7 x! G$ E8 }' {2 w. x

) K1 k4 g" i1 U% m: g2 W添加这条规则,首先到table 10中查找learn table entry,如果找不到则到table 4( j6 t4 W1 m' G/ F% o9 {! q

( H: i1 _3 R7 f! m) [$ ^# c8 |如果包本身就是multicast的或者broadcast的,则不用去table 10里面取查找。
3 @" u( T9 `* w/ Y" X9 |
+ |/ m9 M$ b/ O2 {) Usudo 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)"
, p% r, f& B8 S+ W& X0 G
: H1 {0 g: ?. E+ c, N" n我们进行一项测试. j) a9 f- c5 f" Z" m
' j0 n& N8 v3 ^( u7 G
$ 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 I. q) H: f2 _- |
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
" U. N, N0 V# R0 l5 f) k! SRule: table=0 cookie=0 priority=0   q2 z6 {: |( g8 T! }
OpenFlow actions=resubmit(,1)& M9 e; ?$ S: ~; s+ r( Z/ ^
/ \9 }# a2 x' ]% A& G! H; L& |
        Resubmitted flow: unchanged , I7 a; S! O6 k
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
: J1 e3 o, N8 U        Resubmitted  odp: drop
( i) F" ?- m! Q, i, ?1 ^        Rule: table=1 cookie=0 priority=99,in_port=1
8 {0 ?1 ^8 N2 t+ ]! |/ K/ I6 L        OpenFlow actions=resubmit(,2)7 f# N5 f5 C, I+ {& M7 `  M1 |+ C

% Z4 g5 t: e+ E6 \* Z                Resubmitted flow: unchanged ) D9 \5 z$ M! k- C
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
8 z% ]) H7 H  q6 h- G9 a                Resubmitted  odp: drop
& B% D5 r; z1 l2 W# J                Rule: table=2 cookie=0 0 ]; c4 T6 y0 f6 \
                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)6 f# j; E) s& y

; ]  `$ F8 R- A5 \4 Y* |                        Resubmitted flow: unchanged
" ]' X- d) t) S2 a                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
9 f6 Y* f8 T" C                        Resubmitted  odp: drop
' U# h, d* J( v! Z* r1 D- Z$ I                        Rule: table=3 cookie=0 priority=50 8 C" M, Z* m0 ]1 y# Q7 E( [, D+ [/ {
                        OpenFlow actions=resubmit(,10),resubmit(,4)- Y4 }/ B" K0 E( u  z" a
8 U# b. u# z* Y  G$ m7 K1 D" H
                                Resubmitted flow: unchanged
/ P7 H3 \8 G3 s# P                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
, r6 L4 D/ l& @9 @                                Resubmitted  odp: drop % K) s9 j  A! [; \
                                No match
" G% @* W* T$ g1 h8 K$ r+ g& R; Z* B, ]
                                Resubmitted flow: unchanged % G1 u/ d) h$ H7 z, G  ^) I  C
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
+ u. |/ U. d, S  L                                Resubmitted  odp: drop
  \) z! H6 Y2 [/ e, f" O                                No match
2 \2 h' y& m* p" }1 X" e' j8 c  d. }
Final flow: unchanged
1 }7 r" e7 ]2 X, z" _# H9 f( wRelevant 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 & v4 Y" \5 p* L  V3 e8 e# C
Datapath actions: drop
' D1 O$ E" Q  r! V* o' L2 Y: {+ I* ~) _8 e
由于目标地址f0:00:00:00:00:01没有在table 10中找到,因而到达table 4.1 G9 L- P4 ^7 H
% @9 ~1 r  ]4 f6 N( D
但是这次测试使得table 10中学习到了mac地址90:00:00:00:00:01, m% u% i+ {0 ?! @

0 T! |! x4 k  m& l$ sudo ovs-ofctl dump-flows helloworld : K! C" [2 w! ~
NXST_FLOW reply (xid=0x4):
0 i' t5 W6 c2 fcookie=0x0, duration=91588.452s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) : L6 e! k5 f  r# `% z
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
( J5 ~# H7 D7 t1 |: H- N8 z* ]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
- i7 p3 \7 {1 |% R: ?7 [& m* j# L/ x4 ycookie=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) 9 L! ~2 z8 s. U" l
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) 3 y0 v1 w6 h" \" q6 v& ?
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)
+ v, u8 ]0 s. z6 Ccookie=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) 7 w7 f7 `1 c4 a" O6 X5 @2 q1 m  _9 s
cookie=0x0, duration=87408.609s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop + a+ _! u- K& Q
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 y: G& ^: N+ ?cookie=0x0, duration=352.841s, table=3, n_packets=0, n_bytes=0, idle_age=352, priority=50 actions=resubmit(,10),resubmit(,4)
/ k7 e# V3 A# A8 s) R$ Acookie=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)
  K# z4 v) K5 ~5 g 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 q) P0 a! d/ G
cookie=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]
5 n# M9 s6 q  a' B% B/ }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]1 }( F% {9 U5 q% V
: z5 X  ]5 R# C. n  Q
下面我们进行另一个测试, S% d- A# H0 C  @3 H9 A
# N9 z+ C) S/ V+ l% |+ J
$ 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   
# ^$ r+ d6 J0 FFlow: 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
  ]) O, ^! r8 Y' {Rule: table=0 cookie=0 priority=0 2 ?" ]2 a1 q: e) B* i3 b- D
OpenFlow actions=resubmit(,1)6 Q! k0 r$ x$ x6 z$ `! f9 A

2 `8 L7 W* [* E8 Q' g% K8 |- M8 I        Resubmitted flow: unchanged ( h3 k+ S& ?$ I! x% B: Q
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
0 N3 A/ r4 ^; y* m2 v        Resubmitted  odp: drop
# B( ^4 e# V$ X1 z        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
  ]. G) Q+ G! J, V3 ~" W5 o6 r        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)6 v! E, u7 b+ w+ r& ?
) B% B5 D' A# c. n  {, x2 ?
                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
* J& Z' S( `; J8 b  n7 Q& N                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
1 N7 M8 t( v% d) W/ F0 H: t                Resubmitted  odp: drop 4 b! {# N  {. g/ h- N
                Rule: table=2 cookie=0 * M9 X2 f- c! H. Q; R1 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)8 B, R* S7 ]2 F4 ^+ S
8 h7 Y- r  g1 o# F* A) ~
                        Resubmitted flow: unchanged & d% {+ Z' j/ f/ S
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 - {, i) J7 [& l" m
                        Resubmitted  odp: drop 7 L1 e+ h0 H$ d
                        Rule: table=3 cookie=0 priority=50 - r& k5 [7 N) g3 e- J! a# _$ U  U
                        OpenFlow actions=resubmit(,10),resubmit(,4)
9 t% T/ c% H5 }, D( s; \0 `6 Y8 b( ^& n
                                Resubmitted flow: unchanged 3 O  J4 V6 _3 o
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
8 |3 b2 \" M( t$ \7 [                                Resubmitted  odp: drop # u. p# T8 b( _1 Y
                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01 ! q: F: t0 k9 T) G
                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]
9 j1 H( @1 i& V% B# K. N5 \4 v" u3 q" [* V% p+ z
                                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 E5 K' W; q6 H: S4 W( Z                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 $ y! |, g. g; O+ g( v" f, E1 C
                                Resubmitted  odp: drop
1 S1 M& x8 `" J0 P                                No match. I) |5 J* B5 Z) A; R

" L+ y  z; G# U* g4 A% u, xFinal flow: unchanged , n- X6 J8 A5 y" K( r4 G
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 ; _- B0 `8 V8 o* g$ y" ]$ J* Y
Datapath actions: drop% K( J5 [( ]* L. w
8 P% }, v. `2 d( [
因为刚才学习到了mac地址f0:00:00:00:00:01,所以这次在table 10中找到了这条记录,这次同时也学习到了mac地址90:00:00:00:00:01  d- D. b1 S$ @1 p6 T" O- V7 c
) t9 r9 N. ?$ t! C8 i1 r8 Y, G" d
下面我们再发送第一次的包
7 u# n; k- l1 [
/ ?$ z, z" w1 N# G$ 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 ) z. n2 i5 {/ z6 P8 N2 I
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 1 m( ?4 z9 U  W& e% |7 l
Rule: table=0 cookie=0 priority=0
1 ?+ N, I2 N1 L, _- v$ P. OOpenFlow actions=resubmit(,1)
6 |  R/ P; A2 N% X9 I
& W0 D1 s6 ~$ k8 ?9 c        Resubmitted flow: unchanged
: T0 ]% {, ~: ~5 y. u; O$ i        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & \, [5 M( p1 E& L0 N0 x8 ^
        Resubmitted  odp: drop
; P$ }$ Y& O+ u6 j2 k        Rule: table=1 cookie=0 priority=99,in_port=1 5 f& q2 G- V8 K
        OpenFlow actions=resubmit(,2)8 q: d7 T0 L: h) L2 c+ ^: ^. x

. J( L2 ?* @( I                Resubmitted flow: unchanged
* _- f/ O  g3 s                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 $ g3 }) w8 \/ j# C. E% _
                Resubmitted  odp: drop * v; U- h' |1 v! g; T& G# C
                Rule: table=2 cookie=0
5 T( H: @3 M8 n" 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): b8 K  p4 T7 V  L( H) k
, p7 z- a& Z. u* Q+ g7 M9 a) n4 f
                        Resubmitted flow: unchanged   \9 U) u; R, b  E5 B: v( |4 _
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
( X1 Z8 k' Q( }                        Resubmitted  odp: drop
7 S9 n3 W/ Q" B0 b& P4 a                        Rule: table=3 cookie=0 priority=50 : ^% @4 z4 H, z4 P' m
                        OpenFlow actions=resubmit(,10),resubmit(,4)
, ]; E0 h2 I$ a7 p
4 b+ C& j9 v! @; F0 T) g3 n: R( t                                Resubmitted flow: unchanged + `  q% [) n% Z+ f4 n
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
, h$ a. K3 ?6 A4 m9 r                                Resubmitted  odp: drop
- K1 Q9 |% {% P                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01 1 ?5 [  K6 p* c3 D6 n) f
                                OpenFlow actions=load:0x2->NXM_NX_REG0[0..15]
! O6 d5 \3 z2 r( V# g+ a4 Q
$ x/ J; F0 ]6 l8 i4 l8 P                                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
6 x4 ~+ K% G/ Y6 `; A' B: H                                Resubmitted regs: reg0=0x2 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
5 I7 z8 A; X2 P7 N) v                                Resubmitted  odp: drop
. h- b9 ?: f' k" y                                No match$ s, I- {" s* b( \' k. _7 S
; l( ?9 z* w5 B6 L0 ^. g4 I  {2 V
Final flow: unchanged & r0 p4 e3 e# |; t% Q
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 " L, q) c* c7 o' A( f- u
Datapath actions: drop
4 K% l# |; f1 T0 m+ [9 W
( k% U% U: ~8 Y! e# W发现也在table 10中找到了记录
, u+ p' u! u; d* t' q; V
$ x$ y) M* P3 f5 T* J实现第五个table 4: Output Processing- s* d) h4 i6 q( e* d6 h* V+ L  f

9 n( t" z# h, K" ]这个时候,register 0中包含了output port,如果是0则说明是flood。
6 D0 ?0 b4 }3 i" J
8 D+ J9 n6 b1 o4 @对于port 1来讲,是trunk port,所以携带的vlan tag就让他带着,从port 1出去。2 e8 Y" N, q4 v5 @' Z  @* R2 @
% b& v" [" n" r3 S# c- M
sudo ovs-ofctl add-flow helloworld "table=4 reg0=1 actions=1"
: |9 A  N2 e8 N" r5 k. g& r4 z
对于port 2来讲,是vlan 20的,然而出去的时候,vlan tag会被抹掉,从port 2发出去1 a/ G( z0 q. f! j* Q; h: P& s6 j0 i+ B
" k% Z! Z3 i  e, ]) O5 t  A. Y( g* b
对于port 3, 4来讲,是vlan 30的,然而出去的时候,vlan tag会被抹掉,从port 3, 4出去
# x. Y7 w( |: u5 M, r
6 j! c# g  M3 h# @. U3 _5 w3 J$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   - @2 E% x& o' s" `% u
        table=4 reg0=2 actions=strip_vlan,2 % Y9 h) u* O1 A3 U( M/ z$ ~1 d
        table=4 reg0=3 actions=strip_vlan,3 / W) \9 K& F1 z9 a  S: r" m" n
        table=4 reg0=4 actions=strip_vlan,4 4 H1 n$ E/ M5 w. Q! O
EOF3 Z& n* }0 X, {9 x0 \

( l/ w1 R/ @. I- I+ D3 @* g3 k对于broadcast来讲,我们希望一个vlan的broadcast仅仅在这个vlan里面发送,不影响其他的vlan。' d" G/ w5 W2 L
% [  ^, C: w8 o0 `" ?
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   
+ O- ?$ ~8 S0 r# i2 _! E) d        table=4 reg0=0 priority=99 dl_vlan=20 actions=1,strip_vlan,2
6 `1 Q' G% ~, g& x9 X        table=4 reg0=0 priority=99 dl_vlan=30 actions=1,strip_vlan,3,4
+ r/ Q' t4 z; u* V        table=4 reg0=0 priority=50            actions=1
8 n- q+ n) {* N: c& P& b8 P0 O' c, @EOF
: e' ^$ J: W) R1 k8 I) |2 O5 c+ w0 K5 E
所以对于register = 0的,也即是broadcast的,属于vlan 20的,则从port 1, 2出去,属于vlan 30的,则从port 1, 3, 4出去。4 Z( T" J' z$ E. H. b& [

" i; L- v1 Z' y' F$ sudo ovs-ofctl dump-flows helloworld 0 F& U2 j- c* d8 ?+ F# X: B; H
NXST_FLOW reply (xid=0x4):
2 w+ ?6 u! T* I7 qcookie=0x0, duration=92909.119s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
8 }8 C+ T2 f0 S7 W$ h  C6 i2 Ccookie=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
) [* a& j$ G2 g0 H6 zcookie=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
7 V' p. _' g7 C- ?, K8 ecookie=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) 8 z0 m" j9 h3 T
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 p* B8 h* l* ]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)
# o* R& M0 D( h% ^6 r  \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) / u% n5 j- m& p7 }9 o9 I9 L% C2 f; I
cookie=0x0, duration=88729.276s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
; M9 S8 Q0 l! e0 K" @cookie=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)
& v$ Y4 e( q. K$ ~0 u, ^cookie=0x0, duration=1673.508s, table=3, n_packets=0, n_bytes=0, idle_age=1673, priority=50 actions=resubmit(,10),resubmit(,4) ! W" o# H% r/ c8 }; x5 m
cookie=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) 9 c: u4 o/ w; G4 B- j: c
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x3 actions=strip_vlan,output:3
+ W$ n# Z5 P5 N6 S2 e* G" W) Pcookie=0x0, duration=228.839s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=50,reg0=0x0 actions=output:1 " |( d  ?; y7 g
cookie=0x0, duration=483.068s, table=4, n_packets=0, n_bytes=0, idle_age=483, reg0=0x1 actions=output:1
% U- X# @. ~- b" g* K8 I  U& c* a: ^cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x4 actions=strip_vlan,output:4
9 n. d/ M% x/ E3 [/ Lcookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x2 actions=strip_vlan,output:2 0 v% a1 e/ b  f" o& V6 N. D/ n; f
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
2 ?- v" x9 a2 Mcookie=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 ' l* v. ^1 ^9 H2 A) ~  N
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]
+ y% P5 c5 h- \1 a) a/ \cookie=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] 5 o4 E3 g0 n6 y. o7 W. @
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] 0 {  f& d/ M; Z2 z" l! h
cookie=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]- m: O3 n$ a3 x
# J! q/ A! o# l# k
首先来测试一个multicast和broadcast. A# ]: v7 x% K* T
' B: Y- R% \$ R5 Z( R9 t6 |" C/ r
如果是一个port 1来的vlan 30的broadcast
; P0 ~5 q& {3 h1 k
% M4 o- \/ T! Y) I0 K$ A: T3 M$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=ff:ff:ff:ff:ff:ff,dl_vlan=30
6 L9 Y# C1 K: G4 n, EFlow: 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
$ [) Z5 w% f" zRule: table=0 cookie=0 priority=0 $ P; V# X/ p* ]7 V
OpenFlow actions=resubmit(,1)
9 M8 D/ a% \& V0 L4 Y7 r1 a1 y+ [9 \3 i. f8 x
        Resubmitted flow: unchanged ) X9 N, E  c: \8 y: f
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
/ g$ t" {$ V. J% X        Resubmitted  odp: drop * u" U1 Z3 _1 m  E
        Rule: table=1 cookie=0 priority=99,in_port=1 , a/ ]7 @/ b( [0 `
        OpenFlow actions=resubmit(,2). p' B5 c% u; ~. f& X1 K9 y, M
. w: A" T& ?+ J$ K' H+ f2 x* ^
                Resubmitted flow: unchanged ( O# f2 m  B( Q1 Y
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & @% F, j2 d) k* o+ g/ L- n9 j
                Resubmitted  odp: drop
; Z$ I# W2 E$ ~; m" d4 w$ y  M$ [                Rule: table=2 cookie=0
! A# R, ^" b; J% G6 G1 M( ?                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)
2 D' B7 H/ p4 N7 `6 w) d  t0 y" W0 A% o( p
                        Resubmitted flow: unchanged
% F9 S1 W% W6 U                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0   E# ]+ s9 I3 R6 i! H  a
                        Resubmitted  odp: drop . m( e7 i2 N/ L* K& s
                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 2 l9 v. r; C- A1 U9 G
                        OpenFlow actions=resubmit(,4)
( D% N) f# E3 a7 r  I
  W2 S2 e4 |2 r/ ]3 J                                Resubmitted flow: unchanged
7 g/ T( F* O3 i0 a; s# m                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
; `. F) D3 H$ c! W) a# p6 q                                Resubmitted  odp: drop 6 h2 M5 a  ~" ?7 V& n% C' {
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 8 x/ J# y  r8 W' i" F" X) ]( h" \
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
' ~; y& U2 v' S                                skipping output to input port+ R' D" o9 p( A& f
( c4 Y3 u" G4 F3 R" \9 m4 T
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 0 V9 p9 [& l+ j  x8 I8 \8 V
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 " ?( d7 u& e9 H2 s/ v
Datapath actions: pop_vlan,12,13! }9 A2 X4 m8 v2 N# E
& R6 m! Y: H! a
结果是port 1就不发送了,发送给了port 3, 4
2 q% J+ f2 ]+ ?; A9 P- o$ i+ R: t0 y! C& }: [1 @+ \
$ sudo ovs-appctl ofproto/trace helloworld in_port=3,dl_dst=ff:ff:ff:ff:ff:ff ( v; X- n' j. x6 B4 x+ {/ s0 n
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 9 o4 `$ \9 x$ g5 S( d2 |
Rule: table=0 cookie=0 priority=0
& L5 Y7 E+ P- J+ C) s/ D/ Q8 @' QOpenFlow actions=resubmit(,1)4 Q! Q6 N+ F: a: y3 l; P

7 B2 K4 h0 l$ c4 O" q3 i* E        Resubmitted flow: unchanged + \/ O% h) W5 ]: e: z, b
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 9 L: \! }# i2 g  m0 V5 l& u1 K
        Resubmitted  odp: drop
. @- f; N, \3 q: I        Rule: table=1 cookie=0 priority=99,in_port=3,vlan_tci=0x0000 # S3 N$ K0 o$ ^
        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)
3 Q+ c  d. s3 d
' y$ |4 D6 @% x, D8 {                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 : ^% ^3 r8 K9 i/ z$ h9 k
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
6 U% O& w9 L3 Q8 N+ d; E                Resubmitted  odp: drop
( n! U5 n2 r  L: y, F                Rule: table=2 cookie=0 . B7 |4 G; d8 h- J# W' H7 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)
- M9 G" n$ \7 ]7 n* j. o# ^- s$ D% s( Z1 w& e! N2 ~6 M6 ]7 c7 }5 i3 p. r' I
                        Resubmitted flow: unchanged
) U; r: c: F4 J8 J3 ]8 N8 T                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 5 G0 O  y* A- L2 R0 q, D' f
                        Resubmitted  odp: drop 7 g  q4 f  X* w/ Y5 \
                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00
. o/ c' d' c& Z# @! ~: E                        OpenFlow actions=resubmit(,4)
& C( n1 F* g' C7 u8 m9 X0 @* y+ f- _7 Z+ ]
                                Resubmitted flow: unchanged
8 h* E7 l6 F: G                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
; w' K4 J& l! R" E/ X4 s                                Resubmitted  odp: drop
+ G0 B% H* w, i' f0 b! `; Z                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 8 N2 ?. C: Y! h9 A
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
0 [+ l$ w9 p( y1 H) W* C& n                                skipping output to input port
3 y/ e, k# b- k' j4 w
# {' L! T  D$ w+ g9 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
1 B3 G" a- g6 S/ J1 k3 K& KRelevant 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
6 Q3 I0 Z8 ]+ A8 w; F( w4 H: c+ rDatapath actions: push_vlan(vid=30,pcp=0),10,pop_vlan,13; ^. v( F: ~7 O! f$ h7 t) x

' B: V; m# W$ ]1 c接着我们测试mac learning
) G' n, \+ e# {0 o
! K. R% s5 b. U$ 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 ?1 Z% i) CFlow: 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 B) |8 [) x9 Y% z) v0 T
Rule: table=0 cookie=0 priority=0 8 c5 y+ A- x& A# h
OpenFlow actions=resubmit(,1)9 _, [" @! M* A/ P( Q

- h$ z9 t# X/ R& `  d7 k        Resubmitted flow: unchanged # w; Q  U) M* H3 E
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
' J9 V4 M# U: n0 d4 D        Resubmitted  odp: drop
, E4 W, T' p0 _5 E8 ~  {        Rule: table=1 cookie=0 priority=99,in_port=1 9 n- o2 u% c- R1 n5 U
        OpenFlow actions=resubmit(,2)
; Q" Y; E, f4 |+ u: B( ]3 l, P) y  ^
                Resubmitted flow: unchanged 1 X6 S2 R& y0 Z' c
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
+ q. V& [$ e0 ]                Resubmitted  odp: drop * y) ?( ?3 x5 ]
                Rule: table=2 cookie=0 # B+ D* s! j# I6 `% M! e# ]/ 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)
, z3 o6 X  k" R# d* P
& V5 `$ B; K0 H1 S& H. q; F                        Resubmitted flow: unchanged ( n. ~5 ?) e2 K: J! t/ q
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
, w1 ^% \9 q5 H1 _* q8 P                        Resubmitted  odp: drop   i' O2 }6 h: r
                        Rule: table=3 cookie=0 priority=50 * y. G! N# t' j# y; S: D
                        OpenFlow actions=resubmit(,10),resubmit(,4)2 Q$ H) H. \1 P2 i) c

4 [& ~2 ]* n( p& v2 \  m5 u0 `9 N! {0 I                                Resubmitted flow: unchanged
: g4 @, ]4 L, E& Q' |# Q                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 7 v8 U8 `" ^: R8 q1 ]0 k3 e# K
                                Resubmitted  odp: drop ( |& }& g. j, s; H4 Q. i2 G
                                No match- q& V& j, W2 G$ i' j6 f' j- \
- g9 J% H& T. z# U2 f" j
                                Resubmitted flow: unchanged
. b( a2 S+ o2 K9 e" @( A                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 9 @4 v; I8 o  V, Z! x
                                Resubmitted  odp: drop ' ^) v; b; [. V
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
% P0 u# g0 c7 ?                                OpenFlow actions=output:1,strip_vlan,output:3,output:4 1 N# F5 M% w4 f' X! v
                                skipping output to input port
- \  _/ ]% @( y; ]
# v7 `( V2 c: e: M. s# wFinal 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
# a5 B3 L  o+ o! |+ f+ lRelevant 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 - S9 i( o  B, _# x1 M
Datapath actions: pop_vlan,12,13
( Y" [) y! j7 u4 H$ d8 g! W2 q
( {- |6 C1 R5 }0 {$ \( d" V! a( l) o* e由于这两个地址没有出现过,则除了进行学习以外,广播发送给port 3,4
- [7 \8 p" o- P' _, S3 l( Z3 d0 w* d, w4 ~0 R
$ 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   " _8 D: g2 C/ |! U, E& Q" A2 |$ C
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 4 m+ [3 a5 D0 ?1 u* p6 }, q
Rule: table=0 cookie=0 priority=0
" y3 r) T- V/ |3 v8 ~OpenFlow actions=resubmit(,1)9 D  n! h+ m+ {0 K# y+ j
- u0 @- m/ L! ]  o4 w
        Resubmitted flow: unchanged
. b' B. J5 {1 m* @* u9 Z- _, Y6 `: Z        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 9 t* I: X* ^) K+ ]  y8 L
        Resubmitted  odp: drop
+ j2 P+ V" r6 R$ q& ]        Rule: table=1 cookie=0 priority=99,in_port=4,vlan_tci=0x0000 + `) i! o: j7 ?  A
        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)
# A* @/ w" J2 c7 I: e6 h* d
8 Z$ K: `, F4 U7 N0 ~1 q+ Z                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
4 i( x+ ?3 G: U5 q; v+ X0 Y! ?                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 % x5 Q& @9 Y/ O# |9 V! m
                Resubmitted  odp: drop
) M- X1 |( B: B, p( L4 ^. s: c                Rule: table=2 cookie=0
; W) u9 F9 g  ]                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)
2 E  B/ r* T+ P" K3 L+ C( p
' t) M$ ]/ Z/ b" L$ a" u                        Resubmitted flow: unchanged
$ m$ p( W7 s+ Q6 X. h  N. h                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
; b) T: D; q/ {/ R, q                        Resubmitted  odp: drop $ b8 Q6 H+ m+ B2 C' m, {/ a
                        Rule: table=3 cookie=0 priority=50 ' G6 b; J$ X% ]/ y& ]: M
                        OpenFlow actions=resubmit(,10),resubmit(,4)  ?6 p" t1 W. M# C6 f' |$ c( O( o! F
1 S' c1 I9 L, T9 w* f
                                Resubmitted flow: unchanged
; l$ H$ h; f9 P9 T                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0   V0 C3 I( P6 D7 Y4 V: w
                                Resubmitted  odp: drop , l5 h+ [+ t$ r$ V
                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=10:00:00:00:00:01
' M4 k& k, N% l8 Y3 ?2 |                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]
3 ]; i% {0 K( D0 s1 x
# ?+ i1 U' w- p% z7 E3 _* @! n                                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
& a2 C7 \; v" t" C                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
0 s6 L: {" H' X" N5 A: {+ |                                Resubmitted  odp: drop
6 \3 K0 L, Q$ \0 @2 n, S' i- ^                                Rule: table=4 cookie=0 reg0=0x1   D6 l' n& w  \2 V5 k& r
                                OpenFlow actions=output:1
0 F+ C& m5 I- F0 Y) `/ H4 a8 j: d, V; F; e" ^+ ?
Final flow: unchanged . b/ z% F6 g% P
Relevant 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 6 F0 a8 s5 x& n8 B$ W
Datapath actions: push_vlan(vid=30,pcp=0),101 J" W9 c5 Z6 _+ _4 F
9 q! e7 C/ a* A2 B2 P; `9 \
回复的时候,由于学习过了,则仅仅从port 1发送出去。
' y! M2 p3 ~: V, k, c
# l0 `" |9 T, `' h$ 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
1 X, o6 H5 H3 ^4 |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 t) _- L, W6 Q
Rule: table=0 cookie=0 priority=0 / n. s) }. L4 Z
OpenFlow actions=resubmit(,1)( [6 P; |4 }. z, B6 F$ ~3 ^5 b
* F3 e$ Z0 b0 C# N
        Resubmitted flow: unchanged # j9 m. L/ h0 f/ p5 _& t
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 2 t$ s6 e. o7 Q; o) g' Y' o8 r: a
        Resubmitted  odp: drop - w4 H9 p9 Z9 h# j
        Rule: table=1 cookie=0 priority=99,in_port=1
8 k* R, U8 A$ e, Q! l5 m( U        OpenFlow actions=resubmit(,2)
6 t5 T- i+ T" z5 e1 m7 f
2 x. b+ r  b% i4 L                Resubmitted flow: unchanged
3 b; h- T  K9 Q. B) X/ j                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
  j1 @+ q+ Z# B                Resubmitted  odp: drop
( A3 \0 \5 S. `1 o                Rule: table=2 cookie=0 ( I+ }3 W4 S, B# 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)
4 w7 i9 K3 m& m+ F1 O$ r- R% C+ @( y3 u! q8 i9 n) p
                        Resubmitted flow: unchanged ) i# ]9 _; W0 F- u+ F
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 + ?( I6 o) W. a8 f' T  o
                        Resubmitted  odp: drop - G9 g3 _4 G' S
                        Rule: table=3 cookie=0 priority=50
4 H+ |9 G# P' X/ n% B                        OpenFlow actions=resubmit(,10),resubmit(,4)! j  Z" X$ G& z

$ _9 w% U8 e* y+ E% L6 t+ g                                Resubmitted flow: unchanged * Y8 v* a# w: S, s6 G* i: V, p
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
& R8 x& g9 T8 V- h+ n- I                                Resubmitted  odp: drop 5 U. J  y/ N, f' e
                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=20:00:00:00:00:01
) f/ ^! [5 g/ A, O1 d                                OpenFlow actions=load:0x4->NXM_NX_REG0[0..15]
' Y: \$ h6 O: B  R8 H  \/ I4 ?7 F; @: Q; }: L$ M
                                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 ( r3 f% Q, o) c: T
                                Resubmitted regs: reg0=0x4 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
. G- |  @) t. S' q5 b% ~" p                                Resubmitted  odp: drop , [# Y# T$ f2 o. d* `* z
                                Rule: table=4 cookie=0 reg0=0x4 . {  [+ B1 f9 w0 Z: e
                                OpenFlow actions=strip_vlan,output:40 m4 t: ~5 d8 o6 ^8 k; T6 U
0 u7 T: ?" u& K8 R. K( S
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 ( R( s: \! A) o# Z- m
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
5 @+ m5 A# D; [) @0 z4 ~Datapath actions: pop_vlan,136 v$ u+ J' B$ _8 _9 f
+ ?+ u, f8 M& W. I( a/ C
由于在回复中进行了学习,因而发送的时候,仅仅发送port 4
 楼主| 发表于 2019-10-25 10:00:36 | 显示全部楼层
实现第一个Table 0,Admission control
8 M; N7 v6 |6 `) _9 D
; c$ I3 Q: K: _$ y$ l- a包进入vswitch的时候首先进入Table 0,我们在这里可以设定规则,控制那些包可以进入,那些包不可以进入。
/ x, i/ \5 g9 w% b
  ^! ^& C' D  i8 n( _比如,如果source address是multicast的就不允许进入。
& D. V1 }& b- M# K; }7 H! B" h7 q; D+ T! Z: D; U9 V- P4 \2 @4 Y
01:00:00:00:00:00/01:00:00:00:00:00是广播地址
( I5 [; d3 }6 @/ B+ [! c# }00:00:00:00:00:00/01:00:00:00:00:00是单播地址- c4 u( e! w% s' D4 B
这种表示形式类似CIDR. F# f4 }3 k5 V* w
于是我们添加下面的规则:
0 @! N( S- l+ `" f+ J4 C  zsudo ovs-ofctl add-flow helloworld "table=0, dl_src=01:00:00:00:00:00/01:00:00:00:00:00, actions=drop"
# D- U; N. B) z! F' g0 bSTP的也不接受
/ Z* H' `$ f3 E% u' Asudo ovs-ofctl add-flow helloworld "table=0, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0, actions=drop"
) D" g1 `! C3 G1 z我们在添加最后一个flow,这个flow的priority低于default,如果上面两个不匹配,则我们进入table 1
5 J9 G, U7 V2 y2 O1 Dsudo ovs-ofctl add-flow helloworld "table=0, priority=0, actions=resubmit(,1)"
+ {9 p! o6 O+ Q! [5 F5 U8 [我们查看一下所有的flow# F. a+ d6 c' O5 q6 x. y
$ sudo ovs-ofctl dump-flows helloworld        " v+ X5 Y) P* G$ _
NXST_FLOW reply (xid=0x4):
- e/ S: `( o! `$ Qcookie=0x0, duration=42.162s, table=0, n_packets=0, n_bytes=0, idle_age=42, priority=0 actions=resubmit(,1) , c& u* m3 K' a
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 3 q: w, G4 a: A- o0 r
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
( a" d% k% X: t5 w7 @( e' f. }& }. Q
测试Table 0
: m  c( I# b" w# x, q. s
$ |0 W) {9 e: A) B/ j有个很好的工具ovs-appctl ofproto/trace
- y) F: L6 N8 {+ T3 y: B) W5 @, [" Z; g; ^
不满足条件DROP
! p- _, {( a4 R! y. d! w
) x* [( \  L1 X$ i" m$ E5 D' q- P$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:05 # A- y& B" G, n. X. D
Flow: 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 7 q( [: R% L3 U; s2 m
Rule: table=0 cookie=0 dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0
  C: k, I  Y1 X5 G  t1 DOpenFlow actions=drop: a. o8 p2 y' U4 Q5 c& D/ ]

1 l9 M4 g$ f+ D9 wFinal flow: unchanged * N( b/ @1 g: u( g! u$ B! \. d
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 ( F- T* j+ {1 R. J" z
Datapath actions: drop
  a" b3 [8 Q4 {+ B8 C- T  _# M( b  U  C6 {2 i
满足条件RESUBMIT
/ M0 \. E9 y, v# w# B1 B
  y, B6 {7 F. t& c$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:10 / D+ `4 p) ?& l7 W% b+ e
Flow: 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
& b, w. i, q! a! h% i9 B% ^  GRule: table=0 cookie=0 priority=0
' K4 {+ \& C3 ^9 WOpenFlow actions=resubmit(,1)
) ~( B! n- Z" d5 a+ D1 D/ ?: K1 j7 `2 S; _8 B  r( K
        Resubmitted flow: unchanged
. p& w- U6 E/ e+ o; X4 s+ _* W6 M        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 : B( D( B# m2 z
        Resubmitted  odp: drop ! `) \' s/ Z, c' [/ Z) m) d3 t
        No match- t) o5 p$ V6 F+ i& U
( p4 ]. F: i! @0 F+ {* I# W1 E! U
Final flow: unchanged 3 b3 k5 y9 F5 S7 t1 Y* y7 U/ 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:10/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no 6 ]$ z; {. J8 O+ ^
Datapath actions: drop
5 l. P! u2 Q! r2 }8 h, Q  F+ ~$ A8 ~" J" ~$ u
实现第二个Table 1:VLAN Input Processing
1 @7 i1 Q- `" ~, H) O' C& s: G4 W! E5 I  t
首先添加一个最低优先级的DROP的规则. Z9 x9 h- D3 U$ K& V' |
5 e( S5 g7 L) I7 z9 O
sudo ovs-ofctl add-flow helloworld "table=1, priority=0, actions=drop"! f9 ~0 u+ C- \/ I0 @) @0 T2 g

) O) o7 P/ c6 w7 {; w对于port 1,是trunk口,无论有没有VLAN Header都接受。, |* h7 a' M: Z1 N* |

" s  y( d' ^( M5 O$ {% |sudo ovs-ofctl add-flow helloworld "table=1, priority=99, in_port=1, actions=resubmit(,2)"4 P& d' r; j, A) J: |5 l" \) I
! m& }# K6 @2 U) @! F# ]8 ~
对于port 2, 3, 4, 我们希望没有VLAN Tag,然后我们给打上VLAN Tag
) |) x1 S* P2 Y% Q- S" b# a/ Y+ s6 C* E
$ sudo ovs-ofctl add-flows helloworld - <<'EOF' ' o8 v# H. F9 y( {" |* u
table=1, priority=99, in_port=2, vlan_tci=0, actions=mod_vlan_vid:20, resubmit(,2) ; w! q, B2 E9 K. w
table=1, priority=99, in_port=3, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2) $ B6 T" n( V' P, R2 J1 D
table=1, priority=99, in_port=4, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2)
* {, x! Z% v3 V: x$ hEOF
: O. t- {# b1 z' p# q- U
5 Z! e" W% }$ ^) I) m4 \$ @; _$ sudo ovs-ofctl dump-flows helloworld
: [* ^( ]7 _9 x, }7 N" N4 ]5 j; VNXST_FLOW reply (xid=0x4):
4 ]4 Q0 M" n, C0 g1 c  g" x. j3 a4 Mcookie=0x0, duration=4478.582s, table=0, n_packets=0, n_bytes=0, idle_age=4478, priority=0 actions=resubmit(,1)
6 m/ m! ]* I: f" _* K- J( Bcookie=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
/ U7 R7 x* d4 x* J3 P* Q5 F, t3 A) Zcookie=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 9 O% `: M& f; u! K
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) 0 @0 F' _$ Y" e' F
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)
9 c2 o4 n+ `# ^' V6 T0 zcookie=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)
- ?- v% v8 u, ncookie=0x0, duration=220.318s, table=1, n_packets=0, n_bytes=0, idle_age=220, priority=99,in_port=1 actions=resubmit(,2)
9 C+ ~4 D9 Q; P9 wcookie=0x0, duration=298.739s, table=1, n_packets=0, n_bytes=0, idle_age=298, priority=0 actions=drop+ n, \; O: S. N( A

- G6 [1 ~! e% o+ c) I) U& S+ u测试一个从port 1进入,tag为5的9 Y6 K+ i6 i$ z" W3 a* F
! m) o$ d3 `: f* l' P
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=5 ' u" }" E6 W( ~, @/ J8 Z$ x- f, k; w0 L
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 & w+ u' j4 J7 B% q
Rule: table=0 cookie=0 priority=0 3 ?/ s( }3 V- G
OpenFlow actions=resubmit(,1)3 \, e4 K  K4 H* B; i* Z* m& ?

4 U4 j# M1 _8 X; {; e        Resubmitted flow: unchanged + o4 G; g  P6 n
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
- N4 ~8 l7 b' M        Resubmitted  odp: drop
/ I. K6 k3 ^2 H' B7 c. T5 f        Rule: table=1 cookie=0 priority=99,in_port=1
+ c' O* M9 D7 j5 `        OpenFlow actions=resubmit(,2)4 l1 L: t$ y' v9 w6 `6 B# j" J
2 G% C2 A  ^0 s* Y* J' e; G0 _
                Resubmitted flow: unchanged
, Z7 h, @& L' [* `3 }1 R                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! }7 [" `5 x0 l9 n& l8 c" ~: L
                Resubmitted  odp: drop ' H/ ~7 {) p% N* q
                No match. c$ U( P- _5 y! e% N" r

* t5 F$ D; F+ nFinal flow: unchanged
( c' k% ~* J+ Q7 n! S$ o: n- JRelevant 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 8 l# x# C' R  |2 R3 k$ p: K
Datapath actions: drop: }* |! }( u- v* M+ i+ t
1 g3 D0 m0 A! z; D" m
测试二,从port 2进入,没有打Tag的
0 ?4 T& f1 V$ T! z. |+ T/ w6 u6 n! s  A$ {
$ sudo ovs-appctl ofproto/trace helloworld in_port=2
6 d2 o5 Q* G' T8 ?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
: l3 Q8 Q0 {' b& F: F9 C7 {7 e, RRule: table=0 cookie=0 priority=0 , V5 ^# o( F2 J5 J
OpenFlow actions=resubmit(,1): f: e  i6 h2 t, r

" G: F- }2 D/ r7 i2 Y8 J        Resubmitted flow: unchanged
8 ?5 r- U" u/ Q! D        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
7 h8 x0 k& ~: o- K, _8 I        Resubmitted  odp: drop : Z6 m1 v6 k. O7 @! h
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 8 v0 N' o) k7 ~/ V. z2 U
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
3 w! U& s1 o+ s2 H, W& I/ ?. R) k0 s# s! K& o9 F  C2 K, x) e' }7 \
                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
, \" k* W9 w0 r3 @                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
$ S* K( ~6 J$ Q/ m5 z; x0 I. |                Resubmitted  odp: drop # o7 |7 s5 {3 }+ L! J5 E. Q# |% l
                No match
& M( B; x" ?2 V; |) }* a3 m. |6 M; Q1 }) o4 w
Final flow: unchanged ; _8 L: F6 t; x
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 $ j  G+ f4 g- b4 y1 }) Y+ P8 H! N
Datapath actions: drop
! F" x. z: @  u% p1 @& Y, ~5 b% R! s* l, C
测试三:从port进入,带Tag 5的4 J9 N% E' o: `* D9 a! {: n

% K* y8 Z- s4 C$ sudo ovs-appctl ofproto/trace helloworld in_port=2,vlan_tci=5
$ |5 f0 @- R: m( j# I! ^$ YFlow: 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
% q. f  o# q+ z' D$ R4 ^3 Z% WRule: table=0 cookie=0 priority=0
0 w, x& r0 n9 t. Q5 eOpenFlow actions=resubmit(,1)' [5 m2 K* t4 e. t: {4 p% ~4 \4 b

( f  z8 j; i0 W" g        Resubmitted flow: unchanged 3 g7 V( p( m0 n4 T
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 5 {$ w' @" c2 G# z+ S
        Resubmitted  odp: drop 5 s% g4 D! u/ S1 o, s7 y% T  j
        Rule: table=1 cookie=0 priority=0 ( }) O! ]1 ^. M5 s8 |
        OpenFlow actions=drop3 e1 w2 `  o" j8 L; d
2 \5 h( Q; r( _7 o8 v
Final flow: unchanged & u( w8 D. i$ v! ?0 f$ d: F3 ^
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
2 S8 J- N$ E3 w$ k7 y' l, KDatapath actions: drop9 p( N8 u  y3 R3 V; }4 d

8 J; ^) k# A' k7 n* c. e实现第三个Table 2: MAC, VLAN learning for ingress port& D, e  O* m1 b- K: \; h
( \' a) `/ v: j1 b
对于普通的switch,都会有这个学习的过程,当一个包到来的时候,由于包里面有MAC,VLAN Tag,以及从哪个口进来的这个信息。于是switch学习后,维护了一个表格port –> MAC –> VLAN Tag。
' @! k" K/ ~6 @$ m8 B/ Z
. J5 s! C# |: S2 O$ R这样以后如果有需要发给这个MAC的包,不用ARP,switch自然之道应该发给哪个port,应该打什么VLAN Tag。6 m8 ^% e6 V5 u/ f" J3 ~

5 @8 }+ [5 N% |. KOVS也要学习这个,并维护三个之间的mapping关系。6 M9 i, t) {  S$ O6 s
! {9 z" j5 ]6 w5 B  L2 d0 b# l# c
在我们的例子中,无论是从port进来的本身就带Tag的,还是从port 2, 3, 4进来的后来被打上Tag的,都需要学习。
- y7 _* G7 g0 K8 D' Y
& m& X' W) T9 I3 \: Ssudo 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)"
# I+ u. R# J8 M& t* w4 \, B4 a# J7 m! ?: X/ e( e+ w. x( M
这一句比较难理解。
$ O" S: t$ m. c; Z
' |/ d" G2 K0 Tlearn表示这是一个学习的action
4 ~6 q8 P: [6 h6 k4 F) M! {; _& v& }
; @6 S0 N- i! c+ R- i! A6 \+ \table 10,这是一个MAC learning table,学习的结果会放在这个table中。' d( E2 e3 h1 y( F
* T; i( X; s% Y- c0 J
NXM_OF_VLAN_TCI这个是VLAN Tag,在MAC Learning table中,每一个entry都是仅仅对某一个VLAN来说的,不同VLAN的learning table是分开的。在学习的结果的entry中,会标出这个entry是对于哪个VLAN的。
- \0 U3 Q. i* N! P' o* q! @) G& v; q' l& c$ g8 I
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里面,因为这是为发送用的。9 |: \* f5 y$ r! M; ?, s4 Z

- `5 \' T* C/ i& }0 i0 V* d$ YNXM_OF_IN_PORT[]->NXM_NX_REG0将portf放入register.! o- y+ h$ }2 T1 a2 r( N# e' M& {

: u) Z8 ?3 i: ^+ b/ y: G一般对于学习的entry还需要有hard_timeout,这是的每个学习结果都会expire,需要重新学习。  K% g  ?% [& @" c$ n6 g4 o+ i
( R0 T4 c0 q  D
我们再来分析一个实践中,openstack中使用openvswitch的情况,这是br-tun上的规则。- W- N2 w  C- C; R
) x  N; b$ ~4 v+ Z
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
% \7 G  P. a2 c, i  K( O1 z: \cookie=0x0, duration=802187.786s, table=20, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,21)
$ t6 J1 F% W# p6 p7 E1 G' _9 ~0 J 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 ( N. F' e" n( D% Z6 J, a
cookie=0x0, duration=802187.653s, table=21, n_packets=17, n_bytes=1426, idle_age=65534, hard_age=65534, priority=0 actions=drop - F9 I9 K, }5 |! ^
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
: u6 {7 W! C  ^. C3 g4 ?: u; |  y6 @* M  [0 e- W
这里table 10是用来学习的。table 20是learning table。如果table 20是空的,也即还没有学到什么,则会通过priority=0的规则resubmit到table 21.. l* O* Z( k$ F  A

7 f4 O4 ?, ?$ }6 ]2 e; etable 21是发送规则,将br-int上的vlan tag消除,然后打上gre tunnel的id。
9 K" Q3 a1 }7 x3 M, X
6 L. u* B3 R- U9 R$ v) M上面的情况中,table 20不是空的,也即发送给dl_dst=fa:16:3e:7e:ab:cc的包不用走默认规则,直接通过table 20就发送出去了。
; n7 i3 j# H8 f+ [  u- \5 o) a1 ?/ R  A
table 20的规则是通过table 10学习得到的,table 10是一个接受规则。最终output 1,发送给了br-int# r" Q4 H$ @  q) e8 y; |) p
/ r( `+ F: d5 L. E7 f# g: R
NXM_OF_VLAN_TCI[0..11]是记录vlan tag,所以学习结果中有dl_vlan=1$ ]) C3 P; L. [) v
" u9 T# u: s, X. W5 q* _% W  \7 b
NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]是将mac source address记录,所以结果中有dl_dst=fa:16:3e:7e:ab:cc4 y& @; Z3 X' n
: X# B- \" I% b$ f! G0 x( ]7 C
load:0->NXM_OF_VLAN_TCI[]意思是发送出去的时候,vlan tag设为0,所以结果中有actions=strip_vlan
5 l8 J1 k  x% K+ e( D1 X& M  x: o' h* t* B
load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[]意思是发出去的时候,设置tunnul id,所以结果中有set_tunnel:0x3e9
, U; I6 r$ @- a2 f' J
" l. [8 ~1 I2 G9 |9 A; @/ _output:NXM_OF_IN_PORT[]意思是发送给哪个port,由于是从port2进来的,因而结果中有output:2
% S3 f" ~+ V- I  h! o
. I6 v. S) @4 x测试一:从port 1来一个vlan为20的mac为50:00:00:00:00:01的包& F# x" K6 k8 V5 X1 @
! s: Y) q5 q+ y* `$ j0 F% |
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=20,dl_src=50:00:00:00:00:01 -generate   
9 l3 l2 n! X& M6 h+ DFlow: 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
- i- _+ K* v& xRule: table=0 cookie=0 priority=0 - J& Z* N  ~& V5 }" q
OpenFlow actions=resubmit(,1)! p5 f" P7 m3 K
+ H+ L  v% R  }
        Resubmitted flow: unchanged
! I: a$ m0 ~8 D) c% z$ v        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 / G) f; @0 j( C$ p7 z
        Resubmitted  odp: drop 1 E1 t( E; f8 a* o( P
        Rule: table=1 cookie=0 priority=99,in_port=1 ! C" o9 l" r7 v5 B9 \+ E" [
        OpenFlow actions=resubmit(,2)
' Y( S% Z7 B) ~6 K+ ?* m# u( i" u) I, C- y
                Resubmitted flow: unchanged
* [- s/ Z! }/ z! k2 b                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
! |( e7 F0 O( _* w! \! {" I                Resubmitted  odp: drop
- ^4 }4 c. w' x1 j- Z+ c$ L+ b& M                Rule: table=2 cookie=0   r& P+ S7 G! R- k, E. 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)
% }7 v8 @) ~% B. }, n, ~/ U
8 K* \- L+ W) H- f/ r                        Resubmitted flow: unchanged
+ ]* u3 N4 h8 `                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 * x9 s( I, P( [7 e% `
                        Resubmitted  odp: drop
) f! M. _! ^7 Y) Y% }8 m                        No match" f9 i* q; F  p- V+ c+ d6 ~! f
( V7 o3 x2 M8 p* k' c! y
Final flow: unchanged " A8 S+ e- a2 `- l9 q7 }
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 1 b; R% l; Z2 z- J. T$ ?2 s
Datapath actions: drop
3 L/ m* A; J1 e# `: b3 e9 {1 X3 Z
$ sudo ovs-ofctl dump-flows helloworld . g9 v8 D% l+ `8 z
NXST_FLOW reply (xid=0x4): # Z! Z2 b- O# j5 s$ n/ `. ^
cookie=0x0, duration=90537.25s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) / H3 a! t# _7 T8 x
cookie=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
1 }. U# a' O1 v0 kcookie=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
$ U( _( X  T2 V( [6 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) ) x/ D. K: K( X5 W8 I& L9 u' N) S
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) ) f; K9 ?! e# {1 p! I( h
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) 6 w& @+ j+ S" Y7 P, X1 Z( M
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) 7 p- q8 `" j8 d9 l' `
cookie=0x0, duration=86357.407s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
6 h$ q  c, \" k# E! {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)
' }$ _' m- ^4 E. C) p7 Y 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' i! s, L# }0 J! n2 `% w0 S1 \  A4 p5 t- U' v5 [. r! b
table 10多了一条,vlan为20,dl_dst为50:00:00:00:00:01,发送的时候从port 1出去。( b7 w! d5 E! `9 c% o

$ _. ^5 X0 Q4 d5 r) y9 a3 A测试二:从port 2进来,被打上了vlan 20,mac为50:00:00:00:00:02
  A* F: ~9 k' [5 A* r
( i0 ?6 s& u4 P( \2 a$ M1 P$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=50:00:00:00:00:02 -generate   
* d& d0 `5 f/ q1 k+ fFlow: 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   h8 `- x2 m5 q% J4 `0 f! Z
Rule: table=0 cookie=0 priority=0
( C- Q6 F& G. S' V. [OpenFlow actions=resubmit(,1), {/ {" |7 M7 d' u8 z5 R5 H, S

2 i" Z: V3 N$ E7 U/ h0 [        Resubmitted flow: unchanged $ _# _% s, b2 w6 W5 N
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 5 |$ W- F" D: y% I$ n
        Resubmitted  odp: drop 1 I- J- k5 J. \1 q
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 * `' y/ d+ n1 u1 Q3 {& ]
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
' I' i9 B5 D: m: h4 R3 d, L
, K) D% G8 K. Q                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
1 A9 x4 e2 j2 `, v/ a, h8 D                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
' t4 ^8 C) C, n# ]0 ^7 Q5 b                Resubmitted  odp: drop 2 G9 [' Z' j- v! G4 i
                Rule: table=2 cookie=0 : e6 R0 s  ~' h. B
                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)2 C; @) A1 \, n" F! g7 F

# k5 G' ?' s# }2 _                        Resubmitted flow: unchanged : }; f0 P+ F6 W5 E3 Q
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
9 Y4 J; u$ [  w. w1 o                        Resubmitted  odp: drop
; u" K3 c' v& u0 c% B                        No match
/ H3 x5 g) a; ^! s
, w% k9 F! O5 n& r; X: rFinal flow: unchanged ! H4 m( b: E! s/ D9 W6 U
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
& B" _) Q8 s" V) b1 jDatapath actions: drop$ W: C# J( K! c) e

4 J* v' e4 w$ G9 L' J; l" l( ^9 W) l$ sudo ovs-ofctl dump-flows helloworld                                                
- W; C; f7 w. \- n" Z3 a# cNXST_FLOW reply (xid=0x4):
6 }% j0 h/ d6 ~  h: u- j# a. Bcookie=0x0, duration=90823.14s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) + Q$ F4 k0 K  I$ b6 b/ [
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
- U( d. f4 x$ ~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 . u* ^/ A2 D6 N/ N) A
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)
5 H" p4 W2 ^; icookie=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) + x0 i2 {  W: z/ ~. U, L7 x
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)
$ b9 c7 f' }5 j; b; w* f3 Xcookie=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) 6 E1 j! `/ \6 M9 W! R. ~$ u- V3 l
cookie=0x0, duration=86643.297s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
% b/ ?5 A+ F* H- d4 Ucookie=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)
, t3 s6 I& p; D% L9 F3 ` 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]
/ F2 Y0 B9 D1 s7 H) z- _/ I5 W/ x; }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]+ ~: N" @' p) J% n! t
( h' e# x- t1 H, A
实现第四个table 3: Look Up Destination Port
7 x3 S# N3 P- p0 b- f, s
# L8 N+ \9 R5 y6 g: b( s1 d在table 2中,vswtich通过进入的包,学习了vlanid –> mac –> port的映射后,对于要发送的包,可以根据学习到的table 10里面的内容,根据destination mac和vlan,来找到相应的port发送出去,而不用每次都flood8 ?7 @) M, p' l) N3 Q" f( i' @( u1 A
5 }8 Z7 M) l5 S0 N* [) m5 u6 ^4 @+ G
sudo ovs-ofctl add-flow helloworld "table=3 priority=50 actions=resubmit(,10), resubmit(,4)"
* F8 I0 c' A% C( o9 L0 \8 R+ B; n9 i; m1 A, a) X/ c% @/ N
添加这条规则,首先到table 10中查找learn table entry,如果找不到则到table 4
" B* n3 y1 j5 `1 x2 M- _% i7 G! O" `" j
如果包本身就是multicast的或者broadcast的,则不用去table 10里面取查找。, g, |  C; b) }& S9 ~; X
' B' r6 c  G( @# y; 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)"# F- R$ S1 ^- D  Q  M+ x
! m# O( j) ~& ~0 [' p- j0 U  Y/ m
我们进行一项测试
! }) ^! q( l4 B5 Z
4 c) Z3 n# f1 R" J$ 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   
4 ~" \& T; p0 S7 `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 $ v7 b- w2 C7 r- B7 Y
Rule: table=0 cookie=0 priority=0
7 F1 G0 E/ L0 \6 V/ BOpenFlow actions=resubmit(,1)- a0 i1 P. Z1 S
! j) o- G9 G5 y- ]# \5 T
        Resubmitted flow: unchanged
( S" ~( H5 m  ]3 E2 X* d. G$ C; I4 U        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
% ?7 g% }4 P) m; D        Resubmitted  odp: drop
' U! f2 v$ U4 b) U1 a1 k        Rule: table=1 cookie=0 priority=99,in_port=1 ' q" N/ e- _% r3 j& n8 {% P
        OpenFlow actions=resubmit(,2)
* g. C( {. `* b# ]7 `9 Z
/ i7 D/ T- q( j! D6 U' t/ O/ U                Resubmitted flow: unchanged
# Y: s& g& \4 L0 I7 M                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
, E" K6 p# x3 l; x  e+ a                Resubmitted  odp: drop 3 w1 j: }2 z# B9 ]- P: i  E
                Rule: table=2 cookie=0 , x1 a9 ~3 K' g) N; ~( [$ B+ ~
                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)/ B# j, m6 I, B- ~; k! o- H! m2 m
; v0 A8 v) ~# }+ I
                        Resubmitted flow: unchanged ; W/ }4 Q+ R0 c! m3 e+ K5 L7 S+ e
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
. a2 c" h8 R7 ?" Z7 o: T9 q                        Resubmitted  odp: drop * J% q3 E" W1 x
                        Rule: table=3 cookie=0 priority=50
/ L/ k4 q2 U. z. C# }- g: M! Q/ x                        OpenFlow actions=resubmit(,10),resubmit(,4)$ _/ P$ N) i, x& @

, A/ X9 f* I3 M' {/ d' T5 Z                                Resubmitted flow: unchanged
% U5 j* b& j) `% N; N                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
/ ]5 O% ^- ], f% p& }                                Resubmitted  odp: drop $ b; l/ N# f4 O
                                No match. i3 [1 l; T: ~( v! x* x; {
/ n( l' g& J6 Q" g+ t
                                Resubmitted flow: unchanged 0 }4 k' e0 `/ D
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
4 z& J7 g0 o0 U; ^. T3 q1 w                                Resubmitted  odp: drop
8 o$ H. _, \2 o$ Z- z                                No match% W, q8 Z8 C% W/ C9 r: L) v
! w+ f7 M) w& R* h1 d" {0 i
Final flow: unchanged
( v" ^/ e4 v# Z  y/ u" ~! oRelevant 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
, h; l! z8 }7 {! |" WDatapath actions: drop
6 K# S; ?8 H" m& X  p$ j: N: y1 D& p
由于目标地址f0:00:00:00:00:01没有在table 10中找到,因而到达table 4.7 |. l$ X& i$ q

) p& C4 c3 o& r但是这次测试使得table 10中学习到了mac地址90:00:00:00:00:01
$ H0 I& \. B3 \4 l" b4 T/ F5 D' A8 a! S+ N
$ sudo ovs-ofctl dump-flows helloworld & H+ G' O, ~4 E
NXST_FLOW reply (xid=0x4): % b7 w) y- B- s7 F* I
cookie=0x0, duration=91588.452s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
+ s9 U! w2 r2 b- i/ X' ocookie=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 0 `! \. q$ r% ?0 i9 G, i
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 : v1 f" K; S3 ?- @
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)
: y# e. f4 h( Z4 v! bcookie=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)
6 b' X5 p8 o& n. I6 V' Ncookie=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 o0 s# j+ c" S3 tcookie=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) 8 {/ b9 i7 k$ ~& N( _3 g3 _
cookie=0x0, duration=87408.609s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop ; S4 i. ]% `/ k2 g7 k
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)
2 B% W$ ~6 r: ?: q2 N8 Acookie=0x0, duration=352.841s, table=3, n_packets=0, n_bytes=0, idle_age=352, priority=50 actions=resubmit(,10),resubmit(,4) 9 b, I6 v" U+ z
cookie=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)
+ J0 X% T) a% q; H2 n* @' s- s 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]
8 n: ^: e# x' y. U; I% Acookie=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]
5 {$ L9 g/ w6 C* c1 U6 lcookie=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]
+ E) ~# K. G8 s7 ~- H9 I3 X3 P* v% y
; E- A% K2 [* S' f7 k' n0 C9 t下面我们进行另一个测试! a7 L# t6 w5 ]7 i1 D8 B( ^, q

" l; S6 }' }6 n0 l$ 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   
8 g2 u% G& P0 ~/ r! A* DFlow: 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
1 f' I1 O) L, ~1 l* XRule: table=0 cookie=0 priority=0 # ~) B" V. B% s1 H: M- s2 J' A
OpenFlow actions=resubmit(,1)
( K7 F" L+ c, I( C! X: t" H/ z& M* h, W5 {* w- l
        Resubmitted flow: unchanged . M4 {( l+ E7 V9 x3 ^% i( G
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 9 g: n1 n# Q* {8 n
        Resubmitted  odp: drop
' @5 ]' f6 R2 a        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 3 O3 E* b$ p% U1 m$ |, a
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)% F  W; S+ F- \# n6 L

; ^1 ?% o) Y! e; @, V4 Y# j% Q% W                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 . I8 r* o) f) D: @, }# r
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 0 b- x7 U+ v: B  X, I4 |- Z2 I- w+ y
                Resubmitted  odp: drop
" ?: b2 A+ `7 N# J! z                Rule: table=2 cookie=0 % j: e! s  S* {5 H: v
                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 r/ @; s, C% X0 M5 X1 e
# q: }2 h0 p3 w3 r
                        Resubmitted flow: unchanged 0 E, q$ u4 z+ C7 o5 O, y; t9 X& t: }
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
" J" z' p! W8 o, [$ M3 c                        Resubmitted  odp: drop
! @1 v4 Y* N+ _# P. b$ a+ z- q                        Rule: table=3 cookie=0 priority=50 / u$ j8 I/ E4 G: j5 @8 r; J
                        OpenFlow actions=resubmit(,10),resubmit(,4)% V7 x8 j; ]' Z7 Q) _; z
5 g6 c1 E/ }9 k  A6 C7 u
                                Resubmitted flow: unchanged
  g' b: a+ W  _+ i6 m- }                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
$ C: C5 y+ I% C! B+ [3 [/ |                                Resubmitted  odp: drop
. O3 s3 C. d1 c1 [, m                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01
- k5 s0 f4 k: q/ f8 s5 k                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]
: p& c3 U% S# m' [3 `9 P' ~: Z' V9 Z. [7 m6 P$ m
                                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
' b: O2 z# T* U' e- B0 W' @$ n                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
2 q( x8 `% r) {                                Resubmitted  odp: drop $ z- p  F/ f; ]* g
                                No match
4 e+ H; R1 G4 u* @/ I
: N' d5 s# H2 ]) NFinal flow: unchanged 3 m, E( C# {" g$ C8 Y$ k
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 7 \/ Y6 v% W" Z
Datapath actions: drop
1 _  m5 ?) x6 l3 {! G3 ^; N6 S5 j5 z$ A% Y: p
因为刚才学习到了mac地址f0:00:00:00:00:01,所以这次在table 10中找到了这条记录,这次同时也学习到了mac地址90:00:00:00:00:01+ c* @. r7 u6 e/ @% M4 l0 @
' y. ~; \2 W' ^" P- r4 q8 z
下面我们再发送第一次的包( X% |" B4 d: Q" _) W0 t

1 ?4 H8 }- q9 S- f3 H8 [( u$ 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 * {- V' k, ^  e2 U3 G3 j
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
# b4 V$ M4 p5 Q7 ERule: table=0 cookie=0 priority=0
2 S, W4 _. m% `* `- I+ o  V0 ?, rOpenFlow actions=resubmit(,1)
/ s- G  I$ `! u0 B" J. ]9 B: p3 ?9 i3 \6 n
        Resubmitted flow: unchanged
& l3 k7 @! W6 W# z9 V$ i3 A        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 " k! f% w$ X' X0 S) M$ R. q' w) B6 J. ]
        Resubmitted  odp: drop & V* y. K  p! x
        Rule: table=1 cookie=0 priority=99,in_port=1
; p. i# X- Q: W4 f        OpenFlow actions=resubmit(,2)4 M  b- P% x, {0 e4 l) G* t
3 l) V6 h- _5 ~4 T, O3 _
                Resubmitted flow: unchanged 1 ]0 R0 \) D6 U; A/ I# X/ y+ m
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 7 ?$ K4 {5 _4 l: ~  h2 k  |
                Resubmitted  odp: drop
; `2 N- ^% J' G0 Y                Rule: table=2 cookie=0
: O. j* u  A# |' [; U0 k6 v                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). l* [2 ^/ t+ {% V$ E
# q  {$ h/ V& u3 w* W
                        Resubmitted flow: unchanged
- I# G3 |7 u7 L. }) n8 y( H                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & m( @) r/ q) L
                        Resubmitted  odp: drop
) J# C. h1 b+ I0 T% `                        Rule: table=3 cookie=0 priority=50
" f/ i) E0 z( f                        OpenFlow actions=resubmit(,10),resubmit(,4)
, Y! T. H6 B. o! R/ r
) ^! T2 A4 O& _' d                                Resubmitted flow: unchanged
, f  `0 u7 N7 A, N4 c+ X9 Z  O                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
" t) g7 @: u( s6 w/ T* b                                Resubmitted  odp: drop
! |, t5 k# R9 s, k. k4 u% Y                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01
+ w( j8 I" R& O, t1 t+ E                                OpenFlow actions=load:0x2->NXM_NX_REG0[0..15]$ Y7 q( ]2 f/ N

- {3 L( p2 P- B( S                                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 6 G9 l- k- E* g8 z1 h- C: X
                                Resubmitted regs: reg0=0x2 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
$ |& X; D0 _8 d7 R* M                                Resubmitted  odp: drop ) @0 L9 o7 O: ^; \8 H
                                No match- d, B4 H7 _2 ?
' L7 P: ^  i% G1 c
Final flow: unchanged
8 v- b, R: h2 _* U: G, n$ GRelevant 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
! u5 i  R& c1 y" F2 r2 WDatapath actions: drop5 n3 o0 O) ?; U/ ^: K

& N% i8 V4 D! x) n4 w发现也在table 10中找到了记录
$ C. c- }4 Q& O( v  V  u8 ^- ~+ U
4 P1 }! W% e! G* J1 K; \) r, ^: F7 e2 b实现第五个table 4: Output Processing
: P) K4 F$ E& U8 e/ X" t
) `0 k3 h4 c- V' t+ T$ L( H这个时候,register 0中包含了output port,如果是0则说明是flood。
+ V! H9 D. i* y4 B. q$ ^7 ?) L! {3 a9 j
对于port 1来讲,是trunk port,所以携带的vlan tag就让他带着,从port 1出去。/ C  m2 c, E# |- [

7 A9 z. V7 H$ M. r8 h: @8 csudo ovs-ofctl add-flow helloworld "table=4 reg0=1 actions=1"
! B8 o9 A; R' U* Q+ l/ k3 y
3 u1 L+ J# ^* W2 H对于port 2来讲,是vlan 20的,然而出去的时候,vlan tag会被抹掉,从port 2发出去
- B# m# ?8 m4 t& O" L# e( t5 M2 \0 c' h1 y1 {9 l' j
对于port 3, 4来讲,是vlan 30的,然而出去的时候,vlan tag会被抹掉,从port 3, 4出去) G5 N1 E5 D" I# Q4 v

. T; c' V8 _# ]$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   0 R6 d9 z4 x, v5 Z& L: h
        table=4 reg0=2 actions=strip_vlan,2 1 L- Z! S! w; \& d2 {( O3 K
        table=4 reg0=3 actions=strip_vlan,3 : E+ _5 I  i0 M. m  Q
        table=4 reg0=4 actions=strip_vlan,4 * ]: r$ u3 e) c
EOF
. i  c: _- h! H% l+ a+ p, C- J- N8 [, X, m8 ?3 H
对于broadcast来讲,我们希望一个vlan的broadcast仅仅在这个vlan里面发送,不影响其他的vlan。
  [; |+ e+ X7 p4 y8 Z9 t% @3 [. x: H1 }
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   ( B% S. h0 ~1 r* C1 x
        table=4 reg0=0 priority=99 dl_vlan=20 actions=1,strip_vlan,2 + c0 h( v& \$ U  ^* v/ k- o* M
        table=4 reg0=0 priority=99 dl_vlan=30 actions=1,strip_vlan,3,4
& M7 P! ~5 S: V+ A        table=4 reg0=0 priority=50            actions=1 * q  E, z7 e8 |" x5 i6 c
EOF
" H) b" I8 y% X/ F4 v( S% E: Q6 w$ P0 K3 F7 R9 y
所以对于register = 0的,也即是broadcast的,属于vlan 20的,则从port 1, 2出去,属于vlan 30的,则从port 1, 3, 4出去。
& |# ]# \/ b* j. C8 B6 ~& }+ @( {0 a  N5 l0 l# v
$ sudo ovs-ofctl dump-flows helloworld
0 v( P' ~& M8 I9 O9 F) CNXST_FLOW reply (xid=0x4): 9 A2 j- \5 U. b7 l9 M7 V8 ?
cookie=0x0, duration=92909.119s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
- q9 _; m3 y; V3 ^8 ucookie=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 & J  n/ G2 w2 ~; j/ F. k
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 - L, Y) |+ ^0 \* A  X! i" C2 L
cookie=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) $ R: s9 U$ Z: Q! v
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) $ p/ w1 {3 t: W: P- e
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) # A! ?9 d+ K  A' M. v* {" ]
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)
7 V  J" g: i0 a5 w9 Bcookie=0x0, duration=88729.276s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
% l9 M8 s: p2 hcookie=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)
- \$ i1 h0 w& C5 v, |cookie=0x0, duration=1673.508s, table=3, n_packets=0, n_bytes=0, idle_age=1673, priority=50 actions=resubmit(,10),resubmit(,4)
5 E! K. e8 \) A: s4 P, H- \8 d2 Ecookie=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)
: q2 d( F+ Q0 g  |( Wcookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x3 actions=strip_vlan,output:3
9 c  e( j5 M2 i1 _9 ?" wcookie=0x0, duration=228.839s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=50,reg0=0x0 actions=output:1 ! \1 B6 s0 {" R' q' P6 b
cookie=0x0, duration=483.068s, table=4, n_packets=0, n_bytes=0, idle_age=483, reg0=0x1 actions=output:1 * l) Z7 S1 F* W1 f7 N: l7 T* k
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x4 actions=strip_vlan,output:4
- g& _' }5 W5 H7 Ycookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x2 actions=strip_vlan,output:2   ^2 i( P# W$ W
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
4 A& M: z& a( @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 ( g; m1 t/ @) t& `, a
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]
  O- l. H2 N/ Z9 dcookie=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] 6 }( o, ^2 g9 i3 o; H9 |; }
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] 3 S& X3 x+ ~9 B+ y( N# I1 w+ |
cookie=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]
0 l. w8 E, ?3 z8 P+ V5 m8 H5 M
! f" S* j; e7 t. [3 T首先来测试一个multicast和broadcast
0 ?# [1 f+ V# P# B9 U
7 a4 y: o0 r4 a如果是一个port 1来的vlan 30的broadcast+ @: e9 Q8 O& I3 ]$ l$ O
9 Y# d( T  V% G- D# r8 v5 ?
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=ff:ff:ff:ff:ff:ff,dl_vlan=30 : ]+ K2 Z8 ^: z
Flow: 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
. o4 X$ P! M0 m  H$ u0 W0 _) WRule: table=0 cookie=0 priority=0 : ?( N) ^' D4 Z0 j/ Q
OpenFlow actions=resubmit(,1)
7 {) Q. c# G0 M/ H9 F9 _4 o
+ s4 C  N" G% V, a0 G' [0 l1 q        Resubmitted flow: unchanged % z0 A# Z) p: r0 D
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
& G' I9 \2 t' C4 ?; @1 L        Resubmitted  odp: drop
! n" X5 |' [) L        Rule: table=1 cookie=0 priority=99,in_port=1
; u1 W! s0 i' h/ C+ ~9 {. G- ~1 ]2 @        OpenFlow actions=resubmit(,2), T" W7 z/ D0 e5 {; \7 k+ }

; F1 Q7 v& V) ?; |  H                Resubmitted flow: unchanged . q* j! ?3 Q9 R; I* l7 c5 X
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0   F& z+ C( b, z: B9 [; a' e
                Resubmitted  odp: drop
# T; U* \7 z3 y- B$ J9 f5 w( A                Rule: table=2 cookie=0 / R$ c: P& g2 w' z. z  R. [! E
                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)
% n1 A3 N! ^9 I. S
3 J5 @; N; m; K9 A                        Resubmitted flow: unchanged 8 s  v$ w  G* c$ c2 }
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 0 V' d+ h* u1 Z0 j9 {" k
                        Resubmitted  odp: drop
# {  s$ p% e4 N0 X" N) C                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00
7 E+ o0 @& a( J2 f6 d                        OpenFlow actions=resubmit(,4), Z3 C  r+ v( V6 u) V! i
& C9 N9 q' b0 V
                                Resubmitted flow: unchanged
) v; G9 \8 f3 h$ `7 L  ?/ U0 A                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
) |1 w9 B+ _' `' k% R# ]; {9 b$ j2 k                                Resubmitted  odp: drop
- X" h1 J& h; m; x% r+ h                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
: G6 U* S/ s- Y! P7 L7 K                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
- z; c  o2 {+ {! n$ X                                skipping output to input port' m3 N' E7 I1 E( }
5 E+ O' U  a( ^5 t- |4 g9 f
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 . ^2 Z4 y3 u6 ~4 X
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 2 k( z" R* k: P
Datapath actions: pop_vlan,12,13
, R$ p' o4 i" S) o& M/ x5 h
# R( {* d5 s/ h; `3 e5 P' N结果是port 1就不发送了,发送给了port 3, 4* s  C* x0 y* P: l
& z  g5 n$ w1 Y( [. {
$ sudo ovs-appctl ofproto/trace helloworld in_port=3,dl_dst=ff:ff:ff:ff:ff:ff 5 ~! K  ]; _8 u4 Q
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 $ p7 z5 Y5 R. K7 G
Rule: table=0 cookie=0 priority=0 ! Y/ {% y2 I( J; G4 Y' r! D  p
OpenFlow actions=resubmit(,1)# o' N! G+ d5 _/ i6 s. O2 c) s
+ `% k4 E0 |& e5 U& t/ X( n
        Resubmitted flow: unchanged   \: @4 X6 U9 e& ^: h3 w" G
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
# h/ m3 c6 g  o2 |        Resubmitted  odp: drop
% Y3 G' w6 u! B        Rule: table=1 cookie=0 priority=99,in_port=3,vlan_tci=0x0000 - p- k. v& O) u' O8 D- f4 m. S
        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)
( L- Y. T5 h& j2 M+ ^" W, }* p/ h' L% l4 t( h" q- R: a+ |3 t* }
                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 1 I8 |. m0 p/ z) }/ P7 P$ B8 \1 p
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
( b/ i! B; K3 g$ l& K- _) p                Resubmitted  odp: drop 8 l5 @. t+ P  x( O0 r& l6 t  a
                Rule: table=2 cookie=0 + R% C: W, z7 H* J: f7 `
                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 F5 \! }' M8 @( |: L
4 ^+ _1 a' N  C" Y/ M; d                        Resubmitted flow: unchanged
4 F6 t. K, q/ p5 Z1 }                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
* i+ k+ @* m7 ?; T9 N                        Resubmitted  odp: drop
% Q- M! f7 v7 X9 k8 s5 d  Z                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 ' t' y6 x, L7 X) |
                        OpenFlow actions=resubmit(,4)
- D: r4 l4 D5 M. e$ H+ y9 ~$ U7 e; b/ f
                                Resubmitted flow: unchanged
& d5 W+ N, s/ G  C, l& z                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 1 J  O/ V+ M% A) f3 r4 v
                                Resubmitted  odp: drop
, d, T3 g* a  E! I7 m                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30   d) h- p* V# |" z$ Z7 _5 J8 Y/ q
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
3 w8 r. j+ R) K, d, p2 ]                                skipping output to input port
5 o3 s1 |1 w0 I5 B0 |; ~& d9 g) a& F4 Q7 l
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
0 G6 H% r6 `- {# pRelevant 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 * k4 @2 v; A$ }* E8 e+ r1 H
Datapath actions: push_vlan(vid=30,pcp=0),10,pop_vlan,13
6 I/ p: m" O/ i3 d/ o: G1 e8 ^6 Q' W- l. ?8 d% Y
接着我们测试mac learning
7 _6 z; q5 _+ {( M, }: Z0 ~
; @- ~1 v( s8 k6 r( |6 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   + P& b5 _6 ^. ?* Z2 k0 m5 p) W" l
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 4 @% V) [- l9 y" w! E
Rule: table=0 cookie=0 priority=0
: f2 L; M0 Z6 OOpenFlow actions=resubmit(,1)
/ U2 \" B! I" W7 w3 N1 D; w$ J/ y" P
; Q4 {& l/ `" ^; F        Resubmitted flow: unchanged + X- H/ V9 A$ \  A; E
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
5 ^) t7 r+ B6 p+ x        Resubmitted  odp: drop
( g" \; I0 j$ Q: A8 o6 E) X) ~        Rule: table=1 cookie=0 priority=99,in_port=1
) A3 f  B6 ^* w. ?9 o        OpenFlow actions=resubmit(,2)2 h& m8 ?8 A0 k

* W; Y1 M; _: P# G4 D9 k: O5 _                Resubmitted flow: unchanged 8 H% v9 V7 x6 h, B
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
: k+ [/ h" }8 j, ]0 g                Resubmitted  odp: drop
& B/ J6 S3 L$ _/ |                Rule: table=2 cookie=0
5 l; u1 \7 @2 {& ~0 ]$ E; l                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)
. V% Y: X" E$ n$ M
' W% @3 C+ M& S  Q3 [0 D                        Resubmitted flow: unchanged
* j- W6 }8 K1 P) M                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 J: o3 o" H( L& l" y
                        Resubmitted  odp: drop 4 k3 w0 [; p2 u" u6 g' v" J( J
                        Rule: table=3 cookie=0 priority=50
+ Z( k7 j- E# c8 a0 L8 q                        OpenFlow actions=resubmit(,10),resubmit(,4)/ O3 y, @" S2 _7 @6 S$ j. S
# m3 d9 u  B3 X" v$ n4 k1 R
                                Resubmitted flow: unchanged 0 F& w" r7 s) C( f/ M
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 2 w, [7 M1 D# c! Q
                                Resubmitted  odp: drop : H% A/ ^0 d8 d7 s  O9 |0 J
                                No match" Z& o# e, S* }8 l9 I: ?

- W& R( y2 S. Z                                Resubmitted flow: unchanged : W8 z0 ]0 S& v' l
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
: ^7 w, X( r* b" }; D: ^7 G                                Resubmitted  odp: drop
' {; [7 L. v+ H" [5 z& |2 V                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 : W3 E' L: Q1 s4 S+ ?
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
. q- g  @1 a. g                                skipping output to input port( m! F$ X% [. G3 ~
3 A% n4 w* P) H1 L
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
( n/ q3 o# U+ nRelevant 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 ; z1 J* ^) }  F# N! l- D' o
Datapath actions: pop_vlan,12,13. j0 U% Y; q7 N1 t5 [/ i
, Z( c0 Q! g* K' a0 H
由于这两个地址没有出现过,则除了进行学习以外,广播发送给port 3,4
0 Y% ]8 B3 f5 K2 `0 D, \( H1 v  u, N' g) a
$ 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   4 U4 \; B2 D: s
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
2 P2 v) O$ y6 e& b; k6 [" |Rule: table=0 cookie=0 priority=0
: M4 e% o, m6 ~1 G4 uOpenFlow actions=resubmit(,1)  i+ P- j& H. T- P( R: g) S4 ~

, g$ o! a2 Q) c- N& k* [+ [, l; N) ~        Resubmitted flow: unchanged
& G9 ?* J5 m0 W7 E4 ]7 W& ?% `$ o        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
* w9 I& l. Z0 Y  k        Resubmitted  odp: drop
+ u! a2 r4 X( L3 K        Rule: table=1 cookie=0 priority=99,in_port=4,vlan_tci=0x0000
' Q' d1 d5 Y3 {" X0 W        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)6 R3 r* @6 E: p" L
$ h8 \3 a' F; D& k) Y" Q/ ?2 w
                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
; V# S4 T! W  U. F                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
8 Q  r* U5 I3 ?2 D                Resubmitted  odp: drop ' t4 |! {9 B; C$ M: q/ N4 \+ t
                Rule: table=2 cookie=0 8 n1 B7 ]4 M0 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)
. L, L. `1 ]: @" H. o
# q9 e# u, W% _2 F% {' c                        Resubmitted flow: unchanged 9 f: t- O4 l. ^
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! i7 S# G$ K$ S2 E
                        Resubmitted  odp: drop
% f' T2 B' F! ^2 B2 g                        Rule: table=3 cookie=0 priority=50 , N* q5 J* B3 k* K7 z9 Y
                        OpenFlow actions=resubmit(,10),resubmit(,4)  m( k9 R3 E8 h3 u: K3 B# j, u
9 C! K* l+ k) l! W: ^( Z: l
                                Resubmitted flow: unchanged
! w0 u8 [% R$ Y. W0 k: j                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ( o' A: g9 R- }. ]
                                Resubmitted  odp: drop
- P3 j/ g& }+ D1 C) `                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=10:00:00:00:00:01
: O- v; q0 X5 l( J                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]
3 C1 c6 k+ S# o, q8 B
1 i# u1 P( A, C- z3 F                                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 3 k% |9 g. r8 m. i
                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
: k2 l4 Y& a0 Y* M* T* G                                Resubmitted  odp: drop / K2 h2 _6 d# X' U  ?# u# R
                                Rule: table=4 cookie=0 reg0=0x1
6 H* _/ A2 I/ ]) \6 K/ H                                OpenFlow actions=output:1
; q; `+ h+ m, ^6 j
! D3 H, E. r- p6 E8 z$ zFinal flow: unchanged
0 w( y1 w6 E# R9 `6 I) q7 s( j1 DRelevant 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 7 w0 a6 Y2 c- n* R1 T4 z3 _
Datapath actions: push_vlan(vid=30,pcp=0),10! Q: F1 a6 F( a: A$ ?! |

5 r) M3 j& A; L+ e  P/ E/ b7 w回复的时候,由于学习过了,则仅仅从port 1发送出去。
0 r% X8 b3 b8 Q6 y" i6 U% R3 ^. u$ U
$ 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 6 R' d2 Y+ v4 Q9 f( c9 `* 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
; S' ^- z+ U. J: H" A/ uRule: table=0 cookie=0 priority=0 $ b0 `  _1 `3 T5 J1 P& Y
OpenFlow actions=resubmit(,1)9 J! H. A* F# g) B" E

) s: M9 `8 M6 |+ E# I& G        Resubmitted flow: unchanged
9 M; L; Y! o4 I6 C  z& B        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
+ r; J( _# J8 R" X% B% w' N  F# Y        Resubmitted  odp: drop % b* O2 y4 n8 ^& O2 W1 _2 E+ T; O
        Rule: table=1 cookie=0 priority=99,in_port=1 4 P' ?: \" d, \
        OpenFlow actions=resubmit(,2)" m& u( u* r2 @% A

& A+ u0 I$ N0 n% F1 M- o$ O                Resubmitted flow: unchanged
0 J- m) ]# M3 c1 R5 q+ [- {+ q                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 * Y6 o: w  {" i* v9 f
                Resubmitted  odp: drop ; D  C  D0 `4 q8 X5 W, l: m
                Rule: table=2 cookie=0 6 g; c1 o  }- @3 h% p+ w) b
                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)% i3 W* E- O" d( a
: ~- @3 y  V) f2 C/ V! V
                        Resubmitted flow: unchanged 8 J4 O* O; t$ E- M  ]7 |
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 . b1 V0 U9 q, V5 [, F/ m( Q9 @' F
                        Resubmitted  odp: drop " R! M0 d0 ?% R1 q" T5 n
                        Rule: table=3 cookie=0 priority=50
7 }" u" ~, O: C) @3 H& f! g6 }                        OpenFlow actions=resubmit(,10),resubmit(,4)% |' W$ n. G! n6 }0 K1 T7 o# i) r* u" ^
- }7 W5 @4 w2 p7 p. K
                                Resubmitted flow: unchanged # L# n) [/ j, c8 C+ T. \# [4 ~
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
+ J# B, N  @$ G7 g9 q                                Resubmitted  odp: drop 8 i1 h! J0 {7 `! _
                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=20:00:00:00:00:01 ( I/ i7 J& ~" l; h3 H8 [
                                OpenFlow actions=load:0x4->NXM_NX_REG0[0..15]
1 Y1 M+ i! ?. q0 p. e5 D! r: O% E" G! K9 U# c5 u) C
                                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 ; G# p2 ^  W6 C% R: K
                                Resubmitted regs: reg0=0x4 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 . ?, L) {1 M2 ^! P( L/ x2 A/ x
                                Resubmitted  odp: drop 2 W! G8 Y& f5 x* O; J4 K
                                Rule: table=4 cookie=0 reg0=0x4
( z0 L9 ]% P, a                                OpenFlow actions=strip_vlan,output:4
7 G4 s: S8 \# y5 R$ Q3 O( C) z3 m( q7 U. c3 w0 R8 g
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
' o" v% S4 M* y4 YRelevant 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
5 h; ~6 ^" {6 MDatapath actions: pop_vlan,13
) m5 d3 j# P- P5 \9 x# r/ d2 D0 g0 F
由于在回复中进行了学习,因而发送的时候,仅仅发送port 4
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

北京云银创陇科技有限公司以云计算运维,代码开发

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 点击这里给我发消息

GMT+8, 2026-4-8 10:35 , Processed in 0.071764 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

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