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

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

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2019-10-25 10:00:33 | 显示全部楼层 |阅读模式
ovs-ofctl dump-ports 输出交换机的端口统计信息,包括收发包、丢包、错误包等数量。 ovs-ofctl dump-flows alubr0  2 |3 T; O; a' C7 }* J. I3 D4 c) Y
OFPST_FLOW reply (xid=0x2): flags=[more]
2 ^# [% r; h! j0 S4 W8 w 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[
6 }8 n2 ^8 ?0 Z3 F3 {" S/ m& a: c0..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[],re5 _/ Z# G/ t$ P9 t
submit(,4)9 d4 ?, q% E0 ]8 [# s$ C, W
cookie=0x1, duration=1263.439s, table=4, n_packets=36175, n_bytes=26587191, priority=0 actions=resubmit(,27)- E& S4 S6 W- v& X- k( z# S, d
cookie=0x1, duration=1263.439s, table=5, n_packets=35646, n_bytes=26564073, priority=0 actions=resubmit(,7): ]6 H) A2 P" d! i3 n' ~: @
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
6 F3 ?* i/ B5 w 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! m1 M) |4 C% C5 v$ A6 L
cookie=0x1, duration=1190.175s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=291,dl_src=fa:16:3e:b2:1c:91 actions=drop
& D9 I/ f* t# J1 h 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
( i* i/ C1 T  t3 c5 F/ \s=drop
1 F( G4 _  q, u/ t. m# L# Y4 ^2 w 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
, q# ]/ R0 e& F5 B) ~" [  I cookie=0x1, duration=1197.461s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=29064,dl_src=fa:16:3e:82:2c:2c actions=drop
4 Z9 A$ ^2 W- Z 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
0 U" v. H! N; J" K- U cookie=0x1, duration=1195.700s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=422,dl_src=fa:16:3e:c9:6d:72 actions=drop& [7 ~% X5 A5 r& A9 a
cookie=0x1, duration=1198.286s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=19360,dl_src=fa:16:3e:95:46:90 actions=drop
  P; E) b' b! X- B& W% O 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=7 ]9 P9 ?0 O2 A& P2 a6 L
drop
2 ~& J' U8 U2 d( d( O 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
' a3 y; @2 c1 t1 l 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
2 f* ~8 h) n: ]1 zop7 N; n5 F% ^  i- g3 H# S) K
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& L% M, q: v6 A, g2 S. C* B8 A+ m
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
* F( l. k" i! F* j" o( w 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
, a$ @8 z0 a" e 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=
2 g3 M- @8 |; y( idrop
' T  j4 C/ ]( S9 P cookie=0x1, duration=1191.564s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=185,dl_src=fa:16:3e:55:06:7c actions=drop  r, y0 c8 q- d6 n0 ]+ F
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 action6 T4 }6 u1 L$ g  G" f
s=drop7 g- K8 F" u: H( J% f7 ~
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
8 Q# v; l) s+ t' lp0 j0 |& G( W5 l& M8 s4 \1 }0 L9 w4 a
cookie=0x1, duration=1254.538s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=799,dl_src=fa:16:3e:da:fe:ec actions=drop# q: T4 b! n: ^# Y1 o4 X
# q5 f+ g5 F& t4 z! a" n% ~4 l0 z

5 }$ X8 |" B2 p如果设为fail-secure mode,则初始情况下flow table是空的,否则会有normal$ sudo ovs-vsctl add-br helloworld1
6 _# `! V' A! k% c6 b1 a$ sudo ovs-ofctl show helloworld1
& z. j4 S" O( A$ sudo ovs-ofctl dump-flows helloworld1
" u* \7 J& y6 {1 [7 t% O& b& oNXST_FLOW reply (xid=0x4):
0 x) b/ J" }) n6 d  ~, tcookie=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
" e; e& Y- c; Q) m& p0 ksudo ip link add second_br type veth peer name second_if   
1 {! `: L0 D. T  qsudo ip link add third_br type veth peer name third_if      
5 t3 V) u; a9 ]% o# C" msudo 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 3 f% e0 G* Q$ d
sudo ovs-vsctl add-port helloworld second_br -- set Interface second_br ofport_request=2
% T9 B5 F. F. |( U. O- F- h, Vsudo ovs-vsctl add-port helloworld third_br -- set Interface third_br ofport_request=3
0 f, x+ d3 ~& x4 \$ {9 xsudo ovs-vsctl add-port helloworld forth_br -- set Interface forth_br ofport_request=4ofport_request是指定端口号新添加的port都是出于DOWN的状态* b6 g9 g  E. D

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2019-10-25 10:00:34 | 显示全部楼层
把它们设为UP$ C5 R: q$ Z8 P5 N& @# ?; s
- c+ {5 K* R- }7 U7 e
sudo ip link set first_if up
5 j  `+ I3 ?$ m% _9 k0 G! Y; ~+ ^sudo ip link set first_br up 7 }5 s0 u3 f: Q% a/ X+ h' m) b; B
sudo ip link set second_br up     
, v" l* x3 `; n5 c2 Wsudo ip link set second_if up 9 F6 M7 K4 ?" |
sudo ip link set third_if up      - y7 H& v6 ^% R6 Q0 J: }
sudo ip link set third_br up     , e- b/ O+ S  U  P
sudo ip link set forth_br up         3 ^: f+ h# E$ z% M) N
sudo ip link set forth_if up
+ ]+ Z( x9 q7 X& D* C; K% ?6 o  n$ O2 w# {& {7 }1 l5 U
也可以用下面的命令7 H- H3 W4 b7 r/ b" B5 L% U

# G7 S, @9 u6 C8 T3 r+ M6 wovs-ofctl mod-port helloworld first_br up

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2019-10-25 10:00:35 | 显示全部楼层
实现第一个Table 0,Admission control
. \+ b. S$ {& F6 I% X* {$ j# E9 E$ U" S2 u0 \1 C' |
包进入vswitch的时候首先进入Table 0,我们在这里可以设定规则,控制那些包可以进入,那些包不可以进入。& n2 ^$ @! H, m) f+ v

, e/ A2 a& d5 ]- i: Z比如,如果source address是multicast的就不允许进入。
# V4 Q7 Y% Q4 `1 a& Q( d$ Q/ m0 g$ O& d
01:00:00:00:00:00/01:00:00:00:00:00是广播地址
: d" Z9 s4 {0 \; g! \) v4 Q00:00:00:00:00:00/01:00:00:00:00:00是单播地址8 C# c( @  U4 t% t% H9 ~
这种表示形式类似CIDR# i$ O6 n5 S1 z) \' [
于是我们添加下面的规则:
* ~2 ~/ _5 D( p8 ]+ Y, B. [. usudo ovs-ofctl add-flow helloworld "table=0, dl_src=01:00:00:00:00:00/01:00:00:00:00:00, actions=drop"
% t. l, L3 T1 e' m3 }STP的也不接受5 ~) l% f- J) U/ L
sudo ovs-ofctl add-flow helloworld "table=0, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0, actions=drop"
! o+ L4 E7 \, M. U我们在添加最后一个flow,这个flow的priority低于default,如果上面两个不匹配,则我们进入table 1
8 Q! Q1 u* J4 S1 O3 S$ A/ P, vsudo ovs-ofctl add-flow helloworld "table=0, priority=0, actions=resubmit(,1)"
0 n$ K. e7 k2 S% ?我们查看一下所有的flow
7 {+ U$ h6 O" A* [' Z) u- [$ sudo ovs-ofctl dump-flows helloworld        & f- g" D" r9 Q
NXST_FLOW reply (xid=0x4):
1 O; ?: K3 @6 k4 ^" bcookie=0x0, duration=42.162s, table=0, n_packets=0, n_bytes=0, idle_age=42, priority=0 actions=resubmit(,1)
+ S4 Y- Z( i, i3 Z  ?9 c' R! |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 & l* b, w: ?$ G5 k. J0 i, P. I6 c
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
, o" k& l4 o2 C! J/ o; V$ B: S' c5 x2 @; M) J. O
测试Table 0
& v: v7 j% U6 g  u* h+ a% Q" e- B. u* s6 H6 ~
有个很好的工具ovs-appctl ofproto/trace4 o# [9 h3 }8 A, B

) [1 l6 X2 y' f+ Y  w不满足条件DROP$ \- B6 K5 g1 H8 a/ I1 h

1 c9 C1 V: e; u9 s% c' G$ F! P$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:05
# h0 i9 `: b" N: a, x, }/ bFlow: 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
+ T' z! S. Q5 z; }* i" CRule: table=0 cookie=0 dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0
& j% x7 \. y( i( N% |  m8 EOpenFlow actions=drop
( p/ ]4 D6 S" O$ }! H5 y. B& G" ]' c0 T0 @' I, n8 W8 m5 X) r7 [' t
Final flow: unchanged 9 T/ H/ K7 t$ ?4 c% G, c% J8 B* x
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
. H9 J+ w: k# A# n2 n* L* P+ PDatapath actions: drop
" q/ _# c4 U# w5 A
( t6 u6 |, Q4 A; o# t满足条件RESUBMIT  ]0 X- G0 g- d2 O( v4 F8 }! d. h
/ ]3 n8 C5 X0 d" W( [
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:10
! N+ ]6 A9 v* g: ~  i0 H: D$ K# KFlow: 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
7 w+ ^6 I2 a6 W+ ?. C) P- A! u) SRule: table=0 cookie=0 priority=0 3 G) Y" K. O6 G5 {7 O& M8 x2 E
OpenFlow actions=resubmit(,1)1 a3 @, c3 s+ g
5 ]: g; W/ ]! [/ Q* C' d/ v% Y
        Resubmitted flow: unchanged # K% b  n, X, \0 J- q+ D
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 1 E5 {! R7 g4 ?- P# `/ G) V# n+ G3 F
        Resubmitted  odp: drop
6 O( O9 L% M5 |4 s        No match2 u2 B5 N7 x, y7 f( D7 }
  C' {, o* |3 w/ I, w
Final flow: unchanged
  V, O5 \8 w9 j2 O# iRelevant 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 , K' {: }5 _- ]1 T
Datapath actions: drop
/ e0 M2 ]& B" @
" i! U1 z7 A4 f: g3 G实现第二个Table 1:VLAN Input Processing: E2 }) W$ I2 P0 X
+ j; n. V/ R+ X* Y5 N" V
首先添加一个最低优先级的DROP的规则" j2 D3 Z4 L( X% w* q

4 s/ b3 z+ }7 D/ D- M% U( Csudo ovs-ofctl add-flow helloworld "table=1, priority=0, actions=drop"
* m! `) y5 u# _2 r
5 d$ _* [6 s/ q对于port 1,是trunk口,无论有没有VLAN Header都接受。
# ], N! K8 y, b9 T6 z; x' H2 n
( `0 S/ C1 U3 v* x) _+ p) k# _sudo ovs-ofctl add-flow helloworld "table=1, priority=99, in_port=1, actions=resubmit(,2)"0 q! w7 B/ q$ x$ J
, s- G  B2 L" i
对于port 2, 3, 4, 我们希望没有VLAN Tag,然后我们给打上VLAN Tag' L# N/ I' ]: f2 Y3 A1 C
! B7 r6 |" {% \* R) f
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'
. u) d# h8 y  w- Dtable=1, priority=99, in_port=2, vlan_tci=0, actions=mod_vlan_vid:20, resubmit(,2)
  p0 q: M* g, ]7 j& Z/ utable=1, priority=99, in_port=3, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2)
