Beispiel #1
0
def build_eth_config(subnet, template_config):
    plLogger.LogInfo("build_eth_config: ")

    config_utils.init_config(template_config)

    mac_port_step = None
    if subnet["mac_config"]["_type"] != "Profile::UniqueMacConfig":
        mac_port_step = subnet["mac_config"]["mac_port_step"]

    mac_config = subnet["mac_config"]
    dev_count = subnet["device_count_per_port"]
    if mac_config["_type"] == "Profile::UniqueMacConfig":
        if dev_count > 1:
            # randomize mac is handled outside of this command
            return
        else:
            handle_physical_interface_mac(template_config, subnet)
            return
    plLogger.LogInfo(str(mac_config))
    mac = str(mac_config["mac"])
    mac_step = str(mac_config["mac_step"])

    tag_name = tag_name_util.get_ethIIIf_tag(subnet)

    property_value = {
        "className": "EthIIIf",
        "tagName": tag_name,
        "propertyValueList": {
            "SrcMacStep": mac_step
        }
    }
    property_value_list = config_utils.get_property_value_list(template_config)
    property_value_list.append(property_value)

    stm_property_modifier = {
        "className": "EthIIIf",
        "tagName": tag_name + ".SourceMac",
        "parentTagName": tag_name,
        "propertyName": "SourceMac",
        "propertyValueList": {
            "Start": mac,
            "Step": mac_port_step,
            "ResetOnNewTargetObject": False
        }
    }
    stm_property_modifier_list = config_utils.get_stm_property_modifier_list(
        template_config
    )
    stm_property_modifier_list.append(stm_property_modifier)
Beispiel #2
0
def handle_vlan_id_range_modifier(subnet, template_config):
    vlan_config = subnet["vlan_config"]
    vlan_id = str(vlan_config["vlan_id"])
    vlan_id_step = vlan_config["vlan_id_step"]
    repeat_mode = vlan_config["vlan_id_repeat"]
    priority = str(vlan_config["priority"])
    ips_per_vlan = vlan_config["ips_per_vlan"]
    device_count = subnet["device_count_per_port"]

    add_object = {
        "className": "VlanIf",
        "parentTagName": "ttEmulatedDevice",
        "tagName": "vlanIf",
        "propertyValueList": {
            "IdStep": str(vlan_id_step),
            "Priority": priority,
            "IdRepeatCount": str(ips_per_vlan - 1)
        }
    }
    add_object_list = config_utils.get_add_object_list(template_config)
    add_object_list.append(add_object)
    vlan_port_step = 0
    if repeat_mode == "off":
        vlan_port_step = (
            int(device_count) // int(ips_per_vlan)
        ) * vlan_id_step

    stm_property_modifier = {
        "className": "VlanIf",
        "tagName": "vlanIf" + ".VlanId",
        "parentTagName": "vlanIf",
        "propertyName": "VlanId",
        "propertyValueList": {
            "Start": vlan_id,
            "Step": str(vlan_port_step),
            "ResetOnNewTargetObject": False
        }
    }
    stm_property_modifier_list = config_utils.get_stm_property_modifier_list(
        template_config
    )
    stm_property_modifier_list.append(stm_property_modifier)
Beispiel #3
0
def process_gateway_arp_config(subnet, template_config, gw_port_step):
    ipv4_tag = tag_name_util.get_ipv4If_tag(subnet)
    gateway_config = subnet["gateway_config"]
    gw_ip_config = gateway_config.get("ip_config")
    gw = str(gw_ip_config["ipv4"])
    stm_property_modifier = {
        "className": "Ipv4If",
        "tagName": ipv4_tag + ".Gateway",
        "parentTagName": ipv4_tag,
        "propertyName": "Gateway",
        "propertyValueList": {
            "Start": gw,
            "Step": gw_port_step,
            "ResetOnNewTargetObject": False
        }
    }
    stm_property_modifier_list = config_utils.get_stm_property_modifier_list(
        template_config
    )
    stm_property_modifier_list.append(stm_property_modifier)
