コード例 #1
0
def test_simple_proxy_message():
    print("----Starting producer basic tests")
    producer = kafka_proto_interface.start_kafka_producer()
    msg = tr451_vomci_nbi_message_pb2.Msg()
    msg.header.msg_id = "2"
    msg.header.sender_name = "vOLTMF"
    msg.header.recipient_name = "proxy-1"
    msg.header.object_type = msg.header.VOMCI_PROXY
    msg.header.object_name = "proxy-1"
    msg.body.request.rpc.input_data = bytes(
        "{\"bbf-vomci-proxy:create-onu\":{\"name\":\"ontA\"}}", "utf-8")
    producer.send(KAFKA_CONSUMER_TOPIC, bytes(msg.SerializeToString()))
    assert kafka_if._consumer._last_rcvd_object is None

    #msg.body.request.action.input_data = bytes("{\"bbf-vomci-proxy:managed-onus\":{\"managed-onu\":[{\"name\":\"ont1\",\"delete-onu\":{}}]}}",
    #"utf-8")
    producer = kafka_proto_interface.start_kafka_producer()
    msg = tr451_vomci_nbi_message_pb2.Msg()
    msg.header.msg_id = "4"
    msg.header.sender_name = "vOLTMF"
    msg.header.recipient_name = "proxy-1"
    msg.header.object_type = msg.header.VOMCI_PROXY
    msg.header.object_name = "proxy-1"
    msg.body.request.action.input_data = bytes(
        "{\"bbf-vomci-proxy:managed-onus\":{\"managed-onu\":[{\"name\":\"onuA\",\"set-onu-communication\":{\"onu-attachment-point\":{\"olt-name\":\"olt-grpc-2\",\"channel-termination-name\":\"CT_1\",\"onu-id\":1},\"onu-communication-available\":true,\"vomci-func-remote-endpoint-name\":\"obbaa-vomci\",\"olt-remote-endpoint-name\":\"olt-grpc-2\"}}]}}",
        "utf-8")
    producer.send(KAFKA_CONSUMER_TOPIC, bytes(msg.SerializeToString()))
    assert kafka_if._consumer._last_rcvd_object is None
    """producer = kafka_proto_interface.start_kafka_producer()
コード例 #2
0
    def send_successful_response(self, onu_name):
        if onu_name in self.proto_resp:
            rsp = tr451_vomci_nbi_message_pb2.Msg()
            msg = tr451_vomci_nbi_message_pb2.Msg()
            stat = tr451_vomci_nbi_message_pb2.Status()
            msg = self.proto_resp[onu_name]
            rsp.header.msg_id = msg.header.msg_id
            rsp.header.recipient_name = msg.header.sender_name
            rsp.header.sender_name = msg.header.recipient_name
            rsp.header.object_name = msg.header.object_name
            ob_type = msg.header.OBJECT_TYPE.Name(msg.header.object_type)
            if ob_type == tr451_vomci_nbi_message_pb2.Header.OBJECT_TYPE.VOMCI_FUNCTION:
                rsp.header.object_type = tr451_vomci_nbi_message_pb2.Header.OBJECT_TYPE.VOMCI_FUNCTION
            if ob_type == tr451_vomci_nbi_message_pb2.Header.OBJECT_TYPE.VOMCI_PROXY:
                rsp.header.object_type = tr451_vomci_nbi_message_pb2.Header.OBJECT_TYPE.VOMCI_PROXY
            if ob_type == tr451_vomci_nbi_message_pb2.Header.OBJECT_TYPE.ONU:
                rsp.header.object_type = tr451_vomci_nbi_message_pb2.Header.OBJECT_TYPE.ONU

            tp = msg.body.request.WhichOneof('req_type')
            del self.proto_resp[onu_name]
            if tp == 'rpc':
                stat.status_code = tr451_vomci_nbi_message_pb2.Status.StatusCode.OK
                rsp.body.response.rpc_resp.status_resp.CopyFrom(stat)
            elif tp == 'action':
                rsp.body.response.action_resp.status_resp.status_code = int()
            elif tp == 'replace_config':
                rsp.body.response.replace_config_resp.status_resp.status_code = int(
                )
            logger.info(
                'sending the SUCCESS protobuf response to VOLTMF:{}'.format(
                    rsp))
            self._producer.send_proto_response(rsp)
コード例 #3
0
def test_simple_kafka_message():
    print("----Starting producer basic tests")
    producer = kafka_proto_interface.start_kafka_producer()
    msg = tr451_vomci_nbi_message_pb2.Msg()
    msg.header.msg_id = "1"
    msg.header.sender_name = "VOLTMF"
    msg.header.recipient_name = "vomci-vendor-1"
    msg.header.object_type = msg.header.VOMCI_FUNCTION
    msg.header.object_name = "vOMCI"
    msg.body.request.rpc.input_data = bytes(
        "{\"bbf-vomci-function:create-onu\":{\"name\":\"ontA\"}}", "utf-8")
    producer.send(KAFKA_CONSUMER_TOPIC, bytes(msg.SerializeToString()))
    assert kafka_if._consumer._last_rcvd_object is None

    producer = kafka_proto_interface.start_kafka_producer()
    msg = tr451_vomci_nbi_message_pb2.Msg()
    msg.header.msg_id = "3"
    msg.header.sender_name = "VOLTMF"
    msg.header.recipient_name = "vomci-vendor-1"
    msg.header.object_type = msg.header.VOMCI_FUNCTION
    msg.header.object_name = "vomci-vendor-1"
    #msg.body.request.rpc.input_data = bytes("{\"bbf-vomci-function:create-onu\":{\"name\":\"ontA\"}}","utf-8")
    msg.body.request.action.input_data = bytes(
        "{\"bbf-vomci-function:managed-onus\":{\"managed-onu\":[{\"name\":\"onuA\",\"set-onu-communication\":{\"onu-attachment-point\":{\"olt-name\":\"olt-grpc-2\",\"channel-termination-name\":\"CT_1\",\"onu-id\":1},\"voltmf-remote-endpoint-name\":\"vOLTMF_Kafka\",\"onu-communication-available\":true,\"olt-remote-endpoint-name\":\"obbaa-vproxy-grpc-client-1\"}}]}}",
        "utf-8")
    producer.send(KAFKA_CONSUMER_TOPIC, bytes(msg.SerializeToString()))
    assert kafka_if._consumer._last_rcvd_object is None
    """producer = kafka_proto_interface.start_kafka_producer()
    msg = tr451_vomci_nbi_message_pb2.Msg()
    msg.header.msg_id="5"
    msg.header.sender_name="VOLTMF"
    msg.header.recipient_name="vomci-vendor-1"
    msg.header.object_type=msg.header.VOMCI_FUNCTION
    msg.header.object_name="vomci-vendor-1"
    msg.body.request.action.input_data = bytes("{\"bbf-vomci-function:managed-onus\":{\"managed-onu\":[{\"name\":\"onuA\",\"delete-onu\":{}}]}}","utf-8")
    producer.send(KAFKA_CONSUMER_TOPIC,bytes(msg.SerializeToString()))
    assert kafka_if._consumer._last_rcvd_object is None"""

    producer = kafka_proto_interface.start_kafka_producer()
    msg = tr451_vomci_nbi_message_pb2.Msg()
    msg.header.msg_id = "10"
    msg.header.sender_name = "VOLTMF"
    msg.header.recipient_name = "vomci-vendor-1"
    msg.header.object_type = msg.header.ONU
    msg.header.object_name = "onuA"
    """msg.body.request.replace_config.config_inst = bytes("{\"bbf-qos-filters:filters\":{},\"ietf-ipfix-psamp:ipfix\":{},\"ietf-hardware:hardware\":{},\"bbf-qos-classifiers:classifiers\":{},\"ietf-pseudowires:pseudowires\":{},\"bbf-ghn:ghn\":{},\"bbf-qos-policies:qos-policy-profiles\":{},\"bbf-vdsl:vdsl\":{},\"bbf-xpongemtcont:xpongemtcont\":{},\"ietf-system:system\":{},\"bbf-qos-policer-envelope-profiles:envelope-profiles\":{},\"bbf-ghs:ghs\":{},\"ietf-interfaces:interfaces\":{},\"bbf-qos-policies:policies\":{},\"bbf-qos-traffic-mngt:tm-profiles\":{},\"bbf-qos-policing:policing-profiles\":{},\"bbf-selt:selt\":{},\"bbf-l2-dhcpv4-relay:l2-dhcpv4-relay-profiles\":{},\"ieee802-dot1x:nid-group\":{},\"ietf-alarms:alarms\":{},\"ietf-netconf-acm:nacm\":{},\"bbf-hardware-rpf-dpu:rpf\":{},\"bbf-pppoe-intermediate-agent:pppoe-profiles\":{},\"bbf-fast:fast\":{},\"bbf-mgmd:multicast\":{},\"bbf-melt:melt\":{},\"bbf-subscriber-profiles:subscriber-profiles\":{},\"bbf-ldra:dhcpv6-ldra-profiles\":{},\"bbf-l2-forwarding:forwarding\":{}}", "utf-8")"""
    msg.body.request.replace_config.config_inst = bytes(
        "{\"ietf-hardware:hardware\":{\"component\":[{\"name\":\"ont1\",\"admin-state\":\"unlocked\",\"parent-rel-pos\":1,\"class\":\"iana-hardware:chassis\"},{\"parent\":\"ont1\",\"name\":\"ontCard_ont1_1\",\"admin-state\":\"unlocked\",\"parent-rel-pos\":1,\"class\":\"bbf-hardware-types:board\"},{\"parent\":\"ontCard_ont1_1\",\"name\":\"ontCage_ont1\",\"parent-rel-pos\":1,\"class\":\"bbf-hardware-types:cage\"},{\"parent\":\"ontCage_ont1\",\"name\":\"ontSfp_ont1\",\"parent-rel-pos\":1,\"class\":\"bbf-hardware-types:transceiver\"},{\"parent\":\"ontSfp_ont1\",\"name\":\"ontAniPort_ont1\",\"parent-rel-pos\":1,\"class\":\"bbf-hardware-types:transceiver-link\"},{\"parent\":\"ontCard_ont1_1\",\"name\":\"ontUni_ont1_1_1\",\"parent-rel-pos\":1,\"class\":\"bbf-hardware-types:transceiver-link\"}]},\"bbf-qos-classifiers:classifiers\":{\"classifier-entry\":[{\"name\":\"classifier_eg0\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":0}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"bbf-qos-policing:pbit-marking-list\":[{\"index\":0,\"pbit-value\":0}],\"any-protocol\":[null],\"dscp-range\":\"any\",\"match-all\":[null]}},{\"name\":\"classifier_eg1\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":1}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"bbf-qos-policing:pbit-marking-list\":[{\"index\":0,\"pbit-value\":1}],\"any-protocol\":[null],\"dscp-range\":\"any\",\"match-all\":[null]}},{\"name\":\"classifier_eg2\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":2}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"bbf-qos-policing:pbit-marking-list\":[{\"index\":0,\"pbit-value\":2}],\"any-protocol\":[null],\"dscp-range\":\"any\",\"match-all\":[null]}},{\"name\":\"classifier_eg3\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":3}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"bbf-qos-policing:pbit-marking-list\":[{\"index\":0,\"pbit-value\":3}],\"any-protocol\":[null],\"dscp-range\":\"any\",\"match-all\":[null]}},{\"name\":\"classifier_eg4\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":4}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"bbf-qos-policing:pbit-marking-list\":[{\"index\":0,\"pbit-value\":4}],\"any-protocol\":[null],\"dscp-range\":\"any\",\"match-all\":[null]}},{\"name\":\"classifier_eg5\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":5}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"bbf-qos-policing:pbit-marking-list\":[{\"index\":0,\"pbit-value\":5}],\"any-protocol\":[null],\"dscp-range\":\"any\",\"match-all\":[null]}},{\"name\":\"classifier_eg6\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":6}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"bbf-qos-policing:pbit-marking-list\":[{\"index\":0,\"pbit-value\":6}],\"any-protocol\":[null],\"dscp-range\":\"any\",\"match-all\":[null]}},{\"name\":\"classifier_eg7\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":7}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"bbf-qos-policing:pbit-marking-list\":[{\"index\":0,\"pbit-value\":7}],\"any-protocol\":[null],\"dscp-range\":\"any\",\"match-all\":[null]}},{\"name\":\"classifier_ing0\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":0}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"any-protocol\":[null],\"dscp-range\":\"any\",\"tag\":[{\"index\":0,\"in-pbit-list\":\"0\"}]}},{\"name\":\"classifier_ing1\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":1}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"any-protocol\":[null],\"dscp-range\":\"any\",\"tag\":[{\"index\":0,\"in-pbit-list\":\"1\"}]}},{\"name\":\"classifier_ing2\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":2}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"any-protocol\":[null],\"dscp-range\":\"any\",\"tag\":[{\"index\":0,\"in-pbit-list\":\"2\"}]}},{\"name\":\"classifier_ing3\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":3}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"any-protocol\":[null],\"dscp-range\":\"any\",\"tag\":[{\"index\":0,\"in-pbit-list\":\"3\"}]}},{\"name\":\"classifier_ing4\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":4}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"any-protocol\":[null],\"dscp-range\":\"any\",\"tag\":[{\"index\":0,\"in-pbit-list\":\"4\"}]}},{\"name\":\"classifier_ing5\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":5}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"any-protocol\":[null],\"dscp-range\":\"any\",\"tag\":[{\"index\":0,\"in-pbit-list\":\"5\"}]}},{\"name\":\"classifier_ing6\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":6}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"any-protocol\":[null],\"dscp-range\":\"any\",\"tag\":[{\"index\":0,\"in-pbit-list\":\"6\"}]}},{\"name\":\"classifier_ing7\",\"classifier-action-entry-cfg\":[{\"action-type\":\"bbf-qos-classifiers:scheduling-traffic-class\",\"scheduling-traffic-class\":7}],\"filter-operation\":\"bbf-qos-classifiers:match-all-filter\",\"match-criteria\":{\"any-protocol\":[null],\"dscp-range\":\"any\",\"tag\":[{\"index\":0,\"in-pbit-list\":\"7\"}]}}]},\"bbf-qos-policies:qos-policy-profiles\":{\"policy-profile\":[{\"name\":\"IPP0\",\"policy-list\":[{\"name\":\"POLICY_ING\"}]},{\"name\":\"QPP0\",\"policy-list\":[{\"name\":\"POLICY_EG\"}]}]},\"bbf-xpongemtcont:xpongemtcont\":{\"tconts\":{\"tcont\":[{\"interface-reference\":\"ontAni_ont1\",\"name\":\"tcont_ont1\",\"alloc-id\":1024,\"traffic-descriptor-profile-ref\":\"TDP0\",\"bbf-xpongemtcont-qos:tm-root\":{}}]},\"traffic-descriptor-profiles\":{\"traffic-descriptor-profile\":[{\"fixed-bandwidth\":\"10000000\",\"assured-bandwidth\":\"10000000\",\"maximum-bandwidth\":\"30000000\",\"name\":\"TDP0\"}]},\"gemports\":{\"gemport\":[{\"gemport-id\":1024,\"tcont-ref\":\"tcont_ont1\",\"traffic-class\":0,\"upstream-aes-indicator\":false,\"downstream-aes-indicator\":false,\"name\":\"gem_ont1\",\"interface\":\"enet_uni_ont1_1_1\"}]}},\"ietf-interfaces:interfaces\":{\"interface\":[{\"bbf-qos-traffic-mngt:tm-root\":{},\"name\":\"ontAni_ont1\",\"bbf-interface-port-reference:port-layer-if\":\"ontAniPort_ont1\",\"type\":\"bbf-xpon-if-type:ani\",\"bbf-xponani:ani\":{\"upstream-fec\":true,\"management-gemport-aes-indicator\":false,\"onu-id\":1},\"enabled\":true,\"bbf-interfaces-performance-management:performance\":{\"enable\":false}},{\"ieee802-dot1x:pae\":{\"port-capabilities\":{},\"logon-process\":{\"logon\":false},\"logon-nid\":{}},\"bbf-l2-forwarding:mac-learning\":{\"number-committed-mac-addresses\":1,\"mac-learning-enable\":true,\"mac-learning-failure-action\":\"forward\",\"max-number-mac-addresses\":4294967295},\"bbf-qos-traffic-mngt:tm-root\":{},\"name\":\"enet_uni_ont1_1_1\",\"bbf-interface-port-reference:port-layer-if\":\"ontUni_ont1_1_1\",\"type\":\"iana-if-type:ethernetCsmacd\",\"enabled\":true,\"bbf-interfaces-performance-management:performance\":{\"enable\":false},\"ieee802-ethernet-interface:ethernet\":{\"duplex\":\"full\",\"flow-control\":{\"force-flow-control\":false,\"pfc\":{},\"pause\":{}},\"auto-negotiation\":{}},\"bbf-interface-usage:interface-usage\":{}},{\"bbf-l2-forwarding:mac-learning\":{\"number-committed-mac-addresses\":1,\"mac-learning-enable\":true,\"mac-learning-failure-action\":\"forward\",\"max-number-mac-addresses\":4294967295},\"bbf-qos-enhanced-scheduling:egress-tm-objects\":{},\"bbf-qos-traffic-mngt:tm-root\":{},\"bbf-subscriber-profiles:subscriber-profile\":{},\"bbf-sub-interfaces:subif-lower-layer\":{\"interface\":\"enet_uni_ont1_1_1\"},\"name\":\"enet_vlan_ont1\",\"bbf-qos-policies:ingress-qos-policy-profile\":\"IPP0\",\"type\":\"bbf-if-type:vlan-sub-interface\",\"bbf-sub-interfaces:inline-frame-processing\":{\"ingress-rule\":{\"rule\":[{\"name\":\"rule_1\",\"priority\":100,\"flexible-match\":{\"bbf-sub-interface-tagging:match-criteria\":{\"any-frame\":[null],\"any-protocol\":[null],\"untagged\":[null],\"ethernet-frame-type\":\"any\"}},\"ingress-rewrite\":{\"bbf-sub-interface-tagging:pop-tags\":0,\"bbf-sub-interface-tagging:push-tag\":[{\"index\":0,\"dot1q-tag\":{\"vlan-id\":11,\"tag-type\":\"bbf-dot1q-types:c-vlan\",\"pbit-from-tag-index\":0,\"dei-from-tag-index\":0}}]}}]},\"egress-rewrite\":{\"bbf-sub-interface-tagging:pop-tags\":1}},\"enabled\":true,\"bbf-interfaces-performance-management:performance\":{\"enable\":false},\"bbf-interface-usage:interface-usage\":{}}]},\"bbf-qos-policies:policies\":{\"policy\":[{\"name\":\"POLICY_ING\",\"classifiers\":[{\"name\":\"classifier_ing0\"},{\"name\":\"classifier_ing1\"},{\"name\":\"classifier_ing2\"},{\"name\":\"classifier_ing3\"},{\"name\":\"classifier_ing4\"},{\"name\":\"classifier_ing5\"},{\"name\":\"classifier_ing6\"},{\"name\":\"classifier_ing7\"}]},{\"name\":\"POLICY_EG\",\"classifiers\":[{\"name\":\"classifier_eg0\"},{\"name\":\"classifier_eg1\"},{\"name\":\"classifier_eg2\"},{\"name\":\"classifier_eg3\"},{\"name\":\"classifier_eg4\"},{\"name\":\"classifier_eg5\"},{\"name\":\"classifier_eg6\"},{\"name\":\"classifier_eg7\"}]}]}}",
        "utf-8")
    producer.send(KAFKA_CONSUMER_TOPIC, bytes(msg.SerializeToString()))
    assert kafka_if._consumer._last_rcvd_object is None
コード例 #4
0
 def process_proto_message(m):
     logger.info(
         ">> Consumed Topic: {}, partition {}, offset: {}, key {}, value {}, "
         "timestamp {}".format(m.topic, m.partition, m.offset, m.key,
                               m.value, m.timestamp))
     try:
         message = tr451_vomci_nbi_message_pb2.Msg()
         message.ParseFromString(m.value)
         return message, None
     except Exception as e:
         logger.debug('Error Handling {} of Kafka message {}'.format(
             e, m.key))
         return None, e
コード例 #5
0
    def send_error_msg(self, msg, er_string):  #To DO
        er_rsp = tr451_vomci_nbi_message_pb2.Error()
        rsp = tr451_vomci_nbi_message_pb2.Msg()

        er_rsp.error_type = "application"
        er_rsp.error_tag = "invalid-value"
        er_rsp.error_severity = "error"
        er_rsp.error_app_tag = ""
        if er_string is not None:
            er_rsp.error_message = er_string
        else:
            er_rsp.error_message = "Invalid parameter"
        tp = msg.body.request.WhichOneof('req_type')
        if tp == 'rpc':
            er_rsp.error_path = "/bbf-vomci-func:create-onu/name"
        self._producer.send_proto_response(msg)
コード例 #6
0
 def make_alignment_notification(self, onu_name: str, is_aligned: bool):
     notif = tr451_vomci_nbi_message_pb2.Msg()
     notif.header.msg_id = "1"
     notif.header.sender_name = self._vomci.name
     managed_onu = ManagementChain.GetOnu(onu_name)
     notif.header.recipient_name = managed_onu.voltmf_name
     notif.header.object_name = onu_name
     header = '{"bbf-vomci-function:onu-alignment-status":{'
     iso_time = datetime.datetime.utcnow().replace(
         tzinfo=datetime.timezone.utc, microsecond=0).isoformat()
     event_time = '"event-time" : "' + iso_time + '"'
     onu = '"onu-name":"' + onu_name + '"'
     if is_aligned:
         alignment_status = '"alignment-status": "aligned"'
     else:
         alignment_status = '"alignment-status": "unaligned"'
     data_str = header + event_time + ',' + onu + ',' + alignment_status + '}}'
     notif.body.notification.data = bytes(data_str, 'utf-8')
     return notif
コード例 #7
0
    def send_unsuccessful_response(self, onu_name, gpb=None, error_msg=None):
        rsp = tr451_vomci_nbi_message_pb2.Msg()
        er_rsp = tr451_vomci_nbi_message_pb2.Error()

        logger.info(
            "Sending unsuccessful response. onu_name={} gpb {} error_msg='{}'".
            format(onu_name, (gpb is None) and "set" or "None", error_msg))
        msg = None
        if gpb is not None:
            msg = gpb
        elif onu_name is not None and onu_name in self.proto_resp:
            msg = self.proto_resp[onu_name]
            del self.proto_resp[onu_name]
        if msg is None:
            logger.error(
                '!!! Internal error. msg is None. onu_name={} proto_resp={} gpb={}'
                .format(onu_name, self.proto_resp), gpb)
            assert False

        rsp.header.msg_id = msg.header.msg_id
        rsp.header.recipient_name = msg.header.sender_name
        rsp.header.sender_name = msg.header.recipient_name
        rsp.header.object_name = msg.header.object_name
        ob_type = msg.header.OBJECT_TYPE.Name(msg.header.object_type)
        if onu_name is not None and onu_name in self.proto_resp:
            del self.proto_resp[onu_name]
        if ob_type == 'VOMCI_FUNCTION':
            rsp.header.object_type = tr451_vomci_nbi_message_pb2.Header.OBJECT_TYPE.VOMCI_FUNCTION
        if ob_type == 'VOMCI_PROXY':
            rsp.header.object_type = tr451_vomci_nbi_message_pb2.Header.OBJECT_TYPE.VOMCI_PROXY
        if ob_type == 'ONU':
            rsp.header.object_type = tr451_vomci_nbi_message_pb2.Header.OBJECT_TYPE.ONU

        tp = msg.body.request.WhichOneof('req_type')
        logger.info('received request type :{}'.format(tp))
        if error_msg is not None:
            er_rsp.error_message = error_msg
        else:
            er_rsp.error_message = "Invalid parameter"
        er_rsp.error_severity = "error"
        er_rsp.error_type = "application"
        if tp == 'rpc':
            rsp.body.response.rpc_resp.status_resp.status_code = 1
            er_rsp.error_path = "/bbf-vomci-func:create-onu/name"
            rsp.body.response.rpc_resp.status_resp.error.append(er_rsp)
        elif tp == 'action':
            rsp.body.response.action_resp.status_resp.status_code = 1
            onu_str = "/bbf-vomci-function:managed-onus/managed-onu[name='onu1']"
            if onu_name is not None:
                st = onu_str.replace("onu1", onu_name)
                er_rsp.error_path = st
            else:
                er_rsp.error_path = onu_str
            rsp.body.response.action_resp.status_resp.error.append(er_rsp)
        elif tp == 'replace_config':
            rsp.body.response.replace_config_resp.status_resp.status_code = 1
            rsp.body.response.replace_config_resp.status_resp.error.append(
                er_rsp)
        logger.info(
            'GPB Processing failed,sending Unsuccessful response to VOLTMF:{}'.
            format(rsp))
        self._producer.send_proto_response(rsp)
コード例 #8
0
    def handle_incoming_proto_msg(self, m):
        logger.info(
            '> Incoming Message Handled {}:{}:{}: key= {} value= {}'.format(
                m.topic, m.partition, m.offset, m.key, m.value))
        proto, e = self.process_proto_message(m)
        if proto is None:
            proto = tr451_vomci_nbi_message_pb2.Msg()
            self.send_unsuccessful_response(None,
                                            proto.ParseFromString(m.value),
                                            str(e))
            return
        er_rsp = tr451_vomci_nbi_message_pb2.Error()
        response = proto
        payload = None
        yangpayload = {}
        logger.debug("Parsed protobuf message is: {}".format(proto))
        if proto.HasField('header') and proto.HasField('body'):
            hdr = proto.header
            logger.info('Extracted Header of the protobuf msg: {}'.format(hdr))
            body = proto.body
            logger.info('Extracted Body of the protobuf msg: {}'.format(body))
        else:
            logger.error(
                "Header and/or body of the received protobuf message is NULL")
            er_string = "Received a null protobuff"
            self.send_unsuccessful_response(None, proto, er_string)
            return

        if hdr.msg_id and hdr.sender_name and hdr.recipient_name and hdr.object_name:
            sender_name = hdr.sender_name
            obj_type = hdr.OBJECT_TYPE.Name(hdr.object_type)
            if obj_type == 'VOMCI_FUNCTION' or obj_type == 'VOMCI_PROXY':
                if body.WhichOneof('msg_body') == 'request':
                    request = body.request
                    if request.WhichOneof('req_type') == 'rpc':
                        input_data = body.request.rpc.input_data.decode(
                            "utf-8")
                        try:
                            payload = json.loads(input_data)
                        except Exception as e:
                            logger.error(
                                'Error {} Handling of input_data {}'.format(
                                    e, input_data))
                            self.send_unsuccessful_response(
                                None, proto, str(e))
                            return
                        logger.info(
                            'Json dict of yang data:{}'.format(payload))
                    elif request.WhichOneof('req_type') == 'action':
                        input_data = body.request.action.input_data.decode(
                            "utf-8")
                        try:
                            payload = json.loads(input_data)
                        except Exception as e:
                            logger.error(
                                'Error {} Handling of input_data {}'.format(
                                    e, input_data))
                            self.send_unsuccessful_response(
                                None, proto, str(e))
                            return
                        logger.info(
                            'Json dict of received yang data:{}'.format(
                                payload))
                    else:
                        logger.error(
                            'Error. type not Implemented yet:{}'.format(
                                request.WhichOneof('req_type')))
                        return None
                elif body.WhichOneof('msg_body') == 'response':
                    logger.info(
                        'msg_type response handling is not implemeneted')
                    return None
                elif body.WhichOneof('msg_body') == 'notification':
                    logger.info(
                        'msg_type notification handling is not implemented')
                    return None
                else:
                    er_string = "Unknown Message type"
                    logger.error(er_string)
                    self.send_unsuccessful_response(None, proto, er_string)
                    return
            elif obj_type == 'ONU':
                request = body.request
                if request.WhichOneof('req_type') == 'replace_config':
                    input_data = request.replace_config.config_inst.decode(
                        "utf-8")
                    try:
                        yangpayload['config_inst'] = json.loads(input_data)
                    except Exception as e:
                        logger.error(
                            'Error {} Handling of config_inst {}'.format(
                                e, input_data))
                        self.send_unsuccessful_response(None, proto, str(e))
                        return
                    logger.info('Json dict of received yang request:{}'.format(
                        yangpayload))
                elif request.WhichOneof('req_type') == 'update_config':
                    updconf = request.update_config
                    if updconf.WhichOneof('req_type') == 'update_config_inst':
                        inCurrent = updconf.update_config_inst.current_config_inst.decode(
                            "utf-8")
                        try:
                            current = json.loads(inCurrent)
                        except Exception as e:
                            logger.error(
                                'Error {} Handling of current_config_inst {}'.
                                format(e, inCurrent))
                            self.send_unsuccessful_response(
                                None, proto, str(e))
                            return
                        logger.info(
                            'Json dict of received current config yang request:{}'
                            .format(current))
                        inDelta = updconf.update_config_inst.delta_config.decode(
                            "utf-8")
                        try:
                            delta = json.loads(inDelta)
                        except Exception as e:
                            logger.error(
                                'Error {} Handling of delta_config {}'.format(
                                    e, inDelta))
                            self.send_unsuccessful_response(
                                None, proto, str(e))
                            return
                        yangpayload['current_config_inst'] = current
                        yangpayload['delta_config'] = delta
                        logger.info(
                            'Json Dict of received delta config yang payload:{}'
                            .format(yangpayload))
                    elif updconf.WhichOneof(
                            'req_type') == 'update_config_replica':
                        inDelta = updconf.update_config_replica.delta_config.decode(
                            "utf-8")
                        try:
                            yangpayload['delta_config'] = json.loads(inDelta)
                        except Exception as e:
                            logger.error(
                                'Error {} Handling of delta_config {}'.format(
                                    e, inDelta))
                            self.send_unsuccessful_response(
                                None, proto, str(e))
                            return
                        logger.info(
                            'Jason Dict of received delta config replica:{}'.
                            format(yangpayload))
                    else:
                        logger.info(
                            'unsupported update_config yang request {} for object type ONU'
                            .format(updconf.WhichOneof('req_type')))
                        return
                else:
                    logger.info(
                        'unsupported yang request {} for object type ONU'.
                        format(request.WhichOneof('req_type')))
                    return
            elif obj_type == 'VOLTMF':
                logger.info('OBJECT TYPE is VOLTMF, Not Implemented Yet')
                return
            else:
                logger.error('Error. Unknown OBJECT TYPE')
                return
        else:
            logger.error('ERROR. message Header is Malformed')
            return

        onu_name = None
        olt_name = None
        channel_termination = None
        onu_id = None
        create_onu = False
        if payload is not None:
            if "bbf-vomci-function:create-onu" in payload:
                onudata = payload['bbf-vomci-function:create-onu']
                create_onu = True
            elif 'bbf-vomci-proxy:create-onu' in payload:
                onudata = payload['bbf-vomci-proxy:create-onu']
                create_onu = True
            elif 'bbf-vomci-function:managed-onus' in payload:
                onudata = payload['bbf-vomci-function:managed-onus']
            elif 'bbf-vomci-proxy:managed-onus' in payload:
                onudata = payload['bbf-vomci-proxy:managed-onus']
            else:
                er_string = "Can't decode the payload"
                self.send_unsuccessful_response(None, proto, er_string)
                return
            logger.info('Extracted onu data:{}'.format(onudata))

            if create_onu:
                onu_name = onudata["name"]
                if onu_name is None:
                    er_string = "onu_name is NONE"
                    self.send_unsuccessful_response(None, proto, er_string)
                    return
                self.proto_resp[onu_name] = response
                self._vomci.trigger_create_onu(onu_name)
            elif 'managed-onu' in onudata:
                for data in onudata['managed-onu']:
                    onu_name = None
                    if 'name' in data:
                        onu_name = data['name']
                    if onu_name is None:
                        er_string = "onu-name is NONE"
                        logger.error(er_string)
                        self.send_unsuccessful_response(None, proto, er_string)
                        return

                    self.proto_resp[onu_name] = response
                    if 'delete-onu' in data:
                        logger.info(
                            'Triggering ONU Delete for:{}'.format(onu_name))
                        self._vomci.trigger_delete_onu(onu_name)
                    elif 'set-onu-communication' in data:
                        epdata = data.get('set-onu-communication')
                        if epdata is None:
                            er_string = "ONU header is missing in the payload for ONU {}".format(
                                onu_name)
                            logger.error(er_string)
                            self.send_unsuccessful_response(
                                None, proto, er_string)
                            return
                        onu_header = epdata['onu-attachment-point']
                        olt_name = onu_header.get('olt-name')
                        channel_termination = onu_header.get(
                            'channel-termination-name')
                        onu_id = onu_header.get('onu-id')
                        if onu_id is not None:
                            try:
                                onu_tc_id = int(onu_id)
                            except:
                                er_string = "ONU {}: Invalid TC ONU ID {}".format(
                                    onu_name, onu_id)
                                logger.error(er_string)
                                self.send_unsuccessful_response(
                                    None, proto, er_string)
                                return
                        available = 'onu-communication-available' in epdata and \
                                    epdata['onu-communication-available'] or False
                        olt_endpoint_name = epdata.get(
                            'olt-remote-endpoint-name')
                        if 'voltmf-remote-endpoint-name' in epdata:
                            south_endpoint_name = epdata[
                                'voltmf-remote-endpoint-name']
                        elif 'vomci-func-remote-endpoint-name' in epdata:
                            south_endpoint_name = epdata[
                                'vomci-func-remote-endpoint-name']
                        if available:
                            if olt_endpoint_name is None:
                                er_string = "ONU {}: olt-remote-endpoint-name must be set if onu-communication-available is True".format(
                                    onu_name)
                                logger.error(er_string)
                                self.send_unsuccessful_response(
                                    None, proto, er_string)
                                return
                            if channel_termination is None:
                                er_string = "ONU {}: channel-termination must be set if onu-communication-available is True".format(
                                    onu_name)
                                logger.error(er_string)
                                self.send_unsuccessful_response(
                                    None, proto, er_string)
                                return
                            if onu_id is None:
                                er_string = "ONU {}: onu-id must be set if onu-communication-available is True".format(
                                    onu_name)
                                logger.error(er_string)
                                self.send_unsuccessful_response(
                                    None, proto, er_string)
                                return

                        # Handle set_onu_communication
                        logger.info(
                            'Triggering set_onu_communication for onu_id:{} \
                                    olt-name:{} olt_endpoint_name:{} \
                                    south_endpoint_name:{}'.format(
                                onu_id, olt_name, olt_endpoint_name,
                                south_endpoint_name))
                        self._vomci.trigger_set_onu_communication(
                            olt_name, onu_name, channel_termination, onu_tc_id,
                            available, olt_endpoint_name, south_endpoint_name,
                            sender_name)
                    else:
                        er_string = "UNIMPLEMENTED Request"
                        logger.error(er_string)
                        self.send_unsuccessful_response(None, proto, er_string)
                        return
            else:
                er_string = "missing ONU data"
                logger.error(er_string)
                self.send_unsuccessful_response(None, proto, er_string)
                return
        elif yangpayload:
            onu_name = hdr.object_name
            if onu_name is None:
                er_string = "ONU Name is None"
                logger.error(er_string)
                self.send_unsuccessful_response(None, proto, er_string)
                return

            self.proto_resp[onu_name] = response
            managed_onu = ManagementChain.GetOnu(onu_name)
            if managed_onu is None:
                er_string = 'ONU {} not in the managed-onus database'.format(
                    onu_name)
                logger.error(er_string)
                self.send_unsuccessful_response(None, proto, er_string)
                return

            # Communication path to the ONU must be available
            if not managed_onu.IsConnected():
                er_string = 'ONU {}: communication path is not available'.format(
                    onu_name)
                logger.error(er_string)
                self.send_unsuccessful_response(None, proto, er_string)
                return
            olt_name = (managed_onu.olt_name,
                        managed_onu.downstream_endpoint_name)
            logger.info('Starting configuration of ONU {} at OLT {} ..'.format(
                onu_name, olt_name))
            try:
                ret_val = extractPayload(self._vomci, onu_name, olt_name,
                                         yangpayload)
                if ret_val != OMHStatus.OK:
                    er_string = "payload processsing failed for ONU:{},reason:{}".format(
                        onu_name, str(ret_val))
                    logger.error(er_string)
                    self.send_unsuccessful_response(None, proto, er_string)
                    return
                # handler was submitted. response will be sent when it finishes
            except Exception as e:
                logger.error(
                    "extractPayload failed for ONU:{},reason:{}".format(
                        onu_name, e))
                self.send_unsuccessful_response(None, proto, str(e))
                return
        else:
            logger.error('ERROR. Payload is NULL')
            er_string = "Yang Payload is NULL"
            self.send_unsuccessful_response(None, proto, er_string)
            return
        return