5 @# k+ N0 h' k6 A+ a! |; jtable=1, priority=99, in_port=4, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2) 1 A* n, B8 V. w& W; h2 g
EOF
" z" U% A2 M  Z  Q
! A8 j7 l1 i! b5 q; O4 x$ sudo ovs-ofctl dump-flows helloworld
+ G$ v7 W5 |5 `% INXST_FLOW reply (xid=0x4): % ]9 w( C* w+ s. t0 [  [
cookie=0x0, duration=4478.582s, table=0, n_packets=0, n_bytes=0, idle_age=4478, priority=0 actions=resubmit(,1) 9 f5 Y3 @( Y7 i( w) _! {( d
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
( f- h7 [# t8 s4 Lcookie=0x0, duration=4604.056s, table=0, n_packets=0, n_bytes=0, idle_age=4604, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop 0 X# R# T- b4 i8 G3 S7 c
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 f) e1 W' W3 f9 i7 w2 k5 {5 R8 T
cookie=0x0, duration=89.273s, table=1, n_packets=0, n_bytes=0, idle_age=89, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
; h. w( q" ~2 C6 s8 O5 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) & a3 _% R" @( e  ?0 X
cookie=0x0, duration=220.318s, table=1, n_packets=0, n_bytes=0, idle_age=220, priority=99,in_port=1 actions=resubmit(,2)
- y2 u5 L( d7 D/ [; M( \; |4 Y: [cookie=0x0, duration=298.739s, table=1, n_packets=0, n_bytes=0, idle_age=298, priority=0 actions=drop
! o  ]! ]5 R/ ?
; [# W( d0 Y% |, {* i( C测试一个从port 1进入,tag为5的
4 T6 R; F: X9 g+ W' B+ Z6 G: X+ n) Y' a2 B' A2 _
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=5
7 r% L6 ]5 V% xFlow: metadata=0,in_port=1,vlan_tci=0x0005,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000
. \; |& ?9 n. p  g3 dRule: table=0 cookie=0 priority=0 , c7 u, U( S) o( r" H6 s
OpenFlow actions=resubmit(,1)
) O7 P0 \* |  {- b' e
/ l) J7 \% ]5 S1 U        Resubmitted flow: unchanged ! N0 o- G; s! @1 ?. N
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
* N1 j3 Q5 _: U) [2 B% `( J        Resubmitted  odp: drop
9 i+ o4 `5 K* u" h' g5 o6 h3 i        Rule: table=1 cookie=0 priority=99,in_port=1
- @8 m2 V2 {' n: }        OpenFlow actions=resubmit(,2)
5 q9 {0 p. P9 ?
  B7 @& C4 _0 j3 h+ d1 |* |/ y8 q                Resubmitted flow: unchanged 4 n' h# J7 c8 d
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 " t  Z: N  i4 G( h
                Resubmitted  odp: drop
) h! E4 c5 M5 G8 y* ^                No match7 C3 _6 V1 }( }- Z# d

: k0 A. ]/ W, v. x. a& tFinal flow: unchanged
! `% O' F) U# ?: h: u- bRelevant 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
4 {& X8 E( [! G8 Q. M% VDatapath actions: drop
' b) b% [. C0 I- z& ^" N) R" w. Y6 A3 q% W  D7 F$ g- X, E5 G
测试二,从port 2进入,没有打Tag的
6 a' P6 Z3 `( u. l; @6 Z/ o) U2 r+ ?' b- j. j/ U3 `
$ sudo ovs-appctl ofproto/trace helloworld in_port=2 9 Z3 d( C4 }: J& h* ^: \0 X
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 ; \! Q( c3 H% V7 t. c
Rule: table=0 cookie=0 priority=0
( [& C1 a. q1 M' M& @OpenFlow actions=resubmit(,1)) Z' q3 E6 U# H# |, N$ S1 K
: q  K; S' V, {0 U' G4 S7 N; V6 F
        Resubmitted flow: unchanged
- w' L4 C0 ^% y) m- x        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
: e$ w3 ^7 i1 L) j$ v4 L+ W        Resubmitted  odp: drop
/ H" ^: V9 ~2 J: ~        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 ' ?- v5 }% |' _4 t4 b/ {
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
4 E- V, |( f7 h* o, Z2 @8 j
, x, w" [  f! }+ A" n4 s5 m( {8 ^                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
; d7 C4 h; s0 f; C/ I, L- f: t! E( L; _                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
4 c- [/ `: P. U5 b                Resubmitted  odp: drop 9 o( W/ w, o. Z
                No match% u8 @7 A' F9 w6 M2 O) a; B% i

% Q, t5 u2 R. G1 WFinal flow: unchanged
5 j; U' {: k  aRelevant 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
* K* f$ o# c, zDatapath actions: drop0 Y6 f; L7 E" b: C4 s  K0 k* D

$ @1 M; [% k8 M0 G/ b! r测试三:从port进入,带Tag 5的
9 g$ r1 h9 U3 B, {- c4 w! X/ w6 n$ |7 O. o/ Q9 ?" m: U
$ sudo ovs-appctl ofproto/trace helloworld in_port=2,vlan_tci=5 9 q0 a$ s2 g4 t. ^
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 - b# r+ ?0 r/ r$ M- W$ |9 a
Rule: table=0 cookie=0 priority=0 5 Z( I" Q1 F. c9 G, \) J
OpenFlow actions=resubmit(,1)
+ B! s8 c. h8 O- `  s; @8 e) J* @& G; l2 P# m( b6 b9 s' A( U# I
        Resubmitted flow: unchanged
7 Y; O, T4 e) ?. D3 y2 Q0 Y        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 : `* ?6 \4 J5 f
        Resubmitted  odp: drop
9 S6 X, W) I% [5 V. F        Rule: table=1 cookie=0 priority=0
* a( C; s  y$ H$ u. j' a' V        OpenFlow actions=drop. V* U  y0 l  T% ^8 `6 d% X
/ P1 U9 e; _. C8 q; O% Y- `' B
Final flow: unchanged
7 a: I% R4 d0 g0 ~# C+ K. uRelevant 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
/ Q- x. U/ n( v9 K  B, Y1 E' CDatapath actions: drop; G) m: j2 \4 ~4 R: K' z& B" M* o

' @* P! m( ~, I( {! o( q3 D4 h实现第三个Table 2: MAC, VLAN learning for ingress port
+ X! c+ q  a) V
+ u) p- H) }8 j4 R4 Q+ _' l对于普通的switch,都会有这个学习的过程,当一个包到来的时候,由于包里面有MAC,VLAN Tag,以及从哪个口进来的这个信息。于是switch学习后,维护了一个表格port –> MAC –> VLAN Tag。7 x$ F, r  s) j+ l5 O& S

% J: S0 `6 s! Z) k& b6 _0 {; E这样以后如果有需要发给这个MAC的包,不用ARP,switch自然之道应该发给哪个port,应该打什么VLAN Tag。, k/ h" J) D  S  n0 }/ e
! q* e7 k) U" ?" t$ F
OVS也要学习这个,并维护三个之间的mapping关系。
' n, e7 p8 H: x% z; ]) u# Z* f; G, S# H7 E+ {$ m1 ]: s
在我们的例子中,无论是从port进来的本身就带Tag的,还是从port 2, 3, 4进来的后来被打上Tag的,都需要学习。
; t/ \1 V' c/ j' m! r; n3 n: l
" C: r7 Y; V# P# J! C+ Dsudo 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)"
* E, h" l# h% Z: w7 U7 J. H: {! Z+ b, s
4 x* [* C4 ~. S9 {  M, M这一句比较难理解。) q/ e" v* A, t$ ~

- r( E$ J0 |! t0 Dlearn表示这是一个学习的action% w' Y. R4 ]0 v% J, y: Q( L
: Z# U- n4 A+ Y/ g
table 10,这是一个MAC learning table,学习的结果会放在这个table中。# B1 `- z6 S, v2 [/ V: x* y1 a

1 V2 q2 A6 b: v8 dNXM_OF_VLAN_TCI这个是VLAN Tag,在MAC Learning table中,每一个entry都是仅仅对某一个VLAN来说的,不同VLAN的learning table是分开的。在学习的结果的entry中,会标出这个entry是对于哪个VLAN的。
1 m; l; R) ^5 D+ @7 @! c  o+ @3 H6 C1 a7 [0 T; X- k
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里面,因为这是为发送用的。
1 F, v; V& @, U/ b  `/ z2 ?6 Q, L0 E& e% z
NXM_OF_IN_PORT[]->NXM_NX_REG0将portf放入register.
4 q! w( J: V& l) L3 r# v3 F) E. |3 L( N
一般对于学习的entry还需要有hard_timeout,这是的每个学习结果都会expire,需要重新学习。% T9 u; L: `/ W& J  d
5 Z' p0 \* f4 y2 N
我们再来分析一个实践中,openstack中使用openvswitch的情况,这是br-tun上的规则。9 B4 w7 O. k2 U. l/ k7 H

4 x$ M# [9 I. E4 F9 T  Z* k7 g0 H4 kcookie=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
# @* {+ ?" K6 P1 ycookie=0x0, duration=802187.786s, table=20, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,21) % \7 g" V' F+ M5 B" J5 I2 H
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
; c1 g) p. _& ~3 Y  A7 b4 vcookie=0x0, duration=802187.653s, table=21, n_packets=17, n_bytes=1426, idle_age=65534, hard_age=65534, priority=0 actions=drop 7 e6 |) |; v2 O' M& [* a1 P
cookie=0x0, duration=802055.878s, table=21, n_packets=40, n_bytes=1736, idle_age=65534, hard_age=65534, dl_vlan=1 actions=strip_vlan,set_tunnel:0x3e9,output:2
/ [4 L. U' U9 U7 P
# p9 E. M" `6 k; K这里table 10是用来学习的。table 20是learning table。如果table 20是空的,也即还没有学到什么,则会通过priority=0的规则resubmit到table 21.
1 e* d& Q& X3 h1 Q& e0 U( J" m3 P; S4 K# p
table 21是发送规则,将br-int上的vlan tag消除,然后打上gre tunnel的id。, C8 e6 T1 x/ y# D0 W  B9 `, q
7 |8 |& g6 H8 p- U$ A
上面的情况中,table 20不是空的,也即发送给dl_dst=fa:16:3e:7e:ab:cc的包不用走默认规则,直接通过table 20就发送出去了。7 J* p+ y& p; M: z; ~: [1 ?
; a; U" o, ?6 m) H6 d
table 20的规则是通过table 10学习得到的,table 10是一个接受规则。最终output 1,发送给了br-int
0 e1 A% |1 H/ ?) W+ M
7 R4 J3 T! O; Y. z' s7 u6 ]NXM_OF_VLAN_TCI[0..11]是记录vlan tag,所以学习结果中有dl_vlan=1# Y. M3 D- A  Y( F1 t2 v9 |
( H( q9 N3 }' p4 o8 w+ f' B1 h
NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]是将mac source address记录,所以结果中有dl_dst=fa:16:3e:7e:ab:cc6 @' i6 [& G- b& J* m$ m
( q  `( u# \" c" H% E1 H. M* u
load:0->NXM_OF_VLAN_TCI[]意思是发送出去的时候,vlan tag设为0,所以结果中有actions=strip_vlan, a- x$ \' Y3 O! W1 S

9 y5 \! [# G& Mload:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[]意思是发出去的时候,设置tunnul id,所以结果中有set_tunnel:0x3e9
7 D& H) H, q' a& d+ t, S- v- G$ {+ F5 H/ k) |* V
output:NXM_OF_IN_PORT[]意思是发送给哪个port,由于是从port2进来的,因而结果中有output:2
7 N6 Z4 P# O4 U: F- X
& _4 p# i6 Z$ G- z测试一:从port 1来一个vlan为20的mac为50:00:00:00:00:01的包: j/ r: j0 c' j* {* }$ H# r
# t( T8 e. x+ w) u! S& W, c  D
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=20,dl_src=50:00:00:00:00:01 -generate   3 }3 c  y7 I3 w, [) ^: R
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 7 H9 H3 m/ U; I# a' \! y( i
Rule: table=0 cookie=0 priority=0 8 ^; b0 o  f4 C5 U! Q; Q; b9 d
OpenFlow actions=resubmit(,1)2 L' s# P. w. m& L

+ ^( Q! V' E) ~9 ]8 }        Resubmitted flow: unchanged , l: @( Z0 X  n1 r6 e6 {
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 1 C1 L- ?5 N9 X5 H7 K0 z2 {- _6 h! n
        Resubmitted  odp: drop
) M  L4 B5 t6 L7 n4 F$ {2 X7 G, l        Rule: table=1 cookie=0 priority=99,in_port=1 5 l% s( K: T" P
        OpenFlow actions=resubmit(,2); n4 S# n; c; w; w, k' Q0 p  F
+ R6 e+ M  k2 N# Y1 q
                Resubmitted flow: unchanged + L5 k- U2 `% f
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
9 p: c7 a! Q# q* j                Resubmitted  odp: drop
# |9 ?2 b9 @' J7 a                Rule: table=2 cookie=0
2 _% ?/ p8 _& d5 N9 S  g% Q" 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). k1 ~1 t4 ^2 r0 N+ O" Q: g
8 X6 }& E, i2 l. j
                        Resubmitted flow: unchanged
6 J8 G: Y0 K/ n' l1 l3 D# U                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 - B$ Q. z# V! D; x3 g
                        Resubmitted  odp: drop # X- k  C% F; s" E- }9 y
                        No match
: D# Y8 T' c: u. h2 \' [4 L4 K, a. f. e1 r3 C" N
Final flow: unchanged + }2 s0 I4 ]8 O, c
Relevant fields: skb_priority=0,in_port=1,vlan_tci=0x0014/0x0fff,dl_src=50:00:00:00:00:01,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no - A9 S- H6 {2 v5 V) c& ^( U
Datapath actions: drop
) x! K+ m2 L+ T! l" Q2 {8 O  o2 z' q: B+ i5 _
$ sudo ovs-ofctl dump-flows helloworld
. c6 F/ ^' r& F! R1 yNXST_FLOW reply (xid=0x4): - `* M9 \6 j0 ^# G% S! n0 Z$ G
cookie=0x0, duration=90537.25s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) 5 b- E) |& a) ?8 e7 L
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 + i4 ?3 t7 g0 I4 D
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 : _. c* j: P2 t5 t8 Z: 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)
6 \) `# M- P' B$ ]% }cookie=0x0, duration=86147.941s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
; T4 d, G) V" z2 U. [+ ^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) 1 Q* g# I4 h, _$ B# ?
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)
# R3 Q5 Q1 b+ b9 v8 I5 `# ?cookie=0x0, duration=86357.407s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
6 |  L" S* \+ s. I1 r" N- ?cookie=0x0, duration=83587.281s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3) # H+ e  z1 s: D9 A9 Z$ C
cookie=0x0, duration=31.258s, table=10, n_packets=0, n_bytes=0, idle_age=31, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]
5 f8 f) T0 O0 `$ ?' g5 Q* R& H8 o. _
table 10多了一条,vlan为20,dl_dst为50:00:00:00:00:01,发送的时候从port 1出去。
/ m8 k* V6 @; J$ b, N
5 Z) n& b5 Z! u: n2 U测试二:从port 2进来,被打上了vlan 20,mac为50:00:00:00:00:02
3 P3 K" B3 X6 D$ [$ d! @6 K9 k( y7 Y' {% j( x
$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=50:00:00:00:00:02 -generate   , X9 ?! j1 s! }. }2 ]' U: S  j
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 & [. w# g; l8 l2 g  h6 \( N
Rule: table=0 cookie=0 priority=0
9 F+ j4 l) j- u- n4 V9 VOpenFlow actions=resubmit(,1)5 ~' H) }! x$ |* t( ]! B% X

$ W# O  @3 N! V& K8 J' B) T. ]        Resubmitted flow: unchanged
4 o' `. y+ T, s7 K9 @1 e- V        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 / ~5 M% y7 m9 ~5 R, [2 m
        Resubmitted  odp: drop
6 h# X5 h. ^/ f        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
$ B) N' t% S' H+ K  d, F" P        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
. y$ C$ {+ {0 ]2 c1 V! \  m% V; N9 Z( S4 _# t
                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
  D5 I+ s0 a" }. M3 l                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 , E+ N3 U8 {) n, n( E
                Resubmitted  odp: drop
+ y0 @) t1 i2 h( J0 F                Rule: table=2 cookie=0 : j5 j" E& H6 L+ b
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
2 _3 u0 W- Y/ `0 |/ m: ?( r, t2 l9 I' z7 p; f
                        Resubmitted flow: unchanged ' [; H2 _1 O$ Y( A% U# C, Z' q# o4 t
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 1 }9 N, p  u) j: W% P# j- i
                        Resubmitted  odp: drop
5 a6 ^( Z3 q! y- v                        No match
9 j- H6 W2 l( g: e7 a5 y$ [
% r1 c/ `3 L2 o8 C( l6 n+ EFinal flow: unchanged
: j8 L" R& h3 w! wRelevant 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 # L/ Q9 |/ b% g( S3 Y4 s
Datapath actions: drop/ [+ Q, r  s# g8 Z  C, b, g

" i* }) ]' F: ^7 L9 o$ sudo ovs-ofctl dump-flows helloworld                                                 2 [2 I$ b! [" q/ ^
NXST_FLOW reply (xid=0x4): : Y1 F% O9 Y) @0 T' E/ f* H
cookie=0x0, duration=90823.14s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
+ s' W! J; K$ i7 jcookie=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 1 @! p& h! a2 w9 A" {
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 # I2 i( |: F, M8 E+ w
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)
0 e7 L% I4 [: a" e7 y5 kcookie=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) ; ?. ^! ?. q9 j! j4 ?* _
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)
- F! _8 Z* ^" ?& p/ G" @+ `cookie=0x0, duration=86564.876s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2) 2 [. M: g8 s" n6 F8 k
cookie=0x0, duration=86643.297s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop % {# k4 @. k+ [; [' a1 ~
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) 4 r( B3 w( U, w3 S
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] 0 ^* g" D; ^# Y
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]$ L& U0 l( r) a9 z. Z. _# `' W

, U3 c2 D8 c. `  a/ N实现第四个table 3: Look Up Destination Port
7 b, t6 d# Y" y" V8 I
5 Y7 c# z( f( Q2 r+ y- z$ P: M4 @' I在table 2中,vswtich通过进入的包,学习了vlanid –> mac –> port的映射后,对于要发送的包,可以根据学习到的table 10里面的内容,根据destination mac和vlan,来找到相应的port发送出去,而不用每次都flood$ o$ d, W6 |9 H, J/ t2 p# v
" [7 m( p6 M% ?# z6 e
sudo ovs-ofctl add-flow helloworld "table=3 priority=50 actions=resubmit(,10), resubmit(,4)"5 n6 K! Y" A% ]7 D4 I
8 M% I6 ^$ I0 X, F( D4 r7 k4 t' h
添加这条规则,首先到table 10中查找learn table entry,如果找不到则到table 4
9 q9 ~* \% n1 N2 A  _
3 g- d6 }' g7 G如果包本身就是multicast的或者broadcast的,则不用去table 10里面取查找。
# i: o! |2 K0 V' b; N( K0 {) a
' n( J: ^, {5 Bsudo 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)"
2 [0 g4 d3 l9 i0 T- u" x! d- V1 r- k0 ?! ^0 b
我们进行一项测试+ k; J, h7 [3 h8 w+ t; G! a: b9 b) E

7 K9 p, q7 X, ?$ @$ 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 h7 l' y8 e1 R- X/ |
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 5 ?4 [) ~& l* z$ c3 Z" z4 e- _
Rule: table=0 cookie=0 priority=0
$ U( \; g% x# y1 H" dOpenFlow actions=resubmit(,1)4 j( n+ c. f% R2 u' S9 ~" t( m

" M2 m+ a4 G) G9 h) P$ e& ?, G8 I        Resubmitted flow: unchanged
& o0 C) x  b; k9 @/ P        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
9 E& \6 T7 c6 V" i7 V0 l) J        Resubmitted  odp: drop 6 m" D5 d& T! r! f, b
        Rule: table=1 cookie=0 priority=99,in_port=1
/ Q2 [' x! {: n$ ?! F7 c5 V& S" m0 @7 _        OpenFlow actions=resubmit(,2)
0 @  p$ G" {# t* I5 c
# B9 [: t( U: m/ a                Resubmitted flow: unchanged : v1 d9 [  [2 `, M+ z, _- E7 {
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
4 M! P% \! M6 m) q7 h/ f1 G, B                Resubmitted  odp: drop 9 {, q8 n. M! ]. f$ V
                Rule: table=2 cookie=0 ! n2 V: O- C; u4 r$ j6 O  G; F* n" 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)4 x$ K: S  ?# a8 q& p  C- r: c
  h: n9 X" x2 F# z1 h; N
                        Resubmitted flow: unchanged 3 Z) X3 U! z$ O
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 7 M* o" _* ~9 i6 o! d$ f" Q
                        Resubmitted  odp: drop
: @( J! f; ?5 Q3 H9 H& q. u" o                        Rule: table=3 cookie=0 priority=50 ( p/ G8 A0 _- H$ A! f
                        OpenFlow actions=resubmit(,10),resubmit(,4)
* u( _9 q, j* G" v6 l5 y8 P, W8 ?$ d+ E9 q; @4 i) d
                                Resubmitted flow: unchanged 4 d; _2 ^9 Q+ v1 D: z, z. h( s
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
! L4 B# q4 w' N  M# F, n                                Resubmitted  odp: drop / x  P" V2 \$ G
                                No match0 o5 Q- |4 ~/ k' ^  q+ V

' \. Y, m: Z+ S$ y                                Resubmitted flow: unchanged
/ r# K) l* D. i8 y8 z" g                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 # t  E" V( J* p+ Q( c& g
                                Resubmitted  odp: drop
. I$ G* Y5 ~; s7 \' g1 G5 ^$ q                                No match
+ W' B$ m5 r- R6 v! V! R  s4 l: G: I2 M4 B9 o6 A
Final flow: unchanged 2 \0 ~. w/ P* w" E
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
1 F, q6 M9 m: P2 F- [Datapath actions: drop; q/ t3 I, k! K# U/ {+ M4 v
$ M7 T  |, g0 u+ L
由于目标地址f0:00:00:00:00:01没有在table 10中找到,因而到达table 4.  a' q* y. C% N3 Y+ @

. k  R) H0 A: m3 ~; d8 i5 c! c0 ?. m但是这次测试使得table 10中学习到了mac地址90:00:00:00:00:01. k9 R, g4 F% I5 i1 N7 T4 a$ u
4 O. k4 u9 H0 c! J# C: c% n& N
$ sudo ovs-ofctl dump-flows helloworld ( E" S. h: U+ B3 \( o) F# y
NXST_FLOW reply (xid=0x4): ; o1 `0 Z7 T* C
cookie=0x0, duration=91588.452s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
  \. j+ M9 q- W( K; dcookie=0x0, duration=91778.411s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop
2 G1 O$ d9 n4 Q, ?7 I. Ocookie=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 8 F. t" e. q) ~* S0 G" k( e8 R
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) / r; x' N/ p) w0 o* J& x/ d
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)
- o  C6 e3 x( q9 S0 ?4 }) ccookie=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) . s. {* O  j5 D8 \% S# y. e+ i
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 V! F3 b! J3 n8 s4 {  }; e( F- `cookie=0x0, duration=87408.609s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
/ ~2 x% p" a  ^* Ycookie=0x0, duration=84638.483s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
1 p0 n4 n2 R& p! \% @# p5 N1 ]; c' ocookie=0x0, duration=352.841s, table=3, n_packets=0, n_bytes=0, idle_age=352, priority=50 actions=resubmit(,10),resubmit(,4)
( z5 c. |, O. m9 Kcookie=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 p) D% S& u, l3 R( ^% |0 K 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]
$ X# X. O# o0 C* Z! g& S' |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] 0 ^) w% s5 H& B
cookie=0x0, duration=1082.46s, table=10, n_packets=0, n_bytes=0, idle_age=1082, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]$ n  H" i' P1 b' L$ }' V5 q: t
3 f+ A0 D  @$ |' z
下面我们进行另一个测试
1 \1 k" U& x, k0 W: U8 _- g
4 I7 A- c$ Y( ~0 {$ 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   / Q5 |2 m- N, p) v# x2 m
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
* q8 J" `9 E7 n+ l# RRule: table=0 cookie=0 priority=0   u: m9 v1 w3 X  h, F! B
OpenFlow actions=resubmit(,1)$ z/ X$ |8 S( t. W* c( I

0 r: e+ ^, d# {6 a2 v4 H. G6 B9 v        Resubmitted flow: unchanged . H1 i' h, o: b
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 " A( D$ g% p( F- m% p
        Resubmitted  odp: drop 2 A' [% C. E( m
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
1 a9 s( R$ k5 V: [% K        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
7 g! \! e& m: R7 B* y, b
3 _- X; o5 d5 I9 G  s                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
& K# E4 r/ Y! q                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
: X" N" b) e) {# B" J# m3 f                Resubmitted  odp: drop
2 K: H' O  j& i" F: |$ _                Rule: table=2 cookie=0   e, l3 I1 @6 L4 g  k3 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)
! }0 E' E6 n) X" O8 f, @$ @; e) w1 ]& e* x  u
                        Resubmitted flow: unchanged   Q7 q) P* U" \* |% n) p
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
0 f2 O) o$ k. m                        Resubmitted  odp: drop
" d2 z  M/ S# w' D: f                        Rule: table=3 cookie=0 priority=50
7 I% {* [2 e' u& F9 u  R                        OpenFlow actions=resubmit(,10),resubmit(,4)% }8 k- U' E8 U

: R1 K+ i- S7 T- m) }$ W' O4 K                                Resubmitted flow: unchanged
% D$ d' Y' O% V6 |                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
0 a6 Z* l, t  ]( A* v: L                                Resubmitted  odp: drop ( H8 @* y8 e$ {5 x8 j9 |8 b
                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01
- d' `0 C9 P+ t' T7 {  G                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]  b: F6 R9 b2 }+ X) h$ ]7 r

% X, ~/ R: j3 ?- B8 S+ B                                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
/ Y& [7 R% H- C$ l3 T- y; \                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
; |. q  F$ W) a1 z/ I. [' d8 O                                Resubmitted  odp: drop
+ X9 ^8 ]6 n* u' i0 @                                No match1 p6 X5 Y! y$ A0 G$ U& A5 K
0 |+ L/ u$ N5 J
Final flow: unchanged
- Q( h, u2 C5 _8 ]; oRelevant 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
- ~" |! g) E8 }4 rDatapath actions: drop
2 u( e# f9 J; G) Q$ t1 y/ |
" ~& z2 n; W6 P# V( P; i1 E因为刚才学习到了mac地址f0:00:00:00:00:01,所以这次在table 10中找到了这条记录,这次同时也学习到了mac地址90:00:00:00:00:01$ @1 \/ J7 J' [
1 @- |6 x% F) C! K1 s6 s  r
下面我们再发送第一次的包
2 b: s4 m. ^, a- x' Z2 D7 X& E
1 L, ^  Y$ {! {5 @# }. N5 P$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=20,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01 -generate ! q& j- u: D1 C7 H
Flow: metadata=0,in_port=1,dl_vlan=20,dl_vlan_pcp=0,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000 1 R* m; |( y2 H3 Q; N
Rule: table=0 cookie=0 priority=0 3 j2 {* q0 ~- B0 o8 E, [# J
OpenFlow actions=resubmit(,1)3 x, {# u% e% p$ f. w# ]% I0 s
6 M$ |4 o/ I6 Z
        Resubmitted flow: unchanged
1 T' g8 o; S4 T# b        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
1 N8 s# J! \2 Q/ `8 t; q- ~" o        Resubmitted  odp: drop
+ R' w; |" X' H$ v% \8 ^. E" ?8 D        Rule: table=1 cookie=0 priority=99,in_port=1
" N) \/ E+ T, |! }- N4 M1 H! U  y# e        OpenFlow actions=resubmit(,2): q: Q, T  X- Y
7 o+ o3 A& P! |2 G
                Resubmitted flow: unchanged
. N6 \- u2 h  [( v6 A                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
& M* c' g2 j4 O9 S* `% E) m3 d                Resubmitted  odp: drop
2 e( c% ]- W1 W: {                Rule: table=2 cookie=0 # C: \0 N( u7 Y$ k7 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)3 U- Y7 j0 {- q& l8 C

1 S3 g4 f" X! B" Z                        Resubmitted flow: unchanged
, c  @) C1 ]) D% w# j7 `5 w                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
. Y& y& i* l# z6 V5 x$ S7 E                        Resubmitted  odp: drop
7 i2 n. r6 q3 o, t1 W4 \; {8 p- Z                        Rule: table=3 cookie=0 priority=50
+ m! u6 K" j8 {" s. A* {$ u                        OpenFlow actions=resubmit(,10),resubmit(,4)
: D$ @- |7 j5 D( V9 {" ?" D
; S  Q( j( f! ]) o9 H7 m/ O- Z3 X$ Q                                Resubmitted flow: unchanged . R% p' V( A5 f4 r4 {8 e
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
5 v0 L3 Y' F' ~. w                                Resubmitted  odp: drop * }2 N* N% S0 h& L5 f, |
                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01 8 x* E6 n0 U- m5 _& l1 C" W! L! i
                                OpenFlow actions=load:0x2->NXM_NX_REG0[0..15]+ J$ R' F: r; I7 b: H8 W3 B

% I( t+ Q2 L; f! 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 . L" {# q7 D0 e
                                Resubmitted regs: reg0=0x2 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 8 U* j9 R$ B8 z! J6 g9 y8 u  t
                                Resubmitted  odp: drop
( W( Q. j6 o, l7 L6 _* }                                No match
  |1 _* S4 x5 P. G+ _0 j
5 X" e% u- t( g8 o, N/ dFinal flow: unchanged 9 R3 d3 T2 d! c8 A3 ^
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 % k  x$ Y. W9 Q+ k! _1 o
Datapath actions: drop9 ^' n& o- F* K) R' V) q

5 A" p* D8 ^# z! p- A, `发现也在table 10中找到了记录
$ u9 R& r& L/ _7 ~; e
) g6 H9 j1 f5 ]: r' X/ L实现第五个table 4: Output Processing
% r% {% r% `8 R1 \5 {) l% _( m0 ~+ A% E- X5 L
这个时候,register 0中包含了output port,如果是0则说明是flood。
5 d9 K# }1 Z3 e" b$ F' L- H; I) p) G5 C# q
对于port 1来讲,是trunk port,所以携带的vlan tag就让他带着,从port 1出去。  ]7 T1 E" U9 z! ^  @
. R' W. V7 y% g7 o7 F+ F
sudo ovs-ofctl add-flow helloworld "table=4 reg0=1 actions=1"
$ L" V* [( e1 G  t! Y' W: U3 q/ }8 g9 t( A2 u9 T
对于port 2来讲,是vlan 20的,然而出去的时候,vlan tag会被抹掉,从port 2发出去
5 G! u8 K6 z! r4 o( X& S5 n3 G, ]
对于port 3, 4来讲,是vlan 30的,然而出去的时候,vlan tag会被抹掉,从port 3, 4出去
' Z& J4 K& B5 q5 q$ \8 r5 L
) `- ~; \8 ~  f: h) L" ?/ }2 |( J, n* p$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   
9 l( J6 d" f# n5 C7 n  r7 P        table=4 reg0=2 actions=strip_vlan,2 5 `' J1 E5 @- @* e) k
        table=4 reg0=3 actions=strip_vlan,3 : L# T, H) s, F, ]+ ~
        table=4 reg0=4 actions=strip_vlan,4 6 r- o; `7 [2 D9 K& J: b
EOF
/ O) m5 i3 U* g# U6 V6 \5 W
6 E6 e) l" P" s对于broadcast来讲,我们希望一个vlan的broadcast仅仅在这个vlan里面发送,不影响其他的vlan。
/ S* Q7 w9 d& a
9 r; W# S/ F1 A6 D- R8 W$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   - F$ `/ m- B+ |+ |# @
        table=4 reg0=0 priority=99 dl_vlan=20 actions=1,strip_vlan,2 / l3 U6 C, X( t  f2 k+ n& r  I
        table=4 reg0=0 priority=99 dl_vlan=30 actions=1,strip_vlan,3,4 . V6 p' Q; z+ k# P# B0 x
        table=4 reg0=0 priority=50            actions=1 0 N8 |2 S  {$ Y0 C  I
EOF% ^2 ^3 M3 y/ e2 [
; L$ k- u% j4 Z0 Q4 v2 I
所以对于register = 0的,也即是broadcast的,属于vlan 20的,则从port 1, 2出去,属于vlan 30的,则从port 1, 3, 4出去。7 K( T: d! X* F" W6 c  k: X( H
& o' V5 a: |' ^$ B
$ sudo ovs-ofctl dump-flows helloworld
" v% x- P1 R" C, w6 lNXST_FLOW reply (xid=0x4): 1 N1 l3 q+ k3 v8 [% g
cookie=0x0, duration=92909.119s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) 1 J$ D9 ~! x  u5 l6 K4 v5 K6 l' W1 F
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 & F# I2 Z2 L5 C4 P; Y
cookie=0x0, duration=93034.593s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
: |& |. |8 }' \8 c' k# `4 Ocookie=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)
$ w/ a. l5 t  Y; |+ U( E& [+ p5 R5 ?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)
* V5 H% R+ g" [2 }5 k* ucookie=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)
* X# p+ Z* D4 j# [7 ]cookie=0x0, duration=88650.855s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2)
7 Y1 q6 {' F% L+ Scookie=0x0, duration=88729.276s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
: g. ~- H7 l  v2 Scookie=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) ; I; |& ^- ~$ L
cookie=0x0, duration=1673.508s, table=3, n_packets=0, n_bytes=0, idle_age=1673, priority=50 actions=resubmit(,10),resubmit(,4)
; n5 P9 c7 H  W, Scookie=0x0, duration=1533.371s, table=3, n_packets=0, n_bytes=0, idle_age=1533, priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,4)
1 [8 m0 M; `- I) F2 lcookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x3 actions=strip_vlan,output:3 6 Q7 a) q, F% A$ L
cookie=0x0, duration=228.839s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=50,reg0=0x0 actions=output:1 9 ]" Q$ ?" K* J# J
cookie=0x0, duration=483.068s, table=4, n_packets=0, n_bytes=0, idle_age=483, reg0=0x1 actions=output:1 2 v) c, s. r( g! G1 k  v. S& B
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x4 actions=strip_vlan,output:4 0 [0 A: X  g( {- a  y
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x2 actions=strip_vlan,output:2 , l& Q! l# M- ^  I, Y
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
! H" f* q! }5 J. b1 [+ A0 e2 wcookie=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
! o2 a3 n2 z/ i. acookie=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]
" x: q) q% x6 w, S6 m9 ~cookie=0x0, duration=2090.451s, table=10, n_packets=0, n_bytes=0, idle_age=2090, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:02 actions=load:0x2->NXM_NX_REG0[0..15]
  o' V5 z; \) m$ Ccookie=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] # |1 t) ~9 M. m" i1 r* Y5 C$ e
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]
$ R" C; d- r$ }+ f* a
: E. H5 r6 q# C8 ]0 @( ^: w首先来测试一个multicast和broadcast
; ^( ~" W+ L: z5 w
/ w3 {4 G7 X: p- [如果是一个port 1来的vlan 30的broadcast7 c2 l8 q; z) `  g" z5 X' `
& X9 j6 h) R! n1 y
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=ff:ff:ff:ff:ff:ff,dl_vlan=30 , m- U) H" M3 R6 R
Flow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000
: S* K; c8 v3 V3 C( J: {9 ERule: table=0 cookie=0 priority=0 8 {& _7 w# v: y+ h. b
OpenFlow actions=resubmit(,1)
+ ?; a* l3 X1 L/ M, M
' S1 }/ k: q; O        Resubmitted flow: unchanged , Y* ]( t9 [9 S4 y- c- z
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 1 _; Z% K7 w  B6 {
        Resubmitted  odp: drop
0 r7 F3 Q+ j4 K# s        Rule: table=1 cookie=0 priority=99,in_port=1
7 R& \4 u! W6 l5 O* Y# E: E) |+ t        OpenFlow actions=resubmit(,2)
& L# Z1 g, x" J1 ]5 f+ d
7 h, P" {/ s6 {6 C. o9 R                Resubmitted flow: unchanged - \" c5 v: I: P$ T( q6 F; s
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ( V" u+ d; }5 E3 ~
                Resubmitted  odp: drop
6 @4 j' }8 a1 u  i. S: V- t                Rule: table=2 cookie=0
1 x( O; E" n9 X, H, 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)* [( f' ?7 Z- Q; \

& Z8 u( D& {# Y4 C                        Resubmitted flow: unchanged
5 g" {) |( c# y; s9 D                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ; _! C  d: b! P( Y
                        Resubmitted  odp: drop
5 t3 [; f: m3 y8 T) M) P                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00
8 ^) f1 i* |( q) h- U5 [                        OpenFlow actions=resubmit(,4)6 w+ {- H2 ?' r$ D& h) d$ {
' E' _2 T4 Z% `! S  a
                                Resubmitted flow: unchanged
1 i2 G$ i; h  _6 k; e                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & A1 {2 H3 t6 F* c9 i
                                Resubmitted  odp: drop
: G  R, z) V  [- f$ U- e                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
3 B9 n9 t9 ^7 J7 Z, ~                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
- S* N: X+ k! v5 h7 a, z, L                                skipping output to input port- Y$ `4 u, x- J1 R3 C4 g
8 p" v% }2 o: |
Final flow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000
9 d$ F* p! l% w* [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
8 D0 r- {1 T8 C) Z+ j9 ]  ^2 pDatapath actions: pop_vlan,12,13
/ \7 W; k& @: i% R) c$ X4 A. Z5 z6 ~
结果是port 1就不发送了,发送给了port 3, 4: v' g8 m$ L; E) y
& y8 o+ u+ L3 d% G
$ sudo ovs-appctl ofproto/trace helloworld in_port=3,dl_dst=ff:ff:ff:ff:ff:ff 8 {* n$ C9 n9 v! ]+ i4 m' L+ S
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 % y/ s  ]% z3 a
Rule: table=0 cookie=0 priority=0 $ E4 D  F0 D' z! e. ^
OpenFlow actions=resubmit(,1)
' S: V2 Q& W6 I: i
, q$ `  }  p$ m) z        Resubmitted flow: unchanged
- ]$ E/ i8 A1 u        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 6 B/ V3 _  Q$ W& m  a% X
        Resubmitted  odp: drop
% K& e) R4 _" p$ l+ o; s3 |5 {) y. g        Rule: table=1 cookie=0 priority=99,in_port=3,vlan_tci=0x0000 $ x3 j! V2 f: Y4 J& ?' K
        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)/ K& u# M5 X, `% f- |' L: ?- C( F
/ B" r& f( J( }  O( F$ a- c. y2 R
                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
6 K: w: l7 ?9 i+ Y' L4 }                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
  n; L" o1 `- }! N( ?3 b" z                Resubmitted  odp: drop / [8 G9 t! P: G. o# D2 B
                Rule: table=2 cookie=0 ; b- A3 w7 H3 }# I. n
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)0 R; Q6 |6 m6 e, |# m
' q3 u$ J& L: E6 \& ]
                        Resubmitted flow: unchanged
4 u+ B, d8 C( z3 J9 z) n                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 # S$ u  @; E* F# b5 Y
                        Resubmitted  odp: drop
3 Y8 P8 n* T0 P# b$ n- x$ T: S                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 8 o5 A$ I* g; r' ~5 }6 M4 d* Q
                        OpenFlow actions=resubmit(,4)
# U5 x5 B, o' m& n/ ]0 @% i/ y3 K+ M  t) h9 v
                                Resubmitted flow: unchanged
# x7 U3 s$ L  c3 ]# p                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 + e2 c* T$ X5 ~% f5 U
                                Resubmitted  odp: drop ' Z, x) K& y/ n. C
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
4 P5 {- W4 i  `7 p6 K: Q                                OpenFlow actions=output:1,strip_vlan,output:3,output:4   ^2 u8 E, D- j6 `8 E' C, s3 p
                                skipping output to input port
3 s4 }* V; S- R5 b, T# I! ]
5 [7 d" ~) j  @. PFinal 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
! O$ R) F/ e' h; B+ i* `  v9 LRelevant 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 : Y  c' }' z* G- M
Datapath actions: push_vlan(vid=30,pcp=0),10,pop_vlan,13( P  c1 ^3 v* W3 ?6 I; R1 [

5 w/ w6 x& x7 K9 e* W接着我们测试mac learning
; Z8 Z4 ?6 @2 C; w- N+ w( ]+ b0 o8 y# E# k& r# \# W
$ 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   5 u& `" Q3 @0 ]8 |1 S+ Z- |7 m2 @
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
" t. C6 o* i( n- z: \Rule: table=0 cookie=0 priority=0
+ ^: L- j0 C- mOpenFlow actions=resubmit(,1)
7 `6 g' h, i' {* C' G) s
. X: T" ~, U) V9 m7 H; @        Resubmitted flow: unchanged & g) P! H! o  X# I
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ( m# a: o! s  Q' x' S; Y
        Resubmitted  odp: drop : R5 ^5 s* s! S& _9 ?) O. V
        Rule: table=1 cookie=0 priority=99,in_port=1
/ A4 M% G5 m, p) W5 h- g        OpenFlow actions=resubmit(,2): ~) O+ K0 [; h& z4 _6 |
" t" E0 s' B) G
                Resubmitted flow: unchanged
" {/ k. f0 _! z* j8 c                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & W* K( `( z; z: ~1 n6 y8 X# K" C
                Resubmitted  odp: drop
, b+ v9 g; @$ f                Rule: table=2 cookie=0 3 d& V; P$ _( p
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)7 @( a- ^  j- r1 B: t  \

2 s0 _8 u( T4 q3 F                        Resubmitted flow: unchanged 6 r- F* @! b: V4 k) S5 [
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
6 k0 D! ?, z" a0 t0 F4 H! S" @7 k) H                        Resubmitted  odp: drop
. x% ?8 j! V; _                        Rule: table=3 cookie=0 priority=50   H) i4 X' d" \: O
                        OpenFlow actions=resubmit(,10),resubmit(,4)7 {  |& |5 Y; I# M
0 p1 z1 d+ _$ G) k, T5 H
                                Resubmitted flow: unchanged
  ^- I7 y) o, b1 m4 S& k1 r( `                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 Q# R* {( O5 \
                                Resubmitted  odp: drop
" k3 k. k( V2 c. L7 L                                No match
3 ~) B( O3 a# E* i  c5 N) R7 X- y+ `
                                Resubmitted flow: unchanged $ j4 K9 s1 V+ C* ~5 U" e5 o" m
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 5 Y8 o% M. O; D& @
                                Resubmitted  odp: drop # I0 G) ~% j5 D" L5 E' r; g
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
. \- Q: U( p3 R3 ~                                OpenFlow actions=output:1,strip_vlan,output:3,output:4 + T& \0 @  |- f5 _  s% Q: n
                                skipping output to input port
* P9 d7 T$ t) N. G& H4 T
; y: i" R  ~  Y# S& @9 ~  E$ ]Final flow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000 # j' X! P' e( u* L
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
3 l" C' V9 ~+ k+ ODatapath actions: pop_vlan,12,13
3 I9 n/ r- O7 W( v( G/ B) M  F/ c- A# E1 Z
由于这两个地址没有出现过,则除了进行学习以外,广播发送给port 3,4- r8 C5 z& s3 A* ~# a) B/ F

. B8 W; r  W  `0 Y2 ^* n6 Q! o& `$ sudo ovs-appctl ofproto/trace helloworld in_port=4,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01 -generate   
6 [3 p7 |5 H6 q* _9 fFlow: 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
. I5 z/ G$ X* @( e5 p2 _( ZRule: table=0 cookie=0 priority=0
/ N1 z% T" L% v' b+ q0 W/ B9 `OpenFlow actions=resubmit(,1)) M1 j  ?; ]( D6 o% P, S

' i4 d* v6 m6 h: `: V& j        Resubmitted flow: unchanged
4 ^3 i7 g. I- Z. X/ h) c' B        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
, [! S3 O* o+ l* ?7 q        Resubmitted  odp: drop
: M: Z) R+ {7 L8 O        Rule: table=1 cookie=0 priority=99,in_port=4,vlan_tci=0x0000
5 w1 R& r2 E4 {, r+ H. \# o        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)+ ~- h% @( y- J) C
6 H& j3 R1 X$ H% c+ R
                Resubmitted flow: metadata=0,in_port=4,dl_vlan=30,dl_vlan_pcp=0,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01,dl_type=0x0000 2 i2 \9 Q% j& J$ P8 t. y" }
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
6 d( h$ v0 ~& H$ c, ]' b: u2 D% q0 o                Resubmitted  odp: drop
8 q1 `2 ]" |! O! P                Rule: table=2 cookie=0
' k; y  N8 d. b$ ?5 |                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)/ w" _5 V5 L1 a  u/ s
/ [. W7 U+ J( z* _
                        Resubmitted flow: unchanged & p/ G4 v8 u. p7 r5 |) a( _+ U& {
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 9 Z! D2 D0 m* K: u- b
                        Resubmitted  odp: drop
5 i# x- ^1 Y: ?3 R7 D  h, s- T                        Rule: table=3 cookie=0 priority=50 9 a# s! u  G7 }8 ]% L/ X
                        OpenFlow actions=resubmit(,10),resubmit(,4)
  [: R0 w. J; p- g( Y7 Z# M% N! c7 _
' [. K  Y& u+ B7 b                                Resubmitted flow: unchanged 2 p. N7 d' G# x; `( Z$ ?! y0 r6 u. m" i
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
" C% }6 |: \  Z                                Resubmitted  odp: drop % ?  P  Z# e0 Q5 c
                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=10:00:00:00:00:01
1 I- U( E* n2 z* J6 y                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]; f$ A5 l3 r- c7 u* ?
; j, \4 N8 x# ?
                                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
$ i$ a! f4 l9 Y; K* C                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 , |8 F5 f0 n! E9 k
                                Resubmitted  odp: drop
) y1 e5 w1 f& D; V3 i  m                                Rule: table=4 cookie=0 reg0=0x1
+ g! h! G* f+ j. @( w6 V                                OpenFlow actions=output:1
, V3 }: Q( ?9 s  W( D
0 x* ~3 \) I; n! Z5 G9 J% MFinal flow: unchanged 6 F7 |* L8 i  {6 \) F1 x! s
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
9 N4 ~1 a6 Z" _! D) RDatapath actions: push_vlan(vid=30,pcp=0),10
% E, f( [3 T& `% I/ r/ ?
. l$ v8 A2 H# X7 U* d( K回复的时候,由于学习过了,则仅仅从port 1发送出去。
, o$ i3 G" x" Z; _2 ?) ^/ X1 `6 d7 N3 D6 f; m8 p% d0 A( A' 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 * l9 \( a2 V4 @" b1 |
Flow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000 2 [4 ?0 e  U) C+ \
Rule: table=0 cookie=0 priority=0
" c2 r+ x$ J/ Y* v. m; v. |. y1 d8 uOpenFlow actions=resubmit(,1)
) ]: X# Y0 ~% W4 X$ L. ~6 o% a+ Q7 N  {/ u, B- @. t# I
        Resubmitted flow: unchanged 6 Q- g; P" e6 [' Z4 f
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
7 d  _% a- }  L4 F* H8 r        Resubmitted  odp: drop
# c  \4 E/ [# F+ [8 f5 y/ M8 {4 Y+ \& ?% b        Rule: table=1 cookie=0 priority=99,in_port=1 * `8 d- J4 n2 S* J. ^
        OpenFlow actions=resubmit(,2)! [5 O% t6 I% X( }! D

6 t, O/ m6 v+ @% W6 J0 O1 L                Resubmitted flow: unchanged + s- T4 p; Z; E# G8 q. `) i7 D) U
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
- X9 }7 O) C9 t$ W( M% `" P6 `                Resubmitted  odp: drop ; X" G1 x( r1 v/ ^
                Rule: table=2 cookie=0
5 x2 X: t3 e: y, e+ }+ Z0 h4 u                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
  r! h1 G' L* P2 i/ ?6 H7 n. z/ }2 \- Z/ R7 R- ]9 K; Q; ?
                        Resubmitted flow: unchanged 9 x) W$ I! d( Z
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
, ?! S; x" ~. o/ X0 {                        Resubmitted  odp: drop
! S+ T! s" ]# \! h- S1 |# |  H                        Rule: table=3 cookie=0 priority=50 2 K/ C% i+ F7 e9 b8 F; g: d: a
                        OpenFlow actions=resubmit(,10),resubmit(,4)
4 s) e( Q* w& Y8 a7 R/ v% P6 |; T- e8 ?( Q
                                Resubmitted flow: unchanged
' w+ _8 {- M0 `( Y% i                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
9 @3 N+ }! O& Y                                Resubmitted  odp: drop
) m# z% r% c: u  t* e                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=20:00:00:00:00:01 # t; O2 I6 S% k  }  ]( d. d: i
                                OpenFlow actions=load:0x4->NXM_NX_REG0[0..15]
& q7 f# ~6 \( K. k
) d8 G( A0 m8 B$ f  N( W, _( j% _  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 ' C) _) h+ {4 F
                                Resubmitted regs: reg0=0x4 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 $ J% U* {$ t1 G) m: _
                                Resubmitted  odp: drop
' N8 s6 G8 G* U& m9 B' f+ X                                Rule: table=4 cookie=0 reg0=0x4 3 G4 s$ U" `3 Q+ N& |/ S+ Q8 b' N
                                OpenFlow actions=strip_vlan,output:4
% y( \5 Q+ R3 M9 l$ z8 k: ]0 Y) ^- |! m8 @+ P0 K: {
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 + N$ O, u" s3 c5 L
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
0 N, b0 m' i0 I) r* `Datapath actions: pop_vlan,13  Q- n, X( i$ h1 k

- W0 w' Q) g) C* i" q由于在回复中进行了学习,因而发送的时候,仅仅发送port 4

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2019-10-25 10:00:36 | 显示全部楼层
实现第一个Table 0,Admission control
6 W* |4 q; x( H' t! ~5 ?  p- X% l7 B( D, z4 x/ ~, J9 x4 y! \
包进入vswitch的时候首先进入Table 0,我们在这里可以设定规则,控制那些包可以进入,那些包不可以进入。; A- T: N4 X; T4 X  i" E

! h" \+ X% ?3 L, c6 i8 m3 n/ l8 [8 S1 q比如,如果source address是multicast的就不允许进入。; @# y7 _6 c$ u

" E! ^% N$ a2 d: o3 C/ N01:00:00:00:00:00/01:00:00:00:00:00是广播地址
" l. ~) s% D8 i! w# K4 V00:00:00:00:00:00/01:00:00:00:00:00是单播地址' y5 P6 t2 F" V
这种表示形式类似CIDR# t) j6 A  l+ k! Y) a
于是我们添加下面的规则:
; j; J4 t* y& I6 n4 Esudo ovs-ofctl add-flow helloworld "table=0, dl_src=01:00:00:00:00:00/01:00:00:00:00:00, actions=drop"6 w7 w" w, D1 o) [! m6 `- R
STP的也不接受
1 N8 S% q& Q# n$ E# nsudo ovs-ofctl add-flow helloworld "table=0, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0, actions=drop"+ M! S  N2 @2 x$ q; _  R  l
我们在添加最后一个flow,这个flow的priority低于default,如果上面两个不匹配,则我们进入table 1
0 |0 f! S* t* u2 f1 I% [; gsudo ovs-ofctl add-flow helloworld "table=0, priority=0, actions=resubmit(,1)"' F; M( n) e1 r7 _- x$ |
我们查看一下所有的flow) ^5 W# R3 l0 b% c  J4 U. |
$ sudo ovs-ofctl dump-flows helloworld        % v$ l2 O% V) B( B! l
NXST_FLOW reply (xid=0x4):
3 [+ F  y8 J/ ]# y2 P* Jcookie=0x0, duration=42.162s, table=0, n_packets=0, n_bytes=0, idle_age=42, priority=0 actions=resubmit(,1) 0 F& }7 K- a( Y8 @8 ?  u
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
' {* i( C, V9 u( e2 G0 ncookie=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# U5 ?( S8 h; W- j& W

  F8 ~7 n8 `3 Z9 [! P! N$ m测试Table 0( j3 c( x- B5 _& z; H2 |* e8 F5 _
) }( \: s7 E' m$ t5 x
有个很好的工具ovs-appctl ofproto/trace; a5 U5 S, f6 V' _; G
7 I1 d0 Y' }( `4 z6 e& F
不满足条件DROP
! t4 t# u4 `5 L7 |6 g% R% f/ @* |$ M8 U1 y3 g' G$ ^: Z# K
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:05 # G; R, N& F5 I) ]' q7 @' g6 W
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
2 E: u3 u; R/ Y' V1 ]9 MRule: table=0 cookie=0 dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0
7 o- D% f4 ]; \) G4 t: wOpenFlow actions=drop3 q3 i2 ?. Y' Q1 h, S. `2 l
' f6 N  Q: ~0 m) P; L$ \! t1 ~
Final flow: unchanged 0 l( {* y& U* v4 h" n7 I# g0 l
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
( D$ C7 A& r, G5 D  sDatapath actions: drop. i' V! @6 K' |4 B5 l- L+ m0 V" a3 j

/ d3 H! s8 n) Y9 s' a2 Q满足条件RESUBMIT
8 N6 ^# J+ K5 l. A% A0 y& u; o/ \3 ~4 u+ |
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:10 ! O& o* l. E" ]8 J; S
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 + v+ }# ~* X, v4 ~2 V! P0 p5 j
Rule: table=0 cookie=0 priority=0
5 [1 E# Q% N" n& ~OpenFlow actions=resubmit(,1)
( {; ~( E7 ^" q# d% R( }+ {
( \0 X+ g$ \/ ?) t) ^: W6 L        Resubmitted flow: unchanged , ?$ {1 }8 p8 F: x
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 : b/ R" u2 H) Z1 a
        Resubmitted  odp: drop ! n& ~' @; m5 ]8 \
        No match
" t9 u! c, C- l
3 I: t1 |/ n& a( }( [Final flow: unchanged ! `0 Q! Y0 u8 [) _8 s9 i/ N/ u
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
! T) C4 R8 [+ y3 DDatapath actions: drop
, U3 [& \; R4 _, p5 Q" Z0 l) |! C& X  I
实现第二个Table 1:VLAN Input Processing# Z, B8 h, Q( `% y' S" {4 n% K

7 j6 @9 z6 T% X' v; C首先添加一个最低优先级的DROP的规则
7 b. P& Z9 u* t% N! ^$ h8 A7 \) `! l$ ^* ?/ B; d$ u
sudo ovs-ofctl add-flow helloworld "table=1, priority=0, actions=drop"3 @. e( f6 b+ t6 z1 N' s  ~- O# o

, C8 a3 N  e/ o# w% Q+ y! K; I对于port 1,是trunk口,无论有没有VLAN Header都接受。+ S, V: G0 K  @/ G" ]) d

4 W) U3 t% H- X% E4 q1 I8 Ysudo ovs-ofctl add-flow helloworld "table=1, priority=99, in_port=1, actions=resubmit(,2)"" m0 n, C) j$ t  S/ a1 G- m
/ L) q# l1 ^7 Z3 \
对于port 2, 3, 4, 我们希望没有VLAN Tag,然后我们给打上VLAN Tag" o9 o& f! q) k" }
$ J' E. G0 A- q8 w
$ sudo ovs-ofctl add-flows helloworld - <<'EOF' , S' |- z- y! f* Y* X6 Y
table=1, priority=99, in_port=2, vlan_tci=0, actions=mod_vlan_vid:20, resubmit(,2)
+ w5 \; B/ n* D3 S: Jtable=1, priority=99, in_port=3, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2) : E) q: h0 z9 c# t+ D4 K' a
table=1, priority=99, in_port=4, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2) , M' h9 p. J# z& Q0 _
EOF& S4 Q9 f+ a: d( ~3 \% S0 f) y, V
# M+ _. T) T. ]4 ]
$ sudo ovs-ofctl dump-flows helloworld 3 E5 n) Z" r/ B) f3 ]
NXST_FLOW reply (xid=0x4):   {6 K: Y3 `* l2 A7 E9 B
cookie=0x0, duration=4478.582s, table=0, n_packets=0, n_bytes=0, idle_age=4478, priority=0 actions=resubmit(,1)
* [; v! h- T( A, `  \cookie=0x0, duration=4668.541s, table=0, n_packets=0, n_bytes=0, idle_age=4668, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop & L+ w" S; o8 D  v$ Y, T0 f
cookie=0x0, duration=4604.056s, table=0, n_packets=0, n_bytes=0, idle_age=4604, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
5 N8 z- m4 V7 Ccookie=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) # o  S7 Y5 A* S5 L8 B
cookie=0x0, duration=89.273s, table=1, n_packets=0, n_bytes=0, idle_age=89, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
; j% z8 u! ?9 u5 ~$ Rcookie=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) 0 i: ?9 y* }- |+ D- F6 h
cookie=0x0, duration=220.318s, table=1, n_packets=0, n_bytes=0, idle_age=220, priority=99,in_port=1 actions=resubmit(,2)
/ Z. g* ~% V" Tcookie=0x0, duration=298.739s, table=1, n_packets=0, n_bytes=0, idle_age=298, priority=0 actions=drop) W$ U$ i4 h  U3 F

% {% `# @& P1 a. N, k测试一个从port 1进入,tag为5的
9 Z7 ~! C7 Z. ?. v- Z! `/ I
; X+ M. j3 b! K! A$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=5 ) b. |' Y+ H0 L& o  Q$ i0 q2 o5 {
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
+ G; o0 `+ |  I6 C4 uRule: table=0 cookie=0 priority=0
$ a8 T. K* h( z& BOpenFlow actions=resubmit(,1)
& K* Y& \$ A+ m
' @4 f% h7 e6 C        Resubmitted flow: unchanged
$ E9 A0 k6 X! K. B+ {# g        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 # H2 r0 C' h; o. }" x
        Resubmitted  odp: drop
; ^/ w7 R' P9 Y0 n! N8 e" y/ G& p0 J        Rule: table=1 cookie=0 priority=99,in_port=1
: e. g% y: y; i5 j6 @. a: E9 k        OpenFlow actions=resubmit(,2)
2 z1 ?, ~+ k( p+ @5 a, y' M. |1 e! B5 {5 N) _  V4 _- N
                Resubmitted flow: unchanged ' a1 b7 _3 v! t
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & W* u1 y9 r# A9 ]0 R; N. c! J( x
                Resubmitted  odp: drop
5 M3 g3 s# [) J# W4 `  {0 M1 T                No match
0 q0 ^3 ~* O* a; I& P+ Z
% t8 k. c# T2 s& H5 UFinal flow: unchanged * H7 h8 _* l- ~& \9 X* ~# y( G7 m/ p: C  P3 h
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 , J: a- T/ R. O0 E; k# F  f/ d8 W, O
Datapath actions: drop
) U! C: H% X  i
8 ^; u& {9 L0 q" w, V! r& b- c- n0 |4 t测试二,从port 2进入,没有打Tag的
2 I7 ~7 Y' w0 {% J" [" G
9 G8 j' r: B* P* C$ sudo ovs-appctl ofproto/trace helloworld in_port=2
+ J. y5 H( D" r4 d! G/ SFlow: 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 ( ]9 g' r$ M  t
Rule: table=0 cookie=0 priority=0   f5 ~; i: s* T. N5 E5 K
OpenFlow actions=resubmit(,1)9 F7 e7 _/ q2 y0 g8 ~6 N$ c
! ?) ]5 j- `9 E9 H! [5 i
        Resubmitted flow: unchanged * G2 E, p; ?  V7 N
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
4 f# P* P! K5 f8 i        Resubmitted  odp: drop 0 {* H8 f+ S  ^4 ~% ]9 q6 b0 Q
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
/ p* `) }$ J+ ?6 p5 V        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)+ ?+ `! t6 c, [
  O: p! ^1 u) c8 y# P. v6 ]
                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
, |: J0 Z! y6 y( }$ M) u5 U                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 * {% V* ^5 \3 y6 w5 [4 Z1 }
                Resubmitted  odp: drop
5 z; z/ w; ?- B                No match
5 B) w# W2 A1 h2 y# W  {) x( Q8 c( g8 v
Final flow: unchanged
! w! x; A$ ?6 W, W# P  _Relevant fields: skb_priority=0,in_port=2,vlan_tci=0x0000,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no 2 S- E9 l1 z+ g+ d
Datapath actions: drop- H5 q3 {9 S7 ?5 t$ L- G! q
% g' r0 |) r! x# b
测试三:从port进入,带Tag 5的
! o2 }6 u  ]$ h2 [* X, L, l4 @: Z  k; I' t3 u/ H
$ sudo ovs-appctl ofproto/trace helloworld in_port=2,vlan_tci=5 4 q$ g0 S; Z  t. Q
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 ' ?  w) e1 g; q# C
Rule: table=0 cookie=0 priority=0 1 ?! g* p* X2 k2 W0 b, \+ F8 D
OpenFlow actions=resubmit(,1)6 ^) o) q/ W7 x7 X

0 c+ g. _9 e0 S# u: x        Resubmitted flow: unchanged
, O; u/ c6 I; ^, `8 i        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 7 u- ~" {) v0 h! u! w3 x
        Resubmitted  odp: drop 2 L& g7 s. E. T
        Rule: table=1 cookie=0 priority=0 . _" d$ D$ ?: m- U
        OpenFlow actions=drop
  v1 @/ x8 a' H6 I7 E& T9 e$ D$ _8 H0 Q5 Q9 f/ i% |$ b6 u
Final flow: unchanged
* B  {" @' i) ]" d: W) R6 eRelevant 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
$ v5 E9 b/ }, p! F' R/ m7 Z  P; TDatapath actions: drop. {% m3 g4 B! y0 N. x+ t

! e+ n, ~1 W* D+ l8 Q+ a实现第三个Table 2: MAC, VLAN learning for ingress port+ n& L  P" q5 q
, J: L$ e: C) b0 W3 `1 o* I* Q0 q
对于普通的switch,都会有这个学习的过程,当一个包到来的时候,由于包里面有MAC,VLAN Tag,以及从哪个口进来的这个信息。于是switch学习后,维护了一个表格port –> MAC –> VLAN Tag。
+ ^% e) E% Q9 h, N9 }+ Q3 \% B! [7 B/ |" M  F, ^
这样以后如果有需要发给这个MAC的包,不用ARP,switch自然之道应该发给哪个port,应该打什么VLAN Tag。
: a( n; D+ W$ |2 M! g$ {, x: H2 v$ S1 H
OVS也要学习这个,并维护三个之间的mapping关系。3 n, X3 b" V/ z- K

& b3 a5 f  N0 [" u, @6 a) H/ m" Z在我们的例子中,无论是从port进来的本身就带Tag的,还是从port 2, 3, 4进来的后来被打上Tag的,都需要学习。
; O; C% u; v" Y. n/ I3 I1 k8 I) }6 X) D: Y& K8 y
sudo ovs-ofctl add-flow helloworld "table=2 actions=learn(table=10, NXM_OF_VLAN_TCI[0..11], NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[], load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]), resubmit(,3)"0 l+ F! \9 R3 q4 T! D0 s$ X
+ c, R9 }0 g( j4 u0 g
这一句比较难理解。2 R. G% W; S" t6 n: M
: H1 @5 n5 n# m* V, i2 B) c
learn表示这是一个学习的action% h' ~5 b, ~: l; t
+ O1 ]! d7 D* ^8 G
table 10,这是一个MAC learning table,学习的结果会放在这个table中。" k1 j  f7 [+ V& F0 ~2 e; c- I

$ ^1 r1 q3 `* O5 H) x2 c3 WNXM_OF_VLAN_TCI这个是VLAN Tag,在MAC Learning table中,每一个entry都是仅仅对某一个VLAN来说的,不同VLAN的learning table是分开的。在学习的结果的entry中,会标出这个entry是对于哪个VLAN的。
8 b8 f$ `# V; u: r! ~* C# A) E! y7 ?; o6 |5 R, r
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里面,因为这是为发送用的。
  E4 X) U9 m- v4 d# b
6 D7 F5 w& w! F- T7 s( j3 H, ~NXM_OF_IN_PORT[]->NXM_NX_REG0将portf放入register.
. ?. W  B+ W$ L+ _( e) W6 @
5 ^4 }6 x3 C/ W- y; k4 o一般对于学习的entry还需要有hard_timeout,这是的每个学习结果都会expire,需要重新学习。
# z, e5 i' f( ^* z& _) s- N9 r
8 Z! T* k0 P" H- E3 h- S我们再来分析一个实践中,openstack中使用openvswitch的情况,这是br-tun上的规则。
1 V! w4 s" l- N
% h, y3 l6 }& \  ?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 2 c" n$ ]: J0 i, x
cookie=0x0, duration=802187.786s, table=20, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,21)
$ O" E, O9 d: w. ~- x 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
+ f5 Q7 @2 M1 v; M4 Q! s' R" k3 b- Jcookie=0x0, duration=802187.653s, table=21, n_packets=17, n_bytes=1426, idle_age=65534, hard_age=65534, priority=0 actions=drop
* ~- i3 ]# e4 i" i4 ncookie=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/ A; q: ]; ^- f0 j; S" l* F' H% x  D
; v1 e6 H" @1 [* Z9 r! D! R3 P5 W. g
这里table 10是用来学习的。table 20是learning table。如果table 20是空的,也即还没有学到什么,则会通过priority=0的规则resubmit到table 21.
8 h/ x3 g" q" J8 m! w$ f; M) t
" u4 h' |8 w9 R. C5 h& O" O6 ltable 21是发送规则,将br-int上的vlan tag消除,然后打上gre tunnel的id。9 b, v% X. \  D  L

- O4 j- X8 a! E9 J, b: H. j: \# g5 L上面的情况中,table 20不是空的,也即发送给dl_dst=fa:16:3e:7e:ab:cc的包不用走默认规则,直接通过table 20就发送出去了。
$ P+ K4 Y9 t" ?9 C- @( }' s* Z  U- F! A
table 20的规则是通过table 10学习得到的,table 10是一个接受规则。最终output 1,发送给了br-int. a, I6 P+ G9 s; G. t
+ f+ y; ^- D4 y" O
NXM_OF_VLAN_TCI[0..11]是记录vlan tag,所以学习结果中有dl_vlan=11 w4 v6 v( `7 L! Q4 g5 B

! p9 z8 T7 K5 Z" q. Z; CNXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]是将mac source address记录,所以结果中有dl_dst=fa:16:3e:7e:ab:cc) y5 ?' a0 h, M! f+ D* e
9 X) [( F/ P/ ~. `/ T0 Q
load:0->NXM_OF_VLAN_TCI[]意思是发送出去的时候,vlan tag设为0,所以结果中有actions=strip_vlan* U! o% E3 a2 I5 b$ d
* }' W3 n7 D8 z- W- E
load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[]意思是发出去的时候,设置tunnul id,所以结果中有set_tunnel:0x3e92 N: q* D8 o2 p# r8 C% U

& R- p9 t/ W9 \output:NXM_OF_IN_PORT[]意思是发送给哪个port,由于是从port2进来的,因而结果中有output:27 H  s2 w; _$ n5 s6 O1 O, Q
9 X$ K  V  `; Y
测试一:从port 1来一个vlan为20的mac为50:00:00:00:00:01的包
" |' ~: k! R+ [/ p0 v0 Q) |" m1 x: R8 d) f6 A" A
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=20,dl_src=50:00:00:00:00:01 -generate   
2 I7 B7 |$ @4 r2 yFlow: 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 : U5 ?6 o6 [  W4 Y
Rule: table=0 cookie=0 priority=0
* U8 k6 a# A+ @0 o" COpenFlow actions=resubmit(,1)* m0 u1 {; U* @9 E1 d& ^5 ]5 T* J4 Q) T+ B

' |' n! m& g" j6 U        Resubmitted flow: unchanged 6 P2 ]& c# }9 O, w- S2 J
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
2 W; u! {- X. G$ ]! f. O0 j        Resubmitted  odp: drop
, V  P* x" r$ o7 {0 P6 i0 s- ^        Rule: table=1 cookie=0 priority=99,in_port=1
* F% c# O5 p; i2 E- g8 c1 L        OpenFlow actions=resubmit(,2)" G. e! a1 A- H2 r; B
5 I) S6 e7 E9 y. C: L
                Resubmitted flow: unchanged
6 r$ r% b8 K" I( V7 @8 P8 {                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
. O% @& M$ ^1 p7 m- o                Resubmitted  odp: drop
* V% d  Z, j1 r6 V                Rule: table=2 cookie=0
2 A2 h6 e: _  T' W                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)+ i* S  v, X* a' {4 }

6 d6 v: N3 V" y8 W7 z: ~                        Resubmitted flow: unchanged
& F2 A# q* }6 N                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
* S8 @; H. y( V3 ?, l, b                        Resubmitted  odp: drop
, ?. c: b* G0 v5 B4 P, M0 l+ z                        No match' T$ f% |8 t4 c* J+ Z0 Q# h
; r/ K% X% X2 I
Final flow: unchanged . C9 q3 w9 d' H
Relevant fields: skb_priority=0,in_port=1,vlan_tci=0x0014/0x0fff,dl_src=50:00:00:00:00:01,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no ) c6 q& b6 u" H% ?0 l& @( D
Datapath actions: drop  Q* R1 w5 X" C0 y6 l# @% w- W
; s  A4 d, l" }0 F1 b" D
$ sudo ovs-ofctl dump-flows helloworld
6 g, I0 n, h6 C# T' ]  YNXST_FLOW reply (xid=0x4): ' D" l1 r7 H2 k2 U7 p7 G
cookie=0x0, duration=90537.25s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) $ n+ y: n, R+ F6 d
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
3 ]8 M6 `1 T4 H& g% icookie=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 + P/ ]" v6 i9 Q$ g2 Z
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) $ y% J1 E/ _! `
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)
8 Q9 e$ n" r, L- U1 ucookie=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)
8 q* J4 R9 R4 T5 c  Kcookie=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)
. A! C  V" s8 ^5 i+ v( hcookie=0x0, duration=86357.407s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
6 V6 s: T& h1 ?. M  ]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)
9 r' o) G! o2 n/ y5 l* n 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]
' r) g4 b3 V* ?
' a! {# j# Q- f4 Z3 Wtable 10多了一条,vlan为20,dl_dst为50:00:00:00:00:01,发送的时候从port 1出去。$ ^6 p7 @( o$ x: f$ z
# O' x4 v" e1 [* Q+ M; i- w/ D5 z
测试二:从port 2进来,被打上了vlan 20,mac为50:00:00:00:00:02( @/ D& B/ @) I+ B1 t+ i$ o

" H. S" o9 ~0 K  e8 `$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=50:00:00:00:00:02 -generate   
- j) |) K$ z" b! j  r3 h$ Y/ dFlow: 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 6 |! `; d9 K# G1 h5 M: t
Rule: table=0 cookie=0 priority=0
5 i4 \" b3 p6 m' Q+ MOpenFlow actions=resubmit(,1)) t& v6 k- w4 O7 _. b, {2 h
& c$ N  l4 ?& v+ E7 p: e) t
        Resubmitted flow: unchanged
; `6 v) e4 T4 u2 _0 l- K        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
: B/ G+ g! ?" `4 L* N1 n1 {) D        Resubmitted  odp: drop $ ~! U' U' c" L7 _* R. c( w- e
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 4 o% J5 H/ g4 @
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
: k' q& x5 \# [! S9 M1 M, U( P. _% J, [8 d" a3 @' U
                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 6 A- J( r( Y8 ^( O4 Z# L
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
! j3 a% k9 T3 X2 e8 d                Resubmitted  odp: drop
4 e, H2 n3 R( g$ L                Rule: table=2 cookie=0
+ ?4 U7 }$ N* L# x                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)9 s/ ^+ }# S% e7 \3 E

3 t9 u! E& G! k8 w6 m" r2 B                        Resubmitted flow: unchanged
7 _9 N  C% I9 D7 C  `4 {( M6 T                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ; w( n) ?; s( U( D8 y9 Q! n
                        Resubmitted  odp: drop / |$ j! R7 H: N9 ]$ a
                        No match
! a0 v/ i/ k. ~7 V0 V$ W- [+ O* G, \2 v$ A4 l5 Z1 L( R$ Z
Final flow: unchanged 5 ~& K( E& G8 K
Relevant fields: skb_priority=0,in_port=2,vlan_tci=0x0000,dl_src=50:00:00:00:00:02,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no # b% C' T" T$ W
Datapath actions: drop
7 ^1 a* ]% e) Q. b0 o( {
  X1 b" x$ Z4 d2 s$ sudo ovs-ofctl dump-flows helloworld                                                 / R; W- I1 A+ S6 Q
NXST_FLOW reply (xid=0x4): 0 }. w$ H" A, U% {# F
cookie=0x0, duration=90823.14s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
3 {. Y- I& b- P( Y- j7 e- qcookie=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 , F# z" b4 r( v* z! B+ r6 M1 `
cookie=0x0, duration=90948.614s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
6 C  G, a2 A: H6 \6 N/ @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) . }( E( Q1 O; s6 p# y$ H$ Z
cookie=0x0, duration=86433.831s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
' l, ^) T% r2 l, ~3 V7 Tcookie=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) ) l; ?  r  [2 f1 ^; G, r
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)
# \. |, k7 c+ |0 l: ycookie=0x0, duration=86643.297s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop 4 I- z& }2 H# F7 ~' @  X9 [
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)
  J0 k( E  ?2 H2 ?* g 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] 5 L: G$ n: ^: h! u% d/ w- i
cookie=0x0, duration=317.148s, table=10, n_packets=0, n_bytes=0, idle_age=317, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]' R, y1 k+ N' z# _# g, y2 p  w

+ [; f2 }# q% v; l  v2 L实现第四个table 3: Look Up Destination Port( E' }! d; E' W8 x+ Z

2 S0 E1 \2 D8 x6 K4 S, r+ E' F在table 2中,vswtich通过进入的包,学习了vlanid –> mac –> port的映射后,对于要发送的包,可以根据学习到的table 10里面的内容,根据destination mac和vlan,来找到相应的port发送出去,而不用每次都flood
. S' a- Y' I, v$ a2 v( n
8 |# f' q3 Q3 m1 x, n5 nsudo ovs-ofctl add-flow helloworld "table=3 priority=50 actions=resubmit(,10), resubmit(,4)"
# C! L$ Q& t) i& }
) @, ?; g; I. Q8 ^6 a8 f添加这条规则,首先到table 10中查找learn table entry,如果找不到则到table 4
, q+ i. ]+ i* y8 z. a9 v2 Z6 s: }
如果包本身就是multicast的或者broadcast的,则不用去table 10里面取查找。0 N$ H% F" }* e

; r4 i( B' v% a/ Ksudo 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)"* Q4 }5 A. a& ]- i0 m$ \8 l5 Y. P6 |. {$ L
1 u* I' ?) T% G# _! i( b( ]' @
我们进行一项测试
# y4 j8 \0 I$ J1 q2 L8 f
* v7 t0 [7 e9 B- k" h7 I$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=20,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01 -generate   ( t# c; m1 _: c# X$ M4 C9 K
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
  V# _; a# w/ [, `" E) |6 QRule: table=0 cookie=0 priority=0 0 r# |1 k( ]: K' M6 y% X
OpenFlow actions=resubmit(,1). S. b# j0 l" }# S
. ]9 F* \& O0 k+ ~# U' T6 `
        Resubmitted flow: unchanged 2 m8 h$ ]# I( n  r( r7 \8 Q  x( T6 f+ z, M
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 6 J& n: j( m8 {
        Resubmitted  odp: drop
, d, P5 {2 w' z4 w* U* \0 Q. D. i        Rule: table=1 cookie=0 priority=99,in_port=1 * ~. x+ ~- ~9 d) Q
        OpenFlow actions=resubmit(,2)2 G* f" |- G# k( ~* ^5 v8 f4 v
5 f& n# D2 ?7 Z3 l4 |, ?
                Resubmitted flow: unchanged
/ n0 N% v- O' d- {+ J6 P& I                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
) E) p. o8 O4 }                Resubmitted  odp: drop " w& m$ [, H8 V" \6 V% G
                Rule: table=2 cookie=0 ; U- [. Y- m" h  ^2 |  p, N4 ~
                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 K0 o- |' e; Y2 G

9 M$ V! Q" N1 Z                        Resubmitted flow: unchanged
2 b$ ~) q7 q$ \# T3 v# C8 B, i" y. g                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
3 G- x. ~; Q7 R2 H) G3 F% R7 @                        Resubmitted  odp: drop : K( e7 Z& N! q/ x
                        Rule: table=3 cookie=0 priority=50
, Q$ G. U- j" c/ ~- M& ~                        OpenFlow actions=resubmit(,10),resubmit(,4)$ I/ J" _" P; V# A4 ^" @; {

4 Y4 }" f0 p" _! E                                Resubmitted flow: unchanged & Z! h- R9 m0 b: h" B4 [$ H+ B1 I$ |
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
" F7 P+ o  M) {' x# p                                Resubmitted  odp: drop 7 w( T' t; Y" G( o3 E
                                No match: z( l  ]3 o; V$ ]. P, s1 R4 v. i2 `, _
/ F: t1 H* h. v* I" h
                                Resubmitted flow: unchanged
: ], f4 @" n% W& q7 h" B  q. |                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 - {2 T- x6 h8 E  h+ C- E. P
                                Resubmitted  odp: drop ! S, v4 E7 [5 b; W3 b9 L( r- s* w. {
                                No match" L( P" L. L2 G9 u3 n6 v) p
# D# l9 R1 G- c) r$ P) N( G
Final flow: unchanged 1 z8 A* c. j. u. X
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
- s/ g' ^% K- \/ e8 p: [Datapath actions: drop
1 A: n! Q! J3 M) D/ |6 i3 w: v% F2 H( O5 c4 s  C
由于目标地址f0:00:00:00:00:01没有在table 10中找到,因而到达table 4.
' H* [3 ~2 w) s2 _/ T7 N0 m; G2 V- Q% u' W
但是这次测试使得table 10中学习到了mac地址90:00:00:00:00:01
, v: W- J% o' F) N+ W, ?6 f
+ X1 T/ u6 S9 W( x8 g$ sudo ovs-ofctl dump-flows helloworld
5 B: X! c- `! E9 aNXST_FLOW reply (xid=0x4): , Y8 e5 y- y9 Q5 @. z3 W* I
cookie=0x0, duration=91588.452s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) 2 U! a/ \/ o1 J( u5 A( Q1 L
cookie=0x0, duration=91778.411s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop
( i8 M& Q" c: H8 q$ g* X, Zcookie=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 ) n7 a6 u, C6 |% i- P5 n/ U+ E
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)
( ?; K  Y' D1 e8 Ecookie=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)
$ @5 f$ n! v6 f3 j& ~8 m$ fcookie=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) 3 _; a9 S) R4 S6 P3 f8 C9 w/ I5 x* i
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)
6 Y- w4 _- M) S( s+ R" ]! hcookie=0x0, duration=87408.609s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
1 ]# S6 v1 E" A& V, g6 wcookie=0x0, duration=84638.483s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
2 U  X0 A0 G) jcookie=0x0, duration=352.841s, table=3, n_packets=0, n_bytes=0, idle_age=352, priority=50 actions=resubmit(,10),resubmit(,4)
- p# p( |5 V/ J- H* m1 p: L7 Ucookie=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)
3 u/ B$ n: d5 D 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] 6 {' K6 G) D  e0 u. z6 l
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]   ]$ k6 L- T5 K: [" h. [/ Y
cookie=0x0, duration=1082.46s, table=10, n_packets=0, n_bytes=0, idle_age=1082, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]
8 B, t; L) d+ O  t. D3 K* Y% A2 x2 j! U' X, {3 L, e4 b
下面我们进行另一个测试
; b" a7 x) ^! }- Q; B8 e2 K7 J! }' S* U9 X; O' B
$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01 -generate   
9 C' j# Q0 V. ?" @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 8 o. e5 d4 R2 p7 y! O( m4 _- G
Rule: table=0 cookie=0 priority=0
7 v7 o8 q/ u- h! C6 SOpenFlow actions=resubmit(,1)% A- I0 r0 k9 J) k
3 V  h  [( q5 O; e
        Resubmitted flow: unchanged ( c' j' L/ s3 ?. v. D' R6 I
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 9 `2 G8 W! W3 B) }9 v' S- w4 f0 U
        Resubmitted  odp: drop
& f% |, o  S4 t/ c3 c        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
. n" {( g+ j) q6 g2 q        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
( Q4 \2 [7 n5 i* D( k5 G( |- q9 f8 o# J
                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 + G% `; j9 s+ R$ `
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
- q3 h5 [1 [' `. R! x& H9 d                Resubmitted  odp: drop 7 D" V& |2 q+ w, h( L
                Rule: table=2 cookie=0
& \* o0 g! }* J! a                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)4 F& B( }9 g/ z. M3 d7 ]

$ p8 m: D& J( N4 D3 M4 i  q                        Resubmitted flow: unchanged
- [6 Q8 n* C, M- [* J7 m) `                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
6 k* \0 L2 C3 G: `" J$ `/ B                        Resubmitted  odp: drop 0 I) G. u) A. a
                        Rule: table=3 cookie=0 priority=50 $ T- {2 N3 q2 C, i7 h, D
                        OpenFlow actions=resubmit(,10),resubmit(,4)6 k6 T# \( F; k. H

; w. R9 C9 {: f  I; Z) C5 a0 f                                Resubmitted flow: unchanged 3 b7 H- S& x) D, K! N$ ^
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
5 C- Q, P% l' D5 l$ F9 @) G                                Resubmitted  odp: drop
8 B, ]7 T' U; k) r                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01 ) u9 A- T" U; P: o# R8 |
                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]
: D. i+ S4 k) r. X
+ n5 m- M3 E2 N( ^) n, f3 ~) |) B                                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 * F/ k* W$ X- ^/ `
                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 # Y1 Y' w' q( @+ q: Q& L
                                Resubmitted  odp: drop + d& k  I$ o2 I7 ^
                                No match
5 F) n, ]% q. J2 K1 X" }; K
5 h6 w! M# h# s0 O4 aFinal flow: unchanged $ v( U7 Y" `5 r" g! i9 N* J! _
Relevant fields: skb_priority=0,in_port=2,vlan_tci=0x0000,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01,dl_type=0x0000,nw_frag=no ' q" T% x6 R. S3 m
Datapath actions: drop* s+ L  M* F: J5 q) D9 }( t

% n& M9 B) t0 t6 }; I4 v" Q9 _+ y因为刚才学习到了mac地址f0:00:00:00:00:01,所以这次在table 10中找到了这条记录,这次同时也学习到了mac地址90:00:00:00:00:01# O2 {# S9 {3 x: s$ _

" k1 T9 ?; K/ y$ M: T下面我们再发送第一次的包
* Z, U; z8 g* Q) x5 X8 {# i
$ T; c% |( }2 m6 W5 U  G7 k$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=20,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01 -generate 9 N  o  K, |5 q; h+ A2 N* f
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 ) o& r. y, t( k1 `; X6 n9 J
Rule: table=0 cookie=0 priority=0
( W, n  i% e5 p4 AOpenFlow actions=resubmit(,1); c& Y! n' e& Z/ I2 J$ \' ]
1 j2 F8 v, }" J4 w" D* L1 H/ N
        Resubmitted flow: unchanged 0 J. U% f  a2 d8 D
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! r- Y% e- I1 k3 f. Q
        Resubmitted  odp: drop
3 V& H$ {: T) `' j. r, [! _% h# C        Rule: table=1 cookie=0 priority=99,in_port=1 ! s1 b# g0 C" J' j  m9 G
        OpenFlow actions=resubmit(,2)  G/ _# S0 W* [

8 v, P1 M. |/ i                Resubmitted flow: unchanged 2 O1 u- C5 q) _" V. R
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ' K& z4 f5 \* E$ H. J
                Resubmitted  odp: drop
$ z: Y( f! B! Q                Rule: table=2 cookie=0 5 o- H+ S; W" W# J2 C; P
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
! R- A( [2 g' Q3 t% j% W2 m. L- m4 p; J
                        Resubmitted flow: unchanged
/ ~: M4 N! F% ~! D8 v                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ' x; N! c& C2 W9 R; @. }
                        Resubmitted  odp: drop
2 S2 W, K0 A0 G                        Rule: table=3 cookie=0 priority=50
- E& ^+ W* C, D6 {, Z  W% S9 ?" z                        OpenFlow actions=resubmit(,10),resubmit(,4)7 R5 A* j* ]) u
! g* x7 w9 n6 g
                                Resubmitted flow: unchanged
5 w. S7 y- ~! ?. o# p                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
' R. B; g6 _5 T: i7 m6 q4 L+ ~' W                                Resubmitted  odp: drop
1 Y3 Z  Z8 B' c, b; p                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01 ; L$ j* a. B! D$ L
                                OpenFlow actions=load:0x2->NXM_NX_REG0[0..15]. v2 Z9 V" g1 p2 A2 W5 J
) G6 _4 w9 k7 u: t% P
                                Resubmitted flow: reg0=0x2,metadata=0,in_port=1,dl_vlan=20,dl_vlan_pcp=0,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000
' a" c2 b3 a- U8 E6 X                                Resubmitted regs: reg0=0x2 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
4 j% i/ p; b2 O. K' I. `                                Resubmitted  odp: drop
& p, f* j; C0 }0 J) W                                No match
, H! e* j8 ~5 A: P* t8 _$ C" P  N! L# F) Z
Final flow: unchanged + q% \8 J. e! }% e, D2 R/ k
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 . z7 T  Y* F( Z  G' K
Datapath actions: drop! Q& q9 `: [$ K6 P2 W0 E; Y3 @+ w- M3 c1 ]

9 w9 F7 O' @! o4 P  x. y; Z发现也在table 10中找到了记录
, @8 Y5 o$ i4 r0 o3 W' {
/ f$ d# M, {7 o+ n9 }. R( c实现第五个table 4: Output Processing: Q' _' ^8 R9 Z; {: l- Z1 ?

$ N# D& H" M0 _: [* Q7 [" f# `, T1 S这个时候,register 0中包含了output port,如果是0则说明是flood。
' u5 e' g2 y* T. X$ ^
6 a& L7 h/ n# I; j) S对于port 1来讲,是trunk port,所以携带的vlan tag就让他带着,从port 1出去。
  A' _4 E* ]  D$ q% A  |
$ U6 A$ |. T2 ~' Gsudo ovs-ofctl add-flow helloworld "table=4 reg0=1 actions=1"
+ e" ^6 t) i( A4 H# c) T- N  ?: C- G0 w
对于port 2来讲,是vlan 20的,然而出去的时候,vlan tag会被抹掉,从port 2发出去2 o6 E7 w! T' t4 C& Z8 S: q
0 I1 @: B1 y8 W& \, w
对于port 3, 4来讲,是vlan 30的,然而出去的时候,vlan tag会被抹掉,从port 3, 4出去
7 W" U4 O/ u0 B, h' T6 U: M0 Y: a6 ~0 {) s' ?
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   4 F5 [/ c. l/ R! V$ r/ P' m6 Q
        table=4 reg0=2 actions=strip_vlan,2 ; Y" i9 A; }7 p. P4 a6 c* F
        table=4 reg0=3 actions=strip_vlan,3
9 J8 Z( _( Q' B5 m7 p        table=4 reg0=4 actions=strip_vlan,4
7 N# c; x9 \: o, @6 vEOF
% l/ }' H6 p5 l* w% S5 }) l5 ?$ l  j0 _4 ]0 K  `/ K$ v5 x
对于broadcast来讲,我们希望一个vlan的broadcast仅仅在这个vlan里面发送,不影响其他的vlan。3 S8 ^6 m8 H. {4 k4 e  z6 `
, b( U3 E. h* P  C1 q9 I7 U
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   * q2 q. c* y5 f" k- V
        table=4 reg0=0 priority=99 dl_vlan=20 actions=1,strip_vlan,2 * o/ N* W( ~7 i; T1 H% B
        table=4 reg0=0 priority=99 dl_vlan=30 actions=1,strip_vlan,3,4
5 P2 _# [2 Y' I5 R/ f, N        table=4 reg0=0 priority=50            actions=1 * U3 i* j+ v7 R% f3 w2 V8 A% H
EOF: o0 m( L7 b) `  U1 J- f; `
2 _1 g9 Z- D: p9 w* b
所以对于register = 0的,也即是broadcast的,属于vlan 20的,则从port 1, 2出去,属于vlan 30的,则从port 1, 3, 4出去。' U! M5 g4 j" h% L9 `9 ~
7 q0 Z  q+ I8 H- @& d; o8 k
$ sudo ovs-ofctl dump-flows helloworld : u$ E+ O0 |& G. z* D+ L" e3 J
NXST_FLOW reply (xid=0x4):
: U0 K/ y" l7 b% dcookie=0x0, duration=92909.119s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
) @, E7 Q( p0 _) y# F+ Scookie=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
' C9 d. J8 g/ @1 V& o6 |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 : J8 w7 e  W5 i6 }- j
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)
8 k: \' t: l/ g) V% ]* ]( V( Icookie=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) " g* d* `' R: ]
cookie=0x0, duration=88519.81s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) ! D9 x8 c1 K; a: X6 u' T) m' S9 ^; ]
cookie=0x0, duration=88650.855s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2)
: G9 Y" r$ a6 I$ j8 j& ncookie=0x0, duration=88729.276s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop $ ]9 W/ d9 p% @
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)   A+ E6 J- L, ?  E& F- o
cookie=0x0, duration=1673.508s, table=3, n_packets=0, n_bytes=0, idle_age=1673, priority=50 actions=resubmit(,10),resubmit(,4) $ `* F7 U  y6 v* d- N2 \; z
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) 6 H2 g! a' C8 s0 `' ~; [
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x3 actions=strip_vlan,output:3 8 c1 }" O1 t  q/ o# d
cookie=0x0, duration=228.839s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=50,reg0=0x0 actions=output:1 & K6 Z5 Z3 r4 i9 m
cookie=0x0, duration=483.068s, table=4, n_packets=0, n_bytes=0, idle_age=483, reg0=0x1 actions=output:1
3 L( X8 m/ `1 H& `7 v2 ucookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x4 actions=strip_vlan,output:4 7 [# t) [$ o* r+ W9 Z: e0 T0 f
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x2 actions=strip_vlan,output:2
, J" k5 h3 s: @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 ) |  D2 i: [: w8 C. M2 O7 ~( u
cookie=0x0, duration=228.84s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=99,reg0=0x0,dl_vlan=20 actions=output:1,strip_vlan,output:2
1 x4 n: o* |0 G. G. \6 R8 U/ _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] 3 T: H- h0 {, p) h! e
cookie=0x0, duration=2090.451s, table=10, n_packets=0, n_bytes=0, idle_age=2090, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:02 actions=load:0x2->NXM_NX_REG0[0..15] % O  B! [! m( x3 G. l7 S' D+ l& D% p
cookie=0x0, duration=1258.881s, table=10, n_packets=0, n_bytes=0, idle_age=1258, vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01 actions=load:0x2->NXM_NX_REG0[0..15] 2 p7 B0 d% b. h* z3 Y) f+ m
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]8 o) G" }( e# P- e6 v9 i" u
, }0 B/ a9 y. ?) J
首先来测试一个multicast和broadcast  f+ o( O: Z0 `, g& u" ^! ~9 n1 H
0 K; y8 _2 j( L4 T1 s
如果是一个port 1来的vlan 30的broadcast
# j; D8 v( J/ w- g. B+ S; [7 ~& R1 t- j: X' Q6 u  O& t& U. F8 ?
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=ff:ff:ff:ff:ff:ff,dl_vlan=30
: G" Z2 {7 r  j7 y  f% [! H' bFlow: 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 9 n3 L+ E& X/ T/ l
Rule: table=0 cookie=0 priority=0
2 G% s5 x$ k* I$ g- e4 R8 H* BOpenFlow actions=resubmit(,1)
5 D# d7 i3 R, A* i5 y: J% u0 |! U. @3 l2 G1 z
        Resubmitted flow: unchanged & l  E* Y0 w, v$ V( }
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ( @4 s/ \& p6 f
        Resubmitted  odp: drop
7 e2 l# s, Z- J2 R% `        Rule: table=1 cookie=0 priority=99,in_port=1
) x& t5 ?+ _9 |& G5 z9 d" L$ ~        OpenFlow actions=resubmit(,2)
0 R, P: Q) \/ T+ Z( [
( D- s& f9 o  X8 b8 {# [. `                Resubmitted flow: unchanged
/ d9 T; l5 j9 ~: m- H0 t# Z                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 6 V. _, m4 W& O* ^0 j
                Resubmitted  odp: drop & c  V# v2 z4 T% }- ~$ \2 F
                Rule: table=2 cookie=0 ; }8 n+ L4 h- k7 c' w2 y* v
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
; h; k3 b. d3 R& M1 s. P" e9 ?) b- c) Z/ s& T& X( H1 D" ]) r
                        Resubmitted flow: unchanged 8 |, p& `! {' g) F
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
% v/ d6 ~8 p( L8 Z+ L& [5 r' X2 r- j                        Resubmitted  odp: drop   ~8 S; \. a( ~) P! I% e- Y
                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00   [, e) m0 T0 @9 `
                        OpenFlow actions=resubmit(,4). \; s# o' w0 f8 _- d% W+ p

* k% H3 [9 z% R8 ]" u                                Resubmitted flow: unchanged # o% f, W, z. l/ r& s8 n
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 5 S& v2 t0 [) h  \4 O$ a
                                Resubmitted  odp: drop
' y) ]2 [5 _9 Z4 |% ~% W, `5 E                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 7 z! g5 G* }9 d' i
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
1 o6 P% q& b* y                                skipping output to input port
0 z( m& x6 z/ a$ K2 J9 K; O' L( N2 x
0 d" l9 {( _5 R( F9 t& XFinal 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 5 Y. u, s* X1 x8 Q! w5 @9 e
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
" d- w' E0 q' [1 P' l! s% ]Datapath actions: pop_vlan,12,13: a/ X) N0 k4 i0 ]# I( M
7 e5 a( d. n% L  r  L5 v) A6 B& O
结果是port 1就不发送了,发送给了port 3, 47 F! U. D6 k$ i! y3 j
& h! _, ]8 g( d
$ sudo ovs-appctl ofproto/trace helloworld in_port=3,dl_dst=ff:ff:ff:ff:ff:ff
! U; Q# |1 Z5 X" aFlow: 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
) u; Z4 J  `; J* n9 B/ `2 zRule: table=0 cookie=0 priority=0 " b0 W& }* \- [" D4 D
OpenFlow actions=resubmit(,1)- L7 ^. w- H! F) \5 _) B

