Tested-by: Jiajia, SunX <sunx.jiajia at intel.com>
- Tested Commit: 505c3d03dc7ae8e06c68006e44fd80738a3d70a3
- OS: Fedora20 3.11.10-301.fc20.x86_64 
- GCC: gcc version 4.8.3
- CPU: Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz
- NIC: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection 
[8086:10fb]
- Default x86_64-native-linuxapp-gcc configuration
- Total 22 cases, 22 passed, 0 failed

TOPO:
* Connections ports between tester/ixia and DUT
  - TESTER(Or IXIA)-------DUT
  - portA------------------port0
  - portB------------------port1
  - portC------------------port2
  - portD------------------port3


Test Setup#1 for Functional test
================================

Tester has 4 ports(portA--portD), and DUT has 4 ports(port0--port3), then 
connect portA to port0, portB to port1, portC to port2, portD to port3. 



- Case: Basic bonding--Create bonded devices and slaves
  Description: 
                Use Setup#1.
                Create bonded device and add some ports as salve of bonded 
device,
            Then removed slaves or added slaves or change the bonding primary 
slave
            Or change bonding mode and so on.
  Expected test result:
            Verify the basic functions are normal.

- Case: Basic bonding--MAC Address Test
  Description: 
                Use Setup#1.
                Create bonded device and add some ports as slaves of bonded 
device,
            Check that the changes of  the bonded device and slave MAC
  Expected test result:
            Verify the behavior of bonded device and slave according to the 
mode.

- Case: Basic bonding--Device Promiscuous Mode Test
  Description: 
                Use Setup#1.
                Create bonded device and add some ports as slaves of bonded 
device,
            Set promiscuous mode on or off, then send packets to the bonded 
device
            Or slaves.
  Expected test result:
            Verify the RX/TX status of bonded device and slaves according to 
the mode.

- Case: Mode 0(Round Robin) TX/RX test
  Description: 
                Use Setup#1.
                Create bonded device with mode 0 and add 3 ports as slaves of 
bonded device,
            Forward packets between bonded device and unbounded device, start 
to forward,
            And send packets to unbound device or slaves.
  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 0.

- Case: Mode 0(Round Robin) Bring one slave link down
  Description: 
                Use Setup#1.
                Create bonded device with mode 0 and add 3 ports as slaves of 
bonded device,
            Forward packets between bonded device and unbounded device, start 
to forward,
            Bring the link on either port 0, 1 or 2 down. And send packets to 
unbound 
            device or slaves.
  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 0.

- Case: Mode 0(Round Robin) Bring all slave links down
  Description: 
                Use Setup#1.
                Create bonded device with mode 0 and add 3 ports as slaves of 
bonded device,
            Forward packets between bonded device and unbounded device, start 
to forward,
            Bring the links down on all bonded ports. And send packets to 
unbound 
            device or slaves.
  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 0.

- Case: Mode 1(Active Backup) TX/RX Test
  Description: 
                Use Setup#1.
                Create bonded device with mode 1 and add 3 ports as slaves of 
bonded device,
            Forward packets between bonded device and unbounded device, start 
to forward,
            And send packets to unbound device or slaves.
  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 1.

- Case: Mode 1(Active Backup) Change active slave, RX/TX test
  Description: 
                Use Setup#1.
                Continuing from previous test case.Change the active slave port 
from port0 
            to port1.Verify that the bonded device's MAC has changed to 
slave1's MAC.

            testpmd> set bonding primary 1 4 

           Repeat the transmission and reception(TX/RX) test verify that data 
is now 
           transmitted and received through the new active slave and no longer 
through
           port0
  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 1.

- Case: Mode 1(Active Backup) Link up/down active eth dev
  Description: 
                Use Setup#1.

           Bring link between port A and port0 down. If tester is ixia, can use 
           IxExplorer to set the "Simulate Cable Disconnect" at the port 
property.  
           Verify that the active slave has been changed from port0. Repeat the 
           transmission and reception test verify that data is now transmitted 
and
           received through the new active slave and no longer through port0

           Bring port0 to link down at the remote end.Verify the active slave 
