Bug-6507: MalformedObjectNameException while configuring OpenConfig BGP IPv6 neighbor 39/44639/3
authorAjay <ajayl.bro@gmail.com>
Thu, 25 Aug 2016 03:40:46 +0000 (03:40 +0000)
committerMilos Fabian <milfabia@cisco.com>
Mon, 29 Aug 2016 09:10:09 +0000 (09:10 +0000)
- Since colon is not a valid character for MBean key, replace colon in
  IPv6 neighbor address with dash while creating BGP Peer module name
- Convert neighbor IPv6 address and key which is derieved from it to
  to normalized notation (full-form and leading 0s removed) to match with
  similar conversion for BGP Peer module done in BGPPeerModule#getNormalizedHost

Change-Id: I440b5c81ae2cd4ee042c2fc5c5d30e4846ce8c4c
Signed-off-by: Ajay <ajayl.bro@gmail.com>
bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/comparator/NeighborComparator.java [changed mode: 0644->0755]
bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/moduleconfig/BGPAppPeerProvider.java [changed mode: 0644->0755]
bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/moduleconfig/BGPPeerProvider.java [changed mode: 0644->0755]
bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/openconfig/AbstractBGPNeighborProvider.java [changed mode: 0644->0755]
bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/util/OpenConfigUtil.java [changed mode: 0644->0755]
integration-tests/src/test/java/org/opendaylight/protocol/integration/pcep/AbstractPcepOsgiTest.java
util/pom.xml
util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java

old mode 100644 (file)
new mode 100755 (executable)
index 46a37fa..f4b288b
@@ -12,6 +12,7 @@ import com.google.common.base.Preconditions;
 import java.util.List;
 import java.util.Objects;
 import org.opendaylight.protocol.bgp.openconfig.impl.spi.OpenConfigComparator;
+import org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.Neighbor1;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.Config;
@@ -48,10 +49,10 @@ final class NeighborComparator implements OpenConfigComparator<Neighbor> {
                 return false;
             }
         }
