Index: /tags/Rel_APV_10_4_0_112_1/usr/click/bin/backend/sys_tool.c
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/click/bin/backend/sys_tool.c	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/click/bin/backend/sys_tool.c	(working copy)
@@ -194,6 +194,7 @@
 static char *write_aaa_session(char *segment);
 static char *write_aaa_sso(char *segment);
 static char *write_qos(char *segment) ;
+static char *write_qos_session(char *segment) ;
 static char *write_dpi(char *segment);
 static char *write_segment(char *segment);
 /*vxlan_support*/
@@ -1070,6 +1071,12 @@
         "#Qos configuration"
     },
 
+    {
+        write_qos_session,
+        CMD_NORMAL|CMD_ARRAYOS|CMD_GLOBAL,
+        "#session QoS configuration"
+    },
+
     /* Bug 16763, chenyl, 20070925 */
     {
 	write_segment,
@@ -10116,6 +10123,16 @@
 
 	return buf;
 }
+static char *write_qos_session(char *segment) 
+{
+    char *buf = NULL;
+    int  len;
+
+    if (write_qos_session_kern((void **) &buf, &len) < 0) {
+        return NULL;
+    }
+    return buf;
+}
 
 static int clear_qos(void)
 {
Index: /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libkernelapi/addCommands.pm
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libkernelapi/addCommands.pm	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libkernelapi/addCommands.pm	(working copy)
@@ -3692,6 +3692,13 @@
                 {type => "OUTDATA"},
             ],
     },
+    {
+        cmd_attribute => "CMD_KERN_API|CMD_KAPI_LOCK",
+        function_name => "write_qos_session_kern",
+        function_args => [
+                {type => "OUTDATA"},
+            ],
+    },
     # Bug 14949(QoS), end
 #WRITE cache_filter_kern add by zhangjz
     {
@@ -4121,6 +4128,13 @@
 			{type => "U32"},
 		    ],
 	},
+	{
+		cmd_attribute => "CMD_KERN_API",
+		function_name => "session_qos_kern",
+		function_args => [
+			{type => "INDATA"},
+		    ],
+	},
 	# Bug 14949(QoS), end
 	# bug 8720, tangmeng, 20060406
 	{
Index: /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libparser/commands.pm
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libparser/commands.pm	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libparser/commands.pm	(working copy)
@@ -53345,6 +53345,106 @@
 							},
 						],
 	},
+        {
+                obj_type => "ITEM",
+                name => "session",
+                menu => "root_qos",
+                cmd_attribute => "CMD_ARRAYOS|CMD_SPROXY|CMD_NORMAL|CMD_GLOBAL",
+                user_level => "CLI_LEVEL_CONFIG",
+                help_string => "Configure QoS session",
+                function_name => "session_qos",
+                function_args => [
+                                                        {
+                                                                type => "STRING",
+                                                                help_string => "name",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "STRING",
+                                                                help_string => "Interface name (<system_ifname>|<vlan_ifname>|<bond_ifname>)",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "STRING",
+                                                                help_string => "Output/input direction (OUT/IN/Both)",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "STRING",
+                                                                help_string => "Bandwidth per Session, suffixes may be b, Kb, Mb, and Gb",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "DOTTEDIP",
+                                                                help_string => "Source IP",
+                                                                optional => "NO",
+                                                        },
+                                                       {
+                                                                type => "DOTTEDIP",
+                                                                help_string => "Netmask for source IP",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "U16",
+                                                                help_string => "Source port",
+                                                                optional => "NO",
+                                                        },
+                                            {
+                                                                type => "DOTTEDIP",
+                                                                help_string => "Destination IP",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "DOTTEDIP",
+                                                                help_string => "Netmask for destination IP",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "U16",
+                                                                help_string => "Destination port",
+                                                                optional => "NO",
+                                                        },
+                                                        {
+                                                                type => "STRING",
+                                                                help_string => "Protocol (tcp, udp or any)",
+                                                                optional => "NO",
+                                                        },
+                                                ],
+        },
+        {
+                obj_type => "ITEM",
+                name => "session",
+                menu => "root_show_qos",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
+                user_level => "CLI_LEVEL_ENABLE",
+                help_string => "Show configurations of QoS session",
+                function_name => "show_session_qos_kern",
+                function_args => [
+                                                        {
+                                                                type => "STRING",
+                                                                help_string => "Session QoS, (optional, default is ALL)",
+                                                                optional => "YES",
+                                                                default_value => "\"ALL\"",
+                                                        },
+                                                ],
+        },
+        {
+                obj_type => "ITEM",
+                name => "session",
+                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 QoS session",
+                function_name => "no_session_qos_kern",
+                function_args => [
+                                                        {
+                                                                type => "STRING",
+                                                                help_string => "name",
+                                                                optional => "NO",
+                                                        },
+                                                ],
+        },
+
 	{
 		obj_type => "ITEM",
 		name => "sub",
Index: /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libqos_cli/qos_cli.h
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libqos_cli/qos_cli.h	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libqos_cli/qos_cli.h	(working copy)
@@ -20,6 +20,8 @@
 #define	RM_FILTER_GAIN	5	/* log2 of gain, e.g., 5 => 31/32 */
 #define	RM_NS_PER_SEC	(1000000000)
 
+#define SESSION_BASED_QOS_NLEN 15
+
 /*************************************************************************
  * STRUCTURE DEFINITIONS
  *************************************************************************/
@@ -35,4 +37,3 @@
 extern int challange_user(char *);
 
 #endif /* _QOS_H_DEFINED_ */
-
Index: /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libqos_cli/qos_cli.c
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libqos_cli/qos_cli.c	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libqos_cli/qos_cli.c	(working copy)
@@ -17,6 +17,7 @@
 #include <limits.h>
 #include <math.h>
 #include <stdint.h>
+#include <stdarg.h>
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -66,6 +67,8 @@
 
 #include <click/app/qos/qos_var.h>
 #include <click/app/qos/qos_scheduler.h>
+#include <click/app/qos/qos_classifier.h>
+#include <click/app/qos/qos_session.h>
 #include <click/app/qos/altq_var.h>
 #include <click/app/qos/altq_cbq.h>
 #include "qos_cli.h"
@@ -84,6 +87,11 @@
 #define	SIOCGIFMTU		UINET_SIOCGIFMTU
 #endif
 
+#define QOS_SESSIONS 1024
+
+uint32_t all_bin[QOS_SESSIONS] = {0};
+int pos = 0;
+
 /*
  * ------------------------ function prototypes ---------------------------
  */
@@ -748,6 +756,228 @@
 	return(0);
 }
 
+int is_all_ones (int n, unsigned int no) {
+    int i;
+
+    for (i = 0; i < n; i++, no = no >> 1) {
+        if (!(no & 1)) {
+            return 0;
+        }
+    }
+    return 1;
+}
+ 
+int generate_all_binary(int n, unsigned int no, unsigned int i)
+{
+    if (i == n) {
+        if (no == 0 || is_all_ones(n, no))
+            return 0;
+        all_bin[pos++] = no;
+        return 0;
+    }
+    
+    //AND no with zero at nth position
+
+    no = ~(1 << i) & no;
+
+    generate_all_binary(n, no, i + 1);
+
+    no = (1 << i) | no;
+
+    generate_all_binary(n, no, i + 1);
+    return 0;
+}
+
+void qos_queue_delete(int n_queue, ...) {
+	va_list ap;
+	char *q_name;
+
+	va_start (ap, n_queue);
+
+	while (n_queue--) {
+		q_name = va_arg(ap, char *);
+		no_qos_queue_root_kern(q_name);
+	}
+	va_end(ap);
+}
+
+void qos_filter_delete(int n_filter, ...) {
+	va_list ap;
+	char *f_name;
+
+	va_start (ap, n_filter);
+
+	while (n_filter--) {
+		f_name = va_arg(ap, char *);
+		no_qos_filter_kern(f_name);
+	}
+
+	va_end(ap);
+}
+
+/* CLI: session qos ... */
+int session_qos(char *name, char *sIfName, char *sDir, char *sBand, uint32_t sip, uint32_t smask, uint16_t sport, uint32_t dip, uint32_t dmask, uint16_t dport, char *proto_str)
+{
+    int i;
+    uint32_t sip_new;
+    int host_bits = 0;
+    char q_name_out[QOS_QNAME_SIZE];
+    char filter_name_out[QOS_FLTR_NLEN];
+    char q_name_in[QOS_QNAME_SIZE];
+    char filter_name_in[QOS_FLTR_NLEN];
+    uint8_t q_create_fail, filter_create_fail, qos_session_fail;
+    char *sDirNew;
+
+    char sHwIf[QOS_IFNAMSIZ] = {0};
+
+    q_create_fail = filter_create_fail = qos_session_fail = 0;
+
+    session_qos_conf_t qos_session_data;
+    
+    bzero(&qos_session_data, sizeof(qos_session_data));
+
+    if (strlen(name) > SESSION_BASED_QOS_NLEN) {
+        fprintf (stderr, "Invalid name for session QoS. Maximum name length is restricted to %d.\n", SESSION_BASED_QOS_NLEN);
+        return -1;
+    }
+
+    if (is_duplicate_session_qos_name(name)) {
+        fprintf (stderr, "Session QoS \"%s\" already exists.\n", name);
+        return -1;
+    }
+
+    if (getrealif(sIfName, sHwIf) != 0) {
+        fprintf(stderr, "Error: No such interface - %s exists.\n", sIfName);
+        return -1;
+    }
+        
+    if ((strcasecmp(sDir, QOSD_OUTPUT_STR) != 0) && (strcasecmp(sDir, QOSD_INPUT_STR) != 0) && 
+            (strcasecmp(sDir, QOSD_BIDIRECTION_STR) != 0)) {
+        fprintf(stderr, "Error: %s is invalid, direction must be %s or %s or %s.\n", sDir, QOSD_OUTPUT_STR,
+                QOSD_INPUT_STR, QOSD_BIDIRECTION_STR);
+        return -1;
+    }
+
+    if ((sip & smask) != sip) {
+        fprintf(stderr, "Error: invalid source IP and mask pair\n");
+        return -1;
+    }
+    
+    if ((dip & dmask) != dip) {
+        fprintf(stderr, "Error: invalid destination IP and mask pair\n");
+        return -1;
+    }
+
+    uint32_t smask_nh =  ntohl(smask);
+
+    while (1)  {
+       if (smask_nh & 1)
+            break;
+        else
+            ++host_bits;
+        smask_nh >>= 1;
+        if (host_bits == 0)  {
+            fprintf (stderr, "invalid netmask\n");
+            return(QOS_USERLAND_FAILURE);
+        }
+        if (host_bits > 8)  {
+            fprintf (stderr, "Unsupported netmask. Source network mask should be greater than or equal to 24.\n");
+            return(QOS_USERLAND_FAILURE);
+        }
+    }
+
+    pos = 0;
+
+   /* OR'ed source network part of the source subnet with all binary combinations from host part of the source subnet to generate all possible source IP's */
+    memset(all_bin, 0, sizeof(all_bin));
+    generate_all_binary(host_bits, 0, 0);
+    for (i = 0; i < pos; i++) {
+		sip_new = ntohl(all_bin[i]) | sip;
+		if ((strcasecmp(sDir, QOSD_OUTPUT_STR) == 0) || (strcasecmp(sDir, QOSD_BIDIRECTION_STR) == 0)) {
+			sDirNew = "OUT";
+			sprintf(q_name_out, "%s_%s_%d_%s", Q_NAME_PREFIX_FOR_SESSION_BASED_QOS, name, i, sDirNew);
+			sprintf(filter_name_out, "%s_%s_%d_%s", FILTER_NAME_PREFIX_FOR_SESSION_BASED_QOS, name, i, sDirNew);
+
+			q_create_fail = qos_queue_root(q_name_out, sIfName, sDirNew, sBand, 1, NULL,NULL);
+			if (q_create_fail) 
+				break;
+
+			filter_create_fail = qos_filter_kern(filter_name_out, q_name_out, sip_new, ~0, sport,
+				dip, dmask, dport, proto_str, 1);
+			if (filter_create_fail) {
+				qos_queue_delete (1, q_name_out);
+				break;
+			}
+		}
+		if ((strcasecmp(sDir, QOSD_INPUT_STR) == 0) || (strcasecmp(sDir, QOSD_BIDIRECTION_STR) == 0)) {
+			sDirNew = "IN";
+			sprintf(q_name_in, "%s_%s_%d_%s", Q_NAME_PREFIX_FOR_SESSION_BASED_QOS, name, i, sDirNew);
+			sprintf(filter_name_in, "%s_%s_%d_%s", FILTER_NAME_PREFIX_FOR_SESSION_BASED_QOS, name, i, sDirNew);
+
+			if (strcasecmp(sDir, QOSD_BIDIRECTION_STR) == 0) {
+				q_create_fail = qos_queue_root(q_name_in, sIfName, sDirNew, sBand, 1, NULL,NULL);
+				if (q_create_fail) {
+					qos_filter_delete (1, filter_name_out);
+					qos_queue_delete (1, q_name_out);
+					break;
+				} 
+
+				filter_create_fail = qos_filter_kern(filter_name_in, q_name_in, dip, dmask, dport, sip_new, ~0, sport,
+					proto_str, 1);
+				if (filter_create_fail) {
+					qos_filter_delete (1, filter_name_out);
+					qos_queue_delete (2, q_name_out, q_name_in);
+					break;
+				}
+
+			} else {
+				q_create_fail = qos_queue_root(q_name_in, sIfName, sDirNew, sBand, 1, NULL,NULL);
+				if (q_create_fail) 
+					break;
+
+				filter_create_fail = qos_filter_kern(filter_name_in, q_name_in, sip_new, ~0, sport,
+					dip, dmask, dport, proto_str, 1);
+				if (filter_create_fail) {
+					qos_queue_delete (1, q_name_in);
+					break;
+				}
+			}
+		}
+	}
+	if (q_create_fail || filter_create_fail) {
+		fprintf (stderr, "error creating session QOS\n");
+		if (i > 0) {
+			handle_session_qos_cleanup (name, i - 1, sDir);
+		}
+		return(QOS_USERLAND_FAILURE);
+	}
+
+        /* Save user configuration */
+	strcpy (qos_session_data.name, name);
+	strcpy (qos_session_data.session_q_info.sIfName, sIfName);
+	strcpy (qos_session_data.session_q_info.sDir, sDir);
+	strcpy (qos_session_data.session_q_info.sBand, sBand);
+	qos_session_data.no_of_hosts = pos;
+
+	qos_session_data.tp.sip.s_addr = sip;
+	qos_session_data.tp.smask = smask;
+	qos_session_data.tp.sport = htons(sport);
+	qos_session_data.tp.dip.s_addr = dip;
+	qos_session_data.tp.dmask = dmask;
+	qos_session_data.tp.dport = htons(dport);
+    
+    
+	qos_session_fail = session_qos_kern(&qos_session_data, sizeof (qos_session_data));
+	if (qos_session_fail) {
+		fprintf (stderr, "error creating QoS session config!\n");
+		handle_session_qos_cleanup (name, i - 1, sDir);
+		return(QOS_USERLAND_FAILURE);
+	}
+
+	return QOS_SUCCESS;
+}
+
+
 /* CLI: qos queue root ... */
 int qos_queue_root(char *sQueue, char *sIfName, char *sDir, char *sBand, uint32_t iPri, char *sBorrow, char *sDefault)
 {
@@ -855,8 +1085,7 @@
 	}
 
 	return(0);
