Index: /branches/rel_apv_10_7/usr/click/webui/htdocs/new/src/hive/model/ajax.py
===================================================================
--- /branches/rel_apv_10_7/usr/click/webui/htdocs/new/src/hive/model/ajax.py	(revision 40033)
+++ /branches/rel_apv_10_7/usr/click/webui/htdocs/new/src/hive/model/ajax.py	(working copy)
@@ -373,8 +373,12 @@
             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'])    
+        node_mod = get_model('apv', ['loadbalancing', 'slb', 'node', 'Node'])
         mark_expire_all(node_mod)
+        if output:
+            # We suppose output of CLI is empty if deletion is successful,
+            # so if there is any output, we should return json string to show pop-up message.
+            output = json.dumps([False, output])
         return output
 
     def get_delete_error_msg(self, e_dict):
Index: /branches/rel_apv_10_7/usr/src/sys/click/app/proxy/proxy_errs.h
===================================================================
--- /branches/rel_apv_10_7/usr/src/sys/click/app/proxy/proxy_errs.h	(revision 40033)
+++ /branches/rel_apv_10_7/usr/src/sys/click/app/proxy/proxy_errs.h	(working copy)
@@ -1441,6 +1441,8 @@
 #define ERR_SLBN_CANNOT_MODIFY    (ERR_SLBN + 136)
 #define ERR_SLBN_CANNOT_MODIFY_MSG "The virtual server or real servers can't be modified."
 
+#define ERR_SLBN_RS_INVALID_OPT        (ERR_SLBN + 137)
+#define ERR_SLBN_RS_INVALID_OPT_MSG    "Real service cannot be deleted because it is attached to one or more policies.\n"
 
 /*********************** BEGIN RTSP PROXY ERROR MESSAGES ******************/
 #define ERR_RTSP_OK                                 (ERR_RTSP + 0)
Index: /branches/rel_apv_10_7/usr/src/sys/click/app/slb/slb_kern.h
===================================================================
--- /branches/rel_apv_10_7/usr/src/sys/click/app/slb/slb_kern.h	(revision 40033)
+++ /branches/rel_apv_10_7/usr/src/sys/click/app/slb/slb_kern.h	(working copy)
@@ -75,7 +75,7 @@
 #define SLB_FREE(var, malloc_type) free(var)
 #define SLB_KMEM_ALLOC(var, type, size) var = (type)malloc(size) 
 #define SLB_KMEM_ALLOC_SHARED(var, type, size) var = (type)malloc(size) 
-#define SLB_KMEM_FREE(var, size)  free(var)
+#define SLB_KMEM_FREE(var, size)  free(var)
 #define SLB_KMEM_FREE_SHARED(var)  free(var)
 #endif
 
@@ -709,22 +709,25 @@
 char *get_raw_double_quote_string(char *str);
 char *escape_double_quote_string(char *str);
 int  slb_find_session_body(struct frame *body_first_p, struct frame *body_last_p, 
-                      int chunked, slb_group_persistent_body_t * persistent_body_p,
-                      char ** persistence_value);
-char* write_http2_option_kern(char* buf, char* name);
-char *write_slb_virtual_settings_proxy_protocol(char* buf);
-char *write_slb_group_settings_proxy_protocol(char *buf);
-char *write_segment_slb_virtual_settings_proxy_protocol(char *buf, uint32_t segment_id, uint32_t action_mode);
-char *write_segment_slb_group_settings_proxy_protocol(char *buf, uint32_t segment_id, uint32_t action_mode);
-int get_slb_proxy_protocol_num(void);
-
-char* write_segment_http2_option_kern(char* buf, char* segment_name, int action_mode);
-char* write_slb_snmp_static_real_kern(char* buf, char* name);
-char* write_slb_snmp_static_virtual_kern(char* buf, char* name);
+                      int chunked, slb_group_persistent_body_t * persistent_body_p,
+                      char ** persistence_value);
+char* write_http2_option_kern(char* buf, char* name);
+char *write_slb_virtual_settings_proxy_protocol(char* buf);
+char *write_slb_group_settings_proxy_protocol(char *buf);
+char *write_segment_slb_virtual_settings_proxy_protocol(char *buf, uint32_t segment_id, uint32_t action_mode);
+char *write_segment_slb_group_settings_proxy_protocol(char *buf, uint32_t segment_id, uint32_t action_mode);
+int get_slb_proxy_protocol_num(void);
+
+char* write_segment_http2_option_kern(char* buf, char* segment_name, int action_mode);
+char* write_slb_snmp_static_real_kern(char* buf, char* name);
+char* write_slb_snmp_static_virtual_kern(char* buf, char* name);
 char* segment_write_slb_snmp_static_virtual_kern(char* buf, char* segment_name, int action_mode);
 char* segment_write_slb_snmp_static_real_kern(char* buf, char* segment_name, int action_mode);
 char *write_slb_sip_persistence_timeout(char *buf);
 
