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>
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;
OpendaylightPortStatisticsService, //
OpendaylightFlowTableStatisticsService, //
OpendaylightQueueStatisticsService, //
- FlowNodeInventoryService,
Identifiable<InstanceIdentifier<Node>> {
/**
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;
private RoutedRpcRegistration<OpendaylightQueueStatisticsService> queueStatisticsRegistration;
- private RoutedRpcRegistration<FlowNodeInventoryService> flowNodeInventoryRegistration;
-
protected final SessionContext sessionContext;
protected AbstractModelDrivenSwitch(InstanceIdentifier<Node> identifier,SessionContext conductor) {
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();
}
*/
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;
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;
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;
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!");
- }
}
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;
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;
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;
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) {