diff options
author | Michal Cmarada <michal.cmarada@pantheon.tech> | 2018-06-22 11:02:27 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2018-06-22 10:53:36 +0000 |
commit | 4e8127d8f74726b2ffdf8af89ae879cfa79466f6 (patch) | |
tree | 7e0b7932decf0c67781a4f556db6089cb0bec818 /routing/routing-impl/src/test/java/io/fd | |
parent | b9e58bf303a099805ecb24ca3a97027b3c34a211 (diff) |
HC2VPP-344: Add FIB table management for routing
- update models with FIB table management
- fixes implementation for FIB table management
Change-Id: I5cf397d6e827cb14df970e14ee268ef870931bd4
Signed-off-by: Michal Cmarada <michal.cmarada@pantheon.tech>
Diffstat (limited to 'routing/routing-impl/src/test/java/io/fd')
5 files changed, 312 insertions, 132 deletions
diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/RoutingModuleTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/RoutingModuleTest.java index a12d0e0cc..679b90316 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/RoutingModuleTest.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/RoutingModuleTest.java @@ -31,7 +31,6 @@ import com.google.inject.name.Named; import com.google.inject.testing.fieldbinder.Bind; import com.google.inject.testing.fieldbinder.BoundFieldModule; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.fib.management.services.FibTableService; import io.fd.hc2vpp.routing.read.RoutingReaderFactory; import io.fd.hc2vpp.routing.write.RoutingWriterFactory; import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager; @@ -73,10 +72,6 @@ public class RoutingModuleTest { @Mock private FutureJVppCore futureJVppCore; - @Bind - @Mock - private FibTableService fibTableService; - @Inject private Set<ReaderFactory> readerFactories = new HashSet<>(); diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizerTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizerTest.java index c96e31373..8d49f810d 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizerTest.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizerTest.java @@ -20,45 +20,68 @@ import static io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper.ROUTE_PROTOC import static io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper.ROUTE_PROTOCOL_NAME_2; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.Mockito.when; +import com.google.common.base.Optional; import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.fib.management.services.FibTableService; +import io.fd.hc2vpp.fib.management.FibManagementIIds; import io.fd.honeycomb.translate.write.WriteFailedException; import org.junit.Before; import org.junit.Test; -import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.Direct; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.Static; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.ControlPlaneProtocols; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocol; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocolBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocolKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev180319.RoutingProtocolVppAttr; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev180319.RoutingProtocolVppAttrBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev180319.routing.control.plane.protocols.control.plane.protocol.VppProtocolAttributesBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.types.rev180406.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; public class ControlPlaneProtocolCustomizerTest extends WriterCustomizerTest { + private static final VniReference VRF = new VniReference(1L); + private static final VniReference INVALID_VRF = new VniReference(3L); + private static final String INVALID_TABLE_PROTOCOL_1 = "invalid-table-protocol-1"; private InstanceIdentifier<ControlPlaneProtocol> validId; + private InstanceIdentifier<ControlPlaneProtocol> invalidIid; private ControlPlaneProtocol validData; private ControlPlaneProtocol validData2; private ControlPlaneProtocol invalidData; + private ControlPlaneProtocol invalidTableData; private ControlPlaneProtocolCustomizer customizer; private NamingContext routingProtocolContext; - @Mock - protected FibTableService fibTableService; - @Before public void init() { validId = InstanceIdentifier.create(ControlPlaneProtocol.class); + invalidIid = InstanceIdentifier.create(ControlPlaneProtocols.class) + .child(ControlPlaneProtocol.class, + new ControlPlaneProtocolKey(INVALID_TABLE_PROTOCOL_1, Static.class)); + invalidTableData = new ControlPlaneProtocolBuilder() + .setName(INVALID_TABLE_PROTOCOL_1) + .setType(Static.class) + .addAugmentation(RoutingProtocolVppAttr.class, new RoutingProtocolVppAttrBuilder() + .setVppProtocolAttributes(new VppProtocolAttributesBuilder() + .setPrimaryVrf(INVALID_VRF) + .build()) + .build()) + .build(); validData = new ControlPlaneProtocolBuilder() .setName(ROUTE_PROTOCOL_NAME) .setType(Static.class) .addAugmentation(RoutingProtocolVppAttr.class, new RoutingProtocolVppAttrBuilder() .setVppProtocolAttributes(new VppProtocolAttributesBuilder() - .setPrimaryVrf(new VniReference(1L)) + .setPrimaryVrf(VRF) .build()) .build()) .build(); @@ -68,7 +91,7 @@ public class ControlPlaneProtocolCustomizerTest extends WriterCustomizerTest { .setType(Static.class) .addAugmentation(RoutingProtocolVppAttr.class, new RoutingProtocolVppAttrBuilder() .setVppProtocolAttributes(new VppProtocolAttributesBuilder() - .setPrimaryVrf(new VniReference(1L)) + .setPrimaryVrf(VRF) .build()) .build()) .build(); @@ -78,7 +101,32 @@ public class ControlPlaneProtocolCustomizerTest extends WriterCustomizerTest { .build(); routingProtocolContext = new NamingContext("routing-protocol", "routing-protocol-context"); - customizer = new ControlPlaneProtocolCustomizer(routingProtocolContext, fibTableService); + customizer = new ControlPlaneProtocolCustomizer(routingProtocolContext); + TableKey keyV4 = new TableKey(Ipv4.class, VRF); + TableKey keyV6 = new TableKey(Ipv6.class, VRF); + KeyedInstanceIdentifier<Table, TableKey> vrfIidV4 = FibManagementIIds.FM_FIB_TABLES.child(Table.class, keyV4); + KeyedInstanceIdentifier<Table, TableKey> vrfIidV6 = FibManagementIIds.FM_FIB_TABLES.child(Table.class, keyV6); + TableKey invalidKeyV4 = new TableKey(Ipv4.class, INVALID_VRF); + TableKey invalidKeyV6 = new TableKey(Ipv6.class, INVALID_VRF); + KeyedInstanceIdentifier<Table, TableKey> invalidVrfIidV4 = + FibManagementIIds.FM_FIB_TABLES.child(Table.class, invalidKeyV4); + KeyedInstanceIdentifier<Table, TableKey> invalidVrfIidV6 = + FibManagementIIds.FM_FIB_TABLES.child(Table.class, invalidKeyV6); + when(writeContext.readAfter(vrfIidV4)).thenReturn(Optional.of( + new TableBuilder().setKey(keyV4).setAddressFamily(keyV4.getAddressFamily()) + .setTableId(keyV4.getTableId()).setName("VRF-IPV4-1").build())); + when(writeContext.readAfter(vrfIidV6)).thenReturn(Optional.of( + new TableBuilder().setKey(keyV6).setAddressFamily(keyV6.getAddressFamily()) + .setTableId(keyV6.getTableId()).setName("VRF-IPV6-1").build())); + when(writeContext.readAfter(invalidVrfIidV4)).thenReturn(Optional.absent()); + when(writeContext.readAfter(invalidVrfIidV6)).thenReturn(Optional.absent()); + } + + @Test(expected = WriteFailedException.class) + public void testWriteInvalid() throws WriteFailedException { + noMappingDefined(mappingContext, INVALID_TABLE_PROTOCOL_1, "routing-protocol-context"); + customizer.writeCurrentAttributes(invalidIid, invalidTableData, writeContext); + } @Test diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv4RouteCustomizerTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv4RouteCustomizerTest.java index 41a1ae6d1..36e0aed6d 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv4RouteCustomizerTest.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv4RouteCustomizerTest.java @@ -19,21 +19,17 @@ package io.fd.hc2vpp.routing.write; import static io.fd.hc2vpp.routing.Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY; import static io.fd.hc2vpp.routing.Ipv4RouteData.SECOND_ADDRESS_AS_ARRAY; import static io.fd.hc2vpp.routing.helpers.InterfaceTestHelper.INTERFACE_INDEX; -import static io.fd.hc2vpp.routing.helpers.InterfaceTestHelper.INTERFACE_NAME; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.MultiNamingContext; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.routing.helpers.ClassifyTableTestHelper; -import io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper; -import io.fd.hc2vpp.routing.helpers.SchemaContextTestHelper; +import io.fd.hc2vpp.fib.management.FibManagementIIds; import io.fd.hc2vpp.routing.naming.Ipv4RouteNamesFactory; -import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager; import io.fd.honeycomb.test.tools.HoneycombTestRunner; import io.fd.honeycomb.test.tools.annotations.InjectTestData; import io.fd.honeycomb.translate.write.WriteFailedException; @@ -42,7 +38,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; -import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev180313.StaticRoutes1; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.Ipv4; @@ -50,55 +45,67 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicas import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv4.RouteBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv4.RouteKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv4.route.NextHopBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.Static; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.next.hop.content.next.hop.options.TableLookupCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.ControlPlaneProtocols; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocol; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocolKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.control.plane.protocol.StaticRoutes; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.types.rev180406.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; @RunWith(HoneycombTestRunner.class) -public class Ipv4RouteCustomizerTest extends WriterCustomizerTest - implements ClassifyTableTestHelper, RoutingRequestTestHelper, SchemaContextTestHelper { +public class Ipv4RouteCustomizerTest extends RouteCustomizerTest { - private static final int ROUTE_PROTOCOL_INDEX = 1; - @Captor - private ArgumentCaptor<IpAddDelRoute> requestCaptor; + private static final TableKey + SEC_TABLE_KEY = new TableKey( + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv4.class, + SEC_TABLE_ID); + private static final Table + IPV4_TABLE = new TableBuilder().setName("VRF-IPV4-4") + .setKey(SEC_TABLE_KEY).setTableId(SEC_TABLE_KEY.getTableId()) + .setAddressFamily(SEC_TABLE_KEY.getAddressFamily()).build(); - @Mock - private VppClassifierContextManager classifyManager; + private static final InstanceIdentifier<Route> ROUTE_IID = CONTROL_PROTOCOL_IID + .child(StaticRoutes.class) + .augmentation(StaticRoutes1.class) + .child(Ipv4.class) + .child(Route.class); + private static final InstanceIdentifier<Route> ROUTE_INVALID_IID = CONTROL_PROTOCOL_INVALID_IID + .child(StaticRoutes.class) + .augmentation(StaticRoutes1.class) + .child(Ipv4.class) + .child(Route.class); - @Mock - private MultiNamingContext routeHopContext; + @Captor + private ArgumentCaptor<IpAddDelRoute> requestCaptor; private Ipv4RouteCustomizer customizer; - private InstanceIdentifier<Route> validId; private Ipv4RouteNamesFactory namesFactory; - private NamingContext routingProtocolContext; @Override protected void setUpTest() throws Exception { - NamingContext interfaceContext = new NamingContext("interface", "interface-context"); - routingProtocolContext = new NamingContext("routing-protocol", "routing-protocol-context"); - customizer = new Ipv4RouteCustomizer(api, interfaceContext, - new NamingContext("route", "route-context"), + super.setUpTest(); + customizer = new Ipv4RouteCustomizer(api, interfaceContext, new NamingContext("route", "route-context"), routingProtocolContext, routeHopContext, classifyManager); + namesFactory = new Ipv4RouteNamesFactory(interfaceContext, routingProtocolContext); - validId = InstanceIdentifier.create(ControlPlaneProtocols.class) - .child(ControlPlaneProtocol.class, new ControlPlaneProtocolKey(ROUTE_PROTOCOL_NAME, Static.class)) - .child(StaticRoutes.class) - .augmentation(StaticRoutes1.class) - .child(Ipv4.class) - .child(Route.class); + KeyedInstanceIdentifier<Table, TableKey> secondaryFibIid = + FibManagementIIds.FM_FIB_TABLES.child(Table.class, SEC_TABLE_KEY); - namesFactory = new Ipv4RouteNamesFactory(interfaceContext, routingProtocolContext); + when(writeContext.readAfter(secondaryFibIid)).thenReturn(Optional.of(IPV4_TABLE)); + } + + @Test(expected = WriteFailedException.class) + public void testWriteSingleHopInvalid( + @InjectTestData(resourcePath = "/ipv4/simplehop/simpleHopRouteWithClassifier.json", id = STATIC_ROUTE_PATH) StaticRoutes route) + throws WriteFailedException { + final Route route1 = getIpv4RouteWithId(route, new Ipv4Prefix("192.168.2.1/24")); + noMappingDefined(mappingContext, namesFactory.uniqueRouteName(ROUTE_PROTOCOL_INVALID_NAME, route1), + "route-context"); - defineMapping(mappingContext, INTERFACE_NAME, INTERFACE_INDEX, "interface-context"); - defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, ROUTE_PROTOCOL_INDEX, "routing-protocol-context"); - addMapping(classifyManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext); - whenAddRouteThenSuccess(api); + customizer.writeCurrentAttributes(ROUTE_INVALID_IID, route1, writeContext); + verifyInvocation(0, ImmutableList.of(), api, requestCaptor); } @Test @@ -108,10 +115,10 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest final Route route1 = getIpv4RouteWithId(route, new Ipv4Prefix("192.168.2.1/24")); noMappingDefined(mappingContext, namesFactory.uniqueRouteName(ROUTE_PROTOCOL_NAME, route1), "route-context"); - customizer.writeCurrentAttributes(validId, route1, writeContext); + customizer.writeCurrentAttributes(ROUTE_IID, route1, writeContext); verifyInvocation(1, ImmutableList .of(desiredFlaglessResult(1, 0, 0, FIRST_ADDRESS_AS_ARRAY, 24, - SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 0, ROUTE_PROTOCOL_INDEX, 0, + SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 0, TABLE_ID.intValue(), 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); } @@ -125,13 +132,15 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest .setNextHop(new NextHopBuilder().setNextHopOptions( new TableLookupCaseBuilder() .setSecondaryVrf(new VniReference(4L)) + .setAddressFamily( + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv4.class) .build()).build()) .build(); noMappingDefined(mappingContext, namesFactory.uniqueRouteName(ROUTE_PROTOCOL_NAME, route), "route-context"); - customizer.writeCurrentAttributes(validId, route, writeContext); + customizer.writeCurrentAttributes(ROUTE_IID, route, writeContext); verifyInvocation(1, ImmutableList .of(desiredFlaglessResult(1, 0, 0, FIRST_ADDRESS_AS_ARRAY, 24, - new byte[4], ~0, 0, ROUTE_PROTOCOL_INDEX, 4, + new byte[4], ~0, 0, TABLE_ID.intValue(), 4, 0, 0)), api, requestCaptor); } @@ -144,14 +153,14 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest final Route route1 = getIpv4RouteWithId(route, new Ipv4Prefix("192.168.2.1/24")); noMappingDefined(mappingContext, namesFactory.uniqueRouteName(ROUTE_PROTOCOL_NAME, route1), "route-context"); - customizer.writeCurrentAttributes(validId, route1, writeContext); + customizer.writeCurrentAttributes(ROUTE_IID, route1, writeContext); verifyInvocation(2, ImmutableList.of( desiredFlaglessResult(1, 0, 1, FIRST_ADDRESS_AS_ARRAY, 24, - FIRST_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, ROUTE_PROTOCOL_INDEX, 0, + FIRST_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, TABLE_ID.intValue(), 0, CLASSIFY_TABLE_INDEX, 1), desiredFlaglessResult(1, 0, 1, FIRST_ADDRESS_AS_ARRAY, 24, - SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 3, ROUTE_PROTOCOL_INDEX, 0, + SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 3, TABLE_ID.intValue(), 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); @@ -174,10 +183,10 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest final Route route1 = getIpv4RouteWithId(route, new Ipv4Prefix("192.168.2.1/24")); noMappingDefined(mappingContext, namesFactory.uniqueRouteName(ROUTE_PROTOCOL_NAME, route1), "route-context"); - customizer.writeCurrentAttributes(validId, route1, writeContext); + customizer.writeCurrentAttributes(ROUTE_IID, route1, writeContext); verifyInvocation(1, ImmutableList .of(desiredSpecialResult(1, 0, FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0, - ROUTE_PROTOCOL_INDEX, 0)), + TABLE_ID.intValue(), 0)), api, requestCaptor); } @@ -185,7 +194,7 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest public void testUpdate( @InjectTestData(resourcePath = "/ipv4/specialhop/specialHopRouteBlackhole.json", id = STATIC_ROUTE_PATH) StaticRoutes route) { try { - customizer.updateCurrentAttributes(validId, + customizer.updateCurrentAttributes(ROUTE_IID, new RouteBuilder().build(), getIpv4RouteWithId(route, new Ipv4Prefix("192.168.2.1/24")), writeContext); @@ -202,13 +211,13 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest public void testDeleteSingleHop( @InjectTestData(resourcePath = "/ipv4/simplehop/simpleHopRouteWithClassifier.json", id = STATIC_ROUTE_PATH) StaticRoutes route) throws WriteFailedException { - customizer.deleteCurrentAttributes(validId, + customizer.deleteCurrentAttributes(ROUTE_IID, getIpv4RouteWithId(route, new Ipv4Prefix("192.168.2.1/24")), writeContext); verifyInvocation(1, ImmutableList .of(desiredFlaglessResult(0, 0, 0, FIRST_ADDRESS_AS_ARRAY, 24, SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, - 0, ROUTE_PROTOCOL_INDEX, 0, CLASSIFY_TABLE_INDEX, 1)), + 0, TABLE_ID.intValue(), 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); } @@ -219,14 +228,14 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest final Route route1 = getIpv4RouteWithId(route, new Ipv4Prefix("192.168.2.1/24")); noMappingDefined(mappingContext, namesFactory.uniqueRouteName(ROUTE_PROTOCOL_NAME, route1), "route-context"); - customizer.deleteCurrentAttributes(validId, route1, writeContext); + customizer.deleteCurrentAttributes(ROUTE_IID, route1, writeContext); verifyInvocation(2, ImmutableList.of( desiredFlaglessResult(0, 0, 1, FIRST_ADDRESS_AS_ARRAY, 24, - FIRST_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, ROUTE_PROTOCOL_INDEX, 0, + FIRST_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, TABLE_ID.intValue(), 0, CLASSIFY_TABLE_INDEX, 1), desiredFlaglessResult(0, 0, 1, FIRST_ADDRESS_AS_ARRAY, 24, - new byte[]{-64, -88, 2, 2}, INTERFACE_INDEX, 3, ROUTE_PROTOCOL_INDEX, 0, + new byte[]{-64, -88, 2, 2}, INTERFACE_INDEX, 3, TABLE_ID.intValue(), 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); verify(routeHopContext, times(1)) @@ -245,11 +254,12 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest public void testDeleteSpecialHop( @InjectTestData(resourcePath = "/ipv4/specialhop/specialHopRouteBlackhole.json", id = STATIC_ROUTE_PATH) StaticRoutes route) throws WriteFailedException { - customizer.deleteCurrentAttributes(validId, getIpv4RouteWithId(route, new Ipv4Prefix("192.168.2.1/24")), writeContext); + customizer.deleteCurrentAttributes(ROUTE_IID, getIpv4RouteWithId(route, new Ipv4Prefix("192.168.2.1/24")), + writeContext); verifyInvocation(1, ImmutableList.of(desiredSpecialResult(0, 0, FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0, - ROUTE_PROTOCOL_INDEX, 0)), + TABLE_ID.intValue(), 0)), api, requestCaptor); } } 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 171b59786..0d78ca536 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 @@ -17,18 +17,13 @@ package io.fd.hc2vpp.routing.write; import static io.fd.hc2vpp.routing.helpers.InterfaceTestHelper.INTERFACE_INDEX; -import static io.fd.hc2vpp.routing.helpers.InterfaceTestHelper.INTERFACE_NAME; +import static org.mockito.Mockito.when; +import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.MultiNamingContext; -import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.fib.management.FibManagementIIds; import io.fd.hc2vpp.routing.Ipv6RouteData; -import io.fd.hc2vpp.routing.helpers.ClassifyTableTestHelper; -import io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper; -import io.fd.hc2vpp.routing.helpers.SchemaContextTestHelper; import io.fd.hc2vpp.routing.naming.Ipv6RouteNamesFactory; -import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager; import io.fd.honeycomb.test.tools.HoneycombTestRunner; import io.fd.honeycomb.test.tools.annotations.InjectTestData; import io.fd.honeycomb.translate.write.WriteFailedException; @@ -37,7 +32,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; -import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.StaticRoutes1; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.Ipv6; @@ -45,59 +39,63 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicas import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv6.RouteBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv6.RouteKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv6.route.NextHopBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.Static; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.next.hop.content.next.hop.options.TableLookupCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.ControlPlaneProtocols; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocol; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocolKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.control.plane.protocol.StaticRoutes; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.types.rev180406.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; @RunWith(HoneycombTestRunner.class) -public class Ipv6RouteCustomizerTest extends WriterCustomizerTest - implements RoutingRequestTestHelper, ClassifyTableTestHelper, SchemaContextTestHelper { - - private static final int ROUTE_PROTOCOL_INDEX = 1; - public static final Ipv6Prefix IPV_6_PREFIX = new Ipv6Prefix("2001:0db8:0a0b:12f0:0000:0000:0000:0001/64"); +public class Ipv6RouteCustomizerTest extends RouteCustomizerTest { + + private static final TableKey + SEC_TABLE_KEY = new TableKey( + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6.class, + SEC_TABLE_ID); + private static final Table + IPV6_TABLE = new TableBuilder().setName("VRF-IPV6-4") + .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 InstanceIdentifier<Route> ROUTE_IID = CONTROL_PROTOCOL_IID + .child(StaticRoutes.class) + .augmentation(StaticRoutes1.class) + .child(Ipv6.class) + .child(Route.class); + private static final InstanceIdentifier<Route> ROUTE_INVALID_IID = CONTROL_PROTOCOL_INVALID_IID + .child(StaticRoutes.class) + .augmentation(StaticRoutes1.class) + .child(Ipv6.class) + .child(Route.class); @Captor private ArgumentCaptor<IpAddDelRoute> requestCaptor; - @Mock - private VppClassifierContextManager classifyManager; - - @Mock - private MultiNamingContext routeHopContext; - - private NamingContext interfaceContext; - private NamingContext routeContext; - private NamingContext routingProtocolContext; private Ipv6RouteCustomizer customizer; - - private InstanceIdentifier<Route> validId; private Ipv6RouteNamesFactory namesFactory; @Override protected void setUpTest() throws Exception { - interfaceContext = new NamingContext("interface", "interface-context"); - routeContext = new NamingContext("interface", "interface-context"); - routingProtocolContext = new NamingContext("routing-protocol", "routing-protocol-context"); - customizer = - new Ipv6RouteCustomizer(api, interfaceContext, routeContext, routingProtocolContext, routeHopContext, - classifyManager); - - validId = InstanceIdentifier.create(ControlPlaneProtocols.class) - .child(ControlPlaneProtocol.class, new ControlPlaneProtocolKey(ROUTE_PROTOCOL_NAME, Static.class)) - .child(StaticRoutes.class) - .augmentation(StaticRoutes1.class) - .child(Ipv6.class) - .child(Route.class); - + super.setUpTest(); + customizer = new Ipv6RouteCustomizer(api, interfaceContext, routingProtocolContext, routingProtocolContext, + routeHopContext, classifyManager); namesFactory = new Ipv6RouteNamesFactory(interfaceContext, routingProtocolContext); - defineMapping(mappingContext, INTERFACE_NAME, INTERFACE_INDEX, "interface-context"); - addMapping(classifyManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext); - defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, ROUTE_PROTOCOL_INDEX, "routing-protocol-context"); + KeyedInstanceIdentifier<Table, TableKey> secondaryFibIid = + FibManagementIIds.FM_FIB_TABLES.child(Table.class, SEC_TABLE_KEY); + when(writeContext.readAfter(secondaryFibIid)).thenReturn(Optional.of(IPV6_TABLE)); + } + + @Test(expected = WriteFailedException.class) + public void testWriteSingleInvalidHop( + @InjectTestData(resourcePath = "/ipv6/simplehop/simpleHopRouteWithClassifier.json", id = STATIC_ROUTE_PATH) StaticRoutes route) + throws WriteFailedException { + whenAddRouteThenSuccess(api); + customizer.writeCurrentAttributes(ROUTE_INVALID_IID, getIpv6RouteWithId(route, IPV_6_PREFIX), writeContext); + verifyInvocation(0, ImmutableList.of(), api, requestCaptor); } @Test @@ -105,11 +103,11 @@ public class Ipv6RouteCustomizerTest extends WriterCustomizerTest @InjectTestData(resourcePath = "/ipv6/simplehop/simpleHopRouteWithClassifier.json", id = STATIC_ROUTE_PATH) StaticRoutes route) throws WriteFailedException { whenAddRouteThenSuccess(api); - customizer.writeCurrentAttributes(validId, getIpv6RouteWithId(route, IPV_6_PREFIX), writeContext); + customizer.writeCurrentAttributes(ROUTE_IID, getIpv6RouteWithId(route, IPV_6_PREFIX), writeContext); verifyInvocation(1, ImmutableList .of(desiredFlaglessResult(1, 1, 0, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 64, - Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 0, ROUTE_PROTOCOL_INDEX, - 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); + 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 @@ -120,14 +118,16 @@ public class Ipv6RouteCustomizerTest extends WriterCustomizerTest .setDestinationPrefix(IPV_6_PREFIX) .setNextHop(new NextHopBuilder().setNextHopOptions(new TableLookupCaseBuilder() .setSecondaryVrf(new VniReference(4L)) + .setAddressFamily( + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6.class) .build()).build()) .build(); whenAddRouteThenSuccess(api); noMappingDefined(mappingContext, namesFactory.uniqueRouteName(ROUTE_PROTOCOL_NAME, route), "route-context"); - customizer.writeCurrentAttributes(validId, route, writeContext); + customizer.writeCurrentAttributes(ROUTE_IID, route, writeContext); verifyInvocation(1, ImmutableList .of(desiredFlaglessResult(1, 1, 0, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 64, - new byte[4], ~0, 0, ROUTE_PROTOCOL_INDEX, 4, + new byte[4], ~0, 0, TABLE_ID.intValue(), 4, 0, 0)), api, requestCaptor); } @@ -137,21 +137,21 @@ public class Ipv6RouteCustomizerTest extends WriterCustomizerTest @InjectTestData(resourcePath = "/ipv6/multihop/multiHopRouteWithClassifier.json", id = STATIC_ROUTE_PATH) StaticRoutes route) throws WriteFailedException { whenAddRouteThenSuccess(api); - customizer.writeCurrentAttributes(validId, getIpv6RouteWithId(route, IPV_6_PREFIX), writeContext); + customizer.writeCurrentAttributes(ROUTE_IID, getIpv6RouteWithId(route, IPV_6_PREFIX), writeContext); verifyInvocation(2, ImmutableList.of( desiredFlaglessResult(1, 1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 64, - Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, ROUTE_PROTOCOL_INDEX, 0, + Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, TABLE_ID.intValue(), 0, CLASSIFY_TABLE_INDEX, 1), desiredFlaglessResult(1, 1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 64, - Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, ROUTE_PROTOCOL_INDEX, 0, + Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, TABLE_ID.intValue(), 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); } @Test(expected = UnsupportedOperationException.class) public void testUpdate() throws WriteFailedException { - customizer.updateCurrentAttributes(validId, Ipv6RouteData.IPV6_ROUTE_WITH_CLASSIFIER_BLACKHOLE_HOP, + customizer.updateCurrentAttributes(ROUTE_IID, Ipv6RouteData.IPV6_ROUTE_WITH_CLASSIFIER_BLACKHOLE_HOP, Ipv6RouteData.IPV6_ROUTE_WITH_CLASSIFIER_RECEIVE_HOP, writeContext); } @@ -160,11 +160,11 @@ public class Ipv6RouteCustomizerTest extends WriterCustomizerTest @InjectTestData(resourcePath = "/ipv6/specialhop/specialHopRouteBlackhole.json", id = STATIC_ROUTE_PATH) StaticRoutes route) throws WriteFailedException { whenAddRouteThenSuccess(api); - customizer.deleteCurrentAttributes(validId, getIpv6RouteWithId(route, IPV_6_PREFIX), + customizer.deleteCurrentAttributes(ROUTE_IID, getIpv6RouteWithId(route, IPV_6_PREFIX), writeContext); verifyInvocation(1, ImmutableList .of(desiredSpecialResult(0, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 64, - 1, 0, 0, 0, ROUTE_PROTOCOL_INDEX, 0)), + 1, 0, 0, 0, TABLE_ID.intValue(), 0)), api, requestCaptor); } @@ -173,7 +173,7 @@ public class Ipv6RouteCustomizerTest extends WriterCustomizerTest @InjectTestData(resourcePath = "/ipv6/simplehop/simpleHopRouteWithClassifier.json", id = STATIC_ROUTE_PATH) StaticRoutes route) throws WriteFailedException { whenAddRouteThenSuccess(api); - customizer.deleteCurrentAttributes(validId, getIpv6RouteWithId(route, IPV_6_PREFIX), writeContext); + customizer.deleteCurrentAttributes(ROUTE_IID, getIpv6RouteWithId(route, IPV_6_PREFIX), writeContext); verifyInvocation(1, ImmutableList .of(desiredFlaglessResult(0, 1, 0, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 64, Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 0, 1, @@ -185,7 +185,7 @@ public class Ipv6RouteCustomizerTest extends WriterCustomizerTest @InjectTestData(resourcePath = "/ipv6/multihop/multiHopRouteWithClassifier.json", id = STATIC_ROUTE_PATH) StaticRoutes route) throws WriteFailedException { whenAddRouteThenSuccess(api); - customizer.deleteCurrentAttributes(validId, getIpv6RouteWithId(route, IPV_6_PREFIX), writeContext); + customizer.deleteCurrentAttributes(ROUTE_IID, getIpv6RouteWithId(route, IPV_6_PREFIX), writeContext); verifyInvocation(2, ImmutableList.of( desiredFlaglessResult(0, 1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 64, @@ -202,11 +202,11 @@ public class Ipv6RouteCustomizerTest extends WriterCustomizerTest @InjectTestData(resourcePath = "/ipv6/specialhop/specialHopRouteBlackhole.json", id = STATIC_ROUTE_PATH) StaticRoutes route) throws WriteFailedException { whenAddRouteThenSuccess(api); - customizer.writeCurrentAttributes(validId, getIpv6RouteWithId(route, IPV_6_PREFIX), + customizer.writeCurrentAttributes(ROUTE_IID, getIpv6RouteWithId(route, IPV_6_PREFIX), writeContext); verifyInvocation(1, ImmutableList .of(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 64, - 1, 0, 0, 0, ROUTE_PROTOCOL_INDEX, 0)), + 1, 0, 0, 0, TABLE_ID.intValue(), 0)), api, requestCaptor); } } diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/RouteCustomizerTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/RouteCustomizerTest.java new file mode 100644 index 000000000..ad1613f35 --- /dev/null +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/RouteCustomizerTest.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package io.fd.hc2vpp.routing.write; + +import static io.fd.hc2vpp.routing.helpers.InterfaceTestHelper.INTERFACE_INDEX; +import static io.fd.hc2vpp.routing.helpers.InterfaceTestHelper.INTERFACE_NAME; +import static org.mockito.Mockito.when; + +import com.google.common.base.Optional; +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.MultiNamingContext; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.fib.management.FibManagementIIds; +import io.fd.hc2vpp.routing.helpers.ClassifyTableTestHelper; +import io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper; +import io.fd.hc2vpp.routing.helpers.SchemaContextTestHelper; +import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.Static; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.ControlPlaneProtocols; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocol; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocolBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocolKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev180319.RoutingProtocolVppAttr; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev180319.RoutingProtocolVppAttrBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev180319.routing.control.plane.protocols.control.plane.protocol.VppProtocolAttributesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; + +abstract class RouteCustomizerTest extends WriterCustomizerTest implements RoutingRequestTestHelper, + ClassifyTableTestHelper, SchemaContextTestHelper { + static final Long TABLE_ID = 1L; + static final Long INVALID_TABLE_ID = 3L; + static final String ROUTE_PROTOCOL_INVALID_NAME = "tst-protocol-3"; + static final VniReference SEC_TABLE_ID = new VniReference(4L); + private static final TableKey IPV4_TABLE_KEY = new TableKey(Ipv4.class, new VniReference(TABLE_ID)); + private static final TableKey IPV6_TABLE_KEY = new TableKey(Ipv6.class, new VniReference(TABLE_ID)); + private static final TableKey INVALID_IPV4_TABLE_KEY = new TableKey(Ipv4.class, new VniReference(INVALID_TABLE_ID)); + private static final TableKey INVALID_IPV6_TABLE_KEY = new TableKey(Ipv6.class, new VniReference(INVALID_TABLE_ID)); + private static final InstanceIdentifier<Table> TABLE_V4_IID = + FibManagementIIds.FM_FIB_TABLES.child(Table.class, IPV4_TABLE_KEY); + private static final InstanceIdentifier<Table> TABLE_V6_IID = + FibManagementIIds.FM_FIB_TABLES.child(Table.class, IPV6_TABLE_KEY); + private static final InstanceIdentifier<Table> INVALID_TABLE_V4_IID = + FibManagementIIds.FM_FIB_TABLES.child(Table.class, INVALID_IPV4_TABLE_KEY); + private static final InstanceIdentifier<Table> INVALID_TABLE_V6_IID = + FibManagementIIds.FM_FIB_TABLES.child(Table.class, INVALID_IPV6_TABLE_KEY); + private static final ControlPlaneProtocolKey + CONTROL_PLANE_PROTOCOL_KEY = new ControlPlaneProtocolKey(ROUTE_PROTOCOL_NAME, Static.class); + static final KeyedInstanceIdentifier<ControlPlaneProtocol, ControlPlaneProtocolKey> + CONTROL_PROTOCOL_IID = InstanceIdentifier.create(ControlPlaneProtocols.class) + .child(ControlPlaneProtocol.class, CONTROL_PLANE_PROTOCOL_KEY); + private static final ControlPlaneProtocolKey + CONTROL_PLANE_PROTOCOL_INVALID_KEY = new ControlPlaneProtocolKey(ROUTE_PROTOCOL_INVALID_NAME, Static.class); + static final KeyedInstanceIdentifier<ControlPlaneProtocol, ControlPlaneProtocolKey> + CONTROL_PROTOCOL_INVALID_IID = InstanceIdentifier.create(ControlPlaneProtocols.class) + .child(ControlPlaneProtocol.class, CONTROL_PLANE_PROTOCOL_INVALID_KEY); + + @Mock + VppClassifierContextManager classifyManager; + + @Mock + MultiNamingContext routeHopContext; + + NamingContext routingProtocolContext; + NamingContext interfaceContext; + + @Override + protected void setUpTest() throws Exception { + interfaceContext = new NamingContext("interface", "interface-context"); + routingProtocolContext = new NamingContext("routing-protocol", "routing-protocol-context"); + + defineMapping(mappingContext, INTERFACE_NAME, INTERFACE_INDEX, "interface-context"); + defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, TABLE_ID.intValue(), "routing-protocol-context"); + defineMapping(mappingContext, ROUTE_PROTOCOL_INVALID_NAME, INVALID_TABLE_ID.intValue(), + "routing-protocol-context"); + addMapping(classifyManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext); + whenAddRouteThenSuccess(api); + + when(writeContext.readAfter(CONTROL_PROTOCOL_IID)).thenReturn(Optional.of(new ControlPlaneProtocolBuilder() + .setKey(CONTROL_PLANE_PROTOCOL_KEY).setName(ROUTE_PROTOCOL_NAME).setType(Static.class) + .addAugmentation(RoutingProtocolVppAttr.class, new RoutingProtocolVppAttrBuilder() + .setVppProtocolAttributes(new VppProtocolAttributesBuilder() + .setPrimaryVrf(new VniReference(TABLE_ID)) + .build()).build()) + .build())); + + when(writeContext.readAfter(CONTROL_PROTOCOL_INVALID_IID)).thenReturn(Optional.of( + new ControlPlaneProtocolBuilder().setKey(CONTROL_PLANE_PROTOCOL_INVALID_KEY) + .setName(ROUTE_PROTOCOL_INVALID_NAME).setType(Static.class) + .addAugmentation(RoutingProtocolVppAttr.class, new RoutingProtocolVppAttrBuilder() + .setVppProtocolAttributes(new VppProtocolAttributesBuilder() + .setPrimaryVrf(new VniReference(INVALID_TABLE_ID)).build()).build()) + .build())); + + when(writeContext.readAfter(TABLE_V4_IID)).thenReturn(Optional.of( + new TableBuilder().setKey(IPV4_TABLE_KEY).setAddressFamily(Ipv4.class) + .setTableId(IPV4_TABLE_KEY.getTableId()).build())); + when(writeContext.readAfter(TABLE_V6_IID)).thenReturn(Optional.of( + new TableBuilder().setKey(IPV6_TABLE_KEY).setAddressFamily(Ipv6.class) + .setTableId(IPV6_TABLE_KEY.getTableId()).build())); + when(writeContext.readAfter(INVALID_TABLE_V4_IID)).thenReturn(Optional.absent()); + when(writeContext.readAfter(INVALID_TABLE_V6_IID)).thenReturn(Optional.absent()); + + } +} |