summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-05-09 16:09:46 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-05-12 09:46:42 +0900
commitc53605385ef3be4fbf0e3adaad9c5d123a42faac (patch)
tree996dd7fc30a646ae58a56da819078455e095980d
parentbb38fb2f3032325f5dc723fe14913fa563205f19 (diff)
test_bgpspeaker: Add unit tests for IPv6 Flow Spec
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@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 fc9863ac..34986d27 100644
--- a/ryu/tests/unit/services/protocols/bgp/test_bgpspeaker.py
+++ b/ryu/tests/unit/services/protocols/bgp/test_bgpspeaker.py
@@ -867,3 +867,156 @@ class Test_BGPSpeaker(unittest.TestCase):
# Check
mock_call.assert_called_with(
'flowspec.del_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_add_ipv6(self, mock_call):
+ # Prepare test data
+ flowspec_family = bgpspeaker.FLOWSPEC_FAMILY_IPV6
+ rules = {
+ 'dst_prefix': '2001::3/128/32',
+ }
+
+ 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_ipv6_without_actions(self, mock_call):
+ # Prepare test data
+ flowspec_family = bgpspeaker.FLOWSPEC_FAMILY_IPV6
+ rules = {
+ 'dst_prefix': '2001::3/128/32',
+ }
+
+ 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_ipv6(self, mock_call):
+ # Prepare test data
+ flowspec_family = bgpspeaker.FLOWSPEC_FAMILY_IPV6
+ rules = {
+ 'dst_prefix': '2001::3/128/32',
+ }
+
+ 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_vpnv6(self, mock_call):
+ # Prepare test data
+ flowspec_family = bgpspeaker.FLOWSPEC_FAMILY_VPNV6
+ route_dist = '65001:100'
+ rules = {
+ 'dst_prefix': '2001::3/128/32',
+ }
+
+ 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_vpnv6(self, mock_call):
+ # Prepare test data
+ flowspec_family = bgpspeaker.FLOWSPEC_FAMILY_VPNV6
+ route_dist = '65001:100'
+ rules = {
+ 'dst_prefix': '2001::3/128/32',
+ }
+
+ 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)