-parser = OptionParser()
-parser.add_option("--src_if", dest="src_if")
-parser.add_option("--dst_if", dest="dst_if") # optional
-parser.add_option("--src_mac", dest="src_mac")
-parser.add_option("--first_hop_mac", dest="first_hop_mac")
-parser.add_option("--dst_mac", dest="dst_mac") # optional
-parser.add_option("--src_ip", dest="src_ip")
-parser.add_option("--dst_ip", dest="dst_ip")
-parser.add_option("--hops", dest="hops") # optional
-# If one of 'dst_if', 'dst_mac' and 'hops' is specified all must be specified.
-(opts, args) = parser.parse_args()
-src_if_name = opts.src_if
-dst_if_name = opts.dst_if
-dst_if_defined = True
-if dst_if_name is None:
- dst_if_defined = False
-src_mac = opts.src_mac
-first_hop_mac = opts.first_hop_mac
-dst_mac = opts.dst_mac
-src_ip = opts.src_ip
-dst_ip = opts.dst_ip
-hops = int(opts.hops)
-
-if dst_if_defined and (src_if_name == dst_if_name):
- raise Exception("Source interface name equals destination interface name")
-
-src_if = Interface(src_if_name)
-src_if.send_pkt(create_gratuitous_arp_request(src_mac, src_ip))
-if dst_if_defined:
- dst_if = Interface(dst_if_name)
- dst_if.send_pkt(create_gratuitous_arp_request(dst_mac, dst_ip))
-
-pkt_req_send = auto_pad(Ether(src=src_mac, dst=first_hop_mac) /
- IP(src=src_ip, dst=dst_ip) /
- ICMP())
-pkt_req_send = Ether(pkt_req_send)
-src_if.send_pkt(pkt_req_send)
-
-if dst_if_defined:
- try:
+def main():
+ args = TrafficScriptArg(['src_mac', 'dst_mac', 'src_ip', 'dst_ip',
+ 'hops', 'first_hop_mac', 'is_dst_tg'])
+
+ src_if_name = args.get_arg('tx_if')
+ dst_if_name = args.get_arg('rx_if')
+ is_dst_tg = True if args.get_arg('is_dst_tg') == 'True' else False
+
+ src_mac = args.get_arg('src_mac')
+ first_hop_mac = args.get_arg('first_hop_mac')
+ dst_mac = args.get_arg('dst_mac')
+ src_ip = args.get_arg('src_ip')
+ dst_ip = args.get_arg('dst_ip')
+ hops = int(args.get_arg('hops'))
+
+ if is_dst_tg and (src_if_name == dst_if_name):
+ raise Exception("Source interface name equals destination interface name")
+
+ src_if = Interface(src_if_name)
+ src_if.send_pkt(str(create_gratuitous_arp_request(src_mac, src_ip)))
+ if is_dst_tg:
+ dst_if = Interface(dst_if_name)
+ dst_if.send_pkt(str(create_gratuitous_arp_request(dst_mac, dst_ip)))
+
+ pkt_req_send = (Ether(src=src_mac, dst=first_hop_mac) /
+ IP(src=src_ip, dst=dst_ip) /
+ ICMP())
+ src_if.send_pkt(pkt_req_send)
+
+ if is_dst_tg: