From a17c250234959ea8f97c0784a3af947faaf91a59 Mon Sep 17 00:00:00 2001 From: "Claudio D. Gasparini" Date: Wed, 18 May 2016 15:05:18 +0200 Subject: [PATCH] Fix wrong aligment in Openconfig Fix wrong aligment in some of Openconfig classes and test Change-Id: Ib0d238080658b8f9ee380766f5157bf096ba7670 Signed-off-by: Claudio D. Gasparini --- .../openconfig/BGPGlobalProviderImpl.java | 11 +++---- .../openconfig/BGPNeighborProviderImpl.java | 31 +++++++++---------- .../openconfig/impl/util/OpenConfigUtil.java | 26 +++++++--------- .../impl/util/OpenConfigUtilTest.java | 18 +++++------ 4 files changed, 37 insertions(+), 49 deletions(-) diff --git a/bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/openconfig/BGPGlobalProviderImpl.java b/bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/openconfig/BGPGlobalProviderImpl.java index 3d5f7cecbc..20392f7a42 100644 --- a/bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/openconfig/BGPGlobalProviderImpl.java +++ b/bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/openconfig/BGPGlobalProviderImpl.java @@ -36,7 +36,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; final class BGPGlobalProviderImpl extends AbstractBGPOpenConfigMapper { private static final PeerGroup APP_PEER_GROUP = new PeerGroupBuilder().setPeerGroupName(APPLICATION_PEER_GROUP_NAME) - .setKey(new PeerGroupKey(APPLICATION_PEER_GROUP_NAME)).build(); + .setKey(new PeerGroupKey(APPLICATION_PEER_GROUP_NAME)).build(); public BGPGlobalProviderImpl(final BindingTransactionChain txChain, final BGPConfigStateStore stateHolders) { super(txChain, stateHolders, Bgp.class); @@ -71,12 +71,9 @@ final class BGPGlobalProviderImpl extends AbstractBGPOpenConfigMapper OpenConfigUtil.toGlobalAfiSafiMultiPath(afiSafi, tableType, config.getPathSelectionModes()))).build()) - .setConfig(new ConfigBuilder() - .setAs(config.getLocalAs()) - .setRouterId(config.getBgpRibId()).build()).build(); + final Global global = new GlobalBuilder().setAfiSafis(new AfiSafisBuilder().setAfiSafi(OpenConfigUtil.toAfiSafis(config.getTableTypes(), + (afiSafi, tableType) -> OpenConfigUtil.toGlobalAfiSafiMultiPath(afiSafi, tableType, config.getPathSelectionModes()))).build()) + .setConfig(new ConfigBuilder().setAs(config.getLocalAs()).setRouterId(config.getBgpRibId()).build()).build(); bgpBuilder.setGlobal(global); return bgpBuilder.build(); } diff --git a/bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/openconfig/BGPNeighborProviderImpl.java b/bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/openconfig/BGPNeighborProviderImpl.java index ce2b514dac..1f41128894 100644 --- a/bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/openconfig/BGPNeighborProviderImpl.java +++ b/bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/openconfig/BGPNeighborProviderImpl.java @@ -32,11 +32,6 @@ final class BGPNeighborProviderImpl extends AbstractBGPNeighborProvider getInstanceConfigurationType() { - return BGPPeerInstanceConfiguration.class; - } - @Override public Neighbor apply(final BGPPeerInstanceConfiguration config) { return toNeighborConfiguration(config); @@ -47,38 +42,42 @@ final class BGPNeighborProviderImpl extends AbstractBGPNeighborProvider getInstanceConfigurationType() { + return BGPPeerInstanceConfiguration.class; + } + private static Neighbor toNeighborConfiguration(final BGPPeerInstanceConfiguration config) { return new NeighborBuilder() .setNeighborAddress(config.getHost()) .setKey(new NeighborKey(config.getHost())) .setTransport(new TransportBuilder().setConfig( - new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.transport.ConfigBuilder() + new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.transport.ConfigBuilder() .setPassiveMode(!config.isActive()) .build()).build()) .setConfig( - new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder() - .setAuthPassword(getPasswor(config.getPassword())) + new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder() + .setAuthPassword(getPassword(config.getPassword())) .setPeerAs(config.getAsNumber()) .setPeerType(toPeerTye(config.getPeerRole())) .build()) .setAfiSafis( - new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.AfiSafisBuilder() + new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.AfiSafisBuilder() .setAfiSafi(OpenConfigUtil.toAfiSafis(config.getAdvertizedTables(), - (afiSAfi, tableType) -> OpenConfigUtil.toNeigborAfiSafiMultiPath(afiSAfi, tableType, config.getAddPathCapabilities()))) + (afiSAfi, tableType) -> OpenConfigUtil.toNeigborAfiSafiMultiPath(afiSAfi, tableType, config.getAddPathCapabilities()))) .build()) .setTimers(new TimersBuilder().setConfig( - new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.timers.ConfigBuilder() + new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.timers.ConfigBuilder() .setHoldTime(BigDecimal.valueOf(config.getHoldTimer())) .build()).build()) .setRouteReflector(new RouteReflectorBuilder().setConfig( - new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.route.reflector.ConfigBuilder() - .setRouteReflectorClient(config.getPeerRole() == PeerRole.RrClient) - .build()).build()) + new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.route.reflector.ConfigBuilder() + .setRouteReflectorClient(config.getPeerRole() == PeerRole.RrClient).build()).build()) .build(); } private static PeerType toPeerTye(final PeerRole peerRole) { - switch(peerRole) { + switch (peerRole) { case Ibgp: case RrClient: return PeerType.INTERNAL; @@ -92,7 +91,7 @@ final class BGPNeighborProviderImpl extends AbstractBGPNeighborProvider maybePassword) { + private static String getPassword(final Optional maybePassword) { if (maybePassword.isPresent()) { return maybePassword.get().getValue(); } diff --git a/bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/util/OpenConfigUtil.java b/bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/util/OpenConfigUtil.java index be3ee909a3..7050a4ba28 100644 --- a/bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/util/OpenConfigUtil.java +++ b/bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/util/OpenConfigUtil.java @@ -57,14 +57,10 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public final class OpenConfigUtil { - private static final char EQUALS = '='; - public static final InstanceIdentifier BGP_IID = InstanceIdentifier.create(Bgp.class); - public static final String APPLICATION_PEER_GROUP_NAME = "application-peers"; - public static final String FAILED_TO_READ_SERVICE = "Failed to read service."; - + private static final char EQUALS = '='; private static final BiMap> TABLETYPE_TO_AFISAFI; static { @@ -119,10 +115,10 @@ public final class OpenConfigUtil { public static AfiSafi toNeigborAfiSafiMultiPath(final AfiSafi afiSafi, final BgpTableType tableType, final Collection addPathCapabilities) { final java.util.Optional addPathMayBe = addPathCapabilities.stream().filter( - af -> af.getAfi() == tableType.getAfi() && af.getSafi() == tableType.getSafi()).findFirst(); + af -> af.getAfi() == tableType.getAfi() && af.getSafi() == tableType.getSafi()).findFirst(); if (addPathMayBe.isPresent()) { final AfiSafi2 afiSafi3 = new AfiSafi2Builder().setUseMultiplePaths( - new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.use.multiple.paths.neighbor.UseMultiplePathsBuilder().setConfig( + new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.use.multiple.paths.neighbor.UseMultiplePathsBuilder().setConfig( new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.use.multiple.paths.neighbor.use.multiple.paths.ConfigBuilder() .setEnabled(true).build()).build()).build(); return new AfiSafiBuilder(afiSafi).addAugmentation(AfiSafi2.class, afiSafi3).build(); @@ -142,14 +138,14 @@ public final class OpenConfigUtil { maxPaths = null; } final AfiSafi1 afiSafi1 = new AfiSafi1Builder().setUseMultiplePaths( - new UseMultiplePathsBuilder().setConfig(new ConfigBuilder().setEnabled(true).build()) - .setEbgp(maxPaths != null ? new EbgpBuilder().setConfig( - new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.use.multiple.paths.use.multiple.paths.ebgp.ConfigBuilder() - .setMaximumPaths(maxPaths) - .build()).build() : null) - .setIbgp(maxPaths != null ? new IbgpBuilder().setConfig( - new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.use.multiple.paths.use.multiple.paths.ibgp.ConfigBuilder() - .setMaximumPaths(maxPaths).build()).build() : null).build()).build(); + new UseMultiplePathsBuilder().setConfig(new ConfigBuilder().setEnabled(true).build()) + .setEbgp(maxPaths != null ? new EbgpBuilder().setConfig( + new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.use.multiple.paths.use.multiple.paths.ebgp.ConfigBuilder() + .setMaximumPaths(maxPaths) + .build()).build() : null) + .setIbgp(maxPaths != null ? new IbgpBuilder().setConfig( + new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.use.multiple.paths.use.multiple.paths.ibgp.ConfigBuilder() + .setMaximumPaths(maxPaths).build()).build() : null).build()).build(); return new AfiSafiBuilder(afiSafi).addAugmentation(AfiSafi1.class, afiSafi1).build(); } } diff --git a/bgp/openconfig-impl/src/test/java/org/opendaylight/protocol/bgp/openconfig/impl/util/OpenConfigUtilTest.java b/bgp/openconfig-impl/src/test/java/org/opendaylight/protocol/bgp/openconfig/impl/util/OpenConfigUtilTest.java index 2f1f9dab40..9e7addb9fd 100644 --- a/bgp/openconfig-impl/src/test/java/org/opendaylight/protocol/bgp/openconfig/impl/util/OpenConfigUtilTest.java +++ b/bgp/openconfig-impl/src/test/java/org/opendaylight/protocol/bgp/openconfig/impl/util/OpenConfigUtilTest.java @@ -56,8 +56,7 @@ public class OpenConfigUtilTest { @Test public void testToAfiSafi() { - assertEquals(toAfiSafi(BGP_TABLE_TYPE_IPV4).get(), - AFISAFI_IPV4); + assertEquals(toAfiSafi(BGP_TABLE_TYPE_IPV4).get(), AFISAFI_IPV4); } @Test @@ -68,15 +67,14 @@ public class OpenConfigUtilTest { @Test public void testToAfiSafis() { - final List afiSafis = OpenConfigUtil.toAfiSafis(Lists.newArrayList(BGP_TABLE_TYPE_IPV4), - (afisafi, tableType) -> afisafi); + final List afiSafis = OpenConfigUtil.toAfiSafis(Lists.newArrayList(BGP_TABLE_TYPE_IPV4), (afisafi, tableType) -> afisafi); Assert.assertEquals(Collections.singletonList(AFISAFI_IPV4), afiSafis); } @Test public void toNeigborAfiSafiMultiPathMatch() { final AfiSafi afiSafi = OpenConfigUtil.toNeigborAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, - Lists.newArrayList(new AddressFamiliesBuilder(BGP_TABLE_TYPE_IPV4).setSendReceive(SendReceive.Both).build())); + Lists.newArrayList(new AddressFamiliesBuilder(BGP_TABLE_TYPE_IPV4).setSendReceive(SendReceive.Both).build())); Assert.assertTrue(afiSafi.getAugmentation(AfiSafi2.class).getUseMultiplePaths().getConfig().isEnabled()); } @@ -89,7 +87,7 @@ public class OpenConfigUtilTest { @Test public void toGlobalAfiSafiMultiPathNPaths() { final AfiSafi afiSafi = OpenConfigUtil.toGlobalAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, - Collections.singletonMap(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class), new AddPathBestNPathSelection(5L))); + Collections.singletonMap(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class), new AddPathBestNPathSelection(5L))); final UseMultiplePaths multiplePaths = afiSafi.getAugmentation(AfiSafi1.class).getUseMultiplePaths(); Assert.assertTrue(multiplePaths.getConfig().isEnabled()); Assert.assertEquals(5, multiplePaths.getIbgp().getConfig().getMaximumPaths().intValue()); @@ -99,7 +97,7 @@ public class OpenConfigUtilTest { @Test public void toGlobalAfiSafiMultiPathAllPaths() { final AfiSafi afiSafi = OpenConfigUtil.toGlobalAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, - Collections.singletonMap(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class), new AllPathSelection())); + Collections.singletonMap(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class), new AllPathSelection())); final UseMultiplePaths multiplePaths = afiSafi.getAugmentation(AfiSafi1.class).getUseMultiplePaths(); Assert.assertTrue(multiplePaths.getConfig().isEnabled()); Assert.assertNull(multiplePaths.getIbgp()); @@ -108,12 +106,11 @@ public class OpenConfigUtilTest { @Test public void toGlobalAfiSafiMultiPathNoMatch() { - final AfiSafi afiSafi = OpenConfigUtil.toGlobalAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, - Collections.emptyMap()); + final AfiSafi afiSafi = OpenConfigUtil.toGlobalAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, Collections.emptyMap()); Assert.assertEquals(AFISAFI_IPV4, afiSafi); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testPrivateConstructor() throws Throwable { final Constructor c = OpenConfigUtil.class.getDeclaredConstructor(); c.setAccessible(true); @@ -123,5 +120,4 @@ public class OpenConfigUtilTest { throw e.getCause(); } } - } \ No newline at end of file -- 2.36.6