易陆发现互联网技术论坛

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

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

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

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

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

x
ovs-ofctl dump-ports 输出交换机的端口统计信息,包括收发包、丢包、错误包等数量。 ovs-ofctl dump-flows alubr0  
) y+ ~1 M* D& y1 B: T3 f7 HOFPST_FLOW reply (xid=0x2): flags=[more]# K. e- ]5 O2 G4 l
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[- ~; u/ C& s6 [1 r* n# k
0..11],strip_vlan,resubmit(,22),resubmit(,23),move:NXM_OF_IN_PORT[]->NXM_NX_REG4[0..15],move:NXM_NX_REG1[0..15]->NXM_OF_IN_PORT[],re
7 L8 j6 d: T3 H8 K) V5 \& }submit(,4)
& s9 X/ d3 I' r9 x/ ? cookie=0x1, duration=1263.439s, table=4, n_packets=36175, n_bytes=26587191, priority=0 actions=resubmit(,27)5 p% @- s$ E/ g& j
cookie=0x1, duration=1263.439s, table=5, n_packets=35646, n_bytes=26564073, priority=0 actions=resubmit(,7)
0 |% `  ?$ r! V1 N: i; u cookie=0x1, duration=1193.636s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=18038,dl_src=fa:16:3e:83:4c:69 actions=drop
9 o; y9 J' g* ^/ D, z4 q" _* w0 j5 O 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
- e# q0 r) A! _! a/ l& C 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. D+ R/ B  g2 S" x% Y" b% H% c
cookie=0x1, duration=1176.930s, table=7, n_packets=522, n_bytes=21924, priority=32769,in_port=21588,dl_src=fa:16:3e:f7:f2:b0 action
7 p! U9 Z6 U, a. Y0 `s=drop
2 [( J2 W! D  m  R. O/ S cookie=0x1, duration=1256.088s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=5670,dl_src=fa:16:3e:35:a6:e0 actions=drop
+ S4 o( P- U7 I) I+ N 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=drop4 a. ]7 j0 d! Q! _8 L
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: x. h& i& m0 V5 _7 j2 J
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=drop2 J8 C$ N: a" O
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=drop9 N- t- w- T5 \  y9 n2 p3 Z
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=$ h: B1 A/ q+ F+ Y
drop
% \* s. k9 K6 T1 V$ \ cookie=0x1, duration=1214.428s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=417,dl_src=fa:16:3e:ca:06:53 actions=drop
' \% `6 H# G+ f& D# p; e/ H0 Q! N3 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
/ X0 `2 \( k  w. O8 ^5 hop4 e( P4 E! r) y7 V& E
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* \/ V& M1 C- U8 p
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: N1 p3 S& H1 n8 }) a" [; e6 _
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: Z1 i2 p4 S5 M
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=
4 Z7 L; H& J2 }7 `drop
- C2 O8 Z: J5 C: J# p9 v8 R 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=drop3 k( O  ]& S" y0 e& p) P1 ?
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( d# X9 d' Z0 R( H7 l. ~
s=drop1 Q, r; U4 @0 k; \; H
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
' e( Z! ^% B5 u2 w1 O# U8 _, X/ Cp
0 q6 M- x, h2 F5 @( f* Y9 G8 ^ 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=drop4 m9 f8 k2 h$ S9 n0 P$ t8 Y
8 l# B! B" z" ?  Y" j6 D6 ?# e6 |
$ t  X4 H6 K2 o: A
如果设为fail-secure mode,则初始情况下flow table是空的,否则会有normal$ sudo ovs-vsctl add-br helloworld1
7 M: `" \. |& D6 t/ I7 `/ X- [$ sudo ovs-ofctl show helloworld1 0 f$ o1 ]) G% r) I4 l
$ sudo ovs-ofctl dump-flows helloworld1
0 {0 q. M) B/ i7 R3 tNXST_FLOW reply (xid=0x4): ' ^. U; J4 W4 E' i6 B
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
: f7 U5 X# x, Tsudo ip link add second_br type veth peer name second_if    # x9 L* N3 B. J
sudo ip link add third_br type veth peer name third_if       ! B' c/ E& v" ~' I
sudo ip link add forth_br type veth peer name forth_ifxxx_br将是添加到bridge上的。我们添加四个端口portsudo ovs-vsctl add-port helloworld first_br -- set Interface first_br ofport_request=1
* c' L: E% C2 d  r* qsudo ovs-vsctl add-port helloworld second_br -- set Interface second_br ofport_request=2 2 W8 R6 |% u% K" G. O5 t# y" p
sudo ovs-vsctl add-port helloworld third_br -- set Interface third_br ofport_request=3 + X' e6 [  L9 c
sudo ovs-vsctl add-port helloworld forth_br -- set Interface forth_br ofport_request=4ofport_request是指定端口号新添加的port都是出于DOWN的状态) a) r! F& }6 G3 w3 O/ d
 楼主| 发表于 2019-10-25 10:00:34 | 显示全部楼层
把它们设为UP
. L( w7 u5 I2 B# S3 z
! a0 H; A9 ?: y" X% n" J' isudo ip link set first_if up
" ~3 X, {. G* _' Qsudo ip link set first_br up & D  O% [2 k' c
sudo ip link set second_br up     
3 }( x0 i* w; T: H  C' n6 i$ Xsudo ip link set second_if up
+ j& q( W% \/ X6 H1 O- b7 c5 i8 Msudo ip link set third_if up      5 a# j5 ^1 _& x% J/ [
sudo ip link set third_br up     
1 H* ^. q, p) a" |& S: Q) K; Hsudo ip link set forth_br up         * j7 _3 c4 W  m0 [# W" C  D, E
sudo ip link set forth_if up
" ?2 y8 H1 T- V0 v1 [/ I' q0 [8 s8 z3 {, Q$ S3 @
也可以用下面的命令
( f' x; n+ H/ v2 _' v) O/ U6 T$ E7 b7 C5 n% F
ovs-ofctl mod-port helloworld first_br up
 楼主| 发表于 2019-10-25 10:00:35 | 显示全部楼层
实现第一个Table 0,Admission control
0 C. C) d# O' d; c( s# @, v/ p9 ?" H; g2 o. X4 \
包进入vswitch的时候首先进入Table 0,我们在这里可以设定规则,控制那些包可以进入,那些包不可以进入。
1 B6 Q$ f, A$ P3 ?  R5 M- ]/ A* d
比如,如果source address是multicast的就不允许进入。: K* {- I# l. e$ X6 o1 F
% Y- r9 I# p) U8 G; F  t: j
01:00:00:00:00:00/01:00:00:00:00:00是广播地址
8 |- X7 d" V3 N* _, j! @# \% R00:00:00:00:00:00/01:00:00:00:00:00是单播地址/ F% t( N# b7 Y: @
这种表示形式类似CIDR
' S! M2 k9 @0 Q5 N; S& r4 `于是我们添加下面的规则:' Z0 ]3 I4 u( l7 s1 U
sudo ovs-ofctl add-flow helloworld "table=0, dl_src=01:00:00:00:00:00/01:00:00:00:00:00, actions=drop"! B8 y. Q: o. b0 j' I1 B7 e
STP的也不接受
# h1 H  A& C- h- x; Zsudo ovs-ofctl add-flow helloworld "table=0, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0, actions=drop"1 y, E: @0 @3 ]0 B# k# O9 N2 S
我们在添加最后一个flow,这个flow的priority低于default,如果上面两个不匹配,则我们进入table 1* \4 k' R, N' D6 d! P
sudo ovs-ofctl add-flow helloworld "table=0, priority=0, actions=resubmit(,1)"
" r$ y) |2 B" ?, i4 I2 g我们查看一下所有的flow6 f2 J0 |) D( r, r& b- M
$ sudo ovs-ofctl dump-flows helloworld        
0 n* n4 c& h& O6 ~: T8 U+ \7 `+ ONXST_FLOW reply (xid=0x4):
8 N# i0 p8 f2 U" c( B( Bcookie=0x0, duration=42.162s, table=0, n_packets=0, n_bytes=0, idle_age=42, priority=0 actions=resubmit(,1) 2 B, q9 v1 a3 g6 K7 y% j5 y
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 7 `5 m1 C5 W, n9 w2 p6 Q
cookie=0x0, duration=167.636s, table=0, n_packets=0, n_bytes=0, idle_age=167, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
; n$ A3 H" _1 M, i& U1 j. U, I
; g9 o  }6 B2 x- [) k2 Z- K测试Table 0; H4 e+ y' f0 v% }( ?1 r" I3 d

- a/ ]$ H& M8 h5 J! A' N有个很好的工具ovs-appctl ofproto/trace! K+ r. j8 g, H" ]

$ V8 V# G2 u4 Q' r( I6 v不满足条件DROP* }9 i1 I4 g# ]7 k" h7 s& X" {, Z

