示例#1
0
 def test(self, super_pack):
     inst = SCIONExtPacket()
     inst._l4_proto = 0x42
     super_pack.return_value = b"super"
     inst.ext_hdrs = []
     for idx, class_, len_, type_ in ((0, 0x1, 0x0, 0x0),
                                      (1, 0x2, 0x1, 0x11), (2, 0x3, 0x2,
                                                            0x1)):
         hdr = create_mock(["hdr_len", "EXT_CLASS", "EXT_TYPE", "pack"])
         hdr.EXT_CLASS = class_
         hdr.hdr_len.return_value = len_
         hdr.EXT_TYPE = type_
         hdr.pack.return_value = bytes(
             range(5 + len_ * ExtensionHeader.LINE_LEN))
         inst.ext_hdrs.append(hdr)
     expected = b"".join([
         b"super",
         bytes([0x2, 0x0, 0x0]),
         bytes(range(5)),
         bytes([0x3, 0x1, 0x11]),
         bytes(range(13)),
         bytes([0x42, 0x2, 0x1]),
         bytes(range(21)),
     ])
     # Call
     ntools.eq_(inst._inner_pack(), expected)
示例#2
0
 def test(self, super_values):
     inst = SCIONExtPacket()
     ext_hdrs = []
     for _ in range(3):
         ext_hdrs.append(MagicMock(spec_set=ExtensionHeader))
     # Call
     inst._inner_from_values("cmn hdr", "addr hdr", "path hdr", ext_hdrs)
     # Tests
     super_values.assert_called_once_with(inst, "cmn hdr", "addr hdr",
                                          "path hdr")
     ntools.eq_(inst.ext_hdrs, ext_hdrs)
示例#3
0
 def test_basic(self, inner_values, set_pld):
     inst = SCIONExtPacket.from_values("cmn hdr", "addr hdr", "path hdr",
                                       "ext hdrs")
     # Tests
     ntools.assert_is_instance(inst, SCIONExtPacket)
     inner_values.assert_called_once_with(inst, "cmn hdr", "addr hdr",
                                          "path hdr", "ext hdrs")
     set_pld.assert_called_once_with(inst, b"")
示例#4
0
 def test_unknown_e2e(self, super_val):
     inst = SCIONExtPacket()
     inst._unknown_exts = {ExtensionClass.END_TO_END: [1]}
     # Call
     ntools.assert_raises(SCMPBadEnd2End, inst.validate, "pkt len")
示例#5
0
 def test_unknown_hbh(self, super_val):
     inst = SCIONExtPacket()
     inst._unknown_exts = {ExtensionClass.HOP_BY_HOP: [1]}
     # Call
     ntools.assert_raises(SCMPBadHopByHop, inst.validate, "pkt len")
示例#6
0
 def test_no_unknown(self, super_val):
     inst = SCIONExtPacket()
     # Call
     ntools.ok_(inst.validate("pkt len"))
     # Tests
     super_val.assert_called_once_with(inst, "pkt len")
示例#7
0
 def test_with_exts(self):
     inst = SCIONExtPacket()
     inst.ext_hdrs = [create_mock(["EXT_CLASS"]), 0]
     # Call
     ntools.eq_(inst._get_next_hdr(), inst.ext_hdrs[0].EXT_CLASS)
示例#8
0
 def test_no_exts(self):
     inst = SCIONExtPacket()
     inst.ext_hdrs = []
     inst._l4_proto = 42
     # Call
     ntools.eq_(inst._get_next_hdr(), 42)
示例#9
0
 def test(self, super_offset):
     inst = SCIONExtPacket()
     inst.ext_hdrs = ["a", "bb", "cccc"]
     super_offset.return_value = 42
     # Call
     ntools.eq_(inst._get_offset_len(), 49)
示例#10
0
 def test_payload(self, inner_values, set_pld):
     inst = SCIONExtPacket.from_values("cmn hdr", "addr hdr", "path hdr",
                                       "ext hdrs", "payload")
     # Tests
     set_pld.assert_called_once_with(inst, "payload")