8 f; V- B. ~/ G& N( {8 o/ z* z! v        Resubmitted flow: unchanged 7 g8 `5 j9 E$ z9 S" g8 ~. c
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
6 ?3 c2 l+ \/ M( g  |        Resubmitted  odp: drop 2 c2 }/ j/ ?' |5 @
        Rule: table=1 cookie=0 priority=99,in_port=3,vlan_tci=0x0000 5 \* j3 W. [/ e* e1 W
        OpenFlow actions=mod_vlan_vid:30,resubmit(,2). s1 u6 w, Q( ~- `/ u+ T3 G

. a: f3 ~4 s# k8 t+ _                Resubmitted flow: metadata=0,in_port=3,dl_vlan=30,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000 : D0 p3 C1 |$ q  w8 r' M, l+ W
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 H# R1 M. Q% I4 w
                Resubmitted  odp: drop ; H$ p/ J/ W: v, p
                Rule: table=2 cookie=0 # R& ~% f, w( {- Y2 P* o/ 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)
) U+ m" R0 ~/ a- x( s; ~/ w( y
) R! ^) q& R# s' N% q3 r' y2 b: v                        Resubmitted flow: unchanged ( S  c9 O8 D& b" `
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 5 u. S) ?+ K& k' t; d3 M
                        Resubmitted  odp: drop - B4 {0 x  e7 F) D3 Y/ F
                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00
