Commit a65b35ea authored by Alberto Gonzalez Barneo's avatar Alberto Gonzalez Barneo
Browse files

Added the components needed to work with qkd in webui

parent 6c4ef63c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ class AddDeviceForm(FlaskForm):
    device_drivers_gnmi_openconfig = BooleanField('GNMI OPENCONFIG')
    device_drivers_optical_tfs = BooleanField('OPTICAL TFS')
    device_drivers_ietf_actn = BooleanField('IETF ACTN')
    device_drivers_qkd = BooleanField('QKD')

    device_config_address = StringField('connect/address',default='127.0.0.1',validators=[DataRequired(), Length(min=5)])
    device_config_port = StringField('connect/port',default='0',validators=[DataRequired(), Length(min=1)])
+3 −1
Original line number Diff line number Diff line
@@ -129,6 +129,8 @@ def add():
            device_drivers.append(DeviceDriverEnum.DEVICEDRIVER_OPTICAL_TFS)
        if form.device_drivers_ietf_actn.data:
            device_drivers.append(DeviceDriverEnum.DEVICEDRIVER_IETF_ACTN)
        if form.device_drivers_qkd.data:
            device_drivers.append(DeviceDriverEnum.DEVICEDRIVER_QKD)
        device_obj.device_drivers.extend(device_drivers) # pylint: disable=no-member

        try:
+25 −2
Original line number Diff line number Diff line
@@ -17,6 +17,11 @@ from flask_wtf import FlaskForm
from wtforms import StringField, SelectField, IntegerField, DecimalField
from wtforms.validators import InputRequired, Optional, NumberRange, ValidationError, StopValidation

# Custom uuid validator
def validate_uuid_address(form, field):
    if not re.match(r'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$', field.data):
        raise ValidationError('Invalid uuid format')

# Custom IPv4 address validator
def validate_ipv4_address(form, field):
    try:
@@ -60,7 +65,25 @@ class CustomInputRequired():
            raise StopValidation(self.message)
        
class AddServiceForm_1(FlaskForm):
    service_type = SelectField('Type of service', choices=[('', 'Select a type of service to add'), ('ACL_L2', 'ACL_L2'), ('ACL_IPV4', 'ACL_IPV4'), ('ACL_IPV6', 'ACL_IPV6'), ('L2VPN', 'L2VPN'), ('L3VPN', 'L3VPN')], validators=[InputRequired()])
    service_type = SelectField('Type of service', choices=[('', 'Select a type of service to add'), ('ACL_L2', 'ACL_L2'), ('ACL_IPV4', 'ACL_IPV4'), ('ACL_IPV6', 'ACL_IPV6'), ('L2VPN', 'L2VPN'), ('L3VPN', 'L3VPN'), ('QKD', 'QKD')], validators=[InputRequired()])

class AddServiceForm_QKD(FlaskForm):
    #GENERIC SERVICE PARAMETERS (COMMON & MANDATORY)
    service_name       = StringField('Service Name', validators=[CustomInputRequired()])
    service_type       = SelectField('Service Type', choices=[(6, '6 (QKD)')], validators=[CustomInputRequired()])
    service_device_1   = SelectField('Device_1', choices=[('', 'Select a device (Mandatory)')], validators=[CustomInputRequired()])
    service_device_2   = SelectField('Device_2', choices=[('', 'Select a device (Mandatory)')], validators=[CustomInputRequired()])
    service_endpoint_1 = StringField('Device_1 Endpoint', validators=[CustomInputRequired()])
    service_endpoint_2 = StringField('Device_2 Endpoint', validators=[CustomInputRequired()])
    
    #GENERIC SERVICE CONSTRAINT PARAMETERS (ALL OPTIONAL)
    service_capacity    = DecimalField('Service Capacity', places=2, default=10.00, validators=[Optional(), NumberRange(min=0)])
    service_latency     = DecimalField('Service Latency', places=2, default=15.20, validators=[Optional(), NumberRange(min=0)])
    service_availability= DecimalField('Service Availability', places=2, validators=[Optional(), NumberRange(min=0)])
    service_isolation   = SelectField('Service Isolation', choices=[('', 'Select (Optional)'), ('NO_ISOLATION', 'NO_ISOLATION'), ('PHYSICAL_ISOLATION', 'PHYSICAL_ISOLATION'), 
                                                                    ('LOGICAL_ISOLATION', 'LOGICAL_ISOLATION'), ('PROCESS_ISOLATION', 'PROCESS_ISOLATION'), ('PHYSICAL_MEMORY_ISOLATION', 'PHYSICAL_MEMORY_ISOLATION'), 
                                                                    ('PHYSICAL_NETWORK_ISOLATION', 'PHYSICAL_NETWORK_ISOLATION'), ('VIRTUAL_RESOURCE_ISOLATION', 'VIRTUAL_RESOURCE_ISOLATION'), 
                                                                    ('NETWORK_FUNCTIONS_ISOLATION', 'NETWORK_FUNCTIONS_ISOLATION'), ('SERVICE_ISOLATION', 'SERVICE_ISOLATION')], validators=[Optional()])

class AddServiceForm_ACL_L2(FlaskForm):
    #GENERIC SERVICE PARAMETERS (COMMON & MANDATORY)
