class TestIndexPool(TestCase): pool = IndexPool(8, 0) def test_01_get_next(self): self.assertEqual(self.pool.indices.bin, '00000000') for i in range(8): self.assertEqual(self.pool.get_next(), i) #to check if there's any bit left after using all 8 bits self.assertIsNone(self.pool.get_next()) def test_02_pre_allocate(self): _pool2 = IndexPool(8, 0) self.assertEqual(_pool2.indices.bin, '00000000') _pool2.pre_allocate(( 0, 1, 2, )) self.assertEqual(_pool2.indices.bin, '11100000') def test_03_release(self): self.pool.release(5) self.assertEqual(self.pool.indices.bin, '11111011') self.pool.release(10) self.assertEqual(self.pool.indices.bin, '11111011') self.pool.release(0) self.assertEqual(self.pool.indices.bin, '01111011') def test_04_check_offset(self): _offset = 5 self.pool = IndexPool(8, _offset) for i in range(8): self.assertEqual(self.pool.get_next(), _offset + i)
def __init__(self, adapter, device_id): self.log = structlog.get_logger(device_id=device_id) self.log.debug('function-entry') self.adapter = adapter self.adapter_agent = adapter.adapter_agent self.device_id = device_id self.incoming_messages = DeferredQueue() self.event_messages = DeferredQueue() self.proxy_address = None self.tx_id = 0 self._enabled = False self._omcc_version = OMCCVersion.Unknown self._total_tcont_count = 0 # From ANI-G ME self._qos_flexibility = 0 # From ONT2_G ME self._onu_indication = None self._unis = dict() # Port # -> UniPort self._port_number_pool = IndexPool(_MAXIMUM_PORT, 0) self._pon = None #TODO: probably shouldnt be hardcoded, determine from olt maybe? self._pon_port_number = 100 self.logical_device_id = None # Set up OpenOMCI environment self._onu_omci_device = None self._dev_info_loaded = False self._deferred = None self._in_sync_subscription = None self._connectivity_subscription = None self._capabilities_subscription = None
def __init__(self, adapter, device_id): kwargs = dict() super(AdtranOnuHandler, self).__init__(**kwargs) self.adapter = adapter self.adapter_agent = adapter.adapter_agent self.device_id = device_id self.log = structlog.get_logger(device_id=device_id) self.logical_device_id = None self.proxy_address = None self._enabled = False self.pm_metrics = None self.alarms = None self._mgmt_gemport_aes = False self._upstream_channel_speed = 0 self._openomci = OMCI(self, adapter.omci_agent) self._in_sync_subscription = None self._onu_port_number = 0 self._pon_port_number = 1 self._port_number_pool = IndexPool(_MAXIMUM_PORT, 0) self._unis = dict() # Port # -> UniPort self._pon = PonPort.create(self, self._pon_port_number) self._heartbeat = HeartBeat.create(self, device_id) self._deferred = None # Flow entries self._flows = dict() # OMCI resources # TODO: Some of these could be dynamically chosen self.vlan_tcis_1 = 0x900 self.mac_bridge_service_profile_entity_id = self.vlan_tcis_1 self.gal_enet_profile_entity_id = 0 # Was 0x100, but ONU seems to overwrite and use zero
def __init__(self, adapter, device_id): kwargs = dict() super(AdtranOnuHandler, self).__init__(**kwargs) self.adapter = adapter self.adapter_agent = adapter.adapter_agent self.device_id = device_id self.log = structlog.get_logger(device_id=device_id) self.logical_device_id = None self.proxy_address = None self._event_messages = None self._enabled = False self.pm_metrics = None self.alarms = None self._mgmt_gemport_aes = False self._upstream_channel_speed = 0 self._unis = dict() # Port # -> UniPort self._pons = dict() # Port # -> PonPort self._heartbeat = HeartBeat.create(self, device_id) self._deferred = None self._event_deferred = None self._omci = None self._port_number_pool = IndexPool(_MAXIMUM_PORT, 1) self._olt_created = False # True if deprecated method of OLT creating DA is used self._is_mock = False
def __init__(self, adapter, device_id): kwargs = dict() super(AdtranOnuHandler, self).__init__(**kwargs) self.adapter = adapter self.adapter_agent = adapter.adapter_agent self.device_id = device_id self.log = structlog.get_logger(device_id=device_id) self.logical_device_id = None self.proxy_address = None self._event_messages = None self._enabled = False self.pm_metrics = None self.alarms = None self._mgmt_gemport_aes = False self._upstream_channel_speed = 0 self._unis = dict() # Port # -> UniPort self._pon = None self._heartbeat = HeartBeat.create(self, device_id) self._deferred = None self._event_deferred = None # TODO: Remove next two lines if/when OpenOMCI is in the core or a container # in order to support multiple ONUs per instance self._omci_agent = OpenOMCIAgent(self.adapter_agent.core) self._omci_agent.start() self._port_number_pool = IndexPool(_MAXIMUM_PORT, 1) self._olt_created = False # True if deprecated method of OLT creating DA is used self._is_mock = False
def test_02_pre_allocate(self): _pool2 = IndexPool(8, 0) self.assertEqual(_pool2.indices.bin, '00000000') _pool2.pre_allocate(( 0, 1, 2, )) self.assertEqual(_pool2.indices.bin, '11100000')
def __init__(self, adapter, device_id): self.log = structlog.get_logger(device_id=device_id) self.log.debug('function-entry') self.adapter = adapter self.adapter_agent = adapter.adapter_agent self.parent_adapter = None self.parent_id = None self.device_id = device_id self.incoming_messages = DeferredQueue() self.event_messages = DeferredQueue() self.proxy_address = None self.tx_id = 0 self._enabled = False self.alarms = None self.pm_metrics = None self._omcc_version = OMCCVersion.Unknown self._total_tcont_count = 0 # From ANI-G ME self._qos_flexibility = 0 # From ONT2_G ME self._onu_indication = None self._unis = dict() # Port # -> UniPort self._port_number_pool = IndexPool(_MAXIMUM_PORT, 0) self._pon = None # TODO: probably shouldnt be hardcoded, determine from olt maybe? self._pon_port_number = 100 self.logical_device_id = None self._heartbeat = HeartBeat.create(self, device_id) # Set up OpenOMCI environment self._onu_omci_device = None self._dev_info_loaded = False self._deferred = None self._in_sync_subscription = None self._connectivity_subscription = None self._capabilities_subscription = None self.mac_bridge_service_profile_entity_id = 0x201 self.gal_enet_profile_entity_id = 0x1 self._tp_service_specific_task = dict() self._tech_profile_download_done = dict() # Initialize KV store client self.args = registry('main').get_args() if self.args.backend == 'etcd': host, port = self.args.etcd.split(':', 1) self.kv_client = EtcdStore( host, port, TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX) elif self.args.backend == 'consul': host, port = self.args.consul.split(':', 1) self.kv_client = ConsulStore( host, port, TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX) else: self.log.error('Invalid-backend') raise Exception("Invalid-backend-for-kv-store") # Handle received ONU event messages reactor.callLater(0, self.handle_onu_events)
def __init__(self, agent, device_id, tasks, advertise_events=False, states=DEFAULT_STATES, transitions=DEFAULT_TRANSITIONS, initial_state='disabled', timeout_delay=DEFAULT_RETRY, tick_delay=DEFAULT_TICK_DELAY, interval_skew=DEFAULT_INTERVAL_SKEW, collect_attempts=DEFAULT_COLLECT_ATTEMPTS, create_attempts=DEFAULT_CREATE_ATTEMPTS): """ Class initialization :param agent: (OpenOmciAgent) Agent :param device_id: (str) ONU Device ID :param tasks: (dict) Tasks to run :param advertise_events: (bool) Advertise events on OpenOMCI Event Bus :param states: (list) List of valid states :param transitions: (dict) Dictionary of triggers and state changes :param initial_state: (str) Initial state machine state :param timeout_delay: (int/float) Number of seconds after a timeout to pause :param tick_delay: (int/float) Collection poll check delay while idle :param interval_skew: (int/float) Seconds to randomly skew the next interval collection to spread out requests for PM intervals :param collect_attempts: (int) Max requests for a single PM interval before fail :param create_attempts: (int) Max attempts to create PM Managed entities before stopping state machine """ self.log = structlog.get_logger(device_id=device_id) self._agent = agent self._device_id = device_id self._device = None self._pm_config = None self._timeout_delay = timeout_delay self._tick_delay = tick_delay self._interval_skew = interval_skew self._collect_attempts = collect_attempts self._create_attempts = create_attempts self._sync_time_task = tasks['sync-time'] self._get_interval_task = tasks['collect-data'] self._create_pm_task = tasks['create-pm'] self._delete_pm_task = tasks['delete-pm'] self._advertise_events = advertise_events self._omci_cc_subscriptions = { # RxEvent.enum -> Subscription Object RxEvent.MIB_Reset: None, RxEvent.Create: None, RxEvent.Delete: None } self._omci_cc_sub_mapping = { RxEvent.MIB_Reset: self.on_mib_reset_response, RxEvent.Create: self.on_create_response, RxEvent.Delete: self.on_delete_response, } self._me_watch_list = { MacBridgePortConfigurationData.class_id: { 'create-delete': self.add_remove_enet_frame_pm, 'instances': dict() # BP entity_id -> (PM class_id, PM entity_id) } } self._deferred = None self._task_deferred = None self._current_task = None self._add_me_deferred = None self._delete_me_deferred = None self._next_interval = None self._enet_entity_id = IndexPool(1024, 1) self._add_pm_me_retry = 0 # (Class ID, Instance ID) -> Collect attempts remaining self._pm_me_collect_retries = dict() self._pm_me_extended_info = dict() self._add_pm_me = dict( ) # (pm cid, pm eid) -> (me cid, me eid, upstream) self._del_pm_me = set() # Pollable PM items # Note that some items the KPI extracts are not listed below. These are the # administrative states, operational states, and sensed ethernet type. The values # in the MIB database should be accurate for these items. self._ani_g_items = ["optical_signal_level", "transmit_optical_level"] self._next_poll_time = datetime.utcnow() self._poll_interval = 60 # TODO: Fixed at once a minute # Statistics and attributes # TODO: add any others if it will support problem diagnosis # Set up state machine to manage states self.machine = Machine(model=self, states=states, transitions=transitions, initial=initial_state, queued=True, ignore_invalid_triggers=True, name='{}-{}'.format(self.__class__.__name__, device_id)) try: import logging logging.getLogger('transitions').setLevel(logging.WARNING) except Exception as e: self.log.exception('log-level-failed', e=e)
def test_04_check_offset(self): _offset = 5 self.pool = IndexPool(8, _offset) for i in range(8): self.assertEqual(self.pool.get_next(), _offset + i)
def __init__(self, agent, device_id, tasks, advertise_events=False, states=DEFAULT_STATES, transitions=DEFAULT_TRANSITIONS, initial_state='disabled', timeout_delay=DEFAULT_RETRY, tick_delay=DEFAULT_TICK_DELAY, interval_skew=DEFAULT_INTERVAL_SKEW, collect_attempts=DEFAULT_COLLECT_ATTEMPTS): """ Class initialization :param agent: (OpenOmciAgent) Agent :param device_id: (str) ONU Device ID :param tasks: (dict) Tasks to run :param advertise_events: (bool) Advertise events on OpenOMCI Event Bus :param states: (list) List of valid states :param transitions: (dict) Dictionary of triggers and state changes :param initial_state: (str) Initial state machine state :param timeout_delay: (int/float) Number of seconds after a timeout to pause :param tick_delay: (int/float) Collection poll check delay while idle :param interval_skew: (int/float) Seconds to randomly skew the next interval collection to spread out requests for PM intervals :param collect_attempts: (int) Max requests for a single PM interval before fail """ self.log = structlog.get_logger(device_id=device_id) self._agent = agent self._device_id = device_id self._device = None self._pm_config = None self._timeout_delay = timeout_delay self._tick_delay = tick_delay self._interval_skew = interval_skew self._collect_attempts = collect_attempts self._sync_time_task = tasks['sync-time'] self._get_interval_task = tasks['collect-data'] self._create_pm_task = tasks['create-pm'] self._delete_pm_task = tasks['delete-pm'] self._advertise_events = advertise_events self._omci_cc_subscriptions = { # RxEvent.enum -> Subscription Object RxEvent.MIB_Reset: None, RxEvent.Create: None, RxEvent.Delete: None } self._omci_cc_sub_mapping = { RxEvent.MIB_Reset: self.on_mib_reset_response, RxEvent.Create: self.on_create_response, RxEvent.Delete: self.on_delete_response, } self._me_watch_list = { MacBridgePortConfigurationData.class_id: { 'create-delete': self.add_remove_enet_frame_pm, 'instances': dict() # BP entity_id -> (PM class_id, PM entity_id) } } self._deferred = None self._task_deferred = None self._current_task = None self._add_me_deferred = None self._delete_me_deferred = None self._next_interval = None self._enet_entity_id = IndexPool(1024, 1) # (Class ID, Instance ID) -> Collect attempts remaining self._pm_me_collect_retries = dict() self._add_pm_me = dict( ) # (pm cid, pm eid) -> (me cid, me eid, upstream) self._del_pm_me = set() # Statistics and attributes # TODO: add any others if it will support problem diagnosis # Set up state machine to manage states self.machine = Machine(model=self, states=states, transitions=transitions, initial=initial_state, queued=True, ignore_invalid_triggers=True, name='{}-{}'.format(self.__class__.__name__, device_id))