3 # Copyright (c) 2016 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 from scapy.all import Ether, IP
20 from resources.libraries.python.PacketVerifier import RxQueue, TxQueue
21 from resources.libraries.python.TrafficScriptArg import TrafficScriptArg
23 def check_macswap(pkt_send, pkt_recv):
24 """Compare MAC addresses of sent and received packet.
26 :param pkt_send: Sent packet.
27 :param pkt_recv: Received packet.
31 print "Comparing following packets:"
35 if pkt_send.dst != pkt_recv.src or pkt_send.src != pkt_recv.dst:
36 raise RuntimeError("MAC addresses were not swapped.")
41 args = TrafficScriptArg(['src_mac', 'dst_mac', 'src_ip', 'dst_ip'])
43 rxq = RxQueue(args.get_arg('rx_if'))
44 txq = TxQueue(args.get_arg('tx_if'))
46 src_mac = args.get_arg('src_mac')
47 dst_mac = args.get_arg('dst_mac')
48 src_ip = args.get_arg('src_ip')
49 dst_ip = args.get_arg('dst_ip')
51 pkt_send = (Ether(src=src_mac, dst=dst_mac) /
52 IP(src=src_ip, dst=dst_ip, proto=61))
55 sent_packets.append(pkt_send)
58 pkt_recv = rxq.recv(ignore=sent_packets)
61 raise RuntimeError('Timeout waiting for packet')
63 check_macswap(pkt_send, pkt_recv)
65 if __name__ == "__main__":