コード例 #1
0
ファイル: scion_test.py プロジェクト: nerd100/scion
 def test(self):
     inst = SCIONBasePacket()
     cmn_hdr = MagicMock(spec_set=SCIONCommonHdr)
     addr_hdr = MagicMock(spec_set=SCIONAddrHdr)
     path_hdr = MagicMock(spec_set=SCIONPath)
     # Call
     inst._inner_from_values(cmn_hdr, addr_hdr, path_hdr)
コード例 #2
0
ファイル: scion_test.py プロジェクト: nerd100/scion
 def _setup(self, data_offset=10, hdr_len=20):
     inst = SCIONBasePacket()
     inst.cmn_hdr = create_mock(["get_of_idxs", "hdr_len"])
     inst.cmn_hdr.get_of_idxs.return_value = "iof", "hof"
     inst.cmn_hdr.hdr_len = hdr_len
     data = create_mock(["__len__", "get", "offset", "pop"])
     data.__len__.return_value = 40 - data_offset
     data.offset.return_value = data_offset
     return inst, data
コード例 #3
0
ファイル: scion_test.py プロジェクト: nerd100/scion
 def test(self):
     inst = SCIONBasePacket()
     cmn_hdr = create_mock([
         "__len__",
         "src_addr_type",
         "dst_addr_type",
         "addrs_len",
         "hdr_len",
         "total_len",
         "set_of_idxs",
         "next_hdr",
         "update",
     ])
     cmn_hdr.__len__.return_value = 2
     addrs = create_mock(["__len__", "src_type", "dst_type"])
     addrs.__len__.return_value = 4
     path = create_mock(["__len__", "get_of_idxs"])
     path.__len__.return_value = 8
     path.get_of_idxs.return_value = 3, 7
     inst.cmn_hdr = cmn_hdr
     inst.addrs = addrs
     inst.path = path
     inst._get_offset_len = create_mock()
     inst._get_offset_len.return_value = 42
     inst._get_next_hdr = create_mock()
     # Call
     inst._update_cmn_hdr()
     # Tests
     ntools.eq_(cmn_hdr.src_addr_type, addrs.src_type.return_value)
     ntools.eq_(cmn_hdr.dst_addr_type, addrs.dst_type.return_value)
     ntools.eq_(cmn_hdr.addrs_len, 4)
     ntools.eq_(cmn_hdr.hdr_len, 2 + 4 + 8)
     ntools.eq_(cmn_hdr.total_len, 14 + 42)
     cmn_hdr.set_of_idxs.assert_called_once_with(3, 7)
     ntools.eq_(cmn_hdr.next_hdr, inst._get_next_hdr.return_value)
