'Create a firewall rule for a network interface.
:param  network_interface: The network interface to
attach the firewall rule to.
:type:  network_interface: :class:`ProfitBricksNetworkInterface`
:param  protocol: The protocol for the rule (TCP, UDP, ICMP, ANY)
:type   protocol: ``str``
:param  name: The name for the firewall rule
:type   name: ``str``
:param  source_mac: Only traffic originating from the respective
MAC address is allowed.
Valid format: aa:bb:cc:dd:ee:ff.
Value null allows all source MAC address.
:type   source_mac: ``str``
:param  source_ip: Only traffic originating from the respective IPv4
address is allowed. Value null allows all source IPs.
:type   source_ip: ``str``
:param  target_ip: In case the target NIC has multiple IP addresses,
only traffic directed to the respective IP address
of the NIC is allowed.
Value null allows all target IPs.
:type   target_ip: ``str``
:param  port_range_start: Defines the start range of the allowed port
(from 1 to 65534) if protocol TCP or UDP is chosen.
Leave portRangeStart and portRangeEnd value null
to allow all ports.
type:   port_range_start: ``int``
:param  port_range_end: Defines the end range of the allowed port
(from 1 to 65534) if protocol TCP or UDP is chosen.
Leave portRangeStart and portRangeEnd value null
to allow all ports.
type:   port_range_end: ``int``
:param  icmp_type: Defines the allowed type (from 0 to 254) if the
protocol ICMP is chosen. Value null allows all types.
:type   icmp_type: ``int``
:param  icmp_code: Defines the allowed code (from 0 to 254) if
protocol ICMP is chosen. Value null allows all codes.
:type   icmp_code: ``int``
:return:    Instance class ``ProfitBricksFirewallRule``
:rtype:     :class:`ProfitBricksFirewallRule`'

def ex_create_firewall_rule(self, network_interface, protocol, name=None, source_mac=None, source_ip=None, target_ip=None, port_range_start=None, port_range_end=None, icmp_type=None, icmp_code=None):

    action = (network_interface.href + '/firewallrules')
    body = {'properties': {'protocol': protocol}}
    if (name is not None):
        body['properties']['name'] = name
    if (source_mac is not None):
        body['properties']['sourceMac'] = source_mac
    if (source_ip is not None):
        body['properties']['sourceIp'] = source_ip
    if (target_ip is not None):
        body['properties']['targetIp'] = target_ip
    if (port_range_start is not None):
        body['properties']['portRangeStart'] = str(port_range_start)
    if (port_range_end is not None):
        body['properties']['portRangeEnd'] = str(port_range_end)
    if (icmp_type is not None):
        body['properties']['icmpType'] = str(icmp_type)
    if (icmp_code is not None):
        body['properties']['icmpType'] = str(icmp_code)
    response = self.connection.request(action=action, headers={'Content-Type': 'application/json'}, data=body, method='POST', with_full_url=True)
    return self._to_firewall_rule(response.object, response.headers)
