Esempio n. 1
0
 def serialize_body(self):
     ofs_nbits = (self.start << 6) + (self.end - self.start)
     data = bytearray()
     msg_pack_into(self._fmt_str, data, 0, self.fields, self.basis,
                   self.algorithm, self.max_link, self.arg, ofs_nbits,
                   self.dst)
     return data
Esempio n. 2
0
def _make_exp_hdr(oxx, mod, n):
    exp_hdr = bytearray()
    try:
        get_desc = getattr(mod, '_' + oxx + '_field_desc')
        desc = get_desc(n)
    except KeyError:
        return n, exp_hdr
    if desc._class == OFPXXC_EXPERIMENTER:
        (exp_id, exp_type) = n
        assert desc.experimenter_id == exp_id
        oxx_type = getattr(desc, oxx + '_type')
        if desc.exp_type == 2560:
            # 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 oxx_type == exp_type | (OFPXXC_EXPERIMENTER << 7)
            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 = oxx_type
        assert (n >> 7) == OFPXXC_EXPERIMENTER
    return n, exp_hdr
Esempio n. 3
0
        def serialize_body(self):
            # Pack optional parameters first, as range_present needs
            # to be calculated.
            optional_data = b''
            range_present = 0
            if self.range_ipv4_min != '':
                range_present |= nicira_ext.NX_NAT_RANGE_IPV4_MIN
                optional_data += type_desc.IPv4Addr.from_user(
                    self.range_ipv4_min)
            if self.range_ipv4_max != '':
                range_present |= nicira_ext.NX_NAT_RANGE_IPV4_MAX
                optional_data += type_desc.IPv4Addr.from_user(
                    self.range_ipv4_max)
            if self.range_ipv6_min != '':
                range_present |= nicira_ext.NX_NAT_RANGE_IPV6_MIN
                optional_data += type_desc.IPv6Addr.from_user(
                    self.range_ipv6_min)
            if self.range_ipv6_max != '':
                range_present |= nicira_ext.NX_NAT_RANGE_IPV6_MAX
                optional_data += type_desc.IPv6Addr.from_user(
                    self.range_ipv6_max)
            if self.range_proto_min is not None:
                range_present |= nicira_ext.NX_NAT_RANGE_PROTO_MIN
                optional_data += type_desc.Int2.from_user(self.range_proto_min)
            if self.range_proto_max is not None:
                range_present |= nicira_ext.NX_NAT_RANGE_PROTO_MAX
                optional_data += type_desc.Int2.from_user(self.range_proto_max)

            data = bytearray()
            msg_pack_into(self._fmt_str, data, 0, self.flags, range_present)
            msg_pack_into('!%ds' % len(optional_data), data, len(data),
                          optional_data)

            return data
Esempio n. 4
0
 def serialize_body(self):
     data = bytearray()
     msg_pack_into(self._fmt_str, data, 0,
                   self.max_len,
                   self.controller_id,
                   self.reason)
     return data
Esempio n. 5
0
    def serialize(self, payload=None, prev=None):
        present = 0
        hdr = bytearray()
        optional = bytearray()

        if self.checksum is not None:
            present |= GRE_CHECKSUM_FLG

            # For purposes of computing the checksum,
            # the value of the checksum field is zero.
            # Also, because Reserved1 is always 0x00 of 2 bytes,
            # Set in conjunction with checksum.
            optional += b'\x00' * self._CHECKSUM_LEN

        if self._key is not None:
            present |= GRE_KEY_FLG
            optional += struct.pack(self._KEY_PACK_STR, self._key)

        if self.seq_number is not None:
            present |= GRE_SEQUENCE_NUM_FLG
            optional += struct.pack(self._SEQNUM_PACK_STR, self.seq_number)

        msg_pack_into(self._PACK_STR, hdr, 0, present, self.version,
                      self.protocol)

        hdr += optional

        if self.checksum:
            self.checksum = packet_utils.checksum(hdr)
            struct.pack_into(self._CHECKSUM_PACK_STR, hdr, self._MIN_LEN,
                             self.checksum)

        return hdr
Esempio n. 6
0
 def serialize_body(self):
     data = bytearray()
     msg_pack_into(self._fmt_str, data, 0,
                   self.clause,
                   self.n_clauses,
                   self.id)
     return data
