#
# Copyright 2017 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.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.
#
from scapy.fields import ByteField, PacketField, IntField
from scapy.fields import ShortField, ConditionalField
from scapy.packet import Packet

from voltha.extensions.omci.omci_fields import FixedLenField
from voltha.extensions.omci.omci_messages import OmciCreate, OmciDelete, \
    OmciDeleteResponse, OmciSet, OmciSetResponse, OmciGet, OmciGetResponse, \
    OmciGetAllAlarms, OmciGetAllAlarmsResponse, OmciGetAllAlarmsNext, \
    OmciMibResetResponse, OmciMibReset, OmciMibUploadNextResponse, \
    OmciMibUploadNext, OmciMibUploadResponse, OmciMibUpload, \
    OmciGetAllAlarmsNextResponse, OmciAttributeValueChange, \
    OmciTestResult, OmciAlarmNotification, \
    OmciReboot, OmciRebootResponse, OmciGetNext, OmciGetNextResponse, \
    OmciSynchronizeTime, OmciSynchronizeTimeResponse, OmciGetCurrentData, \
    OmciGetCurrentDataResponse, OmciStartSoftwareDownload, OmciStartSoftwareDownloadResponse, \
    OmciDownloadSection, OmciDownloadSectionLast, OmciDownloadSectionResponse, \
    OmciEndSoftwareDownload, OmciEndSoftwareDownloadResponse, \
    OmciActivateImage, OmciActivateImageResponse, \
    OmciCommitImage, OmciCommitImageResponse, OmciTest, OmciTestResponse

from voltha.extensions.omci.omci_messages import OmciCreateResponse


class OmciFrame(Packet):
    name = "OmciFrame"
    fields_desc = [
        ShortField("transaction_id", 0),
        ByteField("message_type", None),
        ByteField("omci", 0x0a),
        ConditionalField(FixedLenField(
            PacketField("omci_message", None, OmciCreate), align=36),
            lambda pkt: pkt.message_type == OmciCreate.message_id),
        ConditionalField(FixedLenField(
            PacketField("omci_message", None, OmciCreateResponse), align=36),
            lambda pkt: pkt.message_type == OmciCreateResponse.message_id),