UpdatePacketDecoder { private AggregatorPathAttribute decodeAggregatorPathAttribute(ChannelBuffer buffer, ASType asType) { AggregatorPathAttribute attr = new AggregatorPathAttribute(asType); if(buffer.readableBytes() != PathAttributeCodec.valueLength(attr)) throw new AttributeLengthException(); if(asType == ASType.AS_NUMBER_4OCTETS) attr.setAsNumber((int)buffer.readUnsignedInt()); else attr.setAsNumber(buffer.readUnsignedShort()); try { byte[] addr = new byte[4]; buffer.readBytes(addr); attr.setAggregator((Inet4Address)Inet4Address.getByAddress(addr)); } catch (UnknownHostException e) { throw new OptionalAttributeErrorException(); } return attr; }  BGPv4Packet decodeUpdatePacket(ChannelBuffer buffer); NotificationPacket decodeUpdateNotification(ChannelBuffer buffer, int errorSubcode);  }
@Test public void testDecodeAggregatorPathAttribute() throws Exception { UpdatePacket packet; AggregatorPathAttribute aggregator; packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x09, (byte)0x40, (byte)0x07, (byte)0x06, 0x12, 0x34, (byte)0xc0, (byte)0xa8, (byte)0x04, (byte)0x02, })), UpdatePacket.class); Assert.assertEquals(2, packet.getType()); Assert.assertEquals(0, packet.getWithdrawnRoutes().size()); Assert.assertEquals(1, packet.getPathAttributes().size()); Assert.assertEquals(0, packet.getNlris().size()); aggregator = (AggregatorPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AGGREGATOR, PathAttributeCodec.typeCode(aggregator)); Assert.assertEquals(0x1234, aggregator.getAsNumber()); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, aggregator.getAsType()); Assert.assertEquals(Inet4Address.getByAddress(new byte[] { (byte)0xc0, (byte)0xa8, (byte)0x04, (byte)0x02, }), aggregator.getAggregator()); packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0b, (byte)0x40, (byte)0x12, (byte)0x08, 0x56, 0x78, 0x12, 0x34, (byte)0xc0, (byte)0xa8, (byte)0x04, (byte)0x02, })), UpdatePacket.class); Assert.assertEquals(2, packet.getType()); Assert.assertEquals(0, packet.getWithdrawnRoutes().size()); Assert.assertEquals(1, packet.getPathAttributes().size()); Assert.assertEquals(0, packet.getNlris().size()); aggregator = (AggregatorPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_AGGREGATOR, PathAttributeCodec.typeCode(aggregator)); Assert.assertEquals(0x56781234, aggregator.getAsNumber()); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, aggregator.getAsType()); Assert.assertEquals(Inet4Address.getByAddress(new byte[] { (byte)0xc0, (byte)0xa8, (byte)0x04, (byte)0x02, }), aggregator.getAggregator()); }