def _create_policy_to_reply_arp_request(self):
        ignore_action = app_testing_objects.IgnoreAction()
        key1 = (self.subnet.subnet_id, self.port.port_id)
        port_policies = {
            key1: app_testing_objects.PortPolicy(
                rules=[
                    app_testing_objects.PortPolicyRule(
                        # Detect arp requests
                        app_testing_objects.OsKenARPRequestFilter(
                            self.allowed_address_pair_ip_address
                        ),
                        actions=[
                            app_testing_objects.SendAction(
                                self.subnet.subnet_id,
                                self.port.port_id,
                                self._create_arp_response
                            ),
                            app_testing_objects.WaitAction(5),
                            app_testing_objects.DisableRuleAction(),
                            app_testing_objects.StopSimulationAction()
                        ]
                    )
                ],
                default_action=ignore_action
            ),
        }

        return port_policies
Пример #2
0
    def _create_port_policies(self, disable_rule=True):
        ignore_action = app_testing_objects.IgnoreAction()
        key1 = (self.subnet1.subnet_id, self.port1.port_id)
        actions = [
            app_testing_objects.SendAction(self.subnet1.subnet_id,
                                           self.port1.port_id,
                                           self._create_dhcp_request)
        ]
        if disable_rule:
            actions.append(app_testing_objects.DisableRuleAction())

        rules1 = [
            app_testing_objects.PortPolicyRule(
                # Detect dhcp offer
                app_testing_objects.RyuDHCPOfferFilter(),
                actions),
            app_testing_objects.PortPolicyRule(
                # Detect dhcp acknowledge
                app_testing_objects.RyuDHCPAckFilter(),
                actions=[
                    app_testing_objects.DisableRuleAction(),
                    app_testing_objects.WaitAction(5),
                    app_testing_objects.SendAction(
                        self.subnet1.subnet_id, self.port1.port_id,
                        self._create_dhcp_renewal_request),
                ]),
            app_testing_objects.PortPolicyRule(
                # Detect dhcp acknowledge
                app_testing_objects.RyuDHCPAckFilter(),
                actions=[
                    app_testing_objects.StopSimulationAction(),
                    app_testing_objects.DisableRuleAction()
                ]),
            app_testing_objects.PortPolicyRule(
                # Ignore IPv6 packets
                app_testing_objects.RyuIPv6Filter(),
                actions=[ignore_action]),
        ]
        key2 = (self.subnet1.subnet_id, self.port2.port_id)
        rules2 = [
            app_testing_objects.PortPolicyRule(
                # Detect arp replies
                app_testing_objects.RyuDHCPFilter(),
                actions=[
                    app_testing_objects.RaiseAction("Received DHCP packet")
                ]),
            app_testing_objects.PortPolicyRule(
                # Ignore IPv6 packets
                app_testing_objects.RyuIPv6Filter(),
                actions=[ignore_action]),
        ]
        raise_action = app_testing_objects.RaiseAction("Unexpected packet")
        policy1 = app_testing_objects.PortPolicy(rules=rules1,
                                                 default_action=raise_action)
        policy2 = app_testing_objects.PortPolicy(rules=rules2,
                                                 default_action=raise_action)
        return {
            key1: policy1,
            key2: policy2,
        }
Пример #3
0
    def _create_port_policies(self, disable_rule=True):
        ignore_action = app_testing_objects.IgnoreAction()
        key1 = (self.subnet1.subnet_id, self.port1.port_id)
        actions = [
            app_testing_objects.SendAction(self.subnet1.subnet_id,
                                           self.port1.port_id,
                                           self._create_dhcp_request)
        ]
        if disable_rule:
            actions.append(app_testing_objects.DisableRuleAction())

        testclass = self

        class DHCPAckFilterVerifiesMTU(app_testing_objects.RyuDHCPAckFilter):
            def __init__(self, expected_mtu):
                super(DHCPAckFilterVerifiesMTU, self).__init__()
                self.expected_mtu = expected_mtu

            def __call__(self, buf):
                result = super(DHCPAckFilterVerifiesMTU, self).__call__(buf)
                if not result:
                    return result
                pkt = ryu.lib.packet.packet.Packet(buf)
                pkt_dhcp_protocol = pkt.get_protocol(dhcp.dhcp)
                for option in pkt_dhcp_protocol.options.option_list:
                    if option.tag == dhcp.DHCP_INTERFACE_MTU_OPT:
                        mtu = struct.unpack('!H', option.value)
                        testclass.assertEqual((self.expected_mtu, ), mtu)
                return result

        lport1 = self.port1.port.get_logical_port()
        lswitch_ref = lport1.lswitch
        lswitch = self.nb_api.get(lswitch_ref)
        expected_mtu = lswitch.mtu
        rules1 = [
            app_testing_objects.PortPolicyRule(
                # Detect dhcp offer
                app_testing_objects.RyuDHCPOfferFilter(),
                actions),
            app_testing_objects.PortPolicyRule(
                # Detect dhcp acknowledge
                DHCPAckFilterVerifiesMTU(expected_mtu),
                actions=[
                    app_testing_objects.DisableRuleAction(),
                    app_testing_objects.WaitAction(5),
                    app_testing_objects.SendAction(
                        self.subnet1.subnet_id, self.port1.port_id,
                        self._create_dhcp_renewal_request),
                ]),
            app_testing_objects.PortPolicyRule(
                # Detect dhcp acknowledge
                DHCPAckFilterVerifiesMTU(expected_mtu),
                actions=[
                    app_testing_objects.StopSimulationAction(),
                    app_testing_objects.DisableRuleAction()
                ]),
            app_testing_objects.PortPolicyRule(
                # Ignore IPv6 packets
                app_testing_objects.RyuIPv6Filter(),
                actions=[ignore_action]),
        ]
        key2 = (self.subnet1.subnet_id, self.port2.port_id)
        rules2 = [
            app_testing_objects.PortPolicyRule(
                # Detect arp replies
                app_testing_objects.RyuDHCPFilter(),
                actions=[
                    app_testing_objects.RaiseAction("Received DHCP packet")
                ]),
            app_testing_objects.PortPolicyRule(
                # Ignore IPv6 packets
                app_testing_objects.RyuIPv6Filter(),
                actions=[ignore_action]),
        ]
        raise_action = app_testing_objects.RaiseAction("Unexpected packet")
        policy1 = app_testing_objects.PortPolicy(rules=rules1,
                                                 default_action=raise_action)
        policy2 = app_testing_objects.PortPolicy(rules=rules2,
                                                 default_action=raise_action)
        return {
            key1: policy1,
            key2: policy2,
        }