X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Ftraffic_scripts%2Farp_request.py;fp=resources%2Ftraffic_scripts%2Farp_request.py;h=0000000000000000000000000000000000000000;hp=8c5b9c7c47581fc8e95424a17acf804f336c727c;hb=d68951ac245150eeefa6e0f4156e4c1b5c9e9325;hpb=ed0258a440cfad7023d643f717ab78ac568dc59b diff --git a/resources/traffic_scripts/arp_request.py b/resources/traffic_scripts/arp_request.py deleted file mode 100755 index 8c5b9c7c47..0000000000 --- a/resources/traffic_scripts/arp_request.py +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env python - -# Copyright (c) 2016 Cisco and/or its affiliates. -# 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. - -"""Send an ARP request and verify the reply""" - -import sys - -from scapy.all import Ether, ARP - -from resources.libraries.python.PacketVerifier import Interface -from resources.libraries.python.TrafficScriptArg import TrafficScriptArg - - -def parse_arguments(): - """Parse arguments of the script passed through command line - - :return: tuple of parsed arguments - """ - args = TrafficScriptArg(['src_if', 'src_mac', 'dst_mac', - 'src_ip', 'dst_ip']) - - # check for mandatory parameters - params = (args.get_arg('tx_if'), - args.get_arg('src_mac'), - args.get_arg('dst_mac'), - args.get_arg('src_ip'), - args.get_arg('dst_ip')) - if None in params: - raise Exception('Missing mandatory parameter(s)!') - - return params - - -def arp_request_test(): - """Send ARP request, expect a reply and verify its fields. - - returns: test status - :raises RuntimeError: ARP reply timeout. - """ - test_passed = False - (src_if, src_mac, dst_mac, src_ip, dst_ip) = parse_arguments() - - interface = Interface(src_if) - - # build an ARP request - arp_request = (Ether(src=src_mac, dst='ff:ff:ff:ff:ff:ff') / - ARP(psrc=src_ip, hwsrc=src_mac, pdst=dst_ip, - hwdst='ff:ff:ff:ff:ff:ff')) - - # send the request - interface.send_pkt(arp_request) - - try: - # wait for APR reply - ether = interface.recv_pkt() - - if not ether: - raise RuntimeError("ARP reply timeout") - - # verify received packet - - if not ether.haslayer(ARP): - raise RuntimeError('Unexpected packet: does not contain ARP ' + - 'header "{}"'.format(ether.__repr__())) - - arp = ether['ARP'] - arp_reply = 2 - - if arp.op != arp_reply: - raise RuntimeError('expected op={}, received {}'.format(arp_reply, - arp.op)) - if arp.ptype != 0x800: - raise RuntimeError('expected ptype=0x800, received {}'. - format(arp.ptype)) - if arp.hwlen != 6: - raise RuntimeError('expected hwlen=6, received {}'. - format(arp.hwlen)) - if arp.plen != 4: - raise RuntimeError('expected plen=4, received {}'.format(arp.plen)) - if arp.hwsrc != dst_mac: - raise RuntimeError('expected hwsrc={}, received {}'. - format(dst_mac, arp.hwsrc)) - if arp.psrc != dst_ip: - raise RuntimeError('expected psrc={}, received {}'. - format(dst_ip, arp.psrc)) - if arp.hwdst != src_mac: - raise RuntimeError('expected hwdst={}, received {}'. - format(src_mac, arp.hwdst)) - if arp.pdst != src_ip: - raise RuntimeError('expected pdst={}, received {}'. - format(src_ip, arp.pdst)) - test_passed = True - - except RuntimeError as ex: - print 'Error occurred: {}'.format(ex) - - return test_passed - - -def main(): - """Run the test and collect result""" - if arp_request_test(): - sys.exit(0) - else: - sys.exit(1) - -if __name__ == '__main__': - main()