Esempio n. 7
0
    def serialize(self, payload=None, prev=None):
        present = 0
        hdr = bytearray()
        optional = bytearray()

        if self.checksum is not None:
            present |= GRE_CHECKSUM_FLG

            # For purposes of computing the checksum,
            # the value of the checksum field is zero.
            # Also, because Reserved1 is always 0x00 of 2 bytes,
            # Set in conjunction with checksum.
            optional += b'\x00' * self._CHECKSUM_LEN

        if self._key is not None:
            present |= GRE_KEY_FLG
            optional += struct.pack(self._KEY_PACK_STR, self._key)

        if self.seq_number is not None:
            present |= GRE_SEQUENCE_NUM_FLG
            optional += struct.pack(self._SEQNUM_PACK_STR, self.seq_number)

        msg_pack_into(self._PACK_STR, hdr, 0, present, self.version,
                      self.protocol)

        hdr += optional

        if self.checksum:
            self.checksum = packet_utils.checksum(hdr)
            struct.pack_into(self._CHECKSUM_PACK_STR, hdr, self._MIN_LEN,
                             self.checksum)

        return hdr
Esempio n. 8
0
def _make_exp_hdr(oxx, mod, n):
    exp_hdr = bytearray()
    try:
        get_desc = getattr(mod, '_' + oxx + '_field_desc')
        desc = get_desc(n)
    except KeyError:
        return n, exp_hdr
    if desc._class == OFPXXC_EXPERIMENTER:
        (exp_id, exp_type) = n
        assert desc.experimenter_id == exp_id
        oxx_type = getattr(desc, oxx + '_type')
        if hasattr(desc, 'exp_type'):  # XXX
            # XXX
            # This block implements EXT-256 style experimenter OXM.
            assert desc.exp_type == 2560
            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 oxx_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 = oxx_type
        assert (n >> 7) == OFPXXC_EXPERIMENTER
    return n, exp_hdr
 def _serialize_body(self):
     self.serialize_req_header()
     offset = ofproto.OFP_HEADER_SIZE + EVT_HEADER_SIZE + EVT_REQUEST_HEADER_SIZE
     msg_pack_into(EVT_PORT_TIMER_REQUEST_PACK_STR, self.buf, offset,
         self.port_no,self.event_conditions,
         self.interval_sec,self.interval_msec,
         self.threshold_tx_packets,self.threshold_tx_bytes,
         self.threshold_rx_packets,self.threshold_rx_bytes)
Esempio n. 10
0
 def _serialize_body(self):
     self.serialize_req_header()
     offset = ofproto.OFP_HEADER_SIZE + EVT_HEADER_SIZE + EVT_REQUEST_HEADER_SIZE
     msg_pack_into(EVT_PORT_TIMER_REQUEST_PACK_STR, self.buf, offset,
                   self.port_no, self.event_conditions, self.interval_sec,
                   self.interval_msec, self.threshold_tx_packets,
                   self.threshold_tx_bytes, self.threshold_rx_packets,
                   self.threshold_rx_bytes)
Esempio n. 11
0
 def _serialize_subfield(subfield):
     (field, ofs) = subfield
     buf = bytearray()
     n = ofp.oxm_from_user_header(field)
     ofp.oxm_serialize_header(n, buf, 0)
     assert len(buf) == 4  # only 4-bytes NXM/OXM are defined
     msg_pack_into('!H', buf, 4, ofs)
     return buf
Esempio n. 12
0
 def _serialize_subfield(subfield):
     (field, ofs) = subfield
     buf = bytearray()
     n = ofp.oxm_from_user_header(field)
     ofp.oxm_serialize_header(n, buf, 0)
     assert len(buf) == 4  # only 4-bytes NXM/OXM are defined
     msg_pack_into('!H', buf, 4, ofs)
     return buf
Esempio n. 13
0
 def serialize_body(self):
     data = bytearray()
     ofs_nbits = (self.start << 6) + (self.end - self.start)
     msg_pack_into(self._fmt_str, data, 0,
                   ofs_nbits,
                   self.src,
                   self.max_len)
     return data
Esempio n. 14
0
 def serialize_body(self):
     zone_ofs_nbits = ((self.zone_start << 6) +
                       (self.zone_end - self.zone_start))
     data = bytearray()
     msg_pack_into(self._fmt_str, data, 0, self.flags, self.zone_src,
                   zone_ofs_nbits, self.recirc_table, self.alg)
     for a in self.actions:
         a.serialize(data, len(data))
     return data
