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