use retransmissions as TLP packets

This commit is contained in:
Marten Seemann 2018-08-07 18:34:31 +07:00
parent bd23e1651d
commit defafec71e
6 changed files with 88 additions and 115 deletions

View file

@ -810,65 +810,29 @@ var _ = Describe("Session", func() {
Expect(err).ToNot(HaveOccurred())
})
It("sends a TLP probe packet", func() {
It("sends a probe packet", func() {
f := &wire.MaxDataFrame{ByteOffset: 1337}
sph := mockackhandler.NewMockSentPacketHandler(mockCtrl)
sph.EXPECT().TimeUntilSend()
sph.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2).AnyTimes()
sph.EXPECT().SendMode().Return(ackhandler.SendTLP)
sph.EXPECT().ShouldSendNumPackets().Return(1)
sph.EXPECT().SentPacket(gomock.Any()).Do(func(p *ackhandler.Packet) {
Expect(p.Frames).To(HaveLen(1))
Expect(p.Frames[0]).To(BeAssignableToTypeOf(&wire.PingFrame{}))
sph.EXPECT().DequeueProbePacket().Return(&ackhandler.Packet{
PacketNumber: 0x42,
Frames: []wire.Frame{f},
}, nil)
sph.EXPECT().GetStopWaitingFrame(true).Return(&wire.StopWaitingFrame{})
sph.EXPECT().SentPacketsAsRetransmission(gomock.Any(), protocol.PacketNumber(0x42)).Do(func(packets []*ackhandler.Packet, _ protocol.PacketNumber) {
Expect(packets).To(HaveLen(1))
p := packets[0]
Expect(p.Frames).To(HaveLen(2))
Expect(p.Frames[1]).To(Equal(f))
})
sess.sentPacketHandler = sph
err := sess.sendPackets()
Expect(err).ToNot(HaveOccurred())
})
It("sends an RTO probe packets", func() {
sph := mockackhandler.NewMockSentPacketHandler(mockCtrl)
sph.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2).AnyTimes()
sph.EXPECT().TimeUntilSend()
sph.EXPECT().DequeuePacketForRetransmission().Return(&ackhandler.Packet{
PacketNumber: 10,
})
sph.EXPECT().DequeuePacketForRetransmission().Return(&ackhandler.Packet{
PacketNumber: 11,
})
sph.EXPECT().SendMode().Return(ackhandler.SendRTO).Times(2)
sph.EXPECT().ShouldSendNumPackets().Return(2)
sph.EXPECT().GetStopWaitingFrame(gomock.Any()).Return(&wire.StopWaitingFrame{}).Times(2)
gomock.InOrder(
sph.EXPECT().SentPacketsAsRetransmission(gomock.Any(), protocol.PacketNumber(10)),
sph.EXPECT().SentPacketsAsRetransmission(gomock.Any(), protocol.PacketNumber(11)),
)
sess.sentPacketHandler = sph
err := sess.sendPackets()
Expect(err).ToNot(HaveOccurred())
})
It("sends RTO probe packets with new data, if no retransmission is available", func() {
sph := mockackhandler.NewMockSentPacketHandler(mockCtrl)
sph.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2).AnyTimes()
sph.EXPECT().TimeUntilSend()
sph.EXPECT().DequeuePacketForRetransmission().Return(&ackhandler.Packet{
PacketNumber: 10,
})
sph.EXPECT().DequeuePacketForRetransmission()
sph.EXPECT().SendMode().Return(ackhandler.SendRTO).Times(2)
sph.EXPECT().ShouldSendNumPackets().Return(2)
sph.EXPECT().GetStopWaitingFrame(gomock.Any()).Return(&wire.StopWaitingFrame{})
gomock.InOrder(
sph.EXPECT().SentPacketsAsRetransmission(gomock.Any(), protocol.PacketNumber(10)),
sph.EXPECT().SentPacket(gomock.Any()).Do(func(p *ackhandler.Packet) {
Expect(p.Frames).To(HaveLen(1))
Expect(p.Frames[0]).To(BeAssignableToTypeOf(&wire.PingFrame{}))
}),
)
sess.sentPacketHandler = sph
err := sess.sendPackets()
Expect(err).ToNot(HaveOccurred())
})
It("doesn't send when the SentPacketHandler doesn't allow it", func() {
sph := mockackhandler.NewMockSentPacketHandler(mockCtrl)
sph.EXPECT().SendMode().Return(ackhandler.SendNone)