易陆发现互联网技术论坛

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

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

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

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

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

x
ovs-ofctl dump-ports 输出交换机的端口统计信息,包括收发包、丢包、错误包等数量。 ovs-ofctl dump-flows alubr0  ( N0 U$ j7 [" ^, F. R
OFPST_FLOW reply (xid=0x2): flags=[more]! J- O4 r/ f, H4 o1 _6 p& Z
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[
5 M$ s7 _2 K! J" S0..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[],re4 C+ T0 n: V$ l6 v" T
submit(,4)4 E) n9 c0 [" @
cookie=0x1, duration=1263.439s, table=4, n_packets=36175, n_bytes=26587191, priority=0 actions=resubmit(,27)) i0 A; B$ w. E8 B' O' `6 [( h
cookie=0x1, duration=1263.439s, table=5, n_packets=35646, n_bytes=26564073, priority=0 actions=resubmit(,7)6 s3 i) o  V5 e6 `# t% {4 u
cookie=0x1, duration=1193.636s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=18038,dl_src=fa:16:3e:83:4c:69 actions=drop
4 g# _" b% s4 a3 U 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=drop2 U" s" Y  u# S, G: @
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=drop9 `$ D0 s% i1 ]: w+ Z1 k
cookie=0x1, duration=1176.930s, table=7, n_packets=522, n_bytes=21924, priority=32769,in_port=21588,dl_src=fa:16:3e:f7:f2:b0 action
7 y' R3 [2 l& [. Q0 U9 Z9 Es=drop# K' W- w7 w; w; J# V
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
5 I" e! M4 ]* N% Y4 O* d( N* E cookie=0x1, duration=1197.461s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=29064,dl_src=fa:16:3e:82:2c:2c actions=drop) a3 Z( `, m& o( q
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=drop4 ^; M! H+ B$ V4 h
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+ y2 M+ e' c2 [0 n
cookie=0x1, duration=1198.286s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=19360,dl_src=fa:16:3e:95:46:90 actions=drop
9 D1 p$ j: D+ z  N8 H6 c& r8 k$ N 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=5 A! L2 X; N+ ~) j; c3 E
drop/ Z& i1 S) i5 w/ o. j' ?
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
, y) h/ e; N" S- S 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=dr3 K! e4 ]1 n% E# T, D* ~+ Z: H
op
! N/ x6 }7 q4 x" I- y0 U3 U  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- Z% i( D3 M8 u8 m7 e- ?
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$ W) v8 @* A" d, `% ?
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
' O2 V9 Y  w" ?8 M6 }% I 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=! @7 w; \7 H% U( g7 b
drop# m5 n+ L8 z* s! c$ O, w$ s" u
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' g+ I" U& h3 o* i/ c3 y1 e8 g2 r
cookie=0x1, duration=1210.767s, table=7, n_packets=8553, n_bytes=549905, priority=32769,in_port=526,dl_src=fa:16:3e:62:2a:1b action
7 R. t) C2 u8 r& g. I' m: qs=drop
& l8 }: P( h5 Y4 U8 q& j* C; o6 T 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$ P9 L5 I: P6 ], |5 \. |
p. \; S. w  N' m# O7 Y
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
7 U( g$ Z# c8 `' a0 F6 O( g' e
2 v$ N: G- m6 M' O
3 l2 P: L- a) s如果设为fail-secure mode,则初始情况下flow table是空的,否则会有normal$ sudo ovs-vsctl add-br helloworld1
+ _- P1 X5 ~" E/ Z, k$ sudo ovs-ofctl show helloworld1
+ G, z) m+ q# S) j3 ~$ sudo ovs-ofctl dump-flows helloworld1 : g  \! G; K- [9 N0 K1 `
NXST_FLOW reply (xid=0x4):
! F! w" S. z0 ]# Y% i3 K$ \cookie=0x0, duration=31.467s, table=0, n_packets=8, n_bytes=648, idle_age=21, priority=0 actions=NORMAL接下来,创建四个veth pairsudo ip link add first_br type veth peer name first_if 6 F- u) S% D- a% ?" P
sudo ip link add second_br type veth peer name second_if   
. e; l2 X* I% J% d2 K; m6 Q0 q1 isudo ip link add third_br type veth peer name third_if       0 s0 R; s7 u: G" V2 _/ |8 f" Q& ~
sudo ip link add forth_br type veth peer name forth_ifxxx_br将是添加到bridge上的。我们添加四个端口portsudo ovs-vsctl add-port helloworld first_br -- set Interface first_br ofport_request=1
  t- [- K/ I% h% c% L: Q1 _6 ~  Ssudo ovs-vsctl add-port helloworld second_br -- set Interface second_br ofport_request=2
* U0 K) G  q7 Q$ o9 R3 \sudo ovs-vsctl add-port helloworld third_br -- set Interface third_br ofport_request=3 * O: r6 |6 D7 E/ N- L" R6 s
sudo ovs-vsctl add-port helloworld forth_br -- set Interface forth_br ofport_request=4ofport_request是指定端口号新添加的port都是出于DOWN的状态1 f9 c) b6 @: \
 楼主| 发表于 2019-10-25 10:00:34 | 显示全部楼层
