Google is committed to advancing racial equity for Black communities. See how.

nl::Weave::Profiles::WeaveTunnel::WeaveTunnelConnectionMgr

#include <src/lib/profiles/weave-tunneling/WeaveTunnelConnectionMgr.h>

This class encapsulates all the Weave tunnel connection states and the associated management logic and functions.

Summary

An instance of this class would be used to manage the tunnel over each interface through which the Weave tunnel to the Service would exist.

Constructors and Destructors

WeaveTunnelConnectionMgr(void)

Public types

ConnectPolicyCallback)(void *const appState, ReconnectParam &reconnectParam, uint32_t &delayMsec) typedef
void(*
Callback to fetch the interval of time to wait before the next tunnel reconnect.
TunnelConnNotifyReasons{
  kStatus_TunDown = 0,
  kStatus_TunPrimaryUp = 1,
  kStatus_TunPrimaryConnError = 2,
  kStatus_TunBackupConnError = 3,
  kStatus_TunFailoverToBackup = 4,
  kStatus_TunBackupOnlyDown = 5,
  kStatus_TunBackupUp = 6,
  kStatus_TunPrimaryAndBackupUp = 7,
  kStatus_TunPrimaryReconnectRcvd = 8,
  kStatus_TunBackupReconnectRcvd = 9,
  kStatus_TunPrimaryLiveness = 10,
  kStatus_TunBackupLiveness = 11
}
enum
TunnelConnNotifyReasons typedef
TunnelConnectionState{
  kState_NotConnected = 0,
  kState_Connecting = 1,
  kState_ConnectionEstablished = 2,
  kState_TunnelOpen = 3,
  kState_TunnelClosing = 4,
  kState_ReconnectRecvd = 5
}
enum
TunnelConnectionState typedef

Public attributes

mServiceConnDelayPolicyCallback

Public functions

Init(WeaveTunnelAgent *tunAgent, TunnelType tunType, SrcInterfaceType srcIntfType, const char *connIntfName)
Initialize the WeaveTunnelConnectionMgr.
ServiceTunnelClose(WEAVE_ERROR err)
void
Close the Service tunnel.
SetInterfaceName(const char *intfName)
void
Set InterfaceName for Tunnel connection.
SetInterfaceType(const SrcInterfaceType srcIntfType)
void
Set SrcInterfaceType for Tunnel connection.
Shutdown(void)
void
StopAndReconnectTunnelConn(ReconnectParam & reconnParam)
void
Stop Service tunnel connection and attempt to reconnect again.
TryConnectingNow(void)
Attempt to establish a connection to the Service.

Public static functions

DefaultReconnectPolicyCallback(void *const appstate, ReconnectParam & reconnectParam, uint32_t & delayMsec)
void
The default policy implementation for fetching the next time to connect to the Service.
HandleServiceConnectionClosed(WeaveConnection *con, WEAVE_ERROR conErr)
void
Handler invoked when Service TCP connection is closed.
HandleServiceConnectionComplete(WeaveConnection *con, WEAVE_ERROR conErr)
void
Handler invoked when Service TCP connection is completed.
RecvdFromService(WeaveConnection *con, const WeaveMessageInfo *msgInfo, PacketBuffer *message)
void
Handler to receive tunneled IPv6 packets from the Service TCP connection and forward to the Tunnel EndPoint interface after decapsulating the raw IPv6 packet from inside the tunnel header.
ServiceMgrStatusHandler(void *appState, WEAVE_ERROR err, StatusReport *report)
void
Handler invoked if the Service Manager failed to establish the TCP connection to the Service.

Public types

ConnectPolicyCallback

void(* ConnectPolicyCallback)(void *const appState, ReconnectParam &reconnectParam, uint32_t &delayMsec)

Callback to fetch the interval of time to wait before the next tunnel reconnect.

Details
Parameters
[in] appState
App state pointer set during initialization of the SubscriptionClient.
[in] reconnectParam
Structure with parameters that influence the calculation of the reconnection delay.
[out] delayMsec
Time in milliseconds to wait before next reconnect attempt.

TunnelConnNotifyReasons

 TunnelConnNotifyReasons
Properties
kStatus_TunBackupConnError

Used to indicate that a backup tunnel connection attempt has failed or an existing one was locally aborted or closed by peer.

kStatus_TunBackupLiveness

Used to indicate information about the Tunnel Liveness probe on the Backup Weave tunnel.

kStatus_TunBackupOnlyDown

Used to indicate that the backup tunnel is down.

kStatus_TunBackupReconnectRcvd

Used to indicate that the Service has requested a reconnect for the Backup Weave tunnel.

kStatus_TunBackupUp

Used to indicate that the Backup Weave tunnel is up.

kStatus_TunDown

Used to indicate that the Weave tunnel has gone down.

kStatus_TunFailoverToBackup

Used to indicate that the primary tunnel is down and switchover to backup tunnel has occurred.

kStatus_TunPrimaryAndBackupUp

Used to indicate that both the Primary and Backup Weave tunnel are up.

kStatus_TunPrimaryConnError

Used to indicate that a primary tunnel connection attempt has failed or an existing one was locally aborted or closed by peer.

kStatus_TunPrimaryLiveness

Used to indicate information about the Tunnel Liveness probe on the Primary Weave tunnel.

kStatus_TunPrimaryReconnectRcvd

Used to indicate that the Service has requested a reconnect for the Primary Weave tunnel.

kStatus_TunPrimaryUp

Used to indicate that the primary Weave tunnel is up.

TunnelConnNotifyReasons

enum nl::Weave::Profiles::WeaveTunnel::WeaveTunnelConnectionMgr::TunnelConnNotifyReasons TunnelConnNotifyReasons

TunnelConnectionState

 TunnelConnectionState
Properties
kState_Connecting

Used to indicate that the Weave Tunnel connection has been initiated.

kState_ConnectionEstablished

Used to indicate that the Weave Tunnel connection is established and route information is being exchanged.

kState_NotConnected

Used to indicate that the Weave Tunnel is not connected.

kState_ReconnectRecvd

Used to indicate that the Service wants the border gateway to reconnect after a directory lookup.

kState_TunnelClosing

Used to indicate that the Weave Tunnel is closing and the connection is being torn down.

kState_TunnelOpen

Used to indicate that the Weave Tunnel is open and ready for data traffic transit.

TunnelConnectionState

enum nl::Weave::Profiles::WeaveTunnel::WeaveTunnelConnectionMgr::TunnelConnectionState TunnelConnectionState

Public attributes

mServiceConnDelayPolicyCallback

ConnectPolicyCallback mServiceConnDelayPolicyCallback

Public functions

Init

WEAVE_ERROR Init(
  WeaveTunnelAgent *tunAgent,
  TunnelType tunType,
  SrcInterfaceType srcIntfType,
  const char *connIntfName
)

Initialize the WeaveTunnelConnectionMgr.

ServiceTunnelClose

void ServiceTunnelClose(
  WEAVE_ERROR err
)

Close the Service tunnel.

Details
Parameters
[in] err
A WEAVE_ERROR passed in from the caller.

SetInterfaceName

void SetInterfaceName(
  const char *intfName
)

Set InterfaceName for Tunnel connection.

Details
Parameters
[in] tunIntf
The InterfaceName for setting the Service tunnel connection.

SetInterfaceType

void SetInterfaceType(
  const SrcInterfaceType srcIntfType
)

Set SrcInterfaceType for Tunnel connection.

Details
Parameters
[in] srcIntfType
The network technology type of the interface for Service tunnel connection.

Shutdown

void Shutdown(
  void
)

Shutdown the WeaveTunnelConnectionMgr.

StopAndReconnectTunnelConn

void StopAndReconnectTunnelConn(
  ReconnectParam & reconnParam
)

Stop Service tunnel connection and attempt to reconnect again.

Details
Parameters
[in] err
A WEAVE_ERROR passed in from the caller.

TryConnectingNow

WEAVE_ERROR TryConnectingNow(
  void
)

Attempt to establish a connection to the Service.

Try to establish a connecttion to the Service either using ServiceManager or directly.

WeaveTunnelConnectionMgr

 WeaveTunnelConnectionMgr(
  void
)

Public static functions

DefaultReconnectPolicyCallback

void DefaultReconnectPolicyCallback(
  void *const appstate,
  ReconnectParam & reconnectParam,
  uint32_t & delayMsec
)

The default policy implementation for fetching the next time to connect to the Service.

This policy picks a random timeslot (with millisecond resolution) over an increasing window, following a fibonacci sequence upto WEAVE_CONFIG_TUNNELING_RECONNECT_MAX_FIBONACCI_INDEX.

Details
Parameters
[in] appState
App state pointer set during initialization of the SubscriptionClient.
[in] reconnectParam
Structure with parameters that influence the calculation of the reconnection delay.
[out] delayMsec
Time in milliseconds to wait before next reconnect attempt.

HandleServiceConnectionClosed

void HandleServiceConnectionClosed(
  WeaveConnection *con,
  WEAVE_ERROR conErr
)

Handler invoked when Service TCP connection is closed.

The device tries to re-establish the connection to the Service if the mServiceConKeepAlive is set to true.

The device, subsequently, tries to re-establish the connection to the Service.

Details
Parameters
[in] con
A pointer to the WeaveConnection object.
[in] conErr
Any error within the WeaveConnection or WEAVE_NO_ERROR.

HandleServiceConnectionComplete

void HandleServiceConnectionComplete(
  WeaveConnection *con,
  WEAVE_ERROR conErr
)

Handler invoked when Service TCP connection is completed.

The device proceeds to initiate Tunnel control commands to the Service from this function.

The device proceeds to initiate Tunnel control commands to the Service from this function.

Details
Parameters
[in] con
A pointer to the WeaveConnection object.
[in] conErr
Any error within the WeaveConnection or WEAVE_NO_ERROR.

RecvdFromService

void RecvdFromService(
  WeaveConnection *con,
  const WeaveMessageInfo *msgInfo,
  PacketBuffer *message
)

Handler to receive tunneled IPv6 packets from the Service TCP connection and forward to the Tunnel EndPoint interface after decapsulating the raw IPv6 packet from inside the tunnel header.

Details
Parameters
[in] con
A pointer to the WeaveConnection object.
[in] msgInfo
A pointer to the WeaveMessageInfo object.
[in] message
A pointer to the PacketBuffer object holding the tunneled IPv6 packet.

ServiceMgrStatusHandler

void ServiceMgrStatusHandler(
  void *appState,
  WEAVE_ERROR err,
  StatusReport *report
)

Handler invoked if the Service Manager failed to establish the TCP connection to the Service.