Esempio n. 15
0
def _serialize(mod, num, value, mask, buf, offset):
    num, exp_hdr = _make_exp_hdr(mod, num)
    exp_hdr_len = len(exp_hdr)
    value_len = len(value)
    pack_str = "!I%ds%ds" % (exp_hdr_len, value_len,)
    msg_pack_into(pack_str, buf, offset,
                  (num << 9) | (0 << 8) | (exp_hdr_len + value_len),
                  bytes(exp_hdr), value)
    return struct.calcsize(pack_str)
Esempio n. 16
0
 def serialize_body(self):
     # fixup
     data = bytearray()
     msg_pack_into(self._fmt_str, data, 0, self.idle_timeout,
                   self.hard_timeout, self.priority, self.cookie,
                   self.flags, self.table_id, self.fin_idle_timeout,
                   self.fin_hard_timeout)
     for spec in self.specs:
         data += spec.serialize()
     return data
Esempio n. 17
0
 def serialize(self, buf, offset):
     data = bytearray()
     msg_pack_into(NXActionConjunction._fmt_str, data, 0, self.clause,
                   self.n_clauses, self.id)
     payload_offset = (ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
                       struct.calcsize(NXAction._fmt_str))
     self.len = utils.round_up(payload_offset + len(data), 8)
     super(NXActionConjunction, self).serialize(buf, offset)
     msg_pack_into('!%ds' % len(data), buf, offset + payload_offset,
                   bytes(data))
Esempio n. 18
0
 def serialize(self, buf, offset):
     data = self.serialize_body()
     payload_offset = (ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
                       struct.calcsize(self._fmt_str))
     self.len = utils.round_up(payload_offset + len(data), 8)
     super(ofpp.NXAction, self).serialize(buf, offset)
     msg_pack_into(EricssonAction._fmt_str, buf,
                   offset + ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE,
                   self.subtype)
     buf += data
Esempio n. 19
0
 def serialize(self, buf, offset):
     data = bytearray()
     msg_pack_into(NXActionResubmitTable._fmt_str, data, 0,
                   self.in_port, self.table_id)
     payload_offset = (ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
                       struct.calcsize(NXAction._fmt_str))
     self.len = utils.round_up(payload_offset + len(data), 8)
     super(NXActionResubmitTable, self).serialize(buf, offset)
     msg_pack_into('!%ds' % len(data), buf, offset + payload_offset,
                   bytes(data))
Esempio n. 20
0
        def serialize_body(self):
            hdr_data = bytearray()
            n = ofp.oxm_from_user_header(self.dst)
            ofp.oxm_serialize_header(n, hdr_data, 0)
            (dst_num,) = struct.unpack_from('!I', six.binary_type(hdr_data), 0)

            ofs_nbits = (self.start << 6) + (self.end - self.start)
            data = bytearray()
            msg_pack_into(self._fmt_str, data, 0,
                          ofs_nbits, dst_num, self.value)
            return data
Esempio n. 21
0
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)
Esempio n. 22
0
        def serialize_body(self):
            assert isinstance(self.note, (tuple, list))
            for n in self.note:
                assert isinstance(n, six.integer_types)

            pad = (len(self.note) + nicira_ext.NX_ACTION_HEADER_0_SIZE) % 8
            if pad:
                self.note += [0x0 for i in range(8 - pad)]
            note_len = len(self.note)
            data = bytearray()
            msg_pack_into(self._fmt_str % note_len, data, 0, *self.note)
            return data
Esempio n. 23
0
 def serialize_body(self):
     ofs_nbits = (self.start << 6) + (self.end - self.start)
     data = bytearray()
     msg_pack_into(self._fmt_str, data, 0,
                   self.fields,
                   self.basis,
                   self.algorithm,
                   self.max_link,
                   self.arg,
                   ofs_nbits,
                   self.dst)
     return data
Esempio n. 24
0
        def serialize_body(self):
            hdr_data = bytearray()
            n = ofp.oxm_from_user_header(self.dst)
            ofp.oxm_serialize_header(n, hdr_data, 0)
            (dst_num, ) = struct.unpack_from('!I', six.binary_type(hdr_data),
                                             0)

            ofs_nbits = (self.start << 6) + (self.end - self.start)
            data = bytearray()
            msg_pack_into(self._fmt_str, data, 0, ofs_nbits, dst_num,
                          self.value)
            return data