has been changed from port0.
           send 100 packets to port3.

           testpmd> show port stats 4----(Verify port3 have 100 rx 
packets,meanwhile
          port4 have 100 tx packets,the current primary port have 100 tx 
packets,and port0
          doesn`t have any packet)
  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 1. 

- Case: Mode 1(Active Backup) Bring all slave links down
  Description: 
                Use Setup#1.
            Bring all slave ports of bonded port down.
            Verify that bonded callback for link down is called and no active 
slaves. 
            Verify that data cannot be sent or received through bonded port. 
Send 100 packets 
            to port3 and verify that bonded port can't TX 100 packets.

            Bring port 0-2 to link down at the remote end. Verify port4 has 
been link down and has no active slave.
            Send 100 rx packets to port3. 

         testpmd> show port stats 4----(Verify port3 have 100 rx 
packets,meanwhile 
                                        port4 doesn`t have any packet)
  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 1.

- Case: Mode 2(Balance XOR) TX Load Balance test
  Description: 
                Use Setup#1.
            Bonded port will activate each slave eth dev based on the following 
hash function:

             ((dst_mac XOR src_mac) % (number of slave ports))

            Send 300 packets from IXIA port D to non-bonded port(port3),and 
verify these packets 
            will be forwarded to bonded device. The bonded device will 
transimit these packets to all slaves.
            Verify that each slave receive correct number of packets according 
to the policy. The total number
            of packets which received by slave should be equal as 300 packets. 

            Create 3 streams in the IXIA,which streams source MAC are 
00:00:03:00:0F:00,
            00:00:03:00:0F:01,00:00:03:00:0F:02 respectively (make sure 
generate different value by
            the policy ((dst_mac XOR src_mac) % (number of slave ports)) ) and 
dest MAC all is 
            90:E2:BA:4A:54:80(this value should been your unbonded port 
address). Respectively
            send 100 packets to port3 by the 3 streams.

            testpmd> show port stats all----(Verify port3 have 300 rx packets,
            port4 have 300 tx packets,and port 0-2 have 100 tx packets 
respectively)

  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 2.

- Case: Mode 2(Balance XOR) TX Load Balance Link down
  Description: 
                Use Setup#1.
                ring link down of one slave.
            Send 300 packets from non-bonded port(port3), and verify these 
                packets will be forwarded to bonded device. 
            Verify that each active slave receive correct number of packets
            (according to the mode policy), and the down slave will not receive 
packets.
                Link down slave 0 at the remote end.Create 3 streams in the 
IXIA like case13.
                Then respectively send 100 packets to port3 by the 3 streams.

  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 2.

- Case: Mode 2(Balance XOR) Bring all slave links down
  Description: 
                Use Setup#1.
                Bring all slave links down.
                Verify that bonded callback for link down is called.
                Verify no packet can be sent.

                Bring all slaves to link down at the remote end.Create 
                3 streams in the IXIA like case13.Then respectively send 100 
