def add_uni_ports(self): """ Called after in-sync achieved and not in xPON mode""" # TODO: We have to methods adding UNI ports. Go to one # TODO: Should this be moved to the omci.py module for this ONU? # This is only for working WITHOUT xPON pptp_entities = self.openomci.onu_omci_device.configuration.pptp_entities device = self.adapter_agent.get_device(self.device_id) multi_uni = len(pptp_entities) > 1 uni_id = 0 for entity_id, pptp in pptp_entities.items(): intf_id = self.proxy_address.channel_id onu_id = self.proxy_address.onu_id uni_no = platform.mk_uni_port_num(intf_id, onu_id, uni_id=uni_id) uni_name = "uni-{}".format(uni_no) mac_bridge_port_num = uni_id + 1 uni_port = UniPort.create(self, uni_name, uni_no, uni_name) uni_port.entity_id = entity_id uni_port.enabled = True uni_port.mac_bridge_port_num = mac_bridge_port_num uni_port.add_logical_port(uni_port.port_number, multi_uni) self.log.debug("created-uni-port", uni=uni_port) self.adapter_agent.add_port(device.id, uni_port.get_port()) parent_device = self.adapter_agent.get_device(device.parent_id) parent_adapter_agent = registry('adapter_loader').get_agent( parent_device.adapter) if parent_adapter_agent is None: self.log.error('olt-adapter-agent-could-not-be-retrieved') parent_adapter_agent.add_port(device.parent_id, uni_port.get_port()) self._unis[uni_port.port_number] = uni_port self.openomci.onu_omci_device.alarm_synchronizer.set_alarm_params( onu_id=self.proxy_address.onu_id, uni_ports=self._unis.values()) # TODO: this should be in the PonPort class pon_port = self._pon.get_port() self.adapter_agent.delete_port_reference_from_parent( self.device_id, pon_port) # Find index where this ONU peer is (should almost always be zero) d = [ i for i, e in enumerate(pon_port.peers) if e.port_no == intf_id and e.device_id == device.parent_id ] if len(d) > 0: pon_port.peers[d[0]].port_no = uni_port.port_number self.adapter_agent.add_port_reference_to_parent( self.device_id, pon_port) self.adapter_agent.update_device(device) uni_port.enabled = True uni_id += 1
def on_venet_create(self, venet): self.log.info('venet-create', venet=venet) self._check_for_mock_config(venet) # TODO: This first set is copied over from BroadCOM ONU. For testing, actual work # is the last 7 lines. The 'test' code below assumes we have not registered # any UNI ports during 'activate' but we want to create them as the vEnet # information comes in. # onu_device = self.adapter_agent.get_device(self.device_id) # existing_uni_ports = self.adapter_agent.get_ports(onu_device.parent_id, Port.ETHERNET_UNI) # # parent_port_num = None # for uni in existing_uni_ports: # if uni.label == venet['name']: # TODO: was -> data.interface.name: # parent_port_num = uni.port_no # break # # # Create both the physical and logical ports for the UNI now # parent_device = self.adapter_agent.get_device(onu_device.parent_id) # logical_device_id = parent_device.parent_id # assert logical_device_id, 'Invalid logical device ID' # # self.add_uni_port(onu_device, logical_device_id, venet['name'], parent_port_num) # # pon_ports = self.adapter_agent.get_ports(self.device_id, Port.PON_ONU) # if pon_ports: # # TODO: Assumed only one PON port and UNI port per ONU. # pon_port = pon_ports[0] # else: # self.log.error("No-Pon-port-configured-yet") # return # # self.adapter_agent.delete_port_reference_from_parent(self.device_id, pon_port) # pon_port.peers[0].device_id = onu_device.parent_id # pon_port.peers[0].port_no = parent_port_num # self.adapter_agent.add_port_reference_to_parent(self.device_id, pon_port) ################################################################################# # Start of actual work (what actually does something) # TODO: Clean this up. Use looked up UNI if self._olt_created: uni_port = self.uni_port('deprecated') else: # vlan non-zero if created via legacy method (not xPON). Also # Set a random serial number since not xPON based device = self.adapter_agent.get_device(self.device_id) ofp_port_no, cntl_vlan = UniPort.decode_openflow_port_and_control_vlan( self, venet) uni_port = UniPort.create(self, venet['name'], self._next_port_number, cntl_vlan) self._unis[uni_port.port_number] = uni_port self.adapter_agent.add_port(device.id, uni_port.get_port()) uni_port.add_logical_port(ofp_port_no, control_vlan=cntl_vlan) # TODO: Next is just for debugging to see what this call returns after # we add a UNI # existing_uni_ports = self.adapter_agent.get_ports(onu_device.parent_id, Port.ETHERNET_UNI) uni_port.enabled = venet['enabled'] return venet
def activate(self, device): self.log.info('activating') # first we verify that we got parent reference and proxy info assert device.parent_id, 'Invalid Parent ID' assert device.proxy_address.device_id, 'Invalid Device ID' if device.vlan: # vlan non-zero if created via legacy method (not xPON). Also # Set a random serial number since not xPON based self._olt_created = True # register for proxied messages right away self.proxy_address = device.proxy_address self.adapter_agent.register_for_proxied_messages(device.proxy_address) # initialize device info device.root = True device.vendor = 'Adtran Inc.' device.model = 'n/a' device.hardware_version = 'n/a' device.firmware_version = 'n/a' device.reason = '' # TODO: Support more versions as needed images = Image(version='NOT AVAILABLE') device.images.image.extend([images]) device.connect_status = ConnectStatus.UNKNOWN ############################################################################ # Setup PM configuration for this device self.pm_metrics = OnuPmMetrics(self, device, grouped=True, freq_override=False) pm_config = self.pm_metrics.make_proto() self.log.info("initial-pm-config", pm_config=pm_config) self.adapter_agent.update_device_pm_config(pm_config, init=True) ############################################################################ # Setup Alarm handler self.alarms = AdapterAlarms(self.adapter, device.id) # reference of uni_port is required when re-enabling the device if # it was disabled previously # Need to query ONU for number of supported uni ports # For now, temporarily set number of ports to 1 - port #2 # Register physical ports. Should have at least one of each pon_port = PonPort.create(self, self._next_port_number) self._pons[pon_port.port_number] = pon_port self.adapter_agent.add_port(device.id, pon_port.get_port()) parent_device = self.adapter_agent.get_device(device.parent_id) self.logical_device_id = parent_device.parent_id assert self.logical_device_id, 'Invalid logical device ID' if self._olt_created: # vlan non-zero if created via legacy method (not xPON). Also # Set a random serial number since not xPON based uni_port = UniPort.create(self, self._next_port_number, 'deprecated', device.vlan) self._unis[uni_port.port_number] = uni_port self.adapter_agent.add_port(device.id, uni_port.get_port()) device.serial_number = uuid4().hex uni_port.add_logical_port(device.vlan, control_vlan=device.vlan) # Start things up for this ONU Handler. self.enabled = True # Start collecting stats from the device after a brief pause reactor.callLater(30, self.start_kpi_collection, device.id) self.adapter_agent.update_device(device)
def activate(self, device): self.log.info('activating') try: # first we verify that we got parent reference and proxy info assert device.parent_id, 'Invalid Parent ID' assert device.proxy_address.device_id, 'Invalid Device ID' if device.vlan: # vlan non-zero if created via legacy method (not xPON). self._olt_created = True # register for proxied messages right away self.proxy_address = device.proxy_address self.adapter_agent.register_for_proxied_messages(device.proxy_address) # initialize device info device.root = True device.vendor = 'Adtran Inc.' device.model = 'n/a' device.hardware_version = 'n/a' device.firmware_version = 'n/a' device.reason = '' device.connect_status = ConnectStatus.UNKNOWN # Register physical ports. Should have at least one of each self._pon = PonPort.create(self, self._next_port_number) self.adapter_agent.add_port(device.id, self._pon.get_port()) if self._olt_created: # vlan non-zero if created via legacy method (not xPON). Also # Set a random serial number since not xPON based uni_port = UniPort.create(self, self._next_port_number, device.vlan, 'deprecated', device.vlan, None) self._unis[uni_port.port_number] = uni_port self.adapter_agent.add_port(device.id, uni_port.get_port()) device.serial_number = uuid4().hex uni_port.add_logical_port(device.vlan, subscriber_vlan=device.vlan) # Start things up for this ONU Handler. self.enabled = True ############################################################################ # Setup PM configuration for this device # Pass in ONU specific options kwargs = { 'heartbeat': self.heartbeat, 'omci-cc': self.openomci.omci_cc } self.pm_metrics = OnuPmMetrics(self.adapter_agent, self.device_id, grouped=True, freq_override=False, **kwargs) pm_config = self.pm_metrics.make_proto() self.openomci.set_pm_config(self.pm_metrics.omci_pm.openomci_interval_pm) self.log.info("initial-pm-config", pm_config=pm_config) self.adapter_agent.update_device_pm_config(pm_config, init=True) # reference of uni_port is required when re-enabling the device if # it was disabled previously # Need to query ONU for number of supported uni ports # For now, temporarily set number of ports to 1 - port #2 parent_device = self.adapter_agent.get_device(device.parent_id) self.logical_device_id = parent_device.parent_id assert self.logical_device_id, 'Invalid logical device ID' self.adapter_agent.update_device(device) ############################################################################ # Setup Alarm handler self.alarms = AdapterAlarms(self.adapter_agent, device.id, self.logical_device_id) ############################################################################ # Start collecting stats from the device after a brief pause reactor.callLater(30, self.pm_metrics.start_collector) except Exception as e: self.log.exception('activate-failure', e=e) device.reason = 'Failed to activate: {}'.format(e.message) device.connect_status = ConnectStatus.UNREACHABLE device.oper_status = OperStatus.FAILED self.adapter_agent.update_device(device)
def on_venet_create(self, venet): self.log.info('venet-create', venet=venet) self._check_for_mock_config(venet) # TODO: This first set is copied over from BroadCOM ONU. For testing, actual work # is the last 7 lines. The 'test' code below assumes we have not registered # any UNI ports during 'activate' but we want to create them as the vEnet # information comes in. # onu_device = self.adapter_agent.get_device(self.device_id) # existing_uni_ports = self.adapter_agent.get_ports(onu_device.parent_id, Port.ETHERNET_UNI) # # parent_port_num = None # for uni in existing_uni_ports: # if uni.label == venet['name']: # TODO: was -> data.interface.name: # parent_port_num = uni.port_no # break # # # Create both the physical and logical ports for the UNI now # parent_device = self.adapter_agent.get_device(onu_device.parent_id) # logical_device_id = parent_device.parent_id # assert logical_device_id, 'Invalid logical device ID' # # self.add_uni_port(onu_device, logical_device_id, venet['name'], parent_port_num) # # pon_ports = self.adapter_agent.get_ports(self.device_id, Port.PON_ONU) # if pon_ports: # # TODO: Assumed only one PON port and UNI port per ONU. # pon_port = pon_ports[0] # else: # self.log.error("No-Pon-port-configured-yet") # return # # self.adapter_agent.delete_port_reference_from_parent(self.device_id, pon_port) # pon_port.peers[0].device_id = onu_device.parent_id # pon_port.peers[0].port_no = parent_port_num # self.adapter_agent.add_port_reference_to_parent(self.device_id, pon_port) ################################################################################# # Start of actual work (what actually does something) # TODO: Clean this up. Use looked up UNI if self._olt_created: uni_port = self.uni_port('deprecated') else: # vlan non-zero if created via legacy method (not xPON). Also # Set a random serial number since not xPON based device = self.adapter_agent.get_device(self.device_id) ofp_port_no, cntl_vlan = UniPort.decode_openflow_port_and_control_vlan(self, venet) uni_port = UniPort.create(self, venet['name'], self._next_port_number, cntl_vlan) self._unis[uni_port.port_number] = uni_port self.adapter_agent.add_port(device.id, uni_port.get_port()) uni_port.add_logical_port(ofp_port_no, control_vlan=cntl_vlan) # TODO: Next is just for debugging to see what this call returns after # we add a UNI # existing_uni_ports = self.adapter_agent.get_ports(onu_device.parent_id, Port.ETHERNET_UNI) uni_port.enabled = venet['enabled'] return venet