把它们设为UP5 @! g( s: H2 d9 _
, p' L. }4 s( b1 `5 g
sudo ip link set first_if up
$ C( Y; z& ?$ Zsudo ip link set first_br up " c  a+ s. R  Z+ n! e
sudo ip link set second_br up     
! a, O1 W5 y' i' M$ [sudo ip link set second_if up ' b2 R% {" c5 t: b
sudo ip link set third_if up        l0 M6 q* y% e
sudo ip link set third_br up     
) ], e4 {8 i. ]% M& A" Osudo ip link set forth_br up         
# ~% {# b( y' X' c9 e% i2 Q4 k% |sudo ip link set forth_if up& c' n. d: G" s' B

0 z6 @* _3 D/ Q4 q也可以用下面的命令
* U- V  i; A1 M' E9 r4 D8 [- N/ Q
ovs-ofctl mod-port helloworld first_br up
 楼主| 发表于 2019-10-25 10:00:35 | 显示全部楼层
实现第一个Table 0,Admission control% D3 r- [" L. e# E2 N" D0 q0 k
8 `. F1 F& q5 Q  D* {5 u  o
包进入vswitch的时候首先进入Table 0,我们在这里可以设定规则,控制那些包可以进入,那些包不可以进入。
% P' i8 N- I9 t( E! L$ ?) p( c% \; X6 I9 U
比如,如果source address是multicast的就不允许进入。* @; }$ t$ \2 h& Y, G. Z

  i, f. S( N. d- q8 ]: P01:00:00:00:00:00/01:00:00:00:00:00是广播地址
" G0 O: w7 i, I+ U* S. C! v& Y00:00:00:00:00:00/01:00:00:00:00:00是单播地址4 y: d, E: |7 U+ m: P5 s: D
这种表示形式类似CIDR$ F; F' k' ]5 ^
于是我们添加下面的规则:
2 h8 i3 n( r* Usudo ovs-ofctl add-flow helloworld "table=0, dl_src=01:00:00:00:00:00/01:00:00:00:00:00, actions=drop"2 C8 i( z0 U; b% k9 ]) G5 L
STP的也不接受
" `. Q: h9 {; fsudo ovs-ofctl add-flow helloworld "table=0, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0, actions=drop"
( q+ |- x, B( o我们在添加最后一个flow,这个flow的priority低于default,如果上面两个不匹配,则我们进入table 1
3 ]# c, i- J4 x5 S! p3 e; [8 U. isudo ovs-ofctl add-flow helloworld "table=0, priority=0, actions=resubmit(,1)"
- |" c  S& ]  R6 o我们查看一下所有的flow2 Z* g9 G1 t1 z0 n! v% W
$ sudo ovs-ofctl dump-flows helloworld        4 l6 s) X$ G% I$ g5 N
NXST_FLOW reply (xid=0x4): + W5 ]" a& p0 |: Q
cookie=0x0, duration=42.162s, table=0, n_packets=0, n_bytes=0, idle_age=42, priority=0 actions=resubmit(,1) 7 x6 I7 V3 M) Z
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
# n" t/ o9 C! k7 P" ^/ _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=drop7 l3 u4 C; u$ Z  K+ d, w0 ]

1 O" S+ E% q1 Z# [* S测试Table 0
+ X4 n$ J" W' Q+ w8 c  J' ?8 z# A( W& N- e& e& W; m7 l6 ~
有个很好的工具ovs-appctl ofproto/trace/ x3 G4 C# w" e# g$ O

$ w: H4 M3 v7 R4 D$ Y' g8 H不满足条件DROP4 f  f' W$ X& \, |3 P# b
5 S7 n# v& e4 j) C: m. s
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:05
2 T, u% n$ P3 ~% LFlow: 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
$ Q- a( H, S4 j  uRule: table=0 cookie=0 dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 " T8 H) r/ t( z/ l4 I7 P. ~
OpenFlow actions=drop& {' Z: M( I! a* W
4 V2 d! y/ m4 c8 j; a; Q  z8 n
Final flow: unchanged
7 _; m- w5 V3 Q4 `. h* oRelevant 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
# B1 q& R  e7 f8 m+ h3 Z* D5 J8 q) LDatapath actions: drop' L  s; p' v% a

% v% S4 K% q9 L: A2 o& }3 E满足条件RESUBMIT5 [/ P5 S  z$ ]
) S1 I6 a. J; u
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:10 . a/ {3 N: a. [6 B/ x$ v
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
( f# g3 U2 x- ?3 j1 T7 N' oRule: table=0 cookie=0 priority=0
. l0 M& w9 d1 |0 M: MOpenFlow actions=resubmit(,1)
( B, v. F; A0 G$ A+ }3 j, A( r* b6 c: s
        Resubmitted flow: unchanged
3 q( o$ P# N  i6 ^" Q* R- T$ A) A  b7 _        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 - J5 g) J0 O. q5 U& C% H, f
        Resubmitted  odp: drop ' s& Q' S; j# W: w
        No match- z: h: D3 u1 t+ G2 o
3 S" B# R8 l5 G/ w
Final flow: unchanged
7 H& G* W8 Q9 w; z; G' lRelevant fields: skb_priority=0,in_port=1,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=01:80:c2:00:00:10/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
# `3 t3 w2 n& _0 fDatapath actions: drop
. z5 U5 h# A2 S0 M/ ]
* y" _+ Q' @7 P" U; h. P实现第二个Table 1:VLAN Input Processing! P: U) W' J( F1 a/ z( G. q3 c* i, F

9 h5 D+ u7 O  F3 M9 p4 e: N/ g首先添加一个最低优先级的DROP的规则
& S  k% q0 O# l
1 b1 O& P2 {8 nsudo ovs-ofctl add-flow helloworld "table=1, priority=0, actions=drop"
+ p1 j8 K. _1 {3 W& t2 c0 O7 Z5 K; |8 Y& f$ p' ]' Z* N. Y! `
对于port 1,是trunk口,无论有没有VLAN Header都接受。+ N8 s$ M$ D. k3 ^/ N+ L
- x& d# q( s) I( S, w$ ]( E, b7 @
sudo ovs-ofctl add-flow helloworld "table=1, priority=99, in_port=1, actions=resubmit(,2)"
0 N" B: h  Q/ O7 |9 D: V
" |2 K8 k6 |) m) g对于port 2, 3, 4, 我们希望没有VLAN Tag,然后我们给打上VLAN Tag
) W! F7 Y6 N) |1 o# S3 G, D- V6 E) ]" J! P4 P
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'
) g1 k7 K( G6 m( E# p' P, |; i  Ntable=1, priority=99, in_port=2, vlan_tci=0, actions=mod_vlan_vid:20, resubmit(,2)
, l6 ^# N# X; V' I( i7 \: M6 ctable=1, priority=99, in_port=3, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2) ( f- d' h* F( ^( D3 ~
table=1, priority=99, in_port=4, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2)
8 o5 [$ o4 L4 P: A) z( Q; q/ ^EOF
) }  p, U, r& [3 F) C* _* i2 Q, f  [* C6 f4 V
$ sudo ovs-ofctl dump-flows helloworld 3 }8 K" Q4 k$ |, {, Y
NXST_FLOW reply (xid=0x4): : p* \; P2 |: O! {( G* P6 e( d; Y
cookie=0x0, duration=4478.582s, table=0, n_packets=0, n_bytes=0, idle_age=4478, priority=0 actions=resubmit(,1)
5 z4 N9 S2 U0 q! i- Vcookie=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
7 }& e6 `6 ?' h- s# J" _8 \% J! acookie=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 , K+ T, }: X7 @- c( t+ i
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) . Y: @2 i2 T( f' R' Z7 r
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)
" X; `' s* N, r, \1 Ycookie=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) 7 c/ H* s4 I# ]) S( e
cookie=0x0, duration=220.318s, table=1, n_packets=0, n_bytes=0, idle_age=220, priority=99,in_port=1 actions=resubmit(,2)
# s& p/ |* i1 M; e0 fcookie=0x0, duration=298.739s, table=1, n_packets=0, n_bytes=0, idle_age=298, priority=0 actions=drop
" ~: d6 i2 v, K# J7 X) W$ Z  L6 c
9 t5 A8 @- v+ h9 Y测试一个从port 1进入,tag为5的
. c$ P* T2 U0 F
' m- T& {2 F% `5 {8 N$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=5
' P, [% A# r( ?* m' ?% Q" KFlow: 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
+ a9 k0 e8 k" i$ A5 p- oRule: table=0 cookie=0 priority=0 2 Q8 n7 [2 G2 v3 B0 j
OpenFlow actions=resubmit(,1)
4 Z7 ^3 _* f3 _" e5 X& t$ O' G! K( ^6 y- E% I: D/ k; F) D
        Resubmitted flow: unchanged
0 e. O8 t# v9 \; I        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 . L% J3 Q& }$ Y6 M- E5 U
        Resubmitted  odp: drop
" f4 N& v2 v+ |3 q4 g6 P9 M        Rule: table=1 cookie=0 priority=99,in_port=1
* D3 C3 p, j3 x. t8 M1 }- ^; i2 H        OpenFlow actions=resubmit(,2)
% C3 `4 Q2 x# X; r( M1 Q- Q  O3 A  G! s# a6 U
                Resubmitted flow: unchanged # u, I' B1 R# d% \. ]* j
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
& \' P( D- t( O8 x                Resubmitted  odp: drop 8 i2 ~, ~1 l$ l: X# V/ `
                No match8 e9 b3 k/ K4 N( D
" b; }8 \" |* K, x: f. a/ L0 P- S# t
Final flow: unchanged
9 J4 Q- P0 X+ J1 z: n+ `6 f8 vRelevant 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
! ]6 G' X, n. a+ N6 R$ U+ ?& C- m& P: }Datapath actions: drop" }6 J/ R$ U0 e& d
  `- Q4 n; U/ J. S
测试二,从port 2进入,没有打Tag的
" w  ~0 G2 @) y/ e0 U4 S- ~8 r5 Q) x8 ?, _' p
$ sudo ovs-appctl ofproto/trace helloworld in_port=2 / J1 C% d- ^: Y: J
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& G" n+ e/ H; n" [# N6 VRule: table=0 cookie=0 priority=0
7 L  ?' w% `# P' x3 t" o3 ~OpenFlow actions=resubmit(,1)
8 h& }  c1 [) u: N& K' V4 X# q( q; v& S) Z
        Resubmitted flow: unchanged
, O  {% u( g0 r" @/ U& Q2 ^        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 - @) E  v' c4 [
        Resubmitted  odp: drop
! G/ q/ y& J' k' B% n        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
  H# B4 Q+ d% N& J* Z        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)% j, [" N  ?* W8 |. F) E: g2 i

% |4 i$ e8 r; h4 n+ V$ _) y9 j                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
" c  |; H4 l9 {  g  P                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 7 l' f$ u( p6 z2 y9 z
                Resubmitted  odp: drop ' c. P. i9 ]0 j. w
                No match
: x) ^! c& `6 [2 H. P* e2 C- x& U: u8 `6 x* L4 x5 K
Final flow: unchanged 1 P4 z' V9 N8 \" i2 P1 Z8 @
Relevant fields: skb_priority=0,in_port=2,vlan_tci=0x0000,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no 7 r0 L) X2 P8 S% a( W
Datapath actions: drop
" v2 y* P! Q6 {0 |" V4 U, e$ y+ M, X3 n
测试三:从port进入,带Tag 5的3 G8 q+ a$ K& |/ X6 _; |
3 j0 s) h9 w) I
$ sudo ovs-appctl ofproto/trace helloworld in_port=2,vlan_tci=5 4 b# O4 r8 K7 v5 l2 e* H: s& b
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 , n2 n8 ?8 e- k7 v2 [' B4 {
Rule: table=0 cookie=0 priority=0
6 }- h5 P6 ]; |$ f& ]7 F, yOpenFlow actions=resubmit(,1)4 U* J" p" O0 }
/ m% ?& M& H* D- t
        Resubmitted flow: unchanged & t" j+ L0 T3 {# a- ]. C8 e  M3 K$ r
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & L9 o3 q: F( `% I
        Resubmitted  odp: drop
0 m; X# F! }. Q  ^6 w        Rule: table=1 cookie=0 priority=0
7 l0 q1 u9 N; h. |4 {1 [+ w* r        OpenFlow actions=drop' f, E# T: e8 O0 C  q( q
6 r4 H: q) t3 C* i6 T* H
Final flow: unchanged 8 B0 h' l9 H# k0 D- M6 |
Relevant fields: skb_priority=0,in_port=2,vlan_tci=0x0005,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
' E6 k1 K& [5 D& fDatapath actions: drop. O/ r! U8 _1 {8 O3 \. f

4 M( x8 R9 D  l: L实现第三个Table 2: MAC, VLAN learning for ingress port
/ W1 H3 d9 o, D4 e8 @2 ]/ X- |, ~, z; z. A5 _' n; V, v3 L7 y
对于普通的switch,都会有这个学习的过程,当一个包到来的时候,由于包里面有MAC,VLAN Tag,以及从哪个口进来的这个信息。于是switch学习后,维护了一个表格port –> MAC –> VLAN Tag。
8 V! o, U0 A: s/ D) k  J! h( |' _+ h+ K
这样以后如果有需要发给这个MAC的包,不用ARP,switch自然之道应该发给哪个port,应该打什么VLAN Tag。8 {' ~/ f" L' y% f

. ^  w8 H- X- ]% M3 lOVS也要学习这个,并维护三个之间的mapping关系。
3 a8 z6 t4 N& _; ^* v5 L' ~$ F  \/ n. Q, {  C3 V# D
在我们的例子中,无论是从port进来的本身就带Tag的,还是从port 2, 3, 4进来的后来被打上Tag的,都需要学习。
# |( q' Z3 z5 R+ c6 E% I' m
1 W3 W. y# M; [& \- {' Zsudo 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)", N2 K+ s7 Q8 A+ u
. C+ G7 F1 n5 Y# i2 }! T
这一句比较难理解。
- i* {7 }$ _: G9 X+ c$ @* ^
  c% S. p% X; g/ hlearn表示这是一个学习的action
# h0 T, m8 Q, u- L9 w4 W: }
2 ]$ y3 z# j+ J- A/ K; wtable 10,这是一个MAC learning table,学习的结果会放在这个table中。0 f# }4 c" L$ P0 v
1 C3 S: i1 F! g! x
NXM_OF_VLAN_TCI这个是VLAN Tag,在MAC Learning table中,每一个entry都是仅仅对某一个VLAN来说的,不同VLAN的learning table是分开的。在学习的结果的entry中,会标出这个entry是对于哪个VLAN的。4 l, W$ q2 G6 c3 M1 o7 N6 ]
4 @3 }* i3 f" x0 }
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里面,因为这是为发送用的。7 @. q7 Y2 Q, E/ P1 d
8 C- h2 z* H" b1 `3 u$ E- u( X( I  E
NXM_OF_IN_PORT[]->NXM_NX_REG0将portf放入register.
! t3 r9 ^! a1 ?- F$ t6 Z3 G7 w7 W4 R8 D* D+ j. o, r, O
一般对于学习的entry还需要有hard_timeout,这是的每个学习结果都会expire,需要重新学习。) p5 u6 J3 s& z( j% A6 P
& S3 h/ y6 @) a
我们再来分析一个实践中,openstack中使用openvswitch的情况,这是br-tun上的规则。+ x0 l# Y) M& A4 m
' w. P0 b1 j( `9 N0 r( L/ W. j5 D" b
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 ' P: Q" C1 {4 c! o8 ^
cookie=0x0, duration=802187.786s, table=20, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,21)
2 p) m; B* a( ~5 l5 M" l# Q; `( C. \ 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
" ]* V/ q& i9 {0 ^" [cookie=0x0, duration=802187.653s, table=21, n_packets=17, n_bytes=1426, idle_age=65534, hard_age=65534, priority=0 actions=drop
! l* V1 I3 [+ J# L0 Ocookie=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) U, N" T% \- o6 ^

" j2 I, W3 `8 K7 z这里table 10是用来学习的。table 20是learning table。如果table 20是空的,也即还没有学到什么,则会通过priority=0的规则resubmit到table 21.
6 X) M) b# A7 [' J3 c4 F& z$ F# X% v% B; U/ W: R. f
table 21是发送规则,将br-int上的vlan tag消除,然后打上gre tunnel的id。
% s0 u/ K8 w& `) w9 O! B1 ~+ {; Q* B; X$ x9 u
上面的情况中,table 20不是空的,也即发送给dl_dst=fa:16:3e:7e:ab:cc的包不用走默认规则,直接通过table 20就发送出去了。
% }# f8 _# W4 _" m, x) `+ n
2 ~) L) j; B5 V; Ytable 20的规则是通过table 10学习得到的,table 10是一个接受规则。最终output 1,发送给了br-int
) t# O5 Q% f5 r9 C4 M) ?3 P& G, S& m9 \
NXM_OF_VLAN_TCI[0..11]是记录vlan tag,所以学习结果中有dl_vlan=1
$ u* T( s5 e1 A$ [  \+ B8 _* m- z
, R( P1 E8 \: ~( s( ^. q% |NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]是将mac source address记录,所以结果中有dl_dst=fa:16:3e:7e:ab:cc
( |5 m7 \9 Q; j8 u% X' s: Y+ O+ ^. m: }' b, C1 b. R
load:0->NXM_OF_VLAN_TCI[]意思是发送出去的时候,vlan tag设为0,所以结果中有actions=strip_vlan4 X/ c/ X7 q. c$ e1 }% u! Q; d

; i" Y, Y$ q# l% ~# g; kload:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[]意思是发出去的时候,设置tunnul id,所以结果中有set_tunnel:0x3e9) N; U3 @9 @' H  v3 r  `1 M5 X3 v
6 r* z" b  `" `6 A0 e* ^- r
output:NXM_OF_IN_PORT[]意思是发送给哪个port,由于是从port2进来的,因而结果中有output:24 v. b2 P) I: g

' K" c8 F. z  v3 r! a1 \+ l测试一:从port 1来一个vlan为20的mac为50:00:00:00:00:01的包. E- W7 c& X. `8 N

, F$ q6 R9 C# ^" v# [6 e1 I$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=20,dl_src=50:00:00:00:00:01 -generate   - X+ o# W# x$ r, S8 q7 B3 N
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
6 t) i1 D1 l+ w0 i6 PRule: table=0 cookie=0 priority=0
% H4 c( O- H; ]1 y  E. b" ~  d9 ^8 `OpenFlow actions=resubmit(,1)+ d5 d( |/ j: [8 J' S4 i

+ @5 {. J( i/ t( @; Y& z" D% b; t        Resubmitted flow: unchanged
% N8 A: Q4 ]; Y7 R$ T5 v        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
% H8 S$ g3 |* O        Resubmitted  odp: drop ! D, K4 l( E5 t: k
        Rule: table=1 cookie=0 priority=99,in_port=1
& L/ M, f% ~/ |        OpenFlow actions=resubmit(,2)+ N- _8 F; K8 H/ s1 q
& {! x( Z$ T1 [! X4 c* \4 A
                Resubmitted flow: unchanged ! `' |; r* _5 ]' `: c) X0 F) A; z$ `4 u
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
8 y+ r" I. }3 p  }1 g) Q                Resubmitted  odp: drop * m, X4 W* i+ B* ]: Z
                Rule: table=2 cookie=0 + @. b* D1 ]; O' k! 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)
3 s$ x1 t& z6 l6 Y% K1 ]+ F
6 ^$ D) N% T. S  A: {6 Q3 ]1 O                        Resubmitted flow: unchanged 5 s2 N( c2 n* V3 h' v
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 / L! W- _6 n7 |' s. l* T: B6 [
                        Resubmitted  odp: drop % x3 B+ i2 @3 w: d7 R4 O  Q, h! B
                        No match
! B& M- W+ L* I7 y, _1 t0 Z. k2 d# P% _* J
Final flow: unchanged
0 |: U' R+ @& D7 m% y$ N# m! q, ERelevant 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 8 j  k5 l4 c* U# {; E( A5 F
Datapath actions: drop
3 |7 H7 G" h6 t% U
- W) G$ c$ n+ ~" |" o$ sudo ovs-ofctl dump-flows helloworld
2 I! _4 B0 g6 J9 ]NXST_FLOW reply (xid=0x4):
) @; G* {% U! p+ k+ L. `cookie=0x0, duration=90537.25s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) ! c/ i* o/ w4 {, P1 \8 U1 h
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
* G, X7 y* g; E- Xcookie=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 " V* y2 M6 g: n( c$ H
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) " X( H3 ]. U8 a" V# @2 ^# 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) $ W6 s( u+ a! N, w% T0 Y
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) ( S1 @- P* Y+ {0 l
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) " C' B! A( s. Z/ W4 [1 Q
cookie=0x0, duration=86357.407s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
# g: `6 Y) l8 _; k/ _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) 2 G2 a6 T4 r/ {
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]
# o' W7 x2 y. I$ u; D) E& c/ h3 N$ _5 y- B& z. s' ~
table 10多了一条,vlan为20,dl_dst为50:00:00:00:00:01,发送的时候从port 1出去。
" e) c+ c, c- h  d0 B3 v$ [$ ?- L: h# _- E4 `' E
测试二:从port 2进来,被打上了vlan 20,mac为50:00:00:00:00:02
6 i% s5 q2 d0 b$ f' {/ B
7 e5 }$ o6 E# `' l$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=50:00:00:00:00:02 -generate   : G% m8 o, z4 E: K% o$ ^
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 - t4 B3 X9 ]* ~& N% B
Rule: table=0 cookie=0 priority=0
, R- `9 C$ v  D) ^OpenFlow actions=resubmit(,1)
1 D* {' r5 @8 N1 r9 E$ L; z; I0 Q7 _- o% y" ?0 x& H8 {! Y
        Resubmitted flow: unchanged 2 G" l- x+ L& b* q- x. K+ N# @2 t
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
5 M" _3 Q- U- J* A' ?        Resubmitted  odp: drop , I' P, U' j6 z8 `- F# _
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 1 M* a: O/ Q- f# D  R, r
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2): s, _  O1 L; V. d7 q; D# K
; W( _' o7 C! c( f
                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
: f* T: I6 K/ E6 D1 ~- A0 F" w                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 . q0 A1 y, Q! j" L- ?; c
                Resubmitted  odp: drop
+ [7 j, ?& A. o* Q5 G                Rule: table=2 cookie=0 6 d2 H2 K3 O: T5 {5 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)
% g8 u9 N5 `/ E& ?& x4 \* w- \9 g0 L1 ^# K7 M) L6 Y
                        Resubmitted flow: unchanged
9 p9 O8 i: [; s2 R7 N. {( O" P; u                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! K! s2 y6 U0 A  B
                        Resubmitted  odp: drop 1 _' b, `5 n% M/ q+ f; ^
                        No match5 U0 x1 u$ h' k& m$ M

" [% z8 T# B- s/ \/ o! J4 |Final flow: unchanged
5 x  k: a) _, U& uRelevant fields: skb_priority=0,in_port=2,vlan_tci=0x0000,dl_src=50:00:00:00:00:02,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no 5 ^8 i( T( ^" }7 w2 o1 W
Datapath actions: drop/ l9 F; H' |* s1 x9 L" S( r" z

5 `, I. \% G  Y1 o& P1 z$ sudo ovs-ofctl dump-flows helloworld                                                 ! e" }; @- Q' l; D. T, @, I: j7 b
NXST_FLOW reply (xid=0x4): ( T( C, f/ M( b7 U* Y  E
cookie=0x0, duration=90823.14s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) ( c# ]. P) u  ^) z
cookie=0x0, duration=91013.099s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop 2 z# p1 i1 y& g. \
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 ( h4 @" l0 D& ?8 s1 ^3 X
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) ) Q, V$ w+ M! m& Q6 V( f
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)
2 T4 ?, U8 G4 ^. ]# H8 h, o$ Lcookie=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)
7 Z' A: Y) f( ]# ?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)
$ N& }; Y; x7 x2 k) Fcookie=0x0, duration=86643.297s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
/ n( W0 O6 _# |( _& p6 Z) N5 ~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)
) \6 ]  i4 o" z4 ~2 e9 j$ 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] ) g# F# n  ~8 v" O
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]. h( i) w9 m5 v; t
# G  M- q7 N) f: c
实现第四个table 3: Look Up Destination Port( N: P, D" g# j# m6 r
/ ~  ?8 W2 b% l& s+ M
在table 2中,vswtich通过进入的包,学习了vlanid –> mac –> port的映射后,对于要发送的包,可以根据学习到的table 10里面的内容,根据destination mac和vlan,来找到相应的port发送出去,而不用每次都flood
, X8 C0 ?9 l0 W! m" @
- J, ~: d& i9 p) l6 S4 j- c# Rsudo ovs-ofctl add-flow helloworld "table=3 priority=50 actions=resubmit(,10), resubmit(,4)"
: B0 w3 o1 c# `  }& L+ K4 a9 T& j6 h4 L; h) Q8 J: P% j
添加这条规则,首先到table 10中查找learn table entry,如果找不到则到table 4
, H( s6 V+ v% ^6 a- a, Q( s: a6 R1 f5 s3 B. ?$ T
如果包本身就是multicast的或者broadcast的,则不用去table 10里面取查找。
) `4 g/ D% _4 g" |) L; I( V7 B$ D
! n! q1 F; K0 e+ E* O- J- }sudo ovs-ofctl add-flow helloworld "table=3 priority=99 dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,4)"
' B% I0 J: I& j5 n, Z# ^3 }! G! @) F" d, ^- A# |* [
我们进行一项测试8 e$ `3 E& X0 D3 [
' C. V5 E' l+ I2 o5 y( G# y  D
$ 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   
2 F3 ^1 K4 o8 X" ^2 V( T4 @1 U% tFlow: metadata=0,in_port=1,dl_vlan=20,dl_vlan_pcp=0,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000
7 S! J; X* y  cRule: table=0 cookie=0 priority=0 / M) v9 p8 m) F5 @$ v. J" d
OpenFlow actions=resubmit(,1)9 R3 d! O8 h0 s* {
2 w8 x$ a/ Z. ?7 [/ u
        Resubmitted flow: unchanged
2 H4 H3 j6 \4 K5 ]% L; t        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 - I, d2 ]% e& k# V% G& o7 O5 j3 ^, g
        Resubmitted  odp: drop
/ k- A3 p# R9 P* I6 j        Rule: table=1 cookie=0 priority=99,in_port=1
- }/ P4 i* a1 j+ w5 g/ W9 F/ k        OpenFlow actions=resubmit(,2)
' U5 C1 I" I+ c6 \+ x# A+ P# e
# z* x) l  [5 _                Resubmitted flow: unchanged
8 x2 Z* C4 |. l7 S, D- M: N                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
2 t7 p* t+ t. A- o2 O9 ]$ U$ J                Resubmitted  odp: drop
  L6 s1 I7 U% a& A                Rule: table=2 cookie=0   @& B- L; B$ Y3 {# |7 b3 _0 [
                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) T+ A0 k$ \2 P; Q% p. r" M, ?

/ ^- M6 J( }! Y, \. q                        Resubmitted flow: unchanged
9 t1 i. H' N% f7 B* T                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ) C* e6 P5 y1 C8 \. F# V% s. c
                        Resubmitted  odp: drop % U5 ~) C3 T" @% V3 x8 i1 f
                        Rule: table=3 cookie=0 priority=50 $ J$ y) ?7 Y, c- O( R. t" h
                        OpenFlow actions=resubmit(,10),resubmit(,4)
1 Q8 W# r9 o# K
  w% H) T/ W5 U6 S                                Resubmitted flow: unchanged