Beispiel #4
0
def handle_qnq_vlan_range_modifier(subnet, template_config):
    vlan_config = subnet["vlan_config"]
    outer_vlan_id = str(vlan_config["outer_vlan_id"])
    outer_vlan_id_step = vlan_config["outer_vlan_id_step"]
    outer_repeat_mode = str(vlan_config["outer_vlan_id_repeat"])
    outer_priority = str(vlan_config["outer_priority"])
    inner_vlan_id = str(vlan_config["inner_vlan_id"])
    inner_vlan_id_step = vlan_config["inner_vlan_id_step"]
    inner_repeat_mode = str(vlan_config["inner_vlan_id_repeat"])
    inner_priority = str(vlan_config["inner_priority"])
    ips_per_outer_vlan = vlan_config["ips_per_outer_vlan"]
    inner_vlans_per_outer_vlan = vlan_config["inner_vlans_per_outer_vlan"]
    device_count = subnet["device_count_per_port"]

    inner_repeat_count = (
        int(ips_per_outer_vlan) // int(inner_vlans_per_outer_vlan) - 1
    )
    inner_recycle_count = 0
    if inner_repeat_mode == "across_outer":
        inner_recycle_count = inner_vlans_per_outer_vlan - 1

    add_object_outer = {
        "className": "VlanIf",
        "parentTagName": "ttEmulatedDevice",
        "tagName": "outerVlan",
        "propertyValueList": {
            "IdStep": str(outer_vlan_id_step),
            "Priority": outer_priority,
            "IdRepeatCount": str(ips_per_outer_vlan - 1)
        }
    }
    add_object_inner = {
        "className": "VlanIf",
        "parentTagName": "ttEmulatedDevice",
        "tagName": "innerVlan",
        "propertyValueList": {
            "IdStep": str(inner_vlan_id_step),
            "Priority": inner_priority,
            "IdRepeatCount": str(inner_repeat_count),
            "IfRecycleCount": str(inner_recycle_count)
        }
    }

    add_object_list = config_utils.get_add_object_list(template_config)
    add_object_list.append(add_object_outer)
    add_object_list.append(add_object_inner)

    outer_port_step = 0
    inner_port_step = 0
    if outer_repeat_mode == "off":
        outer_port_step = (
            int(device_count) // int(ips_per_outer_vlan)
        ) * int(outer_vlan_id_step)
    if inner_repeat_mode == "off":
        inner_port_step = (
            int(device_count) // int(ips_per_outer_vlan)
        ) * int(inner_vlans_per_outer_vlan) * int(inner_vlan_id_step)

    stm_property_modifier_outer = {
        "className": "VlanIf",
        "tagName": "outerVlan" + ".VlanId",
        "parentTagName": "outerVlan",
        "propertyName": "VlanId",
        "propertyValueList": {
            "Start": outer_vlan_id,
            "Step": str(outer_port_step),
            "ResetOnNewTargetObject": False
        }
    }

    stm_property_modifier_inner = {
        "className": "VlanIf",
        "tagName": "innerVlan" + ".VlanId",
        "parentTagName": "innerVlan",
        "propertyName": "VlanId",
        "propertyValueList": {
            "Start": inner_vlan_id,
            "Step": str(inner_port_step),
            "ResetOnNewTargetObject": False
        }
    }

    stm_property_modifier_list = config_utils.get_stm_property_modifier_list(
        template_config
    )
    stm_property_modifier_list.append(stm_property_modifier_outer)
    stm_property_modifier_list.append(stm_property_modifier_inner)
Beispiel #5
0
def build_ipv4_config(subnet, template_config):
    plLogger.LogInfo("build_ipv4_config: ")

    config_utils.init_config(template_config)

    gateway_type = subnet["gateway_config"]["_type"]
    ip_config = subnet["ip_config"]
    ipv4_port_step = ip_config["ipv4_port_step"]
    gateway_ipv4_port_step = None
    gateway_mac_port_step = None
    gateway_config = subnet["gateway_config"]
    if gateway_type == "Profile::GatewayArpConfig":
        gw_ip_config = gateway_config.get("ip_config")
        gateway_ipv4_port_step = gw_ip_config["ipv4_port_step"]
    elif gateway_type == "Profile::GatewayMacConfig":
        gateway_mac_port_step = gateway_config["mac_port_step"]
    gateway_config = subnet["gateway_config"]
    ip_config = subnet["ip_config"]
    gateway_type = gateway_config["_type"]
    gw_ip_config = gateway_config.get("ip_config")

    ipv4 = str(ip_config["ipv4"])
    ipv4_step = str(ip_config["ipv4_step"])
    prefix = str(ip_config["prefix"])
    pri = 0
    if "control_plane_priority" in ip_config:
        pri_str = str(ip_config["control_plane_priority"])
        if pri_str == "routine":
            pri = 0
        elif pri_str == "high":
            pri = 32
        else:
            pri = 0
    # Modify the Ipv4If parameters
    # Attach StmPropertyModifier objects to the Address and Gateway
    # fields.
    # Address
    tag_name = tag_name_util.get_ipv4If_tag(subnet)
    stm_property_modifier_list = config_utils.get_stm_property_modifier_list(
        template_config
    )
    property_value_list = config_utils.get_property_value_list(template_config)

    ipv4_stm_property_modifier = {
        "className": "Ipv4If",
        "tagName": tag_name + ".Address",
        "parentTagName": tag_name,
        "propertyName": "Address",
        "propertyValueList": {
            "Start": ipv4,
            "Step": ipv4_port_step,
            "ResetOnNewTargetObject": False
        }
    }
    stm_property_modifier_list.append(ipv4_stm_property_modifier)

    # Gateway
    # Profile::GatewayDhcpConfig is handled in dhcp_builder
    if gateway_type == "Profile::GatewayArpConfig":
        process_gateway_arp_config(subnet,
                                   template_config,
                                   gateway_ipv4_port_step)
    elif gateway_type == "Profile::GatewayMacConfig":
        process_gateway_mac_config(subnet,
                                   template_config,
                                   gateway_mac_port_step)
    # Modify any other parameters not on the StmPropertyModifier
    ipv4_property_value = {
        "className": "Ipv4If",
        "tagName": tag_name,
        "propertyValueList": {
            "AddrStep": ipv4_step,
            "PrefixLength": prefix,
            "Tos": str(pri)
        }
    }
    if gateway_type == "Profile::GatewayArpConfig":
        gw_step = str(gw_ip_config["ipv4_step"])
        ipv4_property_value["propertyValueList"]["GatewayStep"] = gw_step
    elif gateway_type == "Profile::GatewayMacConfig":
        ipv4_property_value["propertyValueList"]["ResolveGatewayMac"] = "FALSE"
    property_value_list.append(ipv4_property_value)