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/rcp_host.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 class BackboneAgent : private NonCopyable 68 { 69 public: 70 static constexpr uint16_t kBackboneUdpPort = 61631; ///< The BBR port. 71 72 /** 73 * This constructor intiializes the `BackboneAgent` instance. 74 * 75 * @param[in] aHost The Thread controller instance. 76 */ 77 BackboneAgent(otbr::Ncp::RcpHost &aHost, std::string aInterfaceName, std::string aBackboneInterfaceName); 78 79 /** 80 * This method initializes the Backbone agent. 81 */ 82 void Init(void); 83 84 private: 85 void OnBecomePrimary(void); 86 void OnResignPrimary(void); IsPrimary(void) const87 bool IsPrimary(void) const { return mBackboneRouterState == OT_BACKBONE_ROUTER_STATE_PRIMARY; } 88 void HandleThreadStateChanged(otChangedFlags aFlags); 89 void HandleBackboneRouterState(void); 90 static void HandleBackboneRouterDomainPrefixEvent(void *aContext, 91 otBackboneRouterDomainPrefixEvent aEvent, 92 const otIp6Prefix *aDomainPrefix); 93 void HandleBackboneRouterDomainPrefixEvent(otBackboneRouterDomainPrefixEvent aEvent, 94 const otIp6Prefix *aDomainPrefix); 95 #if OTBR_ENABLE_DUA_ROUTING 96 static void HandleBackboneRouterNdProxyEvent(void *aContext, 97 otBackboneRouterNdProxyEvent aEvent, 98 const otIp6Address *aAddress); 99 void HandleBackboneRouterNdProxyEvent(otBackboneRouterNdProxyEvent aEvent, const otIp6Address *aAddress); 100 #endif 101 102 static const char *StateToString(otBackboneRouterState aState); 103 104 otbr::Ncp::RcpHost &mHost; 105 otBackboneRouterState mBackboneRouterState; 106 Ip6Prefix mDomainPrefix; 107 #if OTBR_ENABLE_DUA_ROUTING 108 NdProxyManager mNdProxyManager; 109 DuaRoutingManager mDuaRoutingManager; 110 #endif 111 }; 112 113 /** 114 * @} 115 */ 116 117 } // namespace BackboneRouter 118 } // namespace otbr 119 120 #endif // OTBR_ENABLE_BACKBONE_ROUTER 121 122 #endif // BACKBONE_ROUTER_BACKBONE_AGENT_HPP_ 123