4 u, y" }) @$ {  D* `                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
! b9 B3 y3 H" V! b, G) ~& ~                                Resubmitted  odp: drop
5 v- t/ R2 T* C4 d                                No match# J% u9 I. V/ F  t' q# p: M% W
2 s( G5 s6 `" t( C# L4 A+ B
                                Resubmitted flow: unchanged
$ F) N6 f* ]4 y0 r5 Y5 C% N                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
' J+ \6 {2 H  q, L8 K3 v6 o                                Resubmitted  odp: drop
" f$ M2 O% e, O4 U                                No match
0 `2 l  \4 s$ }! \% H6 n: u% _& I7 }) f- ]6 P! g' g
Final flow: unchanged
* m# \, t7 L8 z, o& @1 p* ]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 7 d( G6 J: T- m2 e% B. I
Datapath actions: drop
2 `( p. P2 c4 f8 U( o7 `" O
( F3 @6 E; Q9 Q$ n由于目标地址f0:00:00:00:00:01没有在table 10中找到,因而到达table 4.$ Q4 M1 K; L  U! L2 E$ z

, \8 w% J5 H5 E" r( R但是这次测试使得table 10中学习到了mac地址90:00:00:00:00:01
6 _2 W  {, I* ?1 Z& E" S8 K
+ k9 f* D# Q) T% `! f, i$ sudo ovs-ofctl dump-flows helloworld
8 d: v0 \* @) S5 INXST_FLOW reply (xid=0x4): / I$ k' [, E7 m3 e5 M' V
cookie=0x0, duration=91588.452s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
. [" O0 m! O" I4 Scookie=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 ( ^% X, e6 Z5 [
cookie=0x0, duration=91713.926s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
8 R7 a0 o- x: kcookie=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) ! k3 X. m) u$ s5 F8 a% _
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) ( f" l$ M2 i$ m
cookie=0x0, duration=87199.143s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
4 `1 Q. k  x# Y+ I  m9 Tcookie=0x0, duration=87330.188s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2)
5 M) {* s* [) b+ ncookie=0x0, duration=87408.609s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop 0 H. N. J4 J, Z1 J
cookie=0x0, duration=84638.483s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
3 \) R( x( d% X3 L3 d+ a! tcookie=0x0, duration=352.841s, table=3, n_packets=0, n_bytes=0, idle_age=352, priority=50 actions=resubmit(,10),resubmit(,4)
8 ]; b- C5 O+ r1 {) {* X7 Hcookie=0x0, duration=212.704s, table=3, n_packets=0, n_bytes=0, idle_age=212, priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,4)
* p! a/ q  Y8 N+ `8 E 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]
5 s3 f0 [5 {; a- ?2 acookie=0x0, duration=769.784s, table=10, n_packets=0, n_bytes=0, idle_age=769, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:02 actions=load:0x2->NXM_NX_REG0[0..15]
7 u) h2 m" \1 h2 bcookie=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]6 T( m7 O) T0 Y. z" l: f7 A

# q& d) n, B! q9 \9 s1 ?下面我们进行另一个测试
2 \+ p3 E; Q, R" U' d+ Q2 P
% h, [3 P( a5 ^$ 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   7 u  a; G: X1 a9 ]
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   x9 f5 X- F1 I) |4 s/ y
Rule: table=0 cookie=0 priority=0
* c" B4 I7 k- k3 DOpenFlow actions=resubmit(,1)
) O& t2 y9 k( V
: C4 r. ~1 x* x6 A3 U+ y        Resubmitted flow: unchanged * r; W* a) h1 E8 O
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
4 V4 m0 q0 y% w6 O+ |+ s0 @. p        Resubmitted  odp: drop ' O7 K  n) T3 F0 f5 @5 \, d
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
: m) g- G/ L" }        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)  a$ |! e! [9 L

) y# P* B- A8 ?& t                Resubmitted flow: metadata=0,in_port=2,dl_vlan=20,dl_vlan_pcp=0,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01,dl_type=0x0000
2 O% J. G3 B' V, F                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 a+ m/ u9 D& F" U
                Resubmitted  odp: drop ( s4 l7 K& e7 f+ Z2 c5 B
                Rule: table=2 cookie=0
4 Z3 Z- |: \2 F$ |3 g) 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)9 q1 p8 ~3 _4 }% r* i
# z, c0 F) d! b+ [, p  j  N
                        Resubmitted flow: unchanged % N9 R, c* d8 T/ |5 g
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
. P; c5 q5 {" O: y: z5 ]2 Z* K2 H                        Resubmitted  odp: drop
# l& ^8 g1 M4 ^: [1 l2 W                        Rule: table=3 cookie=0 priority=50
( t3 Q8 j  U1 x8 [                        OpenFlow actions=resubmit(,10),resubmit(,4)# B) U8 a/ f  a
* J. V0 L' j$ l+ y% ?2 C- Z7 B
                                Resubmitted flow: unchanged - N2 R1 O% Z* j& ?* J
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0   H5 t0 E9 M# B
                                Resubmitted  odp: drop * t9 V: z1 ]+ K& s, p; Y0 t  t
                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01
) z6 S* W; W1 E, |                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]2 q: Q: O, I: S: w" [
& e! A& \/ ~- F! V1 U0 ?6 i  V) R. h
                                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 # c8 O. {! A4 P1 \8 L9 ^
                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 9 Q5 [3 c: d3 n" @$ g) [% _) \$ s$ q
                                Resubmitted  odp: drop - b$ o$ ]6 ]" S  u8 S9 U
                                No match  f( V) w" Q' F$ ^2 s! G( F
9 R( D  `  d3 M2 z3 P! y
Final flow: unchanged
9 P8 `# f4 a0 w1 xRelevant 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 " H! G# F9 M7 i% v
Datapath actions: drop
3 V! W& r) i# ~1 S% U% m) E5 d+ S/ r. f
因为刚才学习到了mac地址f0:00:00:00:00:01,所以这次在table 10中找到了这条记录,这次同时也学习到了mac地址90:00:00:00:00:01
9 z! H/ Y0 S1 p1 f. z' @
+ Y% O/ u$ O5 ]下面我们再发送第一次的包# P) |- t; f. o

