Implement packet logging for ice4j.

cusax-fix
Damian Minkov 15 years ago
parent 46c0e51695
commit 00f6287db1

Binary file not shown.

@ -1100,6 +1100,7 @@ impl.packetlogging.PACKET_LOGGING_CONFIG=Packet Logging
impl.packetlogging.ENABLE_DISABLE=Enable packet logging
impl.packetlogging.PACKET_LOGGING_RTP=RTP
impl.packetlogging.PACKET_LOGGING_RTP_DESCRIPTION=(stores 1 packet out of every 5000)
impl.packetlogging.PACKET_LOGGING_ICE4J=Ice4J
impl.packetlogging.PACKET_LOGGING_DESCRIPTION=<html>Logs debug packets of various protocols in the <br>log folder using pcap format (tcpdump/wireshark).</html>
impl.packetlogging.PACKET_LOGGING_FILE_COUNT=Number of log files
impl.packetlogging.PACKET_LOGGING_FILE_SIZE=Maximum file size (in KB)

@ -0,0 +1,56 @@
package net.java.sip.communicator.impl.netaddr;
import net.java.sip.communicator.service.packetlogging.*;
import org.ice4j.stack.*;
/**
* Logs Packets coming and going through ice4j stack.
* @author Damian Minkov
*/
public class Ice4jPacketLogger
implements PacketLogger
{
/**
* Logs a incoming or outgoing packet.
*
* @param sourceAddress the source address of the packet.
* @param sourcePort the source port.
* @param destinationAddress the destination address of the packet.
* @param destinationPort the destination port.
* @param packetContent the content of the packet.
* @param sender whether we are sending or not the packet.
*/
public void logPacket(byte[] sourceAddress,
int sourcePort,
byte[] destinationAddress,
int destinationPort,
byte[] packetContent,
boolean sender)
{
if(isEnabled())
{
NetaddrActivator.getPacketLogging()
.logPacket(
PacketLoggingService.ProtocolName.ICE4J,
sourceAddress,
sourcePort,
destinationAddress,
destinationPort,
PacketLoggingService.TransportName.UDP,
sender,
packetContent
);
}
}
/**
* Checks whether the logger is enabled.
* @return <tt>true</tt> if the logger is enabled, <tt>false</tt>
* otherwise.
*/
public boolean isEnabled()
{
return NetaddrActivator.getPacketLogging()
.isLoggingEnabled(PacketLoggingService.ProtocolName.ICE4J);
}
}

@ -6,6 +6,7 @@
*/
package net.java.sip.communicator.impl.netaddr;
import net.java.sip.communicator.service.packetlogging.*;
import org.osgi.framework.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.netaddr.*;
@ -28,6 +29,12 @@ public class NetaddrActivator
private NetworkAddressManagerServiceImpl networkAMS = null;
private static ConfigurationService configurationService = null;
/**
* The OSGi <tt>PacketLoggingService</tt> in
* {@link #bundleContext} and used for debugging.
*/
private static PacketLoggingService packetLoggingService = null;
/**
* Creates a NetworkAddressManager, starts it, and registers it as a
* NetworkAddressManagerService.
@ -91,6 +98,29 @@ public static ConfigurationService getConfigurationService()
return configurationService;
}
/**
* Returns a reference to the <tt>PacketLoggingService</tt> implementation
* currently registered in the bundle context or null if no such
* implementation was found.
*
* @return a reference to a <tt>PacketLoggingService</tt> implementation
* currently registered in the bundle context or null if no such
* implementation was found.
*/
public static PacketLoggingService getPacketLogging()
{
if (packetLoggingService == null)
{
ServiceReference plReference
= bundleContext.getServiceReference(
PacketLoggingService.class.getName());
packetLoggingService
= (PacketLoggingService)bundleContext.getService(plReference);
}
return packetLoggingService;
}
/**
* Stops the Network Address Manager bundle
*

@ -23,6 +23,7 @@
import org.ice4j.ice.*;
import org.ice4j.ice.harvest.*;
import org.ice4j.security.*;
import org.ice4j.stack.*;
/**
* This implementation of the Network Address Manager allows you to
@ -90,6 +91,9 @@ public class NetworkAddressManagerServiceImpl
public void start()
{
this.localHostFinderSocket = initRandomPortSocket();
// set packet logging to ice4j stack
StunStack.setPacketLogger(new Ice4jPacketLogger());
}
/**
@ -569,7 +573,9 @@ public void removeNetworkConfigurationChangeListener(
*/
public Agent createIceAgent()
{
return new Agent();
Agent a = new Agent();
// a.getStunStack().
return a;
}
/**

@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org
Bundle-Version: 0.0.1
System-Bundle: yes
Import-Package: net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.packetlogging,
net.java.sip.communicator.util,
org.osgi.framework,
javax.crypto,

@ -89,6 +89,13 @@ public class PacketLoggingActivator
private final static String PACKET_LOGGING_RTP_ENABLED_PROPERTY_NAME
= "net.java.sip.communicator.packetlogging.PACKET_LOGGING_RTP_ENABLED";
/**
* Configuration property for packet logging for
* ICE4J enabled/disabled.
*/
private final static String PACKET_LOGGING_ICE4J_ENABLED_PROPERTY_NAME
= "net.java.sip.communicator.packetlogging.PACKET_LOGGING_ICE4J_ENABLED";
/**
* Configuration property for packet logging file count.
*/
@ -121,6 +128,11 @@ public class PacketLoggingActivator
*/
private static boolean rtpLoggingEnabled = false;
/**
* Is Packet Logging Service enabled for ice4j.
*/
private static boolean ice4jLoggingEnabled = false;
/**
* Creates a PacketLoggingServiceImpl, starts it, and registers it as a
* PacketLoggingService.
@ -195,6 +207,9 @@ private void loadConfig()
rtpLoggingEnabled = getConfigurationService().getBoolean(
PACKET_LOGGING_RTP_ENABLED_PROPERTY_NAME, false);
ice4jLoggingEnabled = getConfigurationService().getBoolean(
PACKET_LOGGING_ICE4J_ENABLED_PROPERTY_NAME, false);
}
/**
@ -296,6 +311,16 @@ public static boolean isRTPLoggingEnabled()
return rtpLoggingEnabled;
}
/**
* Checks whether packet logging is enabled in the configuration
* for Ice4J.
* @return <tt>true</tt> if packet logging is enabled for RTP.
*/
public static boolean isIce4JLoggingEnabled()
{
return ice4jLoggingEnabled;
}
/**
* Change whether packet logging is enabled and save it in configuration.
* @param enabled <tt>true</tt> if we enable it.
@ -316,6 +341,7 @@ static void setGlobalLoggingEnabled(boolean enabled)
sipLoggingEnabled = false;
jabberLoggingEnabled = false;
rtpLoggingEnabled = false;
ice4jLoggingEnabled = false;
}
globalLoggingEnabled = enabled;
@ -384,6 +410,27 @@ public static void setRTPLoggingEnabled(boolean enabled)
rtpLoggingEnabled = true;
}
/**
* Change whether packet logging for Ice4J is enabled
* and save it in configuration.
* @param enabled <tt>true</tt> if we enable it.
*/
public static void setIce4JLoggingEnabled(boolean enabled)
{
if(enabled)
{
getConfigurationService().setProperty(
PACKET_LOGGING_ICE4J_ENABLED_PROPERTY_NAME, Boolean.TRUE);
}
else
{
getConfigurationService().removeProperty(
PACKET_LOGGING_ICE4J_ENABLED_PROPERTY_NAME);
}
ice4jLoggingEnabled = true;
}
/**
* Our packet logging service instance.
*/

