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

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

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2019-10-25 10:00:33 | 显示全部楼层 |阅读模式
ovs-ofctl dump-ports 输出交换机的端口统计信息,包括收发包、丢包、错误包等数量。 ovs-ofctl dump-flows alubr0  + g( I( i' }0 O4 f' ]
OFPST_FLOW reply (xid=0x2): flags=[more]
+ ]8 {$ J# ?7 S+ L7 h1 k; k; f 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[
) c2 Y  H4 V, I& y: e0..11],strip_vlan,resubmit(,22),resubmit(,23),move:NXM_OF_IN_PORT[]->NXM_NX_REG4[0..15],move:NXM_NX_REG1[0..15]->NXM_OF_IN_PORT[],re
" r/ h' N1 J. Z& X1 Ysubmit(,4)
2 Q; A/ U1 O+ u( k; }$ I cookie=0x1, duration=1263.439s, table=4, n_packets=36175, n_bytes=26587191, priority=0 actions=resubmit(,27)$ @3 Q- c; B- P9 d: g! o1 p
cookie=0x1, duration=1263.439s, table=5, n_packets=35646, n_bytes=26564073, priority=0 actions=resubmit(,7)
2 D9 u/ f# K9 `9 S+ I, _7 r2 P 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
- t- K$ f8 [/ W! H( {; ^ cookie=0x1, duration=1253.085s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=3575,dl_src=fa:16:3e:e8:53:ed actions=drop
& T+ z5 |9 J2 Z7 Z/ [; o8 m 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=drop6 B  g6 i2 R$ H; {& c/ w
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
& @' p' s* ?0 ns=drop
$ l8 A6 o+ v6 m0 i5 | 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
, P4 B4 g* \$ x" ?$ _' U' r 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
* g  x5 ?1 g+ o' _  Y% T cookie=0x1, duration=1196.999s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=249,dl_src=fa:16:3e:83:aa:df actions=drop
8 q; ?. v8 g8 e7 ~5 `3 s 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' o5 i3 p# J" v2 _) R0 C2 @" {1 U
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=drop1 [) r- K1 m0 j! Z0 Y- p
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=
  m0 o# X' }' G% I* |' c5 A7 kdrop* _% w/ g. b8 r9 a, P2 I
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! k8 X6 X4 H# s( e2 l. d% I6 e
cookie=0x1, duration=1207.443s, table=7, n_packets=22, n_bytes=3454, priority=32769,in_port=386,dl_src=fa:16:3e:34:aa:b7 actions=dr. }8 I) g! P* q: R
op6 Y4 W% _" q1 J: D+ |
cookie=0x1, duration=1185.017s, table=7, n_packets=0, n_bytes=0, priority=32769,in_port=29117,dl_src=fa:16:3e:ec:aa:39 actions=drop
% K& G9 Y4 p' b/ Q% w$ t# ?* N0 O 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; k- {, _4 `- J' y8 h# D# r
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% G2 K* L( s4 L( A
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=
- q8 a1 a- F9 Z" Wdrop8 o. \) N4 G% i4 a' I/ S/ W4 i
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=drop9 z0 y5 ~  Y8 U* q
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, r1 {! k2 M' M4 r
s=drop
& q3 E/ a* E6 [) f( R9 q# m cookie=0x1, duration=1231.485s, table=7, n_packets=5, n_bytes=450, priority=32769,in_port=8163,dl_src=fa:16:3e:cd:48:42 actions=dro, [0 L4 Y3 ^! g
p. u( E* w5 z* I) G! u: i
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- [! ^" U* @# }: J) n/ I) t
2 X% S6 B2 X. k3 u
/ {: b3 U# Q* H/ W
如果设为fail-secure mode,则初始情况下flow table是空的,否则会有normal$ sudo ovs-vsctl add-br helloworld1
# k7 s( Q; @) c7 L$ sudo ovs-ofctl show helloworld1 * l& @" W9 L" ^" Y, \' Y* x
$ sudo ovs-ofctl dump-flows helloworld1
/ Z5 ^) i; w) l2 Q. L9 vNXST_FLOW reply (xid=0x4):
7 A5 X4 a3 F: _) y8 Bcookie=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
5 s, s* B$ _0 \/ vsudo ip link add second_br type veth peer name second_if   
/ f6 \  Q# R( f7 y6 _: f# m, E  Psudo ip link add third_br type veth peer name third_if       . S# w. s/ R' K5 I
sudo ip link add forth_br type veth peer name forth_ifxxx_br将是添加到bridge上的。我们添加四个端口portsudo ovs-vsctl add-port helloworld first_br -- set Interface first_br ofport_request=1
% U9 s+ `0 W$ _- u1 W% _sudo ovs-vsctl add-port helloworld second_br -- set Interface second_br ofport_request=2
+ y0 P: r. ~. K- U6 Dsudo ovs-vsctl add-port helloworld third_br -- set Interface third_br ofport_request=3
$ K- h! q* v1 |3 {sudo ovs-vsctl add-port helloworld forth_br -- set Interface forth_br ofport_request=4ofport_request是指定端口号新添加的port都是出于DOWN的状态+ V: C8 R* `# n

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2019-10-25 10:00:34 | 显示全部楼层
把它们设为UP
; l5 j" z: r$ N
" n* I( ]. q+ U& esudo ip link set first_if up
5 o4 Z# P! s/ [  O& _sudo ip link set first_br up - p/ T( i/ a' @; @3 c9 f
sudo ip link set second_br up     2 s* i% R% O: o4 e
sudo ip link set second_if up
8 R4 K' q( K) c6 F, q, g) p0 ysudo ip link set third_if up      
6 s, V; A/ O  L* gsudo ip link set third_br up     & |& l0 a% p5 A( c9 `' o$ M
sudo ip link set forth_br up         
) N6 r6 T0 v1 dsudo ip link set forth_if up
* N( y  n3 [6 K, K. A+ a
% r4 c9 ]! L$ v  l也可以用下面的命令9 n: L- Q7 A1 s$ V
7 {: p. }; L) S' N4 Q; {! \% Z
ovs-ofctl mod-port helloworld first_br up

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2019-10-25 10:00:35 | 显示全部楼层
实现第一个Table 0,Admission control& k0 u2 P: A$ W/ k

7 Z) A' m. ?  K2 }2 T4 T& a  p7 O包进入vswitch的时候首先进入Table 0,我们在这里可以设定规则,控制那些包可以进入,那些包不可以进入。
! q2 F; b& p, Q* L
! H' w3 ]2 A& o9 P3 O4 r比如,如果source address是multicast的就不允许进入。
* F! t( S" z  ^2 Z
/ i* b# K5 d) t' b2 F01:00:00:00:00:00/01:00:00:00:00:00是广播地址9 w- P0 i6 m" E9 D& d
00:00:00:00:00:00/01:00:00:00:00:00是单播地址. p  f- T& H/ C( n3 f
这种表示形式类似CIDR; H9 O: F9 A; F7 r& y5 {
于是我们添加下面的规则:2 w4 v7 s% Z) B! m- ~
sudo ovs-ofctl add-flow helloworld "table=0, dl_src=01:00:00:00:00:00/01:00:00:00:00:00, actions=drop"
, A% n# X+ Y5 @4 ]5 @: |7 A# Y  KSTP的也不接受
, |6 j& e7 Q1 A. m1 g, [' wsudo ovs-ofctl add-flow helloworld "table=0, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0, actions=drop"+ _+ b' p: `" \2 {6 `/ b
我们在添加最后一个flow,这个flow的priority低于default,如果上面两个不匹配,则我们进入table 17 |5 Q: J6 ^. F  f
sudo ovs-ofctl add-flow helloworld "table=0, priority=0, actions=resubmit(,1)"
5 @! E9 d$ a1 R3 p3 R我们查看一下所有的flow4 X& D+ v0 W- |. k
$ sudo ovs-ofctl dump-flows helloworld        
* V. w* {: Q& g- \* u, J$ X5 m: uNXST_FLOW reply (xid=0x4):
* M! a  `1 ]8 a9 acookie=0x0, duration=42.162s, table=0, n_packets=0, n_bytes=0, idle_age=42, priority=0 actions=resubmit(,1) 1 e1 N$ X* e# K, A
cookie=0x0, duration=232.121s, table=0, n_packets=0, n_bytes=0, idle_age=232, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop # @, C( W8 l. K% u: [: S0 m8 ^1 O
cookie=0x0, duration=167.636s, table=0, n_packets=0, n_bytes=0, idle_age=167, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop. D( Q. L% s% Z: [( H
5 a) I3 p- @0 p. [* P* Q
测试Table 0
; F3 q/ J( H3 H8 p: v
. k9 P9 c6 Q  m- Y8 t有个很好的工具ovs-appctl ofproto/trace
2 j) ~3 u7 Q. Y3 U6 c- @
* P  `' U0 c9 v7 H: b* W. P不满足条件DROP
; D/ x- S; S) ^, w
% z: O6 \5 d- q$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:05
: L& T% f+ p  dFlow: 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
( s& N" {" c* }* |! w. CRule: table=0 cookie=0 dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 ! T  D% I) l4 x, w. z- W) f
OpenFlow actions=drop
: h. |% N5 V$ P3 {% x: @/ ?' H" W
& z) r/ D0 z0 k2 u' {) J: T7 p/ |Final flow: unchanged
' o4 ?. ]1 w' wRelevant fields: skb_priority=0,in_port=1,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
$ }& `7 q5 ^/ O2 O6 SDatapath actions: drop
  x: L' Z5 G  |  F( m  ~* T9 l4 i1 n0 o+ |) o3 d
满足条件RESUBMIT
" s/ j8 u  P8 F8 L, b2 Z
, M9 x1 y2 S) {& V$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:10 ) s4 v$ W6 o; w
Flow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=01:80:c2:00:00:10,dl_type=0x0000 $ x9 g+ J2 K5 @. V
Rule: table=0 cookie=0 priority=0 - T3 {. N& G- ~5 \1 M
OpenFlow actions=resubmit(,1)
: v/ _3 V; E2 F2 s# z$ K5 u
, Z  x2 j# D* [0 Q; F% _/ S        Resubmitted flow: unchanged
% o( Q& ^; c6 z! q        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
0 @. q5 p' u+ Z4 Q) y        Resubmitted  odp: drop ! c& R8 I5 [5 M% c
        No match
) E9 p* n; G1 @3 O1 @$ N0 F& N9 X1 }6 Q$ x% X, o6 d
Final flow: unchanged ) U! y- P: S' [5 s
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
1 _3 m+ R- c# D4 w, SDatapath actions: drop" k1 ?: l8 _4 Q8 [, R! s6 s
7 ]5 P) _2 ]0 w3 b5 P2 z
实现第二个Table 1:VLAN Input Processing
2 Z! a) k2 F% P% U
( b: s0 }7 V+ A' C首先添加一个最低优先级的DROP的规则2 g! W1 L5 W% p$ T4 U4 K
, D8 e% ~3 a1 X2 B2 {
sudo ovs-ofctl add-flow helloworld "table=1, priority=0, actions=drop"4 @# @8 g! E! r- s) }/ e- p
" ~. z) ~9 z# R7 `
对于port 1,是trunk口,无论有没有VLAN Header都接受。
2 ^. E# o' f* d. N+ j1 x1 O- j+ ^. X( w/ G; Q% S9 `9 F; i
sudo ovs-ofctl add-flow helloworld "table=1, priority=99, in_port=1, actions=resubmit(,2)"
4 Z* \. P  Y3 \% x! c6 \
9 E( Z1 [2 C2 U对于port 2, 3, 4, 我们希望没有VLAN Tag,然后我们给打上VLAN Tag
3 Q7 |/ U3 P# q
9 k( S) P( _$ ]' Y- m$ sudo ovs-ofctl add-flows helloworld - <<'EOF' 2 H! W6 ~9 i& R$ }
table=1, priority=99, in_port=2, vlan_tci=0, actions=mod_vlan_vid:20, resubmit(,2)
& l. [, J& R3 r3 T% M5 Ktable=1, priority=99, in_port=3, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2)
8 H6 L3 o% P; ptable=1, priority=99, in_port=4, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2)
* ]' j7 O3 G( t( ^4 y2 @EOF
. S. i: [: k; o# K0 t4 z/ `1 [( g# E$ R% i
$ sudo ovs-ofctl dump-flows helloworld - I5 V+ l, a  R: G' D4 V- |
NXST_FLOW reply (xid=0x4): 3 }; z4 @1 x& P+ t9 _
cookie=0x0, duration=4478.582s, table=0, n_packets=0, n_bytes=0, idle_age=4478, priority=0 actions=resubmit(,1) + m4 z% `8 V7 Z3 A$ e3 {3 t
cookie=0x0, duration=4668.541s, table=0, n_packets=0, n_bytes=0, idle_age=4668, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop
: K% {0 d& f; P2 ?: T1 Y" Bcookie=0x0, duration=4604.056s, table=0, n_packets=0, n_bytes=0, idle_age=4604, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop 0 }) p: @, t6 I1 q/ Y0 p
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)
2 ^1 q  K$ t* B; w( R$ \5 qcookie=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) 3 k, J+ p% \' c& u6 \- @7 v# D
cookie=0x0, duration=89.273s, table=1, n_packets=0, n_bytes=0, idle_age=89, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
+ z+ g! w+ F! D$ x2 ncookie=0x0, duration=220.318s, table=1, n_packets=0, n_bytes=0, idle_age=220, priority=99,in_port=1 actions=resubmit(,2) # f; ]- `+ L. o, m
cookie=0x0, duration=298.739s, table=1, n_packets=0, n_bytes=0, idle_age=298, priority=0 actions=drop8 a4 X( `! O  E7 R$ y
- y. B' b3 ^1 O
测试一个从port 1进入,tag为5的
( M6 x, z, H; x' s- k# w5 v1 m4 s' ]# P& ^: {
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=5
) ~3 X  {3 J  Q4 ]# C$ _4 ]; OFlow: 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 & s; I# P( d+ h$ o" O
Rule: table=0 cookie=0 priority=0
9 @( t5 Y0 o9 j6 NOpenFlow actions=resubmit(,1)
7 `; Z8 v1 U( U- J4 y# v7 `: ~" W7 w7 R5 ~) @) y) B9 J2 q
        Resubmitted flow: unchanged
9 N) V8 j9 I! h! v7 b) X! ^/ D& r        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
" x( V8 ?' ^0 V; _* k        Resubmitted  odp: drop ! `1 m2 S9 [6 U* ?8 C7 C6 b3 U: L
        Rule: table=1 cookie=0 priority=99,in_port=1
2 _, V. K+ K0 Z, l        OpenFlow actions=resubmit(,2)
) w8 q+ z+ {4 D( \+ A- p' h1 |8 l. E0 f
                Resubmitted flow: unchanged
1 O0 s( j" e) W$ r* X                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0   t; j/ E9 g  B# W4 m0 k; D0 D+ W
                Resubmitted  odp: drop / K& e' W) X5 F5 _" _3 m
                No match
. Y0 q1 o5 {; h  `% a7 \! `4 S1 e- K$ f- O+ s4 g( r( z
Final flow: unchanged
9 D. {! z0 q7 h. b* FRelevant fields: skb_priority=0,in_port=1,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
0 {1 c  _9 l) H6 ~Datapath actions: drop
2 h- H( \+ _. M1 j1 w
! w0 @4 t) M- _* W+ t. L. q测试二,从port 2进入,没有打Tag的( Q3 m3 }1 O% L
* Y0 h; X) M; q' e3 i
$ sudo ovs-appctl ofproto/trace helloworld in_port=2 - Z, U# Z, j9 w7 m0 L) Q
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 , I: ^$ K. n7 [$ M
Rule: table=0 cookie=0 priority=0 * s  A% K; ?1 Z' A/ F
OpenFlow actions=resubmit(,1)
9 g; H: R/ h; `1 V! z1 _
( w! N4 H! {3 D! w+ S  C' O        Resubmitted flow: unchanged + K- }6 p# h  D: e5 L
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 0 c2 c; F: M! U
        Resubmitted  odp: drop
2 K( b0 i7 U# L' |( U# F# s3 L        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 ! \0 f% I- s% S( |5 k# y' N
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)4 O3 s+ \9 H: r
; o% T: m2 x. X! E: G
                Resubmitted flow: metadata=0,in_port=2,dl_vlan=20这里被打上了Tag,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000
" t- O/ [: N( E4 t                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ' \7 S- P) _3 q9 d: P4 I) ]8 f
                Resubmitted  odp: drop 3 f9 |4 o8 M% w' w
                No match. v& f; d1 e7 I8 i% j$ V

0 j1 i$ F4 `) |1 G% xFinal flow: unchanged
) ?" ~% e, h4 z/ M9 J) _# F& D8 hRelevant fields: skb_priority=0,in_port=2,vlan_tci=0x0000,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
3 h$ v- }* |! |: kDatapath actions: drop3 f- ^5 y2 m# q

+ J/ Q% G& \6 c7 ^' g测试三:从port进入,带Tag 5的7 ~7 y$ n4 B+ `; q

# U$ y/ ^- Z  V6 j$ sudo ovs-appctl ofproto/trace helloworld in_port=2,vlan_tci=5
* _  c# b% u2 TFlow: metadata=0,in_port=2,vlan_tci=0x0005,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000 3 @1 v( Z, L7 v& ?1 X, s+ h. Y# \: Z
Rule: table=0 cookie=0 priority=0 ( N1 i; }4 r) T7 ]# C" V
OpenFlow actions=resubmit(,1)% J8 |5 R9 N- X0 S

/ \/ I0 A% ^, W        Resubmitted flow: unchanged 2 X$ u! A2 s$ r5 P' {* Z
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
  x. @! P4 I4 i        Resubmitted  odp: drop . T' z+ E2 R3 a: z0 {+ Y( u
        Rule: table=1 cookie=0 priority=0
& ~; u$ m& l% n        OpenFlow actions=drop
# v+ v( U( `! x$ j# d
# y: r# e3 r1 \Final flow: unchanged $ C) A, Z" ~7 B3 ~0 N  ?0 W1 V8 m
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
: V4 ~$ i# y) y* S- _Datapath actions: drop5 @6 Z/ O9 ~. w8 F! [
8 f" K8 e& `3 Q+ U# n8 x
实现第三个Table 2: MAC, VLAN learning for ingress port
: _0 e/ @7 F) C; L' {: Q: \0 z0 U5 _
对于普通的switch,都会有这个学习的过程,当一个包到来的时候,由于包里面有MAC,VLAN Tag,以及从哪个口进来的这个信息。于是switch学习后,维护了一个表格port –> MAC –> VLAN Tag。
6 ]( M7 D1 q" x. @6 G" N. u0 O
0 ?9 s1 _! C1 `/ z0 p这样以后如果有需要发给这个MAC的包,不用ARP,switch自然之道应该发给哪个port,应该打什么VLAN Tag。2 q3 Z% m8 o9 w7 c  {  Y
+ n' e0 @4 M# [0 i. U4 u* J- Y, f
OVS也要学习这个,并维护三个之间的mapping关系。
1 ^6 ^$ n1 y# ^9 U- q2 Q1 X2 ?4 r
在我们的例子中,无论是从port进来的本身就带Tag的,还是从port 2, 3, 4进来的后来被打上Tag的,都需要学习。
# w6 |/ ?2 M& y5 y. d8 Q: d
8 N# E  \0 K1 b% e* Rsudo 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)": y' G! j# x4 E" c

' M/ _- s' ^* K8 d  c这一句比较难理解。
: M$ C  c8 @4 w5 Q3 H
& X' z3 u+ B) A7 nlearn表示这是一个学习的action
6 }( q0 H8 y% N$ j: w. ~# F7 |5 M
table 10,这是一个MAC learning table,学习的结果会放在这个table中。
+ ]+ o  q$ H( j8 t3 L: _$ z! k
; u" _( P9 S3 O, HNXM_OF_VLAN_TCI这个是VLAN Tag,在MAC Learning table中,每一个entry都是仅仅对某一个VLAN来说的,不同VLAN的learning table是分开的。在学习的结果的entry中,会标出这个entry是对于哪个VLAN的。; O! N5 L4 a9 x! S. A3 j9 j! I, t

* `# M( e$ ?" H; ^0 a( MNXM_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里面,因为这是为发送用的。8 ?+ T/ |. @' [' n9 C6 g0 K$ _
2 Z9 }) g! F# S3 W2 q4 r
NXM_OF_IN_PORT[]->NXM_NX_REG0将portf放入register.
' W2 v5 X1 A; \8 n
; b2 O8 q1 i# t3 d; h% r一般对于学习的entry还需要有hard_timeout,这是的每个学习结果都会expire,需要重新学习。
; N6 p0 U- I" _/ z# _* ?# V& \2 q; v
( D5 c5 f! b9 I8 E- Q4 i( ], h我们再来分析一个实践中,openstack中使用openvswitch的情况,这是br-tun上的规则。
( ?2 a8 Y! \( x5 I  V' }2 s( v, @% x0 t  J" y$ z
cookie=0x0, duration=802188.071s, table=10, n_packets=4885, n_bytes=347789, idle_age=730, hard_age=65534, priority=1 actions=learn(table=20,hard_timeout=300,priority=1,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:0->NXM_OF_VLAN_TCI[],load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[],output:NXM_OF_IN_PORT[]),output:1 - s6 V( ?! w( b0 @- H" T. r/ y
cookie=0x0, duration=802187.786s, table=20, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,21)
& h5 s* U5 O/ E. ?" @9 L& h cookie=0x0, duration=802038.514s, table=20, n_packets=1239, n_bytes=83620, idle_age=735, hard_age=65534, priority=2,dl_vlan=1,dl_dst=fa:16:3e:7e:ab:cc actions=strip_vlan,set_tunnel:0x3e9,output:2 - x9 H; L2 r  s7 S
cookie=0x0, duration=802187.653s, table=21, n_packets=17, n_bytes=1426, idle_age=65534, hard_age=65534, priority=0 actions=drop , i4 F! o: N1 v' m: |6 @1 Y0 B
cookie=0x0, duration=802055.878s, table=21, n_packets=40, n_bytes=1736, idle_age=65534, hard_age=65534, dl_vlan=1 actions=strip_vlan,set_tunnel:0x3e9,output:23 b8 W: M/ ]. E4 H% _' K

. S7 V& Z- [3 s1 N1 O这里table 10是用来学习的。table 20是learning table。如果table 20是空的,也即还没有学到什么,则会通过priority=0的规则resubmit到table 21.
, Y8 b, |) Z/ d3 ~- y% Y& Z# U0 p9 a2 ~
table 21是发送规则,将br-int上的vlan tag消除,然后打上gre tunnel的id。. o8 L- k; l# z

! e% p* v& S) t1 c( ?上面的情况中,table 20不是空的,也即发送给dl_dst=fa:16:3e:7e:ab:cc的包不用走默认规则,直接通过table 20就发送出去了。
2 r; c0 F6 K; ^/ E/ G& y
0 _4 c) q$ k' I8 l: E4 Gtable 20的规则是通过table 10学习得到的,table 10是一个接受规则。最终output 1,发送给了br-int
$ M+ B' X, I& i2 S1 K
! O6 k; M, d6 HNXM_OF_VLAN_TCI[0..11]是记录vlan tag,所以学习结果中有dl_vlan=1
! v! o9 |. A0 o8 \$ f3 e! R
; P2 g" |/ l; ?/ u1 |  JNXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]是将mac source address记录,所以结果中有dl_dst=fa:16:3e:7e:ab:cc
. l5 Y' w5 I, ?) O5 J. k, v' G+ s& o+ d! V
load:0->NXM_OF_VLAN_TCI[]意思是发送出去的时候,vlan tag设为0,所以结果中有actions=strip_vlan. P% U+ Z9 U, e: o, [0 w

4 \: C) l7 I  X# @load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[]意思是发出去的时候,设置tunnul id,所以结果中有set_tunnel:0x3e9' Y, t7 f4 ~+ X* z* q$ m

, ~0 c: t4 R' O; C: A5 D8 ^output:NXM_OF_IN_PORT[]意思是发送给哪个port,由于是从port2进来的,因而结果中有output:27 ^! L% f! Y# O" Y2 T

; Y  Q1 t' h% v' l- R. V& j测试一:从port 1来一个vlan为20的mac为50:00:00:00:00:01的包9 G. f) ^, k* R, i* r$ U( C" H8 B/ x
/ K) h% L: C; P9 W, K
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=20,dl_src=50:00:00:00:00:01 -generate   
/ ?: i' K, {0 ~* e  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 4 S4 P  {4 |, }9 w) v* e. q0 E" P
Rule: table=0 cookie=0 priority=0
4 Y0 N# T4 Y1 m0 zOpenFlow actions=resubmit(,1)
: e+ p5 E% Y; J& U  Q; T. B5 C/ T3 q. e% {6 c1 U. |9 W9 z/ d
        Resubmitted flow: unchanged
. I) D' S2 k; L+ R! o. U        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
; E* C, g4 B) `; e6 a; ]" e        Resubmitted  odp: drop # f, g1 O7 H+ b- N+ n3 C' ]
        Rule: table=1 cookie=0 priority=99,in_port=1
" T9 F1 p* A) P        OpenFlow actions=resubmit(,2)
5 g# C6 D+ D  V# ~% f! i0 X3 U: E8 i' `. b0 p2 G/ J- L- A
                Resubmitted flow: unchanged 0 O9 C1 W: |/ @/ p* ?# V. t
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
: g- ]8 U; v7 V! V                Resubmitted  odp: drop . S/ y" G% g7 K) F0 y$ P
                Rule: table=2 cookie=0
4 q" N4 H  B% C/ c3 k& Z                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
7 v, W3 N; z: y1 _# d
/ L  d9 P7 S! U# \                        Resubmitted flow: unchanged 7 G3 O8 O* S6 `
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
2 k4 Q4 @1 @3 Y: X5 _                        Resubmitted  odp: drop 4 V9 f: K& A- n4 f* V' I0 ?0 k* V
                        No match. m* k* M5 E" X) |
# ^( b$ r- d! H6 }. ?
Final flow: unchanged * @8 g( f' \- t; F, k
Relevant fields: skb_priority=0,in_port=1,vlan_tci=0x0014/0x0fff,dl_src=50:00:00:00:00:01,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no ' v: X. c0 x6 i: e! u+ c* x
Datapath actions: drop
" f, Q& K" Z9 d" m
4 X! j- L. k$ w( P$ sudo ovs-ofctl dump-flows helloworld
4 e3 s6 C+ U' }8 ZNXST_FLOW reply (xid=0x4):
& m2 t1 a: l" f! ?' N' ^% x9 Mcookie=0x0, duration=90537.25s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
! q  I6 r; L" e8 Hcookie=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 & F9 b8 B3 n6 N& X% V
cookie=0x0, duration=90662.724s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
# _! k) |+ |. c, |; D3 J" M4 |. Acookie=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)
: q% _2 b9 {7 D+ B% Ncookie=0x0, duration=86147.941s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=4,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) 5 d3 v- I/ A' N% _8 p( k
cookie=0x0, duration=86147.941s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
1 D* |& d& e/ F( i& M* v0 ucookie=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)
3 R$ ^' J2 Q' |6 A8 z& ^. L6 i, ?; F% Rcookie=0x0, duration=86357.407s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop 0 C' Z8 m: c0 u% `: }
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)
* v% n9 A$ ?) f2 O% m, N& d 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]9 `$ {: Y1 I1 l' w$ n

9 _$ N- S. q7 v! |0 Jtable 10多了一条,vlan为20,dl_dst为50:00:00:00:00:01,发送的时候从port 1出去。1 t$ P- T  b8 q8 I  R& v1 r$ W. A
5 u# c# U5 a2 T/ N; P! S' i0 y, Q* J
测试二:从port 2进来,被打上了vlan 20,mac为50:00:00:00:00:02- _- i- S, A8 Q. b3 ?2 e
! t1 p9 c- t: ]& B+ T& g7 L
$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=50:00:00:00:00:02 -generate   + E! `  I! }* \
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
3 ^# B5 k, r6 {6 X$ f, a5 [Rule: table=0 cookie=0 priority=0
# v9 c4 w! W$ V) D# V8 U1 POpenFlow actions=resubmit(,1)# l7 N) @. a. a; B( ]8 C" s

! l2 e4 K0 }: g$ s/ v- e7 g# H        Resubmitted flow: unchanged + Q0 J* s. t8 _; R, T
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 6 o* b1 j4 Y6 \2 j- |5 k
        Resubmitted  odp: drop
