简体   繁体   English

TCP 数据包丢弃 (ns3)

[英]TCP packet drop (ns3)

I am new to ns3 network simulator and wanted to know how to get the number of packet drops in a TCP connection.我是 ns3 网络模拟器的新手,想知道如何获取 TCP 连接中的丢包次数。 I know of the following command:我知道以下命令:

devices.Get (1)->TraceConnectWithoutContext ("PhyRxDrop", MakeBoundCallback (&RxDrop, stream));

But this is helpful only for a single TCP connection over a p2p link.但这仅对 p2p 链接上的单个 TCP 连接有用。 In my topology, there is a single p2p connection but 2 applications using TCP over that same p2p link and I would like to know individually for each TCP connection the number of dropped packets.在我的拓扑中,有一个 p2p 连接,但有 2 个应用程序在同一 p2p 链接上使用 TCP,我想分别了解每个 TCP 连接丢弃的数据包数量。 I have researched online quite a lot but was unable to find any resources.我在网上研究了很多,但找不到任何资源。 Kindly point to some resources or give the class name which I can use to detect TCP connection-specific packet losses.请指出一些资源或给出类名,我可以用它来检测特定于 TCP 连接的数据包丢失。

The above command as of now combines the packet losses for both the connections and outputs them to the stream because they are over the same p2p link.上面的命令现在结合了两个连接的数据包丢失并将它们输出到stream因为它们通过相同的 p2p 链接。

The usage of RxDrop tells me you're using referring to fourth.cc in the ns-3 tutorial . RxDrop的用法告诉我你在使用ns-3 教程第四个.cc。 Connecting to the PhyRxDrop TraceSource will result in the requested CallBack being invoked for each dropped packet.连接到 PhyRxDrop TraceSource 将导致为每个丢弃的数据包调用请求的回调。 ns-3 doesn't have a packet filter such that the CallBack would only be invoked for some packets. ns-3没有数据包过滤器,因此只会为某些数据包调用 CallBack。

However, you can determine which connection a packet corresponds to.但是,您可以确定数据包对应于哪个连接。 Simply strip the packet headers, and inspect the port numbers.只需剥离数据包头,并检查端口号。 Remember every connection is defined by a unique 4-tuple: (host IP, host port, destination IP, destination port).请记住,每个连接都由唯一的 4 元组定义:(主机 IP、主机端口、目标 IP、目标端口)。

static void
RxDrop(Ptr<const Packet> packet) {
    /* 
     * Need to copy packet since headers need to be removed
     * to be inspected. Alternatively, remove the headers,
     * and add them back.
     */
    Ptr<Packet> copy = packet->Copy();

    // Headers must be removed in the order they're present.
    PppHeader pppHeader;
    copy->RemoveHeader(pppHeader);
    Ipv4Header ipHeader;
    copy->RemoveHeader(ipHeader);
    TcpHeader tcpHeader;
    copy->RemoveHeader(tcpHeader);

    std::cout << "Source IP: ";
    ipHeader.GetSource().Print(std::cout);
    std::cout << std::endl;
    std::cout << "Source Port: " << tcpHeader.GetSourcePort() << std::endl;
    std::cout << "Destination IP: ";
    ipHeader.GetDestination().Print(std::cout);
    std::cout << std::endl;
    std::cout << "Destination Port: " << tcpHeader.GetDestinationPort() << std::endl;
}

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

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