BGPv4PacketDecoder { public BGPv4Packet decodePacket(ChannelBuffer buffer) { int type = buffer.readUnsignedByte(); BGPv4Packet packet = null; switch (type) { case BGPv4Constants.BGP_PACKET_TYPE_OPEN: packet = openPacketDecoder.decodeOpenPacket(buffer); break; case BGPv4Constants.BGP_PACKET_TYPE_UPDATE: packet = updatePacketDecoder.decodeUpdatePacket(buffer); break; case BGPv4Constants.BGP_PACKET_TYPE_NOTIFICATION: packet = decodeNotificationPacket(buffer); break; case BGPv4Constants.BGP_PACKET_TYPE_KEEPALIVE: packet = decodeKeepalivePacket(buffer); break; case BGPv4Constants.BGP_PACKET_TYPE_ROUTE_REFRESH: packet = routeRefreshPacketDecoder.decodeRouteRefreshPacket(buffer); break; default: throw new BadMessageTypeException(type); } return packet; }  BGPv4Packet decodePacket(ChannelBuffer buffer);  }
@Test public void testDecodeBasicOpenPacket() { OpenPacket open = safeDowncast(decoder.decodePacket(buildProtocolPacket(new byte[] { (byte)0x01, (byte)0x04, (byte)0xfc, (byte)0x00, (byte)0x00, (byte)0xb4, (byte)0xc0, (byte)0xa8, (byte)0x09, (byte)0x01, (byte)0x0, })), OpenPacket.class); Assert.assertEquals(4, open.getProtocolVersion()); Assert.assertEquals(64512, open.getAutonomousSystem()); Assert.assertEquals(180, open.getHoldTime()); Assert.assertEquals(0, open.getCapabilities().size()); Assert.assertEquals(((192L<<24) | (168L << 16) | (9L << 8) | 1), open.getBgpIdentifier()); }