车载信息服务软件开发包使用指南(12)

281 篇文章 30 订阅
该文介绍了如何使用车载信息服务软件开发包来创建VLAN并将其绑定到PDN,以及创建静态NAT表项。首先,通过DataFactory获取VlanManager和NatManager实例,然后初始化并等待完成。接着,实现回调函数来处理创建VLAN和NAT条目的响应。创建VLAN涉及指定接口类型、ID和加速状态,而创建静态NAT条目则需要配置profileID、本地IP、端口和协议。
摘要由CSDN通过智能技术生成

车载信息服务软件开发包使用指南(12)

4.4.11 创建VLAN并绑定PDN

此示例应用程序演示了如何创建 VLAN 并将其绑定到 PDN。

  1. 实现初始化回调,获取DataFactory实例
    可选地,初始化回调可以与获取管理器实例一起提供。 管理器初始化完成后,数据工厂将调用回调。
auto initCb = [&](telux::common::ServiceStatus status) {
    std::lock_guard<std::mutex> lock(mtx);
    status_ = status;
    initCv.notify_all();
};
auto &dataFactory = telux::data::DataFactory::getInstance();
  1. 获取VlanManager实例
std::unique_lock<std::mutex> lck(mtx);
auto dataVlanMgr = dataFactory.getVlanManager(opType, initCb);
  1. 等待VlanManager初始化完成
    initCv.wait(lck);

3.1 查看VlanManager初始化状态
如果 VlanManager 初始化失败,可以通过调用步骤 2 来完成新的初始化尝试。如果 VlanManager 初始化成功,则继续执行步骤 4。

if (status_ == telux::common::ServiceStatus::SERVICE_AVAILABLE) {
    // Go to step 4
}
else {
    //Go to step 2 for another initialization attempt
}

  1. 实现创建VLAN的回调
auto respCbCreate = [](bool isAccelerated, telux::common::ErrorCode error) {
    std::cout << std::endl << std::endl;
    std::cout << "CALLBACK: "
    << "createVlan Response"
    << (error == telux::common::ErrorCode::SUCCESS ? " is successful" : " failed")
    << ". ErrorCode: " << static_cast<int>(error);
    std::cout << " Acceleration " << (isAccelerated ? "is allowed" : "is not allowed") << "\n";
};
  1. 根据接口类型、加速、分配的id创建Vlan
telux::data::VlanConfig config;
config.iface = infType;
config.vlanId = vlanId;
config.isAccelerated = isAccelerated;
dataVlanMgr->createVlan(config, respCbCreate);

现在,将为 createVlan 响应调用响应回调。

  1. 实现 bindWithprofile 响应的回调
auto respCbBind = [](telux::common::ErrorCode error) {
    std::cout << std::endl << std::endl;
    std::cout << "CALLBACK: "
        << "bindWithProfile Response"
        << (error == telux::common::ErrorCode::SUCCESS ? " is successful" : " failed")
        << ". ErrorCode: " << static_cast<int>(error) << std::endl;
};
  1. 将创建的 Vlan 与用户提供的配置文件 ID 绑定
    dataVlanMgr->bindWithProfile(profileId, vlanId, respCbBind);

现在,将为 bindWithProfile 响应调用响应回调。

4.4.12 创建静态NAT表项

此示例应用程序演示了如何创建静态 NAT 条目。

  1. 实现初始化回调,获取DataFactory实例
    可选地,初始化回调可以与获取管理器实例一起提供。管理器初始化完成后,数据工厂将调用回调。
auto initCb = [&](telux::common::ServiceStatus status) {
    std::lock_guard<std::mutex> lock(mtx);
    status_ = status;
    initCv.notify_all();
};
auto &dataFactory = telux::data::DataFactory::getInstance();
  1. 获取 NatManager 实例
std::unique_lock<std::mutex> lck(mtx);
auto dataSnatMgr = dataFactory.getNatManager(opType);
  1. 等待NatManager初始化完成
    initCv.wait(lck);

3.1 查看NatManager初始化状态
如果 NatManager 初始化失败,可以通过调用步骤 2 来完成新的初始化尝试。如果 NatManager 初始化成功,则继续执行步骤 4。

if (status_ == telux::common::ServiceStatus::SERVICE_AVAILABLE) {
    // Go to step 4
}
else {
    //Go to step 2 for another initialization attempt
}
  1. 实现创建SNAT入口的回调
auto respCb = [](telux::common::ErrorCode error) {
    std::cout << std::endl << std::endl;
    std::cout << "CALLBACK: "
        << "addStaticNatEntry"
        << (error == telux::common::ErrorCode::SUCCESS ? " is successful" : " failed");
};
  1. 根据profile id、本地ip、本地端口、全局端口、协议创建Snat入口
natConfig.addr = ipAddr;
natConfig.port = (uint16_t)localIpPort;
natConfig.globalPort = (uint16_t)globalIpPort;
natConfig.proto = (uint8_t)proto;
dataSnatMgr->addStaticNatEntry(profileId, natConfig, respCb);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值