Esempio n. 25
0
 def serialize_body(self):
     # fixup
     data = bytearray()
     msg_pack_into(self._fmt_str, data, 0,
                   self.n_bits, self.src_ofs, self.dst_ofs)
     # src field
     n = ofp.oxm_from_user_header(self.src_field)
     ofp.oxm_serialize_header(n, data, len(data))
     # dst field
     n = ofp.oxm_from_user_header(self.dst_field)
     ofp.oxm_serialize_header(n, data, len(data))
     return data
Esempio n. 26
0
 def serialize_body(self):
     # fixup
     data = bytearray()
     msg_pack_into(self._fmt_str, data, 0, self.n_bits, self.src_ofs,
                   self.dst_ofs)
     # src field
     n = ofp.oxm_from_user_header(self.src_field)
     ofp.oxm_serialize_header(n, data, len(data))
     # dst field
     n = ofp.oxm_from_user_header(self.dst_field)
     ofp.oxm_serialize_header(n, data, len(data))
     return data
Esempio n. 27
0
 def serialize(self, buf, offset):
     data = self.serialize_body()
     payload_offset = (
         ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
         struct.calcsize(NXAction._fmt_str)
     )
     self.len = utils.round_up(payload_offset + len(data), 8)
     super(NXAction, self).serialize(buf, offset)
     msg_pack_into(NXAction._fmt_str,
                   buf,
                   offset + ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE,
                   self.subtype)
     buf += data
Esempio n. 28
0
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)
Esempio n. 29
0
 def serialize(self, buf, offset):
     data = bytearray()
     msg_pack_into(NXActionCT._fmt_str, data, 0, self.flags,
                   self.zone_src, self.zone_ofs_nbits,
                   self.recirc_table, self.alg)
     for a in self.actions:
         a.serialize(data, len(data))
     payload_offset = (ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
                       struct.calcsize(NXAction._fmt_str))
     self.len = utils.round_up(payload_offset + len(data), 8)
     super(NXActionCT, self).serialize(buf, offset)
     msg_pack_into('!%ds' % len(data), buf, offset + payload_offset,
                   bytes(data))
 def _serialize_body(self):
     self.serialize_req_header()
     offset = EVT_REQUEST_HEADER_SIZE
     msg_pack_into(OFP13_FLOW_REQUEST_PACK_STR,self.data,offset,
         self.event_conditions,self.interval_sec,self.interval_msec,
         self.threshold_new_match_packets,self.threshold_new_match_bytes,
         self.threshold_total_match_packets,self.threshold_total_match_bytes,
         self.table_id,self.out_port,self.out_group,self.flow_cookie,self.cookie_mask
         )
     offset += 72
     
     self.match.serialize(self.data,offset)
     ofproto_parser.OFPExperimenter._serialize_body(self)
Esempio n. 31
0
        def serialize_body(self):
            assert isinstance(self.note, (tuple, list))
            for n in self.note:
                assert isinstance(n, six.integer_types)

            pad = (len(self.note) + nicira_ext.NX_ACTION_HEADER_0_SIZE) % 8
            if pad:
                self.note += [0x0 for i in range(8 - pad)]
            note_len = len(self.note)
            data = bytearray()
            msg_pack_into(self._fmt_str % note_len, data, 0,
                          *self.note)
            return data
Esempio n. 32
0
 def serialize_body(self):
     zone_ofs_nbits = ((self.zone_start << 6) +
                       (self.zone_end - self.zone_start))
     data = bytearray()
     msg_pack_into(self._fmt_str, data, 0,
                   self.flags,
                   self.zone_src,
                   zone_ofs_nbits,
                   self.recirc_table,
                   self.alg)
     for a in self.actions:
         a.serialize(data, len(data))
     return data
Esempio n. 33
0
 def serialize(self, buf, offset):
     data = bytearray()
     msg_pack_into(NXActionResubmitTable._fmt_str, data, 0,
                   self.in_port,
                   self.table_id)
     payload_offset = (
         ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
         struct.calcsize(NXAction._fmt_str)
     )
     self.len = utils.round_up(payload_offset + len(data), 8)
     super(NXActionResubmitTable, self).serialize(buf, offset)
     msg_pack_into('!%ds' % len(data), buf, offset + payload_offset,
                   bytes(data))
