Remove workaround for bug 1276 51/29751/8
authorClaudio D. Gasparini <cgaspari@cisco.com>
Mon, 16 Nov 2015 13:40:06 +0000 (14:40 +0100)
committerClaudio D. Gasparini <cgaspari@cisco.com>
Mon, 23 Nov 2015 20:32:58 +0000 (20:32 +0000)
Since bug 1276 is fixed, workaround is not required
anymore.

Change-Id: I5939f3ac94ab3b3f865c3c2920e4f491f39f9827
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
bgp/rib-impl/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPPeerModule.java
bgp/rib-impl/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPPeerAcceptorModuleTest.java
bgp/rib-impl/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPPeerModuleTest.java

index ef634e6b4ba8cfa3ac21edd30570c7fba8e80db1..9798a822892b678e75b012e9a45a97c7d6dfae78 100644 (file)
@@ -75,7 +75,11 @@ public final class BGPPeerModule extends org.opendaylight.controller.config.yang
 
     @Override
     protected void customValidation() {
-        JmxAttributeValidationException.checkNotNull(getHost(), "value is not set.", hostJmxAttribute);
+        final IpAddress host = getHost();
+        JmxAttributeValidationException.checkNotNull(host, "value is not set.", hostJmxAttribute);
+        JmxAttributeValidationException.checkCondition(host.getIpv4Address() != null || host.getIpv6Address() != null,
+            "Unexpected host", hostJmxAttribute);
+
         JmxAttributeValidationException.checkNotNull(getPort(), "value is not set.", portJmxAttribute);
 
         if (getOptionaPassword(getPassword()).isPresent()) {
@@ -122,16 +126,16 @@ public final class BGPPeerModule extends org.opendaylight.controller.config.yang
         final AsNumber remoteAs = getAsOrDefault(r);
         final BGPSessionPreferences prefs = new BGPSessionPreferences(r.getLocalAs(), getHoldtimer(), r.getBgpIdentifier(), remoteAs, tlvs);
         final BGPPeer bgpClientPeer;
-
+        final IpAddress host = getNormalizedHost();
         if (getPeerRole() != null) {
-            bgpClientPeer = new BGPPeer(peerName(getHostWithoutValue()), r, getPeerRole());
+            bgpClientPeer = new BGPPeer(peerName(host), r, getPeerRole());
         } else {
-            bgpClientPeer = new BGPPeer(peerName(getHostWithoutValue()), r, PeerRole.Ibgp);
+            bgpClientPeer = new BGPPeer(peerName(host), r, PeerRole.Ibgp);
         }
 
         bgpClientPeer.registerRootRuntimeBean(getRootRuntimeBeanRegistratorWrapper());
 
-        getPeerRegistryBackwards().addPeer(getHostWithoutValue(), bgpClientPeer, prefs);
+        getPeerRegistryBackwards().addPeer(host, bgpClientPeer, prefs);
 
         final BGPPeerModuleTracker moduleTracker = new BGPPeerModuleTracker(r.getOpenConfigProvider());
         moduleTracker.onInstanceCreate();
@@ -140,7 +144,7 @@ public final class BGPPeerModule extends org.opendaylight.controller.config.yang
             @Override
             public void close() {
                 bgpClientPeer.close();
-                getPeerRegistryBackwards().removePeer(getHostWithoutValue());
+                getPeerRegistryBackwards().removePeer(host);
                 moduleTracker.onInstanceClose();
             }
         };
@@ -196,17 +200,12 @@ public final class BGPPeerModule extends org.opendaylight.controller.config.yang
         return tlvs;
     }
 