9 k3 T* o5 q. W& O9 y# u5 K5 H" `        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 - q& l& v" w* @7 o+ T
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
1 i; U9 ~) g/ [2 Y4 I6 `. `: v& G9 m3 @* ]2 l! f4 O% s8 x/ H
                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 . V. @/ Q' p/ I% ~3 u6 B! [
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 % E! ^* S8 J$ s. @
                Resubmitted  odp: drop 1 m. \' ^( n4 a( f* I) y$ F9 u$ E/ O
                Rule: table=2 cookie=0
# c2 b9 k$ b( W. E8 K9 j                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
! g. p" ?; ]4 J3 f# Q9 ~% I5 y; g# }) \5 P, }- X/ j. |/ k
                        Resubmitted flow: unchanged
' u) p% A# E) V7 u) F2 w" m6 Z                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 4 b5 i. M4 V" Y$ i& l# w# o- U8 G
                        Resubmitted  odp: drop 4 i6 O* }# y' f  a
                        No match
( a) b; P7 ?  U* e7 S$ ~9 |. J; z
Final flow: unchanged   @0 I) ~' L4 N, ~; R8 H1 w- T
Relevant fields: skb_priority=0,in_port=2,vlan_tci=0x0000,dl_src=50:00:00:00:00:02,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no % }/ l7 p3 [$ p# v7 `& @" R
Datapath actions: drop1 {! U* l/ c3 H* E4 ]

0 d/ o- k  o( {$ ~6 Q$ sudo ovs-ofctl dump-flows helloworld                                                
2 J. @. [7 C" x% R( }3 G; C- aNXST_FLOW reply (xid=0x4):
8 K: g/ I9 O, D- h, z8 \+ pcookie=0x0, duration=90823.14s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) 1 k' d7 c6 f1 [6 i
cookie=0x0, duration=91013.099s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop ( U) X& r- C2 X6 ?- n2 H/ j
cookie=0x0, duration=90948.614s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
( Z& ?9 a2 ^1 K! n% d2 w  S( hcookie=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) 3 H$ W. t; X4 N! n) _3 A8 a
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) , M8 m5 J& |, a( [5 B/ f3 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)
4 X( x$ F* A, u6 L5 S1 Xcookie=0x0, duration=86564.876s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2)
- d5 D1 B9 {+ d% E0 [. c6 ?; bcookie=0x0, duration=86643.297s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
# T2 @, g8 p7 B3 Ncookie=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)
, ?0 k% W3 N% @1 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]
& k7 C( C# T, O$ Acookie=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]& z9 }7 M2 e2 F# V4 q
1 n: }/ b0 s% g0 t# R( }# d
实现第四个table 3: Look Up Destination Port
$ R( X! `5 f# Y! a3 N# O5 Y
: u- d3 ^$ O$ `3 }9 l在table 2中,vswtich通过进入的包,学习了vlanid –> mac –> port的映射后,对于要发送的包,可以根据学习到的table 10里面的内容,根据destination mac和vlan,来找到相应的port发送出去,而不用每次都flood0 V! Y1 J* g( S' f( S* n# R6 U
& D& J: L) J  l8 ]
sudo ovs-ofctl add-flow helloworld "table=3 priority=50 actions=resubmit(,10), resubmit(,4)"7 k( u7 X) i' o
9 |7 i$ _! b$ G1 A3 g5 [
添加这条规则,首先到table 10中查找learn table entry,如果找不到则到table 4
6 ^$ S% t* p- n: m5 c1 s6 J0 y9 r0 ^0 V2 `
如果包本身就是multicast的或者broadcast的,则不用去table 10里面取查找。6 v4 d. P6 Z7 J; g; h" n  `% T
& N% D/ V* T, j  T: I1 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)"; d; d* `* F  L2 k& M1 K

" C  ]' F+ N- {/ G  E5 Z我们进行一项测试
) |' j) A7 {- U7 i- z. s3 Z$ x4 y
4 d1 i4 P8 a8 {7 i1 O$ 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   " y2 S- W, l5 b, D: t, [9 h: L+ o
Flow: metadata=0,in_port=1,dl_vlan=20,dl_vlan_pcp=0,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000 1 r) h, I, r5 f7 T2 h! F+ E
Rule: table=0 cookie=0 priority=0 + a- Y" ^; _7 c( @3 C0 q
OpenFlow actions=resubmit(,1)# L: H- y5 v5 I) G: ?; V  d$ ~: G
& |/ R- K4 B/ m! A# W1 ^; b) P" f6 E0 {
        Resubmitted flow: unchanged
% F# m0 [5 F) L' f5 k6 J        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 # x' ]) Z8 P: G
        Resubmitted  odp: drop
' d2 B8 P7 P( _1 }        Rule: table=1 cookie=0 priority=99,in_port=1 : \& @$ y3 ?! k4 D
        OpenFlow actions=resubmit(,2)
4 ^4 n" l% \1 F4 O7 x  V
! a: S6 T, i5 h6 u  z                Resubmitted flow: unchanged
4 T7 ?. R+ T% x# v" y& a6 b                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
* M$ T- Q$ c' ?- p6 M# |3 Z                Resubmitted  odp: drop ! g* m; c: K4 c' u7 {; k
                Rule: table=2 cookie=0 " }5 g* X+ _# S, Y- ^8 U
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
% X4 W) F4 v9 I" n  K. G, s; W% Z9 M5 K; }
                        Resubmitted flow: unchanged
  p2 w6 U! h) F) k, g                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
