Index: /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libkernelapi/addCommands.pm
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libkernelapi/addCommands.pm	(revision 37998)
+++ /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libkernelapi/addCommands.pm	(working copy)
@@ -3706,6 +3706,20 @@
             {type => "STRING"},
             ],
     },
+    {
+        cmd_attribute => "CMD_KERN_API",
+        function_name => "qos_session_config_kern",
+        function_args => [
+            {type => "STRING"},
+            {type => "INDATA"},
+            {type => "INDATA"},
+            {type => "U32"},
+            {type => "U16"},
+            {type => "U32"},
+            {type => "U16"},
+        ],
+    },
+
     # Bug 14949(QoS), end
 #WRITE cache_filter_kern add by zhangjz
     {
Index: /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libparser/commands.pm
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libparser/commands.pm	(revision 37998)
+++ /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libparser/commands.pm	(working copy)
@@ -53445,6 +53445,93 @@
                                                 ],
         },
 
+        {
+                obj_type => "ITEM",
+                name => "dynamic",
+                menu => "root_qos",
+                cmd_attribute => "CMD_ARRAYOS|CMD_SPROXY|CMD_NORMAL|CMD_GLOBAL",
+                user_level => "CLI_LEVEL_CONFIG",
+                help_string => "Configure QoS dynamic session",
+                function_name => "qos_session_config",
+                function_args => [
+                                                        {
+                                                                type => "STRING",
+                                                                help_string => "name",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "STRING",
+                                                                help_string => "Interface name (<system_ifname>|<vlan_ifname>|<bond_ifname>)",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "DOTTEDIP",
+                                                                help_string => "Source IP address (0.0.0.0 to match any)",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "U16",
+                                                                help_string => "Source port (0~65535) (0 to match any)",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "DOTTEDIP",
+                                                                help_string => "Destination IP address (0.0.0.0 to match any)",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "U16",
+                                                                help_string => "Destination port (0~65535) (0 to match any)",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "STRING",
+                                                                help_string => "Bandwidth per Session, suffixes may be b, Kb, Mb, and Gb",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "STRING",
+                                                                help_string => "Output/input direction (OUT/IN)",
+                                                                optional => "NO",
+                                                        },
+                                                ],
+        },
+
+        {
+                obj_type => "ITEM",
+                name => "dynamic",
+                menu => "root_show_qos",
+                cmd_attribute => "CMD_ARRAYOS|CMD_SPROXY|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
+                user_level => "CLI_LEVEL_ENABLE",
+                help_string => "Show configurations of QoS dynamic session",
+                function_name => "show_qos_session_config",
+                function_args => [
+                                                        {
+                                                                type => "STRING",
+                                                                help_string => "Session dynamic QoS, (optional, default is ALL)",
+                                                                optional => "YES",
+                                                                default_value => "\"ALL\"",
+                                                        },
+                                                ],
+        },
+        {
+                obj_type => "ITEM",
+                name => "dynamic",
+                menu => "root_no_qos",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
+                user_level => "CLI_LEVEL_CONFIG",
+                help_string => "Delete configuration of dynamic QoS session",
+                function_name => "delete_qos_session_config",
+                function_args => [
+                                                        {
+                                                                type => "STRING",
+                                                                help_string => "name",
+                                                                optional => "YES",
+                                                                default_value => "\"ALL\"",
+                                                        },
+                                                ],
+        },
+
 	{
 		obj_type => "ITEM",
 		name => "sub",
Index: /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libqos_cli/qos_cli.c
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libqos_cli/qos_cli.c	(revision 37998)
+++ /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libqos_cli/qos_cli.c	(working copy)
@@ -1306,3 +1306,95 @@
  * ------------------------ QoS Classifier functions ---------------------------
  */
 
+int qos_session_config (char *name, char *sIfName, uint32_t sip, uint16_t sport, uint32_t dip, uint16_t dport, char *sBand, char *sDir) {
+	qos_queue_root_t qQoSRoot;
+	struct altq_conf confALTQ;
+	int nIfMtu = 0;
+	int iErrCode = 0;
+	char *sDefault = NULL;
+	char *sBorrow = NULL;
+
+	QOS_CHECK_LICENSE;
+
+	bzero(&qQoSRoot, sizeof(qQoSRoot));
+	bzero(&confALTQ, sizeof(confALTQ));
+
+	bzero(qQoSRoot.sQName, QOS_QNAME_SIZE);
+
+	strncpy(qQoSRoot.sIfName, sIfName, QOS_CANAME_MAXLEN - 1);
+	if (sDir) {
+		strncpy(qQoSRoot.sDir, sDir, QOSD_STR_MAXLEN - 1);
+	} else {
+		strncpy(qQoSRoot.sDir, QOSD_IO_DEFAULT, QOSD_STR_MAXLEN - 1);
+	}
+	if (sBand) {
+		strncpy(qQoSRoot.sBand, sBand, QOS_BANDWIDTH_MAXLEN - 1);
+	} else {
+		strncpy(qQoSRoot.sBand, QOSD_BANDWIDTH_DEFAULT, QOS_BANDWIDTH_MAXLEN - 1);
+	}
+	qQoSRoot.iPri = 1;
+	if (sDefault) {
+		strncpy(qQoSRoot.sDefault, sDefault, QOS_DEFAULT_MAXLEN - 1);
+	} else {
+		strncpy(qQoSRoot.sDefault, QOS_DEFAULT_QUEUE_DEFAULT, QOS_DEFAULT_MAXLEN - 1);
+	}
+	if (sBorrow) {
+		strncpy(qQoSRoot.sBorrow, sBorrow, QOS_BORROW_MAXLEN - 1);
+	} else {
+		strncpy(qQoSRoot.sBorrow, QOS_BORROW_DEFAULT, QOS_BORROW_MAXLEN - 1);
+	}
+
+	strncpy(confALTQ.qname, qQoSRoot.sQName, QOS_QNAME_SIZE - 1);
+	strncpy(confALTQ.parent, "ROOT", QOS_QNAME_SIZE - 1);
+
+	if (getrealif(qQoSRoot.sIfName, confALTQ.ifname) != 0) {
+		printf("ERROR: can't find the QoS interface %s\n", qQoSRoot.sIfName);
+		return(-1);
+	}
+
+	if (qos_direction_str2num(qQoSRoot.sDir, &confALTQ.direction) == -1) {
+		return(-1);
+	}
+
+	if (qos_bandwidth_str2num(qQoSRoot.sBand, &confALTQ.bandwidth) == -1) {
+		return(-1);
+	}
+
+	if (qQoSRoot.iPri >= QOS_MAXPRIO || qQoSRoot.iPri < 0) {
+		printf("ERROR: priority out of range (0 ~ 7)\n");
+		return(-1);
+	} else {
+		confALTQ.priority = qQoSRoot.iPri;
+	}
+
+	if (qos_default_set(qQoSRoot.sDefault, &confALTQ) == -1) {
+		return(-1);
+	}
+
+	if (qos_borrow_set(qQoSRoot.sBorrow, &confALTQ) == -1) {
+		return(-1);
+	}
+
+	/* Fill altq_conf */
+	if (qos_get_ifmtu(confALTQ.ifname, &nIfMtu) == -1) {
+		return(-1);
+	}
+	confALTQ.scheduler = ALTQT_CBQ;
+
+	confALTQ.ifbandwidth = qos_get_ifbandwidth_kern(&confALTQ, sizeof(confALTQ));
+	if (confALTQ.ifbandwidth == 0) {
+		return(-1);
+	}
+
+	qos_evaluate(nIfMtu, &confALTQ);
+
+	/* Kernel config */
+	if ((iErrCode = qos_session_config_kern (name, &qQoSRoot, sizeof(qQoSRoot), &confALTQ, sizeof(confALTQ), sip, sport, dip, dport)) != QOS_SUCCESS)     {
+		if (iErrCode != QOS_USERLAND_FAILURE) {
+			printf("ERROR: %s\n", strerror(iErrCode));
+		}
+		return(-1);
+	}
+
+	return(0);
+}
Index: /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libuinet-atcp/lib/libuinet/Makefile
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libuinet-atcp/lib/libuinet/Makefile	(revision 37998)
+++ /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libuinet-atcp/lib/libuinet/Makefile	(working copy)
@@ -655,6 +655,7 @@
 	qos_http.c	\
 	qos_scheduler.c	\
 	qos_session.c	\
+	qos_dynamic.c	\
 	qos_subr.c
 	
 CLICK_APP_RADIUS_SRCS+=	\
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_cbq.h
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_cbq.h	(revision 37998)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_cbq.h	(working copy)
@@ -90,7 +90,7 @@
 
 #ifdef _KERNEL
 
-#define	CBQ_MAX_CLASSES	256
+#define	CBQ_MAX_CLASSES	100000
 
 /*
  * Define State structures.
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_classifier.h
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_classifier.h	(revision 37998)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_classifier.h	(working copy)
@@ -33,7 +33,10 @@
 /*
  * maximum filter number
  */
-#define QOS_MAX_FLTR_NUM 1024
+//#define QOS_MAX_FLTR_NUM 1024
+//
+#define QOS_MAX_FLTR_NUM 100000
+
 
 /*
  * static filter and dynamic filter
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_classifier.c
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_classifier.c	(revision 37998)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_classifier.c	(working copy)
@@ -55,8 +55,11 @@
 #include <click/app/qos/qos_session.h>
 
 #include <click/app/fastlog/fastlog.h>
+#include <click/app/qos/qos_dynamic.h>
 
+#define MAX_DYN_QUEUE 100000
 
+static void delete_queue_filter (unsigned int count);
 static int qos_filter_add_table(qos_filter_share_t *qs, qos_filter_t *pfltr);
 static int qos_filter_del_table(qos_filter_share_t *qs, qos_filter_t *pfltr);
 static int qos_filter_rebuild(struct ifnet *ifp, int dir);
@@ -65,6 +68,11 @@
 static int qos_filter_iftable_init(qos_filter_ifnode_t *ifn_p);
 static void qos_get_class(clickrule_gnode_t *gnode_p, struct qos_pktattr *pktattr, int flag);
 
+unsigned int current_dyn_q_count = 0;
+unsigned int enq_idx = 0;
+unsigned int deq_idx = 0;
+char q_dynamic_list[MAX_DYN_QUEUE][32];
+
 
 #define QOS_CLASSFIER_DEBUG_FOR_STATIC_POLICY 0
 
@@ -116,6 +124,8 @@
 static uint8_t  dyni_order[] = {0,5,6,7,8,1,2,3,4,11,12,9,10};
 static uint8_t  dyno_order[] = {0,5,6,7,8,1,2,3,4,9,10,11,12};
 
+static uint8_t  i_net_order[] = {1,12,13,14,15,4,5,6,7,8,9,10,11};
+static uint8_t  o_net_order[] = {1,14,15,12,13,4,5,6,7,8,9,10,11};
 /*
  * Storing up all qos filter information.
  */
@@ -188,6 +198,69 @@
 }
 
 
