aboutsummaryrefslogtreecommitdiffstats
path: root/resources/traffic_scripts/arp_request.py
diff options
context:
space:
mode:
authorJan Gelety <jgelety@cisco.com>2019-11-12 05:27:43 +0100
committerJan Gelety <jgelety@cisco.com>2019-11-28 18:26:21 +0100
commitd68951ac245150eeefa6e0f4156e4c1b5c9e9325 (patch)
tree487554a7547218d27f0a61ec02b70502c32cdcb4 /resources/traffic_scripts/arp_request.py
parented0258a440cfad7023d643f717ab78ac568dc59b (diff)
Python3: resources and libraries
Change-Id: I1392c06b1d64f62b141d24c0d42a8e36913b15e2 Signed-off-by: Jan Gelety <jgelety@cisco.com>
Diffstat (limited to 'resources/traffic_scripts/arp_request.py')
-rwxr-xr-xresources/traffic_scripts/arp_request.py120
1 files changed, 0 insertions, 120 deletions
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()