4 C) \& f) q# A! Z                        Resubmitted  odp: drop
. k1 B% T( p% z0 u, M; q                        Rule: table=3 cookie=0 priority=50
3 [) m, g0 D4 @, M/ ?                        OpenFlow actions=resubmit(,10),resubmit(,4)
# j2 X4 l  X7 g! P5 J9 e
+ T# i6 T2 \$ X7 h                                Resubmitted flow: unchanged 8 R' j/ _  S. b% H% a
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 6 H0 |# B& }0 l" l9 m6 V5 m
                                Resubmitted  odp: drop
# ~- h- ?  K, t/ w                                No match+ m$ J  T% Y* Z/ N3 K

+ U) e2 b1 E) V                                Resubmitted flow: unchanged ) |1 ]$ J0 Y  b7 r+ |7 F, f
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 - @4 `$ U7 c* @
                                Resubmitted  odp: drop
! [; d  f( d, \/ w, H                                No match
1 R7 l8 r6 d& H- B+ w1 h6 p0 S" J# u, t9 n; w& x
Final flow: unchanged
6 F: z, g$ D5 a4 @2 n3 {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
8 w$ }8 U3 Z8 D# @! X7 tDatapath actions: drop
5 E* P' n5 a. N8 {% }( F
* X; N: K$ o. c$ u; R4 Q' M% C由于目标地址f0:00:00:00:00:01没有在table 10中找到,因而到达table 4.
' Z. l& J; T4 p7 j0 J# |& D% ?' ]
# _9 p, W9 D6 A& s但是这次测试使得table 10中学习到了mac地址90:00:00:00:00:01
- S: d# n# i5 E, `7 q* U3 z- Y! l2 s2 f& E, q* ], u
$ sudo ovs-ofctl dump-flows helloworld
7 S5 y4 w  K6 ?0 B1 k$ pNXST_FLOW reply (xid=0x4):   i6 m$ c$ m* W3 b
cookie=0x0, duration=91588.452s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) # _$ Z3 w/ p6 F: R  B4 A
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 & e* b2 ]! q5 }# h* Y6 Q0 a$ q! o) N
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
; x/ ^8 K' w/ V) _! N6 J6 @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) ; G6 M8 B- V' H, S: s/ b+ z' N/ M9 ]
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)
9 u% R  I9 H3 X( _3 _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) 1 ^% L1 M9 j/ Q5 r/ [
cookie=0x0, duration=87330.188s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=1 actions=resubmit(,2) : O* b) j9 u# t8 k
cookie=0x0, duration=87408.609s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
0 h! k; ?3 k3 Bcookie=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)
; P6 [3 G6 U' Y& Ncookie=0x0, duration=352.841s, table=3, n_packets=0, n_bytes=0, idle_age=352, priority=50 actions=resubmit(,10),resubmit(,4) / X1 p+ r  F. f: Q, w$ g0 ^5 x
cookie=0x0, duration=212.704s, table=3, n_packets=0, n_bytes=0, idle_age=212, priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,4) . i9 r# x3 Y. r: c" ~" r
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] & e# C6 L1 n- M& b0 Y# O  n
cookie=0x0, duration=769.784s, table=10, n_packets=0, n_bytes=0, idle_age=769, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:02 actions=load:0x2->NXM_NX_REG0[0..15] * h0 h8 s% V8 F' E; t6 e" {
cookie=0x0, duration=1082.46s, table=10, n_packets=0, n_bytes=0, idle_age=1082, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]
8 \/ o9 S4 N1 ]1 T8 n4 u* b
( o3 _6 b; H5 w. @下面我们进行另一个测试/ O; L6 D/ d: {$ Q/ W$ }& a& L4 J
7 F* m2 Z6 p) p
$ 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   
. V. z, ?# k/ w( f  CFlow: metadata=0,in_port=2,vlan_tci=0x0000,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01,dl_type=0x0000 1 I% q  r$ ?1 `7 _- m( z
Rule: table=0 cookie=0 priority=0
* @- K5 M3 c/ \$ S9 F. o* d+ }# KOpenFlow actions=resubmit(,1)  V$ a4 `0 o0 r  S

0 o$ A" a- h! Q6 ^$ a( p- z' |0 t        Resubmitted flow: unchanged
% k; \( v$ _$ T; {        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
' J5 V- ]9 G& j$ a* a  }6 o/ B        Resubmitted  odp: drop
9 b0 d# Z2 B3 h% }9 B1 i4 t& r        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
8 V4 u3 G. T  T: T        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)$ k, z6 k* X3 H
- }; t6 c6 T3 I' ]
                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 ; z. f( t- m9 ]  U
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 0 g/ ^2 X% [7 c% n: h; i' y
                Resubmitted  odp: drop + W- O) r& t9 V! E2 [- Z
                Rule: table=2 cookie=0 : Z: L* \6 [& Q; g1 p# P# 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)  y: K# n" ~& j  _
( R2 i6 i0 F' V4 ]8 }
                        Resubmitted flow: unchanged
2 a4 \( C0 H2 j# l                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
; V6 U+ C8 E9 Q                        Resubmitted  odp: drop
# R- A  C3 ^5 o                        Rule: table=3 cookie=0 priority=50
7 h5 u9 O! s8 ?0 Q7 M( W9 X9 j                        OpenFlow actions=resubmit(,10),resubmit(,4)- y, K9 O9 L0 l/ A1 r! K  F+ }
& v/ _; \% ~) k5 O
                                Resubmitted flow: unchanged
- Y6 [) p' k8 @: M* a0 i                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ; r* [% n& l5 O$ e
                                Resubmitted  odp: drop / v; q8 F& g* Q5 Y" _5 N
                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01
; ]) y, t& F9 B/ r0 [                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]2 g" P* V" w$ \4 q) X

4 p7 U% R* h8 D& C5 }                                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 C: @3 P  t) E" t) d  C$ E/ J
                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 z1 A. e# D4 [0 F( y
                                Resubmitted  odp: drop
$ F* ]2 @; Q, d% v7 d' A                                No match% X# Z" G4 E! t5 H% ]

, q6 N: N0 G" i7 pFinal flow: unchanged " t" I3 a$ O5 `% ?5 t  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 1 r3 x. I  J9 S  u5 p. I
Datapath actions: drop
0 ^4 f: x, A% c# `6 }" E
) O- E# ^& w, {0 e3 h因为刚才学习到了mac地址f0:00:00:00:00:01,所以这次在table 10中找到了这条记录,这次同时也学习到了mac地址90:00:00:00:00:01, b6 G& H7 E5 O7 F0 _; u
7 y$ s" \# a' J% a2 R
下面我们再发送第一次的包: Y. Q$ u) h3 _/ T$ e4 T, M
9 u% B# v8 L; F/ {- p, j
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=20,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01 -generate
0 k( z" V/ m$ C8 S) P2 |9 h+ BFlow: 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' \8 K% p6 o; g8 r- ]Rule: table=0 cookie=0 priority=0
" ^  D5 c! d/ s* _. {& C/ U, VOpenFlow actions=resubmit(,1)( S- X( q/ I- ]0 j( F5 g
, S& v) ?5 e& P) h1 X: ]
        Resubmitted flow: unchanged & ?# h/ X: Y1 i1 m! f2 q  `; d
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0   V. z3 F2 Q" }' H& N) S- i2 ?  a5 s
        Resubmitted  odp: drop
