def kill_bind10(): """ Kill any running bind10 instance """ get_common_logger().debug("Killing all running Bind instances") return fabric_sudo_command('pkill b10-*; sleep ' + str(world.f_cfg.sleep_time_1))
def start_bind10(): """ Start Bind10 instance """ get_common_logger().debug("Starting Bind instances") return fabric_sudo_command('(rm nohup.out; nohup ' + SOFTWARE_INSTALL_DIR + 'sbin/bind10 &); sleep ' + str(SLEEP_TIME_1))
def start_bind10(): """ Start Bind10 instance """ get_common_logger().debug("Starting Bind instances") return fabric_sudo_command('(rm nohup.out; nohup ' + world.f_cfg.software_install_path + 'sbin/bind10 &); sleep ' + str(world.f_cfg.sleep_time_1))
def client_send_msg(step, msgname, iface, addr): """ Sends specified message with defined options. Parameters: msg ('<msg> message'): name of the message. """ # iface and addr not used for v6 for now. # Remove previous message waiting to be sent, just in case this is a # REQUEST after we received ADVERTISE. We don't want to send SOLICIT # the second time. world.climsg = [] if msgname == "SOLICIT": msg = build_msg(DHCP6_Solicit()) elif msgname == "REQUEST": msg = build_msg(DHCP6_Request()) elif msgname == "CONFIRM": msg = build_msg(DHCP6_Confirm()) elif msgname == "RENEW": msg = build_msg(DHCP6_Renew()) elif msgname == "REBIND": msg = build_msg(DHCP6_Rebind()) elif msgname == "DECLINE": msg = build_msg(DHCP6_Decline()) elif msgname == "RELEASE": msg = build_msg(DHCP6_Release()) elif msgname == "INFOREQUEST": world.cfg["add_option"]["IA_NA"] = False world.cfg["add_option"]["IA_TA"] = False msg = build_msg(DHCP6_InfoRequest()) else: assert False, "Invalid message type: %s" % msgname assert msg, "Message preparation failed" if msg: world.climsg.append(msg) get_common_logger().debug("Message %s will be sent over %s interface." % (msgname, world.cfg["iface"]))
def client_send_msg(step, msgname, iface, addr): """ Sends specified message with defined options. Parameters: msg ('<msg> message'): name of the message. """ # iface and addr not used for v6 for now. # Remove previous message waiting to be sent, just in case this is a # REQUEST after we received ADVERTISE. We don't want to send SOLICIT # the second time. world.climsg = [] if msgname == "SOLICIT": msg = build_msg(DHCP6_Solicit()) elif msgname == "REQUEST": msg = build_msg(DHCP6_Request()) elif msgname == "CONFIRM": msg = build_msg(DHCP6_Confirm()) elif msgname == "RENEW": msg = build_msg(DHCP6_Renew()) elif msgname == "REBIND": msg = build_msg(DHCP6_Rebind()) elif msgname == "DECLINE": msg = build_msg(DHCP6_Decline()) elif msgname == "RELEASE": msg = build_msg(DHCP6_Release()) elif msgname == "INFOREQUEST": msg = build_msg(DHCP6_InfoRequest()) else: assert False, "Invalid message type: %s" % msgname assert msg, "Message preparation failed" if msg: world.climsg.append(msg) get_common_logger().debug("Message %s will be sent over %s interface." % (msgname, world.cfg["iface"]))
def client_send_receive(step, contain, msgType): """ @step("Client MUST (NOT )?respond with (\S+) message.") Step is responsible for sending previously prepared server's message and checking the response of a client. Scapy's sr() function is used here. """ found = False debug.recv = [] conf.use_pcap = True templen = len(world.climsg) if msgType == "REQUEST": conf.debug_match = True ans, unans = sr(world.srvmsg, iface=IFACE, nofilter=1, timeout=2, verbose=99, clnt=1) # print ans for entry in ans: sent, received = entry # print sent.show(), received.show() world.climsg.append(received) world.timestamps.append(received.time) if len(world.timestamps) >= 2: world.RTlist.append(world.timestamps[-1] - world.timestamps[-2]) get_common_logger().info("Received packet type = %s" % get_msg_type(received)) msg_traverse(world.climsg[-1]) if get_msg_type(received) == msgType: found = True # print unans for x in unans: get_common_logger().error( ("Unmatched packet type = %s" % get_msg_type(x))) get_common_logger().debug( "Received traffic (answered/unanswered): %d/%d packet(s)." % (len(ans), len(unans))) # set timestamp after sending msg if world.time is None: world.time = time.time() #world.timestamps.append(time.time()) world.srvmsg = [] if contain: assert len(world.climsg) > templen, " No response received." assert found is True, "message not found" else: assert found is False, "message found but not expected"
def remove_local_file(file_local): try: os.remove(file_local) except OSError: get_common_logger().error('File %s cannot be removed' % file_local)
def kill_bind10(): """ Kill any running bind10 instance """ get_common_logger().debug("Killing all running Bind instances") return fabric_sudo_command('pkill b10-*; sleep ' + str(SLEEP_TIME_1))
def loops(step, message_type_1, message_type_2, repeat): import importlib testsetup = importlib.import_module("misc") repeat = int(repeat) testsetup.set_world() testsetup.test_procedure(None) if repeat < 1000: x_range = 10 else: x_range = 250 world.loops["active"] = True world.scapy_verbose = 0 if message_type_1 == "SOLICIT" and message_type_2 == "ADVERTISE": # short two message exchange without saving leases. for x in range(0, repeat): client_send_msg(step, message_type_1, None, None) send_wait_for_message(step, "MAY", True, message_type_2) elif message_type_1 == "SOLICIT" and message_type_2 == "REPLY": # first save server-id option client_send_msg(step, message_type_1, None, None) send_wait_for_message(step, "MAY", True, "ADVERTISE") client_save_option(step, "server-id") # long 4 message exchange with saving leases. for x in range(1, repeat): # if x % x_range == 0: # get_common_logger().info("Message exchane no. %d", x) generate_new(step, "client") client_send_msg(step, message_type_1, None, None) send_wait_for_message(step, "MAY", True, "ADVERTISE") try: client_add_saved_option(step, False) client_copy_option(step, "IA_NA") except AssertionError: pass client_send_msg(step, "REQUEST", None, None) send_wait_for_message(step, "MAY", True, message_type_2) elif message_type_1 == "REQUEST" and message_type_2 == "REPLY": # first save server-id option client_send_msg(step, "SOLICIT", None, None) send_wait_for_message(step, "MAY", True, "ADVERTISE") client_save_option(step, "server-id") # long 4 message exchange with saving leases. for x in range(1, repeat): if x % x_range == 0: get_common_logger().info("Message exchane no. %d", x) generate_new(step, "client") client_add_saved_option(step, False) client_send_msg(step, "REQUEST", None, None) send_wait_for_message(step, "MAY", True, message_type_2) response_check_option_content(step, 13, 3, "NOT", "statuscode", "2") elif message_type_1 == "RELEASE" and message_type_2 == "REPLY": # first save server-id option client_send_msg(step, "SOLICIT", None, None) send_wait_for_message(step, "MAY", True, "ADVERTISE") client_save_option(step, "server-id") # long 4 message exchange with saving leases. for x in range(1, repeat): if x % x_range == 0: get_common_logger().info("Message exchane no. %d", x) client_add_saved_option(step, False) client_send_msg(step, "REQUEST", None, None) send_wait_for_message(step, "MAY", True, message_type_2) client_add_saved_option(step, False) client_copy_option(step, "IA_NA") client_send_msg(step, "RELEASE", None, None) send_wait_for_message(step, "MAY", True, message_type_2) #dhcpmsg.generate_new(step, "client") else: pass for x in range(0, len(world.savedmsg)): world.savedmsg[x] = []
def send_wait_for_message(step, type, presence, exp_message): """ Block until the given message is (not) received. Parameter: new: (' new', optional): Only check the output printed since last time this step was used for this process. process_name ('<name> stderr'): Name of the process to check the output of. message ('message <message>'): Output (part) to wait for. """ world.cliopts = [] #clear options, always build new message, also possible make it in client_send_msg may_flag = False #debug.recv = [] conf.use_pcap = True if str(type) in "MUST": pass elif str(type) in "MAY": may_flag = True # we needs to get it operational # problem: break test with success. (for now we can break test only with fail) else: assert False, "Invalid expected behavior: %s." % str(type) # Uncomment this to get debug.recv filled with all received messages conf.debug_match = True ans, unans = sr(world.climsg, iface = world.cfg["iface"], timeout = world.cfg["wait_interval"], nofilter = 1, verbose = world.scapy_verbose) from features.init_all import SHOW_PACKETS_FROM if SHOW_PACKETS_FROM in ['both', 'client']: world.climsg[0].show() expected_type_found = False received_names = "" world.srvmsg = [] for x in ans: a, b = x world.srvmsg.append(b) if SHOW_PACKETS_FROM in ['both', 'server']: b.show() if not world.loops["active"]: get_common_logger().info("Received packet type = %s" % get_msg_type(b)) received_names = get_msg_type(b) + " " + received_names if get_msg_type(b) == exp_message: expected_type_found = True for x in unans: get_common_logger().error(("Unmatched packet type = %s" % get_msg_type(x))) if not world.loops["active"]: get_common_logger().debug("Received traffic (answered/unanswered): %d/%d packet(s)." % (len(ans), len(unans))) if may_flag: if len(world.srvmsg) != 0: assert True, "Response received." if len(world.srvmsg) == 0: assert True, "Response not received." # stop the test... ?? elif presence: assert len(world.srvmsg) != 0, "No response received." assert expected_type_found, "Expected message " + exp_message + " not received (got " + received_names + ")" elif not presence: assert len(world.srvmsg) == 0, "Response received, not expected"
def send_wait_for_message(step, condition_type, presence, exp_message): """ Block until the given message is (not) received. Parameter: new: (' new', optional): Only check the output printed since last time this step was used for this process. process_name ('<name> stderr'): Name of the process to check the output of. message ('message <message>'): Output (part) to wait for. """ world.cliopts = [ ] # clear options, always build new message, also possible make it in client_send_msg may_flag = False #debug.recv=[] conf.use_pcap = True if str(condition_type) in "MUST": pass elif str(condition_type) in "MAY": may_flag = True # we needs to get it operational # problem: break test with success. (for now we can break test only with fail) else: assert False, "Invalid expected behavior: %s." % str(condition_type) # Uncomment this to get debug.recv filled with all received messages conf.debug_match = True apply_message_fields_changes() ans, unans = sr(world.climsg, iface=world.cfg["iface"], timeout=world.cfg["wait_interval"], nofilter=1, verbose=world.scapy_verbose) if world.f_cfg.show_packets_from in ['both', 'client']: world.climsg[0].show() expected_type_found = False received_names = "" world.srvmsg = [] for x in ans: a, b = x world.srvmsg.append(b) if world.f_cfg.show_packets_from in ['both', 'server']: b.show() if not world.loops["active"]: get_common_logger().info("Received packet type=%s" % get_msg_type(b)) received_names = get_msg_type(b) + " " + received_names if get_msg_type(b) == exp_message: expected_type_found = True for x in unans: get_common_logger().error( ("Unmatched packet type=%s" % get_msg_type(x))) if not world.loops["active"]: get_common_logger().debug( "Received traffic (answered/unanswered): %d/%d packet(s)." % (len(ans), len(unans))) if may_flag: if len(world.srvmsg) != 0: assert True, "Response received." if len(world.srvmsg) == 0: assert True, "Response not received." # stop the test... ?? elif presence: assert len(world.srvmsg) != 0, "No response received." assert expected_type_found, "Expected message " + exp_message + " not received (got " + received_names + ")" elif not presence: assert len(world.srvmsg) == 0, "Response received, not expected"
def loops(step, message_type_1, message_type_2, repeat): import importlib testsetup = importlib.import_module("misc") repeat = int(repeat) testsetup.set_world() testsetup.test_procedure(None) if repeat < 1000: x_range = 10 else: x_range = 250 world.loops["active"] = True world.scapy_verbose = 0 if message_type_1 == "SOLICIT" and message_type_2 == "ADVERTISE": # short two message exchange without saving leases. for x in range(0, repeat): generate_new(step, "client") client_does_include("Client", "client-id", None) client_does_include("Client", "IA-NA", None) client_send_msg(step, message_type_1, None, None) send_wait_for_message(step, "MAY", True, message_type_2) elif message_type_1 == "SOLICIT" and message_type_2 == "REPLY": # first save server-id option client_does_include("Client", "client-id", None) client_does_include("Client", "IA-NA", None) client_send_msg(step, message_type_1, None, None) send_wait_for_message(step, "MAY", True, "ADVERTISE") client_save_option(step, "server-id") # long 4 message exchange with saving leases. for x in range(1, repeat): # if x % x_range == 0: # get_common_logger().info("Message exchange no. %d", x) generate_new(step, "client") client_does_include("Client", "client-id", None) client_does_include("Client", "IA-NA", None) client_send_msg(step, message_type_1, None, None) send_wait_for_message(step, "MAY", True, "ADVERTISE") try: client_add_saved_option(step, False) client_copy_option(step, "IA_NA") except AssertionError: pass client_does_include("Client", "client-id", None) client_send_msg(step, "REQUEST", None, None) send_wait_for_message(step, "MAY", True, message_type_2) elif message_type_1 == "REQUEST" and message_type_2 == "REPLY": # first save server-id option client_send_msg(step, "SOLICIT", None, None) send_wait_for_message(step, "MAY", True, "ADVERTISE") client_save_option(step, "server-id") # long 4 message exchange with saving leases. for x in range(1, repeat): if x % x_range == 0: get_common_logger().info("Message exchane no. %d", x) generate_new(step, "client") client_add_saved_option(step, False) client_send_msg(step, "REQUEST", None, None) send_wait_for_message(step, "MAY", True, message_type_2) response_check_option_content(step, 13, 3, "NOT", "statuscode", "2") elif message_type_1 == "RELEASE" and message_type_2 == "REPLY": # first save server-id option client_send_msg(step, "SOLICIT", None, None) send_wait_for_message(step, "MAY", True, "ADVERTISE") client_save_option(step, "server-id") # long 4 message exchange with saving leases. for x in range(1, repeat): if x % x_range == 0: get_common_logger().info("Message exchane no. %d", x) client_add_saved_option(step, False) client_send_msg(step, "REQUEST", None, None) send_wait_for_message(step, "MAY", True, message_type_2) client_add_saved_option(step, False) client_copy_option(step, "IA_NA") client_send_msg(step, "RELEASE", None, None) send_wait_for_message(step, "MAY", True, message_type_2) #dhcpmsg.generate_new(step, "client") elif message_type_1 == "RENEW" and message_type_2 == "REPLY": # first save server-id option client_send_msg(step, "SOLICIT", None, None) send_wait_for_message(step, "MAY", True, "ADVERTISE") client_save_option(step, "server-id") # long 4 message exchange with saving leases. for x in range(1, repeat): if x % x_range == 0: get_common_logger().info("Message exchane no. %d", x) client_add_saved_option(step, False) client_send_msg(step, "REQUEST", None, None) send_wait_for_message(step, "MAY", True, message_type_2) client_add_saved_option(step, False) client_copy_option(step, "IA_NA") client_send_msg(step, "RENEW", None, None) send_wait_for_message(step, "MAY", True, message_type_2) else: pass for x in range(0, len(world.savedmsg)): world.savedmsg[x] = []