# 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
# -*- coding: utf-8 -*-


# Create your models here.
class OpenflowFlowTableCounter1_0(BaseModel):

    # Per Table
    active_entries = models.IntegerField(null=True)
    packet_lookups = models.BigIntegerField(null=True)
    packet_matches = models.BigIntegerField(null=True)

    # Foreign key to a openflow table 1_0
    openflow_table1_0 = models.ForeignKey('OpenflowFlowTable1_0')

    def sync(self, table_description):
        self.active_entries = table_description['activeCount']
        self.packet_lookups = table_description['lookupCount']
        self.packet_matches = table_description['matchedCount']
        try:
            oftc = OpenflowFlowTableCounter1_0.objects.get(openflow_table1_0=self.openflow_table1_0)
            oftc.active_entries = self.active_entries

# 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_flowtable_counter1_0.py
from django.db import models
from sdn.models.base_model import BaseModel

# -*- coding: utf-8 -*-


# Create your models here.
class OpenflowFlowTableCounter1_0(BaseModel):

    # Per Table
    active_entries = models.IntegerField(null=True)
    packet_lookups = models.BigIntegerField(null=True)
    packet_matches = models.BigIntegerField(null=True)

    # Foreign key to a openflow table 1_0
    openflow_table1_0 = models.ForeignKey('OpenflowFlowTable1_0')

    def sync(self, table_description):
        self.active_entries = table_description['activeCount']
        self.packet_lookups = table_description['lookupCount']
        self.packet_matches = table_description['matchedCount']
        try:
            oftc = OpenflowFlowTableCounter1_0.objects.get(openflow_table1_0=self.openflow_table1_0)
            oftc.active_entries = self.active_entries

            oftc.packet_lookups = self.packet_lookups