-    public IpAddress getHostWithoutValue() {
-        // FIXME we need to remove field "value" from IpAddress since equals does not work as expected when value being present
-        // Remove after this bug is fixed https://bugs.opendaylight.org/show_bug.cgi?id=1276
-        final IpAddress host = super.getHost();
-        Preconditions.checkArgument(host.getIpv4Address() != null || host.getIpv6Address() != null, "Unexpected host %s", host);
-        if(host.getIpv4Address() != null) {
-            return new IpAddress(host.getIpv4Address());
-        } else if(host.getIpv6Address() != null){
+    public IpAddress getNormalizedHost() {
+        final IpAddress host = getHost();
+        if(host.getIpv6Address() != null){
             return new IpAddress(Ipv6Util.getFullForm(host.getIpv6Address()));
         }
-        throw new IllegalArgumentException("Unexpected host " + host);
+        return host;
     }
 
     private io.netty.util.concurrent.Future<Void> initiateConnection(final InetSocketAddress address, final Optional<Rfc2385Key> password, final BGPPeerRegistry registry) {
@@ -253,7 +252,7 @@ public final class BGPPeerModule extends org.opendaylight.controller.config.yang
         @Override
         public void onInstanceCreate() {
             if (neighborProvider != null) {
-                neighborProvider.writeConfiguration(new BGPPeerInstanceConfiguration(identifier, Rev130715Uitl.getIpvAddress(getHostWithoutValue()),
+                neighborProvider.writeConfiguration(new BGPPeerInstanceConfiguration(identifier, Rev130715Uitl.getIpvAddress(getNormalizedHost()),
                     Rev130715Uitl.getPort(getPort().getValue()), getHoldtimer(), getPeerRole(), getInitiateConnection(),
                         getAdvertizedTableDependency(), Rev130715Uitl.getASNumber(getAsOrDefault(getRibDependency()).getValue()),
                         getOptionaPassword(getPassword())));
index 05f45610e676df52f4f444b0f17d5dc7cea1d1c3..b41c9031d58dc7f2890e57630e4f47d7c1c33f7c 100644 (file)
@@ -44,6 +44,7 @@ import org.opendaylight.controller.config.yang.netty.threadgroup.NettyThreadgrou
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
 
 public class BGPPeerAcceptorModuleTest extends AbstractConfigTest {
@@ -70,7 +71,7 @@ public class BGPPeerAcceptorModuleTest extends AbstractConfigTest {
     @Test
     public void testCreateBeanDefaultAddress() throws InstanceAlreadyExistsException, ConflictingVersionException, ValidationException {
         try {
-            final CommitStatus status = createRegistryInstance(Optional.<String>absent(), Optional.<Integer>absent(), true, true);
+            final CommitStatus status = createRegistryInstance(Optional.<IpAddress>absent(), Optional.<Integer>absent(), true, true);
             assertBeanCount(1, FACTORY_NAME);
             assertStatus(status, 3, 0, 0);
             verify(dispatcher).createServer(any(BGPPeerRegistry.class), any(InetSocketAddress.class));
@@ -85,20 +86,20 @@ public class BGPPeerAcceptorModuleTest extends AbstractConfigTest {
 
     @Test
     public void testCreateBean() throws Exception {
-        final CommitStatus status = createRegistryInstance(Optional.of("127.0.0.1"), Optional.of(1790), true, true);
+        final IpAddress ipAdress = new IpAddress(new Ipv4Address("127.0.0.1"));
+        final CommitStatus status = createRegistryInstance(Optional.of(ipAdress), Optional.of(1790), true, true);
         assertBeanCount(1, FACTORY_NAME);
         assertStatus(status, 3, 0, 0);
         verify(dispatcher).createServer(any(BGPPeerRegistry.class), any(InetSocketAddress.class));
     }
 
-    private CommitStatus createRegistryInstance(final Optional<String> address, final Optional<Integer> port, final boolean addRegistry, final boolean addDispatcher ) throws InstanceAlreadyExistsException, ValidationException, ConflictingVersionException {
+    private CommitStatus createRegistryInstance(final Optional<IpAddress> address, final Optional<Integer> port, final boolean addRegistry, final boolean addDispatcher ) throws InstanceAlreadyExistsException, ValidationException, ConflictingVersionException {
         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
         final ObjectName module = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
         final BGPPeerAcceptorModuleMXBean proxy = transaction.newMXBeanProxy(module, BGPPeerAcceptorModuleMXBean.class);
 
-        // FIXME JMX crashes if union was not created via artificial constructor - Bug:1276
         if(address.isPresent()) {
-            proxy.setBindingAddress(new IpAddress(address.get().toCharArray()));
+            proxy.setBindingAddress(address.get());
         }
         if(port.isPresent()) {
             proxy.setBindingPort(new PortNumber(port.get()));
index aeb31cced7dbabd435e268d145bb7fc575cd05b2..1cd6f4f58e66eb70533d463939053caa5ddbb53d 100644 (file)
@@ -26,6 +26,7 @@ import org.opendaylight.controller.config.yang.tcpmd5.netty.cfg.MD5ClientChannel
 import org.opendaylight.controller.config.yang.tcpmd5.netty.cfg.MD5ClientChannelFactoryModuleMXBean;
 import org.opendaylight.tcpmd5.jni.NativeTestSupport;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
@@ -38,7 +39,7 @@ public class BGPPeerModuleTest extends AbstractRIBImplModuleTest {
     private static final String INSTANCE_NAME = "bgp-peer-module-impl";
     private static final String FACTORY_NAME = BGPPeerModuleFactory.NAME;
 
-    private static final String HOST = "127.0.0.1";
+    private static final IpAddress HOST = new IpAddress(new Ipv4Address("127.0.0.1"));
     private static final PortNumber portNumber = new PortNumber(1);
 
     @Override
@@ -146,17 +147,13 @@ public class BGPPeerModuleTest extends AbstractRIBImplModuleTest {
         assertStatus(status, 0, 1, 15);
     }
 
-    private ObjectName createBgpPeerInstance(final ConfigTransactionJMXClient transaction, final String host,
+    private ObjectName createBgpPeerInstance(final ConfigTransactionJMXClient transaction, final IpAddress host,
             final PortNumber port, final boolean md5, final boolean internalPeerRole) throws Exception {
         final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
         final BGPPeerModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, BGPPeerModuleMXBean.class);
 
         mxBean.setPeerRegistry(createPeerRegistry(transaction));
-
-        // FIXME JMX crashes if union was not created via artificial constructor - Bug:1276
-        // annotated for JMX as value
-        // IpAddress host1 = new IpAddress(new Ipv4Address(host));
-        mxBean.setHost(host == null ? null : new IpAddress(host.toCharArray()));
+        mxBean.setHost(host);
         mxBean.setPort(port);
         mxBean.setAdvertizedTable(Collections.<ObjectName>emptyList());
         {
@@ -207,7 +204,7 @@ public class BGPPeerModuleTest extends AbstractRIBImplModuleTest {
         return createBgpPeerInstance(HOST, portNumber, md5);
     }
 
-    private CommitStatus createBgpPeerInstance(final String host, final PortNumber port, final boolean md5) throws Exception {
+    private CommitStatus createBgpPeerInstance(final IpAddress host, final PortNumber port, final boolean md5) throws Exception {
         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
         createBgpPeerInstance(transaction, host, port, md5, false);
         return transaction.commit();