# 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/switch.py
# class Switch(BaseModel):
#     # Buffers
#     buffers = models.IntegerField()
# 
#     # Description
#     software = models.CharField(max_length=100)
#     hardware = models.CharField(max_length=100)
#     manufacturer = models.CharField(max_length=100)
#     serial_num = models.CharField(max_length=100)
#     datapath = models.CharField(max_length=100)
# 
#     # Capabilities
#     capabilities = models.IntegerField()
# 
#     # Inet Address
#     inet_address = models.CharField(max_length=100)
# 
#     # Connected Since
#     connected_since = models.BigIntegerField()
# 
#     # DPID
#     dpid = models.CharField(max_length=100, db_index=True)
# 
#     # Foreign key to controller
#     controller = models.ForeignKey(Controller)
# 
# Path: sdn/models/openflow_port_counter1_0.py
# 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']
#         try:
#             opc = OpenflowPortCounter1_0.objects.get(port=self.port)
#             opc.received_packets = self.received_packets
#             opc.transmitted_packets = self.transmitted_packets
#             opc.received_bytes = self.received_bytes
#             opc.transmitted_bytes = self.transmitted_bytes
#             opc.received_drops = self.received_drops
#             opc.transmit_drops = self.transmit_drops
#             opc.receive_errors = self.receive_errors
#             opc.transmit_errors = self.transmit_errors
#             opc.receive_frame_alignment_errors = self.receive_frame_alignment_errors
#             opc.receive_overrun_erros = self.receive_overrun_erros
#             opc.receive_crc_errors = self.receive_crc_errors
#             opc.collisions = self.collisions
#             opc.save()
#         except OpenflowPortCounter1_0.DoesNotExist:
#             self.save()


from django.db import models
from sdn.models.base_model import BaseModel
from sdn.models.switch import Switch
from sdn.models.openflow_port_counter1_0 import OpenflowPortCounter1_0
# -*- coding: utf-8 -*-


# Create your models here.
class Port(BaseModel):
    port_number = models.IntegerField()
    hardware_address = models.CharField(max_length=100)
    name = models.CharField(max_length=100)
    config = models.IntegerField()
    state = models.IntegerField()
    current_features = models.IntegerField()
    advertised_features = models.IntegerField()
    supported_features = models.IntegerField()
    peer_features = models.IntegerField()

    # Foreign key to switch
    switch = models.ForeignKey(Switch)

    def sync(self, port_description, port_counters):
        self.port_number = port_description['portNumber']
        self.hardware_address = port_description['hardwareAddress']
        self.name = port_description['name']
        self.config = port_description['config']
        self.state = port_description['state']
        self.current_features = port_description['currentFeatures']
        self.advertised_features = port_description['advertisedFeatures']

# 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/switch.py
# class Switch(BaseModel):
#     # Buffers
#     buffers = models.IntegerField()
# 
#     # Description
#     software = models.CharField(max_length=100)
#     hardware = models.CharField(max_length=100)
#     manufacturer = models.CharField(max_length=100)
#     serial_num = models.CharField(max_length=100)
#     datapath = models.CharField(max_length=100)
# 
#     # Capabilities
#     capabilities = models.IntegerField()
# 
#     # Inet Address
#     inet_address = models.CharField(max_length=100)
# 
#     # Connected Since
#     connected_since = models.BigIntegerField()
# 
#     # DPID
#     dpid = models.CharField(max_length=100, db_index=True)
# 
#     # Foreign key to controller
#     controller = models.ForeignKey(Controller)
# 
# Path: sdn/models/openflow_port_counter1_0.py
# 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']
#         try:
#             opc = OpenflowPortCounter1_0.objects.get(port=self.port)
#             opc.received_packets = self.received_packets
#             opc.transmitted_packets = self.transmitted_packets
#             opc.received_bytes = self.received_bytes
#             opc.transmitted_bytes = self.transmitted_bytes
#             opc.received_drops = self.received_drops
#             opc.transmit_drops = self.transmit_drops
#             opc.receive_errors = self.receive_errors
#             opc.transmit_errors = self.transmit_errors
#             opc.receive_frame_alignment_errors = self.receive_frame_alignment_errors
#             opc.receive_overrun_erros = self.receive_overrun_erros
#             opc.receive_crc_errors = self.receive_crc_errors
#             opc.collisions = self.collisions
#             opc.save()
#         except OpenflowPortCounter1_0.DoesNotExist:
#             self.save()


# Path: sdn/models/port.py
from django.db import models
from sdn.models.base_model import BaseModel
from sdn.models.switch import Switch
from sdn.models.openflow_port_counter1_0 import OpenflowPortCounter1_0

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


# Create your models here.
class Port(BaseModel):
    port_number = models.IntegerField()
    hardware_address = models.CharField(max_length=100)
    name = models.CharField(max_length=100)
    config = models.IntegerField()
    state = models.IntegerField()
    current_features = models.IntegerField()
    advertised_features = models.IntegerField()
    supported_features = models.IntegerField()
    peer_features = models.IntegerField()

    # Foreign key to switch
    switch = models.ForeignKey(Switch)

    def sync(self, port_description, port_counters):
        self.port_number = port_description['portNumber']
        self.hardware_address = port_description['hardwareAddress']
        self.name = port_description['name']
        self.config = port_description['config']
        self.state = port_description['state']
        self.current_features = port_description['currentFeatures']
        self.advertised_features = port_description['advertisedFeatures']

        self.supported_features = port_description['supportedFeatures']