netdev-dpdk: fix mbuf leaks
[cascardo/ovs.git] / tests / ovs-vswitchd.at
1 AT_BANNER([ovs-vswitchd])
2
3 dnl The OVS initscripts never make an empty database (one without even an
4 dnl Open_vSwitch record) visible to ovs-vswitchd, but hand-rolled scripts
5 dnl sometimes do.  At one point, "ovs-vswitchd --detach" would never detach
6 dnl and use 100% CPU if this happened, so this test checks for regression.
7 AT_SETUP([ovs-vswitchd detaches correctly with empty db])
8 on_exit 'kill `cat ovsdb-server.pid ovs-vswitchd.pid`'
9
10 dnl Create database.
11 touch .conf.db.~lock~
12 AT_CHECK([ovsdb-tool create conf.db $abs_top_srcdir/vswitchd/vswitch.ovsschema])
13
14 dnl Start ovsdb-server.  *Don't* initialize database.
15 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:$OVS_RUNDIR/db.sock], [0], [ignore], [ignore])
16 AT_CAPTURE_FILE([ovsdb-server.log])
17
18 dnl Start ovs-vswitchd.
19 AT_CHECK([ovs-vswitchd --detach --no-chdir --pidfile --enable-dummy --disable-system --log-file], [0], [], [stderr])
20 AT_CAPTURE_FILE([ovs-vswitchd.log])
21
22 dnl ovs-vswitchd detached OK or we wouldn't have made it this far.  Success.
23 AT_CLEANUP
24
25
26 dnl ----------------------------------------------------------------------
27 m4_define([OVS_VSCTL_CHECK_RX_PKT], [
28 AT_CHECK([ovs-vsctl list int $1 | grep statistics | sed -n 's/^.*\(rx_packets=[[0-9]][[0-9]]*\).*$/\1/p'],[0],
29 [dnl
30 rx_packets=$2
31 ])
32 ])
33
34 AT_SETUP([ovs-vswitchd -- stats-update-interval])
35 OVS_VSWITCHD_START([add-port br0 p1 -- set int p1 type=internal])
36 ovs-appctl time/stop
37
38 dnl at the beginning, the update of rx_packets should happen every 5 seconds.
39 ovs-appctl time/warp 11000 1000
40 OVS_VSCTL_CHECK_RX_PKT([p1], [0])
41 AT_CHECK([ovs-appctl netdev-dummy/receive p1 'eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x0800),ipv4(src=10.0.0.2,dst=10.0.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=8,code=0)'])
42 ovs-appctl time/warp 11000 1000
43 OVS_VSCTL_CHECK_RX_PKT([p1], [1])
44
45 dnl set the stats update interval to 100K ms, the following 'recv' should not be updated.
46 AT_CHECK([ovs-vsctl set O . other_config:stats-update-interval=100000])
47 ovs-appctl time/warp 51000 1000
48 for i in `seq 1 5`; do
49     AT_CHECK([ovs-appctl netdev-dummy/receive p1 'eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x0800),ipv4(src=10.0.0.2,dst=10.0.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=8,code=0)'])
50 done
51
52 OVS_VSCTL_CHECK_RX_PKT([p1], [1])
53 dnl advance the clock by 100K ms, the previous 'recv' should be updated.
54 ovs-appctl time/warp 100000 1000
55 OVS_VSCTL_CHECK_RX_PKT([p1], [6])
56
57 dnl now remove the configuration. 'recv' one packet.  there should be an update after 5000 ms.
58 AT_CHECK([ovs-vsctl clear O . other_config])
59 AT_CHECK([ovs-appctl netdev-dummy/receive p1 'eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x0800),ipv4(src=10.0.0.2,dst=10.0.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=8,code=0)'])
60 ovs-appctl time/warp 11000 1000
61 OVS_VSCTL_CHECK_RX_PKT([p1], [7])
62
63 OVS_VSWITCHD_STOP
64 AT_CLEANUP
65
66 dnl ----------------------------------------------------------------------
67 AT_SETUP([ovs-vswitchd -- start additional ovs-vswitchd process])
68 OVS_VSWITCHD_START
69
70 # start another ovs-vswitchd process.
71 ovs-vswitchd --log-file=fakelog --unixctl="`pwd`"/unixctl &
72
73 # sleep for a while
74 sleep 5
75
76 # stop the process.
77 ovs-appctl -t `pwd`/unixctl exit
78
79 # check the fakelog, should only see one ERR for reporting
80 # the existing ovs-vswitchd process.
81 AT_CHECK([test `grep ERR fakelog | wc -l` -eq 1])
82
83 AT_CHECK([tail -n1 fakelog | sed -e 's/^.*ERR|//; s/pid [[0-9]]*//'], [0], [dnl
84 another ovs-vswitchd process is running, disabling this process () until it goes away
85 ])
86
87 OVS_VSWITCHD_STOP
88 AT_CLEANUP
89
90 dnl ----------------------------------------------------------------------
91 AT_SETUP([ovs-vswitchd -- switch over to another ovs-vswitchd process])
92 OVS_VSWITCHD_START
93
94 # start a new ovs-vswitchd process.
95 ovs-vswitchd --log-file=fakelog --enable-dummy --unixctl="`pwd`"/unixctl &
96
97 # sleep for a while.
98 sleep 5
99
100 # kill the current active ovs-vswitchd process.
101 kill `cat ovs-vswitchd.pid`
102
103 sleep 5
104
105 # check the creation of br0 on the new ovs-vswitchd process.
106 AT_CHECK([grep "bridge br0" fakelog | sed -e 's/port [[0-9]]*$/port/;
107 s/datapath ID [[a-z0-9]]*$/datapath ID/;s/^.*INFO|//'], [0], [dnl
108 bridge br0: added interface br0 on port
109 bridge br0: using datapath ID
110 ])
111
112 # stop the process.
113 ovs-appctl -t `pwd`/unixctl exit
114
115 # check the fakelog, should not see WARN/ERR/EMER log other than the one
116 # for reporting the existing ovs-vswitchd process and the one for killing
117 # the process.
118 AT_CHECK([sed -n "
119 /|ERR|another ovs-vswitchd process is running/d
120 /|WARN|/p
121 /|ERR|/p
122 /|EMER|/p" fakelog
123 ])
124
125 # cleanup.
126 kill `cat ovsdb-server.pid`
127 AT_CLEANUP
128
129 dnl ----------------------------------------------------------------------
130 AT_SETUP([ovs-vswitchd -- invalid database path])
131
132 # start an ovs-vswitchd process with invalid db path.
133 ovs-vswitchd unix:invalid.db.sock --log-file=fakelog --enable-dummy --unixctl="`pwd`"/unixctl &
134
135 # sleep for a while.
136 sleep 10
137
138 # stop the process.
139 ovs-appctl -t `pwd`/unixctl exit
140
141 # should not see this log (which indicates high cpu utilization).
142 AT_CHECK([grep "wakeup due to" fakelog], [ignore])
143
144 # check the fakelog, should not see any WARN/ERR/EMER log.
145 AT_CHECK([sed -n "
146 /|WARN|/p
147 /|ERR|/p
148 /|EMER|/p" fakelog
149 ])
150
151 AT_CLEANUP
152
153 dnl ----------------------------------------------------------------------
154 AT_SETUP([ovs-vswitchd -- set service controller])
155 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
156 OVS_VSWITCHD_START
157
158 AT_CHECK([ovs-vsctl set-controller br0 punix:$(pwd)/br0.void])
159 OVS_WAIT_UNTIL([test -e br0.void])
160
161 AT_CHECK([ovs-vsctl set-controller br0 punix:$(pwd)/br0.void/../overwrite.file])
162 OVS_WAIT_UNTIL([test -n "`grep ERR ovs-vswitchd.log | grep overwrite.file`"])
163
164 OVS_VSWITCHD_STOP(["/Not adding Unix domain socket controller/d"])
165 AT_CLEANUP
166
167 dnl ----------------------------------------------------------------------
168 dnl OVSDB server before release version 2.5 does not support the monitor2
169 dnl method.  This test defeatures the OVSDB server to simulate an older
170 dnl OVSDB server and make sure ovs-vswitchd can still work with it
171 AT_SETUP([ovs-vswitchd -- Compatible with OVSDB server - w/o monitor2])
172 OVS_VSWITCHD_START
173
174 dnl defeature OVSDB server -- no monitor2
175 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/disable-monitor2])
176
177 sleep 1
178
179 AT_CHECK([ovs-vsctl add-port br0 p0  -- set interface p0 type=internal])
180 AT_CHECK([ovs-vsctl add-port br0 p1  -- set interface p1 type=internal])
181
182 dnl ovs-vswitchd should still 'see' ovsdb change with the 'monitor' method
183 AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
184                 br0 65534/100: (dummy)
185                 p0 1/1: (dummy)
186                 p1 2/2: (dummy)
187 ])
188 OVS_VSWITCHD_STOP
189 AT_CLEANUP
190
191 dnl ----------------------------------------------------------------------
192 AT_SETUP([ovs-vswitchd - do not create sockets with unsafe names])
193 OVS_VSWITCHD_START
194
195 # On Unix systems, test for sockets with "test -S".
196 #
197 # On Windows systems, we simulate a socket with a regular file that contains
198 # a TCP port number, so use "test -f" there instead.
199 if test $IS_WIN32 = yes; then
200    S=f
201 else
202    S=S
203 fi
204
205 # Create a bridge with an ordinary name and make sure that the management
206 # socket gets creatd.
207 AT_CHECK([ovs-vsctl add-br a -- set bridge a datapath-type=dummy])
208 AT_CHECK([test -$S a.mgmt])
209
210 # Create a bridge with an unsafe name and make sure that the management
211 # socket does not get created.
212 mkdir b
213 AT_CHECK([ovs-vsctl add-br b/c -- set bridge b/c datapath-type=dummy], [0],
214   [], [ovs-vsctl: Error detected while setting up 'b/c'.  See ovs-vswitchd log for details.
215 ])
216 AT_CHECK([test ! -e b/c.mgmt])
217
218 OVS_VSWITCHD_STOP(['/ignoring bridge with invalid name/d'])
219 AT_CLEANUP