Index: /branches/reconfiguration/modules/dspin_router/caba/source/include/dspin_router.h
===================================================================
--- /branches/reconfiguration/modules/dspin_router/caba/source/include/dspin_router.h	(revision 872)
+++ /branches/reconfiguration/modules/dspin_router/caba/source/include/dspin_router.h	(revision 873)
@@ -84,4 +84,18 @@
     };
 
+    // Black-Hole position
+    enum
+    {
+        BH_NONE,
+        BH_N,
+        BH_NE,
+        BH_E,
+        BH_SE,
+        BH_S,
+        BH_SW,
+        BH_W,
+        BH_NW
+    };
+
     protected:
     SC_HAS_PROCESS(DspinRouter);
@@ -137,9 +151,12 @@
     bool                        m_broadcast_supported;
     int                         m_disable_mask;
+    int                         m_blackhole_pos;
 
     // methods
     void    transition();
     void    genMoore();
-    int     xfirst_route( sc_uint<flit_width> data );
+    int     xfirst_route( size_t xdest, size_t ydest );
+    int     recovery_route( size_t xdest, size_t ydest );
+    int     route( sc_uint<flit_width> data );
     int     broadcast_route( int iter, int source, sc_uint<flit_width> data );
     bool    is_broadcast( sc_uint<flit_width> data );
@@ -147,6 +164,15 @@
     public:
 
-    void    set_disable_mask( int mask );
-    void    print_trace();
+    void set_disable_mask( int mask )
+    {
+        m_disable_mask = mask;
+    }
+
+    void set_blackhole_pos( int pos )
+    {
+        m_blackhole_pos = pos;
+    }
+
+    void print_trace();
 };
 
Index: /branches/reconfiguration/modules/dspin_router/caba/source/src/dspin_router.cpp
===================================================================
--- /branches/reconfiguration/modules/dspin_router/caba/source/src/dspin_router.cpp	(revision 872)
+++ /branches/reconfiguration/modules/dspin_router/caba/source/src/dspin_router.cpp	(revision 873)
@@ -117,12 +117,131 @@
 
     ///////////////////////////////////////////////////
