Tristan Matthews | 0a329cc | 2013-07-17 13:20:14 -0400 | [diff] [blame] | 1 | # $Id: mod_call.py 2078 2008-06-27 21:12:12Z nanang $ |
| 2 | import time |
| 3 | import imp |
| 4 | import sys |
| 5 | import inc_const as const |
| 6 | from inc_cfg import * |
| 7 | |
| 8 | # Load configuration |
| 9 | cfg_file = imp.load_source("cfg_file", ARGS[1]) |
| 10 | |
| 11 | # Check media flow between ua1 and ua2 |
| 12 | def check_media(ua1, ua2): |
| 13 | ua1.send("#") |
| 14 | ua1.expect("#") |
| 15 | ua1.send("1122") |
| 16 | ua2.expect(const.RX_DTMF + "1") |
| 17 | ua2.expect(const.RX_DTMF + "1") |
| 18 | ua2.expect(const.RX_DTMF + "2") |
| 19 | ua2.expect(const.RX_DTMF + "2") |
| 20 | |
| 21 | |
| 22 | # Test body function |
| 23 | def test_func(t): |
| 24 | callee = t.process[0] |
| 25 | caller = t.process[1] |
| 26 | |
| 27 | # if have_reg then wait for couple of seconds for PUBLISH |
| 28 | # to complete (just in case pUBLISH is used) |
| 29 | if callee.inst_param.have_reg: |
| 30 | time.sleep(1) |
| 31 | if caller.inst_param.have_reg: |
| 32 | time.sleep(1) |
| 33 | |
| 34 | # Caller making call |
| 35 | caller.send("m") |
| 36 | caller.send(t.inst_params[0].uri) |
| 37 | caller.expect(const.STATE_CALLING) |
| 38 | |
| 39 | # Callee waits for call and answers with 180/Ringing |
| 40 | time.sleep(0.2) |
| 41 | callee.expect(const.EVENT_INCOMING_CALL) |
| 42 | callee.send("a") |
| 43 | callee.send("180") |
| 44 | callee.expect("SIP/2.0 180") |
| 45 | caller.expect("SIP/2.0 180") |
| 46 | |
| 47 | # Synchronize stdout |
| 48 | caller.sync_stdout() |
| 49 | callee.sync_stdout() |
| 50 | |
| 51 | # Callee answers with 200/OK |
| 52 | callee.send("a") |
| 53 | callee.send("200") |
| 54 | |
| 55 | # Wait until call is connected in both endpoints |
| 56 | time.sleep(0.2) |
| 57 | caller.expect(const.STATE_CONFIRMED) |
| 58 | callee.expect(const.STATE_CONFIRMED) |
| 59 | |
| 60 | # Synchronize stdout |
| 61 | caller.sync_stdout() |
| 62 | callee.sync_stdout() |
| 63 | time.sleep(0.1) |
| 64 | caller.sync_stdout() |
| 65 | callee.sync_stdout() |
| 66 | |
| 67 | # Test that media is okay |
| 68 | time.sleep(0.3) |
| 69 | check_media(caller, callee) |
| 70 | check_media(callee, caller) |
| 71 | |
| 72 | # Hold call by caller |
| 73 | caller.send("H") |
| 74 | caller.expect("INVITE sip:") |
| 75 | callee.expect("INVITE sip:") |
| 76 | caller.expect(const.MEDIA_HOLD) |
| 77 | callee.expect(const.MEDIA_HOLD) |
| 78 | |
| 79 | # Synchronize stdout |
| 80 | caller.sync_stdout() |
| 81 | callee.sync_stdout() |
| 82 | |
| 83 | # Release hold |
| 84 | time.sleep(0.5) |
| 85 | caller.send("v") |
| 86 | caller.expect("INVITE sip:") |
| 87 | callee.expect("INVITE sip:") |
| 88 | caller.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold") |
| 89 | callee.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold") |
| 90 | |
| 91 | # Synchronize stdout |
| 92 | caller.sync_stdout() |
| 93 | callee.sync_stdout() |
| 94 | |
| 95 | # Test that media is okay |
| 96 | check_media(caller, callee) |
| 97 | check_media(callee, caller) |
| 98 | |
| 99 | # Synchronize stdout |
| 100 | caller.sync_stdout() |
| 101 | callee.sync_stdout() |
| 102 | |
| 103 | # Hold call by callee |
| 104 | callee.send("H") |
| 105 | callee.expect("INVITE sip:") |
| 106 | caller.expect("INVITE sip:") |
| 107 | caller.expect(const.MEDIA_HOLD) |
| 108 | callee.expect(const.MEDIA_HOLD) |
| 109 | |
| 110 | # Synchronize stdout |
| 111 | caller.sync_stdout() |
| 112 | callee.sync_stdout() |
| 113 | |
| 114 | # Release hold |
| 115 | time.sleep(0.1) |
| 116 | callee.send("v") |
| 117 | callee.expect("INVITE sip:") |
| 118 | caller.expect("INVITE sip:") |
| 119 | callee.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold") |
| 120 | caller.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold") |
| 121 | |
| 122 | # Synchronize stdout |
| 123 | caller.sync_stdout() |
| 124 | callee.sync_stdout() |
| 125 | |
| 126 | # Test that media is okay |
| 127 | # Wait for some time for ICE negotiation |
| 128 | time.sleep(0.6) |
| 129 | check_media(caller, callee) |
| 130 | check_media(callee, caller) |
| 131 | |
| 132 | # Synchronize stdout |
| 133 | caller.sync_stdout() |
| 134 | callee.sync_stdout() |
| 135 | |
| 136 | # UPDATE (by caller) |
| 137 | caller.send("U") |
| 138 | #caller.sync_stdout() |
| 139 | callee.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE") |
| 140 | caller.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE") |
| 141 | |
| 142 | # Synchronize stdout |
| 143 | caller.sync_stdout() |
| 144 | callee.sync_stdout() |
| 145 | |
| 146 | # Test that media is okay |
| 147 | time.sleep(0.1) |
| 148 | check_media(caller, callee) |
| 149 | check_media(callee, caller) |
| 150 | |
| 151 | # UPDATE (by callee) |
| 152 | callee.send("U") |
| 153 | callee.expect("UPDATE sip:") |
| 154 | caller.expect("UPDATE sip:") |
| 155 | caller.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE") |
| 156 | callee.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE") |
| 157 | |
| 158 | # Synchronize stdout |
| 159 | caller.sync_stdout() |
| 160 | callee.sync_stdout() |
| 161 | |
| 162 | # Test that media is okay |
| 163 | time.sleep(0.1) |
| 164 | check_media(caller, callee) |
| 165 | check_media(callee, caller) |
| 166 | |
| 167 | # Synchronize stdout |
| 168 | caller.sync_stdout() |
| 169 | callee.sync_stdout() |
| 170 | |
| 171 | # Set codecs in both caller and callee so that there is |
| 172 | # no common codec between them. |
| 173 | # In caller we only enable PCMU, in callee we only enable PCMA |
| 174 | caller.send("Cp") |
| 175 | caller.expect("Enter codec") |
| 176 | caller.send("* 0") |
| 177 | caller.send("Cp") |
| 178 | caller.expect("Enter codec") |
| 179 | caller.send("pcmu 120") |
| 180 | |
| 181 | callee.send("Cp") |
| 182 | callee.expect("Enter codec") |
| 183 | callee.send("* 0") |
| 184 | callee.send("Cp") |
| 185 | callee.expect("Enter codec") |
| 186 | callee.send("pcma 120") |
| 187 | |
| 188 | # Test when UPDATE fails (by callee) |
| 189 | callee.send("U") |
| 190 | caller.expect("SIP/2.0 488") |
| 191 | callee.expect("SIP/2.0 488") |
| 192 | callee.sync_stdout() |
| 193 | caller.sync_stdout() |
| 194 | |
| 195 | # Test that media is still okay |
| 196 | time.sleep(0.1) |
| 197 | check_media(caller, callee) |
| 198 | check_media(callee, caller) |
| 199 | |
| 200 | # Test when UPDATE fails (by caller) |
| 201 | caller.send("U") |
| 202 | caller.expect("UPDATE sip:") |
| 203 | callee.expect("UPDATE sip:") |
| 204 | callee.expect("SIP/2.0 488") |
| 205 | caller.expect("SIP/2.0 488") |
| 206 | caller.sync_stdout() |
| 207 | callee.sync_stdout() |
| 208 | |
| 209 | # Test that media is still okay |
| 210 | time.sleep(0.1) |
| 211 | check_media(callee, caller) |
| 212 | check_media(caller, callee) |
| 213 | |
| 214 | # Hangup call |
| 215 | time.sleep(0.1) |
| 216 | caller.send("h") |
| 217 | |
| 218 | # Wait until calls are cleared in both endpoints |
| 219 | caller.expect(const.STATE_DISCONNECTED) |
| 220 | callee.expect(const.STATE_DISCONNECTED) |
| 221 | |
| 222 | |
| 223 | # Here where it all comes together |
| 224 | test = cfg_file.test_param |
| 225 | test.test_func = test_func |
| 226 | |