QKnxNetIpRouter Class

The QKnxNetIpRouter class enables sending and receiving routing KNXnet/IP packets to and from other KNXnet/IP routers. More...

Header: #include <QKnxNetIpRouter>
qmake: QT += knx
Since: Qt 5.12
Inherits: QObject

Public Types

enum Error { None, KnxRouting, Network }
enum FilterAction { RouteDecremented, RouteLast, ForwardLocally, IgnoreTotally, IgnoreAcked }
typedef KnxAddressWhitelist
enum RoutingMode { Block, RouteAll, Filter }
enum State { NotInit, Routing, NeighborBusy, Stop, Failure }

Public Functions

QKnxNetIpRouter(QObject *parent = nullptr)
virtual ~QKnxNetIpRouter()
QKnxNetIpRouter::Error error() const
QString errorString() const
QKnxNetIpRouter::KnxAddressWhitelist filterTable() const
QKnxAddress individualAddress() const
QNetworkInterface interfaceAffinity() const
QHostAddress multicastAddress() const
QKnxNetIpRouter::RoutingMode routingMode() const
void setFilterTable(const QKnxNetIpRouter::KnxAddressWhitelist &table)
void setIndividualAddress(const QKnxAddress &address)
void setInterfaceAffinity(const QHostAddress &address)
void setInterfaceAffinity(const QNetworkInterface &iface)
void setMulticastAddress(const QHostAddress &address)
void setRoutingMode(QKnxNetIpRouter::RoutingMode mode)
QKnxNetIpRouter::State state() const
  • 34 public functions inherited from QObject

Public Slots

void sendRoutingBusy(const QKnxNetIpFrame &frame)
void sendRoutingIndication(const QKnxNetIpFrame &frame)
void sendRoutingLostMessage(const QKnxNetIpFrame &frame)
void sendRoutingSystemBroadcast(const QKnxNetIpFrame &frame)
void start()
void stop()
  • 1 public slot inherited from QObject

Signals

void errorOccurred(QKnxNetIpRouter::Error error, QString errorString)
void routingBusyReceived(QKnxNetIpFrame frame)
void routingBusySent(QKnxNetIpFrame frame)
void routingIndicationReceived(QKnxNetIpFrame frame, QKnxNetIpRouter::FilterAction routingAction)
void routingIndicationSent(QKnxNetIpFrame frame)
void routingLostCountReceived(QKnxNetIpFrame frame)
void routingLostCountSent(QKnxNetIpFrame frame)
void routingSystemBroadcastReceived(QKnxNetIpFrame frame)
void routingSystemBroadcastSent(QKnxNetIpFrame frame)
void stateChanged(QKnxNetIpRouter::State state)

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public variable inherited from QObject
  • 10 static public members inherited from QObject
  • 9 protected functions inherited from QObject
  • 2 protected variables inherited from QObject

Detailed Description

The QKnxNetIpRouter class enables sending and receiving routing KNXnet/IP packets to and from other KNXnet/IP routers.

The QKnxNetIpRouter is bound to a physical network interface which is used for transmitting and receiving the routing frames. It also requires the multicast address used by the KNX installation.

The following code sample illustrates how to use the QKnxNetIpRouter to send and receive KNXnet/IP frames:

QKnxNetIpRouter router1;
QKnxNetIpRouter router2;
router1.setInterfaceAffinity(QNetworkInterface::interfaceFromName("eth0"));
router1.setMulticastAddress(QHostAddress("224.0.23.32"));
router1.start();

auto busyWaitTime = ...
auto busyControlField = ...

// Sending a routing indication to another router on the same IP network
auto routingBusyFrame = QKnxNetIpRoutingBusyProxy::builder()
    .setDeviceState(QKnxNetIp::DeviceState::IpFault)
    .setRoutingBusyWaitTime(busyWaitTime)
    .setRoutingBusyControl(busyControlField)
    .create();
router1.sendRoutingBusy(routingBusyFrame);

// Processing routing indications received
QObject::connect(&router1,
                 &QKnxNetIpRouter::routingIndicationReceived,
             [](QKnxNetIpFrame frame,
                QKnxNetIpRouter::FilterAction routingAction) {
        QKnxNetIpRoutingIndicationProxy indication(frame);
        qInfo().noquote() << "Received routing indication:"
                          << indication.isValid();

        switch (routingAction) {
        case QKnxNetIpRouter::FilterAction::RouteDecremented:
            auto cemi = indication.cemi();
            auto extCtrl = cemi.extendedControlField();
            count = extCtrl.hopCount();
            // decrement and send to other subnet
            extCtrl.setHopCount(--count);
            auto newIndication =  QKnxNetIpRoutingIndicationProxy::builder()
                                    .setCemi(cemi)
                                    .create();
            router2.sendRoutingIndication(newIndication)
            // ....
        case QKnxNetIpRouter::FilterAction::RouteLast:
        case QKnxNetIpRouter::FilterAction::ForwardLocally:
        case QKnxNetIpRouter::FilterAction::IgnoreTotally:
        case QKnxNetIpRouter::FilterAction::IgnoreAcked:
        //....
        default:
            break;
        }
        //....
});

See also QKnxLinkLayerFrame and Routing.

Member Type Documentation

enum QKnxNetIpRouter::Error

This enum holds the state of the QKnxNetIpRouter.

ConstantValueDescription
QKnxNetIpRouter::None0No errors.
QKnxNetIpRouter::KnxRouting1Error found at the KNX routing protocol level.
QKnxNetIpRouter::Network2UDP/IP network error.

enum QKnxNetIpRouter::FilterAction

This enum holds the possible courses of action of a router in response to a received layer service data unit (LSDU). An LSDU is a type of frame used by the L_Data service belonging to the data link layer.

ConstantValueDescription
QKnxNetIpRouter::RouteDecremented0The LSDU shall be routed from one subnetwork (on the primary side or the secondary side) to the second subnetwork side (on the secondary side or the primary side) after the hop count value is decremented. The LSDU shall only be routed to the second subnetwork after it has been positively acknowledged on the first subnetwork.
QKnxNetIpRouter::RouteLast1The LSDU shall be routed from the first subnetwork to the second subnetwork and the hop count value shall be set to zero. The telegram shall be acknowledged according to the Data Link Layer specifications of the medium of the first subnetwork and then the LSDU shall be routed to the second subnetwork.
QKnxNetIpRouter::ForwardLocally2The LSDU shall be processed to an NSDU and given to the local network layer user after it has been acknowledged positively on the subnetwork from which it has arrived.
QKnxNetIpRouter::IgnoreTotally3The LSDU shall be ignored; no acknowledgment shall be sent back to the originator of the LSDU.
QKnxNetIpRouter::IgnoreAcked4The LSDU shall be ignored, nonetheless it shall be acknowledged on the subnetwork from which it has arrived.

typedef QKnxNetIpRouter::KnxAddressWhitelist

A synonym for QKnxNetIpRouter::QSet<QKnxAddress>, which is the type used to store the filter table of the router. The filter table is interpreted as a whitelist by the routing algorithm. The addresses stored are allowed to be routed. Any frame with a destination address that is not contained in the table is blocked.

enum QKnxNetIpRouter::RoutingMode

This enum holds the possible parameterization actions that a router shall apply on telegrams of a point-to-multipoint connectionless communication mode with standard group addresses.

ConstantValueDescription
QKnxNetIpRouter::Block0No telegrams are allowed to be forwarded on the interface.
QKnxNetIpRouter::RouteAll1All telegrams are routed and the filter table is ignored.
QKnxNetIpRouter::Filter2All telegrams with destination addresses not in the filter table are blocked, the rest of telegrams are forwarded.

enum QKnxNetIpRouter::State

This enum holds the state of the QKnxNetIpRouter.

ConstantValueDescription
QKnxNetIpRouter::NotInit0Router not started yet.
QKnxNetIpRouter::Routing1Router is listening for incoming messages and accepting messages for sending.
QKnxNetIpRouter::NeighborBusy2A KNX router in the same network sent a busy message or the QKnxNetIpRouter itself detected a busy situation.
QKnxNetIpRouter::Stop3Router has been explicitly stopped by the user.
QKnxNetIpRouter::Failure4Any error that occurs in the router shall set this state.

Member Function Documentation

QKnxNetIpRouter::QKnxNetIpRouter(QObject *parent = nullptr)

Constructs a KNXnet/IP router with the parent parent.

[virtual] QKnxNetIpRouter::~QKnxNetIpRouter()

Destroys the instance of QKnxNetIpRouter. The destructor is virtual.

QKnxNetIpRouter::Error QKnxNetIpRouter::error() const

Returns a routing error code that describes the last error to occur in the KNX router.

[signal] void QKnxNetIpRouter::errorOccurred(QKnxNetIpRouter::Error error, QString errorString)

This signal is emitted when the KNXnet/IP router encounters the error error that is described by errorString.

QString QKnxNetIpRouter::errorString() const

Returns a QString describing the latest known error that occurred in the KNX router.

QKnxNetIpRouter::KnxAddressWhitelist QKnxNetIpRouter::filterTable() const

