]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | # SPDX-License-Identifier: ISC |
f40b18e8 KK |
2 | # |
3 | # Copyright (c) 2019 by VMware, Inc. ("VMware") | |
4 | # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. | |
5 | # ("NetDEF") in this file. | |
6 | # | |
f40b18e8 KK |
7 | |
8 | import sys | |
9 | import argparse | |
10 | from scapy.all import Raw, sendp | |
11 | import binascii | |
12 | ||
13 | ||
14 | def send_packet(packet, iface, interval, count): | |
15 | """ | |
16 | Read BSR packet in Raw format and send it to specified interface | |
17 | ||
18 | Parameter: | |
19 | --------- | |
20 | * `packet` : BSR packet in raw format | |
21 | * `interface` : Interface from which packet would be send | |
22 | * `interval` : Interval between the packets | |
23 | * `count` : Number of packets to be sent | |
24 | """ | |
25 | ||
26 | data = binascii.a2b_hex(packet) | |
27 | p = Raw(load=data) | |
28 | p.show() | |
29 | sendp(p, inter=int(interval), iface=iface, count=int(count)) | |
30 | ||
31 | ||
32 | if __name__ == "__main__": | |
33 | parser = argparse.ArgumentParser(description="Send BSR Raw packet") | |
34 | parser.add_argument("packet", help="Packet in raw format") | |
35 | parser.add_argument("iface", help="Packet send to this ineterface") | |
36 | parser.add_argument("--interval", help="Interval between packets", default=0) | |
37 | parser.add_argument( | |
38 | "--count", help="Number of times packet is sent repetitively", default=0 | |
39 | ) | |
40 | args = parser.parse_args() | |
41 | ||
42 | if not args.packet or not args.iface: | |
43 | sys.exit(1) | |
44 | ||
45 | send_packet(args.packet, args.iface, args.interval, args.count) |