ANSI C UA Server SDK  1.5.2.328
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules Pages
Troubleshooting

Using Wireshark to Analyze OPC UA Binary Protocol

This section describes how to use Wireshark for OPC UA protocol analyzing.

First you need to install Wireshark. The source code as well as binary installers for Windows and Mac OS X are available at http://www.wireshark.org/download.html.

How to Use Wireshark

To use Wireshark, follow these steps:

  • install Wireshark and follow the on-screen instructions
  • start Wireshark
  • configure the Protocol Preferences (add Ports you want to capture)
  • select your network card
  • configure the Capture Filter
  • start capturing

If you now start your OPC UA Server and connect with your Client, you will capture all service calls on the network. After performing the actions you want to capture, stop the Wireshark capturing. You can now set “Display Filters” to reduce the view and all the captured information.

Example

First set the OPC UA ports you want to capture by setting the Wireshark Preferences. Choose “Edit” → “Preferences” from the menu. Select “Protocols” from the tree and scroll down to OpcUa. Enter all the ports you need separated by a comma (see screenshot) and confirm with “Apply”.

wireshark1.png
Set Port Numbers

Click on “Capture Options” in the main window.

wireshark5.png
Capture Options

If necessary, select the network interface for capturing.

To reduce the amount of data collected, set a capture filter to “tcp” or a specific port, e.g. “tcp port 4841” (see screenshot), and start capturing by clicking on “Start”. Then perform the actions you want to capture.

wireshark2.png
Set Capture Filter

The result is displayed in the main window having three horizontal sections. The first upper section shows the individual telegram including timestamp and direction (source to destination). To show only OPC UA related packages, enter “opcua” at “Filter”. On selecting a certain message its content is expanded in the window below. In the example you can see a response sent from the server to the client that was returned on a call of the Browse Service. The content of all objects can be decoded. In addition, the lowest window pane shows the hexadecimal view for the selected item.

wireshark3.png
Decoded Browse Response

Wireshark Issue: Lots of Checksum Errors due to TCP Checksum Offloading

When using a newer network interface card, you may notice a lot of checksum errors while capturing (see the following screenshot) caused by TCP checksum offloading (see the Wireshark wiki for more information).

wireshark-tcpoffloading-error.png
TCP Offloading Error

To suppress these errors, you have to disable TCP checksum validation. Choose “Edit” → “Preferences” from the menu, select “Protocols” → “TCP” from the tree and uncheck the box at “Validate the TCP checksum if possible” (see screenshot).

wireshark-tcpoffloading-config.png
Disable TCP Checksum Validation

Using the Trace Functionality

The SDK comes with a built-in tracing mechanism. Enabling the trace and setting the trace level is possible when initializing the UA stack. The OpcUa_ProxyStubConfiguration structure passed into UaBase_Module_InitializeUaStack offers parameters that modify the trace:

OpcUa_ProxyStubConfiguration proxyStubConfiguration;
/* Enable the trace */
proxyStubConfiguration.bProxyStub_Trace_Enabled = OpcUa_True;
/* Set the trace level */
proxyStubConfiguration.uProxyStub_Trace_Level = OPCUA_TRACE_OUTPUT_LEVEL_ERROR;
UaBase_Module_InitializeUaStack(&g_hProxyStubPlatformLayer, &proxyStubConfiguration);

In your code you can also trace into the SDK trace by including <opcua_trace.h> and calling OpcUa_Trace, e.g.:

OpcUa_Trace(OPCUA_TRACE_LEVEL_INFO, "This is a sample trace on trace level INFO\n");

Visual Studio Projects: Configuration Required

When running the included Visual Studio examples for ANSI C SDK Demo Server and Oversampling Example in debug mode, the following window shows up:

missing_vs_settings.png
Missing Settings in Visual Studio

This is caused by a limitation of Visual Studio which prevents us from including all required settings in the Visual Studio solution. Unfortunately, it is necessary for you to perform two settings before you can use the included projects.

Set the Correct StartUp Project

By default, Visual Studio sets the first project in a solution as StartUp Project, which happens to be the wrong project in both of the included solutions. To work as expected, the following StartUp Projects have to be set:

  • uaserverc in the UA Demo Server Project
  • uaserver-oversampling in the UA Oversampling Server Project

This is exemplarily shown in the following screenshot for the Demo Server Project: Right-click on the project uaserverc and select Set as StartUp Project from the context menu.

set_startup_project.png
Set StartUp Project

Set Working Directory

By default, Visual Studio sets the directory containing the project file as working directory. This has to be changed to the output directory.

Right-click on the StartUp Project (see above) and select Properties from the context menu. Fill in the following value: $(TargetDir)

The servers should now start up properly in debug mode.