8 Y% m9 p+ d6 ]1 C                        OpenFlow actions=resubmit(,4)
) y5 @8 }/ z: y' ?! m' v
5 e, _* F8 |9 y( ]$ X: e, S                                Resubmitted flow: unchanged 5 N" T) O  s" Q8 I9 |2 E0 R
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 , X* g1 U* A$ p6 x( Q- l% B
                                Resubmitted  odp: drop 6 X, u. X- D; ~1 m+ v" e# W5 t
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
1 }* P' M% ?. Y( d+ P                                OpenFlow actions=output:1,strip_vlan,output:3,output:4 : u' ~3 y5 E/ ~
                                skipping output to input port
1 `( |) Z; M1 j9 J
- g  z# C7 {: E$ LFinal 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 : E5 h5 R% @$ c3 ^0 `
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 7 F. K4 ^3 ?' C, O) m
Datapath actions: push_vlan(vid=30,pcp=0),10,pop_vlan,139 f  D# b( [! Z  I2 _
, |) C" B: Z7 {. Y% {
接着我们测试mac learning
: j2 y! o" b  p) q6 r5 j
* A( w0 H4 z% c) `; n+ A$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=30,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01 -generate   
% w5 D' M! }! C/ y3 o1 y9 r3 T- N6 rFlow: 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 ( W( c% z: e6 N7 |! i% K8 m
Rule: table=0 cookie=0 priority=0 2 u( k: _3 W1 E! Y6 G2 R& J. v* q
OpenFlow actions=resubmit(,1)8 d; }2 z1 J1 D, X# B  ?

1 B5 Q, t# K! A7 Z( z        Resubmitted flow: unchanged   B1 p0 r$ a, T3 m6 p1 |- H$ P
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 4 _8 w4 {  u, E* j! R8 _" k
        Resubmitted  odp: drop , `: ?9 g+ k+ F' n
        Rule: table=1 cookie=0 priority=99,in_port=1 ) }* p& v& |  N8 |* l9 F$ ~; K
        OpenFlow actions=resubmit(,2)! c' F4 |5 A, s3 O. U

