2 * Copyright (c) 2020, The OpenThread Authors.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of the copyright holder nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
31 * This file includes definition for Thread Backbone agent.
34 #ifndef BACKBONE_ROUTER_BACKBONE_AGENT_HPP_
35 #define BACKBONE_ROUTER_BACKBONE_AGENT_HPP_
37 #include <openthread/backbone_router_ftd.h>
39 #include "agent/instance_params.hpp"
40 #include "agent/ncp_openthread.hpp"
41 #include "backbone_router/nd_proxy.hpp"
44 namespace BackboneRouter {
47 * @addtogroup border-router-backbone
50 * This module includes definition for Thread Backbone agent.
56 * This class implements Thread Backbone agent functionality.
63 * This constructor intiializes the `BackboneAgent` instance.
65 * @param[in] aNcp The Thread instance.
68 BackboneAgent(otbr::Ncp::ControllerOpenThread &aNcp);
71 * This method initializes the Backbone agent.
77 * This method updates the fd_set and timeout for mainloop.
79 * @param[inout] aReadFdSet A reference to fd_set for polling read.
80 * @param[inout] aWriteFdSet A reference to fd_set for polling read.
81 * @param[inout] aErrorFdSet A reference to fd_set for polling error.
82 * @param[inout] aMaxFd A reference to the current max fd in @p aReadFdSet and @p aWriteFdSet.
83 * @param[inout] aTimeout A reference to the timeout.
86 void UpdateFdSet(fd_set & aReadFdSet,
90 timeval &aTimeout) const;
93 * This method performs border agent processing.
95 * @param[in] aReadFdSet A reference to read file descriptors.
96 * @param[in] aWriteFdSet A reference to write file descriptors.
97 * @param[in] aErrorFdSet A reference to error file descriptors.
100 void Process(const fd_set &aReadFdSet, const fd_set &aWriteFdSet, const fd_set &aErrorFdSet);
103 void OnBecomePrimary(void);
104 void OnResignPrimary(void);
105 bool IsPrimary(void) const { return mBackboneRouterState == OT_BACKBONE_ROUTER_STATE_PRIMARY; }
106 static void HandleBackboneRouterState(void *aContext, int aEvent, va_list aArguments);
107 void HandleBackboneRouterState(void);
108 static void HandleBackboneRouterDomainPrefixEvent(void *aContext, int aEvent, va_list aArguments);
109 void HandleBackboneRouterDomainPrefixEvent(otBackboneRouterDomainPrefixEvent aEvent,
110 const otIp6Prefix * aDomainPrefix);
111 static void HandleBackboneRouterNdProxyEvent(void *aContext, int aEvent, va_list aArguments);
112 void HandleBackboneRouterNdProxyEvent(otBackboneRouterNdProxyEvent aEvent, const otIp6Address *aAddress);
114 static const char *StateToString(otBackboneRouterState aState);
116 otbr::Ncp::ControllerOpenThread &mNcp;
117 otBackboneRouterState mBackboneRouterState;
118 NdProxyManager mNdProxyManager;
119 Ip6Prefix mDomainPrefix;
126 } // namespace BackboneRouter
129 #endif // BACKBONE_ROUTER_BACKBONE_AGENT_HPP_