Beispiel #1
0
 def _setup(self, src_type):
     inst = SCIONAddrHdr()
     inst.calc_lens = create_mock()
     inst.update = create_mock()
     data = create_mock(["get", "pop"])
     data.get.side_effect = "src addr", "dst addr"
     data.pop.side_effect = None, None
     src = create_mock(["__len__", "host"])
     src.__len__.return_value = 3
     src.host = create_mock(["TYPE"])
     src.host.TYPE = src_type
     return inst, data, src, "dst"
Beispiel #2
0
 def _setup(self, src_type, haddr, saddr):
     inst = SCIONAddrHdr()
     inst.calc_lens = create_mock()
     inst.update = create_mock()
     data = create_mock_full({
         "pop()...": ("1-1", "2-2", "dst host", "src host"),
     })
     src_host = create_mock_full({"TYPE": src_type})
     src = create_mock_full({"host": src_host})
     haddr.side_effect = (
         create_mock_full({"LEN": 12}, return_value="dst haddr"),
         create_mock_full({"LEN": 34}, return_value="src haddr"),
     )
     saddr.side_effect = "dst", src
     return inst, data, src, "dst"
Beispiel #3
0
 def _check(self, type_lens, exp_total, exp_pad, calc_len, calc_padding):
     calc_len.side_effect = type_lens
     calc_padding.return_value = exp_pad
     # Call
     results = SCIONAddrHdr.calc_lens(1, 2)
     # Tests
     assert_these_calls(calc_len, [call(1), call(2)])
     calc_padding.assert_called_once_with(sum(type_lens),
                                          SCIONAddrHdr.BLK_SIZE)
     ntools.eq_(results, (exp_total, exp_pad))
Beispiel #4
0
 def test(self):
     inst = SCIONAddrHdr()
     inst.update = create_mock()
     inst.src = "src"
     inst.dst = "dst"
     # Call
     inst.reverse()
     # Tests
     ntools.eq_(inst.src, "dst")
     ntools.eq_(inst.dst, "src")
     inst.update.assert_called_once_with()
Beispiel #5
0
 def test(self):
     inst = SCIONAddrHdr()
     inst.update = create_mock()
     inst.src = create_mock(["pack"])
     inst.src.pack.return_value = b"src saddr"
     inst.dst = create_mock(["pack"])
     inst.dst.pack.return_value = b"dst saddr"
     inst._total_len = 24
     inst._pad_len = 6
     expected = b"src saddr" b"dst saddr"
     expected += bytes(inst._pad_len)
     # Call
     ntools.eq_(inst.pack(), expected)
     # Tests
     inst.update.assert_called_once_with()
Beispiel #6
0
 def test(self):
     inst = SCIONAddrHdr()
     inst.calc_lens = create_mock_full(return_value=(1, 3))
     inst.src = create_mock_full({"host": create_mock(["TYPE"])})
     inst.dst = create_mock_full({"host": create_mock(["TYPE"])})
     # Call
     inst.update()
     # Tests
     inst.calc_lens.assert_called_once_with(inst.dst.host.TYPE,
                                            inst.src.host.TYPE)
     ntools.eq_(inst._total_len, 1)
     ntools.eq_(inst._pad_len, 3)
Beispiel #7
0
 def test(self):
     inst = SCIONAddrHdr()
     inst.update = create_mock()
     dst_ia = create_mock_full({"pack()": b"dsIA"})
     dst_host = create_mock_full({"pack()": b"dst H"})
     inst.dst = create_mock_full({"isd_as": dst_ia, "host": dst_host})
     src_ia = create_mock_full({"pack()": b"srIA"})
     src_host = create_mock_full({"pack()": b"src H"})
     inst.src = create_mock_full({"isd_as": src_ia, "host": src_host})
     inst._total_len = 24
     inst._pad_len = 6
     expected = b"dsIA" b"srIA" b"dst H" b"src H"
     expected += bytes(inst._pad_len)
     # Call
     ntools.eq_(inst.pack(), expected)
     # Tests
     inst.update.assert_called_once_with()
Beispiel #8
0
 def test(self):
     inst = SCIONAddrHdr()
     inst._total_len = 42
     # Call
     ntools.eq_(len(inst), 42)