$ J; ?9 j& j# P                Resubmitted flow: unchanged
  y9 c7 N4 \" R% M                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 $ g0 _, n; b  H# z( l
                Resubmitted  odp: drop - J3 L3 W$ T9 J4 B: B
                Rule: table=2 cookie=0
' `$ E/ J' U8 ~1 c7 o7 {                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 ?9 n/ X! i' Q, ?! S8 q8 U
4 ^" A7 Y8 s# C2 K! l2 W! ~                        Resubmitted flow: unchanged - c9 Q. ?2 I& P; j
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
4 }; r9 w0 P$ Q# }% t2 Z                        Resubmitted  odp: drop ( q7 N6 D1 Z8 w3 Y: w
                        Rule: table=3 cookie=0 priority=50
, x1 V; n9 S# q! s                        OpenFlow actions=resubmit(,10),resubmit(,4)
3 f% Y; _  [$ D! A! K; C5 N2 \
3 p% v$ l8 Y7 F. H' \                                Resubmitted flow: unchanged - s4 O$ v$ ?5 |( ~. f( q% V: A
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
0 C5 ]* u4 t! k8 S1 n; B9 t: \                                Resubmitted  odp: drop
3 E3 d1 S/ \2 v. q                                No match
. l* Z% _+ @7 ]% x* b: L% B+ J6 V0 }
                                Resubmitted flow: unchanged