4 {2 |* I' _  Y4 s+ M# `        Rule: table=1 cookie=0 priority=99,in_port=1 9 [8 o, b9 y0 ?! Y$ b% r
        OpenFlow actions=resubmit(,2)8 v3 [4 B" N' H  H" t
& K% m. p0 \  R( s! H  [$ h
                Resubmitted flow: unchanged
( D8 p1 `7 k! W/ [8 D7 }                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ) p; N/ V2 i" b! m6 N! x% T; t" Q
                Resubmitted  odp: drop
, ~% Q& q9 k8 X6 ], o4 q% Z                Rule: table=2 cookie=0 0 P2 V5 u! |1 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 o$ s/ p8 ^& m6 T( W3 n9 _0 s  v: h6 y
                        Resubmitted flow: unchanged 3 r. M8 ^# A, j/ E
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 2 l$ L4 x0 r/ ?0 H  Y3 i
                        Resubmitted  odp: drop
9 d  T/ z: R, X( b+ G1 s/ |+ {( q9 F                        Rule: table=3 cookie=0 priority=50 ' l0 z: L) m) ]; N" L5 J+ i! C
                        OpenFlow actions=resubmit(,10),resubmit(,4)
' |6 F. R8 {& Q2 }1 N% y* w) `* U6 S8 o8 p" d
                                Resubmitted flow: unchanged
0 P0 m& m0 w, U. }: {( ~                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ) z7 d8 o6 l% i( f' H- l4 G
                                Resubmitted  odp: drop # f7 C; w$ B9 l+ X( x1 [
                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01   B/ Z9 `* p* Q/ k! d( W$ u( {5 r
                                OpenFlow actions=load:0x2->NXM_NX_REG0[0..15]  A4 m2 }/ y9 R1 Z
: m& y6 G- {( a2 H2 t
                                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 - k* [: [" E. k" c+ n, ?4 h8 n. v0 E
                                Resubmitted regs: reg0=0x2 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
+ Z$ ^9 `, o6 q7 B! |                                Resubmitted  odp: drop . l$ s% I, {0 z
                                No match
4 v+ Z, ]/ ]8 F0 I
( c( S* u2 _& f" v& F) FFinal flow: unchanged
# f4 B( j& u% T/ ZRelevant 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
+ T2 H1 S' S0 b. v$ \Datapath actions: drop
4 F& O$ x0 Y$ d2 `9 L1 Q7 U  I
$ s  p# I, O4 w' O0 `3 M发现也在table 10中找到了记录
* P) R- i* k: V) Z: A7 O5 b* m2 ]3 X5 e$ G: T
实现第五个table 4: Output Processing; [7 R2 z/ V- T/ B) F. g
, V1 N1 [8 @/ ~. R/ q6 k8 S" t( Y1 t
这个时候,register 0中包含了output port,如果是0则说明是flood。4 O3 _) ^0 p$ S# F! N+ q4 }
, e& u  x, Z* l1 b
对于port 1来讲,是trunk port,所以携带的vlan tag就让他带着,从port 1出去。, d- U4 P6 M9 y, p

! c% r: ^  w4 P- Zsudo ovs-ofctl add-flow helloworld "table=4 reg0=1 actions=1", j; K* R7 X* @* r( \% b

4 C  U: D7 |- X0 B对于port 2来讲,是vlan 20的,然而出去的时候,vlan tag会被抹掉,从port 2发出去+ x2 [& y0 l" @; ?$ b' `
3 d4 H* e8 G0 L  L& L/ z
对于port 3, 4来讲,是vlan 30的,然而出去的时候,vlan tag会被抹掉,从port 3, 4出去
8 k- h8 k1 n9 y$ S% x- B* N% b9 U4 J! }/ J' ^2 f
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   
" E9 C) \9 y& Y) k# a$ D        table=4 reg0=2 actions=strip_vlan,2 ; J8 Q7 p* ?! \" e
        table=4 reg0=3 actions=strip_vlan,3
5 r/ {- b& ?) ~0 ?& `0 V        table=4 reg0=4 actions=strip_vlan,4
2 s7 G: q) e- ~0 n* Y3 Y# A3 MEOF
/ u. I8 s! |% B& _6 B6 {) K3 t
/ D& q) H' Y8 c3 a- k对于broadcast来讲,我们希望一个vlan的broadcast仅仅在这个vlan里面发送,不影响其他的vlan。
" R& x- |6 }! f' S! _/ i/ l; E; U# g5 M$ m8 @, H
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   
8 r6 k$ e' X3 F2 i( R2 t! R        table=4 reg0=0 priority=99 dl_vlan=20 actions=1,strip_vlan,2 5 E3 F+ x) Z/ D3 E7 d0 {
        table=4 reg0=0 priority=99 dl_vlan=30 actions=1,strip_vlan,3,4 1 x/ \) m& k' `6 r9 ~
        table=4 reg0=0 priority=50            actions=1
7 A3 h& O! f" D0 v& O9 Z* b2 YEOF
. I1 m4 G- x7 z, Y* p, C; @( J  r4 U/ j( f& P5 i  V9 j1 ]
所以对于register = 0的,也即是broadcast的,属于vlan 20的,则从port 1, 2出去,属于vlan 30的,则从port 1, 3, 4出去。
& r( [2 L( F. u+ N$ \" v, d; f' Z: Z/ v: D2 g
$ sudo ovs-ofctl dump-flows helloworld
. E" d& q% L% FNXST_FLOW reply (xid=0x4):
2 W$ a  X! U8 z9 ecookie=0x0, duration=92909.119s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
4 T5 b$ u0 n% G- j' ccookie=0x0, duration=93099.078s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop   z6 I0 a$ @3 R+ @  P
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 . c! I. d& q5 {8 i, V
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) 7 i6 H, R2 y! j' {
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) 3 T- s: U% n0 t- E
cookie=0x0, duration=88519.81s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)
! s1 M) e5 f6 U# k( _8 bcookie=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) - X( W# t4 M! f, f
cookie=0x0, duration=88729.276s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
+ i; O- p8 e1 W2 R# Scookie=0x0, duration=85959.15s, table=2, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
3 L1 `/ L0 Y1 u# Zcookie=0x0, duration=1673.508s, table=3, n_packets=0, n_bytes=0, idle_age=1673, priority=50 actions=resubmit(,10),resubmit(,4)
* g) g; m( L5 ~% J+ |- }5 ?cookie=0x0, duration=1533.371s, table=3, n_packets=0, n_bytes=0, idle_age=1533, priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,4)
6 d* v9 `) W% x: Zcookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x3 actions=strip_vlan,output:3 2 b9 [; \5 c! \
cookie=0x0, duration=228.839s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=50,reg0=0x0 actions=output:1 $ ?9 u$ E; a% h- g9 |, M8 Q; w6 \
cookie=0x0, duration=483.068s, table=4, n_packets=0, n_bytes=0, idle_age=483, reg0=0x1 actions=output:1 & [% \  @; d- \' i9 A% Q9 ^! b6 S
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x4 actions=strip_vlan,output:4
9 x+ O) m. ?1 V0 L+ B: x- V! ]9 i6 @cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x2 actions=strip_vlan,output:2 ( L& O0 h! r, g* y. n
cookie=0x0, duration=228.84s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=99,reg0=0x0,dl_vlan=30 actions=output:1,strip_vlan,output:3,output:4
; r# u6 y+ R1 `4 L! {3 ]/ n. Mcookie=0x0, duration=228.84s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=99,reg0=0x0,dl_vlan=20 actions=output:1,strip_vlan,output:2
/ R9 R* }2 p) y! _) h8 i" [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]
9 A6 X- I  X. V" A4 ?* ~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] ( h7 J2 h" i' V
cookie=0x0, duration=1258.881s, table=10, n_packets=0, n_bytes=0, idle_age=1258, vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01 actions=load:0x2->NXM_NX_REG0[0..15] ) U& a0 Z, e1 R- I
cookie=0x0, duration=2403.127s, table=10, n_packets=0, n_bytes=0, idle_age=2403, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]% X1 _: V& b+ n' |% X8 F- Q  {

& C2 i: ~6 T' d5 {$ U/ b首先来测试一个multicast和broadcast
" f: ?, c: s" V/ P
& d3 M7 t6 c/ Y2 h* Q% f3 S- |如果是一个port 1来的vlan 30的broadcast% ~% S. V: W4 W+ _, W2 y
( _2 g7 }: s* `' A; `
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=ff:ff:ff:ff:ff:ff,dl_vlan=30
9 f3 g- N7 t/ p8 bFlow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000
, \3 A8 Z/ c+ D- N" m& M6 hRule: table=0 cookie=0 priority=0 . C# U) _, E8 o
OpenFlow actions=resubmit(,1)- A; H* \2 u& {. ^& u( X
% U) O6 C0 I' W) s  n5 T4 M8 q
        Resubmitted flow: unchanged
& T% b1 D! \  _, x        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 7 [- ^" |  M& z$ S6 M+ K3 e/ I5 J
        Resubmitted  odp: drop + q, b( v. }0 A6 s5 @
        Rule: table=1 cookie=0 priority=99,in_port=1 ( U# `. {' S! [% a4 |! f7 ~
        OpenFlow actions=resubmit(,2)* t7 B, V- Q6 b; |( E4 w3 [. Q) k7 T5 M: l
8 v5 x, |0 \7 M7 x6 i
                Resubmitted flow: unchanged * j# }9 t0 W- F) {& U' C
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 ~8 d% I9 Z1 q3 f
                Resubmitted  odp: drop 1 {: o: P  S9 O, Q7 J$ ~) Y
                Rule: table=2 cookie=0
; q4 z' }, Z1 r& j                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
* l8 T3 M7 f" C0 G9 g0 b
" K- g, Y* Q. M( f' R; G: ~                        Resubmitted flow: unchanged - u2 @- g; E' N( E5 }
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
! C& _' ]$ Z0 ?$ j: l" r                        Resubmitted  odp: drop   f( {9 b* }1 ~0 p  q0 U" ]
                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 9 E1 w% [7 }1 n( x! x. _, Z) {9 R6 Y# C
                        OpenFlow actions=resubmit(,4)- n* V1 b: F$ C. I3 q

3 k9 T& `/ ~2 V4 m& \                                Resubmitted flow: unchanged
* j- V; l* U6 S3 T4 l/ ^                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
' O6 u: i: d" H                                Resubmitted  odp: drop
; r1 p/ g5 L* i3 m  J+ |3 O                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
5 B0 o; @0 h& k; J9 |2 c* Q* E7 L. X                                OpenFlow actions=output:1,strip_vlan,output:3,output:4 2 E4 h2 o3 H9 ^9 [
                                skipping output to input port
! `& o6 h" X& w+ x2 l2 u* {
0 R( z: L# y/ h4 }* F7 rFinal flow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000 ' I# {# C) x3 j0 C" [- p- D9 O8 `3 i
Relevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:f0/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
; J# E" E5 ^& d" yDatapath actions: pop_vlan,12,13
! A: R% v" w) {" c! Q+ ^/ B: l4 S6 M( i- @) A. F
结果是port 1就不发送了,发送给了port 3, 4
5 N) x& V& P& \" i7 `) f2 F
' T& H8 F8 r9 U6 y( V) ]4 C; N$ sudo ovs-appctl ofproto/trace helloworld in_port=3,dl_dst=ff:ff:ff:ff:ff:ff
6 S6 o# j+ \  P- N* V' s) tFlow: 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
# {  b# m/ E2 ]: V" V  tRule: table=0 cookie=0 priority=0 ' d' F7 I( A- w
OpenFlow actions=resubmit(,1)" w8 S2 t$ F% g+ k+ t$ W# {
+ Z' X% p* N6 L, v  _% ~2 ?
        Resubmitted flow: unchanged
) ^) f+ u3 c, o# J6 `# {: w        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! C/ w5 m/ \, c% w2 t$ D9 s+ W
        Resubmitted  odp: drop
4 t5 t) a4 @6 T        Rule: table=1 cookie=0 priority=99,in_port=3,vlan_tci=0x0000
: |/ r. |+ O$ k        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)+ R/ `% f5 K. K$ n( w1 R5 K; p
0 e" E# }& j3 o: @) M1 i9 I
                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 5 b% \2 r, U) m
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 + S: s) u! p6 e7 y: T6 x
                Resubmitted  odp: drop 9 r1 I* d) s" T( R: ?9 d3 C" Q
                Rule: table=2 cookie=0
2 A$ r9 K$ [( o- ^                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
& X3 @7 n/ f, K5 R( V' ]( A9 P1 H* F$ Q6 N. J
                        Resubmitted flow: unchanged ! q5 k( E" J' g+ h; L2 M; o
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 , I# f" ?& E8 k+ R! T, x; \9 k6 V
                        Resubmitted  odp: drop 7 z2 c+ ^# u/ O& X) P
                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00
, M% E4 j3 n) b8 j                        OpenFlow actions=resubmit(,4)! W( h8 m) d8 T. n2 U7 v
8 U& f3 A9 ^& ]& i+ J
                                Resubmitted flow: unchanged
8 P+ |% M! K7 ?: q8 y                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
& U3 @8 Y# m) y( U3 N                                Resubmitted  odp: drop ) s8 _" D( D: A0 w6 R0 Z2 ^5 S
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
! B, C8 q8 V5 j" v7 S& P3 h                                OpenFlow actions=output:1,strip_vlan,output:3,output:4 6 M6 {' {4 g/ K! B2 G
                                skipping output to input port
* n0 ?& L. N$ F) }2 n% R) Q5 b$ i8 F: U
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 : p3 q% K' R* r0 h5 O* l7 m$ W
Relevant fields: skb_priority=0,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:f0/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
. d3 f1 I# x, k9 @4 DDatapath actions: push_vlan(vid=30,pcp=0),10,pop_vlan,13/ W) Y% j, X6 o) z
3 n. }, }5 h0 l( T+ s
接着我们测试mac learning( t7 X/ W; e8 g8 D" s2 b9 H( t

4 T5 h* y3 @; |/ @1 _/ j; O$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=30,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01 -generate   * O% O0 l5 n- {2 e% b
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
. N( D- }- P* I) K5 O& pRule: table=0 cookie=0 priority=0
3 U" @2 u% v! d6 r6 L) OOpenFlow actions=resubmit(,1): W) Q/ _) S1 e) k4 t3 ]
. _- Z7 _" z  \) y/ x4 H/ a6 E3 _
        Resubmitted flow: unchanged
5 o4 A0 M6 }( s0 F        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 4 T' D3 t8 n6 s# J
        Resubmitted  odp: drop 5 S: W! S! Y; L
        Rule: table=1 cookie=0 priority=99,in_port=1 0 X- {' x0 m6 Z0 G! K/ D# y
        OpenFlow actions=resubmit(,2)
1 k& P8 V2 B# ]0 Y) M# S6 S# O9 \  e8 ^1 o7 S9 H" U8 n
                Resubmitted flow: unchanged
  ]3 a$ a  @7 Z" J; u8 ~                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & w$ h$ s0 v& b5 X
                Resubmitted  odp: drop " T8 n3 {. ], m5 q! }% H
                Rule: table=2 cookie=0 0 w9 Q6 v: A* }0 O- E, l% B' {1 N) i3 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)
+ C" g; J" G; q+ f
8 |- y: {5 o- K7 O                        Resubmitted flow: unchanged
% f8 U. P( R- S/ d( O5 Y! A                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 1 k; e. A  W0 G1 i1 E4 i# q
                        Resubmitted  odp: drop
4 h9 [* p/ _. M5 x                        Rule: table=3 cookie=0 priority=50
2 o6 m4 L' ?" L# q/ |                        OpenFlow actions=resubmit(,10),resubmit(,4)
  Q+ P5 z* O6 \2 Z9 Y3 b
  b3 s1 n, W, e" v; U2 D; a                                Resubmitted flow: unchanged / {5 a8 `- ?' q. \1 m. }
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ; f- F/ K$ m: }/ N
                                Resubmitted  odp: drop
- @. R& R  T2 j: X, {" L' S                                No match
8 \4 s' i3 Z! W. y5 H* o) T5 t* E9 m/ Q" w1 [5 z9 z& y. d: U9 r
                                Resubmitted flow: unchanged
3 M- k6 z) D- B  h! h9 w                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
$ _' V3 s/ X2 W9 Q                                Resubmitted  odp: drop 9 }( t* ~  \5 [; g3 x" E
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 : y, \7 G0 T( V  s1 |) `) m! @; d
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
/ v: ^3 ]& a. L* |% x/ x2 W                                skipping output to input port8 K2 U/ l9 \. g# K( S. z

0 f5 O) H( U  Z, x, a8 eFinal 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 " P5 k) E. U) ^. d! f
Relevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000,nw_frag=no
3 {% J6 U/ E3 w+ _& @& {Datapath actions: pop_vlan,12,13
  {/ U) e& ]7 h5 o
) Y; J3 G" ?  m& X由于这两个地址没有出现过,则除了进行学习以外,广播发送给port 3,4
7 Q, a$ Z( w( m8 o  \; y$ K: {4 s9 c; E
$ sudo ovs-appctl ofproto/trace helloworld in_port=4,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01 -generate   
  K+ z1 D1 M! b* Y& o4 ~' _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
5 \# b9 p4 _% x7 j% \Rule: table=0 cookie=0 priority=0 : M) A" d4 ?( {' a) \
OpenFlow actions=resubmit(,1)
! A$ J/ |+ B$ E6 |; M; K
1 O% m; P, `4 @8 U! j) N        Resubmitted flow: unchanged - {+ m/ A3 ]0 @$ \- p/ _2 ~! E
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
: d/ H! i+ K) ~5 m+ f        Resubmitted  odp: drop 5 C' |4 I  b( i. S* v* D- M7 x
        Rule: table=1 cookie=0 priority=99,in_port=4,vlan_tci=0x0000 ; n' i1 F, ~1 z- W2 A  ]
        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)/ e1 \2 `. W! S3 [* V- h8 r

. t, v. Z9 t9 N% A8 y                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
3 g  ?3 x: t$ b' q4 C' \                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 0 W3 @6 a0 b9 c9 `; v( D* j0 ^* m
                Resubmitted  odp: drop
! Z$ [: |; z" t  v                Rule: table=2 cookie=0 8 _7 V, f; }# `- \
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
6 G6 a4 j  M5 k1 m4 d0 w! |  w$ u6 V2 Q0 y7 M  f
                        Resubmitted flow: unchanged ! Y/ |# t% N6 E- S6 S+ B
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
7 V8 s" d# q0 J                        Resubmitted  odp: drop . K" }5 S! d# L8 U
                        Rule: table=3 cookie=0 priority=50 / A5 }5 [, M3 u! u+ Y
                        OpenFlow actions=resubmit(,10),resubmit(,4)0 y$ G* O5 M4 }# B4 n8 O) |) I
* v+ r: T8 ?$ I, P6 F  X
                                Resubmitted flow: unchanged   b; R2 {* X' p8 e7 N4 l$ R; N
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
& K* V6 s1 W. X5 x" y                                Resubmitted  odp: drop
$ w' F6 f2 \6 s/ S" o                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=10:00:00:00:00:01
! A1 A! x1 `  E+ N" z                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]
$ B5 G. G+ q. g8 G4 ~" L1 O+ N4 E0 k
                                Resubmitted flow: reg0=0x1,metadata=0,in_port=4,dl_vlan=30,dl_vlan_pcp=0,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01,dl_type=0x0000
4 z; s8 L6 j0 I) s: h2 z5 L" t                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
: `& M' V+ m1 o/ ~, o                                Resubmitted  odp: drop
7 M3 G& ]( N" L1 ?: H: y                                Rule: table=4 cookie=0 reg0=0x1
' _. \" o' Z9 A                                OpenFlow actions=output:14 n* K# k& \, s' J( T: E6 G3 G0 e

+ Y7 r! S$ j' A6 N0 n, r, FFinal flow: unchanged
( ]/ r! P2 \- I- ]' 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 ; N2 f' U4 a9 Y0 K1 F
Datapath actions: push_vlan(vid=30,pcp=0),105 q7 c! e( [/ v. f4 ~) q

; G! L- f* p' T; @' d: Q* M回复的时候,由于学习过了,则仅仅从port 1发送出去。; Z9 I/ ]) r) J/ y6 {8 v
! a/ a$ B  \2 F/ l5 P' |! h8 t
$ 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
. W& E/ z9 |' e4 u3 WFlow: 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 J: K- s, `" f, p
Rule: table=0 cookie=0 priority=0 6 c. y4 O1 X3 b7 @: |1 H3 S# D
OpenFlow actions=resubmit(,1)
. U% U* q# c6 j% }. ?* l. C, Q* W
; K3 }* M( c5 g1 n2 E7 d        Resubmitted flow: unchanged 6 ^$ Y  o- w& d+ l; d4 Q
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
9 i& M' @* g& J- T" w* O& \        Resubmitted  odp: drop
+ e8 l8 o! ~4 M1 @, F9 N        Rule: table=1 cookie=0 priority=99,in_port=1
$ C/ \# P$ q: [2 K, X        OpenFlow actions=resubmit(,2)" q+ }7 }" E5 h- y) d% K

1 |! `) V/ Q" ?- u7 a) H                Resubmitted flow: unchanged
3 e1 e2 B! `# M& `. {8 m                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
' O: N) Z* ?% S: x: f                Resubmitted  odp: drop $ w* T4 I, q8 b* d" m
                Rule: table=2 cookie=0
8 ^. l. D8 W. v/ ^/ Q( \                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 \; ?' C" b* e3 v) Y1 p- T
' y! \8 Q8 b6 R! W) I0 n. z                        Resubmitted flow: unchanged 7 q5 I0 l1 ]5 X+ v* w2 e8 `
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
4 _+ ?6 b/ }+ t* Z4 m5 f                        Resubmitted  odp: drop
  l$ k& \, N1 Y/ k: ]6 w                        Rule: table=3 cookie=0 priority=50