コード例 #4
0
ファイル: scion_test.py プロジェクト: sezergueler/scion
 def test(self):
     inst = SCIONBasePacket()
     cmn_hdr = create_mock([
         "__len__", "src_addr_type", "dst_addr_type", "addrs_len", "hdr_len",
         "hdr_len_bytes", "bytes_to_hdr_len", "total_len", "set_of_idxs", "next_hdr", "update",
     ])
     cmn_hdr.__len__.return_value = SCIONCommonHdr.LEN
     cmn_hdr.bytes_to_hdr_len = lambda x: x//8
     cmn_hdr.hdr_len_bytes.return_value = 32
     addrs = create_mock(["__len__", "src_type", "dst_type"])
     addrs.__len__.return_value = 16
     path = create_mock(["__len__", "get_of_idxs"])
     path.__len__.return_value = 8
     path.get_of_idxs.return_value = 3, 7
     inst.cmn_hdr = cmn_hdr
     inst.addrs = addrs
     inst.path = path
     inst._get_offset_len = create_mock()
     inst._get_offset_len.return_value = 42
     inst._get_next_hdr = create_mock()
     # Call
     inst._update_cmn_hdr()
     # Tests
     ntools.eq_(cmn_hdr.src_addr_type, addrs.src_type.return_value)
     ntools.eq_(cmn_hdr.dst_addr_type, addrs.dst_type.return_value)
     ntools.eq_(cmn_hdr.addrs_len, 16)
     ntools.eq_(cmn_hdr.hdr_len, (8 + 16 + 8)//8)
     ntools.eq_(cmn_hdr.total_len, 32 + 42)
     cmn_hdr.set_of_idxs.assert_called_once_with(3, 7)
     ntools.eq_(cmn_hdr.next_hdr, inst._get_next_hdr.return_value)
コード例 #5
0
ファイル: scion_test.py プロジェクト: nerd100/scion
 def test(self, addr_hdr):
     inst = SCIONBasePacket()
     cmn_hdr = create_mock(["addrs_len", "dst_addr_type", "src_addr_type"])
     inst.cmn_hdr = cmn_hdr
     data = create_mock(["get", "pop"])
     # Call
     inst._parse_addrs(data)
     # Tests
     addr_hdr.assert_called_once_with(
         (cmn_hdr.dst_addr_type, cmn_hdr.src_addr_type,
          data.get.return_value))
     ntools.eq_(inst.addrs, addr_hdr.return_value)
     data.pop.assert_called_once_with(addr_hdr.__len__.return_value)
コード例 #6
0
ファイル: scion_test.py プロジェクト: nerd100/scion
 def test(self):
     inst = SCIONBasePacket()
     inst.path = "path"
     inst.cmn_hdr = create_mock(["validate"])
     inst.addrs = create_mock(["validate"])
     inst._validate_of_idxes = create_mock()
     inst._payload = PayloadRaw()
     # Call
     inst.validate("pkt len")
     # Tests
     inst.cmn_hdr.validate.assert_called_once_with("pkt len", 4)
     inst.addrs.validate.assert_called_once_with()
     inst._validate_of_idxes.assert_called_once_with()
コード例 #7
0
ファイル: scion_test.py プロジェクト: nerd100/scion
 def test(self, ext_fv, pld_fp, hdr_fv):
     inst = SCIONBasePacket()
     inst.addrs = create_mock(["dst", "src"])
     scmp_ext = create_mock(["EXT_TYPE"])
     scmp_ext.EXT_TYPE = ExtHopByHopType.SCMP
     inst.ext_hdrs = [scmp_ext, "ext1", "ext2", "ext3", "ext4"]
     inst.set_payload = create_mock()
     # Call
     inst.convert_to_scmp_error("addr",
                                "class",
                                "type",
                                "pkt",
                                "arg1",
                                "arg2",
                                hopbyhop="hbh",
                                kwarg1="kwval1")
     # Tests
     ext_fv.assert_called_once_with(hopbyhop="hbh")
     ntools.eq_(inst.ext_hdrs,
                [ext_fv.return_value, "ext1", "ext2", "ext3"])
     pld_fp.assert_called_once_with("class",
                                    "type",
                                    "pkt",
                                    "arg1",
                                    "arg2",
                                    kwarg1="kwval1")
     hdr_fv.assert_called_once_with("addr", inst.addrs.dst, "class", "type")
     ntools.eq_(inst.l4_hdr, hdr_fv.return_value)
     inst.set_payload.assert_called_once_with(pld_fp.return_value)
コード例 #8
0
ファイル: scion_test.py プロジェクト: nerd100/scion
 def test(self, inner_values, pld_raw, set_pld, update):
     inst = SCIONBasePacket.from_values("cmn hdr", "addr hdr", "path hdr")
     # Tests
     ntools.assert_is_instance(inst, SCIONBasePacket)
     inner_values.assert_called_once_with(inst, "cmn hdr", "addr hdr",
                                          "path hdr")
     pld_raw.assert_called_once_with()
     set_pld.assert_called_once_with(inst, pld_raw.return_value)
     update.assert_called_once_with(inst)
コード例 #9
0
ファイル: scion_test.py プロジェクト: nerd100/scion
 def test(self):
     inst = SCIONBasePacket()
     inst.addrs = create_mock(['reverse'])
     inst.path = create_mock(['reverse'])
     # Call
     inst.reverse()
     # Tests
     inst.addrs.reverse.assert_called_once_with()
     inst.path.reverse.assert_called_once_with()
コード例 #10
0
ファイル: scion_test.py プロジェクト: nerd100/scion
 def test(self):
     inst = SCIONBasePacket()
     inst.addrs = create_mock(["update"])
     inst._update_cmn_hdr = create_mock()
     # Call
     inst.update()
     # Tests
     inst.addrs.update.assert_called_once_with()
     inst._update_cmn_hdr.assert_called_once_with()
コード例 #11
0
ファイル: scion_test.py プロジェクト: nerd100/scion
 def test(self, update):
     hdr_exp = b"cmn hdr" b"addrs" b"path"
     total_exp = hdr_exp + b"inner pack"
     inst = SCIONBasePacket()
     inst.update = create_mock()
     inst.cmn_hdr = create_mock(["hdr_len", "pack", "total_len"])
     inst.cmn_hdr.hdr_len = len(hdr_exp)
     inst.cmn_hdr.total_len = len(total_exp)
     inst.cmn_hdr.pack.return_value = b"cmn hdr"
     inst.addrs = create_mock(["pack"])
     inst.addrs.pack.return_value = b"addrs"
     inst.path = create_mock(["pack"])
     inst.path.pack.return_value = b"path"
     inst._inner_pack = create_mock()
     inst._inner_pack.return_value = b"inner pack"
     # Call
     ntools.eq_(inst.pack(), total_exp)
     # Tests
     inst.update.assert_called_once_with()
コード例 #12
0
ファイル: scion_test.py プロジェクト: sezergueler/scion
 def test(self, raw, pld_raw):
     inst = SCIONBasePacket()
     inst._inner_parse = create_mock()
     inst.set_payload = create_mock()
     data = create_mock(["get"])
     raw.return_value = data
     # Call
     inst._parse(b"data")
     # Tests
     raw.assert_called_once_with(b"data", inst.NAME, inst.MIN_LEN, min_=True)
     inst._inner_parse.assert_called_once_with(data)
     pld_raw.assert_called_once_with(data.get.return_value)
     inst.set_payload.assert_called_once_with(pld_raw.return_value)
コード例 #13
0
ファイル: scion_test.py プロジェクト: nerd100/scion
 def test_bad_hof(self):
     inst = SCIONBasePacket()
     inst.path = create_mock(["get_iof", "get_hof"])
     inst.path.get_hof.side_effect = SCIONIndexError
     # Call
     ntools.assert_raises(SCMPBadHOFOffset, inst._validate_of_idxes)