使用 setTrafficClass 和 WireShark 进行 DSCP 标记的问题

Issue with DSCP marking using setTrafficClass and WireShark(使用 setTrafficClass 和 WireShark 进行 DSCP 标记的问题)

本文介绍了使用 setTrafficClass 和 WireShark 进行 DSCP 标记的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 setTrafficClass 标记 DSCP 值.我在两台不同的机器上设置了服务器和客户端,我可以打印 DSCP 的值,但我在 WireShark 中看不到它.我在网上浏览了一些帖子,但没有任何帮助.我正在使用 Windows 7 专业版.任何帮助,将不胜感激.谢谢!

I am trying to mark DSCP values using setTrafficClass. I have server and client set up on two different machines and I am able to print value of DSCP but I can not see it in WireShark. I have gone through some posts online but nothing helped. I am using Windows 7 professional. Any help would be appreciated. Thank you!

我正在进行更多测试,看看如何做到这一点.这是客户端代码:

I am more testing to see how this can be done. Here is the client code:

试试{

        Socket socket = new Socket(addr, 2345);
        socket.setTrafficClass(10);

        PrintWriter out = new PrintWriter( socket.getOutputStream(), true);

        out.println("Current DSCP value: " + socket.getTrafficClass());
        out.close();
        socket.close();

    }

    catch (Exception e) {
        e.printStackTrace();
    }

}

服务器:

    try {
        ServerSocket serverSocket = new ServerSocket(1234);
        Socket clientSocket = serverSocket.accept();

        BufferedReader in = new BufferedReader(new InputStreamReader(
                clientSocket.getInputStream()));

        String fromClient = in.readLine();
        System.out.println(fromClient);

        in.close();
        clientSocket.close();
        serverSocket.close();

    } catch (Exception e) {
        e.printStackTrace();
    }

}

在服务器端的控制台中:当前DSCP值:10

In console on server side: Current DSCP value: 10

我的服务器代码和客户端位于不同的机器上.

My server code and client are on separate machines.

在wireshark中我看到了:

In wireshark I see:

区分服务字段:0x00(DSCP 0x00:默认;ECN:0x00:非 ECT(不支持 ECN 传输))

Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport))

我希望看到 wireshark 的变化,我只看到默认值为零.

I expect to see changes in wireshark and I only see default value zero.

推荐答案

上次我在 Java 中使用 DSCP 值时,必须将 java.net.preferIPv4Stack 系统属性设置为 true 由于 JVM 中的错误.尽管似乎在 java.net.Socket API 中工作,但不会在底层套接字上设置 DSCP 值.

Last time I worked with DSCP values in Java one had to set the java.net.preferIPv4Stack system property to true due to a bug in the JVM. Othwerwise DSCP values would not be set on the underlying socket despite appearing to work in the java.net.Socket API.

另外你可能需要在连接socket之前调用setTrafficClass,在某些平台上连接后可能无法工作.

Also you may have to call setTrafficClass before connecting the socket, it may not work after connection on some platforms.

java -Djava.net.preferIPv4Stack=true ...

这篇关于使用 setTrafficClass 和 WireShark 进行 DSCP 标记的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:使用 setTrafficClass 和 WireShark 进行 DSCP 标记的问题

基础教程推荐