def serialize(n, value, mask, buf, offset): if mask: assert len(value) == len(mask) pack_str = "!I%ds%ds" % (len(value), len(mask)) msg_pack_into(pack_str, buf, offset, (n << 9) | (1 << 8) | (len(value) * 2), value, mask) else: pack_str = "!I%ds" % (len(value),) msg_pack_into(pack_str, buf, offset, (n << 9) | (0 << 8) | len(value), value) return struct.calcsize(pack_str)
def _serialize_header(mod, n, buf, offset): try: desc = mod._oxm_field_desc(n) value_len = desc.type.size except KeyError: value_len = 0 n, exp_hdr = _make_exp_hdr(mod, n) exp_hdr_len = len(exp_hdr) pack_str = "!I%ds" % (exp_hdr_len,) msg_pack_into(pack_str, buf, offset, (n << 9) | (0 << 8) | (exp_hdr_len + value_len), bytes(exp_hdr)) return struct.calcsize(pack_str)
def _serialize_header(mod, n, buf, offset): try: desc = mod._oxm_field_desc(n) value_len = desc.type.size except KeyError: value_len = 0 n, exp_hdr = _make_exp_hdr(mod, n) exp_hdr_len = len(exp_hdr) pack_str = "!I%ds" % (exp_hdr_len, ) msg_pack_into(pack_str, buf, offset, (n << 9) | (0 << 8) | (exp_hdr_len + value_len), bytes(exp_hdr)) return struct.calcsize(pack_str)
def _serialize(mod, n, value, mask, buf, offset): n, exp_hdr = _make_exp_hdr(mod, n) exp_hdr_len = len(exp_hdr) value_len = len(value) if mask: assert value_len == len(mask) pack_str = "!I%ds%ds%ds" % (exp_hdr_len, value_len, len(mask)) msg_pack_into(pack_str, buf, offset, (n << 9) | (1 << 8) | (exp_hdr_len + value_len * 2), bytes(exp_hdr), value, mask) else: pack_str = "!I%ds%ds" % (exp_hdr_len, value_len,) msg_pack_into(pack_str, buf, offset, (n << 9) | (0 << 8) | (exp_hdr_len + value_len), bytes(exp_hdr), value) return struct.calcsize(pack_str)
def _serialize(mod, n, value, mask, buf, offset): n, exp_hdr = _make_exp_hdr(mod, n) exp_hdr_len = len(exp_hdr) value_len = len(value) if mask: assert value_len == len(mask) pack_str = "!I%ds%ds%ds" % (exp_hdr_len, value_len, len(mask)) msg_pack_into(pack_str, buf, offset, (n << 9) | (1 << 8) | (exp_hdr_len + value_len * 2), bytes(exp_hdr), value, mask) else: pack_str = "!I%ds%ds" % ( exp_hdr_len, value_len, ) msg_pack_into(pack_str, buf, offset, (n << 9) | (0 << 8) | (exp_hdr_len + value_len), bytes(exp_hdr), value) return struct.calcsize(pack_str)
def serialize(mod, n, value, mask, buf, offset): exp_hdr = bytearray() if isinstance(n, tuple): (cls, exp_type) = n desc = mod._oxm_field_desc(n) assert issubclass(cls, _Experimenter) assert isinstance(desc, cls) assert cls is ONFExperimenter onf_exp_hdr_pack_str = '!IH' # experimenter_id, exp_type msg_pack_into(onf_exp_hdr_pack_str, exp_hdr, 0, cls.experimenter_id, exp_type) assert len(exp_hdr) == struct.calcsize(onf_exp_hdr_pack_str) n = desc.oxm_type assert (n >> 7) == OFPXMC_EXPERIMENTER exp_hdr_len = len(exp_hdr) value_len = len(value) if mask: assert value_len == len(mask) pack_str = "!I%ds%ds%ds" % (exp_hdr_len, value_len, len(mask)) msg_pack_into(pack_str, buf, offset, (n << 9) | (1 << 8) | (exp_hdr_len + value_len * 2), bytes(exp_hdr), value, mask) else: pack_str = "!I%ds%ds" % (exp_hdr_len, value_len,) msg_pack_into(pack_str, buf, offset, (n << 9) | (0 << 8) | (exp_hdr_len + value_len), bytes(exp_hdr), value) return struct.calcsize(pack_str)
def _make_exp_hdr(mod, n): exp_hdr = bytearray() try: desc = mod._oxm_field_desc(n) except KeyError: return n, exp_hdr if isinstance(desc, _Experimenter): # XXX (exp_id, exp_type) = n assert desc.experimenter_id == exp_id if isinstance(desc, OldONFExperimenter): # XXX # XXX # This block implements EXT-256 style experimenter OXM. exp_hdr_pack_str = '!IH' # experimenter_id, exp_type msg_pack_into(exp_hdr_pack_str, exp_hdr, 0, desc.experimenter_id, desc.exp_type) else: assert desc.oxm_type == exp_type exp_hdr_pack_str = '!I' # experimenter_id msg_pack_into(exp_hdr_pack_str, exp_hdr, 0, desc.experimenter_id) assert len(exp_hdr) == struct.calcsize(exp_hdr_pack_str) n = desc.oxm_type assert (n >> 7) == OFPXMC_EXPERIMENTER return n, exp_hdr
def _make_exp_hdr(mod, n): exp_hdr = bytearray() try: desc = mod._oxm_field_desc(n) except KeyError: return n, exp_hdr if isinstance(desc, _Experimenter): # XXX (exp_id, exp_type) = n assert desc.experimenter_id == exp_id if isinstance(desc, ONFExperimenter): # XXX # XXX # This block implements EXT-256 style experimenter OXM. exp_hdr_pack_str = '!IH' # experimenter_id, exp_type msg_pack_into(exp_hdr_pack_str, exp_hdr, 0, desc.experimenter_id, desc.exp_type) else: assert desc.oxm_type == exp_type exp_hdr_pack_str = '!I' # experimenter_id msg_pack_into(exp_hdr_pack_str, exp_hdr, 0, desc.experimenter_id) assert len(exp_hdr) == struct.calcsize(exp_hdr_pack_str) n = desc.oxm_type assert (n >> 7) == OFPXMC_EXPERIMENTER return n, exp_hdr