Ejemplo n.º 1
0
    def create_acl_plugin_classify_chain(node, list_name, data, macip=False):
        """Create classify chain using the ietf-acl node.

        :param node: Honeycomb node.
        :param list_name: Name for the classify list.
        :param data: Dictionary of settings to send to Honeycomb.
        :param macip: Use simple MAC+IP classifier. Optional.
        :type node: dict
        :type list_name: str
        :type data: dict
        :type macip: bool
        :returns: Content of response.
        :rtype: bytearray
        :raises HoneycombError: If the operation fails.
        """

        if macip:
            path = "/acl/vpp-acl:vpp-macip-acl/{0}".format(list_name)
        else:
            path = "/acl/vpp-acl:vpp-acl/{0}".format(list_name)

        status_code, resp = HcUtil.put_honeycomb_data(node,
                                                      "config_plugin_acl",
                                                      data, path)

        if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED):
            raise HoneycombError("Could not create classify chain."
                                 "Status code: {0}.".format(status_code))

        return resp
Ejemplo n.º 2
0
    def configure_policer(node, policy_name, policer_data=None):
        """Configure Policer on the specified node.

        :param node: Honeycomb node.
        :param policer_data: Dictionary of configurations to apply. \
        If it is None then the existing configuration is removed.
        :type node: dict
        :type policer_data: dict
        :returns: Content of response.
        :rtype: bytearray
        :raises HoneycombError: If policer could not be configured.
        """

        path = '/' + policy_name

        if not policer_data:
            status_code, _ = HcUtil.delete_honeycomb_data(
                node, 'config_policer', path)
        else:
            data = {'policer': policer_data}

            status_code, _ = HcUtil.put_honeycomb_data(node, 'config_policer',
                                                       data, path)

        if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED):
            raise HoneycombError(
                'Configuring policer failed. Status code:{0}'\
                    .format(status_code))
Ejemplo n.º 3
0
    def configure_interface_slaac(node, interface, slaac_data=None):
        """Configure SLAAC on the specified interfaces.

        :param node: Honeycomb node.
        :param interface: Interface to configure SLAAC.
        :param slaac_data: Dictionary of configurations to apply. \
        If it is None then the existing configuration is removed.
        :type node: dict
        :type interface: str
        :type slaac_data: dict of dicts
        :returns: Content of response.
        :rtype: bytearray
        :raises HoneycombError: If RA could not be configured.
        """

        interface = Topology.convert_interface_reference(
            node, interface, 'name')
        interface = interface.replace('/', '%2F')
        path = 'interface/' + interface + '/ipv6/ipv6-router-advertisements'

        if not slaac_data:
            status_code, _ = HcUtil.delete_honeycomb_data(
                node, 'config_slaac', path)
        else:
            data = {
                       'ipv6-router-advertisements': slaac_data
            }

            status_code, _ = HcUtil.put_honeycomb_data(
                node, 'config_slaac', data, path)

        if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED):
            raise HoneycombError(
                'Configuring SLAAC failed. Status code:{0}'.format(status_code))
Ejemplo n.º 4
0
    def set_proxyarp_interface_config(node, interface, state):
        """Enable or disable the proxyARP feature on the specified interface.

        :param node: Honeycomb node.
        :param interface: Name or sw_if_index of an interface on the node.
        :param state: Desired proxyARP state: enable, disable.
        :type node: dict
        :type interface: str
        :type state: str
        :raises ValueError: If the state argument is incorrect.
        :raises HoneycombError: If the status code in response is not
            200 = OK or 201 = ACCEPTED.
        """

        interface = Topology.convert_interface_reference(
            node, interface, "name")
        interface = interface.replace("/", "%2F")

        path = "/interface/{0}/proxy-arp".format(interface)

        if state == "disable":
            status_code, _ = HcUtil.delete_honeycomb_data(
                node, "config_vpp_interfaces", path)
        elif state == "enable":
            data = {"proxy-arp": {}}
            status_code, _ = HcUtil.put_honeycomb_data(
                node, "config_vpp_interfaces", data, path)
        else:
            raise ValueError("State argument has to be enable or disable.")

        if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED):
            raise HoneycombError(
                "Interface proxyARP configuration on node {0} was not"
                " successful.".format(node["host"]))