4 k( l( e& b) s$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:05
: y3 o# t4 k9 M- F$ nFlow: 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 ! ?. R9 L7 p3 G& w
Rule: table=0 cookie=0 dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0
+ F9 o: m! h: G2 lOpenFlow actions=drop
  j6 o1 S, x6 D& x& y/ [1 V
  J" N& ~$ G) W7 sFinal flow: unchanged : F- n- |$ C8 h9 P& F& M* q
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
. ^% A& C* a- b% T) @Datapath actions: drop% u& F  S& O& U: J/ F/ I& C( Q

7 X! w; F/ z3 }8 d满足条件RESUBMIT
1 E6 \) W5 E% ^& c* j8 ?" B* }+ o$ y5 p1 ^6 k+ E# [/ z
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:10
# I9 D' U$ p% x& N/ F6 yFlow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=01:80:c2:00:00:10,dl_type=0x0000
3 t8 R9 y2 e4 |  E( R5 E9 l( XRule: table=0 cookie=0 priority=0
# K* N" @+ F. A, x1 q- ?' w1 v9 eOpenFlow actions=resubmit(,1)' |# T% Q& w7 P4 Y
& E. j  N- q. c! @& F& ^
        Resubmitted flow: unchanged 2 S! b% v+ ^1 r. X. g' S
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! n0 o5 V" L( P  w/ x% a: Z& j
        Resubmitted  odp: drop
/ N/ S4 I9 G! \  O. U( |        No match7 {& F9 p/ d6 l

( G! s( o6 ]( y7 ZFinal flow: unchanged
' b7 ^$ e& L! t( ~) b7 ^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
% \3 _: V# B* q/ RDatapath actions: drop1 J" A' ?5 T! D7 ]" B1 d

: U1 M- ], o7 q3 o( p1 E实现第二个Table 1:VLAN Input Processing# S4 L- v8 g) J& ^7 M2 ^
5 p" i; M8 n& w+ D3 p/ Y" i  x; P
首先添加一个最低优先级的DROP的规则1 U7 T0 w, l9 b6 |0 d2 x& e; h, K6 q

5 j7 }6 N; E4 }- H1 r9 zsudo ovs-ofctl add-flow helloworld "table=1, priority=0, actions=drop"0 |- r, R0 K* H# H( O& I

  i4 S0 J! p# R对于port 1,是trunk口,无论有没有VLAN Header都接受。
1 c! G8 B6 ]6 L" x
$ R* ~" v8 a- |! a  J3 fsudo ovs-ofctl add-flow helloworld "table=1, priority=99, in_port=1, actions=resubmit(,2)"1 z: a& M/ I4 Y0 D

) h/ G9 R/ n6 U( f% R7 A对于port 2, 3, 4, 我们希望没有VLAN Tag,然后我们给打上VLAN Tag+ j* R3 ~6 U# ~* k- @

8 u6 t* m9 z# G' N0 e, Z$ sudo ovs-ofctl add-flows helloworld - <<'EOF' . L/ D& y/ ]- w7 ~9 z. Y
table=1, priority=99, in_port=2, vlan_tci=0, actions=mod_vlan_vid:20, resubmit(,2) . l( @( R" X1 O6 f1 Y0 w
table=1, priority=99, in_port=3, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2) 9 ^0 s! `0 _  a9 f5 U
table=1, priority=99, in_port=4, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2)
  _: k  O- F: U# C7 j3 e. o* cEOF
( r8 I7 x+ ?- c
: @, t2 v; V  X$ B: L$ sudo ovs-ofctl dump-flows helloworld
6 A! `0 R7 p; z- C+ A3 tNXST_FLOW reply (xid=0x4):
: l4 }( R# E! ~  z1 kcookie=0x0, duration=4478.582s, table=0, n_packets=0, n_bytes=0, idle_age=4478, priority=0 actions=resubmit(,1) / o  _. t( u& Y: E: l& M
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
# D* \$ _; a# {$ `- Mcookie=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 I& {# B( R& r- j6 Icookie=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)
) A; `. k% E! Q5 kcookie=0x0, duration=89.273s, table=1, n_packets=0, n_bytes=0, idle_age=89, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
# H) I( c% I+ y7 ^- [+ v2 acookie=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) ( L% ~& i- O/ O# _- l7 s1 s
cookie=0x0, duration=220.318s, table=1, n_packets=0, n_bytes=0, idle_age=220, priority=99,in_port=1 actions=resubmit(,2)
* R7 c& y" q: {8 o# Rcookie=0x0, duration=298.739s, table=1, n_packets=0, n_bytes=0, idle_age=298, priority=0 actions=drop- e( A1 s' X5 r6 U  r: x1 S1 K
6 K  q# o$ `( r' l$ R: s6 v
测试一个从port 1进入,tag为5的
8 e3 b7 v9 ?9 p: a. A- H& z& Y- [) \/ m4 O8 x+ {. I
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=5 # G+ j$ A( ]) @( Q. h
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
, T& {7 y/ ?" j$ P9 ~Rule: table=0 cookie=0 priority=0
5 ^$ A, d# x# v( G8 HOpenFlow actions=resubmit(,1)8 X7 ?5 p. q, `- m4 T  P' a
: i+ [) ?, i6 K+ j. R( e7 c% L
        Resubmitted flow: unchanged : L- r; @$ n! h* s4 j& G
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ' d( l0 D/ v9 k" K/ B
        Resubmitted  odp: drop 2 J# S8 r7 k5 Y
        Rule: table=1 cookie=0 priority=99,in_port=1 ) l* j* M, h7 }  ]& C6 |5 g
        OpenFlow actions=resubmit(,2)
, }* ~  V9 X$ \/ B& O+ W9 O+ y, v! `9 V9 Q
                Resubmitted flow: unchanged , |  G: a% N5 ?0 C* j3 }% u
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 + P. x) d) T' G) D  ]+ S. x) i
                Resubmitted  odp: drop
( f6 r: G; k4 X                No match
2 R+ u2 v: V( g3 v, v- o* K4 O$ G: ?/ q3 U
Final flow: unchanged 9 b; ~: g) O% m, R$ m" Z
Relevant fields: skb_priority=0,in_port=1,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no 9 H4 L  i5 F* ^0 I
Datapath actions: drop
/ A" w! L* S8 `  G. q$ d) C* L/ s% p. f) u+ ]0 U, V4 Q
测试二,从port 2进入,没有打Tag的, G& L& n" g2 l! l# E% j8 e+ f
' ]5 k" T  c0 z! F* V
$ sudo ovs-appctl ofproto/trace helloworld in_port=2
( B0 w5 Q3 t5 Q* ?! n7 G& j/ B& `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 6 i4 U) @9 `3 w! ^* C1 q
Rule: table=0 cookie=0 priority=0 ( A0 m* \! [! o- Q6 S
OpenFlow actions=resubmit(,1)
. S' @+ r! @/ G0 n; j' X( [' H2 Q, W0 ~" `
        Resubmitted flow: unchanged - l! r( V8 P  S2 ^$ ]- B
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
7 [- X! b- a. m, T* k  N5 S: e        Resubmitted  odp: drop * v$ ?- q1 ^6 e
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 3 J! ?/ Q, H. t& g7 I% X
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
# L+ J: j) {# z( K' j
8 V9 P0 |  n# z3 W' Y* K8 B                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
1 T5 n/ d9 W) ^3 J6 g# G1 e$ D/ q                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 : _1 E5 v3 y9 K0 H% Q3 b8 ]  M, i
                Resubmitted  odp: drop , @+ K3 [; N3 h4 {
                No match
4 q2 G" N" M" h9 p
, s2 A% `+ h' AFinal flow: unchanged
7 Y2 s9 E% i: f( Z8 D7 x5 zRelevant 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 + C+ C- q: a3 j! |* D
Datapath actions: drop: _% y8 v: \- ]8 Q( ~7 `: b
" r( O& U$ q# i' n; i0 i- j& Y2 n
测试三:从port进入,带Tag 5的2 t. m* r" Q1 g  p8 `9 j% U/ L

! s1 d8 ?5 D- z  a' Q% x7 k$ sudo ovs-appctl ofproto/trace helloworld in_port=2,vlan_tci=5
9 z9 J3 y3 H* u- SFlow: 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 . g" k' w% Y' Q8 R# N
Rule: table=0 cookie=0 priority=0 , B5 {$ X3 P" C  z
OpenFlow actions=resubmit(,1)( X0 S2 n& m3 n; ~

# a4 V! @) N! Y        Resubmitted flow: unchanged 1 t, J5 ]; `, m4 E
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
8 Q0 M5 m4 i' [        Resubmitted  odp: drop 7 ]* G/ j9 _! j0 e2 O$ b
        Rule: table=1 cookie=0 priority=0 7 g% q# I* v; [  Z5 N: c
        OpenFlow actions=drop
! O* D! L( n  P/ y" j+ Q* s% P
6 G2 a! z7 U1 l: oFinal flow: unchanged ) g5 m3 t: d6 U0 f8 G: f1 o
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 z8 I; B, B3 T. e; P0 R: O" a
Datapath actions: drop8 ~( ?1 x  P3 {3 ]& ~+ }# v, `
& n0 Q, n' v8 r0 J/ ]3 {: S  |
实现第三个Table 2: MAC, VLAN learning for ingress port" {8 G; P9 C* Z  p4 }" I: x6 F
* I- P5 G* r$ Q' T% H5 n
对于普通的switch,都会有这个学习的过程,当一个包到来的时候,由于包里面有MAC,VLAN Tag,以及从哪个口进来的这个信息。于是switch学习后,维护了一个表格port –> MAC –> VLAN Tag。
# ^6 O0 x! V; d/ g% i, s/ R) Y
$ F) {# K$ S8 X3 H* M0 `3 k这样以后如果有需要发给这个MAC的包,不用ARP,switch自然之道应该发给哪个port,应该打什么VLAN Tag。
! a4 H% s  H& R) G6 t, h7 z
) D! z- y: c/ y" x' iOVS也要学习这个,并维护三个之间的mapping关系。
8 b6 `7 E" w* f, @- G# k9 @2 v# A- a. B" l, t& O3 n
在我们的例子中,无论是从port进来的本身就带Tag的,还是从port 2, 3, 4进来的后来被打上Tag的,都需要学习。
7 v  \; o6 g6 f1 m2 [* i( X* X/ h) D: N+ m+ }1 `
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)"& ]  Q+ z' i1 F. D7 Q( s
% ?. F. m0 E+ I# S) |+ K
这一句比较难理解。% Z7 B: W$ i  c0 J) C% J" r
2 e6 E1 l; a3 Q6 O1 j& j+ U
learn表示这是一个学习的action0 _! t5 y( D( C
* A# m: @8 @0 \* E
table 10,这是一个MAC learning table,学习的结果会放在这个table中。
  b3 B8 u$ P/ o: W, \: `& A; G& M5 l' e# ]8 M
NXM_OF_VLAN_TCI这个是VLAN Tag,在MAC Learning table中,每一个entry都是仅仅对某一个VLAN来说的,不同VLAN的learning table是分开的。在学习的结果的entry中,会标出这个entry是对于哪个VLAN的。+ r) f$ I6 Z1 I$ X6 u, K+ U7 [7 {' `

5 ?. }6 i5 k! uNXM_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里面,因为这是为发送用的。
0 p) E0 N; {- J3 s9 u+ }  F( a' Z1 e- L2 _# s4 j8 A
NXM_OF_IN_PORT[]->NXM_NX_REG0将portf放入register.
% `6 \" I" b$ U2 E* k; Q' ]2 [3 B8 `) Z. w/ ?  j+ g
一般对于学习的entry还需要有hard_timeout,这是的每个学习结果都会expire,需要重新学习。
' E6 K- l" P  p* D' f/ V2 a, |4 b+ b" Q( b, R- I1 y
我们再来分析一个实践中,openstack中使用openvswitch的情况,这是br-tun上的规则。
& f% @" ^1 l* b  i2 Q/ Y6 K- r. L; o
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
( ~: `: P7 q2 n. a# A# a4 `cookie=0x0, duration=802187.786s, table=20, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,21)
' W# e0 c: B) A 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
, q9 B7 R& i  X. B# jcookie=0x0, duration=802187.653s, table=21, n_packets=17, n_bytes=1426, idle_age=65534, hard_age=65534, priority=0 actions=drop
- e* ]7 F  U  y9 Scookie=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, {$ ^# v7 T: f3 T  [
, [; }0 |! i0 L- ~* a  N# j# x
这里table 10是用来学习的。table 20是learning table。如果table 20是空的,也即还没有学到什么,则会通过priority=0的规则resubmit到table 21.6 j! s7 y! k* v: q7 \

) P: R) X/ @. f; s# C2 k; u& t; Y; atable 21是发送规则,将br-int上的vlan tag消除,然后打上gre tunnel的id。
# U3 @, q, w8 q: J$ _/ w
5 N, P/ b, C3 q0 x6 A上面的情况中,table 20不是空的,也即发送给dl_dst=fa:16:3e:7e:ab:cc的包不用走默认规则,直接通过table 20就发送出去了。
- m8 t9 t( c2 N* w) n9 f& D" X1 K4 r" {8 e4 F8 y
table 20的规则是通过table 10学习得到的,table 10是一个接受规则。最终output 1,发送给了br-int
( S7 b4 i  ~9 T/ ~) z* Z6 ]5 R0 L" j9 T0 u7 a2 W7 j% p; y
NXM_OF_VLAN_TCI[0..11]是记录vlan tag,所以学习结果中有dl_vlan=1
/ R6 N7 V+ y: `  V
" [( t2 y9 m: Z# Y1 K+ qNXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]是将mac source address记录,所以结果中有dl_dst=fa:16:3e:7e:ab:cc2 v  y# {/ Z* a. @" B1 l, g% e

, [7 B/ r* a! T) _/ c1 `; T  lload:0->NXM_OF_VLAN_TCI[]意思是发送出去的时候,vlan tag设为0,所以结果中有actions=strip_vlan
$ q2 L' v. q' I, w: R9 n- G4 a% i8 r8 y& W" F/ X; D* H8 [
load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[]意思是发出去的时候,设置tunnul id,所以结果中有set_tunnel:0x3e9& r5 ]1 x6 \' f: _
4 P+ b. r8 q/ o; ~& _& a0 d
output:NXM_OF_IN_PORT[]意思是发送给哪个port,由于是从port2进来的,因而结果中有output:2: c& ?; I" t0 P6 a8 @% i# F) f

% E" S+ Y/ ?; R# @测试一:从port 1来一个vlan为20的mac为50:00:00:00:00:01的包
; c% G" \( x9 a( u7 K9 P6 J2 Y2 M5 E& @' G+ c
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=20,dl_src=50:00:00:00:00:01 -generate   ; U  t. z  f  W, B
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 ( h5 c) Q- a% [) |$ v
Rule: table=0 cookie=0 priority=0 6 l8 m( F/ T/ {. g6 J
OpenFlow actions=resubmit(,1)
  e7 g8 _* u6 b7 v9 e3 }
+ e) x: P* \/ t! `: p        Resubmitted flow: unchanged
& }5 n* P5 v/ Y' D( q        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
% z0 }5 s8 r( ]) h        Resubmitted  odp: drop ; Z$ n: v  t. N5 `1 n2 z. x
        Rule: table=1 cookie=0 priority=99,in_port=1
* G; W. Y6 x5 ?        OpenFlow actions=resubmit(,2)
$ M6 f1 ]* w1 E6 u$ m8 {
* F0 y! g, K/ e1 T8 ~  C$ k0 o                Resubmitted flow: unchanged
4 G8 T4 ~& _$ ]3 M- I+ l. G& N1 R                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ( |' |1 P0 z1 x% ]
                Resubmitted  odp: drop 8 \8 M: n9 U( q: S
                Rule: table=2 cookie=0
; ?, ?4 G* z2 {/ j' Y6 b& ~5 p# i2 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)9 u: w  {2 H3 S8 l+ R3 l4 B* ~+ @
$ q1 J+ p/ d% \. a8 f' q
                        Resubmitted flow: unchanged
. B3 a2 w1 d6 I5 ^                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ; \. o  D( z+ K
                        Resubmitted  odp: drop ; i/ M1 @' x* b% C; Y
                        No match
5 m) r5 Y7 r* w/ o& w7 A+ `- g; S8 Z6 }$ [; c; Z
Final flow: unchanged
1 J: _' a# e. k  o" Z# |/ J, XRelevant 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
) X2 a0 b7 p6 L/ ^Datapath actions: drop
' D( \& t/ c* a  A5 \" b% x0 [4 h! w/ H. j* T
$ sudo ovs-ofctl dump-flows helloworld
" P1 ^6 X3 \- M. |, oNXST_FLOW reply (xid=0x4): 5 N+ X' s# v* C; N( w) i: k# s9 h
cookie=0x0, duration=90537.25s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
6 G/ T' s% G, Q0 V) K+ s+ Wcookie=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
" d. r/ A) l" e, @1 B, |# |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 ; G# r7 ~( `7 f/ J3 _5 P, ]9 V
cookie=0x0, duration=86147.941s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2)
3 D- H4 M+ V; Icookie=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) ( ?: g2 r7 X, \9 E
cookie=0x0, duration=86147.941s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) / o  X6 r4 @: l8 x" J* R3 v$ f/ S
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) ) F/ z' ]4 e/ z2 f  E1 w
cookie=0x0, duration=86357.407s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
" f* ^* T, k% p# x. Q* xcookie=0x0, duration=83587.281s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3) ; V8 U2 E" Z6 Q+ y; t  a
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]; p1 z6 k* g; I- Q, B
3 h" g  K: ~4 K7 R9 ^7 U8 M( D: Q
table 10多了一条,vlan为20,dl_dst为50:00:00:00:00:01,发送的时候从port 1出去。
: S- A5 R  K/ H- j$ f) {6 }. {4 O1 A) C1 b+ u, J
测试二:从port 2进来,被打上了vlan 20,mac为50:00:00:00:00:02: m/ O) E, B1 s" a7 @

& r; I  F  o1 ]& b. B$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=50:00:00:00:00:02 -generate   
  k% C: y% m$ s6 Q$ M* MFlow: metadata=0,in_port=2,vlan_tci=0x0000,dl_src=50:00:00:00:00:02,dl_dst=00:00:00:00:00:00,dl_type=0x0000 : `5 i0 I& m6 N( o. g
Rule: table=0 cookie=0 priority=0 $ I) `( W1 |, Y1 j  X6 n1 c
OpenFlow actions=resubmit(,1)1 T% t) u' }8 _% D9 K4 U: ?% [& S

3 A- N# z) L* p& V        Resubmitted flow: unchanged 6 \: u# T0 }! G! V; S: h/ z5 y
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
+ U; l) R0 g" j: L: ?8 m        Resubmitted  odp: drop
3 g4 s4 Z0 b; ]7 n* f8 y        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 9 Y. d( `5 V) v0 ]
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2); G! y4 x1 t) l8 C# N, Z; o5 E2 n
7 H7 V3 \5 I% S7 _, |, q' c8 B
                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 5 _0 w8 V- ]6 g! \% N, E- q
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
. a. Y( B* v8 {' X                Resubmitted  odp: drop
8 i- M, C+ O; a% x& I                Rule: table=2 cookie=0 2 X! r) c5 B' T2 Y: [+ |" 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)
" Z: ^0 e9 r8 Z0 [& ]6 p. W7 @; d0 r
                        Resubmitted flow: unchanged . D8 q6 x4 |8 d: M5 R$ F# n
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 " n2 M( N) @6 A/ I/ ?, h
                        Resubmitted  odp: drop
( F% O1 ^4 T9 D0 E2 t! V8 J6 F0 U                        No match
2 @6 |0 P- |8 j2 v8 Y) K7 B9 x" X$ X9 F/ z; d/ Y2 H8 q
Final flow: unchanged
' ^/ T; F% e* t) A4 SRelevant 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; m, c/ d* |- L
Datapath actions: drop
$ q! x/ Y+ I  L7 k3 \: {
$ m; f$ y, ^* k! |$ sudo ovs-ofctl dump-flows helloworld                                                
5 B! o! C: A2 m. x" BNXST_FLOW reply (xid=0x4): ! C. D( y  I, K
cookie=0x0, duration=90823.14s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
+ s9 e+ Y7 g0 D, Z( U5 `, lcookie=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
/ b* E" z- _1 v2 F& M5 [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 5 w2 F5 H- P2 y) ^( N. ^  }$ J' d6 F: Y
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)
& `7 I0 i( y. x: t1 E: a% Dcookie=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)
4 f  ?/ o2 w2 v" Ncookie=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) 8 l) V! j0 Z, C) a" h
cookie=0x0, duration=86564.876s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2)
; q: s: O1 o' p  hcookie=0x0, duration=86643.297s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop 1 }: o" y( o( N: t
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)
( p+ t2 H  R3 m, s3 K8 t 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] 9 _. w: m3 a) J" v, B) Q
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]
& Y5 B. C2 [9 W  ]0 K2 X4 A' C( ~4 q- z
实现第四个table 3: Look Up Destination Port
$ T8 U' ?( P" v6 R6 ]
3 ]# E' T/ B% G: J: h在table 2中,vswtich通过进入的包,学习了vlanid –> mac –> port的映射后,对于要发送的包,可以根据学习到的table 10里面的内容,根据destination mac和vlan,来找到相应的port发送出去,而不用每次都flood3 l; w9 j  n* E$ f# Y: _# h3 A
7 }+ ^, p1 F8 i. M' [+ u
sudo ovs-ofctl add-flow helloworld "table=3 priority=50 actions=resubmit(,10), resubmit(,4)"
- [4 B  r% F& [% }  k+ @: M: z! \' W2 X
添加这条规则,首先到table 10中查找learn table entry,如果找不到则到table 47 ~* P) I3 m  r2 S

: S/ A4 `1 B! ]# i5 |如果包本身就是multicast的或者broadcast的,则不用去table 10里面取查找。. z6 P$ `) H+ [7 @% u! k, |

