Exemplo n.º 1
0
 def test_tx_def_miss_action(self):
     """
     Create TX root table and forward all traffic to next SW steering table,
     create two matchers with different priorities, one with default miss
     action (on TX it's go to wire action) and one with drop action, default
     miss action should occur before the drop action hence packets
     should reach server side which has RX rule with QP action.
     """
     self.create_players(Mlx5DrResources)
     self.domain_tx = DrDomain(self.client.ctx,
                               dve.MLX5DV_DR_DOMAIN_TYPE_NIC_TX)
     tx_def_miss = DrActionDefMiss()
     tx_drop_action = DrActionDrop()
     smac_value = struct.pack(
         '!6s', bytes.fromhex(PacketConsts.SRC_MAC.replace(':', '')))
     self.tx_table, self.tx_dest_act = self.create_rx_recv_rules(
         smac_value, [tx_def_miss], domain=self.domain_tx)
     qp_action = DrActionQp(self.server.qp)
     self.create_rx_recv_rules(smac_value, [qp_action])
     smac_mask = bytes([0xff] * 6) + bytes(2)
     mask_param = Mlx5FlowMatchParameters(len(smac_mask), smac_mask)
     matcher_tx2 = DrMatcher(self.tx_table, 2, u.MatchCriteriaEnable.OUTER,
                             mask_param)
     smac_value += bytes(2)
     value_param = Mlx5FlowMatchParameters(len(smac_value), smac_value)
     self.rules.append(DrRule(matcher_tx2, value_param, [tx_drop_action]))
     u.raw_traffic(self.client, self.server, self.iters)
Exemplo n.º 2
0
 def create_tx_modify_rule(self):
     """
     Creares a rule on TX domain that modifies smac in the packet and sends
     it to the wire.
     """
     from tests.mlx5_prm_structs import SetActionIn
     self.domain_tx = DrDomain(self.client.ctx,
                               dve.MLX5DV_DR_DOMAIN_TYPE_NIC_TX)
     table = DrTable(self.domain_tx, 0)
     smac_mask = bytes([0xff] * 6)
     mask_param = Mlx5FlowMatchParameters(len(smac_mask), smac_mask)
     matcher = DrMatcher(table, 0, u.MatchCriteriaEnable.OUTER, mask_param)
     smac_value = struct.pack(
         '!6s', bytes.fromhex(PacketConsts.SRC_MAC.replace(':', '')))
     value_param = Mlx5FlowMatchParameters(len(smac_value), smac_value)
     action1 = SetActionIn(action_type=SET_ACTION,
                           field=OUT_SMAC_47_16_FIELD_ID,
                           data=0x88888888,
                           length=OUT_SMAC_47_16_FIELD_LENGTH)
     action2 = SetActionIn(action_type=SET_ACTION,
                           field=OUT_SMAC_15_0_FIELD_ID,
                           data=0x8888,
                           length=OUT_SMAC_15_0_FIELD_LENGTH)
     self.modify_actions = DrActionModify(
         self.domain_tx, dve.MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL,
         [action1, action2])
     self.rules.append(DrRule(matcher, value_param, [self.modify_actions]))
Exemplo n.º 3
0
 def create_rx_recv_rules(self,
                          smac_value,
                          actions,
                          log_matcher_size=None,
                          domain=None):
     """
     Creates a rule on RX domain that forwards packets that match the smac in the matcher
     to the SW steering flow table and another rule on that table with provided actions.
     :param smac_value: The smac matcher value.
     :param actions: List of actions to attach to the recv rule.
     :param log_matcher_size: Size of the matcher table
     :param domain: RX DR domain to use if provided, otherwise create default RX domain.
     :return: Non root table and dest table action to it
     """
     self.domain_rx = domain if domain else DrDomain(
         self.server.ctx, dve.MLX5DV_DR_DOMAIN_TYPE_NIC_RX)
     root_table = DrTable(self.domain_rx, 0)
     table = DrTable(self.domain_rx, 1)
     smac_mask = bytes([0xff] * 6) + bytes(2)
     mask_param = Mlx5FlowMatchParameters(len(smac_mask), smac_mask)
     root_matcher = DrMatcher(root_table, 0, u.MatchCriteriaEnable.OUTER,
                              mask_param)
     self.matcher = DrMatcher(table, 1, u.MatchCriteriaEnable.OUTER,
                              mask_param)
     if log_matcher_size:
         self.matcher.set_layout(log_matcher_size)
     # Size of the matcher value should be modulo 4
     smac_value += bytes(2)
     value_param = Mlx5FlowMatchParameters(len(smac_value), smac_value)
     self.dest_table_action = DrActionDestTable(table)
     self.rules.append(
         DrRule(root_matcher, value_param, [self.dest_table_action]))
     self.rules.append(DrRule(self.matcher, value_param, actions))
     return table, self.dest_table_action
