Esempio n. 1
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
Esempio n. 2
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)
Esempio n. 3
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]))
Esempio 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)
Esempio n. 5
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')
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
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))
Esempio 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)
Esempio n. 10
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)