Example #1
0
 def test_pcb_type(self, raw, pcb_path, super_parse):
     data = create_mock(["pop", "__len__"])
     data.pop.side_effect = PathTransType.PCB_PATH, b"pcb_path"
     data.__len__.return_value = 9
     raw.return_value = data
     inst = PathTransportExt()
     pcb_path.return_value = "parsed_pcb_path"
     # Call
     inst._parse("data")
     # Tests
     ntools.eq_(inst.path, "parsed_pcb_path")
     pcb_path.assert_called_once_with(b"pcb_path")
Example #2
0
 def test_of_type(self, raw, super_parse, of_path):
     data = create_mock(["pop", "__len__"])
     data.pop.side_effect = PathTransType.OF_PATH, b"of_path"
     data.__len__.return_value = 8
     raw.return_value = data
     inst = PathTransportExt()
     of_path.return_value = "parsed_of_path"
     # Call
     inst._parse("data")
     # Tests
     raw.assert_called_once_with("data", inst.NAME, inst.MIN_LEN, min_=True)
     super_parse.assert_called_once_with(inst, data)
     ntools.eq_(inst.path_type, PathTransType.OF_PATH)
     ntools.eq_(inst.path, of_path.return_value)
     of_path.assert_called_once_with(b"of_path")
Example #3
0
 def test_wrong_type(self, raw, super_parse):
     data = create_mock(["pop", "__len__"])
     data.pop.return_value = 3456
     data.__len__.return_value = 1
     raw.return_value = data
     inst = PathTransportExt()
     # Call
     ntools.assert_raises(SCIONParseError, inst._parse, "data")
Example #4
0
 def _check(self, plen, expected, init_size):
     path = create_mock(["pack"])
     path.pack.return_value = bytes(range(plen))
     # Call
     inst = PathTransportExt.from_values("path_type", path)
     # Tests
     ntools.eq_(inst.path_type, "path_type")
     ntools.eq_(inst.path, path)
     init_size.assert_called_once_with(inst, expected)
Example #5
0
 def test(self, calc_padding, check_len):
     inst = PathTransportExt()
     inst._hdr_len = 1
     inst.path_type = 1
     inst.path = create_mock(["pack"])
     inst.path.pack.return_value = b"packed_path"
     calc_padding.return_value = 1
     expected = b"\x01packed_path\x00"
     # Call
     inst.pack()
     # Tests
     calc_padding.assert_called_once_with(11 - 4, inst.LINE_LEN)
     check_len.assert_called_once_with(inst, expected)
Example #6
0
    def _create_extensions(self):
        # Determine number of border routers on path in single direction
        fwd_path = self.path_meta.fwd_path()
        routers_no = (fwd_path.get_as_hops() - 1) * 2
        # Number of router for round-trip (return path is symmetric)
        routers_no *= 2

        # Extensions
        exts = []
        # Create PathTransportExtension
        # One with data-plane path.
        of_path = PathTransOFPath.from_values(self.addr, self.dst, fwd_path)
        exts.append(
            PathTransportExt.from_values(PathTransType.OF_PATH, of_path))
        return exts