public override byte[] encodeControlInformation() { try { byte[] budtVersion = PacketUtil.encode(udtVersion); byte[] bsocketType = PacketUtil.encode(socketType); byte[] binitialSeqNo = PacketUtil.encode(initialSeqNo); byte[] bpacketSize = PacketUtil.encode(packetSize); byte[] bmaxFlowWndSize = PacketUtil.encode(maxFlowWndSize); byte[] bconnectionType = PacketUtil.encode(connectionType); byte[] bsocketID = PacketUtil.encode(socketID); byte[] bvalue = new byte[budtVersion.Length + bsocketType.Length + binitialSeqNo.Length + bpacketSize.Length + bmaxFlowWndSize.Length + bconnectionType.Length + bsocketID.Length]; Array.Copy(budtVersion, 0, bvalue, 0, budtVersion.Length); Array.Copy(bsocketType, 0, bvalue, budtVersion.Length, bsocketType.Length); Array.Copy(binitialSeqNo, 0, bvalue, budtVersion.Length + bsocketType.Length, binitialSeqNo.Length); Array.Copy(bpacketSize, 0, bvalue, budtVersion.Length + bsocketType.Length + binitialSeqNo.Length, bpacketSize.Length); Array.Copy(bmaxFlowWndSize, 0, bvalue, budtVersion.Length + bsocketType.Length + binitialSeqNo.Length + bpacketSize.Length, bmaxFlowWndSize.Length); Array.Copy(bconnectionType, 0, bvalue, budtVersion.Length + bsocketType.Length + binitialSeqNo.Length + bpacketSize.Length + bmaxFlowWndSize.Length, bconnectionType.Length); Array.Copy(bsocketID, 0, bvalue, budtVersion.Length + bsocketType.Length + binitialSeqNo.Length + bpacketSize.Length + bmaxFlowWndSize.Length + bconnectionType.Length, bsocketID.Length); return(bvalue); } catch (Exception e) { // can't happen Log.Write(this.ToString(), "can't happen", e); return(null); } }
/** * add an interval of lost packet numbers * @param firstSequenceNumber * @param lastSequenceNumber */ public void addLossInfo(long firstSequenceNumber, long lastSequenceNumber) { //check if we really need an interval if (lastSequenceNumber - firstSequenceNumber == 0) { addLossInfo(firstSequenceNumber); return; } //else add an interval byte[] enc1 = PacketUtil.encodeSetHighest(true, firstSequenceNumber); byte[] enc2 = PacketUtil.encodeSetHighest(false, lastSequenceNumber); try { for (int i = 0; i < enc1.Length; i++) { lossInfo.Add(enc1[i]); } for (int i = 0; i < enc2.Length; i++) { lossInfo.Add(enc2[i]); } } catch (Exception ignore) { Log.Write(this.ToString(), ignore); } }
public override byte[] encodeControlInformation() { try { byte[] backNumber = PacketUtil.encode(ackNumber); byte[] broundTripTime = PacketUtil.encode(roundTripTime); byte[] broundTripTimeVariance = PacketUtil.encode(roundTripTimeVariance); byte[] bbufferSize = PacketUtil.encode(bufferSize); byte[] bpktArrivalSpeed = PacketUtil.encode(pktArrivalSpeed); byte[] bestimatedLinkCapacity = PacketUtil.encode(estimatedLinkCapacity); byte[] bvalue = new byte[backNumber.Length + broundTripTime.Length + broundTripTimeVariance.Length + bbufferSize.Length + bpktArrivalSpeed.Length + bestimatedLinkCapacity.Length]; Array.Copy(backNumber, 0, bvalue, 0, backNumber.Length); Array.Copy(broundTripTime, 0, bvalue, backNumber.Length, broundTripTime.Length); Array.Copy(broundTripTimeVariance, 0, bvalue, backNumber.Length + broundTripTime.Length, broundTripTimeVariance.Length); Array.Copy(bbufferSize, 0, bvalue, backNumber.Length + broundTripTime.Length + broundTripTimeVariance.Length, bbufferSize.Length); Array.Copy(bpktArrivalSpeed, 0, bvalue, backNumber.Length + broundTripTime.Length + broundTripTimeVariance.Length + bbufferSize.Length, bpktArrivalSpeed.Length); Array.Copy(bestimatedLinkCapacity, 0, bvalue, backNumber.Length + broundTripTime.Length + broundTripTimeVariance.Length + bbufferSize.Length + bpktArrivalSpeed.Length, bestimatedLinkCapacity.Length); return(bvalue); } catch (Exception e) { // can't happen return(null); } }
/** * create the right type of control packet based on the packet data * @param packetData * @return */ public static ControlPacket createControlPacket(byte[] encodedData, int length) { ControlPacket packet = null; int pktType = PacketUtil.decodeType(encodedData, 0); long additionalInfo = PacketUtil.decode(encodedData, 4); long timeStamp = PacketUtil.decode(encodedData, 8); long destID = PacketUtil.decode(encodedData, 12); byte[] controlInformation = new byte[length - 16]; Array.Copy(encodedData, 16, controlInformation, 0, controlInformation.Length); //TYPE 0000:0 if ((int)ControlPacket.ControlPacketType.CONNECTION_HANDSHAKE == pktType) { packet = new ConnectionHandshake(controlInformation); } //TYPE 0001:1 else if ((int)ControlPacket.ControlPacketType.KEEP_ALIVE == pktType) { packet = new KeepAlive(); } //TYPE 0010:2 else if ((int)ControlPacket.ControlPacketType.ACK == pktType) { packet = new Acknowledgement(additionalInfo, controlInformation); } //TYPE 0011:3 else if ((int)ControlPacket.ControlPacketType.NAK == pktType) { packet = new NegativeAcknowledgement(controlInformation); } //TYPE 0101:5 else if ((int)ControlPacket.ControlPacketType.SHUTDOWN == pktType) { packet = new Shutdown(); } //TYPE 0110:6 else if ((int)ControlPacket.ControlPacketType.ACK2 == pktType) { packet = new Acknowledgment2(additionalInfo, controlInformation); } //TYPE 0111:7 else if ((int)ControlPacket.ControlPacketType.MESSAGE_DROP_REQUEST == pktType) { packet = new MessageDropRequest(controlInformation); } //TYPE 1111:8 else if ((int)ControlPacket.ControlPacketType.USER_DEFINED == pktType) { packet = new UserDefined(controlInformation); } if (packet != null) { packet.setTimeStamp(timeStamp); packet.setDestinationID(destID); } return(packet); }
/** * return the header according to specification p.5 * @return */ byte[] getHeader() { byte[] res = new byte[16]; Array.Copy(PacketUtil.encodeControlPacketType(controlPacketType), 0, res, 0, 4); Array.Copy(PacketUtil.encode(getAdditionalInfo()), 0, res, 4, 4); Array.Copy(PacketUtil.encode(timeStamp), 0, res, 8, 4); Array.Copy(PacketUtil.encode(destinationID), 0, res, 12, 4); return(res); }
private void decode(byte[] encodedData, int length) { packetSequenceNumber = PacketUtil.decode(encodedData, 0); messageNumber = PacketUtil.decode(encodedData, 4); timeStamp = PacketUtil.decode(encodedData, 8); destinationID = PacketUtil.decode(encodedData, 12); data = new byte[length - 16]; Array.Copy(encodedData, 16, data, 0, data.Length); }
/** * complete header+data packet for transmission */ public byte[] getEncoded() { //header.length is 16 byte[] result = new byte[16 + data.Length]; Array.Copy(PacketUtil.encode(packetSequenceNumber), 0, result, 0, 4); Array.Copy(PacketUtil.encode(messageNumber), 0, result, 4, 4); Array.Copy(PacketUtil.encode(timeStamp), 0, result, 8, 4); Array.Copy(PacketUtil.encode(destinationID), 0, result, 12, 4); Array.Copy(data, 0, result, 16, data.Length); return(result); }
void decode(byte[] data) { udtVersion = PacketUtil.decode(data, 0); socketType = PacketUtil.decode(data, 4); initialSeqNo = PacketUtil.decode(data, 8); packetSize = PacketUtil.decode(data, 12); maxFlowWndSize = PacketUtil.decode(data, 16); connectionType = PacketUtil.decode(data, 20); socketID = PacketUtil.decode(data, 24); if (data.Length > 28) { cookie = PacketUtil.decode(data, 28); } }
/** * add a single lost packet number * @param singleSequenceNumber */ public void addLossInfo(long singleSequenceNumber) { byte[] enc = PacketUtil.encodeSetHighest(false, singleSequenceNumber); try { for (int i = 0; i < enc.Length; i++) { lossInfo.Add(enc[i]); } } catch (Exception ignore) { Log.Write(this.ToString(), ignore); } }
void decodeControlInformation(byte[] data) { ackNumber = PacketUtil.decode(data, 0); if (data.Length > 4) { roundTripTime = PacketUtil.decode(data, 4); roundTripTimeVariance = PacketUtil.decode(data, 8); bufferSize = PacketUtil.decode(data, 12); } if (data.Length > 16) { pktArrivalSpeed = PacketUtil.decode(data, 16); estimatedLinkCapacity = PacketUtil.decode(data, 20); } }
public override byte[] encodeControlInformation() { try { byte[] bmsgFirstSeqNo = PacketUtil.encode(msgFirstSeqNo); byte[] bmsgLastSeqNo = PacketUtil.encode(msgLastSeqNo); byte[] bos = new byte[bmsgFirstSeqNo.Length + bmsgLastSeqNo.Length]; Array.Copy(bmsgFirstSeqNo, 0, bos, 0, bmsgFirstSeqNo.Length); Array.Copy(bmsgLastSeqNo, 0, bos, bmsgFirstSeqNo.Length, bmsgLastSeqNo.Length); return(bos); } catch (Exception e) { // can't happen return(null); } }
void decode(byte[] data) { msgFirstSeqNo = PacketUtil.decode(data, 0); msgLastSeqNo = PacketUtil.decode(data, 4); }