[英]Communicating Through Protocol Layers With INET Packet
我對接收方的接收數據包感到不安。 請幫我想辦法。 在 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());
}
在 RECEIVER 端,我嘗試獲取 SENDER 的網絡地址,如下所示:
auto l3 = packet->addTagIfAbsent<L3AddressReq>()->getSrcAddress();
EV_DEBUG << "THE SOURCE NETWORK ADDRESS IS : " <<l3<<endl;
當我打印 l3 時,output 是 DEBUG: THE SOURCE.NETWORK ADDRESS IS: <none>
怎么了? 如何通過收到的數據包訪問 SENDER.network Address?
提前謝謝了。 我會很感激
請求標簽是您添加到數據包中的東西,將信息向下發送到較低的 OSI 層。 在接收端,協議層將使用指示符標記對數據包進行注釋,以便上層 OSI 層可以在需要時獲取該信息。 您正在向傳入數據包添加一個空的請求標記,所以它是空的也就不足為奇了。 您需要的是從數據包中獲取L3AddressInd
標記並從中提取源地址:
L3Address srcAddr = packet->getTag<L3AddressInd>()->getSrcAddress();
或者
MacAddress srcAddr = packet->getTag<MacAddressInd>()->getSrcAddress();
取決於數據包是如何接收的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.