Exemplo n.º 4
0
 def test_dest_array(self):
     """
     Creates RX domain, root table with matcher on source mac. Create a rule
     to forward all traffic to the non-root table. On this table add a rule
     with multi dest array action which include destination QP actions and
     next FT (also with QP action).
     Validate on all QPs the received packets.
     """
     max_actions = 8
     self.client = Mlx5DrResources(qp_count=max_actions, **self.dev_info)
     self.server = Mlx5DrResources(qp_count=max_actions, **self.dev_info)
     self.domain_rx = DrDomain(self.server.ctx, dve.MLX5DV_DR_DOMAIN_TYPE_NIC_RX)
     actions = []
     dest_attrs = []
     for qp in self.server.qps[:-1]:
         qp_action = DrActionQp(qp)
         actions.append(qp_action)
         dest_attrs.append(DrActionDestAttr(dve.MLX5DV_DR_ACTION_DEST, qp_action))
     ft_action = DrTable(self.domain_rx, 0xff)
     last_table_action = DrActionDestTable(ft_action)
     smac_mask = bytes([0xff] * 6) + bytes(2)
     mask_param = Mlx5FlowMatchParameters(len(smac_mask), smac_mask)
     last_matcher = DrMatcher(ft_action, 1, u.MatchCriteriaEnable.OUTER, mask_param)
     dest_attrs.append(DrActionDestAttr(dve.MLX5DV_DR_ACTION_DEST, last_table_action))
     last_qp_action = DrActionQp(self.server.qps[max_actions - 1])
     smac_value = struct.pack('!6s2s', bytes.fromhex(PacketConsts.SRC_MAC.replace(':', '')),
                              bytes(2))
     value_param = Mlx5FlowMatchParameters(len(smac_value), smac_value)
     self.rules.append(DrRule(last_matcher, value_param, [last_qp_action]))
     multi_dest_a = DrActionDestArray(self.domain_rx, len(dest_attrs), dest_attrs)
     smac_value = struct.pack('!6s', bytes.fromhex(PacketConsts.SRC_MAC.replace(':', '')))
     self.create_rx_recv_qp_rule(smac_value, [multi_dest_a], domain=self.domain_rx)
     u.raw_traffic(self.client, self.server, self.iters)
Exemplo n.º 5
0
 def dest_port(self, is_vport=True):
     """
     Creates FDB domain, root table with matcher on source mac on the server
     side. Create a rule to forward all traffic to the non-root table.
     On this table apply VPort/IBPort action goto PF.
     Validate RX side of FDB:
     On the server open another RX domain on PF with QP action and validate
     packets by sending traffic from client, catch all traffic with
     VPort/IBPort action goto PF, open another RX domain on PF with QP
     action and validate packets.
     Validate TX side of FDB:
     Send traffic from server and validate packets on servers' QP
     with the same rules.
     :param is_vport: A flag to indicate if to use VPort or IBPort action.
     """
     self.client = Mlx5DrResources(**self.dev_info)
     self.server = Mlx5DrResources(**self.dev_info)
     self.domain_fdb = DrDomain(self.server.ctx, dve.MLX5DV_DR_DOMAIN_TYPE_FDB)
     port_action = DrActionVPort(self.domain_fdb, PF_VPORT) if is_vport \
         else DrActionIBPort(self.domain_fdb, self.ib_port)
     smac_value = struct.pack('!6s', bytes.fromhex(PacketConsts.SRC_MAC.replace(':', '')))
     self.fdb_table, self.fdb_dest_act = self.create_rx_recv_qp_rule(smac_value, [port_action],
                                                                     domain=self.domain_fdb)
     self.domain_rx = DrDomain(self.server.ctx, dve.MLX5DV_DR_DOMAIN_TYPE_NIC_RX)
     rx_table = DrTable(self.domain_rx, 0)
     qp_action = DrActionQp(self.server.qp)
     smac_mask = bytes([0xff] * 6)
     mask_param = Mlx5FlowMatchParameters(len(smac_mask), smac_mask)
     rx_matcher = DrMatcher(rx_table, 0, u.MatchCriteriaEnable.OUTER, mask_param)
     value_param = Mlx5FlowMatchParameters(len(smac_value), smac_value)
     self.rules.append(DrRule(rx_matcher, value_param, [qp_action]))
     # Validate traffic on RX
     u.raw_traffic(self.client, self.server, self.iters)
     # Validate traffic on TX
     self.send_server_fdb_to_nic_packets(self.iters)
Exemplo n.º 6
0
 def create_client_send_rule(self, actions):
     """
     Create rule over the client TX domain.
     :param actions: List of actions to attach to the send rule.
     """
     self.domain_tx = DrDomain(self.client.ctx, dve.MLX5DV_DR_DOMAIN_TYPE_NIC_TX)
     table = DrTable(self.domain_tx, 0)
     mask_param = Mlx5FlowMatchParameters(len(bytes([0xff] * 6)), bytes([0xff] * 6))
     matcher = DrMatcher(table, 0, u.MatchCriteriaEnable.OUTER, mask_param)
     smac_value = struct.pack('!6s', bytes.fromhex(PacketConsts.SRC_MAC.replace(':', '')))
     value_param = Mlx5FlowMatchParameters(len(smac_value), smac_value)
     self.rules.append(DrRule(matcher, value_param, actions))
Exemplo n.º 7
0
 def create_matcher(self,
                    mask,
                    match_criteria_enable,
                    flags=0,
                    ft_type=dve.MLX5DV_FLOW_TABLE_TYPE_NIC_RX_):
     """
     Creates a matcher from a provided mask.
     :param mask: The mask to match on (in bytes)
     :param match_criteria_enable: Bitmask representing which of the
                                   headers and parameters in match_criteria
                                   are used
     :param flags: Flow matcher flags
     :param ft_type: Flow table type
     :return: Resulting matcher
     """
     try:
         flow_match_param = Mlx5FlowMatchParameters(len(mask), mask)
         attr = Mlx5FlowMatcherAttr(
             match_mask=flow_match_param,
             match_criteria_enable=match_criteria_enable,
             flags=flags,
             ft_type=ft_type)
         matcher = Mlx5FlowMatcher(self.ctx, attr)
     except PyverbsRDMAError as ex:
         if ex.error_code in [errno.EOPNOTSUPP, errno.EPROTONOSUPPORT]:
             raise unittest.SkipTest('Matcher creation is not supported')
         raise ex
     return matcher
Exemplo n.º 8
0
    def test_root_tbl_drop_action(self):
        """
        Create drop action on TX and verify using counter on the server RX that
        only packets that miss the drop rule arrived to the server RX.
        """
        self.create_players(Mlx5DrResources)
        # Create server counter.
        self.server.create_counter()
        self.server_counter_action = DrActionFlowCounter(self.server.counter)

        # Create rule that attaches all the packets in the server RX, sends them
        # to the server RX domain and counts them.
        domain_rx = DrDomain(self.server.ctx, dve.MLX5DV_DR_DOMAIN_TYPE_NIC_RX)
        table = DrTable(domain_rx, 0)
        mask_param = Mlx5FlowMatchParameters(MAX_MATCH_PARAM_SIZE, bytes(MAX_MATCH_PARAM_SIZE))
        matcher = DrMatcher(table, 0, u.MatchCriteriaEnable.NONE, mask_param)
        self.rx_drop_action = DrActionDrop()
        self.rules.append(DrRule(matcher, mask_param, [self.server_counter_action, self.rx_drop_action]))

        # Create drop action on the client TX on specific smac.
        self.tx_drop_action = DrActionDrop()
        self.create_client_send_rule([self.tx_drop_action])

        # Send packets with two differet smacs and expect half to be dropped.
        src_mac_drop = struct.pack('!6s', bytes.fromhex(PacketConsts.SRC_MAC.replace(':', '')))
        src_mac_non_drop = struct.pack('!6s', bytes.fromhex("88:88:88:88:88:88".replace(':', '')))
        self.send_client_raw_packets(int(self.iters/2), src_mac=src_mac_drop)
        recv_packets = self.server.query_counter_packets()
        self.assertEqual(recv_packets, 0, 'Drop action did not drop the TX packets')
        self.send_client_raw_packets(int(self.iters/2), src_mac=src_mac_non_drop)
        recv_packets = self.server.query_counter_packets()
        self.assertEqual(recv_packets, int(self.iters/2),
                         'Drop action dropped TX packets that not matched the rule')