. s0 ~1 \% B* L5 T* M$ B8 t: t" G. j                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 1 g0 R8 b  `1 O, S8 ]
                                Resubmitted  odp: drop 7 o' d' i( C! i" I- r* i1 a6 }
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
0 J, k6 a! W+ O5 n+ d8 W1 q# n) K                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
* c! D; H# \1 I) p9 d% x) {                                skipping output to input port
- C  t' E* u. q- P( N3 C
0 C7 R( q/ g% QFinal 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
* z; Y" s. b- P' r. U1 |: aRelevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000,nw_frag=no 6 Q' l8 ^* @+ G+ L# z! t" ~
Datapath actions: pop_vlan,12,13
0 |8 ?# a1 F, s( Z' m- u% z8 S" c( {( \( v+ d7 q( S2 ]
由于这两个地址没有出现过,则除了进行学习以外,广播发送给port 3,4+ C& d+ u; {0 ~
$ F! w0 m3 X/ [5 e# O) f
$ sudo ovs-appctl ofproto/trace helloworld in_port=4,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01 -generate   
( \8 t: p9 H( c. i2 W: k1 k; PFlow: 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
% S! Z. p& u" d+ s. ]Rule: table=0 cookie=0 priority=0 / F* e  K' x# p5 {$ N3 t+ O
OpenFlow actions=resubmit(,1)
6 ?' F4 Q7 l" U; T; }; _+ x8 c/ L, q/ }
        Resubmitted flow: unchanged
9 Y. C' T3 }2 v( G  F: n0 E        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 4 ]+ r5 y" A0 K2 p
        Resubmitted  odp: drop 0 H& a0 I8 b! \+ C! j) z
        Rule: table=1 cookie=0 priority=99,in_port=4,vlan_tci=0x0000
# ^( I" c5 V' y        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)  y' Y: A' Z8 R3 G+ w

6 E0 V  {- I1 C4 V- a* e% I                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
0 J; \1 k" f" O) V. C' a$ o                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
5 D" n7 [3 f) q5 \5 D( K                Resubmitted  odp: drop 2 D% n, C7 F( C! Q- U- {  L8 `
                Rule: table=2 cookie=0
2 b) o/ ^0 O/ X3 W2 X9 G4 g& v* F& T                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 R) b3 s' K: |* L
( _3 C( G1 o  k' @. \
                        Resubmitted flow: unchanged
6 K" W: L* g/ {5 H# \, @                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & Q7 O! G8 |$ p
                        Resubmitted  odp: drop
( y! G1 e) j" n+ A7 l                        Rule: table=3 cookie=0 priority=50
% ], O, N9 D) \" n' U7 Y( I% q                        OpenFlow actions=resubmit(,10),resubmit(,4)/ B7 Y# \- B  V. d- t& H6 F

9 S: O- a& O! l$ b7 |' i                                Resubmitted flow: unchanged
7 ]2 p7 i) u; f+ t                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! t) D: \1 r2 @8 v) E
                                Resubmitted  odp: drop