5 j$ |9 o* y- I6 u                        OpenFlow actions=resubmit(,10),resubmit(,4)8 W0 }: ^% X* V3 P% ^* n) B

5 L& A8 `, I3 t- n- Z1 a                                Resubmitted flow: unchanged
4 l8 U$ V  ~+ y" z, y7 u                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 G) n: x3 {) F
                                Resubmitted  odp: drop , z0 ?  R9 `- y2 q+ y( D- K  @
                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=20:00:00:00:00:01
. [$ f, z5 ^3 }  G. h                                OpenFlow actions=load:0x4->NXM_NX_REG0[0..15]. Q' D# m; s  u
& i& o, L+ z6 x3 D) U4 l
                                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
5 p/ w3 L& R; z, x) \                                Resubmitted regs: reg0=0x4 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
9 s+ f2 a  A' C9 R3 J! |                                Resubmitted  odp: drop 0 _8 R6 x6 h/ f/ |' w3 d
                                Rule: table=4 cookie=0 reg0=0x4
$ B0 o/ x' U! x  m) D( z, c* G                                OpenFlow actions=strip_vlan,output:4
7 G- ^$ {2 K' q4 w) |  S* M* U
( t9 v) {2 @1 Y9 D; @5 `& uFinal flow: reg0=0x4,metadata=0,in_port=1,vlan_tci=0x0000,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000
. j7 Y9 Z# ?3 oRelevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000,nw_frag=no
3 {* x% }3 h$ ^/ L1 }! qDatapath actions: pop_vlan,13
$ _) A5 v% F/ ~7 p8 x6 J- X: N( B; e0 H( h& b$ i! C
由于在回复中进行了学习,因而发送的时候,仅仅发送port 4

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2019-10-25 10:00:36 | 显示全部楼层
实现第一个Table 0,Admission control! }& Z: I! _0 L: i/ V5 p

3 ?) a, M0 a% a1 B8 g: W  X! K+ g$ a1 A包进入vswitch的时候首先进入Table 0,我们在这里可以设定规则,控制那些包可以进入,那些包不可以进入。' T) P5 z2 P- x; ~7 w0 I

. y5 r3 ]. G; v比如,如果source address是multicast的就不允许进入。0 ]' U6 \6 g2 S: ]0 J$ z( R

. Z; K$ N# g) L0 F  f9 h! T3 X' t01:00:00:00:00:00/01:00:00:00:00:00是广播地址
& o# I% y; W9 D# f5 e" B5 Q00:00:00:00:00:00/01:00:00:00:00:00是单播地址, b8 @+ b; n$ I- P& ^
这种表示形式类似CIDR. {. C6 V2 \9 R
于是我们添加下面的规则:
  `3 \! X8 Q! d+ H* [sudo ovs-ofctl add-flow helloworld "table=0, dl_src=01:00:00:00:00:00/01:00:00:00:00:00, actions=drop"
+ U7 Q# R* O5 a9 MSTP的也不接受
8 p9 c, G; t& [5 e: d8 f+ wsudo ovs-ofctl add-flow helloworld "table=0, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0, actions=drop"
+ f! K0 V% k& x; _我们在添加最后一个flow,这个flow的priority低于default,如果上面两个不匹配,则我们进入table 1: {1 H, h+ d2 p& y& W/ T5 q1 n
sudo ovs-ofctl add-flow helloworld "table=0, priority=0, actions=resubmit(,1)"/ x% x9 ^, H% p# x% O, I# i. K8 R. n
我们查看一下所有的flow, F% h; T& U# H3 e) H
$ sudo ovs-ofctl dump-flows helloworld        4 g% f# o7 I7 [5 D7 r$ j
NXST_FLOW reply (xid=0x4):
. r: R5 V8 J' hcookie=0x0, duration=42.162s, table=0, n_packets=0, n_bytes=0, idle_age=42, priority=0 actions=resubmit(,1) 8 D+ g: r/ ^1 T' @
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 5 c% i5 M  I  c. M& d+ 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=drop
& P' N( U1 \/ t0 `% m* t/ E
" @( ^- I+ ~, @, a测试Table 0
" w* O4 P( w& H  y6 @0 q( h7 D& W$ b# o, l$ G3 J7 T* ^" I
有个很好的工具ovs-appctl ofproto/trace
  v8 p6 Y- `; U% a3 _' d! G2 H
7 w3 S; V( M2 s% a不满足条件DROP1 j8 i8 k, b8 S- x

, H, `3 x- S$ t  B$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:05
- e$ |1 p: t, F- ]# kFlow: 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
* A. b( J, D- t" S- I& sRule: table=0 cookie=0 dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0
$ y7 U3 ]. F& c2 i5 VOpenFlow actions=drop
8 ?- U. \( |; G
( V7 Z  F. i: ^Final flow: unchanged
: z' U" G3 T7 i8 i& }5 R1 TRelevant fields: skb_priority=0,in_port=1,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no ) q. g& `( O! l/ h5 K
Datapath actions: drop
* {2 }6 _4 d8 H+ N! _  Q7 w& z& b- Z& d4 Q6 s3 G
满足条件RESUBMIT% y1 W4 T6 z9 e3 u1 d$ P: ^5 L

9 |4 F) X4 o3 _: h0 d; l$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=01:80:c2:00:00:10 6 ~" l7 L& S8 P8 {1 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
5 f! ~- C0 z9 _Rule: table=0 cookie=0 priority=0 4 c4 d& n+ X5 O8 \& L. {5 J- ]
OpenFlow actions=resubmit(,1)) A; P9 I1 t) O6 I) t2 O4 }& M  D
* U/ b6 N2 d% y  O5 A
        Resubmitted flow: unchanged " J  ]/ z/ q- {1 s" Z; V, V. {
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 # P: r1 Y8 ~" V2 Z# n9 n* @- n4 z. {
        Resubmitted  odp: drop $ [% f& v, Q% i
        No match3 H0 b" Y2 Z7 ~0 t' t
+ T1 X$ [: o( g9 S- t
Final flow: unchanged
# Z; S6 d( x# d/ Q5 W6 e& s* fRelevant 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 + g% j* e. c, u0 M! Z: `
Datapath actions: drop  X" N2 H# Q4 F$ ]  ~! b
. U" I. I# |" E: {* b
实现第二个Table 1:VLAN Input Processing. L' v/ Z+ x+ m2 h
* O# I7 r6 c/ |1 ~  r& I; {. l2 |/ C6 v
首先添加一个最低优先级的DROP的规则7 K. a: B1 _4 p7 K1 }7 O! f" r1 ^

4 c$ a, |. n+ x6 asudo ovs-ofctl add-flow helloworld "table=1, priority=0, actions=drop"
+ }" v$ Y. u5 R0 F' }: d: \/ k
% S# E) E$ m0 X9 }* U2 F/ n& @( _对于port 1,是trunk口,无论有没有VLAN Header都接受。# I% Z5 N. h! R# Z* D

' H$ m, ~3 C" O+ S: S  _0 Gsudo ovs-ofctl add-flow helloworld "table=1, priority=99, in_port=1, actions=resubmit(,2)"* R& D/ T; X  {; J. p5 S& w& a
- p. {1 ~+ F0 O
对于port 2, 3, 4, 我们希望没有VLAN Tag,然后我们给打上VLAN Tag6 j+ P8 Q; S) e

' O' q$ Z4 @4 u$ `/ b* D$ sudo ovs-ofctl add-flows helloworld - <<'EOF'
+ p  j$ l* W0 g& ~8 htable=1, priority=99, in_port=2, vlan_tci=0, actions=mod_vlan_vid:20, resubmit(,2)
4 Q4 j& B$ E" S, ]/ F1 Ctable=1, priority=99, in_port=3, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2) 8 y! {) h% H2 V. v/ N( p
table=1, priority=99, in_port=4, vlan_tci=0, actions=mod_vlan_vid:30, resubmit(,2) ' n! m, C8 R; L1 Y0 r  {0 m
EOF
" `3 l9 x! d$ O3 G# E( t6 m2 r+ A+ t; R
$ sudo ovs-ofctl dump-flows helloworld 5 I3 v4 W" c1 s
NXST_FLOW reply (xid=0x4):
$ V; [5 \# A& k) B+ g2 c$ g4 O: hcookie=0x0, duration=4478.582s, table=0, n_packets=0, n_bytes=0, idle_age=4478, priority=0 actions=resubmit(,1)
/ e* F2 S. b$ }6 Q* q2 a- ]cookie=0x0, duration=4668.541s, table=0, n_packets=0, n_bytes=0, idle_age=4668, dl_src=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop 0 y, ^$ a: P, `
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   H8 q0 r6 U' m4 \; R, P. m
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) ; n+ D% X+ v* L- C# L7 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) 8 _8 _8 e' b8 _  U% s
cookie=0x0, duration=89.273s, table=1, n_packets=0, n_bytes=0, idle_age=89, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2) ' R' C. m  h6 g9 s8 I' _9 p# o
cookie=0x0, duration=220.318s, table=1, n_packets=0, n_bytes=0, idle_age=220, priority=99,in_port=1 actions=resubmit(,2)
- T& t5 b3 }1 i& Q3 l$ ~9 P% I2 o+ r3 tcookie=0x0, duration=298.739s, table=1, n_packets=0, n_bytes=0, idle_age=298, priority=0 actions=drop
0 M6 A5 i4 K% O% Y$ D1 A4 B# i, [9 [% {3 [: t7 C/ k0 p
测试一个从port 1进入,tag为5的2 @: r- m* W1 u' [& V: w$ i
# J! |9 m$ D9 S/ E
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=5 " U$ u& t  _5 `# N1 M" {; S! {0 k
Flow: metadata=0,in_port=1,vlan_tci=0x0005,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000
8 a5 B$ P$ Q* R( sRule: table=0 cookie=0 priority=0 8 U  i5 Z, S1 i+ q
OpenFlow actions=resubmit(,1)7 `/ V9 U$ z# F' U3 f
# i" D& K1 P* O
        Resubmitted flow: unchanged
% ]4 ^& D5 r& x: m) |        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 $ ?! l. ^: @' j8 k
        Resubmitted  odp: drop $ }7 A: C% t" }: `% O& I
        Rule: table=1 cookie=0 priority=99,in_port=1 . j/ |2 h( Q( J) C
        OpenFlow actions=resubmit(,2)1 q# D2 f2 s6 t
& ~- F1 a6 H' p7 c5 t/ Q0 x8 g
                Resubmitted flow: unchanged 2 F2 t) X1 t" g
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 5 D4 X+ A9 b6 G/ Y3 y
                Resubmitted  odp: drop - h6 k5 Z) @: n5 m) F! x; ^
                No match7 [) w1 y5 C4 n" j
  _4 n; Y7 ]3 o, P4 C9 Y2 L- d
Final flow: unchanged
' Y* M7 t) m! P) \" v7 k2 ORelevant 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
% f7 u  c- `& CDatapath actions: drop
. W' j2 `0 O7 ~7 W3 }. d# N1 O
# w/ |9 L: a+ I& n+ z' h. N9 f测试二,从port 2进入,没有打Tag的0 ^. W" T! E  C

3 A: S4 r% L6 S/ O7 o$ sudo ovs-appctl ofproto/trace helloworld in_port=2
3 G2 m. v& ~4 \8 b5 ^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 7 y* d: i, S7 Y7 p
Rule: table=0 cookie=0 priority=0 - n  y5 n' k9 A
OpenFlow actions=resubmit(,1)* F. ^' n& N$ s; l* m; o2 i3 h0 {% G
. a  U* W8 h0 j2 h" C! K% |$ V) Q( L
        Resubmitted flow: unchanged