+/* Policy checks for VS deletion in slb_rs_group_kern.c */
+int is_vs_attached_to_policy(char *vs_name);
+
 #ifndef _KERNEL
 
 /* These are CLI function prototypes which are in kernelWrapper.h, but we
Index: /branches/rel_apv_10_7/usr/src/sys/click/app/slb/slb_rs_group_kern.c
===================================================================
--- /branches/rel_apv_10_7/usr/src/sys/click/app/slb/slb_rs_group_kern.c	(revision 40033)
+++ /branches/rel_apv_10_7/usr/src/sys/click/app/slb/slb_rs_group_kern.c	(working copy)
@@ -42,6 +42,7 @@
 #include <click/app/slb/slb.h>
 #include <click/app/slb/slb_interface.h>
 #include <click/app/slb/slb_rs_group.h>
+#include <click/app/slb/slb_vs_policy.h>
 #include <click/app/slb/slb_kern.h>
 #include <click/app/slb/slb_cli_util.h>
 #include <click/app/slb/slb_debug.h>
@@ -263,6 +264,129 @@
 	return -2;
 }
 
+/*
+ * Check if a real service is bound to static policy
+ * rs_name: name of the real service
+ * Returns: 1 if RS is bound to static policy, 0 if not, -1 on error
+ */
+int is_rs_bound_to_static_policy(char *rs_name)
+{
+	int i;
+	uint32_t real_id, avail_real;
+	slb_protocol_e real_proto;
+	slb_vs_t *vs_p = NULL;
+	slb_rs_t *rs_table = slb_get_rs_table();
+
+	if (!rs_name || !rs_table) {
+		return -1;
+	}
+
+	/* Get the real service ID from name */
+	real_id = slb_real_name_to_id(rs_name, &avail_real, &real_proto);
+	if (!SLB_RS_ID_VALID(real_id)) {
+		return -1; /* RS not found */
+	}
+
+	/* Check all virtual services for static policy binding */
+	for (i = 0; i < g_slb_vs_limit; i++) {
+		if (SLB_VS_ID_EMPTY(i)) {
+			continue;
+		}
+		vs_p = &slb_vs_table[i];
+
+		/* Check if this VS has static policy binding to our RS */
+		if (vs_p->static_memb_p && vs_p->static_memb_p->rid == real_id) {
+			return 1; /* RS is bound to static policy */
+		}
+	}
+
+	return 0; /* RS is not bound to any static policy */
+}
+
+/*
+ * Check if a virtual service has any policy attached to it
+ * vs_name: name of the virtual service
+ * Returns: 1 if policy is attached, 0 if not, -1 on error
+ */
+int is_vs_attached_to_policy(char *vs_name)
+{
+	int i, j;
+	slb_vs_t *vs_p = NULL;
+
+	if (!vs_name) {
+		return -1;
+	}
+
+	/* Find the VS and check if it has any policies */
+	for (i = 0; i < g_slb_vs_limit; i++) {
+		if (SLB_VS_ID_EMPTY(i)) {
+			continue;
+		}
+		vs_p = &slb_vs_table[i];
+
+		if (strcmp(vs_p->name, vs_name) == 0) {
+			/* Check standard policies */
+			for (j = 0; j < POLICY_COUNT; j++) {
+				if (!TAILQ_EMPTY(&(vs_p->policy[j]))) {
+					return 1;
+				}
+			}
+
+			/* Check RTSP policies */
+			if (!TAILQ_EMPTY(&(vs_p->rtsp_policy))) {
+				return 1;
+			}
+
+			/* Check default policy */
+			if (SLB_GROUP_ID_VALID(vs_p->default_group_id)) {
+				return 1;
+			}
+
+			/* Check backup policy */
+			if (SLB_GROUP_ID_VALID(vs_p->backup_group_id)) {
+				return 1;
+			}
+
+			/* Check static policy */
+			if (vs_p->static_memb_p) {
+				return 1;
+			}
+
+			return 0; /* VS found but no policies */
+		}
+	}
+
+	return -1; /* VS not found */
+}
+
+/*
+ * Check if a real service is attached to any group
+ * rs_name: name of the real service
+ * Returns: 1 if RS is in any group, 0 if not, -1 on error
+ */
+int is_rs_in_any_group(char *rs_name)
+{
+	uint32_t real_id, avail_real;
+	slb_protocol_e real_proto;
+	slb_rs_t *rs_table = slb_get_rs_table();
+
+	if (!rs_name || !rs_table) {
+		return -1;
+	}
+
+	/* Get the real service ID from name */
+	real_id = slb_real_name_to_id(rs_name, &avail_real, &real_proto);
+	if (!SLB_RS_ID_VALID(real_id)) {
+		return -1; /* RS not found */
+	}
+
+	/* Check if the RS has any membership (is in any group) */
+	if (SLB_MEM_ID_VALID(rs_table[real_id].slb_mem)) {
+		return 1; /* RS is in at least one group */
+	}
+
+	return 0; /* RS is not in any group */
+}
 
 static uint8_t hc_type_ok_kern(void *pcb, uint8_t hc_type, 
                                slb_protocol_e proto, uint32_t timeout);