+80 −4
Original line number Diff line number Diff line
@@ -35,14 +35,14 @@ from common.tools.object_factory.Constraint import (
from common.tools.object_factory.Context import json_context_id
from common.tools.object_factory.Device import json_device_id
from common.tools.object_factory.EndPoint import json_endpoint_id
from common.tools.object_factory.Service import json_service_l2nm_planned, json_service_l3nm_planned
from common.tools.object_factory.Service import json_service_l2nm_planned, json_service_l3nm_planned, json_service_qkd_planned
from common.tools.object_factory.Topology import json_topology_id
from context.client.ContextClient import ContextClient
from device.client.DeviceClient import DeviceClient
from service.client.ServiceClient import ServiceClient
from webui.service.service.forms import (
    AddServiceForm_1, AddServiceForm_ACL_L2, AddServiceForm_ACL_IPV4, AddServiceForm_ACL_IPV6,
    AddServiceForm_L2VPN, AddServiceForm_L3VPN
    AddServiceForm_L2VPN, AddServiceForm_L3VPN, AddServiceForm_QKD
)

LOGGER = logging.getLogger(__name__)
@@ -329,10 +329,83 @@ def add_configure():
    form_1 = AddServiceForm_1()
    if form_1.validate_on_submit():
        service_type = str(form_1.service_type.data)
        if service_type in {'ACL_L2', 'ACL_IPV4', 'ACL_IPV6', 'L2VPN', 'L3VPN'}:
        if service_type in {'ACL_L2', 'ACL_IPV4', 'ACL_IPV6', 'L2VPN', 'L3VPN', 'QKD'}:
            return redirect(url_for('service.add_configure_{:s}'.format(service_type)))
    return render_template('service/add.html', form_1=form_1, submit_text='Continue to configuraton')

@service.route('add/configure/QKD', methods=['GET', 'POST'])
def add_configure_QKD():
    form_qkd = AddServiceForm_QKD()
    service_obj = Service()

    context_uuid, topology_uuid = get_context_and_topology_uuids()
    if context_uuid and topology_uuid:
        context_client.connect()
        grpc_topology = get_topology(context_client, topology_uuid, context_uuid=context_uuid, rw_copy=False)
        if grpc_topology:
            topo_device_uuids = {device_id.device_uuid.uuid for device_id in grpc_topology.device_ids}          
            devices = get_filtered_devices(context_client, topo_device_uuids)
            grpc_devices = context_client.ListDevices(Empty())                                          
            devices = [
                device for device in grpc_devices.devices
                if device.device_id.device_uuid.uuid in topo_device_uuids and DeviceDriverEnum.DEVICEDRIVER_QKD in device.device_drivers
            ]
            choices = get_device_choices(devices)
            add_device_choices_to_form(choices, form_qkd.service_device_1)
            add_device_choices_to_form(choices, form_qkd.service_device_2)
        else:
            flash('Context({:s})/Topology({:s}) not found'.format(str(context_uuid), str(topology_uuid)), 'danger')
    else:
        flash('Missing context or topology UUID', 'danger')

    if form_qkd.validate_on_submit():
        try:
            [selected_device_1, selected_device_2, selected_endpoint_1, selected_endpoint_2] = validate_selected_devices_and_endpoints(form_qkd, devices)
        except Exception as e:
            flash('{:s}'.format(str(e.args[0])), 'danger')
            current_app.logger.exception(e)
            return render_template('service/configure_QKD.html', form_qkd=form_qkd, submit_text='Add New Service')
        
        service_uuid, service_type, endpoint_ids = set_service_parameters(service_obj, form_qkd, selected_device_1, selected_device_2, selected_endpoint_1, selected_endpoint_2)
        constraints = add_constraints(form_qkd)
        params_device_1_with_data = get_device_params(form_qkd, 1, service_type)
        params_device_2_with_data = get_device_params(form_qkd, 2, service_type)
        print(params_device_1_with_data)
        print(params_device_2_with_data)
        params_settings = {}
        config_rules = [
            json_config_rule_set(
                    '/settings', params_settings
                ),
            json_config_rule_set(
                '/device[{:s}]/endpoint[{:s}]/settings'.format(str(selected_device_1.name), str(selected_endpoint_1)), params_device_1_with_data
            ),
            json_config_rule_set(
                '/device[{:s}]/endpoint[{:s}]/settings'.format(str(selected_device_2.name), str(selected_endpoint_2)), params_device_2_with_data
            )
        ]

        service_client.connect()
        context_client.connect()
        device_client.connect()
        descriptor_json = json_service_qkd_planned(service_uuid = service_uuid, endpoint_ids = endpoint_ids, constraints = constraints, config_rules = config_rules, context_uuid= context_uuid)
        descriptor_json = {"services": [descriptor_json]}
        try:
            process_descriptors(descriptor_json)
            flash('Service "{:s}" added successfully!'.format(service_obj.service_id.service_uuid.uuid), 'success')
            return redirect(url_for('service.home', service_uuid=service_obj.service_id.service_uuid.uuid))
        except Exception as e:
            flash('Problem adding service: {:s}'.format((str(e.args[0]))), 'danger')
            current_app.logger.exception(e)
        finally:
            context_client.close()                                                                                      
            device_client.close()
            service_client.close()

    
    return render_template('service/configure_QKD.html', form_qkd=form_qkd, submit_text='Add New Service')


@service.route('add/configure/ACL_L2', methods=['GET', 'POST'])
def add_configure_ACL_L2():
    form_acl = AddServiceForm_ACL_L2()
@@ -666,6 +739,9 @@ def get_device_params(form, device_num, form_type):
            'ni_description': str(getattr(form, 'NI_description').data),
            'subif_description': str(getattr(form, f'Device_{device_num}_IF_description').data),
        }
    elif form_type == 6:
        device_params = {
        }
    else:
        raise ValueError(f'Unsupported form type: {form_type}')

+58.7 KiB
Loading image diff...
Loading