RouteConfigurationParser { public RouteConfiguration parseConfiguration(HierarchicalConfiguration config) throws ConfigurationException { String prefix = config.getString("Prefix[@value]"); List<HierarchicalConfiguration> pa = config.configurationsAt("PathAttributes"); if(StringUtils.isBlank(prefix)) throw new ConfigurationException("NLRI missing"); if(pa.size() > 1) throw new ConfigurationException("PathAttributes missing of given multiple times"); else { PathAttributeConfiguration pac = new PathAttributeConfigurationImpl(); if(pa.size() == 1) pac = pathAttrParser.parseConfiguration(pa.get(0)); return new RouteConfigurationImpl(nlriParser.parseNlri(prefix), pac); } }  RouteConfiguration parseConfiguration(HierarchicalConfiguration config);  }
@Test public void testParseIpV4NoDefault() throws Exception { RouteConfiguration route = parser.parseConfiguration(config.configurationAt("Route(0)")); Assert.assertNotNull(route.getNlri()); Assert.assertEquals(new NetworkLayerReachabilityInformation(24, new byte[] { (byte)0xc0, (byte)0xa8, (byte)0x01 }), route.getNlri()); Assert.assertNotNull(route.getPathAttributes()); Assert.assertEquals(1, route.getPathAttributes().getAttributes().size()); }
@Test public void testParseIpV4Default() throws Exception { RouteConfiguration route = parser.parseConfiguration(config.configurationAt("Route(1)")); Assert.assertNotNull(route.getNlri()); Assert.assertEquals(new NetworkLayerReachabilityInformation(0, null), route.getNlri()); Assert.assertNotNull(route.getPathAttributes()); Assert.assertEquals(1, route.getPathAttributes().getAttributes().size()); }
@Test public void testBadPrefix() { for(int i=2; i<6; i++) { boolean caught = false; String key = "Route(" + i + ")"; try { parser.parseConfiguration(config.configurationAt(key)); } catch(ConfigurationException e) { caught = true; } Assert.assertTrue(key, caught); } }
@Test public void testBadIPv4Prefixe() { for(int i=6; i<13; i++) { boolean caught = false; String key = "Route(" + i + ")"; try { parser.parseConfiguration(config.configurationAt(key)); } catch(ConfigurationException e) { caught = true; } Assert.assertTrue(key, caught); } }
@Test public void testParseIpV6FullLength() throws Exception { RouteConfiguration route = parser.parseConfiguration(config.configurationAt("Route(13)")); Assert.assertNotNull(route.getNlri()); Assert.assertEquals(new NetworkLayerReachabilityInformation(60, new byte[] { (byte)0x20, (byte)0x01, (byte)0x0d, (byte)0xb8, (byte)0x00, (byte)0x00, (byte)0xcd, (byte)0x30 }), route.getNlri()); Assert.assertNotNull(route.getPathAttributes()); Assert.assertEquals(1, route.getPathAttributes().getAttributes().size()); }
@Test public void testParseIpV6ShortLength() throws Exception { RouteConfiguration route = parser.parseConfiguration(config.configurationAt("Route(14)")); Assert.assertNotNull(route.getNlri()); Assert.assertEquals(new NetworkLayerReachabilityInformation(60, new byte[] { (byte)0x20, (byte)0x01, (byte)0x0d, (byte)0xb8, (byte)0x00, (byte)0x00, (byte)0xcd, (byte)0x30 }), route.getNlri()); Assert.assertNotNull(route.getPathAttributes()); Assert.assertEquals(1, route.getPathAttributes().getAttributes().size()); }
@Test public void testParseIpV6Compact() throws Exception { RouteConfiguration route = parser.parseConfiguration(config.configurationAt("Route(15)")); Assert.assertNotNull(route.getNlri()); Assert.assertEquals(new NetworkLayerReachabilityInformation(60, new byte[] { (byte)0x20, (byte)0x01, (byte)0x0d, (byte)0xb8, (byte)0x00, (byte)0x00, (byte)0xcd, (byte)0x30 }), route.getNlri()); Assert.assertNotNull(route.getPathAttributes()); Assert.assertEquals(1, route.getPathAttributes().getAttributes().size()); }
@Test public void testParseIpV6Default() throws Exception { RouteConfiguration route = parser.parseConfiguration(config.configurationAt("Route(16)")); Assert.assertNotNull(route.getNlri()); Assert.assertEquals(new NetworkLayerReachabilityInformation(0, null), route.getNlri()); Assert.assertNotNull(route.getPathAttributes()); Assert.assertEquals(1, route.getPathAttributes().getAttributes().size()); }
@Test public void testBadIPv6Prefixe() { for(int i=17; i<22; i++) { boolean caught = false; String key = "Route(" + i + ")"; try { parser.parseConfiguration(config.configurationAt(key)); } catch(ConfigurationException e) { caught = true; } Assert.assertTrue(key, caught); } }
@Test public void testParseBinary() throws Exception { RouteConfiguration route = parser.parseConfiguration(config.configurationAt("Route(23)")); Assert.assertNotNull(route.getNlri()); Assert.assertEquals(new NetworkLayerReachabilityInformation(60, new byte[] { (byte)0x20, (byte)0x01, (byte)0x0d, (byte)0xb8, (byte)0x00, (byte)0x00, (byte)0xcd, (byte)0x30 }), route.getNlri()); Assert.assertNotNull(route.getPathAttributes()); Assert.assertEquals(1, route.getPathAttributes().getAttributes().size()); }
@Test public void testBadBinaryPrefixe() { for(int i=24; i<27; i++) { boolean caught = false; String key = "Route(" + i + ")"; try { parser.parseConfiguration(config.configurationAt(key)); } catch(ConfigurationException e) { caught = true; } Assert.assertTrue(key, caught); } }