Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
bklang committed Oct 15, 2014
1 parent 1299023 commit 893865f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
Gemfile.lock
.ruby-gemset
tmp/
/examples/*.xml
/examples/*.pcap
/examples/*.log
14 changes: 14 additions & 0 deletions examples/navigate_ivr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source: 192.0.2.15
destination: 192.0.2.200
max_concurrent: 10
calls_per_second: 5
number_of_calls: 20
steps:
- invite
- wait_for_answer
- ack_answer
- sleep 3
- send_digits '3125551234'
- sleep 5
- send_digits '#'
- wait_for_hangup
11 changes: 11 additions & 0 deletions examples/simple_call.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
source: 192.0.2.15
destination: 192.0.2.200
max_concurrent: 10
calls_per_second: 5
number_of_calls: 20
steps:
- invite
- wait_for_answer
- ack_answer
- sleep 5
- hangup
13 changes: 10 additions & 3 deletions lib/sippy_cup/scenario.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def initialize(name, args = {}, &block)
@scenario_options = args.merge name: name
@filename = args[:filename] || name.downcase.gsub(/\W+/, '_')
@filename = File.expand_path @filename, Dir.pwd
@media = Media.new '127.0.0.255', 55555, '127.255.255.255', 5060
@media = nil
@message_variables = 0
# Reference variables don't generate warnings/errors if unused in the scenario
@reference_variables = Set.new
Expand Down Expand Up @@ -314,6 +314,7 @@ def send_answer(opts = {})
Server: #{USER_AGENT}
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Type: application/sdp
[routes]
Content-Length: [len]
v=0
Expand All @@ -324,12 +325,15 @@ def send_answer(opts = {})
m=audio [media_port] RTP/AVP 0
a=rtpmap:0 PCMU/8000
MSG
start_media
send msg, opts
end

#
# Helper method to answer an INVITE and expect the ACK
#
# @param [Hash] opts A set of options containing SIPp element attributes - will be passed to both the <send> and <recv> elements
#
def answer(opts = {})
send_answer opts
receive_ack opts
Expand Down Expand Up @@ -443,7 +447,7 @@ def ack_answer(opts = {})
def sleep(seconds)
milliseconds = (seconds.to_f * MSEC).to_i
pause milliseconds
@media << "silence:#{milliseconds}"
@media << "silence:#{milliseconds}" if @media
end

#
Expand All @@ -458,6 +462,7 @@ def sleep(seconds)
# send_digits '1234'
#
def send_digits(digits)
raise "Media not started" unless @media
delay = (0.250 * MSEC).to_i # FIXME: Need to pass this down to the media layer
digits.split('').each do |digit|
raise ArgumentError, "Invalid DTMF digit requested: #{digit}" unless VALID_DTMF.include? digit
Expand Down Expand Up @@ -648,7 +653,7 @@ def to_xml(options = {})
# scenario.compile! # Leaves files at test_scenario.xml and test_scenario.pcap
#
def compile!
unless @media.empty?
unless @media.nil?
print "Compiling media to #{@filename}.pcap..."
compile_media.to_file filename: "#{@filename}.pcap"
puts "done."
Expand Down Expand Up @@ -736,6 +741,7 @@ def parse_args(args)
end

def compile_media
raise "Media not started" unless @media
@media.compile!
end

Expand Down Expand Up @@ -776,6 +782,7 @@ def register_auth(domain, user, password, opts = {})
end

def start_media
@media = Media.new '127.0.0.255', 55555, '127.255.255.255', 44444
nop = doc.create_element('nop') { |nop|
nop << doc.create_element('action') { |action|
action << doc.create_element('exec')
Expand Down

0 comments on commit 893865f

Please sign in to comment.