Пример #1
0
        /// <summary>
        /// Create a frame containing a DATA fragment
        /// </summary>
        /// <param name="messageSeqNumber">message sequence number</param>
        /// <param name="fragmentSeqNumber">fragment sequence number</param>
        /// <param name="isBroadcast">true if fragment is broadcasted</param>
        /// <param name="requireAck">true if an acknowledgment is required</param>
        /// <param name="pduSize">max size for the sublayer payload</param>
        /// <param name="reservedTail">max size for the sublayer tail</param>
        /// <param name="reservedHead">max size for the sublayer header</param>
        /// <param name="nbFragments">number of DATA fragments in the message</param>
        /// <param name="fragmentIndex">index of the DATA fragment</param>
        /// <param name="payloadData">payload</param>
        /// <param name="indexPayloadData">start index in the payload </param>
        /// <param name="nbBytes">number of bytes in the payload</param>
        /// <returns>the generated frame</returns>
        public static Frame CreateDataFrame(byte messageSeqNumber, byte fragmentSeqNumber, bool isBroadcast, bool requireAck,
                                            int pduSize, int reservedTail, int reservedHead, byte nbFragments, byte fragmentIndex, Frame payloadData, int indexPayloadData, int nbBytes)
        {
            if (pduSize < 2 + 2 + nbBytes)
            {
                throw new ArgumentException("pdu size is too small", "pduSize");
            }
            FragmentHeader header = new FragmentHeader(FragmentType.DATA, messageSeqNumber, requireAck, fragmentSeqNumber);

            Frame frame = Frame.GetFrame(reservedHead + reservedTail + 2 + 2 + nbBytes);

            frame.ReserveHeader(reservedHead);
            UInt16 serializedHdr = FragmentHeader.Encode(header);

            frame.AllocBack(4);
            frame.Write(0, serializedHdr);
            frame.Write(2, nbFragments);
            frame.Write(3, fragmentIndex);
            frame.AppendToBack(payloadData, indexPayloadData, nbBytes);
            return(frame);
        }
Пример #2
0
        /// <summary>
        /// Create a frame containing an ACK fragment
        /// </summary>
        /// <param name="messageSeqNumber">message sequence number</param>
        /// <param name="fragmentSeqNumber">fragment sequence number</param>
        /// <param name="pduSize">max size for the sublayer payload</param>
        /// <param name="reservedTail">max size for the sublayer tail</param>
        /// <param name="reservedHead">max size for the sublayer header</param>
        /// <param name="lastFragmentSeqNumberReceived">last fragment sequence number received by the receiver</param>
        /// <param name="fragmentMissingTable">table of missing fragments</param>
        /// <returns>the generated frame</returns>
        public static Frame CreateAckFragmentFrame(byte messageSeqNumber, byte fragmentSeqNumber, int pduSize, int reservedTail, int reservedHead, byte lastFragmentSeqNumberReceived, BitArray fragmentMissingTable)
        {
            byte[] byteArray = BitArray.ToByteArray(fragmentMissingTable);
            if (pduSize < 2 /* header */ + 1 /*last frag nb rec. */ + byteArray.Length + 1 /* size bit array */)
            {
                throw new ArgumentException("pdu size is too small", "pduSize");
            }
            FragmentHeader header = new FragmentHeader(FragmentType.ACK, messageSeqNumber, false, fragmentSeqNumber);

            Frame frame = Frame.GetFrame(reservedHead + reservedTail + 2 + 1 + byteArray.Length + 1);

            frame.ReserveHeader(reservedHead);
            UInt16 serializedHdr = FragmentHeader.Encode(header);

            frame.AllocBack(4);
            frame.Write(0, serializedHdr);
            frame.Write(2, lastFragmentSeqNumberReceived);
            frame.Write(3, (byte)fragmentMissingTable.Length);
            frame.AppendToBack(byteArray, 0, byteArray.Length);
            return(frame);
        }