示例#1
0
    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()
示例#3
0
# 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:
示例#4
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import threading
import time
import logging
from omci_logger import OmciLogger
import vomci
import sys
from mapper.yang_to_omci_mapper import extractPayload
import json

OmciLogger(level=logging.DEBUG)
logger = OmciLogger.getLogger(__name__)


def start_vomci_threads():
    logger.debug('Starting vomci')
    v_omci = vomci.VOmci()
    v_omci.start()
    while True:
        time.sleep(20)
    # send_msg_to_proxy(v_omci)


def send_msg_to_proxy(v_omci):
    logger.info("sending a message to proxy")
    msg = b'this is a just a test message from vomci....'
示例#5
0
import json
import threading
import time
import nbi.kafka_interface as kafka_interface
from omci_logger import OmciLogger
import vomci

DEFAULT_BOOTSTRAP_SERVERS = kafka_interface.DEFAULT_BOOTSTRAP_SERVERS
logger = OmciLogger.getDebugLogger(__name__)
# logger.basicConfig(level=logging.DEBUG)
KAFKA_CONSUMER_TOPIC = kafka_interface.KAFKA_REQUEST_TOPICS[0]
KAFKA_RESPONSE_TOPIC = kafka_interface.KAFKA_RESPONSE_TOPIC


def create_consumer():
    print("--Starting Consumer")
    nbi_consumer = kafka_interface.RequestConsumer(
        topics=[KAFKA_CONSUMER_TOPIC, 'abc'],
        bootstrap_servers=[DEFAULT_BOOTSTRAP_SERVERS])
    return nbi_consumer


def create_consumer_with_timeout():
    print("--Starting Consumer with_timeout")
    nbi_consumer = kafka_interface.RequestConsumer(
        topics=[KAFKA_CONSUMER_TOPIC, 'abc'],
        bootstrap_servers=[DEFAULT_BOOTSTRAP_SERVERS],
        consumer_timeout_ms=10000)
    return nbi_consumer