@@ -1697,11 +1821,39 @@
     uint32_t real_id, avail_real;
     slb_protocol_e real_proto;
     char user_config_name[SLB_NAME_MAX_LEN+1] = {0};
+    int group_check_result;
+    int static_policy_check_result;
+    int has_error = 0;
 
     if (real_name && (get_user_config_name(real_name, user_config_name) != 0)) {
         strlcpy(user_config_name, real_name, sizeof(user_config_name));
     }
     DBPRINT(("no_slb_real_kern(%s)...\n", user_config_name));
+
+    /* Check if the real service is in any group before deletion */
+    group_check_result = is_rs_in_any_group(real_name);
+
+    /* Check if the real service is bound to any static policy before deletion */
+    static_policy_check_result = is_rs_bound_to_static_policy(real_name);
+
+    if (group_check_result == 1) {
+        SLB_PRINTF((pcb, "Error: Cannot delete real service \"%s\" because it is attached to a real service group.\n", user_config_name));
+        SLB_PRINTF((pcb, "Please remove the real service from all groups first using 'no slb group member' command.\n"));
+        DBPRINT(("Error: Cannot delete real service \"%s\" because it is attached to a real service group.\n", user_config_name));
+        has_error = 1;
+    }
+
+    if (static_policy_check_result == 1) {
+        SLB_PRINTF((pcb, "Error: Cannot delete real service \"%s\" because it is bound to a static policy.\n", user_config_name));
+        SLB_PRINTF((pcb, "Please remove the static policy binding first using 'no slb policy static' command.\n"));
+        DBPRINT(("Error: Cannot delete real service \"%s\" because it is bound to a static policy.\n", user_config_name));
+        has_error = 1;
+    }
+
+    if (has_error) {
+        return ERR_SLBN_RS_INVALID_OPT;
+    }
+
 #ifdef _KERNEL
     OA_rs_update = 1;
 #endif
Index: /branches/rel_apv_10_7/usr/src/sys/click/app/slb/slb_vs_policy_kern.c
===================================================================
--- /branches/rel_apv_10_7/usr/src/sys/click/app/slb/slb_vs_policy_kern.c	(revision 40033)
+++ /branches/rel_apv_10_7/usr/src/sys/click/app/slb/slb_vs_policy_kern.c	(working copy)
@@ -5034,6 +5034,22 @@
 			return ERR_SLBN_ORCHE_VS_HAS_ATTACH_ORCHE;
 		}
 
+		/* Check if the virtual service has any policy attached before deletion */
+		{
+			int policy_check_result;
+			policy_check_result = is_vs_attached_to_policy(name);
+			if (policy_check_result == 1) {
+				if (get_user_config_name(name, user_config_name) == 0) {
+					SLB_PRINTF((pcb, "Error: Cannot delete virtual service \"%s\" because it has policies attached.\n", user_config_name));
+				} else {
+					SLB_PRINTF((pcb, "Error: Cannot delete virtual service \"%s\" because it has policies attached.\n", name));
+				}
+				SLB_PRINTF((pcb, "Please remove all attached policies first using 'no slb policy' commands.\n"));
+				DBPRINT(("Error: Cannot delete virtual service \"%s\" because it has policies attached.\n", name));
+				return ERR_SLBN_VS_INVALID_OPT;
+			}
+		}
+
 		if ((!(vs_p->flags & (SLB_VS_DISABLED | SLB_VS_FAILED))) &&
 			 vs_p->port != 0) {
 			/* One less app listening on this port */
