UpdatePacket extends BGPv4Packet { @SuppressWarnings("unchecked") public <T extends PathAttribute> Set<T> lookupPathAttributes(Class<T> paClass) { Set<T> result = new HashSet<T>(); for(PathAttribute pa : pathAttributes) { if(pa.getClass().equals(paClass)) result.add((T)pa); } return result; }  int calculatePacketSize(); @Override int getType(); List<NetworkLayerReachabilityInformation> getWithdrawnRoutes(); void setWithdrawnRoutes(List<NetworkLayerReachabilityInformation> withdrawnRoutes); List<NetworkLayerReachabilityInformation> getNlris(); void setNlris(List<NetworkLayerReachabilityInformation> nlris); List<PathAttribute> getPathAttributes(); void setPathAttributes(List<PathAttribute> pathAttributes); @SuppressWarnings("unchecked") Set<T> lookupPathAttributes(Class<T> paClass); Set<PathAttribute> filterPathAttributes(Class<? extends PathAttribute>... filteredClasses); String toString();  }
@Test public void testLookupPathAttributes() { UpdatePacket packet = new UpdatePacket(); MultiProtocolReachableNLRI reachableIPv4Unicast = new MultiProtocolReachableNLRI(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING); MultiProtocolReachableNLRI reachableIPv6Unicast = new MultiProtocolReachableNLRI(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING); MultiProtocolUnreachableNLRI unreachableIPv4Unicast = new MultiProtocolUnreachableNLRI(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING); MultiProtocolUnreachableNLRI unreachableIPv6Unicast = new MultiProtocolUnreachableNLRI(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING); packet.getPathAttributes().add(reachableIPv6Unicast); packet.getPathAttributes().add(reachableIPv4Unicast); packet.getPathAttributes().add(unreachableIPv6Unicast); packet.getPathAttributes().add(unreachableIPv4Unicast); Set<MultiProtocolReachableNLRI> reachables = packet.lookupPathAttributes(MultiProtocolReachableNLRI.class); Set<MultiProtocolUnreachableNLRI> unreachables = packet.lookupPathAttributes(MultiProtocolUnreachableNLRI.class); Assert.assertNotNull(reachables); Assert.assertNotNull(unreachables); Assert.assertEquals(2, reachables.size()); Assert.assertEquals(2, unreachables.size()); Assert.assertTrue(reachables.contains(reachableIPv4Unicast)); Assert.assertTrue(reachables.contains(reachableIPv6Unicast)); Assert.assertTrue(unreachables.contains(unreachableIPv4Unicast)); Assert.assertTrue(unreachables.contains(unreachableIPv6Unicast)); }