+ O0 T" m" Z/ H; R: r7 d- tsudo 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)"3 |1 k; [, m4 E; p- B4 |( W. h

2 x& M% Y8 v, Y) d1 p: T' Y我们进行一项测试- w) o0 d" u, E4 {& _

- s. U) k2 I" Y1 J5 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   ; F! _% W' Q5 t" @
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 , |% M# z" G" P7 i% y5 j* R5 h
Rule: table=0 cookie=0 priority=0 $ D; G8 v& ?8 H5 a& n
OpenFlow actions=resubmit(,1): n# g: P/ w& @" i9 p  Z. L
5 A$ C. T) n/ P1 m% S: A
        Resubmitted flow: unchanged
. M1 D3 w% {; |7 f        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 6 {" S" g; n( l. d: N
        Resubmitted  odp: drop . y! R7 t8 i& ]* a' f$ F) p: b% B5 ^
        Rule: table=1 cookie=0 priority=99,in_port=1 1 I/ `$ T0 ?2 `$ J0 Z
        OpenFlow actions=resubmit(,2)
% ^1 z( \8 m; k, f# N+ V) D: J/ O2 i9 w
                Resubmitted flow: unchanged $ N5 y$ s8 c% g8 ?% {6 ]
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
$ T  i4 ~- f% ]; i' w                Resubmitted  odp: drop
- y' A8 u8 ]! x3 s; s) v                Rule: table=2 cookie=0
) ]' A& ?5 q; r3 ~# C! y& m; C                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)  N& v* s, [" [9 @
# R0 y# \% d  w; U" Y
                        Resubmitted flow: unchanged
" W0 K% f, h2 F; F% x                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
& u9 Q+ k4 Z0 _                        Resubmitted  odp: drop
: B; k. ?; L+ v$ O& {                        Rule: table=3 cookie=0 priority=50
4 N3 Z3 |' Q( b$ J8 {                        OpenFlow actions=resubmit(,10),resubmit(,4)
; F4 V+ q+ L- f' }, `8 d9 C( \! L. D4 ^% k1 ]
                                Resubmitted flow: unchanged
' N9 X% D9 g9 X# m0 J( }5 r, @8 x/ O                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 8 K) F' {% w4 d' D1 H, j
                                Resubmitted  odp: drop
+ I! q1 {3 p$ o" q4 }5 [8 U                                No match+ X( c& J; o" G8 f  D
, t# J0 K! }( q5 U5 Z8 A- }
                                Resubmitted flow: unchanged 9 N! E" h  {7 _/ Q
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 , h) y6 u% r+ h1 M/ Q) Q6 z2 d
                                Resubmitted  odp: drop 1 p) P# C1 j0 b# t" I" Q; Y
                                No match/ q! W- Y3 L! R% N
$ G0 n9 f/ k) n7 @8 g0 I! Z; `1 J" Z
Final flow: unchanged
$ j# J+ H% Q5 _+ }" ARelevant 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) G7 n  I  k$ N
Datapath actions: drop3 [  h/ k+ r7 m5 M+ P: m" ^. h
* J& U5 \+ r" F" _$ i
由于目标地址f0:00:00:00:00:01没有在table 10中找到,因而到达table 4.
9 o! V8 ^8 |: o  ]
- q1 w- V7 O2 }7 i/ h4 y9 f但是这次测试使得table 10中学习到了mac地址90:00:00:00:00:01/ a* ~. O) Q1 l( m( k- f0 t8 Q

8 @7 _1 H+ |& m4 R6 g$ sudo ovs-ofctl dump-flows helloworld 8 w1 q1 d/ D) Z! `' r  t$ s8 }2 R
NXST_FLOW reply (xid=0x4): / ]7 M$ O  S9 H* R3 W6 s
cookie=0x0, duration=91588.452s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) ! n3 F7 V+ H5 a8 J0 X1 h$ c
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
$ G; m/ D9 `1 A6 Z# w% ?; \* M3 ycookie=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 % j8 _% Z" c0 J+ X. r1 ]  K
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) - g2 x* h/ O6 f9 Q! B, F
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)
  n+ {* ?- S1 K: e' {) ^% q& ~7 `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) ! `0 l$ V2 `: S3 G/ ?, {
cookie=0x0, duration=87330.188s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2)
4 w; ?: b9 y: T, l1 Jcookie=0x0, duration=87408.609s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
5 s2 P+ C! C9 r! i' E% S- j8 j, c5 ^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)
: v& X6 M: H& b! ]" Jcookie=0x0, duration=352.841s, table=3, n_packets=0, n_bytes=0, idle_age=352, priority=50 actions=resubmit(,10),resubmit(,4)
# H0 y7 k8 G  m8 D0 pcookie=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) 5 e2 R% \, |: b8 R& O. j9 X: T6 i
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] # G/ L8 q- P9 i$ \0 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] 2 E2 Z# j" ~4 `
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]
' R: \: z" n9 V  M: l0 d1 ]8 \9 m' _- t3 [' d8 }0 H7 g
下面我们进行另一个测试
* N: O$ `/ T+ B$ D, F- l% y* N! G8 Q# q$ [2 E/ \% y  I  V3 R/ h0 O+ t
$ 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   # P4 Z, b! M) Z% C! s
Flow: 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 " Y6 D0 i. ^' H  g$ U( D* N
Rule: table=0 cookie=0 priority=0
# |1 J# f# y/ f9 t( x. P9 v  X7 U; zOpenFlow actions=resubmit(,1)
* {: Y/ _* d1 }. X2 G4 R4 s+ Q8 {7 D$ x, |; f, W0 L* {  K+ N2 C
        Resubmitted flow: unchanged
3 r& P9 q! n8 k% B8 ~        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 4 B2 E2 o7 e8 j3 x( e
        Resubmitted  odp: drop / e2 }1 O' h* \$ B
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 , l, I; o* k8 y$ }3 U3 g4 b2 p
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)" C5 C- M- ^  K

* z* P& L7 _2 Y4 U  ^- r: r4 n1 g9 T                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
& f8 D: j6 n. g" T3 t( }* P/ D                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
- L* f: H" E. S. o* H; g                Resubmitted  odp: drop
- l5 v4 |9 O: g. i$ o7 C0 T3 ^0 ~                Rule: table=2 cookie=0 4 {" j, C0 F+ @  |  S
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
2 O( _# G' |0 x
5 s% _5 n. }  B, t. L' M* i6 F/ O! G0 P                        Resubmitted flow: unchanged ( q6 C5 S+ g' K
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
. S8 {; K% P9 p& V                        Resubmitted  odp: drop 3 ~4 }( I% H3 x% ]% Q5 b
                        Rule: table=3 cookie=0 priority=50
% t4 a# |$ _5 I5 I5 U                        OpenFlow actions=resubmit(,10),resubmit(,4)3 a0 i" B7 a6 J

% J% O  @+ }7 E- t% l                                Resubmitted flow: unchanged
" K- M- R# n, H/ |) a( G& w: g                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
& v  k7 z7 R# m2 r" h                                Resubmitted  odp: drop 9 [  M2 P9 J7 L( V3 G; P* E
                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01 2 W! P* o) m6 g4 p
                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]
3 \: A! k4 u) ^" H6 O1 v- J5 W) l6 ^. T3 b3 b! [6 X! f
                                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
/ H6 I2 g5 R: t% n1 ]                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
+ z4 t, L. |! `8 ~) C5 t% @# _4 G                                Resubmitted  odp: drop 8 o7 @! W) c9 H9 v# `+ U- r9 |# z6 `
                                No match% H9 R5 D: Q8 z& ?

* B6 i( W* m3 |8 FFinal flow: unchanged
/ _  `9 q! L2 G9 z9 NRelevant 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
" r0 Z+ }" k( s; w5 h; Y% rDatapath actions: drop
3 u. J( q3 m, w# i* L# I" }% W+ c; s$ Z: A
因为刚才学习到了mac地址f0:00:00:00:00:01,所以这次在table 10中找到了这条记录,这次同时也学习到了mac地址90:00:00:00:00:01
+ P$ f7 q6 J# {& y. S+ i) I. U& l
  _7 X2 c4 ?) h: c% N下面我们再发送第一次的包
5 J+ G/ q8 K. I3 j( \/ Q; i- L, x! r" T
$ 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
7 Q- e/ f: L+ h7 [  MFlow: 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
' K! k+ @( v6 D  |0 ]; y: {" RRule: table=0 cookie=0 priority=0
$ M7 X0 D/ t5 j* p- gOpenFlow actions=resubmit(,1), J* ~* I7 {+ K) y
. W8 W. X8 u0 S& |8 y8 q" `+ P. z
        Resubmitted flow: unchanged
% s3 L, j/ U9 s* a% o8 n5 ~4 b        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
# @( I7 R/ E/ p* \- t1 {7 K& f        Resubmitted  odp: drop : W/ \6 `7 g( C4 y9 K# ?$ d9 V
        Rule: table=1 cookie=0 priority=99,in_port=1
3 o# F3 {  Q  [7 e% K! ?/ p7 C* F        OpenFlow actions=resubmit(,2)
. I/ a& h* {3 ^' ?1 C; i3 h  Z" N5 H  U! C4 Y6 [7 n
                Resubmitted flow: unchanged
6 i4 @3 }9 }; N( X: }4 {                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
3 c3 R9 P7 x2 r. L                Resubmitted  odp: drop # d4 |/ t9 v. x& p% @
                Rule: table=2 cookie=0
1 h' E5 x1 {. [: ~* _: d                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
$ o- u7 G/ K  L$ P& i, `2 t. ^; t6 N" G0 y2 Q( I. a# h
                        Resubmitted flow: unchanged
) i" ?; K, q' D/ y                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
6 G& V8 R9 P3 ]9 \                        Resubmitted  odp: drop 2 W& E; s0 n& `" i* R; Y
                        Rule: table=3 cookie=0 priority=50
" v6 g" }5 h2 _0 B1 C( B                        OpenFlow actions=resubmit(,10),resubmit(,4)
+ i, M; n8 y; E! x' C- V; m: Z; i7 N  u% F$ T0 L$ ~5 [
                                Resubmitted flow: unchanged
/ y9 A. T- z( P                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
8 `  r* k* }  B0 }, `                                Resubmitted  odp: drop
' o- d& I, E, I* V                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01 7 b) t  e: Q% b! H
                                OpenFlow actions=load:0x2->NXM_NX_REG0[0..15]2 }9 T; e+ Z- E

7 _/ x3 P$ L) D# X' q% u                                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 8 X6 S3 R: h  N- [" @: v4 `
                                Resubmitted regs: reg0=0x2 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
! u! o1 \# L' I: @9 Z* C) e5 l! T                                Resubmitted  odp: drop 6 u5 z+ Z" o# `5 ^  e
                                No match: ]6 ~  Z) T8 j' h" K/ U: F5 w

+ b- m2 g" J; \8 x+ R: p$ Z; RFinal flow: unchanged
* t; N' Y: w- e) H% aRelevant 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
, Q% R3 M, D% w, nDatapath actions: drop
0 I7 ~: R$ _" z* h9 I$ b, m& t7 r  v0 \
发现也在table 10中找到了记录
6 Z. m' m# S+ R+ Z/ R& L" M( {  I* M/ H0 i3 Q* a
实现第五个table 4: Output Processing
/ q4 U6 z6 w4 T  R) y
. ?4 @/ W- H1 f这个时候,register 0中包含了output port,如果是0则说明是flood。  s0 l4 Q# A' K" l

