public void ValidateUadpPubSubConnectionNetworkMessageReceiveFromUnicast() { // Arrange var localhost = GetFirstNic(); Assert.IsNotNull(localhost, "localhost is null"); Assert.IsNotNull(localhost.Address, "localhost.Address is null"); PubSubConfigurationDataType subscriberConfiguration = UaPubSubConfigurationHelper.LoadConfiguration(SubscriberConfigurationFileName); Assert.IsNotNull(subscriberConfiguration, "subscriberConfiguration is null"); NetworkAddressUrlDataType subscriberAddress = new NetworkAddressUrlDataType(); subscriberAddress.Url = "opc.udp://" + localhost.Address.ToString() + ":4840"; subscriberConfiguration.Connections[0].Address = new ExtensionObject(subscriberAddress); UaPubSubApplication subscriberApplication = UaPubSubApplication.Create(subscriberConfiguration); Assert.IsNotNull(subscriberApplication, "subscriberApplication is null"); UadpPubSubConnection subscriberConnection = subscriberApplication.PubSubConnections[0] as UadpPubSubConnection; Assert.IsNotNull(subscriberConnection, "subscriberConnection is null"); subscriberConnection.UadpMessageReceived += DataReceived; PubSubConfigurationDataType publisherConfiguration = UaPubSubConfigurationHelper.LoadConfiguration(PublisherConfigurationFileName); Assert.IsNotNull(publisherConfiguration, "publisherConfiguration is null"); NetworkAddressUrlDataType publisherAddress = new NetworkAddressUrlDataType(); publisherAddress.Url = "opc.udp://" + localhost.Address.ToString() + ":4840"; publisherConfiguration.Connections[0].Address = new ExtensionObject(publisherAddress); UaPubSubApplication publisherApplication = UaPubSubApplication.Create(publisherConfiguration); Assert.IsNotNull(publisherApplication, "publisherApplication is null"); UadpPubSubConnection publisherConnection = publisherApplication.PubSubConnections[0] as UadpPubSubConnection; Assert.IsNotNull(publisherConnection, "publisherConnection is null"); //Act subscriberConnection.Start(); m_shutdownEvent = new ManualResetEvent(false); // physical network ip is mandatory on UdpClientUnicast as parameter UdpClient udpUnicastClient = new UdpClientUnicast(localhost.Address, 4840); Assert.IsNotNull(udpUnicastClient, "udpUnicastClient is null"); // first physical network ip = unicast address ip IPEndPoint remoteEndPoint = new IPEndPoint(localhost.Address, 4840); Assert.IsNotNull(remoteEndPoint, "remoteEndPoint is null"); m_sentBytes = PrepareData(publisherConnection); int sentBytesLen = udpUnicastClient.Send(m_sentBytes, m_sentBytes.Length, remoteEndPoint); Assert.AreEqual(sentBytesLen, m_sentBytes.Length, "Sent bytes size not equal to published bytes size!"); Thread.Sleep(EstimatedPublishingTime); // Assert if (!m_shutdownEvent.WaitOne(EstimatedPublishingTime)) { Assert.Fail("Subscriber unicast error ... published data not received"); } subscriberConnection.Stop(); }
public void ValidateUdpPubSubConnectionNetworkMessageReceiveFromUnicast() { // Arrange var localhost = GetFirstNic(); Assert.IsNotNull(localhost, "localhost is null"); Assert.IsNotNull(localhost.Address, "localhost.Address is null"); string configurationFile = Utils.GetAbsoluteFilePath(m_subscriberConfigurationFileName, true, true, false); PubSubConfigurationDataType subscriberConfiguration = UaPubSubConfigurationHelper.LoadConfiguration(configurationFile); Assert.IsNotNull(subscriberConfiguration, "subscriberConfiguration is null"); NetworkAddressUrlDataType subscriberAddress = new NetworkAddressUrlDataType(); subscriberAddress.Url = string.Format(kUdpUrlFormat, Utils.UriSchemeOpcUdp, localhost.Address.ToString()); subscriberConfiguration.Connections.First().Address = new ExtensionObject(subscriberAddress); UaPubSubApplication subscriberApplication = UaPubSubApplication.Create(subscriberConfiguration); Assert.IsNotNull(subscriberApplication, "subscriberApplication is null"); UdpPubSubConnection subscriberConnection = subscriberApplication.PubSubConnections[0] as UdpPubSubConnection; Assert.IsNotNull(subscriberConnection, "subscriberConnection is null"); subscriberApplication.RawDataReceived += RawDataReceived; configurationFile = Utils.GetAbsoluteFilePath(m_publisherConfigurationFileName, true, true, false); PubSubConfigurationDataType publisherConfiguration = UaPubSubConfigurationHelper.LoadConfiguration(configurationFile); Assert.IsNotNull(publisherConfiguration, "publisherConfiguration is null"); NetworkAddressUrlDataType publisherAddress = new NetworkAddressUrlDataType(); publisherAddress.Url = string.Format(kUdpUrlFormat, Utils.UriSchemeOpcUdp, localhost.Address.ToString()); publisherConfiguration.Connections.First().Address = new ExtensionObject(publisherAddress); UaPubSubApplication publisherApplication = UaPubSubApplication.Create(publisherConfiguration); Assert.IsNotNull(publisherApplication, "publisherApplication is null"); UdpPubSubConnection publisherConnection = publisherApplication.PubSubConnections.First() as UdpPubSubConnection; Assert.IsNotNull(publisherConnection, "publisherConnection is null"); //Act subscriberConnection.Start(); m_shutdownEvent = new ManualResetEvent(false); // physical network ip is mandatory on UdpClientUnicast as parameter UdpClient udpUnicastClient = new UdpClientUnicast(localhost.Address, kDiscoveryPortNo); Assert.IsNotNull(udpUnicastClient, "udpUnicastClient is null"); // first physical network ip = unicast address ip IPEndPoint remoteEndPoint = new IPEndPoint(localhost.Address, kDiscoveryPortNo); Assert.IsNotNull(remoteEndPoint, "remoteEndPoint is null"); m_sentBytes = PrepareData(publisherConnection); int sentBytesLen = udpUnicastClient.Send(m_sentBytes, m_sentBytes.Length, remoteEndPoint); Assert.AreEqual(sentBytesLen, m_sentBytes.Length, "Sent bytes size not equal to published bytes size!"); Thread.Sleep(kEstimatedPublishingTime); // Assert if (!m_shutdownEvent.WaitOne(kEstimatedPublishingTime)) { Assert.Fail("Subscriber unicast error ... published data not received"); } subscriberConnection.Stop(); }