' i0 D/ }. x/ _1 E        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! ?0 t3 j4 \* P9 r
        Resubmitted  odp: drop * R; @/ [- m! R$ x/ m  t. d
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
! R4 |$ E/ M# A; L        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)
3 H* {2 L' Q1 F3 J3 X' H' W( F- E; |; }/ c) a$ h, b
                Resubmitted flow: metadata=0,in_port=2,dl_vlan=20这里被打上了Tag,dl_vlan_pcp=0,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,dl_type=0x0000 + m3 E* E: U! c; t
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
( k( @- |% A! F/ z" U/ F* x                Resubmitted  odp: drop * j' r- P+ }+ q7 W) c: ?( T
                No match
7 ]9 [. b) G  `* n8 ~% E: N3 n
% ~; M# ~2 W/ M1 I+ l4 q5 ?$ qFinal flow: unchanged
  C2 c( N$ l2 A- h! g8 gRelevant fields: skb_priority=0,in_port=2,vlan_tci=0x0000,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
2 s- \" r- d5 r2 @9 w# |Datapath actions: drop
, R) \! O! h: ]* U. W0 P6 \; n  ]/ y2 j8 j5 w  U) S& x: _
测试三:从port进入,带Tag 5的2 ?' D( r/ q6 R4 m. U

3 @5 C5 e; a6 M# C9 q$ sudo ovs-appctl ofproto/trace helloworld in_port=2,vlan_tci=5
4 ]2 ^4 l$ L5 A) R# }6 gFlow: 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 - e1 G7 q) }0 u
Rule: table=0 cookie=0 priority=0
( I: Z0 Y  d, H. \( t* S, _OpenFlow actions=resubmit(,1)) i6 }7 l; X6 H0 u- x3 S( T4 @* M
8 r6 y9 b1 u2 k8 g% k+ b4 P( V6 E
        Resubmitted flow: unchanged
* R% V! H  ~6 `) b        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 , f( e0 h3 a9 L
        Resubmitted  odp: drop 8 f" U5 [) {8 J3 x3 {0 _" t* M" Z
        Rule: table=1 cookie=0 priority=0
6 B5 N0 o& F) g# H5 x        OpenFlow actions=drop. X9 ?& e& ~1 y6 b+ Q
) s7 S# ]4 [" h) [- _
Final flow: unchanged * w! Z% M5 A' s& N
Relevant fields: skb_priority=0,in_port=2,vlan_tci=0x0005,dl_src=00:00:00:00:00:00/01:00:00:00:00:00,dl_dst=00:00:00:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
$ z" y9 r' W+ H7 _6 h( p8 ADatapath actions: drop- b( d/ A5 t* _" N
/ y: B) G0 t3 O/ U# w
实现第三个Table 2: MAC, VLAN learning for ingress port
- u% j4 ]. P' N3 `0 M0 x! d( A( S0 s  p* Y4 b
对于普通的switch,都会有这个学习的过程,当一个包到来的时候,由于包里面有MAC,VLAN Tag,以及从哪个口进来的这个信息。于是switch学习后,维护了一个表格port –> MAC –> VLAN Tag。
# C/ L& U- R& H: ]& C. h6 m# M: n  `. J6 `
这样以后如果有需要发给这个MAC的包,不用ARP,switch自然之道应该发给哪个port,应该打什么VLAN Tag。
* [$ V9 j5 |0 J/ C; D8 o! p, G8 h' p5 Z
OVS也要学习这个,并维护三个之间的mapping关系。
* M9 I7 x6 a! i2 a# U+ k8 w7 I$ ]8 k
在我们的例子中,无论是从port进来的本身就带Tag的,还是从port 2, 3, 4进来的后来被打上Tag的,都需要学习。9 u% @7 \- A5 I6 T  `, e% P0 i7 a

9 Y8 y4 f* p+ a7 G. Asudo 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)"! ^, f& X1 S$ _, y6 Y% u
$ D& X# Z8 E$ g  x, L# [, Q
这一句比较难理解。
' K) ^. t9 c1 p# c2 u6 e" M/ C% Y5 t. Q
learn表示这是一个学习的action
4 m, O$ O& q7 m: [8 I/ e& l3 l) q1 A. [4 h& I5 b+ e- u: T8 F
table 10,这是一个MAC learning table,学习的结果会放在这个table中。! v1 O: X& t/ E) t% W7 r5 F* @
/ I" ?* g! a9 d7 m9 @3 @
NXM_OF_VLAN_TCI这个是VLAN Tag,在MAC Learning table中,每一个entry都是仅仅对某一个VLAN来说的,不同VLAN的learning table是分开的。在学习的结果的entry中,会标出这个entry是对于哪个VLAN的。
# ^- F, w* S6 V' W
9 B- d3 F# u& w( ]' G  N/ S" iNXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]这个的意思是当前包里面的MAC Source Address会被放在学习结果的entry里面的dl_dst里面。这是因为每个switch都是通过Ingress包来学习,某个MAC从某个port进来,switch就应该记住以后发往这个MAC的包要从这个port出去,因而MAC source address就被放在了Mac destination address里面,因为这是为发送用的。9 ^, P, h' J9 b3 l* e, ?
: f. m' a- h: J5 `5 S1 ^
NXM_OF_IN_PORT[]->NXM_NX_REG0将portf放入register.1 X* m7 o5 Q  `# t
. ^9 ^9 w5 L1 {+ x- |, o" o# a) S
一般对于学习的entry还需要有hard_timeout,这是的每个学习结果都会expire,需要重新学习。( P8 K8 m% @  w8 @7 w
+ {" _& X5 ~% w
我们再来分析一个实践中,openstack中使用openvswitch的情况,这是br-tun上的规则。7 }9 ?& T+ l- e0 b9 y
8 q! ]2 E' @% _: l
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 * Y5 [( m: r9 N2 e( |9 \
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 j/ a# P& |8 W+ }# x
cookie=0x0, duration=802038.514s, table=20, n_packets=1239, n_bytes=83620, idle_age=735, hard_age=65534, priority=2,dl_vlan=1,dl_dst=fa:16:3e:7e:ab:cc actions=strip_vlan,set_tunnel:0x3e9,output:2 $ D, ^. r; J: b$ z! @' t, U7 z1 @
cookie=0x0, duration=802187.653s, table=21, n_packets=17, n_bytes=1426, idle_age=65534, hard_age=65534, priority=0 actions=drop
* I& f! _0 L8 wcookie=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$ u7 t0 [9 d8 r  o5 U! t) d
( V( s0 s; n. Y, a
这里table 10是用来学习的。table 20是learning table。如果table 20是空的,也即还没有学到什么,则会通过priority=0的规则resubmit到table 21.
0 H/ Z* {* H/ t- E  V3 l1 x; B5 p- e0 f3 p5 j* a# [
table 21是发送规则,将br-int上的vlan tag消除,然后打上gre tunnel的id。  b7 k  U6 w  @) l% S% v& V) B
) Y  r& C; s' I+ x; q! Y
上面的情况中,table 20不是空的,也即发送给dl_dst=fa:16:3e:7e:ab:cc的包不用走默认规则,直接通过table 20就发送出去了。
0 F+ n& ]0 h, |6 x' G, X& X: ~( p  k* \% V# Q
table 20的规则是通过table 10学习得到的,table 10是一个接受规则。最终output 1,发送给了br-int/ R3 z; V# n! ]6 e/ o
4 u5 V' k- W& t" ]: N' d4 ]
NXM_OF_VLAN_TCI[0..11]是记录vlan tag,所以学习结果中有dl_vlan=1
8 B1 K! z! z3 i; R8 p% }1 A1 l: d' W6 r
NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]是将mac source address记录,所以结果中有dl_dst=fa:16:3e:7e:ab:cc, I. {5 [: M: ^: _

+ g- ?4 C0 l" l) S6 O/ E9 i( T2 }load:0->NXM_OF_VLAN_TCI[]意思是发送出去的时候,vlan tag设为0,所以结果中有actions=strip_vlan  k+ u6 x* }* F' R- Y$ K$ H
  V  l/ s7 K+ S- l2 X, w- H
load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[]意思是发出去的时候,设置tunnul id,所以结果中有set_tunnel:0x3e92 Z6 T; G) i6 F: h
" e5 }$ R7 X0 A0 \8 E$ e" G
output:NXM_OF_IN_PORT[]意思是发送给哪个port,由于是从port2进来的,因而结果中有output:2
1 K# r- n/ j" R& \  e  E
9 I0 L3 \) A! c! g$ |. W7 c. e测试一:从port 1来一个vlan为20的mac为50:00:00:00:00:01的包
1 K8 I7 T; m" d1 D9 u9 ]+ h
8 ?! M& p( k  ?7 t$ sudo ovs-appctl ofproto/trace helloworld in_port=1,vlan_tci=20,dl_src=50:00:00:00:00:01 -generate   
+ w1 |  I# d" a& Z& o2 RFlow: 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 ' q9 i. O8 \2 Y" u
Rule: table=0 cookie=0 priority=0 0 X, H8 o8 f8 j: Y8 @- U; H. f7 ~
OpenFlow actions=resubmit(,1)) |9 R+ o5 b6 n/ j

" ~5 l5 `2 P& N  v* B1 a# i! u        Resubmitted flow: unchanged
  E2 @0 i& y0 ?/ S  s* F! K        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ( n8 @7 {. Q5 s2 Y
        Resubmitted  odp: drop ; ^, t. O2 C7 m" o: O: j
        Rule: table=1 cookie=0 priority=99,in_port=1 2 {3 ]) n' {1 |* r0 Z
        OpenFlow actions=resubmit(,2)! q9 }2 C- _+ _' K$ h  \
) w" E) B: ]7 M8 B6 u
                Resubmitted flow: unchanged   N) ~% x$ o% x- p4 V
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 }- ]& u: W- ]
                Resubmitted  odp: drop 3 p/ R- ]: Y, |; u
                Rule: table=2 cookie=0 ) v1 R7 ~6 s) K% J2 T4 T$ R5 }
                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 T1 a! s* S2 W. f; h; Z' t5 {

1 r; |+ Q2 r. g, v2 _                        Resubmitted flow: unchanged
4 {  k2 ?3 V' g- ?6 Z( H                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 5 T; x2 x3 M& r( E+ Q% A# v5 \
                        Resubmitted  odp: drop & l* x0 p+ T1 W. H8 B0 ^4 U
                        No match& p+ G! I% T1 z, [
# r. Q% P, v. L8 p
Final flow: unchanged
; M' r- }( ?7 [4 G# aRelevant 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
- a, k/ X. f9 i9 ~2 a, ^6 WDatapath actions: drop! e! p" i0 a7 e& C

5 T) d8 D5 \* s$ sudo ovs-ofctl dump-flows helloworld
, ?; m9 T3 P" K+ J" ]6 KNXST_FLOW reply (xid=0x4):
) t! u# V7 {$ z( i* _0 A* Z8 _8 [cookie=0x0, duration=90537.25s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1) : o4 j' e* Q2 [+ F7 Q5 j5 c
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
! B4 Z; z, T8 ?( rcookie=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
$ e: c  x) y" b, {& P& I4 Q# pcookie=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) , j, h6 z. v( h! _$ B& T
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)
4 S# `0 U1 c' Z* K& n( C4 Vcookie=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) 7 k: A8 l6 s& t% n: X& V
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)
1 M+ x2 m0 |; {# {/ {! Y6 x( qcookie=0x0, duration=86357.407s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
- D* s4 m3 J. x2 ^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)
% N* t9 M1 A) L- D8 { 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]
; I  s6 p& H8 i# y8 y! w$ C) H/ M! n( _1 ^9 r+ d. j$ S& n* {
table 10多了一条,vlan为20,dl_dst为50:00:00:00:00:01,发送的时候从port 1出去。
# p% I& E8 S+ g+ O6 p+ z6 d5 c0 Y. A- w" h! c
测试二:从port 2进来,被打上了vlan 20,mac为50:00:00:00:00:02! ?8 }4 s# c6 `0 ^( |4 T+ g3 F. b

" j  _! J! i. U" z$ sudo ovs-appctl ofproto/trace helloworld in_port=2,dl_src=50:00:00:00:00:02 -generate   $ y6 U0 \7 H7 i8 ~9 o4 U7 B+ @
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
1 ~' [$ c: m+ w/ }4 @# A7 l/ }: Y. t/ V7 hRule: table=0 cookie=0 priority=0 2 ?$ j8 l4 |8 S+ f' m
OpenFlow actions=resubmit(,1)' Q. y7 q! F% q( P3 l. u. q9 j  W( i
) {5 w! v- P3 d& g
        Resubmitted flow: unchanged & V& P6 u* f- t  A1 L
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 4 Z9 I# z! p9 ?) `
        Resubmitted  odp: drop
- C2 y: l/ t/ c        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000 9 g+ i' Y7 Q/ P  D- j* L1 l1 a6 }
        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)# g: H' W5 E- E( k& y

4 R* D% a3 Q/ U" D2 r& |" [                Resubmitted flow: metadata=0,in_port=2,dl_vlan=20,dl_vlan_pcp=0,dl_src=50:00:00:00:00:02,dl_dst=00:00:00:00:00:00,dl_type=0x0000
7 G+ M, h1 z9 _% r+ ?                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 6 C, Q& m7 @& F) H" J$ f5 ?! R
                Resubmitted  odp: drop
# M. d8 ?9 F" r0 M3 H) Y" j                Rule: table=2 cookie=0 & A; F; C2 v- f7 q/ [3 u1 W
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)4 I6 N* V6 x2 b) m2 `

: q1 r9 D- U' u. i+ ^' D                        Resubmitted flow: unchanged 3 t( `3 k; o2 j" L7 }
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & _- A+ X8 _' P6 s1 o0 u( r; B' U
                        Resubmitted  odp: drop 2 g7 B8 j. z2 ~" e! J5 M
                        No match
  }5 v6 @+ C- Q# L6 J7 X. x1 R2 `1 v
& R( u. [7 M( w+ jFinal flow: unchanged
8 z& \; M$ B( u& H2 r9 @$ A1 YRelevant 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 ' |" G- U* R- c$ l* P
Datapath actions: drop- Z. K8 H) |4 F' z8 ^. _
& i" L( k* n2 Q0 e
$ sudo ovs-ofctl dump-flows helloworld                                                 + J; I" X/ p' k# z% N0 d& d3 ~# [
NXST_FLOW reply (xid=0x4): + C  ?: L, ?! T7 b
cookie=0x0, duration=90823.14s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
' I' f5 i2 u' {% icookie=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 8 D0 b2 A  [- i* q* H2 E: {
cookie=0x0, duration=90948.614s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
  ^, }2 U5 f* @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) 1 C( c  U" j" e+ m* L* X9 y
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)
" |. s0 L4 F" X% G) A  `/ E) Z4 acookie=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) # Y- v8 E  i3 f% a; J2 k: v+ Y6 P
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)
9 C+ Q5 X5 g6 i1 Ycookie=0x0, duration=86643.297s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
) D5 b9 F! b$ [0 O  r3 ]3 Qcookie=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)
! n2 a; b$ P- h+ u2 U6 Q/ P 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]
/ \) q. s  n7 T# N. N% {" Tcookie=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]" I0 u! p7 O8 ]$ [+ {. t
/ i. j. i  i& p
实现第四个table 3: Look Up Destination Port
5 b# e' z6 U+ u% A1 {2 n
) [5 X8 A; {5 v" t在table 2中,vswtich通过进入的包,学习了vlanid –> mac –> port的映射后,对于要发送的包,可以根据学习到的table 10里面的内容,根据destination mac和vlan,来找到相应的port发送出去,而不用每次都flood1 ~$ W' w, q$ h) `8 c
: P5 Y' X& P& B6 R5 \- m& l
sudo ovs-ofctl add-flow helloworld "table=3 priority=50 actions=resubmit(,10), resubmit(,4)"
8 `1 |2 a( o: x1 Z# @) D
* l7 u( _6 y" f9 k3 D! d% f- b添加这条规则,首先到table 10中查找learn table entry,如果找不到则到table 4
5 F* j2 G) {  p! o. a$ w, K7 t: [; J# u' C
如果包本身就是multicast的或者broadcast的,则不用去table 10里面取查找。
1 U4 A, a2 {1 I! p4 H" p. F9 i6 X" ^  C5 d3 t1 L. L" d
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)"
& T1 Z9 k$ R& b) f" d; c. T. U( O+ b4 e4 j" O- v9 O
我们进行一项测试. \- y7 C1 ?. K' \) w" b' S' i
  b+ Z8 S6 ]4 s: J1 e
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=20,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01 -generate   + u! U8 H0 M! m% N" k  M6 r0 U8 ~* X
Flow: metadata=0,in_port=1,dl_vlan=20,dl_vlan_pcp=0,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000 6 A% ]; j  F+ y& _' A
Rule: table=0 cookie=0 priority=0
0 x! ]& Q/ v$ }% S" XOpenFlow actions=resubmit(,1): O. S! ^4 Q5 m* ^1 ]/ z. _

; Q& \- Q6 T* y: G/ T0 V9 V        Resubmitted flow: unchanged
  A& Y$ a! p6 B8 p; A3 j        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 8 g( U2 q' n' \) y& d- u
        Resubmitted  odp: drop 7 |  }, j6 H7 d/ X5 n# u  E
        Rule: table=1 cookie=0 priority=99,in_port=1
7 h; H3 q! L2 l6 W! F9 w- f        OpenFlow actions=resubmit(,2)9 G- R. u  @2 N$ S' _3 F. P
$ G) u" h4 W1 p+ M( k
                Resubmitted flow: unchanged 5 x( C1 l+ L: W( P5 s. d/ \
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
1 h" T$ S3 B$ M1 o; I( j; \* _( D2 x                Resubmitted  odp: drop
! {! k0 S0 b% [( a                Rule: table=2 cookie=0 2 K$ Q( \  i4 i1 C. ?0 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)
) p: i1 h% ?- g: t8 f8 x
3 ~& |0 F% z# h; k                        Resubmitted flow: unchanged
0 z* v0 {7 W6 a% m0 Q                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
& Q' b- P$ J2 B& C3 P                        Resubmitted  odp: drop
1 ^- I8 ~" F# z8 s  }                        Rule: table=3 cookie=0 priority=50 # [4 T+ F1 I$ d0 `7 ?0 _5 e9 l8 o
                        OpenFlow actions=resubmit(,10),resubmit(,4)
7 I" G/ C  k' S
  S9 @% |& ^! Q# n* ~8 t                                Resubmitted flow: unchanged
