| 1 |
import time |
| 2 |
import sys |
| 3 |
import inc_const as const |
| 4 |
import inc_util as util |
| 5 |
from inc_cfg import * |
| 6 |
|
| 7 |
|
| 8 |
cfg_file = util.load_module_from_file("cfg_file", ARGS[1]) |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
def hole_punch(ua1, ua2): |
| 19 |
if ua1.use_telnet: |
| 20 |
ua1.send("# 987") |
| 21 |
else: |
| 22 |
ua1.send("#") |
| 23 |
ua1.expect("#") |
| 24 |
ua1.send("987") |
| 25 |
|
| 26 |
if ua2.use_telnet: |
| 27 |
ua2.send("# 789") |
| 28 |
else: |
| 29 |
ua2.send("#") |
| 30 |
ua2.expect("#") |
| 31 |
ua2.send("789") |
| 32 |
|
| 33 |
time.sleep(0.1) |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
def check_media(ua1, ua2): |
| 38 |
if ua1.use_telnet: |
| 39 |
ua1.send("# 1122") |
| 40 |
else: |
| 41 |
ua1.send("#") |
| 42 |
ua1.expect("#") |
| 43 |
ua1.send("1122") |
| 44 |
ua2.expect(const.RX_DTMF + "1") |
| 45 |
ua2.expect(const.RX_DTMF + "1") |
| 46 |
ua2.expect(const.RX_DTMF + "2") |
| 47 |
ua2.expect(const.RX_DTMF + "2") |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
def test_func(t): |
| 52 |
callee = t.process[0] |
| 53 |
caller = t.process[1] |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
if callee.inst_param.have_reg: |
| 58 |
time.sleep(1) |
| 59 |
if caller.inst_param.have_reg: |
| 60 |
time.sleep(1) |
| 61 |
|
| 62 |
|
| 63 |
use_ice = ("--use-ice" in caller.inst_param.arg) and ("--use-ice" in callee.inst_param.arg) |
| 64 |
|
| 65 |
|
| 66 |
use_stun = ("--stun-srv" in caller.inst_param.arg) or ("--stun-srv" in callee.inst_param.arg) |
| 67 |
|
| 68 |
|
| 69 |
use_dtls_srtp = "--srtp-keying=1" in caller.inst_param.arg |
| 70 |
|
| 71 |
|
| 72 |
if caller.use_telnet: |
| 73 |
caller.send("call new " + t.inst_params[0].uri) |
| 74 |
else: |
| 75 |
caller.send("m") |
| 76 |
caller.send(t.inst_params[0].uri) |
| 77 |
caller.expect(const.STATE_CALLING) |
| 78 |
|
| 79 |
|
| 80 |
time.sleep(0.2) |
| 81 |
callee.expect(const.EVENT_INCOMING_CALL) |
| 82 |
if callee.use_telnet: |
| 83 |
callee.send("call answer 180") |
| 84 |
else: |
| 85 |
callee.send("a") |
| 86 |
callee.send("180") |
| 87 |
callee.expect("SIP/2.0 180") |
| 88 |
caller.expect("SIP/2.0 180") |
| 89 |
|
| 90 |
|
| 91 |
caller.sync_stdout() |
| 92 |
callee.sync_stdout() |
| 93 |
|
| 94 |
|
| 95 |
if callee.use_telnet: |
| 96 |
callee.send("call answer 200") |
| 97 |
else: |
| 98 |
callee.send("a") |
| 99 |
callee.send("200") |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
caller.expect(const.STATE_CONFIRMED) |
| 104 |
callee.expect(const.STATE_CONFIRMED) |
| 105 |
|
| 106 |
|
| 107 |
caller.sync_stdout() |
| 108 |
callee.sync_stdout() |
| 109 |
|
| 110 |
caller.sync_stdout() |
| 111 |
callee.sync_stdout() |
| 112 |
|
| 113 |
|
| 114 |
if use_ice: |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
time.sleep(0.5) |
| 120 |
|
| 121 |
|
| 122 |
if use_dtls_srtp: |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
time.sleep(0.5) |
| 127 |
|
| 128 |
|
| 129 |
if use_stun and not use_ice: |
| 130 |
hole_punch(caller, callee) |
| 131 |
|
| 132 |
|
| 133 |
check_media(caller, callee) |
| 134 |
check_media(callee, caller) |
| 135 |
|
| 136 |
|
| 137 |
if caller.use_telnet: |
| 138 |
caller.send("call hold") |
| 139 |
else: |
| 140 |
caller.send("H") |
| 141 |
caller.expect("INVITE sip:") |
| 142 |
callee.expect("INVITE sip:") |
| 143 |
callee.expect(const.MEDIA_HOLD) |
| 144 |
caller.expect(const.MEDIA_HOLD) |
| 145 |
|
| 146 |
|
| 147 |
caller.sync_stdout() |
| 148 |
callee.sync_stdout() |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
if caller.use_telnet: |
| 153 |
caller.send("call reinvite") |
| 154 |
else: |
| 155 |
caller.send("v") |
| 156 |
caller.expect("INVITE sip:") |
| 157 |
callee.expect("INVITE sip:") |
| 158 |
callee.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold") |
| 159 |
caller.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold") |
| 160 |
|
| 161 |
|
| 162 |
caller.sync_stdout() |
| 163 |
callee.sync_stdout() |
| 164 |
|
| 165 |
|
| 166 |
if use_stun and not use_ice: |
| 167 |
hole_punch(caller, callee) |
| 168 |
|
| 169 |
|
| 170 |
check_media(caller, callee) |
| 171 |
check_media(callee, caller) |
| 172 |
|
| 173 |
|
| 174 |
caller.sync_stdout() |
| 175 |
callee.sync_stdout() |
| 176 |
|
| 177 |
|
| 178 |
if callee.use_telnet: |
| 179 |
callee.send("call hold") |
| 180 |
else: |
| 181 |
callee.send("H") |
| 182 |
callee.expect("INVITE sip:") |
| 183 |
caller.expect("INVITE sip:") |
| 184 |
caller.expect(const.MEDIA_HOLD) |
| 185 |
callee.expect(const.MEDIA_HOLD) |
| 186 |
|
| 187 |
|
| 188 |
caller.sync_stdout() |
| 189 |
callee.sync_stdout() |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
if callee.use_telnet: |
| 194 |
callee.send("call reinvite") |
| 195 |
else: |
| 196 |
callee.send("v") |
| 197 |
callee.expect("INVITE sip:") |
| 198 |
caller.expect("INVITE sip:") |
| 199 |
caller.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold") |
| 200 |
callee.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold") |
| 201 |
|
| 202 |
|
| 203 |
caller.sync_stdout() |
| 204 |
callee.sync_stdout() |
| 205 |
|
| 206 |
|
| 207 |
if use_stun and not use_ice: |
| 208 |
hole_punch(caller, callee) |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
check_media(caller, callee) |
| 214 |
check_media(callee, caller) |
| 215 |
|
| 216 |
|
| 217 |
caller.sync_stdout() |
| 218 |
callee.sync_stdout() |
| 219 |
|
| 220 |
|
| 221 |
if caller.use_telnet: |
| 222 |
caller.send("call update") |
| 223 |
else: |
| 224 |
caller.send("U") |
| 225 |
|
| 226 |
callee.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE") |
| 227 |
caller.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE") |
| 228 |
|
| 229 |
|
| 230 |
caller.sync_stdout() |
| 231 |
callee.sync_stdout() |
| 232 |
|
| 233 |
|
| 234 |
if use_stun and not use_ice: |
| 235 |
hole_punch(caller, callee) |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
check_media(caller, callee) |
| 240 |
check_media(callee, caller) |
| 241 |
|
| 242 |
|
| 243 |
if callee.use_telnet: |
| 244 |
callee.send("call update") |
| 245 |
else: |
| 246 |
callee.send("U") |
| 247 |
callee.expect("UPDATE sip:") |
| 248 |
caller.expect("UPDATE sip:") |
| 249 |
caller.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE") |
| 250 |
callee.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE") |
| 251 |
|
| 252 |
|
| 253 |
caller.sync_stdout() |
| 254 |
callee.sync_stdout() |
| 255 |
|
| 256 |
|
| 257 |
if use_stun and not use_ice: |
| 258 |
hole_punch(caller, callee) |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
check_media(caller, callee) |
| 263 |
check_media(callee, caller) |
| 264 |
|
| 265 |
|
| 266 |
caller.sync_stdout() |
| 267 |
callee.sync_stdout() |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
if caller.use_telnet: |
| 273 |
caller.send("Cp * 0") |
| 274 |
caller.send("Cp") |
| 275 |
caller.expect("PCMU/8000.* prio: 0") |
| 276 |
caller.send("Cp PCMU 120") |
| 277 |
caller.send("Cp") |
| 278 |
caller.expect("PCMU/8000.* prio: 120") |
| 279 |
else: |
| 280 |
caller.send("Cp") |
| 281 |
caller.expect("Enter codec") |
| 282 |
caller.send("* 0") |
| 283 |
caller.send("Cp") |
| 284 |
caller.expect("Enter codec") |
| 285 |
caller.send("pcmu 120") |
| 286 |
|
| 287 |
if callee.use_telnet: |
| 288 |
callee.send("Cp * 0") |
| 289 |
callee.send("Cp") |
| 290 |
callee.expect("PCMA/8000.* prio: 0") |
| 291 |
callee.send("Cp PCMA 120") |
| 292 |
callee.send("Cp") |
| 293 |
callee.expect("PCMA/8000.* prio: 120") |
| 294 |
else: |
| 295 |
callee.send("Cp") |
| 296 |
callee.expect("Enter codec") |
| 297 |
callee.send("* 0") |
| 298 |
callee.send("Cp") |
| 299 |
callee.expect("Enter codec") |
| 300 |
callee.send("pcma 120") |
| 301 |
|
| 302 |
|
| 303 |
if callee.use_telnet: |
| 304 |
callee.send("call update") |
| 305 |
else: |
| 306 |
callee.send("U") |
| 307 |
caller.expect("SIP/2.0 488") |
| 308 |
callee.expect("SIP/2.0 488") |
| 309 |
callee.sync_stdout() |
| 310 |
caller.sync_stdout() |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
check_media(caller, callee) |
| 315 |
check_media(callee, caller) |
| 316 |
|
| 317 |
|
| 318 |
if caller.use_telnet: |
| 319 |
caller.send("call update") |
| 320 |
else: |
| 321 |
caller.send("U") |
| 322 |
caller.expect("UPDATE sip:") |
| 323 |
callee.expect("UPDATE sip:") |
| 324 |
callee.expect("SIP/2.0 488") |
| 325 |
caller.expect("SIP/2.0 488") |
| 326 |
caller.sync_stdout() |
| 327 |
callee.sync_stdout() |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
check_media(callee, caller) |
| 332 |
check_media(caller, callee) |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
if caller.use_telnet: |
| 337 |
caller.send("call hangup") |
| 338 |
else: |
| 339 |
caller.send("h") |
| 340 |
|
| 341 |
|
| 342 |
caller.expect(const.STATE_DISCONNECTED) |
| 343 |
callee.expect(const.STATE_DISCONNECTED) |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
test = cfg_file.test_param |
| 348 |
test.test_func = test_func |
| 349 |
|