Re: how to (cross)connect two (physical) eth ports for ping test?

2018-08-19 Thread Roman Mashak
"Robert P. J. Day"  writes:

>   (i'm sure this has been explained many times before, so a link
> covering this will almost certainly do just fine.)
>
>   i want to loop one physical ethernet port into another, and just
> ping the daylights from one to the other for stress testing. my fedora
> laptop doesn't actually have two unused ethernet ports, so i just want
> to emulate this by slapping a couple startech USB/net adapters into
> two empty USB ports, setting this up, then doing it all over again
> monday morning on the actual target system, which does have multiple
> ethernet ports.

[...]

I used this in the past to test dual-port NIC over loopback cable, you
will need to ajust the script:

#!/bin/bash -x

ip="sudo $HOME/bin/ip"
eth1=192.168.2.100
eth2=192.168.2.101

dev1=eth1
dev2=eth2
dev1mac=00:1b:21:9b:24:b4
dev2mac=00:1b:21:9b:24:b5

# fake client interfaces and addresses
dev=dummy0
dev_mac=00:00:00:00:00:11

# max fake clients supported for simulation
maxusers=3

## Create dummy device
## Accepted parameters:
##$1 - devname
##$2 - devmac
##$3 - subnet (e.g. 10.10.10)
##$4 - max number of IP addresses to create on interface
setup_dummy()
{
#   sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
   # Enable tc hardware offload
#   ethtool -K $SGW_DEV hw-tc-offload on

   $ip link add $1 address $2 type dummy
   $ip link set $1 up
   for i in `seq 1 $4`;
   do
  $ip addr add $3.$i/32 dev $1
   done
}

## Delete dummy device
## Accepted parameters:
##$1 - devname
delete_dummy()
{
  $ip link del $1 type dummy
}

setup_network()
{
  # Send traffic eth3 <-> eth4 over loopback cable, where both interfaces
  # eth3 and eth4 are in the same subnet.
  #
  # We assume that NetworkManager is not running and eth3/eth4 are configured
  # via /etc/network/interfaces:
  #
  # 192.168.1.100/32 dev eth3
  # 192.168.1.101/32 dev eth4
  #
  # Specify source IP address when sending the traffic:
  # ping -I 192.168.1.100 192.168.1.101
  #
  #
  $ip neigh add $eth2 lladdr $dev2mac nud permanent dev $dev1
  $ip neigh add $eth1 lladdr $dev1mac nud permanent dev $dev2
  $ip route add table main $eth1 dev $dev2
  $ip route add table main $eth2 dev $dev1
  $ip rule add from all lookup local pref 100
  $ip rule del pref 0
  $ip rule add from $eth2 to $eth1 iif $dev1 lookup local pref 1
  $ip rule add from $eth1 to $eth2 iif $dev2 lookup local pref 2
  $ip rule add from $eth2 to $eth1 lookup main pref 3
  $ip rule add from $eth1 to $eth2 lookup main pref 4

#  $ip rule add from 10.10.10.0/24 to $eth1 iif $dev1 lookup local pref 5
#  $ip rule add from 10.10.10.0/24 to $eth2 iif $dev2 lookup local pref 6
#  $ip rule add from $eth1 to 10.10.10.0/24 iif $dev2 lookup local pref 7
#  $ip rule add from $eth2 to 10.10.10.0/24 iif $dev1 lookup local pref 8
}

restore_network()
{
  # FIX: hangs connections
  $ip rule flush
  $ip rule add priority 32767 lookup default
}

#delete_dummy dummy0
#delete_dummy dummy1

#setup_dummy dummy0 00:00:00:00:00:11 10.10.10 3
#setup_dummy dummy1 00:00:00:00:00:22 20.20.20 3
setup_network



Re: how to (cross)connect two (physical) eth ports for ping test?

2018-08-19 Thread Robert P. J. Day
On Sat, 18 Aug 2018, Willy Tarreau wrote:

> On Sat, Aug 18, 2018 at 09:10:25PM +0200, Andrew Lunn wrote:
> > On Sat, Aug 18, 2018 at 01:39:50PM -0400, Robert P. J. Day wrote:
> > >
> > >   (i'm sure this has been explained many times before, so a link
> > > covering this will almost certainly do just fine.)
> > >
> > >   i want to loop one physical ethernet port into another, and just
> > > ping the daylights from one to the other for stress testing. my fedora
> > > laptop doesn't actually have two unused ethernet ports, so i just want
> > > to emulate this by slapping a couple startech USB/net adapters into
> > > two empty USB ports, setting this up, then doing it all over again
> > > monday morning on the actual target system, which does have multiple
> > > ethernet ports.
> > >
> > >   so if someone can point me to the recipe, that would be great and
> > > you can stop reading.
> > >
> > >   as far as my tentative solution goes, i assume i need to put at
> > > least one of the physical ports in a network namespace via "ip netns",
> > > then ping from the netns to the root namespace. or, going one step
> > > further, perhaps putting both interfaces into two new namespaces, and
> > > setting up forwarding.
> >
> > Namespaces is a good solution. Something like this should work:
> >
> > ip netns add namespace1
> > ip netns add namespace2
> >
> > ip link set eth1 netns namespace1
> > ip link set eth2 netns namespace2
> >
> > ip netns exec namespace1 \
> > ip addr add 10.42.42.42/24 dev eth1
> >
> > ip netns exec namespace1 \
> > ip link set eth1 up
> >
> > ip netns exec namespace2 \
> > ip addr add 10.42.42.24/24 dev eth2
> >
> > ip netns exec namespace2 \
> > ip link set eth2 up
> >
> > ip netns exec namespace1 \
> > ping 10.42.42.24
> >
> > You might also want to consider iperf3 for stress testing, depending
> > on the sort of stress you need.
>
> FWIW I have a setup somewhere involving ip rule + ip route which
> achieves the same without involving namespaces. It's a bit hackish
> but sometimes convenient. I can dig if someone is interested.

  sure, i'm interested ... always educational to see different