: Q0 G( \$ X( `' Q8 [& V! R                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=10:00:00:00:00:01 - J5 V/ ?5 l. N
                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]
2 Q8 j* [: N2 H0 r% T; F( w1 Z$ O
' l2 \$ q' n" w$ Z( `% Z( v3 T                                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
* _) p6 a4 `) _, G6 [% c6 Z! K7 k                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 + Q( }: n+ d+ C" a% A/ u; M
                                Resubmitted  odp: drop ( z; x; y% q/ Q2 P; U: N8 V! }: u
                                Rule: table=4 cookie=0 reg0=0x1 8 M  O% G6 Y6 F6 J% H, }8 c# U( d
                                OpenFlow actions=output:19 V3 f! K" `6 w/ k0 Z0 h

* H. u! k2 q9 d/ M: C) a+ z6 |Final flow: unchanged
* d5 o0 N$ _: RRelevant 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 . _% P/ M8 H. g2 k
Datapath actions: push_vlan(vid=30,pcp=0),10
) U) Q6 U% t3 B2 a9 k! O! S1 L, t9 q9 j- W
回复的时候,由于学习过了,则仅仅从port 1发送出去。
5 K, H9 Y8 x6 w  C' m* A$ z+ q5 S* l
- a: |+ p, M" h* r9 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
1 n- L3 k! S  |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
6 G4 s, Z- F1 u' x# wRule: table=0 cookie=0 priority=0 ) ^* A' z  S$ _6 \4 u+ E
OpenFlow actions=resubmit(,1)5 n' Z) F$ p9 l
, w! k# p6 v8 r0 s
        Resubmitted flow: unchanged