" M/ Q; L0 ^" A# c% }; x& k6 l对于port 1来讲,是trunk port,所以携带的vlan tag就让他带着,从port 1出去。
& d. r1 I; x7 y6 O0 k+ [" A. D2 ^3 X6 B
sudo ovs-ofctl add-flow helloworld "table=4 reg0=1 actions=1"' P: D8 y, Y+ W5 f3 Z
5 x# V0 \# C- p
对于port 2来讲,是vlan 20的,然而出去的时候,vlan tag会被抹掉,从port 2发出去2 d, r5 x* U' R' S- [' ]

8 U( n, d! [$ O对于port 3, 4来讲,是vlan 30的,然而出去的时候,vlan tag会被抹掉,从port 3, 4出去
  j. B/ ~$ u% U6 S9 w- Z  }% Z. k0 ?: _1 q. S0 v8 g
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   , H, Y$ @3 G1 ?. N
        table=4 reg0=2 actions=strip_vlan,2 8 O6 J* b" a  }: g- @$ K# R0 f( c
        table=4 reg0=3 actions=strip_vlan,3 ! |' P$ o: C9 ]5 n( B
        table=4 reg0=4 actions=strip_vlan,4
% h3 r  ^: e* WEOF7 e# M0 a9 B1 Y  ?" Z

; D. p( b: \6 L对于broadcast来讲,我们希望一个vlan的broadcast仅仅在这个vlan里面发送,不影响其他的vlan。4 G7 [0 E! g# }" M' l1 t
9 L- ~7 \( k9 e% {; q
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   , }' `+ t$ ~6 F. v0 S
        table=4 reg0=0 priority=99 dl_vlan=20 actions=1,strip_vlan,2   U8 p1 `& h  R9 t$ H
        table=4 reg0=0 priority=99 dl_vlan=30 actions=1,strip_vlan,3,4
# J8 t  [8 s! b5 r" ^2 a        table=4 reg0=0 priority=50            actions=1 , q6 d# t7 ^$ p7 _7 w: r6 {4 _* P
EOF
8 ?+ I" U  q$ g. J$ R
) d5 c7 E1 v- v" J( q4 b  J所以对于register = 0的,也即是broadcast的,属于vlan 20的,则从port 1, 2出去,属于vlan 30的,则从port 1, 3, 4出去。
- T7 c( R0 Z6 D) q7 @  z( S; d* Z, C% [. R+ v  g# _! z  S
$ sudo ovs-ofctl dump-flows helloworld
( u9 c9 ^" b" {# ENXST_FLOW reply (xid=0x4): 0 Y$ j" I: U. y5 |4 R8 `; k" P
cookie=0x0, duration=92909.119s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) ; o" Q7 B# \+ M. V; y3 ^! r
cookie=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 . w5 a, @& ]- U5 L/ C8 i
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 ) K" x9 \3 ?3 k
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)
" g  Z) q) T$ \+ ocookie=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) 7 C+ e8 _( O, s+ c- K
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)
; r2 f# d! j8 g  r+ J3 j5 t3 X* Ocookie=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) 9 I2 o  a1 |8 Y- P( a+ V5 F! V
cookie=0x0, duration=88729.276s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
! c" k, _/ I2 y1 tcookie=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)
6 o% t0 F  T2 r* p, Dcookie=0x0, duration=1673.508s, table=3, n_packets=0, n_bytes=0, idle_age=1673, priority=50 actions=resubmit(,10),resubmit(,4) 5 m9 a( A& B0 R! k* V7 F0 |6 T
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)
2 n8 T& y" j2 X$ C$ r1 `cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x3 actions=strip_vlan,output:3 & f* h8 J5 p% o' Y( Z% D
cookie=0x0, duration=228.839s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=50,reg0=0x0 actions=output:1 + Y  J- [: N. V$ p4 v# a" }  _" F/ T* Q
cookie=0x0, duration=483.068s, table=4, n_packets=0, n_bytes=0, idle_age=483, reg0=0x1 actions=output:1
  F' l% X# J3 g0 kcookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x4 actions=strip_vlan,output:4
. i- O+ j" J( @) f' J2 P$ \cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x2 actions=strip_vlan,output:2 1 A* m, X! ?8 `  c& B) r
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 M! _9 a" g/ i# b
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
* U% E; X( R! zcookie=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]
$ L: o( {1 q) E3 \7 |% [, m: Jcookie=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]
( _9 i2 |9 U, v# n, x# Rcookie=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]
" p3 U. P0 U5 ?  h5 Ucookie=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]  V; A$ a  E8 G. g

# _' N: M' i, D; b- y首先来测试一个multicast和broadcast6 T' _, l  J! W8 W
) d. f* _3 @6 [0 G* o2 J; O9 c& y
如果是一个port 1来的vlan 30的broadcast
8 B, m# i" R* l9 v9 Q, e" G
8 s& G0 o5 ?% t! T' y$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=ff:ff:ff:ff:ff:ff,dl_vlan=30
$ v9 Y) M' d& m: y6 LFlow: 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 ( k1 N  J( b. @4 n/ c# e
Rule: table=0 cookie=0 priority=0
3 z7 H$ t* W+ Y7 i5 @OpenFlow actions=resubmit(,1)
% @$ k& a/ `5 \3 U% g
; t9 p" _1 G7 Y; E6 c/ P" d. h        Resubmitted flow: unchanged
4 j- j$ [3 Y% [  b) b8 U        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
) n) R9 G5 X, j- T2 C- j: h1 n        Resubmitted  odp: drop
- p4 {$ n% t2 N% f; r7 G        Rule: table=1 cookie=0 priority=99,in_port=1
1 Q5 t# q  S/ m& m* a8 R" x! `        OpenFlow actions=resubmit(,2)
0 a2 p6 Z& E* {5 j( V( \8 @3 C/ _5 w% i. X5 t  q6 J
                Resubmitted flow: unchanged 8 Y" v3 z0 s1 T, z7 B) |: s( P7 o
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ( k, }6 U& M6 \9 B
                Resubmitted  odp: drop / {( U& t& d  @. J3 n/ h7 f
                Rule: table=2 cookie=0 # w+ ]  A1 |' {; T. D) N; Q  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)0 K  w2 M. ]3 t5 {, F' t
# o) e; E  s; P, q) F  e
                        Resubmitted flow: unchanged : p$ H& n7 y4 N5 k
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
0 ?9 c: c9 _" ?  Z6 X# W' {                        Resubmitted  odp: drop * Q3 M$ v! A7 f& p, G3 j
                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00
  V) C! m  J9 ^                        OpenFlow actions=resubmit(,4)  E- ^6 A+ G- `* G
$ y  m( j6 B* h
                                Resubmitted flow: unchanged
* g  q* U: Y* P+ k/ Q/ Q: f                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 + O0 q  Q# q) P
                                Resubmitted  odp: drop
1 G( j- V! H: |4 L* W                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 2 l& R/ g2 {( N6 A
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
2 M2 O1 u  d+ y  |8 L, }                                skipping output to input port/ k: Z  r8 m) s6 W. a" S+ i

% J& L9 t/ J: G& RFinal 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
; o3 n6 S- Y2 q% X  {! g3 w' q3 [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
5 N- }4 P3 u+ ]Datapath actions: pop_vlan,12,136 E2 S: |2 P1 Y$ r+ P% ~

+ H- r5 H6 s- M$ y结果是port 1就不发送了,发送给了port 3, 4
/ T" Y) U/ w0 J: I9 f$ ?! w( s  D4 z: {4 Z0 p5 M5 d
$ sudo ovs-appctl ofproto/trace helloworld in_port=3,dl_dst=ff:ff:ff:ff:ff:ff * D* w9 n# Y& P+ [
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
& }+ k* G) `) c% A" n! s  |Rule: table=0 cookie=0 priority=0
' f/ d# ?# ]/ Z  u: uOpenFlow actions=resubmit(,1)
5 S- u% k+ v8 n. y6 ~6 O& S0 J2 M6 [6 S
        Resubmitted flow: unchanged ) S( H6 v, f8 n* P# v! |# E
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! K5 N, Z* q' `
        Resubmitted  odp: drop % m- l7 K) e6 b7 f
        Rule: table=1 cookie=0 priority=99,in_port=3,vlan_tci=0x0000
& }) |) @+ P+ E) N        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)
8 j5 c& n! `* }2 q' i6 N+ S
; c9 B( u& f6 ~2 r2 Y0 R: m                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 * j) V+ Q: \2 q0 [1 l
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & q  ^7 x9 y. E5 G4 ]' c( D
                Resubmitted  odp: drop
& s$ L- V) t; i3 o/ r0 k                Rule: table=2 cookie=0 : @) F9 _0 y7 E- N. @7 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)
- Q3 g1 [% W* c, _+ |5 i4 g4 O. w2 q
                        Resubmitted flow: unchanged 9 L7 x' q# o7 E! s. g
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 6 d  Y2 T& I) `2 V( D2 G
                        Resubmitted  odp: drop 3 l5 s6 J5 b& }! S+ A3 f9 X
                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 ( ]1 Q7 Y5 Y( C, O- u# g
                        OpenFlow actions=resubmit(,4)
; l2 \: }& H1 Z  a
% E& o: o5 T! M  L+ |, P4 y2 @- \                                Resubmitted flow: unchanged & N  f# ^( O! ?, x" g4 L) t
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & b" H+ a5 C) ^2 v8 G
                                Resubmitted  odp: drop
" E8 h& J: s+ Q* h; f4 L                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 / b1 _# q# J1 f
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
* p1 e! \# w: x3 G4 _                                skipping output to input port
  R4 W: M1 Y, _6 D0 d3 z7 ?. {4 c$ W- d" P
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 1 T6 y$ z# \6 j+ r) J+ B
Relevant fields: skb_priority=0,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:f0/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no ) v- k' _4 X+ d6 B
Datapath actions: push_vlan(vid=30,pcp=0),10,pop_vlan,13
$ f/ i# s% d7 L, |, h1 Q9 s/ H7 E  z- t, s
接着我们测试mac learning& H, p, y8 U4 `, P( P; i6 M2 V+ ^

) c0 o$ a: P; r/ ^& |5 M$ 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   ! J" a( X+ ?0 a. ]; A
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
5 |+ P7 V. r6 d; vRule: table=0 cookie=0 priority=0 - }8 x: e; [7 H& u
OpenFlow actions=resubmit(,1)
  y0 M' g- Q+ R. `+ k" I: p. M
        Resubmitted flow: unchanged
/ J8 J( _( i% p% I        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 s% h$ H% J+ M9 h  k
        Resubmitted  odp: drop & e+ W" A1 [4 f+ S
        Rule: table=1 cookie=0 priority=99,in_port=1
. i0 D! Z5 C# x  t9 ~        OpenFlow actions=resubmit(,2): X( x7 P1 k; o* Y' l6 ^6 L
, L% P0 y# p1 Q: t
                Resubmitted flow: unchanged ; d1 O5 d0 b2 ~4 E1 H4 a" X
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 : w6 _! W  X" F7 O& c) s
                Resubmitted  odp: drop ( x4 Q% K8 ], }8 J
                Rule: table=2 cookie=0 * c6 ]( Y, Q9 ]5 }# s) Z
                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)# O8 p7 Y" E6 r$ d5 v0 z# I

3 K  ]' m( h7 p' y9 L$ w1 U% G                        Resubmitted flow: unchanged / ^  I+ H9 e, w2 n1 g+ O, s
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
  O" G' g, q4 h8 E# O                        Resubmitted  odp: drop 5 }2 C( U1 N0 L0 F
                        Rule: table=3 cookie=0 priority=50 " y6 O9 L5 j( I( |) S: q
                        OpenFlow actions=resubmit(,10),resubmit(,4)+ r! M7 y: i; w

% k* W- G3 R- D& Y                                Resubmitted flow: unchanged
9 A, n$ Q8 d4 V. u                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
! A3 F: r, O4 B+ C& G( E0 H1 ]                                Resubmitted  odp: drop 7 _# Y# N( Q+ w* T) o
                                No match$ o$ n$ A; N4 F- s
- D# h  G) |0 o
                                Resubmitted flow: unchanged
3 |8 M+ J' N- T; m3 U$ M+ s                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 % y. A' O/ M& N6 f6 S0 [
                                Resubmitted  odp: drop 6 N3 T" E8 q/ N/ L- [
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 5 n0 ]/ W# x  J% r
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4 9 t' }, J: Q+ H3 H
                                skipping output to input port
