From 2899b098ee31ffe976b8a4c6769b78fdff62fe83 Mon Sep 17 00:00:00 2001 From: Pavel Chlupacek Date: Fri, 9 Sep 2016 14:56:03 +0200 Subject: [PATCH 1/2] Add posibility to define webrtc address indpenedently from external address for b2b appliactions --- bootstrap/src/main/config/mediaserver.xml | 5 +++++ .../configuration/XmlConfigurationLoader.java | 1 + .../bootstrap/ioc/provider/UdpManagerProvider.java | 1 + .../server/mgcp/connection/RtpConnectionImpl.java | 10 +++++----- .../server/mgcp/tx/cmd/NotificationRequestCmd.java | 2 +- .../core/configuration/NetworkConfiguration.java | 9 +++++++++ .../media/server/io/network/UdpManager.java | 10 ++++++++++ .../media/server/impl/rtp/sdp/SdpFactory.java | 13 ++++++------- .../server/impl/rtp/channels/MediaChannelTest.java | 8 ++++---- 9 files changed, 42 insertions(+), 17 deletions(-) diff --git a/bootstrap/src/main/config/mediaserver.xml b/bootstrap/src/main/config/mediaserver.xml index df643e3ff..826e666bc 100644 --- a/bootstrap/src/main/config/mediaserver.xml +++ b/bootstrap/src/main/config/mediaserver.xml @@ -11,14 +11,19 @@ MA 02110-1301 USA, or see the FSF site: http://www.fsf.org. --> + 127.0.0.1 + 127.0.0.1 + + 127.0.0.1 127.0.0.1 255.255.255.255 false +
127.0.0.1
2427 diff --git a/bootstrap/src/main/java/org/mobicents/media/server/bootstrap/configuration/XmlConfigurationLoader.java b/bootstrap/src/main/java/org/mobicents/media/server/bootstrap/configuration/XmlConfigurationLoader.java index d8a221e49..87d8ff918 100644 --- a/bootstrap/src/main/java/org/mobicents/media/server/bootstrap/configuration/XmlConfigurationLoader.java +++ b/bootstrap/src/main/java/org/mobicents/media/server/bootstrap/configuration/XmlConfigurationLoader.java @@ -88,6 +88,7 @@ public MediaServerConfiguration load(String filepath) { private static void configureNetwork(HierarchicalConfiguration src, NetworkConfiguration dst) { dst.setBindAddress(src.getString("bindAddress", NetworkConfiguration.BIND_ADDRESS)); dst.setExternalAddress(src.getString("externalAddress", NetworkConfiguration.EXTERNAL_ADDRESS)); + dst.setWebRTCAddress(src.getString("webRtcAddress", NetworkConfiguration.WEB_RTC_ADDRESS)); dst.setNetwork(src.getString("network", NetworkConfiguration.NETWORK)); dst.setSubnet(src.getString("subnet", NetworkConfiguration.SUBNET)); dst.setSbc(src.getBoolean("sbc", NetworkConfiguration.SBC)); diff --git a/bootstrap/src/main/java/org/mobicents/media/server/bootstrap/ioc/provider/UdpManagerProvider.java b/bootstrap/src/main/java/org/mobicents/media/server/bootstrap/ioc/provider/UdpManagerProvider.java index 7b2d9ee66..ba5d2a000 100644 --- a/bootstrap/src/main/java/org/mobicents/media/server/bootstrap/ioc/provider/UdpManagerProvider.java +++ b/bootstrap/src/main/java/org/mobicents/media/server/bootstrap/ioc/provider/UdpManagerProvider.java @@ -49,6 +49,7 @@ public UdpManager get() { udpManager.setBindAddress(config.getNetworkConfiguration().getBindAddress()); udpManager.setLocalBindAddress(config.getControllerConfiguration().getAddress()); udpManager.setExternalAddress(config.getNetworkConfiguration().getExternalAddress()); + udpManager.setWebRTCAddress(config.getNetworkConfiguration().getWebRTCAddress()); udpManager.setLocalNetwork(config.getNetworkConfiguration().getNetwork()); udpManager.setLocalSubnet(config.getNetworkConfiguration().getSubnet()); udpManager.setUseSbc(config.getNetworkConfiguration().isSbc()); diff --git a/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/connection/RtpConnectionImpl.java b/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/connection/RtpConnectionImpl.java index 800dae2d9..c5437fbd8 100644 --- a/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/connection/RtpConnectionImpl.java +++ b/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/connection/RtpConnectionImpl.java @@ -227,11 +227,12 @@ private void setOtherPartyInboundCall() throws IOException { setupAudioChannelInbound(remoteAudio); } + boolean isWebRtc = this.remoteSdp.containsIce(); + // Generate SDP answer String bindAddress = this.local ? this.channelsManager .getLocalBindAddress() : this.channelsManager.getBindAddress(); - String externalAddress = this.channelsManager.getUdpManager() - .getExternalAddress(); + String externalAddress = isWebRtc ? this.channelsManager.getUdpManager().getWebRTCAddress() : this.channelsManager.getUdpManager().getExternalAddress(); if (this.audioChannel.isOpen()) { this.localSdp = SdpFactory.buildSdp(false, bindAddress, externalAddress, this.audioChannel); @@ -420,9 +421,8 @@ public void generateOffer(boolean webrtc) throws IOException { } // generate SDP offer based on audio channel - String bindAddress = this.local ? this.channelsManager.getLocalBindAddress() : this.channelsManager - .getBindAddress(); - String externalAddress = this.channelsManager.getUdpManager().getExternalAddress(); + String bindAddress = this.local ? this.channelsManager.getLocalBindAddress() : this.channelsManager.getBindAddress(); + String externalAddress = webrtc ? this.channelsManager.getUdpManager().getWebRTCAddress() : this.channelsManager.getUdpManager().getExternalAddress(); this.localSdp = SdpFactory.buildSdp(true, bindAddress, externalAddress, this.audioChannel); this.remoteSdp = null; } diff --git a/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/tx/cmd/NotificationRequestCmd.java b/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/tx/cmd/NotificationRequestCmd.java index cc30f2686..3ea6390eb 100644 --- a/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/tx/cmd/NotificationRequestCmd.java +++ b/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/tx/cmd/NotificationRequestCmd.java @@ -155,7 +155,7 @@ public long perform() { } catch (UnknownPackageException e) { throw new MgcpCommandException(MgcpResponseCode.CAN_NOT_DETECT_EVENT, new Text(e.getMessage())); } catch (Exception e) { - e.printStackTrace(); + logger.error("Unexpected Exception while performing notification request CMD: " + request.toString(), e); throw new MgcpCommandException(MgcpResponseCode.TRANSIENT_ERROR, new Text(e.getMessage())); } diff --git a/core/src/main/java/org/mobicents/media/core/configuration/NetworkConfiguration.java b/core/src/main/java/org/mobicents/media/core/configuration/NetworkConfiguration.java index 2ae845d86..7addc4820 100644 --- a/core/src/main/java/org/mobicents/media/core/configuration/NetworkConfiguration.java +++ b/core/src/main/java/org/mobicents/media/core/configuration/NetworkConfiguration.java @@ -31,12 +31,14 @@ public class NetworkConfiguration { public static final String BIND_ADDRESS = "127.0.0.1"; public static final String EXTERNAL_ADDRESS = ""; + public static final String WEB_RTC_ADDRESS = ""; public static final String NETWORK = "127.0.0.1"; public static final String SUBNET = "255.255.255.255"; public static final boolean SBC = false; private String bindAddress; private String externalAddress; + private String webRTCAddress; private String network; private String subnet; private boolean sbc; @@ -98,4 +100,11 @@ public void setSbc(boolean sbc) { this.sbc = sbc; } + public String getWebRTCAddress() { + return webRTCAddress; + } + + public void setWebRTCAddress(String webRTCAddress) { + this.webRTCAddress = webRTCAddress; + } } diff --git a/io/network/src/main/java/org/mobicents/media/server/io/network/UdpManager.java b/io/network/src/main/java/org/mobicents/media/server/io/network/UdpManager.java index 171815b05..c10cccf6b 100644 --- a/io/network/src/main/java/org/mobicents/media/server/io/network/UdpManager.java +++ b/io/network/src/main/java/org/mobicents/media/server/io/network/UdpManager.java @@ -67,6 +67,7 @@ public class UdpManager { private String bindAddress; private String localBindAddress; private String externalAddress; + private String webRTCAddress; private byte[] localNetwork; private IPAddressType currNetworkType; @@ -156,6 +157,15 @@ public void setExternalAddress(String externalAddress) { this.externalAddress = externalAddress; } + /** gets and sets address used in WebRTC **/ + public String getWebRTCAddress() { + return webRTCAddress; + } + + public void setWebRTCAddress(String webRTCAddress) { + this.webRTCAddress = webRTCAddress; + } + /** * Modify rtp timeout. * diff --git a/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/sdp/SdpFactory.java b/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/sdp/SdpFactory.java index 3e04808aa..3b21626c2 100644 --- a/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/sdp/SdpFactory.java +++ b/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/sdp/SdpFactory.java @@ -78,7 +78,7 @@ public static SessionDescription buildSdp(boolean offer, String localAddress, St // Media Descriptions boolean ice = false; for (MediaChannel channel : channels) { - MediaDescriptionField md = buildMediaDescription(channel, offer); + MediaDescriptionField md = buildMediaDescription(channel, offer, originAddress); md.setSession(sd); sd.addMediaDescription(md); @@ -122,17 +122,16 @@ public static void rejectMediaField(SessionDescription answer, MediaDescriptionF * The channel to read information from * @return The SDP media description */ - public static MediaDescriptionField buildMediaDescription(MediaChannel channel, boolean offer) { + public static MediaDescriptionField buildMediaDescription(MediaChannel channel, boolean offer, String originAddress) { MediaDescriptionField md = new MediaDescriptionField(); md.setMedia(channel.getMediaType()); md.setPort(channel.getRtpPort()); MediaProfile profile = channel.isDtlsEnabled() ? MediaProfile.RTP_SAVPF : MediaProfile.RTP_AVP; md.setProtocol(profile.getProfile()); - final String externalAddress = channel.getExternalAddress() == null || channel.getExternalAddress().isEmpty() ? null : channel.getExternalAddress(); - md.setConnection(new ConnectionField("IN", "IP4", externalAddress != null ? externalAddress : channel.getRtpAddress())); + md.setConnection(new ConnectionField("IN", "IP4", originAddress)); md.setPtime(new PacketTimeAttribute(20)); - md.setRtcp(new RtcpAttribute(channel.getRtcpPort(), "IN", "IP4", externalAddress != null ? externalAddress : channel.getRtcpAddress())); + md.setRtcp(new RtcpAttribute(channel.getRtcpPort(), "IN", "IP4", originAddress)); if (channel.isRtcpMux()) { md.setRtcpMux(new RtcpMuxAttribute()); } @@ -143,12 +142,12 @@ public static MediaDescriptionField buildMediaDescription(MediaChannel channel, md.setIcePwd(new IcePwdAttribute(channel.getIcePwd())); // Fix connection address based on default (only) candidate - md.getConnection().setAddress(externalAddress != null ? externalAddress : channel.getRtpAddress()); + md.getConnection().setAddress(originAddress); md.setPort(channel.getRtpPort()); // Fix RTCP if rtcp-mux is used if(channel.isRtcpMux()) { - md.getRtcp().setAddress(externalAddress != null ? externalAddress : channel.getRtpAddress()); + md.getRtcp().setAddress(originAddress); md.getRtcp().setPort(channel.getRtpPort()); } diff --git a/io/rtp/src/test/java/org/mobicents/media/server/impl/rtp/channels/MediaChannelTest.java b/io/rtp/src/test/java/org/mobicents/media/server/impl/rtp/channels/MediaChannelTest.java index bb7a5d9ff..7902b8f57 100644 --- a/io/rtp/src/test/java/org/mobicents/media/server/impl/rtp/channels/MediaChannelTest.java +++ b/io/rtp/src/test/java/org/mobicents/media/server/impl/rtp/channels/MediaChannelTest.java @@ -104,7 +104,7 @@ public void testSipCallNonRtcpMux() throws IllegalStateException, IOException, I String localAddress = localChannel.rtpChannel.getLocalHost(); int localRtpPort = localChannel.rtpChannel.getLocalPort(); int localRtcpPort = localChannel.rtcpChannel.getLocalPort(); - MediaDescriptionField audioOffer = SdpFactory.buildMediaDescription(localChannel, true); + MediaDescriptionField audioOffer = SdpFactory.buildMediaDescription(localChannel, true, localAddress); // activate "remote" channel and bind it to local address // there will be two underlying channels for RTP and RTCP @@ -114,7 +114,7 @@ public void testSipCallNonRtcpMux() throws IllegalStateException, IOException, I String remoteAddress = remoteChannel.rtpChannel.getLocalHost(); int remoteRtpPort = remoteChannel.rtpChannel.getLocalPort(); int remoteRtcpPort = remoteChannel.rtcpChannel.getLocalPort(); - MediaDescriptionField audioAnswer = SdpFactory.buildMediaDescription(remoteChannel, false); + MediaDescriptionField audioAnswer = SdpFactory.buildMediaDescription(remoteChannel, false, localAddress); // ... remote peer receives SDP offer from local peer // negotiate codecs with local peer @@ -163,7 +163,7 @@ public void testSipCallWithRtcpMux() throws IllegalStateException, IOException, String localAddress = localChannel.rtpChannel.getLocalHost(); int localPort = localChannel.rtpChannel.getLocalPort(); - MediaDescriptionField audioOffer = SdpFactory.buildMediaDescription(localChannel, true); + MediaDescriptionField audioOffer = SdpFactory.buildMediaDescription(localChannel, true, localAddress); // activate "remote" channel and bind it to local address // there will be two underlying channels for RTP and RTCP @@ -172,7 +172,7 @@ public void testSipCallWithRtcpMux() throws IllegalStateException, IOException, String remoteAddress = remoteChannel.rtpChannel.getLocalHost(); int remotePort = remoteChannel.rtpChannel.getLocalPort(); - MediaDescriptionField audioAnswer = SdpFactory.buildMediaDescription(remoteChannel, false); + MediaDescriptionField audioAnswer = SdpFactory.buildMediaDescription(remoteChannel, false, localAddress); // ... remote peer receives SDP offer from local peer // negotiate codecs with local peer From e2ae1bb80ddcd5724f101b9250d7ea135cf4482e Mon Sep 17 00:00:00 2001 From: Pavel Chlupacek Date: Mon, 12 Sep 2016 08:01:53 +0200 Subject: [PATCH 2/2] Fixed WebRTC SDP SRFLX candidate to honor WebRTC address configuration --- .../media/server/impl/rtp/RtpChannel.java | 4 ++++ .../server/impl/rtp/channels/MediaChannel.java | 11 +++++++++++ .../media/server/impl/rtp/sdp/SdpFactory.java | 16 ++++++++-------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/RtpChannel.java b/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/RtpChannel.java index fb7ed5342..4227c34c0 100644 --- a/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/RtpChannel.java +++ b/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/RtpChannel.java @@ -407,6 +407,10 @@ public String getExternalAddress() { return this.udpManager.getExternalAddress(); } + public String getWebRTCAddress() { + return this.udpManager.getWebRTCAddress(); + } + public boolean hasExternalAddress() { return notEmpty(this.udpManager.getExternalAddress()); } diff --git a/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/channels/MediaChannel.java b/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/channels/MediaChannel.java index 6d291b11d..659db8e5d 100644 --- a/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/channels/MediaChannel.java +++ b/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/channels/MediaChannel.java @@ -181,6 +181,17 @@ public String getExternalAddress() { } return ""; } + + public String getWebRTCAddress() { + if (this.rtpChannel.isBound()) { + if (this.rtpChannel.getWebRTCAddress() != null && !this.rtpChannel.getWebRTCAddress().isEmpty()) { + return this.rtpChannel.getWebRTCAddress(); + } else { + return this.rtpChannel.getExternalAddress(); + } + } + return ""; + } /** * Gets the address the RTP channel is bound to. diff --git a/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/sdp/SdpFactory.java b/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/sdp/SdpFactory.java index 3b21626c2..83f3671f8 100644 --- a/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/sdp/SdpFactory.java +++ b/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/sdp/SdpFactory.java @@ -156,13 +156,13 @@ public static MediaDescriptionField buildMediaDescription(MediaChannel channel, if(!channel.isRtcpMux()) { md.addCandidate(processHostCandidate(channel, IceComponent.RTCP_ID)); } - - if(channel.getExternalAddress() != null && !channel.getExternalAddress().isEmpty()) { - // Add SRFLX candidate - md.addCandidate(processSrflxCandidate(channel, IceComponent.RTP_ID)); - if(!channel.isRtcpMux()) { - md.addCandidate(processSrflxCandidate(channel, IceComponent.RTCP_ID)); - } + + if(channel.getWebRTCAddress() != null && !channel.getWebRTCAddress().isEmpty()) { + // Add SRFLX candidate from WebRTC address + md.addCandidate(processSrflxCandidate(channel, IceComponent.RTP_ID)); + if(!channel.isRtcpMux()) { + md.addCandidate(processSrflxCandidate(channel, IceComponent.RTCP_ID)); + } } // List rtpCandidates = channel.getRtpCandidates(); @@ -299,7 +299,7 @@ private static CandidateAttribute processHostCandidate(MediaChannel candidate, s private static CandidateAttribute processSrflxCandidate(MediaChannel candidate, short componentId) { CandidateAttribute candidateSdp = processHostCandidate(candidate, componentId); candidateSdp.setCandidateType(CandidateAttribute.TYP_SRFLX); - candidateSdp.setAddress(candidate.getExternalAddress()); + candidateSdp.setAddress(candidate.getWebRTCAddress()); switch (componentId) { case IceComponent.RTP_ID: