def proxy_address(self): if self._proxy_address is None: from voltha.protos.device_pb2 import Device device_id = self.olt.device_id if self.olt.autoactivate: self._proxy_address = Device.ProxyAddress( device_id=device_id, channel_id=self.onu_vid, channel_group_id=self.pon.pon_id, onu_id=self.onu_id) else: try: v_ont_ani = self._vont_ani voltha_core = self.olt.adapter_agent.core xpon_agent = voltha_core.xpon_agent channel_group_id = xpon_agent.get_channel_group_for_vont_ani( v_ont_ani) parent_chnl_pair_id = xpon_agent.get_port_num( device_id, v_ont_ani.data.preferred_chanpair) self._proxy_address = Device.ProxyAddress( device_id=device_id, channel_group_id=channel_group_id, channel_id=parent_chnl_pair_id, channel_termination=v_ont_ani.data.preferred_chanpair, onu_id=self.onu_id, onu_session_id=self.onu_id) except Exception: pass return self._proxy_address
def _detect_onus(self, device): # send out get 'links' to the OLT device olt_mac = device.mac_address links_frame = self._make_links_frame(mac_address=olt_mac) self.io_port.send(links_frame) while True: response = yield self.incoming_queues[olt_mac].get() # verify response and if not the expected response if 1: # TODO check if it is really what we expect, and wait if not break jdev = json.loads(response.payload.payload.body.load) onu_mac = '' for macid in jdev['results']: if macid['macid'] is None: log.info('MAC ID is NONE %s' % str(macid['macid'])) elif macid['macid'][:6].upper() == SUMITOMO_ELECTRIC_INDUSTRIES_OUI: onu_mac = macid['macid'] log.info('SUMITOMO mac address %s' % str(macid['macid'])) log.info('activate-olt-for-onu-%s' % onu_mac) # Convert from string to colon separated form onu_mac = ':'.join(s.encode('hex') for s in onu_mac.decode('hex')) vlan_id = self._olt_side_onu_activation(int(macid['macid'][-4:-2], 16)) self.adapter_agent.child_device_detected( parent_device_id=device.id, parent_port_no=1, child_device_type='dpoe_onu', mac_address = onu_mac, proxy_address=Device.ProxyAddress( device_id=device.id, channel_id=vlan_id ), vlan=vlan_id ) else: onu_mac = '000c' + macid.get('macid', 'e2000000')[4:] log.info('activate-olt-for-onu-%s' % onu_mac) # Convert from string to colon separated form onu_mac = ':'.join(s.encode('hex') for s in onu_mac.decode('hex')) vlan_id = self._olt_side_onu_activation(int(macid['macid'][-4:-2], 16)) self.adapter_agent.child_device_detected( parent_device_id=device.id, parent_port_no=1, child_device_type='tibit_onu', mac_address = onu_mac, proxy_address=Device.ProxyAddress( device_id=device.id, channel_id=vlan_id ), vlan=vlan_id ) # also record the vlan_id -> (device_id, logical_device_id, linkid) for # later use. The linkid is the macid returned. self.vlan_to_device_ids[vlan_id] = (device.id, device.parent_id, macid.get('macid', 0)) # Give the ONUs a chance to arrive before starting metric collection reactor.callLater(5.0, self.start_kpi_collection, device.id)
def add_onu_device(self, parent_device_id, parent_port_no, vendor_id, proxy_address, admin_state, **kw): device_type = None for dt in self.root_proxy.get('/device_types'): if (dt.vendor_id == vendor_id or vendor_id in dt.vendor_ids) and \ dt.id.endswith("_onu"): device_type = dt assert device_type is not None # we create new ONU device objects and insert them into the config device = Device( id=create_cluster_device_id(self.core.core_store_id), # id=uuid4().hex[:12], type=device_type.id, vendor_id=vendor_id, parent_id=parent_device_id, parent_port_no=parent_port_no, proxy_address=proxy_address, admin_state=admin_state, adapter=device_type.adapter, **kw) self._make_up_to_date('/devices', device.id, device) topic = self._gen_tx_proxy_address_topic(proxy_address) self._tx_event_subscriptions[topic] = self.event_bus.subscribe( topic, lambda t, m: self._send_proxied_message(proxy_address, m))
def add_olt_device(self): device = Device(type='ponsim_olt', host_and_port=self.olt_host_and_port) device = self.post('/api/v1/devices', MessageToDict(device), expected_http_code=200) return device['id']
def _provision_simulated_olt_grpc(self, stub): device = Device( type='simulated_olt', mac_address='00:00:00:00:00:01' ) device = stub.CreateDevice(device) return device
def add_onu_device(self, intf_id, port_no, onu_id, serial_number): self.log.info("Adding ONU", port_no=port_no, onu_id=onu_id, serial_number=serial_number) # NOTE - channel_id of onu is set to intf_id proxy_address = Device.ProxyAddress(device_id=self.device_id, channel_id=intf_id, onu_id=onu_id, onu_session_id=onu_id) self.log.debug("Adding ONU", proxy_address=proxy_address) serial_number_str = self.stringify_serial_number(serial_number) self.adapter_agent.add_onu_device( parent_device_id=self.device_id, parent_port_no=port_no, vendor_id=serial_number.vendor_id, proxy_address=proxy_address, root=True, serial_number=serial_number_str, admin_state=AdminState. ENABLED #, **{'vlan':4091} # magic still maps to brcm_openomci_onu.pon_port.BRDCM_DEFAULT_VLAN )
def add_olt_device(self, host): device = Device(type='ponsim_olt', host_and_port='{}:50060'.format(host)) device = self.post('/api/v1/devices', MessageToDict(device), expected_http_code=200) return device
def add_device(self): return self.post('/api/v1/devices', MessageToDict(Device( type=device_type, host_and_port=host_and_port )), expected_http_code=200)
def add_onu_device(self, intf_id, port_no, onu_id, serial_number): self.log.info("Adding ONU", port_no=port_no, onu_id=onu_id, serial_number=serial_number) # NOTE - channel_id of onu is set to intf_id proxy_address = Device.ProxyAddress(device_id=self.device_id, channel_id=intf_id, onu_id=onu_id, onu_session_id=onu_id) self.log.info("Adding ONU", proxy_address=proxy_address) serial_number_str = ''.join([ serial_number.vendor_id, self.stringify_vendor_specific(serial_number.vendor_specific) ]) self.adapter_agent.add_onu_device( parent_device_id=self.device_id, parent_port_no=port_no, vendor_id=serial_number.vendor_id, proxy_address=proxy_address, root=True, serial_number=serial_number_str, admin_state=AdminState.ENABLED) # FIXME
def add_device(self): device = Device( type='simulated_olt', ) device = self.post('/api/v1/devices', MessageToDict(device), expected_http_code=200) return device
def _add_olt_device_rest(self, grpc=None): device = Device( type='simulated_olt', mac_address='00:00:00:00:00:01' ) device = self.post('/api/v1/devices', MessageToDict(device), expected_http_code=200) return device['id']
def _provision_ponsim_olt_grpc(self, stub): if orch_env == ENV_K8S_SINGLE_NODE: host_and_port = get_pod_ip('olt') + ':50060' else: host_and_port = '172.17.0.1:50060' device = Device(type='ponsim_olt', host_and_port=host_and_port) device = stub.CreateDevice(device) return device
def add_olt_device(self): device = Device( type='asfvolt16_olt', host_and_port='172.17.0.1:50060' ) device = self.post('/api/v1/devices', MessageToDict(device), expected_http_code=200) return device['id']
def onu_create(self, intf_id, onu_id, serial_number): onu_device = self.adapter_agent.get_child_device( self.device.id, serial_number=serial_number) if onu_device: self.log.debug("data_model onu update", intf_id=intf_id, onu_id=onu_id, serial_number=serial_number, oper_state=onu_device.oper_status) if onu_device.oper_status == OperStatus.UNKNOWN: # olt reboot self.log.debug("onu active or activating", intf_id=intf_id, onu_id=onu_id, serial_number=serial_number, oper_state=onu_device.oper_status) onu_device.oper_status = OperStatus.DISCOVERED onu_device.connect_status = ConnectStatus.REACHABLE self.adapter_agent.update_device(onu_device) else: # onu activating self.log.debug("onu active or activating", intf_id=intf_id, onu_id=onu_id, serial_number=serial_number, oper_state=onu_device.oper_status) raise ValueError return self.log.debug("data_model onu create", intf_id=intf_id, onu_id=onu_id, serial_number=serial_number) # NOTE - channel_id of onu is set to intf_id proxy_address = Device.ProxyAddress(device_id=self.device.id, channel_id=intf_id, onu_id=onu_id, onu_session_id=onu_id) port_no = self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT) vendor_id = serial_number[:4] self.adapter_agent.add_onu_device( parent_device_id=self.device.id, parent_port_no=port_no, vendor_id=vendor_id, proxy_address=proxy_address, root=False, serial_number=serial_number, admin_state=AdminState.ENABLED, connect_status=ConnectStatus.REACHABLE) # Add onu info to cache onu_info = OnuInfo(intf_id=intf_id, onu_id=onu_id, serial_number=serial_number) self._onu_ids[OnuId(intf_id=intf_id, onu_id=onu_id)] = onu_info self._onu_serial_numbers[serial_number] = onu_info
def onu_detected(self, parent_port_no=None, child_device_type=None, onu_id=None): self.adapter_agent.child_device_detected( parent_device_id=self.device.id, parent_port_no=parent_port_no, child_device_type=child_device_type, proxy_address=Device.ProxyAddress(device_id=self.device.id, channel_id=onu_id), vlan=0)
def proxy_address(self): if self._proxy_address is None: from voltha.protos.device_pb2 import Device device_id = self.olt.device_id self._proxy_address = Device.ProxyAddress( device_id=device_id, channel_id=self.pon.port_no, onu_id=self.onu_id, onu_session_id=self.onu_id) return self._proxy_address
def _simulate_detection_of_onus(self, device_id): for i in xrange(1, 5): log.info('activate-olt-for-onu-{}'.format(i)) vlan_id = self._olt_side_onu_activation(i) yield asleep(0.05) self.adapter_agent.child_device_detected( parent_device_id=device_id, parent_port_no=1, child_device_type='simulated_onu', proxy_address=Device.ProxyAddress(device_id=device_id, channel_id=vlan_id), vlan=vlan_id)
def add_device(self): print "Adding device" device = Device(type='simulated_olt') device = self.post('/api/v1/devices', MessageToDict(device), expected_http_code=200) print "Added device - id:{}, type:{}".format(device['id'], device['type']) sleep(5) return device
def deactivate_onu(self, onu_id=None, channel_id=None, onu_session_id=None): try: child_device = self.adapter_agent.get_child_device_with_proxy_address(Device.ProxyAddress( device_id=self.device.id, channel_id=channel_id, onu_id=onu_id, onu_session_id=onu_session_id )) if child_device: # self.adapter_agent.update_child_device_state(child_device, admin_state=AdminState.DISABLED) child_device.admin_state=AdminState.DISABLED self.adapter_agent.update_device(child_device) except KeyError: log.debug("ONU {} cannot be deactivated".format(onu_id))
def _simulate_detection_of_onus(self, device_id): try: for i in xrange(1, 5): log.info('activate-olt-for-onu-{}'.format(i)) vlan_id = self._olt_side_onu_activation(i) yield asleep(0.05) self.adapter_agent.child_device_detected( parent_device_id=device_id, parent_port_no=1, child_device_type='simulated_onu', proxy_address=Device.ProxyAddress(device_id=device_id, channel_id=vlan_id), admin_state=AdminState.ENABLED, vlan=vlan_id) except Exception as e: log.exception('error', e=e)
def child_device_detected(self, parent_device_id, parent_port_no, child_device_type, proxy_address, **kw): # we create new ONU device objects and insert them into the config # TODO should we auto-enable the freshly created device? Probably. device = Device(id=uuid4().hex[:12], type=child_device_type, parent_id=parent_device_id, parent_port_no=parent_port_no, admin_state=AdminState.ENABLED, proxy_address=proxy_address, **kw) self._make_up_to_date('/devices', device.id, device) topic = self._gen_tx_proxy_address_topic(proxy_address) self._tx_event_subscriptions[topic] = self.event_bus.subscribe( topic, lambda t, m: self._send_proxied_message(proxy_address, m))
def __init__(self, onu_info): self._onu_id = onu_info['onu-id'] if self._onu_id is None: raise ValueError('No ONU ID available') pon = onu_info['pon'] self._olt = pon.olt self._pon_id = pon.pon_id self._name = '{}@{}'.format(pon.physical_port_name, self._onu_id) self.log = structlog.get_logger(pon_id=self._pon_id, onu_id=self._onu_id) self._valid = True # Set false during delete/cleanup self._serial_number_base64 = Onu.string_to_serial_number( onu_info['serial-number']) self._serial_number_string = onu_info['serial-number'] self._device_id = onu_info['device-id'] self._password = onu_info['password'] self._created = False self._proxy_address = Device.ProxyAddress( device_id=self.olt.device_id, channel_id=self.olt.pon_id_to_port_number(self._pon_id), onu_id=self._onu_id, onu_session_id=self._onu_id) self._sync_tick = _HW_SYNC_SECS self._expedite_sync = False self._expedite_count = 0 self._resync_flows = False self._sync_deferred = None # For sync of ONT config to hardware # Resources self._gem_ports = {} # gem-id -> GemPort self._tconts = {} # alloc-id -> TCont self._uni_ports = onu_info['uni-ports'] # Provisionable items self._enabled = onu_info['enabled'] self._upstream_fec_enable = onu_info.get('upstream-fec') self._upstream_channel_speed = onu_info['upstream-channel-speed'] # TODO: how do we want to enforce upstream channel speed (if at all)? # KPI related items self._rssi = -9999 self._equalization_delay = 0 self._fiber_length = 0 self._timestamp = None # Last time the KPI items were updated
def on_new_onu_discovered(self, onu): """ Called when a new ONU is discovered and VOLTHA device adapter needs to be informed :param onu: :return: """ olt = self.parent adapter = olt.adapter_agent proxy = Device.ProxyAddress(device_id=olt.device_id, channel_id=self.port_number, onu_id=onu.onu_id) adapter.child_device_detected(parent_device_id=olt.device_id, parent_port_no=self.port_number, child_device_type=onu.vendor_device, proxy_address=proxy)
def child_device_detected(self, parent_device_id, parent_port_no, child_device_type, proxy_address, admin_state, **kw): # we create new ONU device objects and insert them into the config device = Device( id=create_cluster_device_id(self.core.core_store_id), # id=uuid4().hex[:12], type=child_device_type, parent_id=parent_device_id, parent_port_no=parent_port_no, proxy_address=proxy_address, admin_state=admin_state, **kw) self._make_up_to_date('/devices', device.id, device) topic = self._gen_tx_proxy_address_topic(proxy_address) self._tx_event_subscriptions[topic] = self.event_bus.subscribe( topic, lambda t, m: self._send_proxied_message(proxy_address, m))
def onu_detected(self, parent_port_no=None, child_device_type=None, onu_id=None, serial_number=None, onu_session_id=None): self.adapter_agent.child_device_detected( parent_device_id=self.device.id, parent_port_no=parent_port_no, child_device_type=child_device_type, serial_number=serial_number, proxy_address=Device.ProxyAddress( device_id=self.device.id, channel_id= parent_port_no, # happens to be the channel id as well onu_id=onu_id, onu_session_id=onu_session_id), vlan=0)
def activate_onu(self, onu): """ Called when a new ONU is discovered and VOLTHA device adapter needs to be informed :param onu: :return: """ olt = self.olt adapter = self.adapter_agent channel_id = onu.onu_vid proxy = Device.ProxyAddress(device_id=olt.device_id, channel_id=channel_id) adapter.child_device_detected(parent_device_id=olt.device_id, parent_port_no=self._port_no, child_device_type=onu.vendor_id, proxy_address=proxy, admin_state=AdminState.ENABLED, vlan=channel_id)
def deactivate_onu(self, onu_id=None, channel_id=None, onu_session_id=None): try: child_device = self.adapter_agent.get_child_device_with_proxy_address(Device.ProxyAddress( device_id=self.device.id, channel_id=channel_id, onu_id=onu_id, onu_session_id=onu_session_id )) # self.adapter_agent.delete_child_device(self.device.id, child_device) if child_device: child_device.admin_state = AdminState.DISABLED # self.adapter_agent._make_up_to_date('/devices', child_device.id, child_device) reactor.callLater(0, self.adapter_agent._make_up_to_date, '/devices', child_device.id, child_device) #child_device.admin_state=AdminState.DISABLED #self.adapter_agent.update_device(child_device) except Exception: log.debug("ONU {} cannot be deactivated".format(onu_id))
def delete_onu(self, onu_id): uri = AdtranOltHandler.GPON_ONU_CONFIG_URI.format(self._pon_id, onu_id) name = 'pon-delete-onu-{}-{}'.format(self._pon_id, onu_id) onu = self._onu_by_id.get(onu_id) # Remove from any local dictionary if onu_id in self._onu_by_id: del self._onu_by_id[onu_id] for sn in [ onu.serial_numbers for onu in self._onus.itervalues() if onu.onu_id == onu_id ]: del self._onus[sn] try: yield self._parent.rest_client.request('DELETE', uri, name=name) except Exception as e: self.log.exception('onu', serial_number=onu.serial_number, e=e) if onu is not None: # Clean up adapter agent of this ONU proxy = Device.ProxyAddress(device_id=self.olt.device_id, channel_id=onu.channel_id) onu_device = self.olt.adapter_agent.get_child_device_with_proxy_address( proxy) if onu_device is not None: self.olt.adapter_agent.delete_child_device( self.olt.device_id, onu_device.device_id) self.olt.adapter_agent.update_child_devices_state( self.olt.device_id, admin_state=AdminState.DISABLED) def delete_child_device(self, parent_device_id, child_device_id): onu_device = self.root_proxy.get( '/devices/{}'.format(child_device_id)) if onu_device is not None: if onu_device.parent_id == parent_device_id: self.log.debug('deleting-child-device', parent_device_id=parent_device_id, child_device_id=child_device_id) self._remove_node('/devices', child_device_id)
def rx_packet(self, message): try: self.log.debug('rx_packet') pon_id, onu_id, msg, is_omci = AdtranZmqClient.decode_packet(message) if is_omci: proxy_address = Device.ProxyAddress(device_id=self.device_id, channel_id=self.get_channel_id(pon_id, onu_id), onu_id=onu_id) self.adapter_agent.receive_proxied_message(proxy_address, msg) else: pass # TODO: Packet in support not yet supported # self.adapter_agent.send_packet_in(logical_device_id=logical_device_id, # logical_port_no=cvid, # C-VID encodes port no # packet=str(msg)) except Exception as e: self.log.exception('rx_packet', e=e)
def onu_detected(self, parent_port_no=None, child_device_type=None, onu_id=None, serial_number=None, onu_session_id=None, channel_id=None): log.debug('onu-detected') try: # self.adapter_agent.child_device_detected( # parent_device_id=self.device.id, # parent_port_no=parent_port_no, # child_device_type=child_device_type, # serial_number=serial_number, # proxy_address=Device.ProxyAddress( # device_id=self.device.id, # channel_id=channel_id, # happens to be the channel id as well # onu_id=onu_id, # onu_session_id=onu_session_id # ), # admin_state=AdminState.ENABLED, # vlan=0) reactor.callLater(0, self.adapter_agent.child_device_detected, parent_device_id=self.device.id, parent_port_no=parent_port_no, child_device_type=child_device_type, serial_number=serial_number, proxy_address=Device.ProxyAddress( device_id=self.device.id, channel_id=channel_id, # happens to be the channel id as well onu_id=onu_id, onu_session_id=onu_session_id ), admin_state=AdminState.ENABLED, vlan=0) except Exception as e: log.exception('onu-detected-failed', e=e) raise e