- v% b, s" w  J
) U$ v. i8 X8 L' \$ F. IFinal 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
4 U$ J- E1 B3 Y" W  F, pRelevant 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
7 d) N/ a' t" X; g5 l" Y9 y% sDatapath actions: pop_vlan,12,135 c1 [3 ?" k# n# g% j* `7 _7 Z6 |
" a- |. ?, H( Q5 K9 Q- Z1 m
由于这两个地址没有出现过,则除了进行学习以外,广播发送给port 3,4" d5 ]0 X% `2 S2 H1 o. B( C" {

* v4 u3 v+ D0 i1 k- C  o5 `$ 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   5 E2 k% R- [4 K7 a
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 : y* @, S  ^4 U' B
Rule: table=0 cookie=0 priority=0
: H5 U$ ^. I# N7 T8 @  X% sOpenFlow actions=resubmit(,1)
' P! G* w1 ]4 _- n! g3 c0 g" a, n8 O
        Resubmitted flow: unchanged * y& Z+ F3 p! j+ P3 u
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0   Q+ B3 G# c2 N2 h# [, X
        Resubmitted  odp: drop
& q5 v6 m& ^3 U: c9 k        Rule: table=1 cookie=0 priority=99,in_port=4,vlan_tci=0x0000
9 H% J( z0 k7 @8 k7 B6 d/ e6 q8 d        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)
; L* v3 a2 y; B( W4 n9 _( D3 ~8 r; d5 R' r& V
                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
' L6 w0 B1 d& ?% a$ I                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 1 J0 r% P- A% |* O" G- h
                Resubmitted  odp: drop : W# h$ P$ B% h& j3 J$ L' W" M2 {
                Rule: table=2 cookie=0
! |2 J+ |1 }  s( }4 d% i                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, `3 `$ V" V- P& ?
3 [0 h" T: J; X6 ~! [7 t, r1 D+ N                        Resubmitted flow: unchanged 5 J8 _( B7 W* |) p  L
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
2 q  [+ [, }( r( `( z6 n8 n                        Resubmitted  odp: drop
6 K* Z# n8 I/ B' u1 s; ~                        Rule: table=3 cookie=0 priority=50
( X0 L2 d3 D. ^+ B/ u                        OpenFlow actions=resubmit(,10),resubmit(,4)( O$ {' A) x, x6 \0 k" Y0 S

5 E, y7 x" W  y3 Q! E+ o                                Resubmitted flow: unchanged 5 G2 }8 H; ?' o, |+ U
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
7 H9 l$ l4 Y& w: L: T1 j3 y                                Resubmitted  odp: drop * e/ s) T+ z. |$ {# t
                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=10:00:00:00:00:01
$ S( @# T$ M5 @& q) \2 ~                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]9 T+ I  z9 q8 u: z# X- ^

% x* s) @6 \8 i6 o3 W+ H' G                                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
4 h9 a8 I! f- t3 O                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 8 k( e- C$ v- F- z" z2 v  l
                                Resubmitted  odp: drop ) v6 P$ J' T) i$ `$ ^, _- g
                                Rule: table=4 cookie=0 reg0=0x1 1 y8 O* @: x0 `
                                OpenFlow actions=output:1$ w$ q9 x  S0 d0 N5 C9 D& `% P

$ s; R4 V: i! r6 G$ k) l3 ?Final flow: unchanged
& l3 X# P, j) oRelevant 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 ( k6 s" {) X) E
Datapath actions: push_vlan(vid=30,pcp=0),10/ I' K$ O/ L; x$ h6 B" N. Z7 x
9 o- q; ^- \+ }( ?" T
回复的时候,由于学习过了,则仅仅从port 1发送出去。% p0 \7 j, O5 J3 f" a
- Z4 \* w3 Q* l: y% C% S
$ 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 " P2 _" ~0 {: e1 L, 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 9 Z9 v, |* j2 h. m" c0 D
Rule: table=0 cookie=0 priority=0 / Z, x  ?0 F* v/ R* U& L2 ~2 V" _
OpenFlow actions=resubmit(,1); k7 Z$ J6 Z$ c- R9 l) Z* U9 m

1 c8 `, B+ ?0 h$ R- U2 A5 e% }0 I9 P        Resubmitted flow: unchanged - o0 |" [9 v) x3 J
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 % Y7 m1 m7 I' G! u2 @6 \6 Y* Y
        Resubmitted  odp: drop
, Y; E, q1 J" ?6 e6 x9 L; x) F  P        Rule: table=1 cookie=0 priority=99,in_port=1 1 @8 Y' l) m$ ]+ d- G
        OpenFlow actions=resubmit(,2)- ~" `; T( R$ l; U
; Y0 x% c& U) o6 ?; W; u4 ^
                Resubmitted flow: unchanged 1 m1 V1 R1 W3 L( {! i( Z
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 / J- E4 k6 s( j$ C2 q
                Resubmitted  odp: drop
, I+ U/ |$ B2 J+ [                Rule: table=2 cookie=0 % }3 a- f; o% f! s: z7 J
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
4 |6 h" D8 u9 c1 R; ^& |
$ `( z5 H( W$ S: m- p. _2 k5 e                        Resubmitted flow: unchanged
1 _" |0 _& s# s  K8 {8 E( I+ N- ~                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 , v4 M( l" F) P8 j0 B  T
                        Resubmitted  odp: drop
9 i9 T9 R* f$ u+ p                        Rule: table=3 cookie=0 priority=50   j- @, _! J  I) \+ b% I0 G: A
                        OpenFlow actions=resubmit(,10),resubmit(,4)( A' v  Q7 n; m+ A* l6 M

1 Y% b% I7 J$ D+ t9 `( E/ j                                Resubmitted flow: unchanged , F8 T: F" N' V- w! M# x. H1 S: M
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 : \9 J* z% B2 Z! d
                                Resubmitted  odp: drop
% E8 M* A2 e* C5 U3 [4 `" N' e                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=20:00:00:00:00:01 $ o& y! v$ z: [  a& e1 n
                                OpenFlow actions=load:0x4->NXM_NX_REG0[0..15]0 d0 z# Y" o/ S& ~7 K6 l
$ E5 b1 B3 ~$ @+ \
                                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 . c; g( ]; f3 q4 Z1 }+ Y
                                Resubmitted regs: reg0=0x4 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
7 H. Q' |- h! l9 A6 N                                Resubmitted  odp: drop
' q0 b4 F: A8 k% n  _                                Rule: table=4 cookie=0 reg0=0x4
4 \# V0 l3 |& ~) J7 G. ]                                OpenFlow actions=strip_vlan,output:4
6 _5 c/ s( x3 c) ^% k6 ~8 B/ T) C) y
+ c/ h+ R" ?3 @- |! t: `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
8 s2 v/ r  g/ x0 }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
# P9 O( K) N" C9 b: u$ J" hDatapath actions: pop_vlan,13, ^) e9 K+ ~( o6 Z' h; \
% L# Q  p0 m7 F
由于在回复中进行了学习,因而发送的时候,仅仅发送port 4
 楼主| 发表于 2019-10-25 10:00:36 | 显示全部楼层
实现第一个Table 0,Admission control  T* L% O6 |* O% D& n4 `
7 Z9 o: ~: {% ~# }
包进入vswitch的时候首先进入Table 0,我们在这里可以设定规则,控制那些包可以进入,那些包不可以进入。
8 b. R" _1 u% }( G  c
: K) i$ `; Z5 h$ \. w; _7 F比如,如果source address是multicast的就不允许进入。
" Z& Y; T' z/ L4 s4 m+ U% P: y) b+ D- d' L9 c) m) k$ {+ Q
01:00:00:00:00:00/01:00:00:00:00:00是广播地址
- V, |4 z# I( @# u% W& x) a4 S3 h00:00:00:00:00:00/01:00:00:00:00:00是单播地址
; ~/ W8 v% Y  n) g' A3 e" J这种表示形式类似CIDR
& N6 k  Y+ ]# p0 ^% G于是我们添加下面的规则:
: {8 C) e0 C8 Z' ~  _  r, r: dsudo ovs-ofctl add-flow helloworld "table=0, dl_src=01:00:00:00:00:00/01:00:00:00:00:00, actions=drop"- T9 t7 C, _* B6 h6 m% [# j) Z# Z
STP的也不接受
% y, f6 g; @, M4 n1 `sudo ovs-ofctl add-flow helloworld "table=0, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0, actions=drop"! a7 y1 R, y7 u! i0 ], i! J
我们在添加最后一个flow,这个flow的priority低于default,如果上面两个不匹配,则我们进入table 1" }" S0 K" B1 G# `
sudo ovs-ofctl add-flow helloworld "table=0, priority=0, actions=resubmit(,1)"  I' O/ U5 y* x. a
我们查看一下所有的flow' F+ v$ f6 B# R3 k5 s! o( q7 v
$ sudo ovs-ofctl dump-flows helloworld        5 t" o3 J# X* k  k
NXST_FLOW reply (xid=0x4):
2 n7 Z3 p7 a2 F) W$ R+ \cookie=0x0, duration=42.162s, table=0, n_packets=0, n_bytes=0, idle_age=42, priority=0 actions=resubmit(,1)
  X7 q2 z5 D! scookie=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
, W  S: X' P0 t7 W& vcookie=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; b$ K) M" Y  b7 d% z  u, r( @3 c
  ?! f+ p. [+ d
测试Table 0& g: c  d8 {) u/ J/ i

* j  @4 F% ?9 U+ @有个很好的工具ovs-appctl ofproto/trace
1 r  ^7 e" J& ?$ ?: L
% k0 ~5 e# U3 s+ r% h. v4 p) k& r不满足条件DROP5 |( B  t! X+ A1 _. e
9 J  R! {+ w, ~
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:05
7 n8 E; @4 L; |/ @0 X, G8 u' [+ 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:05,dl_type=0x0000 9 j! H1 b" K; F$ i! C( C
Rule: table=0 cookie=0 dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0
" Q4 p+ L) |. Y& g5 L# T1 I! B0 {OpenFlow actions=drop: p: {" x$ B% S  ^2 F) }
7 |+ y7 W# }: U) q# R  Y
Final flow: unchanged
0 g6 E: c( E. A- f, lRelevant 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 * t& O$ C6 Z* e5 {  V
Datapath actions: drop
! u! H6 s" O1 `6 r" o/ Z3 M! g4 I1 Z; s: ~8 G% R1 P
满足条件RESUBMIT
3 v9 T, v1 Y4 n, v( @  Q( K6 ?  C; @% A
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:10 ; t+ g  S8 _8 O: i
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 1 H+ G2 c: U9 O* Q: I( [( b, M
Rule: table=0 cookie=0 priority=0 - M. A! F) C1 B3 n
OpenFlow actions=resubmit(,1). I9 o+ G8 J, Y  @; a

' m" a6 e2 T( J        Resubmitted flow: unchanged : s2 m6 ]- A& c( z8 G& @; Z
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
( K5 h& W" u1 [' P        Resubmitted  odp: drop
4 N& E$ |+ A0 w9 E8 w        No match
. u6 D1 A! l- ~9 j: i. |3 p  f* z' [% p# w/ c) _# Z( u3 d; f" O  X
Final flow: unchanged
; }; F, F4 y, g% f& |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   P- g) k7 J, }9 O3 H5 q2 D
Datapath actions: drop" M. A, Y4 e7 q
4 P* q' w" s# B, q8 U  D, \
实现第二个Table 1:VLAN Input Processing
- o$ b  J5 N' s* e! m8 a% y
9 T4 K& r# _5 M首先添加一个最低优先级的DROP的规则2 R4 O  q7 R6 T2 o
8 Y" w2 B6 s4 H! d7 w  O3 `# O
sudo ovs-ofctl add-flow helloworld "table=1, priority=0, actions=drop"
  h5 u  n9 i4 a7 g/ a7 X# ]. n/ t% z2 j- Z8 u
对于port 1,是trunk口,无论有没有VLAN Header都接受。, e7 t) Y! z8 H3 F# t' s9 m3 l4 r' G
$ ]9 K: W) U: F& m  j! l
sudo ovs-ofctl add-flow helloworld "table=1, priority=99, in_port=1, actions=resubmit(,2)". {( ^# m6 ]' q4 M' \

$ S2 H" x$ |" [6 Z" n( ~& d对于port 2, 3, 4, 我们希望没有VLAN Tag,然后我们给打上VLAN Tag9 s, Y+ @3 O, r5 \! Z8 a
- x, b  T  v7 K& I
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'
7 _% X: A$ g9 E0 m- G1 ?$ Z" Stable=1, priority=99, in_port=2, vlan_tci=0, actions=mod_vlan_vid:20, resubmit(,2)
7 z: \6 P2 ?+ xtable=1, priority=99, in_port=3, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2)
5 c$ ^" J/ J9 S0 `2 Itable=1, priority=99, in_port=4, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2)
2 _5 Y# E9 ?, E; Y" x8 YEOF( Q8 ?! V% E1 R8 c( P
5 L( G% D9 K  d6 R( ^
$ sudo ovs-ofctl dump-flows helloworld
: L- `6 v$ C0 |6 s" Q- l4 q! E. ENXST_FLOW reply (xid=0x4):
! o2 Z1 W: {) C' rcookie=0x0, duration=4478.582s, table=0, n_packets=0, n_bytes=0, idle_age=4478, priority=0 actions=resubmit(,1)
; i# ?4 t+ J2 \+ c; Y5 N* Fcookie=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
; b, o" ?, O8 G6 Q; b; V0 B! Icookie=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 1 ^/ d! `% z7 Y" E
cookie=0x0, duration=89.273s, table=1, n_packets=0, n_bytes=0, idle_age=89, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2)
3 I! L" g' o; q- Z  P: Ecookie=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) , f" l1 l2 s, w- @! a5 s
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" D6 ?. ]7 V8 X( i# Mcookie=0x0, duration=220.318s, table=1, n_packets=0, n_bytes=0, idle_age=220, priority=99,in_port=1 actions=resubmit(,2) , C1 l7 e* d! L4 H1 f
cookie=0x0, duration=298.739s, table=1, n_packets=0, n_bytes=0, idle_age=298, priority=0 actions=drop3 C3 @. X  L* T" g4 Q
! V/ J* D' \6 T- E& y
测试一个从port 1进入,tag为5的( m6 o" z6 [; Q  T( W0 `

1 q& T; M) Q, P( W, w$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=5 . y; Y! D9 m3 d0 ^
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
8 j, g) `4 s1 M( ~7 cRule: table=0 cookie=0 priority=0 4 z1 X' Y- J" L7 o: j6 R# @
OpenFlow actions=resubmit(,1)
. f( X- N4 }0 ^8 ^3 }
; u$ N+ v. y. j3 o& S/ {        Resubmitted flow: unchanged 5 ^% J1 i' \; E2 @$ v) w: N
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
. `% y$ M* u/ p5 c* _8 {. I        Resubmitted  odp: drop   T) v8 c1 e- I& |% E( M
        Rule: table=1 cookie=0 priority=99,in_port=1 / W7 G2 A4 }0 {- _% h' {5 c
        OpenFlow actions=resubmit(,2)2 W+ u0 ]; Q$ H2 R4 c% r0 l
3 D# c: h% z$ x( ^
                Resubmitted flow: unchanged
  @# v8 N) h9 Z2 r) u4 _                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 T9 k7 u! V0 e; m2 D8 b0 V
                Resubmitted  odp: drop ( M6 x" u  T) \7 i. ~, D
                No match, {3 ^& b0 X* d: p( }" J, Y9 A
6 Y2 G; [- f5 Y$ g" U5 N6 [
Final flow: unchanged
* Q0 y( k0 E( b- x5 |+ C6 r- R" URelevant 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 7 g7 `- ]5 W5 O7 {1 E! _9 v
Datapath actions: drop- S! w+ }8 b+ W3 t* R' f: D/ |, s
" v0 I7 o# g$ P6 b+ }( `
测试二,从port 2进入,没有打Tag的2 L! x# @3 H9 R! v! }  _' b
2 N  h+ b9 L$ u$ X* j, I/ v( g6 q
$ sudo ovs-appctl ofproto/trace helloworld in_port=2 ; X8 l# a' d1 U! \' f
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
4 u5 a* M$ \% D7 }1 |4 _  vRule: table=0 cookie=0 priority=0 & F5 e( Q+ E8 C! G0 c
OpenFlow actions=resubmit(,1)
) v1 s' b: i+ P. y; w# }" H% o: Z" O: V7 |# g6 h/ C, _3 B
        Resubmitted flow: unchanged
, b( Q4 l/ G5 m' M, i        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
! D4 ~' }2 h+ n; m; r        Resubmitted  odp: drop 5 |0 v: ~  w$ d5 r( _
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
7 c! ?% M9 [" D- K$ I        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)0 e  n( M6 E/ Q3 V! ?
2 v/ p$ _1 P% S6 u( J! V3 ^, h$ @
                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
. f6 P! |8 _; b2 }0 _: N8 ^7 d                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 6 o9 x' e0 \1 h- G$ U) P
                Resubmitted  odp: drop
3 o5 i( s  W! Q; d* H% X. j                No match
1 J* c; `0 Q/ e% q) R3 A: }& U" T# e, u1 I1 w
Final flow: unchanged
& ]0 D4 a4 o7 t! n/ t) M1 Q6 uRelevant 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
  \3 y. M  x( b. u( s# \Datapath actions: drop* w# x. d( j+ ?$ i5 n, L
' N1 w/ l  N0 V  T) l5 g
测试三:从port进入,带Tag 5的  V- x& m5 F' [1 S* z: q

. E: p, v$ M  x$ sudo ovs-appctl ofproto/trace helloworld in_port=2,vlan_tci=5 * {3 ]$ X/ {0 _( ]) u
Flow: 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 3 `, t" |' }/ ^2 D' M
Rule: table=0 cookie=0 priority=0
4 @; @  P3 \( L& L3 {OpenFlow actions=resubmit(,1)
# z6 B% h2 t8 }8 b  x) H% U! Y: ^" Q4 j# Q7 |& d! ?* }- M' {5 ~5 r
        Resubmitted flow: unchanged
3 q5 K+ Y' m5 \7 l8 d$ ^6 [5 Q. q" b+ x/ u        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 + |$ a7 s7 P. ?
        Resubmitted  odp: drop   n9 i8 d) D2 D! c% a  `0 o4 [# E! y$ G# j
        Rule: table=1 cookie=0 priority=0
6 V) j* r# I$ ?6 O2 c        OpenFlow actions=drop' v1 K" Y# ?! s% n
% \8 u( i- t# l/ \. ~9 W, p
Final flow: unchanged / V' k: T3 A, \6 F0 G- Q6 w: {
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 8 b9 \% F5 n, u3 s  m- g
Datapath actions: drop
1 A& J, f3 s% t( w/ Q  x; p/ d& {2 P4 _* f$ B/ g7 Q
实现第三个Table 2: MAC, VLAN learning for ingress port% y6 }. W) D* K$ h" V

4 f) U) X  `' H: a对于普通的switch,都会有这个学习的过程,当一个包到来的时候,由于包里面有MAC,VLAN Tag,以及从哪个口进来的这个信息。于是switch学习后,维护了一个表格port –> MAC –> VLAN Tag。6 ?1 Y' {+ |( {8 w

$ N/ ~! n- J9 i1 Z9 d: R. ]3 X0 b6 {这样以后如果有需要发给这个MAC的包,不用ARP,switch自然之道应该发给哪个port,应该打什么VLAN Tag。, i1 C% w+ q: k8 y. s  |5 a2 ]" v

% C* E4 L4 j9 U/ O9 T' L1 T1 {9 qOVS也要学习这个,并维护三个之间的mapping关系。  N, j( o: z- }

1 D  W# r- V: u  g2 }- h+ U+ A在我们的例子中,无论是从port进来的本身就带Tag的,还是从port 2, 3, 4进来的后来被打上Tag的,都需要学习。
8 o, h+ s, h5 k* c6 s& a; V" h- F9 N6 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)"2 X9 V! a. h3 c: Y
3 y5 o# c3 P$ ^- K4 g; l5 g" b
这一句比较难理解。
% `% e2 c- r( K9 D/ J& c% l/ c
) A! Y" p' ]6 J+ z) l6 B* p* h; Jlearn表示这是一个学习的action
! y3 S' V, Q' j9 Q6 R) H  ?* T2 @0 v% }) }; ?/ Q
table 10,这是一个MAC learning table,学习的结果会放在这个table中。( Q# \2 M; g) q; I. X
$ a5 W; u* d' x& ^" K
NXM_OF_VLAN_TCI这个是VLAN Tag,在MAC Learning table中,每一个entry都是仅仅对某一个VLAN来说的,不同VLAN的learning table是分开的。在学习的结果的entry中,会标出这个entry是对于哪个VLAN的。9 B5 l+ j; N$ l4 w
/ S2 t% G# ^5 ~8 _! ~* ?9 c
NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]这个的意思是当前包里面的MAC Source Address会被放在学习结果的entry里面的dl_dst里面。这是因为每个switch都是通过Ingress包来学习,某个MAC从某个port进来,switch就应该记住以后发往这个MAC的包要从这个port出去,因而MAC source address就被放在了Mac destination address里面,因为这是为发送用的。# u) Z) x0 [- V
( T. S# X2 I0 g: C0 n) b8 y
NXM_OF_IN_PORT[]->NXM_NX_REG0将portf放入register.( i( [0 Z0 W. G, \' `

% r* y* b* j/ n$ ^& ^) ~一般对于学习的entry还需要有hard_timeout,这是的每个学习结果都会expire,需要重新学习。
) l6 M% s+ |$ B# F3 ]8 d7 s3 ]) W! e- a6 u3 l5 ]9 {$ S
我们再来分析一个实践中,openstack中使用openvswitch的情况,这是br-tun上的规则。1 |  M( o: k: V" |) H/ _8 t8 v
. {4 Y5 n: X# Z* N7 e
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
! ]' Z+ m, C/ c+ A  [/ V" {cookie=0x0, duration=802187.786s, table=20, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,21)
* N, s0 v) |* |- Q& |. C: A 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
5 w/ b; B' x. {, Q" bcookie=0x0, duration=802187.653s, table=21, n_packets=17, n_bytes=1426, idle_age=65534, hard_age=65534, priority=0 actions=drop
+ M# E; |5 d( A! dcookie=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:23 u5 L5 k4 f7 f1 K  J8 _. Y
  @! Q8 N+ F* @, f
这里table 10是用来学习的。table 20是learning table。如果table 20是空的,也即还没有学到什么,则会通过priority=0的规则resubmit到table 21.
: o# X9 O& a) A8 o7 Q7 `  B9 A! s" D( N3 G% l
table 21是发送规则,将br-int上的vlan tag消除,然后打上gre tunnel的id。" x' Q3 n0 {+ u( q! s
* T+ i" u, ?+ }0 _
上面的情况中,table 20不是空的,也即发送给dl_dst=fa:16:3e:7e:ab:cc的包不用走默认规则,直接通过table 20就发送出去了。
- u7 L3 V, C+ ]/ Q& q2 j& `
  x. V" p6 D& k$ O9 itable 20的规则是通过table 10学习得到的,table 10是一个接受规则。最终output 1,发送给了br-int
# b8 K& e, i' h- I# w
, p% U' e, l8 INXM_OF_VLAN_TCI[0..11]是记录vlan tag,所以学习结果中有dl_vlan=1% D3 D( h# i' J
0 G7 ?' h3 c% f( C3 j3 z
NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]是将mac source address记录,所以结果中有dl_dst=fa:16:3e:7e:ab:cc# r0 w8 U2 {: ]+ c7 a. G9 R) P2 R+ a
& X0 l5 v+ l# E/ a. t0 J) w
load:0->NXM_OF_VLAN_TCI[]意思是发送出去的时候,vlan tag设为0,所以结果中有actions=strip_vlan+ g/ v+ K( i9 U% }0 m7 c+ N
$ T8 r# k( y9 N+ f* G$ P  h
load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[]意思是发出去的时候,设置tunnul id,所以结果中有set_tunnel:0x3e9. d' V* k/ a. _5 o, _% x

: ~8 o0 K' K( t6 \' r) z6 w/ \output:NXM_OF_IN_PORT[]意思是发送给哪个port,由于是从port2进来的,因而结果中有output:2
# T- l- }% ?" J' y3 P3 c  L; _- K4 a7 |* W0 E. `0 {
测试一:从port 1来一个vlan为20的mac为50:00:00:00:00:01的包0 \; ?1 b# J+ U5 i9 `1 `

, \& g$ x! n. B$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=20,dl_src=50:00:00:00:00:01 -generate   # X1 Z  }, l( T% c# e
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 ; U# R2 N5 K, G4 Y# D5 m0 O
Rule: table=0 cookie=0 priority=0 6 Y) t  ~- D7 j$ \
OpenFlow actions=resubmit(,1)
/ D9 ~; I+ M7 o8 g! e/ y6 M" M  [* F$ v1 t8 ~
        Resubmitted flow: unchanged
, T9 z" r8 Y1 J2 w$ P, `: s        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
( d: R7 @( z% e3 j& q2 s        Resubmitted  odp: drop , a# [5 v  |* Z# n  I$ w; Q
        Rule: table=1 cookie=0 priority=99,in_port=1
2 j! _, `! x. P: S4 J        OpenFlow actions=resubmit(,2)$ e& x) p# P5 D4 N! H4 d" @0 Q
1 K0 ^" a8 z. F  f
                Resubmitted flow: unchanged 1 b/ \4 X; y" N! a) T
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
& \+ d! V, H& |. S; T, q/ j                Resubmitted  odp: drop
1 B! M) R. B! [0 U- [7 l                Rule: table=2 cookie=0 6 t3 s& o8 D1 s
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
8 x- g- [4 U7 L) I" @( e8 O8 d
$ C8 [* E* g* K" e) \) ~+ v) Q                        Resubmitted flow: unchanged 7 t4 ~! U; v# \/ W6 h
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
7 Y7 u  a$ H. F- n) u1 E                        Resubmitted  odp: drop $ l5 Q. A+ j9 }- d# F0 O2 Z
                        No match
9 Y! }6 b, |% k9 G" R& L1 t8 ?6 E# t3 p0 r
Final flow: unchanged
2 Q- N6 ~, E$ l! f& w9 XRelevant 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 & m4 }$ k$ j) [) O6 K
Datapath actions: drop% f' m$ G2 S* T2 T0 i6 E

' r- }. z+ Z: b( W- t/ t- N$ sudo ovs-ofctl dump-flows helloworld
0 o( i% I+ \1 Z/ Y6 |NXST_FLOW reply (xid=0x4):
5 m0 G) B$ f5 lcookie=0x0, duration=90537.25s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
) D2 ^! _! M% q; `2 K. ~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
, @# X) m3 F/ q! e, v" G" c( zcookie=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 9 s  ?8 O, J# L4 I+ b* y
cookie=0x0, duration=86147.941s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2)
9 g/ [1 [, {+ X( d+ b7 `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) & y) G* r' R9 V; C
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)
9 i% M8 a: P7 a7 \# ]4 |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)
& p/ i6 \, g7 N+ V% icookie=0x0, duration=86357.407s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop / |6 z0 z* A/ J" I* y: h; @2 ^
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)
. C+ E/ ]; C: g( s 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]- ?, G; {2 Q$ c5 e

" @+ J( h9 @* V2 j% P9 @table 10多了一条,vlan为20,dl_dst为50:00:00:00:00:01,发送的时候从port 1出去。
1 M% y" p4 i( w, w1 w% J- V9 J' ]1 J
测试二:从port 2进来,被打上了vlan 20,mac为50:00:00:00:00:02
3 {* k5 V* ?# ^* S4 E' e
% t% K. |6 P! n& U' [1 r$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=50:00:00:00:00:02 -generate   
7 i; w5 H' k( t$ @/ i. H  |Flow: 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
; r$ f2 M. e+ J; y3 a' CRule: table=0 cookie=0 priority=0 8 f; @) g9 b, V9 v2 m3 M& U+ j# W( {
OpenFlow actions=resubmit(,1)% E, b' o6 {' ^9 J% h

& [7 k- f1 A( }% O1 \  x        Resubmitted flow: unchanged
9 n2 o, P, a; G' G1 m' Y3 |) H        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 . E, T+ ?! K1 O8 v
        Resubmitted  odp: drop
( C0 S$ n, ]/ R$ F        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
3 j: e: u/ R4 X2 q        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)' d& J( x: f* ?0 W
+ l4 o  b# ~1 ?! E
                Resubmitted flow: metadata=0,in_port=2,dl_vlan=20,dl_vlan_pcp=0,dl_src=50:00:00:00:00:02,dl_dst=00:00:00:00:00:00,dl_type=0x0000 4 i( s& K9 ^; |( r0 E. s
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 L' }- ~8 A1 @/ {" X, d
                Resubmitted  odp: drop ) [% g3 C: T1 j: W
                Rule: table=2 cookie=0
: x' }6 F  `  Q0 r/ K) {                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
! ]( G& N0 s; O: Z
( R  U- @; x. S: Z- L                        Resubmitted flow: unchanged / R$ g9 p) E3 l* p# o$ [) E
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 8 U8 W& C' O3 d- R9 V4 ~! O
                        Resubmitted  odp: drop ( l: k- W* `/ d: `) Q
                        No match
4 P7 c3 Q+ p  a( r! O& P$ d8 n
7 Y7 A; ~8 {' q) w( ]9 IFinal flow: unchanged
+ r% ?5 M/ m% G/ R. u9 N2 hRelevant 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 5 D( W  N4 U0 Y7 H$ o! i
Datapath actions: drop( A7 V: d  g# g$ L/ Z" M5 d! S

  j( u  G" b  R0 R" S3 t' I$ sudo ovs-ofctl dump-flows helloworld                                                 : N+ F# N' }1 ^
NXST_FLOW reply (xid=0x4):
" H# V; ?: E+ W% c( lcookie=0x0, duration=90823.14s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
/ F& c# V7 [8 n1 T' Rcookie=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 5 t9 F9 S% w, o0 m( l
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: b' Y. g" M2 ~9 |5 x7 `
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)
8 n! h1 b7 R0 Ycookie=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) ) r6 P) j! P5 Q9 }0 Y
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)
. |9 C$ v0 f* Z: @1 N3 _$ F; ]8 z3 ncookie=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) 5 E: E7 ?+ _/ r5 f! m
cookie=0x0, duration=86643.297s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
2 g4 F+ h: w) I7 hcookie=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) ! l! j; [7 c9 d( p- J! f
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] ' @1 @9 H4 s" h
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]! F+ g: |( \. P& w$ }5 P
: v! v1 I( n& f+ I0 N
实现第四个table 3: Look Up Destination Port) o! A" U1 S% I5 A$ a* e: Q

) O" o( Z+ J# q: b# T  b在table 2中,vswtich通过进入的包,学习了vlanid –> mac –> port的映射后,对于要发送的包,可以根据学习到的table 10里面的内容,根据destination mac和vlan,来找到相应的port发送出去,而不用每次都flood
; A* Y2 f+ Y" D6 o6 r6 G; M0 ~; b1 O
sudo ovs-ofctl add-flow helloworld "table=3 priority=50 actions=resubmit(,10), resubmit(,4)": e) c/ F% ]$ d( s
4 ?8 m1 p, g. @
添加这条规则,首先到table 10中查找learn table entry,如果找不到则到table 4
  N9 W  ^' {+ t9 R+ z' c7 M8 q2 b8 m5 @* O
如果包本身就是multicast的或者broadcast的,则不用去table 10里面取查找。* }# D% F' l4 o( _; N

0 F+ \; M* s, B+ o1 ?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)"3 \6 [1 t. P) N4 Z% E% j

! B# d; p9 j9 M6 v+ T+ |4 V我们进行一项测试* `* w3 M5 j+ {1 f
6 [4 F( p# E$ n; }( `$ u, J$ O# f
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=20,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01 -generate   
1 h3 a  N: P" B, t8 h# kFlow: 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 2 ?/ W5 ^3 P7 N+ Q! I
Rule: table=0 cookie=0 priority=0
' h( a+ B/ C" |/ VOpenFlow actions=resubmit(,1)
/ r& s  l+ F/ a0 u
' l  O4 r, I( d+ |( H5 W+ v1 c        Resubmitted flow: unchanged
" }1 t: G  D# x1 h$ B        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ) |. e4 i# F3 S
        Resubmitted  odp: drop
# h7 G* U/ `- f- V        Rule: table=1 cookie=0 priority=99,in_port=1 ' y) _( D& g$ ~
        OpenFlow actions=resubmit(,2)
/ E3 X2 _6 v5 c9 G9 ^2 U0 G6 T, L" L7 \
                Resubmitted flow: unchanged 4 G$ P. J0 }  W1 B3 z
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 4 R: i/ U4 A! g) @
                Resubmitted  odp: drop ! }8 `/ n$ U5 ?5 v( W4 n
                Rule: table=2 cookie=0 ( K+ D% a4 F9 k2 v: s! i1 i4 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)
& R# V/ H( T: ~% L: j6 S
2 p1 r, s2 ?* @6 N! C                        Resubmitted flow: unchanged
! z* Y2 i( q- ?$ h7 e0 n                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
% W2 F9 t" d( p3 M9 G                        Resubmitted  odp: drop
- V2 Q: R0 y. F                        Rule: table=3 cookie=0 priority=50
1 h& B7 w  e0 ^& k7 `4 j                        OpenFlow actions=resubmit(,10),resubmit(,4)" J: X* U7 }1 Y

8 P2 o8 |* H3 x* }- o; p2 \                                Resubmitted flow: unchanged 7 K& Q1 A- M+ \# M
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
  J/ U6 c; I4 Y3 i5 E( }& S                                Resubmitted  odp: drop : Q0 c, U" C7 D/ @& L
                                No match
4 x* q% o( J& t, _  ?( l  k# A! W* E
* Y) k) ?- ?( o& A; A                                Resubmitted flow: unchanged ( {/ e, z/ D/ S; l# @* C& e! ^4 K
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
( U; O" \; {$ `# U- Y                                Resubmitted  odp: drop / Q. ^- E9 f5 d- ]. B
                                No match
% }" f: n  p& A2 i: A$ o+ \( n' f) ~8 C/ X" D% `& D
Final flow: unchanged
) i4 j7 W+ D7 m- p: Z  PRelevant 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 7 [0 t+ \. F- n8 g; \; [
Datapath actions: drop9 h5 A  K! [4 ~2 e! e7 b( P. d

" q4 M4 u: l4 Q: R! x4 ~8 h- ~由于目标地址f0:00:00:00:00:01没有在table 10中找到,因而到达table 4.
- C8 F. [6 |4 H9 B5 K4 t8 {5 l- g. l' ~
但是这次测试使得table 10中学习到了mac地址90:00:00:00:00:01: V# _; I; A. ~7 Q3 w1 V: a
. w! n+ W9 w9 n* l( a
$ sudo ovs-ofctl dump-flows helloworld
- T1 `( D  E0 q8 x9 g8 ^NXST_FLOW reply (xid=0x4):
0 I. d) O5 B; `  y" {cookie=0x0, duration=91588.452s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
6 c1 E& l, }% I. T: i, ?/ N; Tcookie=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
- y) B* f3 r! 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
: Y& [/ k5 @" U# mcookie=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) / F* b- Z' w6 Y6 C$ o
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)
. j& f* ^& Q: M5 vcookie=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)
- n0 Q; O( R/ Y  k! d  ~! 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) " C; a% w% Z% c* l- ?5 K7 s
cookie=0x0, duration=87408.609s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop * X4 O( X' d0 ]
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 }: H8 g' O$ S
cookie=0x0, duration=352.841s, table=3, n_packets=0, n_bytes=0, idle_age=352, priority=50 actions=resubmit(,10),resubmit(,4)
& T6 o$ V8 c5 S7 l4 q# Hcookie=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)
4 s7 g" ^$ V! z/ w: ` 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] 0 d0 u) R; p7 J
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] ' k4 e+ k, S+ i/ g* D, \+ F
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]" [# ~- l: g, a3 A; O: {+ R) j

5 @) ]4 c7 }) p0 D4 Q( F& [下面我们进行另一个测试
% D' K2 j: N6 R  Q5 e0 J# c* W5 J3 {+ ^7 z: z! |5 n7 a. R$ `- Q
$ 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   
% h; H3 G4 P8 uFlow: 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 ' x+ b- v9 }3 P  I
Rule: table=0 cookie=0 priority=0
% q) Z- w7 s6 OOpenFlow actions=resubmit(,1)
/ T  ]* A1 K& B) w: ~: ~" y& |$ [, Y. W: P6 A
        Resubmitted flow: unchanged
% x* p3 b8 u; ]8 I" K        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
# @' z2 u8 T$ O& k6 c, |        Resubmitted  odp: drop
/ G% e: P; o1 L: a2 ~8 l        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
2 B! s5 @* {7 N4 ?        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
0 G  l1 b, t5 r
+ t1 `  N0 R- d                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 / O, b7 O3 z0 g! Q3 S7 s
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
/ e  {. s5 y, I/ u0 L2 E+ D                Resubmitted  odp: drop
1 p. L- u- y/ h% j                Rule: table=2 cookie=0
  f- h/ G" a4 z% 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)1 [* A: Q2 _" G# ?# I( Z. T: b
" Y% p$ k9 ~( X* W9 k+ t
                        Resubmitted flow: unchanged
1 M. p& g( `/ W# C                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
3 u8 c: Z# g5 ?                        Resubmitted  odp: drop 6 d: R6 H6 N+ U1 w
                        Rule: table=3 cookie=0 priority=50   ?. a9 n+ d7 ^' c* f
                        OpenFlow actions=resubmit(,10),resubmit(,4)" _- s, B) _: p. w5 m

) O) j: I, S) M% w                                Resubmitted flow: unchanged
" {, A% y: d& c8 B                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 " G. x8 m% A3 y6 E  T$ l
                                Resubmitted  odp: drop 9 j/ d/ W. ?3 h! N
                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01 + Z& |! A* V$ \; [8 h
                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]
6 [+ ~: p$ @2 |. \. Q6 }
3 h. L3 F7 }$ u8 t" q                                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
) w% A4 K3 r" n! w3 A6 z1 j- w                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
. _! u  L1 i8 s                                Resubmitted  odp: drop
2 j9 }8 A/ s/ i+ ~& }& U                                No match: F. P4 u" C( u; U& ?  @
* Q' y) i  t$ x) q" T* \" c
Final flow: unchanged
& k0 G3 k  m% qRelevant 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
$ L! m4 D6 ]: F- z6 M2 U1 BDatapath actions: drop: m0 d! j( o- l" M) Z4 k) G' {

0 V. n" T3 U5 h因为刚才学习到了mac地址f0:00:00:00:00:01,所以这次在table 10中找到了这条记录,这次同时也学习到了mac地址90:00:00:00:00:01
  z( W' }* P0 W4 P& `3 E, ?) N/ G; `' Y) a
下面我们再发送第一次的包4 `" y. u# w5 N7 t3 o2 o
5 W9 s+ L9 V) H
$ 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 ; s/ E/ C) ?) m/ y
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
* ?; Y, H/ L: O8 K% s! eRule: table=0 cookie=0 priority=0
- N# X4 ^2 n/ ?9 r8 nOpenFlow actions=resubmit(,1)
1 C3 r8 ~( W/ a7 `+ Q& F8 p) F4 E* Z* j, j& G1 P3 p) C" T: v7 z5 ?) I
        Resubmitted flow: unchanged