Esempio n. 34
0
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)
Esempio n. 35
0
 def serialize(self, buf, offset):
     data = bytearray()
     msg_pack_into(NXActionConjunction._fmt_str, data, 0,
                   self.clause,
                   self.n_clauses,
                   self.id)
     payload_offset = (
         ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
         struct.calcsize(NXAction._fmt_str)
     )
     self.len = utils.round_up(payload_offset + len(data), 8)
     super(NXActionConjunction, self).serialize(buf, offset)
     msg_pack_into('!%ds' % len(data), buf, offset + payload_offset,
                   bytes(data))
Esempio n. 36
0
    def _serialize_body(self):
        self.serialize_req_header()
        offset = EVT_REQUEST_HEADER_SIZE
        msg_pack_into(OFP13_FLOW_REQUEST_PACK_STR, self.data, offset,
                      self.event_conditions, self.interval_sec,
                      self.interval_msec, self.threshold_new_match_packets,
                      self.threshold_new_match_bytes,
                      self.threshold_total_match_packets,
                      self.threshold_total_match_bytes, self.table_id,
                      self.out_port, self.out_group, self.flow_cookie,
                      self.cookie_mask)
        offset += 72

        self.match.serialize(self.data, offset)
        ofproto_parser.OFPExperimenter._serialize_body(self)
Esempio n. 37
0
 def serialize(self, buf, offset):
     # fixup
     data = bytearray()
     msg_pack_into(NXActionLearn._fmt_str, data, 0, self.idle_timeout,
                   self.hard_timeout, self.priority, self.cookie,
                   self.flags, self.table_id, self.fin_idle_timeout,
                   self.fin_hard_timeout)
     for spec in self.specs:
         data += spec.serialize()
     payload_offset = (ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
                       struct.calcsize(NXAction._fmt_str))
     self.len = utils.round_up(payload_offset + len(data), 8)
     super(NXActionLearn, self).serialize(buf, offset)
     msg_pack_into('!%ds' % len(data), buf, offset + payload_offset,
                   bytes(data))
Esempio n. 38
0
 def serialize_body(self):
     # fixup
     data = bytearray()
     msg_pack_into(self._fmt_str, data, 0,
                   self.idle_timeout,
                   self.hard_timeout,
                   self.priority,
                   self.cookie,
                   self.flags,
                   self.table_id,
                   self.fin_idle_timeout,
                   self.fin_hard_timeout)
     for spec in self.specs:
         data += spec.serialize()
     return data
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)
Esempio n. 40
0
 def serialize(self, buf, offset):
     # fixup
     data = bytearray()
     msg_pack_into(NXActionRegMove._fmt_str, data, 0, self.n_bits,
                   self.src_ofs, self.dst_ofs)
     # src field
     n = ofp.oxm_from_user_header(self.src_field)
     ofp.oxm_serialize_header(n, data, len(data))
     # dst field
     n = ofp.oxm_from_user_header(self.dst_field)
     ofp.oxm_serialize_header(n, data, len(data))
     payload_offset = (ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
                       struct.calcsize(NXAction._fmt_str))
     self.len = utils.round_up(payload_offset + len(data), 8)
     super(NXActionRegMove, self).serialize(buf, offset)
     msg_pack_into('!%ds' % len(data), buf, offset + payload_offset,
                   bytes(data))
Esempio n. 41
0
def OFPExpStateStatsMultipartRequest(datapath, flags=0, table_id=ofproto.OFPTT_ALL, state=None, match=None):
    get_from_state = 1
    if state is None:
        get_from_state = 0
        state = 0
        
    if match is None:
        match = ofproto_parser.OFPMatch()

    data=bytearray()
    msg_pack_into(osproto.OFP_STATE_STATS_REQUEST_0_PACK_STR, data, 0, table_id, get_from_state, state)
    
    offset=osproto.OFP_STATE_STATS_REQUEST_0_SIZE
    match.serialize(data, offset)

    exp_type=osproto.OFPMP_EXP_STATE_STATS
    return ofproto_parser.OFPExperimenterStatsRequest(datapath=datapath, flags=flags, experimenter=0xBEBABEBA, exp_type=exp_type, data=data)
Esempio n. 42
0
def _make_exp_hdr(mod, num):
    exp_hdr = bytearray()
    try:
        desc = mod._oxs_field_desc(num)
    except KeyError:
        return num, exp_hdr
    if isinstance(desc, Experimenter):  # XXX
        (exp_id, exp_type) = num
        assert desc.experimenter_id == exp_id
        assert desc.oxs_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)
        num = desc.oxs_type
        assert (num >> 7) == OFPXSC_EXPERIMENTER
    return num, exp_hdr
