Enable L2TP and Add Tunnel
Please follow below steps to enable L2TP and Tunnel
1. Implement initialization callback and get get the DataFactory instance
Optionally initialization callback can be provided with get manager instance. Data factory will call callback when manager initialization is complete.
auto initCb = [&](telux::common::ServiceStatus status) {
std::lock_guard<std::mutex> lock(mtx);
status_ = status;
initCv.notify_all();
};
auto &dataFactory = telux::data::DataFactory::getInstance();
2. Get the L2tpManager instances
std::unique_lock<std::mutex> lck(mtx);
auto dataL2tpMgr = dataFactory.getL2tpManager(initCb);
3. Wait for L2tpManager initialization to be complete
3.1 Check L2tpManager initialization state
If L2tpManager initialization failed, new initialization attempt can be accomplished by calling step 2. If L2tpManager initialization succeed, proceed to step 4
if (status_ == telux::common::ServiceStatus::SERVICE_AVAILABLE) {
}
else {
}
4. Instantiate setConfig callback instance - this is optional
auto setConfigCb = [&setConfigPass, &promise](telux::common::ErrorCode error) {
std::cout << std::endl << std::endl;
std::cout << "CALLBACK: "
<< "setConfig Response"
<< (error == telux::common::ErrorCode::SUCCESS ? " is successful" : " failed");
};
### 5. Set L2TP Configuration
bool enable = true;
bool enableMss = true;
bool enableMtu = true;
int mtuSize = 0;
dataL2tpMgr->setConfig(enable, enableMss, enableMtu, setConfigCb, mtuSize);
6. Configure L2TP Tunnel and Session
std::cout << "L2TP Set Configuration succeeded ... Adding Tunnel" << std::endl;
telux::data::net::L2tpTunnelConfig l2tpTunnelConfig;
l2tpTunnelConfig.locIface = "eth0.1";
l2tpTunnelConfig.prot = static_cast<telux::data::net::L2tpProtocol>(2);
l2tpTunnelConfig.locId = 1;
l2tpTunnelConfig.peerId = 1;
l2tpTunnelConfig.localUdpPort = 500;
l2tpTunnelConfig.peerUdpPort = 100;
l2tpTunnelConfig.ipType = static_cast<telux::data::IpFamilyType>(6);
l2tpTunnelConfig.peerIpv6Addr = "fe80::b044::c0ff::fec4";
telux::data::net::L2tpSessionConfig l2tpSessionConfig;
l2tpSessionConfig.locId = 1;
l2tpSessionConfig.peerId = 1;
l2tpTunnelConfig.sessionConfig.emplace_back(l2tpSessionConfig);
7. Instantiate addTunnel callback instance - this is optional
auto addTunnelCb = [&setConfigPass, &promise](telux::common::ErrorCode error) {
std::cout << std::endl << std::endl;
std::cout << "CALLBACK: "
<< "addTunnel Response"
<< (error == telux::common::ErrorCode::SUCCESS ? " is successful" : " failed")
<< ". ErrorCode: " << static_cast<int>(error) << "\n";
};
8. addTunnel to L2TP
dataL2tpMgr->addTunnel(l2tpTunnelConfig, addTunnelCb);