简体   繁体   English

使用 .NET 数据包通过协议层进行通信

[英]Communicating Through Protocol Layers With INET Packet

I'm troubling with the reception packet at the receiver side.我对接收方的接收数据包感到不安。 Please help me to find a way.请帮我想办法。 At the SENDER side, I encapsulate the data packet (which comes from UdpBasicApp through Udp protocol) when it arrives at Network Layer as follows:在 SENDER 端,当数据包(通过 Udp 协议来自 UdpBasicApp)到达网络层时,我将其封装如下:

void Sim::encapsulate(Packet *packet) {
    cModule *iftModule = findModuleByPath("SensorNetwork.sink.interfaceTable");
    IInterfaceTable *ift = check_and_cast<IInterfaceTable *>(iftModule);
    auto *ie = ift->findFirstNonLoopbackInterface();
    mySinkMacAddr  = ie->getMacAddress();
    mySinkNetwAddr = ie->getNetworkAddress();
    interfaceId = ie->getInterfaceId();

    //Set Source and Destination Mac and Network Address.
    packet->addTagIfAbsent<MacAddressReq>()->setSrcAddress(myMacAddr);
    packet->addTagIfAbsent<MacAddressReq>()->setDestAddress(mySinkMacAddr);
    packet->addTagIfAbsent<L3AddressReq>()->setSrcAddress(myNetwAddr);
    packet->addTagIfAbsent<L3AddressReq>()->setDestAddress(mySinkNetwAddr);

    packet->addTagIfAbsent<InterfaceReq>()->setInterfaceId(interfaceId);

    //Attaches a "control info" structure (object) to the down message or packet.
    packet->addTagIfAbsent<PacketProtocolTag>()->setProtocol(&getProtocol());
    packet->addTagIfAbsent<DispatchProtocolInd>()->setProtocol(&getProtocol());
}

At the RECEIVER side, I try to get the Network Address of the SENDER as follows:在 RECEIVER 端,我尝试获取 SENDER 的网络地址,如下所示:

auto l3 = packet->addTagIfAbsent<L3AddressReq>()->getSrcAddress();
EV_DEBUG << "THE SOURCE NETWORK ADDRESS IS : " <<l3<<endl;

And when I print l3, the output is DEBUG: THE SOURCE.NETWORK ADDRESS IS: <none>当我打印 l3 时,output 是 DEBUG: THE SOURCE.NETWORK ADDRESS IS: <none>

What is wrong?怎么了? How can I access to the SENDER.network Address through the received packet?如何通过收到的数据包访问 SENDER.network Address?

Many thanks in advance.提前谢谢了。 I will be grateful我会很感激

Request tags are things that you add to a packet sending information down to lower OSI layers.请求标签是您添加到数据包中的东西,将信息向下发送到较低的 OSI 层。 On receiving end, protocol layers will annotate the packet with indicator tags so upper OSI layers can get that information if needed.在接收端,协议层将使用指示符标记对数据包进行注释,以便上层 OSI 层可以在需要时获取该信息。 You are adding an empty request tag to an incoming packet, so no wonder it is empty.您正在向传入数据包添加一个空的请求标记,所以它是空的也就不足为奇了。 What you need is get the L3AddressInd tag from the packet and extract the source address from there:您需要的是从数据包中获取L3AddressInd标记并从中提取源地址:

L3Address srcAddr = packet->getTag<L3AddressInd>()->getSrcAddress();

or或者

MacAddress srcAddr = packet->getTag<MacAddressInd>()->getSrcAddress();

depending on how the packet was received.取决于数据包是如何接收的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM