venkata anil e01e264ff4 provider network ping simulation
This workload creates a provider vlan network, boots a VM on this
network and then pings this VM.

Asumming this workload runs on undercloud and both undercloud
and compute node use same interface for vlan provider network,
for example, ens7f0 in both undercloud and compute nodes (through
bridge-mappings) is used for vlan provider network.

Ideally for each provider network rally is creating, one vlan
interface on top of ens7f0 should be created on undercloud, so
that undercloud can ping the VM which is on same provider vlan

ip link add link ens7f0 name ens7f0.1 type vlan id 1
ip a a <ipadress_on_provider_net> dev ens7f0.1

However when we want to scale test vlan provider network, we
can't create those many vlan interfaces on undercloud.

This workload uses scapy to build the vlan packet with all
the required content and sends (and receives) icmp packet on the
undercloud's interface (i.e ens7f0 in this example) used for
provider network. It also sends GARP reply so that VM should
be able to resolve the ARP for provider network gateway.

As scapy has to be run as a root user, we need to move scapy
code to a separate python program.
scapy_icmp.py will send the vlan ICMP packet using scapy library
as a root user. Main workload will call this python program
with required arguments.

Change-Id: I2290b06e899b96a2a3f060ea6fedd3323978ebf3
2021-08-04 13:12:19 +05:30

65 lines
2.2 KiB
Python
Executable File

#!/usr/bin/python3
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import sys
import time
from scapy.all import srp
from scapy.all import Ether
from scapy.all import ARP
from scapy.all import sendp
from scapy.all import Dot1Q
from scapy.all import IP
from scapy.all import ICMP
LOG = logging.getLogger(__name__)
def _send_icmp(dst_ip, dst_mac, src_ip, src_mac, iface, vlan):
# send 1 icmp packet so that dest VM can send ARP packet to resolve gateway
sendp(Ether(dst=dst_mac, src=src_mac)/Dot1Q(vlan=int(vlan))/IP(dst=dst_ip)/ICMP(),
iface=iface, verbose=0)
bcast = "ff:ff:ff:ff:ff:ff"
# Send GARP using ARP reply method
sendp(Ether(dst=bcast,src=src_mac)/Dot1Q(vlan=int(vlan))/ARP(
op=2,psrc=src_ip, hwsrc=src_mac, hwdst=src_mac, pdst=src_ip), iface=iface, verbose=0)
# send ICMP and validate reply
ans, unans = srp(Ether(dst=dst_mac, src=src_mac)/Dot1Q(vlan=int(vlan))/IP(dst=dst_ip)/ICMP(),
iface=iface, timeout=5, verbose=0)
if (str(ans).find('ICMP:0') == -1):
for snd, rcv in ans:
if (rcv.summary().find(dst_ip) != -1):
LOG.info("Ping to {} is succesful".format(dst_ip))
return True
return False
def main(args):
dst_ip, dst_mac, src_ip, src_mac, iface, vlan = args[1:]
attempts = 0
max_attempts = 120
while attempts < max_attempts:
if _send_icmp(dst_ip, dst_mac, src_ip, src_mac, iface, vlan):
LOG.info("Ping to {} is succesful".format(dst_ip))
return 0
LOG.info("Ping to {} is failed, attempt {}".format(dst_ip, attempts))
attempts += 1
time.sleep(5)
return 1
if __name__ == "__main__":
main(sys.argv)