def parse_arguments(self, argv : Optional[Tuple[str, ...]] = None): """ Parse commend line arguments. Returns handler_type, args """ prog_basename = os.path.basename(sys.argv[0]) (prog_root, _) = os.path.splitext(prog_basename) if argv is None: argv = sys.argv self._args = self._parser.parse_args(argv[1:]) # handler parameter is mandatory if self._any_handler: if self._args.handler is None: print("-f, --handler parameter is mandatory. Valid values:{}".format(self._valid_handler_names)) return None, None if self._args.handler not in self.handler_map: print("--handler value is invalid. Supported values:{}".format(self._valid_handler_names)) return None, None self._handler_type = self.handler_map[self._args.handler] self._name = self._name is None and self._args.handler or self._name loglevel_map = {0: logging.WARN, 1: logging.INFO, 2: logging.DEBUG} OmciLogger(level=loglevel_map[self._args.loglevel]) logger = OmciLogger.getLogger(prog_root) logger.debug('args %r' % self._args) return self._handler_type, self._args
def test_extractPayload(): polt_host = '10.66.1.2' polt_port = 8433 vomci_name = 'vomci1' cterm_name = 'channeltermination.1' onu_id = 0 onu_name = 'onuTrial' tci = 1 log_level = 2 loglevel_map = {0: logging.WARN, 1: logging.INFO, 2: logging.DEBUG} OmciLogger(level=loglevel_map[log_level]) logger = OmciLogger.getLogger(__name__) logger.info("test_YangtoOmciMapper: connecting to the pOLT {}:{}".format( polt_host, polt_port)) channel = GrpcClientChannel(vomci_name) ret_val = channel.connect(polt_host, polt_port) if not ret_val: logger.info("test_YangtoOmciMapper: connection failed with pOLT") return -1 olt = channel.add_managed_onu(channel.remote_endpoint_name, onu_name, (cterm_name, onu_id), tci) logger.info("test_YangtoOmciMapper: connected to the pOLT: {}".format( olt.id)) onu = olt.OnuGet((cterm_name, onu_id)) activate_handler = OnuActivateHandler(onu) status = activate_handler.run() logger.info( "test_YangtoOmciMapper: activate_handler status: {}".format(status)) payload = '{"identifier": "0", "operation": "edit-config", ' \ '"delta":{"bbf-qos-classifiers:classifiers": {"classifier-entry": [{"name" : "classifier1", ' \ '"classifier-action-entry-cfg": [{"action-type": "bbf-qos-cls:scheduling-traffic-class", "scheduling-traffic-class": 0}], ' \ '"match-criteria": {"tag": [{"index": 0, "in-pbit-list": 0}]}}]}, ' \ '"bbf-qos-policies:policies": {"policy": [{"name" : "policy1", "classifiers": [{"name":"classifier1"}]}]}, ' \ '"bbf-qos-policies:qos-policy-profiles": {"policy-profile": [{"name": "profile1", "policy-list": [{"name": "policy1"}]}]}, ' \ '"ietf-interfaces:interfaces": {"interface": [{"name": "uni.1", "type": "ianaift:ethernetCsmacd", ' \ '"enabled": "true", "port-layer-if": "ontUni_ont1_1_1", "ingress-qos-policy-profile": "profile1"}, ' \ '{"name": "enet_vlan_ont1", "type": "bbfift:vlan-sub-interface", "subif-lower-layer": {"interface" : "uni.1"}, ' \ '"inline-frame-processing": {"ingress-rule": {"rule": [{"name": "rule1", "priority": "100", "flexible-match": {"match-criteria": "untagged"}, ' \ '"ingress-rewrite": {"pop-tags" : 0, "push-tag": [{"index": 0, "dot1q-tag": {"tag-type": "bbf-dot1qt:c-vlan", "vlan-id": 100, "pbit-from-tag-index": 0}}]}}]}}, ' \ '"ingress-qos-policy-profile": "profile1"}]}, "bbf-xpongemtcont:xpongemtcont": {"tconts": {"tcont": [{"name": "tcont.1", "alloc-id": 1024}]}, ' \ '"gemports": {"gemport": [{"name": "gemport.1", "interface": "uni.1", "gemport-id": 1025, "traffic-class": 0, "tcont-ref": "tcont.1"}]}}}}' payloadDict = json.loads(payload) extractPayload(onu_name, olt.id, payloadDict) if onu.olt.channel is not None: onu.olt.channel.disconnect()
# MIB upload handler # # Created by I.Ternovsky (Broadcom) on 17 July 2020 # """ Upload ONU MIB, Usually this handler is executed as a part of ONU activation when a new ONU is discovered """ from omh_nbi.onu_driver import OnuDriver from omh_nbi.omh_handler import OmhHandler, OMHStatus from encode_decode.omci_action_mib_upload import MibUploadAction from encode_decode.omci_action_mib_upload_next import MibUploadNextAction from omci_logger import OmciLogger logger = OmciLogger.getLogger(__name__) class OnuMibUploadHandler(OmhHandler): def __init__(self, onu: 'OnuDriver'): super().__init__(name='mib_upload', onu = onu, description='mib_upload: {}'.format(onu.onu_id)) self._num_me_decoded = 0 def run_to_completion(self) -> OMHStatus: # ONU MIB Upload sequence: # - MIB_UPLOAD(onu_data.0) --> number of the following MIB_UPLOAD_NEXT commands # - for i in range(number_of_mib_upload_next_commands): # MIB_UPLOAD_NEXT(i) self.onu.clear() upload_action = MibUploadAction(self) status = self.transaction(upload_action) if status != OMHStatus.OK: