• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *    Copyright (c) 2020, The OpenThread Authors.
3  *    All rights reserved.
4  *
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.
15  *
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.
27  */
28 
29 /**
30  * @file
31  *   This file includes definition for Thread Backbone agent.
32  */
33 
34 #ifndef BACKBONE_ROUTER_BACKBONE_AGENT_HPP_
35 #define BACKBONE_ROUTER_BACKBONE_AGENT_HPP_
36 
37 #if OTBR_ENABLE_BACKBONE_ROUTER
38 
39 #include <openthread/backbone_router_ftd.h>
40 
41 #include "backbone_router/dua_routing_manager.hpp"
42 #include "backbone_router/nd_proxy.hpp"
43 #include "common/code_utils.hpp"
44 #include "ncp/ncp_openthread.hpp"
45 
46 namespace otbr {
47 namespace BackboneRouter {
48 
49 /**
50  * @addtogroup border-router-backbone
51  *
52  * @brief
53  *   This module includes definition for Thread Backbone agent.
54  *
55  * @{
56  */
57 
58 /**
59  * This class implements Thread Backbone agent functionality.
60  *
61  */
62 class BackboneAgent : private NonCopyable
63 {
64 public:
65     static constexpr uint16_t kBackboneUdpPort = 61631; ///< The BBR port.
66 
67     /**
68      * This constructor intiializes the `BackboneAgent` instance.
69      *
70      * @param[in] aNcp  The Thread instance.
71      *
72      */
73     BackboneAgent(otbr::Ncp::ControllerOpenThread &aNcp,
74                   std::string                      aInterfaceName,
75                   std::string                      aBackboneInterfaceName);
76 
77     /**
78      * This method initializes the Backbone agent.
79      *
80      */
81     void Init(void);
82 
83 private:
84     void        OnBecomePrimary(void);
85     void        OnResignPrimary(void);
IsPrimary(void) const86     bool        IsPrimary(void) const { return mBackboneRouterState == OT_BACKBONE_ROUTER_STATE_PRIMARY; }
87     void        HandleThreadStateChanged(otChangedFlags aFlags);
88     void        HandleBackboneRouterState(void);
89     static void HandleBackboneRouterDomainPrefixEvent(void *                            aContext,
90                                                       otBackboneRouterDomainPrefixEvent aEvent,
91                                                       const otIp6Prefix *               aDomainPrefix);
92     void        HandleBackboneRouterDomainPrefixEvent(otBackboneRouterDomainPrefixEvent aEvent,
93                                                       const otIp6Prefix *               aDomainPrefix);
94 #if OTBR_ENABLE_DUA_ROUTING
95     static void HandleBackboneRouterNdProxyEvent(void *                       aContext,
96                                                  otBackboneRouterNdProxyEvent aEvent,
97                                                  const otIp6Address *         aAddress);
98     void        HandleBackboneRouterNdProxyEvent(otBackboneRouterNdProxyEvent aEvent, const otIp6Address *aAddress);
99 #endif
100 
101     static const char *StateToString(otBackboneRouterState aState);
102 
103     otbr::Ncp::ControllerOpenThread &mNcp;
104     otBackboneRouterState            mBackboneRouterState;
105     Ip6Prefix                        mDomainPrefix;
106 #if OTBR_ENABLE_DUA_ROUTING
107     NdProxyManager    mNdProxyManager;
108     DuaRoutingManager mDuaRoutingManager;
109 #endif
110 };
111 
112 /**
113  * @}
114  */
115 
116 } // namespace BackboneRouter
117 } // namespace otbr
118 
119 #endif // OTBR_ENABLE_BACKBONE_ROUTER
120 
121 #endif // BACKBONE_ROUTER_BACKBONE_AGENT_HPP_
122