Esempio n. 43
0
        def serialize(self, buf, offset):
            hdr_data = bytearray()
            n = ofp.oxm_from_user_header(self.dst)
            ofp.oxm_serialize_header(n, hdr_data, 0)
            (dst_num, ) = struct.unpack_from('!I', six.binary_type(hdr_data),
                                             0)

            ofs_nbits = (self.ofs << 6) + self.nbits - 1
            data = bytearray()
            msg_pack_into(NXActionRegLoad._fmt_str, data, 0, ofs_nbits,
                          dst_num, self.value)
            payload_offset = (ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
                              struct.calcsize(NXAction._fmt_str))
            self.len = utils.round_up(payload_offset + len(data), 8)
            super(NXActionRegLoad, self).serialize(buf, offset)
            msg_pack_into('!%ds' % len(data), buf, offset + payload_offset,
                          bytes(data))
Esempio n. 44
0
        def serialize(self, buf, offset):
            hdr_data = bytearray()
            n = ofp.oxm_from_user_header(self.dst)
            ofp.oxm_serialize_header(n, hdr_data, 0)
            (dst_num,) = struct.unpack_from('!I', six.binary_type(hdr_data), 0)

            ofs_nbits = (self.ofs << 6) + self.nbits - 1
            data = bytearray()
            msg_pack_into(NXActionRegLoad._fmt_str, data, 0,
                          ofs_nbits, dst_num, self.value)
            payload_offset = (
                ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
                struct.calcsize(NXAction._fmt_str)
            )
            self.len = utils.round_up(payload_offset + len(data), 8)
            super(NXActionRegLoad, self).serialize(buf, offset)
            msg_pack_into('!%ds' % len(data), buf, offset + payload_offset,
                          bytes(data))
Esempio n. 45
0
 def serialize(self, buf, offset):
     data = bytearray()
     msg_pack_into(NXActionCT._fmt_str, data, 0,
                   self.flags,
                   self.zone_src,
                   self.zone_ofs_nbits,
                   self.recirc_table,
                   self.alg)
     for a in self.actions:
         a.serialize(data, len(data))
     payload_offset = (
         ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
         struct.calcsize(NXAction._fmt_str)
     )
     self.len = utils.round_up(payload_offset + len(data), 8)
     super(NXActionCT, self).serialize(buf, offset)
     msg_pack_into('!%ds' % len(data), buf, offset + payload_offset,
                   bytes(data))
Esempio n. 46
0
 def serialize(self, buf, offset):
     # fixup
     data = bytearray()
     msg_pack_into(NXActionRegMove._fmt_str, data, 0,
                   self.n_bits, self.src_ofs, self.dst_ofs)
     # src field
     n = ofp.oxm_from_user_header(self.src_field)
     ofp.oxm_serialize_header(n, data, len(data))
     # dst field
     n = ofp.oxm_from_user_header(self.dst_field)
     ofp.oxm_serialize_header(n, data, len(data))
     payload_offset = (
         ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
         struct.calcsize(NXAction._fmt_str)
     )
     self.len = utils.round_up(payload_offset + len(data), 8)
     super(NXActionRegMove, self).serialize(buf, offset)
     msg_pack_into('!%ds' % len(data), buf, offset + payload_offset,
                   bytes(data))
Esempio n. 47
0
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
Esempio n. 48
0
    def _test_msg_pack_into(self, offset_type='e'):
        fmt = '!HH'
        len_ = struct.calcsize(fmt)
        buf = bytearray(len_)
        offset = len_
        arg1 = 1
        arg2 = 2

        if offset_type == 'l':
            offset += 1
        elif offset_type == 'g':
            offset -= 1

        pack_utils.msg_pack_into(fmt, buf, offset, arg1, arg2)

        check_offset = len(buf) - len_
        res = struct.unpack_from(fmt, six.binary_type(buf), check_offset)

        eq_(arg1, res[0])
        eq_(arg2, res[1])

        return True
