diff options
Diffstat (limited to 'routing')
5 files changed, 91 insertions, 4 deletions
diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/naming/Ipv6RouteNamesFactory.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/naming/Ipv6RouteNamesFactory.java index da8affb7b..91370c7fd 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/naming/Ipv6RouteNamesFactory.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/naming/Ipv6RouteNamesFactory.java @@ -56,7 +56,7 @@ public final class Ipv6RouteNamesFactory implements RouteMapper, RouteRequestPro return bindName(parentProtocolName, // to have address in compressed form doubleDotlessAddress(route.getDestinationPrefix()), - String.valueOf(extractPrefix(route.getDestinationPrefix()))); + route.getDestinationPrefix().getValue().substring(route.getDestinationPrefix().getValue().indexOf('/') + 1)); } /** @@ -72,7 +72,8 @@ public final class Ipv6RouteNamesFactory implements RouteMapper, RouteRequestPro * Construct unique name from provided parentProtocolName and {@code Ipv6Prefix} */ public String uniqueRouteName(@Nonnull final String parentProtocolName, @Nonnull final Ipv6Prefix prefix) { - return bindName(parentProtocolName, doubleDotlessAddress(prefix), String.valueOf(extractPrefix(prefix))); + return bindName(parentProtocolName, doubleDotlessAddress(prefix), + prefix.getValue().substring(prefix.getValue().indexOf('/') + 1)); } diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/Ipv6RouteNamesFactoryTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/Ipv6RouteNamesFactoryTest.java index 2acf9fe4f..76326bf04 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/Ipv6RouteNamesFactoryTest.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/Ipv6RouteNamesFactoryTest.java @@ -53,6 +53,7 @@ public class Ipv6RouteNamesFactoryTest implements RoutingRequestTestHelper, Sche private NamingContext interfaceContext; private NamingContext routingProtocolContext; private Ip6FibDetails vppRoute; + private Ip6FibDetails vppRoute128; private FibPath vppPath; private Ipv6RouteNamesFactory factory; @@ -66,6 +67,11 @@ public class Ipv6RouteNamesFactoryTest implements RoutingRequestTestHelper, Sche vppRoute.addressLength = 64; vppRoute.tableId = 1; + vppRoute128 = new Ip6FibDetails(); + vppRoute128.address = FIRST_ADDRESS_AS_ARRAY; + vppRoute128.addressLength = (byte) 128; + vppRoute128.tableId = 1; + vppPath = new FibPath(); vppPath.nextHop = FIRST_ADDRESS_AS_ARRAY; vppPath.swIfIndex = 2; @@ -87,6 +93,17 @@ public class Ipv6RouteNamesFactoryTest implements RoutingRequestTestHelper, Sche } @Test + public void testUniqueRouteName128( + @InjectTestData(resourcePath = "/ipv6/simplehop/simpleHopRoute128.json", id = STATIC_ROUTE_PATH) + StaticRoutes data) { + assertEquals("tst-protocol_2001-db8-a0b-12f0--1_128", + factory.uniqueRouteName(ROUTE_PROTOCOL_NAME, + getIpv6RouteWithId(data, + new Ipv6Prefix("2001:0db8:0a0b:12f0:0000:0000:0000:0001/128")))); + assertEquals("tst-protocol_2001-db8-a0b-12f0--1_128", factory.uniqueRouteName(vppRoute128, mappingContext)); + } + + @Test public void testUniqueRouteHopName() { assertEquals("iface_2001-db8-a0b-12f0--1_3", factory.uniqueRouteHopName( new NextHopBuilder() diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/read/Ipv6RouteCustomizerTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/read/Ipv6RouteCustomizerTest.java index 81dae7bfd..fd2844bd6 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/read/Ipv6RouteCustomizerTest.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/read/Ipv6RouteCustomizerTest.java @@ -101,6 +101,7 @@ public class Ipv6RouteCustomizerTest extends ListReaderCustomizerTest<Route, Rou private InstanceIdentifier<Route> routeIdSpecialHop; private InstanceIdentifier<Route> routeIdSimpleHop; + private InstanceIdentifier<Route> routeIdSimpleHop128; private InstanceIdentifier<Route> routeIdListHop; private Ipv6RouteNamesFactory factory; @@ -131,6 +132,8 @@ public class Ipv6RouteCustomizerTest extends ListReaderCustomizerTest<Route, Rou ipv6InstanceIdentifier.child(Route.class, new RouteKey(new Ipv6Prefix("2001:db8:a0b:12f0::2/22"))); routeIdListHop = ipv6InstanceIdentifier.child(Route.class, new RouteKey(new Ipv6Prefix("2001:db8:a0b:12f0::2/16"))); + routeIdSimpleHop128 = + ipv6InstanceIdentifier.child(Route.class, new RouteKey(new Ipv6Prefix("2001:db8:a0b:12f0::2/128"))); factory = new Ipv6RouteNamesFactory(interfaceContext, routingProtocolContext); @@ -138,6 +141,7 @@ public class Ipv6RouteCustomizerTest extends ListReaderCustomizerTest<Route, Rou final Ip6FibDetailsReplyDump replyDump = replyDump(); when(executor.executeDump(routeIdSpecialHop, EntityDumpExecutor.NO_PARAMS)).thenReturn(replyDump); when(executor.executeDump(routeIdSimpleHop, EntityDumpExecutor.NO_PARAMS)).thenReturn(replyDump); + when(executor.executeDump(routeIdSimpleHop128, EntityDumpExecutor.NO_PARAMS)).thenReturn(replyDump); when(executor.executeDump(routeIdListHop, EntityDumpExecutor.NO_PARAMS)).thenReturn(replyDump); defineMapping(mappingContext, "iface-1", 1, "interface-context"); @@ -150,6 +154,8 @@ public class Ipv6RouteCustomizerTest extends ListReaderCustomizerTest<Route, Rou Ip6FibDetails listRoute = replyDump.ip6FibDetails.get(2); String listRouteName = factory.uniqueRouteName(listRoute, mappingContext); defineMapping(mappingContext, listRouteName, 3, "route-context"); + defineMapping(mappingContext, factory.uniqueRouteName(replyDump.ip6FibDetails.get(3), mappingContext), 4, + "route-context"); addMapping(classifyManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext); @@ -210,7 +216,21 @@ public class Ipv6RouteCustomizerTest extends ListReaderCustomizerTest<Route, Rou detail3.path = new FibPath[]{path3, path4}; - replyDump.ip6FibDetails = Arrays.asList(detail1, detail2, detail3); + //second is simple + Ip6FibDetails detail4 = new Ip6FibDetails(); + detail4.tableId = 1; + detail4.address = Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY; + detail4.addressLength = (byte) 128; + detail4.path = new FibPath[]{}; + + FibPath path5 = new FibPath(); + path5.weight = 3; + path5.nextHop = Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY; + path5.afi = 0; + path5.swIfIndex = 1; + detail4.path = new FibPath[]{path5}; + + replyDump.ip6FibDetails = Arrays.asList(detail1, detail2, detail3, detail4); return replyDump; } @@ -218,9 +238,10 @@ public class Ipv6RouteCustomizerTest extends ListReaderCustomizerTest<Route, Rou public void getAllIds() throws Exception { final List<RouteKey> keys = getCustomizer().getAllIds(routeIdSpecialHop, ctx); - assertThat(keys, hasSize(3)); + assertThat(keys, hasSize(4)); assertThat(keys, hasItems(new RouteKey(new Ipv6Prefix("2001:db8:a0b:12f0::1/24")), new RouteKey(new Ipv6Prefix("2001:db8:a0b:12f0::2/22")), + new RouteKey(new Ipv6Prefix("2001:db8:a0b:12f0::2/128")), new RouteKey(new Ipv6Prefix("2001:db8:a0b:12f0::2/16")))); } @@ -257,6 +278,23 @@ public class Ipv6RouteCustomizerTest extends ListReaderCustomizerTest<Route, Rou } @Test + public void readCurrentAttributesSimpleHop128() throws Exception { + final RouteBuilder builder = new RouteBuilder(); + getCustomizer().readCurrentAttributes(routeIdSimpleHop128, builder, ctx); + + assertEquals(new Ipv6Prefix("2001:db8:a0b:12f0::2/128"), builder.getDestinationPrefix()); + assertEquals("2001:db8:a0b:12f0::2/128", builder.getDestinationPrefix().getValue()); + + NextHopOptions hopOptions = builder.getNextHop().getNextHopOptions(); + assertTrue(hopOptions instanceof SimpleNextHop); + + SimpleNextHop hop = SimpleNextHop.class.cast(hopOptions); + assertEquals("2001:db8:a0b:12f0::1", hop.getAugmentation(SimpleNextHop1.class) + .getNextHopAddress().getValue()); + assertEquals("iface-1", hop.getOutgoingInterface()); + } + + @Test public void readCurrentAttributesListHop() throws Exception { diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv6RouteCustomizerTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv6RouteCustomizerTest.java index 0d78ca536..0e724b874 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv6RouteCustomizerTest.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv6RouteCustomizerTest.java @@ -60,6 +60,7 @@ public class Ipv6RouteCustomizerTest extends RouteCustomizerTest { .setKey(SEC_TABLE_KEY).setTableId(SEC_TABLE_KEY.getTableId()) .setAddressFamily(SEC_TABLE_KEY.getAddressFamily()).build(); private static final Ipv6Prefix IPV_6_PREFIX = new Ipv6Prefix("2001:0db8:0a0b:12f0:0000:0000:0000:0001/64"); + private static final Ipv6Prefix IPV_6_PREFIX_128 = new Ipv6Prefix("2001:0db8:0a0b:12f0:0000:0000:0000:0001/128"); private static final InstanceIdentifier<Route> ROUTE_IID = CONTROL_PROTOCOL_IID .child(StaticRoutes.class) @@ -110,6 +111,18 @@ public class Ipv6RouteCustomizerTest extends RouteCustomizerTest { 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); } + @Test + public void testWriteSingleHop128( + @InjectTestData(resourcePath = "/ipv6/simplehop/simpleHopRoute128.json", id = STATIC_ROUTE_PATH) StaticRoutes route) + throws WriteFailedException { + whenAddRouteThenSuccess(api); + customizer.writeCurrentAttributes(ROUTE_IID, getIpv6RouteWithId(route, IPV_6_PREFIX_128), writeContext); + verifyInvocation(1, ImmutableList + .of(desiredFlaglessResult(1, 1, 0, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 128, + Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 0, TABLE_ID.intValue(), + 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); + } + //TODO - https://jira.fd.io/browse/HONEYCOMB-396 @Test public void testWriteTableLookup() throws WriteFailedException { diff --git a/routing/routing-impl/src/test/resources/ipv6/simplehop/simpleHopRoute128.json b/routing/routing-impl/src/test/resources/ipv6/simplehop/simpleHopRoute128.json new file mode 100644 index 000000000..2e7510607 --- /dev/null +++ b/routing/routing-impl/src/test/resources/ipv6/simplehop/simpleHopRoute128.json @@ -0,0 +1,18 @@ +{ + "static-routes": { + "ipv6": { + "route": [ + { + "destination-prefix": "2001:0db8:0a0b:12f0:0000:0000:0000:0001/128", + "next-hop": { + "next-hop-address" : "2001:0db8:0a0b:12f0:0000:0000:0000:0002", + "outgoing-interface": "iface" + }, + "vpp-ipv6-route" : { + "classify-table": "classify-table-one" + } + } + ] + } + } +} |