1 {" ^6 d7 L5 A! X6 a, G                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 * d- \* O$ k- L9 j3 `+ C- s3 }
                                Resubmitted  odp: drop , {/ ^7 ~( X$ m2 l; O
                                No match4 O6 L( o9 Z: M5 Y" @
4 U" q, a9 d6 i) r" z+ V
                                Resubmitted flow: unchanged ( P; c4 N5 G! V7 a
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & |& g9 m3 |" F5 n8 \4 h
                                Resubmitted  odp: drop
. f0 w' Y, a3 _7 x. y                                No match
: f& D, B/ `* S( g) [
- O) I8 N" t0 ?' w) pFinal flow: unchanged
! n- _- N+ d! M% ARelevant fields: skb_priority=0,in_port=1,vlan_tci=0x0014/0x0fff,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000,nw_frag=no
- d) v- b0 k2 A) R. d) c9 lDatapath actions: drop1 u( P" i8 R, X  X
8 u8 j( t. I6 O) F8 _8 r
由于目标地址f0:00:00:00:00:01没有在table 10中找到,因而到达table 4./ D" p, q* l7 k2 N; {

, j4 ]# |1 k2 z' x: E/ D( _但是这次测试使得table 10中学习到了mac地址90:00:00:00:00:01
/ Y5 W2 ?- @! \1 K% p5 @) C2 P. k
$ sudo ovs-ofctl dump-flows helloworld . t. f1 j1 B& G
NXST_FLOW reply (xid=0x4): ; Q# p9 E# ~& r
cookie=0x0, duration=91588.452s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
0 r6 q! ^/ q$ x" Icookie=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
8 H2 s/ ?3 X1 s6 n- x. \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 ) K; v4 }& k7 l, R. R
cookie=0x0, duration=87199.143s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=2,vlan_tci=0x0000 actions=mod_vlan_vid:20,resubmit(,2)
7 S6 U9 W7 D, n: \$ S  j& Zcookie=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! W) K8 K3 K
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)
* T9 t% b3 v0 V4 \8 ecookie=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)
$ I" T7 C! F" n; gcookie=0x0, duration=87408.609s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop 7 R/ s6 _7 J9 \- g( R
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)
4 o0 k& |/ e  Bcookie=0x0, duration=352.841s, table=3, n_packets=0, n_bytes=0, idle_age=352, priority=50 actions=resubmit(,10),resubmit(,4)
  i" K! M6 t) U! O7 Ocookie=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) ; ~; g7 x7 m' U1 ~$ n! t, l
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] , t. s" m9 C2 Q$ h# O
cookie=0x0, duration=769.784s, table=10, n_packets=0, n_bytes=0, idle_age=769, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:02 actions=load:0x2->NXM_NX_REG0[0..15]
7 M0 s  S( C/ z$ H+ Mcookie=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 I, a. j! r4 e+ _9 ~% B& @9 H; P( f2 R2 I+ w
下面我们进行另一个测试
+ q* J! X0 w6 U; W& q6 j
7 R, s9 v$ l; M+ S6 d$ 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   
( {& I" b  g2 g9 F/ c! d" o1 j+ 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 4 D3 A5 t5 i! @2 T4 `' [) t
Rule: table=0 cookie=0 priority=0
) P' @: v7 i% _" DOpenFlow actions=resubmit(,1)
$ N. x* O* h8 T) |: h. l9 t2 }6 t9 K; U
        Resubmitted flow: unchanged
' j- b. _6 J+ t3 V" `        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! Q/ p  Y: `  W( [
        Resubmitted  odp: drop 9 n3 _8 |' G) Y8 t
        Rule: table=1 cookie=0 priority=99,in_port=2,vlan_tci=0x0000
7 l. U$ O/ h( U) Y        OpenFlow actions=mod_vlan_vid:20,resubmit(,2)- U2 f" _1 q0 @3 ~1 }+ p8 w9 R
! S$ U7 X6 J( x: ?. g8 E* [- 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
# b0 \% \0 B  X" O6 z* a                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & T. `% ?. h' W' j9 ~: K
                Resubmitted  odp: drop
& P8 i) j2 a: v% T                Rule: table=2 cookie=0
3 @) f" T4 U; S* Q  R; L                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)2 o( S* p5 W; h/ N1 z. t4 D2 S
8 c  j+ ~$ E! z1 O* [2 {
                        Resubmitted flow: unchanged
2 m- k0 C1 [' m                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 1 f+ W+ n' i0 N( T# y9 i
                        Resubmitted  odp: drop
0 n/ }/ U2 s: o  F                        Rule: table=3 cookie=0 priority=50 ) K9 }- B5 ?- c" {( q: C- r
                        OpenFlow actions=resubmit(,10),resubmit(,4)
8 T+ N) Q2 I6 G  a: @9 W3 n0 A
$ |. e, u2 N3 `: X2 W                                Resubmitted flow: unchanged
  w7 A3 m# L5 Y7 ]2 d                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
. {8 f  `! a7 y. V0 R                                Resubmitted  odp: drop 8 l# h! l' o6 J% w  ?5 k/ O
                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01 , d( S% z+ R0 d+ |% Y( c* |
                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]" L. f. X  u' B9 S

2 Q, p: V; ?1 B  G# b, }" [                                Resubmitted flow: reg0=0x1,metadata=0,in_port=2,dl_vlan=20,dl_vlan_pcp=0,dl_src=90:00:00:00:00:01,dl_dst=f0:00:00:00:00:01,dl_type=0x0000
: T- c1 j+ @$ {/ @' e, _& h9 G                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
2 I) G+ @7 a! y1 v2 Q                                Resubmitted  odp: drop
+ ~! b$ A% P: _                                No match2 ^3 J: V% _$ m/ Y1 ~( o3 d
( @  I' c) s: z1 U# u/ t
Final flow: unchanged
# @. H4 G1 Q5 r  U" U" HRelevant 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
+ p; }3 a" I" T9 f9 Z4 [/ _; u0 d. Q2 J! QDatapath actions: drop7 a' I+ y) I' K* Y, `0 t6 r

7 r+ q! D+ i; W. Y因为刚才学习到了mac地址f0:00:00:00:00:01,所以这次在table 10中找到了这条记录,这次同时也学习到了mac地址90:00:00:00:00:01
2 Q6 H& l* Y4 D% R- b9 l
3 n' @! C3 u2 r; R8 ~. x( [) D9 j" |下面我们再发送第一次的包
* E# E5 o& o; ~$ @6 y
% K# I0 h! Z7 a( u$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=20,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01 -generate
1 _/ v! |! k, t0 M  V! n+ jFlow: metadata=0,in_port=1,dl_vlan=20,dl_vlan_pcp=0,dl_src=f0:00:00:00:00:01,dl_dst=90:00:00:00:00:01,dl_type=0x0000 # }& g" m, d# I
Rule: table=0 cookie=0 priority=0 & U; `# `" k# n3 X
OpenFlow actions=resubmit(,1)5 d* S2 ^2 I$ w5 l

5 L6 c; s: `7 H: x) U        Resubmitted flow: unchanged 9 k# k  j7 Y! {2 l
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 % x1 {& ^' |1 ?" n
        Resubmitted  odp: drop
/ W3 O6 \0 z' k, @4 u3 S        Rule: table=1 cookie=0 priority=99,in_port=1
) i$ v8 g0 Q- Y        OpenFlow actions=resubmit(,2). J- i; ^$ P  t; h
9 R& K! K1 y" K
                Resubmitted flow: unchanged ( [/ J* ^0 u. b& h& {& i. g, P" J
                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 m+ E& ~( w9 G" \: d$ o
                Resubmitted  odp: drop : g# t, S; `& U6 h2 O$ c9 D
                Rule: table=2 cookie=0 1 d6 p( r' C7 Q+ h8 [- y
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)
5 i( ^, t2 ^% `( [
: T  V* t2 o: D' c+ K4 n- @                        Resubmitted flow: unchanged
4 g, @9 W7 n3 Y6 d5 Z& ?                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
; h" f  c- B5 ^7 _6 E7 x                        Resubmitted  odp: drop , n( c/ ]! O8 l
                        Rule: table=3 cookie=0 priority=50
( \3 w, }/ W! ?2 J2 T# B0 z2 I: ^                        OpenFlow actions=resubmit(,10),resubmit(,4); f4 K; C* I' j/ k- M
9 b9 |3 C4 s' O+ l+ y" n! |
                                Resubmitted flow: unchanged
3 y3 N3 A! a; G                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
, _7 _) R8 y* G0 C0 w                                Resubmitted  odp: drop
3 N9 r/ Q! Y  w; `# w                                Rule: table=10 cookie=0 vlan_tci=0x0014/0x0fff,dl_dst=90:00:00:00:00:01 4 q3 o8 i& H7 F3 f4 c2 ^$ G+ d0 r
                                OpenFlow actions=load:0x2->NXM_NX_REG0[0..15]) h' ]* `5 M3 {8 i4 _, F% X
0 y* h4 ]3 T# s/ e' ], G; t
                                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 % \+ I& c) ~; N6 l9 ]
                                Resubmitted regs: reg0=0x2 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
" ^9 v5 h7 d  t  K                                Resubmitted  odp: drop
9 t3 _, C9 y) W) p- q8 l2 G8 k                                No match7 q, d4 x5 e7 K

, a6 I$ J: b" z& D& vFinal flow: unchanged ! C% H9 m9 N2 W& l+ Z
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
& u9 q9 \) `& `2 z9 b0 VDatapath actions: drop5 k, I7 h0 S3 f, J( d3 d( W7 J/ T2 t
4 c; s6 T& \! `- L3 G* w7 U9 o
发现也在table 10中找到了记录
1 T$ G" E3 k+ B* {- T6 |
# m8 k7 b$ G3 o- w; ?! j8 d实现第五个table 4: Output Processing/ U4 J" X3 u8 X9 G! j3 d* q$ s/ \
2 C3 W4 [7 p6 ?* G! K
这个时候,register 0中包含了output port,如果是0则说明是flood。
' t% F( |/ K; v( C2 K- @/ h6 [5 U5 t& o" a' {3 e/ ]/ H6 P! I" z
对于port 1来讲,是trunk port,所以携带的vlan tag就让他带着,从port 1出去。
& N: |* n7 \1 B. S( J
0 r  x6 v' F2 p3 J  ksudo ovs-ofctl add-flow helloworld "table=4 reg0=1 actions=1"- g0 `* A6 Z; X) h* }; P: W

