UpdatePacketDecoder { public BGPv4Packet decodeUpdatePacket(ChannelBuffer buffer) { UpdatePacket packet = new UpdatePacket(); ProtocolPacketUtils.verifyPacketSize(buffer, BGPv4Constants.BGP_PACKET_MIN_SIZE_UPDATE, -1); if(buffer.readableBytes() < 2) throw new MalformedAttributeListException(); int withdrawnOctets = buffer.readUnsignedShort(); if(withdrawnOctets > buffer.readableBytes()) throw new MalformedAttributeListException(); ChannelBuffer withdrawnBuffer = null; if(withdrawnOctets > 0) { withdrawnBuffer = ChannelBuffers.buffer(withdrawnOctets); buffer.readBytes(withdrawnBuffer); } if(buffer.readableBytes() < 2) throw new MalformedAttributeListException(); int pathAttributeOctets = buffer.readUnsignedShort(); if(pathAttributeOctets > buffer.readableBytes()) throw new MalformedAttributeListException(); ChannelBuffer pathAttributesBuffer = null; if(pathAttributeOctets > 0) { pathAttributesBuffer = ChannelBuffers.buffer(pathAttributeOctets); buffer.readBytes(pathAttributesBuffer); } if(withdrawnBuffer != null) { try { packet.getWithdrawnRoutes().addAll(decodeWithdrawnRoutes(withdrawnBuffer)); } catch(IndexOutOfBoundsException e) { throw new MalformedAttributeListException(); } } if(pathAttributesBuffer != null) { try { packet.getPathAttributes().addAll(decodePathAttributes(pathAttributesBuffer)); } catch (IndexOutOfBoundsException ex) { throw new MalformedAttributeListException(); } } if(buffer.readableBytes() > 0) { try { while (buffer.readable()) { packet.getNlris().add(NLRICodec.decodeNLRI(buffer)); } } catch (IndexOutOfBoundsException e) { throw new InvalidNetworkFieldException(); } catch(IllegalArgumentException e) { throw new InvalidNetworkFieldException(); } } return packet; }  BGPv4Packet decodeUpdatePacket(ChannelBuffer buffer); NotificationPacket decodeUpdateNotification(ChannelBuffer buffer, int errorSubcode);  }
@Test public void testDecodeOriginIgpPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x40, (byte)0x01, (byte)0x01, (byte)0x00, })), 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()); OriginPathAttribute origin = (OriginPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_ORIGIN, PathAttributeCodec.typeCode(origin)); Assert.assertEquals(Origin.IGP, origin.getOrigin()); }
@Test public void testDecodeOriginEgpPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x40, (byte)0x01, (byte)0x01, (byte)0x01, })), 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()); OriginPathAttribute origin = (OriginPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_ORIGIN, PathAttributeCodec.typeCode(origin)); Assert.assertEquals(Origin.EGP, origin.getOrigin()); }
@Test public void testDecodeOriginIncompletePacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x40, (byte)0x01, (byte)0x01, (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()); OriginPathAttribute origin = (OriginPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_ORIGIN, PathAttributeCodec.typeCode(origin)); Assert.assertEquals(Origin.INCOMPLETE, origin.getOrigin()); }
@Test public void testDecodeNextHopPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x07, (byte)0x40, (byte)0x03, (byte)0x04, (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()); NextHopPathAttribute nextHop = (NextHopPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(Inet4Address.getByAddress(new byte[] { (byte)0xc0, (byte)0xa8, (byte)0x04, (byte)0x02 }), nextHop.getNextHop().getAddress()); }
@Test public void testDecodeNextHopPacketIpMulticastNextHop() throws Exception { (new AssertExecption() { @Override protected void doExecute() { safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x07, (byte)0x40, (byte)0x03, (byte)0x04, (byte)0xe0, (byte)0x00, (byte)0x00, (byte)0x01, })), UpdatePacket.class); } }).execute(InvalidNextHopException.class); }
@Test public void testDecodeEmptyUpdatePacket() { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x00, })), UpdatePacket.class); Assert.assertEquals(2, packet.getType()); Assert.assertEquals(0, packet.getWithdrawnRoutes().size()); Assert.assertEquals(0, packet.getPathAttributes().size()); Assert.assertEquals(0, packet.getNlris().size()); }
@Test public void testDecodeCompletePacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x1d, (byte)0x40, (byte)0x01, (byte)0x01, (byte)0x02, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x40, (byte)0x03, (byte)0x04, (byte)0xc0, (byte)0xa8, (byte)0x04, (byte)0x02, (byte)0x80, (byte)0x04, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x08, (byte)0x00, (byte)0x40, (byte)0x05, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x64, (byte)0x00 })), UpdatePacket.class); Assert.assertEquals(2, packet.getType()); Assert.assertEquals(0, packet.getWithdrawnRoutes().size()); Assert.assertEquals(5, packet.getPathAttributes().size()); Assert.assertEquals(1, packet.getNlris().size()); OriginPathAttribute origin = (OriginPathAttribute)packet.getPathAttributes().remove(0); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); NextHopPathAttribute nextHop = (NextHopPathAttribute)packet.getPathAttributes().remove(0); MultiExitDiscPathAttribute multiExitDisc = (MultiExitDiscPathAttribute)packet.getPathAttributes().remove(0); LocalPrefPathAttribute localPref = (LocalPrefPathAttribute)packet.getPathAttributes().remove(0); NetworkLayerReachabilityInformation nlri = packet.getNlris().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_ORIGIN, PathAttributeCodec.typeCode(origin)); Assert.assertEquals(Origin.INCOMPLETE, origin.getOrigin()); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(0, asPath.getPathSegments().size()); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_NEXT_HOP, PathAttributeCodec.typeCode(nextHop)); Assert.assertEquals(Inet4Address.getByAddress(new byte[] {(byte)0xc0, (byte)0xa8, (byte)0x04, (byte)0x02 }), nextHop.getNextHop().getAddress()); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_MULTI_EXIT_DISC, PathAttributeCodec.typeCode(multiExitDisc)); Assert.assertEquals(2048, multiExitDisc.getDiscriminator()); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_LOCAL_PREF, PathAttributeCodec.typeCode(localPref)); Assert.assertEquals(100, localPref.getLocalPreference()); Assert.assertEquals(0, nlri.getPrefixLength()); Assert.assertNotNull(nlri.getPrefix()); Assert.assertEquals(1, nlri.getPrefix().length); Assert.assertEquals(0, nlri.getPrefix()[0]); }
@Test public void testDecodeWithdrawnDefaultPrefixUpdatePacket() { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x01, 0x00, 0x00, 0x00, })), UpdatePacket.class); Assert.assertEquals(2, packet.getType()); Assert.assertEquals(0, packet.getPathAttributes().size()); Assert.assertEquals(0, packet.getNlris().size()); Assert.assertEquals(1, packet.getWithdrawnRoutes().size()); Assert.assertEquals(packet.getWithdrawnRoutes().remove(0), new NetworkLayerReachabilityInformation(0, null)); }
@Test public void testDecodeWithdrawnFourBitPrefixPrefixUpdatePacket() { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x02, 0x04, (byte)0xc0, 0x00, 0x00, })), UpdatePacket.class); Assert.assertEquals(2, packet.getType()); Assert.assertEquals(0, packet.getPathAttributes().size()); Assert.assertEquals(0, packet.getNlris().size()); Assert.assertEquals(1, packet.getWithdrawnRoutes().size()); Assert.assertEquals(packet.getWithdrawnRoutes().remove(0), new NetworkLayerReachabilityInformation(4, new byte[] { (byte)0xc0 })); }
@Test public void testDecodeWithdrawnEightBitPrefixPrefixUpdatePacket() { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x02, 0x08, (byte)0xc8, 0x00, 0x00, })), UpdatePacket.class); Assert.assertEquals(2, packet.getType()); Assert.assertEquals(0, packet.getPathAttributes().size()); Assert.assertEquals(0, packet.getNlris().size()); Assert.assertEquals(1, packet.getWithdrawnRoutes().size()); Assert.assertEquals(packet.getWithdrawnRoutes().remove(0), new NetworkLayerReachabilityInformation(8, new byte[] { (byte)0xc8 })); }
@Test public void testDecodeWithdrawnTwelveBitPrefixPrefixUpdatePacket() { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x03, 0x0c, (byte)0xc0, (byte)0xe0, 0x00, 0x00, })), UpdatePacket.class); Assert.assertEquals(2, packet.getType()); Assert.assertEquals(0, packet.getPathAttributes().size()); Assert.assertEquals(0, packet.getNlris().size()); Assert.assertEquals(1, packet.getWithdrawnRoutes().size()); Assert.assertEquals(packet.getWithdrawnRoutes().remove(0), new NetworkLayerReachabilityInformation(12, new byte[] { (byte)0xc0, (byte)0xe0 })); }
@Test public void testDecodeWithdrawnSixteenBitPrefixPrefixUpdatePacket() { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x03, 0x10, (byte)0xc0, (byte)0xef, 0x00, 0x00, })), UpdatePacket.class); Assert.assertEquals(2, packet.getType()); Assert.assertEquals(0, packet.getPathAttributes().size()); Assert.assertEquals(0, packet.getNlris().size()); Assert.assertEquals(1, packet.getWithdrawnRoutes().size()); Assert.assertEquals(packet.getWithdrawnRoutes().remove(0), new NetworkLayerReachabilityInformation(16, new byte[] { (byte)0xc0, (byte)0xef })); }
@Test public void testDecodeMalformedWithdrawnRoutesNopathAttributeListUpdatePacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, })); } }).execute(ConnectionNotSynchronizedException.class); }
@Test public void testDecodeMalformedWithdrawnRoutesLengthOnPacketEndUpdatePacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x02, 0x00, 0x00, })); } }).execute(MalformedAttributeListException.class); }
@Test public void testDecodeMalformedWithdrawnRoutesLengthOverEndUpdatePacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x04, 0x00, 0x00, })); } }).execute(MalformedAttributeListException.class); }
@Test public void testDecodeAttributeListTooLongUpdatePacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x02, })); } }).execute(MalformedAttributeListException.class); }
@Test public void testDecodeOriginInvalidPacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x40, (byte)0x01, (byte)0x01, (byte)0x04, })), UpdatePacket.class); } }).execute(InvalidOriginException.class); }
@Test public void testDecodeOriginShortPacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x03, (byte)0x40, (byte)0x01, (byte)0x00, })), UpdatePacket.class); } }).execute(AttributeLengthException.class); }
@Test public void testDecodeASPath4EmptyPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x00, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(0, asPath.getPathSegments().size()); }
@Test public void testDecodeASPath4ASSequenceOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0a, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x06, 0x02, 0x01, 0x00, 0x00, 0x12, 0x34, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(1, asPath.getPathSegments().size()); PathSegment segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSequenceTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0e, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x0a, 0x02, 0x02, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(1, asPath.getPathSegments().size()); PathSegment segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSetOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0a, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x06, 0x01, 0x01, 0x00, 0x00, 0x12, 0x34, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(1, asPath.getPathSegments().size()); PathSegment segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASConfedSequenceOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0a, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x06, 0x03, 0x01, 0x00, 0x00, 0x12, 0x34, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(1, asPath.getPathSegments().size()); PathSegment segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_CONFED_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASConfedSetOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0a, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x06, 0x04, 0x01, 0x00, 0x00, 0x12, 0x34, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(1, asPath.getPathSegments().size()); PathSegment segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_CONFED_SET, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSetTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0e, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x0a, 0x01, 0x02, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(1, asPath.getPathSegments().size()); PathSegment segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSeqeunceOneASNumberASSeqeunceOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x0c, 0x02, 0x01, 0x00, 0x00, 0x12, 0x34, 0x02, 0x01, 0x00, 0x00, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSeqeunceTw0ASNumberASSeqeunceOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x14, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x10, 0x02, 0x02, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, (byte)0x89, (byte)0xab, 0x02, 0x01, 0x00, 0x00, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x89ab, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSeqeunceTw0ASNumberASSeqeunceTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x18, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x14, 0x02, 0x02, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, (byte)0x89, (byte)0xab, 0x02, 0x02, 0x00, 0x00, 0x56, 0x78, 0x00, 0x00, (byte)0xcd, (byte)0xef })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x89ab, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); Assert.assertEquals((Integer)0xcdef, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSeqeunceOneASNumberASSeqeunceTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x14, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x10, 0x02, 0x01, 0x00, 0x00, 0x12, 0x34, 0x02, 0x02, 0x00, 0x00, 0x56, 0x78, 0x00, 0x00, (byte)0xcd, (byte)0xef })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); Assert.assertEquals((Integer)0xcdef, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSeqeunceOneASNumberASSetOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x0c, 0x02, 0x01, 0x00, 0x00, 0x12, 0x34, 0x01, 0x01, 0x00, 0x00, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSeqeunceTw0ASNumberASSetASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x14, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x10, 0x02, 0x02, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, (byte)0x89, (byte)0xab, 0x01, 0x01, 0x00, 0x00, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x89ab, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSeqeunceTw0ASNumberASSetTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x18, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x14, 0x02, 0x02, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, (byte)0x89, (byte)0xab, 0x01, 0x02, 0x00, 0x00, 0x56, 0x78, 0x00, 0x00, (byte)0xcd, (byte)0xef })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x89ab, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); Assert.assertEquals((Integer)0xcdef, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSeqeunceOneASNumberASSetTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x14, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x10, 0x02, 0x01, 0x00, 0x00, 0x12, 0x34, 0x01, 0x02, 0x00, 0x00, 0x56, 0x78, 0x00, 0x00, (byte)0xcd, (byte)0xef })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); Assert.assertEquals((Integer)0xcdef, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSetOneASNumberASSeqeunceOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x0c, 0x01, 0x01, 0x00, 0x00, 0x12, 0x34, 0x02, 0x01, 0x00, 0x00, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSetTw0ASNumberASSeqeunceOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x14, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x10, 0x01, 0x02, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, (byte)0x89, (byte)0xab, 0x02, 0x01, 0x00, 0x00, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x89ab, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSetTw0ASNumberASSeqeunceTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x18, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x14, 0x01, 0x02, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, (byte)0x89, (byte)0xab, 0x02, 0x02, 0x00, 0x00, 0x56, 0x78, 0x00, 0x00, (byte)0xcd, (byte)0xef })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x89ab, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); Assert.assertEquals((Integer)0xcdef, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4ASSetOneASNumberASSeqeunceTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x14, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x10, 0x01, 0x01, 0x00, 0x00, 0x12, 0x34, 0x02, 0x02, 0x00, 0x00, 0x56, 0x78, 0x00, 0x00, (byte)0xcd, (byte)0xef })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS4_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_4OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); Assert.assertEquals((Integer)0xcdef, segment.getAses().remove(0)); }
@Test public void testDecodeASPath4BadPathTypeOneASNumberPacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0a, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x06, 0x05, 0x01, 0x00, 0x00, 0x12, 0x34, })), UpdatePacket.class); } }).execute(MalformedASPathAttributeException.class); }
@Test public void testDecodeASPath4ASSequenceTwoASNumberOneMissingPacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0a, (byte)0x50, (byte)0x11, (byte)0x00, (byte)0x06, 0x02, 0x02, 0x00, 0x00, 0x12, 0x34, })), UpdatePacket.class); } }).execute(MalformedASPathAttributeException.class); }
@Test public void testDecodeASPath2EmptyPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x00, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(0, asPath.getPathSegments().size()); }
@Test public void testDecodeASPath2ASSequenceOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x08, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x04, 0x02, 0x01, 0x12, 0x34, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(1, asPath.getPathSegments().size()); PathSegment segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSequenceTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0a, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x06, 0x02, 0x02, 0x12, 0x34, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(1, asPath.getPathSegments().size()); PathSegment segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSetOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x08, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x04, 0x01, 0x01, 0x12, 0x34, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(1, asPath.getPathSegments().size()); PathSegment segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSetTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0a, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x06, 0x01, 0x02, 0x12, 0x34, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(1, asPath.getPathSegments().size()); PathSegment segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSeqeunceOneASNumberASSeqeunceOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0c, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x08, 0x02, 0x01, 0x12, 0x34, 0x02, 0x01, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSeqeunceTw0ASNumberASSeqeunceOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0e, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x0a, 0x02, 0x02, 0x12, 0x34, (byte)0x89, (byte)0xab, 0x02, 0x01, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x89ab, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSeqeunceTw0ASNumberASSeqeunceTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x0c, 0x02, 0x02, 0x12, 0x34, (byte)0x89, (byte)0xab, 0x02, 0x02, 0x56, 0x78, (byte)0xcd, (byte)0xef })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x89ab, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); Assert.assertEquals((Integer)0xcdef, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSeqeunceOneASNumberASSeqeunceTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0e, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x0a, 0x02, 0x01, 0x12, 0x34, 0x02, 0x02, 0x56, 0x78, (byte)0xcd, (byte)0xef })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); Assert.assertEquals((Integer)0xcdef, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSeqeunceOneASNumberASSetOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0c, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x08, 0x02, 0x01, 0x12, 0x34, 0x01, 0x01, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSeqeunceTw0ASNumberASSetASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0e, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x0a, 0x02, 0x02, 0x12, 0x34, (byte)0x89, (byte)0xab, 0x01, 0x01, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x89ab, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSeqeunceTw0ASNumberASSetTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x0c, 0x02, 0x02, 0x12, 0x34, (byte)0x89, (byte)0xab, 0x01, 0x02, 0x56, 0x78, (byte)0xcd, (byte)0xef })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x89ab, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); Assert.assertEquals((Integer)0xcdef, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSeqeunceOneASNumberASSetTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0e, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x0a, 0x02, 0x01, 0x12, 0x34, 0x01, 0x02, 0x56, 0x78, (byte)0xcd, (byte)0xef })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); Assert.assertEquals((Integer)0xcdef, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSetOneASNumberASSeqeunceOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0c, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x08, 0x01, 0x01, 0x12, 0x34, 0x02, 0x01, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSetTw0ASNumberASSeqeunceOneASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0e, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x0a, 0x01, 0x02, 0x12, 0x34, (byte)0x89, (byte)0xab, 0x02, 0x01, 0x56, 0x78, })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x89ab, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSetTw0ASNumberASSeqeunceTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x0c, 0x01, 0x02, 0x12, 0x34, (byte)0x89, (byte)0xab, 0x02, 0x02, 0x56, 0x78, (byte)0xcd, (byte)0xef })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); Assert.assertEquals((Integer)0x89ab, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); Assert.assertEquals((Integer)0xcdef, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2ASSetOneASNumberASSeqeunceTwoASNumberPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0e, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x0a, 0x01, 0x01, 0x12, 0x34, 0x02, 0x02, 0x56, 0x78, (byte)0xcd, (byte)0xef })), 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()); ASPathAttribute asPath = (ASPathAttribute)packet.getPathAttributes().remove(0); PathSegment segment; Assert.assertEquals(BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_AS_PATH, PathAttributeCodec.typeCode(asPath)); Assert.assertEquals(ASType.AS_NUMBER_2OCTETS, asPath.getAsType()); Assert.assertEquals(2, asPath.getPathSegments().size()); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SET, segment.getPathSegmentType()); Assert.assertEquals(1, segment.getAses().size()); Assert.assertEquals((Integer)0x1234, segment.getAses().remove(0)); segment = asPath.getPathSegments().remove(0); Assert.assertEquals(PathSegmentType.AS_SEQUENCE, segment.getPathSegmentType()); Assert.assertEquals(2, segment.getAses().size()); Assert.assertEquals((Integer)0x5678, segment.getAses().remove(0)); Assert.assertEquals((Integer)0xcdef, segment.getAses().remove(0)); }
@Test public void testDecodeASPath2BadPathTypeOneASNumberPacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x08, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x04, 0x05, 0x01, 0x12, 0x34, })), UpdatePacket.class); } }).execute(MalformedASPathAttributeException.class); }
@Test public void testDecodeASPath2ASSequenceTwoASNumberOneMissingPacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x08, (byte)0x50, (byte)0x02, (byte)0x00, (byte)0x04, 0x02, 0x02, 0x12, 0x34, })), UpdatePacket.class); } }).execute(MalformedASPathAttributeException.class); }
@Test public void testDecodeAtomiAcggregatePathAttribute() throws Exception { UpdatePacket packet; packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x03, (byte)0x40, (byte)0x06, (byte)0x00, })), 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()); Assert.assertTrue(packet.getPathAttributes().remove(0) instanceof AtomicAggregatePathAttribute); }
@Test public void testDecodeOneNlriUpdatePacket() { UpdatePacket packet; NetworkLayerReachabilityInformation nlri; packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x10, (byte)0xac, 0x10, })), UpdatePacket.class); Assert.assertEquals(2, packet.getType()); Assert.assertEquals(0, packet.getWithdrawnRoutes().size()); Assert.assertEquals(0, packet.getPathAttributes().size()); Assert.assertEquals(1, packet.getNlris().size()); nlri = packet.getNlris().remove(0); Assert.assertEquals(16, nlri.getPrefixLength()); assertArraysEquals(new byte[] { (byte)0xac, 0x10} , nlri.getPrefix()); }
@Test public void testDecodeTwoNlriUpdatePacket() { UpdatePacket packet; NetworkLayerReachabilityInformation nlri; packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x10, (byte)0xac, 0x10, 0x1c, (byte)0xc0, (byte)0xa8, 0x20, 0, })), UpdatePacket.class); Assert.assertEquals(2, packet.getType()); Assert.assertEquals(0, packet.getWithdrawnRoutes().size()); Assert.assertEquals(0, packet.getPathAttributes().size()); Assert.assertEquals(2, packet.getNlris().size()); nlri = packet.getNlris().remove(0); Assert.assertEquals(16, nlri.getPrefixLength()); assertArraysEquals(new byte[] { (byte)0xac, 0x10} , nlri.getPrefix()); nlri = packet.getNlris().remove(0); Assert.assertEquals(28, nlri.getPrefixLength()); assertArraysEquals(new byte[] { (byte)0xc0, (byte)0xa8, 0x20, 0} , nlri.getPrefix()); }
@Test public void testDecodeBogusNlriUpdatePacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x10, (byte)0xac, 0x10, 0x1c, (byte)0xc0, (byte)0xa8, 0x20, })), UpdatePacket.class); } }).execute(InvalidNetworkFieldException.class); }
@Test public void testDecodeValidMpReachNlriNullNextHopZeroNlriUpdatePacket() { UpdatePacket packet; packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x08, (byte)0x80, 0x0e, 0x05, 0x00, 0x01, 0x01, 0x00, 0x00, })), 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()); MultiProtocolReachableNLRI mp = (MultiProtocolReachableNLRI)packet.getPathAttributes().remove(0); Assert.assertEquals(AddressFamily.IPv4, mp.getAddressFamily()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, mp.getSubsequentAddressFamily()); Assert.assertNull(mp.getNextHop()); Assert.assertEquals(0, mp.getNlris().size()); }
@Test public void testDecodeValidMpReachNlriFourByteNextHopZeroNlriUpdatePacket() { UpdatePacket packet; packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x0c, (byte)0x80, 0x0e, 0x09, 0x00, 0x01, 0x01, 0x04, (byte)0xc0, (byte)0xa8, 0x04, 0x02, 0x00, })), 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()); MultiProtocolReachableNLRI mp = (MultiProtocolReachableNLRI)packet.getPathAttributes().remove(0); Assert.assertEquals(AddressFamily.IPv4, mp.getAddressFamily()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, mp.getSubsequentAddressFamily()); assertArraysEquals(new byte[] { (byte)0xc0, (byte)0xa8, 0x04, 0x02, }, mp.getNextHop().getAddress()); Assert.assertEquals(0, mp.getNlris().size()); }
@Test public void testDecodeValidMpReachNlriFourByteNextHopOneNlriUpdatePacket() { UpdatePacket packet; packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x0f, (byte)0x80, 0x0e, 0x0c, 0x00, 0x01, 0x01, 0x04, (byte)0xc0, (byte)0xa8, 0x04, 0x02, 0x00, 0x0c, (byte)0xab, 0x10, })), 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()); MultiProtocolReachableNLRI mp = (MultiProtocolReachableNLRI)packet.getPathAttributes().remove(0); Assert.assertEquals(AddressFamily.IPv4, mp.getAddressFamily()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, mp.getSubsequentAddressFamily()); assertArraysEquals(new byte[] { (byte)0xc0, (byte)0xa8, 0x04, 0x02, }, mp.getNextHop().getAddress()); Assert.assertEquals(1, mp.getNlris().size()); NetworkLayerReachabilityInformation nlri = mp.getNlris().remove(0); Assert.assertEquals(12, nlri.getPrefixLength()); assertArraysEquals(new byte[] { (byte)0xab, 0x10, } , nlri.getPrefix()); }
@Test public void testDecodeValidMpReachNlriFourByteNextHopTwoNlriUpdatePacket() { UpdatePacket packet; packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x13, (byte)0x80, 0x0e, 0x10, 0x00, 0x01, 0x01, 0x04, (byte)0xc0, (byte)0xa8, 0x04, 0x02, 0x00, 0x0c, (byte)0xab, 0x10, 0x14, (byte)0xc0, (byte)0xa8, (byte)0xf0, })), 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()); MultiProtocolReachableNLRI mp = (MultiProtocolReachableNLRI)packet.getPathAttributes().remove(0); Assert.assertEquals(AddressFamily.IPv4, mp.getAddressFamily()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, mp.getSubsequentAddressFamily()); assertArraysEquals(new byte[] { (byte)0xc0, (byte)0xa8, 0x04, 0x02, }, mp.getNextHop().getAddress()); Assert.assertEquals(2, mp.getNlris().size()); NetworkLayerReachabilityInformation nlri = mp.getNlris().remove(0); Assert.assertEquals(12, nlri.getPrefixLength()); assertArraysEquals(new byte[] { (byte)0xab, 0x10, } , nlri.getPrefix()); nlri = mp.getNlris().remove(0); Assert.assertEquals(20, nlri.getPrefixLength()); assertArraysEquals(new byte[] { (byte)0xc0, (byte)0xa8, (byte)0xf0, } , nlri.getPrefix()); }
@Test public void testDecodeValidMpReachNlriNullNextHopOneNlriUpdatePacket() { UpdatePacket packet; packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x0b, (byte)0x80, 0x0e, 0x08, 0x00, 0x01, 0x01, 0x00, 0x00, 0x0c, (byte)0xab, 0x10, })), 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()); MultiProtocolReachableNLRI mp = (MultiProtocolReachableNLRI)packet.getPathAttributes().remove(0); Assert.assertEquals(AddressFamily.IPv4, mp.getAddressFamily()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, mp.getSubsequentAddressFamily()); Assert.assertNull(mp.getNextHop()); Assert.assertEquals(1, mp.getNlris().size()); NetworkLayerReachabilityInformation nlri = mp.getNlris().remove(0); Assert.assertEquals(12, nlri.getPrefixLength()); assertArraysEquals(new byte[] { (byte)0xab, 0x10, } , nlri.getPrefix()); }
@Test public void testDecodeBogusAfiMpReachNlriUpdatePacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x08, (byte)0x80, 0x0e, 0x05, 0x00, (byte)0xF1, 0x01, 0x00, 0x00, })); } }).execute(OptionalAttributeErrorException.class); }
@Test public void testDecodeBogusSafiMpReachNlriUpdatePacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x08, (byte)0x80, 0x0e, 0x05, 0x00, (byte)0x01, 0x04, 0x00, 0x00, })); } }).execute(OptionalAttributeErrorException.class); }
@Test public void testDecodeBogusNextHopMpReachNlriUpdatePacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x08, (byte)0x80, 0x0e, 0x05, 0x00, (byte)0x01, 0x01, 0x02, 0x00, })); } }).execute(OptionalAttributeErrorException.class); }
@Test public void testDecodeMissingReservedMpReachNlriUpdatePacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x07, (byte)0x80, 0x0e, 0x04, 0x00, (byte)0x01, 0x01, 0x00, })); } }).execute(OptionalAttributeErrorException.class); (new AssertExecption() { @Override protected void doExecute() { decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x0c, (byte)0x80, 0x0e, 0x09, 0x00, (byte)0x01, 0x01, 0x02, 0x00, 0x00, 0x0c, (byte)0xab, 0x10, })); } }).execute(OptionalAttributeErrorException.class); }
@Test public void testDecodeBadNlriMpReachNlriUpdatePacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x0a, (byte)0x80, 0x0e, 0x07, 0x00, (byte)0x01, 0x01, 0x00, 0x00, 0x0c, (byte)0xab, })); } }).execute(OptionalAttributeErrorException.class); }
@Test public void testDecodeValidMpUnreachNlriZeroNlriUpdatePacket() { UpdatePacket packet; packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x06, (byte)0x80, 0x0f, 0x03, 0x00, 0x01, 0x01, })), 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()); MultiProtocolUnreachableNLRI mp = (MultiProtocolUnreachableNLRI)packet.getPathAttributes().remove(0); Assert.assertEquals(AddressFamily.IPv4, mp.getAddressFamily()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, mp.getSubsequentAddressFamily()); Assert.assertEquals(0, mp.getNlris().size()); }
@Test public void testDecodeValidMpUnreachNlriOneNlriUpdatePacket() { UpdatePacket packet; packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x09, (byte)0x80, 0x0f, 0x06, 0x00, 0x01, 0x01, 0x0c, (byte)0xab, 0x10, })), 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()); MultiProtocolUnreachableNLRI mp = (MultiProtocolUnreachableNLRI)packet.getPathAttributes().remove(0); Assert.assertEquals(AddressFamily.IPv4, mp.getAddressFamily()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, mp.getSubsequentAddressFamily()); Assert.assertEquals(1, mp.getNlris().size()); NetworkLayerReachabilityInformation nlri = mp.getNlris().remove(0); Assert.assertEquals(12, nlri.getPrefixLength()); assertArraysEquals(new byte[] { (byte)0xab, 0x10, } , nlri.getPrefix()); }
@Test public void testDecodeValidMpUnreachNlriTwoNlriUpdatePacket() { UpdatePacket packet; packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x0d, (byte)0x80, 0x0f, 0x0a, 0x00, 0x01, 0x01, 0x0c, (byte)0xab, 0x10, 0x14, (byte)0xc0, (byte)0xa8, (byte)0xf0, })), 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()); MultiProtocolUnreachableNLRI mp = (MultiProtocolUnreachableNLRI)packet.getPathAttributes().remove(0); Assert.assertEquals(AddressFamily.IPv4, mp.getAddressFamily()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, mp.getSubsequentAddressFamily()); Assert.assertEquals(2, mp.getNlris().size()); NetworkLayerReachabilityInformation nlri = mp.getNlris().remove(0); Assert.assertEquals(12, nlri.getPrefixLength()); assertArraysEquals(new byte[] { (byte)0xab, 0x10, } , nlri.getPrefix()); nlri = mp.getNlris().remove(0); Assert.assertEquals(20, nlri.getPrefixLength()); assertArraysEquals(new byte[] { (byte)0xc0, (byte)0xa8, (byte)0xf0, } , nlri.getPrefix()); }
@Test public void testDecodeBadNlriMpUnreachNlriUpdatePacket() throws Exception { (new AssertExecption() { @Override protected void doExecute() { decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { 0x00, 0x00, 0x00, 0x08, (byte)0x80, 0x0f, 0x05, 0x00, (byte)0x01, 0x01, 0x0c, (byte)0xab, })); } }).execute(OptionalAttributeErrorException.class); }
@Test public void testDecodeOriginatorIDPacket() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x07, (byte)0x80, (byte)0x09, (byte)0x04, (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()); OriginatorIDPathAttribute originator = (OriginatorIDPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(0xc0a80402, originator.getOriginatorID()); }
@Test public void testDecodeClusterListPacketOneCLusterID() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x07, (byte)0x80, (byte)0x0a, (byte)0x04, (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()); ClusterListPathAttribute originator = (ClusterListPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(1, originator.getClusterIds().size()); Assert.assertEquals(new Integer(0xc0a80402), originator.getClusterIds().remove(0)); }
@Test public void testDecodeClusterListPacketTwoCLusterID() throws Exception { UpdatePacket packet = safeDowncast(decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0b, (byte)0x80, (byte)0x0a, (byte)0x08, (byte)0xc0, (byte)0xa8, (byte)0x04, (byte)0x02, (byte)0xc0, (byte)0xa8, (byte)0x05, (byte)0x03, })), 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()); ClusterListPathAttribute originator = (ClusterListPathAttribute)packet.getPathAttributes().remove(0); Assert.assertEquals(2, originator.getClusterIds().size()); Assert.assertEquals(new Integer(0xc0a80402), originator.getClusterIds().remove(0)); Assert.assertEquals(new Integer(0xc0a80503), originator.getClusterIds().remove(0)); }
@Test public void testDecodeClusterListPacketBrokenCLusterID() throws Exception { (new AssertExecption() { @Override protected void doExecute() { decoder.decodeUpdatePacket(buildProtocolPacket(new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x05, (byte)0x80, (byte)0x0a, (byte)0x02, (byte)0xc0, (byte)0xa8, })); } }).execute(OptionalAttributeErrorException.class); }