def start_migration(): print "Start migration..." # bring down the interfaces at ovs-1 print "bring down the interfaces in ovs-1" remote_cmd.ssh_run_cmd(ovs1_IP, "sudo sh interface-down.sh") for connection in core.openflow._connections.values(): if connection.dpid == oldswitch_dpid: connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request())) log.debug("Sent %i flow/port stats request(s)", len(core.openflow._connections))
def _handle_flow_ready(event): if event.ofp.xid != 0x80000000: return log.debug("barrier msg received from %s: ", event.connection.dpid) log.info("install drop rule for 1s") _drop(1, event.connection, 1) _drop(1, event.connection, 2) # bring up the interfaces at ovs-2 print "bring up the interfaces in ovs-2" remote_cmd.ssh_run_cmd(ovs2_IP, "sudo sh interface-up.sh")
def start_migration(): log.info("Start migration...") global start_time start_time = time.time() log.info('move ovs1') log.info('bring down the interfaces in ovs1') remote_cmd.ssh_run_cmd(ovs1_IP, 'sudo ifconfig eth2 down;sudo ifconfig eth3 down') log.info('request flow tables in ovs-1') for connection in core.openflow._connections.values(): if connection.dpid == ovs1_dpid: _request_flow_info(connection)
def start_migration(): print "Start migration..." # bring down the interfaces at ovs-1 print 'bring down the interfaces in ovs-1' remote_cmd.ssh_run_cmd(ovs1_IP,'sudo sh interface-down.sh') log.info("install drop rule for 1s") for connection in core.openflow._connections.values(): if connection.dpid == newswitch_dpid: _drop(1, connection, 1) _drop(1, connection, 2) # bring up the interfaces at ovs-2 print 'bring up the interfaces in ovs-2' remote_cmd.ssh_run_cmd(ovs2_IP,'sudo sh interface-up.sh')
def _exp_prep(): # bring up the interfaces at ovs-1 and ovs-3 print 'bring up the interfaces in ovs-1 and ovs-3' remote_cmd.ssh_run_cmd(ovs1_IP,'sudo sh interface-up.sh') remote_cmd.ssh_run_cmd(ovs3_IP,'sudo sh interface-up.sh') # bring down the interfaces at ovs-4 and ovs-6 print 'bring down the interfaces in ovs-4 and ovs-6' remote_cmd.ssh_run_cmd(ovs4_IP,'sudo sh interface-down.sh') remote_cmd.ssh_run_cmd(ovs6_IP,'sudo sh interface-down.sh')
def _handle_flow_ready(event): if event.ofp.xid != 0x80000000: return log.debug("barrier msg received from %s: ", event.connection.dpid) global barrier_count barrier_count = barrier_count+1 if barrier_count == 3: log.info("install drop rule for 1s") for connection in core.openflow._connections.values(): if connection.dpid == ovs4_dpid or connection.dpid == ovs6_dpid: _drop(4, connection, 1) _drop(4, connection, 2) # bring down the interfaces at ovs-1 and ovs-3 print 'bring down the interfaces in ovs-1' remote_cmd.ssh_run_cmd(ovs1_IP,'sudo sh interface-down.sh') remote_cmd.ssh_run_cmd(ovs3_IP,'sudo sh interface-down.sh') # bring up the interfaces at ovs-4 and ovs-6 print 'bring up the interfaces in ovs-4 and ovs-6' _threading_run_cmd(ovs4_IP,'sudo sh interface-up.sh') _threading_run_cmd(ovs6_IP,'sudo sh interface-up.sh')
def start_migration(): print "Start migration..." # bring down the interfaces at ovs-1 and ovs-3 print 'bring down the interfaces in ovs-1' remote_cmd.ssh_run_cmd(ovs1_IP,'sudo sh interface-down.sh') remote_cmd.ssh_run_cmd(ovs3_IP,'sudo sh interface-down.sh') log.info("install drop rule for 1s") for connection in core.openflow._connections.values(): if connection.dpid == ovs4_dpid or connection.dpid == ovs6_dpid: print connection.dpid _drop(2, connection, 1) _drop(2, connection, 2) #_drop(2, connection, 3) print 'bring up the interfaces in ovs-4 and ovs-6' remote_cmd.ssh_run_cmd(ovs4_IP,'sudo sh interface-up.sh') remote_cmd.ssh_run_cmd(ovs6_IP,'sudo sh interface-up.sh')
def _handle_flow_ready(event): if event.ofp.xid != 0x80000000: return log.debug("barrier msg received from %s: ", event.connection.dpid) if event.connection.dpid == ovs1_dpid: log.info('bring up tunnel interfaces in ovs-1 and ovs-4') remote_cmd.ssh_run_cmd(ovs1_IP, 'sudo ifconfig eth1 up') remote_cmd.ssh_run_cmd(ovs4_IP, 'sudo ifconfig eth1 up') log.info('redirect at gateway 1 and 2 to vn2') for connection in core.openflow._connections.values(): if connection.dpid == g1_dpid: _gw_to_vn(connection, 1, 3, 2) elif connection.dpid == g2_dpid: _gw_to_vn(connection, 1, 3, 2) log.info('movs ovs-2') log.debug('bring down interface in ovs-2') remote_cmd.ssh_run_cmd(ovs2_IP,'sudo ifconfig eth2 down') log.info('request flow tables in ovs2') for connection in core.openflow._connections.values(): if connection.dpid == ovs2_dpid: _request_flow_info(connection) elif event.connection.dpid == ovs2_dpid: log.info('bring up the interfaces in ovs-2 and ovs-5') remote_cmd.ssh_run_cmd(ovs2_IP,'sudo ifconfig eth1 up') remote_cmd.ssh_run_cmd(ovs5_IP,'sudo ifconfig eth1 up') log.info('bring down the interaces in ovs-4') #remote_cmd.ssh_run_cmd(ovs4_IP,'sudo ifconfig eth1 down') log.info('move ovs-3') log.debug('bring down the interfaces on ovs-3') remote_cmd.ssh_run_cmd(ovs3_IP,'sudo ifconfig eth1 down') log.info('request flow tables on ovs3') for connection in core.openflow._connections.values(): if connection.dpid == ovs3_dpid: _request_flow_info(connection) elif event.connection.dpid == ovs3_dpid: log.info('bring down the interaces in ovs-5') #remote_cmd.ssh_run_cmd(ovs4_IP,'sudo ifconfig eth1 down') log.info('redirect at gateway 3 to vn2') for connection in core.openflow._connections.values(): if connection.dpid == g3_dpid: _gw_to_vn(connection, 1, 3, 2) log.info('migration finished') global start_time migration_time = time.time() - start_time log.info("%s seconds", migration_time)
def _dump_flow(host, cmd): remote_cmd.ssh_run_cmd(host, cmd)
def _config_sw_interface(): print 'bring down interfaces to tunnel switch on vn-1' remote_cmd.ssh_run_cmd(ovs1_IP, 'sudo ifconfig eth1 down;sudo ifconfig eth2 up;sudo ifconfig eth3 up') remote_cmd.ssh_run_cmd(ovs2_IP, 'sudo ifconfig eth1 down;sudo ifconfig eth2 up') remote_cmd.ssh_run_cmd(ovs3_IP, 'sudo ifconfig eth2 down;sudo ifconfig eth1 up') print 'bring down interfaces to tunnel switch on vn-2' remote_cmd.ssh_run_cmd(ovs4_IP, 'sudo ifconfig eth1 down') remote_cmd.ssh_run_cmd(ovs5_IP, 'sudo ifconfig eth1 down') remote_cmd.ssh_run_cmd(ovs6_IP, 'sudo ifconfig eth2 down')
import remote_cmd import time def _write_to_log(log_file_dir, data): if log_file_dir == '': return target = open(log_file_dir, 'a') target.write(str(data)) target.write('\n') target.close() gw_1 = '128.163.232.71' for i in range(0, 50): start_time = time.time() cmd = 'sudo python ssh_cmd.py ' + str(start_time) remote_cmd.ssh_run_cmd(gw_1, cmd) print("--- %s seconds ---" % (time.time() - start_time)) _write_to_log('time.log', "%s" % (time.time() - start_time))
def _iperf(IP, cmd): print 'start iperf' remote_cmd.ssh_run_cmd(IP, cmd)