def test(self): # add dummy flows to test removal when there are already some flows in operational self.__set_active_map(MapNames.DUMMY) self.adder = FlowAdderThread(self, 0, self.host, self.port, self.net, MultiTest.flows + 1, MultiTest.flows + 11) self.adder.run() self.__set_active_map(MapNames.TEST) self.adder = FlowAdderThread(self, 1, self.host, self.port, self.net, 1, MultiTest.flows + 1) self.adder.run() # if we didn't manage to get any flows on controller there is no point doing test assert len(MultiTest.active_map) > 0, ('Stored flows should be greater than 0, actual is {0}'.format(len(MultiTest.active_map))) # check numer of flows before deletion MultiTest.log.debug('{0} flows are stored by results from threads, {1} errors'.format(len(MultiTest.active_map), MultiTest.total_errors)) MultiTest.log.debug('{0} flows are stored in controller config'.format(self.check_config_flows(self.host, self.port, self.active_map))) MultiTest.log.info('{0} flows are stored in controller operational'.format(self.check_oper_flows_loop(self.host, self.port, self.active_map))) self.remover = FlowRemoverThread(self, 0, self.host, self.port, self.net, list(MultiTest.active_map.items())) self.remover.run() MultiTest.log.info('\n\n---------- preparation finished, running test ----------') # check and test after deletion flows_oper_after = self.check_oper_flows_loop(self.host, self.port, self.active_map) MultiTest.log.debug('{0} flows are stored in controller config'.format(self.check_config_flows(self.host, self.port, self.active_map))) MultiTest.log.info('{0} flows are stored in controller operational'.format(flows_oper_after)) # check if we have managed to delete all test if len(MultiTest.active_map) <> 0: MultiTest.log.warning('Not all flows added during test have been deleted, ids of remaining flows are: {0}'.format(sorted(MultiTest.active_map))) # if we didn't manage to get any flows on controller there is no point doing test assert flows_oper_after == len(MultiTest.active_map), 'Number of flows added during test stored in operational should be {0}, is {1}'.format(len(MultiTest.active_map), flows_oper_after)
def test(self): # add dummy flows to test removal when there are already some flows in operational self.__set_active_map(MapNames.DUMMY) self.adder = FlowAdderThread(self, 0, self.host, self.port, self.net, MultiTest.flows + 1, MultiTest.flows + 11) self.adder.run() self.__set_active_map(MapNames.TEST) self.adder = FlowAdderThread(self, 1, self.host, self.port, self.net, 1, MultiTest.flows + 1) self.adder.run() # if we didn't manage to get any flows on controller there is no point doing test assert len(MultiTest.active_map) > 0, ( 'Stored flows should be greater than 0, actual is {0}'.format( len(MultiTest.active_map))) # check numer of flows before deletion MultiTest.log.debug( '{0} flows are stored by results from threads, {1} errors'.format( len(MultiTest.active_map), MultiTest.total_errors)) MultiTest.log.debug('{0} flows are stored in controller config'.format( self.check_config_flows(self.host, self.port, self.active_map))) MultiTest.log.info( '{0} flows are stored in controller operational'.format( self.check_oper_flows_loop(self.host, self.port, self.active_map))) self.remover = FlowRemoverThread(self, 0, self.host, self.port, self.net, list(MultiTest.active_map.items())) self.remover.run() MultiTest.log.info( '\n\n---------- preparation finished, running test ----------') # check and test after deletion flows_oper_after = self.check_oper_flows_loop(self.host, self.port, self.active_map) MultiTest.log.debug('{0} flows are stored in controller config'.format( self.check_config_flows(self.host, self.port, self.active_map))) MultiTest.log.info( '{0} flows are stored in controller operational'.format( flows_oper_after)) # check if we have managed to delete all test if len(MultiTest.active_map) <> 0: MultiTest.log.warning( 'Not all flows added during test have been deleted, ids of remaining flows are: {0}' .format(sorted(MultiTest.active_map))) # if we didn't manage to get any flows on controller there is no point doing test assert flows_oper_after == len( MultiTest.active_map ), 'Number of flows added during test stored in operational should be {0}, is {1}'.format( len(MultiTest.active_map), flows_oper_after)
def __setup_threads(self): if in_args.threads is not None: self.threads_count = int(in_args.threads) for i in range(0, self.threads_count): t = FlowAdderThread(self, i, self.host, self.port, self.net,\ flows_ids_from=i*MultiTest.flows + 1, flows_ids_to=i*MultiTest.flows + MultiTest.flows) self.thread_pool.append(t)
def __setup_threads(self): if in_args.threads is not None: self.threads_count = int(in_args.threads) for i in range(0, self.threads_count): #thread will have predetermined flows id to avoid using shared resource t = FlowAdderThread(i, self.host, self.port, self.net, flows_ids_from=i * MultiTest.flows + 1, flows_ids_to=(i + 1) * MultiTest.flows + 1) self.thread_pool.append(t)
class MultiTest(unittest.TestCase): log = logging.getLogger('MultiTest') total_errors = 0 total_flows = 0 ids = [] def setUp(self): MultiTest.log.info('setUp') self.threads_count = 50 self.thread_pool = list() self.__start_MN() self.__setup_threads() self.__run_threads() def tearDown(self): MultiTest.log.info('tearDown') self.net.stop() @staticmethod def inc_error(value=1): MultiTest.total_errors += value @staticmethod def inc_flow(value=1): MultiTest.total_flows += 1 @staticmethod def add_flow_id(flow_id=None): if (flow_id > None) : MultiTest.ids.append(flow_id) def __start_MN(self): self.net = MininetTools.create_network(self.host, self.mn_port) self.net.start() MultiTest.log.info('mininet stared') MultiTest.log.info('waiting {0} seconds...'.format(WAIT_TIME)) time.sleep(WAIT_TIME) def test(self): # add dummy flows to test removal when there are already some flows in operational self.__set_active_map(MapNames.DUMMY) self.adder = FlowAdderThread(self, 0, self.host, self.port, self.net, MultiTest.flows + 1, MultiTest.flows + 11) self.adder.run() self.__set_active_map(MapNames.TEST) self.adder = FlowAdderThread(self, 1, self.host, self.port, self.net, 1, MultiTest.flows + 1) self.adder.run() # if we didn't manage to get any flows on controller there is no point doing test assert len(MultiTest.active_map) > 0, ('Stored flows should be greater than 0, actual is {0}'.format(len(MultiTest.active_map))) # check numer of flows before deletion MultiTest.log.debug('{0} flows are stored by results from threads, {1} errors'.format(len(MultiTest.active_map), MultiTest.total_errors)) MultiTest.log.debug('{0} flows are stored in controller config'.format(self.check_config_flows(self.host, self.port, self.active_map))) MultiTest.log.info('{0} flows are stored in controller operational'.format(self.check_oper_flows_loop(self.host, self.port, self.active_map))) self.remover = FlowRemoverThread(self, 0, self.host, self.port, self.net, list(MultiTest.active_map.items())) self.remover.run() MultiTest.log.info('\n\n---------- preparation finished, running test ----------') # check and test after deletion flows_oper_after = self.check_oper_flows_loop(self.host, self.port, self.active_map) MultiTest.log.debug('{0} flows are stored in controller config'.format(self.check_config_flows(self.host, self.port, self.active_map))) MultiTest.log.info('{0} flows are stored in controller operational'.format(flows_oper_after)) # check if we have managed to delete all test if len(MultiTest.active_map) <> 0: MultiTest.log.warning('Not all flows added during test have been deleted, ids of remaining flows are: {0}'.format(sorted(MultiTest.active_map))) # if we didn't manage to get any flows on controller there is no point doing test assert flows_oper_after == len(MultiTest.active_map), 'Number of flows added during test stored in operational should be {0}, is {1}'.format(len(MultiTest.active_map), flows_oper_after) def __setup_threads(self): if in_args.threads is not None: self.threads_count = int(in_args.threads) for i in range(0, self.threads_count): #thread will have predetermined flows id to avoid using shared resource t = FlowAdderThread(i, self.host, self.port, self.net, flows_ids_from=i*MultiTest.flows + 1, flows_ids_to=(i+1)*MultiTest.flows + 1) self.thread_pool.append(t) def __run_threads(self): # start threads for t in self.thread_pool: t.start() # wait for them to finish for t in self.thread_pool: t.join()
class MultiTest(unittest.TestCase): log = logging.getLogger('MultiTest') total_errors = 0 total_flows = 0 ids = [] def setUp(self): MultiTest.log.info('setUp') self.threads_count = 50 self.thread_pool = list() self.__start_MN() self.__setup_threads() self.__run_threads() def tearDown(self): MultiTest.log.info('tearDown') self.net.stop() @staticmethod def inc_error(value=1): MultiTest.total_errors += value @staticmethod def inc_flow(value=1): MultiTest.total_flows += 1 @staticmethod def add_flow_id(flow_id=None): if (flow_id > None): MultiTest.ids.append(flow_id) def __start_MN(self): self.net = MininetTools.create_network(self.host, self.mn_port) self.net.start() MultiTest.log.info('mininet stared') MultiTest.log.info('waiting {0} seconds...'.format(WAIT_TIME)) time.sleep(WAIT_TIME) def test(self): # add dummy flows to test removal when there are already some flows in operational self.__set_active_map(MapNames.DUMMY) self.adder = FlowAdderThread(self, 0, self.host, self.port, self.net, MultiTest.flows + 1, MultiTest.flows + 11) self.adder.run() self.__set_active_map(MapNames.TEST) self.adder = FlowAdderThread(self, 1, self.host, self.port, self.net, 1, MultiTest.flows + 1) self.adder.run() # if we didn't manage to get any flows on controller there is no point doing test assert len(MultiTest.active_map) > 0, ( 'Stored flows should be greater than 0, actual is {0}'.format( len(MultiTest.active_map))) # check numer of flows before deletion MultiTest.log.debug( '{0} flows are stored by results from threads, {1} errors'.format( len(MultiTest.active_map), MultiTest.total_errors)) MultiTest.log.debug('{0} flows are stored in controller config'.format( self.check_config_flows(self.host, self.port, self.active_map))) MultiTest.log.info( '{0} flows are stored in controller operational'.format( self.check_oper_flows_loop(self.host, self.port, self.active_map))) self.remover = FlowRemoverThread(self, 0, self.host, self.port, self.net, list(MultiTest.active_map.items())) self.remover.run() MultiTest.log.info( '\n\n---------- preparation finished, running test ----------') # check and test after deletion flows_oper_after = self.check_oper_flows_loop(self.host, self.port, self.active_map) MultiTest.log.debug('{0} flows are stored in controller config'.format( self.check_config_flows(self.host, self.port, self.active_map))) MultiTest.log.info( '{0} flows are stored in controller operational'.format( flows_oper_after)) # check if we have managed to delete all test if len(MultiTest.active_map) <> 0: MultiTest.log.warning( 'Not all flows added during test have been deleted, ids of remaining flows are: {0}' .format(sorted(MultiTest.active_map))) # if we didn't manage to get any flows on controller there is no point doing test assert flows_oper_after == len( MultiTest.active_map ), 'Number of flows added during test stored in operational should be {0}, is {1}'.format( len(MultiTest.active_map), flows_oper_after) def __setup_threads(self): if in_args.threads is not None: self.threads_count = int(in_args.threads) for i in range(0, self.threads_count): #thread will have predetermined flows id to avoid using shared resource t = FlowAdderThread(i, self.host, self.port, self.net, flows_ids_from=i * MultiTest.flows + 1, flows_ids_to=(i + 1) * MultiTest.flows + 1) self.thread_pool.append(t) def __run_threads(self): # start threads for t in self.thread_pool: t.start() # wait for them to finish for t in self.thread_pool: t.join()
class MultiTest(unittest.TestCase, TestClassAdd, TestClassRemove, CheckConfigFlowsComponent, CheckOperFlowsComponent): log = logging.getLogger('MultiTest') total_errors = 0 id_maps = dict() active_map = dict() def setUp(self): MultiTest.log.info('test setup...') self.__start_MN() MultiTest.id_maps[MapNames.TEST] = dict() MultiTest.id_maps[MapNames.DUMMY] = dict() MultiTest.active_map = MultiTest.id_maps[MapNames.TEST] def tearDown(self): MultiTest.log.info('test cleanup...') self.__set_active_map(MapNames.DUMMY) self.remover = FlowRemoverThread(self, 1, self.host, self.port, self.net, list(MultiTest.active_map.items())) self.remover.run() for k, v in MultiTest.id_maps.items(): if len(v) > 0: MultiTest.log.warning('not all flows were deleted, remaining test flows: {0}, from map: {1}'.format(len(v),k)) def __set_active_map(self, key): try: MultiTest.active_map = MultiTest.id_maps[key] except KeyError as e: MultiTest.log.warning('Error switching between map ids: {0}'.format(str(e))) def inc_error(self, value=1): MultiTest.total_errors += value def inc_flow(self, flow_id= None, cookie_id=1): if flow_id is not None and cookie_id is not None: #we dont care about actual value, just need to store flow_id as unique identifier MultiTest.active_map[flow_id] = flow_id def delete_flow_from_map(self, flow_id, cookie_id=None): del MultiTest.active_map[flow_id] def __start_MN(self): self.net = MininetTools.create_network(self.host, self.mn_port) self.net.start() MultiTest.log.info('mininet stared') MultiTest.log.info('waiting {0} seconds...'.format(WAIT_TIME)) time.sleep(WAIT_TIME) def test(self): # add dummy flows to test removal when there are already some flows in operational self.__set_active_map(MapNames.DUMMY) self.adder = FlowAdderThread(self, 0, self.host, self.port, self.net, MultiTest.flows + 1, MultiTest.flows + 11) self.adder.run() self.__set_active_map(MapNames.TEST) self.adder = FlowAdderThread(self, 1, self.host, self.port, self.net, 1, MultiTest.flows + 1) self.adder.run() # if we didn't manage to get any flows on controller there is no point doing test assert len(MultiTest.active_map) > 0, ('Stored flows should be greater than 0, actual is {0}'.format(len(MultiTest.active_map))) # check numer of flows before deletion MultiTest.log.debug('{0} flows are stored by results from threads, {1} errors'.format(len(MultiTest.active_map), MultiTest.total_errors)) MultiTest.log.debug('{0} flows are stored in controller config'.format(self.check_config_flows(self.host, self.port, self.active_map))) MultiTest.log.info('{0} flows are stored in controller operational'.format(self.check_oper_flows_loop(self.host, self.port, self.active_map))) self.remover = FlowRemoverThread(self, 0, self.host, self.port, self.net, list(MultiTest.active_map.items())) self.remover.run() MultiTest.log.info('\n\n---------- preparation finished, running test ----------') # check and test after deletion flows_oper_after = self.check_oper_flows_loop(self.host, self.port, self.active_map) MultiTest.log.debug('{0} flows are stored in controller config'.format(self.check_config_flows(self.host, self.port, self.active_map))) MultiTest.log.info('{0} flows are stored in controller operational'.format(flows_oper_after)) # check if we have managed to delete all test if len(MultiTest.active_map) <> 0: MultiTest.log.warning('Not all flows added during test have been deleted, ids of remaining flows are: {0}'.format(sorted(MultiTest.active_map))) # if we didn't manage to get any flows on controller there is no point doing test assert flows_oper_after == len(MultiTest.active_map), 'Number of flows added during test stored in operational should be {0}, is {1}'.format(len(MultiTest.active_map), flows_oper_after)