- T/ t$ ^2 Y! o. s5 h+ b$ 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
) [( r0 E6 S; v" P/ V- a+ eFlow: 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
/ j" g) }& g) }) |1 k/ g9 ]+ dRule: table=0 cookie=0 priority=0 9 b! X- D, y+ q; u
OpenFlow actions=resubmit(,1): j* o2 I1 _$ Q! W( S- K: f
9 b0 A; g" \: a) \1 _, _
        Resubmitted flow: unchanged 8 K" Q0 A  @5 h
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & x9 e' H  v% K" T1 `
        Resubmitted  odp: drop $ w8 _/ j( k& K" e
        Rule: table=1 cookie=0 priority=99,in_port=1
( l: U9 t' {/ f- I9 |        OpenFlow actions=resubmit(,2)
  G$ a  P( f2 g3 W) F
+ @' i/ r; U3 y& h5 I' ^                Resubmitted flow: unchanged 7 H! c3 z7 R# G; L; `' o; d
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 0 i$ g/ z% _6 r3 r2 C
                Resubmitted  odp: drop
, q  g# y, y  r9 \$ g                Rule: table=2 cookie=0 & R6 r% q& ~" e
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
+ s  x/ u5 D# {) h  ]* q
# c8 n- L" @1 \                        Resubmitted flow: unchanged : j! x  m/ @* \5 d
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
1 R6 D1 C/ b6 u! n4 V' ?% U                        Resubmitted  odp: drop . B9 m+ _- z/ V  y
                        Rule: table=3 cookie=0 priority=50
. ]7 J1 j0 G$ Y' R; X/ a' Z                        OpenFlow actions=resubmit(,10),resubmit(,4)
% X4 r% b3 {% u( |5 n, g7 E4 ]7 h' X6 u. K9 e& _
                                Resubmitted flow: unchanged , r# m; C4 t4 q0 L- z
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
1 j0 u2 @1 b5 |$ C3 H5 @                                Resubmitted  odp: drop ! c( Z/ i0 C, p- B3 ]& X) t
                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01
* f4 v3 R/ w0 {# V) }+ w5 @                                OpenFlow actions=load:0x2->NXM_NX_REG0[0..15]2 b: S; n% C3 ^$ }6 ]( E

& Q5 C1 @1 F9 p9 q4 ?; n4 I% x) W* L' R                                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 ( W5 o8 k' T0 ?
                                Resubmitted regs: reg0=0x2 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 / Z: K- C8 f% ^( a
                                Resubmitted  odp: drop
' ]  W5 S! a: U+ g/ k! p                                No match: a! b* Y  R# w) ?

- n* q( J5 {3 S: E  {Final flow: unchanged
! _: {& P) H% F, v) }" _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
" M/ M: d. w) O( O! q/ M- r* ]Datapath actions: drop) Z5 u" I" Y* o  ^1 h1 f
6 T+ d4 P6 X% w( A
发现也在table 10中找到了记录
1 k& A1 M6 n) m. }+ N, g
3 L$ e- S/ B- Z' a4 K" j( {实现第五个table 4: Output Processing
. c+ M. ]9 o9 x$ G9 i) a3 j8 G+ X
" Q( o- f1 n( ~9 F+ }- j) B6 Q这个时候,register 0中包含了output port,如果是0则说明是flood。/ s+ R% ^1 ]! m
; y5 i3 M; P0 u( ~
对于port 1来讲,是trunk port,所以携带的vlan tag就让他带着,从port 1出去。2 q  \4 T/ P1 e4 ]

  n3 X* o; `" M; G+ ^1 y2 v  x4 e$ F; }sudo ovs-ofctl add-flow helloworld "table=4 reg0=1 actions=1"
: i6 W( i( V8 b7 k( \+ F, @$ o" `4 o3 z; s7 i, b6 b* N
对于port 2来讲,是vlan 20的,然而出去的时候,vlan tag会被抹掉,从port 2发出去( I2 u! e! U6 a8 X- R

5 R* O( n( R* V$ f+ {0 C对于port 3, 4来讲,是vlan 30的,然而出去的时候,vlan tag会被抹掉,从port 3, 4出去9 o! L1 E0 U% |
8 `- \3 X  a* F
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   8 y: H. `+ L6 X" i
        table=4 reg0=2 actions=strip_vlan,2
. V( T- ^( h/ e        table=4 reg0=3 actions=strip_vlan,3 5 v: w$ h5 ~- `
        table=4 reg0=4 actions=strip_vlan,4 $ P, c7 Z' Z( h! @3 k. d
EOF3 {0 X' Y. O. K6 J3 o

9 r; U( X) H3 }) w8 E8 @  r对于broadcast来讲,我们希望一个vlan的broadcast仅仅在这个vlan里面发送,不影响其他的vlan。* C. S4 e4 O, A% X0 D, F

9 B% p, G7 ?3 d$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   ; [- J0 Z% p, ~8 h
        table=4 reg0=0 priority=99 dl_vlan=20 actions=1,strip_vlan,2 8 {' _5 B2 n- S4 E8 }
        table=4 reg0=0 priority=99 dl_vlan=30 actions=1,strip_vlan,3,4 5 m1 \9 x: _, u0 g9 m2 {
        table=4 reg0=0 priority=50            actions=1 " N' k9 l' `! R2 t3 f0 f# v- E
EOF  S2 n& A- n/ K

  e" s, Y: Z1 ^5 I所以对于register = 0的,也即是broadcast的,属于vlan 20的,则从port 1, 2出去,属于vlan 30的,则从port 1, 3, 4出去。
! [  A% q' _3 M, J0 J4 e7 L9 J+ R) b
$ sudo ovs-ofctl dump-flows helloworld ) l: ]+ y" s4 j( U/ {
NXST_FLOW reply (xid=0x4):
1 i$ y" F" \2 d# I: I% Rcookie=0x0, duration=92909.119s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) ' k+ X$ }3 ^' L0 C+ O5 c$ _" c
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
! \8 t6 ]1 Z& Y; ?- W  y8 Q* ]/ xcookie=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 * E6 `. R  z6 C& v$ V7 s1 N
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) & d# G( V4 g6 E1 B7 w
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)
) F9 h/ k8 ^& k- w4 l( x( wcookie=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)
+ z1 ^& }. H" n1 [4 X9 m2 p3 ucookie=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) 6 G5 ]5 u2 a6 |
cookie=0x0, duration=88729.276s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
' H+ e8 Y: {0 C8 H: Z6 \1 W( tcookie=0x0, duration=85959.15s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3) * r: I* C/ y! P& y* c
cookie=0x0, duration=1673.508s, table=3, n_packets=0, n_bytes=0, idle_age=1673, priority=50 actions=resubmit(,10),resubmit(,4)
7 O8 L4 ]3 ^+ `# X9 acookie=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) 3 k. |9 R/ P. U' x
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x3 actions=strip_vlan,output:3 ) a- g( I5 |, W) {
cookie=0x0, duration=228.839s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=50,reg0=0x0 actions=output:1 1 S7 m7 |" c2 y, K. J
cookie=0x0, duration=483.068s, table=4, n_packets=0, n_bytes=0, idle_age=483, reg0=0x1 actions=output:1 . b, J: {% ?8 T, K. q5 s; k
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x4 actions=strip_vlan,output:4
6 L  H; o0 j# ^+ Z* Scookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x2 actions=strip_vlan,output:2 2 f) b2 l5 w' Z! ^2 \
cookie=0x0, duration=228.84s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=99,reg0=0x0,dl_vlan=30 actions=output:1,strip_vlan,output:3,output:4
2 ~0 `: h! \3 ?2 B8 r* o; e2 J9 Rcookie=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 " T1 Y% R+ ?, y7 D1 d! C
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] & D' U5 f* i3 T
cookie=0x0, duration=2090.451s, table=10, n_packets=0, n_bytes=0, idle_age=2090, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:02 actions=load:0x2->NXM_NX_REG0[0..15]
5 s7 R8 I0 d0 T3 z) P$ F* ~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]
/ d- V1 h2 \- e: w0 `* ^; B" kcookie=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]" X# i, F, c0 w8 Z0 X

# l$ k1 s+ f" ?首先来测试一个multicast和broadcast
: W. U' x6 F  J5 p* p% w: ^; m0 L% x+ W6 f8 M0 N; @
如果是一个port 1来的vlan 30的broadcast
' V" k  O3 s+ p% M1 q- @6 A5 z" K9 G5 }3 ]  @! K0 `
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=ff:ff:ff:ff:ff:ff,dl_vlan=30 3 ?+ D8 R- q, o9 i* \
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 - d& x5 P" _* |
Rule: table=0 cookie=0 priority=0 / ~$ P4 j/ |* h  A" S. y: F
OpenFlow actions=resubmit(,1)7 `- I8 V' e9 G8 N3 x0 t1 F

) `4 W( X8 \/ P( A: l0 r# b        Resubmitted flow: unchanged
' |/ y- o1 Y  w7 k" I        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 , P4 |  f9 N/ a
        Resubmitted  odp: drop 7 F- ?+ y& E0 Q4 |& |7 a( J& ], c
        Rule: table=1 cookie=0 priority=99,in_port=1 * P- K( a( f- I' i; y: P0 Q; U) z
        OpenFlow actions=resubmit(,2)
& R/ \: z( Z0 G# I9 O3 B0 q
3 ^! a; h7 H" J5 ~0 \3 O, P                Resubmitted flow: unchanged
! g* ^  L: @8 c- v                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
1 i& t% e. {2 }- v                Resubmitted  odp: drop
4 N. v! j6 d2 W6 `                Rule: table=2 cookie=0 + s& |9 ^7 s! ^7 j# 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)5 N# k; ^6 z" Y) X% W0 q0 x

1 [8 ?4 e, [/ ]8 V9 N$ w                        Resubmitted flow: unchanged , D. N7 }; Q) Y* H' A
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 m- F) Y$ z% z( X( w5 p
                        Resubmitted  odp: drop
- Q9 D  N& ^( ?3 e" I: {+ G8 y2 I                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00
1 |6 F, T3 {' P0 ~- M; d6 f/ y7 J                        OpenFlow actions=resubmit(,4). e/ N) Z4 }/ V! h

6 \. K) P" b( m6 f8 M- [                                Resubmitted flow: unchanged   Y/ N5 ?9 {2 N- b" F! |' e
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ) O% D1 M- s9 ~3 ~! n
                                Resubmitted  odp: drop
$ P% C5 y% i8 e. c( q                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
; b3 d2 d2 [8 q# S                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
8 i: ^+ r" t+ n5 J5 o                                skipping output to input port
' A$ f1 e0 B7 r  Z# m# m: \4 ~
+ }5 W  x5 n4 {" k1 j# C7 y! 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
6 G2 v: Y0 E: M8 t0 X, \" WRelevant 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
+ ~: e! T3 C  n. MDatapath actions: pop_vlan,12,135 y/ b2 f) h+ M6 M! O  D! @! @8 [
1 d- M* C; q% j* G1 o
结果是port 1就不发送了,发送给了port 3, 4$ x9 Q8 k5 C0 Z8 O4 ]3 r
3 a* T! g7 d9 V. g0 S1 y
$ sudo ovs-appctl ofproto/trace helloworld in_port=3,dl_dst=ff:ff:ff:ff:ff:ff
" K$ r* \; [7 D% l% J* V" |; @0 JFlow: metadata=0,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000
9 u4 _" j$ C/ [. o& W) lRule: table=0 cookie=0 priority=0 # j, I/ h5 g$ q% D7 Z
OpenFlow actions=resubmit(,1)- |+ y- k7 j# x% Q; P
8 y, k* ~+ ?6 \( n- s0 Z3 w" I5 \
        Resubmitted flow: unchanged
& D8 U: `; v7 S1 x# e  z" S        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ' u9 x# U7 ]* N: L) b
        Resubmitted  odp: drop
# X, p: N/ B, O6 I! k3 k0 g* E7 R        Rule: table=1 cookie=0 priority=99,in_port=3,vlan_tci=0x0000
. `3 `0 e# A3 r3 a0 B        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)7 c' |) T3 n$ |$ O5 }, c

8 m2 p1 a  [5 V                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 : m1 k- f) O1 h  ~( v
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
5 B8 y; T+ m& e' v, X2 Z                Resubmitted  odp: drop 8 o8 O+ K% `) {1 N
                Rule: table=2 cookie=0
! l, l8 |; X9 Z; M                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
  O8 {& B% ^- V. w! t
5 f7 X: q7 Q8 m/ j$ x                        Resubmitted flow: unchanged & r2 ^( ?* [& L5 W1 W: w; O
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
# ]  ^) G( D; [/ u, V4 w1 w: C3 }                        Resubmitted  odp: drop & q) @: D* H& E& g9 t* h
                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 : h$ i7 {$ ~8 A7 x, z
                        OpenFlow actions=resubmit(,4)
" l& A# ]$ U9 H$ ]( w9 A0 D2 s3 L6 C! E, _7 m9 \! q6 X
                                Resubmitted flow: unchanged $ J+ {' u, S/ C2 r! k, ^2 ]! z
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
* K' ~9 {4 N& B3 K" a$ E                                Resubmitted  odp: drop & n/ o* t+ h3 g( T9 s* K
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
. w- b! H) J+ w3 {  n/ y                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
, b5 j! ?2 K  U& s9 i8 M  ^5 t                                skipping output to input port# @9 A# {! X. \# l% O& o

& c( `, N9 `: B1 }- DFinal flow: metadata=0,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000
1 E! o1 r/ P5 [( e9 dRelevant 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
" j+ Y  D* V1 {! O3 _/ u) i" K/ S# }Datapath actions: push_vlan(vid=30,pcp=0),10,pop_vlan,13" ~! Y( H' y) m

2 ?) u# w, I7 {2 J$ n4 k% H2 A0 v5 U* A接着我们测试mac learning( @3 @1 X, ?0 M% t) d+ b
5 k1 W0 R3 T9 t+ E" z2 K8 D
$ 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   , c2 |3 P8 U  n8 ^+ J
Flow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000 4 G' ^) [# p3 U# j- H& F
Rule: table=0 cookie=0 priority=0 # j, ?7 @5 W. C: N' f5 v2 s
OpenFlow actions=resubmit(,1)
4 Z9 b& M9 s4 ~6 V5 k0 F
1 S. F9 u9 j0 P) j, p        Resubmitted flow: unchanged 2 A9 X) d2 D5 W, L: G! ]% f
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
6 U% i3 k4 w; ?3 r: z        Resubmitted  odp: drop
4 I6 _- u: D$ E5 {% e9 n        Rule: table=1 cookie=0 priority=99,in_port=1 0 x6 |/ k) s2 a; R
        OpenFlow actions=resubmit(,2)# i1 ^6 n) O; d8 a1 W- \" ~+ g
/ l( I" E( r' t- d* x8 t/ [
                Resubmitted flow: unchanged
8 W. p- A6 `9 \+ S3 {                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
5 {3 }5 w5 P- T" F                Resubmitted  odp: drop 8 t* g6 b# @+ j% q
                Rule: table=2 cookie=0
5 W  h# t, S  x# @4 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)
* g5 Z& R1 ^1 u" [% A  W- a: K, e8 Q* o
                        Resubmitted flow: unchanged
$ D, ?3 L# N, k. h4 s: V                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 5 G8 ]& J9 I& u
                        Resubmitted  odp: drop ( P8 t1 u" g: }# f! g9 Q# F/ `: A' [, S
                        Rule: table=3 cookie=0 priority=50 3 m) _& C2 z  Q/ [8 w- A8 ^
                        OpenFlow actions=resubmit(,10),resubmit(,4)
/ f) R* j' S; h- W( d# m8 v" f& N) K% Q* p# L9 ?. g1 x  z
                                Resubmitted flow: unchanged 1 N! `) Y9 a7 R6 r9 O
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
3 N; N! A# `& Q! N                                Resubmitted  odp: drop
2 H+ B; _( T: Y                                No match
  s! b2 G: B6 O1 X3 a6 b
5 W9 v+ G! H& C+ F                                Resubmitted flow: unchanged
+ l+ J# G8 _5 G8 w( v7 ~                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 * h4 t5 H7 o0 A6 b/ _* N* U" O
                                Resubmitted  odp: drop . _: z, C9 S5 J9 s, g
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 1 Q& \2 J* l' i/ i
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4 0 e" a$ R6 q+ R. ^
                                skipping output to input port
4 E: e# L2 t7 W6 W3 A/ K: x
2 I* Q1 [* l5 k. g- r  Q5 T5 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
+ L3 V" ?! p1 ?# pRelevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000,nw_frag=no
: S6 H. j& f& m/ |& }, y, v- xDatapath actions: pop_vlan,12,13
/ c9 n3 e' C* X! I" O' V6 T* H* r) e+ K
由于这两个地址没有出现过,则除了进行学习以外,广播发送给port 3,4
# p" b' {& `/ I/ Y
, ~/ c# \8 {% ^0 z& W6 J6 T$ 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   * h! r3 c6 G* R7 X
Flow: metadata=0,in_port=4,vlan_tci=0x0000,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01,dl_type=0x0000
8 N& X+ X% D- ]Rule: table=0 cookie=0 priority=0 : H  e* N& F% U% k0 R# Y" o! u0 H9 u8 d
OpenFlow actions=resubmit(,1)
% I! n6 a, `: \
! u. C% Z$ n) k: e0 R: n( d+ @        Resubmitted flow: unchanged ! N2 B% Z7 g2 t9 |5 X
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 - _9 y0 R7 J6 i( H, X# y" D
        Resubmitted  odp: drop " O& w# u; g, }  u
        Rule: table=1 cookie=0 priority=99,in_port=4,vlan_tci=0x0000 / y" _. T/ W4 {  Q) k% K+ i2 `! U
        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)
% {, H/ S% \0 }  d, V0 W
# A/ {. ~" o1 p                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 % C! Q  Q4 V& N8 S
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! N& Q( Z8 U1 @2 j
                Resubmitted  odp: drop
$ {8 ^4 r7 c# t* u7 P$ c; c                Rule: table=2 cookie=0
1 `8 G8 f4 p0 w( [$ T  \7 @                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 j; W% P0 N: \. ]. V3 B( H- h; c& t, m5 r2 Q" H5 @! V% g* I/ E, |0 p
                        Resubmitted flow: unchanged
/ C  \* X8 {6 p$ _( W" T                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & [+ m: I" {& f3 f/ ~6 s5 Q
                        Resubmitted  odp: drop . L4 _( x$ s! _+ w1 B6 `# m- I4 _
                        Rule: table=3 cookie=0 priority=50
! {6 [* c; ~: U, i                        OpenFlow actions=resubmit(,10),resubmit(,4)3 a# [8 u2 S- @5 j& y* g7 w% S

1 r" }# D9 ~0 Q4 c                                Resubmitted flow: unchanged
0 Y: A& y7 \6 F2 ^                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
& Z- z$ d" V: h) Z                                Resubmitted  odp: drop ; s# _, u. [& \: y0 F
                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=10:00:00:00:00:01 6 [1 A& H% R! @/ |% g( Z" X
                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]
- }! W, _* @! s( D* K) J+ i& L+ ^9 f" J* ^, w1 C0 }1 d5 @
                                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
( S. k: Y- v2 I: A6 X5 b5 C                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 , a; ^6 }8 ~, j
                                Resubmitted  odp: drop
: ]3 q" ^  [& s                                Rule: table=4 cookie=0 reg0=0x1 3 C. ?4 d" @/ a7 y6 K
                                OpenFlow actions=output:1
& |  O9 C% c5 }9 ]' d' B
. j% Y6 {* h5 t& s* wFinal flow: unchanged
7 E# T5 ^2 {; H, \3 ERelevant 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 , B: t% P/ x; \3 Z; {, @7 @
Datapath actions: push_vlan(vid=30,pcp=0),10# O5 K' ~5 N8 n. _2 ^1 J
) U' W, J  ]0 O2 M
回复的时候,由于学习过了,则仅仅从port 1发送出去。
, ?, e- d8 q0 [* _* s8 A
" N1 _5 \- q# B5 l$ 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
7 j7 p& V* C4 D, d+ NFlow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000
9 P: E* D: l  U8 @Rule: table=0 cookie=0 priority=0
# a3 o" A+ }' G: m" {" yOpenFlow actions=resubmit(,1)
/ i% d4 E, i+ V) Z* K  o
$ O7 I9 P0 ?5 D* i; b2 p        Resubmitted flow: unchanged + v' y; S5 ?" a, _; v
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
5 C- z$ a  Y( z% l% N  m$ X1 D6 o        Resubmitted  odp: drop
- \) O" l3 W: i# B  I4 n        Rule: table=1 cookie=0 priority=99,in_port=1
& i+ k% L* ]& o& B( J6 ?        OpenFlow actions=resubmit(,2)
5 D- w9 w, c  D& m9 X" p7 l  n
$ B  f- u( `+ M7 @* i" k. ~                Resubmitted flow: unchanged 4 _( [+ f3 P) b% n
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0   h% l, L; ], T; ~4 }
                Resubmitted  odp: drop
. @2 }: W: G4 ?2 w; W! {3 K' [5 t                Rule: table=2 cookie=0 9 P: W4 @, Q* u, d& F5 @+ 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)& N- r; x/ Q. {) E
1 r8 e( I- A* C  z) \
                        Resubmitted flow: unchanged . h( y) U/ l1 X' M7 i1 Z
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
4 Q* ~, S  A" v, O2 u6 M                        Resubmitted  odp: drop ( A$ N) [. B( U: B
                        Rule: table=3 cookie=0 priority=50 2 s$ e6 L: b7 M- {
                        OpenFlow actions=resubmit(,10),resubmit(,4)
" ^6 @$ l5 y4 S5 a* c3 n
0 u/ [3 T" R' a: w0 B( j                                Resubmitted flow: unchanged
! ]/ \2 N  Z# Q& A& \                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
. w& P8 J9 l1 q) @                                Resubmitted  odp: drop
4 q+ }  M5 B) E: I+ l                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=20:00:00:00:00:01 * q  b. ~$ l% G, t
                                OpenFlow actions=load:0x4->NXM_NX_REG0[0..15]& ~7 k6 m# e5 V$ V9 a" W$ H1 S

3 P2 K" I) z4 f% H8 b' R                                Resubmitted flow: reg0=0x4,metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000
) S* T1 C$ {+ A9 p$ \% U7 J                                Resubmitted regs: reg0=0x4 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
! {; q* \! N" ^0 d% ~  M6 Y                                Resubmitted  odp: drop
2 ~  @: ]& n9 |0 g3 o/ ]                                Rule: table=4 cookie=0 reg0=0x4
- n$ m3 n9 S+ u                                OpenFlow actions=strip_vlan,output:44 O( i4 _9 `$ k. F2 s8 a. T% o7 o- B7 d
/ q+ C  L% d% x5 }0 i: c
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# l' @0 Z6 y7 q  r
Relevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000,nw_frag=no
$ v% B  s. h6 }7 h8 ~Datapath actions: pop_vlan,13
0 z% i" y& ^, W7 o( e6 |! P( }0 J( n( N  X8 l2 h) z
由于在回复中进行了学习,因而发送的时候,仅仅发送port 4
 楼主| 发表于 2019-10-25 10:00:36 | 显示全部楼层
实现第一个Table 0,Admission control( @1 y/ x. [1 S
' f- x: W& {4 H. \; W4 q+ A
包进入vswitch的时候首先进入Table 0,我们在这里可以设定规则,控制那些包可以进入,那些包不可以进入。6 D3 r# W+ @( M1 M* X6 e' D

0 h0 N4 H) R% c+ [( i比如,如果source address是multicast的就不允许进入。
: u9 y5 f  d; @* V
. }/ A6 ?9 q+ ^' x5 C# C01:00:00:00:00:00/01:00:00:00:00:00是广播地址# u% k' `+ P* e$ B) Q' C2 L' ?9 |
00:00:00:00:00:00/01:00:00:00:00:00是单播地址! w8 Q" t+ [4 V5 ?, }
这种表示形式类似CIDR
4 l+ Q) P! S& s! E于是我们添加下面的规则:2 `0 z& ?! G2 J& @9 x
sudo ovs-ofctl add-flow helloworld "table=0, dl_src=01:00:00:00:00:00/01:00:00:00:00:00, actions=drop"- R" g  @1 G$ [, a: q4 X5 }' _( }
STP的也不接受* V: `7 K2 V; ^* G% ]* p
sudo ovs-ofctl add-flow helloworld "table=0, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0, actions=drop"
' P6 D& N9 p8 H! H/ H我们在添加最后一个flow,这个flow的priority低于default,如果上面两个不匹配,则我们进入table 1' L) X+ c! k+ q* p, r
sudo ovs-ofctl add-flow helloworld "table=0, priority=0, actions=resubmit(,1)"
8 _" Z9 I" ^& w3 k+ A# w5 d我们查看一下所有的flow
5 P7 i6 ^# L! q5 l$ sudo ovs-ofctl dump-flows helloworld        
0 H( @5 M7 X2 Q& PNXST_FLOW reply (xid=0x4): % ?1 ?3 c4 q# |2 E
cookie=0x0, duration=42.162s, table=0, n_packets=0, n_bytes=0, idle_age=42, priority=0 actions=resubmit(,1) $ T9 }" f/ W7 q9 Z2 f% O
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
: G' G$ R3 ^& {- c1 Dcookie=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% K+ i9 V6 A0 }! L
8 H+ R2 P2 O# J8 T
测试Table 0* @; O9 U3 _' V: M# E9 V) y5 s
6 v, p( W5 t: R1 y; z* B4 C& J: y
有个很好的工具ovs-appctl ofproto/trace/ c, c! M) s& ^1 B

( K: l, c/ x! c* s2 H( c不满足条件DROP
) c) C7 Q. O4 U+ A( Q
# V2 B- D* Y: Z$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:05
# |0 `9 _3 f. j. ?4 u4 I: HFlow: 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 % r2 ^/ J: v* G& U5 C$ z. T
Rule: table=0 cookie=0 dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 . Y4 Z, C! C2 f0 M$ O- L
OpenFlow actions=drop
& Z0 g+ `7 w0 M6 @- |3 z$ z- m- Y+ {) n
Final flow: unchanged
* C' P+ p& O- n/ g1 NRelevant 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
+ J. w9 K8 V5 X# c1 N5 U; UDatapath actions: drop
! E, W8 J$ F. @% L7 T% j5 d) m
( D4 n8 J& D& D/ o, X0 Z* ]; M满足条件RESUBMIT2 j5 v. m% D" L& V$ i5 M

/ g: B+ K! {* h! t7 o3 Y$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:10 8 ~- h  v2 i( y9 b
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 ( {! u) w8 x! ]
Rule: table=0 cookie=0 priority=0 % D5 K) ]( e. u" \1 j
OpenFlow actions=resubmit(,1)
* q% l  q) ?# S: X, t, v+ n' ]" y7 P& U
        Resubmitted flow: unchanged
: X  e# d' W6 W1 s/ {. _        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 6 T3 v8 q% N# H" B1 x# I
        Resubmitted  odp: drop - G2 ]! X! Y5 B  }. s" T
        No match
8 @: a, ~& z9 g4 ?3 m) `% b9 L1 T' V; L0 L% M6 g7 s7 }1 B
Final flow: unchanged 1 q7 W- Z% c' P% R" j- O
Relevant fields: skb_priority=0,in_port=1,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=01:80:c2:00:00:10/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
3 }" p& J! L2 w$ w/ C' GDatapath actions: drop
& ]9 z6 @5 ^) e  V$ o5 F6 u" o6 s
. b, @: H9 d3 R1 X实现第二个Table 1:VLAN Input Processing0 m: c) I8 W: U; m7 ]' q1 q2 r# g

, M% Q: U8 Q) E4 B# V首先添加一个最低优先级的DROP的规则
  q0 c5 z0 N7 H
% R  N/ y3 {9 I  J% }; Csudo ovs-ofctl add-flow helloworld "table=1, priority=0, actions=drop"- v8 `: v6 I! l* T: ~
% T/ B0 n, \6 `* V  d
对于port 1,是trunk口,无论有没有VLAN Header都接受。8 @+ d" X: ~. O5 F1 w6 ~

& @( h( R' |5 x& C) a0 \7 Fsudo ovs-ofctl add-flow helloworld "table=1, priority=99, in_port=1, actions=resubmit(,2)"1 N* _# D3 t4 H8 b) U* `

7 R% S; b6 V2 C对于port 2, 3, 4, 我们希望没有VLAN Tag,然后我们给打上VLAN Tag
7 S/ m( v+ N8 e3 g$ q# `" a# N. v
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'
+ |. N5 D8 i8 }/ b$ x8 d' B! Etable=1, priority=99, in_port=2, vlan_tci=0, actions=mod_vlan_vid:20, resubmit(,2) . p1 X4 Y: ?0 y' p& n( J8 _
table=1, priority=99, in_port=3, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2) / A  x1 d/ o2 D+ c2 x. v
table=1, priority=99, in_port=4, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2)
% Z- B' p, G7 k! @EOF
* }- a/ q; G  ~  Z: ?5 A
& r7 T6 q, _/ A* F$ sudo ovs-ofctl dump-flows helloworld : v0 }. l  u& w% E
NXST_FLOW reply (xid=0x4): * X: w. |  x) {0 o0 U6 X/ Q) \. G+ |* b
cookie=0x0, duration=4478.582s, table=0, n_packets=0, n_bytes=0, idle_age=4478, priority=0 actions=resubmit(,1)
& \( H7 ~3 e% e( Ocookie=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 2 p2 p6 i6 e% d
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
7 o7 w3 g4 k0 `* f5 ?5 ]+ a" @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 K9 S: B9 e& D* K- }, C* Rcookie=0x0, duration=89.273s, table=1, n_packets=0, n_bytes=0, idle_age=89, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
1 m2 B. @3 p; H6 m8 V; f, ?5 Lcookie=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)
: O) O3 |) H# _6 G2 vcookie=0x0, duration=220.318s, table=1, n_packets=0, n_bytes=0, idle_age=220, priority=99,in_port=1 actions=resubmit(,2) 1 H" m  e+ _  `1 x+ O
cookie=0x0, duration=298.739s, table=1, n_packets=0, n_bytes=0, idle_age=298, priority=0 actions=drop
/ v, w0 V- `8 V* L4 i/ r
6 z( \1 ^2 Y! T8 f测试一个从port 1进入,tag为5的: Z7 @3 o2 ~# q% o

2 n) _8 c. A6 w4 W3 v8 s$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=5 $ X! l+ _% t6 {; L. S' h
Flow: metadata=0,in_port=1,vlan_tci=0x0005,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000 ' u$ J3 e/ U1 k0 u& f2 x% O8 j
Rule: table=0 cookie=0 priority=0 & N+ O/ }8 H6 }) D
OpenFlow actions=resubmit(,1)2 C  }/ j4 i) ?2 {: J: S
  M8 E+ B4 X( O3 _
        Resubmitted flow: unchanged ' ?8 R% H) b) ]7 b
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
( y* z, ~$ A5 R; ~        Resubmitted  odp: drop - f/ h: y7 Y& y, Y! L- i
        Rule: table=1 cookie=0 priority=99,in_port=1 ' I4 T/ X' E" a5 e1 M) [
        OpenFlow actions=resubmit(,2)6 n; z" W, e9 d2 B

  f+ [. ^; d" L' o& k+ y! p0 ]5 @                Resubmitted flow: unchanged ! d, A  k- x/ i/ s* o
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! O3 @  W* c3 u+ O9 l
                Resubmitted  odp: drop . ]/ U  o$ ], W
                No match7 a$ b4 \( i* A) E! R
' K& _. M" Y' p3 |6 F6 v+ B
Final flow: unchanged 2 \: j0 b& R8 |- r+ T! ~
Relevant fields: skb_priority=0,in_port=1,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
9 n- X, E) W' I4 B! u8 UDatapath actions: drop8 {( d$ T. W) l

3 y/ X; A) O! b测试二,从port 2进入,没有打Tag的! n0 F2 M2 P- S) V  u7 T

) o+ P1 l# |: b% K' n0 m) Q$ sudo ovs-appctl ofproto/trace helloworld in_port=2 5 L( o9 J( P' M$ X# }' Y. A4 w8 b
Flow: metadata=0,in_port=2,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000
" @: `' \* J* dRule: table=0 cookie=0 priority=0 4 f: ]) C8 x- ?2 \
OpenFlow actions=resubmit(,1)0 X, c8 T# \; b* f; `: G

2 z- a7 y1 z! \7 R        Resubmitted flow: unchanged 4 a# p- m+ C. y1 v' q
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
: x& Q1 {! u5 Z' Q: G* n; W! O        Resubmitted  odp: drop
# r3 @; ^! ]$ u5 o! _& c+ ~        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
) e& [7 {6 p& d: j3 k3 d) R* K        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)1 s) s$ g3 T) r4 r5 K

: ]/ f! ?6 D4 q* e- n# \! [                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   q; _; z6 {+ l5 J  Q* n
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 $ m% d- n% B- ^/ _# \: c
                Resubmitted  odp: drop 8 @. Z0 |1 X+ v
                No match
+ Y0 k1 a$ D5 H0 L
* q1 a3 d) y: P! E1 mFinal flow: unchanged ! b4 I2 @: f4 C4 u
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 1 O1 t4 f3 `0 N" J
Datapath actions: drop
6 g% Y, Q; G+ T9 A" e
/ v& O8 e2 N/ G6 A* h; {6 n3 ^  I测试三:从port进入,带Tag 5的/ B' M, @6 ^: F2 f& y  t( \3 t* r3 e

* g/ |8 p0 @/ \4 u' G  y$ sudo ovs-appctl ofproto/trace helloworld in_port=2,vlan_tci=5 3 y4 j7 E. X1 I5 T% J2 h) 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 9 K, R( C+ u/ S
Rule: table=0 cookie=0 priority=0 ' @6 W7 E' F, X. t2 i6 r
OpenFlow actions=resubmit(,1)
/ y% E2 D5 e0 Y# z
, z$ U" W, T1 I# X* ^" `. r        Resubmitted flow: unchanged $ x5 \% m, `) w& }+ [! K
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 , t$ M! J. T- n
        Resubmitted  odp: drop 4 d2 @) D* w0 u2 r4 k- F9 }
        Rule: table=1 cookie=0 priority=0
6 b$ J( O  \& b. M7 o        OpenFlow actions=drop+ v% A7 o8 J3 P& u/ F* U
  I  H5 ?: G. E- }% o
Final flow: unchanged
3 @7 I0 C5 `4 PRelevant 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 9 c+ `5 o4 o2 v+ w! E
Datapath actions: drop
$ k) \  t+ T3 l9 V# i8 ]
, v$ a* w" |: g+ [实现第三个Table 2: MAC, VLAN learning for ingress port
" N3 ^0 f) ]/ F$ @6 p2 x# [7 k4 w2 O% w- b3 U0 _
对于普通的switch,都会有这个学习的过程,当一个包到来的时候,由于包里面有MAC,VLAN Tag,以及从哪个口进来的这个信息。于是switch学习后,维护了一个表格port –> MAC –> VLAN Tag。
/ J. F" L1 t" ?+ Z3 @# M: D
9 g: M: |6 S/ _2 R- a/ ?这样以后如果有需要发给这个MAC的包,不用ARP,switch自然之道应该发给哪个port,应该打什么VLAN Tag。
6 c% Y( v# T4 z& u% v7 ?& ~# ?! @- ^' R$ B; }* }
OVS也要学习这个,并维护三个之间的mapping关系。) l/ q" P( M6 l. }
+ |2 V" s% B& Z
在我们的例子中,无论是从port进来的本身就带Tag的,还是从port 2, 3, 4进来的后来被打上Tag的,都需要学习。% c2 K6 c& u0 l, ]( Q, b* A

3 l+ i1 w* N! O) `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)"/ J' ]( @8 W& ?% c# [0 g, i  o

  ?3 d& j# \5 V$ T0 O, ]1 Q3 \这一句比较难理解。7 ^) |, u- a: F
' c# _' U; Z2 c8 k8 c% L
learn表示这是一个学习的action
0 a. j& w) N# ]
2 ~* ?7 [! o& Q" H) _table 10,这是一个MAC learning table,学习的结果会放在这个table中。
  B' R. g: H" ]+ k6 n; ^
* \& t7 r5 q5 z/ ~, }NXM_OF_VLAN_TCI这个是VLAN Tag,在MAC Learning table中,每一个entry都是仅仅对某一个VLAN来说的,不同VLAN的learning table是分开的。在学习的结果的entry中,会标出这个entry是对于哪个VLAN的。. @7 @, x: @" v- y
2 n- `3 e3 c& d$ d
NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]这个的意思是当前包里面的MAC Source Address会被放在学习结果的entry里面的dl_dst里面。这是因为每个switch都是通过Ingress包来学习,某个MAC从某个port进来,switch就应该记住以后发往这个MAC的包要从这个port出去,因而MAC source address就被放在了Mac destination address里面,因为这是为发送用的。2 q" ~: u% B$ z# z. A) F

6 l# v  [" v' G, c! ^8 d7 XNXM_OF_IN_PORT[]->NXM_NX_REG0将portf放入register.9 E+ c: m$ M3 M1 M& i
$ m0 X3 F% d4 f/ u$ F- J3 b
一般对于学习的entry还需要有hard_timeout,这是的每个学习结果都会expire,需要重新学习。, `3 K/ d* n, `! I% u, |
' n0 W! ?( V# E( ]
我们再来分析一个实践中,openstack中使用openvswitch的情况,这是br-tun上的规则。
7 L% L5 K; J1 @' B
1 W' Z; @( s  m' ?9 Ncookie=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
" K  U- J) }8 Y) v4 ]  `' F* i7 Gcookie=0x0, duration=802187.786s, table=20, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,21)
3 t4 R6 y0 t, N1 H0 F% x4 \$ ] 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 3 ^) S& Q* T* G! H
cookie=0x0, duration=802187.653s, table=21, n_packets=17, n_bytes=1426, idle_age=65534, hard_age=65534, priority=0 actions=drop
0 `+ ~% k1 r- Q: d4 a2 icookie=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/ t1 J6 \; y6 c3 Z& z. {
! A% k) [1 ?2 E1 \9 S5 w0 r9 U# p
这里table 10是用来学习的。table 20是learning table。如果table 20是空的,也即还没有学到什么,则会通过priority=0的规则resubmit到table 21.9 k1 L6 D7 P# W- p! B
+ L" m: p8 N6 X$ s- a; \; L6 R
table 21是发送规则,将br-int上的vlan tag消除,然后打上gre tunnel的id。
8 h) ^5 Y* o/ v: |
4 ]' _6 M0 C* t+ i. D1 `上面的情况中,table 20不是空的,也即发送给dl_dst=fa:16:3e:7e:ab:cc的包不用走默认规则,直接通过table 20就发送出去了。
( E$ t% K& d; n/ V
) V' F" i5 E" m9 |; xtable 20的规则是通过table 10学习得到的,table 10是一个接受规则。最终output 1,发送给了br-int
; m) w+ ]+ a+ J9 Y1 h- S
6 U' T5 i& [2 b9 G$ R% U6 MNXM_OF_VLAN_TCI[0..11]是记录vlan tag,所以学习结果中有dl_vlan=1* Q. [! c; z! b! B* F) n