+void create_queue_filter(uint32_t sip, uint16_t sport, uint32_t dip, uint16_t dport,char *sDir, qos_queue_root_t *pQoSQRoot, struct altq_conf *pALTConf)
+{
+    char q_name[32] = "";
+    char f_name[32] = "";
+    char ip_str[20];
+    uint32_t smask = -1;
+    uint32_t dmask = -1;
+    
+
+    if (sip) {
+        sprintf (ip_str, "%u", sip);
+    } else {
+        sprintf (ip_str, "%u", dip);
+    }
+
+    sprintf (q_name, "qd_%s_%u_%u_%s", ip_str, sport, dport, sDir);
+
+    strcpy(f_name, q_name);
+    f_name[0] = 'f';
+    
+    
+    strcpy(pQoSQRoot->sQName, q_name);
+    strcpy(pALTConf->qname, q_name);
+
+    qos_queue_root_kern (NULL, pQoSQRoot, sizeof(qos_queue_root_t), pALTConf, sizeof(struct altq_conf));
+
+    if (!sip) {
+        smask = 0;
+    }
+    if (!dip) {
+        dmask = 0;
+    }
+        
+    qos_filter_kern(NULL, f_name, q_name, sip, smask, sport, dip, dmask, dport, "any", 1);
+
+    if (enq_idx == MAX_DYN_QUEUE)
+        enq_idx = 0;
+    sprintf (q_dynamic_list[enq_idx++], "%s", q_name);
+    ++current_dyn_q_count;
+
+/*
+If current Queue utilization is 100% then delete 30% of the queue(and corresponding filter)
+*/
+    if (current_dyn_q_count >= MAX_DYN_QUEUE) {
+        delete_queue_filter(0.3 * MAX_DYN_QUEUE);
+    }
+}
+
+void delete_queue_filter (unsigned int count) {
+    char q_name[32];
+    char f_name[32];
+
+    while(count--) {
+        if (deq_idx == MAX_DYN_QUEUE) 
+            deq_idx = 0;
+        strcpy (q_name, q_dynamic_list[deq_idx++]);
+        strcpy (f_name, q_name);
+        f_name[0] = 'f';
+        no_qos_filter_kern (NULL, f_name);
+        no_qos_queue_root_kern (NULL, q_name);
+        --current_dyn_q_count;
+    }
+}
 /******************************************************************************
  *  Get a proper class for the outbound or inbound packets
  *
@@ -212,6 +285,18 @@
 	struct ip *ip;
 	struct mbuf *m;
 
+	uint32_t src_ip_qos = 0;
+	uint16_t src_port_qos = 0;
+	uint32_t dst_ip_qos = 0;
+	uint16_t dst_port_qos = 0;
+
+	dyn_qos_session_lookup_t *temp = NULL;
+	int i, j;
+	char *sDir;
+	int src_ip_index;
+	int dst_ip_index;
+
+
 	m = *mp;
 	if(NULL == ifp || NULL == m || NULL == pktattr) {
 		englog(ENGLOG_QOS, QOS_ENGLOG_ERR, "qos_etherclassify: ifp, m or pktattr is NULL.\n");
@@ -298,19 +383,37 @@
 		return;
 	}
    
+	rtuple = (uint8_t *)a5tuple_p;
+
 	ifn_p = (qos_filter_ifnode_t *)
 		clickrule4_lookup(&qos_filter_share.iftable, (uint32_t)(uintptr_t)ifp);
 	/*
 	 * (NULL == ifn_p) means that the interface is not init(no filters).
 	 */
