diff options
author | Shinpei Muraoka <shinpei.muraoka@gmail.com> | 2017-03-24 17:10:52 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-03-28 10:00:55 +0900 |
commit | ab902d2b5e73cc12a576715db4cf76cee112905f (patch) | |
tree | ca58fe3613e81533b96b34165295af634cf88fd5 | |
parent | 9fa4e6b42d0f5431a7af70e9ec91c7caf46b3bc3 (diff) |
utils/test_bgp: 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/utils/test_bgp.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/ryu/tests/unit/services/protocols/bgp/utils/test_bgp.py b/ryu/tests/unit/services/protocols/bgp/utils/test_bgp.py new file mode 100644 index 00000000..25ecd05f --- /dev/null +++ b/ryu/tests/unit/services/protocols/bgp/utils/test_bgp.py @@ -0,0 +1,85 @@ +# Copyright (C) 2017 Nippon Telegraph and Telephone Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import logging +import unittest + +from nose.tools import eq_, raises + +from ryu.lib.packet.bgp import ( + BGPFlowSpecTrafficRateCommunity, + BGPFlowSpecTrafficActionCommunity, + BGPFlowSpecRedirectCommunity, + BGPFlowSpecTrafficMarkingCommunity, +) + +from ryu.services.protocols.bgp.core import BgpCoreError +from ryu.services.protocols.bgp.utils.bgp import create_v4flowspec_actions + + +LOG = logging.getLogger(__name__) + + +class Test_Utils_BGP(unittest.TestCase): + """ + Test case for ryu.services.protocols.bgp.utils.bgp + """ + + def _test_create_v4flowspec_actions(self, actions, expected_communities): + communities = create_v4flowspec_actions(actions) + expected_communities.sort(key=lambda x: x.subtype) + communities.sort(key=lambda x: x.subtype) + eq_(str(expected_communities), str(communities)) + + def test_create_v4flowspec_actions_all_actions(self): + actions = { + 'traffic_rate': { + 'as_number': 0, + 'rate_info': 100.0, + }, + 'traffic_action': { + 'action': 3, + }, + 'redirect': { + 'as_number': 10, + 'local_administrator': 10, + }, + 'traffic_marking': { + 'dscp': 24, + } + } + expected_communities = [ + BGPFlowSpecTrafficRateCommunity(as_number=0, rate_info=100.0), + BGPFlowSpecTrafficActionCommunity(action=3), + BGPFlowSpecRedirectCommunity(as_number=10, local_administrator=10), + BGPFlowSpecTrafficMarkingCommunity(dscp=24), + ] + self._test_create_v4flowspec_actions(actions, expected_communities) + + def test_create_v4flowspec_actions_without_actions(self): + actions = None + expected_communities = [] + self._test_create_v4flowspec_actions(actions, expected_communities) + + @raises(ValueError) + def test_create_v4flowspec_actions_not_exist_actions(self): + actions = { + 'traffic_test': { + 'test': 10, + }, + } + expected_communities = [] + self._test_create_v4flowspec_actions(actions, expected_communities) |