# 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/port.py
# 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']
#         self.peer_features = port_description['peerFeatures']
# 
#         # Create a port counter
#         ofpc = OpenflowPortCounter1_0()
#         try:
#             # Verify if this port already exists
#             p = Port.objects.get(port_number=self.port_number, hardware_address=self.hardware_address, name=self.name)
#             p.config = self.config
#             p.state - self.state
#             p.currentFeatures = self.current_features
#             p.advertised_features = self.advertised_features
#             p.supported_features = self.supported_features
#             p.peer_features = self.peer_features
#             p.save()
#             # Assign port to a port counter
#             ofpc.port = p
#         except Port.DoesNotExist:
#             self.save()
#             # Assign port to a port counter
#             ofpc.port = self
#         # Call port counter sync method
#         ofpc.sync(port_counters)
# 
# Path: sdn/models/openflow_flowtable1_0.py
# class OpenflowFlowTable1_0(BaseModel):
#     # Foreign key to a openflow switch
#     table_id = models.IntegerField()
#     openflow_switch1_0 = models.ForeignKey('OpenflowSwitch1_0')
# 
#     def sync(self, table_description, header_description, sync_time):
#         # The openflow switch 1.0 has one openflow table
#         self.table_id = table_description['tableId']
#         oftc = OpenflowFlowTableCounter1_0()
#         oftable = OpenflowFlowTable1_0()
#         try:
#             oft = OpenflowFlowTable1_0.objects.get(table_id=self.table_id, openflow_switch1_0=self.openflow_switch1_0)
#             oft.table_id = self.table_id
#             oft.openflow_switch1_0 = self.openflow_switch1_0
#             oft.save()
#             oftable = oft
#             oftc.openflow_table1_0 = oft
#         except OpenflowFlowTable1_0.DoesNotExist:
#             self.save()
#             oftable = self
#             oftc.openflow_table1_0 = self
# 
#         # TODO: put table counter in sync method
#         # Adding the table counters
#         oftc.sync(table_description)
# 
#         # Adding the flow headers
#         for header in header_description:
#             ofh = OpenflowHeader1_0()
#             ofh.openflow_table1_0 = oftable
#             ofh.sync(header, sync_time)


from django.db import models
from sdn.models.switch import Switch
from sdn.models.port import Port
from sdn.models.openflow_flowtable1_0 import OpenflowFlowTable1_0
import logging
import time
# -*- coding: utf-8 -*-

# Get an instance of a logger
logger = logging.getLogger(__name__)

SWITCH_CHOICE = (
    ('ofd', 'OPENFLOW_DEDICATED'),
    ('ofe', 'OPENFLOW_ENABLED')
)


# Create your models here.
class OpenflowSwitch1_0(Switch):
    # Switch type
    switch_type = models.CharField(max_length=3, choices=SWITCH_CHOICE)

    def sync(self, switch_description, table_description, header_description, port_description, sync_time, debug_time):
        # TODO: Identify which are switch types)
        self.switch_type = 'ofe'
        self.buffers = switch_description['buffers']
        self.software = switch_description['description']['software']

# 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/port.py
# 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']
#         self.peer_features = port_description['peerFeatures']
# 
#         # Create a port counter
#         ofpc = OpenflowPortCounter1_0()
#         try:
#             # Verify if this port already exists
#             p = Port.objects.get(port_number=self.port_number, hardware_address=self.hardware_address, name=self.name)
#             p.config = self.config
#             p.state - self.state
#             p.currentFeatures = self.current_features
#             p.advertised_features = self.advertised_features
#             p.supported_features = self.supported_features
#             p.peer_features = self.peer_features
#             p.save()
#             # Assign port to a port counter
#             ofpc.port = p
#         except Port.DoesNotExist:
#             self.save()
#             # Assign port to a port counter
#             ofpc.port = self
#         # Call port counter sync method
#         ofpc.sync(port_counters)
# 
# Path: sdn/models/openflow_flowtable1_0.py
# class OpenflowFlowTable1_0(BaseModel):
#     # Foreign key to a openflow switch
#     table_id = models.IntegerField()
#     openflow_switch1_0 = models.ForeignKey('OpenflowSwitch1_0')
# 
#     def sync(self, table_description, header_description, sync_time):
#         # The openflow switch 1.0 has one openflow table
#         self.table_id = table_description['tableId']
#         oftc = OpenflowFlowTableCounter1_0()
#         oftable = OpenflowFlowTable1_0()
#         try:
#             oft = OpenflowFlowTable1_0.objects.get(table_id=self.table_id, openflow_switch1_0=self.openflow_switch1_0)
#             oft.table_id = self.table_id
#             oft.openflow_switch1_0 = self.openflow_switch1_0
#             oft.save()
#             oftable = oft
#             oftc.openflow_table1_0 = oft
#         except OpenflowFlowTable1_0.DoesNotExist:
#             self.save()
#             oftable = self
#             oftc.openflow_table1_0 = self
# 
#         # TODO: put table counter in sync method
#         # Adding the table counters
#         oftc.sync(table_description)
# 
#         # Adding the flow headers
#         for header in header_description:
#             ofh = OpenflowHeader1_0()
#             ofh.openflow_table1_0 = oftable
#             ofh.sync(header, sync_time)


# Path: sdn/models/openflow_switch1_0.py
from django.db import models
from sdn.models.switch import Switch
from sdn.models.port import Port
from sdn.models.openflow_flowtable1_0 import OpenflowFlowTable1_0
import logging
import time

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

# Get an instance of a logger
logger = logging.getLogger(__name__)

SWITCH_CHOICE = (
    ('ofd', 'OPENFLOW_DEDICATED'),
    ('ofe', 'OPENFLOW_ENABLED')
)


# Create your models here.
class OpenflowSwitch1_0(Switch):
    # Switch type
    switch_type = models.CharField(max_length=3, choices=SWITCH_CHOICE)

    def sync(self, switch_description, table_description, header_description, port_description, sync_time, debug_time):
        # TODO: Identify which are switch types)
        self.switch_type = 'ofe'
        self.buffers = switch_description['buffers']
        self.software = switch_description['description']['software']

        self.hardware = switch_description['description']['hardware']