Fix binding name for route 12/13512/2
authorMichal Cmarada <[email protected]>
Mon, 9 Jul 2018 11:59:31 +0000 (13:59 +0200)
committerMichal Cmarada <[email protected]>
Wed, 18 Jul 2018 10:25:43 +0000 (12:25 +0200)
In specific case when route uses 128 mask and this value is
converted to byte value it is changed to -128, which breaks
internal naming of routes. This needed to be fixed because
routes with 128 mask are not being read from VPP to operational
state.

Change-Id: Ic3b6ded721e7996587982b6a2b3bc8c9ebe03b43
Signed-off-by: Michal Cmarada <[email protected]>
routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/naming/Ipv6RouteNamesFactory.java
routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/Ipv6RouteNamesFactoryTest.java
routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/read/Ipv6RouteCustomizerTest.java
routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv6RouteCustomizerTest.java
routing/routing-impl/src/test/resources/ipv6/simplehop/simpleHopRoute128.json [new file with mode: 0644]

index da8affb..91370c7 100644 (file)
@@ -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));
     }
 
 
index 2acf9fe..76326bf 100644 (file)
@@ -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;
@@ -86,6 +92,17 @@ public class Ipv6RouteNamesFactoryTest implements RoutingRequestTestHelper, Sche
         assertEquals("tst-protocol_2001-db8-a0b-12f0--1_64", factory.uniqueRouteName(vppRoute, mappingContext));
     }
 
+    @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(
index 81dae7b..fd2844b 100644 (file)
@@ -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"))));
     }
 
@@ -256,6 +277,23 @@ public class Ipv6RouteCustomizerTest extends ListReaderCustomizerTest<Route, Rou
         assertEquals("iface-1", hop.getOutgoingInterface());
     }
 
+    @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 {
 
index 0d78ca5..0e724b8 100644 (file)
@@ -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 (file)
index 0000000..2e75106
--- /dev/null
@@ -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"
+          }
+        }
+      ]
+    }
+  }
+}