Esempio n. 49
0
 def serialize(self, buf, offset):
     # fixup
     data = bytearray()
     msg_pack_into(NXActionLearn._fmt_str, data, 0,
                   self.idle_timeout,
                   self.hard_timeout,
                   self.priority,
                   self.cookie,
                   self.flags,
                   self.table_id,
                   self.fin_idle_timeout,
                   self.fin_hard_timeout)
     for spec in self.specs:
         data += spec.serialize()
     payload_offset = (
         ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
         struct.calcsize(NXAction._fmt_str)
     )
     self.len = utils.round_up(payload_offset + len(data), 8)
     super(NXActionLearn, self).serialize(buf, offset)
     msg_pack_into('!%ds' % len(data), buf, offset + payload_offset,
                   bytes(data))
Esempio n. 50
0
    def _test_msg_pack_into(self, offset_type='e'):
        fmt = '!HH'
        len_ = struct.calcsize(fmt)
        buf = bytearray(len_)
        offset = len_
        arg1 = 1
        arg2 = 2

        if offset_type == 'l':
            offset += 1
        elif offset_type == 'g':
            offset -= 1

        pack_utils.msg_pack_into(fmt, buf, offset, arg1, arg2)

        check_offset = len(buf) - len_
        res = struct.unpack_from(fmt, six.binary_type(buf), check_offset)

        eq_(arg1, res[0])
        eq_(arg2, res[1])

        return True
Esempio n. 51
0
        def serialize_body(self):
            # Pack optional parameters first, as range_present needs
            # to be calculated.
            optional_data = b''
            range_present = 0
            if self.range_ipv4_min != '':
                range_present |= nicira_ext.NX_NAT_RANGE_IPV4_MIN
                optional_data += type_desc.IPv4Addr.from_user(
                    self.range_ipv4_min)
            if self.range_ipv4_max != '':
                range_present |= nicira_ext.NX_NAT_RANGE_IPV4_MAX
                optional_data += type_desc.IPv4Addr.from_user(
                    self.range_ipv4_max)
            if self.range_ipv6_min != '':
                range_present |= nicira_ext.NX_NAT_RANGE_IPV6_MIN
                optional_data += type_desc.IPv6Addr.from_user(
                    self.range_ipv6_min)
            if self.range_ipv6_max != '':
                range_present |= nicira_ext.NX_NAT_RANGE_IPV6_MAX
                optional_data += type_desc.IPv6Addr.from_user(
                    self.range_ipv6_max)
            if self.range_proto_min is not None:
                range_present |= nicira_ext.NX_NAT_RANGE_PROTO_MIN
                optional_data += type_desc.Int2.from_user(
                    self.range_proto_min)
            if self.range_proto_max is not None:
                range_present |= nicira_ext.NX_NAT_RANGE_PROTO_MAX
                optional_data += type_desc.Int2.from_user(
                    self.range_proto_max)

            data = bytearray()
            msg_pack_into(self._fmt_str, data, 0,
                          self.flags,
                          range_present)
            msg_pack_into('!%ds' % len(optional_data), data, len(data),
                          optional_data)

            return data
Esempio n. 52
0
 def serialize(self):
     buf = bytearray()
     if isinstance(self.src, tuple):
         src_type = 0  # subfield
     else:
         src_type = 1  # immediate
     # header
     val = (src_type << 13) | (self._dst_type << 11) | self.n_bits
     msg_pack_into(self._hdr_fmt_str, buf, 0, val)
     # src
     if src_type == 0:  # subfield
         buf += self._serialize_subfield(self.src)
     elif src_type == 1:  # immediate
         src_len = (self.n_bits + 15) // 16 * 2
         buf += type_desc.IntDescr(size=src_len).from_user(self.src)
     # dst
     if self._dst_type == 0:  # match
         buf += self._serialize_subfield(self.dst)
     elif self._dst_type == 1:  # load
         buf += self._serialize_subfield(self.dst)
     elif self._dst_type == 2:  # output
         pass  # empty
     return buf
Esempio n. 53
0
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
Esempio n. 54
0
 def serialize(self):
     buf = bytearray()
     if isinstance(self.src, tuple):
         src_type = 0  # subfield
     else:
         src_type = 1  # immediate
     # header
     val = (src_type << 13) | (self._dst_type << 11) | self.n_bits
     msg_pack_into(self._hdr_fmt_str, buf, 0, val)
     # src
     if src_type == 0:  # subfield
         buf += self._serialize_subfield(self.src)
     elif src_type == 1:  # immediate
         src_len = (self.n_bits + 15) // 16 * 2
         buf += type_desc.IntDescr(size=src_len).from_user(self.src)
     # dst
     if self._dst_type == 0:  # match
         buf += self._serialize_subfield(self.dst)
     elif self._dst_type == 1:  # load
         buf += self._serialize_subfield(self.dst)
     elif self._dst_type == 2:  # output
         pass  # empty
     return buf