Exemplo n.º 9
0
 def test_root_tbl_qp_rule(self):
     """
     Creates RX domain, root table with matcher on source mac. Creates QP
     action and a rule with this action on the matcher.
     """
     self.create_players(Mlx5DrResources)
     domain_rx = DrDomain(self.server.ctx, dve.MLX5DV_DR_DOMAIN_TYPE_NIC_RX)
     table = DrTable(domain_rx, 0)
     smac_mask = bytes([0xff] * 6)
     mask_param = Mlx5FlowMatchParameters(len(smac_mask), smac_mask)
     matcher = DrMatcher(table, 0, u.MatchCriteriaEnable.OUTER, mask_param)
     qp_action = DrActionQp(self.server.qp)
     smac_value = struct.pack(
         '!6s', bytes.fromhex(PacketConsts.SRC_MAC.replace(':', '')))
     value_param = Mlx5FlowMatchParameters(len(smac_value), smac_value)
     self.rule = DrRule(matcher, value_param, [qp_action])
     u.raw_traffic(self.client, self.server, self.iters)
Exemplo n.º 10
0
    def test_tx_packet_reformat(self):
        """
        Creates packet reformat (encap) action on TX and with QP action on RX
        verifies that the packet was encapsulated as expected.
        """
        self.client = Mlx5FlowResources(**self.dev_info)
        outer = u.gen_outer_headers(self.client.msg_size)
        # Due to encapsulation action Ipv4 and UDP checksum of the outer header
        # will be recalculated, need to skip them during packet validation.
        ipv4_id_idx = [18, 19]
        ipv4_chksum_idx = [24, 25]
        udp_chksum_idx = [34, 35]
        # Server will receive encaped packet so message size must include the
        # length of the outer part.
        self.server = Mlx5FlowResources(msg_size=self.client.msg_size +
                                        len(outer),
                                        **self.dev_info)
        empty_bytes_arr = bytes(MAX_MATCH_PARAM_SIZE)
        empty_value_param = Mlx5FlowMatchParameters(len(empty_bytes_arr),
                                                    empty_bytes_arr)

        # TX steering
        tx_matcher = self.client.create_matcher(
            empty_bytes_arr, u.MatchCriteriaEnable.NONE,
            e.IBV_FLOW_ATTR_FLAGS_EGRESS, dve.MLX5DV_FLOW_TABLE_TYPE_NIC_TX_)
        # Create encap action
        reformat_action = Mlx5PacketReformatFlowAction(
            self.client.ctx,
            data=outer,
            reformat_type=dve.
            MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL_,
            ft_type=dve.MLX5DV_FLOW_TABLE_TYPE_NIC_TX_)
        action_reformat_attr = Mlx5FlowActionAttr(
            flow_action=reformat_action,
            action_type=dve.MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION)
        self.client.flow = Mlx5Flow(tx_matcher, empty_value_param,
                                    [action_reformat_attr], 1)

        # RX steering
        rx_matcher = self.server.create_matcher(empty_bytes_arr,
                                                u.MatchCriteriaEnable.NONE)
        action_qp_attr = Mlx5FlowActionAttr(
            action_type=dve.MLX5DV_FLOW_ACTION_DEST_IBV_QP, qp=self.server.qp)
        self.server.flow = Mlx5Flow(rx_matcher, empty_value_param,
                                    [action_qp_attr], 1)

        # Send traffic and validate packet
        packet = u.gen_packet(self.client.msg_size)
        u.raw_traffic(self.client,
                      self.server,
                      self.iters,
                      expected_packet=outer + packet,
                      skip_idxs=ipv4_id_idx + ipv4_chksum_idx + udp_chksum_idx)
