# Path: sdn/models/base_model.py
# class BaseModel(models.Model):
#     class Meta:
#         # Makes django recognize model in split modules
#         app_label = 'sdn'
#         # Turns this into an abstract model (does not create table for it)
#         abstract = True
# 
#     # Default exception for models in manager
#     class ModelException(Exception):
#         # Get an instance of a logger
#         logger = logging.getLogger(__name__)
# 
#         def __init__(self, msg):
#             self.msg = msg
#             self.logger.warning(msg)
# 
#         def __str__(self):
#             return repr(self.msg)


from django.db import models
from sdn.models.base_model import BaseModel
class OpenflowPortCounter1_0(BaseModel):
    # Per Port
    received_packets = models.BigIntegerField(null=True)
    transmitted_packets = models.BigIntegerField(null=True)
    received_bytes = models.BigIntegerField(null=True)
    transmitted_bytes = models.BigIntegerField(null=True)
    received_drops = models.BigIntegerField(null=True)
    transmit_drops = models.BigIntegerField(null=True)
    receive_errors = models.BigIntegerField(null=True)
    transmit_errors = models.BigIntegerField(null=True)
    receive_frame_alignment_errors = models.BigIntegerField(null=True)
    receive_overrun_erros = models.BigIntegerField(null=True)
    receive_crc_errors = models.BigIntegerField(null=True)
    collisions = models.BigIntegerField(null=True)

    # Foreign key to a port
    port = models.ForeignKey('Port')

    def sync(self, port_counters):
        self.received_packets = port_counters['receivePackets']
        self.transmitted_packets = port_counters['transmitPackets']
        self.received_bytes = port_counters['receiveBytes']
        self.transmitted_bytes = port_counters['transmitBytes']
        self.received_drops = port_counters['receiveDropped']
        self.transmit_drops = port_counters['transmitDropped']
        self.receive_errors = port_counters['receiveErrors']
        self.transmit_errors = port_counters['transmitErrors']
        self.receive_frame_alignment_errors = port_counters['receiveFrameErrors']
        self.receive_overrun_erros = port_counters['receiveOverrunErrors']
        self.receive_crc_errors = port_counters['receiveCRCErrors']

# Path: sdn/models/base_model.py
# class BaseModel(models.Model):
#     class Meta:
#         # Makes django recognize model in split modules
#         app_label = 'sdn'
#         # Turns this into an abstract model (does not create table for it)
#         abstract = True
# 
#     # Default exception for models in manager
#     class ModelException(Exception):
#         # Get an instance of a logger
#         logger = logging.getLogger(__name__)
# 
#         def __init__(self, msg):
#             self.msg = msg
#             self.logger.warning(msg)
# 
#         def __str__(self):
#             return repr(self.msg)


# Path: sdn/models/openflow_port_counter1_0.py
from django.db import models
from sdn.models.base_model import BaseModel

class OpenflowPortCounter1_0(BaseModel):
    # Per Port
    received_packets = models.BigIntegerField(null=True)
    transmitted_packets = models.BigIntegerField(null=True)
    received_bytes = models.BigIntegerField(null=True)
    transmitted_bytes = models.BigIntegerField(null=True)
    received_drops = models.BigIntegerField(null=True)
    transmit_drops = models.BigIntegerField(null=True)
    receive_errors = models.BigIntegerField(null=True)
    transmit_errors = models.BigIntegerField(null=True)
    receive_frame_alignment_errors = models.BigIntegerField(null=True)
    receive_overrun_erros = models.BigIntegerField(null=True)
    receive_crc_errors = models.BigIntegerField(null=True)
    collisions = models.BigIntegerField(null=True)

    # Foreign key to a port
    port = models.ForeignKey('Port')

    def sync(self, port_counters):
        self.received_packets = port_counters['receivePackets']
        self.transmitted_packets = port_counters['transmitPackets']
        self.received_bytes = port_counters['receiveBytes']
        self.transmitted_bytes = port_counters['transmitBytes']
        self.received_drops = port_counters['receiveDropped']
        self.transmit_drops = port_counters['transmitDropped']
        self.receive_errors = port_counters['receiveErrors']
        self.transmit_errors = port_counters['transmitErrors']
        self.receive_frame_alignment_errors = port_counters['receiveFrameErrors']
        self.receive_overrun_erros = port_counters['receiveOverrunErrors']
        self.receive_crc_errors = port_counters['receiveCRCErrors']

        self.collisions = port_counters['collisions']