packets 
                to port3 by the 3 streams.

                testpmd> show port info 4----(Verify bonding port has been 
linked down)
              testpmd> show port stats all----(Verify port3 have 300 rx 
packets,meanwhile
                                                         port 0,1,2 and 4 don`t 
have any packet)
  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 2.


- Case: Mode 2(Balance XOR) Layer 3+4 forwarding        
  Description: 
                Use Setup#1.
                Use "xmit_hash_policy()" to change to this forwarding mode
                Create a stream of traffic which will exercise all slave ports 
using the transmit policy 

                 ((SRC_PORT XOR DST_PORT) XOR ((SRC_IP XOR DST_IP) AND 0xffff) 
% # of Slaves

                Transmit data through bonded device, verify TX packet count for 
each slave port is as expected

                Create 3 streams on a port which is mapped with unbonded port 3 
at the IXIA end.
              And set different IP by the transmit policy.Then send 100 packets 
on each stream.

           testpmd> show port stats all----(Verify port3 have 300 rx packets,
                                meanwhile port4 have 300 rx packets, port 0-2 
have 100 tx packets respectively)

                Add Vlan tag in the previouse 3 streams. Everthing else remains 
the same. 
                Then send 100 packets on each stream. Verify the packet statics 
is the same as above.  

              testpmd> show port stats all----(Verify port3  
                have 300 rx packets,meanwhile port4 have 300 rx packets,port 
0-2 have 100 tx packets respecitvely)
  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 2.

- Case: Mode 2(Balance XOR) RX test
  Description: 
                Use Setup#1.
                Send 100 packets to each bonded slaves(port0,1,2)
                Verify that each slave receives 100 packets and the bonded 
device receive a total 300 packets.
                Verify that the bonded device forwards 300 packets to the 
non-bonded port(port4).

                Send 100 packets to port0,1,2 respectively.

                testpmd> show port stats all----(Verify port0,1,2 have 100 tx 
packets respectively 
                                and port4 have 300 rx packets,and port3 have 
300 tx packets)

  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 2.

- Case: Mode 3(Broadcast) TX/RX Test
  Description: 
                Use Setup#1.
                Add ports 0-2 as slave devices to the bonded port 4. Make all 
slaves
              to be active slaves on bonded device. 

            RX: Send a packet stream(100 packets) from port A on the traffic
                    generator to be forwarded through the bonded port4 to port3.
                    Verify the sum of the packets transmitted from the traffic 
generator
                    portA is equal the total received packets on port0, port4 
and portD(Traffic generator).

               testpmd> show port stats all---(Verify port0 receive 100 
packets, 
                                and port4 receive 100 packets, and port3 
transmit 100 packets)

           TX: Send a packet stream(100 packets) from portD on the traffic 
generator 
               to be forwarded through port3 to the bonded port4. Verify the 
sum of 
               the packets(100packets) transmitted from the traffic generator 
port is equal the total 
               received packets on port4, portA and transmitted to port0.

          testpmd> show port stats all---(Verify port3 RX 100 packets, 
                    and port0,1,2 TX 100 packets,port4 has 300 TX packets)
  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 3.


- Case: Mode 3(Broadcast) Bring one slave link down
  Description: 
                Use Setup#1.
                Bring one slave port link down. Send 100 packets through portD 
to port3,
              then port3 forwards to bondede device(port4), verify that the 
bonded device 
                and other slaves TX the correct number of packets(100 packets 
for each port).
  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 3.

- Case: Mode 3(Broadcast) Bring all slave links down
  Description: 
                Use Setup#1.
                Bring all slave ports of bonded port down
                Verify that bonded callback for link down is called
                Verify that data cannot be sent or received through bonded port.
  Expected test result:
            Verify the RX/TX status of bonded device and slaves in mode 3.

- Case: Mode 5(Transmit load balance) basic test
 ============================================================================

Use Setup#1

Create bonded device. Add first slave - port 0. Verify default bonded device 
has default mode 5. Verify bonded device MAC address is that of primary slave. 
Add another slaves port 1 and 2 to the bonded device. Verify that their MAC are 
different.

Bring the primary slave down. Verify if bonding interface reconfigured itself. 
The next port (in this scenario port 1) should became a primary one but the MAC 
should not be changed - should still be the MAC of port 0.

Bring a slave of bonding device down. Verify if bonding interface reconfigured 
itself.

Bring the portA, portB and portC down. Verify the bonded device will link down.

Set bonded device promiscuous mode to be off. Verify only the promiscuous state 
of primary interface will be off.


- Case: Mode 5(Transmit load balance)  TX/RX test
============================================================================

Use Setup#1

Create a bonded device(port4 in this scenario). Add port 0-2 as slaves of 
bonding port4. Make packets to transmit between port3 and port4. Then start to 
forward streams.

TX: Prepare a packet stream which will send packets in 5 minutes. Send this 
stream from portD to port3. Verify that port3 will receive all packets---no 
missed packets and no error packets. Port 0-2 transmitting packets will be 
represented as packet0, packet1 and packet2 respectively and their average 
packets will be represented as mean.  Then verify port 0-2 will meet the 
situation:
mean = (packet0 + packet1 + packet2)/3, packet0, packet1 and packet2 will be 
higher than 90% of mean and lower than 110% of mean. Then the test of port0, 
port1 and port2 balancing are finished positive.

RX: A continuation of TX testing setup. Prepare 3 packet streams and each 
stream has 100 packets. Respectively, send these streams from portA, portB and 
portC. Verify only the primary slave port0 will receive 100 packets, and port3 
will transmit 100 packets.


- Case: Mode 5(Transmit load balance)  Bring one slave link down 
============================================================================

Use Setup#1

Create a bonded device(port4 in this scenario). Add port0, port1 and port2 as 
slaves of bonding port4. Make packets to transmit between port3 and port4. Then 
start to forward streams.

TX: Prepare a packet stream which will send packets in 5 minutes. Bringing 
port0 link down in the remote end. Send this stream from portD to port3. After 
the time of 5 minutes is out, verify that port3 will receive all packets---no 
missed packets and no error packets. Port 1-2 transmitting packets will be 
represented as packet1 and packet2 respectively and their average packets will 
be represented as mean. Then verify port1 and port2 will meet the situation:
mean = (packet1 + packet2)/2, packet1 and packet2 will be higher than 90% of 
mean and lower than 110% of mean. Then the test of port1 and port2 balancing 
are finished positive.

RX: Prepare 3 packet streams and each stream has 100 packets. Respectively, 
send these streams from portA, portB and portC. Verify the primary port(port0 
this scenario) will receive 100 packets, and port1 and port2 will receive 
nothing, and port3 will transmit 100 packets.


- Case: Mode 5(Transmit load balance)  Bring all slaves link down 
=============================================================================

Use Setup#1

First, set the same setup as case 30. Second, bring all slaves link down.

TX: Prepare 1 packet stream which will have 300 packets. Send this stream from 
portD to port3. Verify port0, port1 and port2 will transmit nothing.

RX: Prepare 3 packet streams and each stream has 100 packets. Respectively, 
send these streams from portA, portB and portC. Verify port0, port1 and port2 
will receive nothing.

> -----Original Message-----
> From: Doherty, Declan
> Sent: Monday, December 08, 2014 7:20 PM
> To: dev at dpdk.org
> Cc: Wodkowski, PawelX; Jiajia, SunX; Doherty, Declan
> Subject: [PATCH v2] bond: fix for mac assignment to slaves device
> 
> -V2:
> Tidies up the slave_remove function as per Pawel's comments.
> 
> Adding call to mac_address_slaves_update from the lsc handler when the
> first slave become active to propagate any mac changes made while
> devices are inactive
> 
> Changed removing slave logic to use memmove instead of memcpy to move
> data within the same array, as this was corrupting the slave array.
> 
> Adding unit test to cover failing assignment scenarios
> 
> Signed-off-by: Declan Doherty <declan.doherty at intel.com>
> ---
>  app/test/test_link_bonding.c           | 192
> ++++++++++++++++++++++++++++++++-
>  app/test/virtual_pmd.c                 |   1 -
>  lib/librte_pmd_bond/rte_eth_bond_pmd.c |  19 ++--
>  3 files changed, 200 insertions(+), 12 deletions(-)
> 
> diff --git a/app/test/test_link_bonding.c
> b/app/test/test_link_bonding.c
> index f62c490..4523de6 100644
> --- a/app/test/test_link_bonding.c
> +++ b/app/test/test_link_bonding.c
> @@ -454,7 +454,7 @@ test_remove_slave_from_bonded_device(void)
> 
>       mac_addr = (struct ether_addr *)slave_mac;
>       mac_addr->addr_bytes[ETHER_ADDR_LEN-1] =
> -                     test_params->slave_port_ids[test_params-
> >bonded_slave_count-1];
> +                     test_params->bonded_slave_count-1;
> 
>       rte_eth_macaddr_get(
>                       test_params->slave_port_ids[test_params-
> >bonded_slave_count-1],
> @@ -810,8 +810,7 @@ test_set_primary_slave(void)
>                               test_params->bonded_port_id);
> 
>               expected_mac_addr = (struct ether_addr *)&slave_mac;
> -             expected_mac_addr->addr_bytes[ETHER_ADDR_LEN-1] =
> -                             test_params->slave_port_ids[i];
> +             expected_mac_addr->addr_bytes[ETHER_ADDR_LEN-1] = i;
> 
>               /* Check primary slave MAC */
>               rte_eth_macaddr_get(test_params->slave_port_ids[i],
> &read_mac_addr);
> @@ -928,6 +927,192 @@ test_set_explicit_bonded_mac(void)
>       return 0;
>  }
> 
> +#define BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT (3)
> +
> +static int
> +test_set_bonded_port_initialization_mac_assignment(void)
> +{
> +     int i, slave_count, bonded_port_id;
> +
> +     uint8_t slaves[RTE_MAX_ETHPORTS];
> +     int slave_port_ids[BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT];
> +
> +     struct ether_addr slave_mac_addr, bonded_mac_addr, read_mac_addr;
> +
> +     /* Initialize default values for MAC addresses */
> +     memcpy(&slave_mac_addr, slave_mac, sizeof(struct ether_addr));
> +     memcpy(&bonded_mac_addr, slave_mac, sizeof(struct ether_addr));
> +
> +     /*
> +      * 1. a - Create / configure  bonded / slave ethdevs
> +      */
> +     bonded_port_id = rte_eth_bond_create("ethdev_bond_mac_ass_test",
> +                     BONDING_MODE_ACTIVE_BACKUP, rte_socket_id());
> +     TEST_ASSERT(bonded_port_id > 0, "failed to create bonded device");
> +
> +     TEST_ASSERT_SUCCESS(configure_ethdev(bonded_port_id, 0, 0),
> +                             "Failed to configure bonded ethdev");
> +
> +     for (i = 0; i < BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT; i++) {
> +             char pmd_name[RTE_ETH_NAME_MAX_LEN];
> +
> +             slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = i + 100;
> +
> +             snprintf(pmd_name, RTE_ETH_NAME_MAX_LEN, "eth_slave_%d", i);
> +
> +             slave_port_ids[i] = virtual_ethdev_create(pmd_name,
> +                             &slave_mac_addr, rte_socket_id(), 1);
> +
> +             TEST_ASSERT(slave_port_ids[i] >= 0,
> +                             "Failed to create slave ethdev %s", pmd_name);
> +
> +             TEST_ASSERT_SUCCESS(configure_ethdev(slave_port_ids[i], 1,
> 0),
> +                             "Failed to configure virtual ethdev %s",
> +                             pmd_name);
> +     }
> +
> +
> +     /*
> +      * 2. Add slave ethdevs to bonded device
> +      */
> +     for (i = 0; i < BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT; i++) {
> +             TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(bonded_port_id,
> +                             slave_port_ids[i]),
> +                             "Failed to add slave (%d) to bonded port (%d).",
> +                             slave_port_ids[i], bonded_port_id);
> +     }
> +
> +     slave_count = rte_eth_bond_slaves_get(bonded_port_id, slaves,
> +                     RTE_MAX_ETHPORTS);
> +     TEST_ASSERT_EQUAL(BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT,
> slave_count,
> +                     "Number of slaves (%d) is not as expected (%d)",
> +                     slave_count, BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT);
> +
> +
> +     /*
> +      * 3. Set explicit MAC address on bonded ethdev
> +      */
> +     bonded_mac_addr.addr_bytes[ETHER_ADDR_LEN-2] = 0xFF;
> +     bonded_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 0xAA;
> +
> +     TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
> +                     bonded_port_id, &bonded_mac_addr),
> +                     "Failed to set MAC address on bonded port (%d)",
> +                     bonded_port_id);
> +
> +
> +     /* 4. a - Start bonded ethdev
> +      *    b - Enable slave devices
> +      *    c - Verify bonded/slaves ethdev MAC addresses
> +      */
> +     TEST_ASSERT_SUCCESS(rte_eth_dev_start(bonded_port_id),
> +                     "Failed to start bonded pmd eth device %d.",
> +                     bonded_port_id);
> +
> +     for (i = 0; i < BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT; i++) {
> +             virtual_ethdev_simulate_link_status_interrupt(
> +                             slave_port_ids[i], 1);
> +     }
> +
> +     rte_eth_macaddr_get(bonded_port_id, &read_mac_addr);
> +     TEST_ASSERT_SUCCESS(memcmp(&bonded_mac_addr, &read_mac_addr,
> +                     sizeof(read_mac_addr)),
> +                     "bonded port mac address not as expected");
> +
> +     rte_eth_macaddr_get(slave_port_ids[0], &read_mac_addr);
> +     TEST_ASSERT_SUCCESS(memcmp(&bonded_mac_addr, &read_mac_addr,
> +                     sizeof(read_mac_addr)),
> +                     "slave port 0 mac address not as expected");
> +
> +     slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 1 + 100;
> +     rte_eth_macaddr_get(slave_port_ids[1], &read_mac_addr);
> +     TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
> +                     sizeof(read_mac_addr)),
> +                     "slave port 1 mac address not as expected");
> +
> +     slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 2 + 100;
> +     rte_eth_macaddr_get(slave_port_ids[2], &read_mac_addr);
> +     TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
> +                     sizeof(read_mac_addr)),
> +                     "slave port 2 mac address not as expected");
> +
> +
> +     /* 7. a - Change primary port
> +      *    b - Stop / Start bonded port
> +      *    d - Verify slave ethdev MAC addresses
> +      */
> +     TEST_ASSERT_SUCCESS(rte_eth_bond_primary_set(bonded_port_id,
> +                     slave_port_ids[2]),
> +                     "failed to set primary port on bonded device.");
> +
> +     rte_eth_dev_stop(bonded_port_id);
> +     TEST_ASSERT_SUCCESS(rte_eth_dev_start(bonded_port_id),
> +                             "Failed to start bonded pmd eth device %d.",
> +                             bonded_port_id);
> +
> +     rte_eth_macaddr_get(bonded_port_id, &read_mac_addr);
> +     TEST_ASSERT_SUCCESS(memcmp(&bonded_mac_addr, &read_mac_addr,
> +                     sizeof(read_mac_addr)),
> +                     "bonded port mac address not as expected");
> +
> +     slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 0 + 100;
> +     rte_eth_macaddr_get(slave_port_ids[0], &read_mac_addr);
> +     TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
> +                     sizeof(read_mac_addr)),
> +                     "slave port 0 mac address not as expected");
> +
> +     slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 1 + 100;
> +     rte_eth_macaddr_get(slave_port_ids[1], &read_mac_addr);
> +     TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
> +                     sizeof(read_mac_addr)),
> +                     "slave port 1 mac address not as expected");
> +
> +     rte_eth_macaddr_get(slave_port_ids[2], &read_mac_addr);
> +     TEST_ASSERT_SUCCESS(memcmp(&bonded_mac_addr, &read_mac_addr,
> +                     sizeof(read_mac_addr)),
> +                     "slave port 2 mac address not as expected");
> +
> +     /* 6. a - Stop bonded ethdev
> +      *    b - remove slave ethdevs
> +      *    c - Verify slave ethdevs MACs are restored
> +      */
> +     rte_eth_dev_stop(bonded_port_id);
> +
> +     for (i = 0; i < BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT; i++) {
> +
>       TEST_ASSERT_SUCCESS(rte_eth_bond_slave_remove(bonded_port_id,
> +                             slave_port_ids[i]),
> +                             "Failed to remove slave %d from bonded port
> (%d).",
> +                             slave_port_ids[i], bonded_port_id);
> +     }
> +
> +     slave_count = rte_eth_bond_slaves_get(bonded_port_id, slaves,
> +                     RTE_MAX_ETHPORTS);
> +
> +     TEST_ASSERT_EQUAL(slave_count, 0,
> +                     "Number of slaves (%d) is great than expected (%d).",
> +                     slave_count, 0);
> +
> +     slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 0 + 100;
> +     rte_eth_macaddr_get(slave_port_ids[0], &read_mac_addr);
> +     TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
> +                     sizeof(read_mac_addr)),
> +                     "slave port 0 mac address not as expected");
> +
> +     slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 1 + 100;
> +     rte_eth_macaddr_get(slave_port_ids[1], &read_mac_addr);
> +     TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
> +                     sizeof(read_mac_addr)),
> +                     "slave port 1 mac address not as expected");
> +
> +     slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 2 + 100;
> +     rte_eth_macaddr_get(slave_port_ids[2], &read_mac_addr);
> +     TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
> +                     sizeof(read_mac_addr)),
> +                     "slave port 2 mac address not as expected");
> +
> +     return 0;
> +}
> +
> 
>  static int
>  initialize_bonded_device_with_slaves(uint8_t bonding_mode, uint8_t
> bond_en_isr,
> @@ -4368,6 +4553,7 @@ static struct unit_test_suite
> link_bonding_test_suite  = {
>               TEST_CASE(test_set_bonding_mode),
>               TEST_CASE(test_set_primary_slave),
>               TEST_CASE(test_set_explicit_bonded_mac),
> +
>       TEST_CASE(test_set_bonded_port_initialization_mac_assignment),
>               TEST_CASE(test_status_interrupt),
>               TEST_CASE(test_adding_slave_after_bonded_device_started),
>               TEST_CASE(test_roundrobin_tx_burst),
> diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c
> index ade6cb0..9fac95d 100644
> --- a/app/test/virtual_pmd.c
> +++ b/app/test/virtual_pmd.c
> @@ -588,7 +588,6 @@ virtual_ethdev_create(const char *name, struct
> ether_addr *mac_addr,
> 
>       memcpy(eth_dev->data->mac_addrs, mac_addr,
>                       sizeof(*eth_dev->data->mac_addrs));
> -     eth_dev->data->mac_addrs->addr_bytes[5] = eth_dev->data->port_id;
> 
>       eth_dev->data->dev_started = 0;
>       eth_dev->data->promiscuous = 0;
> diff --git a/lib/librte_pmd_bond/rte_eth_bond_pmd.c
> b/lib/librte_pmd_bond/rte_eth_bond_pmd.c
> index 539baa4..3db473b 100644
> --- a/lib/librte_pmd_bond/rte_eth_bond_pmd.c
> +++ b/lib/librte_pmd_bond/rte_eth_bond_pmd.c
> @@ -982,16 +982,17 @@ void
>  slave_remove(struct bond_dev_private *internals,
>               struct rte_eth_dev *slave_eth_dev)
>  {
> -     int i, found = 0;
> +     uint8_t i;
> 
> -     for (i = 0; i < internals->slave_count; i++) {
> -             if (internals->slaves[i].port_id ==     slave_eth_dev->data-
> >port_id)
> -                     found = 1;
> +     for (i = 0; i < internals->slave_count; i++)
> +             if (internals->slaves[i].port_id ==
> +                             slave_eth_dev->data->port_id)
> +                     break;
> 
> -             if (found && i < (internals->slave_count - 1))
> -                     memcpy(&internals->slaves[i], &internals->slaves[i+1],
> -                                     sizeof(internals->slaves[i]));
> -     }
> +     if (i < (internals->slave_count - 1))
> +             memmove(&internals->slaves[i], &internals->slaves[i + 1],
> +                             sizeof(internals->slaves[0]) *
> +                             (internals->slave_count - i - 1));
> 
>       internals->slave_count--;
>  }
> @@ -1501,6 +1502,8 @@ bond_ethdev_lsc_event_callback(uint8_t port_id,
> enum rte_eth_event_type type,
>                       internals->current_primary_port = port_id;
>                       lsc_flag = 1;
> 
> +                     mac_address_slaves_update(bonded_eth_dev);
> +
>                       /* Inherit eth dev link properties from first active
> slave */
>                       link_properties_set(bonded_eth_dev,
>                                       &(slave_eth_dev->data->dev_link));
> --
> 1.7.12.2

Reply via email to