summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorShinpei Muraoka <shinpei.muraoka@gmail.com>2017-03-24 17:10:50 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-03-28 10:00:37 +0900
commit4230897783f1e6e67c3b9ab0450b608906acfa0e (patch)
tree8d2fbe1af10c33a1048e70b05d858c43eb6a05b3
parent06a61123be135e33b130e0165b44b884acc0b34c (diff)
test_bgpspeaker: Add unit tests for Flow Specification
Signed-off-by: Shinpei Muraoka <shinpei.muraoka@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/tests/unit/services/protocols/bgp/test_bgpspeaker.py153
1 files changed, 153 insertions, 0 deletions
diff --git a/ryu/tests/unit/services/protocols/bgp/test_bgpspeaker.py b/ryu/tests/unit/services/protocols/bgp/test_bgpspeaker.py
index 6347e1d0..fc9863ac 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)