Signed-off-by: Shinpei Muraoka <[email protected]>
---
 .../unit/services/protocols/bgp/test_bgpspeaker.py | 153 +++++++++++++++++++++
 1 file changed, 153 insertions(+)

diff --git a/ryu/tests/unit/services/protocols/bgp/test_bgpspeaker.py 
b/ryu/tests/unit/services/protocols/bgp/test_bgpspeaker.py
index 6347e1d..fc9863a 100644
--- a/ryu/tests/unit/services/protocols/bgp/test_bgpspeaker.py
+++ b/ryu/tests/unit/services/protocols/bgp/test_bgpspeaker.py
@@ -714,3 +714,156 @@ class Test_BGPSpeaker(unittest.TestCase):
         # Check
         mock_call.assert_called_with(
             'evpn_prefix.add_local', 'Invalid arguments detected')
+
+    @mock.patch(
+        'ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
+        mock.MagicMock(return_value=None))
+    @mock.patch('ryu.services.protocols.bgp.bgpspeaker.call')
+    def test_flowspec_prefix_add_ipv4(self, mock_call):
+        # Prepare test data
+        flowspec_family = bgpspeaker.FLOWSPEC_FAMILY_IPV4
+        rules = {
+            'dst_prefix': '10.60.1.0/24',
+        }
+
+        actions = {
+            'traffic_marking': {
+                'dscp': 24,
+            }
+        }
+
+        expected_kwargs = {
+            'flowspec_family': flowspec_family,
+            'rules': rules,
+            'actions': actions,
+        }
+
+        # Test
+        speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
+        speaker.flowspec_prefix_add(
+            flowspec_family=flowspec_family,
+            rules=rules,
+            actions=actions)
+
+        # Check
+        mock_call.assert_called_with(
+            'flowspec.add', **expected_kwargs)
+
+    @mock.patch(
+        'ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
+        mock.MagicMock(return_value=None))
+    @mock.patch('ryu.services.protocols.bgp.bgpspeaker.call')
+    def test_flowspec_prefix_add_ipv4_without_actions(self, mock_call):
+        # Prepare test data
+        flowspec_family = bgpspeaker.FLOWSPEC_FAMILY_IPV4
+        rules = {
+            'dst_prefix': '10.60.1.0/24',
+        }
+
+        expected_kwargs = {
+            'flowspec_family': flowspec_family,
+            'rules': rules,
+            'actions': {},
+        }
+
+        # Test
+        speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
+        speaker.flowspec_prefix_add(
+            flowspec_family=flowspec_family,
+            rules=rules)
+
+        # Check
+        mock_call.assert_called_with(
+            'flowspec.add', **expected_kwargs)
+
+    @mock.patch(
+        'ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
+        mock.MagicMock(return_value=None))
+    @mock.patch('ryu.services.protocols.bgp.bgpspeaker.call')
+    def test_flowspec_prefix_del_ipv4(self, mock_call):
+        # Prepare test data
+        flowspec_family = bgpspeaker.FLOWSPEC_FAMILY_IPV4
+        rules = {
+            'dst_prefix': '10.60.1.0/24',
+        }
+
+        expected_kwargs = {
+            'flowspec_family': flowspec_family,
+            'rules': rules,
+        }
+
+        # Test
+        speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
+        speaker.flowspec_prefix_del(
+            flowspec_family=flowspec_family,
+            rules=rules)
+
+        # Check
+        mock_call.assert_called_with(
+            'flowspec.del', **expected_kwargs)
+
+    @mock.patch(
+        'ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
+        mock.MagicMock(return_value=None))
+    @mock.patch('ryu.services.protocols.bgp.bgpspeaker.call')
+    def test_flowspec_prefix_add_vpnv4(self, mock_call):
+        # Prepare test data
+        flowspec_family = bgpspeaker.FLOWSPEC_FAMILY_VPNV4
+        route_dist = '65001:100'
+        rules = {
+            'dst_prefix': '10.70.1.0/24',
+        }
+
+        actions = {
+            'traffic_marking': {
+                'dscp': 24,
+            }
+        }
+
+        expected_kwargs = {
+            'flowspec_family': flowspec_family,
+            'route_dist': route_dist,
+            'rules': rules,
+            'actions': actions,
+        }
+
+        # Test
+        speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
+        speaker.flowspec_prefix_add(
+            flowspec_family=flowspec_family,
+            route_dist=route_dist,
+            rules=rules,
+            actions=actions)
+
+        # Check
+        mock_call.assert_called_with(
+            'flowspec.add_local', **expected_kwargs)
+
+    @mock.patch(
+        'ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
+        mock.MagicMock(return_value=None))
+    @mock.patch('ryu.services.protocols.bgp.bgpspeaker.call')
+    def test_flowspec_prefix_del_vpnv4(self, mock_call):
+        # Prepare test data
+        flowspec_family = bgpspeaker.FLOWSPEC_FAMILY_VPNV4
+        route_dist = '65001:100'
+        rules = {
+            'dst_prefix': '10.70.1.0/24',
+        }
+
+        expected_kwargs = {
+            'flowspec_family': flowspec_family,
+            'route_dist': route_dist,
+            'rules': rules,
+        }
+
+        # Test
+        speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
+        speaker.flowspec_prefix_del(
+            flowspec_family=flowspec_family,
+            route_dist=route_dist,
+            rules=rules)
+
+        # Check
+        mock_call.assert_called_with(
+            'flowspec.del_local', **expected_kwargs)
-- 
2.7.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to