-        if (!Objects.equals(neighbor1.getKey(), neighbor2.getKey())) {
+        if (!Objects.equals(OpenConfigUtil.getNeighborKey(neighbor1), OpenConfigUtil.getNeighborKey(neighbor2))) {
             return false;
         }
-        if (!Objects.equals(neighbor1.getNeighborAddress(), neighbor2.getNeighborAddress())) {
+        if (!Objects.equals(OpenConfigUtil.getNeighborAddress(neighbor1), OpenConfigUtil.getNeighborAddress(neighbor2))) {
             return false;
         }
         if (!Objects.equals(neighbor1.getRouteReflector(), neighbor2.getRouteReflector())) {
old mode 100644 (file)
new mode 100755 (executable)
index 4743296..274e7a5
@@ -17,6 +17,7 @@ import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.protocol.bgp.openconfig.impl.spi.BGPConfigHolder;
 import org.opendaylight.protocol.bgp.openconfig.impl.spi.BGPConfigStateStore;
 import org.opendaylight.protocol.bgp.openconfig.impl.util.GlobalIdentifier;
+import org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
@@ -71,7 +72,7 @@ final class BGPAppPeerProvider {
     }
 
     public void onNeighborRemoved(final Neighbor removedNeighbor) {
-        final ModuleKey moduleKey = neighborState.getModuleKey(removedNeighbor.getKey());
+        final ModuleKey moduleKey = neighborState.getModuleKey(OpenConfigUtil.getNeighborKey(removedNeighbor));
         if (moduleKey != null) {
             try {
                 final ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
@@ -87,12 +88,12 @@ final class BGPAppPeerProvider {
     }
 
     public void onNeighborModified(final Neighbor modifiedAppNeighbor) {
-        final ModuleKey moduleKey = neighborState.getModuleKey(modifiedAppNeighbor.getKey());
+        final ModuleKey moduleKey = neighborState.getModuleKey(OpenConfigUtil.getNeighborKey(modifiedAppNeighbor));
         final ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
         if (moduleKey != null) {
             //update an existing peer configuration
             try {
-                if (neighborState.addOrUpdate(moduleKey, modifiedAppNeighbor.getKey(), modifiedAppNeighbor)) {
+                if (neighborState.addOrUpdate(moduleKey, OpenConfigUtil.getNeighborKey(modifiedAppNeighbor), modifiedAppNeighbor)) {
                     final Optional<Module> maybeModule = configModuleOp.readModuleConfiguration(moduleKey, rTx);
                     if (maybeModule.isPresent()) {
                         final Module peerConfigModule = toPeerConfigModule(modifiedAppNeighbor, maybeModule.get());
@@ -116,7 +117,7 @@ final class BGPAppPeerProvider {
 
                     final Module peerConfigModule = toPeerConfigModule(modifiedAppNeighbor, rib, moduleDataBroker);
                     configModuleOp.putModuleConfiguration(peerConfigModule, dataBroker.newWriteOnlyTransaction());
-                    neighborState.addOrUpdate(peerConfigModule.getKey(), modifiedAppNeighbor.getKey(), modifiedAppNeighbor);
+                    neighborState.addOrUpdate(peerConfigModule.getKey(), OpenConfigUtil.getNeighborKey(modifiedAppNeighbor), modifiedAppNeighbor);
                 } catch (final Exception e) {
                     LOG.error("Failed to create a configuration module: {}", moduleKey, e);
                     throw new IllegalStateException(e);
old mode 100644 (file)
new mode 100755 (executable)
index 2fc4cb5..100b1c3
@@ -20,6 +20,7 @@ import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFaile
 import org.opendaylight.protocol.bgp.openconfig.impl.spi.BGPConfigHolder;
 import org.opendaylight.protocol.bgp.openconfig.impl.spi.BGPConfigStateStore;
 import org.opendaylight.protocol.bgp.openconfig.impl.util.GlobalIdentifier;
+import org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.RouteReflector;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.Timers;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.Transport;
@@ -76,7 +77,7 @@ final class BGPPeerProvider {
     }
 
     public void onNeighborRemoved(final Neighbor removedNeighbor) {
-        final ModuleKey moduleKey = neighborState.getModuleKey(removedNeighbor.getKey());
+        final ModuleKey moduleKey = neighborState.getModuleKey(OpenConfigUtil.getNeighborKey(removedNeighbor));
         if (moduleKey != null) {
             try {
                 final ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
@@ -92,7 +93,7 @@ final class BGPPeerProvider {
     }
 
     public void onNeighborModified(final Neighbor modifiedNeighbor) {
-        final ModuleKey moduleKey = neighborState.getModuleKey(modifiedNeighbor.getKey());
+        final ModuleKey moduleKey = neighborState.getModuleKey(OpenConfigUtil.getNeighborKey(modifiedNeighbor));
         final ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
         final List<AdvertizedTable> advertizedTables = getAdvertizedTables(modifiedNeighbor, rTx);
         if (moduleKey != null) {
@@ -108,7 +109,7 @@ final class BGPPeerProvider {
 
     private void updateExistingPeerConfiguration(final ModuleKey moduleKey, final Neighbor modifiedNeighbor, final List<AdvertizedTable>
         advertizedTables, final ReadOnlyTransaction rTx) {
-        if (neighborState.addOrUpdate(moduleKey, modifiedNeighbor.getKey(), modifiedNeighbor)) {
+        if (neighborState.addOrUpdate(moduleKey, OpenConfigUtil.getNeighborKey(modifiedNeighbor), modifiedNeighbor)) {
             final Optional<Module> maybeModule = getOldModuleConfiguration(moduleKey, rTx);
             if (maybeModule.isPresent()) {
                 final Module peerConfigModule = toPeerConfigModule(modifiedNeighbor, maybeModule.get(), advertizedTables);
@@ -143,7 +144,7 @@ final class BGPPeerProvider {
                 final Rib rib = RibInstanceFunction.getRibInstance(this.configModuleOp, this.TO_RIB_FUNCTION, ribImplKey.getName(), rTx);
                 final Module peerConfigModule = toPeerConfigModule(modifiedNeighbor, advertizedTables, rib);
                 configModuleOp.putModuleConfiguration(peerConfigModule, dataBroker.newWriteOnlyTransaction());
-                neighborState.addOrUpdate(peerConfigModule.getKey(), modifiedNeighbor.getKey(), modifiedNeighbor);
+                neighborState.addOrUpdate(peerConfigModule.getKey(), OpenConfigUtil.getNeighborKey(modifiedNeighbor), modifiedNeighbor);
             } catch (final Exception e) {
                 LOG.error("Failed to create a configuration module: {}", moduleKey, e);
                 throw new IllegalStateException(e);
@@ -165,7 +166,7 @@ final class BGPPeerProvider {
 
     private static Module toPeerConfigModule(final Neighbor neighbor, final List<AdvertizedTable> tableTypes, final Rib rib) {
         final ModuleBuilder mBuilder = new ModuleBuilder();
-        mBuilder.setName(createPeerName(neighbor.getNeighborAddress()));
+        mBuilder.setName(createPeerName(OpenConfigUtil.getNeighborAddress(neighbor)));
         mBuilder.setType(BgpPeer.class);
         mBuilder.setConfiguration(toBgpPeerConfig(neighbor, tableTypes, rib).build());
         mBuilder.setKey(new ModuleKey(mBuilder.getName(), mBuilder.getType()));
@@ -182,7 +183,7 @@ final class BGPPeerProvider {
                 .gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address(neighbor.getNeighborAddress().getIpv4Address().getValue()));
         } else {
             ipAdress = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress(new org.opendaylight.yang
-                .gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address(neighbor.getNeighborAddress().getIpv6Address().getValue()));
+                .gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address(OpenConfigUtil.getNeighborAddress(neighbor).getIpv6Address().getValue()));
         }
         bgpPeerBuilder.setHost(ipAdress);
         final Timers timers = neighbor.getTimers();
@@ -208,7 +209,7 @@ final class BGPPeerProvider {
     }
 
     private static String createPeerName(final IpAddress ipAddress) {
-        final String address = ipAddress.getIpv4Address() != null ? ipAddress.getIpv4Address().getValue() : ipAddress.getIpv6Address().getValue();
+        final String address = ipAddress.getIpv4Address() != null ? ipAddress.getIpv4Address().getValue() : ipAddress.getIpv6Address().getValue().replace(':', '-');
         return PEER + address;
     }
 
@@ -226,7 +227,7 @@ final class BGPPeerProvider {
                 return PeerRole.Ebgp;
             }
         }
-        LOG.info("Unknown peer role, setting peer {} role to iBGP", neighbor.getKey());
+        LOG.info("Unknown peer role, setting peer {} role to iBGP", OpenConfigUtil.getNeighborKey(neighbor));
         return PeerRole.Ibgp;
     }
 
old mode 100644 (file)
new mode 100755 (executable)
index 6bdc6be..512f8fa
@@ -12,6 +12,7 @@ import static org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.
 import com.google.common.base.Preconditions;
 import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
 import org.opendaylight.protocol.bgp.openconfig.impl.spi.BGPConfigStateStore;
+import org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil;
 import org.opendaylight.protocol.bgp.openconfig.spi.InstanceConfiguration;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborKey;
@@ -36,6 +37,6 @@ abstract class AbstractBGPNeighborProvider<T extends InstanceConfiguration> exte
 
     @Override
     public final NeighborKey keyForConfiguration(final Neighbor neighbor) {
-        return neighbor.getKey();
+        return OpenConfigUtil.getNeighborKey(neighbor);
     }
 }
old mode 100644 (file)
new mode 100755 (executable)
index fb745b1..db4a530
@@ -15,13 +15,18 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.protocol.util.Ipv6Util;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafiBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborKey;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4LABELLEDUNICAST;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV6LABELLEDUNICAST;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV6UNICAST;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.FlowspecSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.LabeledUnicastSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
@@ -84,4 +89,25 @@ public final class OpenConfigUtil {
     public static String getModuleName(final String provider) {
         return provider.substring(provider.lastIndexOf('=') + 2, provider.length() - 2);
     }
+
+    public static NeighborKey getNeighborKey(final Neighbor neighbor) {
+        if (neighbor.getKey() == null || neighbor.getKey().getNeighborAddress() == null) {
+            return null;
+        }
+        return new NeighborKey(getNormalizedNeighborAddress(neighbor.getKey().getNeighborAddress()));
+    }
+
+    public static IpAddress getNeighborAddress(final Neighbor neighbor) {
+        return getNormalizedNeighborAddress(neighbor.getNeighborAddress());
+
+    }
+
+    private static IpAddress getNormalizedNeighborAddress(final IpAddress address) {
+        if (address != null && address.getIpv6Address() != null) {
+            final Ipv6Address ipv6Address = Ipv6Util.getFullForm(address.getIpv6Address());
+            return new IpAddress(ipv6Address);
+        } else {
+            return address;
+        }
+    }
 }
index d6ab0252047c53a914a2bddd002d12ea9318fef9..bf05de469f2df33dcc6679e805b5d281e9ab9c11 100644 (file)
@@ -72,6 +72,7 @@ public class AbstractPcepOsgiTest {
     private Option pcepModules() {
         return new DefaultCompositeOption(
                 mavenBundle("org.opendaylight.mdsal.model", "ietf-topology").versionAsInProject(), //
+                mavenBundle("org.opendaylight.mdsal.model", "ietf-inet-types-2013-07-15").versionAsInProject(), //
                 mavenBundle("org.opendaylight.yangtools", "object-cache-api").versionAsInProject(), //
                 mavenBundle("org.opendaylight.bgpcep", "pcep-topology-api").versionAsInProject(), //
                 mavenBundle("org.opendaylight.bgpcep", "pcep-tunnel-api").versionAsInProject(), //
index a5000156bb0a57a2f5c3cfa0fe3be9b09e1fdc17..361e8bbee5f31f81faf8916151b0dc73f4ff3865 100644 (file)
             <groupId>org.opendaylight.mdsal.model</groupId>
             <artifactId>ietf-inet-types</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal.model</groupId>
+            <artifactId>ietf-inet-types-2013-07-15</artifactId>
+        </dependency>
         <!-- Testing dependencies -->
         <dependency>
             <groupId>junit</groupId>
index effad46d4e19dbcff2b2f3edc61912228066cbcd..8d06146d4030139fdf3278734a407dc015db0dfb 100644 (file)
@@ -41,6 +41,16 @@ public final class Ipv6Util {
         return new Ipv6Address(InetAddresses.forString(ip.getValue()).getHostAddress());
     }
 
+    /**
+     * Creates uncompressed IP Address
+     *
+     * @param ip to be uncompressed
+     * @return Ipv6Address with same, but uncompressed, value
+     */
+    public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address getFullForm(final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address ip) {
+        return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address(InetAddresses.forString(ip.getValue()).getHostAddress());
+    }
+
     /**
      * Reads from ByteBuf buffer and converts bytes to Ipv6Address.
      *