Ejemplo n.º 5
0
    def set_acl_plugin_interface(node, interface, acl_name, direction):
        """Assign an interface to an ietf-acl classify chain.

        :param node: Honeycomb node.
        :param interface: Name of an interface on the node.
        :param acl_name: Name of an ACL chain configured through ACL-plugin.
        :param direction: Classify incoming or outgoing packets.
            Valid options are: ingress, egress
        :type node: dict
        :type interface: str or int
        :type acl_name: str
        :type direction: str
        :returns: Content of response.
        :rtype: bytearray
        :raises ValueError: If the direction argument is incorrect.
        :raises HoneycombError: If the operation fails.
        """

        interface = Topology.convert_interface_reference(
            node, interface, "name")

        interface = interface.replace("/", "%2F")

        if direction not in ("ingress", "egress"):
            raise ValueError(
                "Unknown traffic direction {0}. "
                "Valid options are: ingress, egress.".format(direction))

        path = "/attachment-points/interface/{0}/{1}/acl-sets/".format(
            interface, direction)

        data = {"acl-sets": {"acl-set": {"name": acl_name}}}

        status_code, resp = HcUtil.put_honeycomb_data(node,
                                                      "config_plugin_acl",
                                                      data, path)

        if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED):
            raise HoneycombError("Could not configure ACL on interface. "
                                 "Status code: {0}.".format(status_code))

        return resp
Ejemplo n.º 6
0
    def configure_nat_on_interface(node, interface, direction, delete=False):
        """Configure NAT on the specified interface.

        :param node: Honeycomb node.
        :param interface: Name of an interface on the node.
        :param direction: NAT direction, outbound or inbound.
        :param delete: Delete an existing interface NAT configuration.
        :type node: dict
        :type interface: str
        :type direction: str
        :type delete: bool
        :returns: Content of response.
        :rtype: bytearray
        :raises HoneycombError: If the operation fails.
        """

        interface = Topology.convert_interface_reference(
            node, interface, "name")

        interface = interface.replace("/", "%2F")
        path = "/interface/{0}/interface-nat:nat/{1}".format(
            interface, direction)

        data = {direction: {}}

        if delete:
            status_code, resp = HcUtil.delete_honeycomb_data(
                node, "config_vpp_interfaces", path)
        else:
            status_code, resp = HcUtil.put_honeycomb_data(
                node, "config_vpp_interfaces", data, path)

        if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED):
            raise HoneycombError("Could not configure NAT on interface. "
                                 "Status code: {0}.".format(status_code))

        return resp
Ejemplo n.º 7
0
    def set_acl_plugin_interface(node,
                                 interface,
                                 acl_name,
                                 direction,
                                 macip=False):
        """Assign an interface to an ietf-acl classify chain.

        :param node: Honeycomb node.
        :param interface: Name of an interface on the node.
        :param acl_name: Name of an ACL chain configured through ACL-plugin.
        :param direction: Classify incoming or outgiong packets.
            Valid options are: ingress, egress
        :param macip: Use simple MAC+IP classifier. Optional.
        :type node: dict
        :type interface: str or int
        :type acl_name: str
        :type direction: str
        :type macip: bool
        :returns: Content of response.
        :rtype: bytearray
        :raises ValueError: If the direction argument is incorrect.
        :raises HoneycombError: If the operation fails.
        """

        interface = Topology.convert_interface_reference(
            node, interface, "name")

        interface = interface.replace("/", "%2F")

        if direction not in ("ingress", "egress"):
            raise ValueError(
                "Unknown traffic direction {0}. "
                "Valid options are: ingress, egress.".format(direction))

        path = "/interface/{0}/interface-acl:acl/{1}".format(
            interface, direction)

        if macip:
            data = {
                direction: {
                    "vpp-macip-acl": {
                        "type": "vpp-acl:vpp-macip-acl",
                        "name": acl_name
                    }
                }
            }
        else:
            data = {
                direction: {
                    "vpp-acls": [{
                        "type": "vpp-acl:vpp-acl",
                        "name": acl_name
                    }]
                }
            }

        status_code, resp = HcUtil.put_honeycomb_data(node,
                                                      "config_vpp_interfaces",
                                                      data, path)

        if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED):
            raise HoneycombError("Could not configure ACL on interface. "
                                 "Status code: {0}.".format(status_code))

        return resp