@ -42,6 +42,11 @@ public class PacketLoggingConfigForm
*/
private JCheckBox rtpProtocolCheckBox;
/**
* Check box to enable/disable packet debug of Ice4J.
*/
private JCheckBox ice4jProtocolCheckBox;
/**
* The file count label.
*/
@ -102,6 +107,10 @@ private void init()
rtpProtocolCheckBox.addActionListener(this);
rtpProtocolCheckBox.setToolTipText(rtpDescription);
ice4jProtocolCheckBox = new JCheckBox(
resources.getI18NString("impl.packetlogging.PACKET_LOGGING_ICE4J"));
ice4jProtocolCheckBox.addActionListener(this);
JPanel mainPanel = new TransparentPanel();
add(mainPanel, BorderLayout.NORTH);
@ -138,6 +147,7 @@ private void init()
loggersButtonPanel.add(sipProtocolCheckBox);
loggersButtonPanel.add(jabberProtocolCheckBox);
loggersButtonPanel.add(rtpProtocolCheckBox);
loggersButtonPanel.add(ice4jProtocolCheckBox);
c.insets = new Insets(0, 20, 10, 0);
c.gridy = 2;
@ -179,6 +189,8 @@ private void loadValues()
PacketLoggingActivator.isJabberLoggingEnabled());
rtpProtocolCheckBox.setSelected(
PacketLoggingActivator.isRTPLoggingEnabled());
ice4jProtocolCheckBox.setSelected(
PacketLoggingActivator.isIce4JLoggingEnabled());
fileCountField.setText(String.valueOf(PacketLoggingActivator
.getPacketLoggingService().getLogfileCount()));
fileSizeField.setText(String.valueOf(PacketLoggingActivator
@ -195,6 +207,7 @@ private void updateButtonsState()
sipProtocolCheckBox.setEnabled(enableCheckBox.isSelected());
jabberProtocolCheckBox.setEnabled(enableCheckBox.isSelected());
rtpProtocolCheckBox.setEnabled(enableCheckBox.isSelected());
ice4jProtocolCheckBox.setEnabled(enableCheckBox.isSelected());
fileCountField.setEnabled(enableCheckBox.isSelected());
fileSizeField.setEnabled(enableCheckBox.isSelected());
fileSizeLabel.setEnabled(enableCheckBox.isSelected());
@ -230,6 +243,11 @@ else if(source.equals(rtpProtocolCheckBox))
PacketLoggingActivator.setRTPLoggingEnabled(
rtpProtocolCheckBox.isSelected());
}
else if(source.equals(ice4jProtocolCheckBox))
{
PacketLoggingActivator.setIce4JLoggingEnabled(
ice4jProtocolCheckBox.isSelected());
}
}
/**

@ -311,6 +311,9 @@ public boolean isLoggingEnabled(ProtocolName protocol)
case RTP:
return PacketLoggingActivator.isGlobalLoggingEnabled()
&& PacketLoggingActivator.isRTPLoggingEnabled();
case ICE4J:
return PacketLoggingActivator.isGlobalLoggingEnabled()
&& PacketLoggingActivator.isIce4JLoggingEnabled();
default:
return false;
}

Loading…
Cancel
Save