solutions.

rday

-- 


Robert P. J. Day Ottawa, Ontario, CANADA
  http://crashcourse.ca/dokuwiki

Twitter:   http://twitter.com/rpjday
LinkedIn:   http://ca.linkedin.com/in/rpjday



Re: how to (cross)connect two (physical) eth ports for ping test?

2018-08-18 Thread Willy Tarreau
On Sat, Aug 18, 2018 at 09:10:25PM +0200, Andrew Lunn wrote:
> On Sat, Aug 18, 2018 at 01:39:50PM -0400, Robert P. J. Day wrote:
> > 
> >   (i'm sure this has been explained many times before, so a link
> > covering this will almost certainly do just fine.)
> > 
> >   i want to loop one physical ethernet port into another, and just
> > ping the daylights from one to the other for stress testing. my fedora
> > laptop doesn't actually have two unused ethernet ports, so i just want
> > to emulate this by slapping a couple startech USB/net adapters into
> > two empty USB ports, setting this up, then doing it all over again
> > monday morning on the actual target system, which does have multiple
> > ethernet ports.
> > 
> >   so if someone can point me to the recipe, that would be great and
> > you can stop reading.
> > 
> >   as far as my tentative solution goes, i assume i need to put at
> > least one of the physical ports in a network namespace via "ip netns",
> > then ping from the netns to the root namespace. or, going one step
> > further, perhaps putting both interfaces into two new namespaces, and
> > setting up forwarding.
> 
> Namespaces is a good solution. Something like this should work:
> 
> ip netns add namespace1
> ip netns add namespace2
> 
> ip link set eth1 netns namespace1
> ip link set eth2 netns namespace2
> 
> ip netns exec namespace1 \
> ip addr add 10.42.42.42/24 dev eth1
> 
> ip netns exec namespace1 \
> ip link set eth1 up
> 
> ip netns exec namespace2 \
> ip addr add 10.42.42.24/24 dev eth2
> 
> ip netns exec namespace2 \
> ip link set eth2 up
> 
> ip netns exec namespace1 \
> ping 10.42.42.24
> 
> You might also want to consider iperf3 for stress testing, depending
> on the sort of stress you need.

FWIW I have a setup somewhere involving ip rule + ip route which achieves
the same without involving namespaces. It's a bit hackish but sometimes
convenient. I can dig if someone is interested.

Regards,
Willy


Re: how to (cross)connect two (physical) eth ports for ping test?

2018-08-18 Thread Andrew Lunn
On Sat, Aug 18, 2018 at 01:39:50PM -0400, Robert P. J. Day wrote:
> 
>   (i'm sure this has been explained many times before, so a link
> covering this will almost certainly do just fine.)
> 
>   i want to loop one physical ethernet port into another, and just
> ping the daylights from one to the other for stress testing. my fedora
> laptop doesn't actually have two unused ethernet ports, so i just want
> to emulate this by slapping a couple startech USB/net adapters into
> two empty USB ports, setting this up, then doing it all over again
> monday morning on the actual target system, which does have multiple
> ethernet ports.
> 
>   so if someone can point me to the recipe, that would be great and
> you can stop reading.
> 
>   as far as my tentative solution goes, i assume i need to put at
> least one of the physical ports in a network namespace via "ip netns",
> then ping from the netns to the root namespace. or, going one step
> further, perhaps putting both interfaces into two new namespaces, and
> setting up forwarding.

Namespaces is a good solution. Something like this should work:

ip netns add namespace1
ip netns add namespace2

ip link set eth1 netns namespace1
ip link set eth2 netns namespace2

ip netns exec namespace1 \
ip addr add 10.42.42.42/24 dev eth1

ip netns exec namespace1 \
ip link set eth1 up

ip netns exec namespace2 \
ip addr add 10.42.42.24/24 dev eth2

ip netns exec namespace2 \
ip link set eth2 up

ip netns exec namespace1 \
ping 10.42.42.24

You might also want to consider iperf3 for stress testing, depending
on the sort of stress you need.

   Andrew


how to (cross)connect two (physical) eth ports for ping test?

2018-08-18 Thread Robert P. J. Day


  (i'm sure this has been explained many times before, so a link
covering this will almost certainly do just fine.)

  i want to loop one physical ethernet port into another, and just
ping the daylights from one to the other for stress testing. my fedora
laptop doesn't actually have two unused ethernet ports, so i just want
to emulate this by slapping a couple startech USB/net adapters into
two empty USB ports, setting this up, then doing it all over again
monday morning on the actual target system, which does have multiple
ethernet ports.

  so if someone can point me to the recipe, that would be great and
you can stop reading.

  as far as my tentative solution goes, i assume i need to put at
least one of the physical ports in a network namespace via "ip netns",
then ping from the netns to the root namespace. or, going one step
further, perhaps putting both interfaces into two new namespaces, and
setting up forwarding.

  anyway, a recipe for this would be just ducky. thank you kindly.

rday

-- 


Robert P. J. Day Ottawa, Ontario, CANADA
  http://crashcourse.ca/dokuwiki

Twitter:   http://twitter.com/rpjday
LinkedIn:   http://ca.linkedin.com/in/rpjday