def test_one_port_mask(self):
     masks = ovs_ext_lib.get_port_mask(100, 101)
     self.assertEqual(masks, ['0x64/0xfffe'])
     masks = ovs_ext_lib.get_port_mask(100, 103)
     self.assertEqual(masks, ['0x64/0xfffc'])
     masks = ovs_ext_lib.get_port_mask(32768, 65535)
     self.assertEqual(masks, ['0x8000/0x8000'])
 def test_multi_port_masks(self):
     masks = ovs_ext_lib.get_port_mask(101, 102)
     self.assertEqual(masks, ['0x65/0xffff', '0x66/0xffff'])
     masks = ovs_ext_lib.get_port_mask(101, 104)
     self.assertEqual(
         masks,
         ['0x65/0xffff', '0x66/0xfffe', '0x68/0xffff']
     )
     masks = ovs_ext_lib.get_port_mask(1, 65535)
     self.assertEqual(
         masks, [
             '0x1/0xffff',
             '0x2/0xfffe',
             '0x4/0xfffc',
             '0x8/0xfff8',
             '0x10/0xfff0',
             '0x20/0xffe0',
             '0x40/0xffc0',
             '0x80/0xff80',
             '0x100/0xff00',
             '0x200/0xfe00',
             '0x400/0xfc00',
             '0x800/0xf800',
             '0x1000/0xf000',
             '0x2000/0xe000',
             '0x4000/0xc000',
             '0x8000/0x8000'
         ]
     )
     masks = ovs_ext_lib.get_port_mask(32767, 65535)
     self.assertEqual(
         masks, ['0x7fff/0xffff', '0x8000/0x8000']
     )
Example #3
0
    def _parse_flow_classifier(self, flow_classifier):
        dl_type, nw_proto, source_port_masks, destination_port_masks = (
            (None, ) * 4)

        if (
            not flow_classifier['source_port_range_min'] and
            not flow_classifier['source_port_range_max']
        ):
            # wildcard
            source_port_masks = ['0/0x0']
        elif not flow_classifier['source_port_range_min']:
            source_port_masks = ovs_ext_lib.get_port_mask(
                1,
                flow_classifier['source_port_range_max'])
        elif not flow_classifier['source_port_range_max']:
            source_port_masks = ovs_ext_lib.get_port_mask(
                flow_classifier['source_port_range_min'],
                65535)
        else:
            source_port_masks = ovs_ext_lib.get_port_mask(
                flow_classifier['source_port_range_min'],
                flow_classifier['source_port_range_max'])

        if (
            not flow_classifier['destination_port_range_min'] and
            not flow_classifier['destination_port_range_max']
        ):
            # wildcard
            destination_port_masks = ['0/0x0']
        elif not flow_classifier['destination_port_range_min']:
            destination_port_masks = ovs_ext_lib.get_port_mask(
                1,
                flow_classifier['destination_port_range_max'])
        elif not flow_classifier['destination_port_range_max']:
            destination_port_masks = ovs_ext_lib.get_port_mask(
                flow_classifier['destination_port_range_min'],
                65535)
        else:
            destination_port_masks = ovs_ext_lib.get_port_mask(
                flow_classifier['destination_port_range_min'],
                flow_classifier['destination_port_range_max'])

        if "IPv4" == flow_classifier['ethertype']:
            dl_type = 0x0800
            if n_const.PROTO_NAME_TCP == flow_classifier['protocol']:
                nw_proto = n_const.PROTO_NUM_TCP
            elif n_const.PROTO_NAME_UDP == flow_classifier['protocol']:
                nw_proto = n_const.PROTO_NUM_UDP
            elif n_const.PROTO_NAME_ICMP == flow_classifier['protocol']:
                nw_proto = n_const.PROTO_NUM_ICMP
            else:
                nw_proto = None
        elif "IPv6" == flow_classifier['ethertype']:
            LOG.error(_LE("Current portchain agent don't support Ipv6"))
        else:
            LOG.error(_LE("invalid protocol input"))
        return (dl_type, nw_proto,
                source_port_masks, destination_port_masks
                )
 def test_single_port(self):
     masks = ovs_ext_lib.get_port_mask(100, 100)
     self.assertEqual(masks, ['0x64/0xffff'])
 def test_single_port(self):
     masks = ovs_ext_lib.get_port_mask(100, 100)
     self.assertEqual(masks, ['0x64/0xffff'])