-}
-
+} 
 /* CLI: no qos queue root ... */
 int no_qos_queue_root(char *sQueue)
 {
Index: /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libuinet-atcp/lib/libuinet/Makefile
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libuinet-atcp/lib/libuinet/Makefile	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/click/lib/libuinet-atcp/lib/libuinet/Makefile	(working copy)
@@ -654,6 +654,7 @@
 	qos_classifier.c	\
 	qos_http.c	\
 	qos_scheduler.c	\
+	qos_session.c	\
 	qos_subr.c
 	
 CLICK_APP_RADIUS_SRCS+=	\
Index: /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/apv/doc/en/network.xml
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/apv/doc/en/network.xml	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/apv/doc/en/network.xml	(working copy)
@@ -1777,6 +1777,129 @@
                 <finish_msg/>
             </action>
         </model>
+
+        <model name="QosSession" status="NEW">
+            <verbose_name>QoS Session</verbose_name>
+                <help_text>The QoS Session policy enforces bandwidth control in the specified session of the interface.</help_text>
+            <help_link/>
+            <fieldgrp name="default">
+                <verbose_name>Basic Settings</verbose_name>
+                <help_text/>
+                <field name="interface" type="asso">
+                    <verbose_name>Interface</verbose_name>
+                    <help_text/>
+                </field>
+                <field name="direction" type="enum">
+                    <verbose_name>Direction</verbose_name>
+                    <choices>
+                        <choice value="OUT">
+                            <verbose_name>Out</verbose_name>
+                            <help_text>Outbound direction</help_text>
+                        </choice>
+                        <choice value="IN">
+                            <verbose_name>In</verbose_name>
+                            <help_text>Inbound direction</help_text>
+                        </choice>
+                        <choice value="BOTH">
+                            <verbose_name>BOTH</verbose_name>
+                            <help_text>Dedicated bandwidth will be assigned to outbound as well as inbound connections.</help_text>
+                        </choice>
+                    </choices>
+                    <help_text>BOTH - dedicated bandwidth will be assigned to outbound as well as inbound connections.</help_text>
+                </field>
+                <field name="bandwidth" type="GroupField">
+                    <verbose_name>Bandwidth</verbose_name>
+                    <help_text>Specifies the maximum bandwidth allowed in the specified direction of the interface. The bandwidth is shared by all QoS queues in the specified direction of the interface.</help_text>
+                    <subfields>
+                        <field name="bandwidth_value" type="int">
+                            <verbose_name>Bandwidth Value</verbose_name>
+                            <help_text/>
+                        </field>
+                        <field name="bandwidth_gb" type="int">
+                            <verbose_name>Bandwidth Value</verbose_name>
+                            <help_text/>
+                        </field>
+                        <field name="bandwidth_mb" type="int">
+                            <verbose_name>Bandwidth Value</verbose_name>
+                            <help_text/>
+                        </field>
+                        <field name="bandwidth_kb" type="int">
+                            <verbose_name>Bandwidth Value</verbose_name>
+                            <help_text/>
+                        </field>
+                        <field name="bandwidth_b" type="int">
+                            <verbose_name>Bandwidth Value</verbose_name>
+                            <help_text/>
+                        </field>
+                        <field name="bandwidth_suffix" type="enum">
+                            <verbose_name>Bandwidth Unit</verbose_name>
+                            <help_text/>
+                            <choices>
+                                <choice value="Gb">
+                                    <verbose_name>Gbps</verbose_name>
+                                    <help_text/>
+                                </choice>
+                                <choice value="Mb">
+                                    <verbose_name>Mbps</verbose_name>
+                                    <help_text/>
+                                </choice>
+                                <choice value="Kb">
+                                    <verbose_name>Kbps</verbose_name>
+                                    <help_text/>
+                                </choice>
+                                <choice value="b">
+                                    <verbose_name>bps</verbose_name>
+                                    <help_text/>
+                                </choice>
+                            </choices>
+                        </field>
+                    </subfields>
+                </field>
+                <field name="src_ip" type="ip4addr">
+                    <verbose_name>Source IP</verbose_name>
+                    <help_text>A dedicated bandwidth will be assigned to Source IP in the source network</help_text>
+                </field>
+                <field name="src_mask" type="string">
+                    <verbose_name>Source Netmask</verbose_name>
+                    <help_text/>
+                </field>
+                <field name="src_port" type="uint32">
+                    <verbose_name>Source Port</verbose_name>
+                    <help_text/>
+                </field>
+                <field name="des_ip" type="ip4addr">
+                    <verbose_name>Destination IP</verbose_name>
+                    <help_text/>
+                </field>
+                <field name="des_mask" type="string">
+                    <verbose_name>Destination Netmask</verbose_name>
+                    <help_text/>
+                </field>
+                <field name="des_port" type="uint32">
+                    <verbose_name>Destination Port</verbose_name>
+                    <help_text/>
+                </field>
+                <field name="protocol" type="enum">
+                    <verbose_name>Protocol</verbose_name>
+                    <help_text/>
+                    <choices>
+                        <choice value="tcp">
+                            <verbose_name>TCP</verbose_name>
+                            <help_text/>
+                        </choice>
+                        <choice value="udp">
+                            <verbose_name>UDP</verbose_name>
+                            <help_text/>
+                        </choice>
+                        <choice value="any">
+                            <verbose_name>Any</verbose_name>
+                            <help_text/>
+                        </choice>
+                    </choices>
+                </field>
+            </fieldgrp>
+        </model>
+
     </package>
     <package name="spanport">
         <verbose_name>SPAN Port</verbose_name>
@@ -2303,4 +2426,4 @@
             </fieldgrp>
         </model>
     </package>
-</package>
\ No newline at end of file
+</package>
Index: /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/apv/models/network/qos/__init__.py
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/apv/models/network/qos/__init__.py	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/apv/models/network/qos/__init__.py	(working copy)
@@ -9,11 +9,12 @@
 from hive.router import get_current_session
 from django.shortcuts import redirect
 from hive.node.model import *
+from hive.utils import andebug
 from jinja2 import Environment, PackageLoader, ChoiceLoader
 import re
 __=_
 
-child_seq = ['QosInterface', 'QosQueue', 'QosRootQueue', 'QosSubQueue', 'QosFilter', 'QosStatistics']
+child_seq = ['QosInterface', 'QosQueue', 'QosRootQueue', 'QosSubQueue', 'QosFilter', 'QosSession', 'QosStatistics']
 
 class QosInterface(ANModel):
     interface = AssoField2(verbose_name=_('Interface'), tgt='network.interface.InterfaceSettings.qos_tgt', mul='*', pos='left', primary_key=True)
@@ -36,6 +37,8 @@
 
     queue = AssoField2(verbose_name=_('Queue'), tgt='network.qos.QosRootQueue.interface', mul='1', pos='right', optional=True)
 
+    session = AssoField2(verbose_name=_('Queue'), tgt='network.qos.QosSession.interface', mul='1', pos='right', optional=True)
+
     class Meta:
         verbose_name = _('Qos Interface')
         show_im_export_button = True
@@ -522,3 +525,94 @@
 
         def _perform_Refresh(self, options):
             return ''
+
+class QosSession(ANModel):
+    name = CharField(verbose_name=_('Name'), primary_key=True, length="1..31")
+    interface = AssoField2(verbose_name=_('Interface'), tgt='network.qos.QosInterface.session', mul='*', pos='left')
+    direction = EnumField(verbose_name=_('Direction'), values=(
+                           ('OUT', 'OUT', '', 'fa-sign-out text-warning'),
+                           ('IN', 'IN', '', 'fa-sign-in text-warning'),
+                           ('BOTH', 'BOTH', '', 'fa-refresh text-warning'),
+                           ))
+    bandwidth = GroupField(verbose_name=_('Bandwidth'), custom_display=lambda val:str(val['bandwidth_value'])+val['bandwidth_suffix'], fields={
+                              'bandwidth_value':IntegerField(verbose_name=_('Bandwidth Value'),condition=GroupFieldValueCondition('bandwidth','bandwidth_suffix',[''])),
+                              'bandwidth_gb':IntegerField(verbose_name=_('Bandwidth Value'),condition=GroupFieldValueCondition('bandwidth','bandwidth_suffix',['Gb']),scope='1..3'),
+                              'bandwidth_mb':IntegerField(verbose_name=_('Bandwidth Value'),condition=GroupFieldValueCondition('bandwidth','bandwidth_suffix',['Mb']),scope='1..4095'),
+                              'bandwidth_kb':IntegerField(verbose_name=_('Bandwidth Value'),condition=GroupFieldValueCondition('bandwidth','bandwidth_suffix',['Kb']),scope='1..4194303'),
+                              'bandwidth_b':IntegerField(verbose_name=_('Bandwidth Value'),condition=GroupFieldValueCondition('bandwidth','bandwidth_suffix',['b']),scope='1..4294967295'),
+                              'bandwidth_suffix':EnumField(verbose_name=_('Bandwidth Unit'), values=(
+                                                          ('Gb','Gbps'),
+                                                          ('Mb','Mbps'),
+                                                          ('Kb','Kbps'),
+                                                          ('b','bps')))})
+
+    src_ip = IPv4AddressField(verbose_name=_('Source IP'))
+    src_mask = NetmaskField(verbose_name=_('Source Mask'))
+    src_port = Uint32Field(verbose_name=_('Source Port'))
+    
+    des_ip = IPv4AddressField(verbose_name=_('Destination IP'))
+    des_mask = NetmaskField(verbose_name=_('Destination Mask'))
+    des_port = Uint32Field(verbose_name=_('Destination Port'))
+    
+    protocol = EnumField(verbose_name=_('Protocol'), values=(
+                           ('tcp', 'TCP'),
+                           ('udp', 'UDP'),
+                           ('any', 'ANY'),
+                           ))
+
+    class Meta:
+        verbose_name = _('QoS Session')
+        show_im_export_button = True
+
+
+    class Manager(CLIManager):
+        def _get_query_set(self):
+            self.cli.set_enable()
+            parser = RegexParser('qos session "(?P<name>.*?)" (?P<interface_name>.*?) (?P<direction>[Ii][Nn]|[Oo][Uu][Tt]|[Bb][Oo][Tt][Hh]) (?P<bandwidth>[\w|0-9]+) (?P<src_ip>[0-9|\.]+) (?P<src_mask>[0-9|\.]+) (?P<src_port>[0-9]+) (?P<des_ip>[0-9|\.]+) (?P<des_mask>[0-9|\.]+) (?P<des_port>[0-9]+) (?P<protocol>tcp|udp|any)', MATCHALL, reflags=re.S)
+
+            result = self.cli.cmd('show qos session', parser)
+            for each_result in result:
+                each_result['interface'] = [{'interface':[{'name':each_result['interface_name'], '_asso_idx':0}], 'direction':each_result['direction']}]
+                del each_result['interface_name']
+                each_result['direction'] = each_result['direction'].upper()
+                bandwidth_value=re.sub('\D', '', each_result['bandwidth'])
+                bandwidth_suffix=re.sub('\d', '', each_result['bandwidth'])
+                # For upper or lower chars
+                key_list = {'gb':'Gb', 'mb':'Mb','kb':'Kb','b':'b'}
+                bandwidth_suffix = key_list[bandwidth_suffix.lower()]
+                if bandwidth_suffix == 'Gb':
+                    each_result['bandwidth']={'bandwidth_value':bandwidth_value,'bandwidth_gb':bandwidth_value, 'bandwidth_suffix':bandwidth_suffix}
+                elif bandwidth_suffix == 'Mb':
+                    each_result['bandwidth']={'bandwidth_value':bandwidth_value,'bandwidth_mb':bandwidth_value,'bandwidth_suffix':bandwidth_suffix}
+                elif bandwidth_suffix == 'Kb':
+                    each_result['bandwidth']={'bandwidth_value':bandwidth_value,'bandwidth_kb':bandwidth_value, 'bandwidth_suffix':bandwidth_suffix}
+                elif bandwidth_suffix == 'b':
+                    each_result['bandwidth']={'bandwidth_value':bandwidth_value,'bandwidth_b':bandwidth_value,'bandwidth_suffix':bandwidth_suffix}
+                self._model._meta.mark_delay_query(each_result)
+            data = QuerySet(self._model, result)
+            return data
+        
+        def _insert(self, instance):
+            data = instance.get_field_dict()
+            andebug('hive.debug', data)
+            if 'bandwidth_gb' in data['bandwidth']:
+                data['bandwidth']=str(data['bandwidth']['bandwidth_gb'])+data['bandwidth']['bandwidth_suffix']
+            elif 'bandwidth_mb' in data['bandwidth']:
+                data['bandwidth']=str(data['bandwidth']['bandwidth_mb'])+data['bandwidth']['bandwidth_suffix']
+            elif 'bandwidth_kb' in data['bandwidth']:
+                data['bandwidth']=str(data['bandwidth']['bandwidth_kb'])+data['bandwidth']['bandwidth_suffix'] 
+            elif 'bandwidth_b' in data['bandwidth']:
+                data['bandwidth']=str(data['bandwidth']['bandwidth_b'])+data['bandwidth']['bandwidth_suffix']
+            data['interface_name'] = data['interface'][0]['interface'][0]['name'] # data['interface'][0]['name']
+            self.cli.set_config()
+            result = self.cli.cmd('qos session "%(name)s" "%(interface_name)s" %(direction)s %(bandwidth)s %(src_ip)s %(src_mask)s %(src_port)s %(des_ip)s %(des_mask)s %(des_port)s %(protocol)s' % data,
+                            BlankParser(nonblank_exception=CLICmdError, supplement=True))
+            return result
+
+
+        def _delete(self, pk_list):
+            self.cli.set_config()
+            for each_pk in pk_list:
+                result = self.cli.cmd('no qos session "%s"' % (each_pk['name']),
+                                  BlankParser(nonblank_exception=CLICmdError, supplement=True))
+            return
Index: /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/apv/tree.py
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/apv/tree.py	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/apv/tree.py	(working copy)
@@ -148,6 +148,7 @@
             ('qos_queue', {'cls':ModelNode, 'model':'network.qos.QosQueue'}),
             ('qos_filter', {'cls':ModelNode, 'model':'network.qos.QosFilter'}),
             ('qos_status', {'cls':ModelNode, 'model':'network.qos.QosStatistics'}),
+            ('qos_session', {'cls':ModelNode, 'model':'network.qos.QosSession'}),
         ])}),
         ('ipv6', {'cls':MenuNode, 'license':'IPv6', 'verbose_name':_('IPv6 Advanced Settings'), 'sub_nodes':D([
             ('nat64', {'cls':ModelNode, 'model':'nat.nat.NAT64Settings'}),
Index: /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/hive/model/ajax.py
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/hive/model/ajax.py	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/hive/model/ajax.py	(working copy)
@@ -12,16 +12,16 @@
 from hive.model.loading import get_app, get_model
 from django.http import Http404
 import json
-from hive.exceptions import ValidationError, ModelQueryException, ActionPerformException, FieldDoesNotExist, ManagerImplError, BadRequestException, UpdateException
+from hive.exceptions import ValidationError, ModelQueryException, ActionPerformException, FieldDoesNotExist, ManagerImplError, BadRequestException
 import copy
 import time
 from jinja2 import Environment, PackageLoader, ChoiceLoader
-from hive.utils import HiveEnvironment, andebug, anerror, url2obj, IntRange, get_time_internal
+from hive.utils import HiveEnvironment, andebug, anerror, url2obj, IntRange, get_time_internal, get_need_db_list
 from hive.model.utils import reduce_asso_value_item, get_complex_field, get_config_list_data, save_config_list_data
 from jinja2.exceptions import TemplateNotFound
 from django.template import RequestContext
 import urllib
-from hive.model.query import mark_expire_all, update_cache_field
+from hive.model.query import mark_expire_all, update_cache_field, mark_expire_one
 from hive.notification import send_notification
 from hive.model.legacycli import cli_parse, EasyParser, RegexParser, MATCHONE, MATCHALL
 from django.utils.importlib import import_module
@@ -29,8 +29,11 @@
 from djproject.an_settings import TEST_IP_POOL, DIR_STR, MAX_FILES_COUNT, RRDCACHED_SOCKET
 from django.utils.translation import ugettext_lazy as _
 from djproject.an_settings import GRAPH_DB_FILE_LIST
+from hive.utils import escapehtml 
 import sqlite3, re
 
+TIMEFORMAT='%Y-%m-%d %X'
+        
 def main():
     pass
 
@@ -69,7 +72,7 @@
             template = env.get_template('/'.join(self.model._meta.path) + '/box_' + sub_action + '.html')
         except TemplateNotFound:
             template = env.get_template('box_' + sub_action + '.html')
-        ctx = {'REQUEST':self.request, 'SESSION':self.session, 'MEDIA':'/media/',
+        ctx = {'REQUEST':self.request, 'SESSION':self.session, 'MEDIA':'/media/', 'app_name': self.app._meta.app_label,
                'MODEL':self.model, 'MANAGER':self.manager, 'csrf_token':django_ctx['csrf_token'], 'PARAMS':kwargs}
         
         if "action=BatchMemberAttr" in self.request.META["REQUEST_URI"]:
@@ -157,7 +160,13 @@
         """
         if 'filter' in kwargs:
             filters = json.loads(urllib.unquote(kwargs['filter']))
-            qs = self.manager.filter(filters)
+            if 'with_fields' not in kwargs and not filters:
+                try:
+                    return self.manager.list()
+                except ManagerImplError:
+                    qs = self.manager.filter(filters)
+            else:
+                qs = self.manager.filter(filters)
         else:
             qs = copy.copy(self.manager.all())
             
@@ -184,12 +193,12 @@
         try:
             new_obj.clean_fields()
         except ValidationError, e:
-            return json.dumps([False, unicode(e)])
+            return json.dumps([False, escapehtml(unicode(e))])
         try:
             self.manager.insert(new_obj)
         except ModelQueryException, e:
             if e.has_error():
-                return json.dumps([False, unicode(e)])
+                return json.dumps([False, escapehtml(unicode(e))])
             elif e.get_detail():
                 return json.dumps([True, new_obj.url_params(), e.get_detail()])
             elif unicode(e):
@@ -198,18 +207,113 @@
         send_notification('info', 'A new %s is added.' % self.model._meta.verbose_name) 
         return json.dumps([True, new_obj.url_params(), []])
 
+    def batch_add(self, **kwargs):
+        new_instance_list = []
+        added_pk_list = []
+        ex_ins_list = []
+        try:
+            json_str = kwargs['post_data']
+            json_list = json.loads(json_str)
+            deriving_fields = self.model._meta.conditional_deriving_fields
+            for each_json in json_list:
+                concrete_dict = {}
+                if self.model._meta.abstract:
+                    for field in deriving_fields:
+                        concrete_dict[field] = each_json[field]
+                    real_model = self.model._meta.get_child_by_field_cond(concrete_dict)
+                else:
+                    real_model = self.model
+                json_data = {}
+                for key in real_model._meta.field_groups['default'].fields:
+                    if key.attname in each_json:
+                        json_data[key.attname] = each_json[key.attname]
+                if "/group/Group/" in self.request.path:
+                    if 'gphc' in each_json and each_json['gphc']:
+                        json_data['healthchecks'] = [{'hc_name':each_json['gphc']}]
+                if "/rs/RealService/" in self.request.path:
+                    if 'hc' in each_json and each_json['hc']:
+                        each_json['hc']['hc_name'] = 'Built-in HealthCheck of %s' % each_json['service_name']
+                        ex_ins_list.append(each_json['hc'])
+                new_obj = real_model(**json_data)
+                try:
+                    new_obj.clean_fields()
+                except ValidationError, e:
+                    return json.dumps([False, 'Add %s Failed: %s' % (new_obj.repr(), unicode(e))])
+                new_instance_list.append(new_obj)
+
+        except KeyError:
+            raise
+        for ins in new_instance_list:
+            try:
+                real_manager = self.session.get_model_manager(self.app._meta.app, ins._meta.path)
+                real_manager.insert(ins)
+                if "/group/Group/" in self.request.path:
+                    real_manager._update_healthchecks(ins)
+            except ModelQueryException, e:
+                mark_expire_all(self.model, clear_all_if_has_asso=True)
+                try:
+                    self.manager.delete(added_pk_list)
+                except:
+                    pass
+                return json.dumps([False, 'Add %s Failed: %s' %(ins.repr(), unicode(e))])
+            added_pk_list.append(ins.pk_dict())
+        try:
+            if "/rs/RealService/" in self.request.path:
+                if len(ex_ins_list):
+                    HCManager = self.session.get_model_manager(self.app._meta.app, 'loadbalancing.slb.healthcheck.HealthCheck')
+                    for hc_info in ex_ins_list:
+                        hc_pk = {"hc_name":hc_info["hc_name"]}
+                        hc_ins = HCManager.get(hc_pk)
+                        old_value_dict = dict(hc_ins.get_field_dict(withstats=False))
+                        for key,value in hc_info.iteritems():
+                            update_cache_field(hc_ins, key, value, False)
+                        try:
+                            hc_ins.clean_fields()
+                        except ValidationError, e:
+                            # roll back
+                            for key,value in old_value_dict.iteritems():
+                                setattr(hc_ins, key, value)
+                            mark_expire_all(self.model, clear_all_if_has_asso=True)
+                            try:
+                                self.manager.delete(added_pk_list)
+                            except:
+                                pass
+                            return json.dumps([False, 'Set %s Failed: %s' %(hc_ins.repr(), unicode(e))])
+                        try:
+                            real_manager = self.session.get_model_manager(self.app._meta.app, hc_ins._meta.path)
+                            real_manager.update(hc_ins,  old_values=old_value_dict)
+                        except ModelQueryException, e:
+                            mark_expire_all(self.model, clear_all_if_has_asso=True)
+                            try:
+                                self.manager.delete(added_pk_list)
+                            except:
+                                pass
+                            return json.dumps([False, 'Set %s Failed: %s' %(hc_ins.repr(), unicode(e))])
+        except ModelQueryException, e:
+            mark_expire_all(self.model, clear_all_if_has_asso=True)
+            try:
+                self.manager.delete(added_pk_list)
+            except:
+                pass
+            return json.dumps([False, 'Set Health Check Failed' + unicode(e)])
+        return json.dumps([True, '', []])
+
     def delete(self, **kwargs):
         try:
             pk_str_list = kwargs['pk'].split('ÿÿÿÿÿ')
             pk_list = [json.loads(pk_str) for pk_str in pk_str_list]
-            additional_field = kwargs['additional_field'].split('ÿÿÿÿÿ')
+            if 'additional_field' in kwargs:
+                additional_field = kwargs['additional_field'].split('ÿÿÿÿÿ')
+            else:
+                additional_field = None
 
-            if "/rs/RealService/_delete" in self.request.path:
+            if additional_field and "/rs/RealService/_delete" in self.request.path:
                 return self.delete_rs_custom(pk_list, additional_field)
             if len(pk_list) == 1:
                 # first try to get the instance, so we can get the real instance model.
                 instance = self.manager.get(pk_list[0])
-                send_notification('info', '%s (%s) is deleted.' % (instance.repr_by_pk(pk_list[0]), instance._meta.verbose_name))
+                if instance:
+                    send_notification('info', '%s (%s) is deleted.' % (instance.repr_by_pk(pk_list[0]), instance._meta.verbose_name))
             else:
                 send_notification('info', '%d %s are deleted.' % (len(pk_list), self.model._meta.verbose_name))
             return self.manager.delete(pk_list)
@@ -255,12 +359,20 @@
         map_dict = {'HTTP': 'http', 'HTTPS': 'https', 'DNS': 'dns', 'FTP': 'ftp', 'SIP over TCP': 'siptcp', 'SIP over UDP': 'sipudp', 
         'RTSP': 'rtsp', 'RDP': 'rdp', 'RADAUTH': 'radauth', 'RADACCT': 'radacct', 'Diameter': 'diameter', 'TCP': 'tcp', 'TCPS': 'tcps',
         'UDP': 'udp', 'Tuxedo': 'tuxedo', 'IP': 'ip', 'Fwdmac': 'fwdmac', 'Fwdip': 'fwdip', 'L2 MAC': 'l2mac', 'L2 IP': 'l2ip'}
+        map_class = {'HTTP': 'L4L7RealService', 'HTTPS': 'L4L7RealService', 'DNS': 'L4L7RealService', 'FTP': 'L4L7RealService', 'SIP over TCP': 'L4L7RealService',
+        'SIP over UDP': 'L4L7RealService',  'Fwdip': 'L4L7RealService','RTSP': 'L4L7RealService', 'RDP': 'L4L7RealService', 'RADAUTH': 'L4L7RealService',
+        'RADACCT': 'L4L7RealService', 'Diameter': 'L4L7RealService', 'TCP': 'L4L7RealService', 'TCPS': 'L4L7RealService','UDP': 'L4L7RealService', 
+        'Tuxedo': 'TUXEDORealService', 'IP': 'IPRealService', 'Fwdmac': 'FWDMACRealService','L2 MAC': 'L2MACRealService', 'L2 IP': 'L2IPRealService'}
         
         mod = get_model('apv', ['loadbalancing', 'slb', 'rs', 'RealService'])    
         for i in range(len(pk_list)):
             each = pk_list[i]
             output = self.session.cli.cmd('no slb real %s "%s"' % (map_dict[additional_field[i]], each['service_name']))
+            rs_mod = get_model('apv', ['loadbalancing', 'slb', 'rs', '%s'%map_class[additional_field[i]]])
+            mark_expire_one(rs_mod, pk_list[i])
             mark_expire_all(mod)
+        node_mod = get_model('apv', ['loadbalancing', 'slb', 'node', 'Node'])    
+        mark_expire_all(node_mod)
         return output
 
     def get_delete_error_msg(self, e_dict):
@@ -528,7 +640,16 @@
                     if get_external_data:                    
                         tmp_ret = ins_manager.get_external_data_for_list(each, field_list)
                         sub_ret['external'] = tmp_ret
-
+                    # QoS Session - Interface & Direction values display workaround for Both direction.
+                    expected_keys = ['name', 'interface', 'direction', 'src_ip', 'des_ip', 'bandwidth']
+                    count = 0
+                    for _ekey in expected_keys:
+                        if _ekey in sub_ret.keys():
+                            count += 1
+                    if count == len(expected_keys):
+                        # To update interface value for Both direction
+                        if 'both' in str(sub_ret['direction']).lower():
+                            sub_ret['interface'] = str(sub_ret['interface']).replace('&nbsp; &nbsp; &nbsp;</a>', 'BOTH&nbsp; &nbsp; &nbsp;</a>')
                     #add hide data in response, hide data include "pk_str", "action", "functions"
                     hide_data = ins_manager.get_internal_data_for_list(each)
                     sub_ret['internal'] = hide_data
@@ -851,21 +972,57 @@
             value_list = [time_str, num(value)]
         return value_list
 
+    def get_sql_select_info(self, table_name, instance):
+        instance_str = instance.pk_str()
+        if not instance_str:
+            instance_str = '{}'
+        where_str = " where pk is '"
+        if "VirtualService" in table_name:
+            table_name = "GlobalVirtualServiceStats"
+            where_str =  " where service_name is '"
+            instance_str = instance.service_name
+        if "RealService" in table_name:
+            table_name = "GlobalRealServiceStats"
+            where_str =  " where service_name is '"
+            instance_str = instance.service_name
+        if table_name == "PervsCompressStatistics":
+            where_str =  " where service_name is '"
+            instance_str = instance.service_name
+        if table_name in ["LLBLinkRoute"]:
+            table_name = "ExLLBLinkStatistics"
+            where_str =  " where name is '"
+            instance_str = instance.name
+        if table_name in ["ExSSLRealHostStatistics", "ExSSLVirtualHostStatistics"]:
+            where_str =  " where name is '"
+            instance_str = instance.name
+        if table_name in ["LLBGlobalStatistics"]:
+            table_name = "ExLLBLinkStatistics"
+            where_str =  " where name is '"
+            instance_str = instance.service_name
+        if table_name == "DefaultPolicy":
+            if model_list[-2] == "types":
+                # for slb default policy, set table name to slb_DefaultPolicy
+                table_name = "slb_DefaultPolicy"
+        if table_name in ['SystemInterface', 'BondInterface']:
+            instance_str = '{"name": "' + instance.id + '"}'
+        return table_name, where_str, instance_str
+
     def get_statistics_data(self, **kwargs):
         # {'instance':[pk_dict1, pk_dict2, ...], 'field':[xxx, ...]}
         keys = json.loads(kwargs['keys'])
         field_sum = 1
         last_time = ''
-        TIMEFORMAT='%Y-%m-%d %X'
         ret = {}
+        ret['data'] = []
+        ret['data_name'] = []
         if 'key' in kwargs:
             ret['key'] = kwargs['key']
         for field in keys['field']:
             field_sum += 1
         last_value = [0] * field_sum
+
         start = int(kwargs['start_time'])
         end = int(kwargs['end_time'])
-
         end_time = time.time() + end
         if not start:
             start_time = end_time - 1800.0
@@ -873,24 +1030,19 @@
             start_time = time.time() + start
         ret['start_time'] = time.strftime(TIMEFORMAT, time.localtime(start_time))
         ret['end_time'] = time.strftime(TIMEFORMAT, time.localtime(end_time))
-        ret['data'] = []
-        ret['data_name'] = []
-        u_start = time.strftime(TIMEFORMAT, time.gmtime(start_time))
-        u_end = time.strftime(TIMEFORMAT, time.gmtime(end_time))
-        start_db = u_start.split(' ')[0]+'.db'
-        end_db = u_end.split(' ')[0]+'.db'
-        all_db = filter(lambda e: e.endswith('.db'), os.listdir(GRAPH_DB_FILE_LIST))
-        all_db_list = sorted(all_db)
-        if end_db in all_db_list and start_db in all_db_list:
-            start_index = all_db_list.index(start_db)
-            end_index = all_db_list.index(end_db)
-        elif end_db in all_db_list and start_db not in all_db_list:
-            start_index = 0
-            end_index = all_db_list.index(end_db)
+        
+        if "LLBLinkRoute" in self.request.path_info:
+            need_db_list = ["storemon_1.db"]
+            start_db = "storemon_1.db"
+            end_db = "storemon_1.db"
         else:
-            ret['error'] = unicode(_('Fail to query the data.')) 
-            return json.dumps(ret)
-        need_db_list = all_db_list[start_index:end_index+1]
+            db_info = get_need_db_list(start_time, end_time)
+            start_db = db_info['start_db']
+            end_db = db_info['end_db']
+            need_db_list = db_info['need_db_list']
+            if need_db_list is None:
+                ret['error'] = unicode(_('Fail to query the data.')) 
+                return json.dumps(ret)
         for each_db in need_db_list:
             db_file_exist = os.path.isfile(GRAPH_DB_FILE_LIST+each_db)
             if db_file_exist:
@@ -923,29 +1075,23 @@
                             data_name += '('+ unicode(field_obj.unit_name) + ')'
                         ret['data_name'].append(data_name)
                         ret['data'].append([])
-                    instance_str = instance.pk_str()
-                    if not instance_str:
-                        instance_str = '{}'
+                    
                     model_list = instance._meta._model._meta.path
                     table_name = model_list[-1]
-                    if table_name == "DefaultPolicy":
-                        if model_list[-2] == "types":
-                            # for slb default policy, set table name to slb_DefaultPolicy
-                            table_name = "slb_DefaultPolicy"
-                    if table_name in ['SystemInterface', 'BondInterface']:
-                        instance_str = '{"name": "' + instance.id + '"}'
+                    table_name, where_str, instance_str = self.get_sql_select_info(table_name, instance)
+                    
                     if start_db == end_db:
-                        cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time > " + str(int(start_time)) + " and time < " + str(int(end_time)) + " group by timef"
+                        cmd += " from " + table_name + where_str + instance_str +"' and time > " + str(int(start_time)) + " and time < " + str(int(end_time)) + " group by timef"
                     elif each_db == start_db:
-                        cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time > " + str(int(start_time)) + " group by timef"
+                        cmd += " from " +  table_name + where_str + instance_str +"' and time > " + str(int(start_time)) + " group by timef"
                     elif each_db == end_db:
-                        cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time < " + str(int(end_time)) + " group by timef"
+                        cmd += " from " +  table_name + where_str + instance_str +"' and time < " + str(int(end_time)) + " group by timef"
                     else:
                         (y,m,d) = each_db.split('.db')[0].split('-')
                         t = (int(y), int(m), int(d), 0, 0, 0, 0, 0, 0)
                         start_secs = int(time.mktime( t ))
                         end_secs = int(time.mktime( t )) + 86400
-                        cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time > " + str(start_secs) + " and time < " + str(end_secs) + " group by timef"
+                        cmd += " from " +  table_name + where_str + instance_str +"' and time > " + str(start_secs) + " and time < " + str(end_secs) + " group by timef"
                     try:
                         db.execute(cmd)
                     except sqlite3.OperationalError, e:
@@ -1058,7 +1204,7 @@
             return template.render({'THEME': self.session.theme})
 
         group_basic = False
-        if sub_action == "instance_config" and "slb/group/methods" in self.request.path and self.request.GET['group_name'] == 'default':
+        if sub_action == "instance_config" and "slb/group/methods" in self.request.path and 'group_name' in self.request.GET and self.request.GET['group_name'] == 'default':
             group_basic = True
         try:
             template = env.get_template('/'.join(self.model._meta.path) + '/box_' + sub_action + '.html')
@@ -1188,14 +1334,16 @@
             # roll back
             for key,value in old_value_dict.iteritems():
                 setattr(self.object, key, value)
-            raise UpdateException([False, unicode(e)], 400)
-            # return json.dumps([False, unicode(e)])
+            return json.dumps([False, escapehtml(unicode(e))])
         try:
             self.manager.update(self.object, field_list=json_dict.keys(), old_values=old_value_dict)
         except ModelQueryException, e:
             andebug('hive.debug', 'raising exception at ajax\'s update: %s' % old_value_dict)
             if e.has_error():
-                return json.dumps([False, unicode(e)])
+                for key, value in old_value_dict.iteritems():
+                    if key in json_dict:
+                        setattr(self.object, key, value)
+                return json.dumps([False, escapehtml(unicode(e))])
             elif e.get_detail():
                 return json.dumps([True, self.object.url_params(), e.get_detail()])
             else:
@@ -1300,7 +1448,6 @@
         keys = json.loads(kwargs['keys'])
         field_sum = 1
         last_time = ''
-        TIMEFORMAT='%Y-%m-%d %X'
         
         ret = {}
         if 'key' in kwargs:
@@ -1321,23 +1468,19 @@
         ret['data'] = []
         ret['data_name'] = []
         
-        u_start = time.strftime(TIMEFORMAT, time.gmtime(start_time))
-        u_end = time.strftime(TIMEFORMAT, time.gmtime(end_time))
-        start_db = u_start.split(' ')[0]+'.db'
-        end_db = u_end.split(' ')[0]+'.db'
-        
-        all_db = filter(lambda e: e.endswith('.db'), os.listdir(GRAPH_DB_FILE_LIST))
-        all_db_list = sorted(all_db)
-        if end_db in all_db_list and start_db in all_db_list:
-            start_index = all_db_list.index(start_db)
-            end_index = all_db_list.index(end_db)
-        elif end_db in all_db_list and start_db not in all_db_list:
-            start_index = 0
-            end_index = all_db_list.index(end_db)
+        if "LLBGlobalStatistics" in self.request.path_info:
+            need_db_list = ["storemon_1.db"]
+            start_db = "storemon_1.db"
+            end_db = "storemon_1.db"
         else:
-            ret['error'] = unicode(_('Fail to query the data.')) 
-            return json.dumps(ret)
-        need_db_list = all_db_list[start_index:end_index+1]
+            db_info = get_need_db_list(start_time, end_time)
+            if db_info is None:
+                ret['error'] = unicode(_('Fail to query the data.')) 
+                return json.dumps(ret)
+            start_db = db_info['start_db']
+            end_db = db_info['end_db']
+            need_db_list = db_info['need_db_list']
+            
         for each_db in need_db_list:
             db_file_exist = os.path.isfile(GRAPH_DB_FILE_LIST+each_db)
             if db_file_exist:
@@ -1365,6 +1508,11 @@
                 instance_str = instance.pk_str()
                 model_list = instance._meta._model._meta.path
                 table_name = model_list[-1]
+                where_str = " where "
+                if table_name == "SystemStatusGraph":
+                    table_name = "SystemStatus"
+                # if table_name in["GlobalStatistics","GlobalSSLThroughStats", "InterfaceThroughputStatistics"]:
+                #     where_str = " where "
                 if table_name == "DefaultPolicy":
                     if model_list[-2] == "types":
                         # for slb default policy, set table name to slb_DefaultPolicy
@@ -1374,17 +1522,20 @@
                 if not instance_str:
                     instance_str = '{}'
                 if start_db == end_db:
-                    cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time > " + str(int(start_time)) + " and time < " + str(int(end_time)) + " group by timef"
+                    if "LLBGlobalStatistics" in self.request.path_info:
+                        cmd += " from ExLLBLinkStatistics where time > " + str(int(start_time)) + " and time < " + str(int(end_time)) + " group by timef"
+                    else:
+                        cmd += " from " +  table_name + where_str +" time > " + str(int(start_time)) + " and time < " + str(int(end_time)) + " group by timef"
                 elif each_db == start_db:
-                    cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time > " + str(int(start_time)) + " group by timef"
+                    cmd += " from " +  table_name + where_str +" time > " + str(int(start_time)) + " group by timef"
                 elif each_db == end_db:
-                    cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time < " + str(int(end_time)) + " group by timef"
+                    cmd += " from " +  table_name + where_str +" time < " + str(int(end_time)) + " group by timef"
                 else:
                     (y,m,d) = each_db.split('.db')[0].split('-')
                     t = (int(y), int(m), int(d), 0, 0, 0, 0, 0, 0)
                     start_secs = int(time.mktime( t ))
                     end_secs = int(time.mktime( t )) + 86400
-                    cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time > " + str(start_secs) + " and time < " + str(end_secs) + " group by timef"
+                    cmd += " from " +  table_name + where_str +" time > " + str(start_secs) + " and time < " + str(end_secs) + " group by timef"
                 try:
                     db.execute(cmd)
                 except sqlite3.OperationalError, e:
@@ -1475,6 +1626,35 @@
                 conn.close()
         return json.dumps(ret)
 
+    def config_sync(self, **kwargs):
+        try:
+            json_str = kwargs['post_data']
+            json_dict = json.loads(json_str)
+            fields = json_dict['fields']
+            tgt_instances = json_dict['instances']
+        except KeyError:
+            raise Http404
+        try:
+            result = self.manager.config_sync(self.object, fields=fields, target_instances=tgt_instances)
+            return json.dumps(result)
+        except ModelQueryException, e:
+            andebug('hive.debug', 'raising exception at ajax\'s config_sync: %s' % json_str)
+            return json.dumps([False, [unicode(e)]])
+
+    def get_syncable_instance_list(self, **kwargs):
+        try:
+            result = self.manager.get_syncable_instance_list(self.object)
+            return result
+        except ManagerImplError:
+            try:
+                return self.manager.list()
+            except ManagerImplError:
+                qs = copy.copy(self.manager.all())
+                rtn = []
+                for each in qs:
+                    each_rtn = {'pk':each.pk_dict(), 'repr':each.repr()}
+                    rtn.append(each_rtn)
+                return json.dumps(rtn)
 if __name__ == '__main__':
     main()
 
Index: /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/media/docs/rest/apv/network/qos/index.html
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/media/docs/rest/apv/network/qos/index.html	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/media/docs/rest/apv/network/qos/index.html	(working copy)
@@ -1,78 +1,104 @@
 <!DOCTYPE html>
 <html>
   <head>
-    <meta charset="utf-8">
+    <meta charset="utf-8" />
     <title>eCloud RESTful API Reference Manual</title>
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <meta name="description" content="">
-    <meta name="author" content="">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <meta name="description" content="" />
+    <meta name="author" content="" />
     <link rel="stylesheet" href="../../../static/css/bootstrap.min.css" />
     <link rel="stylesheet" href="../../../static/css/font-awesome.min.css" />
-    <script type="text/javascript" src="../../../static/js/jquery.min.js"></script>
-    <script type="text/javascript" src="../../../static/js/bootstrap.min.js"></script>
-</head>
-<body>
-<nav class="navbar navbar-default">
-    <a class="navbar-brand" href="#">eCloud RESTful API</a>
-    <form class="navbar-form navbar-left" role="search">
-      <div class="form-group">
-        <input type="text" class="form-control" placeholder="Search">
+    <script
+      type="text/javascript"
+      src="../../../static/js/jquery.min.js"
+    ></script>
+    <script
+      type="text/javascript"
+      src="../../../static/js/bootstrap.min.js"
+    ></script>
+  </head>
+  <body>
+    <nav class="navbar navbar-default">
+      <a class="navbar-brand" href="#">eCloud RESTful API</a>
+      <form class="navbar-form navbar-left" role="search">
+        <div class="form-group">
+          <input type="text" class="form-control" placeholder="Search" />
+        </div>
+        <button type="submit" class="btn btn-default">Submit</button>
+      </form>
+    </nav>
+
+    <div
+      class="panel panel-primary"
+      style="margin-left: 10px; margin-right: 10px"
+    >
+      <div class="panel-heading">
+        <i class="fa fa-folder" style="margin-right: 10px"></i>Qos&nbsp;&nbsp;<a
+          style="color: white"
+          href="../index.html"
+          ><i class="fa fa-chevron-up"></i
+        ></a>
+        <span class="text-warning pull-right" style="color: white"
+          >/rest/APV/network/qos</span
+        >
       </div>
-      <button type="submit" class="btn btn-default">Submit</button>
-    </form>
-</nav>
-
-<div class="panel panel-primary" style="margin-left:10px;margin-right:10px;">
-    <div class="panel-heading"><i class="fa fa-folder" style="margin-right:10px;"></i>Qos&nbsp;&nbsp;<a style="color:white;" href="../index.html"><i class="fa fa-chevron-up"></i></a>
-    <span class="text-warning pull-right" style="color:white;">/rest/APV/network/qos</span>
-    </div>
-    
-    <ul class="list-group">
-        
-        
-
-        
-        
-        <a class="list-group-item" href="qosinterface.html"><i class="fa fa-file-text-o" style="margin-right:10px;"></i>QoS Interface <span class="text-primary pull-right">/rest/APV/network/qos/QosInterface</span></a>
-        
-        
-        
-
-        
-        
-        <a class="list-group-item" href="qosqueue.html"><i class="fa fa-file-text-o" style="margin-right:10px;"></i>QoS Queue <span class="text-primary pull-right">/rest/APV/network/qos/QosQueue</span></a>
-        
-        
-        
-
-        
-        
-        <a class="list-group-item" href="qosrootqueue.html"><i class="fa fa-file-text-o" style="margin-right:10px;"></i>QoS Root Queue <span class="text-primary pull-right">/rest/APV/network/qos/QosRootQueue</span></a>
-        
-        
-        
-
-        
-        
-        <a class="list-group-item" href="qossubqueue.html"><i class="fa fa-file-text-o" style="margin-right:10px;"></i>QoS Sub-queue <span class="text-primary pull-right">/rest/APV/network/qos/QosSubQueue</span></a>
-        
-        
-        
-
-        
-        
-        <a class="list-group-item" href="qosfilter.html"><i class="fa fa-file-text-o" style="margin-right:10px;"></i>QoS Filter <span class="text-primary pull-right">/rest/APV/network/qos/QosFilter</span></a>
-        
-        
-        
-
-        
-        
-        <a class="list-group-item" href="qosstatistics.html"><i class="fa fa-file-text-o" style="margin-right:10px;"></i>QoS Statistics <span class="text-primary pull-right">/rest/APV/network/qos/QosStatistics</span></a>
-        
-        
-    </ul>
-</div>
 
-</body>
-</html>
\ No newline at end of file
+      <ul class="list-group">
+        <a class="list-group-item" href="qosinterface.html"
+          ><i class="fa fa-file-text-o" style="margin-right: 10px"></i>QoS
+          Interface
+          <span class="text-primary pull-right"
+            >/rest/APV/network/qos/QosInterface</span
+          ></a
+        >
+
+        <a class="list-group-item" href="qosqueue.html"
+          ><i class="fa fa-file-text-o" style="margin-right: 10px"></i>QoS Queue
+          <span class="text-primary pull-right"
+            >/rest/APV/network/qos/QosQueue</span
+          ></a
+        >
+
+        <a class="list-group-item" href="qosrootqueue.html"
+          ><i class="fa fa-file-text-o" style="margin-right: 10px"></i>QoS Root
+          Queue
+          <span class="text-primary pull-right"
+            >/rest/APV/network/qos/QosRootQueue</span
+          ></a
+        >
+
+        <a class="list-group-item" href="qossubqueue.html"
+          ><i class="fa fa-file-text-o" style="margin-right: 10px"></i>QoS
+          Sub-queue
+          <span class="text-primary pull-right"
+            >/rest/APV/network/qos/QosSubQueue</span
+          ></a
+        >
+
+        <a class="list-group-item" href="qosfilter.html"
+          ><i class="fa fa-file-text-o" style="margin-right: 10px"></i>QoS
+          Filter
+          <span class="text-primary pull-right"
+            >/rest/APV/network/qos/QosFilter</span
+          ></a
+        >
+
+        <a class="list-group-item" href="qosstatistics.html"
+          ><i class="fa fa-file-text-o" style="margin-right: 10px"></i>QoS
+          Statistics
+          <span class="text-primary pull-right"
+            >/rest/APV/network/qos/QosStatistics</span
+          ></a
+        >
+
+        <a class="list-group-item" href="qossession.html"
+          ><i class="fa fa-file-text-o" style="margin-right: 10px"></i>QoS
+          Session
+          <span class="text-primary pull-right"
+            >/rest/APV/network/qos/QosSession</span
+          ></a
+        >
+      </ul>
+    </div>
+  </body>
+</html>
Index: /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/media/docs/rest/apv/network/qos/qossession.html
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/media/docs/rest/apv/network/qos/qossession.html	(revision 0)
+++ /tags/Rel_APV_10_4_0_112_1/usr/click/webui/htdocs/new/src/media/docs/rest/apv/network/qos/qossession.html	(working copy)
@@ -0,0 +1,945 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8" />
+    <title>eCloud RESTful API Reference Manual</title>
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <meta name="description" content="" />
+    <meta name="author" content="" />
+    <link rel="stylesheet" href="../../../static/css/bootstrap.min.css" />
+    <link rel="stylesheet" href="../../../static/css/font-awesome.min.css" />
+    <script
+      type="text/javascript"
+      src="../../../static/js/jquery.min.js"
+    ></script>
+    <script
+      type="text/javascript"
+      src="../../../static/js/bootstrap.min.js"
+    ></script>
+  </head>
+  <body>
+    <nav class="navbar navbar-default">
+      <a class="navbar-brand" href="#">eCloud RESTful API</a>
+      <form class="navbar-form navbar-left" role="search">
+        <div class="form-group">
+          <input type="text" class="form-control" placeholder="Search" />
+        </div>
+        <button type="submit" class="btn btn-default">Submit</button>
+      </form>
+    </nav>
+
+    <div
+      class="panel panel-primary"
+      style="margin-left: 10px; margin-right: 10px"
+    >
+      <div class="panel-heading">
+        <i class="fa fa-folder" style="margin-right: 10px"></i>QoS
+        Session&nbsp;&nbsp;<a style="color: white" href="index.html"
+          ><i class="fa fa-chevron-up"></i
+        ></a>
+        <span class="text-warning pull-right" style="color: white"
+          >/rest/apv/network/qos/QosSession</span
+        >
+      </div>
+
+      <div class="panel-body">
+        <p>
+          The QoS Session policy enforces bandwidth control in the specified
+          session of the interface.
+        </p>
+      </div>
+
+      <ul class="list-group">
+        <!--########################
+    Query model meta data
+#########################-->
+        <li class="list-group-item">
+          <div class="row">
+            <div class="col-md-1">
+              <span class="label label-success">GET</span>
+            </div>
+            <div class="col-md-5" style="word-wrap: break-word">
+              /rest/apv/network/qos/QosSession/meta
+            </div>
+            <div class="col-md-5">Query the meta data of model QoS Session</div>
+            <div class="col-md-1">
+              <button
+                class="btn btn-info btn-sm btn-detail"
+                data-target="#detail-qossession-meta"
+                data-toggle="collapse"
+                id="detail-qossession-meta-btn"
+              >
+                detail
+              </button>
+            </div>
+          </div>
+          <div id="detail-qossession-meta" class="row collapse">
+            <div class="col-md-12">
+              <div class="row">
+                <div class="col-md-3"><b>Normal response codes</b></div>
+                <div class="col-md-9">200(OK)</div>
+              </div>
+              <div class="row">
+                <div class="col-md-3"><b>Error response codes</b></div>
+                <div class="col-md-9">
+                  401(unauthorized), 403(access forbidden), 500(internal service
+                  error), 501(unimplemented)
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-3"><b>Request parameters</b></div>
+                <div class="col-md-9">None</div>
+              </div>
+              <br />
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Available fields and field groups</b>
+                  <table class="table table-bordered table-striped">
+                    <thead>
+                      <tr>
+                        <th>Field Group Name</th>
+                        <th>Field Name</th>
+                        <th>Type</th>
+                        <th>Description</th>
+                      </tr>
+                    </thead>
+
+                    <tr>
+                      <td>default</td>
+                      <td>name</td>
+                      <td>string</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>interface</td>
+                      <td>asso</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>direction</td>
+                      <td>enum</td>
+                      <td>
+                        Available values:<br />
+                        <ul>
+                          <li><b>OUT</b> (Out) - Outbound direction</li>
+                          <li><b>IN</b> (In) - Inbound direction</li>
+                        </ul>
+                      </td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>bandwidth</td>
+                      <td>GroupField</td>
+                      <td>
+                        Specifies the maximum bandwidth allowed in the specified
+                        direction of the interface. The bandwidth is shared by
+                        all QoS queues in the specified direction of the
+                        interface.
+                      </td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>src_ip</td>
+                      <td>ip4addr</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>src_mask</td>
+                      <td>string</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>src_port</td>
+                      <td>uint32</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>des_ip</td>
+                      <td>ip4addr</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>des_mask</td>
+                      <td>string</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>des_port</td>
+                      <td>uint32</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>protocol</td>
+                      <td>enum</td>
+                      <td>
+                        Available values:<br />
+                        <ul>
+                          <li><b>tcp</b> (TCP)</li>
+                          <li><b>udp</b> (UDP)</li>
+                          <li><b>any</b> (Any)</li>
+                        </ul>
+                      </td>
+                    </tr>
+                  </table>
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Response format</b>
+                  <pre>
+{
+    "QosSession": {
+        "meta": {
+            "abstract": false,
+            "verbose_name": QoS Session,
+        },
+
+        "fieldgroups": [
+            {
+                "fields": [
+                    {
+                        "verbose_name": field_verbose_name1,
+                        "field_name": field_name1
+                    },
+                    ...
+                ],
+                "group_name": field_group_name1
+            },
+            ...
+        ]
+    }
+}
+                            </pre
+                  >
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Examples</b>
+                </div>
+              </div>
+            </div>
+          </div>
+        </li>
+
+        <!--########################
+    Create A New Instance
+#########################-->
+        <li class="list-group-item">
+          <div class="row">
+            <div class="col-md-1">
+              <span class="label label-success">POST</span>
+            </div>
+            <div class="col-md-5" style="word-wrap: break-word">
+              /rest/apv/network/qos/QosSession
+            </div>
+            <div class="col-md-5">Create a QoS Session</div>
+            <div class="col-md-1">
+              <button
+                class="btn btn-info btn-sm btn-detail"
+                data-target="#detail-qossession-create"
+                data-toggle="collapse"
+                id="detail-qossession-create-btn"
+              >
+                detail
+              </button>
+            </div>
+          </div>
+          <div id="detail-qossession-create" class="row collapse">
+            <div class="col-md-12">
+              <div class="row">
+                <div class="col-md-3"><b>Normal response codes</b></div>
+                <div class="col-md-9">200(successfully created)</div>
+              </div>
+              <div class="row">
+                <div class="col-md-3"><b>Error response codes</b></div>
+                <div class="col-md-9">
+                  401(unauthorized), 403(access forbidden), 500(internal service
+                  error), 501(unimplemented)
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Request format</b>
+                  <pre>
+{
+    &lt;param1&gt;:&lt;value1&gt;,
+    &lt;param2&gt;:&lt;value2&gt;,
+    ...
+}
+                            </pre
+                  >
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Request parameters</b>
+                  <table class="table table-bordered table-striped">
+                    <thead>
+                      <tr>
+                        <th>Parameter</th>
+                        <th>Type</th>
+                        <th>Description</th>
+                      </tr>
+                    </thead>
+
+                    <tr>
+                      <td>name</td>
+                      <td>string</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>interface</td>
+                      <td>asso</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>direction</td>
+                      <td>enum</td>
+                      <td>
+                        Available values:<br />
+                        <ul>
+                          <li><b>OUT</b> (Out) - Outbound direction</li>
+                          <li><b>IN</b> (In) - Inbound direction</li>
+                        </ul>
+                      </td>
+                    </tr>
+
+                    <tr>
+                      <td>bandwidth</td>
+                      <td>
+                        GroupField (Nested Field. It should be a dict.)
+                        <br />
+                        <table class="table table-bordered table-striped">
+                          <thead>
+                            <tr>
+                              <th>Parameter</th>
+                              <th>Type</th>
+                              <th>Description</th>
+                            </tr>
+                          </thead>
+
+                          <tr>
+                            <td>bandwidth_value</td>
+                            <td>int</td>
+                            <td></td>
+                          </tr>
+
+                          <tr>
+                            <td>bandwidth_gb</td>
+                            <td>int</td>
+                            <td></td>
+                          </tr>
+
+                          <tr>
+                            <td>bandwidth_mb</td>
+                            <td>int</td>
+                            <td></td>
+                          </tr>
+
+                          <tr>
+                            <td>bandwidth_kb</td>
+                            <td>int</td>
+                            <td></td>
+                          </tr>
+
+                          <tr>
+                            <td>bandwidth_b</td>
+                            <td>int</td>
+                            <td></td>
+                          </tr>
+
+                          <tr>
+                            <td>bandwidth_suffix</td>
+                            <td>enum</td>
+                            <td>
+                              Available values:<br />
+                              <ul>
+                                <li><b>Gb</b> (Gbps)</li>
+                                <li><b>Mb</b> (Mbps)</li>
+                                <li><b>Kb</b> (Kbps)</li>
+                                <li><b>b</b> (bps)</li>
+                              </ul>
+                            </td>
+                          </tr>
+                        </table>
+                      </td>
+                      <td>
+                        Specifies the maximum bandwidth allowed in the specified
+                        direction of the interface. The bandwidth is shared by
+                        all QoS queues in the specified direction of the
+                        interface.
+                      </td>
+                    </tr>
+
+                    <tr>
+                      <td>src_ip</td>
+                      <td>ip4addr</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>src_mask</td>
+                      <td>string</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>src_port</td>
+                      <td>uint32</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>des_ip</td>
+                      <td>ip4addr</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>des_mask</td>
+                      <td>string</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>des_port</td>
+                      <td>uint32</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>protocol</td>
+                      <td>enum</td>
+                      <td>
+                        Available values:<br />
+                        <ul>
+                          <li><b>tcp</b> (TCP)</li>
+                          <li><b>udp</b> (UDP)</li>
+                          <li><b>any</b> (Any)</li>
+                        </ul>
+                      </td>
+                    </tr>
+                  </table>
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Response format</b>
+                  <pre>
+{
+    "QosSession": {
+        "instance_id":&lt;instance_id&gt;,
+        &lt;param1&gt;:&lt;value1&gt;,
+        &lt;param2&gt;:&lt;value2&gt;,
+        ...
+    }
+}
+                            </pre
+                  >
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12"><b>Response parameters</b></div>
+                <div class="col-md-12">Same as request parameters.</div>
+              </div>
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Examples</b>
+                </div>
+              </div>
+            </div>
+          </div>
+        </li>
+
+        <!--########################
+    Perform a per model action
+#########################-->
+
+        <!--########################
+    Get Instance List
+#########################-->
+        <li class="list-group-item">
+          <div class="row">
+            <div class="col-md-1">
+              <span class="label label-success">GET</span>
+            </div>
+            <div class="col-md-5" style="word-wrap: break-word">
+              /rest/apv/network/qos/QosSession[?<i>&lt;filters&gt;</i>]
+            </div>
+            <div class="col-md-5">Get the list of QoS Session</div>
+            <div class="col-md-1">
+              <button
+                class="btn btn-info btn-sm btn-detail"
+                data-target="#detail-qossession-list"
+                data-toggle="collapse"
+                id="detail-qossession-list-btn"
+              >
+                detail
+              </button>
+            </div>
+          </div>
+          <div id="detail-qossession-list" class="row collapse">
+            <div class="col-md-12">
+              <div class="row">
+                <div class="col-md-3"><b>Normal response codes</b></div>
+                <div class="col-md-9">200(OK)</div>
+              </div>
+              <div class="row">
+                <div class="col-md-3"><b>Error response codes</b></div>
+                <div class="col-md-9">
+                  401(unauthorized), 403(access forbidden), 500(internal service
+                  error), 501(unimplemented)
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-3"><b>Request parameters</b></div>
+                <div class="col-md-9">
+                  One or more in-url key=value parameters as filters. Available
+                  keys are all field names of QosSession
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Response format</b>
+                  <pre>
+{
+    "QosSession": [
+        {
+            "instance_id":&lt;instance_id&gt;,
+            &lt;param1&gt;:&lt;value1&gt;,
+            &lt;param2&gt;:&lt;value2&gt;,
+            ...
+        },
+        ...
+    ]
+}
+                            </pre
+                  >
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Examples</b>
+                </div>
+              </div>
+            </div>
+          </div>
+        </li>
+        <!--########################
+    Query A Single Instance
+#########################-->
+        <li class="list-group-item">
+          <div class="row">
+            <div class="col-md-1">
+              <span class="label label-success">GET</span>
+            </div>
+            <div class="col-md-5" style="word-wrap: break-word">
+              /rest/apv/network/qos/QosSession/&lt;qossession_id&gt;[/&lt;field_group_name&gt;][/&lt;field_name&gt;]
+            </div>
+            <div class="col-md-5">
+              Query the info of a specific QoS Session. Or only query part of
+              the info by providing a detailed field group or single field name.
+            </div>
+            <div class="col-md-1">
+              <button
+                class="btn btn-info btn-sm btn-detail"
+                data-target="#detail-qossession-getone"
+                data-toggle="collapse"
+                id="detail-qossession-getone-btn"
+              >
+                detail
+              </button>
+            </div>
+          </div>
+          <div id="detail-qossession-getone" class="row collapse">
+            <div class="col-md-12">
+              <div class="row">
+                <div class="col-md-3"><b>Normal response codes</b></div>
+                <div class="col-md-9">200(OK)</div>
+              </div>
+              <div class="row">
+                <div class="col-md-3"><b>Error response codes</b></div>
+                <div class="col-md-9">
+                  401(unauthorized), 403(access forbidden), 404(no such
+                  instance), 500(internal service error), 501(unimplemented)
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Request parameters</b>
+                  <table class="table table-bordered table-striped">
+                    <thead>
+                      <tr>
+                        <th>Parameter</th>
+                        <th>Type</th>
+                        <th>Description</th>
+                      </tr>
+                    </thead>
+                    <tbody>
+                      <tr>
+                        <td>instance_id</td>
+                        <td>URI</td>
+                        <td>ID of the instance</td>
+                      </tr>
+                      <tr>
+                        <td>field_group_name</td>
+                        <td>URI</td>
+                        <td>
+                          (optional) Target field group name to query. Available
+                          names are: <span class="text-primary">default, </span
+                          ><span class="text-warning"
+                            >Notice: There could only be one field_group_name or
+                            field_name in the URL. And if both field_group_name
+                            and field_name are not specified, will try to query
+                            default field_group data.</span
+                          >
+                        </td>
+                      </tr>
+                      <tr>
+                        <td>field_name</td>
+                        <td>URI</td>
+                        <td>
+                          (optional) Target field name to query. Available names
+                          are:
+                          <span class="text-primary"
+                            >name, interface, direction, bandwidth, src_ip,
+                            src_mask, src_port, des_ip, des_mask, des_port,
+                            protocol, </span
+                          ><span class="text-warning"
+                            >Notice: There could only be one field_group_name or
+                            field_name in the URL.</span
+                          >
+                        </td>
+                      </tr>
+                    </tbody>
+                  </table>
+                  <b>Available fields and field groups</b>
+                  <table class="table table-bordered table-striped">
+                    <thead>
+                      <tr>
+                        <th>Field Group Name</th>
+                        <th>Field Name</th>
+                        <th>Type</th>
+                        <th>Description</th>
+                      </tr>
+                    </thead>
+
+                    <tr>
+                      <td>default</td>
+                      <td>name</td>
+                      <td>string</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>interface</td>
+                      <td>asso</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>direction</td>
+                      <td>enum</td>
+                      <td>
+                        Available values:<br />
+                        <ul>
+                          <li><b>OUT</b> (Out) - Outbound direction</li>
+                          <li><b>IN</b> (In) - Inbound direction</li>
+                        </ul>
+                      </td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>bandwidth</td>
+                      <td>GroupField</td>
+                      <td>
+                        Specifies the maximum bandwidth allowed in the specified
+                        direction of the interface. The bandwidth is shared by
+                        all QoS queues in the specified direction of the
+                        interface.
+                      </td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>src_ip</td>
+                      <td>ip4addr</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>src_mask</td>
+                      <td>string</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>src_port</td>
+                      <td>uint32</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>des_ip</td>
+                      <td>ip4addr</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>des_mask</td>
+                      <td>string</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>des_port</td>
+                      <td>uint32</td>
+                      <td></td>
+                    </tr>
+
+                    <tr>
+                      <td>default</td>
+                      <td>protocol</td>
+                      <td>enum</td>
+                      <td>
+                        Available values:<br />
+                        <ul>
+                          <li><b>tcp</b> (TCP)</li>
+                          <li><b>udp</b> (UDP)</li>
+                          <li><b>any</b> (Any)</li>
+                        </ul>
+                      </td>
+                    </tr>
+                  </table>
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Response format</b>
+                  <i>When no field_group/field name is provided:</i>
+                  <pre>
+{
+    "QosSession": {
+        "instance_id":&lt;instance_id&gt;,
+        &lt;field1&gt;:&lt;value1&gt;,
+        &lt;field2&gt;:&lt;value2&gt;,
+        ...
+    }
+}
+                            </pre
+                  >
+                  <i>When some field_group name is provided:</i>
+                  <pre>
+{
+    "QosSession": {
+        "instance_id":&lt;instance_id&gt;,
+        &lt;field1&gt;:&lt;value1&gt;,
+        &lt;field2&gt;:&lt;value2&gt;,
+        ...
+    }
+}
+                            </pre
+                  >
+                  <i>When some field name is provided:</i>
+                  <pre>
+{
+    "QosSession": {
+        "instance_id":&lt;instance_id&gt;,
+        &lt;field&gt;:&lt;value&gt;,
+    }
+}
+                            </pre
+                  >
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Examples</b>
+                </div>
+              </div>
+            </div>
+          </div>
+        </li>
+        <!--########################
+    Delete A Single Instance
+#########################-->
+
+        <li class="list-group-item">
+          <div class="row">
+            <div class="col-md-1">
+              <span class="label label-success">DELETE</span>
+            </div>
+            <div class="col-md-5" style="word-wrap: break-word">
+              /rest/apv/network/qos/QosSession/&lt;qossession_id&gt;
+            </div>
+            <div class="col-md-5">Delete a specific QoS Session</div>
+            <div class="col-md-1">
+              <button
+                class="btn btn-info btn-sm btn-detail"
+                data-target="#detail-qossession-delete"
+                data-toggle="collapse"
+                id="detail-qossession-delete-btn"
+              >
+                detail
+              </button>
+            </div>
+          </div>
+          <div id="detail-qossession-delete" class="row collapse">
+            <div class="col-md-12">
+              <div class="row">
+                <div class="col-md-3"><b>Normal response codes</b></div>
+                <div class="col-md-9">200(OK)</div>
+              </div>
+              <div class="row">
+                <div class="col-md-3"><b>Error response codes</b></div>
+                <div class="col-md-9">
+                  401(unauthorized), 403(access forbidden), 404(no such
+                  instance), 500(internal service error), 501(unimplemented)
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Response format</b>
+                  <pre>
+{
+    "msg": &lt;success-or-error-msg&gt;
+}
+                            </pre
+                  >
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Examples</b>
+                </div>
+              </div>
+            </div>
+          </div>
+        </li>
+
+        <!--########################
+    Update A Single Instance
+#########################-->
+
+        <!--########################
+    Query Target Instances By AssoField
+#########################-->
+        <li class="list-group-item"><b>Relational-instance Queries:</b></li>
+
+        <!--########################
+            This side is composition asso target,
+            the asso field only have one value
+        #########################-->
+        <li class="list-group-item">
+          <div class="row">
+            <div class="col-md-1">
+              <span class="label label-success">GET</span>
+            </div>
+            <div class="col-md-5" style="word-wrap: break-word">
+              /rest/apv/network/qos/QosSession/&lt;qossession_id&gt;/interface
+            </div>
+            <div class="col-md-5">
+              Query the info of the corresponding Interface.
+            </div>
+            <div class="col-md-1">
+              <button
+                class="btn btn-info btn-sm btn-detail"
+                data-target="#detail-qossession-asso-interface"
+                data-toggle="collapse"
+                id="detail-qossession-asso-interface-btn"
+              >
+                detail
+              </button>
+            </div>
+          </div>
+          <div id="detail-qossession-asso-interface" class="row collapse">
+            <div class="col-md-12">
+              <div class="row">
+                <div class="col-md-3"><b>Normal response codes</b></div>
+                <div class="col-md-9">200(OK)</div>
+              </div>
+              <div class="row">
+                <div class="col-md-3"><b>Error response codes</b></div>
+                <div class="col-md-9">
+                  401(unauthorized), 403(access forbidden), 404(no such
+                  instance), 500(internal service error), 501(unimplemented)
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12">
+                  <b>Request parameters</b>
+                  <table class="table table-bordered table-striped">
+                    <thead>
+                      <tr>
+                        <th>Parameter</th>
+                        <th>Type</th>
+                        <th>Description</th>
+                      </tr>
+                    </thead>
+                    <tbody>
+                      <tr>
+                        <td>instance_id</td>
+                        <td>URI</td>
+                        <td>ID of the instance</td>
+                      </tr>
+                    </tbody>
+
+                    <tbody></tbody>
+                  </table>
+
+                  <b>Response format</b>
+                  <pre>
+{
+    "QosSession": {
+        "instance_id":&lt;instance_id&gt;,
+        "interface":&lt;value&gt;
+    }
+}
+                            </pre
+                  >
+                </div>
+              </div>
+              <div class="row">
+                <div class="col-md-12"><b>Examples</b></div>
+                <div class="col-md-12"><b></b></div>
+              </div>
+            </div>
+          </div>
+        </li>
+        <!--########################
+            This side is composition asso,
+            the asso field have a list of values
+        #########################-->
+      </ul>
+    </div>
+  </body>
+</html>
Index: /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_classifier.c
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_classifier.c	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_classifier.c	(working copy)
@@ -52,6 +52,7 @@
 #include <click/app/qos/qos_var.h>
 #include <click/app/qos/qos_scheduler.h>
 #include <click/app/qos/qos_classifier.h>
+#include <click/app/qos/qos_session.h>
 
 #include <click/app/fastlog/fastlog.h>
 
@@ -804,6 +805,7 @@
 		return QOS_FAILURE;
 	}
 
+	fastlog_syslog(LOG_DEBUG, "Creating QoS filter \"%s\"\n", qos_filter->fltr_name);
 	/*
 	 * Get queue information from queue name.
 	 */
@@ -1142,12 +1144,12 @@
 
 	if(strlen(fltr_name) == 0) {
 		app_printf(pcb, "ERROR: The input name is illegal, it can not be an empty string\n");
-		return QOS_SUCCESS;
+		return QOS_FAILURE;
 	}
 
 	if(strlen(fltr_name) >= QOS_FLTR_NLEN) {
 		app_printf(pcb, "ERROR: The input name is too long, maximum is %d\n", QOS_FLTR_NLEN-1);
-		return QOS_SUCCESS;
+		return QOS_FAILURE;
 	}
 
 	if((fltr_name[0] == 'a' || fltr_name[0] == 'A') &&
@@ -1155,7 +1157,7 @@
 			(fltr_name[2] == 'l' || fltr_name[2] == 'L') &&
 			strlen(fltr_name) == 3) {
 		app_printf(pcb, "ERROR: \"%s\" is reserved for system\n", fltr_name);
-		return QOS_SUCCESS;
+		return QOS_FAILURE;
 	}
 
 	snprintf(fltr.fltr_name, QOS_FLTR_NLEN, "%s", fltr_name);
@@ -1163,18 +1165,18 @@
 
 	if (!clickrule_mask(smask) ) {
 		app_printf(pcb, "ERROR: invalid source mask\n");
-		return QOS_SUCCESS;
+		return QOS_FAILURE;
 	} else if(!clickrule_mask(dmask)) {
 		app_printf(pcb, "ERROR: invalid destination mask\n");
-		return QOS_SUCCESS;
+		return QOS_FAILURE;
 	}
 
 	if ((sip & smask) != sip) {
 		app_printf(pcb, "ERROR: invalid source ip and mask pair\n");
-		return QOS_SUCCESS;
+		return QOS_FAILURE;
 	} else if ((dip & dmask) != dip) {
 		app_printf(pcb, "ERROR: invalid destination ip and mask pair\n");
-		return QOS_SUCCESS;
+		return QOS_FAILURE;
 	}
 
 	if ((strcmp(proto_str, PROTO_TCP_STR) == 0)) {
@@ -1186,7 +1188,7 @@
 	} else {
 		app_printf(pcb, "ERROR: invalid protocol string, please use %s, %s or %s\n",
 				PROTO_TCP_STR, PROTO_UDP_STR, PROTO_ANY_STR);
-		return QOS_SUCCESS;
+		return QOS_FAILURE;
 	}
 
 	fltr.tp.proto = proto;
@@ -1206,7 +1208,8 @@
 	fltr.priority = pri;
 
 	if(QOS_FAILURE == qos_filter_add(pcb, &fltr)) {
-		/*app_printf(pcb, "Fail to add filter\n");*/
+		app_printf(pcb, "Failed to add the filter.\n");
+		return QOS_FAILURE;
 	}
 
 	return QOS_SUCCESS;
@@ -1223,6 +1226,8 @@
 {
 	QOS_CHECK_LICENSE;
 
+	fastlog_syslog(LOG_DEBUG, "Deleting QoS filter \"%s\"\n", fltr_name);
+
 	if(QOS_FAILURE == qos_filter_del(pcb, fltr_name)) {
 		qos_filter_share.fltr_g_stats.count_del_table_fail++;
 		/*app_printf(pcb, "Fail to delete filter\n");*/
@@ -1288,6 +1293,10 @@
 			}
 		}
 
+		if (!strncmp(pfltr->fltr_name, FILTER_NAME_PREFIX_FOR_SESSION_BASED_QOS, strlen(FILTER_NAME_PREFIX_FOR_SESSION_BASED_QOS))) {
+			continue;
+		}
+
 		isfound = 1;
 
 		smask.s_addr = pfltr->tp.smask;
Index: /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_scheduler.h
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_scheduler.h	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_scheduler.h	(working copy)
@@ -19,6 +19,7 @@
 #define QOSD_OUTPUT_STR	"OUT"
 #define QOSD_INPUT_STR	"IN"
 #define QOSD_ANY_STR	"ANY"
+#define QOSD_BIDIRECTION_STR	"Both"
 #define QOSD_STR_MAXLEN	4
 
 #define QOSD_IO_DEFAULT	QOSD_OUTPUT_STR
Index: /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_scheduler.c
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_scheduler.c	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_scheduler.c	(working copy)
@@ -54,6 +54,7 @@
 #include <click/app/qos/qos_var.h>
 #include <click/app/qos/qos_scheduler.h>
 #include <click/app/qos/qos_classifier.h>
+#include <click/app/qos/qos_session.h>
 
 #include <click/app/qos/altq_var.h>
 #include <click/app/qos/altq_cbq.h>
@@ -694,6 +695,8 @@
 	pQoSQRoot = (qos_queue_root_t *)pRoot;
 	pALTQConf = (struct altq_conf *)pALTQ;
 
+	fastlog_syslog(LOG_DEBUG, "Creating QoS queue \"%s\"\n", pQoSQRoot->sQName);
+
 	/* Check default */
 	if (pALTQConf->pq_u.cbq_opts.flags & CBQCLF_DEFCLASS) {
 		iErrCode = qos_has_default_kern(pcb, pALTQConf->ifname, pALTQConf->direction);
@@ -827,6 +830,8 @@
 
 	QOS_CHECK_LICENSE;
 
+	fastlog_syslog(LOG_DEBUG, "Deleting QoS Queue \"%s\"\n", sQueue);
+
 	bzero(&confALTQ, sizeof(confALTQ));
 	bzero(&infoQoSQueue, sizeof(infoQoSQueue));
 
@@ -1563,6 +1568,10 @@
 			}
 		}
 
+		if (!strncmp(pQoSQRoot->sQName, Q_NAME_PREFIX_FOR_SESSION_BASED_QOS, strlen(Q_NAME_PREFIX_FOR_SESSION_BASED_QOS))) {
+			continue;
+		}
+
 		isfound = 1;
 
 		app_printf(pcb, "qos queue root \"%s\" \"%s\" %s %s %d %s %s\n",
@@ -1653,6 +1662,10 @@
 	/* show_qos_queue_sub_kern(pcb, QOS_NAME_FOR_ALL); */
 
 	STAILQ_FOREACH(pQoSQRoot, &qos_queue_root_head, list_entry) {
+        if (!strncmp(pQoSQRoot->sQName, Q_NAME_PREFIX_FOR_SESSION_BASED_QOS, strlen(Q_NAME_PREFIX_FOR_SESSION_BASED_QOS))) {
+            continue;
+        }
+
 		app_printf(pcb, "qos queue root \"%s\" \"%s\" %s %s %d %s %s\n",
 				pQoSQRoot->sQName, pQoSQRoot->sIfName, pQoSQRoot->sDir,
 				pQoSQRoot->sBand, pQoSQRoot->iPri, pQoSQRoot->sBorrow,
@@ -1663,7 +1676,6 @@
 			if(strcmp(pQoSQRoot->sQName, pQoSQSub->sQRoot)) {
 				continue;
 			}
-
 			app_printf(pcb, "    %s \"%s\" \"%s\" %s %d %s %s\n", "qos queue sub",
 					pQoSQSub->sQName, pQoSQSub->sParent,pQoSQSub->sBand,
 					pQoSQSub->iPri, pQoSQSub->sBorrow, pQoSQSub->sDefault);
Index: /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_session.h
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_session.h	(revision 0)
+++ /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_session.h	(working copy)
@@ -0,0 +1,31 @@
+#include <click/app/kernelapi/kernelapi.h>
+#include <click/app/qos/qos_var.h>
+#include <click/app/qos/qos_scheduler.h>
+#include <click/netinet/click_rule.h>
+
+#define SESSION_BASED_QOS_NLEN 15
+
+#define QOS_MAX_SESSION_NUM 20
+
+#define Q_NAME_PREFIX_FOR_SESSION_BASED_QOS "q_sess"
+#define FILTER_NAME_PREFIX_FOR_SESSION_BASED_QOS "f_sess"
+
+typedef struct session_queue {
+    char sIfName[QOS_CANAME_MAXLEN];
+    char sDir[QOSD_STR_MAXLEN + 1];
+    char sBand[QOS_BANDWIDTH_MAXLEN];
+} session_queue_t;
+
+
+/* for qos filter commands */
+typedef struct session_qos_conf {
+    char name[SESSION_BASED_QOS_NLEN + 1];
+    unsigned int no_of_hosts;
+    session_queue_t session_q_info;
+    clickrule_5tuple_t tp;
+    STAILQ_ENTRY(session_qos_conf) list_entry;
+} session_qos_conf_t;
+
+STAILQ_HEAD(session_qos_conf_head, session_qos_conf);
+
+extern struct session_qos_conf_head session_qos_conf_head;
Index: /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_session.c
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_session.c	(revision 0)
+++ /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_session.c	(working copy)
@@ -0,0 +1,234 @@
+#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_session.h>
+
+#define PROTO_TCP_STR "tcp"
+#define PROTO_UDP_STR "udp"
+#define PROTO_ANY_STR "any"
+
+#define QOS_QNAME_SIZE  32
+#define QOS_FLTR_NLEN  32
+#define NET_BYTES 16
+
+static int qos_session_group_count(void);
+
+struct session_qos_conf_head session_qos_conf_head = STAILQ_HEAD_INITIALIZER(session_qos_conf_head);
+
+
+/* Calculate current session group count */
+static int qos_session_group_count(void)
+{
+    session_qos_conf_t *qos_session_node = NULL;
+    int n_count = 0;
+
+    STAILQ_FOREACH(qos_session_node, &session_qos_conf_head, list_entry) {
+        n_count++;
+    }
+
+    return(n_count);
+}
+
+/******************************************************************************
+ *  *  CLI interfaces of qos session
+ *   *  Add.
+ *    *
+ *     *  return: QOS_SUCCESS, success; QOS_USERLAND_FAILURE,failure.
+ *      ******************************************************************************/
+int session_qos_kern(void *pcb, void * qos_session_node, int32_t qos_session_len)
+{
+    session_qos_conf_t *session_qos_save = NULL;
+    session_qos_conf_t *session_qos_data = NULL;
+    uint32_t proto;
+
+/* Check qos session group number */
+    if (qos_session_group_count() >= QOS_MAX_SESSION_NUM) {
+        app_printf(pcb, "ERROR: too many QoS session groups configured (maximum %d)\n", QOS_MAX_SESSION_NUM);
+        return(QOS_USERLAND_FAILURE);
+    }
+
+    session_qos_save = (session_qos_conf_t *)qos_session_node;
+
+    session_qos_data = (session_qos_conf_t *)malloc(sizeof(session_qos_conf_t), M_QOS, M_NOWAIT | M_ZERO);
+    if (session_qos_data == NULL) {
+        app_printf(pcb, "memory allocation failed for session based QOS node.\n");
+        return(QOS_USERLAND_FAILURE);
+    }
+
+
+    memcpy(session_qos_data, session_qos_save, sizeof(session_qos_conf_t));
+
+    STAILQ_INSERT_TAIL(&session_qos_conf_head, session_qos_data, list_entry);
+    return 0;
+}
+
+void handle_session_qos_cleanup (void *pcb, char *name, int n_hosts, char *sDir) {
+    char q_name[QOS_QNAME_SIZE];
+    char filter_name[QOS_FLTR_NLEN];
+    int j;
+    
+
+    if ((strcasecmp(sDir, QOSD_OUTPUT_STR) == 0) || (strcasecmp(sDir, QOSD_BIDIRECTION_STR) == 0) )
+    {
+        for (j = n_hosts; j >= 0; j--) {
+            sprintf(filter_name, "%s_%s_%d_%s", FILTER_NAME_PREFIX_FOR_SESSION_BASED_QOS, name, j, QOSD_OUTPUT_STR);
+            sprintf(q_name, "%s_%s_%d_%s", Q_NAME_PREFIX_FOR_SESSION_BASED_QOS, name, j, QOSD_OUTPUT_STR);
+            no_qos_filter_kern(pcb, filter_name);
+            no_qos_queue_root_kern(pcb, q_name);
+        }
+    }
+    if ((strcasecmp(sDir, QOSD_INPUT_STR) == 0) || (strcasecmp(sDir, QOSD_BIDIRECTION_STR) == 0) )
+    {
+        for (j = n_hosts; j >= 0; j--) {
+            sprintf(filter_name, "%s_%s_%d_%s", FILTER_NAME_PREFIX_FOR_SESSION_BASED_QOS, name, j, QOSD_INPUT_STR);
+            sprintf(q_name, "%s_%s_%d_%s", Q_NAME_PREFIX_FOR_SESSION_BASED_QOS, name, j, QOSD_INPUT_STR);
+            no_qos_filter_kern(pcb, filter_name);
+            no_qos_queue_root_kern(pcb, q_name);
+        }
+    }
+}
+
+int no_session_qos_kern(void *pcb, char *pName)
+{
+    char *dir;
+    int no_of_hosts;
+
+    session_qos_conf_t *qos_conf_node = NULL;
+
+    fastlog_syslog(LOG_DEBUG, "Attempt to delete session QoS : %s\n", pName);
+
+    QOS_CHECK_LICENSE;
+
+    STAILQ_FOREACH(qos_conf_node, &session_qos_conf_head, list_entry) {
+        if (strcmp(pName, qos_conf_node->name) == 0) {
+            break;
+        }
+    }
+
+    if (qos_conf_node == NULL) {
+        app_printf(pcb, "Session QoS not found!\n");
+        return QOS_SUCCESS;
+    }
+
+    no_of_hosts = qos_conf_node->no_of_hosts;
+    dir = qos_conf_node->session_q_info.sDir;
+
+    handle_session_qos_cleanup (pcb, pName, no_of_hosts - 1, dir);
+
+    STAILQ_REMOVE(&session_qos_conf_head, qos_conf_node, session_qos_conf, list_entry);
+    free(qos_conf_node, M_QOS);
+    return QOS_SUCCESS;
+}
+
+
+int qos_session_clear_all(void *pcb)
+{
+    char *dir;
+    int no_of_hosts;
+
+    session_qos_conf_t *qos_conf_node = NULL;
+
+    fastlog_syslog(LOG_DEBUG, "attempt to delete all QoS sessions.\n");
+
+    QOS_CHECK_LICENSE;
+
+    STAILQ_FOREACH(qos_conf_node, &session_qos_conf_head, list_entry) {
+        no_of_hosts = qos_conf_node->no_of_hosts;
+        dir = qos_conf_node->session_q_info.sDir;
+
+        handle_session_qos_cleanup (pcb, qos_conf_node->name, no_of_hosts - 1, dir);
+
+        STAILQ_REMOVE(&session_qos_conf_head, qos_conf_node, session_qos_conf, list_entry);
+        free(qos_conf_node, M_QOS);
+    }
+    return QOS_SUCCESS;
+}
+
+
+int show_session_qos_kern(void *pcb, char *pName)
+{
+    int isfound;
+    int i;
+    struct in_addr smask, dmask;
+    char sip_str[NET_BYTES], smsk_str[NET_BYTES], dip_str[NET_BYTES], dmsk_str[NET_BYTES], pro_str[NET_BYTES];
+
+    session_qos_conf_t *qos_conf_run = NULL;
+
+    QOS_CHECK_LICENSE;
+
+    isfound = 0;
+    STAILQ_FOREACH(qos_conf_run, &session_qos_conf_head, list_entry) {
+        /* check session qos name */
+        if(strcmp(pName, qos_conf_run->name) && strncmp(pName, QOS_NAME_FOR_ALL, sizeof(QOS_NAME_FOR_ALL))) {
+            continue;
+        }
+
+        isfound = 1;
+
+        smask.s_addr = qos_conf_run->tp.smask;
+        dmask.s_addr = qos_conf_run->tp.dmask;
+        snprintf(sip_str, NET_BYTES, "%s", inet_ntoa(qos_conf_run->tp.sip));
+        snprintf(smsk_str, NET_BYTES, "%s", inet_ntoa(smask));
+        snprintf(dip_str, NET_BYTES, "%s", inet_ntoa(qos_conf_run->tp.dip));
+        snprintf(dmsk_str, NET_BYTES, "%s", inet_ntoa(dmask));
+
+        if(IPPROTO_TCP == qos_conf_run->tp.proto) {
+            snprintf(pro_str, NET_BYTES, "%s", PROTO_TCP_STR);
+        }
+        else if(IPPROTO_UDP == qos_conf_run->tp.proto) {
+            snprintf(pro_str, NET_BYTES, "%s", PROTO_UDP_STR);
+        }
+        else if(IPPROTO_IP == qos_conf_run->tp.proto) {
+            snprintf(pro_str, NET_BYTES, "%s", PROTO_ANY_STR);
+        }
+        else {
+            sprintf(pro_str, "%s", "ERROR");
+        }
+
+        app_printf(pcb,  "qos session \"%s\" %s %s %s %s %s %d %s %s %d %s\n", qos_conf_run->name, qos_conf_run->session_q_info.sIfName, qos_conf_run->session_q_info.sDir, qos_conf_run->session_q_info.sBand, sip_str, smsk_str, ntohs(qos_conf_run->tp.sport), dip_str, dmsk_str, ntohs(qos_conf_run->tp.dport), pro_str);
+
+    }
+
+    if(!isfound && strncmp(pName, QOS_NAME_FOR_ALL, sizeof(QOS_NAME_FOR_ALL))) {
+        app_printf(pcb, "No such session QoS entry found!");
+    }
+
+    return QOS_SUCCESS;
+}
+
+int is_duplicate_session_qos_name(void *pcb, char *name)
+{
+    session_qos_conf_t *qos_conf_run = NULL;
+
+    STAILQ_FOREACH(qos_conf_run, &session_qos_conf_head, list_entry) {
+        /* check session qos name */
+        if(!strcmp(name, qos_conf_run->name)) {
+            return(QOS_USERLAND_FAILURE);
+        }
+    }
+    return QOS_SUCCESS;
+}
Index: /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_subr.c
===================================================================
--- /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_subr.c	(revision 37853)
+++ /tags/Rel_APV_10_4_0_112_1/usr/src/sys/click/app/qos/qos_subr.c	(working copy)
@@ -52,6 +52,7 @@
 #include <click/app/qos/qos_var.h>
 #include <click/app/qos/qos_scheduler.h>
 #include <click/app/qos/qos_classifier.h>
+#include <click/app/qos/qos_session.h>
 #include <click/app/qos/altq_classq.h>
 #include <click/app/qos/altq_rmclass.h>
 #include <click/app/qos/altq_cbq.h>
@@ -67,6 +68,8 @@
 #define QOS_INDENT_2 "        "
 #define QOS_INDENT_3 "            "
 
+#define NET_BYTES 16
+
 /* QoS license */
 int qos_license = 0;
 
@@ -366,6 +369,8 @@
  ******************************************************************************/
 int clear_qos_all_kern(void *pcb)
 {
+
+    qos_session_clear_all(pcb);
     /* bug 14949, qiuzj, http qos */
     clear_qos_http_url(pcb);
     
@@ -394,7 +399,7 @@
 	qos_queue_root_t *pQoSQRoot = NULL;
 	qos_queue_sub_t *pQoSQSub = NULL;
 	struct in_addr smask, dmask;
-	char sip_str[16], smsk_str[16],dip_str[16], dmsk_str[16], pro_str[16];
+	char sip_str[NET_BYTES], smsk_str[NET_BYTES],dip_str[NET_BYTES], dmsk_str[NET_BYTES], pro_str[NET_BYTES];
     
      http_qos_rule_t *rule_p;
 
@@ -463,6 +468,9 @@
 			if(strcmp(pQoSIfConf->sHwIf, pQoSQRoot->sHwIf)) {
 				continue;
 			}
+			if (!strncmp(pQoSQRoot->sQName, Q_NAME_PREFIX_FOR_SESSION_BASED_QOS, strlen(Q_NAME_PREFIX_FOR_SESSION_BASED_QOS))) {
+				continue;
+			}
 
 			app_printf(pcb, "%sqos queue root \"%s\" \"%s\" %s %s %d %s %s\n",
 					QOS_INDENT_1, pQoSQRoot->sQName, pQoSQRoot->sIfName, pQoSQRoot->sDir,
@@ -479,22 +487,22 @@
 
 				smask.s_addr = pfltr->tp.smask;
 				dmask.s_addr = pfltr->tp.dmask;
-				snprintf(sip_str, 16, "%s", inet_ntoa(pfltr->tp.sip));
-				snprintf(smsk_str, 16, "%s", inet_ntoa(smask));
-				snprintf(dip_str, 16, "%s", inet_ntoa(pfltr->tp.dip));
-				snprintf(dmsk_str, 16, "%s", inet_ntoa(dmask));
+				snprintf(sip_str, NET_BYTES, "%s", inet_ntoa(pfltr->tp.sip));
+				snprintf(smsk_str, NET_BYTES, "%s", inet_ntoa(smask));
+				snprintf(dip_str, NET_BYTES, "%s", inet_ntoa(pfltr->tp.dip));
+				snprintf(dmsk_str, NET_BYTES, "%s", inet_ntoa(dmask));
 
 				if(IPPROTO_TCP == pfltr->tp.proto) {
-					snprintf(pro_str, 16, "%s", PROTO_TCP_STR);
+					snprintf(pro_str, NET_BYTES, "%s", PROTO_TCP_STR);
 				}
 				else if(IPPROTO_UDP == pfltr->tp.proto) {
-					snprintf(pro_str, 16, "%s", PROTO_UDP_STR);
+					snprintf(pro_str, NET_BYTES, "%s", PROTO_UDP_STR);
 				}
 				else if(IPPROTO_IP == pfltr->tp.proto) {
-					snprintf(pro_str, 16, "%s", PROTO_ANY_STR);
+					snprintf(pro_str, NET_BYTES, "%s", PROTO_ANY_STR);
 				}
 				else {
-					snprintf(pro_str, 16, "%s", "ERROR");
+					snprintf(pro_str, NET_BYTES, "%s", "ERROR");
 				}
 
 				app_printf(pcb, "%sqos filter \"%s\" \"%s\" %s %s %d %s %s %d %s %d\n",
@@ -535,22 +543,22 @@
 					}
 					smask.s_addr = pfltr->tp.smask;
 					dmask.s_addr = pfltr->tp.dmask;
-					snprintf(sip_str, 16, "%s", inet_ntoa(pfltr->tp.sip));
-					snprintf(smsk_str, 16, "%s", inet_ntoa(smask));
-					snprintf(dip_str, 16, "%s", inet_ntoa(pfltr->tp.dip));
-					snprintf(dmsk_str, 16, "%s", inet_ntoa(dmask));
+					snprintf(sip_str, NET_BYTES, "%s", inet_ntoa(pfltr->tp.sip));
+					snprintf(smsk_str, NET_BYTES, "%s", inet_ntoa(smask));
+					snprintf(dip_str, NET_BYTES, "%s", inet_ntoa(pfltr->tp.dip));
+					snprintf(dmsk_str, NET_BYTES, "%s", inet_ntoa(dmask));
 
 					if(IPPROTO_TCP == pfltr->tp.proto) {
-						snprintf(pro_str, 16, "%s", PROTO_TCP_STR);
+						snprintf(pro_str, NET_BYTES, "%s", PROTO_TCP_STR);
 					}
 					else if(IPPROTO_UDP == pfltr->tp.proto) {
-						snprintf(pro_str, 16, "%s", PROTO_UDP_STR);
+						snprintf(pro_str, NET_BYTES, "%s", PROTO_UDP_STR);
 					}
 					else if(IPPROTO_IP == pfltr->tp.proto) {
-						snprintf(pro_str, 16, "%s", PROTO_ANY_STR);
+						snprintf(pro_str, NET_BYTES, "%s", PROTO_ANY_STR);
 					}
 					else {
-						snprintf(pro_str, 16, "%s", "ERROR");
+						snprintf(pro_str, NET_BYTES, "%s", "ERROR");
 					}
 
 					app_printf(pcb, "%sqos filter \"%s\" \"%s\" %s %s %d %s %s %d %s %d\n",
@@ -581,6 +589,10 @@
 		return QOS_USERLAND_FAILURE;
 	}
 
+	if (name_for_all && dir_for_any) {
+		show_session_qos_kern (pcb, QOS_NAME_FOR_ALL);
+	}
+
 	return QOS_SUCCESS;
 }
 
@@ -753,7 +765,7 @@
 	qos_filter_t *pfltr;
 	int i;
 	struct in_addr smask, dmask;
-	char sip_str[16], smsk_str[16],dip_str[16], dmsk_str[16], pro_str[16];
+	char sip_str[NET_BYTES], smsk_str[NET_BYTES],dip_str[NET_BYTES], dmsk_str[NET_BYTES], pro_str[NET_BYTES];
 
 	/*
 	 * qos filter len
@@ -817,6 +829,10 @@
 	 * write qos queue root
 	 */
 	STAILQ_FOREACH(pQoSQRoot, &qos_queue_root_head, list_entry) {
+		if (!strncmp(pQoSQRoot->sQName, Q_NAME_PREFIX_FOR_SESSION_BASED_QOS, strlen(Q_NAME_PREFIX_FOR_SESSION_BASED_QOS))) {
+			continue;
+		}
+
 		cur += sprintf(cur, "qos queue root \"%s\" \"%s\" %s %s %d %s %s\n",
 				pQoSQRoot->sQName, pQoSQRoot->sIfName, pQoSQRoot->sDir,
 				pQoSQRoot->sBand, pQoSQRoot->iPri, pQoSQRoot->sBorrow,
@@ -842,25 +858,28 @@
 		if(!pfltr->used) {
 			continue;
 		}
+		if (!strncmp(pfltr->fltr_name, FILTER_NAME_PREFIX_FOR_SESSION_BASED_QOS, strlen(FILTER_NAME_PREFIX_FOR_SESSION_BASED_QOS))) {
+			continue;
+		}
 
 		smask.s_addr = pfltr->tp.smask;
 		dmask.s_addr = pfltr->tp.dmask;
-		snprintf(sip_str, 16, "%s", inet_ntoa(pfltr->tp.sip));
-		snprintf(smsk_str, 16, "%s", inet_ntoa(smask));
-		snprintf(dip_str, 16, "%s", inet_ntoa(pfltr->tp.dip));
-		snprintf(dmsk_str, 16, "%s", inet_ntoa(dmask));
+		snprintf(sip_str, NET_BYTES, "%s", inet_ntoa(pfltr->tp.sip));
+		snprintf(smsk_str, NET_BYTES, "%s", inet_ntoa(smask));
+		snprintf(dip_str, NET_BYTES, "%s", inet_ntoa(pfltr->tp.dip));
+		snprintf(dmsk_str, NET_BYTES, "%s", inet_ntoa(dmask));
 
 		if(IPPROTO_TCP == pfltr->tp.proto) {
-			snprintf(pro_str, 16, "%s", PROTO_TCP_STR);
+			snprintf(pro_str, NET_BYTES, "%s", PROTO_TCP_STR);
 		}
 		else if(IPPROTO_UDP == pfltr->tp.proto) {
-			snprintf(pro_str, 16, "%s", PROTO_UDP_STR);
+			snprintf(pro_str, NET_BYTES, "%s", PROTO_UDP_STR);
 		}
 		else if(IPPROTO_IP == pfltr->tp.proto) {
-			snprintf(pro_str, 16, "%s", PROTO_ANY_STR);
+			snprintf(pro_str, NET_BYTES, "%s", PROTO_ANY_STR);
 		}
 		else {
-			snprintf(pro_str, 16, "%s", "ERROR");
+			snprintf(pro_str, NET_BYTES, "%s", "ERROR");
 		}
 
 		cur += sprintf(cur, "qos filter \"%s\" \"%s\" %s %s %d %s %s %d %s %d\n",
@@ -878,3 +897,58 @@
 	return QOS_SUCCESS;
 }
 
+
+int write_qos_session_kern(void *pcb, void **config_data, int *length) {
+    unsigned int len;
+    char *cur, *buffer;
+    struct in_addr smask, dmask;
+    char sip_str[NET_BYTES], smsk_str[NET_BYTES], dip_str[NET_BYTES], dmsk_str[NET_BYTES], pro_str[NET_BYTES];
+
+    session_qos_conf_t *qos_conf_run = NULL;
+
+    /* QoS session command format */
+    char qos_session_cmd[] = "qos session xxxxxx xxx xxxxxxxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxxxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxxxx xxxxx";
+
+    len = (sizeof(qos_session_cmd) + SESSION_BASED_QOS_NLEN + 1) * QOS_MAX_SESSION_NUM;
+
+    MALLOC(buffer, char *, len, M_TEMP, M_NOWAIT);
+
+    if (NULL == buffer) {
+        app_printf(pcb, "ERROR: out of memory for session buffer size %d(%lld)\n", len, (long long int)(uintptr_t) buffer);
+        return QOS_FAILURE;
+    }
+
+    bzero(buffer, len);
+    cur = buffer;
+    STAILQ_FOREACH(qos_conf_run, &session_qos_conf_head, list_entry) {
+        smask.s_addr = qos_conf_run->tp.smask;
+        dmask.s_addr = qos_conf_run->tp.dmask;
+        snprintf(sip_str, NET_BYTES, "%s", inet_ntoa(qos_conf_run->tp.sip));
+        snprintf(smsk_str, NET_BYTES, "%s", inet_ntoa(smask));
+        snprintf(dip_str, NET_BYTES, "%s", inet_ntoa(qos_conf_run->tp.dip));
+        snprintf(dmsk_str, NET_BYTES, "%s", inet_ntoa(dmask));
+
+        if(IPPROTO_TCP == qos_conf_run->tp.proto) {
+            snprintf(pro_str, NET_BYTES, "%s", PROTO_TCP_STR);
+        }
+        else if(IPPROTO_UDP == qos_conf_run->tp.proto) {
+            snprintf(pro_str, NET_BYTES, "%s", PROTO_UDP_STR);
+        }
+        else if(IPPROTO_IP == qos_conf_run->tp.proto) {
+            snprintf(pro_str, NET_BYTES, "%s", PROTO_ANY_STR);
+        }
+        else {
+            snprintf(pro_str, NET_BYTES, "%s", "ERROR");
+        }
+
+        cur += sprintf (cur, "qos session \"%s\" %s %s %s %s %s %d %s %s %d %s\n", qos_conf_run->name,
+             qos_conf_run->session_q_info.sIfName, qos_conf_run->session_q_info.sDir,
+             qos_conf_run->session_q_info.sBand, sip_str, smsk_str, ntohs(qos_conf_run->tp.sport), dip_str, dmsk_str,
+             ntohs(qos_conf_run->tp.dport), pro_str);
+
+    }
+    *length = cur - buffer + 1; /* Add 1 for the NULL character */
+    *config_data = buffer;
+
+    return QOS_SUCCESS;
+}
