Skip to content

Commit

Permalink
Merge pull request #76 from mojolingo/sip-advertise-IP
Browse files Browse the repository at this point in the history
Permit supplying a SIP advertise address that is different from the bind IP
  • Loading branch information
benlangfeld committed Jan 23, 2015
2 parents d2d0ac9 + e3f0ae5 commit cf76327
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@ This is a backward incompatible change. If upgrading from Sippy Cup 0.4.0 please
You will also need to compile the latest [SIPp from Github](https://github.com/sipp/sipp) to make use of all the features.
* Feature: Add support for saving screen and error reports to specified files
* Feature: Add support for UAS actions (waiting for an incoming call)
* Feature: Permit supplying a SIP advertise address that is different from the bind IP for NAT traversal purposes
* Bugfix: Much improved support for sending a hangup from SIPp, rather than waiting for the far end to do it
* Bugfix: If scenario compilation fails on the CLI, explain why
* Change: Rework the `register` command so it works without any other expectations
Expand Down
3 changes: 3 additions & 0 deletions README.markdown
Expand Up @@ -239,6 +239,9 @@ Each parameter has an impact on the test, and may either be changed once the XML

<dt>calls_per_second_max</dt>
<dd>The maximum rate of calls-per-second. If unset, the CPS rate will remain at the level set by `calls_per_second`.</dd>

<dt>advertise_address</dt>
<dd>The IP address to advertise in SIP and SDP if different from the bind IP (defaults to the bind IP).</dd>
</dl>

### Additional SIPp Scenario Attributes
Expand Down
28 changes: 15 additions & 13 deletions lib/sippy_cup/scenario.rb
Expand Up @@ -81,6 +81,7 @@ def self.from_manifest(manifest, options = {})
# @option options [String] :source The source IP/hostname with which to invoke SIPp.
# @option options [String, Numeric] :source_port The source port to bind SIPp to (defaults to 8836).
# @option options [String] :destination The target system at which to direct traffic.
# @option options [String] :advertise_address The IP address to advertise in SIP and SDP if different from the bind IP (defaults to the bind IP).
# @option options [String] :from_user The SIP user from which traffic should appear.
# @option options [String] :to_user The SIP user to send requests to.
# @option options [Integer] :media_port The RTCP (media) port to bind to locally.
Expand Down Expand Up @@ -110,6 +111,7 @@ def initialize(name, args = {}, &block)
@reference_variables = Set.new
@media_nodes = []
@errors = []
@adv_ip = args[:advertise_address] || "[local_ip]"

instance_eval &block if block_given?
end
Expand Down Expand Up @@ -152,12 +154,12 @@ def invite(opts = {})
opts[:retrans] ||= 500
# FIXME: The DTMF mapping (101) is hard-coded. It would be better if we could
# get this from the DTMF payload generator
from_addr = "#{@from_user}@[local_ip]:[local_port]"
from_addr = "#{@from_user}@#{@adv_ip}:[local_port]"
to_addr = "[service]@[remote_ip]:[remote_port]"
msg = <<-MSG
INVITE sip:#{to_addr} SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
Via: SIP/2.0/[transport] #{@adv_ip}:[local_port];branch=[branch]
From: "#{@from_user}" <sip:#{from_addr}>;tag=[call_number]
To: <sip:#{to_addr}>
Call-ID: [call_id]
Expand All @@ -169,7 +171,7 @@ def invite(opts = {})
Content-Length: [len]
#{opts.has_key?(:headers) ? opts.delete(:headers).sub(/\n*\Z/, "\n") : ''}
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
o=user1 53655765 2353687637 IN IP[local_ip_type] #{@adv_ip}
s=-
c=IN IP[media_ip_type] [media_ip]
t=0 0
Expand Down Expand Up @@ -323,7 +325,7 @@ def send_answer(opts = {})
Content-Length: [len]
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
o=user1 53655765 2353687637 IN IP[local_ip_type] #{@adv_ip}
s=-
c=IN IP[media_ip_type] [media_ip]
t=0 0
Expand Down Expand Up @@ -444,8 +446,8 @@ def ack_answer(opts = {})
msg = <<-BODY
ACK [next_url] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: "#{@from_user}" <sip:#{@from_user}@[local_ip]:[local_port]>;tag=[call_number]
Via: SIP/2.0/[transport] #{@adv_ip}:[local_port];branch=[branch]
From: "#{@from_user}" <sip:#{@from_user}@#{@adv_ip}:[local_port]>;tag=[call_number]
To: <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID: [call_id]
CSeq: [cseq] ACK
Expand Down Expand Up @@ -495,8 +497,8 @@ def send_digits(digits)
info = <<-INFO
INFO [next_url] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: "#{@from_user}" <sip:#{@from_user}@[local_ip]:[local_port]>;tag=[call_number]
Via: SIP/2.0/[transport] #{@adv_ip}:[local_port];branch=[branch]
From: "#{@from_user}" <sip:#{@from_user}@#{@adv_ip}:[local_port]>;tag=[call_number]
To: <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID: [call_id]
CSeq: [cseq] INFO
Expand Down Expand Up @@ -559,7 +561,7 @@ def send_bye(opts = {})
msg = <<-MSG
BYE sip:[$call_addr] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
Via: SIP/2.0/[transport] #{@adv_ip}:[local_port];branch=[branch]
From: <sip:[$local_addr]>;tag=[call_number]
To: <sip:[$remote_addr]>;tag=[$remote_tag]
Contact: <sip:[$local_addr];transport=[transport]>
Expand Down Expand Up @@ -786,12 +788,12 @@ def register_message(domain, user)
<<-BODY
REGISTER sip:#{domain} SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
Via: SIP/2.0/[transport] #{@adv_ip}:[local_port];branch=[branch]
From: <sip:#{user}@#{domain}>;tag=[call_number]
To: <sip:#{user}@#{domain}>
Call-ID: [call_id]
CSeq: [cseq] REGISTER
Contact: <sip:#{@from_user}@[local_ip]:[local_port];transport=[transport]>
Contact: <sip:#{@from_user}@#{@adv_ip}:[local_port];transport=[transport]>
Max-Forwards: 10
Expires: 120
User-Agent: #{USER_AGENT}
Expand All @@ -803,12 +805,12 @@ def register_auth(domain, user, password)
<<-AUTH
REGISTER sip:#{domain} SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
Via: SIP/2.0/[transport] #{@adv_ip}:[local_port];branch=[branch]
From: <sip:#{user}@#{domain}>;tag=[call_number]
To: <sip:#{user}@#{domain}>
Call-ID: [call_id]
CSeq: [cseq] REGISTER
Contact: <sip:#{@from_user}@[local_ip]:[local_port];transport=[transport]>
Contact: <sip:#{@from_user}@#{@adv_ip}:[local_port];transport=[transport]>
Max-Forwards: 20
Expires: 3600
[authentication username=#{user} password=#{password}]
Expand Down

0 comments on commit cf76327

Please sign in to comment.