
我正在尝试搭建 LTE PDCP 层回调,报了如下错误,我是新手 ns3,不知道哪里出了错误,我的源码在下面,能帮我看一下吗?
#include < 字符串>
#include “ns3/lte-helper.h”
#include “ns3/epc-helper.h”
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/ipv4-global-routing-helper.h”
#include “ns3/internet-module.h”
#include “ns3/mobility-module.h”
#include “ns3/lte-module.h”
#include “ns3/applications-module.h”
#include “ns3/point-to-point-helper.h”
#include “ns3/config-store.h”
#include “ns3/netanim-module.h”
#include “ns3/wifi-module.h”
#include “ns3/gtk-config-store.h”
#include “/data/user/wangtengsheng/ns3/ns3_wifi/ns3-mmwave-5.0/src/lte/model/lwa-tag.h”
#include “/data/user/wangtengsheng/ns3/ns3_wifi/ns3-mmwave-5.0/src/lte/model/pdcp-lcid.h”
#include “/data/user/wangtengsheng/ns3/ns3_wifi/ns3-mmwave-5.0/src/lte/model/lwalwip-header.h”
使用命名空间 NS3;
std::map<uint16_t, Ptr<Socket>> lwaSocketMap;
std::map<std::string, Ptr<Socket>> contextSocketMap;
通过 LtePdcp 传输的 lwa/lwip 数据包处理功能::D oTransmitPdcpSdu
void LtePdcpLwaHandler (LteRlcSapProvider::TransmitPdcpPduParameters params){
NS_LOG_DEBUG(“rnti : ” << params.rnti);
复制传入数据包
Ptr<Packet> currentPacket = params.pdcpPdu->Copy();
删除标头以获取序列号并包含 LWA/LWIP 标头
//wifi接收到的数据包
LtePdcpHeader pdcpHeader;
currentPacket->RemoveHeader (pdcpHeader) 的 RemoveHeader;
ipv4header ipHeader;
currentPacket->RemoveHeader (ipHeader) 的 RemoveHeader (删除标头);
TcpHeader tcpHeader;
currentPacket->RemoveHeader (tcpHeader) 的 RemoveHeader 文件;
再次添加标题
currentPacket->AddHeader (tcpHeader) 的 AddHeader (tcpHeader);
currentPacket->AddHeader (ipHeader) 的添加标头;
currentPacket->AddHeader (pdcpHeader) 的 AddHeader 文件;
读取 PDCP 层添加的 LWA 标签并添加 LWA 信息
作为数据包的单独标头(传输时不会删除
通过 API 的数据包)
LwaTag lwaTag;
PdcpLcid lcid标签;
uint32_t lcid=0;
uint32_t bid=0;
LwaLwipHeader lwaLwipHeader;
标签复制帧的逻辑通道 ID
if(currentPacket->FindFirstMatchingByteTag (lcidTag)){
lcid = lcidTag.Get();
出价 = LCID - 2;
}
lwaLwipHeader.SetBearerId (出价);
// packet handling for lwa packets
if (currentPacket->PeekPacketTag(lwaTag)){
//copy the status of LWA activation (LTE, Split, swtiched)
lwaLwipHeader.SetLwaActivate (lwaTag.Get());
// add lwa lwip header
currentPacket->AddHeader (lwaLwipHeader);
lwaSocketMap.find(params.rnti)->second->Send(currentPacket);
//NS_LOG_DEBUG ("LWA: Sent packet with PDCP Sequence Number " << pdcpHeader.GetSequenceNumber());
}
}
// assign callback function to the pdcp object
// NOTE: object is created after bearer release which is after attach procedure
static void
Callback_LtePDCPTX
(uint16_t rnti){
std::string rntiPath = "/NodeList/*/DeviceList/*/$ns3::LteNetDevice/$ns3::LteEnbNetDevice/LteEnbRrc/UeMap/" + std::to_string(rnti) + "/DataRadioBearerMap/*/LtePdcp/TxPDUtrace";
Config::ConnectWithoutContext (rntiPath, MakeCallback (&LtePdcpLwaHandler));
}
void NotifyConnectionEstablishedUe (
std::string context,
uint64_t imsi,
uint16_t cellId,
uint16_t rnti)
{
std::cout << Simulator::Now ().GetSeconds ()
<< " UE IMSI " << imsi
<< ": connected to CellId " << cellId
<< " with RNTI " << rnti
<< " context " << context
<< std::endl;
// create socket on lwaap socket to enable transmission of lwa packets
/*
Ptr<Socket> lwaapTxSocket = Socket::CreateSocket (lwaapNode, tid);
lwaapTxSocket->Bind ();
lwaapTxSocket->Connect (InetSocketAddress (Ipv4Address::ConvertFrom(wifiIpInterfaces.GetAddress (i+1)), 9));
lwaapTxSocket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ());
lwaapTxSocket->SetAllowBroadcast (true);
//TODO: temporary fix assuming rnti=i+1
lwaSocketMap.insert(std::pair<uint16_t, Ptr<Socket>>(i+1, lwaapTxSocket));
NS_LOG_INFO("STA Socket bound " << i+1);
*/
lwaSocketMap.insert(std::pair<uint16_t, Ptr<Socket>>(rnti, contextSocketMap.find(context)->second));
Simulator::Schedule(MilliSeconds(100), &Callback_LtePDCPTX, rnti);
}
/**
* Sample simulation script for LTE+EPC. It instantiates several eNodeB,
* attaches one UE per eNodeB starts a flow for each UE to and from a remote host.
* It also starts yet another flow between each UE pair.
*/
NS_LOG_COMPONENT_DEFINE ("EpcFirstExample");
int
main (int argc, char *argv[])
{
uint16_t numberOfNodes = 1;
Time simTime = MilliSeconds (11000);
double distance = 40.0;
Time interPacketInterval = MilliSeconds (10);
// MTU size for P2P link between EnB and Wifi AP
double xwLwaLinkMtuSize=1500;
//delay of p2p link
std::string xwLwaLinkDelay="0ms";
//data rate of p2p link
std::string xwLwaLinkDataRate="100Mbps";
// Command line arguments
CommandLine cmd;
cmd.AddValue ("numberOfNodes", "Number of eNodeBs + UE pairs", numberOfNodes);
cmd.AddValue ("simTime", "Total duration of the simulation", simTime);
cmd.AddValue ("distance", "Distance between eNBs [m]", distance);
cmd.AddValue ("interPacketInterval", "Inter packet interval", interPacketInterval);
cmd.Parse(argc, argv);
Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();
lteHelper->SetEpcHelper (epcHelper);
ConfigStore inputConfig;
inputConfig.ConfigureDefaults();
// parse again so you can override default values from the command line
cmd.Parse(argc, argv);
Ptr<Node> pgw = epcHelper->GetPgwNode ();
// Create a single RemoteHost
NodeContainer remoteHostContainer;
remoteHostContainer.Create (1);
Ptr<Node> remoteHost = remoteHostContainer.Get (0);
InternetStackHelper internet;
internet.Install (remoteHostContainer);
// Create the Internet
PointToPointHelper p2ph;
p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
p2ph.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (10)));
NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
Ipv4AddressHelper ipv4h;
ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
// interface 0 is localhost, 1 is the p2p device
// Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1);
Ipv4StaticRoutingHelper ipv4RoutingHelper;
Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
NodeContainer ueNodes, enbNodes, wifiApNodes, wifiStaNodes;
enbNodes.Create(numberOfNodes);
ueNodes.Create(numberOfNodes);
wifiApNodes.Create(1);
wifiStaNodes.Add(ueNodes); // LTE 用户设备同时作为 Wi-Fi STA
// Configure Wi-Fi
WifiHelper wifiHelper;
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiMacHelper wifiMac;
Ssid ssid = Ssid("LteWifiNetwork");
wifiMac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
NetDeviceContainer wifiApDevs = wifiHelper.Install(wifiPhy, wifiMac, wifiApNodes);
wifiMac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
NetDeviceContainer wifiStaDevs = wifiHelper.Install(wifiPhy, wifiMac, wifiStaNodes);
// start call back 100ms before datageneration
// uint32_t callbackStartMs = uint32_t (3 * 1000 - 100);
// Simulator::Schedule (MilliSeconds(callbackStartMs),&Callback_LtePDCPTX);
// Install Mobility Model
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
// 分配 eNB 和 UE 的位置,距离不超过 30
for (uint16_t i = 0; i < numberOfNodes; i++)
{
positionAlloc->Add(Vector(10.0 * i+10, 10.0 * i, 0.0)); // eNB 位置
positionAlloc->Add(Vector(10.0 * i, 10.0 * i + 10.0, 0.0)); // 对应 UE 位置
positionAlloc->Add(Vector(10.0 * i+40, 10.0 * i+10, 0.0)); // remoteHost 位置
positionAlloc->Add(Vector(10.0 * i+10, 10.0 * i+20, 0.0)); // wifiAp 位置
}
MobilityHelper mobility;
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.SetPositionAllocator(positionAlloc);
mobility.Install(enbNodes);
mobility.Install(ueNodes);
mobility.Install(remoteHostContainer);
mobility.Install(wifiApNodes);
// Install LTE Devices to the nodes
NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes);
NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ueNodes);
// Install the IP stack on the UEs
internet.Install (ueNodes);
internet.Install(wifiApNodes);
Ipv4InterfaceContainer ueIpIface;
ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevs));
// Assign IP address to UEs, and install applications
for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
{
Ptr<Node> ueNode = ueNodes.Get (u);
// Set the default gateway for the UE
Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ());
ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
// ueStaticRouting->AddNetworkRouteTo(Ipv4Address("192.168.1.0"),Ipv4Mask("255.255.255.0"),)
}
// Assign IP addresses for Wi-Fi
ipv4h.SetBase("192.168.1.0", "255.255.255.0");
// Ipv4InterfaceContainer wifiApInterfaces = ipv4h.Assign(wifiApDevs);
// Ipv4InterfaceContainer wifiStaInterfaces = ipv4h.Assign(wifiStaDevs);
Ipv4InterfaceContainer wifiIpInterfaces;
wifiIpInterfaces.Add (ipv4h.Assign (wifiApDevs));
wifiIpInterfaces.Add (ipv4h.Assign (wifiStaDevs));
// Configure Applications
// create p2p helper for LWA/Xw link
PointToPointHelper p2pHelpXw;
p2pHelpXw.SetDeviceAttribute ("DataRate", StringValue (xwLwaLinkDataRate));
p2pHelpXw.SetChannelAttribute ("Delay", StringValue (xwLwaLinkDelay));
p2pHelpXw.SetDeviceAttribute ("Mtu", UintegerValue (xwLwaLinkMtuSize));
// create lwaap node
// NodeContainer lwaNode;
Ptr<Node> lwaapNode = CreateObject<Node> ();
// lwaNode.Add(lwaapNode);
Names::Add("LWAAP", lwaapNode);
// install p2p net devices to create parallel lwa and lwip links
NetDeviceContainer xwLwaDevices = p2pHelpXw.Install (lwaapNode, wifiApNodes.Get(0));
xwLwaDevices.Add(p2pHelpXw.Install (lwaapNode, wifiApNodes.Get(0)));
// install ip stack on additional nodes
internet.Install(lwaapNode);
// assign ip adresses to lwa / lwip links
Ipv4AddressHelper XwAddress;
XwAddress.SetBase ("20.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer xwLwaIpInterfaces = XwAddress.Assign (xwLwaDevices);
Ptr<ListPositionAllocator> positionAlloclwa = CreateObject<ListPositionAllocator> ();
mobility.SetPositionAllocator(positionAlloclwa);
positionAlloclwa->Add(Vector(10.0 +10, 15, 0.0)); // lwa 位置
MobilityHelper Lwamobility;
Lwamobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.SetPositionAllocator(positionAlloclwa);
mobility.Install(lwaapNode);
// Attach one UE per eNodeB
for (uint16_t i = 0; i < numberOfNodes; i++)
{
lteHelper->Attach (ueLteDevs.Get(i), enbLteDevs.Get(i));
// side effect: the default EPS bearer will be activated
Ptr<LteUeNetDevice> ueDev = ueLteDevs.Get(i)->GetObject<LteUeNetDevice> ();
Ptr<LteUeRrc> ueRrc = ueDev->GetRrc ();
ueRrc->TraceConnect("ConnectionEstablished", std::to_string(i), MakeCallback(&NotifyConnectionEstablishedUe));
//创建UDP套接字
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
Ptr<Socket> lwaapTxSocket = Socket::CreateSocket (lwaapNode, tid);
lwaapTxSocket->Bind ();
lwaapTxSocket->Connect (InetSocketAddress (Ipv4Address::ConvertFrom(wifiIpInterfaces.GetAddress (i+1)), 9));
lwaapTxSocket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ());
lwaapTxSocket->SetAllowBroadcast (true);
//TODO: temporary fix assuming rnti=i+1
contextSocketMap.insert(std::pair<std::string, Ptr<Socket>>(std::to_string(i+1), lwaapTxSocket));
//创建接收wifiSta->UE套接字
Ptr<Socket> staRxSocket = Socket::CreateSocket (ueNodes.Get(i), tid);
staRxSocket->Bind (InetSocketAddress (Ipv4Address::GetAny(), 9));
ueRrc->m_staRxSocket = staRxSocket;
}
// Install and start applications on UEs and remote host
uint16_t dlPort = 1100;
ApplicationContainer clientApps;
ApplicationContainer serverApps;
for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
{
PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort));
serverApps.Add (dlPacketSinkHelper.Install (ueNodes.Get(u)));
UdpClientHelper dlClient (ueIpIface.GetAddress (u), dlPort);
dlClient.SetAttribute ("Interval", TimeValue (interPacketInterval));
dlClient.SetAttribute ("MaxPackets", UintegerValue (1000000));
clientApps.Add (dlClient.Install (remoteHost));
}
serverApps.Start (Seconds (1));
clientApps.Start (Seconds (10));
AnimationInterface anim("lte-wifi-distribution.xml");
anim.UpdateNodeDescription(remoteHost, "RemoteHost");
anim.UpdateNodeColor(remoteHost, 0, 0, 255);
anim.UpdateNodeDescription(pgw, "PGW");
anim.UpdateNodeColor(pgw, 0, 0, 255);
anim.UpdateNodeDescription(lwaapNode, "LWAAP");
anim.UpdateNodeColor(lwaapNode, 0, 0, 255);
for (uint32_t i = 0; i < wifiApNodes.GetN(); ++i)
{
anim.UpdateNodeDescription(wifiApNodes.Get(i), "WiFi-AP");
anim.UpdateNodeColor(wifiApNodes.Get(i), 255, 0, 0);
}
for (uint32_t i = 0; i < enbNodes.GetN(); ++i)
{
anim.UpdateNodeDescription(enbNodes.Get(i), "eNB");
anim.UpdateNodeColor(enbNodes.Get(i), 0, 255, 0);
}
for (uint32_t i = 0; i < ueNodes.GetN(); ++i)
{
anim.UpdateNodeDescription(ueNodes.Get(i), "UE");
anim.UpdateNodeColor(ueNodes.Get(i), 0, 255, 255);
}
//lteHelper->EnableTraces ();
// Uncomment to enable PCAP tracing
//p2ph.EnablePcapAll("lena-simple-epc");
Simulator::Stop (simTime);
Simulator::Run ();
/*GtkConfigStore config;
config.ConfigureAttributes();*/
Simulator::Destroy ();
return 0;
}