+
 	if (NULL == ifn_p) {
-		pktattr->pattr_class = NULL;
-		qos_filter_share.fltr_g_stats.hits_interface_fail++;
-		/*englog(ENGLOG_QOS, QOS_ENGLOG_DEBUG, "qos_etherclassify: No filters in the interface.\n");*/
-		return;
+		goto label;
 	}
 
-	rtuple = (uint8_t *)a5tuple_p;
+#if 0
+	if(QOSD_INPUT == direction) {
+		table = &(ifn_p->if_i_table);
+		rorder = (uint8_t *) table->rule_order;
+	    fastlog_syslog(LOG_DEBUG, "QOS input dirn.. protocol : %d...src port : %d %d\n", rtuple[rorder[0]], rtuple[rorder[1]],rtuple[rorder[2]]);
+	    fastlog_syslog(LOG_DEBUG, "QOS input dirn.. dst port : %d %d\n", rtuple[rorder[3]],rtuple[rorder[4]]);
+	    fastlog_syslog(LOG_DEBUG, "QOS inut src ip : %d %d %d %d\n", rtuple[rorder[5]], rtuple[rorder[6]],rtuple[rorder[7]],rtuple[rorder[8]]);
+	    fastlog_syslog(LOG_DEBUG, "QOS inut dst ip :  %d %d %d %d\n", rtuple[rorder[9]], rtuple[rorder[10]], rtuple[rorder[11]],rtuple[rorder[12]]);
+    }
+	if(QOSD_OUTPUT == direction) {
+		table = &(ifn_p->if_o_table);
+		rorder = (uint8_t *) table->rule_order;
+	    fastlog_syslog(LOG_DEBUG, "QOS out dirn.. protocol : %d...src port : %d %d\n", rtuple[rorder[0]], rtuple[rorder[1]],rtuple[rorder[2]]);
+	    fastlog_syslog(LOG_DEBUG, "QOS out dirn.. dst port : %d %d\n", rtuple[rorder[3]],rtuple[rorder[4]]);
+	    fastlog_syslog(LOG_DEBUG, "QOS out src ip : %d %d %d %d\n", rtuple[rorder[5]], rtuple[rorder[6]],rtuple[rorder[7]],rtuple[rorder[8]]);
+	    fastlog_syslog(LOG_DEBUG, "QOS out dst ip :  %d %d %d %d\n", rtuple[rorder[9]], rtuple[rorder[10]], rtuple[rorder[11]],rtuple[rorder[12]]);
+    }
+#endif
+
 	if(QOSD_OUTPUT == direction) {
 		table = &(ifn_p->if_dyno_table);
 		rorder = (uint8_t *) table->rule_order;
@@ -416,6 +519,62 @@
 		}
 	}
 