2 Q: d7 D, A/ G, vNXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]是将mac source address记录,所以结果中有dl_dst=fa:16:3e:7e:ab:cc5 A- t, Y# h. S& u0 b& ~
; Q6 _4 h# Z2 X( o) Y/ v
load:0->NXM_OF_VLAN_TCI[]意思是发送出去的时候,vlan tag设为0,所以结果中有actions=strip_vlan
# `9 {( G$ p1 l
! a( j8 K. D1 b1 S/ nload:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[]意思是发出去的时候,设置tunnul id,所以结果中有set_tunnel:0x3e9
) ], E7 B) J2 W3 X3 a7 k- p) U" X7 R2 T& a# @! N% Y$ t4 o3 I+ V
output:NXM_OF_IN_PORT[]意思是发送给哪个port,由于是从port2进来的,因而结果中有output:2$ S/ i) }, n' g. H! ?0 o! e

# h/ Z, E( M) M! x) r: A# L4 r4 P测试一:从port 1来一个vlan为20的mac为50:00:00:00:00:01的包
+ R3 Z+ L: u, S3 Q0 R- L! z9 `
  f9 i9 E7 N9 C# v5 c" z$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=20,dl_src=50:00:00:00:00:01 -generate   
4 M0 r" X. |( Z, ?) c9 D( l! bFlow: 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
. k8 M' S; P& Y5 G, a# i* _Rule: table=0 cookie=0 priority=0
- G6 c" Y: \; ]/ S5 H, GOpenFlow actions=resubmit(,1)
% x/ c1 I+ p7 H# N# L
# i1 p0 z$ ?0 `5 M+ n' O        Resubmitted flow: unchanged 2 _7 i' B* m" J# D0 w. L6 z. H8 ~8 C
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
' T/ F. f5 L1 B7 H        Resubmitted  odp: drop . ]; V5 @. K* L
        Rule: table=1 cookie=0 priority=99,in_port=1
