CapabilitiesParser { public Capabilities parseConfig(HierarchicalConfiguration hierarchicalConfiguration) throws ConfigurationException { CapabilitiesImpl caps = new CapabilitiesImpl(); int as4Number = hierarchicalConfiguration.getInt("LargeAutonomousSystem[@local]", -1); if(as4Number > 0) { if(hierarchicalConfiguration.getBoolean("LargeAutonomousSystem[@optional]", false)) caps.addOptionalCapability(new AutonomousSystem4Capability(as4Number)); else caps.addRequiredCapability(new AutonomousSystem4Capability(as4Number)); } if(hierarchicalConfiguration.containsKey("RouteRefresh")) { if(hierarchicalConfiguration.getBoolean("RouteRefresh[@optional]", false)) caps.addOptionalCapability(new RouteRefreshCapability()); else caps.addRequiredCapability(new RouteRefreshCapability()); } parseMultiprotocolCapabilities(hierarchicalConfiguration.configurationsAt("MultiProtocol"), caps); parseOutboundRouteFilteringCapabilities(hierarchicalConfiguration.configurationsAt("OutboundRouteFiltering"), caps); return caps; }  Capabilities parseConfig(HierarchicalConfiguration hierarchicalConfiguration);  }
@Test public void testEmptyConfiguration() throws Exception { Capabilities caps = parser.parseConfig(config.configurationAt("Capabilities(0)")); Assert.assertEquals(0, caps.getRequiredCapabilities().size()); }
@Test public void testOneAS4Configuration() throws Exception { Capabilities caps = parser.parseConfig(config.configurationAt("Capabilities(1)")); Iterator<Capability> capIt = caps.getRequiredCapabilities().iterator(); Assert.assertTrue(capIt.hasNext()); AutonomousSystem4Capability cap = (AutonomousSystem4Capability)capIt.next(); Assert.assertEquals(256, cap.getAutonomousSystem()); Assert.assertFalse(capIt.hasNext()); }
@Test public void testTwoAS4Configuration() throws Exception { Capabilities caps = parser.parseConfig(config.configurationAt("Capabilities(2)")); Iterator<Capability> capIt = caps.getRequiredCapabilities().iterator(); Assert.assertTrue(capIt.hasNext()); AutonomousSystem4Capability cap = (AutonomousSystem4Capability)capIt.next(); Assert.assertEquals(256, cap.getAutonomousSystem()); Assert.assertFalse(capIt.hasNext()); }
@Test public void testOneRouteRefreshConfiguration() throws Exception { Capabilities caps = parser.parseConfig(config.configurationAt("Capabilities(3)")); Iterator<Capability> capIt = caps.getRequiredCapabilities().iterator(); Assert.assertTrue(capIt.hasNext()); Assert.assertEquals(RouteRefreshCapability.class, capIt.next().getClass()); Assert.assertFalse(capIt.hasNext()); }
@Test public void testOneMultiProtoclConfiguration() throws Exception { Capabilities caps = parser.parseConfig(config.configurationAt("Capabilities(4)")); Iterator<Capability> capIt = caps.getRequiredCapabilities().iterator(); Assert.assertTrue(capIt.hasNext()); MultiProtocolCapability cap = (MultiProtocolCapability)capIt.next(); Assert.assertEquals(AddressFamily.IPv4, cap.getAfi()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, cap.getSafi()); Assert.assertFalse(capIt.hasNext()); }
@Test public void testTwoMultiProtoclConfiguration() throws Exception { Capabilities caps = parser.parseConfig(config.configurationAt("Capabilities(5)")); Iterator<Capability> capIt = caps.getRequiredCapabilities().iterator(); Assert.assertTrue(capIt.hasNext()); MultiProtocolCapability cap = (MultiProtocolCapability)capIt.next(); Assert.assertEquals(AddressFamily.IPv4, cap.getAfi()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, cap.getSafi()); Assert.assertTrue(capIt.hasNext()); cap = (MultiProtocolCapability)capIt.next(); Assert.assertEquals(AddressFamily.IPv6, cap.getAfi()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, cap.getSafi()); Assert.assertFalse(capIt.hasNext()); }
@Test public void testOneOutboundRouteFilteringConfiguration() throws Exception { Capabilities caps = parser.parseConfig(config.configurationAt("Capabilities(6)")); Iterator<Capability> capIt = caps.getRequiredCapabilities().iterator(); Assert.assertTrue(capIt.hasNext()); OutboundRouteFilteringCapability cap = (OutboundRouteFilteringCapability)capIt.next(); Map<ORFType, ORFSendReceive> filters = cap.getFilters(); Assert.assertEquals(AddressFamily.IPv4, cap.getAddressFamily()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, cap.getSubsequentAddressFamily()); Assert.assertEquals(1, filters.size()); Assert.assertTrue(filters.containsKey(ORFType.ADDRESS_PREFIX_BASED)); Assert.assertEquals(ORFSendReceive.BOTH, filters.get(ORFType.ADDRESS_PREFIX_BASED)); Assert.assertFalse(capIt.hasNext()); }
@Test public void testTwoOutboundRouteFilteringConfiguration() throws Exception { Capabilities caps = parser.parseConfig(config.configurationAt("Capabilities(7)")); Iterator<Capability> capIt = caps.getRequiredCapabilities().iterator(); Assert.assertTrue(capIt.hasNext()); OutboundRouteFilteringCapability cap = (OutboundRouteFilteringCapability)capIt.next(); Map<ORFType, ORFSendReceive> filters = cap.getFilters(); Assert.assertEquals(AddressFamily.IPv4, cap.getAddressFamily()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, cap.getSubsequentAddressFamily()); Assert.assertEquals(1, filters.size()); Assert.assertTrue(filters.containsKey(ORFType.ADDRESS_PREFIX_BASED)); Assert.assertEquals(ORFSendReceive.BOTH, filters.get(ORFType.ADDRESS_PREFIX_BASED)); cap = (OutboundRouteFilteringCapability)capIt.next(); filters = cap.getFilters(); Assert.assertEquals(AddressFamily.IPv6, cap.getAddressFamily()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, cap.getSubsequentAddressFamily()); Assert.assertEquals(1, filters.size()); Assert.assertTrue(filters.containsKey(ORFType.ADDRESS_PREFIX_BASED)); Assert.assertEquals(ORFSendReceive.BOTH, filters.get(ORFType.ADDRESS_PREFIX_BASED)); Assert.assertFalse(capIt.hasNext()); }
@Test public void testOneAS4TwoMultiProtoclConfiguration() throws Exception { Capabilities caps = parser.parseConfig(config.configurationAt("Capabilities(8)")); Iterator<Capability> capIt = caps.getRequiredCapabilities().iterator(); Assert.assertTrue(capIt.hasNext()); AutonomousSystem4Capability as4cap = (AutonomousSystem4Capability)capIt.next(); Assert.assertEquals(256, as4cap.getAutonomousSystem()); Assert.assertTrue(capIt.hasNext()); MultiProtocolCapability cap = (MultiProtocolCapability)capIt.next(); Assert.assertEquals(AddressFamily.IPv4, cap.getAfi()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, cap.getSafi()); Assert.assertTrue(capIt.hasNext()); cap = (MultiProtocolCapability)capIt.next(); Assert.assertEquals(AddressFamily.IPv6, cap.getAfi()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, cap.getSafi()); Assert.assertFalse(capIt.hasNext()); }
@Test public void testRequiredOneAS4OptionalTwoMultiProtoclConfiguration() throws Exception { Capabilities caps = parser.parseConfig(config.configurationAt("Capabilities(9)")); Iterator<Capability> capIt = caps.getRequiredCapabilities().iterator(); Assert.assertTrue(capIt.hasNext()); AutonomousSystem4Capability as4cap = (AutonomousSystem4Capability)capIt.next(); Assert.assertEquals(256, as4cap.getAutonomousSystem()); Assert.assertFalse(capIt.hasNext()); capIt = caps.getOptionalCapabilities().iterator(); Assert.assertTrue(capIt.hasNext()); MultiProtocolCapability cap = (MultiProtocolCapability)capIt.next(); Assert.assertEquals(AddressFamily.IPv4, cap.getAfi()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, cap.getSafi()); Assert.assertTrue(capIt.hasNext()); cap = (MultiProtocolCapability)capIt.next(); Assert.assertEquals(AddressFamily.IPv6, cap.getAfi()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, cap.getSafi()); Assert.assertFalse(capIt.hasNext()); }