( `* B- y$ ?. i# @6 ?- j( @6 @        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
  w, a+ u- |1 ?, F0 M        Resubmitted  odp: drop + h' c. ]5 ?( \+ X
        Rule: table=1 cookie=0 priority=99,in_port=1
2 }3 T/ Y# E" n        OpenFlow actions=resubmit(,2)2 W9 q% E. Y4 f, U' p2 c8 B

( `* j4 E9 U# j+ |$ S4 ^                Resubmitted flow: unchanged : N3 O( |$ c5 D
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & o% ^) U; p  E3 R
                Resubmitted  odp: drop 0 z5 M6 \( a7 D+ |1 {
                Rule: table=2 cookie=0
* v/ b4 [% Y, q: p                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
8 L2 W( }) r6 y7 B" b) T
( K, R- v$ C# U7 i, v  x                        Resubmitted flow: unchanged 1 n/ _$ \9 j2 @* {% {
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 * U# Z6 J  s0 ]  ~
                        Resubmitted  odp: drop + D5 y1 `3 t' Y# y7 b
                        Rule: table=3 cookie=0 priority=50
; G9 z) |9 D+ J1 G2 Q, |                        OpenFlow actions=resubmit(,10),resubmit(,4)
) O  }$ z4 Q$ H& _0 [5 ?- T+ _. N2 I3 t3 m
                                Resubmitted flow: unchanged ' S- F5 E; X# o5 j5 d
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
% x" X/ X4 j7 j, `                                Resubmitted  odp: drop
8 ?4 \* v5 ^1 S$ w1 W                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=20:00:00:00:00:01
) \# B0 C# K5 B2 E. Q8 r                                OpenFlow actions=load:0x4->NXM_NX_REG0[0..15]# f- j& X- k4 n- O1 D+ [
" }5 g  `4 u8 u, T: Z. 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
1 K$ I; I+ A: z0 i  B6 e                                Resubmitted regs: reg0=0x4 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
& g8 Y! I' \% ]1 ?! e8 c+ {                                Resubmitted  odp: drop & P/ M, |9 W2 ~- E7 B
                                Rule: table=4 cookie=0 reg0=0x4
/ s8 c; f) L  i. n. q# B/ M# J& \                                OpenFlow actions=strip_vlan,output:4
- H* J% q( Q& a8 k0 C; g9 R' @' X) g7 r0 @
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
  B5 ]4 G/ d8 J$ h* m0 cRelevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000,nw_frag=no
6 F6 G4 J/ t4 O; W3 h* }# _Datapath actions: pop_vlan,13
9 R/ z3 L7 y! g3 I; Q6 A2 ~3 t# A+ E7 d# b1 n5 @; a  Z2 h
由于在回复中进行了学习,因而发送的时候,仅仅发送port 4
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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