Returns the filter table used by the routing algorithm.

See also setFilterTable().

QKnxAddress QKnxNetIpRouter::individualAddress() const

Returns the routing interface's individual address.

See also setIndividualAddress().

QNetworkInterface QKnxNetIpRouter::interfaceAffinity() const

Returns the current network interface used by this KNX routing instance.

See also setInterfaceAffinity().

QHostAddress QKnxNetIpRouter::multicastAddress() const

Returns the multicast address used by the QKnxNetIpRouter.

See also setMulticastAddress().

[signal] void QKnxNetIpRouter::routingBusyReceived(QKnxNetIpFrame frame)

This signal is emitted when the KNXnet/IP router receives a routing busy frame.

[signal] void QKnxNetIpRouter::routingBusySent(QKnxNetIpFrame frame)

This signal is emitted when the KNXnet/IP router has finished sending the routing busy frame.

[signal] void QKnxNetIpRouter::routingIndicationReceived(QKnxNetIpFrame frame, QKnxNetIpRouter::FilterAction routingAction)

This signal is emitted when the KNXnet/IP router receives a routing indication frame and specifies the action routingAction to be applied by the router.

[signal] void QKnxNetIpRouter::routingIndicationSent(QKnxNetIpFrame frame)

This signal is emitted when the KNXnet/IP router has finished sending the routing indication frame.

[signal] void QKnxNetIpRouter::routingLostCountReceived(QKnxNetIpFrame frame)

This signal is emitted when the KNXnet/IP router receives a routing lost count message held in frame.

[signal] void QKnxNetIpRouter::routingLostCountSent(QKnxNetIpFrame frame)

This signal is emitted when the KNXnet/IP router has finished sending the routing lost count frame.

QKnxNetIpRouter::RoutingMode QKnxNetIpRouter::routingMode() const

Returns the routing mode.

See also setRoutingMode().

[signal] void QKnxNetIpRouter::routingSystemBroadcastReceived(QKnxNetIpFrame frame)

This signal is emitted when the KNXnet/IP router receives the routing system broadcast frame.

[signal] void QKnxNetIpRouter::routingSystemBroadcastSent(QKnxNetIpFrame frame)

This signal is emitted when the KNXnet/IP router has finished sending the routing system broadcast frame.

[slot] void QKnxNetIpRouter::sendRoutingBusy(const QKnxNetIpFrame &frame)

Multicasts the routing busy message containing frame through the network interface associated with the QKnxNetIpRouter.

[slot] void QKnxNetIpRouter::sendRoutingIndication(const QKnxNetIpFrame &frame)

Multicasts the routing indication frame through the network interface associated with the QKnxNetIpRouter.

[slot] void QKnxNetIpRouter::sendRoutingLostMessage(const QKnxNetIpFrame &frame)

Multicasts the routing lost message frame through the network interface associated with the QKnxNetIpRouter.

[slot] void QKnxNetIpRouter::sendRoutingSystemBroadcast(const QKnxNetIpFrame &frame)

Multicasts the routing system broadcast frame through the network interface associated with the QKnxNetIpRouter.

void QKnxNetIpRouter::setFilterTable(const QKnxNetIpRouter::KnxAddressWhitelist &table)

Sets the filter table used by the routing algorithm to table.

See also filterTable().

void QKnxNetIpRouter::setIndividualAddress(const QKnxAddress &address)

Sets the routing interface's individual address to address.

See also individualAddress().

void QKnxNetIpRouter::setInterfaceAffinity(const QHostAddress &address)

Searches for the network interface that is bound to address that the QKnxNetIpRouter instance shall use.

See also interfaceAffinity().

void QKnxNetIpRouter::setInterfaceAffinity(const QNetworkInterface &iface)

Sets the network interface iface that the QNetworkInterface instance shall use.

void QKnxNetIpRouter::setMulticastAddress(const QHostAddress &address)

Sets the multicast address to address.

See also multicastAddress().

void QKnxNetIpRouter::setRoutingMode(QKnxNetIpRouter::RoutingMode mode)

Sets the routing mode to mode.

See also routingMode().

[slot] void QKnxNetIpRouter::start()

Signals the QKnxNetIpRouter to start listening for messages received and accept sending messages.

QKnxNetIpRouter::State QKnxNetIpRouter::state() const

Returns the current state of the KNX router.

[signal] void QKnxNetIpRouter::stateChanged(QKnxNetIpRouter::State state)

This signal is emitted when the KNXnet/IP router transitions to a different state.

[slot] void QKnxNetIpRouter::stop()

Stops the QKnxNetIpRouter. No messages can be received from or sent to the network.

© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.