0 c# l/ Q, [( U7 y8 k        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
6 D2 v7 O8 N4 A/ d, g) u        Resubmitted  odp: drop 4 N- O& u2 t' b+ }" B
        Rule: table=1 cookie=0 priority=99,in_port=1
; E6 Y: a$ [6 |3 j3 ~- |! B        OpenFlow actions=resubmit(,2)
9 t% H& e' g! d6 v. l$ c/ H7 {) ~2 w
                Resubmitted flow: unchanged 9 p3 Z# q2 B0 L7 s) }
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
" O; G9 f- [) Y6 g/ x                Resubmitted  odp: drop 5 \! J/ ]; d3 j- U; Y
                Rule: table=2 cookie=0
8 ]+ I: M4 Y$ S& Q9 z$ {                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 i3 y/ }4 y8 e. t8 v+ }  \4 C' g% M$ R: d, Y
                        Resubmitted flow: unchanged " Y& Q7 p& |( A7 n9 t. ~" j7 F
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
, q7 \/ y3 o& ?% z* E                        Resubmitted  odp: drop 7 h- x+ S- b: C4 r' d
                        Rule: table=3 cookie=0 priority=50
/ o0 e) B8 C' \; v* {0 Y                        OpenFlow actions=resubmit(,10),resubmit(,4)
* B, @0 C' S4 U( p9 P/ H0 n& j, u" X
                                Resubmitted flow: unchanged 3 O7 k( _* f' z. x: {' r
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 " X1 H" N* D3 A' _( w
                                Resubmitted  odp: drop 2 i+ S( y. q: |8 T+ M6 u
                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01
( L0 i/ t; N* l" Z) v2 ~; K                                OpenFlow actions=load:0x2->NXM_NX_REG0[0..15]  c1 x) i3 n2 B- S  _, K" T
/ l- }& [% z" q3 f; z" l
                                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 + d& E! q% d- ^' e+ a
                                Resubmitted regs: reg0=0x2 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
/ i: E( q  R( M7 F2 k  q2 Z, G/ U5 Q                                Resubmitted  odp: drop
4 r2 X" f) c1 o7 y                                No match5 g! o. F( e8 W) n
0 X. I  n6 ^3 y
Final flow: unchanged / d* j9 F2 U- D( p5 s
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 0 p' d/ Q% h. n  m- ~+ J: ~
Datapath actions: drop
( j2 y* G; Z. E4 y- L/ U; p4 [
' f6 a) N3 ~. `2 G7 b9 Z发现也在table 10中找到了记录5 }" e6 q( B! W3 `0 x

/ Z1 L. m; A4 D6 t! k实现第五个table 4: Output Processing$ {1 ^6 U7 {9 `3 ^; K( b' U
2 C; J5 g4 r+ ?* y) l. J7 p6 k
这个时候,register 0中包含了output port,如果是0则说明是flood。# [0 l8 u, A) f( p! e

/ j7 @; v. R/ N$ Y' V/ j- q对于port 1来讲,是trunk port,所以携带的vlan tag就让他带着,从port 1出去。
9 |4 V5 B# }& Q; _3 o& |7 `- g/ q: \# M( E
sudo ovs-ofctl add-flow helloworld "table=4 reg0=1 actions=1"* g% _% y- n; S: G- ~4 N
/ [# ]" X7 J" J" F7 ~, J2 ^+ x
对于port 2来讲,是vlan 20的,然而出去的时候,vlan tag会被抹掉,从port 2发出去- y$ J! b9 g) r+ N
+ B- [6 T' K, [' T2 L
对于port 3, 4来讲,是vlan 30的,然而出去的时候,vlan tag会被抹掉,从port 3, 4出去6 @. ?$ L6 ]" L( p4 B$ s! a4 R

$ a* d* ]7 \% A" t1 s$ o& F( m' B$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   5 R" }% c' L! x# s1 T
        table=4 reg0=2 actions=strip_vlan,2 7 }/ U2 K+ p: b; T7 @* a
        table=4 reg0=3 actions=strip_vlan,3
( H1 k9 s, {2 g& g        table=4 reg0=4 actions=strip_vlan,4
& H# ?8 Q8 r( x& mEOF
9 |# P  a7 F6 m) C! q9 R( s" a
; Q2 p0 ~" A, T! s5 P对于broadcast来讲,我们希望一个vlan的broadcast仅仅在这个vlan里面发送,不影响其他的vlan。. R0 y* h) [' m

  y! c1 D/ O6 J) Q$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   : S8 D' A: N( U  Z
        table=4 reg0=0 priority=99 dl_vlan=20 actions=1,strip_vlan,2 7 `5 Z7 d4 B4 S% J2 j9 |. w
        table=4 reg0=0 priority=99 dl_vlan=30 actions=1,strip_vlan,3,4 % V6 L& P, v2 t! a# ^4 ~4 w9 Y' W/ S
        table=4 reg0=0 priority=50            actions=1
, G' q8 z& @& n, R9 j! ^- g3 fEOF
! y, j' ?4 \9 K& V
. q- u" I# m6 r; _2 @所以对于register = 0的,也即是broadcast的,属于vlan 20的,则从port 1, 2出去,属于vlan 30的,则从port 1, 3, 4出去。
1 k4 c/ }5 r* f2 A2 R  L
! {" @" g* o% [/ ^6 _8 `$ sudo ovs-ofctl dump-flows helloworld 8 e3 H; ]- i1 a" S
NXST_FLOW reply (xid=0x4): % G9 F/ ]9 \4 ^  Y
cookie=0x0, duration=92909.119s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
3 c$ l; O: j" G! x: ]5 S4 L8 Icookie=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
/ o# \9 g9 q- N: `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 3 a* J, {5 V) K5 _0 @" h
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)   R1 X3 R/ m0 x& H9 k. V. l
cookie=0x0, duration=88519.81s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
- a* _" _- H: _* `9 \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)
' V( w7 U% g8 x. p0 Y4 ocookie=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)
, V& o' Z" B) D; X' H' [% |cookie=0x0, duration=88729.276s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop , q) A  a8 }" n- b* ]2 Q- N- c
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) 8 ]# ?0 x% s; L# u! {
cookie=0x0, duration=1673.508s, table=3, n_packets=0, n_bytes=0, idle_age=1673, priority=50 actions=resubmit(,10),resubmit(,4)
" j, ]% @7 e- f( Mcookie=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 P0 ]& k. w. A+ Mcookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x3 actions=strip_vlan,output:3 5 C6 O( T% I- F* z. D# b$ h6 \
cookie=0x0, duration=228.839s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=50,reg0=0x0 actions=output:1 ; k  K& R' u$ e$ ]' a6 O" g. b
cookie=0x0, duration=483.068s, table=4, n_packets=0, n_bytes=0, idle_age=483, reg0=0x1 actions=output:1 " @0 `$ E* h/ M% M6 E
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x4 actions=strip_vlan,output:4 7 o- |9 q; @# s
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x2 actions=strip_vlan,output:2 # v. d: M! O1 N/ @' \
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
9 N9 a9 |# V5 k$ s9 D8 Bcookie=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 # T2 {% u! x" m0 W
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]
' w& y9 `4 J, B5 T( _7 Gcookie=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]
: \0 U" j6 y6 {9 X, b8 G5 p7 lcookie=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] : g. z. l7 B" O" m6 D% y/ U
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]
/ |6 g4 U5 ~5 B- X+ f" C) \( s
2 z" f- }) b( H首先来测试一个multicast和broadcast4 _# \  \$ A# x- D6 d

3 R; V! a0 m3 Z如果是一个port 1来的vlan 30的broadcast
& E/ m" Z' J* K+ P) ?
6 x$ V" `* D" A: }8 `$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=ff:ff:ff:ff:ff:ff,dl_vlan=30
9 k9 \+ x% W, z$ gFlow: 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
+ M+ `0 j3 l* x# \- cRule: table=0 cookie=0 priority=0
1 r. l' b% ~  A5 Q( ~) iOpenFlow actions=resubmit(,1)
0 S% Q8 b* U, P9 P+ i' i6 g# D6 W; [) {  [; j  ]3 K
        Resubmitted flow: unchanged
  I) t' Q$ l1 y: I$ U        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0   t- W( e0 _1 w/ N
        Resubmitted  odp: drop 4 z; |) b8 o+ h1 Y4 a8 O0 B
        Rule: table=1 cookie=0 priority=99,in_port=1 $ P4 {, H2 S6 o0 W8 d
        OpenFlow actions=resubmit(,2)
$ [/ B: e3 `4 B0 s0 V5 |( N4 _% \. O% M, `4 v9 F" g0 d
                Resubmitted flow: unchanged 8 K; s4 k4 Q  X0 X5 ~% u
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 4 s/ P* p5 {. Z
                Resubmitted  odp: drop . f0 o7 L) T3 W7 y) d
                Rule: table=2 cookie=0 ' @5 v6 D$ z. M) O( 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)
  M- u+ M+ Q( \: T1 T4 S% r8 `* b) u* y) y& o6 j# e1 S
                        Resubmitted flow: unchanged
5 N- r- \5 U$ d" W3 U0 i* e                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
" y; k( L% {5 i                        Resubmitted  odp: drop
) b7 Q# b" |/ D                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00
; Z  U' m+ Z# b+ A4 e                        OpenFlow actions=resubmit(,4)# @2 T& [  V: l- x3 Q3 d( }

/ i4 o- C& }! M; B                                Resubmitted flow: unchanged
$ C2 z; f- i" F4 G8 q                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
* ]! F+ h# g' v: l& t+ ^* F                                Resubmitted  odp: drop . p1 r3 l" H% U/ [
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30   K, j5 Q( l3 \, l& s/ U; M
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
1 [5 @9 B9 q1 I5 ]8 `                                skipping output to input port9 ]& d& U7 t. f! u8 S9 h' y

9 K! {8 A: J; sFinal 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
) W/ Y9 g( L8 j: v4 @7 a: W) R+ hRelevant 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 1 Q/ [4 U8 L4 M* N5 x: g
Datapath actions: pop_vlan,12,13
! y$ I$ A9 @! k
/ @9 r. O4 d5 J6 r7 X+ c" c) g结果是port 1就不发送了,发送给了port 3, 4! e, g$ I1 K/ q. H7 J- W1 ~
$ C6 y7 ^; E8 g9 U6 V, E
$ sudo ovs-appctl ofproto/trace helloworld in_port=3,dl_dst=ff:ff:ff:ff:ff:ff 2 M" a: g+ G4 \! @
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   n' f8 M: K1 e# A
Rule: table=0 cookie=0 priority=0
: P2 Z* u; D1 _OpenFlow actions=resubmit(,1)
# ?: T, H7 U3 K; R7 D, W! h- l5 l+ b( _/ X
        Resubmitted flow: unchanged 7 K/ ^  I3 `4 G) S# }; x
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
3 i+ l- @  Q- I( v' F) j$ l  t0 K0 j        Resubmitted  odp: drop " t1 O6 R& I) b
        Rule: table=1 cookie=0 priority=99,in_port=3,vlan_tci=0x0000
9 t3 Q; r1 K  ~: n: H        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)
8 r0 J4 n# x5 ~1 I! S& `5 [( ]6 i7 n: q6 t0 ?
                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 Y( m% }- u% `4 g                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
+ U- l( {5 T4 n. R" R4 w8 c8 E7 o                Resubmitted  odp: drop ' X6 T4 v6 c. W9 D, R
                Rule: table=2 cookie=0 8 U9 ]- U9 e5 ?+ Q4 H# G  c/ _3 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)2 j  {$ S: d7 N9 X1 Q* U) P
+ ?: z+ X' {1 y: T3 Z8 ?9 u
                        Resubmitted flow: unchanged " P4 T9 M  s1 o& G
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0   X  P# r4 v/ B: {# U& W* M
                        Resubmitted  odp: drop
. @: H7 M+ C' b( v                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 : l0 X8 w; e5 Y6 V5 w! T1 \* N
                        OpenFlow actions=resubmit(,4)
+ F/ H8 ]8 e! m( K( G, x/ x& ~# c. P: B
                                Resubmitted flow: unchanged
8 e) y; S! n( R' Y6 B/ Q0 \: Q                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 9 q' ?7 n* y' {& ^6 ]# ?3 F+ \* y
                                Resubmitted  odp: drop
- A" k6 k" o6 s: d# h" u                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
: Y. D! S5 m  z                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
2 R5 {6 y! x5 C) w  f$ l; J                                skipping output to input port. @% m8 D& b  }6 x8 _
" f7 @5 _9 o$ b) ]1 L. k, _; y
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
. t: `% m' L5 f! T. B4 ]Relevant fields: skb_priority=0,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:f0/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no . D3 O+ C3 ~  m  l! y+ `
Datapath actions: push_vlan(vid=30,pcp=0),10,pop_vlan,13
! i; I+ Z& c3 E( W
/ q; C2 G! |' P3 I  J接着我们测试mac learning6 F2 u8 E* w( [& S
" H9 W6 ?. l3 F
$ 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   
8 ]! m) U3 `9 d+ S2 S( O" W+ qFlow: 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 1 C" b/ G2 z9 [/ R6 _6 T
Rule: table=0 cookie=0 priority=0 2 n& \7 _6 a5 A" D% f: a: V$ ~
OpenFlow actions=resubmit(,1)
+ |% R9 e6 H8 h0 y3 n: O
8 o( X4 ~5 e; F- |, T5 f1 h        Resubmitted flow: unchanged
0 O7 ~$ C* a1 Y8 ?  j        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 2 d3 h1 {/ }$ ^
        Resubmitted  odp: drop
5 N$ l, P2 ]5 v6 T        Rule: table=1 cookie=0 priority=99,in_port=1
* X% w/ G' ]% h* r% t6 }, \        OpenFlow actions=resubmit(,2)
8 r+ |4 S! P. V! E  |" B7 J
6 p/ s0 [. s0 l: m6 v0 z                Resubmitted flow: unchanged + h2 h- m0 P+ O4 r1 H! f& K. Q7 ^
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 : u5 k2 m3 I8 K; ^
                Resubmitted  odp: drop $ r- L: @  |. z# v
                Rule: table=2 cookie=0
" F5 Z8 p0 ?- Q- e$ Z6 ~3 S                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
& i; L, I, E% a
; _; ]3 ^6 T! y/ U                        Resubmitted flow: unchanged . i; U2 _9 K$ k1 f/ @
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 $ y- @" h9 f2 y1 n
                        Resubmitted  odp: drop 8 N4 V! ?5 I( T9 P, L! g
                        Rule: table=3 cookie=0 priority=50
. ~1 `! r( W' z4 p                        OpenFlow actions=resubmit(,10),resubmit(,4)  C0 K, I8 j( w% n5 L) x! C0 Z

( y8 L  l& q3 _( M                                Resubmitted flow: unchanged
6 }8 f! z! X2 S( S6 s8 f2 h                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 7 a$ e  M  V& d9 Q- x
                                Resubmitted  odp: drop
/ t7 G" X4 ]4 E: m7 x8 y6 _                                No match
1 ]3 p8 h! k. d9 \
9 G' E" n" }  Q& `% b                                Resubmitted flow: unchanged
+ ?9 f) q& c/ N0 w                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 + p. G. D9 D( K$ i
                                Resubmitted  odp: drop
3 l: t/ }9 D/ F9 P                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 " p2 }6 M! m; @& V
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4 $ s# \0 G+ H1 z1 M( z1 \
                                skipping output to input port) A+ R$ X4 ^1 C1 A# G/ L8 ~

/ \! }3 i5 A  gFinal 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
- b% g$ r. A* T0 x( x7 v2 o5 XRelevant 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 , W9 L$ ~8 W: _
Datapath actions: pop_vlan,12,136 \+ j( j( Y9 U& f; Z2 ~/ c

1 N, o. `$ M7 B2 m6 Y由于这两个地址没有出现过,则除了进行学习以外,广播发送给port 3,4
! D. Q6 S! f( q9 n$ J8 t6 v3 I& O" B6 ~6 I: C
$ 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   
. K: A- ]* c! ^& MFlow: 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
* G5 ]' c4 {1 y7 D0 b1 ERule: table=0 cookie=0 priority=0   |) y+ ^0 N- R0 n; a
OpenFlow actions=resubmit(,1). i9 _) O( r* b' g

) E4 d$ I6 B6 J        Resubmitted flow: unchanged 3 i: X3 Z! D- m% A' [$ `1 o
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & H7 I& [0 u- J) a) @( E8 @' `8 m+ v
        Resubmitted  odp: drop ) K# j( [  d: O, j8 Q
        Rule: table=1 cookie=0 priority=99,in_port=4,vlan_tci=0x0000 0 I  a# f/ `' P( L  z* [( |
        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)
  q& W) y; x. y( {1 {5 S' h/ q( `
9 M7 ~* j% I5 T1 M' b0 m                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 & n' m1 v5 I9 n9 |* m( T8 N
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
+ v) t1 p% l1 k8 s5 I                Resubmitted  odp: drop
3 c3 J& @& y. X: A                Rule: table=2 cookie=0
6 j7 ^: q9 X. d! R5 h) r: B; Q+ z                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): t5 ^3 A! U5 [( i! H, S; y: h
) z! p  A, l3 M# i. u
                        Resubmitted flow: unchanged 8 q% j; q) U  I$ t4 Q
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
/ z  C, j6 X# F& C) ]' S. \& A                        Resubmitted  odp: drop
4 U+ P# k8 d7 ^( R                        Rule: table=3 cookie=0 priority=50 # m. o" h" G5 i7 T
                        OpenFlow actions=resubmit(,10),resubmit(,4)
* T. _6 U/ w8 W$ v/ m4 j
) _: V+ T; y9 X* d. {                                Resubmitted flow: unchanged * q) o/ n, y  G  }
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
; d6 }; C+ c/ i) t, ~+ y0 y5 z: X                                Resubmitted  odp: drop
5 C5 r8 s2 |) j                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=10:00:00:00:00:01
4 n* g+ _% J3 K                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15], F# R; R$ J: \0 e
7 {% L3 O4 q  e& p1 _+ |4 [! b) p
                                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 * F; }( ?" Q: f% Z! h
                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 2 ?! O4 H; ~0 j9 X1 B7 s( j: D# I
                                Resubmitted  odp: drop 4 g8 H" ?& ^7 i# D" x
                                Rule: table=4 cookie=0 reg0=0x1
& n) H- }' }) r" a" ^3 m& R0 ]                                OpenFlow actions=output:1
. S- T$ y% h5 @& q$ I3 D  A
1 E+ [( i7 [6 s( t0 O) YFinal flow: unchanged : c, @6 r- S5 c" L/ H
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
& a6 ~+ F' n5 k& r- S6 W  V6 C$ FDatapath actions: push_vlan(vid=30,pcp=0),10. x1 Q3 X0 i* g/ p0 l) r/ m' C( ]8 b
+ E1 b2 N6 k, m8 G
回复的时候,由于学习过了,则仅仅从port 1发送出去。( m, Q! X! b  _; [  `( J
, ^7 i! v& e0 L- [5 |/ F, e. Y, D% g
$ 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
8 w7 L" J- k( F* ~- b: hFlow: 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 i4 A/ ^& }& iRule: table=0 cookie=0 priority=0
) o: a3 _' |$ n# d6 i6 w3 ]OpenFlow actions=resubmit(,1)
- r& C. p- p3 D7 P1 s7 h5 T$ P5 x; `0 Y
        Resubmitted flow: unchanged 8 e/ ]; t: V$ U/ `
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 - {& d$ h/ q, Z3 e- Y. |: C
        Resubmitted  odp: drop   F. L* q- t+ k# ^9 a
        Rule: table=1 cookie=0 priority=99,in_port=1 + E" b7 D+ H7 J
        OpenFlow actions=resubmit(,2)0 j) R+ S+ d' ]6 [, n2 Z4 c9 h1 H* X, o" ^

2 x! \: V9 D# \/ x" [                Resubmitted flow: unchanged
" ?7 W4 h7 U1 G! D# Q( Y7 d1 ^                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
3 |& y$ F2 k( _( x- Q: V& h4 L/ q                Resubmitted  odp: drop
9 o" W3 m, H+ n% L                Rule: table=2 cookie=0
* X4 j, u4 G0 s. R* Z8 n' S0 ?6 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)
% H' w& ]! \) c2 x4 P3 g% Z
5 x0 w* Z' y+ B0 E# x4 V, z* w5 w                        Resubmitted flow: unchanged
8 N# Y! y% ~0 t0 Q8 h                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ) L# X2 Z! ]' T" C8 f4 M: K1 X
                        Resubmitted  odp: drop
% u" J4 {, t& `# R                        Rule: table=3 cookie=0 priority=50
" ^$ t2 |: w! t( ~9 e                        OpenFlow actions=resubmit(,10),resubmit(,4)7 m9 `9 Q. o/ v, n& N* Q$ d, D

6 o/ X; T# n" k! {. ]                                Resubmitted flow: unchanged 8 J; A/ r. t( n5 ?/ V" _) e
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 4 O6 O9 T! B' N
                                Resubmitted  odp: drop
4 a/ u/ R, L6 W& c) z4 p                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=20:00:00:00:00:01 ! {- P; ~' |2 }
                                OpenFlow actions=load:0x4->NXM_NX_REG0[0..15]
, [  N) U+ ?' C' E# d0 G( S. f5 o; j3 z! |$ }( u9 u& M$ x
                                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
/ U2 C' w+ K. m- W/ W3 G( N8 c                                Resubmitted regs: reg0=0x4 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ) L+ P+ \7 Z% A- m) v6 E
                                Resubmitted  odp: drop % {7 g. v! v# B3 y
                                Rule: table=4 cookie=0 reg0=0x4 * X1 h5 B, N- x8 \: B& w
                                OpenFlow actions=strip_vlan,output:4
% U5 j* E8 I0 B3 j4 n) v( k: |( z
/ U6 B: D: l% h3 UFinal 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
- `' t9 s2 {( r+ Z: N5 T! JRelevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000,nw_frag=no
" Q8 M4 k$ f, |Datapath actions: pop_vlan,13# S' ?) V" }+ s, E
- V7 x9 H+ B" X' Y% c7 q5 j
由于在回复中进行了学习,因而发送的时候,仅仅发送port 4
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

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

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

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )点击这里给我发消息

GMT+8, 2026-4-8 21:41 , Processed in 0.063376 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

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