Exemplo n.º 11
0
    def test_packet_reformat(self):
        """
        Creates packet reformat actions on TX (encap) and on RX (decap).
        """
        self.create_players(Mlx5DrResources)
        smac_mask = bytes([0xff] * 6) + bytes(2)
        mask_param = Mlx5FlowMatchParameters(len(smac_mask), smac_mask)
        smac_value = struct.pack(
            '!6s', bytes.fromhex(PacketConsts.SRC_MAC.replace(':', '')))
        value_param = Mlx5FlowMatchParameters(len(smac_value), smac_value)

        # TX steering
        domain_tx = DrDomain(self.client.ctx, dve.MLX5DV_DR_DOMAIN_TYPE_NIC_TX)
        tx_table = DrTable(domain_tx, 0)
        tx_matcher = DrMatcher(tx_table, 0, u.MatchCriteriaEnable.OUTER,
                               mask_param)
        # Create encap action
        outer = u.gen_outer_headers(self.client.msg_size)
        tx_reformat_type = dve.MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL_
        reformat_action_tx = DrActionPacketReformat(
            domain=domain_tx,
            data=outer,
            flags=dve.MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL,
            reformat_type=tx_reformat_type)
        self.rules.append(DrRule(tx_matcher, value_param,
                                 [reformat_action_tx]))

        # RX steering
        domain_rx = DrDomain(self.server.ctx, dve.MLX5DV_DR_DOMAIN_TYPE_NIC_RX)
        # Create decap action
        rx_reformat_type = dve.MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2_
        reformat_action_rx = DrActionPacketReformat(
            domain=domain_rx, reformat_type=rx_reformat_type)
        qp_action = DrActionQp(self.server.qp)
        self.create_rx_recv_rules(smac_value, [reformat_action_rx, qp_action],
                                  domain=domain_rx)

        # Send traffic and validate packet
        u.raw_traffic(self.client, self.server, self.iters)
Exemplo n.º 12
0
 def test_smac_matcher_to_qp_flow(self):
     """
     Creates a matcher to match on outer source mac and a flow that forwards
     packets to QP when matching on source mac.
     """
     self.create_players(Mlx5FlowResources)
     smac_mask = bytes([0xff] * 6)
     matcher = self.server.create_matcher(smac_mask,
                                          u.MatchCriteriaEnable.OUTER)
     smac_value = struct.pack(
         '!6s', bytes.fromhex(PacketConsts.SRC_MAC.replace(':', '')))
     value_param = Mlx5FlowMatchParameters(len(smac_value), smac_value)
     action_qp = Mlx5FlowActionAttr(
         action_type=dve.MLX5DV_FLOW_ACTION_DEST_IBV_QP, qp=self.server.qp)
     self.server.flow = Mlx5Flow(matcher, value_param, [action_qp], 1)
     u.raw_traffic(self.client, self.server, self.iters)
Exemplo n.º 13
0
    def test_prevent_duplicate_rule(self):
        """
        Creates RX domain, sets duplicate rule to be not allowed on that domain,
        try creating duplicate rule. Fail if creation succeeded.
        """
        from tests.mlx5_prm_structs import FlowTableEntryMatchParam

        self.server = Mlx5DrResources(**self.dev_info)
        domain_rx = DrDomain(self.server.ctx, dve.MLX5DV_DR_DOMAIN_TYPE_NIC_RX)
        domain_rx.allow_duplicate_rules(False)
        table = DrTable(domain_rx, 1)
        empty_param = Mlx5FlowMatchParameters(len(FlowTableEntryMatchParam()),
                                              FlowTableEntryMatchParam())
        matcher = DrMatcher(table, 0, u.MatchCriteriaEnable.NONE, empty_param)
        self.qp_action = DrActionQp(self.server.qp)
        self.drop_action = DrActionDrop()
        self.rules.append(DrRule(matcher, empty_param, [self.qp_action]))
        with self.assertRaises(PyverbsRDMAError) as ex:
            self.rules.append(DrRule(matcher, empty_param, [self.drop_action]))
            self.assertEqual(ex.exception.error_code, errno.EEXIST)