Removed implementation of RPC get-node-ip-address 82/10382/2
authorMartin Sunal <msunal@cisco.com>
Wed, 27 Aug 2014 14:47:36 +0000 (16:47 +0200)
committerMartin Sunal <msunal@cisco.com>
Wed, 27 Aug 2014 15:06:46 +0000 (15:06 +0000)
implementation of RPC get-node-ip-address from flow-node-inventory is removed.
This RPC is not needed anymore. IP address is stored in datastore.

Signed-off-by: Martin Sunal <msunal@cisco.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/ModelDrivenSwitch.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/AbstractModelDrivenSwitch.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImpl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/SalRegistrationManager.java

index 2a06cd88cd1a60b8dcf78f1d41666ffc89888c9c..06350308b4de6155d356c02204179c2dc55bc012 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.openflowplugin.openflow.md;
 
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowNodeInventoryService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
@@ -44,7 +43,6 @@ public interface ModelDrivenSwitch extends //
         OpendaylightPortStatisticsService, //
         OpendaylightFlowTableStatisticsService, //
         OpendaylightQueueStatisticsService, //
-        FlowNodeInventoryService,
         Identifiable<InstanceIdentifier<Node>> {
 
     /**
index 5dada33e6805e2e0da6ed26759dd863c4919888c..e3db0982a122a5d1e0e797a5f30254bc16b2f5e5 100644 (file)
@@ -11,7 +11,6 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderCo
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
 import org.opendaylight.openflowplugin.openflow.md.ModelDrivenSwitch;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowNodeInventoryService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
@@ -61,8 +60,6 @@ public abstract class AbstractModelDrivenSwitch implements ModelDrivenSwitch {
 
     private RoutedRpcRegistration<OpendaylightQueueStatisticsService> queueStatisticsRegistration;
 
-    private RoutedRpcRegistration<FlowNodeInventoryService> flowNodeInventoryRegistration;
-
     protected final SessionContext sessionContext;
 
     protected AbstractModelDrivenSwitch(InstanceIdentifier<Node> identifier,SessionContext conductor) {
@@ -128,10 +125,6 @@ public abstract class AbstractModelDrivenSwitch implements ModelDrivenSwitch {
         queueStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
         builder.add(queueStatisticsRegistration);
 
-        flowNodeInventoryRegistration = ctx.addRoutedRpcImplementation(FlowNodeInventoryService.class, this);
-        flowNodeInventoryRegistration.registerPath(NodeContext.class, getIdentifier());
-        builder.add(flowNodeInventoryRegistration);
-
         return builder.toInstance();
     }
 
index 8c7e0633f891283548a6103627874691cf997942..10247a54c60013445e58af98286353c54143c795 100644 (file)
@@ -7,10 +7,6 @@
  */
 package org.opendaylight.openflowplugin.openflow.md.core.sal;
 
-import java.net.Inet4Address;
-import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
@@ -21,12 +17,6 @@ import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatch
 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SwitchConnectionCookieOFImpl;
-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.Ipv6Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.GetNodeIpAddressInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.GetNodeIpAddressOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.GetNodeIpAddressOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
@@ -94,7 +84,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.Upd
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 
 import com.google.common.util.concurrent.Futures;
@@ -531,36 +520,4 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
         ListenableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> result = task.submit();
         return result;
     }
-
-    @Override
-    public Future<RpcResult<GetNodeIpAddressOutput>> getNodeIpAddress(GetNodeIpAddressInput input) {
-        if (!sessionContext.isValid()) {
-            return Futures.immediateFuture(RpcResultBuilder
-                    .<GetNodeIpAddressOutput> failed()
-                    .withError(org.opendaylight.yangtools.yang.common.RpcError.ErrorType.TRANSPORT,
-                            "Session is not valid.").build());
-        }
-        InetSocketAddress remoteAddress = sessionContext.getPrimaryConductor().getConnectionAdapter()
-                .getRemoteAddress();
-        if (remoteAddress == null) {
-            return Futures.immediateFuture(RpcResultBuilder
-                    .<GetNodeIpAddressOutput> failed()
-                    .withError(org.opendaylight.yangtools.yang.common.RpcError.ErrorType.TRANSPORT,
-                            "No connection with switch.").build());
-        }
-        IpAddress ipAddress = resolveIpAddress(remoteAddress.getAddress());
-        GetNodeIpAddressOutput result = new GetNodeIpAddressOutputBuilder().setIpAddress(ipAddress).build();
-        return Futures.immediateFuture(RpcResultBuilder.<GetNodeIpAddressOutput> success(result).build());
-    }
-
-    private static IpAddress resolveIpAddress(InetAddress address) {
-        String hostAddress = address.getHostAddress();
-        if (address instanceof Inet4Address) {
-            return new IpAddress(new Ipv4Address(hostAddress));
-        }
-        if (address instanceof Inet6Address) {
-            return new IpAddress(new Ipv6Address(hostAddress));
-        }
-        throw new IllegalArgumentException("Unsupported IP address type!");
-    }
 }
