Reorganize packages and add some tests for protocol layer