diff --git a/simics-workspace/modules/afdxES/binary-search.dml b/simics-workspace/modules/afdxES/binary-search.dml
index cb40fb2..094271c 100644
--- a/simics-workspace/modules/afdxES/binary-search.dml
+++ b/simics-workspace/modules/afdxES/binary-search.dml
@@ -2,157 +2,142 @@ dml 1.2;

 import "config-tables.dml";

-method BinarySearchAnalyseCfgCamArray(analyse_cfg_cam *array, analyse_cfg_cam T) -> (int result)
-{
+//
+// The first parameter is the array looked for
+// The second parameter is the key to search
+// Return the position of the key in the array, if the key not in the array, return -1
+//
+method BinarySearchAnalyseCfgCamArray(analyse_cfg_cam *array, analyse_cfg_cam T) -> (int result) {
 	local int32 low;
-	local int32 high;
+    local int32 high;
     local int32 mid;
-	low = 0;
-	high = ANALYSE_CFG_CAM_MAX_SIZE - 1;
-	while (low <= high)
-	{
+    local bool is_smaller;
+    local bool is_bigger;
+
+    low = 0;
+	high = ANALYSE_CFG_CAM_MAX_SIZE - 1; // fix me!
+
+	while (low <= high) {
 		mid = (low + high) / 2;
-		local bool compare_result;
-		inline $is_smaller_analyse(array, mid, T) -> (compare_result);
-		if (compare_result)
-		{
+		inline $is_smaller_analyse(T, array, mid) -> (is_smaller);
+		if (is_smaller) {
 			high = mid - 1;
-		}
-		else
-		{
-			inline $is_bigger_analyse(array, mid, T) -> (compare_result);
-			if (compare_result)
-			{
+		} else {
+			inline $is_bigger_analyse(T, array, mid) -> (is_bigger);
+			if (is_bigger) {
 				low = mid + 1;
-			}
-			else
-			{
-			    result = array[mid].address;
+			} else {
+			    result = mid;
                 return;
 		    }
 		}
 	}
+
 	result = -1;
 }

-method is_bigger_analyse(analyse_cfg_cam *L, int position, analyse_cfg_cam pivotkey) -> (bool result)
-{
-	if (cast(L[position].cam_data_part1, uint28) > cast(pivotkey.cam_data_part1, uint28))
-	{
-		result = true;
-	}
-	else if (cast(L[position].cam_data_part1, uint28) < cast(pivotkey.cam_data_part1, uint28))
-	{
-		result = false;
-	}
-	else
-	{
-		if (cast(L[position].cam_data_part2, uint32) > cast(pivotkey.cam_data_part2, uint32))
-		{
-			result = true;
-		}
-		else if (cast(L[position].cam_data_part2, uint32) < cast(pivotkey.cam_data_part2, uint32))
-		{
-			result = false;
-		}
-		else
-		{
-			if (cast(L[position].cam_data_part3, uint32) >= cast(pivotkey.cam_data_part3, uint32))
-			{
-				result = true;
-			} else
-			{
-				result = false;
-			}
-		}
-	}
+//
+// if pivotkey > L[position] return true, else return false
+//
+method is_bigger_analyse(analyse_cfg_cam pivotkey, analyse_cfg_cam *L, int position) -> (bool result) {
+    if (pivotkey.cam_data_part1.MULTICAST_ID == 0) { // unicast
+        if (cast(pivotkey.cam_data_part2, uint32) > cast(L[position].cam_data_part2, uint32)) {
+            result = true;
+        } else if (cast(pivotkey.cam_data_part2, uint32) == cast(L[position].cam_data_part2, uint32)) {
+            if (cast(pivotkey.cam_data_part3, uint32) > cast(L[position].cam_data_part3, uint32)) {
+                result = true;
+            } else {
+                result = false;
+            }
+        } else {
+            result = false;
+        }
+    } else {                    // multicast
+        if (cast(pivotkey.cam_data_part3, uint32) > cast(L[position].cam_data_part3, uint32)) {
+            result = true;
+        } else {
+            result = false;
+        }
+    }
 }
-
-method is_smaller_analyse(analyse_cfg_cam *L, int position, analyse_cfg_cam pivotkey) -> (bool result)
-{
-	if (cast(L[position].cam_data_part1, uint28) > cast(pivotkey.cam_data_part1, uint28))
-	{
-		result = false;
-	}
-	else if (cast(L[position].cam_data_part1, uint28) < cast(pivotkey.cam_data_part1, uint28))
-	{
-		result = true;
-	}
-	else
-	{
-		if (cast(L[position].cam_data_part2, uint32) > cast(pivotkey.cam_data_part2, uint32))
-		{
-			result = false;
-		}
-		else if (cast(L[position].cam_data_part2, uint32) < cast(pivotkey.cam_data_part2, uint32))
-		{
-			result = true;
-		}
-		else
-		{
-			if (cast(L[position].cam_data_part3, uint32) >= cast(pivotkey.cam_data_part3, uint32))
-			{
-				result = false;
-			}
-			else
-			{
-				result = true;
-			}
-		}
-	}
+
+//
+// if pivotkey < L[position] return true, else return false
+//
+method is_smaller_analyse(analyse_cfg_cam pivotkey, analyse_cfg_cam *L, int position) -> (bool result) {
+    if (pivotkey.cam_data_part1.MULTICAST_ID == 0) { // unicast
+        if (cast(pivotkey.cam_data_part2, uint32) < cast(L[position].cam_data_part2, uint32)) {
+            result = true;
+        } else if (cast(pivotkey.cam_data_part2, uint32) == cast(L[position].cam_data_part2, uint32)) {
+            if (cast(pivotkey.cam_data_part3, uint32) < cast(L[position].cam_data_part3, uint32)) {
+                result = true;
+            } else {
+                result = false;
+            }
+        } else {
+            result = false;
+        }
+    } else {                    // multicast
+        if (cast(pivotkey.cam_data_part3, uint32) < cast(L[position].cam_data_part3, uint32)) {
+            result = true;
+        } else {
+            result = false;
+        }
+    }
 }

-method BinarySearchRMCfgCamArray(rm_cfg_cam *array, rm_cfg_cam T) -> (int result)
-{
+//
+// The first parameter is the array looked for
+// The second parameter is the key to search
+// Return the position of the key in the array, if the key not in the array, return -1
+//
+method BinarySearchRMCfgCamArray(rm_cfg_cam *array, rm_cfg_cam T) -> (int result) {
 	local int32 low;
-	local int32 high;
+    local int32 high;
     local int32 mid;
+    local bool is_smaller;
+    local bool is_bigger;
+
 	low = 0;
-	high = RM_CFG_CAM_MAX_SIZE - 1;
-	while (low <= high)
-	{
+	high = RM_CFG_CAM_MAX_SIZE - 1; // fix me
+
+	while (low <= high)	{
 		mid = (low + high) / 2;
-		local bool compare_result;
-		inline $is_smaller_rm(array, mid, T) -> (compare_result);
-		if (compare_result)
-		{
+		inline $is_smaller_rm(T, array, mid) -> (is_smaller); // T < array[mid] ?
+		if (is_smaller) {
 			high = mid - 1;
-		}
-		else
-		{
-			inline $is_bigger_rm(array, mid, T) -> (compare_result);
-			if (compare_result)
-			{
+		} else {
+			inline $is_bigger_rm(T, array, mid) -> (is_bigger); // T > array[mid] ?
+			if (is_bigger) {
 				low = mid + 1;
-			}
-			else
-			{
-			    result = array[mid].address;
+			} else {
+			    result = mid;
                 return;
 		    }
 		}
 	}
+
 	result = -1;
 }

-method is_bigger_rm(rm_cfg_cam *L, int position, rm_cfg_cam pivotkey) -> (bool result)
-{
-	if (L[position].VL_ID > pivotkey.VL_ID)
-	{
+//
+// if pivotkey > L[position] return true, else return false
+//
+method is_bigger_rm(rm_cfg_cam pivotkey, rm_cfg_cam *L, int position) -> (bool result) {
+	if (pivotkey.VL_ID > L[position].VL_ID) {
 		result = true;
-	} else
-	{
+	} else {
 		result = false;
 	}
 }

-method is_smaller_rm(rm_cfg_cam *L, int position, rm_cfg_cam pivotkey) -> (bool result)
-{
-	if (L[position].VL_ID >= pivotkey.VL_ID)
-	{
-		result = false;
-	} else
-	{
+//
+// if pivotkey < L[position] return true, else return false
+//
+method is_smaller_rm(rm_cfg_cam pivotkey, rm_cfg_cam *L, int position) -> (bool result) {
+	if (pivotkey.VL_ID < L[position].VL_ID) {
 		result = true;
+	} else {
+		result = false;
 	}
 }
diff --git a/simics-workspace/modules/afdxES2/binary-search.dml b/simics-workspace/modules/afdxES2/binary-search.dml
index d275339..094271c 100644
--- a/simics-workspace/modules/afdxES2/binary-search.dml
+++ b/simics-workspace/modules/afdxES2/binary-search.dml
@@ -2,140 +2,142 @@ dml 1.2;

 import "config-tables.dml";

+//
+// The first parameter is the array looked for
+// The second parameter is the key to search
+// Return the position of the key in the array, if the key not in the array, return -1
+//
 method BinarySearchAnalyseCfgCamArray(analyse_cfg_cam *array, analyse_cfg_cam T) -> (int result) {
 	local int32 low;
-	local int32 high;
+    local int32 high;
     local int32 mid;
-	low = 0;
-	high = ANALYSE_CFG_CAM_MAX_SIZE - 1;
+    local bool is_smaller;
+    local bool is_bigger;
+
+    low = 0;
+	high = ANALYSE_CFG_CAM_MAX_SIZE - 1; // fix me!
+
 	while (low <= high) {
-		log "info" :"low=%d ,high=%d",low,high;
 		mid = (low + high) / 2;
-		local bool compare_result;
-		inline $is_smaller_analyse(array, mid, T) -> (compare_result);
-		if (compare_result) {
+		inline $is_smaller_analyse(T, array, mid) -> (is_smaller);
+		if (is_smaller) {
 			high = mid - 1;
 		} else {
-			inline $is_bigger_analyse(array, mid, T) -> (compare_result);
-			if (compare_result) {
+			inline $is_bigger_analyse(T, array, mid) -> (is_bigger);
+			if (is_bigger) {
 				low = mid + 1;
 			} else {
 			    result = mid;
+                return;
 		    }
 		}
 	}
+
 	result = -1;
 }

-method is_bigger_analyse(analyse_cfg_cam *L, int position, analyse_cfg_cam pivotkey) -> (bool result) {
-	if (cast(L[position].cam_data_part1, uint28) > cast(pivotkey.cam_data_part1, uint28)) {
-		result = true;
-	} else if (cast(L[position].cam_data_part1, uint28) < cast(pivotkey.cam_data_part1, uint28)) {
-		result = false;
-	} else {
-		if (cast(L[position].cam_data_part2, uint32) > cast(pivotkey.cam_data_part2, uint32)) {
-			result = true;
-		} else if (cast(L[position].cam_data_part2, uint32) < cast(pivotkey.cam_data_part2, uint32)) {
-			result = false;
-		} else {
-			if (cast(L[position].cam_data_part3, uint32) > cast(pivotkey.cam_data_part3, uint32)) {
-				result = true;
-			} else {
-				result = false;
-			}
-		}
-	}
+//
+// if pivotkey > L[position] return true, else return false
+//
+method is_bigger_analyse(analyse_cfg_cam pivotkey, analyse_cfg_cam *L, int position) -> (bool result) {
+    if (pivotkey.cam_data_part1.MULTICAST_ID == 0) { // unicast
+        if (cast(pivotkey.cam_data_part2, uint32) > cast(L[position].cam_data_part2, uint32)) {
+            result = true;
+        } else if (cast(pivotkey.cam_data_part2, uint32) == cast(L[position].cam_data_part2, uint32)) {
+            if (cast(pivotkey.cam_data_part3, uint32) > cast(L[position].cam_data_part3, uint32)) {
+                result = true;
+            } else {
+                result = false;
+            }
+        } else {
+            result = false;
+        }
+    } else {                    // multicast
+        if (cast(pivotkey.cam_data_part3, uint32) > cast(L[position].cam_data_part3, uint32)) {
+            result = true;
+        } else {
+            result = false;
+        }
+    }
 }
-
-method is_smaller_analyse(analyse_cfg_cam *L, int position, analyse_cfg_cam pivotkey) -> (bool result) {
-	if (cast(L[position].cam_data_part1, uint28) > cast(pivotkey.cam_data_part1, uint28)) {
-		result = false;
-	} else if (cast(L[position].cam_data_part1, uint28) < cast(pivotkey.cam_data_part1, uint28)) {
-		result = true;
-	} else {
-		if (cast(L[position].cam_data_part2, uint32) > cast(pivotkey.cam_data_part2, uint32)) {
-			result = false;
-		} else if (cast(L[position].cam_data_part2, uint32) < cast(pivotkey.cam_data_part2, uint32)) {
-			result = true;
-		} else {
-			if (cast(L[position].cam_data_part3, uint32) >= cast(pivotkey.cam_data_part3, uint32)) {
-				result = false;
-			} else {
-				result = true;
-			}
-		}
-	}
+
+//
+// if pivotkey < L[position] return true, else return false
+//
+method is_smaller_analyse(analyse_cfg_cam pivotkey, analyse_cfg_cam *L, int position) -> (bool result) {
+    if (pivotkey.cam_data_part1.MULTICAST_ID == 0) { // unicast
+        if (cast(pivotkey.cam_data_part2, uint32) < cast(L[position].cam_data_part2, uint32)) {
+            result = true;
+        } else if (cast(pivotkey.cam_data_part2, uint32) == cast(L[position].cam_data_part2, uint32)) {
+            if (cast(pivotkey.cam_data_part3, uint32) < cast(L[position].cam_data_part3, uint32)) {
+                result = true;
+            } else {
+                result = false;
+            }
+        } else {
+            result = false;
+        }
+    } else {                    // multicast
+        if (cast(pivotkey.cam_data_part3, uint32) < cast(L[position].cam_data_part3, uint32)) {
+            result = true;
+        } else {
+            result = false;
+        }
+    }
 }

-method BinarySearchRMCfgCamArray(rm_cfg_cam *array, rm_cfg_cam T) -> (int result)
-{
+//
+// The first parameter is the array looked for
+// The second parameter is the key to search
+// Return the position of the key in the array, if the key not in the array, return -1
+//
+method BinarySearchRMCfgCamArray(rm_cfg_cam *array, rm_cfg_cam T) -> (int result) {
 	local int32 low;
-	local int32 high;
+    local int32 high;
     local int32 mid;
+    local bool is_smaller;
+    local bool is_bigger;
+
 	low = 0;
-	high = $rm_cfg_cam_index - 1;
-
-		log "info" : "========================= 1 rm_cfg_cam begin ========================";
-		local int32 i;
-		for(i=0;i<32;i++)
-			log "info" : "$rm_cfg_cam_array[%d].VL_ID = %d", i, $rm_cfg_cam_array[i].VL_ID;
-		log "info" : "=========================1 rm_cfg_cam  end ========================";
-
-		log "info": "T ================";
-		log "info" : "T.VL_ID = %d",  T.VL_ID;
-		log "info": "T ================";
-
-
-	while (low <= high)
-	{
-		log "info" :"low=%d ,high=%d",low,high;
+	high = RM_CFG_CAM_MAX_SIZE - 1; // fix me
+
+	while (low <= high)	{
 		mid = (low + high) / 2;
-		local bool compare_result;
-		inline $is_smaller_rm(array, mid, T) -> (compare_result);
-		if (compare_result)
-		{
-			log "info" :"small!";
+		inline $is_smaller_rm(T, array, mid) -> (is_smaller); // T < array[mid] ?
+		if (is_smaller) {
 			high = mid - 1;
-		}
-		else
-		{
-			log "info" :"big!";
-			inline $is_bigger_rm(array, mid, T) -> (compare_result);
-			if (compare_result)
-			{
+		} else {
+			inline $is_bigger_rm(T, array, mid) -> (is_bigger); // T > array[mid] ?
+			if (is_bigger) {
 				low = mid + 1;
-			}
-			else
-			{
-				log "info": "equal ";
+			} else {
 			    result = mid;
-				return ;
+                return;
 		    }
-		}
-
+		}
 	}
+
 	result = -1;
 }

-method is_bigger_rm(rm_cfg_cam *L, int position, rm_cfg_cam pivotkey) -> (bool result)
-{
-	if (L[position].VL_ID > pivotkey.VL_ID)
-	{
+//
+// if pivotkey > L[position] return true, else return false
+//
+method is_bigger_rm(rm_cfg_cam pivotkey, rm_cfg_cam *L, int position) -> (bool result) {
+	if (pivotkey.VL_ID > L[position].VL_ID) {
 		result = true;
-	} else
-	{
+	} else {
 		result = false;
 	}
 }

-method is_smaller_rm(rm_cfg_cam *L, int position, rm_cfg_cam pivotkey) -> (bool result)
-{
-	if (L[position].VL_ID >= pivotkey.VL_ID)
-	{
-		result = false;
-	} else
-	{
+//
+// if pivotkey < L[position] return true, else return false
+//
+method is_smaller_rm(rm_cfg_cam pivotkey, rm_cfg_cam *L, int position) -> (bool result) {
+	if (pivotkey.VL_ID < L[position].VL_ID) {
 		result = true;
-
+	} else {
+		result = false;
 	}
 }
add ignore rule
diff --git a/ChangeLog.org b/ChangeLog.org
index d4577c3..77dfabb 100644
--- a/ChangeLog.org
+++ b/ChangeLog.org
@@ -1,6 +1,6 @@
 # -*- org -*-

-# Time-stamp: <2014-08-04 16:33:56 Monday by tyrion>
+# Time-stamp: <2014-08-04 16:41:31 Monday by tyrion>

 #+OPTIONS: ^:nil author:nil timestamp:nil creator:nil

diff --git a/simics-workspace/modules/afdxES/analyse-binary-search.dml b/simics-workspace/modules/afdxES/analyse-binary-search.dml
index e69de29..afae962 100644
--- a/simics-workspace/modules/afdxES/analyse-binary-search.dml
+++ b/simics-workspace/modules/afdxES/analyse-binary-search.dml
@@ -0,0 +1,87 @@
+dml 1.2;
+
+import "config-tables.dml";
+
+//
+// The first parameter is the array looked for
+// The second parameter is the key to search
+// Return the position of the key in the array, if the key not in the array, return -1
+//
+method BinarySearchAnalyseCfgCamArray(analyse_cfg_cam *array, analyse_cfg_cam T) -> (int result) {
+	local int32 low;
+    local int32 high;
+    local int32 mid;
+    local bool is_smaller;
+    local bool is_bigger;
+
+    low = 0;
+	high = ANALYSE_CFG_CAM_MAX_SIZE - 1; // fix me!
+
+	while (low <= high) {
+		mid = (low + high) / 2;
+		inline $is_smaller_analyse(T, array, mid) -> (is_smaller);
+		if (is_smaller) {
+			high = mid - 1;
+		} else {
+			inline $is_bigger_analyse(T, array, mid) -> (is_bigger);
+			if (is_bigger) {
+				low = mid + 1;
+			} else {
+			    result = mid;
+                return;
+		    }
+		}
+	}
+
+	result = -1;
+}
+
+//
+// if pivotkey > L[position] return true, else return false
+//
+method is_bigger_analyse(analyse_cfg_cam pivotkey, analyse_cfg_cam *L, int position) -> (bool result) {
+    if (pivotkey.cam_data_part1.MULTICAST_ID == 0) { // unicast
+        if (cast(pivotkey.cam_data_part2, uint32) > cast(L[position].cam_data_part2, uint32)) {
+            result = true;
+        } else if (cast(pivotkey.cam_data_part2, uint32) == cast(L[position].cam_data_part2, uint32)) {
+            if (cast(pivotkey.cam_data_part3, uint32) > cast(L[position].cam_data_part3, uint32)) {
+                result = true;
+            } else {
+                result = false;
+            }
+        } else {
+            result = false;
+        }
+    } else {                    // multicast
+        if (cast(pivotkey.cam_data_part3, uint32) > cast(L[position].cam_data_part3, uint32)) {
+            result = true;
+        } else {
+            result = false;
+        }
+    }
+}
+
+//
+// if pivotkey < L[position] return true, else return false
+//
+method is_smaller_analyse(analyse_cfg_cam pivotkey, analyse_cfg_cam *L, int position) -> (bool result) {
+    if (pivotkey.cam_data_part1.MULTICAST_ID == 0) { // unicast
+        if (cast(pivotkey.cam_data_part2, uint32) < cast(L[position].cam_data_part2, uint32)) {
+            result = true;
+        } else if (cast(pivotkey.cam_data_part2, uint32) == cast(L[position].cam_data_part2, uint32)) {
+            if (cast(pivotkey.cam_data_part3, uint32) < cast(L[position].cam_data_part3, uint32)) {
+                result = true;
+            } else {
+                result = false;
+            }
+        } else {
+            result = false;
+        }
+    } else {                    // multicast
+        if (cast(pivotkey.cam_data_part3, uint32) < cast(L[position].cam_data_part3, uint32)) {
+            result = true;
+        } else {
+            result = false;
+        }
+    }
+}
diff --git a/simics-workspace/modules/afdxES/analyse-quick-sort.dml b/simics-workspace/modules/afdxES/analyse-quick-sort.dml
index e69de29..c060916 100644
--- a/simics-workspace/modules/afdxES/analyse-quick-sort.dml
+++ b/simics-workspace/modules/afdxES/analyse-quick-sort.dml
@@ -0,0 +1,93 @@
+dml 1.2;
+
+import "config-tables.dml";
+
+method is_bigger_analyse_(analyse_cfg_cam pivotkey, analyse_cfg_cam *L, int position) -> (bool result) {
+    if (cast(L[position].cam_data_part1, uint28) > cast(pivotkey.cam_data_part1, uint28))
+        result = false;
+    else if (cast(L[position].cam_data_part1, uint28) < cast(pivotkey.cam_data_part1, uint28))
+        result = true;
+    else
+    {
+        if (cast(L[position].cam_data_part2, uint32) > cast(pivotkey.cam_data_part2, uint32))
+            result = false;
+        else if (cast(L[position].cam_data_part2, uint32) < cast(pivotkey.cam_data_part2, uint32))
+            result = true;
+        else
+        {
+            if (cast(L[position].cam_data_part3, uint32) >= cast(pivotkey.cam_data_part3, uint32))
+                result = false;
+            else
+                result = true;
+        }
+    }
+
+}
+
+method is_smaller_analyse_(analyse_cfg_cam pivotkey, analyse_cfg_cam *L, int position) -> (bool result) {
+    if (cast(pivotkey.cam_data_part1, uint28) < cast(L[position].cam_data_part1, uint28)) {
+        result = true;
+    } else if (cast(pivotkey.cam_data_part1, uint28) == cast(L[position].cam_data_part1, uint28)) {
+        if (cast(pivotkey.cam_data_part2, uint32) < cast(L[position].cam_data_part2, uint32)) {
+            result = true;
+        } else if (cast(pivotkey.cam_data_part2, uint32) == cast(L[position].cam_data_part2, uint32)) {
+            if (cast(pivotkey.cam_data_part3, uint32) < cast(L[position].cam_data_part3, uint32))  {
+                result = true;
+            } else {
+                result = false;
+            }
+        } else {
+            result = false;
+        }
+    } else {
+        result = false;
+    }
+}
+
+method swap_analyse_cam_array_item(analyse_cfg_cam *L, int low, int high) {
+    local analyse_cfg_cam tmp = L[low];
+    L[low] = L[high];
+    L[high] = tmp;
+}
+
+method partition_of_analyse_cam_array(analyse_cfg_cam *L, int low, int high) -> (int position) {
+    local analyse_cfg_cam pivotkey;
+    local bool is_bigger;
+    local bool is_smaller;
+
+    pivotkey = L[low];
+
+    while (low < high) {
+        inline $is_bigger_analyse_(pivotkey, L, high) -> (is_bigger);
+        while ((low < high) && !is_bigger) {
+            --high;
+            inline $is_bigger_analyse_(pivotkey, L, high) -> (is_bigger);
+        }
+
+        call $swap_analyse_cam_array_item(L, low, high);
+
+        inline $is_smaller_analyse_(pivotkey, L, low) -> (is_smaller);
+        while ((low < high) && !is_smaller) {
+            ++low;
+            inline $is_smaller_analyse_(pivotkey, L, low) -> (is_smaller);
+        }
+
+        call $swap_analyse_cam_array_item(L, low, high);
+    }
+
+    position = low;
+}
+
+method qsort_analyse_cam_array(analyse_cfg_cam *L, int low, int high) {
+    local int pivot;
+
+    if (low < high) {
+        call $partition_of_analyse_cam_array(L, low, high) -> (pivot);
+        call $qsort_analyse_cam_array(L, low, pivot - 1);
+        call $qsort_analyse_cam_array(L, pivot + 1, high);
+    }
+}
+
+method QuickSortAnalyseCamArray(analyse_cfg_cam *L) {
+    call $qsort_analyse_cam_array(L, 0, $analyse_cfg_cam_index - 1);
+}
diff --git a/simics-workspace/modules/afdxES/binary-search.dml b/simics-workspace/modules/afdxES/binary-search.dml
index 094271c..6d0d94c 100644
--- a/simics-workspace/modules/afdxES/binary-search.dml
+++ b/simics-workspace/modules/afdxES/binary-search.dml
@@ -1,143 +1,6 @@
 dml 1.2;

 import "config-tables.dml";
+import "analyse-binary-search.dml";
+import "rm-binary-search.dml";

-//
-// The first parameter is the array looked for
-// The second parameter is the key to search
-// Return the position of the key in the array, if the key not in the array, return -1
-//
-method BinarySearchAnalyseCfgCamArray(analyse_cfg_cam *array, analyse_cfg_cam T) -> (int result) {
-	local int32 low;
-    local int32 high;
-    local int32 mid;
-    local bool is_smaller;
-    local bool is_bigger;
-
-    low = 0;
-	high = ANALYSE_CFG_CAM_MAX_SIZE - 1; // fix me!
-
-	while (low <= high) {
-		mid = (low + high) / 2;
-		inline $is_smaller_analyse(T, array, mid) -> (is_smaller);
-		if (is_smaller) {
-			high = mid - 1;
-		} else {
-			inline $is_bigger_analyse(T, array, mid) -> (is_bigger);
-			if (is_bigger) {
-				low = mid + 1;
-			} else {
-			    result = mid;
-                return;
-		    }
-		}
-	}
-
-	result = -1;
-}
-
-//
-// if pivotkey > L[position] return true, else return false
-//
-method is_bigger_analyse(analyse_cfg_cam pivotkey, analyse_cfg_cam *L, int position) -> (bool result) {
-    if (pivotkey.cam_data_part1.MULTICAST_ID == 0) { // unicast
-        if (cast(pivotkey.cam_data_part2, uint32) > cast(L[position].cam_data_part2, uint32)) {
-            result = true;
-        } else if (cast(pivotkey.cam_data_part2, uint32) == cast(L[position].cam_data_part2, uint32)) {
-            if (cast(pivotkey.cam_data_part3, uint32) > cast(L[position].cam_data_part3, uint32)) {
-                result = true;
-            } else {
-                result = false;
-            }
-        } else {
-            result = false;
-        }
-    } else {                    // multicast
-        if (cast(pivotkey.cam_data_part3, uint32) > cast(L[position].cam_data_part3, uint32)) {
-            result = true;
-        } else {
-            result = false;
-        }
-    }
-}
-
-//
-// if pivotkey < L[position] return true, else return false
-//
-method is_smaller_analyse(analyse_cfg_cam pivotkey, analyse_cfg_cam *L, int position) -> (bool result) {
-    if (pivotkey.cam_data_part1.MULTICAST_ID == 0) { // unicast
-        if (cast(pivotkey.cam_data_part2, uint32) < cast(L[position].cam_data_part2, uint32)) {
-            result = true;
-        } else if (cast(pivotkey.cam_data_part2, uint32) == cast(L[position].cam_data_part2, uint32)) {
-            if (cast(pivotkey.cam_data_part3, uint32) < cast(L[position].cam_data_part3, uint32)) {
-                result = true;
-            } else {
-                result = false;
-            }
-        } else {
-            result = false;
-        }
-    } else {                    // multicast
-        if (cast(pivotkey.cam_data_part3, uint32) < cast(L[position].cam_data_part3, uint32)) {
-            result = true;
-        } else {
-            result = false;
-        }
-    }
-}
-
-//
-// The first parameter is the array looked for
-// The second parameter is the key to search
-// Return the position of the key in the array, if the key not in the array, return -1
-//
-method BinarySearchRMCfgCamArray(rm_cfg_cam *array, rm_cfg_cam T) -> (int result) {
-	local int32 low;
-    local int32 high;
-    local int32 mid;
-    local bool is_smaller;
-    local bool is_bigger;
-
-	low = 0;
-	high = RM_CFG_CAM_MAX_SIZE - 1; // fix me
-
-	while (low <= high)	{
-		mid = (low + high) / 2;
-		inline $is_smaller_rm(T, array, mid) -> (is_smaller); // T < array[mid] ?
-		if (is_smaller) {
-			high = mid - 1;
-		} else {
-			inline $is_bigger_rm(T, array, mid) -> (is_bigger); // T > array[mid] ?
-			if (is_bigger) {
-				low = mid + 1;
-			} else {
-			    result = mid;
-                return;
-		    }
-		}
-	}
-
-	result = -1;
-}
-
-//
-// if pivotkey > L[position] return true, else return false
-//
-method is_bigger_rm(rm_cfg_cam pivotkey, rm_cfg_cam *L, int position) -> (bool result) {
-	if (pivotkey.VL_ID > L[position].VL_ID) {
-		result = true;
-	} else {
-		result = false;
-	}
-}
-
-//
-// if pivotkey < L[position] return true, else return false
-//
-method is_smaller_rm(rm_cfg_cam pivotkey, rm_cfg_cam *L, int position) -> (bool result) {
-	if (pivotkey.VL_ID < L[position].VL_ID) {
-		result = true;
-	} else {
-		result = false;
-	}
-}
diff --git a/simics-workspace/modules/afdxES/pci-register.dml b/simics-workspace/modules/afdxES/pci-register.dml
index ebb539b..d5687d0 100644
--- a/simics-workspace/modules/afdxES/pci-register.dml
+++ b/simics-workspace/modules/afdxES/pci-register.dml
@@ -1,6 +1,9 @@
 dml 1.2;

-import "pci-device.dml";          // Generic PCI device
+import "pci-device.dml";          // Generic PCI device
+import "binary-search.dml";
+import "quick-sort.dml";
+
 // Basic bank declaration
 bank pci_config {
     // List of base address registers used by the device
@@ -1347,7 +1350,7 @@ bank pciport{
             //if ($mode == 0) {
                 call $write_analyse_cam();
                 log "info"  ,2: "Method write_analyse_cam has been called";
-                call $QuickSort($analyse_cfg_cam_array);
+                call $QuickSortAnalyseCamArray($analyse_cfg_cam_array);
                 log "info"  ,2: "Method QuickSort has been called";
             //} else {
             //    local uint32 length = 4 * 4;
@@ -1390,103 +1393,7 @@ bank pciport{
             }
         }

-		method is_bigger(analyse_cfg_cam *L, int position, analyse_cfg_cam pivotkey) -> (bool result)
-		{
-			if (cast(L[position].cam_data_part1, uint28) > cast(pivotkey.cam_data_part1, uint28))
-				result = true;
-			else if (cast(L[position].cam_data_part1, uint28) < cast(pivotkey.cam_data_part1, uint28))
-				result = false;
-			else
-			{
-				if (cast(L[position].cam_data_part2, uint32) > cast(pivotkey.cam_data_part2, uint32))
-					result = true;
-				else if (cast(L[position].cam_data_part2, uint32) < cast(pivotkey.cam_data_part2, uint32))
-					result = false;
-				else
-				{
-					if (cast(L[position].cam_data_part3, uint32) >= cast(pivotkey.cam_data_part3, uint32))
-						result = true;
-					else
-						result = false;
-				}
-			}
-		}
-
-		method is_smaller(analyse_cfg_cam *L, int position, analyse_cfg_cam pivotkey) -> (bool result)
-		{
-			if (cast(L[position].cam_data_part1, uint28) > cast(pivotkey.cam_data_part1, uint28))
-				result = false;
-			else if (cast(L[position].cam_data_part1, uint28) < cast(pivotkey.cam_data_part1, uint28))
-				result = true;
-			else
-			{
-				if (cast(L[position].cam_data_part2, uint32) > cast(pivotkey.cam_data_part2, uint32))
-					result = false;
-				else if (cast(L[position].cam_data_part2, uint32) < cast(pivotkey.cam_data_part2, uint32))
-					result = true;
-				else
-				{
-					if (cast(L[position].cam_data_part3, uint32) >= cast(pivotkey.cam_data_part3, uint32))
-						result = false;
-					else
-						result = true;
-				}
-			}
-		}
-
-		method swap(analyse_cfg_cam *L, int low, int high)
-		{
-			local analyse_cfg_cam tmp = L[low];
-			L[low] = L[high];
-			L[high] = tmp;
-		}
-
-		method Partition(analyse_cfg_cam *L, int low, int high) -> (int position)
-		{
-			local analyse_cfg_cam pivotkey;
-			pivotkey = L[low];
-
-			while (low < high)
-			{
-			    local bool compare_result;
-			    inline $is_bigger(L, high, pivotkey) -> (compare_result);
-				while ((low < high) && compare_result)
-				{
-					--high;
-					inline $is_bigger(L, high, pivotkey) -> (compare_result);
-				}
-
-				call $swap(L, low, high);
-
-				inline $is_smaller(L, low, pivotkey) -> (compare_result);
-				while ((low < high) && compare_result)
-				{
-				    ++low;
-					inline $is_smaller(L, low, pivotkey) -> (compare_result);
-				}
-
-				call $swap(L, low, high);
-			}
-
-			position = low;
-		}
-
-		method QSort(analyse_cfg_cam *L, int low, int high)
-		{
-			local int pivot;
-
-			if (low < high)
-			{
-				call $Partition(L, low, high) -> (pivot);
-				call $QSort(L, low, pivot - 1);
-			    call $QSort(L, pivot + 1, high);
-			}
-		}
-
-		method QuickSort(analyse_cfg_cam *L)
-		{
-	        call $QSort(L, 0, $analyse_cfg_cam_index - 1);
-        }
+
     }

     register analyse_cfg_ram_addr
@@ -1681,7 +1588,7 @@ bank pciport{
                 log "info" ,2:"rm_cfg_cam_addr";
                 log "info", 2:"rm_cfg_cam_addr = %x",$this;
                 call $write_rm_cam();
-                call $QuickSort($rm_cfg_cam_array);
+                call $QuickSortRMCamArray($rm_cfg_cam_array);
                 // call $print_transfer_table();
             //} else {
             //    local uint32 length = 4 * 2;
@@ -1699,82 +1606,6 @@ bank pciport{
             $rm_cfg_cam_array[$rm_cfg_cam_index].VL_ID = $rm_cfg_cam_data.VL_ID;
             $rm_cfg_cam_index++;
         }
-
-		method is_bigger(rm_cfg_cam *L, int position, rm_cfg_cam pivotkey) -> (bool result)
-		{
-			if (L[position].VL_ID >= pivotkey.VL_ID)
-			{
-				result = true;
-			} else
-			{
-				result = false;
-			}
-		}
-
-		method is_smaller(rm_cfg_cam *L, int position, rm_cfg_cam pivotkey) -> (bool result)
-		{
-			if (L[position].VL_ID >= pivotkey.VL_ID)
-			{
-				result = false;
-			} else
-			{
-				result = true;
-			}
-		}
-
-		method swap(rm_cfg_cam *L, int low, int high)
-		{
-			local rm_cfg_cam tmp = L[low];
-			L[low] = L[high];
-			L[high] = tmp;
-		}
-
-		method Partition(rm_cfg_cam *L, int low, int high) -> (int position)
-		{
-			local rm_cfg_cam pivotkey;
-			pivotkey = L[low];
-
-			while (low < high)
-			{
-			    local bool compare_result;
-			    inline $is_bigger(L, high, pivotkey) -> (compare_result);
-				while ((low < high) && compare_result)
-				{
-					--high;
-					inline $is_bigger(L, high, pivotkey) -> (compare_result);
-				}
-
-				call $swap(L, low, high);
-
-				inline $is_smaller(L, low, pivotkey) -> (compare_result);
-				while ((low < high) && compare_result)
-				{
-				    ++low;
-					inline $is_smaller(L, low, pivotkey) -> (compare_result);
-				}
-
-				call $swap(L, low, high);
-			}
-
-			position = low;
-		}
-
-		method QSort(rm_cfg_cam *L, int low, int high)
-		{
-			local int pivot;
-
-			if (low < high)
-			{
-				call $Partition(L, low, high) -> (pivot);
-				call $QSort(L, low, pivot - 1);
-			    call $QSort(L, pivot + 1, high);
-			}
-		}
-
-		method QuickSort(rm_cfg_cam *L)
-		{
-	        call $QSort(L, 0, $rm_cfg_cam_index - 1);
-        }
     }

     register rm_cfg_ram_addr
diff --git a/simics-workspace/modules/afdxES/quick-sort.dml b/simics-workspace/modules/afdxES/quick-sort.dml
index e69de29..83f5dfc 100644
--- a/simics-workspace/modules/afdxES/quick-sort.dml
+++ b/simics-workspace/modules/afdxES/quick-sort.dml
@@ -0,0 +1,4 @@
+dml 1.2;
+
+import "analyse-quick-sort.dml";
+import "rm-quick-sort.dml";
diff --git a/simics-workspace/modules/afdxES/rm-binary-search.dml b/simics-workspace/modules/afdxES/rm-binary-search.dml
index e69de29..e7630e0 100644
--- a/simics-workspace/modules/afdxES/rm-binary-search.dml
+++ b/simics-workspace/modules/afdxES/rm-binary-search.dml
@@ -0,0 +1,59 @@
+dml 1.2;
+
+import "config-tables.dml";
+
+//
+// The first parameter is the array looked for
+// The second parameter is the key to search
+// Return the position of the key in the array, if the key not in the array, return -1
+//
+method BinarySearchRMCfgCamArray(rm_cfg_cam *array, rm_cfg_cam T) -> (int result) {
+	local int32 low;
+    local int32 high;
+    local int32 mid;
+    local bool is_smaller;
+    local bool is_bigger;
+
+	low = 0;
+	high = RM_CFG_CAM_MAX_SIZE - 1; // fix me
+
+	while (low <= high)	{
+		mid = (low + high) / 2;
+		inline $is_smaller_rm(T, array, mid) -> (is_smaller); // T < array[mid] ?
+		if (is_smaller) {
+			high = mid - 1;
+		} else {
+			inline $is_bigger_rm(T, array, mid) -> (is_bigger); // T > array[mid] ?
+			if (is_bigger) {
+				low = mid + 1;
+			} else {
+			    result = mid;
+                return;
+		    }
+		}
+	}
+
+	result = -1;
+}
+
+//
+// if pivotkey > L[position] return true, else return false
+//
+method is_bigger_rm(rm_cfg_cam pivotkey, rm_cfg_cam *L, int position) -> (bool result) {
+	if (pivotkey.VL_ID > L[position].VL_ID) {
+		result = true;
+	} else {
+		result = false;
+	}
+}
+
+//
+// if pivotkey < L[position] return true, else return false
+//
+method is_smaller_rm(rm_cfg_cam pivotkey, rm_cfg_cam *L, int position) -> (bool result) {
+	if (pivotkey.VL_ID < L[position].VL_ID) {
+		result = true;
+	} else {
+		result = false;
+	}
+}
diff --git a/simics-workspace/modules/afdxES/rm-quick-sort.dml b/simics-workspace/modules/afdxES/rm-quick-sort.dml
index e69de29..47c6be3 100644
--- a/simics-workspace/modules/afdxES/rm-quick-sort.dml
+++ b/simics-workspace/modules/afdxES/rm-quick-sort.dml
@@ -0,0 +1,74 @@
+dml 1.2;
+
+import "config-tables.dml";
+
+//
+// if pivotkey > L[position] return true, else return false
+//
+method is_bigger_rm_(rm_cfg_cam pivotkey, rm_cfg_cam *L, int position) -> (bool result) {
+	if (pivotkey.VL_ID > L[position].VL_ID) {
+		result = true;
+	} else {
+		result = false;
+	}
+}
+
+//
+// if pivotkey < L[position] return true, else return false
+//
+method is_smaller_rm_(rm_cfg_cam pivotkey, rm_cfg_cam *L, int position) -> (bool result) {
+	if (pivotkey.VL_ID < L[position].VL_ID) {
+		result = true;
+	} else {
+		result = false;
+	}
+}
+
+
+method swap_rm_cam_array_item(rm_cfg_cam *L, int low, int high) {
+    local rm_cfg_cam tmp = L[low];
+    L[low] = L[high];
+    L[high] = tmp;
+}
+
+method partition_of_rm_cam_array(rm_cfg_cam *L, int low, int high) -> (int position) {
+    local rm_cfg_cam pivotkey;
+    local bool is_bigger;
+    local bool is_smaller;
+
+    pivotkey = L[low];
+
+    while (low < high) {
+        inline $is_bigger_rm_(pivotkey, L, high) -> (is_bigger);
+        while ((low < high) && !is_bigger) {
+            --high;
+            inline $is_bigger_rm_(pivotkey, L, high) -> (is_bigger);
+        }
+
+        call $swap_rm_cam_array_item(L, low, high);
+
+        inline $is_smaller_rm_(pivotkey, L, low) -> (is_smaller);
+        while ((low < high) && !is_smaller) {
+            ++low;
+            inline $is_smaller_rm_(pivotkey, L, low) -> (is_smaller);
+        }
+
+        call $swap_rm_cam_array_item(L, low, high);
+    }
+
+    position = low;
+}
+
+method qsort_rm_cam_array(rm_cfg_cam *L, int low, int high) {
+    local int pivot;
+
+    if (low < high) {
+        call $partition_of_rm_cam_array(L, low, high) -> (pivot);
+        call $qsort_rm_cam_array(L, low, pivot - 1);
+        call $qsort_rm_cam_array(L, pivot + 1, high);
+    }
+}
+
+method QuickSortRMCamArray(rm_cfg_cam *L) {
+    call $qsort_rm_cam_array(L, 0, $rm_cfg_cam_index - 1);
+}
add refactor log
fix ignore rule
diff --git a/simics-workspace/modules/afdxES/analyse-binary-search.dml b/simics-workspace/modules/afdxES/analyse-binary-search.dml
index afae962..51ee6ab 100644
--- a/simics-workspace/modules/afdxES/analyse-binary-search.dml
+++ b/simics-workspace/modules/afdxES/analyse-binary-search.dml
@@ -15,7 +15,7 @@ method BinarySearchAnalyseCfgCamArray(analyse_cfg_cam *array, analyse_cfg_cam T)
     local bool is_bigger;

     low = 0;
-	high = ANALYSE_CFG_CAM_MAX_SIZE - 1; // fix me!
+	high = $analyse_cfg_cam_index - 1;

 	while (low <= high) {
 		mid = (low + high) / 2;
diff --git a/simics-workspace/modules/afdxES/config-tables-log.dml b/simics-workspace/modules/afdxES/config-tables-log.dml
index e69de29..fe1c18c 100644
--- a/simics-workspace/modules/afdxES/config-tables-log.dml
+++ b/simics-workspace/modules/afdxES/config-tables-log.dml
@@ -0,0 +1,15 @@
+dml 1.2;
+
+import "config-tables.dml";
+
+method print_analyse_cfg_cam_table() {
+    local uint8 i = 0;
+    for (; i < $analyse_cfg_cam_index; ++i) {
+        log "info" : "The $analyse_cfg_cam_array[%d].cam_data_part1.RETENTION = %d", i, $analyse_cfg_cam_array[i].cam_data_part1.RETENTION;
+        log "info" : "The $analyse_cfg_cam_array[%d].cam_data_part1.ICMP_TYPE_ID = %d", i, $analyse_cfg_cam_array[i].cam_data_part1.ICMP_TYPE_ID;
+        log "info" : "The $analyse_cfg_cam_array[%d].cam_data_part1.MULTICAST_ID = %d", i, $analyse_cfg_cam_array[i].cam_data_part1.MULTICAST_ID;
+        log "info" : "The $analyse_cfg_cam_array[%d].cam_data_part2.DEST_IP = %d", i, $analyse_cfg_cam_array[i].cam_data_part2.DEST_IP;
+        log "info" : "The $analyse_cfg_cam_array[%d].cam_data_part3.VL = %d", i, $analyse_cfg_cam_array[i].cam_data_part3.VL;
+        log "info" : "The $analyse_cfg_cam_array[%d].cam_data_part3.DEST_UDP = %d", i, $analyse_cfg_cam_array[i].cam_data_part3.DEST_UDP;
+    }
+}
diff --git a/simics-workspace/modules/afdxES/log.dml b/simics-workspace/modules/afdxES/log.dml
index e69de29..352fd25 100644
--- a/simics-workspace/modules/afdxES/log.dml
+++ b/simics-workspace/modules/afdxES/log.dml
@@ -0,0 +1,3 @@
+dml 1.2;
+
+import "config-tables-log.dml";
diff --git a/simics-workspace/modules/afdxES/pci-register.dml b/simics-workspace/modules/afdxES/pci-register.dml
index d5687d0..b705daa 100644
--- a/simics-workspace/modules/afdxES/pci-register.dml
+++ b/simics-workspace/modules/afdxES/pci-register.dml
@@ -3,6 +3,7 @@ dml 1.2;
 import "pci-device.dml";          // Generic PCI device
 import "binary-search.dml";
 import "quick-sort.dml";
+import "log.dml";

 // Basic bank declaration
 bank pci_config {
@@ -1348,10 +1349,12 @@ bank pciport{
 		    log "info" ,2: "before write_analyse_cam##########################################################";
 			log "info" ,2:"analyse_cfg_cam_addr =%x",$this;
             //if ($mode == 0) {
-                call $write_analyse_cam();
-                log "info"  ,2: "Method write_analyse_cam has been called";
-                call $QuickSortAnalyseCamArray($analyse_cfg_cam_array);
-                log "info"  ,2: "Method QuickSort has been called";
+            call $write_analyse_cam();
+            log "info"  ,2: "Method write_analyse_cam has been called";
+            call $QuickSortAnalyseCamArray($analyse_cfg_cam_array);
+            log "info"  ,2: "Method QuickSort has been called";
+            call $print_analyse_cfg_cam_table();
+
             //} else {
             //    local uint32 length = 4 * 4;
              //   local uint8 *data = new uint8[length];
diff --git a/simics-workspace/modules/afdxES/rm-binary-search.dml b/simics-workspace/modules/afdxES/rm-binary-search.dml
index e7630e0..d6e548f 100644
--- a/simics-workspace/modules/afdxES/rm-binary-search.dml
+++ b/simics-workspace/modules/afdxES/rm-binary-search.dml
@@ -15,7 +15,7 @@ method BinarySearchRMCfgCamArray(rm_cfg_cam *array, rm_cfg_cam T) -> (int result
     local bool is_bigger;

 	low = 0;
-	high = RM_CFG_CAM_MAX_SIZE - 1; // fix me
+	high = $rm_cfg_cam_index - 1; // fix me

 	while (low <= high)	{
 		mid = (low + high) / 2;
diff --git a/simics-workspace/modules/afdxES/unpacket_frame.dml b/simics-workspace/modules/afdxES/unpacket_frame.dml
index 030e977..cff77e2 100644
--- a/simics-workspace/modules/afdxES/unpacket_frame.dml
+++ b/simics-workspace/modules/afdxES/unpacket_frame.dml
@@ -50,7 +50,8 @@ method unpacket_frame(uint8 *buffer,uint32 size)->(RX_MIB rx_mib)
 	T.cam_data_part3.DEST_UDP = dest_udp;
 	//find port through  item group. single has IP dest address ,mulitple hasn't IP dest address

-	call $BinarySearchAnalyseCfgCamArray(($analyse_cfg_cam_array), T) -> (port_id);
+	call $BinarySearchAnalyseCfgCamArray(($analyse_cfg_cam_array), T) -> (port_id);
+    port_id = $analyse_cfg_cam_array[port_id].address;

 	enable_network_A = cast((*(buffer + INTERFACE_ID_ADDR)>>5)&0x1,uint1);
 	enable_network_B = cast((*(buffer + INTERFACE_ID_ADDR)>>6)&0x1,uint1);
add udp header log
refactor
fix quick sort bug
add config-tables-log
test binary search and add mib
fix afdxES2 quick sort and binary search
fix packet frame : interface id << 5
add mac header log, and fix transmit registers
fix rm network enable compare
delete some dirty code
move exchange with 429 middle out of afdxES.dml
refactoring
delete some code
refactoring