index 27cc0bdb748268688498c7c433ea44a40fa290ab..a426e283ad9feff5a273859416de5179a0b470c0 100644 (file)
@@ -8,7 +8,12 @@
 package org.opendaylight.openflowplugin.openflow.md.core.sal;
 
 import java.math.BigInteger;
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.util.Collection;
+import java.util.concurrent.Future;
 
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
@@ -20,11 +25,15 @@ import org.opendaylight.openflowplugin.openflow.md.core.session.SessionListener;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionManager;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SwitchSessionKeyOF;
 import org.opendaylight.openflowplugin.openflow.md.lldp.LLDPSpeaker;
+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.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeUpdatedBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.GetNodeIpAddressInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.GetNodeIpAddressInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.GetNodeIpAddressOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.GetNodeIpAddressOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
@@ -40,6 +49,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -125,29 +135,36 @@ public class SalRegistrationManager implements SessionListener, AutoCloseable {
         builder.setId(sw.getNodeId());
         builder.setNodeRef(nodeRef);
         FlowCapableNodeUpdatedBuilder builder2 = new FlowCapableNodeUpdatedBuilder();
-        setIpAddressToBuilder(builder2, sw, nodeRef);
+        builder2.setIpAddress(getIpAddressOf(sw));
         builder2.setSwitchFeatures(swFeaturesUtil.buildSwitchFeatures(features));
         builder.addAugmentation(FlowCapableNodeUpdated.class, builder2.build());
         return builder.build();
     }
 
-    private void setIpAddressToBuilder(FlowCapableNodeUpdatedBuilder builder, ModelDrivenSwitch sw, NodeRef nodeRef) {
-        GetNodeIpAddressInput rpcInputGetIpAddress = new GetNodeIpAddressInputBuilder().setNode(nodeRef).build();
-        RpcResult<GetNodeIpAddressOutput> rpcResultGetIpAddress = Futures.getUnchecked(sw
-                .getNodeIpAddress(rpcInputGetIpAddress));
-        if (rpcResultGetIpAddress.isSuccessful()) {
-            builder.setIpAddress(rpcResultGetIpAddress.getResult().getIpAddress());
-        } else {
-            printRpcErrors(rpcResultGetIpAddress.getErrors());
+    private IpAddress getIpAddressOf(ModelDrivenSwitch sw) {
+        SessionContext sessionContext = sw.getSessionContext();
+        if (!sessionContext.isValid()) {
+            LOG.warn("IP address of the node {} cannot be obtained. Session is not valid.", sw.getNodeId());
+            return null;
         }
+        InetSocketAddress remoteAddress = sessionContext.getPrimaryConductor().getConnectionAdapter()
+                .getRemoteAddress();
+        if (remoteAddress == null) {
+            LOG.warn("IP address of the node {} cannot be obtained. No connection with switch.", sw.getNodeId());
+            return null;
+        }
+        return resolveIpAddress(remoteAddress.getAddress());
     }
 
-    private static void printRpcErrors(Collection<RpcError> rpcErrors) {
-        if (rpcErrors != null) {
-            for (RpcError error : rpcErrors) {
-                LOG.warn("{}", error);
-            }
+    private static IpAddress resolveIpAddress(InetAddress address) {
+        String hostAddress = address.getHostAddress();
+        if (address instanceof Inet4Address) {
+            return new IpAddress(new Ipv4Address(hostAddress));
+        }
+        if (address instanceof Inet6Address) {
+            return new IpAddress(new Ipv6Address(hostAddress));
         }
+        throw new IllegalArgumentException("Unsupported IP address type!");
     }
 
     private NodeRemoved nodeRemoved(NodeRef nodeRef) {