Beispiel #1
0
 def test_merge_common_rules_single(self):
     rule_conj_tuple = ({
         'direction': 'egress',
         'ethertype': 'IPv4',
         'protocol': 1
     }, 8)
     result = rules.merge_common_rules([rule_conj_tuple])
     self.assertEqual([(rule_conj_tuple[0], [rule_conj_tuple[1]])], result)
Beispiel #2
0
    def _add_non_ip_conj_flows(self, port):
        """Install conjunction flows that don't depend on IP address of remote
        groups, which consist of actions=conjunction(conj_id, 2/2) flows and
        actions=accept flows.

        The remaining part is done by ConjIPFlowManager.
        """
        port_rules = collections.defaultdict(list)
        for sec_group_id, rule in (
                self._create_remote_rules_generator_for_port(port)):
            direction = rule['direction']
            ethertype = rule['ethertype']
            protocol = rule.get('protocol')
            priority_offset = rules.flow_priority_offset(rule)

            conj_id = self.conj_ip_manager.add(port.vlan_tag, sec_group_id,
                                               rule['remote_group_id'],
                                               direction, ethertype,
                                               priority_offset)

            rule1 = rule.copy()
            del rule1['remote_group_id']
            port_rules_key = (direction, ethertype, protocol)
            port_rules[port_rules_key].append((rule1, conj_id))

        for (direction, ethertype,
             protocol), rule_conj_list in (port_rules.items()):
            all_conj_ids = set()
            for rule, conj_id in rule_conj_list:
                all_conj_ids.add(conj_id)

            if protocol in [
                    lib_const.PROTO_NUM_SCTP, lib_const.PROTO_NUM_TCP,
                    lib_const.PROTO_NUM_UDP
            ]:
                rule_conj_list = rules.merge_port_ranges(rule_conj_list)
            else:
                rule_conj_list = rules.merge_common_rules(rule_conj_list)

            for rule, conj_ids in rule_conj_list:
                flows = rules.create_flows_from_rule_and_port(rule,
                                                              port,
                                                              conjunction=True)
                for flow in rules.substitute_conjunction_actions(
                        flows, 2, conj_ids):
                    self._add_flow(**flow)

            # Install accept flows and store conj_id to reg7 for future process
            for conj_id in all_conj_ids:
                for flow in rules.create_conj_flows(port, conj_id, direction,
                                                    ethertype):
                    flow['actions'] = "set_field:{:d}->reg{:d},{:s}".format(
                        flow['conj_id'], ovsfw_consts.REG_REMOTE_GROUP,
                        flow['actions'])
                    self._add_flow(**flow)
Beispiel #3
0
    def _add_non_ip_conj_flows(self, port):
        """Install conjunction flows that don't depend on IP address of remote
        groups, which consist of actions=conjunction(conj_id, 2/2) flows and
        actions=accept flows.

        The remaining part is done by ConjIPFlowManager.
        """
        port_rules = collections.defaultdict(list)
        for sec_group_id, rule in (
                self._create_remote_rules_generator_for_port(port)):
            direction = rule['direction']
            ethertype = rule['ethertype']
            protocol = rule.get('protocol')
            priority_offset = rules.flow_priority_offset(rule)

            conj_id = self.conj_ip_manager.add(port.vlan_tag, sec_group_id,
                                               rule['remote_group_id'],
                                               direction, ethertype,
                                               priority_offset)

            rule1 = rule.copy()
            del rule1['remote_group_id']
            port_rules_key = (direction, ethertype, protocol)
            port_rules[port_rules_key].append((rule1, conj_id))

        for (direction, ethertype, protocol), rule_conj_list in (
                port_rules.items()):
            all_conj_ids = set()
            for rule, conj_id in rule_conj_list:
                all_conj_ids.add(conj_id)

            if protocol in [lib_const.PROTO_NUM_SCTP,
                            lib_const.PROTO_NUM_TCP,
                            lib_const.PROTO_NUM_UDP]:
                rule_conj_list = rules.merge_port_ranges(rule_conj_list)
            else:
                rule_conj_list = rules.merge_common_rules(rule_conj_list)

            for rule, conj_ids in rule_conj_list:
                flows = rules.create_flows_from_rule_and_port(
                    rule, port, conjunction=True)
                for flow in rules.substitute_conjunction_actions(
                        flows, 2, conj_ids):
                    self._add_flow(**flow)

            # Install accept flows and store conj_id to reg7 for future process
            for conj_id in all_conj_ids:
                for flow in rules.create_conj_flows(
                        port, conj_id, direction, ethertype):
                    flow['actions'] = "set_field:{:d}->reg{:d},{:s}".format(
                        flow['conj_id'],
                        ovsfw_consts.REG_REMOTE_GROUP,
                        flow['actions']
                    )
                    self._add_flow(**flow)
Beispiel #4
0
 def test_merge_common_rules(self):
     rule_conj_list = [({
         'direction': 'ingress',
         'ethertype': 'IPv4',
         'protocol': 1
     }, 8),
                       ({
                           'direction': 'ingress',
                           'ethertype': 'IPv4',
                           'protocol': 1,
                           'port_range_min': 3
                       }, 16),
                       ({
                           'direction': 'ingress',
                           'ethertype': 'IPv4',
                           'protocol': 1,
                           'port_range_min': 3,
                           'port_range_max': 0
                       }, 40),
                       ({
                           'direction': 'ingress',
                           'ethertype': 'IPv4',
                           'protocol': 1
                       }, 24)]
     result = rules.merge_common_rules(rule_conj_list)
     self.assertItemsEqual([({
         'direction': 'ingress',
         'ethertype': 'IPv4',
         'protocol': 1
     }, [8, 24]),
                            ({
                                'direction': 'ingress',
                                'ethertype': 'IPv4',
                                'protocol': 1,
                                'port_range_min': 3
                            }, [16]),
                            ({
                                'direction': 'ingress',
                                'ethertype': 'IPv4',
                                'protocol': 1,
                                'port_range_min': 3,
                                'port_range_max': 0
                            }, [40])], result)
Beispiel #5
0
 def test_merge_common_rules(self):
     rule_conj_list = [({'direction': 'ingress', 'ethertype': 'IPv4',
                         'protocol': 1}, 8),
                       ({'direction': 'ingress', 'ethertype': 'IPv4',
                         'protocol': 1, 'port_range_min': 3}, 16),
                       ({'direction': 'ingress', 'ethertype': 'IPv4',
                         'protocol': 1, 'port_range_min': 3,
                         'port_range_max': 0}, 40),
                       ({'direction': 'ingress', 'ethertype': 'IPv4',
                         'protocol': 1}, 24)]
     result = rules.merge_common_rules(rule_conj_list)
     self.assertItemsEqual(
         [({'direction': 'ingress', 'ethertype': 'IPv4',
            'protocol': 1}, [8, 24]),
          ({'direction': 'ingress', 'ethertype': 'IPv4',
            'protocol': 1, 'port_range_min': 3}, [16]),
          ({'direction': 'ingress', 'ethertype': 'IPv4',
            'protocol': 1, 'port_range_min': 3, 'port_range_max': 0},
           [40])],
         result)
Beispiel #6
0
 def test_merge_common_rules_single(self):
     rule_conj_tuple = ({'direction': 'egress', 'ethertype': 'IPv4',
                         'protocol': 1}, 8)
     result = rules.merge_common_rules([rule_conj_tuple])
     self.assertEqual([(rule_conj_tuple[0], [rule_conj_tuple[1]])],
                      result)