Esempio n. 55
0
 def _serialize_body(self):
     self.serialize_req_header()
     offset = ofproto.OFP_HEADER_SIZE + EVT_HEADER_SIZE + EVT_REQUEST_HEADER_SIZE
     self.match.serialize(self.buf, offset)
     offset += ofproto.OFP_MATCH_SIZE
     msg_pack_into("!BxHQQ", self.buf, offset, self.table_id, self.out_port,
                   self.flow_cookie, self.cookie_mask)
     offset += 20
     msg_pack_into("!H2xII", self.buf, offset, self.event_conditions,
                   self.interval_sec, self.interval_msec)
     offset += 12
     msg_pack_into("!QQQQ", self.buf, offset,
                   self.threshold_new_match_packets,
                   self.threshold_new_match_bytes,
                   self.threshold_total_match_packets,
                   self.threshold_total_match_bytes)
     offset += 32
Esempio n. 56
0
        def serialize(self, buf, offset):
            # Pack optional parameters first, as range_present needs
            # to be calculated.
            optional_data = b''
            range_present = 0
            if self.range_ipv4_min != '':
                range_present |= nicira_ext.NX_NAT_RANGE_IPV4_MIN
                optional_data += type_desc.IPv4Addr.from_user(
                    self.range_ipv4_min)
            if self.range_ipv4_max != '':
                range_present |= nicira_ext.NX_NAT_RANGE_IPV4_MAX
                optional_data += type_desc.IPv4Addr.from_user(
                    self.range_ipv4_max)
            if self.range_ipv6_min != '':
                range_present |= nicira_ext.NX_NAT_RANGE_IPV6_MIN
                optional_data += type_desc.IPv6Addr.from_user(
                    self.range_ipv6_min)
            if self.range_ipv6_max != '':
                range_present |= nicira_ext.NX_NAT_RANGE_IPV6_MAX
                optional_data += type_desc.IPv6Addr.from_user(
                    self.range_ipv6_max)
            if self.range_proto_min is not None:
                range_present |= nicira_ext.NX_NAT_RANGE_PROTO_MIN
                optional_data += type_desc.Int2.from_user(
                    self.range_proto_min)
            if self.range_proto_max is not None:
                range_present |= nicira_ext.NX_NAT_RANGE_PROTO_MAX
                optional_data += type_desc.Int2.from_user(
                    self.range_proto_max)

            data = bytearray()
            msg_pack_into(NXActionNAT._fmt_str, data, 0,
                          self.flags,
                          range_present)
            msg_pack_into('!%ds' % len(optional_data), data, len(data),
                          optional_data)

            payload_offset = (
                ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
                struct.calcsize(NXAction._fmt_str)
            )
            self.len = utils.round_up(payload_offset + len(data), 8)
            super(NXActionNAT, self).serialize(buf, offset)
            msg_pack_into('!%ds' % len(data), buf, offset + payload_offset,
                          bytes(data))
Esempio n. 57
0
        def serialize_body(self):
            ofs_nbits = (self.start << 6) + (self.end - self.start)
            data = bytearray()
            slave_offset = (nicira_ext.NX_ACTION_BUNDLE_0_SIZE -
                            nicira_ext.NX_ACTION_HEADER_0_SIZE)
            self.n_slaves = len(self.slaves)
            for s in self.slaves:
                msg_pack_into('!H', data, slave_offset, s)
                slave_offset += 2
            pad_len = (utils.round_up(self.n_slaves, 4) - self.n_slaves)

            if pad_len != 0:
                msg_pack_into('%dx' % pad_len * 2, data, slave_offset)

            msg_pack_into(self._fmt_str, data, 0, self.algorithm, self.fields,
                          self.basis, self.slave_type, self.n_slaves,
                          ofs_nbits, self.dst)

            return data
Esempio n. 58
0
 def serialize(self, buf, offset):
     super(NXAction, self).serialize(buf, offset)
     msg_pack_into(NXAction._fmt_str, buf,
                   offset + ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE,
                   self.subtype)