+
+label:
+	if(QOSD_OUTPUT == direction) {
+		rorder = (uint8_t *) o_net_order;
+        sDir = "OUT";
+        *((uint8_t *)&src_port_qos + 0) = rtuple[rorder[4]];
+        *((uint8_t *)&src_port_qos + 1) = rtuple[rorder[3]];
+
+        *((uint8_t *)&dst_port_qos + 0) = rtuple[rorder[2]];
+        *((uint8_t *)&dst_port_qos + 1) = rtuple[rorder[1]];
+    } else {
+		rorder = (uint8_t *) i_net_order;
+        sDir = "IN";
+        *((uint8_t *)&src_port_qos + 0) = rtuple[rorder[2]];
+        *((uint8_t *)&src_port_qos + 1) = rtuple[rorder[1]];
+
+        *((uint8_t *)&dst_port_qos + 0) = rtuple[rorder[4]];
+        *((uint8_t *)&dst_port_qos + 1) = rtuple[rorder[3]];
+    }
+
+    src_ip_index = 5;
+    dst_ip_index = 9;
+
+
+    for (i = 0; i < 4; i++) {
+        *((uint8_t *)&src_ip_qos + i) = rtuple[rorder[i+src_ip_index]];
+    }
+    for (i = 0; i < 4; i++) {
+        *((uint8_t *)&dst_ip_qos + i) = rtuple[rorder[i+dst_ip_index]];
+    }
+#if 0
+	fastlog_syslog(LOG_DEBUG, "TO CHECK ..src ip : %u, src_port : %u, dst_ip : %u, dst_port : %u, dir : %d\n",src_ip_qos, src_port_qos, dst_ip_qos, dst_port_qos, direction);
+#endif
+
+    temp = qos_session_lookup(src_ip_qos, src_port_qos, dst_ip_qos, dst_port_qos, direction);
+
+    if (temp && !strcmp(temp->qos_session_altq_conf_save->ifname, ifp->if_xname) 
+        && !strcmp(temp->qos_session_q_save->sDir, sDir))    {
+
+            if (!temp->is_sip_match) {
+                src_ip_qos = 0;
+            }
+            if (!src_ip_qos && !temp->is_sport_match) {
+                src_port_qos = 0;
+            }
+            if (!temp->is_dip_match) {
+                dst_ip_qos = 0;
+            }
+            if (!dst_ip_qos && !temp->is_dport_match) {
+                dst_port_qos = 0;
+            }
+
+            create_queue_filter(src_ip_qos, src_port_qos, dst_ip_qos, dst_port_qos, sDir, temp->qos_session_q_save,
+                 temp->qos_session_altq_conf_save);
+    }
+
 	pktattr->pattr_class = NULL;
 	qos_filter_share.fltr_g_stats.hits_filter_fail++;
 	qos_printf("qos_etherclassify: Not found the class.\n");