, \# B9 _( Y/ U+ X对于port 2来讲,是vlan 20的,然而出去的时候,vlan tag会被抹掉,从port 2发出去
6 Y: Y, V0 G8 F5 `( j. U6 D- a: J5 E4 b% b/ d5 w
对于port 3, 4来讲,是vlan 30的,然而出去的时候,vlan tag会被抹掉,从port 3, 4出去
% j) P0 n) O  {) P# ?$ o5 z0 @: ?, G4 ~9 e; t+ J! V: ~# T/ a
$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   
4 B3 b1 G* I" C1 M% D9 \        table=4 reg0=2 actions=strip_vlan,2
8 j* b# z& y- l; Q: m( C        table=4 reg0=3 actions=strip_vlan,3
+ x9 \9 s8 |. j2 x7 {; H5 n! C        table=4 reg0=4 actions=strip_vlan,4
& p! r9 B) L0 \3 D# |EOF$ c( H9 [6 _5 j# b6 v5 R
' K1 y1 v) Y3 v8 q: ]1 }; m( v
对于broadcast来讲,我们希望一个vlan的broadcast仅仅在这个vlan里面发送,不影响其他的vlan。
! e. H9 G+ y4 Q8 h+ _: [/ M
# p/ l) Z  n. Z4 e$ sudo ovs-ofctl add-flows helloworld - <<'EOF'   
( B! i* s, B9 e        table=4 reg0=0 priority=99 dl_vlan=20 actions=1,strip_vlan,2 0 H0 ?9 c) M5 l; M: r
        table=4 reg0=0 priority=99 dl_vlan=30 actions=1,strip_vlan,3,4 2 ?$ \/ }4 o8 }! P0 p" s
        table=4 reg0=0 priority=50            actions=1
$ k: `6 H- {0 A, z/ u: NEOF
" j7 S- B9 f: A" j; E
2 u0 l2 M" N$ ~所以对于register = 0的,也即是broadcast的,属于vlan 20的,则从port 1, 2出去,属于vlan 30的,则从port 1, 3, 4出去。
+ j$ d/ n" t: \1 ?& {/ X' z
2 }1 `/ L( f2 l+ Z$ sudo ovs-ofctl dump-flows helloworld
/ w$ ^# l0 Q. N" MNXST_FLOW reply (xid=0x4):
- B$ p( k) D5 z# w8 N" Ucookie=0x0, duration=92909.119s, table=0, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=resubmit(,1)
7 d! @; S2 ?  _- C2 Ncookie=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 * p7 C% O' [: N: x* z# @
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 + i% f) }5 R4 [1 m1 Y& G1 c
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) $ _/ V+ C; N; w3 n3 B
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) $ `3 q" ^* q$ j+ F* {
cookie=0x0, duration=88519.81s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=99,in_port=3,vlan_tci=0x0000 actions=mod_vlan_vid:30,resubmit(,2)   O: \' D! ~$ o+ V1 u) j! c
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)
' n6 m& G. z1 n) ucookie=0x0, duration=88729.276s, table=1, n_packets=0, n_bytes=0, idle_age=65534, hard_age=65534, priority=0 actions=drop
; i: l& E, }& R5 ?5 B1 ccookie=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)
' Q: P4 G# W7 B6 pcookie=0x0, duration=1673.508s, table=3, n_packets=0, n_bytes=0, idle_age=1673, priority=50 actions=resubmit(,10),resubmit(,4) 7 E6 E% J+ i1 R; z- d1 W
cookie=0x0, duration=1533.371s, table=3, n_packets=0, n_bytes=0, idle_age=1533, priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,4)
* P5 @) q9 @3 pcookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x3 actions=strip_vlan,output:3
& R) S5 Q4 t1 w6 F# t; E6 ycookie=0x0, duration=228.839s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=50,reg0=0x0 actions=output:1 9 y3 P2 U6 D" _% C0 m! M# D/ q
cookie=0x0, duration=483.068s, table=4, n_packets=0, n_bytes=0, idle_age=483, reg0=0x1 actions=output:1 0 Z+ p' T3 r% z8 z# \, ?/ O
cookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x4 actions=strip_vlan,output:4
. t" B0 L1 f; D( ]. Rcookie=0x0, duration=332.478s, table=4, n_packets=0, n_bytes=0, idle_age=332, reg0=0x2 actions=strip_vlan,output:2
$ S3 b+ M+ E( W6 S- `cookie=0x0, duration=228.84s, table=4, n_packets=0, n_bytes=0, idle_age=228, priority=99,reg0=0x0,dl_vlan=30 actions=output:1,strip_vlan,output:3,output:4 & c# Q5 p2 E' @. w; Y; C
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
: O. b, \! v1 }& ~3 t7 w' gcookie=0x0, duration=1438.031s, table=10, n_packets=0, n_bytes=0, idle_age=1438, hard_age=1109, vlan_tci=0x0014/0x0fff,dl_dst=f0:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15] - V( ~4 a- O9 h, H
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] . P$ d2 K. m; g& I2 ]4 `
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] ! s. W& @* {& r$ s. v: J- D
cookie=0x0, duration=2403.127s, table=10, n_packets=0, n_bytes=0, idle_age=2403, vlan_tci=0x0014/0x0fff,dl_dst=50:00:00:00:00:01 actions=load:0x1->NXM_NX_REG0[0..15]; A0 k' e) V1 e6 [( p+ r8 M

& l! F; h8 D; F  N首先来测试一个multicast和broadcast
: M5 [2 I+ x* O( Y% g9 J; q, e
  O. O+ n  |9 I: S. N# B4 Q+ B如果是一个port 1来的vlan 30的broadcast* M! e$ p7 T& o$ R% R
( }3 S1 x6 n$ x
$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_dst=ff:ff:ff:ff:ff:ff,dl_vlan=30
6 q* S! E- J8 s4 W$ G* F5 O6 [# Q+ S0 YFlow: 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 ) N/ B$ X+ p: i! y0 ^
Rule: table=0 cookie=0 priority=0 5 y! y6 ~/ M, |6 c
OpenFlow actions=resubmit(,1)
. X7 q$ |- O) R8 k' R" E  m. O. p
3 f( ~# @# w; u; G, S: W        Resubmitted flow: unchanged , N( O  H) L* F8 t
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 / A- B8 a; C- e* k& h
        Resubmitted  odp: drop
9 Y/ \! r% j/ e% n: N) A        Rule: table=1 cookie=0 priority=99,in_port=1
- Q, O: v  k3 h- \+ a        OpenFlow actions=resubmit(,2)
& x7 w8 f5 K9 a. ?: r6 Y2 p7 N; p5 B8 m2 D/ Y3 A/ ~
                Resubmitted flow: unchanged
1 H* {# X1 s; Y, `1 A                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 9 }: d9 t( D  h5 Q' s. i7 n" o8 ?' R
                Resubmitted  odp: drop
5 ]3 j) p- O# Z# ~7 I                Rule: table=2 cookie=0
( i" C8 H$ O% _# }                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)4 g& n5 ]0 M. B8 f
. Z* g8 h- W$ e, H! _5 d- A( j
                        Resubmitted flow: unchanged
) g/ i' b! _& w1 i7 U                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 : s4 y: H" ^; V
                        Resubmitted  odp: drop / h6 c" s1 u8 N' \! k) y
                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00
5 v) ?: ]" N& Z( l7 ^& l                        OpenFlow actions=resubmit(,4)* \4 V  |) I3 F' W+ O5 z

! k# C: B$ B+ _! d# t                                Resubmitted flow: unchanged ; e/ O% Z. `. o
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
0 V' A- _8 t& f0 t2 W/ m                                Resubmitted  odp: drop
$ L+ [" m8 Q% J' _3 d3 w- j. z  o                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
3 S6 {/ I  h, D                                OpenFlow actions=output:1,strip_vlan,output:3,output:4 ; x* Z! y5 e0 G, N0 z$ U$ y
                                skipping output to input port
, r, U* z. m2 ~2 B9 q  Z! v4 e9 X* v+ e$ p" \3 c
Final flow: metadata=0,in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:ff,dl_type=0x0000
9 D1 O( b& g7 A- Z0 j- ~& F! y2 jRelevant 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
' H5 ^' f, \' `$ W* R, DDatapath actions: pop_vlan,12,13
% m$ ?4 T3 o5 _  X1 h- v2 c! y
5 o0 K$ w* F$ ~+ o* h4 n结果是port 1就不发送了,发送给了port 3, 48 t/ S* \$ r' D6 O
" W/ H$ Q+ F9 r7 v
$ sudo ovs-appctl ofproto/trace helloworld in_port=3,dl_dst=ff:ff:ff:ff:ff:ff & ^6 p8 ~/ {& B& j$ c
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
6 _  f' O" _( H* _5 ~; O- x. ERule: table=0 cookie=0 priority=0 ; n( v6 N9 n( w9 e7 Q
OpenFlow actions=resubmit(,1)) S" w/ S6 ~9 w( Q. W0 u
0 X. c9 ^9 N5 z9 k  [
        Resubmitted flow: unchanged . d1 P( m5 j6 h* M8 I
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
. r3 q/ Q) p; R( @# k        Resubmitted  odp: drop
; B) |4 N- s+ d        Rule: table=1 cookie=0 priority=99,in_port=3,vlan_tci=0x0000
* K* G4 e- K, B7 \8 U$ t7 _        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)
& m' H7 [' X9 ^5 ^! w4 ^+ D
6 }$ f% W- F3 o$ g! Z" r, k4 X                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
' |& Z( ^& n% T9 i                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 3 H" d" k$ v/ P& ^
                Resubmitted  odp: drop 7 Q" k0 F. I+ q  \7 C, Z& ?- G
                Rule: table=2 cookie=0
4 P1 C* s/ e$ 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)  |: U9 z- L& _8 p

; i4 u1 J( o2 d' B                        Resubmitted flow: unchanged
0 W3 `0 S2 }" Y. E9 O7 q                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
0 i/ j, T/ x: U( l3 X; F# s                        Resubmitted  odp: drop
$ Z- r5 ]4 x; S$ Z7 P1 h, C                        Rule: table=3 cookie=0 priority=99,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00
1 G+ }1 f* }$ B& L                        OpenFlow actions=resubmit(,4)
  j; [* q* z% c2 \! ^1 H
$ C7 g" E/ G8 Y! O                                Resubmitted flow: unchanged
8 \' J5 M* q/ M  x% U7 U                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 : p* i( G4 b' d
                                Resubmitted  odp: drop 0 Q2 H: i5 r7 ]6 {0 H: c8 j% t
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30 ' z3 K% x" _5 ]. {2 ]
                                OpenFlow actions=output:1,strip_vlan,output:3,output:4 # \8 I; E( T7 j1 j. Q: s) C7 t
                                skipping output to input port
5 M1 l6 A; b! H1 h0 V! Z7 p" V3 n( f4 ?3 U
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 ' B: x+ V6 ~9 U1 Z4 x
Relevant fields: skb_priority=0,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=ff:ff:ff:ff:ff:f0/ff:ff:ff:ff:ff:f0,dl_type=0x0000,nw_frag=no
8 [4 J/ p2 a& EDatapath actions: push_vlan(vid=30,pcp=0),10,pop_vlan,13
) ?8 @: f; z" M2 p* |9 C1 z* m$ n' ~6 L) |# }5 k; \. S4 Z
接着我们测试mac learning
0 Q* |8 X" M. H4 N5 T
! r& O* j, n* {$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=30,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01 -generate   
$ T( g8 I' b( k7 oFlow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000
2 ]% {5 v8 v; o: @Rule: table=0 cookie=0 priority=0
/ [3 p2 g/ k7 U( W+ u$ T# [OpenFlow actions=resubmit(,1)
2 U; ^: @: q6 g$ p5 n6 t
, P4 M8 R: Z% L& p) t, g7 B        Resubmitted flow: unchanged , E9 A0 a2 R$ T3 x
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0   J" \3 ~" f& T4 ~
        Resubmitted  odp: drop
+ K9 T: [5 l- z4 v  y* S( H. N        Rule: table=1 cookie=0 priority=99,in_port=1 % x( H2 F3 Y  b) d8 J, R3 [" y5 Z
        OpenFlow actions=resubmit(,2)' {1 `' K+ m4 y7 s+ p$ D  U. o
/ S' }2 M; Z+ |2 s
                Resubmitted flow: unchanged
; Y7 l, m2 i( q3 X1 S' P& B                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
3 \5 \, \- Q2 s: U. ?+ p8 T                Resubmitted  odp: drop ) |- ?+ \7 v5 h* b) r4 M
                Rule: table=2 cookie=0 7 I) l3 j1 |+ X1 g9 I4 v) L
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3)* R0 x" C5 U. `' y" {

5 U0 ?" J1 z) y2 j6 q  q( h# F                        Resubmitted flow: unchanged
, D: S( ?, U  U2 l                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
) e/ k: f; d% j/ y3 @$ u9 b3 I# ?) x                        Resubmitted  odp: drop 7 e: |2 `0 h3 m/ \0 u7 |7 A' R
                        Rule: table=3 cookie=0 priority=50 ) c6 l& E. r4 h. N. Q- p
                        OpenFlow actions=resubmit(,10),resubmit(,4)
3 i: m, N. E/ @) k! X. v% _! ?9 a( d8 n: v5 H) w5 w7 S' E
                                Resubmitted flow: unchanged $ ^6 E2 @  O' U6 j* v0 j" t9 @2 b
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 : y# K" m7 b) U8 D- ]0 e" ~
                                Resubmitted  odp: drop 4 m  z  l; T# p/ d# ]6 `' c1 w, B4 A
                                No match
4 f- B5 B# z% d7 |0 ^' ?4 t) [. E
/ x, \' Q1 G& Y' w5 e                                Resubmitted flow: unchanged 8 X- b/ H0 Y0 ?
                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
% x8 ?3 Q5 i0 D& l7 \$ J/ ^                                Resubmitted  odp: drop 8 a7 l, Y3 i) O& [1 W
                                Rule: table=4 cookie=0 priority=99,reg0=0x0,dl_vlan=30
) v. F3 a7 V$ b                                OpenFlow actions=output:1,strip_vlan,output:3,output:4
# W: [; n) t4 \2 D                                skipping output to input port
, V% z+ U9 T) Y7 {9 ?7 G
! j1 p. ^+ K/ K! l0 R, P4 S# nFinal 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 : I! d% v  |, u! Z6 r- K& 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 ; N+ {: A! ~5 o( g
Datapath actions: pop_vlan,12,139 F6 W7 p# j; ]1 Q/ d# R

( `4 v# t0 O$ J  b5 O6 c) C+ ~由于这两个地址没有出现过,则除了进行学习以外,广播发送给port 3,43 U( v; m0 l+ k. M# x: @% ^. B

# p$ w% {! `1 u( M9 B. c: `; H: R$ sudo ovs-appctl ofproto/trace helloworld in_port=4,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01 -generate   9 D; c6 n2 ]) V6 Z9 N
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 - j! a  X) G$ b+ ~3 i) f9 L
Rule: table=0 cookie=0 priority=0
8 x# O% Q1 I# W( `$ A& m, NOpenFlow actions=resubmit(,1)3 h+ b% F+ ~$ M& Y
% y% x3 O, n+ A* \; N: g. ]
        Resubmitted flow: unchanged
# n7 ?. ~3 m2 |$ i+ H        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ! F% e! @, F, M6 x8 p' H: e
        Resubmitted  odp: drop - e, S/ B- v+ \
        Rule: table=1 cookie=0 priority=99,in_port=4,vlan_tci=0x0000
. U; X* C% @* n3 `4 Q        OpenFlow actions=mod_vlan_vid:30,resubmit(,2)$ Q/ x" T# n5 u4 o. Z- l/ N. e

: {2 }) u. C  J8 x, r7 D7 B( Y                Resubmitted flow: metadata=0,in_port=4,dl_vlan=30,dl_vlan_pcp=0,dl_src=20:00:00:00:00:01,dl_dst=10:00:00:00:00:01,dl_type=0x0000
0 y) q8 D/ C8 l1 R9 _7 s                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
2 d8 X7 I% Y+ m2 A; o                Resubmitted  odp: drop $ O4 t8 L- s! C+ G
                Rule: table=2 cookie=0
4 \, q1 P- v8 v( 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)# ^" n" `. S* B& t' a# U

4 S) ^' `: U, W# h1 d8 j0 g                        Resubmitted flow: unchanged + F# [9 }4 G: i" ]7 l# f
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & |) I" C3 \3 `6 n8 y& n; [
                        Resubmitted  odp: drop
4 \# n9 W8 H' E; A* {* F% B' L, ^                        Rule: table=3 cookie=0 priority=50
6 K2 r3 `( k. D! h' s/ F4 v                        OpenFlow actions=resubmit(,10),resubmit(,4)7 I3 T# ^) D4 {& d5 J) ~
9 ^! \0 U% q7 K3 j9 H: R
                                Resubmitted flow: unchanged
4 ~: K1 T% ?9 F8 D1 I                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
' U9 [8 Z1 q3 y# c9 B" G) L5 J                                Resubmitted  odp: drop / w5 n" X4 V! g1 C9 P' ]& V( @
                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=10:00:00:00:00:01
) \7 Q3 d- N1 S3 n/ f# ~3 C                                OpenFlow actions=load:0x1->NXM_NX_REG0[0..15]5 @- e0 N  O! Y, u6 N
) X6 ?$ F' M$ y
                                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
5 d( m7 ~( H( q5 R9 `& ]. x3 f                                Resubmitted regs: reg0=0x1 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 & ^) {7 T2 z; t) F4 P7 k
                                Resubmitted  odp: drop
# @+ V9 a' H8 d. L8 k                                Rule: table=4 cookie=0 reg0=0x1 " Y2 D7 h) V! X0 e4 K6 B
                                OpenFlow actions=output:1
/ f: v# s( @7 t' O: ]9 i# |& z' M( W# \5 N4 x
Final flow: unchanged $ ~7 B: n1 Z) ]
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 2 X# G- e& I, B4 v; @  c8 N" z
Datapath actions: push_vlan(vid=30,pcp=0),10
& b+ V  [7 x) n- c
; }' v/ Q5 O/ [; c# ]: b2 v! a回复的时候,由于学习过了,则仅仅从port 1发送出去。/ Q. t  [8 [9 ~4 w; S5 D: M

+ R5 F- e; e0 a$ sudo ovs-appctl ofproto/trace helloworld in_port=1,dl_vlan=30,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01 -generate 6 p8 X, o, ~& ^7 T0 g6 c4 ]
Flow: metadata=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000
6 F/ {, g2 x4 z; j& q, m" MRule: table=0 cookie=0 priority=0
2 I6 E6 Q6 y% o7 P6 b3 t- BOpenFlow actions=resubmit(,1): E. k/ @( f1 i2 u2 i' o
( K0 o# `8 d. ~
        Resubmitted flow: unchanged - ?4 x3 l9 E8 R. U( ?
        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
! I4 ~9 S+ V& Z        Resubmitted  odp: drop 0 U! j- f0 `4 m7 _! V
        Rule: table=1 cookie=0 priority=99,in_port=1
! t0 w/ H# a3 P7 P- l+ ]6 J        OpenFlow actions=resubmit(,2)# `9 l6 k  K3 _: C
- ?$ c$ S* k3 m8 a8 M3 H8 j
                Resubmitted flow: unchanged
# Q. O1 `! I  K* s                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
1 Z( O+ e" r- u; J$ x6 L                Resubmitted  odp: drop
( ~7 V$ v/ s2 o, j' L0 f; I                Rule: table=2 cookie=0 2 q# u) ~/ W" ]( W+ z( j
                OpenFlow actions=learn(table=10,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG0[0..15]),resubmit(,3): Z# |5 O: V' V* l; q! v2 O

5 {# c6 ]4 D  ]0 r$ B  W                        Resubmitted flow: unchanged - M; t. q7 {( ^! C) |0 k$ @( \
                        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
8 v1 w+ k  \) x3 V                        Resubmitted  odp: drop 8 R1 l: b+ h1 `( f; X9 V( i7 K
                        Rule: table=3 cookie=0 priority=50 5 S7 G8 f  ]3 b' f, d! C& A$ J
                        OpenFlow actions=resubmit(,10),resubmit(,4)" ?4 z& z4 m5 B; L- J* l

% }; H  X  U% K" y                                Resubmitted flow: unchanged
$ S& A) V5 c" l6 P( r! |# ~( G                                Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 ' B8 q6 x, k4 d2 J
                                Resubmitted  odp: drop
  Q1 D6 C) k7 P2 y& R$ @# j                                Rule: table=10 cookie=0 vlan_tci=0x001e/0x0fff,dl_dst=20:00:00:00:00:01
8 c6 V1 m" h, J9 k                                OpenFlow actions=load:0x4->NXM_NX_REG0[0..15]$ o* n3 o3 S& B' ?1 S/ D( X6 t6 C
+ z0 T8 k1 H/ \( m6 [: M$ B
                                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   b; j; i$ ]* L5 @
                                Resubmitted regs: reg0=0x4 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 / q3 l5 S3 _" g$ s3 q4 p! `5 W
                                Resubmitted  odp: drop % e7 w- w: L1 E: P
                                Rule: table=4 cookie=0 reg0=0x4
& t( G( g: D1 t4 X5 t                                OpenFlow actions=strip_vlan,output:4
6 k5 J" `4 E$ V& }* g5 ^& ]5 ^( C: b' a3 E
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 4 K( M- ^8 m& u- V( X
Relevant fields: skb_priority=0,in_port=1,dl_vlan=30,dl_vlan_pcp=0,dl_src=10:00:00:00:00:01,dl_dst=20:00:00:00:00:01,dl_type=0x0000,nw_frag=no
4 R2 l6 x& \: o1 Q! r  T. k  gDatapath actions: pop_vlan,13
- |9 d0 b) q6 {* `/ G# ]* e- ?+ R+ ~: @- E  l1 b+ `
由于在回复中进行了学习,因而发送的时候,仅仅发送port 4
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-12 02:28 , Processed in 0.021168 second(s), 21 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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