aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/network_services/traffic_profile/test_traffic_profile.py45
1 files changed, 33 insertions, 12 deletions
diff --git a/tests/unit/network_services/traffic_profile/test_traffic_profile.py b/tests/unit/network_services/traffic_profile/test_traffic_profile.py
index 0bb0a88a6..37b9a08d0 100644
--- a/tests/unit/network_services/traffic_profile/test_traffic_profile.py
+++ b/tests/unit/network_services/traffic_profile/test_traffic_profile.py
@@ -13,14 +13,15 @@
# 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.
-#
-from __future__ import absolute_import
+import ipaddress
-import unittest
import mock
+import six
+import unittest
from tests.unit import STL_MOCKS
+from yardstick.common import exceptions as y_exc
STLClient = mock.MagicMock()
stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
@@ -215,11 +216,27 @@ class TestTrexProfile(unittest.TestCase):
TrexProfile(TrafficProfile)
self.assertEqual({}, trex_profile.generate_imix_data(False))
- def test__get_start_end_ipv6(self):
- trex_profile = \
- TrexProfile(TrafficProfile)
- self.assertRaises(SystemExit, trex_profile._get_start_end_ipv6,
- "1.1.1.3", "1.1.1.1")
+ def test__count_ip_ipv4(self):
+ start, end, count = TrexProfile._count_ip('1.1.1.1', '1.2.3.4')
+ self.assertEqual('1.1.1.1', str(start))
+ self.assertEqual('1.2.3.4', str(end))
+ diff = (int(ipaddress.IPv4Address(six.u('1.2.3.4'))) -
+ int(ipaddress.IPv4Address(six.u('1.1.1.1'))))
+ self.assertEqual(diff, count)
+
+ def test__count_ip_ipv6(self):
+ start_ip = '0064:ff9b:0:0:0:0:9810:6414'
+ end_ip = '0064:ff9b:0:0:0:0:9810:6420'
+ start, end, count = TrexProfile._count_ip(start_ip, end_ip)
+ self.assertEqual(0x98106414, start)
+ self.assertEqual(0x98106420, end)
+ self.assertEqual(0x98106420 - 0x98106414, count)
+
+ def test__count_ip_ipv6_exception(self):
+ start_ip = '0064:ff9b:0:0:0:0:9810:6420'
+ end_ip = '0064:ff9b:0:0:0:0:9810:6414'
+ with self.assertRaises(y_exc.IPv6RangeError):
+ TrexProfile._count_ip(start_ip, end_ip)
def test__dscp_range_action_partial_actual_count_zero(self):
traffic_profile = TrexProfile(TrafficProfile)
@@ -258,13 +275,17 @@ class TestTrexProfile(unittest.TestCase):
def test__general_single_action_partial(self):
trex_profile = TrexProfile(TrafficProfile)
- trex_profile._general_single_action_partial(ETHERNET)(SRC)(self.EXAMPLE_ETHERNET_ADDR)
- self.assertEqual(self.EXAMPLE_ETHERNET_ADDR, trex_profile.ether_packet.src)
+ trex_profile._general_single_action_partial(ETHERNET)(SRC)(
+ self.EXAMPLE_ETHERNET_ADDR)
+ self.assertEqual(self.EXAMPLE_ETHERNET_ADDR,
+ trex_profile.ether_packet.src)
- trex_profile._general_single_action_partial(IP)(DST)(self.EXAMPLE_IP_ADDR)
+ trex_profile._general_single_action_partial(IP)(DST)(
+ self.EXAMPLE_IP_ADDR)
self.assertEqual(self.EXAMPLE_IP_ADDR, trex_profile.ip_packet.dst)
- trex_profile._general_single_action_partial(IPv6)(DST)(self.EXAMPLE_IPv6_ADDR)
+ trex_profile._general_single_action_partial(IPv6)(DST)(
+ self.EXAMPLE_IPv6_ADDR)
self.assertEqual(self.EXAMPLE_IPv6_ADDR, trex_profile.ip6_packet.dst)
trex_profile._general_single_action_partial(UDP)(SRC_PORT)(5060)