@@ -1296,7 +1455,9 @@
 		if (!strncmp(pfltr->fltr_name, FILTER_NAME_PREFIX_FOR_SESSION_BASED_QOS, strlen(FILTER_NAME_PREFIX_FOR_SESSION_BASED_QOS))) {
 			continue;
 		}
-
+		if (!strncmp(pfltr->fltr_name, "fd_", 3)) {
+			continue;
+		}
 		isfound = 1;
 
 		smask.s_addr = pfltr->tp.smask;
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.h
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.h	(revision 0)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.h	(working copy)
@@ -0,0 +1,41 @@
+#include <click/app/qos/qos_scheduler.h>
+
+#define N_CHILDREN 256
+
+typedef struct dyn_session_qos_conf {
+    char name[15];
+    char port[10];
+    uint32_t sip;
+    uint16_t sport;
+    uint32_t dip;
+    uint16_t dport; 
+    char band[10];
+    char dir[4];
+    STAILQ_ENTRY(dyn_session_qos_conf) list_entry;
+} dyn_session_qos_conf_t;
+
+STAILQ_HEAD(dyn_session_qos_conf_head, dyn_session_qos_conf);
+
+
+typedef struct dyn_qos_session_lookup {
+    struct dyn_qos_session_lookup *dyn_qos_session_lookup_node[N_CHILDREN];
+    char name[15];
+    qos_queue_root_t *qos_session_q_save;
+    struct altq_conf *qos_session_altq_conf_save;
+    int direction;
+    int is_sip_match;
+    int is_dip_match;
+    int is_sport_match;
+    int is_dport_match;
+    int is_leaf;
+} dyn_qos_session_lookup_t;
+
+
+dyn_qos_session_lookup_t *createNode(void);
+int qos_session_config_kern(void *pcb, char *name, void *pRoot, int32_t nRoot, void *pALTQ, int32_t nALTQ, uint32_t sip, uint16_t sport, uint32_t dip, uint16_t dport);
+void save_dyn_qos_session_config (char *name, char *port, uint32_t sip, uint16_t sport, uint32_t dip, uint16_t dport, char *band, char *dir);
+void *qos_session_lookup(uint32_t sip, uint16_t sport, uint32_t dip, uint16_t dport, uint8_t direction);
+void display_qos_session_config(void *pcb, dyn_session_qos_conf_t *node, uint64_t prefix);
+int show_qos_session_config(void *pcb, char *name);
+void remove_qos_session_config(dyn_qos_session_lookup_t *root);
+int delete_qos_session_config(void *pcb, char *name);
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.c
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.c	(revision 0)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.c	(working copy)
@@ -0,0 +1,287 @@
+#include <sys/types.h>
+#include <sys/ctype.h>
+#include <sys/param.h>
+#include <sys/lock.h>
+#include <sys/systm.h>
+#include <sys/sysctl.h>
+#include <sys/socket.h>
+#include <sys/mbuf.h>
+#include <sys/syslog.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/pcpu.h>
+#include <net/if.h>
+#include <net/if_var.h>
+#include <net/netisr.h>
+#include <net/ethernet.h>
+#include <net/route.h>
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+#include <netinet/in_var.h>
+#include <netinet/tcp.h>
+#include <netinet/tcpip.h>
+#include <machine/in_cksum.h>
+#include <click/app/qos/qos_dynamic.h>
+
+
+struct dyn_session_qos_conf_head dyn_session_qos_conf_head = STAILQ_HEAD_INITIALIZER(dyn_session_qos_conf_head);
+
+dyn_qos_session_lookup_t *dyn_qos_session_lookup_root = NULL;
+
+
+dyn_qos_session_lookup_t *createNode(void) {
+    int i;
+    dyn_qos_session_lookup_t *node = (dyn_qos_session_lookup_t *) malloc(sizeof(dyn_qos_session_lookup_t), M_QOS, M_NOWAIT | M_ZERO);
+    if (node) {
+        node->is_leaf = 0;
+        for (i = 0; i < N_CHILDREN; ++i) {
+            node->dyn_qos_session_lookup_node[i] = NULL;
+        }
+    }
+    node->qos_session_q_save = NULL;
+    node->qos_session_altq_conf_save = NULL;
+
+    return node;
+}
+
+
+int qos_session_config_kern(void *pcb, char *name, void *pRoot, int32_t nRoot, void *pALTQ, int32_t nALTQ, uint32_t sip, uint16_t sport, uint32_t dip, uint16_t dport) {
+
+    qos_queue_root_t *pQoSQRoot = NULL;
+    struct altq_conf *pALTQConf = NULL;
+
+    int iErrCode = 0;
+    int s = 0;
+    int i;
+    uint8_t direction = 0;
+    int octet;
+
+    QOS_CHECK_LICENSE;
+
+    if ((pRoot == NULL) || (sizeof(qos_queue_root_t) != nRoot) ||
+            (pALTQ == NULL) || (sizeof(struct altq_conf) != nALTQ)) {
+        return(QOS_USERLAND_FAILURE);
+    }
+
+    pQoSQRoot = (qos_queue_root_t *)pRoot;
+    pALTQConf = (struct altq_conf *)pALTQ;
+
+    direction = pALTQConf -> direction;
+
+    if (dyn_qos_session_lookup_root == NULL) 
+        dyn_qos_session_lookup_root = createNode();
+
+    dyn_qos_session_lookup_t *current = dyn_qos_session_lookup_root;
+
+    for (i = 3; i >= 0; --i) {
+        int octet = (sip >> (i * 8)) & 0xFF;
+
+        if (!current->dyn_qos_session_lookup_node[octet]) {
+            current->dyn_qos_session_lookup_node[octet] = createNode();
+        }
+        current = current->dyn_qos_session_lookup_node[octet];
+    }
+    for (i = 1; i >= 0; --i) {
+        int octet = (sport >> (i * 8)) & 0xFF;
+
+        if (!current->dyn_qos_session_lookup_node[octet]) {
+            current->dyn_qos_session_lookup_node[octet] = createNode();
+        }
+        current = current->dyn_qos_session_lookup_node[octet];
+    }
+    for (i = 3; i >= 0; --i) {
+        int octet = (dip >> (i * 8)) & 0xFF;
+
+        if (!current->dyn_qos_session_lookup_node[octet]) {
+            current->dyn_qos_session_lookup_node[octet] = createNode();
+        }
+        current = current->dyn_qos_session_lookup_node[octet];
+    }
+    for (i = 1; i >= 0; --i) {
+        int octet = (dport >> (i * 8)) & 0xFF;
+
+        if (!current->dyn_qos_session_lookup_node[octet]) {
+            current->dyn_qos_session_lookup_node[octet] = createNode();
+        }
+        current = current->dyn_qos_session_lookup_node[octet];
+    }
+
+    strcpy(current->name, name);
+    current->direction = direction;
+    current->is_leaf = 1;
+
+    current->qos_session_q_save = (qos_queue_root_t *) malloc(sizeof(qos_queue_root_t), M_QOS, M_NOWAIT | M_ZERO);
+    memcpy(current->qos_session_q_save, pQoSQRoot, sizeof(qos_queue_root_t));
+
+    current->qos_session_altq_conf_save = (struct altq_conf *) malloc(sizeof(struct altq_conf), M_QOS, M_NOWAIT | M_ZERO);
+    memcpy(current->qos_session_altq_conf_save, pALTQConf, sizeof(struct altq_conf));
+
+    save_dyn_qos_session_config (name, pQoSQRoot->sIfName, sip, sport, dip, dport, pQoSQRoot->sBand, pQoSQRoot->sDir);
+    return 0;
+}
+
+
+void save_dyn_qos_session_config (char *name, char *port, uint32_t sip, uint16_t sport, uint32_t dip, uint16_t dport, char *band, char *dir) {
+
+    dyn_session_qos_conf_t *dyn_session_qos_data = NULL;
+
+    dyn_session_qos_data = (dyn_session_qos_conf_t *)malloc(sizeof(dyn_session_qos_conf_t), M_QOS, M_NOWAIT | M_ZERO);
+
+    strcpy (dyn_session_qos_data->name, name);
+    strcpy (dyn_session_qos_data->port, port);
+    strcpy (dyn_session_qos_data->band, band);
+    strcpy (dyn_session_qos_data->dir, dir);
+    
+    dyn_session_qos_data->sip = sip;
+    dyn_session_qos_data->sport = sport;
+    dyn_session_qos_data->dip = dip;
+    dyn_session_qos_data->dport = dport; 
+
+
+    STAILQ_INSERT_TAIL(&dyn_session_qos_conf_head, dyn_session_qos_data, list_entry);
+}
+
+
+int show_qos_session_config(void *pcb, char *name) {
+
+    dyn_session_qos_conf_t *dyn_qos_conf_run = NULL;
+
+    STAILQ_FOREACH(dyn_qos_conf_run, &dyn_session_qos_conf_head, list_entry) {
+        if(strcmp(name, dyn_qos_conf_run->name) && strncmp(name, QOS_NAME_FOR_ALL, sizeof(QOS_NAME_FOR_ALL))) {
+            continue;
+        }
+
+        app_printf(pcb,  "qos dynamic \"%s\" %s %u.%u.%u.%u %u %u.%u.%u.%u %u %s %s\n", 
+            dyn_qos_conf_run->name, dyn_qos_conf_run->port, 
+            (dyn_qos_conf_run->sip) & 0xFF,
+            (dyn_qos_conf_run->sip >> 8) & 0xFF,
+            (dyn_qos_conf_run->sip >> 16) & 0xFF,
+            (dyn_qos_conf_run->sip >> 24) & 0xFF,
+            dyn_qos_conf_run->sport, 
+            (dyn_qos_conf_run->dip) & 0xFF,
+            (dyn_qos_conf_run->dip >> 8) & 0xFF,
+            (dyn_qos_conf_run->dip >> 16) & 0xFF,
+            (dyn_qos_conf_run->dip >> 24) & 0xFF,
+            dyn_qos_conf_run->dport,
+            dyn_qos_conf_run->band, dyn_qos_conf_run->dir);
+    }
+    return QOS_SUCCESS;
+}
+
+
+void *qos_session_lookup(uint32_t sip, uint16_t sport, uint32_t dip, uint16_t dport, uint8_t direction) {
+    int i;
+    int octet;
+    int wild_card;
+    int is_sip_match = 0;
+    int is_dip_match = 0;
+    int is_sport_match = 0;
+    int is_dport_match = 0;
+
+    dyn_qos_session_lookup_t* current = dyn_qos_session_lookup_root;
+    if (current == NULL)
+        return current;
+
+    wild_card = 0;
+    for (i = 3; i >= 0; --i) {
+        int octet = (sip >> (i * 8)) & 0xFF;
+
+        if (!wild_card && (current->dyn_qos_session_lookup_node[octet])) {
+            current = current->dyn_qos_session_lookup_node[octet];
+        }
+        else if (current->dyn_qos_session_lookup_node[0]) {
+            wild_card = 1;
+            current = current->dyn_qos_session_lookup_node[0];
+        }
+        else {
+            return NULL;
+        }
+    } 
+    if (!wild_card)
+        is_sip_match = 1;
+
+    wild_card = 0;
+    for (i = 1; i >= 0; --i) {
+        int octet = (sport >> (i * 8)) & 0xFF;
+
+        if (!wild_card && (current->dyn_qos_session_lookup_node[octet])) {
+            current = current->dyn_qos_session_lookup_node[octet];
+        }
+        else if (current->dyn_qos_session_lookup_node[0]) {
+            wild_card = 1;
+            current = current->dyn_qos_session_lookup_node[0];
+        }
+        else {
+            return NULL;
+        }
+    }
+    if (!wild_card)
+        is_sport_match = 1;
+
+    wild_card = 0;
+    for (i = 3; i >= 0; --i) {
+        int octet = (dip >> (i * 8)) & 0xFF;
+
+        if (!wild_card && (current->dyn_qos_session_lookup_node[octet])) {
+            current = current->dyn_qos_session_lookup_node[octet];
+        }
+        else if (current->dyn_qos_session_lookup_node[0]) {
+            wild_card = 1;
+            current = current->dyn_qos_session_lookup_node[0];
+        }
+        else {
+            return NULL;
+        }
+    }
+    if (!wild_card)
+        is_dip_match = 1;
+
+    wild_card = 0;
+    for (i = 1; i >= 0; --i) {
+        int octet = (dport >> (i * 8)) & 0xFF;
+
+        if (!wild_card && (current->dyn_qos_session_lookup_node[octet])) {
+            current = current->dyn_qos_session_lookup_node[octet];
+        }
+        else if (current->dyn_qos_session_lookup_node[0]) {
+            wild_card = 1;
+            current = current->dyn_qos_session_lookup_node[0];
+        }
+        else {
+            return NULL;
+        }
+    }
+    if (!wild_card)
+        is_dport_match = 1;
+
+    if ((current->direction == direction) && current->is_leaf) {
+        current->is_sip_match = is_sip_match;
+        current->is_dip_match = is_dip_match;
+        current->is_sport_match = is_sport_match;
+        current->is_dport_match = is_dport_match;
+        return current;
+    }
+    return NULL;
+} 
+
+
+//TODO delete indivisual entry and also delete qos dynamic session config
+void remove_qos_session_config(dyn_qos_session_lookup_t *root) {
+    int i;
+    if (root) {
+        for (i = 0; i < N_CHILDREN; ++i) {
+            remove_qos_session_config (root->dyn_qos_session_lookup_node[i]);
+        }
+        free(root, M_QOS);
+    }
+}
+
+
+int delete_qos_session_config(void *pcb, char *name) {
+    remove_qos_session_config (dyn_qos_session_lookup_root);
+    dyn_qos_session_lookup_root = NULL;
+    return 0;
+}
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_scheduler.h
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_scheduler.h	(revision 37998)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_scheduler.h	(working copy)
@@ -43,7 +43,8 @@
 #define QOS_BORROW_DEFAULT	QOS_UNBORROW
 
 /* QoS queue size limit */
