@Test
 public void testDecodeConnectionCollisionResolutionNotificationPacket() {
   safeDowncast(
       decoder.decodePacket(
           buildProtocolPacket(
               new byte[] {
                 (byte) 0x03, // type code NOTIFICATION
                 (byte) 0x06, // CEASE error code
                 (byte) 0x07, // Connection collision resolution
               })),
       ConnectionCollisionResolutionNotificationPacket.class);
 }
 @Test
 public void testDecodeUnknownCeaseNotificationPacket() {
   safeDowncast(
       decoder.decodePacket(
           buildProtocolPacket(
               new byte[] {
                 (byte) 0x03, // type code NOTIFICATION
                 (byte) 0x06, // CEASE error code
                 (byte) 0x0f, // Unknown subcode
               })),
       UnspecifiedCeaseNotificationPacket.class);
 }
 @Test
 public void testDecodeOutOfResourcesNotificationPacket() {
   safeDowncast(
       decoder.decodePacket(
           buildProtocolPacket(
               new byte[] {
                 (byte) 0x03, // type code NOTIFICATION
                 (byte) 0x06, // CEASE error code
                 (byte) 0x08, // UNSPECIFIC
               })),
       OutOfResourcesNotificationPacket.class);
 }
 @Test
 public void testDecodeOtherConfigurationChangeNotificationPacket() {
   safeDowncast(
       decoder.decodePacket(
           buildProtocolPacket(
               new byte[] {
                 (byte) 0x03, // type code NOTIFICATION
                 (byte) 0x06, // CEASE error code
                 (byte) 0x06, // Other configuration change
               })),
       OtherConfigurationChangeNotificationPacket.class);
 }
 @Test
 public void testDecodeAdministrativeResetNotificationPacket() {
   safeDowncast(
       decoder.decodePacket(
           buildProtocolPacket(
               new byte[] {
                 (byte) 0x03, // type code NOTIFICATION
                 (byte) 0x06, // CEASE error code
                 (byte) 0x04, // Administrative reset
               })),
       AdministrativeResetNotificationPacket.class);
 }
 @Test
 public void testDecodePeerDecofiguredNotificationPacket() {
   safeDowncast(
       decoder.decodePacket(
           buildProtocolPacket(
               new byte[] {
                 (byte) 0x03, // type code NOTIFICATION
                 (byte) 0x06, // CEASE error code
                 (byte) 0x03, // Peer deconfigured
               })),
       PeerDeconfiguredNotificationPacket.class);
 }
 @Test
 public void testDecodeAdministrativeShutdownNotificationPacket() {
   safeDowncast(
       decoder.decodePacket(
           buildProtocolPacket(
               new byte[] {
                 (byte) 0x03, // type code NOTIFICATION
                 (byte) 0x06, // CEASE error code
                 (byte) 0x02, // ADMINISTRATIVE SHUTDOWN
               })),
       AdministrativeShutdownNotificationPacket.class);
 }
  @Test
  public void testDecodeUnsupportedCapabilityNotificationPacket() {
    CapabilityListUnsupportedCapabilityNotificationPacket packet =
        safeDowncast(
            decoder.decodePacket(
                buildProtocolPacket(
                    new byte[] {
                      (byte) 0x03, // type code NOTIFICATION
                      (byte) 0x02, // error code: BGP Open
                      (byte) 0x07, // suberror code: Unsupported capability
                      (byte) 0x41, // Capability code 65: 4-octet AS numbers
                      (byte) 0x04, // Capability length: 4 octets
                      (byte) 0x00,
                      (byte) 0x00,
                      (byte) 0xfc,
                      (byte) 0x00, // AS number 64512
                      0x02, // Capability code 2: Route refresh
                      0x00, // Capability length: 0 octets
                      0x01, // Capability code 1: Multi-Protocol
                      0x04, // Capability length: 4 octets
                      0x00,
                      0x01, // Address Family 1: IPv4
                      0x00, // reserved
                      0x01, // Subsequent address family 1: Unicast forwarding
                    })),
            CapabilityListUnsupportedCapabilityNotificationPacket.class);

    Iterator<Capability> capIt = packet.getCapabilities().iterator();

    Assert.assertTrue(capIt.hasNext());
    AutonomousSystem4Capability as4cap = (AutonomousSystem4Capability) capIt.next();
    Assert.assertEquals(64512, as4cap.getAutonomousSystem());

    Assert.assertTrue(capIt.hasNext());
    Assert.assertEquals(RouteRefreshCapability.class, capIt.next().getClass());

    Assert.assertTrue(capIt.hasNext());
    MultiProtocolCapability mpCap = (MultiProtocolCapability) capIt.next();
    Assert.assertEquals(AddressFamily.IPv4, mpCap.getAfi());
    Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, mpCap.getSafi());

    Assert.assertFalse(capIt.hasNext());
  }
  @Test
  public void testDecodeMaximumNumberOfPrefixesReachedNotificationPacket() {
    MaximumNumberOfPrefixesReachedNotificationPacket packet =
        safeDowncast(
            decoder.decodePacket(
                buildProtocolPacket(
                    new byte[] {
                      (byte) 0x03, // type code NOTIFICATION
                      (byte) 0x06, // CEASE error code
                      (byte) 0x01, // Maximum number of prefixes reached
                    })),
            MaximumNumberOfPrefixesReachedNotificationPacket.class);

    Assert.assertNull(packet.getAddressFamily());
    Assert.assertNull(packet.getSubsequentAddressFamily());
    Assert.assertEquals(0, packet.getPrefixUpperBound());

    packet =
        safeDowncast(
            decoder.decodePacket(
                buildProtocolPacket(
                    new byte[] {
                      (byte) 0x03, // type code NOTIFICATION
                      (byte) 0x06, // CEASE error code
                      (byte) 0x01, // Maximum number of prefixes reached
                      0x01, // AFI IPv4
                    })),
            MaximumNumberOfPrefixesReachedNotificationPacket.class);

    Assert.assertNull(packet.getAddressFamily());
    Assert.assertNull(packet.getSubsequentAddressFamily());
    Assert.assertEquals(0, packet.getPrefixUpperBound());

    packet =
        safeDowncast(
            decoder.decodePacket(
                buildProtocolPacket(
                    new byte[] {
                      (byte) 0x03, // type code NOTIFICATION
                      (byte) 0x06, // CEASE error code
                      (byte) 0x01, // Maximum number of prefixes reached
                      0x00,
                      0x01, // AFI IPv4
                      0x01, // SAI Unicast forwarding
                    })),
            MaximumNumberOfPrefixesReachedNotificationPacket.class);

    Assert.assertNull(packet.getAddressFamily());
    Assert.assertNull(packet.getSubsequentAddressFamily());
    Assert.assertEquals(0, packet.getPrefixUpperBound());

    packet =
        safeDowncast(
            decoder.decodePacket(
                buildProtocolPacket(
                    new byte[] {
                      (byte) 0x03, // type code NOTIFICATION
                      (byte) 0x06, // CEASE error code
                      (byte) 0x01, // Maximum number of prefixes reached
                      0x00,
                      0x7f, // AFI Illegal
                      0x01, // SAFI Unicast routing
                      0x00,
                      0x00,
                      0x12,
                      0x34, // upper bound 0x1234
                    })),
            MaximumNumberOfPrefixesReachedNotificationPacket.class);

    Assert.assertNull(packet.getAddressFamily());
    Assert.assertNull(packet.getSubsequentAddressFamily());
    Assert.assertEquals(0, packet.getPrefixUpperBound());

    packet =
        safeDowncast(
            decoder.decodePacket(
                buildProtocolPacket(
                    new byte[] {
                      (byte) 0x03, // type code NOTIFICATION
                      (byte) 0x06, // CEASE error code
                      (byte) 0x01, // Maximum number of prefixes reached
                      0x00,
                      0x01, // AFI IPv4
                      0x01, // SAFI Unicast routing
                      0x00,
                      0x00,
                      0x12,
                      0x34, // upper bound 0x1234
                    })),
            MaximumNumberOfPrefixesReachedNotificationPacket.class);

    Assert.assertEquals(AddressFamily.IPv4, packet.getAddressFamily());
    Assert.assertEquals(
        SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, packet.getSubsequentAddressFamily());
    Assert.assertEquals(0x1234, packet.getPrefixUpperBound());
  }