java.lang.Object
org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionAdapterImpl
All Implemented Interfaces:
ConnectionAdapter, ConnectionFacade, MessageConsumer, OpenflowProtocolService, org.opendaylight.yangtools.yang.binding.RpcService

public class ConnectionAdapterImpl extends Object implements ConnectionFacade
Handles messages (notifications + rpcs) and connections.
Author:
mirehak, michal.polkorab
  • Field Details

    • REMOVAL_LISTENER

      protected static final com.google.common.cache.RemovalListener<RpcResponseKey,org.opendaylight.openflowjava.protocol.impl.core.connection.ResponseExpectedRpcListener<?>> REMOVAL_LISTENER
    • channel

      protected final io.netty.channel.Channel channel
    • address

      protected final InetSocketAddress address
    • disconnectOccured

      protected boolean disconnectOccured
    • output

      protected final org.opendaylight.openflowjava.protocol.impl.core.connection.ChannelOutboundQueue output
    • responseCache

      protected com.google.common.cache.Cache<RpcResponseKey,org.opendaylight.openflowjava.protocol.impl.core.connection.ResponseExpectedRpcListener<?>> responseCache
      expiring cache for future rpcResponses.
  • Constructor Details

    • ConnectionAdapterImpl

      public ConnectionAdapterImpl(io.netty.channel.Channel channel, InetSocketAddress address, boolean useBarrier, int channelOutboundQueueSize)
      Default constructor.
      Parameters:
      channel - the channel to be set - used for communication
      address - client address (used only in case of UDP communication, as there is no need to store address over tcp (stable channel))
      useBarrier - value is configurable by configSubsytem
  • Method Details

    • setMessageListener

      public void setMessageListener(OpenflowProtocolListener messageListener)
      Description copied from interface: ConnectionAdapter
      Sets the protocol message listener.
      Specified by:
      setMessageListener in interface ConnectionAdapter
      Parameters:
      messageListener - here will be pushed all messages from switch
    • setConnectionReadyListener

      public void setConnectionReadyListener(ConnectionReadyListener connectionReadyListener)
      Description copied from interface: ConnectionAdapter
      Set listener for connection became ready-to-use event.
      Specified by:
      setConnectionReadyListener in interface ConnectionAdapter
      Parameters:
      connectionReadyListener - listens to connection ready event
    • setSystemListener

      public void setSystemListener(SystemNotificationsListener systemListener)
      Description copied from interface: ConnectionAdapter
      Sets the system message listener.
      Specified by:
      setSystemListener in interface ConnectionAdapter
      Parameters:
      systemListener - here will be pushed all system messages from library
    • setAlienMessageListener

      public void setAlienMessageListener(AlienMessageListener alienMessageListener)
      Description copied from interface: ConnectionAdapter
      Set handler for alien messages received from device.
      Specified by:
      setAlienMessageListener in interface ConnectionAdapter
      Parameters:
      alienMessageListener - here will be pushed all alien messages from switch
    • consumeDeviceMessage

      public void consumeDeviceMessage(org.opendaylight.yangtools.yang.binding.DataObject message)
      Method is equivalent to MessageConsumer.consume(DataObject) to prevent missing method in every children of AbstractConnectionAdapterStatistics class, because we overriding original method for StatisticsCounters.
      Parameters:
      message - from device to processing
    • checkListeners

      public void checkListeners()
      Description copied from interface: ConnectionAdapter
      Throws exception if any of required listeners is missing.
      Specified by:
      checkListeners in interface ConnectionAdapter
    • fireConnectionReadyNotification

      public void fireConnectionReadyNotification()
      Description copied from interface: ConnectionAdapter
      Notify listener about connection ready-to-use event.
      Specified by:
      fireConnectionReadyNotification in interface ConnectionAdapter
    • onSwitchCertificateIdentified

      public void onSwitchCertificateIdentified(List<X509Certificate> certificateChain)
      Description copied from interface: ConnectionAdapter
      Notify listener about switch certificate information.
      Specified by:
      onSwitchCertificateIdentified in interface ConnectionAdapter
      Parameters:
      certificateChain - X509 certificate chain presented by the switch
    • registerOutboundQueueHandler

      public <T extends OutboundQueueHandler> OutboundQueueHandlerRegistration<T> registerOutboundQueueHandler(T handler, int maxQueueDepth, long maxBarrierNanos)
      Description copied from interface: ConnectionAdapter
      Registers a new bypass outbound queue.
      Specified by:
      registerOutboundQueueHandler in interface ConnectionAdapter
      Type Parameters:
      T - handler type
      Parameters:
      handler - queue handler
      maxQueueDepth - max amount of not confirmed messaged in queue (i.e. edge for barrier message)
      maxBarrierNanos - regular base for barrier message
      Returns:
      An OutboundQueueHandlerRegistration
    • setPacketInFiltering

      public void setPacketInFiltering(boolean enabled)
      Description copied from interface: ConnectionAdapter
      Set filtering of PacketIn messages. By default these messages are not filtered.
      Specified by:
      setPacketInFiltering in interface ConnectionAdapter
      Parameters:
      enabled - True if PacketIn messages should be filtered, false if they should be reported.
    • setDatapathId

      public void setDatapathId(BigInteger datapathId)
      Description copied from interface: ConnectionAdapter
      Set datapathId for the dpn.
      Specified by:
      setDatapathId in interface ConnectionAdapter
      Parameters:
      datapathId - of the dpn
    • setExecutorService

      public void setExecutorService(ExecutorService executorService)
      Description copied from interface: ConnectionAdapter
      Sets executorService.
      Specified by:
      setExecutorService in interface ConnectionAdapter
      Parameters:
      executorService - for all dpns
    • flowMod

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<FlowModOutput>> flowMod(FlowModInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke flow-mod RPC.
      Specified by:
      flowMod in interface OpenflowProtocolService
      Parameters:
      input - of flow-mod
      Returns:
      output of flow-mod
    • sendToSwitchExpectRpcResultFuture

      protected <I extends OfHeader, O extends OfHeader> com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<O>> sendToSwitchExpectRpcResultFuture(I input, Class<O> responseClazz, String failureInfo)
      Sends given message to switch, sending result or switch response will be reported via return value.
      Parameters:
      input - message to send
      responseClazz - type of response
      failureInfo - describes, what type of message caused failure by sending
      Returns:
      future object,
      • if send fails, RpcResult will contain errors and failed status
      • else RpcResult will be stored in responseCache and wait for particular timeout ( AbstractConnectionAdapter.RPC_RESPONSE_EXPIRATION),
        • either switch will manage to answer and then corresponding response message will be set into returned future
        • or response in cache will expire and returned future will be cancelled
    • sendToSwitchFuture

      protected <O extends org.opendaylight.yangtools.yang.binding.DataObject> com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<O>> sendToSwitchFuture(Object input, String failureInfo)
      Sends given message to switch, sending result will be reported via return value.
      Parameters:
      input - message to send
      failureInfo - describes, what type of message caused failure by sending
      Returns:
      future object,
      • if send successful, RpcResult without errors and successful status will be returned,
      • else RpcResult will contain errors and failed status
    • consume

      public void consume(org.opendaylight.yangtools.yang.binding.DataObject message)
      Description copied from interface: MessageConsumer
      Invoked to consume a message.
      Specified by:
      consume in interface MessageConsumer
      Parameters:
      message - to process
    • disconnect

      public Future<Boolean> disconnect()
      Description copied from interface: ConnectionAdapter
      Disconnect corresponding switch.
      Specified by:
      disconnect in interface ConnectionAdapter
      Returns:
      future set to true, when disconnect completed
    • barrier

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<BarrierOutput>> barrier(BarrierInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke barrier RPC.
      Specified by:
      barrier in interface OpenflowProtocolService
      Parameters:
      input - of barrier
      Returns:
      output of barrier
    • echo

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<EchoOutput>> echo(EchoInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke echo RPC.
      Specified by:
      echo in interface OpenflowProtocolService
      Parameters:
      input - of echo
      Returns:
      output of echo
    • echoReply

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<EchoReplyOutput>> echoReply(EchoReplyInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke echo-reply RPC.
      Specified by:
      echoReply in interface OpenflowProtocolService
      Parameters:
      input - of echo-reply
      Returns:
      output of echo-reply
    • experimenter

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<ExperimenterOutput>> experimenter(ExperimenterInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke experimenter RPC.
           
               Send experimenter message to device, reply is not solicitated.
           
       
      Specified by:
      experimenter in interface OpenflowProtocolService
      Parameters:
      input - of experimenter
      Returns:
      output of experimenter
    • getConfig

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<GetConfigOutput>> getConfig(GetConfigInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke get-config RPC.
      Specified by:
      getConfig in interface OpenflowProtocolService
      Parameters:
      input - of get-config
      Returns:
      output of get-config
    • getFeatures

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<GetFeaturesOutput>> getFeatures(GetFeaturesInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke get-features RPC.
      Specified by:
      getFeatures in interface OpenflowProtocolService
      Parameters:
      input - of get-features
      Returns:
      output of get-features
    • getQueueConfig

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<GetQueueConfigOutput>> getQueueConfig(GetQueueConfigInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke get-queue-config RPC.
      Specified by:
      getQueueConfig in interface OpenflowProtocolService
      Parameters:
      input - of get-queue-config
      Returns:
      output of get-queue-config
    • groupMod

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<GroupModOutput>> groupMod(GroupModInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke group-mod RPC.
      Specified by:
      groupMod in interface OpenflowProtocolService
      Parameters:
      input - of group-mod
      Returns:
      output of group-mod
    • hello

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<HelloOutput>> hello(HelloInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke hello RPC.
      Specified by:
      hello in interface OpenflowProtocolService
      Parameters:
      input - of hello
      Returns:
      output of hello
    • meterMod

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<MeterModOutput>> meterMod(MeterModInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke meter-mod RPC.
      Specified by:
      meterMod in interface OpenflowProtocolService
      Parameters:
      input - of meter-mod
      Returns:
      output of meter-mod
    • packetOut

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<PacketOutOutput>> packetOut(PacketOutInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke packet-out RPC.
      Specified by:
      packetOut in interface OpenflowProtocolService
      Parameters:
      input - of packet-out
      Returns:
      output of packet-out
    • multipartRequest

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<MultipartRequestOutput>> multipartRequest(MultipartRequestInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke multipart-request RPC.
      Specified by:
      multipartRequest in interface OpenflowProtocolService
      Parameters:
      input - of multipart-request
      Returns:
      output of multipart-request
    • portMod

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<PortModOutput>> portMod(PortModInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke port-mod RPC.
      Specified by:
      portMod in interface OpenflowProtocolService
      Parameters:
      input - of port-mod
      Returns:
      output of port-mod
    • roleRequest

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<RoleRequestOutput>> roleRequest(RoleRequestInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke role-request RPC.
      Specified by:
      roleRequest in interface OpenflowProtocolService
      Parameters:
      input - of role-request
      Returns:
      output of role-request
    • setConfig

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<SetConfigOutput>> setConfig(SetConfigInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke set-config RPC.
      Specified by:
      setConfig in interface OpenflowProtocolService
      Parameters:
      input - of set-config
      Returns:
      output of set-config
    • tableMod

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<TableModOutput>> tableMod(TableModInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke table-mod RPC.
      Specified by:
      tableMod in interface OpenflowProtocolService
      Parameters:
      input - of table-mod
      Returns:
      output of table-mod
    • getAsync

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<GetAsyncOutput>> getAsync(GetAsyncInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke get-async RPC.
      Specified by:
      getAsync in interface OpenflowProtocolService
      Parameters:
      input - of get-async
      Returns:
      output of get-async
    • setAsync

      public com.google.common.util.concurrent.ListenableFuture<org.opendaylight.yangtools.yang.common.RpcResult<SetAsyncOutput>> setAsync(SetAsyncInput input)
      Description copied from interface: OpenflowProtocolService
      Invoke set-async RPC.
      Specified by:
      setAsync in interface OpenflowProtocolService
      Parameters:
      input - of set-async
      Returns:
      output of set-async
    • isAlive

      public boolean isAlive()
      Description copied from interface: ConnectionAdapter
      Determines if the connection to the switch is alive.
      Specified by:
      isAlive in interface ConnectionAdapter
      Returns:
      true, if connection to switch is alive
    • isAutoRead

      public boolean isAutoRead()
      Description copied from interface: ConnectionAdapter
      Determines if the channel is configured to auto-read.
      Specified by:
      isAutoRead in interface ConnectionAdapter
      Returns:
      true, if channel is configured to auto-read
    • setAutoRead

      public void setAutoRead(boolean autoRead)
      Description copied from interface: ConnectionAdapter
      Sets option for automatic channel reading - if set to false, incoming messages won't be read.
      Specified by:
      setAutoRead in interface ConnectionAdapter
      Parameters:
      autoRead - target value to be switched to
    • getRemoteAddress

      public InetSocketAddress getRemoteAddress()
      Description copied from interface: ConnectionAdapter
      Returns the address of the connected switch.
      Specified by:
      getRemoteAddress in interface ConnectionAdapter
      Returns:
      address of the remote end - address of a switch if connected
    • findRpcResponse

      protected org.opendaylight.openflowjava.protocol.impl.core.connection.ResponseExpectedRpcListener<?> findRpcResponse(RpcResponseKey key)
      Return cached RpcListener or null if not cached.