From 9a183e6c950358c08835fd956265ad93cbb8038d Mon Sep 17 00:00:00 2001 From: Oleksandr Naumets Date: Wed, 24 Oct 2018 12:33:25 +0100 Subject: Add IxNextgen API for settings IP priority Add IxNextgen API for setting IP priority which includes: - Raw priority; - ToS; - Diff-Serv. JIRA: YARDSTICK-1488 Change-Id: I83d85db113a5374fdafc3d50130e5e3584edfc4a Signed-off-by: Oleksandr Naumets --- .../libs/ixia_libs/ixnet/ixnet_api.py | 52 +++++++++++++++++ .../traffic_profile/ixia_rfc2544.py | 1 + .../libs/ixia_libs/test_ixnet_api.py | 67 +++++++++++++++++++++- 3 files changed, 117 insertions(+), 3 deletions(-) diff --git a/yardstick/network_services/libs/ixia_libs/ixnet/ixnet_api.py b/yardstick/network_services/libs/ixia_libs/ixnet/ixnet_api.py index 87e9dbf85..eb958abef 100644 --- a/yardstick/network_services/libs/ixia_libs/ixnet/ixnet_api.py +++ b/yardstick/network_services/libs/ixia_libs/ixnet/ixnet_api.py @@ -526,6 +526,8 @@ class IxNextgen(object): # pragma: no cover or ipaddress.IPV4LENGTH dstmask = traffic_param['outer_l3']['dstmask'] \ or ipaddress.IPV4LENGTH + priority = traffic_param['outer_l3']['priority'] + if srcip: self._update_ipv4_address( self._get_stack_item(fg_id, PROTO_IPV4)[0], @@ -534,6 +536,56 @@ class IxNextgen(object): # pragma: no cover self._update_ipv4_address( self._get_stack_item(fg_id, PROTO_IPV4)[0], 'dstIp', str(dstip), dstseed, dstmask, count) + if priority: + self._update_ipv4_priority( + self._get_stack_item(fg_id, PROTO_IPV4)[0], priority) + + def _update_ipv4_priority(self, ip_descriptor, priority): + """Set the IPv4 priority in a config element stack IP field + + :param ip_descriptor: (str) IP descriptor, e.g.: + /traffic/trafficItem:1/configElement:1/stack:"ipv4-2" + :param priority: (dict) priority configuration from traffic profile, e.g.: + {'tos': + 'precedence': [1, 4, 7] + } + """ + if 'raw' in priority: + priority_field = self._get_field_in_stack_item(ip_descriptor, + 'priority.raw') + self._set_priority_field(priority_field, priority['raw']) + + elif 'dscp' in priority: + for field, value in priority['dscp'].items(): + priority_field = self._get_field_in_stack_item( + ip_descriptor, + 'priority.ds.phb.{field}.{field}'.format(field=field)) + self._set_priority_field(priority_field, value) + + elif 'tos' in priority: + for field, value in priority['tos'].items(): + priority_field = self._get_field_in_stack_item( + ip_descriptor, 'priority.tos.' + field) + self._set_priority_field(priority_field, value) + + def _set_priority_field(self, field_descriptor, value): + """Set the priority field described by field_descriptor + + :param field_descriptor: (str) field descriptor, e.g.: + /traffic/trafficItem:1/configElement:1/stack:"ipv4-2"/ \ + field:"ipv4.header.priority.raw-3 + :param value: (list, int) list of integers or single integer value + """ + if isinstance(value, list): + self.ixnet.setMultiAttribute(field_descriptor, + '-valueList', value, + '-activeFieldChoice', 'true', + '-valueType', 'valueList') + else: + self.ixnet.setMultiAttribute(field_descriptor, + '-activeFieldChoice', 'true', + '-singleValue', str(value)) + self.ixnet.commit() def update_l4(self, traffic): """Update the L4 headers diff --git a/yardstick/network_services/traffic_profile/ixia_rfc2544.py b/yardstick/network_services/traffic_profile/ixia_rfc2544.py index b8aa78d80..8d4e171a8 100644 --- a/yardstick/network_services/traffic_profile/ixia_rfc2544.py +++ b/yardstick/network_services/traffic_profile/ixia_rfc2544.py @@ -111,6 +111,7 @@ class IXIARFC2544Profile(trex_traffic_profile.TrexProfile): 'dstmask': dstmask, 'type': key, 'proto': outer_l3.get('proto'), + 'priority': outer_l3.get('priority') }) outer_l4 = value.get('outer_l4') diff --git a/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py b/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py index 66fed81f1..7f8934f6a 100644 --- a/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py +++ b/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py @@ -46,7 +46,8 @@ TRAFFIC_PARAMETERS = { 'dstip': '152.16.40.20', 'srcip': '152.16.100.20', 'dstmask': 24, - 'srcmask': 24 + 'srcmask': 24, + 'priority': {'raw': '0x01'} }, 'outer_l4': { 'seed': 1, @@ -78,7 +79,8 @@ TRAFFIC_PARAMETERS = { 'dstip': '2001::10', 'srcip': '2021::10', 'dstmask': 64, - 'srcmask': 64 + 'srcmask': 64, + 'priority': {'raw': '0x01'} }, 'outer_l4': { 'seed': 1, @@ -602,6 +604,62 @@ class TestIxNextgen(unittest.TestCase): '-randomMask', '0.0.0.63', '-valueType', 'random', '-countValue', 25) + def test__update_ipv4_priority_raw(self): + priority = {'raw': '0x01'} + self.ixnet_gen._set_priority_field = mock.Mock() + with mock.patch.object(self.ixnet_gen, '_get_field_in_stack_item', + return_value='field_desc'): + self.ixnet_gen._update_ipv4_priority('field_desc', priority) + + self.ixnet_gen._set_priority_field.assert_called_once_with( + 'field_desc', priority['raw']) + + def test__update_ipv4_priority_dscp(self): + priority = {'dscp': {'defaultPHB': [0, 1, 2, 3]}} + self.ixnet_gen._set_priority_field = mock.Mock() + with mock.patch.object(self.ixnet_gen, '_get_field_in_stack_item', + return_value='field_desc'): + self.ixnet_gen._update_ipv4_priority('field_desc', priority) + + self.ixnet_gen._set_priority_field.assert_called_once_with( + 'field_desc', priority['dscp']['defaultPHB']) + + def test__update_ipv4_priority_tos(self): + priority = {'tos': {'precedence': [0, 4, 7]}} + self.ixnet_gen._set_priority_field = mock.Mock() + with mock.patch.object(self.ixnet_gen, '_get_field_in_stack_item', + return_value='field_desc'): + self.ixnet_gen._update_ipv4_priority('field_desc', priority) + + self.ixnet_gen._set_priority_field.assert_called_once_with( + 'field_desc', priority['tos']['precedence']) + + def test__update_ipv4_priority_wrong_priority_type(self): + priority = {'test': [0, 4, 7]} + self.ixnet_gen._set_priority_field = mock.Mock() + with mock.patch.object(self.ixnet_gen, '_get_field_in_stack_item', + return_value='field_desc'): + self.ixnet_gen._update_ipv4_priority('field_desc', priority) + + self.assertEqual(self.ixnet_gen._set_priority_field.call_count, 0) + + def test__set_priority_field_list_value(self): + value = [1, 4, 7] + self.ixnet_gen._set_priority_field('field_desc', value) + self.ixnet_gen.ixnet.setMultiAttribute.assert_called_once_with( + 'field_desc', + '-valueList', [1, 4, 7], + '-activeFieldChoice', 'true', + '-valueType', 'valueList') + + def test__set_priority_field_single_value(self): + value = 7 + self.ixnet_gen._set_priority_field('field_desc', value) + self.ixnet_gen.ixnet.setMultiAttribute.assert_called_once_with( + 'field_desc', + '-activeFieldChoice', 'true', + '-singleValue', '7') + def test__update_udp_port(self): with mock.patch.object(self.ixnet_gen, '_get_field_in_stack_item', return_value='field_desc'): @@ -622,10 +680,13 @@ class TestIxNextgen(unittest.TestCase): mock_update_add, \ mock.patch.object(self.ixnet_gen, '_get_stack_item'), \ mock.patch.object(self.ixnet_gen, - '_get_config_element_by_flow_group_name', return_value='celm'): + '_get_config_element_by_flow_group_name', return_value='celm'), \ + mock.patch.object(self.ixnet_gen, '_update_ipv4_priority') as \ + mock_update_priority: self.ixnet_gen.update_ip_packet(TRAFFIC_PARAMETERS) self.assertEqual(4, len(mock_update_add.mock_calls)) + self.assertEqual(2, len(mock_update_priority.mock_calls)) def test_update_ip_packet_exception_no_config_element(self): with mock.patch.object(self.ixnet_gen, -- cgit 1.2.3-korg