コード例 #1
0
 def test(self, raw, scmp_info):
     inst = SCMPPayload()
     data = create_mock(["pop"])
     data.pop.side_effect = (
         bytes.fromhex("0102030405060700"),
         "info",
         "cmn hdr",
         "addrs",
         "path",
         "exts",
         "l4 hdr",
     )
     raw.return_value = data
     # Call
     inst._parse("class", "type", "data")
     # Tests
     raw.assert_called_once_with("data", inst.NAME)
     ntools.eq_(inst.l4_proto, 0x07)
     pop_calls = [call(inst.META_LEN)
                  ] + [call(x * LINE_LEN) for x in range(1, 7)]
     assert_these_calls(data.pop, pop_calls)
     scmp_info.assert_called_once_with("class", "type", "info")
     ntools.eq_(inst.info, scmp_info.return_value)
     ntools.eq_(inst._cmn_hdr, "cmn hdr")
     ntools.eq_(inst._addrs, "addrs")
     ntools.eq_(inst._path, "path")
     ntools.eq_(inst._exts, "exts")
     ntools.eq_(inst._l4_hdr, "l4 hdr")
コード例 #2
0
 def _setup(self, inc_list, build_info, inc_parts):
     pkt = create_mock(["cmn_hdr", "addrs", "path", "pack_exts", "l4_hdr"])
     pkt.cmn_hdr = create_mock(["pack"])
     pkt.addrs = create_mock(["pack"])
     pkt.path = create_mock(["pack"])
     pkt.pack_exts = create_mock()
     pkt.l4_hdr = create_mock(["TYPE", "pack"])
     inc_parts.return_value = inc_list
     # Call
     inst = SCMPPayload.from_pkt("class",
                                 "type",
                                 pkt,
                                 "arg1",
                                 "arg2",
                                 kwarg1="kwval1")
     # Tests
     build_info.assert_called_once_with("class",
                                        "type",
                                        pkt,
                                        "arg1",
                                        "arg2",
                                        kwarg1="kwval1")
     ntools.eq_(inst.info, build_info.return_value)
     inc_parts.assert_called_once_with("class", "type")
     return inst, pkt
コード例 #3
0
 def _setup(self):
     inst = SCMPPayload()
     inst._cmn_hdr = b"cmn hdr "
     inst._addrs = b"addr hdr"
     inst._path = b"path hdr"
     inst._exts = b"ext hdrs"
     inst._l4_hdr = b"l4 proto header "
     inst.l4_proto = 42
     return inst
コード例 #4
0
ファイル: scion.py プロジェクト: xabarass/scion
 def parse_payload(self):
     if not self.l4_hdr:
         raise SCIONParseError("Cannot parse payload of non-L4 packet")
     praw = self._payload.pack()
     if self.l4_hdr.TYPE == L4Proto.UDP:
         # Treat as SCION control message
         pld = SignedCtrlPayload.from_raw(praw).pld()
     elif self.l4_hdr.TYPE == L4Proto.SCMP:
         pld = SCMPPayload((self.l4_hdr.class_, self.l4_hdr.type, praw))
     self.set_payload(pld)
     return pld
コード例 #5
0
ファイル: scion.py プロジェクト: xabarass/scion
 def convert_to_scmp_error(self, addr, class_, type_, pkt, *args,
                           hopbyhop=False, **kwargs):
     self.addrs.src = addr
     if self.ext_hdrs:
         if self.ext_hdrs[0].EXT_TYPE == ExtHopByHopType.SCMP:
             # Remove any existing SCMP ext header
             del self.ext_hdrs[0]
     # Insert SCMP ext at start of headers
     self.ext_hdrs.insert(0, SCMPExt.from_values(hopbyhop=hopbyhop))
     # Trim any extra headers, in the case of SCMPTooManyHopByHop, max+1 as
     # the SCMP ext header isn't counted.
     self.ext_hdrs = self.ext_hdrs[:MAX_HOPBYHOP_EXT + 1]
     # Create SCMP payload.
     pld = SCMPPayload.from_pkt(class_, type_, pkt, *args, **kwargs)
     self.l4_hdr = SCMPHeader.from_values(self.addrs.src, self.addrs.dst,
                                          class_, type_)
     self.set_payload(pld)
コード例 #6
0
 def _create_payload(self, _):
     self.info = SCMPInfoEcho.from_values()
     return SCMPPayload.from_values(self.info)
コード例 #7
0
 def _parse_pld_scmp(self, data):  # pragma: no cover
     return SCMPPayload((self.l4_hdr.class_, self.l4_hdr.type, data.pop()))
コード例 #8
0
 def _setup(self):
     inst = SCMPPayload()
     inst._pack_meta = create_mock()
     inst._pack_meta.return_value = b"metadata"
     return inst