/// <summary> /// Encode NetWork Detection Request /// </summary> /// <param name="sendBuffer">The buffer list to contain the encoded PDU.</param> /// <param name="networkDetectionRequest">The Network Detect Request want to be encoded</param> internal static void EncodeNetworkDetectionRequest(List <byte> sendBuffer, NETWORK_DETECTION_REQUEST networkDetectionRequest, bool isSubHeader = false) { if (!isSubHeader) { EncodeStructure(sendBuffer, networkDetectionRequest.headerLength); EncodeStructure(sendBuffer, (byte)networkDetectionRequest.headerTypeId); } EncodeStructure(sendBuffer, networkDetectionRequest.sequenceNumber); EncodeStructure(sendBuffer, (ushort)networkDetectionRequest.requestType); AUTO_DETECT_REQUEST_TYPE requestType = networkDetectionRequest.requestType; if (requestType == AUTO_DETECT_REQUEST_TYPE.RDP_RTT_REQUEST_IN_CONNECTTIME || requestType == AUTO_DETECT_REQUEST_TYPE.RDP_RTT_REQUEST_AFTER_CONNECTTIME) { //RDP_RTT_REQUEST } else if (requestType == AUTO_DETECT_REQUEST_TYPE.RDP_BW_START_IN_CONNECTTIME || requestType == AUTO_DETECT_REQUEST_TYPE.RDP_BW_START_AFTER_CONNECTTIME_OR_RELIABLEUDP || requestType == AUTO_DETECT_REQUEST_TYPE.RDP_BW_START_AFTER_CONNECTTIME_OR_LOSSYUDP) { //RDP_BW_START } else if (requestType == AUTO_DETECT_REQUEST_TYPE.RDP_BW_PAYLOAD) { //RDP_BW_PAYLOAD RDP_BW_PAYLOAD bwPayload = (RDP_BW_PAYLOAD)networkDetectionRequest; EncodeStructure(sendBuffer, bwPayload.payloadLength); EncodeBytes(sendBuffer, bwPayload.payload); } else if (requestType == AUTO_DETECT_REQUEST_TYPE.RDP_BW_STOP_IN_CONNECTTIME || requestType == AUTO_DETECT_REQUEST_TYPE.RDP_BW_STOP_AFTER_CONNECTTIME_OR_RELIABLEUDP || requestType == AUTO_DETECT_REQUEST_TYPE.RDP_BW_STOP_AFTER_CONNECTTIME_OR_LOSSYUDP) { //RDP_BW_STOP if (requestType == AUTO_DETECT_REQUEST_TYPE.RDP_BW_STOP_IN_CONNECTTIME) { RDP_BW_STOP bwStop = (RDP_BW_STOP)networkDetectionRequest; EncodeStructure(sendBuffer, bwStop.payloadLength); EncodeBytes(sendBuffer, bwStop.payload); } } else if (requestType == AUTO_DETECT_REQUEST_TYPE.RDP_NETCHAR_RESULT_BANDWIDTH_AVERAGERTT || requestType == AUTO_DETECT_REQUEST_TYPE.RDP_NETCHAR_RESULT_BASERTT_AVERAGERTT || requestType == AUTO_DETECT_REQUEST_TYPE.RDP_NETCHAR_RESULT_BASERTT_BANDWIDTH_AVERAGERTT) { //RDP_NETCHAR_RESULT RDP_NETCHAR_RESULT netCharResult = (RDP_NETCHAR_RESULT)networkDetectionRequest; if (requestType == AUTO_DETECT_REQUEST_TYPE.RDP_NETCHAR_RESULT_BANDWIDTH_AVERAGERTT) { EncodeStructure(sendBuffer, netCharResult.bandwidth); EncodeStructure(sendBuffer, netCharResult.averageRTT); } else if (requestType == AUTO_DETECT_REQUEST_TYPE.RDP_NETCHAR_RESULT_BASERTT_AVERAGERTT) { EncodeStructure(sendBuffer, netCharResult.baseRTT); EncodeStructure(sendBuffer, netCharResult.averageRTT); } else if (requestType == AUTO_DETECT_REQUEST_TYPE.RDP_NETCHAR_RESULT_BASERTT_BANDWIDTH_AVERAGERTT) { EncodeStructure(sendBuffer, netCharResult.baseRTT); EncodeStructure(sendBuffer, netCharResult.bandwidth); EncodeStructure(sendBuffer, netCharResult.averageRTT); } } }
/// <summary> /// Encode a RDP_BW_STOP structure for subheader, don't encode the first two field /// </summary> /// <param name="bwStop"></param> /// <returns></returns> public static byte[] EncodeRdpBWStop(RDP_BW_STOP bwStop) { List <byte> bufferList = new List <byte>(); bufferList.AddRange(ToBytes(bwStop.sequenceNumber)); bufferList.AddRange(ToBytes((ushort)bwStop.requestType)); // payloadLength and payload Must not be present when the structure is in SubHeaderData of RDP_TUNNEL_SUBHEADER return(bufferList.ToArray()); }
/// <summary> /// Parse RDP_BW_STOP structure from RDPEMT subheader /// </summary> /// <param name="data">Data of subheader, not include first two bytes of Parse RDP_BW_STOP</param> /// <returns></returns> public static RDP_BW_STOP ParseRdpBWStop(byte[] data) { RDP_BW_STOP bwStop = new RDP_BW_STOP(); bwStop.sequenceNumber = ParseUInt16(data, 0); bwStop.requestType = (AUTO_DETECT_REQUEST_TYPE)ParseUInt16(data, 2); // payloadLength and payload Must not be present when the structure is in SubHeaderData of RDP_TUNNEL_SUBHEADER return(bwStop); }
/// <summary> /// Send a Tunnel Data PDU with RDP_BW_STOP in its subheader /// </summary> /// <param name="requestedProtocol"></param> /// <param name="sequenceNumber"></param> private void SendTunnelDataPdu_BWStop(Multitransport_Protocol_value requestedProtocol, ushort sequenceNumber) { AUTO_DETECT_REQUEST_TYPE requestType = AUTO_DETECT_REQUEST_TYPE.RDP_BW_STOP_AFTER_CONNECTTIME_OR_RELIABLEUDP; RdpemtServer rdpemtServer = rdpemtServerR; if (requestedProtocol == Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECL) { requestType = AUTO_DETECT_REQUEST_TYPE.RDP_BW_STOP_AFTER_CONNECTTIME_OR_LOSSYUDP; rdpemtServer = rdpemtServerL; } RDP_BW_STOP bwStop = RdpbcgrUtility.GenerateBandwidthMeasureStop(requestType, sequenceNumber); byte[] reqData = rdpbcgrServer.EncodeNetworkDetectionRequest(bwStop, true); List <byte[]> subHdDataList = new List <byte[]>(); subHdDataList.Add(reqData); RDP_TUNNEL_DATA tunnelData = rdpemtServer.CreateTunnelDataPdu(null, subHdDataList); rdpemtServer.SendRdpemtPacket(tunnelData); }