( |7 p/ n( B5 W; s& X        OpenFlow actions=resubmit(,2)
6 Z( }8 ?) u( S2 ]$ h
: q! a6 d0 S1 {0 X                Resubmitted flow: unchanged 3 y& g# I" Y: P- y$ s! M
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
5 l& O2 \( U' u, F% y+ J0 n. f                Resubmitted  odp: drop
9 X& \8 j/ }1 d7 r6 R7 e                Rule: table=2 cookie=0 0 ^2 E4 m# S, w) v# y: V6 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)
' z% _  p1 ~' s5 `  C
3 B$ F! }- S  @# D                        Resubmitted flow: unchanged & C$ a- ~1 s0 _; ~9 A5 J' T
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
4 |5 M% g+ t# [! `4 v                        Resubmitted  odp: drop 5 W2 F( A! k0 `, a/ C$ }
                        No match
  N  l* C6 a' V5 X1 @) e2 I0 }: Y( S8 @: Z+ g/ r0 L
Final flow: unchanged
% r# S0 G# D5 D8 a) b$ v9 PRelevant 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
/ V& p1 ~, K( b! }Datapath actions: drop4 H8 }4 j7 k. V! R( k: k
" n( S8 {9 A* H, p# M
$ sudo ovs-ofctl dump-flows helloworld 2 N& r" b9 m* i- R& S0 ^0 g9 S
NXST_FLOW reply (xid=0x4): ( ?. O/ r9 K& h& Z$ }
cookie=0x0, duration=90537.25s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
$ t" x  O. G- h4 V# r7 Fcookie=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
  @' K  C  A7 r1 acookie=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
# ]( |/ t& I: R" w: X8 d- Dcookie=0x0, duration=86147.941s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2) 9 I* i" j! u& ?3 y
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)
" Y7 a  v; u; \# e0 Ncookie=0x0, duration=86147.941s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) 2 m3 j4 D6 M3 M
cookie=0x0, duration=86278.986s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2) $ E0 O4 H) {; V6 Y! g  Q0 p, y* y
cookie=0x0, duration=86357.407s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop ' X; s- ^( V  j* T7 I; E
cookie=0x0, duration=83587.281s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
0 m/ c  Y* s7 A$ k% [ 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]
4 b4 _0 S  C3 z, h6 m* Y
' }2 ^, x2 A+ V+ qtable 10多了一条,vlan为20,dl_dst为50:00:00:00:00:01,发送的时候从port 1出去。' a$ V0 U% Q  Z6 ]  Z/ t
; u8 L* [0 ^+ d2 x2 y* Y
测试二:从port 2进来,被打上了vlan 20,mac为50:00:00:00:00:02. ]$ N% }8 Z' e/ G! k

* O) |2 O9 o( h" o8 K. v3 L$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=50:00:00:00:00:02 -generate   + s- B0 E& T9 j$ c% X/ ]/ @; c
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
8 ]" f! c  N1 i) {4 ]; DRule: table=0 cookie=0 priority=0 5 `2 t# c' K1 }1 {9 Q  }) }3 ?  q" M
OpenFlow actions=resubmit(,1)3 W4 o* u7 H) E5 i! h* \( G

9 X& M5 O- b$ H* K1 Q" o+ s) v        Resubmitted flow: unchanged 1 r8 X6 Y# L- u) }7 G
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
3 N- |# Y% Z. V. `% L' w2 _        Resubmitted  odp: drop 0 J7 p2 s! w! e7 W) _5 U; o- Q
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000   S5 C9 f/ H1 m- w. W/ B, P% N: |$ y5 ^
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
1 g* g$ W* a& k8 S# a7 T  }1 F. s" L
9 N! q9 _/ H! U: m( _. N1 W7 {8 Z                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 }4 K' N: x# u                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
7 h1 ]3 @, s: c/ n0 M5 z                Resubmitted  odp: drop
1 J, K# N# z: k: O                Rule: table=2 cookie=0 " X5 c, P' W1 s- q9 Z" 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)( F) ~& U& D% l' \" k( r. ~. Y

" j4 I0 e. d7 J* W! h& c( Y; r8 W                        Resubmitted flow: unchanged + P6 z' Y1 I/ B( j
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 + d- V9 V9 _/ P+ c- L+ c: v* ~7 P! ?
                        Resubmitted  odp: drop
' }" ?, B" n9 f' g% ^1 f) W2 H                        No match+ r! \: r0 B( h6 V) X  {4 H
1 \7 q; W+ z( }* Y- P/ X
Final flow: unchanged
! b( W$ z, O& H4 mRelevant 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
6 r3 ^9 @4 E% }2 H% O$ F8 zDatapath actions: drop
# E  a& I3 a1 a# j8 E/ M; ]
% {) p' K$ \5 }& ~9 t9 ?) D$ sudo ovs-ofctl dump-flows helloworld                                                
# E$ c/ {6 O8 ~9 Q0 z6 v& fNXST_FLOW reply (xid=0x4):
4 v. F- y2 g  \cookie=0x0, duration=90823.14s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) , d, o+ K4 S# |2 s
cookie=0x0, duration=91013.099s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop ; N0 c& O- i  b. w* @
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
, M7 f4 s  i6 e, e2 b! lcookie=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)
9 X' W/ ~6 T( N  Y9 W, r3 |1 {8 |5 @9 Dcookie=0x0, duration=86433.831s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
# J! m# Q7 s6 X. ^cookie=0x0, duration=86433.831s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) # k9 J' ?0 k1 V$ L7 v4 @5 l# r: I
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) - C$ h9 K* E9 ~# a4 a
cookie=0x0, duration=86643.297s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
7 K0 v% N6 L  n% D& A3 }( V5 W& Ccookie=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 [, W" ]7 f6 c2 M2 X% _& t cookie=0x0, duration=4.472s, table=10, n_packets=0, n_bytes=0, idle_age=4, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:02 actions=load:0x2->NXM_NX_REG0[0..15] , z, G$ q4 G9 [: h; Z& [
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]. C# X) f. T5 q" }" D9 M+ S6 Y7 W

3 K$ A( y/ y- o+ e实现第四个table 3: Look Up Destination Port9 G; j4 w; y2 {/ u  B5 L( B$ `
2 C! `. G, [5 ?3 ?+ X# f" P4 W
在table 2中,vswtich通过进入的包,学习了vlanid –> mac –> port的映射后,对于要发送的包,可以根据学习到的table 10里面的内容,根据destination mac和vlan,来找到相应的port发送出去,而不用每次都flood
' w/ y- s2 H6 d7 R/ W) N  J3 g" K4 t, R7 m2 b/ E/ @
sudo ovs-ofctl add-flow helloworld "table=3 priority=50 actions=resubmit(,10), resubmit(,4)"
& ]% D6 T% @9 n- S
, N/ }9 g- b9 x: a添加这条规则,首先到table 10中查找learn table entry,如果找不到则到table 4
" D' i- j2 V" y( z( a' S1 E
4 e3 M% N4 G( J* `% S1 C如果包本身就是multicast的或者broadcast的,则不用去table 10里面取查找。
" M0 O$ m0 w4 s7 K/ a
1 r( K4 F+ a9 F( z0 x3 qsudo 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 v" p( q$ |( A# g, a$ K' p* ?+ K& v3 M; s
我们进行一项测试
! t% Q- p8 o+ ?3 H, M4 r- i& P- h4 z+ 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! G; u+ F6 G# }& PFlow: metadata=0,in_port=1,dl_vlan=20,dl_vlan_pcp=0,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000 2 |* E) Y) w4 W+ R  P
Rule: table=0 cookie=0 priority=0   l% T3 @1 D5 l# s: ]% r+ n8 |
OpenFlow actions=resubmit(,1)
5 p, p. G& v* P8 S  F8 d
: f% g3 C7 ?# t5 ]        Resubmitted flow: unchanged
& y2 s! c) a# c( y  g* X) l. @        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
9 ?$ x2 Y" K) F2 q; T% _        Resubmitted  odp: drop / C0 b2 g+ m1 Z, _
        Rule: table=1 cookie=0 priority=99,in_port=1
' q( ]" Z3 r8 Z0 d: `        OpenFlow actions=resubmit(,2)) P* F1 w. _! o/ z
; {3 g0 P  K# j7 ?: w1 R5 z
                Resubmitted flow: unchanged
" q% d" f+ [, ]3 ^                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
; H1 t, w( q6 N  ~" r' y  x" r7 |                Resubmitted  odp: drop " R. ]4 D4 L8 ]% X4 {* S, Y7 D
                Rule: table=2 cookie=0 ' }1 K# ]: j8 c! 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)
' q; S1 x, |: l1 `( x2 b" _
! {9 h1 t4 p* Q                        Resubmitted flow: unchanged
( C0 k  R" ?: t, {                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
% ]: m9 A0 B! L                        Resubmitted  odp: drop # a; R, J+ S$ ]6 m2 ]/ H
                        Rule: table=3 cookie=0 priority=50
/ x6 N0 j2 C$ |+ f8 p4 j, X- |2 T                        OpenFlow actions=resubmit(,10),resubmit(,4)
1 H4 a: l! h7 N5 F9 f6 p
" j, T9 \; v( Z+ k! c2 D                                Resubmitted flow: unchanged ; R- Q1 P0 m4 }0 E' r
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 - K* o- {! q- O2 B4 L
                                Resubmitted  odp: drop
8 I4 @& ]( p# i: z  @$ x% q                                No match1 y5 U7 _2 L; |* _1 n9 c6 n
& ~  p, n; M3 `% b7 x' y
                                Resubmitted flow: unchanged 4 m% }+ J6 ?( D* P  u0 H' G
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
- p' Y! j6 i2 V$ F" C' J7 g1 N  N9 l                                Resubmitted  odp: drop 3 Z- ?* a  @1 c
                                No match
, [! ^  {9 t5 Z5 K: A& j' d) c3 G3 b6 z$ c+ [  L9 ^) U9 J5 o) v
Final flow: unchanged
- E0 [; i' C$ [+ n  _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
3 _  r6 N9 v# Q' o* e. hDatapath actions: drop
! I, I5 d- G5 r
8 F) q6 N) q( l, E  ~5 y+ K由于目标地址f0:00:00:00:00:01没有在table 10中找到,因而到达table 4.
  ?! K& D7 W9 ^4 Y" P, z- e1 N
0 v& K4 R; y  ^1 u; w3 y$ C2 Y但是这次测试使得table 10中学习到了mac地址90:00:00:00:00:01
# e/ m8 J/ A: p! [
6 n. M7 ^2 G/ _( p! L$ sudo ovs-ofctl dump-flows helloworld
* H) D' a1 p% s+ [0 oNXST_FLOW reply (xid=0x4): ; M7 `8 h1 B5 ^2 I7 k
cookie=0x0, duration=91588.452s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) . g# ~( V  X7 c7 B
cookie=0x0, duration=91778.411s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop ; A9 L+ p- E! b, t" w- Z5 U. b
cookie=0x0, duration=91713.926s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop , V, [( q* N9 G$ F7 ?2 ~: k) Z2 C
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)
8 O/ k2 i) M( [: w  acookie=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)
' Y2 [4 q# \  T( s5 o# scookie=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) / E! t/ F/ |" l
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) 0 b. r6 _2 ~$ [7 F7 r. j
cookie=0x0, duration=87408.609s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
% B2 b% k0 h3 H' C0 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)
) O5 [. h: G+ y/ O2 i& _4 ^cookie=0x0, duration=352.841s, table=3, n_packets=0, n_bytes=0, idle_age=352, priority=50 actions=resubmit(,10),resubmit(,4)
* ~: R% f$ R1 M# W/ I: Ncookie=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) % X) v- u$ |3 @# Q; \( g# w
cookie=0x0, duration=117.364s, table=10, n_packets=0, n_bytes=0, idle_age=117, vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]
5 s6 P/ U! `* B; T1 icookie=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]
- z0 [# v6 z  o1 v5 I7 \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]
/ D# K% f4 G& P/ d; G' K+ D% E& n0 ]  A
下面我们进行另一个测试' @3 v5 w" d& a9 \, ?6 a) s

, g* `+ f( m# V' J$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01 -generate   
. z) B( I- X( d" G; ~2 S9 vFlow: 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   g5 s  a  F% N3 Z0 }. D! e
Rule: table=0 cookie=0 priority=0 0 k$ B( E' y+ U4 C" q$ s" U+ M
OpenFlow actions=resubmit(,1)
; Q& }" ?( \# r1 ]' G
/ U( d/ S$ n% O( V3 M        Resubmitted flow: unchanged 3 F* A! `7 N0 ]
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
/ P* J, u% Y7 \0 Z3 D  @        Resubmitted  odp: drop / J1 V9 B' y( A0 v. Q
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 ) S- n0 j4 Z7 m! G# o4 w
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)& g" G% F* ]) |' I
# u- b: `+ m. v, R; G
                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 ' U9 F  {- J* [9 a3 ~/ `# g6 l
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
2 H/ y. h0 B3 N" y                Resubmitted  odp: drop " r6 K% u+ m' ?3 X% ], W
                Rule: table=2 cookie=0 * S/ C% D9 `" Z; i. ?1 |* R$ c
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
5 K: Y! X- o; ?. D# D" r! l0 s4 ]! H
" E# x. R, c1 L9 A6 x                        Resubmitted flow: unchanged + N7 G, k$ k' b
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
6 C& G% g  k9 p, t5 K                        Resubmitted  odp: drop 6 l" y! B7 I! Y5 j2 m8 M) z
                        Rule: table=3 cookie=0 priority=50
+ b  E# }. q0 T' C8 D5 K9 e4 V7 t                        OpenFlow actions=resubmit(,10),resubmit(,4)
( j( ]) v9 L' h- i- r* Z/ H9 V) L  y2 Y9 O" @+ b5 c& H8 K; T+ }& }
                                Resubmitted flow: unchanged 9 k! ]7 Q, w/ v, Y! ]
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
  g1 T( |) I9 |5 k! E! k                                Resubmitted  odp: drop ! ~5 {/ u6 t; |$ n. u
                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01 # e) X0 t. P# h  t; E2 S
                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]
0 g' R+ j  }( p7 E; u( P
1 T2 r1 h2 r* j' Z6 L$ p- H                                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
1 B( f% u! V: U- {& m                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
! g+ Z- A7 @  N                                Resubmitted  odp: drop & W" v) Z" G; L
                                No match
; W2 L; v2 Q3 B& u: @% {2 m' r& {& d
Final flow: unchanged 2 q1 R2 \$ @2 g0 H# ]8 Z
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 " V! e2 F( M& }: b* `2 x0 F
Datapath actions: drop
9 Z0 k. Z6 D( V7 |- g; S& s  ~$ e3 s) q. }; S& Z" u; C
因为刚才学习到了mac地址f0:00:00:00:00:01,所以这次在table 10中找到了这条记录,这次同时也学习到了mac地址90:00:00:00:00:01( z5 D: ]. A9 z
5 ~/ k6 @; s* L6 F: E5 X! o
下面我们再发送第一次的包+ Q; q8 O$ D: ?& a* p
7 d& s; S1 {+ G
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=20,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01 -generate + C, y+ U6 a4 k2 s
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
# v3 N( f7 B. Z: g  ERule: table=0 cookie=0 priority=0 8 F- s( B. L1 I+ [+ W
OpenFlow actions=resubmit(,1)- z2 N! T4 [0 A: s6 V
# X; S! K# e' e9 H' @0 a8 F+ y
        Resubmitted flow: unchanged
4 E8 A: E$ i8 Z. d, B# F7 q        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
! F  F; E/ [2 a% F$ P        Resubmitted  odp: drop ( c  l7 l8 O; _; k% ^4 N9 U
        Rule: table=1 cookie=0 priority=99,in_port=1 . [$ p, a0 s3 g, c# e$ w6 c. X
        OpenFlow actions=resubmit(,2)
" c; N# ?- I) `5 ~5 A7 P$ m
; L) d8 a, g% k; j; v$ V5 o: D6 F# Z                Resubmitted flow: unchanged 6 H; z8 f; [; g8 j. l5 K6 Q( _; T, {
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
$ v& b/ M/ d2 }$ ^3 ]                Resubmitted  odp: drop
5 J7 S) ]9 ^! M* [3 U                Rule: table=2 cookie=0
* [/ `% l: M; R0 Y( 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)
) ^& v- H! K& z' V' k- T
' L. t( S4 V, @6 p- W, d+ m                        Resubmitted flow: unchanged ! Z0 p& R9 p. F1 S; [
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 - z. Z, \9 z' t6 Y2 M2 }9 n' T
                        Resubmitted  odp: drop
; e( e% ?( w) ^- Y                        Rule: table=3 cookie=0 priority=50 : N6 t" T# g# A: e1 r
                        OpenFlow actions=resubmit(,10),resubmit(,4)6 U; ]% S; \4 o! Y3 w8 Z
/ T) W. {+ C! N# c+ _3 z
                                Resubmitted flow: unchanged
8 ^* u5 h8 k: e& D% J7 G( i/ u                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
1 v* ]/ }" y" \' i                                Resubmitted  odp: drop
" U! T5 C/ q. Z, \  |                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01
8 @5 d/ o6 S4 |/ X* {2 u: [: ]                                OpenFlow actions=load:0x2->NXM_NX_REG0[0..15]: q' }; ]$ c% A: S" _: C+ ^( M
  l* n# d  N# G. u9 ]" `) D
                                Resubmitted flow: reg0=0x2,metadata=0,in_port=1,dl_vlan=20,dl_vlan_pcp=0,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000 6 F: R& f+ ^: V+ c/ J! F1 A
                                Resubmitted regs: reg0=0x2 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 % U; w" b, D4 u# u* b3 c9 p  v
                                Resubmitted  odp: drop
5 f# E: q% f' s# N( o% A' m% {+ M  ]                                No match
3 V8 S2 U/ h  R% H. Y( o
3 G" }/ x! |% Y5 G9 |Final flow: unchanged ) b% g9 _8 C; w* F
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 : U( E$ P0 y) |+ j# f6 D" I
Datapath actions: drop
, j; _9 f4 v  U' l
3 c, ]5 r3 @4 s9 c1 Y0 K发现也在table 10中找到了记录) ~7 n9 Y; V* [* F9 T( r7 i& o8 u

* G* _# ~# t$ i, p- F实现第五个table 4: Output Processing
7 ~! E2 A  U# O2 l8 Q5 r+ Q6 v' o( x
这个时候,register 0中包含了output port,如果是0则说明是flood。6 D! v+ [3 Y. S, d+ `
4 v/ _- ]* y+ L/ w
对于port 1来讲,是trunk port,所以携带的vlan tag就让他带着,从port 1出去。( V. c  F% s! u/ ~  C

6 [( _! B* H/ r2 @# y3 {! x  ]sudo ovs-ofctl add-flow helloworld "table=4 reg0=1 actions=1"
/ P# `$ ~6 k3 }6 ?0 x9 R* F( _3 e8 @" T+ p4 q. i0 R
对于port 2来讲,是vlan 20的,然而出去的时候,vlan tag会被抹掉,从port 2发出去" e# g/ R- o( B0 @- [1 f8 Q

1 \/ k; E: u; a# a. C对于port 3, 4来讲,是vlan 30的,然而出去的时候,vlan tag会被抹掉,从port 3, 4出去$ E7 P, @# ?+ y) y% Y3 o

/ u  T6 l. t7 n( x+ S5 b$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   3 t0 l5 P# }  W( Z
        table=4 reg0=2 actions=strip_vlan,2 0 b2 `; Q- s8 |4 l( \
        table=4 reg0=3 actions=strip_vlan,3 6 o/ o5 V+ q6 G) u8 A
        table=4 reg0=4 actions=strip_vlan,4
3 E9 _$ k. L2 t. A: ?6 XEOF
" |. H$ W2 p6 g  x/ ]$ L1 r- |6 k7 \. _% L( Y2 W
对于broadcast来讲,我们希望一个vlan的broadcast仅仅在这个vlan里面发送,不影响其他的vlan。$ R) X# p& V7 Q) }2 n: ~/ L) I/ J
" ]: a; u$ T1 q' j8 t
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   7 G" I$ x+ a% s5 c5 d
        table=4 reg0=0 priority=99 dl_vlan=20 actions=1,strip_vlan,2 , [; s8 m: O- r" f# r" K
        table=4 reg0=0 priority=99 dl_vlan=30 actions=1,strip_vlan,3,4
- a7 c1 {5 ]; y8 [8 v        table=4 reg0=0 priority=50            actions=1 , J6 v  V7 q6 c0 g; M  _7 I4 b
EOF
: N+ l6 a; E6 v- F' F$ |. K- ~  w; j6 X  h; ^
所以对于register = 0的,也即是broadcast的,属于vlan 20的,则从port 1, 2出去,属于vlan 30的,则从port 1, 3, 4出去。6 K' B% [/ K- f, r- E6 e

) m- K  x& z1 l+ W: |- }0 b3 L  @- K- s$ sudo ovs-ofctl dump-flows helloworld
* I) N) r3 N! L8 @  GNXST_FLOW reply (xid=0x4): 4 X  a$ `! G3 F# u% m6 b
cookie=0x0, duration=92909.119s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) $ g) _5 ^& V7 G2 F+ @, q
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
) Q9 A( O& R1 {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 ) P, n6 O2 ^1 v# z  q
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) / \* H% T& o8 U
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)
5 r: g" X- j% u" |  v# [( ocookie=0x0, duration=88519.81s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) , ~: O. H8 i- D8 I, w( L! X: k
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)
8 d( }6 K: \" j% e4 Q  [2 Xcookie=0x0, duration=88729.276s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop ( c) L( o6 Q$ y* p* r5 }
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) 2 R0 i) R" S, _
cookie=0x0, duration=1673.508s, table=3, n_packets=0, n_bytes=0, idle_age=1673, priority=50 actions=resubmit(,10),resubmit(,4)
4 m  A. |4 X/ M" g- }( fcookie=0x0, duration=1533.371s, table=3, n_packets=0, n_bytes=0, idle_age=1533, priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,4) 9 m& s$ ^( N6 v  R9 c+ e
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x3 actions=strip_vlan,output:3
$ B4 d+ y0 M6 A* F" Vcookie=0x0, duration=228.839s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=50,reg0=0x0 actions=output:1
) H5 U8 D1 F' J. e, \cookie=0x0, duration=483.068s, table=4, n_packets=0, n_bytes=0, idle_age=483, reg0=0x1 actions=output:1 1 T$ ^* J! @! r3 I3 d
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x4 actions=strip_vlan,output:4 , G, W; Q- A% y' ?* u0 C
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x2 actions=strip_vlan,output:2
' W8 z$ j$ j$ I2 @1 I; }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 + c8 g& ~, o( F2 ^& g* R, I" z
cookie=0x0, duration=228.84s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=99,reg0=0x0,dl_vlan=20 actions=output:1,strip_vlan,output:2
  i) w6 G) D4 h" _+ e, H' scookie=0x0, duration=1438.031s, table=10, n_packets=0, n_bytes=0, idle_age=1438, hard_age=1109, vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]
$ w, ^9 q! `7 Vcookie=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] ! h4 j0 U; i% |9 L
cookie=0x0, duration=1258.881s, table=10, n_packets=0, n_bytes=0, idle_age=1258, vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01 actions=load:0x2->NXM_NX_REG0[0..15]
3 j9 d2 _0 f5 ncookie=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]
# k& A7 [! |3 t( S' _# T  n" j: b% t& V& l& I* P: C
首先来测试一个multicast和broadcast
* I3 S$ s6 J6 X4 I2 O$ W: M3 q( f. z. ~
如果是一个port 1来的vlan 30的broadcast  h# M/ e! V) l+ L6 T
. _, Z5 p4 S% D/ [2 `8 W9 \
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=ff:ff:ff:ff:ff:ff,dl_vlan=30
+ q3 Q2 [, K8 n' ?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
: d/ }& ]) P3 X, U  q. [Rule: table=0 cookie=0 priority=0
: s8 F/ H( ^3 Z2 c1 o4 X9 sOpenFlow actions=resubmit(,1)  h7 Q" a% ?& D$ ~4 s) K8 A1 ~

% [) {7 p6 E5 X0 s. J+ |6 D1 w3 d3 S        Resubmitted flow: unchanged
7 K, ~9 W/ l2 r& f5 G! `        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 2 J9 O5 Z  U& n- g$ b- t" ?
        Resubmitted  odp: drop
! l+ \) E: |2 ^  G        Rule: table=1 cookie=0 priority=99,in_port=1
: G2 \/ C6 e8 p. E! B  z        OpenFlow actions=resubmit(,2), L* @9 E5 ?, d/ r# v0 v
+ {# c4 K- _$ d% E; T
                Resubmitted flow: unchanged
% z9 I: K" ]. K7 w                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
1 Y# W; y  {5 A( O' K, z/ J8 g                Resubmitted  odp: drop 2 g, s( |* @4 _3 P- X
                Rule: table=2 cookie=0
8 T( b" Z) 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)7 p0 T6 D, G/ F, q& ^% ]

! ]: }- D4 s2 k! R. [                        Resubmitted flow: unchanged & y+ \- j$ Z) J0 i! d/ c
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 r' p2 \3 O7 e; \5 P* u
                        Resubmitted  odp: drop / }: y! y) X+ U5 T
                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00
4 n" {4 ~/ H& Q                        OpenFlow actions=resubmit(,4)
; h6 }3 J3 d; V0 z  x, N! G$ K* w/ v/ H3 s  E: f# l  f$ P8 g; r
                                Resubmitted flow: unchanged
2 {9 s- Z1 D: h5 }0 D" x3 y. A5 I( }  m                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
8 n# I- Y& T9 Z4 H2 B7 n( L                                Resubmitted  odp: drop
* D: p% _7 I; J1 W3 W+ j* Z0 ^, y                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
7 P1 a# U5 F; P5 G                                OpenFlow actions=output:1,strip_vlan,output:3,output:4 3 s2 U: m6 e" @& S* r1 C
                                skipping output to input port6 E0 `( }. h2 \4 _2 a( R
; |- c9 e; G& c+ w% f
Final flow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000
+ y' Q6 C' f0 I9 ARelevant 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
$ S3 j) Z: A  j6 fDatapath actions: pop_vlan,12,13
6 L8 K4 e/ e$ J" t& h8 i  n$ f8 n5 K. R; N( l1 U/ y/ p# Y5 q
结果是port 1就不发送了,发送给了port 3, 4  M* _7 i5 W9 j& C

5 e3 I3 W! o0 v' o$ sudo ovs-appctl ofproto/trace helloworld in_port=3,dl_dst=ff:ff:ff:ff:ff:ff . K' j% u1 o8 _/ B
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 - M4 o0 y) C: O% s& T
Rule: table=0 cookie=0 priority=0 6 ~6 G: D- A) F
OpenFlow actions=resubmit(,1)6 z2 g' p! d& b$ C# s" ]. r

* |6 `3 s5 x+ U5 s        Resubmitted flow: unchanged
6 u4 x' L% R- w3 b0 B4 n- M( }; {        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 * [6 {: H# y* o- w" j; s9 s  z
        Resubmitted  odp: drop
) r" i6 o3 e! ~2 u/ I' o        Rule: table=1 cookie=0 priority=99,in_port=3,vlan_tci=0x0000 " F6 p2 ^' @! k0 X$ G
        OpenFlow actions=mod_vlan_vid:30,resubmit(,2): p0 v* f  ?' M( q$ K8 ]
3 P, P: X" R1 {( d
                Resubmitted flow: metadata=0,in_port=3,dl_vlan=30,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000 / \1 J) O% F1 c3 ?) |8 ^6 f
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 $ L& u( l  ^  ?: H+ @; H
                Resubmitted  odp: drop
0 _0 w1 r2 g2 I9 @2 O" \8 D7 a                Rule: table=2 cookie=0
9 w/ O% L$ X2 S+ 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)
5 E, w& {$ I( B- p  U: l
( q  A0 i2 q6 t) a                        Resubmitted flow: unchanged * c) A: C1 J" {
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 Q4 Q* }: A# z
                        Resubmitted  odp: drop
% ?3 J0 y4 ^% k, F- y* U                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 % g; O( F2 G& ], E! z; r1 V% e
                        OpenFlow actions=resubmit(,4)/ H) f: L9 ?8 ?) M. \! T
3 u1 n, p# p8 p+ K, q2 q. _1 |& A/ U3 H
                                Resubmitted flow: unchanged 9 L& g8 B$ Q, w4 r3 R  p1 e
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ; p' s) P; L' p
                                Resubmitted  odp: drop : _* x2 Q8 U) Z( [  F( P
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
# R% l& {6 z/ N9 X                                OpenFlow actions=output:1,strip_vlan,output:3,output:4 ; c+ |$ m% P" O5 k
                                skipping output to input port
) r* Y! H0 B% c% {4 G1 W1 y; A- }, V' d
Final flow: metadata=0,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000 - @$ N: z8 a* z) Z) u& C  t# D
Relevant fields: skb_priority=0,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:f0/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
3 o7 ]# d# }& x1 S5 }- O9 BDatapath actions: push_vlan(vid=30,pcp=0),10,pop_vlan,13( I+ u; D$ \, ?0 U/ G3 q

+ y6 e  U, V" `9 @接着我们测试mac learning% r7 l' l; u: \1 w  o3 G
; R3 W7 v, Q5 u: }1 _
$ 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   $ R% N# a# D: l* J- G! Z4 G, q
Flow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000 4 H1 q% ~( m5 \6 T, B
Rule: table=0 cookie=0 priority=0
! r( @( {( f# Q5 T, y/ hOpenFlow actions=resubmit(,1)
- t  H8 A* v- o: o
2 t2 x' t) L* P% y        Resubmitted flow: unchanged ; [1 m/ M9 Z# ~( C# [* S0 V
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
1 B5 [1 J; J. z; v        Resubmitted  odp: drop ( w5 `& V$ f5 h. R8 g8 c+ s
        Rule: table=1 cookie=0 priority=99,in_port=1
; c8 x' G  \  R. H        OpenFlow actions=resubmit(,2)/ j  A2 w/ z: x  a3 D# b1 z& K0 u
0 G9 N3 }9 N, r0 P7 Y
                Resubmitted flow: unchanged # g% Q! M- O, w! [
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 $ S* L$ d$ n7 K7 m+ ^/ ]8 S2 ]0 g( L
                Resubmitted  odp: drop 5 b4 G4 e$ s: x5 u
                Rule: table=2 cookie=0 & W; W- x: S2 D5 P- T7 W5 p5 e
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)4 T2 b' Q1 R3 a* f/ s" n0 R
; ^# o  J9 _9 d! b
                        Resubmitted flow: unchanged / V9 N" ?! x0 ?+ e0 C# n
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
; z  T8 ~0 t9 K+ q! _# |1 g                        Resubmitted  odp: drop
" O( j" T. X8 [) k( R% ]( @8 X$ T                        Rule: table=3 cookie=0 priority=50
. w& ^& }' O7 ]8 i                        OpenFlow actions=resubmit(,10),resubmit(,4)
+ G3 n- q# Y+ j: J+ p( X" G8 F3 f0 i8 l3 S, [' {( @
                                Resubmitted flow: unchanged   a, ]; X; a; h* Q
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 * `* q3 [# t2 w' S9 u) q
                                Resubmitted  odp: drop
5 \9 R8 ~" i  Q7 Y, V: U0 i                                No match7 [* y2 h) f  Z7 j, {

) D9 q% [1 v3 j7 K% `  P( f                                Resubmitted flow: unchanged
: c$ H* }; v. x7 D- n                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 + w$ T/ o( _# {" J; F9 \4 b- z( @
                                Resubmitted  odp: drop
0 ^: @# C; t0 V8 o                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
/ O9 K1 }8 w- f# k                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
+ C6 a6 a1 `0 _; Z7 f. u                                skipping output to input port
* [$ ^& W9 d: y5 C
' V$ H2 `/ A; p% F2 t5 oFinal 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
; J2 d' b. H) S( y( NRelevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000,nw_frag=no   j/ ]8 w6 {/ h  ^" ?7 P3 `, Y
Datapath actions: pop_vlan,12,13" L( U( \, [4 D  B2 S  x
/ a# [# O) l9 ^( d. t: f
由于这两个地址没有出现过,则除了进行学习以外,广播发送给port 3,4
9 n$ ^8 X2 j5 a; e  Y3 `3 P
' l7 z$ T1 d. y1 A: n! E) u$ 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   
& g- M7 }, f/ Q" A- GFlow: 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
. ]" I% Z5 [) q) A5 K. tRule: table=0 cookie=0 priority=0
5 y0 b7 C1 V. uOpenFlow actions=resubmit(,1)
5 b7 r4 b6 p. I6 K0 P' _
* M8 {, T  T# }* c( H        Resubmitted flow: unchanged 5 C. ^( O6 D" o/ l2 ?# J0 G4 p  n" F
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
" U% L# o6 e4 j+ |$ o$ z& @        Resubmitted  odp: drop 5 X5 y4 F8 v% g$ k  ^$ V
        Rule: table=1 cookie=0 priority=99,in_port=4,vlan_tci=0x0000
  t6 C  V) b- U6 t$ R        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)* R, v7 p/ i( |0 Z5 U# Y+ u
% E) `- \2 Z% I# \* Q9 z  |  v
                Resubmitted flow: metadata=0,in_port=4,dl_vlan=30,dl_vlan_pcp=0,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01,dl_type=0x0000
& p+ [( l: P) R9 G( p                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
1 y. E% Z# T; J  t; U: M+ W) p                Resubmitted  odp: drop - J# }( A& y; f/ ]7 z; \! R
                Rule: table=2 cookie=0
. C$ a: m' J* U& P. C                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)1 E& r& [4 C/ N$ t$ f: ?  a1 h

# C7 O' l7 h5 \8 P- }0 ]: Z5 t: j; C                        Resubmitted flow: unchanged
. t, I/ o1 j7 A4 F                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
' r2 [+ U. K, V% m4 B9 ^                        Resubmitted  odp: drop
, K6 C* z# D2 F7 B( }( A                        Rule: table=3 cookie=0 priority=50
' b- t* x6 Q; v4 O, V# c                        OpenFlow actions=resubmit(,10),resubmit(,4)
& e0 n7 m7 c( H3 J# j6 D8 x
  w0 `4 X' I: D+ Z+ C4 `/ i                                Resubmitted flow: unchanged 0 M! d, q6 ~% p  o; p, C
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
# L- X$ G( T* `" {6 e+ x1 f                                Resubmitted  odp: drop
7 x2 G; |, Y2 C. h& v1 l                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=10:00:00:00:00:01
% M; c) b% y( G' p* z" M, s                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]
8 |; ~( ~9 A) B( W$ c, S4 L, A
* \5 X1 q' w2 G                                Resubmitted flow: reg0=0x1,metadata=0,in_port=4,dl_vlan=30,dl_vlan_pcp=0,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01,dl_type=0x0000   h, r% n# z& M* j
                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
- z* m2 ^1 W+ F2 Z                                Resubmitted  odp: drop
1 W. o3 L- k7 l4 @: [  R                                Rule: table=4 cookie=0 reg0=0x1
% n4 t* G' f7 K: F5 c/ }4 {                                OpenFlow actions=output:1& `3 ^, R5 M5 ^7 K
1 G& K! v5 r' U- p, L
Final flow: unchanged 4 J+ g* L2 _9 `3 O- C( P; i
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
* s8 h# V  a: [$ |! IDatapath actions: push_vlan(vid=30,pcp=0),106 d1 u% ]' M1 V3 |0 I
* X- M% d. x- h' ~; ?, r; K
回复的时候,由于学习过了,则仅仅从port 1发送出去。* a9 F9 a2 \& [$ I$ @$ i  o- w
% _, o3 C' H3 r/ l5 l1 L' i
$ 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
0 N  p% X  }  X* d  F! m' x, V3 eFlow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000
5 r6 K2 m/ u( j6 IRule: table=0 cookie=0 priority=0
% w1 `# I8 G  w3 zOpenFlow actions=resubmit(,1)
# u) g5 s5 Q7 l
# W. ]1 E5 D& @3 k        Resubmitted flow: unchanged
5 ]! p. i$ g& m/ x1 ]+ F3 S        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
4 v) \5 s' B, l2 h4 Z        Resubmitted  odp: drop
7 U4 {7 d2 j; j5 n" ^8 C        Rule: table=1 cookie=0 priority=99,in_port=1 * }. l0 G- d% U! L. t
        OpenFlow actions=resubmit(,2)4 E8 F1 }4 X' r$ Q( S

1 s4 v" q5 f7 {6 V, V$ u  L( {$ m9 l                Resubmitted flow: unchanged
# k7 O) A1 N. L- I                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
8 _% W! r$ Q/ k8 l7 `9 {                Resubmitted  odp: drop
; T) m9 }5 d6 O9 A" ^                Rule: table=2 cookie=0 0 G* Z& B) r% 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)& }. V7 S3 r: z7 a" T- p

7 h+ o* b8 }# j. B, t: E9 k* d* w                        Resubmitted flow: unchanged ( T) i1 o6 `! H: n3 X+ G
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 # @, _& t8 K* T/ }: {+ z
                        Resubmitted  odp: drop
9 Q7 v* c6 I2 ~  Y5 K0 R9 {( m                        Rule: table=3 cookie=0 priority=50 . A7 D1 U: k3 A; h
                        OpenFlow actions=resubmit(,10),resubmit(,4)* o* v1 ~! G6 w/ _# j( q

! _' i- V; ^* C# b8 M                                Resubmitted flow: unchanged ; ?: i" u* |1 k7 o; U
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 * A/ v, e7 O9 ~8 B9 b
                                Resubmitted  odp: drop
7 ^3 _5 L. a/ n* b6 v7 [% ~, E                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=20:00:00:00:00:01 - H6 n- k1 n; ^9 N8 V6 |: f9 y; ]
                                OpenFlow actions=load:0x4->NXM_NX_REG0[0..15]6 I$ X# s* E; a- S0 q
" Q5 T* s5 T9 T+ f/ P+ ]( O( U* D' u
                                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
, A  \' W5 i4 w$ ^$ j0 S& _                                Resubmitted regs: reg0=0x4 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
+ _) k. u' m3 }. V) m) B2 b1 Z0 T                                Resubmitted  odp: drop
8 M' L% s# F) H  W- [& g                                Rule: table=4 cookie=0 reg0=0x4
. X$ z+ L" p4 `! X# T4 [8 x                                OpenFlow actions=strip_vlan,output:4
. |5 {& R, F6 j# t% V
; X6 V1 {9 l2 e( OFinal 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 & k8 @8 I$ d( f! E# Z, w
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
- T( X  w* ]3 P/ a5 tDatapath actions: pop_vlan,131 N- S" x- N; r0 t1 o2 q0 o$ i* }

2 i& F" P/ G0 M% J. y$ C由于在回复中进行了学习,因而发送的时候,仅仅发送port 4
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

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

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

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

GMT+8, 2026-4-8 21:36 , Processed in 0.091330 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

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