-    tmpl(int)::xfirst_route( sc_uint<flit_width> data )
-    {
-        size_t xdest = (size_t)(data >> m_x_shift) & m_x_mask;
-        size_t ydest = (size_t)(data >> m_y_shift) & m_y_mask;
+    tmpl(int)::xfirst_route( size_t xdest, size_t ydest )
+    {
         return (xdest < m_local_x ? REQ_WEST :
                (xdest > m_local_x ? REQ_EAST :
                (ydest < m_local_y ? REQ_SOUTH :
                (ydest > m_local_y ? REQ_NORTH : REQ_LOCAL))));
+    }
+
+    ///////////////////////////////////////////////////
+    tmpl(int)::recovery_route( size_t xdest, size_t ydest )
+    {
+        int bhpos = m_blackhole_pos;
+        if ( xdest > m_local_x ) {
+            if ( (bhpos == BH_NE) || (bhpos == BH_E) || (bhpos == BH_SE) ||
+                 (bhpos == BH_S) ) {
+                return REQ_EAST;
+            }
+            else if ( bhpos == BH_N ) {
+                if ( (m_local_y == 1) || (m_local_x == 0) || (ydest >= m_local_y) ||
+                     (xdest > (m_local_x + 1)) ) {
+                    return REQ_EAST;
+                }
+                else {
+                    return REQ_WEST;
+                }
+            }
+            else if ( bhpos == BH_NW ) {
+                if ( (m_local_y == 1) || (ydest >= m_local_y) ||
+                     (xdest > (m_local_x + 2)) ) {
+                    return REQ_EAST;
+                }
+                else {
+                    return REQ_SOUTH;
+                }
+            }
+            else if ( bhpos == BH_W ) {
+                if ( (m_local_y == 0) || (ydest > m_local_y)) {
+                    return REQ_NORTH;
+                }
+                else {
+                    return REQ_SOUTH;
+                }
+            }
+            else if ( bhpos == BH_SW ) {
+                if ( (ydest <= m_local_y) || (xdest > (m_local_x + 1)) ) {
+                    return REQ_EAST;
+                }
+                else {
+                    return REQ_NORTH;
+                }
+            }
+            std::cout << "error: unexpected condition in function "
+                      << __FILE__ << ":" << __func__ << " +" << __LINE__
+                      << std::endl;
+            exit(1);
+        }                    // end if (xdest > m_local_x)
+        else if ( xdest < m_local_x ) {
+            if ( (bhpos == BH_N) || (bhpos == BH_NW) || (bhpos == BH_W) ||
+                 (bhpos == BH_SW) || (bhpos == BH_S) ) {
+                return REQ_WEST;
+            }
+            else if ( bhpos == BH_NE ) {
+                if ( (xdest < (m_local_x - 1)) || (ydest >= m_local_y) ) {
+                    return REQ_WEST;
+                }
+                else {
+                    return REQ_SOUTH;
+                }
+            }
+            else if ( bhpos == BH_SE ) {
+                if ( (m_local_x == 1) && (ydest > (m_local_y + 1)) ) {
+                    return REQ_NORTH;
+                }
+                else {
+                    return REQ_WEST;
+                }
+            }
+            else if ( bhpos == BH_E ) {
+                if ( (m_local_y == 0) ||
+                    ((m_local_x == 1) && (ydest > m_local_y)) ) {
+                    return REQ_NORTH;
+                }
+                else {
+                    return REQ_SOUTH;
+                }
+            }
+            std::cout << "error: unexpected condition in function "
+                      << __FILE__ << ":" << __func__ << " +" << __LINE__
+                      << std::endl;
+            exit(1);
+        }                    // end if (xdest < m_local_x)
+        else if ( ydest > m_local_y ) {
+            if ( bhpos != BH_S ) {
+                return REQ_NORTH;
+            }
+            else if ( m_local_x != 0 ) {
+                return REQ_WEST;
+            }
+            else {
+                return REQ_EAST;
+            }
+        }                    // end if (ydest > m_local_y)
+        else if ( ydest < m_local_y ) {
+            if ( bhpos != BH_N ) {
+                return REQ_SOUTH;
+            }
+            else if ( m_local_x != 0) {
+                return REQ_WEST;
+            }
+            else {
+                return REQ_EAST;
+            }
+        }                    // end if (ydest < m_local_y)
+        return REQ_LOCAL;
+    }
+
+    ///////////////////////////////////////////////////
+    tmpl(int)::route( sc_uint<flit_width> data )
+    {
+        size_t xdest = (size_t)(data >> m_x_shift) & m_x_mask;
+        size_t ydest = (size_t)(data >> m_y_shift) & m_y_mask;
+        if ( m_blackhole_pos == BH_NONE ) {
+            return xfirst_route(xdest, ydest);
+        }
+        else {
+            return recovery_route(xdest, ydest);
+        }
     }
 
@@ -182,10 +301,4 @@
     }
 
-    /////////////////////////////////////////////////////////
-    tmpl(void)::set_disable_mask( int mask )
-    {
-        m_disable_mask = mask;
-    }
-
     /////////////////////////
     tmpl(void)::print_trace()
@@ -265,4 +378,6 @@
                 r_fifo_out[i].init();
             }
+
+            set_blackhole_pos(BH_NONE);
             return;
         }
@@ -327,5 +442,5 @@
                         else                                  // unicast
                         {
-                            req_in[i]       = xfirst_route(r_fifo_in[i].read().data);
+                            req_in[i]       = route(r_fifo_in[i].read().data);
                             r_index_in[i]   = req_in[i];
                             r_fsm_in[i]     = INFSM_REQ;
