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
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)