-#define QOS_DEFAULT_QLIMIT	1024
+
+#define QOS_DEFAULT_QLIMIT	100000
 
 /*************************************************************************
  * STRUCTURE DEFINITIONS
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_scheduler.c
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_scheduler.c	(revision 37998)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_scheduler.c	(working copy)
@@ -1571,6 +1571,9 @@
 		if (!strncmp(pQoSQRoot->sQName, Q_NAME_PREFIX_FOR_SESSION_BASED_QOS, strlen(Q_NAME_PREFIX_FOR_SESSION_BASED_QOS))) {
 			continue;
 		}
+		if (!strncmp(pQoSQRoot->sQName, "qd_", 3)) {
+			continue;
+		}
 
 		isfound = 1;
 
@@ -1665,6 +1668,10 @@
         if (!strncmp(pQoSQRoot->sQName, Q_NAME_PREFIX_FOR_SESSION_BASED_QOS, strlen(Q_NAME_PREFIX_FOR_SESSION_BASED_QOS))) {
             continue;
         }
+        if (!strncmp(pQoSQRoot->sQName, "qd_", 3)) {
+            continue;
+        }
+
 
 		app_printf(pcb, "qos queue root \"%s\" \"%s\" %s %s %d %s %s\n",
 				pQoSQRoot->sQName, pQoSQRoot->sIfName, pQoSQRoot->sDir,
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_subr.c
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_subr.c	(revision 37998)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_subr.c	(working copy)
@@ -472,6 +472,11 @@
 				continue;
 			}
 
+#if 1
+        if (!strncmp(pQoSQRoot->sQName, "qd_", 3)) {
+            continue;
+        }
+#endif
 			app_printf(pcb, "%sqos queue root \"%s\" \"%s\" %s %s %d %s %s\n",
 					QOS_INDENT_1, pQoSQRoot->sQName, pQoSQRoot->sIfName, pQoSQRoot->sDir,
 					pQoSQRoot->sBand, pQoSQRoot->iPri, pQoSQRoot->sBorrow,
@@ -861,6 +866,11 @@
 		if (!strncmp(pfltr->fltr_name, FILTER_NAME_PREFIX_FOR_SESSION_BASED_QOS, strlen(FILTER_NAME_PREFIX_FOR_SESSION_BASED_QOS))) {
 			continue;
 		}
+#if 1
+        if (!strncmp(pfltr->fltr_name, "fd_", 3)) {
+            continue;
+        }
+#endif
 
 		smask.s_addr = pfltr->tp.smask;
 		dmask.s_addr = pfltr->tp.dmask;
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_var.h
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_var.h	(revision 37998)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_var.h	(working copy)
@@ -45,7 +45,7 @@
 #define QOS_MAXPRIO		8
 
 /* QoS maximum queue */
-#define QOS_MAXQ		1024
+#define QOS_MAXQ		100000
 
 /* QoS interface maximum number */
 #define MAX_VLAN 4094
