2 # Copyright (c) 2016 Cisco and/or its affiliates.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 """Traffic script that sends an ip icmp packet
16 from one interface to the other"""
19 from resources.libraries.python.PacketVerifier import RxQueue, TxQueue
20 from resources.libraries.python.TrafficScriptArg import TrafficScriptArg
21 from scapy.layers.inet import ICMP, IP
22 from scapy.all import Ether
26 """ Send IP icmp packet from one traffic generator interface to the other"""
27 args = TrafficScriptArg(['src_mac', 'dst_mac', 'src_ip', 'dst_ip'])
29 src_mac = args.get_arg('src_mac')
30 dst_mac = args.get_arg('dst_mac')
31 src_ip = args.get_arg('src_ip')
32 dst_ip = args.get_arg('dst_ip')
33 tx_if = args.get_arg('tx_if')
34 rx_if = args.get_arg('rx_if')
41 # Create empty ip ICMP packet and add padding before sending
42 pkt_raw = Ether(src=src_mac, dst=dst_mac) / \
43 IP(src=src_ip, dst=dst_ip) / \
46 # Send created packet on one interface and receive on the other
47 sent_packets.append(pkt_raw)
52 # Check whether received packet contains layers Ether, IP and ICMP
54 raise RuntimeError('ICMP echo Rx timeout')
56 if not ether.haslayer(IP):
58 'Not an IP packet received {0}'.format(ether.__repr__()))
60 if not ether.haslayer(ICMP):
62 'Not an ICMP packet received {0}'.format(ether.__repr__()))
66 if __name__ == "__main__":