diff --git a/simics-workspace/modules/afdxES/config-tables.dml b/simics-workspace/modules/afdxES/config-tables.dml
index 0abcdad..c3ce7ce 100644
--- a/simics-workspace/modules/afdxES/config-tables.dml
+++ b/simics-workspace/modules/afdxES/config-tables.dml
@@ -133,18 +133,6 @@ data fragment_cfg_ram fragment_cfg_ram_array[FRAGMENT_CFG_RAM_MAX_SIZE];
 data uint32 fragment_cfg_ram_index;
 /////////////////////////////////////  fragment_cfg_ram  end  //////////////////////////////////////

-constant ANALYSE_CFG_CAM = 0;
-constant ANALYSE_CFG_RAM = 1;
-constant TRANSMIT_CFG_RAM = 2;
-constant SCHEDULING_CFG_RAM = 3;
-constant RM_CFG_CAM = 4;
-constant RM_CFG_RAM = 5;
-constant FRAGMENT_CFG_RAM = 6;
-constant PACKET_SEND = 7;
-constant PACKET_RECV = 8;
-constant DO_LOAD_CONF = 9;
-constant CFG_TYPE_SIZE = 4;
-constant CFG_NUM = 128;

 method cfg_table_index {
     $analyse_cfg_cam_index = 0;
diff --git a/simics-workspace/modules/afdxES/constant.dml b/simics-workspace/modules/afdxES/constant.dml
index b438b3b..9ae5dd1 100644
--- a/simics-workspace/modules/afdxES/constant.dml
+++ b/simics-workspace/modules/afdxES/constant.dml
@@ -40,7 +40,7 @@ constant SRC_IP_ADDR_LENGTH = 4;
 //for
 constant IP_DEST_ADDR = 30;
 constant UDP_DEST_ADDR = 36;
-constant  VL_ADDR = 4;
+constant VL_ADDR = 4;
 constant MULTICAST_ADDR = IP_DEST_ADDR;
 constant UDP_HEADER_ADDR =34;
 constant MF_ADDR = 20;
@@ -80,6 +80,9 @@ constant RECV_VL_NUM = 256;
 constant To429Middleware = 0;
 constant To664Middleware = 1;

+// for port cache
+constant CACHE_ITEM_MAXSIZE = 10 * 1024;
+constant PORT_CACHE_MAXSIZE = 1024 * 1024;

 data uint32 tx_buf_overflow_number[256];
 data uint32 rx_buf_overflow_number[256];
diff --git a/simics-workspace/modules/afdxES/pci-action.dml b/simics-workspace/modules/afdxES/pci-action.dml
index f560f62..d7ee5b0 100644
--- a/simics-workspace/modules/afdxES/pci-action.dml
+++ b/simics-workspace/modules/afdxES/pci-action.dml
@@ -40,7 +40,7 @@ method transmit() {
             call $wrapped_frame(buf, length);
             break;
         case To664Middleware:
-            // fix me !!!
+            call $Send_Payload_To_664_Middleware(buf, $pciport.tx_port_id.id, $pciport.tx_frame_len.frame_len);
             break;
         default:
             log "error" : "Unsupported work mode";
diff --git a/simics-workspace/modules/afdxES/pci-register.dml b/simics-workspace/modules/afdxES/pci-register.dml
index 70bc434..021a129 100644
--- a/simics-workspace/modules/afdxES/pci-register.dml
+++ b/simics-workspace/modules/afdxES/pci-register.dml
@@ -1315,7 +1315,13 @@ bank pciport{
             if (port_id >= 0 && port_id < 4096) {
                 switch ($port[port_id].port_type) {
                 case 0: case 1:
-                    inline $IsPortQueueEmpty(($port[port_id].queue)) ->(is_empty);
+                    if ($middleware_mode == To429Middleware) {
+                        inline $IsPortQueueEmpty($port[port_id].queue) ->(is_empty);
+                    } else if ($middleware_mode == To664Middleware) {
+                        inline $IsPortCacheEmpty($PortCache[port_id]) ->(is_empty);
+                    } else {
+                        log "info" : "Unsupported work mode!\n";
+                    }
                     break;
                 case 2:
                     inline $IsPortSampleEmpty(&($port[port_id])) -> (is_empty);
@@ -1345,12 +1351,24 @@ bank pciport{
                 local uint32 port_id = $pciport.rx_port_id;
                 local bool is_empty;
                 local PortItem item;
-
+                local Cache_Item item1;
                 if (port_id >= 0 && port_id < 4096) {
-                    inline $DePortQueue(($port[port_id].queue), &item)->(is_empty);
-                    if (is_empty == false) {
-                        log "info" : "queue is empty!";
-                        return;
+                    switch ($middleware_mode) {
+                    case To429Middleware:
+                        inline $DePortQueue($port[port_id].queue, &item)-> (is_empty);
+                        if (is_empty == false) {
+                            return;
+                        }
+                        break;
+                    case To664Middleware:
+                        inline $DePortCache($PortCache[port_id], &item1) -> (is_empty);
+                        if (is_empty == false) {
+                            return;
+                        }
+                        break;
+                    default:
+                        log "info" : "Unsupported work mode!\n";
+                        break;
                     }
                 } else {
                     log "error": "wrong port id";
@@ -1359,21 +1377,31 @@ bank pciport{
                 local exception_type_t ex;
                 local dbuffer_t *dbuf = new_dbuffer();
                 local uint8 *buf;
-                local uint8 i =0;
-                buf = dbuffer_append(dbuf, item.size-8);
-                for (; i < item.size-8; ++i) {
-                    buf[i] = item.frame[i+8];
-                    log "info" : "The buf[%d] = %x", i, buf[i];
+                local uint8 i = 0;
+                if ($middleware_mode == To429Middleware) {
+                    buf = dbuffer_append(dbuf, item.size-8);
+                    for (; i < item.size-8; ++i) {
+                        buf[i] = item.frame[i+8];
+                    }
+
+                    call $pci_data_to_memory(Sim_Addr_Space_Memory,
+                                             buf,
+                                             $pci9056.dmapadr0.padr0,
+                                             item.size-8) -> (ex);
+                } else if ($middleware_mode == To664Middleware) {
+                    /*
+                    buf = dbuffer_append(dbuf, item.size-8);
+                    for (; i < item.size-8; ++i) {
+                        buf[i] = item.frame[i+8];
+                    }
+
+                    call $pci_data_to_memory(Sim_Addr_Space_Memory,
+                                             buf,
+                                             $pci9056.dmapadr0.padr0,
+                                             item.size-8) -> (ex);
+                    */
                 }
-
-                call $pci_data_to_memory(Sim_Addr_Space_Memory,
-                                         buf,
-                                         $pci9056.dmapadr0.padr0,
-                                         item.size-8) -> (ex);
-                log "info": "write to pci memory space";
-                log "info": "The $pci9056.dmasiz0.siz0 is %d", $pci9056.dmasiz0.siz0;
-                log "info" : "The item size is %d", item.size;
-
+
                 dbuffer_free(dbuf);//free dbuf

                 if (ex != Sim_PE_No_Exception) {
diff --git a/simics-workspace/modules/afdxES/port-cache.dml b/simics-workspace/modules/afdxES/port-cache.dml
index e69de29..276064b 100644
--- a/simics-workspace/modules/afdxES/port-cache.dml
+++ b/simics-workspace/modules/afdxES/port-cache.dml
@@ -0,0 +1,85 @@
+dml 1.2;
+
+import "constant.dml";
+
+
+struct Cache_Item {
+    uint8 buffer[CACHE_ITEM_MAXSIZE];
+    uint32 size;
+}
+
+struct Payload {
+    uint8 *buffer;
+    uint32 size;
+    Payload *next;
+}
+
+struct Port_Cache {
+    Payload *head;
+    Payload *tail;
+    uint32 size;
+}
+
+data Port_Cache *PortCache[PORT_SIZE];
+
+method Init_Port_Cache() {
+    local uint32 i = 0;
+    for (; i < PORT_SIZE; ++i) {
+        call InitPortCache() -> ($PortCache[i]);
+    }
+}
+
+method InitPortCache() -> (Port_Cache *port_cache) {
+    local Port_Cache *cache;
+    cache = new Port_Cache;
+    cache->size = 0;
+    cache->head = new Payload;
+    cache->head->next = NULL;
+    cache->tail = cache->head;
+    port_cache = cache;
+}
+
+method EnPortCache(Port_Cache *port_cache, Cache_Item item) -> (bool result) {
+    if (port_cache->size + item.size < PORT_CACHE_MAXSIZE) {
+        port_cache->tail->next = new Payload;
+        port_cache->tail->next->buffer = new uint8[item.size];
+        memcpy(port_cache->tail->next->buffer, item.buffer, item.size);
+        port_cache->tail->next->size = item.size;
+        port_cache->size += item.size;
+        port_cache->tail->next->next = NULL;
+        port_cache->tail = port_cache->tail->next;
+
+        result = true;
+    } else {
+        result = false;
+    }
+}
+
+method DePortCache(Port_Cache *port_cache, Cache_Item *item) -> (bool result) {
+    local Payload *delete_item;
+    local uint32 size;
+
+    if (port_cache->head->next == NULL) {
+        result = false;
+    } else {
+        memcpy(item->buffer, port_cache->head->next->buffer, port_cache->head->next->size);
+        size = port_cache->head->next->size;
+        delete_item = port_cache->head->next;
+        port_cache->head->next = port_cache->head->next->next;
+        if (delete_item == port_cache->tail) {
+            port_cache->tail = port_cache->head;
+        }
+        delete delete_item;
+        port_cache->size -= size;
+        item->size = size;
+        result = true;
+    }
+}
+
+method IsPortCacheEmpty(Port_Cache *port_cache) -> (bool result) {
+    if (port_cache->size == 0) {
+        result = true;
+    } else {
+        result = false;
+    }
+}
diff --git a/simics-workspace/modules/afdxES/tomiddleware.c b/simics-workspace/modules/afdxES/tomiddleware.c
index 5a64230..5033e43 100644
--- a/simics-workspace/modules/afdxES/tomiddleware.c
+++ b/simics-workspace/modules/afdxES/tomiddleware.c
@@ -2,7 +2,7 @@

 SOCKET client_socket;

-int socket_init(void) {
+int Init_664_Work_Mode(void) {
     WSADATA wsa;

     if (WSAStartup(MAKEWORD(2,2), &wsa)) {
@@ -33,7 +33,7 @@ int socket_init(void) {
     return 0;
 }

-int socket_send(unsigned char *sendbuf, int size) {
+int Send_To_664_Middleware(unsigned char *sendbuf, int size) {
     int len = send(client_socket, (char *)sendbuf, size, 0);

     if (len == size) {
@@ -45,7 +45,7 @@ int socket_send(unsigned char *sendbuf, int size) {
     }
 }

-int socket_recv(unsigned char *recvbuf, int size) {
+int Recv_Data_From_664_Middleware(unsigned char *recvbuf, int size) {
     fd_set rfds;
     FD_ZERO(&rfds);
     FD_SET(client_socket, &rfds);
@@ -67,12 +67,22 @@ int socket_recv(unsigned char *recvbuf, int size) {

             len = recv(client_socket, (char *)recvbuf, size, 0);
             if (len > 0) {
-                fprintf(stdout, "Socket recv sucessfully, send %d sizes!\n", len);
+                fprintf(stdout, "Socket recv sucessfully, recv %d size!\n", len);
             } else {
-                fprintf("Socket recv failed, error code is %d.\n", WSAGetLastError());
+                fprintf(stderr, "Socket recv failed, error code is %d.\n", WSAGetLastError());
             }
         }

         return len;
     }
 }
+
+int Recv_Mib_Info_From_664_Middleware(unsigned char *recvbuf, int size) {
+    int len = recv(client_socket, (char *)recvbuf, size, 0);
+    if (len > 0) {
+        fprintf(stdout, "Socket recv successfully, recv %d size!\n", len);
+    } else {
+        fprintf(stderr, "Socket recv failed, error code is %d.\n", WSAGetLastError());
+    }
+    return len;
+}
diff --git a/simics-workspace/modules/afdxES/tomiddleware.dml b/simics-workspace/modules/afdxES/tomiddleware.dml
index 82941d7..0a93bfd 100644
--- a/simics-workspace/modules/afdxES/tomiddleware.dml
+++ b/simics-workspace/modules/afdxES/tomiddleware.dml
@@ -1,25 +1,70 @@
 dml 1.2;

-extern int socket_init(void);
-extern int socket_recv(char *recvbuf, int size);
-extern int socket_send(char *sendbuf, int size);
+import "port-cache.dml";

-method socket_loop_recv() {
+extern int Init_664_Work_Mode(void);
+extern int Send_To_664_Middleware(char *recvbuf, int size);
+extern int Recv_Data_From_664_Middleware(char *sendbuf, int size);
+extern int Recv_Mib_Info_From_664_Middleware(char *recvbuf, int size);
+
+constant ANALYSE_CFG_CAM = 0;
+constant ANALYSE_CFG_RAM = 1;
+constant TRANSMIT_CFG_RAM = 2;
+constant SCHEDULING_CFG_RAM = 3;
+constant RM_CFG_CAM = 4;
+constant RM_CFG_RAM = 5;
+constant FRAGMENT_CFG_RAM = 6;
+constant PACKET_SEND = 7;
+constant PACKET_RECV = 8;
+constant DO_LOAD_CONF = 9;
+constant PACKET_MAC_MIB = 10;
+constant PACKET_RX_MIB = 11;
+constant PACKET_TX_MIB = 12;
+constant CFG_TYPE_SIZE = 4;
+constant CFG_NUM = 128;
+
+
+method Handle_664_Data(uint8 *data, int length) {
+    local bool is_cached_ok;
+    local Cache_Item item;
+    local uint32 port_id;
+
+    memcpy(item.buffer, data+1, length-1);
+    item.size = length - 1;
+    port_id = *cast(&data[5], uint32*);
+
+    switch(data[0]) {
+    case PACKET_RECV:
+        call $EnPortCache($PortCache[port_id], item) -> (is_cached_ok);
+        if (!is_cached_ok) {
+            log "error" : "Port: %d's cache has full!\n", port_id;
+        }
+        break;
+    case PACKET_MAC_MIB: case PACKET_RX_MIB: case PACKET_TX_MIB:
+        log "error" : "A fatal error， MAC_MIB， RX_MIB， and TX_MIB info cann't recv form this method!\n";
+        break;
+    default:
+        log "error" : "Unsupported frame type!\n";
+        break;
+    }
+}
+
+method Recv_Data_From_664_Middleware_Loop_Event() {
     local int length;
     local uint8 *buf = new uint8 [PORT_DATA_SIZE];
-    length = socket_recv(buf, PORT_DATA_SIZE);
+    length = Recv_Data_From_664_Middleware(buf, PORT_DATA_SIZE);

     if (length > 0) {
-
+        call $Handle_664_Data(buf, length);
     }
-    after (1) call $socket_loop_recv();
-
+
+    after (1) call $Recv_Data_From_664_Middleware_Loop_Event();
 }

 method init_middleware_mode() {
     if ($middleware_mode == To664Middleware) {
-        socket_init();
-        call $socket_loop_recv();
+        Init_664_Work_Mode();
+        call $Recv_Data_From_664_Middleware_Loop_Event();
     }
 }

@@ -29,39 +74,49 @@ method LoadCfgTo664Middleware() {

     data_type = ANALYSE_CFG_CAM;
     cfg_table_size = sizeoftype(analyse_cfg_cam) * CFG_NUM;
-    socket_send(cast(&data_type, uint8*), CFG_TYPE_SIZE);
-    socket_send(cast(&$analyse_cfg_cam_array, uint8*), cfg_table_size);
+    Send_To_664_Middleware(cast(&data_type, uint8*), CFG_TYPE_SIZE);
+    Send_To_664_Middleware(cast(&$analyse_cfg_cam_array, uint8*), cfg_table_size);

     data_type = ANALYSE_CFG_RAM;
     cfg_table_size = sizeoftype(analyse_cfg_ram) * CFG_NUM;
-    socket_send(cast(&data_type, uint8*), CFG_TYPE_SIZE);
-    socket_send(cast(&$analyse_cfg_ram_array, uint8*), cfg_table_size);
+    Send_To_664_Middleware(cast(&data_type, uint8*), CFG_TYPE_SIZE);
+    Send_To_664_Middleware(cast(&$analyse_cfg_ram_array, uint8*), cfg_table_size);

     data_type = TRANSMIT_CFG_RAM;
     cfg_table_size = sizeoftype(transmit_cfg_ram) * CFG_NUM;
-    socket_send(cast(&data_type, uint8*), CFG_TYPE_SIZE);
-    socket_send(cast(&$transmit_cfg_ram_array, uint8*), cfg_table_size);
+    Send_To_664_Middleware(cast(&data_type, uint8*), CFG_TYPE_SIZE);
+    Send_To_664_Middleware(cast(&$transmit_cfg_ram_array, uint8*), cfg_table_size);

     data_type = SCHEDULING_CFG_RAM;
     cfg_table_size = sizeoftype(scheduling_cfg_ram) * CFG_NUM;
-    socket_send(cast(&data_type, uint8*), CFG_TYPE_SIZE);
-    socket_send(cast(&$scheduling_cfg_ram_array, uint8*), cfg_table_size);
+    Send_To_664_Middleware(cast(&data_type, uint8*), CFG_TYPE_SIZE);
+    Send_To_664_Middleware(cast(&$scheduling_cfg_ram_array, uint8*), cfg_table_size);

     data_type = RM_CFG_CAM;
     cfg_table_size = sizeoftype(rm_cfg_cam) * CFG_NUM;
-    socket_send(cast(&data_type, uint8*), CFG_TYPE_SIZE);
-    socket_send(cast(&$rm_cfg_cam_array, uint8*), cfg_table_size);
+    Send_To_664_Middleware(cast(&data_type, uint8*), CFG_TYPE_SIZE);
+    Send_To_664_Middleware(cast(&$rm_cfg_cam_array, uint8*), cfg_table_size);

     data_type = RM_CFG_RAM;
     cfg_table_size = sizeoftype(rm_cfg_ram) * CFG_NUM;
-    socket_send(cast(&data_type, uint8*), CFG_TYPE_SIZE);
-    socket_send(cast(&$rm_cfg_ram_array, uint8*), cfg_table_size);
+    Send_To_664_Middleware(cast(&data_type, uint8*), CFG_TYPE_SIZE);
+    Send_To_664_Middleware(cast(&$rm_cfg_ram_array, uint8*), cfg_table_size);

     data_type = FRAGMENT_CFG_RAM;
     cfg_table_size = sizeoftype(fragment_cfg_ram) * CFG_NUM;
-    socket_send(cast(&data_type, uint8*), CFG_TYPE_SIZE);
-    socket_send(cast(&$fragment_cfg_ram_array, uint8*), cfg_table_size);
+    Send_To_664_Middleware(cast(&data_type, uint8*), CFG_TYPE_SIZE);
+    Send_To_664_Middleware(cast(&$fragment_cfg_ram_array, uint8*), cfg_table_size);

     data_type = DO_LOAD_CONF;
-    socket_send(cast(&data_type, uint8*), CFG_TYPE_SIZE);
+    Send_To_664_Middleware(cast(&data_type, uint8*), CFG_TYPE_SIZE);
+}
+
+method Send_Payload_To_664_Middleware(uint8 *data, uint32 port_id, uint32 length) {
+    local uint32 data_type = 0;
+
+    data_type = PACKET_SEND;
+    Send_To_664_Middleware(cast(&data_type, uint8*), CFG_TYPE_SIZE);
+    Send_To_664_Middleware(cast(&length, uint8*), CFG_TYPE_SIZE);
+    Send_To_664_Middleware(cast(&port_id, uint8*), CFG_TYPE_SIZE);
+    Send_To_664_Middleware(data, length);
 }
diff --git a/simics-workspace/modules/afdxES/tomiddleware.h b/simics-workspace/modules/afdxES/tomiddleware.h
index d06a452..4d82b19 100644
--- a/simics-workspace/modules/afdxES/tomiddleware.h
+++ b/simics-workspace/modules/afdxES/tomiddleware.h
@@ -9,8 +9,10 @@
 #include <WINSOCK2.H>

-extern int socket_init(void);
-extern int socket_recv(unsigned char *recvbuf, int size);
-extern int socket_send(unsigned char *sendbuf, int size);
+extern int Init_664_Work_Mode(void);
+extern int Send_To_664_Middleware(unsigned char *recvbuf, int size);
+extern int Recv_Data_From_664_Middleware(unsigned char *sendbuf, int size);
+extern int Recv_Mib_Info_From_664_Middleware(unsigned char *recvbuf, int size);
+

 #endif