Index: pjproject/trunk/pjmedia/include/pjmedia/transport_ice.h
===================================================================
--- pjproject/trunk/pjmedia/include/pjmedia/transport_ice.h	(revision 1435)
+++ pjproject/trunk/pjmedia/include/pjmedia/transport_ice.h	(revision 1436)
@@ -217,4 +217,20 @@
 
 
+/**
+ * Simulate packet lost in the specified direction (for testing purposes).
+ * When enabled, the transport will randomly drop packets to the specified
+ * direction.
+ *
+ * @param tp	    The ICE media transport.
+ * @param dir	    Media direction to which packets will be randomly dropped.
+ * @param pct_lost  Percent lost (0-100). Set to zero to disable packet
+ *		    lost simulation.
+ *
+ * @return	    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_ice_simulate_lost(pjmedia_transport *tp,
+					       pjmedia_dir dir,
+					       unsigned pct_lost);
+
 
 
Index: pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c	(revision 1435)
+++ pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c	(revision 1436)
@@ -21,4 +21,6 @@
 #include <pj/assert.h>
 #include <pj/log.h>
+#include <pj/rand.h>
+
 
 struct transport_ice
@@ -33,4 +35,7 @@
     pj_sockaddr_in	 remote_rtp;
     pj_sockaddr_in	 remote_rtcp;
+
+    unsigned		 tx_drop_pct;	/**< Percent of tx pkts to drop.    */
+    unsigned		 rx_drop_pct;	/**< Percent of rx pkts to drop.    */
 
     void	       (*rtp_cb)(void*,
@@ -651,4 +656,15 @@
 {
     struct transport_ice *tp_ice = (struct transport_ice*)tp;
+
+    /* Simulate packet lost on TX direction */
+    if (tp_ice->tx_drop_pct) {
+	if ((pj_rand() % 100) <= (int)tp_ice->tx_drop_pct) {
+	    PJ_LOG(5,(tp_ice->ice_st->obj_name, 
+		      "TX RTP packet dropped because of pkt lost "
+		      "simulation"));
+	    return PJ_SUCCESS;
+	}
+    }
+
     return pj_ice_strans_sendto(tp_ice->ice_st, 1, 
 			        pkt, size, &tp_ice->remote_rtp,
@@ -679,7 +695,19 @@
     struct transport_ice *tp_ice = (struct transport_ice*) ice_st->user_data;
 
-    if (comp_id==1 && tp_ice->rtp_cb)
+    if (comp_id==1 && tp_ice->rtp_cb) {
+
+	/* Simulate packet lost on RX direction */
+	if (tp_ice->rx_drop_pct) {
+	    if ((pj_rand() % 100) <= (int)tp_ice->rx_drop_pct) {
+		PJ_LOG(5,(ice_st->obj_name, 
+			  "RX RTP packet dropped because of pkt lost "
+			  "simulation"));
+		return;
+	    }
+	}
+
 	(*tp_ice->rtp_cb)(tp_ice->stream, pkt, size);
-    else if (comp_id==2 && tp_ice->rtcp_cb)
+
+    } else if (comp_id==2 && tp_ice->rtcp_cb)
 	(*tp_ice->rtcp_cb)(tp_ice->stream, pkt, size);
 
@@ -734,2 +762,20 @@
 
 
+/* Simulate lost */
+PJ_DEF(pj_status_t) pjmedia_ice_simulate_lost( pjmedia_transport *tp,
+					       pjmedia_dir dir,
+					       unsigned pct_lost)
+{
+    struct transport_ice *ice = (struct transport_ice*) tp;
+
+    PJ_ASSERT_RETURN(tp && pct_lost <= 100, PJ_EINVAL);
+
+    if (dir & PJMEDIA_DIR_ENCODING)
+	ice->tx_drop_pct = pct_lost;
+
+    if (dir & PJMEDIA_DIR_DECODING)
+	ice->rx_drop_pct = pct_lost;
+
+    return PJ_SUCCESS;
+}
+
Index: pjproject/trunk/pjmedia/src/pjmedia/transport_udp.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/transport_udp.c	(revision 1435)
+++ pjproject/trunk/pjmedia/src/pjmedia/transport_udp.c	(revision 1436)
@@ -700,14 +700,11 @@
     struct transport_udp *udp = (struct transport_udp*)tp;
 
-    PJ_ASSERT_RETURN(tp && 
-		     (dir==PJMEDIA_DIR_ENCODING||dir==PJMEDIA_DIR_DECODING) &&
-		     pct_lost <= 100, PJ_EINVAL);
-
-    if (dir == PJMEDIA_DIR_ENCODING)
+    PJ_ASSERT_RETURN(tp && pct_lost <= 100, PJ_EINVAL);
+
+    if (dir & PJMEDIA_DIR_ENCODING)
 	udp->tx_drop_pct = pct_lost;
-    else if (dir == PJMEDIA_DIR_DECODING)
+    
+    if (dir & PJMEDIA_DIR_DECODING)
 	udp->rx_drop_pct = pct_lost;
-    else
-	return PJ_EINVAL;
 
     return PJ_SUCCESS;
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 1435)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 1436)
@@ -612,4 +612,12 @@
 	    goto on_error;
 	}
+
+	pjmedia_ice_simulate_lost(pjsua_var.calls[i].med_tp,
+				  PJMEDIA_DIR_ENCODING,
+				  pjsua_var.media_cfg.tx_drop_pct);
+
+	pjmedia_ice_simulate_lost(pjsua_var.calls[i].med_tp,
+				  PJMEDIA_DIR_DECODING,
+				  pjsua_var.media_cfg.rx_drop_pct);
 
 	status = pjmedia_ice_start_init(pjsua_var.calls[i].med_tp, 0, &addr,
