Esempio n. 1
0
File: NAT.py Progetto: preym17/csit
    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
Esempio n. 2
0
    def get_lisp_operational_data(node):
        """Retrieve Lisp properties from Honeycomb operational data.

        :param node: Honeycomb node.
        :type node: dict
        :returns: List operational data.
        :rtype: bytearray
        """

        status_code, resp = HcUtil.get_honeycomb_data(node, "oper_lisp")

        if status_code != HTTPCodes.OK:
            raise HoneycombError("Could not retrieve Lisp operational data."
                                 "Status code: {0}.".format(status_code))
        else:
            # get rid of empty vni-table entry
            resp["lisp-state"]["lisp-feature-data"]["eid-table"][
                "vni-table"].remove({
                    "virtual-network-identifier": 0,
                    "vrf-subtable": {
                        "table-id": 0
                    }
                })
            return resp
Esempio n. 3
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