public void ValidateMqttLocalPubSubConnectionWithUadp( [Values((byte)1, (UInt16)1, (UInt32)1, (UInt64)1, "abc")] object publisherId) { RestartMosquitto("mosquitto"); //Arrange UInt16 writerGroupId = 1; string mqttLocalBrokerUrl = "mqtt://localhost:1883"; ITransportProtocolConfiguration mqttConfiguration = new MqttClientProtocolConfiguration(version: EnumMqttProtocolVersion.V500); UadpNetworkMessageContentMask uadpNetworkMessageContentMask = UadpNetworkMessageContentMask.PublisherId | UadpNetworkMessageContentMask.WriterGroupId | UadpNetworkMessageContentMask.PayloadHeader; UadpDataSetMessageContentMask uadpDataSetMessageContentMask = UadpDataSetMessageContentMask.None; DataSetFieldContentMask dataSetFieldContentMask = DataSetFieldContentMask.None; DataSetMetaDataType[] dataSetMetaDataArray = new DataSetMetaDataType[] { MessagesHelper.CreateDataSetMetaData1("DataSet1"), MessagesHelper.CreateDataSetMetaData2("DataSet2"), MessagesHelper.CreateDataSetMetaData3("DataSet3") }; PubSubConfigurationDataType publisherConfiguration = MessagesHelper.CreatePublisherConfiguration( Profiles.PubSubMqttUadpTransport, mqttLocalBrokerUrl, publisherId: publisherId, writerGroupId: writerGroupId, uadpNetworkMessageContentMask: uadpNetworkMessageContentMask, uadpDataSetMessageContentMask: uadpDataSetMessageContentMask, dataSetFieldContentMask: dataSetFieldContentMask, dataSetMetaDataArray: dataSetMetaDataArray, nameSpaceIndexForData: kNamespaceIndexAllTypes); Assert.IsNotNull(publisherConfiguration, "publisherConfiguration should not be null"); // Configure the mqtt publisher configuration with the MQTTbroker PubSubConnectionDataType mqttPublisherConnection = MessagesHelper.GetConnection(publisherConfiguration, publisherId); Assert.IsNotNull(mqttPublisherConnection, "The MQTT publisher connection is invalid."); mqttPublisherConnection.ConnectionProperties = mqttConfiguration.ConnectionProperties; Assert.IsNotNull(mqttPublisherConnection.ConnectionProperties, "The MQTT publisher connection properties are not valid."); // Create publisher application for multiple datasets UaPubSubApplication publisherApplication = UaPubSubApplication.Create(publisherConfiguration); MessagesHelper.LoadData(publisherApplication, kNamespaceIndexAllTypes); IUaPubSubConnection publisherConnection = publisherApplication.PubSubConnections.First(); Assert.IsNotNull(publisherConnection, "Publisher first connection should not be null"); Assert.IsNotNull(publisherConfiguration.Connections.First(), "publisherConfiguration first connection should not be null"); Assert.IsNotNull(publisherConfiguration.Connections.First().WriterGroups.First(), "publisherConfiguration first writer group of first connection should not be null"); var networkMessages = publisherConnection.CreateNetworkMessages(publisherConfiguration.Connections.First().WriterGroups.First(), new WriterGroupPublishState()); Assert.IsNotNull(networkMessages, "connection.CreateNetworkMessages shall not return null"); Assert.GreaterOrEqual(networkMessages.Count, 1, "connection.CreateNetworkMessages shall have at least one network message"); UadpNetworkMessage uaNetworkMessage = networkMessages[0] as UadpNetworkMessage; Assert.IsNotNull(uaNetworkMessage, "networkMessageEncode should not be null"); bool hasDataSetWriterId = (uadpNetworkMessageContentMask & UadpNetworkMessageContentMask.PayloadHeader) != 0; PubSubConfigurationDataType subscriberConfiguration = MessagesHelper.CreateSubscriberConfiguration( Profiles.PubSubMqttUadpTransport, mqttLocalBrokerUrl, publisherId: publisherId, writerGroupId: writerGroupId, setDataSetWriterId: hasDataSetWriterId, uadpNetworkMessageContentMask: uadpNetworkMessageContentMask, uadpDataSetMessageContentMask: uadpDataSetMessageContentMask, dataSetFieldContentMask: dataSetFieldContentMask, dataSetMetaDataArray: dataSetMetaDataArray, nameSpaceIndexForData: kNamespaceIndexAllTypes); Assert.IsNotNull(subscriberConfiguration, "subscriberConfiguration should not be null"); // Create subscriber application for multiple datasets UaPubSubApplication subscriberApplication = UaPubSubApplication.Create(subscriberConfiguration); Assert.IsNotNull(subscriberApplication, "subscriberApplication should not be null"); Assert.IsNotNull(subscriberApplication.PubSubConnections.First(), "subscriberConfiguration first connection should not be null"); // Configure the mqtt subscriber configuration with the MQTTbroker PubSubConnectionDataType mqttSubcriberConnection = MessagesHelper.GetConnection(subscriberConfiguration, publisherId); Assert.IsNotNull(mqttSubcriberConnection, "The MQTT subscriber connection is invalid."); mqttSubcriberConnection.ConnectionProperties = mqttConfiguration.ConnectionProperties; Assert.IsNotNull(mqttSubcriberConnection.ConnectionProperties, "The MQTT subscriber connection properties are not valid."); var dataSetReaders = subscriberApplication.PubSubConnections.First().GetOperationalDataSetReaders(); Assert.IsNotNull(dataSetReaders, "dataSetReaders should not be null"); IUaPubSubConnection subscriberConnection = subscriberApplication.PubSubConnections.First(); Assert.IsNotNull(subscriberConnection, "Subscriber first connection should not be null"); //Act // it will signal if the uadp message was received from local ip m_uaDataShutdownEvent = new ManualResetEvent(false); subscriberApplication.DataReceived += UaPubSubApplication_DataReceived; subscriberConnection.Start(); publisherConnection.Start(); //Assert if (!m_uaDataShutdownEvent.WaitOne(kEstimatedPublishingTime)) { Assert.Fail("The UADP message was not received"); } subscriberConnection.Stop(); publisherConnection.Stop(); }
/// <summary> /// Set network message content mask /// </summary> /// <param name="networkMessageContentMask"></param> public void SetNetworkMessageContentMask(UadpNetworkMessageContentMask networkMessageContentMask) { NetworkMessageContentMask = networkMessageContentMask; SetFlags(); }