public static Protocol connectProtocols ( List < Protocol > protocol_list ) throws Exception { Protocol current_layer = null , next_layer = null ; for ( int i = 0 ; i < protocol_list . size ( ) ; i ++ ) { current_layer = protocol_list . get ( i ) ; if ( i + 1 >= protocol_list . size ( ) ) break ; next_layer = protocol_list . get ( i + 1 ) ; next_layer . setDownProtocol ( current_layer ) ; current_layer . setUpProtocol ( next_layer ) ; } // basic protocol sanity check sanityCheck ( protocol_list ) ; return current_layer ; }
Creates a protocol stack by iterating through the protocol list and connecting adjacent layers . The list starts with the topmost layer and has the bottommost layer at the tail .