only add an ECN control message if ECN is supported

This commit is contained in:
Marten Seemann 2023-08-31 13:06:37 +07:00
parent 5dd6d91c11
commit b73a4de7ea
12 changed files with 90 additions and 29 deletions

View file

@ -17,13 +17,22 @@ var _ = Describe("Protocol", func() {
})
It("converts ECN bits from the IP header wire to the correct types", func() {
Expect(ECN(0)).To(Equal(ECNNon))
Expect(ECN(0b00000010)).To(Equal(ECT0))
Expect(ECN(0b00000001)).To(Equal(ECT1))
Expect(ECN(0b00000011)).To(Equal(ECNCE))
Expect(ParseECNHeaderBits(0)).To(Equal(ECNNon))
Expect(ParseECNHeaderBits(0b00000010)).To(Equal(ECT0))
Expect(ParseECNHeaderBits(0b00000001)).To(Equal(ECT1))
Expect(ParseECNHeaderBits(0b00000011)).To(Equal(ECNCE))
Expect(func() { ParseECNHeaderBits(0b1010101) }).To(Panic())
})
It("converts to IP header bits", func() {
for _, v := range [...]ECN{ECNNon, ECT0, ECT1, ECNCE} {
Expect(ParseECNHeaderBits(v.ToHeaderBits())).To(Equal(v))
}
Expect(func() { ECN(42).ToHeaderBits() }).To(Panic())
})
It("has a string representation for ECN", func() {
Expect(ECNUnsupported.String()).To(Equal("ECN unsupported"))
Expect(ECNNon.String()).To(Equal("Not-ECT"))
Expect(ECT0.String()).To(Equal("ECT(0)"))
Expect(ECT1.String()).To(Equal("ECT(1)"))